nsIWidget.h 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035
  1. /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsIWidget_h__
  6. #define nsIWidget_h__
  7. #include "mozilla/UniquePtr.h"
  8. #include "nsISupports.h"
  9. #include "nsColor.h"
  10. #include "nsRect.h"
  11. #include "nsStringGlue.h"
  12. #include "nsCOMPtr.h"
  13. #include "nsWidgetInitData.h"
  14. #include "nsTArray.h"
  15. #include "nsITheme.h"
  16. #include "nsITimer.h"
  17. #include "nsRegionFwd.h"
  18. #include "nsXULAppAPI.h"
  19. #include "mozilla/Maybe.h"
  20. #include "mozilla/EventForwards.h"
  21. #include "mozilla/layers/LayersTypes.h"
  22. #include "mozilla/RefPtr.h"
  23. #include "mozilla/TimeStamp.h"
  24. #include "mozilla/gfx/Point.h"
  25. #include "mozilla/widget/IMEData.h"
  26. #include "nsDataHashtable.h"
  27. #include "nsIObserver.h"
  28. #include "nsIWidgetListener.h"
  29. #include "FrameMetrics.h"
  30. #include "Units.h"
  31. // forward declarations
  32. class nsIRollupListener;
  33. class imgIContainer;
  34. class nsIContent;
  35. class ViewWrapper;
  36. class nsIScreen;
  37. class nsIRunnable;
  38. class nsIKeyEventInPluginCallback;
  39. namespace mozilla {
  40. namespace dom {
  41. class TabChild;
  42. } // namespace dom
  43. namespace plugins {
  44. class PluginWidgetChild;
  45. } // namespace plugins
  46. namespace layers {
  47. class AsyncDragMetrics;
  48. class Composer2D;
  49. class Compositor;
  50. class CompositorBridgeChild;
  51. class LayerManager;
  52. class LayerManagerComposite;
  53. class PLayerTransactionChild;
  54. struct ScrollableLayerGuid;
  55. } // namespace layers
  56. namespace gfx {
  57. class DrawTarget;
  58. class SourceSurface;
  59. } // namespace gfx
  60. namespace widget {
  61. class TextEventDispatcher;
  62. class TextEventDispatcherListener;
  63. class CompositorWidget;
  64. class CompositorWidgetInitData;
  65. } // namespace widget
  66. } // namespace mozilla
  67. /**
  68. * Callback function that processes events.
  69. *
  70. * The argument is actually a subtype (subclass) of WidgetEvent which carries
  71. * platform specific information about the event. Platform specific code
  72. * knows how to deal with it.
  73. *
  74. * The return value determines whether or not the default action should take
  75. * place.
  76. */
  77. typedef nsEventStatus (* EVENT_CALLBACK)(mozilla::WidgetGUIEvent* aEvent);
  78. // Hide the native window system's real window type so as to avoid
  79. // including native window system types and APIs. This is necessary
  80. // to ensure cross-platform code.
  81. typedef void* nsNativeWidget;
  82. /**
  83. * Flags for the GetNativeData and SetNativeData functions
  84. */
  85. #define NS_NATIVE_WINDOW 0
  86. #define NS_NATIVE_GRAPHIC 1
  87. #define NS_NATIVE_TMP_WINDOW 2
  88. #define NS_NATIVE_WIDGET 3
  89. #define NS_NATIVE_DISPLAY 4
  90. #define NS_NATIVE_REGION 5
  91. #define NS_NATIVE_OFFSETX 6
  92. #define NS_NATIVE_OFFSETY 7
  93. #define NS_NATIVE_PLUGIN_PORT 8
  94. #define NS_NATIVE_SCREEN 9
  95. // The toplevel GtkWidget containing this nsIWidget:
  96. #define NS_NATIVE_SHELLWIDGET 10
  97. // Has to match to NPNVnetscapeWindow, and shareable across processes
  98. // HWND on Windows and XID on X11
  99. #define NS_NATIVE_SHAREABLE_WINDOW 11
  100. #define NS_NATIVE_OPENGL_CONTEXT 12
  101. // See RegisterPluginWindowForRemoteUpdates
  102. #define NS_NATIVE_PLUGIN_ID 13
  103. // This is available only with GetNativeData() in parent process. Anybody
  104. // shouldn't access this pointer as a valid pointer since the result may be
  105. // special value like NS_ONLY_ONE_NATIVE_IME_CONTEXT. So, the result is just
  106. // an identifier of distinguishing a text composition is caused by which native
  107. // IME context. Note that the result is only valid in the process. So,
  108. // XP code should use nsIWidget::GetNativeIMEContext() instead of using this.
  109. #define NS_RAW_NATIVE_IME_CONTEXT 14
  110. #ifdef XP_WIN
  111. #define NS_NATIVE_TSF_THREAD_MGR 100
  112. #define NS_NATIVE_TSF_CATEGORY_MGR 101
  113. #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
  114. #define NS_NATIVE_ICOREWINDOW 103 // winrt specific
  115. #define NS_NATIVE_CHILD_WINDOW 104
  116. #define NS_NATIVE_CHILD_OF_SHAREABLE_WINDOW 105
  117. #endif
  118. #if defined(MOZ_WIDGET_GTK)
  119. // set/get nsPluginNativeWindowGtk, e10s specific
  120. #define NS_NATIVE_PLUGIN_OBJECT_PTR 104
  121. #ifdef MOZ_X11
  122. #define NS_NATIVE_COMPOSITOR_DISPLAY 105
  123. #endif // MOZ_X11
  124. #endif
  125. #define NS_IWIDGET_IID \
  126. { 0x06396bf6, 0x2dd8, 0x45e5, \
  127. { 0xac, 0x45, 0x75, 0x26, 0x53, 0xb1, 0xc9, 0x80 } }
  128. /*
  129. * Window shadow styles
  130. * Also used for the -moz-window-shadow CSS property
  131. */
  132. #define NS_STYLE_WINDOW_SHADOW_NONE 0
  133. #define NS_STYLE_WINDOW_SHADOW_DEFAULT 1
  134. #define NS_STYLE_WINDOW_SHADOW_MENU 2
  135. #define NS_STYLE_WINDOW_SHADOW_TOOLTIP 3
  136. #define NS_STYLE_WINDOW_SHADOW_SHEET 4
  137. /**
  138. * Transparency modes
  139. */
  140. enum nsTransparencyMode {
  141. eTransparencyOpaque = 0, // Fully opaque
  142. eTransparencyTransparent, // Parts of the window may be transparent
  143. eTransparencyGlass, // Transparent parts of the window have Vista AeroGlass effect applied
  144. eTransparencyBorderlessGlass // As above, but without a border around the opaque areas when there would otherwise be one with eTransparencyGlass
  145. };
  146. /**
  147. * Cursor types.
  148. */
  149. enum nsCursor { ///(normal cursor, usually rendered as an arrow)
  150. eCursor_standard,
  151. ///(system is busy, usually rendered as a hourglass or watch)
  152. eCursor_wait,
  153. ///(Selecting something, usually rendered as an IBeam)
  154. eCursor_select,
  155. ///(can hyper-link, usually rendered as a human hand)
  156. eCursor_hyperlink,
  157. ///(north/south/west/east edge sizing)
  158. eCursor_n_resize,
  159. eCursor_s_resize,
  160. eCursor_w_resize,
  161. eCursor_e_resize,
  162. ///(corner sizing)
  163. eCursor_nw_resize,
  164. eCursor_se_resize,
  165. eCursor_ne_resize,
  166. eCursor_sw_resize,
  167. eCursor_crosshair,
  168. eCursor_move,
  169. eCursor_help,
  170. eCursor_copy, // CSS3
  171. eCursor_alias,
  172. eCursor_context_menu,
  173. eCursor_cell,
  174. eCursor_grab,
  175. eCursor_grabbing,
  176. eCursor_spinning,
  177. eCursor_zoom_in,
  178. eCursor_zoom_out,
  179. eCursor_not_allowed,
  180. eCursor_col_resize,
  181. eCursor_row_resize,
  182. eCursor_no_drop,
  183. eCursor_vertical_text,
  184. eCursor_all_scroll,
  185. eCursor_nesw_resize,
  186. eCursor_nwse_resize,
  187. eCursor_ns_resize,
  188. eCursor_ew_resize,
  189. eCursor_none,
  190. // This one better be the last one in this list.
  191. eCursorCount
  192. };
  193. enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
  194. eZPlacementBottom = 0, // bottom of the window stack
  195. eZPlacementBelow, // just below another widget
  196. eZPlacementTop // top of the window stack
  197. };
  198. /**
  199. * Before the OS goes to sleep, this topic is notified.
  200. */
  201. #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
  202. /**
  203. * After the OS wakes up, this topic is notified.
  204. */
  205. #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
  206. /**
  207. * Before the OS suspends the current process, this topic is notified. Some
  208. * OS will kill processes that are suspended instead of resuming them.
  209. * For that reason this topic may be useful to safely close down resources.
  210. */
  211. #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
  212. /**
  213. * After the current process resumes from being suspended, this topic is
  214. * notified.
  215. */
  216. #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
  217. namespace mozilla {
  218. namespace widget {
  219. /**
  220. * Size constraints for setting the minimum and maximum size of a widget.
  221. * Values are in device pixels.
  222. */
  223. struct SizeConstraints {
  224. SizeConstraints()
  225. : mMaxSize(NS_MAXSIZE, NS_MAXSIZE)
  226. {
  227. }
  228. SizeConstraints(mozilla::LayoutDeviceIntSize aMinSize,
  229. mozilla::LayoutDeviceIntSize aMaxSize)
  230. : mMinSize(aMinSize),
  231. mMaxSize(aMaxSize)
  232. {
  233. }
  234. mozilla::LayoutDeviceIntSize mMinSize;
  235. mozilla::LayoutDeviceIntSize mMaxSize;
  236. };
  237. struct AutoObserverNotifier {
  238. AutoObserverNotifier(nsIObserver* aObserver,
  239. const char* aTopic)
  240. : mObserver(aObserver)
  241. , mTopic(aTopic)
  242. {
  243. }
  244. void SkipNotification()
  245. {
  246. mObserver = nullptr;
  247. }
  248. uint64_t SaveObserver()
  249. {
  250. if (!mObserver) {
  251. return 0;
  252. }
  253. uint64_t observerId = ++sObserverId;
  254. sSavedObservers.Put(observerId, mObserver);
  255. SkipNotification();
  256. return observerId;
  257. }
  258. ~AutoObserverNotifier()
  259. {
  260. if (mObserver) {
  261. mObserver->Observe(nullptr, mTopic, nullptr);
  262. }
  263. }
  264. static void NotifySavedObserver(const uint64_t& aObserverId,
  265. const char* aTopic)
  266. {
  267. nsCOMPtr<nsIObserver> observer = sSavedObservers.Get(aObserverId);
  268. if (!observer) {
  269. MOZ_ASSERT(aObserverId == 0, "We should always find a saved observer for nonzero IDs");
  270. return;
  271. }
  272. sSavedObservers.Remove(aObserverId);
  273. observer->Observe(nullptr, aTopic, nullptr);
  274. }
  275. private:
  276. nsCOMPtr<nsIObserver> mObserver;
  277. const char* mTopic;
  278. private:
  279. static uint64_t sObserverId;
  280. static nsDataHashtable<nsUint64HashKey, nsCOMPtr<nsIObserver>> sSavedObservers;
  281. };
  282. } // namespace widget
  283. } // namespace mozilla
  284. /**
  285. * The base class for all the widgets. It provides the interface for
  286. * all basic and necessary functionality.
  287. */
  288. class nsIWidget : public nsISupports
  289. {
  290. protected:
  291. typedef mozilla::dom::TabChild TabChild;
  292. public:
  293. typedef mozilla::layers::Composer2D Composer2D;
  294. typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild;
  295. typedef mozilla::layers::AsyncDragMetrics AsyncDragMetrics;
  296. typedef mozilla::layers::FrameMetrics FrameMetrics;
  297. typedef mozilla::layers::LayerManager LayerManager;
  298. typedef mozilla::layers::LayerManagerComposite LayerManagerComposite;
  299. typedef mozilla::layers::LayersBackend LayersBackend;
  300. typedef mozilla::layers::PLayerTransactionChild PLayerTransactionChild;
  301. typedef mozilla::layers::ZoomConstraints ZoomConstraints;
  302. typedef mozilla::widget::IMEMessage IMEMessage;
  303. typedef mozilla::widget::IMENotification IMENotification;
  304. typedef mozilla::widget::IMEState IMEState;
  305. typedef mozilla::widget::InputContext InputContext;
  306. typedef mozilla::widget::InputContextAction InputContextAction;
  307. typedef mozilla::widget::NativeIMEContext NativeIMEContext;
  308. typedef mozilla::widget::SizeConstraints SizeConstraints;
  309. typedef mozilla::widget::TextEventDispatcher TextEventDispatcher;
  310. typedef mozilla::widget::TextEventDispatcherListener
  311. TextEventDispatcherListener;
  312. typedef mozilla::LayoutDeviceIntMargin LayoutDeviceIntMargin;
  313. typedef mozilla::LayoutDeviceIntPoint LayoutDeviceIntPoint;
  314. typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect;
  315. typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion;
  316. typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize;
  317. typedef mozilla::ScreenIntPoint ScreenIntPoint;
  318. typedef mozilla::DesktopIntRect DesktopIntRect;
  319. typedef mozilla::CSSRect CSSRect;
  320. // Used in UpdateThemeGeometries.
  321. struct ThemeGeometry {
  322. // The ThemeGeometryType value for the themed widget, see
  323. // nsITheme::ThemeGeometryTypeForWidget.
  324. nsITheme::ThemeGeometryType mType;
  325. // The device-pixel rect within the window for the themed widget
  326. LayoutDeviceIntRect mRect;
  327. ThemeGeometry(nsITheme::ThemeGeometryType aType,
  328. const LayoutDeviceIntRect& aRect)
  329. : mType(aType)
  330. , mRect(aRect)
  331. { }
  332. };
  333. NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
  334. nsIWidget()
  335. : mLastChild(nullptr)
  336. , mPrevSibling(nullptr)
  337. , mOnDestroyCalled(false)
  338. , mWindowType(eWindowType_child)
  339. , mZIndex(0)
  340. {
  341. ClearNativeTouchSequence(nullptr);
  342. }
  343. /**
  344. * Create and initialize a widget.
  345. *
  346. * All the arguments can be null in which case a top level window
  347. * with size 0 is created. The event callback function has to be
  348. * provided only if the caller wants to deal with the events this
  349. * widget receives. The event callback is basically a preprocess
  350. * hook called synchronously. The return value determines whether
  351. * the event goes to the default window procedure or it is hidden
  352. * to the os. The assumption is that if the event handler returns
  353. * false the widget does not see the event. The widget should not
  354. * automatically clear the window to the background color. The
  355. * calling code must handle paint messages and clear the background
  356. * itself.
  357. *
  358. * In practice at least one of aParent and aNativeParent will be null. If
  359. * both are null the widget isn't parented (e.g. context menus or
  360. * independent top level windows).
  361. *
  362. * The dimensions given in aRect are specified in the parent's
  363. * device coordinate system.
  364. * This must not be called for parentless widgets such as top-level
  365. * windows, which use the desktop pixel coordinate system; a separate
  366. * method is provided for these.
  367. *
  368. * @param aParent parent nsIWidget
  369. * @param aNativeParent native parent widget
  370. * @param aRect the widget dimension
  371. * @param aInitData data that is used for widget initialization
  372. *
  373. */
  374. virtual MOZ_MUST_USE nsresult
  375. Create(nsIWidget* aParent,
  376. nsNativeWidget aNativeParent,
  377. const LayoutDeviceIntRect& aRect,
  378. nsWidgetInitData* aInitData = nullptr) = 0;
  379. /*
  380. * As above, but with aRect specified in DesktopPixel units (for top-level
  381. * widgets).
  382. * Default implementation just converts aRect to device pixels and calls
  383. * through to device-pixel Create, but platforms may override this if the
  384. * mapping is not straightforward or the native platform needs to use the
  385. * desktop pixel values directly.
  386. */
  387. virtual MOZ_MUST_USE nsresult
  388. Create(nsIWidget* aParent,
  389. nsNativeWidget aNativeParent,
  390. const DesktopIntRect& aRect,
  391. nsWidgetInitData* aInitData = nullptr)
  392. {
  393. LayoutDeviceIntRect devPixRect =
  394. RoundedToInt(aRect * GetDesktopToDeviceScale());
  395. return Create(aParent, aNativeParent, devPixRect, aInitData);
  396. }
  397. /**
  398. * Allocate, initialize, and return a widget that is a child of
  399. * |this|. The returned widget (if nonnull) has gone through the
  400. * equivalent of CreateInstance(widgetCID) + Create(...).
  401. *
  402. * |CreateChild()| lets widget backends decide whether to parent
  403. * the new child widget to this, nonnatively parent it, or both.
  404. * This interface exists to support the PuppetWidget backend,
  405. * which is entirely non-native. All other params are the same as
  406. * for |Create()|.
  407. *
  408. * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
  409. * |nsIWidget*| this, not its native widget (if it exists), when
  410. * calling |Create()|. This is a timid hack around poorly
  411. * understood code, and shouldn't be used in new code.
  412. */
  413. virtual already_AddRefed<nsIWidget>
  414. CreateChild(const LayoutDeviceIntRect& aRect,
  415. nsWidgetInitData* aInitData = nullptr,
  416. bool aForceUseIWidgetParent = false) = 0;
  417. /**
  418. * Attach to a top level widget.
  419. *
  420. * In cases where a top level chrome widget is being used as a content
  421. * container, attach a secondary listener and update the device
  422. * context. The primary widget listener will continue to be called for
  423. * notifications relating to the top-level window, whereas other
  424. * notifications such as painting and events will instead be called via
  425. * the attached listener. SetAttachedWidgetListener should be used to
  426. * assign the attached listener.
  427. *
  428. * aUseAttachedEvents if true, events are sent to the attached listener
  429. * instead of the normal listener.
  430. */
  431. virtual void AttachViewToTopLevel(bool aUseAttachedEvents) = 0;
  432. /**
  433. * Accessor functions to get and set the attached listener. Used by
  434. * nsView in connection with AttachViewToTopLevel above.
  435. */
  436. virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
  437. virtual nsIWidgetListener* GetAttachedWidgetListener() = 0;
  438. virtual void SetPreviouslyAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
  439. virtual nsIWidgetListener* GetPreviouslyAttachedWidgetListener() = 0;
  440. /**
  441. * Accessor functions to get and set the listener which handles various
  442. * actions for the widget.
  443. */
  444. //@{
  445. virtual nsIWidgetListener* GetWidgetListener() = 0;
  446. virtual void SetWidgetListener(nsIWidgetListener* alistener) = 0;
  447. //@}
  448. /**
  449. * Close and destroy the internal native window.
  450. * This method does not delete the widget.
  451. */
  452. virtual void Destroy() = 0;
  453. /**
  454. * Destroyed() returns true if Destroy() has been called already.
  455. * Otherwise, false.
  456. */
  457. bool Destroyed() const { return mOnDestroyCalled; }
  458. /**
  459. * Reparent a widget
  460. *
  461. * Change the widget's parent. Null parents are allowed.
  462. *
  463. * @param aNewParent new parent
  464. */
  465. NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
  466. /**
  467. * Return the parent Widget of this Widget or nullptr if this is a
  468. * top level window
  469. *
  470. * @return the parent widget or nullptr if it does not have a parent
  471. *
  472. */
  473. virtual nsIWidget* GetParent(void) = 0;
  474. /**
  475. * Return the top level Widget of this Widget
  476. *
  477. * @return the top level widget
  478. */
  479. virtual nsIWidget* GetTopLevelWidget() = 0;
  480. /**
  481. * Return the top (non-sheet) parent of this Widget if it's a sheet,
  482. * or nullptr if this isn't a sheet (or some other error occurred).
  483. * Sheets are only supported on some platforms (currently only OS X).
  484. *
  485. * @return the top (non-sheet) parent widget or nullptr
  486. *
  487. */
  488. virtual nsIWidget* GetSheetWindowParent(void) = 0;
  489. /**
  490. * Return the physical DPI of the screen containing the window ...
  491. * the number of device pixels per inch.
  492. */
  493. virtual float GetDPI() = 0;
  494. /**
  495. * Return the scaling factor between device pixels and the platform-
  496. * dependent "desktop pixels" used to manage window positions on a
  497. * potentially multi-screen, mixed-resolution desktop.
  498. */
  499. virtual mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() = 0;
  500. /**
  501. * Return the default scale factor for the window. This is the
  502. * default number of device pixels per CSS pixel to use. This should
  503. * depend on OS/platform settings such as the Mac's "UI scale factor"
  504. * or Windows' "font DPI". This will take into account Gecko preferences
  505. * overriding the system setting.
  506. */
  507. mozilla::CSSToLayoutDeviceScale GetDefaultScale();
  508. /**
  509. * Return the Gecko override of the system default scale, if any;
  510. * returns <= 0.0 if the system scale should be used as-is.
  511. * nsIWidget::GetDefaultScale() [above] takes this into account.
  512. * It is exposed here so that code that wants to check for a
  513. * default-scale override without having a widget on hand can
  514. * easily access the same value.
  515. * Note that any scale override is a browser-wide value, whereas
  516. * the default GetDefaultScale value (when no override is present)
  517. * may vary between widgets (or screens).
  518. */
  519. static double DefaultScaleOverride();
  520. /**
  521. * Return the first child of this widget. Will return null if
  522. * there are no children.
  523. */
  524. nsIWidget* GetFirstChild() const {
  525. return mFirstChild;
  526. }
  527. /**
  528. * Return the last child of this widget. Will return null if
  529. * there are no children.
  530. */
  531. nsIWidget* GetLastChild() const {
  532. return mLastChild;
  533. }
  534. /**
  535. * Return the next sibling of this widget
  536. */
  537. nsIWidget* GetNextSibling() const {
  538. return mNextSibling;
  539. }
  540. /**
  541. * Set the next sibling of this widget
  542. */
  543. void SetNextSibling(nsIWidget* aSibling) {
  544. mNextSibling = aSibling;
  545. }
  546. /**
  547. * Return the previous sibling of this widget
  548. */
  549. nsIWidget* GetPrevSibling() const {
  550. return mPrevSibling;
  551. }
  552. /**
  553. * Set the previous sibling of this widget
  554. */
  555. void SetPrevSibling(nsIWidget* aSibling) {
  556. mPrevSibling = aSibling;
  557. }
  558. /**
  559. * Show or hide this widget
  560. *
  561. * @param aState true to show the Widget, false to hide it
  562. *
  563. */
  564. NS_IMETHOD Show(bool aState) = 0;
  565. /**
  566. * Make the window modal.
  567. */
  568. virtual void SetModal(bool aModal) = 0;
  569. /**
  570. * Make the non-modal window opened by modal window fake-modal, that will
  571. * call SetFakeModal(false) on destroy on Cocoa.
  572. */
  573. virtual void SetFakeModal(bool aModal)
  574. {
  575. SetModal(aModal);
  576. }
  577. /**
  578. * Are we app modal. Currently only implemented on Cocoa.
  579. */
  580. virtual bool IsRunningAppModal()
  581. {
  582. return false;
  583. }
  584. /**
  585. * The maximum number of simultaneous touch contacts supported by the device.
  586. * In the case of devices with multiple digitizers (e.g. multiple touch screens),
  587. * the value will be the maximum of the set of maximum supported contacts by
  588. * each individual digitizer.
  589. */
  590. virtual uint32_t GetMaxTouchPoints() const = 0;
  591. /**
  592. * Returns whether the window is visible
  593. *
  594. */
  595. virtual bool IsVisible() const = 0;
  596. /**
  597. * Perform platform-dependent sanity check on a potential window position.
  598. * This is guaranteed to work only for top-level windows.
  599. *
  600. * @param aAllowSlop: if true, allow the window to slop offscreen;
  601. * the window should be partially visible. if false,
  602. * force the entire window onscreen (or at least
  603. * the upper-left corner, if it's too large).
  604. * @param aX in: an x position expressed in screen coordinates.
  605. * out: the x position constrained to fit on the screen(s).
  606. * @param aY in: an y position expressed in screen coordinates.
  607. * out: the y position constrained to fit on the screen(s).
  608. *
  609. **/
  610. virtual void ConstrainPosition(bool aAllowSlop,
  611. int32_t *aX,
  612. int32_t *aY) = 0;
  613. /**
  614. * NOTE:
  615. *
  616. * For a top-level window widget, the "parent's coordinate system" is the
  617. * "global" display pixel coordinate space, *not* device pixels (which
  618. * may be inconsistent between multiple screens, at least in the Mac OS
  619. * case with mixed hi-dpi and lo-dpi displays). This applies to all the
  620. * following Move and Resize widget APIs.
  621. *
  622. * The display-/device-pixel distinction becomes important for (at least)
  623. * Mac OS X with Hi-DPI (retina) displays, and Windows when the UI scale
  624. * factor is set to other than 100%.
  625. *
  626. * The Move and Resize methods take floating-point parameters, rather than
  627. * integer ones. This is important when manipulating top-level widgets,
  628. * where the coordinate system may not be an integral multiple of the
  629. * device-pixel space.
  630. **/
  631. /**
  632. * Move this widget.
  633. *
  634. * Coordinates refer to the top-left of the widget. For toplevel windows
  635. * with decorations, this is the top-left of the titlebar and frame .
  636. *
  637. * @param aX the new x position expressed in the parent's coordinate system
  638. * @param aY the new y position expressed in the parent's coordinate system
  639. *
  640. **/
  641. NS_IMETHOD Move(double aX, double aY) = 0;
  642. /**
  643. * Reposition this widget so that the client area has the given offset.
  644. *
  645. * @param aX the new x offset of the client area expressed as an
  646. * offset from the origin of the client area of the parent
  647. * widget (for root widgets and popup widgets it is in
  648. * screen coordinates)
  649. * @param aY the new y offset of the client area expressed as an
  650. * offset from the origin of the client area of the parent
  651. * widget (for root widgets and popup widgets it is in
  652. * screen coordinates)
  653. *
  654. **/
  655. NS_IMETHOD MoveClient(double aX, double aY) = 0;
  656. /**
  657. * Resize this widget. Any size constraints set for the window by a
  658. * previous call to SetSizeConstraints will be applied.
  659. *
  660. * @param aWidth the new width expressed in the parent's coordinate system
  661. * @param aHeight the new height expressed in the parent's coordinate system
  662. * @param aRepaint whether the widget should be repainted
  663. *
  664. */
  665. NS_IMETHOD Resize(double aWidth,
  666. double aHeight,
  667. bool aRepaint) = 0;
  668. /**
  669. * Move or resize this widget. Any size constraints set for the window by
  670. * a previous call to SetSizeConstraints will be applied.
  671. *
  672. * @param aX the new x position expressed in the parent's coordinate system
  673. * @param aY the new y position expressed in the parent's coordinate system
  674. * @param aWidth the new width expressed in the parent's coordinate system
  675. * @param aHeight the new height expressed in the parent's coordinate system
  676. * @param aRepaint whether the widget should be repainted if the size changes
  677. *
  678. */
  679. NS_IMETHOD Resize(double aX,
  680. double aY,
  681. double aWidth,
  682. double aHeight,
  683. bool aRepaint) = 0;
  684. /**
  685. * Resize the widget so that the inner client area has the given size.
  686. *
  687. * @param aWidth the new width of the client area.
  688. * @param aHeight the new height of the client area.
  689. * @param aRepaint whether the widget should be repainted
  690. *
  691. */
  692. NS_IMETHOD ResizeClient(double aWidth,
  693. double aHeight,
  694. bool aRepaint) = 0;
  695. /**
  696. * Resize and reposition the widget so tht inner client area has the given
  697. * offset and size.
  698. *
  699. * @param aX the new x offset of the client area expressed as an
  700. * offset from the origin of the client area of the parent
  701. * widget (for root widgets and popup widgets it is in
  702. * screen coordinates)
  703. * @param aY the new y offset of the client area expressed as an
  704. * offset from the origin of the client area of the parent
  705. * widget (for root widgets and popup widgets it is in
  706. * screen coordinates)
  707. * @param aWidth the new width of the client area.
  708. * @param aHeight the new height of the client area.
  709. * @param aRepaint whether the widget should be repainted
  710. *
  711. */
  712. NS_IMETHOD ResizeClient(double aX,
  713. double aY,
  714. double aWidth,
  715. double aHeight,
  716. bool aRepaint) = 0;
  717. /**
  718. * Sets the widget's z-index.
  719. */
  720. virtual void SetZIndex(int32_t aZIndex) = 0;
  721. /**
  722. * Gets the widget's z-index.
  723. */
  724. int32_t GetZIndex()
  725. {
  726. return mZIndex;
  727. }
  728. /**
  729. * Position this widget just behind the given widget. (Used to
  730. * control z-order for top-level widgets. Get/SetZIndex by contrast
  731. * control z-order for child widgets of other widgets.)
  732. * @param aPlacement top, bottom, or below a widget
  733. * (if top or bottom, param aWidget is ignored)
  734. * @param aWidget widget to place this widget behind
  735. * (only if aPlacement is eZPlacementBelow).
  736. * null is equivalent to aPlacement of eZPlacementTop
  737. * @param aActivate true to activate the widget after placing it
  738. */
  739. virtual void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
  740. nsIWidget *aWidget, bool aActivate) = 0;
  741. /**
  742. * Minimize, maximize or normalize the window size.
  743. * Takes a value from nsSizeMode (see nsIWidgetListener.h)
  744. */
  745. virtual void SetSizeMode(nsSizeMode aMode) = 0;
  746. /**
  747. * Return size mode (minimized, maximized, normalized).
  748. * Returns a value from nsSizeMode (see nsIWidgetListener.h)
  749. */
  750. virtual nsSizeMode SizeMode() = 0;
  751. /**
  752. * Enable or disable this Widget
  753. *
  754. * @param aState true to enable the Widget, false to disable it.
  755. *
  756. */
  757. NS_IMETHOD Enable(bool aState) = 0;
  758. /**
  759. * Ask whether the widget is enabled
  760. */
  761. virtual bool IsEnabled() const = 0;
  762. /**
  763. * Request activation of this window or give focus to this widget.
  764. *
  765. * @param aRaise If true, this function requests activation of this
  766. * widget's toplevel window.
  767. * If false, the appropriate toplevel window (which in
  768. * the case of popups may not be this widget's toplevel
  769. * window) is already active.
  770. */
  771. NS_IMETHOD SetFocus(bool aRaise = false) = 0;
  772. /**
  773. * Get this widget's outside dimensions relative to its parent widget. For
  774. * popup widgets the returned rect is in screen coordinates and not
  775. * relative to its parent widget.
  776. *
  777. * @return the x, y, width and height of this widget.
  778. */
  779. virtual LayoutDeviceIntRect GetBounds() = 0;
  780. /**
  781. * Get this widget's outside dimensions in device coordinates. This
  782. * includes any title bar on the window.
  783. *
  784. * @return the x, y, width and height of this widget.
  785. */
  786. virtual LayoutDeviceIntRect GetScreenBounds() = 0;
  787. /**
  788. * Similar to GetScreenBounds except that this function will always
  789. * get the size when the widget is in the nsSizeMode_Normal size mode
  790. * even if the current size mode is not nsSizeMode_Normal.
  791. * This method will fail if the size mode is not nsSizeMode_Normal and
  792. * the platform doesn't have the ability.
  793. * This method will always succeed if the current size mode is
  794. * nsSizeMode_Normal.
  795. *
  796. * @param aRect On return it holds the x, y, width and height of
  797. * this widget.
  798. */
  799. virtual MOZ_MUST_USE nsresult
  800. GetRestoredBounds(LayoutDeviceIntRect& aRect) = 0;
  801. /**
  802. * Get this widget's client area bounds, if the window has a 3D border
  803. * appearance this returns the area inside the border. The position is the
  804. * position of the client area relative to the client area of the parent
  805. * widget (for root widgets and popup widgets it is in screen coordinates).
  806. *
  807. * @return the x, y, width and height of the client area of this widget.
  808. */
  809. virtual LayoutDeviceIntRect GetClientBounds() = 0;
  810. /**
  811. * Sets the non-client area dimensions of the window. Pass -1 to restore
  812. * the system default frame size for that border. Pass zero to remove
  813. * a border, or pass a specific value adjust a border. Units are in
  814. * pixels. (DPI dependent)
  815. *
  816. * Platform notes:
  817. * Windows: shrinking top non-client height will remove application
  818. * icon and window title text. Glass desktops will refuse to set
  819. * dimensions between zero and size < system default.
  820. *
  821. */
  822. NS_IMETHOD SetNonClientMargins(LayoutDeviceIntMargin& aMargins) = 0;
  823. /**
  824. * Get the client offset from the window origin.
  825. *
  826. * @return the x and y of the offset.
  827. */
  828. virtual LayoutDeviceIntPoint GetClientOffset() = 0;
  829. /**
  830. * Equivalent to GetClientBounds but only returns the size.
  831. */
  832. virtual LayoutDeviceIntSize GetClientSize() {
  833. // Depending on the backend, overloading this method may be useful if
  834. // requesting the client offset is expensive.
  835. return GetClientBounds().Size();
  836. }
  837. /**
  838. * Set the background color for this widget
  839. *
  840. * @param aColor the new background color
  841. *
  842. */
  843. virtual void SetBackgroundColor(const nscolor &aColor) { }
  844. /**
  845. * Get the cursor for this widget.
  846. *
  847. * @return this widget's cursor.
  848. */
  849. virtual nsCursor GetCursor(void) = 0;
  850. /**
  851. * Set the cursor for this widget
  852. *
  853. * @param aCursor the new cursor for this widget
  854. */
  855. NS_IMETHOD SetCursor(nsCursor aCursor) = 0;
  856. /**
  857. * If a cursor type is currently cached locally for this widget, clear the
  858. * cached cursor to force an update on the next SetCursor call.
  859. */
  860. virtual void ClearCachedCursor() = 0;
  861. /**
  862. * Sets an image as the cursor for this widget.
  863. *
  864. * @param aCursor the cursor to set
  865. * @param aX the X coordinate of the hotspot (from left).
  866. * @param aY the Y coordinate of the hotspot (from top).
  867. * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not
  868. * supported
  869. */
  870. NS_IMETHOD SetCursor(imgIContainer* aCursor,
  871. uint32_t aHotspotX, uint32_t aHotspotY) = 0;
  872. /**
  873. * Get the window type of this widget.
  874. */
  875. nsWindowType WindowType() { return mWindowType; }
  876. /**
  877. * Determines if this widget is one of the three types of plugin widgets.
  878. */
  879. bool IsPlugin() {
  880. return mWindowType == eWindowType_plugin ||
  881. mWindowType == eWindowType_plugin_ipc_chrome ||
  882. mWindowType == eWindowType_plugin_ipc_content;
  883. }
  884. /**
  885. * Set the transparency mode of the top-level window containing this widget.
  886. * So, e.g., if you call this on the widget for an IFRAME, the top level
  887. * browser window containing the IFRAME actually gets set. Be careful.
  888. *
  889. * This can fail if the platform doesn't support
  890. * transparency/glass. By default widgets are not
  891. * transparent. This will also fail if the toplevel window is not
  892. * a Mozilla window, e.g., if the widget is in an embedded
  893. * context.
  894. *
  895. * After transparency/glass has been enabled, the initial alpha channel
  896. * value for all pixels is 1, i.e., opaque.
  897. * If the window is resized then the alpha channel values for
  898. * all pixels are reset to 1.
  899. * Pixel RGB color values are already premultiplied with alpha channel values.
  900. */
  901. virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
  902. /**
  903. * Get the transparency mode of the top-level window that contains this
  904. * widget.
  905. */
  906. virtual nsTransparencyMode GetTransparencyMode() = 0;
  907. /**
  908. * This represents a command to set the bounds and clip region of
  909. * a child widget.
  910. */
  911. struct Configuration {
  912. nsCOMPtr<nsIWidget> mChild;
  913. uintptr_t mWindowID; // e10s specific, the unique plugin port id
  914. bool mVisible; // e10s specific, widget visibility
  915. LayoutDeviceIntRect mBounds;
  916. nsTArray<LayoutDeviceIntRect> mClipRegion;
  917. };
  918. /**
  919. * Sets the clip region of each mChild (which must actually be a child
  920. * of this widget) to the union of the pixel rects given in
  921. * mClipRegion, all relative to the top-left of the child
  922. * widget. Clip regions are not implemented on all platforms and only
  923. * need to actually work for children that are plugins.
  924. *
  925. * Also sets the bounds of each child to mBounds.
  926. *
  927. * This will invalidate areas of the children that have changed, but
  928. * does not need to invalidate any part of this widget.
  929. *
  930. * Children should be moved in the order given; the array is
  931. * sorted so to minimize unnecessary invalidation if children are
  932. * moved in that order.
  933. */
  934. virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) = 0;
  935. virtual nsresult SetWindowClipRegion(const nsTArray<LayoutDeviceIntRect>& aRects,
  936. bool aIntersectWithExisting) = 0;
  937. /**
  938. * Appends to aRects the rectangles constituting this widget's clip
  939. * region. If this widget is not clipped, appends a single rectangle
  940. * (0, 0, bounds.width, bounds.height).
  941. */
  942. virtual void GetWindowClipRegion(nsTArray<LayoutDeviceIntRect>* aRects) = 0;
  943. /**
  944. * Register or unregister native plugin widgets which receive Configuration
  945. * data from the content process via the compositor.
  946. *
  947. * Lookups are used by the main thread via the compositor to lookup widgets
  948. * based on a unique window id. On Windows and Linux this is the
  949. * NS_NATIVE_PLUGIN_PORT (hwnd/XID). This tracking maintains a reference to
  950. * widgets held. Consumers are responsible for removing widgets from this
  951. * list.
  952. */
  953. virtual void RegisterPluginWindowForRemoteUpdates() = 0;
  954. virtual void UnregisterPluginWindowForRemoteUpdates() = 0;
  955. static nsIWidget* LookupRegisteredPluginWindow(uintptr_t aWindowID);
  956. /**
  957. * Iterates across the list of registered plugin widgets and updates thier
  958. * visibility based on which plugins are included in the 'visible' list.
  959. *
  960. * The compositor knows little about tabs, but it does know which plugin
  961. * widgets are currently included in the visible layer tree. It calls this
  962. * helper to hide widgets it knows nothing about.
  963. */
  964. static void UpdateRegisteredPluginWindowVisibility(uintptr_t aOwnerWidget,
  965. nsTArray<uintptr_t>& aPluginIds);
  966. #if defined(XP_WIN)
  967. /**
  968. * Iterates over the list of registered plugins and for any that are owned
  969. * by aOwnerWidget and visible it takes a snapshot.
  970. *
  971. * @param aOwnerWidget only captures visible widgets owned by this
  972. */
  973. static void CaptureRegisteredPlugins(uintptr_t aOwnerWidget);
  974. /**
  975. * Take a scroll capture for this widget if possible.
  976. */
  977. virtual void UpdateScrollCapture() = 0;
  978. /**
  979. * Creates an async ImageContainer to hold scroll capture images that can be
  980. * used if the plugin is hidden during scroll.
  981. * @return the async container ID of the created ImageContainer.
  982. */
  983. virtual uint64_t CreateScrollCaptureContainer() = 0;
  984. #endif
  985. /**
  986. * Set the shadow style of the window.
  987. *
  988. * Ignored on child widgets and on non-Mac platforms.
  989. */
  990. virtual void SetWindowShadowStyle(int32_t aStyle) = 0;
  991. /*
  992. * On Mac OS X, this method shows or hides the pill button in the titlebar
  993. * that's used to collapse the toolbar.
  994. *
  995. * Ignored on child widgets and on non-Mac platforms.
  996. */
  997. virtual void SetShowsToolbarButton(bool aShow) = 0;
  998. /*
  999. * On Mac OS X Lion, this method shows or hides the full screen button in
  1000. * the titlebar that handles native full screen mode.
  1001. *
  1002. * Ignored on child widgets, non-Mac platforms, & pre-Lion Mac.
  1003. */
  1004. virtual void SetShowsFullScreenButton(bool aShow) = 0;
  1005. enum WindowAnimationType {
  1006. eGenericWindowAnimation,
  1007. eDocumentWindowAnimation
  1008. };
  1009. /**
  1010. * Sets the kind of top-level window animation this widget should have. On
  1011. * Mac OS X, this causes a particular kind of animation to be shown when the
  1012. * window is first made visible.
  1013. *
  1014. * Ignored on child widgets and on non-Mac platforms.
  1015. */
  1016. virtual void SetWindowAnimationType(WindowAnimationType aType) = 0;
  1017. /**
  1018. * Specifies whether the window title should be drawn even if the window
  1019. * contents extend into the titlebar. Ignored on windows that don't draw
  1020. * in the titlebar. Only implemented on OS X.
  1021. */
  1022. virtual void SetDrawsTitle(bool aDrawTitle) {}
  1023. /**
  1024. * Indicates whether the widget should attempt to make titlebar controls
  1025. * easier to see on dark titlebar backgrounds.
  1026. */
  1027. virtual void SetUseBrightTitlebarForeground(bool aBrightForeground) {}
  1028. /**
  1029. * Hide window chrome (borders, buttons) for this widget.
  1030. *
  1031. */
  1032. NS_IMETHOD HideWindowChrome(bool aShouldHide) = 0;
  1033. enum FullscreenTransitionStage
  1034. {
  1035. eBeforeFullscreenToggle,
  1036. eAfterFullscreenToggle
  1037. };
  1038. /**
  1039. * Prepares for fullscreen transition and returns whether the widget
  1040. * supports fullscreen transition. If this method returns false,
  1041. * PerformFullscreenTransition() must never be called. Otherwise,
  1042. * caller should call that method twice with "before" and "after"
  1043. * stages respectively in order. In the latter case, this method may
  1044. * return some data via aData pointer. Caller must pass that data to
  1045. * PerformFullscreenTransition() if any, and caller is responsible
  1046. * for releasing that data.
  1047. */
  1048. virtual bool PrepareForFullscreenTransition(nsISupports** aData) = 0;
  1049. /**
  1050. * Performs fullscreen transition. This method returns immediately,
  1051. * and will post aCallback to the main thread when the transition
  1052. * finishes.
  1053. */
  1054. virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
  1055. uint16_t aDuration,
  1056. nsISupports* aData,
  1057. nsIRunnable* aCallback) = 0;
  1058. /**
  1059. * Return the screen the widget is in, or null if we don't know.
  1060. */
  1061. virtual already_AddRefed<nsIScreen> GetWidgetScreen() = 0;
  1062. /**
  1063. * Put the toplevel window into or out of fullscreen mode.
  1064. * If aTargetScreen is given, attempt to go fullscreen on that screen,
  1065. * if possible. (If not, it behaves as if aTargetScreen is null.)
  1066. * If !aFullScreen, aTargetScreen is ignored.
  1067. * aTargetScreen support is currently only implemented on Windows.
  1068. *
  1069. * @return NS_OK if the widget is setup properly for fullscreen and
  1070. * FullscreenChanged callback has been or will be called. If other
  1071. * value is returned, the caller should continue the change itself.
  1072. */
  1073. virtual nsresult MakeFullScreen(bool aFullScreen,
  1074. nsIScreen* aTargetScreen = nullptr) = 0;
  1075. /**
  1076. * Same as MakeFullScreen, except that, on systems which natively
  1077. * support fullscreen transition, calling this method explicitly
  1078. * requests that behavior.
  1079. * It is currently only supported on OS X 10.7+.
  1080. */
  1081. virtual nsresult MakeFullScreenWithNativeTransition(
  1082. bool aFullScreen, nsIScreen* aTargetScreen = nullptr)
  1083. {
  1084. return MakeFullScreen(aFullScreen, aTargetScreen);
  1085. }
  1086. /**
  1087. * Invalidate a specified rect for a widget so that it will be repainted
  1088. * later.
  1089. */
  1090. NS_IMETHOD Invalidate(const LayoutDeviceIntRect& aRect) = 0;
  1091. enum LayerManagerPersistence
  1092. {
  1093. LAYER_MANAGER_CURRENT = 0,
  1094. LAYER_MANAGER_PERSISTENT
  1095. };
  1096. /**
  1097. * Return the widget's LayerManager. The layer tree for that
  1098. * LayerManager is what gets rendered to the widget.
  1099. */
  1100. inline LayerManager* GetLayerManager()
  1101. {
  1102. return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
  1103. LAYER_MANAGER_CURRENT);
  1104. }
  1105. inline LayerManager* GetLayerManager(LayerManagerPersistence aPersistence)
  1106. {
  1107. return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
  1108. aPersistence);
  1109. }
  1110. /**
  1111. * Like GetLayerManager(), but prefers creating a layer manager of
  1112. * type |aBackendHint| instead of what would normally be created.
  1113. * LayersBackend::LAYERS_NONE means "no hint".
  1114. */
  1115. virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager,
  1116. LayersBackend aBackendHint,
  1117. LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) = 0;
  1118. /**
  1119. * Called before each layer manager transaction to allow any preparation
  1120. * for DrawWindowUnderlay/Overlay that needs to be on the main thread.
  1121. *
  1122. * Always called on the main thread.
  1123. */
  1124. virtual void PrepareWindowEffects() = 0;
  1125. /**
  1126. * Called when Gecko knows which themed widgets exist in this window.
  1127. * The passed array contains an entry for every themed widget of the right
  1128. * type (currently only NS_THEME_TOOLBAR) within the window, except for
  1129. * themed widgets which are transformed or have effects applied to them
  1130. * (e.g. CSS opacity or filters).
  1131. * This could sometimes be called during display list construction
  1132. * outside of painting.
  1133. * If called during painting, it will be called before we actually
  1134. * paint anything.
  1135. */
  1136. virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) = 0;
  1137. /**
  1138. * Informs the widget about the region of the window that is opaque.
  1139. *
  1140. * @param aOpaqueRegion the region of the window that is opaque.
  1141. */
  1142. virtual void UpdateOpaqueRegion(const LayoutDeviceIntRegion& aOpaqueRegion) {}
  1143. /**
  1144. * Informs the widget about the region of the window that is draggable.
  1145. */
  1146. virtual void UpdateWindowDraggingRegion(const LayoutDeviceIntRegion& aRegion) {}
  1147. /**
  1148. * Tells the widget whether the given input block results in a swipe.
  1149. * Should be called in response to a WidgetWheelEvent that has
  1150. * mFlags.mCanTriggerSwipe set on it.
  1151. */
  1152. virtual void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) {}
  1153. /**
  1154. * Internal methods
  1155. */
  1156. //@{
  1157. virtual void AddChild(nsIWidget* aChild) = 0;
  1158. virtual void RemoveChild(nsIWidget* aChild) = 0;
  1159. virtual void* GetNativeData(uint32_t aDataType) = 0;
  1160. virtual void SetNativeData(uint32_t aDataType, uintptr_t aVal) = 0;
  1161. virtual void FreeNativeData(void * data, uint32_t aDataType) = 0;//~~~
  1162. //@}
  1163. /**
  1164. * Set the widget's title.
  1165. * Must be called after Create.
  1166. *
  1167. * @param aTitle string displayed as the title of the widget
  1168. */
  1169. NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
  1170. /**
  1171. * Set the widget's icon.
  1172. * Must be called after Create.
  1173. *
  1174. * @param anIconSpec string specifying the icon to use; convention is to pass
  1175. * a resource: URL from which a platform-dependent resource
  1176. * file name will be constructed
  1177. */
  1178. NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0;
  1179. /**
  1180. * Return this widget's origin in screen coordinates.
  1181. *
  1182. * @return screen coordinates stored in the x,y members
  1183. */
  1184. virtual LayoutDeviceIntPoint WidgetToScreenOffset() = 0;
  1185. /**
  1186. * Given the specified client size, return the corresponding window size,
  1187. * which includes the area for the borders and titlebar. This method
  1188. * should work even when the window is not yet visible.
  1189. */
  1190. virtual LayoutDeviceIntSize ClientToWindowSize(
  1191. const LayoutDeviceIntSize& aClientSize) = 0;
  1192. /**
  1193. * Dispatches an event to the widget
  1194. *
  1195. */
  1196. NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* event,
  1197. nsEventStatus & aStatus) = 0;
  1198. /**
  1199. * Dispatches an event to APZ only.
  1200. * No-op in the child process.
  1201. */
  1202. virtual void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) = 0;
  1203. /**
  1204. * Dispatches an event that must be handled by APZ first, when APZ is
  1205. * enabled. If invoked in the child process, it is forwarded to the
  1206. * parent process synchronously.
  1207. */
  1208. virtual nsEventStatus DispatchInputEvent(mozilla::WidgetInputEvent* aEvent) = 0;
  1209. /**
  1210. * Confirm an APZ-aware event target. This should be used when APZ will
  1211. * not need a layers update to process the event.
  1212. */
  1213. virtual void SetConfirmedTargetAPZC(uint64_t aInputBlockId,
  1214. const nsTArray<mozilla::layers::ScrollableLayerGuid>& aTargets) const = 0;
  1215. /**
  1216. * Returns true if APZ is in use, false otherwise.
  1217. */
  1218. virtual bool AsyncPanZoomEnabled() const = 0;
  1219. /**
  1220. * Enables the dropping of files to a widget.
  1221. */
  1222. virtual void EnableDragDrop(bool aEnable) = 0;
  1223. /**
  1224. * Enables/Disables system mouse capture.
  1225. * @param aCapture true enables mouse capture, false disables mouse capture
  1226. *
  1227. */
  1228. virtual void CaptureMouse(bool aCapture) = 0;
  1229. /**
  1230. * Classify the window for the window manager. Mostly for X11.
  1231. */
  1232. virtual void SetWindowClass(const nsAString& xulWinType) = 0;
  1233. /**
  1234. * Enables/Disables system capture of any and all events that would cause a
  1235. * popup to be rolled up. aListener should be set to a non-null value for
  1236. * any popups that are not managed by the popup manager.
  1237. * @param aDoCapture true enables capture, false disables capture
  1238. *
  1239. */
  1240. virtual void CaptureRollupEvents(nsIRollupListener* aListener,
  1241. bool aDoCapture) = 0;
  1242. /**
  1243. * Bring this window to the user's attention. This is intended to be a more
  1244. * gentle notification than popping the window to the top or putting up an
  1245. * alert. See, for example, Win32 FlashWindow or the NotificationManager on
  1246. * the Mac. The notification should be suppressed if the window is already
  1247. * in the foreground and should be dismissed when the user brings this window
  1248. * to the foreground.
  1249. * @param aCycleCount Maximum number of times to animate the window per system
  1250. * conventions. If set to -1, cycles indefinitely until
  1251. * window is brought into the foreground.
  1252. */
  1253. NS_IMETHOD GetAttention(int32_t aCycleCount) = 0;
  1254. /**
  1255. * Ask whether there user input events pending. All input events are
  1256. * included, including those not targeted at this nsIwidget instance.
  1257. */
  1258. virtual bool HasPendingInputEvent() = 0;
  1259. /**
  1260. * Set the background color of the window titlebar for this widget. On Mac,
  1261. * for example, this will remove the grey gradient and bottom border and
  1262. * instead show a single, solid color.
  1263. *
  1264. * Ignored on any platform that does not support it. Ignored by widgets that
  1265. * do not represent windows.
  1266. *
  1267. * @param aColor The color to set the title bar background to. Alpha values
  1268. * other than fully transparent (0) are respected if possible
  1269. * on the platform. An alpha of 0 will cause the window to
  1270. * draw with the default style for the platform.
  1271. *
  1272. * @param aActive Whether the color should be applied to active or inactive
  1273. * windows.
  1274. */
  1275. virtual void SetWindowTitlebarColor(nscolor aColor, bool aActive) = 0;
  1276. /**
  1277. * If set to true, the window will draw its contents into the titlebar
  1278. * instead of below it.
  1279. *
  1280. * Ignored on any platform that does not support it. Ignored by widgets that
  1281. * do not represent windows.
  1282. * May result in a resize event, so should only be called from places where
  1283. * reflow and painting is allowed.
  1284. *
  1285. * @param aState Whether drawing into the titlebar should be activated.
  1286. */
  1287. virtual void SetDrawsInTitlebar(bool aState) = 0;
  1288. /*
  1289. * Determine whether the widget shows a resize widget. If it does,
  1290. * aResizerRect returns the resizer's rect.
  1291. *
  1292. * Returns false on any platform that does not support it.
  1293. *
  1294. * @param aResizerRect The resizer's rect in device pixels.
  1295. * @return Whether a resize widget is shown.
  1296. */
  1297. virtual bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) = 0;
  1298. /**
  1299. * Return the popup that was last rolled up, or null if there isn't one.
  1300. */
  1301. virtual nsIContent* GetLastRollup() = 0;
  1302. /**
  1303. * Begin a window resizing drag, based on the event passed in.
  1304. */
  1305. NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent,
  1306. int32_t aHorizontal,
  1307. int32_t aVertical) = 0;
  1308. /**
  1309. * Begin a window moving drag, based on the event passed in.
  1310. */
  1311. NS_IMETHOD BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) = 0;
  1312. enum Modifiers {
  1313. CAPS_LOCK = 0x01, // when CapsLock is active
  1314. NUM_LOCK = 0x02, // when NumLock is active
  1315. SHIFT_L = 0x0100,
  1316. SHIFT_R = 0x0200,
  1317. CTRL_L = 0x0400,
  1318. CTRL_R = 0x0800,
  1319. ALT_L = 0x1000, // includes Option
  1320. ALT_R = 0x2000,
  1321. COMMAND_L = 0x4000,
  1322. COMMAND_R = 0x8000,
  1323. HELP = 0x10000,
  1324. FUNCTION = 0x100000,
  1325. NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
  1326. };
  1327. /**
  1328. * Utility method intended for testing. Dispatches native key events
  1329. * to this widget to simulate the press and release of a key.
  1330. * @param aNativeKeyboardLayout a *platform-specific* constant.
  1331. * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
  1332. * On Windows, it is converted to a hex string and passed to
  1333. * LoadKeyboardLayout, see
  1334. * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
  1335. * @param aNativeKeyCode a *platform-specific* keycode.
  1336. * On Windows, this is the virtual key code.
  1337. * @param aModifiers some combination of the above 'Modifiers' flags;
  1338. * not all flags will apply to all platforms. Mac ignores the _R
  1339. * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
  1340. * FUNCTION.
  1341. * @param aCharacters characters that the OS would decide to generate
  1342. * from the event. On Windows, this is the charCode passed by
  1343. * WM_CHAR.
  1344. * @param aUnmodifiedCharacters characters that the OS would decide
  1345. * to generate from the event if modifier keys (other than shift)
  1346. * were assumed inactive. Needed on Mac, ignored on Windows.
  1347. * @param aObserver the observer that will get notified once the events
  1348. * have been dispatched.
  1349. * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
  1350. * layout is not supported and the event was not fired
  1351. */
  1352. virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
  1353. int32_t aNativeKeyCode,
  1354. uint32_t aModifierFlags,
  1355. const nsAString& aCharacters,
  1356. const nsAString& aUnmodifiedCharacters,
  1357. nsIObserver* aObserver) = 0;
  1358. /**
  1359. * Utility method intended for testing. Dispatches native mouse events
  1360. * may even move the mouse cursor. On Mac the events are guaranteed to
  1361. * be sent to the window containing this widget, but on Windows they'll go
  1362. * to whatever's topmost on the screen at that position, so for
  1363. * cross-platform testing ensure that your window is at the top of the
  1364. * z-order.
  1365. * @param aPoint screen location of the mouse, in device
  1366. * pixels, with origin at the top left
  1367. * @param aNativeMessage *platform-specific* event type (e.g. on Mac,
  1368. * NSMouseMoved; on Windows, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN etc)
  1369. * @param aModifierFlags *platform-specific* modifier flags (ignored
  1370. * on Windows)
  1371. * @param aObserver the observer that will get notified once the events
  1372. * have been dispatched.
  1373. */
  1374. virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
  1375. uint32_t aNativeMessage,
  1376. uint32_t aModifierFlags,
  1377. nsIObserver* aObserver) = 0;
  1378. /**
  1379. * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native message.
  1380. * aPoint is location in device pixels to which the mouse pointer moves to.
  1381. * @param aObserver the observer that will get notified once the events
  1382. * have been dispatched.
  1383. */
  1384. virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
  1385. nsIObserver* aObserver) = 0;
  1386. /**
  1387. * Utility method intended for testing. Dispatching native mouse scroll
  1388. * events may move the mouse cursor.
  1389. *
  1390. * @param aPoint Mouse cursor position in screen coordinates.
  1391. * In device pixels, the origin at the top left of
  1392. * the primary display.
  1393. * @param aNativeMessage Platform native message.
  1394. * @param aDeltaX The delta value for X direction. If the native
  1395. * message doesn't indicate X direction scrolling,
  1396. * this may be ignored.
  1397. * @param aDeltaY The delta value for Y direction. If the native
  1398. * message doesn't indicate Y direction scrolling,
  1399. * this may be ignored.
  1400. * @param aDeltaZ The delta value for Z direction. If the native
  1401. * message doesn't indicate Z direction scrolling,
  1402. * this may be ignored.
  1403. * @param aModifierFlags Must be values of Modifiers, or zero.
  1404. * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
  1405. * document.
  1406. * @param aObserver The observer that will get notified once the
  1407. * events have been dispatched.
  1408. */
  1409. virtual nsresult SynthesizeNativeMouseScrollEvent(LayoutDeviceIntPoint aPoint,
  1410. uint32_t aNativeMessage,
  1411. double aDeltaX,
  1412. double aDeltaY,
  1413. double aDeltaZ,
  1414. uint32_t aModifierFlags,
  1415. uint32_t aAdditionalFlags,
  1416. nsIObserver* aObserver) = 0;
  1417. /*
  1418. * TouchPointerState states for SynthesizeNativeTouchPoint. Match
  1419. * touch states in nsIDOMWindowUtils.idl.
  1420. */
  1421. enum TouchPointerState {
  1422. // The pointer is in a hover state above the digitizer
  1423. TOUCH_HOVER = (1 << 0),
  1424. // The pointer is in contact with the digitizer
  1425. TOUCH_CONTACT = (1 << 1),
  1426. // The pointer has been removed from the digitizer detection area
  1427. TOUCH_REMOVE = (1 << 2),
  1428. // The pointer has been canceled. Will cancel any pending os level
  1429. // gestures that would triggered as a result of completion of the
  1430. // input sequence. This may not cancel moz platform related events
  1431. // that might get tirggered by input already delivered.
  1432. TOUCH_CANCEL = (1 << 3),
  1433. // ALL_BITS used for validity checking during IPC serialization
  1434. ALL_BITS = (1 << 4) - 1
  1435. };
  1436. /*
  1437. * Create a new or update an existing touch pointer on the digitizer.
  1438. * To trigger os level gestures, individual touch points should
  1439. * transition through a complete set of touch states which should be
  1440. * sent as individual messages.
  1441. *
  1442. * @param aPointerId The touch point id to create or update.
  1443. * @param aPointerState one or more of the touch states listed above
  1444. * @param aPoint coords of this event
  1445. * @param aPressure 0.0 -> 1.0 float val indicating pressure
  1446. * @param aOrientation 0 -> 359 degree value indicating the
  1447. * orientation of the pointer. Use 90 for normal taps.
  1448. * @param aObserver The observer that will get notified once the events
  1449. * have been dispatched.
  1450. */
  1451. virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
  1452. TouchPointerState aPointerState,
  1453. LayoutDeviceIntPoint aPoint,
  1454. double aPointerPressure,
  1455. uint32_t aPointerOrientation,
  1456. nsIObserver* aObserver) = 0;
  1457. /*
  1458. * Helper for simulating a simple tap event with one touch point. When
  1459. * aLongTap is true, simulates a native long tap with a duration equal to
  1460. * ui.click_hold_context_menus.delay. This pref is compatible with the
  1461. * apzc long tap duration. Defaults to 1.5 seconds.
  1462. * @param aObserver The observer that will get notified once the events
  1463. * have been dispatched.
  1464. */
  1465. virtual nsresult SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint,
  1466. bool aLongTap,
  1467. nsIObserver* aObserver);
  1468. /*
  1469. * Cancels all active simulated touch input points and pending long taps.
  1470. * Native widgets should track existing points such that they can clear the
  1471. * digitizer state when this call is made.
  1472. * @param aObserver The observer that will get notified once the touch
  1473. * sequence has been cleared.
  1474. */
  1475. virtual nsresult ClearNativeTouchSequence(nsIObserver* aObserver);
  1476. virtual void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) = 0;
  1477. // If this widget supports out-of-process compositing, it can override
  1478. // this method to provide additional information to the compositor.
  1479. virtual void GetCompositorWidgetInitData(mozilla::widget::CompositorWidgetInitData* aInitData)
  1480. {}
  1481. private:
  1482. class LongTapInfo
  1483. {
  1484. public:
  1485. LongTapInfo(int32_t aPointerId, LayoutDeviceIntPoint& aPoint,
  1486. mozilla::TimeDuration aDuration,
  1487. nsIObserver* aObserver) :
  1488. mPointerId(aPointerId),
  1489. mPosition(aPoint),
  1490. mDuration(aDuration),
  1491. mObserver(aObserver),
  1492. mStamp(mozilla::TimeStamp::Now())
  1493. {
  1494. }
  1495. int32_t mPointerId;
  1496. LayoutDeviceIntPoint mPosition;
  1497. mozilla::TimeDuration mDuration;
  1498. nsCOMPtr<nsIObserver> mObserver;
  1499. mozilla::TimeStamp mStamp;
  1500. };
  1501. static void OnLongTapTimerCallback(nsITimer* aTimer, void* aClosure);
  1502. mozilla::UniquePtr<LongTapInfo> mLongTapTouchPoint;
  1503. nsCOMPtr<nsITimer> mLongTapTimer;
  1504. static int32_t sPointerIdCounter;
  1505. public:
  1506. /**
  1507. * Activates a native menu item at the position specified by the index
  1508. * string. The index string is a string of positive integers separated
  1509. * by the "|" (pipe) character. The last integer in the string represents
  1510. * the item index in a submenu located using the integers preceding it.
  1511. *
  1512. * Example: 1|0|4
  1513. * In this string, the first integer represents the top-level submenu
  1514. * in the native menu bar. Since the integer is 1, it is the second submeu
  1515. * in the native menu bar. Within that, the first item (index 0) is a
  1516. * submenu, and we want to activate the 5th item within that submenu.
  1517. */
  1518. virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
  1519. /**
  1520. * This is used for native menu system testing.
  1521. *
  1522. * Updates a native menu at the position specified by the index string.
  1523. * The index string is a string of positive integers separated by the "|"
  1524. * (pipe) character.
  1525. *
  1526. * Example: 1|0|4
  1527. * In this string, the first integer represents the top-level submenu
  1528. * in the native menu bar. Since the integer is 1, it is the second submeu
  1529. * in the native menu bar. Within that, the first item (index 0) is a
  1530. * submenu, and we want to update submenu at index 4 within that submenu.
  1531. *
  1532. * If this is called with an empty string it forces a full reload of the
  1533. * menu system.
  1534. */
  1535. virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
  1536. /**
  1537. * This is used for testing macOS service menu code.
  1538. *
  1539. * @param aResult - the current text selection. Is empty if no selection.
  1540. * @return nsresult - whether or not aResult was assigned the selected text.
  1541. */
  1542. NS_IMETHOD
  1543. GetSelectionAsPlaintext(nsAString& aResult)
  1544. {
  1545. return NS_ERROR_NOT_IMPLEMENTED;
  1546. }
  1547. /**
  1548. * Notify IME of the specified notification.
  1549. *
  1550. * @return If the notification is mouse button event and it's consumed by
  1551. * IME, this returns NS_SUCCESS_EVENT_CONSUMED.
  1552. */
  1553. NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) = 0;
  1554. /**
  1555. * Start plugin IME. If this results in a string getting committed, the
  1556. * result is in aCommitted (otherwise aCommitted is empty).
  1557. *
  1558. * aKeyboardEvent The event with which plugin IME is to be started
  1559. * panelX and panelY Location in screen coordinates of the IME input panel
  1560. * (should be just under the plugin)
  1561. * aCommitted The string committed during IME -- otherwise empty
  1562. */
  1563. NS_IMETHOD StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent,
  1564. int32_t aPanelX, int32_t aPanelY,
  1565. nsString& aCommitted) = 0;
  1566. /**
  1567. * Tells the widget whether or not a plugin (inside the widget) has the
  1568. * keyboard focus. Should be sent when the keyboard focus changes too or
  1569. * from a plugin.
  1570. *
  1571. * aFocused Whether or not a plugin is focused
  1572. */
  1573. virtual void SetPluginFocused(bool& aFocused) = 0;
  1574. /*
  1575. * Tell the plugin has focus. It is unnecessary to use IPC
  1576. */
  1577. bool PluginHasFocus()
  1578. {
  1579. return GetInputContext().mIMEState.mEnabled == IMEState::PLUGIN;
  1580. }
  1581. /**
  1582. * Set IME candidate window position by windowless plugin.
  1583. */
  1584. virtual void SetCandidateWindowForPlugin(
  1585. const mozilla::widget::CandidateWindowPosition& aPosition) = 0;
  1586. /**
  1587. * Handle default action when PluginEvent isn't handled
  1588. */
  1589. virtual void DefaultProcOfPluginEvent(
  1590. const mozilla::WidgetPluginEvent& aEvent) = 0;
  1591. /*
  1592. * Notifies the input context changes.
  1593. */
  1594. NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
  1595. const InputContextAction& aAction) = 0;
  1596. /*
  1597. * Get current input context.
  1598. */
  1599. NS_IMETHOD_(InputContext) GetInputContext() = 0;
  1600. /**
  1601. * Get native IME context. This is different from GetNativeData() with
  1602. * NS_RAW_NATIVE_IME_CONTEXT, the result is unique even if in a remote
  1603. * process.
  1604. */
  1605. NS_IMETHOD_(NativeIMEContext) GetNativeIMEContext();
  1606. /*
  1607. * Given a WidgetKeyboardEvent, this method synthesizes a corresponding
  1608. * native (OS-level) event for it. This method allows tests to simulate
  1609. * keystrokes that trigger native key bindings (which require a native
  1610. * event).
  1611. */
  1612. NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) = 0;
  1613. /*
  1614. * Execute native key bindings for aType.
  1615. */
  1616. typedef void (*DoCommandCallback)(mozilla::Command, void*);
  1617. enum NativeKeyBindingsType
  1618. {
  1619. NativeKeyBindingsForSingleLineEditor,
  1620. NativeKeyBindingsForMultiLineEditor,
  1621. NativeKeyBindingsForRichTextEditor
  1622. };
  1623. NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
  1624. NativeKeyBindingsType aType,
  1625. const mozilla::WidgetKeyboardEvent& aEvent,
  1626. DoCommandCallback aCallback,
  1627. void* aCallbackData) = 0;
  1628. /*
  1629. * Retrieves preference for IME updates
  1630. */
  1631. virtual nsIMEUpdatePreference GetIMEUpdatePreference() = 0;
  1632. /*
  1633. * Call this method when a dialog is opened which has a default button.
  1634. * The button's rectangle should be supplied in aButtonRect.
  1635. */
  1636. NS_IMETHOD OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) = 0;
  1637. /**
  1638. * Return true if this process shouldn't use platform widgets, and
  1639. * so should use PuppetWidgets instead. If this returns true, the
  1640. * result of creating and using a platform widget is undefined,
  1641. * and likely to end in crashes or other buggy behavior.
  1642. */
  1643. static bool
  1644. UsePuppetWidgets()
  1645. {
  1646. return XRE_IsContentProcess();
  1647. }
  1648. /**
  1649. * Allocate and return a "puppet widget" that doesn't directly
  1650. * correlate to a platform widget; platform events and data must
  1651. * be fed to it. Currently used in content processes. NULL is
  1652. * returned if puppet widgets aren't supported in this build
  1653. * config, on this platform, or for this process type.
  1654. *
  1655. * This function is called "Create" to match CreateInstance().
  1656. * The returned widget must still be nsIWidget::Create()d.
  1657. */
  1658. static already_AddRefed<nsIWidget>
  1659. CreatePuppetWidget(TabChild* aTabChild);
  1660. /**
  1661. * Allocate and return a "plugin proxy widget", a subclass of PuppetWidget
  1662. * used in wrapping a PPluginWidget connection for remote widgets. Note
  1663. * this call creates the base object, it does not create the widget. Use
  1664. * nsIWidget's Create to do this.
  1665. */
  1666. static already_AddRefed<nsIWidget>
  1667. CreatePluginProxyWidget(TabChild* aTabChild,
  1668. mozilla::plugins::PluginWidgetChild* aActor);
  1669. /**
  1670. * Reparent this widget's native widget.
  1671. * @param aNewParent the native widget of aNewParent is the new native
  1672. * parent widget
  1673. */
  1674. virtual void ReparentNativeWidget(nsIWidget* aNewParent) = 0;
  1675. /**
  1676. * Return true if widget has it's own GL context
  1677. */
  1678. virtual bool HasGLContext() { return false; }
  1679. /**
  1680. * Returns true to indicate that this widget paints an opaque background
  1681. * that we want to be visible under the page, so layout should not force
  1682. * a default background.
  1683. */
  1684. virtual bool WidgetPaintsBackground() { return false; }
  1685. virtual bool NeedsPaint() {
  1686. return IsVisible() && !GetBounds().IsEmpty();
  1687. }
  1688. /**
  1689. * Get the natural bounds of this widget. This method is only
  1690. * meaningful for widgets for which Gecko implements screen
  1691. * rotation natively. When this is the case, GetBounds() returns
  1692. * the widget bounds taking rotation into account, and
  1693. * GetNaturalBounds() returns the bounds *not* taking rotation
  1694. * into account.
  1695. *
  1696. * No code outside of the composition pipeline should know or care
  1697. * about this. If you're not an agent of the compositor, you
  1698. * probably shouldn't call this method.
  1699. */
  1700. virtual LayoutDeviceIntRect GetNaturalBounds() {
  1701. return GetBounds();
  1702. }
  1703. /**
  1704. * Set size constraints on the window size such that it is never less than
  1705. * the specified minimum size and never larger than the specified maximum
  1706. * size. The size constraints are sizes of the outer rectangle including
  1707. * the window frame and title bar. Use 0 for an unconstrained minimum size
  1708. * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
  1709. * does not necessarily change the size of a window to conform to this size,
  1710. * thus Resize should be called afterwards.
  1711. *
  1712. * @param aConstraints: the size constraints in device pixels
  1713. */
  1714. virtual void SetSizeConstraints(const SizeConstraints& aConstraints) = 0;
  1715. /**
  1716. * Return the size constraints currently observed by the widget.
  1717. *
  1718. * @return the constraints in device pixels
  1719. */
  1720. virtual const SizeConstraints GetSizeConstraints() = 0;
  1721. /**
  1722. * If this is owned by a TabChild, return that. Otherwise return
  1723. * null.
  1724. */
  1725. virtual TabChild* GetOwningTabChild() { return nullptr; }
  1726. /**
  1727. * If this isn't directly compositing to its window surface,
  1728. * return the compositor which is doing that on our behalf.
  1729. */
  1730. virtual CompositorBridgeChild* GetRemoteRenderer()
  1731. { return nullptr; }
  1732. /**
  1733. * Some platforms (only cocoa right now) round widget coordinates to the
  1734. * nearest even pixels (see bug 892994), this function allows us to
  1735. * determine how widget coordinates will be rounded.
  1736. */
  1737. virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
  1738. virtual void UpdateZoomConstraints(const uint32_t& aPresShellId,
  1739. const FrameMetrics::ViewID& aViewId,
  1740. const mozilla::Maybe<ZoomConstraints>& aConstraints) {};
  1741. /**
  1742. * GetTextEventDispatcher() returns TextEventDispatcher belonging to the
  1743. * widget. Note that this never returns nullptr.
  1744. */
  1745. NS_IMETHOD_(TextEventDispatcher*) GetTextEventDispatcher() = 0;
  1746. /**
  1747. * GetNativeTextEventDispatcherListener() returns a
  1748. * TextEventDispatcherListener instance which is used when the widget
  1749. * instance handles native IME and/or keyboard events.
  1750. */
  1751. NS_IMETHOD_(TextEventDispatcherListener*)
  1752. GetNativeTextEventDispatcherListener() = 0;
  1753. virtual void ZoomToRect(const uint32_t& aPresShellId,
  1754. const FrameMetrics::ViewID& aViewId,
  1755. const CSSRect& aRect,
  1756. const uint32_t& aFlags) = 0;
  1757. /**
  1758. * OnWindowedPluginKeyEvent() is called when native key event is
  1759. * received in the focused plugin process directly in PluginInstanceChild.
  1760. *
  1761. * @param aKeyEventData The native key event data. The actual type
  1762. * copied into NativeEventData depends on the
  1763. * caller. Please check PluginInstanceChild.
  1764. * @param aCallback Callback interface. When this returns
  1765. * NS_SUCCESS_EVENT_HANDLED_ASYNCHRONOUSLY,
  1766. * the event handler has to call this callback.
  1767. * Otherwise, the caller should do that instead.
  1768. * @return NS_ERROR_* if this fails to handle the event.
  1769. * NS_SUCCESS_EVENT_CONSUMED if the key event is
  1770. * consumed.
  1771. * NS_OK if the key event isn't consumed.
  1772. * NS_SUCCESS_EVENT_HANDLED_ASYNCHRONOUSLY if the
  1773. * key event will be handled asynchronously.
  1774. */
  1775. virtual nsresult OnWindowedPluginKeyEvent(
  1776. const mozilla::NativeEventData& aKeyEventData,
  1777. nsIKeyEventInPluginCallback* aCallback);
  1778. /**
  1779. * LookUpDictionary shows the dictionary for the word around current point.
  1780. *
  1781. * @param aText the word to look up dictiorary.
  1782. * @param aFontRangeArray text decoration of aText
  1783. * @param aIsVertical true if the word is vertical layout
  1784. * @param aPoint top-left point of aText
  1785. */
  1786. virtual void LookUpDictionary(
  1787. const nsAString& aText,
  1788. const nsTArray<mozilla::FontRange>& aFontRangeArray,
  1789. const bool aIsVertical,
  1790. const LayoutDeviceIntPoint& aPoint)
  1791. { }
  1792. protected:
  1793. /**
  1794. * Like GetDefaultScale, but taking into account only the system settings
  1795. * and ignoring Gecko preferences.
  1796. */
  1797. virtual double GetDefaultScaleInternal() { return 1.0; }
  1798. // keep the list of children. We also keep track of our siblings.
  1799. // The ownership model is as follows: parent holds a strong ref to
  1800. // the first element of the list, and each element holds a strong
  1801. // ref to the next element in the list. The prevsibling and
  1802. // lastchild pointers are weak, which is fine as long as they are
  1803. // maintained properly.
  1804. nsCOMPtr<nsIWidget> mFirstChild;
  1805. nsIWidget* MOZ_NON_OWNING_REF mLastChild;
  1806. nsCOMPtr<nsIWidget> mNextSibling;
  1807. nsIWidget* MOZ_NON_OWNING_REF mPrevSibling;
  1808. // When Destroy() is called, the sub class should set this true.
  1809. bool mOnDestroyCalled;
  1810. nsWindowType mWindowType;
  1811. int32_t mZIndex;
  1812. };
  1813. NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
  1814. #endif // nsIWidget_h__