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