PresShellWidgetListener.h (3081B)
1 /* -*- Mode: C++; tab-width: 2; 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 mozilla_PresShellWidgetListener_h__ 7 #define mozilla_PresShellWidgetListener_h__ 8 9 #include "Units.h" 10 #include "mozilla/Attributes.h" 11 #include "mozilla/CallState.h" 12 #include "nsCOMPtr.h" 13 #include "nsIWidgetListener.h" 14 15 class nsIWidget; 16 17 namespace mozilla { 18 class PresShell; 19 namespace dom { 20 class BrowserParent; 21 } // namespace dom 22 namespace widget { 23 struct InitData; 24 enum class TransparencyMode : uint8_t; 25 enum class WindowType : uint8_t; 26 } // namespace widget 27 28 class PresShellWidgetListener final : public nsIWidgetListener { 29 public: 30 // Stops listening to mWidget and clears it. 31 void DetachWidget(); 32 33 /** 34 * Attach/detach a top level widget. Attaching allows the shell to begin 35 * receiving gecko events. The underlying base window associated with the 36 * widget will continues to receive events it expects. 37 * 38 * An attached widget will not be destroyed when we are destroyed, 39 * allowing the recycling of a single top level widget over multiple pres 40 * shells. 41 * 42 * @param aWidget The widget to attach to / detach from. 43 */ 44 void AttachToTopLevelWidget(nsIWidget* aWidget); 45 void DetachFromTopLevelWidget(); 46 47 static uint32_t GetLastUserEventTime(); 48 49 nsIWidget* GetWidget() const { return mWindow; } 50 bool HasWidget() const { return !!mWindow; } 51 52 // nsIWidgetListener 53 mozilla::PresShell* GetPresShell() override; 54 PresShellWidgetListener* GetAsPresShellWidgetListener() override { 55 return this; 56 } 57 bool IsPaintSuppressed() const override { 58 return IsPrimaryFramePaintSuppressed(); 59 } 60 void WindowResized(nsIWidget*, const LayoutDeviceIntSize&) override; 61 void DynamicToolbarMaxHeightChanged(mozilla::ScreenIntCoord aHeight) override; 62 void DynamicToolbarOffsetChanged(mozilla::ScreenIntCoord aOffset) override; 63 void KeyboardHeightChanged(mozilla::ScreenIntCoord aHeight) override; 64 void AndroidPipModeChanged(bool) override; 65 MOZ_CAN_RUN_SCRIPT_BOUNDARY 66 void PaintWindow(nsIWidget* aWidget) override; 67 void DidCompositeWindow(mozilla::layers::TransactionId aTransactionId, 68 const mozilla::TimeStamp& aCompositeStart, 69 const mozilla::TimeStamp& aCompositeEnd) override; 70 MOZ_CAN_RUN_SCRIPT_BOUNDARY 71 nsEventStatus HandleEvent(mozilla::WidgetGUIEvent*) override; 72 void SafeAreaInsetsChanged(const mozilla::LayoutDeviceIntMargin&) override; 73 74 explicit PresShellWidgetListener(mozilla::PresShell*); 75 virtual ~PresShellWidgetListener(); 76 77 bool IsPrimaryFramePaintSuppressed() const; 78 79 private: 80 void CallOnAllRemoteChildren( 81 const std::function<mozilla::CallState(mozilla::dom::BrowserParent*)>& 82 aCallback); 83 84 mozilla::PresShell* mPresShell = nullptr; 85 nsCOMPtr<nsIWidget> mWindow; 86 nsCOMPtr<nsIWidget> mPreviousWindow; 87 }; 88 89 } // namespace mozilla 90 91 #endif