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