Coverage Report

Created: 2018-09-25 14:53

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