1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/windows/winrt/MetroWidget.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,269 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#pragma once 1.10 + 1.11 +#include "nscore.h" 1.12 +#include "nsdefs.h" 1.13 +#include "prlog.h" 1.14 +#include "nsAutoPtr.h" 1.15 +#include "nsBaseWidget.h" 1.16 +#include "nsWindowBase.h" 1.17 +#include "nsString.h" 1.18 +#include "nsTArray.h" 1.19 +#include "nsWindowDbg.h" 1.20 +#include "WindowHook.h" 1.21 +#include "TaskbarWindowPreview.h" 1.22 +#include "nsIdleService.h" 1.23 +#ifdef ACCESSIBILITY 1.24 +#include "mozilla/a11y/Accessible.h" 1.25 +#endif 1.26 +#include "mozilla/EventForwards.h" 1.27 +#include "mozilla/layers/CompositorParent.h" 1.28 +#include "mozilla/layers/LayerManagerComposite.h" 1.29 +#include "nsDeque.h" 1.30 +#include "APZController.h" 1.31 + 1.32 +#include "mozwrlbase.h" 1.33 + 1.34 +#include <windows.system.h> 1.35 +#include <windows.ui.core.h> 1.36 +#include <Windows.ApplicationModel.core.h> 1.37 +#include <Windows.ApplicationModel.h> 1.38 +#include <Windows.Applicationmodel.Activation.h> 1.39 + 1.40 +class nsNativeDragTarget; 1.41 + 1.42 +namespace mozilla { 1.43 +namespace widget { 1.44 +namespace winrt { 1.45 + 1.46 +class FrameworkView; 1.47 + 1.48 +} } } 1.49 + 1.50 +class DispatchMsg; 1.51 + 1.52 +class MetroWidget : public nsWindowBase, 1.53 + public nsIObserver 1.54 +{ 1.55 + typedef uint32_t TouchBehaviorFlags; 1.56 + 1.57 + typedef mozilla::widget::WindowHook WindowHook; 1.58 + typedef mozilla::widget::TaskbarWindowPreview TaskbarWindowPreview; 1.59 + typedef ABI::Windows::UI::Input::IPointerPoint IPointerPoint; 1.60 + typedef ABI::Windows::UI::Core::IPointerEventArgs IPointerEventArgs; 1.61 + typedef ABI::Windows::UI::Core::IKeyEventArgs IKeyEventArgs; 1.62 + typedef ABI::Windows::UI::Core::ICharacterReceivedEventArgs ICharacterReceivedEventArgs; 1.63 + typedef mozilla::widget::winrt::FrameworkView FrameworkView; 1.64 + typedef mozilla::widget::winrt::APZController APZController; 1.65 + typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid; 1.66 + 1.67 + static LRESULT CALLBACK 1.68 + StaticWindowProcedure(HWND aWnd, UINT aMsg, WPARAM aWParan, LPARAM aLParam); 1.69 + LRESULT WindowProcedure(HWND aWnd, UINT aMsg, WPARAM aWParan, LPARAM aLParam); 1.70 + 1.71 +public: 1.72 + MetroWidget(); 1.73 + virtual ~MetroWidget(); 1.74 + 1.75 + NS_DECL_ISUPPORTS_INHERITED 1.76 + NS_DECL_NSIOBSERVER 1.77 + 1.78 + static HWND GetICoreWindowHWND() { return sICoreHwnd; } 1.79 + 1.80 + // nsWindowBase 1.81 + virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE; 1.82 + virtual bool DispatchKeyboardEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE; 1.83 + virtual bool DispatchScrollEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE; 1.84 + virtual bool DispatchPluginEvent(const MSG &aMsg) MOZ_OVERRIDE { return false; } 1.85 + virtual bool IsTopLevelWidget() MOZ_OVERRIDE { return true; } 1.86 + virtual nsWindowBase* GetParentWindowBase(bool aIncludeOwner) MOZ_OVERRIDE { return nullptr; } 1.87 + // InitEvent assumes physical coordinates and is used by shared win32 code. Do 1.88 + // not hand winrt event coordinates to this routine. 1.89 + virtual void InitEvent(mozilla::WidgetGUIEvent& aEvent, 1.90 + nsIntPoint* aPoint = nullptr) MOZ_OVERRIDE; 1.91 + 1.92 + // nsBaseWidget 1.93 + virtual CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight); 1.94 + virtual void SetWidgetListener(nsIWidgetListener* aWidgetListener); 1.95 + 1.96 + // nsIWidget interface 1.97 + NS_IMETHOD Create(nsIWidget *aParent, 1.98 + nsNativeWidget aNativeParent, 1.99 + const nsIntRect &aRect, 1.100 + nsDeviceContext *aContext, 1.101 + nsWidgetInitData *aInitData = nullptr); 1.102 + NS_IMETHOD Destroy(); 1.103 + NS_IMETHOD EnableDragDrop(bool aEnable); 1.104 + NS_IMETHOD SetParent(nsIWidget *aNewParent); 1.105 + NS_IMETHOD Show(bool bState); 1.106 + NS_IMETHOD IsVisible(bool & aState); 1.107 + NS_IMETHOD IsEnabled(bool *aState); 1.108 + NS_IMETHOD GetBounds(nsIntRect &aRect); 1.109 + NS_IMETHOD GetScreenBounds(nsIntRect &aRect); 1.110 + NS_IMETHOD GetClientBounds(nsIntRect &aRect); 1.111 + NS_IMETHOD Invalidate(bool aEraseBackground = false, 1.112 + bool aUpdateNCArea = false, 1.113 + bool aIncludeChildren = false); 1.114 + NS_IMETHOD Invalidate(const nsIntRect & aRect); 1.115 + NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, 1.116 + nsEventStatus& aStatus); 1.117 + NS_IMETHOD ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY); 1.118 + NS_IMETHOD Move(double aX, double aY); 1.119 + NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint); 1.120 + NS_IMETHOD Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint); 1.121 + NS_IMETHOD SetFocus(bool aRaise); 1.122 + NS_IMETHOD Enable(bool aState); 1.123 + NS_IMETHOD SetCursor(nsCursor aCursor); 1.124 + NS_IMETHOD SetTitle(const nsAString& aTitle); 1.125 + NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, 1.126 + bool aDoCapture); 1.127 + NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); 1.128 + virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout, 1.129 + int32_t aNativeKeyCode, 1.130 + uint32_t aModifierFlags, 1.131 + const nsAString& aCharacters, 1.132 + const nsAString& aUnmodifiedCharacters); 1.133 + virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint, 1.134 + uint32_t aNativeMessage, 1.135 + uint32_t aModifierFlags); 1.136 + virtual nsresult SynthesizeNativeMouseScrollEvent(nsIntPoint aPoint, 1.137 + uint32_t aNativeMessage, 1.138 + double aDeltaX, 1.139 + double aDeltaY, 1.140 + double aDeltaZ, 1.141 + uint32_t aModifierFlags, 1.142 + uint32_t aAdditionalFlags); 1.143 + virtual bool HasPendingInputEvent(); 1.144 + virtual double GetDefaultScaleInternal(); 1.145 + float GetDPI(); 1.146 + mozilla::LayoutDeviceIntPoint CSSIntPointToLayoutDeviceIntPoint(const mozilla::CSSIntPoint &aCSSPoint); 1.147 + void ChangedDPI(); 1.148 + virtual uint32_t GetMaxTouchPoints() const MOZ_OVERRIDE; 1.149 + virtual bool IsVisible() const; 1.150 + virtual bool IsEnabled() const; 1.151 + // ShouldUseOffMainThreadCompositing is defined in base widget 1.152 + virtual bool ShouldUseOffMainThreadCompositing(); 1.153 + bool ShouldUseMainThreadD3D10Manager(); 1.154 + bool ShouldUseBasicManager(); 1.155 + bool ShouldUseAPZC(); 1.156 + virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr, 1.157 + LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, 1.158 + LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, 1.159 + bool* aAllowRetaining = nullptr); 1.160 + virtual void GetPreferredCompositorBackends(nsTArray<mozilla::layers::LayersBackend>& aHints) { aHints.AppendElement(mozilla::layers::LayersBackend::LAYERS_D3D11); } 1.161 + 1.162 + // IME related interfaces 1.163 + NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, 1.164 + const InputContextAction& aAction); 1.165 + NS_IMETHOD_(nsIWidget::InputContext) GetInputContext(); 1.166 + NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE; 1.167 + NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState); 1.168 + virtual nsIMEUpdatePreference GetIMEUpdatePreference() MOZ_OVERRIDE; 1.169 + 1.170 + // FrameworkView helpers 1.171 + void SizeModeChanged(); 1.172 + void Activated(bool aActiveated); 1.173 + void Paint(const nsIntRegion& aInvalidRegion); 1.174 + 1.175 + MetroWidget* MetroWidget::GetTopLevelWindow(bool aStopOnDialogOrPopup) { return this; } 1.176 + virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations); 1.177 + virtual void* GetNativeData(uint32_t aDataType); 1.178 + virtual void FreeNativeData(void * data, uint32_t aDataType); 1.179 + virtual nsIntPoint WidgetToScreenOffset(); 1.180 + 1.181 + already_AddRefed<nsIPresShell> GetPresShell(); 1.182 + 1.183 + void UserActivity(); 1.184 + 1.185 +#ifdef ACCESSIBILITY 1.186 + mozilla::a11y::Accessible* DispatchAccessibleEvent(uint32_t aEventType); 1.187 + mozilla::a11y::Accessible* GetAccessible(); 1.188 +#endif // ACCESSIBILITY 1.189 + 1.190 + // needed for current nsIFilePicker 1.191 + void PickerOpen(); 1.192 + void PickerClosed(); 1.193 + bool DestroyCalled() { return false; } 1.194 + void SuppressBlurEvents(bool aSuppress); 1.195 + bool BlurEventsSuppressed(); 1.196 + 1.197 + // needed for nsITaskbarWindowPreview 1.198 + bool HasTaskbarIconBeenCreated() { return false; } 1.199 + void SetHasTaskbarIconBeenCreated(bool created = true) { } 1.200 + already_AddRefed<nsITaskbarWindowPreview> GetTaskbarPreview() { return nullptr; } 1.201 + void SetTaskbarPreview(nsITaskbarWindowPreview *preview) { } 1.202 + WindowHook& GetWindowHook() { return mWindowHook; } 1.203 + 1.204 + void SetView(FrameworkView* aView); 1.205 + void FindMetroWindow(); 1.206 + virtual void SetTransparencyMode(nsTransparencyMode aMode); 1.207 + virtual nsTransparencyMode GetTransparencyMode(); 1.208 + 1.209 + TouchBehaviorFlags ContentGetAllowedTouchBehavior(const nsIntPoint& aPoint); 1.210 + 1.211 + // apzc controller related api 1.212 + void ApzcGetAllowedTouchBehavior(mozilla::WidgetInputEvent* aTransformedEvent, nsTArray<TouchBehaviorFlags>& aOutBehaviors); 1.213 + void ApzcSetAllowedTouchBehavior(const ScrollableLayerGuid& aGuid, nsTArray<TouchBehaviorFlags>& aBehaviors); 1.214 + 1.215 + // Hit test a point to see if an apzc would consume input there 1.216 + bool ApzHitTest(mozilla::ScreenIntPoint& pt); 1.217 + // Transforms a coord so that it properly targets gecko content based 1.218 + // on apzc transforms currently applied. 1.219 + void ApzTransformGeckoCoordinate(const mozilla::ScreenIntPoint& pt, 1.220 + mozilla::LayoutDeviceIntPoint* aRefPointOut); 1.221 + // send ContentRecievedTouch calls to the apz with appropriate preventDefault params 1.222 + void ApzContentConsumingTouch(const ScrollableLayerGuid& aGuid); 1.223 + void ApzContentIgnoringTouch(const ScrollableLayerGuid& aGuid); 1.224 + // Input handling 1.225 + nsEventStatus ApzReceiveInputEvent(mozilla::WidgetInputEvent* aEvent, 1.226 + ScrollableLayerGuid* aOutTargetGuid); 1.227 + 1.228 +protected: 1.229 + friend class FrameworkView; 1.230 + 1.231 + struct OleInitializeWrapper { 1.232 + HRESULT const hr; 1.233 + 1.234 + OleInitializeWrapper() 1.235 + : hr(::OleInitialize(nullptr)) 1.236 + { 1.237 + } 1.238 + 1.239 + ~OleInitializeWrapper() { 1.240 + if (SUCCEEDED(hr)) { 1.241 + ::OleFlushClipboard(); 1.242 + ::OleUninitialize(); 1.243 + } 1.244 + } 1.245 + }; 1.246 + 1.247 + void SetSubclass(); 1.248 + void RemoveSubclass(); 1.249 + nsIWidgetListener* GetPaintListener(); 1.250 + 1.251 + // Async event dispatching 1.252 + void DispatchAsyncScrollEvent(DispatchMsg* aEvent); 1.253 + void DeliverNextScrollEvent(); 1.254 + void DeliverNextKeyboardEvent(); 1.255 + 1.256 +protected: 1.257 + OleInitializeWrapper mOleInitializeWrapper; 1.258 + WindowHook mWindowHook; 1.259 + Microsoft::WRL::ComPtr<FrameworkView> mView; 1.260 + nsTransparencyMode mTransparencyMode; 1.261 + nsIntRegion mInvalidatedRegion; 1.262 + nsCOMPtr<nsIIdleServiceInternal> mIdleService; 1.263 + HWND mWnd; 1.264 + static HWND sICoreHwnd; 1.265 + WNDPROC mMetroWndProc; 1.266 + bool mTempBasicLayerInUse; 1.267 + uint64_t mRootLayerTreeId; 1.268 + nsDeque mEventQueue; 1.269 + nsDeque mKeyEventQueue; 1.270 + nsRefPtr<APZController> mController; 1.271 + nsRefPtr<nsNativeDragTarget> mNativeDragTarget; 1.272 +};