1 /* -*- Mode: C++; tab-width: 4; 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 NSWINDOW_H_
7 #define NSWINDOW_H_
8 
9 #include "nsBaseWidget.h"
10 #include "gfxPoint.h"
11 
12 #include "nsTArray.h"
13 
14 @class UIWindow;
15 @class UIView;
16 @class ChildView;
17 
18 class nsWindow final : public nsBaseWidget {
19   typedef nsBaseWidget Inherited;
20 
21  public:
22   nsWindow();
23 
24   NS_INLINE_DECL_REFCOUNTING_INHERITED(nsWindow, Inherited)
25 
26   //
27   // nsIWidget
28   //
29 
30   [[nodiscard]] virtual nsresult Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
31                                         const LayoutDeviceIntRect& aRect,
32                                         nsWidgetInitData* aInitData = nullptr) override;
33   virtual void Destroy() override;
34   virtual void Show(bool aState) override;
Enable(bool aState)35   virtual void Enable(bool aState) override {}
IsEnabled()36   virtual bool IsEnabled() const override { return true; }
IsVisible()37   virtual bool IsVisible() const override { return mVisible; }
38   virtual void SetFocus(Raise, mozilla::dom::CallerType aCallerType) override;
39   virtual LayoutDeviceIntPoint WidgetToScreenOffset() override;
40 
41   virtual void SetBackgroundColor(const nscolor& aColor) override;
42   virtual void* GetNativeData(uint32_t aDataType) override;
43 
44   virtual void Move(double aX, double aY) override;
45   virtual void SetSizeMode(nsSizeMode aMode) override;
46   void EnteredFullScreen(bool aFullScreen);
47   virtual void Resize(double aWidth, double aHeight, bool aRepaint) override;
48   virtual void Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override;
49   virtual LayoutDeviceIntRect GetScreenBounds() override;
50   void ReportMoveEvent();
51   void ReportSizeEvent();
52   void ReportSizeModeEvent(nsSizeMode aMode);
53 
54   CGFloat BackingScaleFactor();
55   void BackingScaleFactorChanged();
GetDPI()56   virtual float GetDPI() override {
57     // XXX: terrible
58     return 326.0f;
59   }
GetDefaultScaleInternal()60   virtual double GetDefaultScaleInternal() override { return BackingScaleFactor(); }
61   virtual int32_t RoundsWidgetCoordinatesTo() override;
62 
SetTitle(const nsAString & aTitle)63   virtual nsresult SetTitle(const nsAString& aTitle) override { return NS_OK; }
64 
65   virtual void Invalidate(const LayoutDeviceIntRect& aRect) override;
66   virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* aEvent, nsEventStatus& aStatus) override;
67 
68   void WillPaintWindow();
69   bool PaintWindow(LayoutDeviceIntRegion aRegion);
70 
HasModalDescendents()71   bool HasModalDescendents() { return false; }
72 
73   // virtual nsresult
74   // NotifyIME(const IMENotification& aIMENotification) override;
75   virtual void SetInputContext(const InputContext& aContext, const InputContextAction& aAction);
76   virtual InputContext GetInputContext();
77   /*
78   virtual bool ExecuteNativeKeyBinding(
79                       NativeKeyBindingsType aType,
80                       const mozilla::WidgetKeyboardEvent& aEvent,
81                       DoCommandCallback aCallback,
82                       void* aCallbackData) override;
83   */
84 
85  protected:
86   virtual ~nsWindow();
87   void BringToFront();
88   nsWindow* FindTopLevel();
89   bool IsTopLevel();
90   nsresult GetCurrentOffset(uint32_t& aOffset, uint32_t& aLength);
91   nsresult DeleteRange(int aOffset, int aLen);
92 
93   void TearDownView();
94 
95   ChildView* mNativeView;
96   bool mVisible;
97   nsTArray<nsWindow*> mChildren;
98   nsWindow* mParent;
99   InputContext mInputContext;
100 
101   void OnSizeChanged(const mozilla::gfx::IntSize& aSize);
102 
103   static void DumpWindows();
104   static void DumpWindows(const nsTArray<nsWindow*>& wins, int indent = 0);
105   static void LogWindow(nsWindow* win, int index, int indent);
106 };
107 
108 #endif /* NSWINDOW_H_ */
109