Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
6 #pragma once
8 #include "nscore.h"
9 #include "nsdefs.h"
10 #include "prlog.h"
11 #include "nsAutoPtr.h"
12 #include "nsBaseWidget.h"
13 #include "nsWindowBase.h"
14 #include "nsString.h"
15 #include "nsTArray.h"
16 #include "nsWindowDbg.h"
17 #include "WindowHook.h"
18 #include "TaskbarWindowPreview.h"
19 #include "nsIdleService.h"
20 #ifdef ACCESSIBILITY
21 #include "mozilla/a11y/Accessible.h"
22 #endif
23 #include "mozilla/EventForwards.h"
24 #include "mozilla/layers/CompositorParent.h"
25 #include "mozilla/layers/LayerManagerComposite.h"
26 #include "nsDeque.h"
27 #include "APZController.h"
29 #include "mozwrlbase.h"
31 #include <windows.system.h>
32 #include <windows.ui.core.h>
33 #include <Windows.ApplicationModel.core.h>
34 #include <Windows.ApplicationModel.h>
35 #include <Windows.Applicationmodel.Activation.h>
37 class nsNativeDragTarget;
39 namespace mozilla {
40 namespace widget {
41 namespace winrt {
43 class FrameworkView;
45 } } }
47 class DispatchMsg;
49 class MetroWidget : public nsWindowBase,
50 public nsIObserver
51 {
52 typedef uint32_t TouchBehaviorFlags;
54 typedef mozilla::widget::WindowHook WindowHook;
55 typedef mozilla::widget::TaskbarWindowPreview TaskbarWindowPreview;
56 typedef ABI::Windows::UI::Input::IPointerPoint IPointerPoint;
57 typedef ABI::Windows::UI::Core::IPointerEventArgs IPointerEventArgs;
58 typedef ABI::Windows::UI::Core::IKeyEventArgs IKeyEventArgs;
59 typedef ABI::Windows::UI::Core::ICharacterReceivedEventArgs ICharacterReceivedEventArgs;
60 typedef mozilla::widget::winrt::FrameworkView FrameworkView;
61 typedef mozilla::widget::winrt::APZController APZController;
62 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
64 static LRESULT CALLBACK
65 StaticWindowProcedure(HWND aWnd, UINT aMsg, WPARAM aWParan, LPARAM aLParam);
66 LRESULT WindowProcedure(HWND aWnd, UINT aMsg, WPARAM aWParan, LPARAM aLParam);
68 public:
69 MetroWidget();
70 virtual ~MetroWidget();
72 NS_DECL_ISUPPORTS_INHERITED
73 NS_DECL_NSIOBSERVER
75 static HWND GetICoreWindowHWND() { return sICoreHwnd; }
77 // nsWindowBase
78 virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE;
79 virtual bool DispatchKeyboardEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE;
80 virtual bool DispatchScrollEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE;
81 virtual bool DispatchPluginEvent(const MSG &aMsg) MOZ_OVERRIDE { return false; }
82 virtual bool IsTopLevelWidget() MOZ_OVERRIDE { return true; }
83 virtual nsWindowBase* GetParentWindowBase(bool aIncludeOwner) MOZ_OVERRIDE { return nullptr; }
84 // InitEvent assumes physical coordinates and is used by shared win32 code. Do
85 // not hand winrt event coordinates to this routine.
86 virtual void InitEvent(mozilla::WidgetGUIEvent& aEvent,
87 nsIntPoint* aPoint = nullptr) MOZ_OVERRIDE;
89 // nsBaseWidget
90 virtual CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight);
91 virtual void SetWidgetListener(nsIWidgetListener* aWidgetListener);
93 // nsIWidget interface
94 NS_IMETHOD Create(nsIWidget *aParent,
95 nsNativeWidget aNativeParent,
96 const nsIntRect &aRect,
97 nsDeviceContext *aContext,
98 nsWidgetInitData *aInitData = nullptr);
99 NS_IMETHOD Destroy();
100 NS_IMETHOD EnableDragDrop(bool aEnable);
101 NS_IMETHOD SetParent(nsIWidget *aNewParent);
102 NS_IMETHOD Show(bool bState);
103 NS_IMETHOD IsVisible(bool & aState);
104 NS_IMETHOD IsEnabled(bool *aState);
105 NS_IMETHOD GetBounds(nsIntRect &aRect);
106 NS_IMETHOD GetScreenBounds(nsIntRect &aRect);
107 NS_IMETHOD GetClientBounds(nsIntRect &aRect);
108 NS_IMETHOD Invalidate(bool aEraseBackground = false,
109 bool aUpdateNCArea = false,
110 bool aIncludeChildren = false);
111 NS_IMETHOD Invalidate(const nsIntRect & aRect);
112 NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent,
113 nsEventStatus& aStatus);
114 NS_IMETHOD ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY);
115 NS_IMETHOD Move(double aX, double aY);
116 NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint);
117 NS_IMETHOD Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint);
118 NS_IMETHOD SetFocus(bool aRaise);
119 NS_IMETHOD Enable(bool aState);
120 NS_IMETHOD SetCursor(nsCursor aCursor);
121 NS_IMETHOD SetTitle(const nsAString& aTitle);
122 NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener,
123 bool aDoCapture);
124 NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent);
125 virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
126 int32_t aNativeKeyCode,
127 uint32_t aModifierFlags,
128 const nsAString& aCharacters,
129 const nsAString& aUnmodifiedCharacters);
130 virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
131 uint32_t aNativeMessage,
132 uint32_t aModifierFlags);
133 virtual nsresult SynthesizeNativeMouseScrollEvent(nsIntPoint aPoint,
134 uint32_t aNativeMessage,
135 double aDeltaX,
136 double aDeltaY,
137 double aDeltaZ,
138 uint32_t aModifierFlags,
139 uint32_t aAdditionalFlags);
140 virtual bool HasPendingInputEvent();
141 virtual double GetDefaultScaleInternal();
142 float GetDPI();
143 mozilla::LayoutDeviceIntPoint CSSIntPointToLayoutDeviceIntPoint(const mozilla::CSSIntPoint &aCSSPoint);
144 void ChangedDPI();
145 virtual uint32_t GetMaxTouchPoints() const MOZ_OVERRIDE;
146 virtual bool IsVisible() const;
147 virtual bool IsEnabled() const;
148 // ShouldUseOffMainThreadCompositing is defined in base widget
149 virtual bool ShouldUseOffMainThreadCompositing();
150 bool ShouldUseMainThreadD3D10Manager();
151 bool ShouldUseBasicManager();
152 bool ShouldUseAPZC();
153 virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
154 LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
155 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
156 bool* aAllowRetaining = nullptr);
157 virtual void GetPreferredCompositorBackends(nsTArray<mozilla::layers::LayersBackend>& aHints) { aHints.AppendElement(mozilla::layers::LayersBackend::LAYERS_D3D11); }
159 // IME related interfaces
160 NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
161 const InputContextAction& aAction);
162 NS_IMETHOD_(nsIWidget::InputContext) GetInputContext();
163 NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE;
164 NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState);
165 virtual nsIMEUpdatePreference GetIMEUpdatePreference() MOZ_OVERRIDE;
167 // FrameworkView helpers
168 void SizeModeChanged();
169 void Activated(bool aActiveated);
170 void Paint(const nsIntRegion& aInvalidRegion);
172 MetroWidget* MetroWidget::GetTopLevelWindow(bool aStopOnDialogOrPopup) { return this; }
173 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations);
174 virtual void* GetNativeData(uint32_t aDataType);
175 virtual void FreeNativeData(void * data, uint32_t aDataType);
176 virtual nsIntPoint WidgetToScreenOffset();
178 already_AddRefed<nsIPresShell> GetPresShell();
180 void UserActivity();
182 #ifdef ACCESSIBILITY
183 mozilla::a11y::Accessible* DispatchAccessibleEvent(uint32_t aEventType);
184 mozilla::a11y::Accessible* GetAccessible();
185 #endif // ACCESSIBILITY
187 // needed for current nsIFilePicker
188 void PickerOpen();
189 void PickerClosed();
190 bool DestroyCalled() { return false; }
191 void SuppressBlurEvents(bool aSuppress);
192 bool BlurEventsSuppressed();
194 // needed for nsITaskbarWindowPreview
195 bool HasTaskbarIconBeenCreated() { return false; }
196 void SetHasTaskbarIconBeenCreated(bool created = true) { }
197 already_AddRefed<nsITaskbarWindowPreview> GetTaskbarPreview() { return nullptr; }
198 void SetTaskbarPreview(nsITaskbarWindowPreview *preview) { }
199 WindowHook& GetWindowHook() { return mWindowHook; }
201 void SetView(FrameworkView* aView);
202 void FindMetroWindow();
203 virtual void SetTransparencyMode(nsTransparencyMode aMode);
204 virtual nsTransparencyMode GetTransparencyMode();
206 TouchBehaviorFlags ContentGetAllowedTouchBehavior(const nsIntPoint& aPoint);
208 // apzc controller related api
209 void ApzcGetAllowedTouchBehavior(mozilla::WidgetInputEvent* aTransformedEvent, nsTArray<TouchBehaviorFlags>& aOutBehaviors);
210 void ApzcSetAllowedTouchBehavior(const ScrollableLayerGuid& aGuid, nsTArray<TouchBehaviorFlags>& aBehaviors);
212 // Hit test a point to see if an apzc would consume input there
213 bool ApzHitTest(mozilla::ScreenIntPoint& pt);
214 // Transforms a coord so that it properly targets gecko content based
215 // on apzc transforms currently applied.
216 void ApzTransformGeckoCoordinate(const mozilla::ScreenIntPoint& pt,
217 mozilla::LayoutDeviceIntPoint* aRefPointOut);
218 // send ContentRecievedTouch calls to the apz with appropriate preventDefault params
219 void ApzContentConsumingTouch(const ScrollableLayerGuid& aGuid);
220 void ApzContentIgnoringTouch(const ScrollableLayerGuid& aGuid);
221 // Input handling
222 nsEventStatus ApzReceiveInputEvent(mozilla::WidgetInputEvent* aEvent,
223 ScrollableLayerGuid* aOutTargetGuid);
225 protected:
226 friend class FrameworkView;
228 struct OleInitializeWrapper {
229 HRESULT const hr;
231 OleInitializeWrapper()
232 : hr(::OleInitialize(nullptr))
233 {
234 }
236 ~OleInitializeWrapper() {
237 if (SUCCEEDED(hr)) {
238 ::OleFlushClipboard();
239 ::OleUninitialize();
240 }
241 }
242 };
244 void SetSubclass();
245 void RemoveSubclass();
246 nsIWidgetListener* GetPaintListener();
248 // Async event dispatching
249 void DispatchAsyncScrollEvent(DispatchMsg* aEvent);
250 void DeliverNextScrollEvent();
251 void DeliverNextKeyboardEvent();
253 protected:
254 OleInitializeWrapper mOleInitializeWrapper;
255 WindowHook mWindowHook;
256 Microsoft::WRL::ComPtr<FrameworkView> mView;
257 nsTransparencyMode mTransparencyMode;
258 nsIntRegion mInvalidatedRegion;
259 nsCOMPtr<nsIIdleServiceInternal> mIdleService;
260 HWND mWnd;
261 static HWND sICoreHwnd;
262 WNDPROC mMetroWndProc;
263 bool mTempBasicLayerInUse;
264 uint64_t mRootLayerTreeId;
265 nsDeque mEventQueue;
266 nsDeque mKeyEventQueue;
267 nsRefPtr<APZController> mController;
268 nsRefPtr<nsNativeDragTarget> mNativeDragTarget;
269 };