widget/windows/winrt/MetroWidget.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial