michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #pragma once michael@0: michael@0: #include "nscore.h" michael@0: #include "nsdefs.h" michael@0: #include "prlog.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsBaseWidget.h" michael@0: #include "nsWindowBase.h" michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: #include "nsWindowDbg.h" michael@0: #include "WindowHook.h" michael@0: #include "TaskbarWindowPreview.h" michael@0: #include "nsIdleService.h" michael@0: #ifdef ACCESSIBILITY michael@0: #include "mozilla/a11y/Accessible.h" michael@0: #endif michael@0: #include "mozilla/EventForwards.h" michael@0: #include "mozilla/layers/CompositorParent.h" michael@0: #include "mozilla/layers/LayerManagerComposite.h" michael@0: #include "nsDeque.h" michael@0: #include "APZController.h" michael@0: michael@0: #include "mozwrlbase.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: class nsNativeDragTarget; michael@0: michael@0: namespace mozilla { michael@0: namespace widget { michael@0: namespace winrt { michael@0: michael@0: class FrameworkView; michael@0: michael@0: } } } michael@0: michael@0: class DispatchMsg; michael@0: michael@0: class MetroWidget : public nsWindowBase, michael@0: public nsIObserver michael@0: { michael@0: typedef uint32_t TouchBehaviorFlags; michael@0: michael@0: typedef mozilla::widget::WindowHook WindowHook; michael@0: typedef mozilla::widget::TaskbarWindowPreview TaskbarWindowPreview; michael@0: typedef ABI::Windows::UI::Input::IPointerPoint IPointerPoint; michael@0: typedef ABI::Windows::UI::Core::IPointerEventArgs IPointerEventArgs; michael@0: typedef ABI::Windows::UI::Core::IKeyEventArgs IKeyEventArgs; michael@0: typedef ABI::Windows::UI::Core::ICharacterReceivedEventArgs ICharacterReceivedEventArgs; michael@0: typedef mozilla::widget::winrt::FrameworkView FrameworkView; michael@0: typedef mozilla::widget::winrt::APZController APZController; michael@0: typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid; michael@0: michael@0: static LRESULT CALLBACK michael@0: StaticWindowProcedure(HWND aWnd, UINT aMsg, WPARAM aWParan, LPARAM aLParam); michael@0: LRESULT WindowProcedure(HWND aWnd, UINT aMsg, WPARAM aWParan, LPARAM aLParam); michael@0: michael@0: public: michael@0: MetroWidget(); michael@0: virtual ~MetroWidget(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: static HWND GetICoreWindowHWND() { return sICoreHwnd; } michael@0: michael@0: // nsWindowBase michael@0: virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE; michael@0: virtual bool DispatchKeyboardEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE; michael@0: virtual bool DispatchScrollEvent(mozilla::WidgetGUIEvent* aEvent) MOZ_OVERRIDE; michael@0: virtual bool DispatchPluginEvent(const MSG &aMsg) MOZ_OVERRIDE { return false; } michael@0: virtual bool IsTopLevelWidget() MOZ_OVERRIDE { return true; } michael@0: virtual nsWindowBase* GetParentWindowBase(bool aIncludeOwner) MOZ_OVERRIDE { return nullptr; } michael@0: // InitEvent assumes physical coordinates and is used by shared win32 code. Do michael@0: // not hand winrt event coordinates to this routine. michael@0: virtual void InitEvent(mozilla::WidgetGUIEvent& aEvent, michael@0: nsIntPoint* aPoint = nullptr) MOZ_OVERRIDE; michael@0: michael@0: // nsBaseWidget michael@0: virtual CompositorParent* NewCompositorParent(int aSurfaceWidth, int aSurfaceHeight); michael@0: virtual void SetWidgetListener(nsIWidgetListener* aWidgetListener); michael@0: michael@0: // nsIWidget interface michael@0: NS_IMETHOD Create(nsIWidget *aParent, michael@0: nsNativeWidget aNativeParent, michael@0: const nsIntRect &aRect, michael@0: nsDeviceContext *aContext, michael@0: nsWidgetInitData *aInitData = nullptr); michael@0: NS_IMETHOD Destroy(); michael@0: NS_IMETHOD EnableDragDrop(bool aEnable); michael@0: NS_IMETHOD SetParent(nsIWidget *aNewParent); michael@0: NS_IMETHOD Show(bool bState); michael@0: NS_IMETHOD IsVisible(bool & aState); michael@0: NS_IMETHOD IsEnabled(bool *aState); michael@0: NS_IMETHOD GetBounds(nsIntRect &aRect); michael@0: NS_IMETHOD GetScreenBounds(nsIntRect &aRect); michael@0: NS_IMETHOD GetClientBounds(nsIntRect &aRect); michael@0: NS_IMETHOD Invalidate(bool aEraseBackground = false, michael@0: bool aUpdateNCArea = false, michael@0: bool aIncludeChildren = false); michael@0: NS_IMETHOD Invalidate(const nsIntRect & aRect); michael@0: NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus& aStatus); michael@0: NS_IMETHOD ConstrainPosition(bool aAllowSlop, int32_t *aX, int32_t *aY); michael@0: NS_IMETHOD Move(double aX, double aY); michael@0: NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint); michael@0: NS_IMETHOD Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint); michael@0: NS_IMETHOD SetFocus(bool aRaise); michael@0: NS_IMETHOD Enable(bool aState); michael@0: NS_IMETHOD SetCursor(nsCursor aCursor); michael@0: NS_IMETHOD SetTitle(const nsAString& aTitle); michael@0: NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, michael@0: bool aDoCapture); michael@0: NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent); michael@0: virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout, michael@0: int32_t aNativeKeyCode, michael@0: uint32_t aModifierFlags, michael@0: const nsAString& aCharacters, michael@0: const nsAString& aUnmodifiedCharacters); michael@0: virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint, michael@0: uint32_t aNativeMessage, michael@0: uint32_t aModifierFlags); michael@0: virtual nsresult SynthesizeNativeMouseScrollEvent(nsIntPoint aPoint, michael@0: uint32_t aNativeMessage, michael@0: double aDeltaX, michael@0: double aDeltaY, michael@0: double aDeltaZ, michael@0: uint32_t aModifierFlags, michael@0: uint32_t aAdditionalFlags); michael@0: virtual bool HasPendingInputEvent(); michael@0: virtual double GetDefaultScaleInternal(); michael@0: float GetDPI(); michael@0: mozilla::LayoutDeviceIntPoint CSSIntPointToLayoutDeviceIntPoint(const mozilla::CSSIntPoint &aCSSPoint); michael@0: void ChangedDPI(); michael@0: virtual uint32_t GetMaxTouchPoints() const MOZ_OVERRIDE; michael@0: virtual bool IsVisible() const; michael@0: virtual bool IsEnabled() const; michael@0: // ShouldUseOffMainThreadCompositing is defined in base widget michael@0: virtual bool ShouldUseOffMainThreadCompositing(); michael@0: bool ShouldUseMainThreadD3D10Manager(); michael@0: bool ShouldUseBasicManager(); michael@0: bool ShouldUseAPZC(); michael@0: virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr, michael@0: LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, michael@0: LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, michael@0: bool* aAllowRetaining = nullptr); michael@0: virtual void GetPreferredCompositorBackends(nsTArray& aHints) { aHints.AppendElement(mozilla::layers::LayersBackend::LAYERS_D3D11); } michael@0: michael@0: // IME related interfaces michael@0: NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, michael@0: const InputContextAction& aAction); michael@0: NS_IMETHOD_(nsIWidget::InputContext) GetInputContext(); michael@0: NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState); michael@0: virtual nsIMEUpdatePreference GetIMEUpdatePreference() MOZ_OVERRIDE; michael@0: michael@0: // FrameworkView helpers michael@0: void SizeModeChanged(); michael@0: void Activated(bool aActiveated); michael@0: void Paint(const nsIntRegion& aInvalidRegion); michael@0: michael@0: MetroWidget* MetroWidget::GetTopLevelWindow(bool aStopOnDialogOrPopup) { return this; } michael@0: virtual nsresult ConfigureChildren(const nsTArray& aConfigurations); michael@0: virtual void* GetNativeData(uint32_t aDataType); michael@0: virtual void FreeNativeData(void * data, uint32_t aDataType); michael@0: virtual nsIntPoint WidgetToScreenOffset(); michael@0: michael@0: already_AddRefed GetPresShell(); michael@0: michael@0: void UserActivity(); michael@0: michael@0: #ifdef ACCESSIBILITY michael@0: mozilla::a11y::Accessible* DispatchAccessibleEvent(uint32_t aEventType); michael@0: mozilla::a11y::Accessible* GetAccessible(); michael@0: #endif // ACCESSIBILITY michael@0: michael@0: // needed for current nsIFilePicker michael@0: void PickerOpen(); michael@0: void PickerClosed(); michael@0: bool DestroyCalled() { return false; } michael@0: void SuppressBlurEvents(bool aSuppress); michael@0: bool BlurEventsSuppressed(); michael@0: michael@0: // needed for nsITaskbarWindowPreview michael@0: bool HasTaskbarIconBeenCreated() { return false; } michael@0: void SetHasTaskbarIconBeenCreated(bool created = true) { } michael@0: already_AddRefed GetTaskbarPreview() { return nullptr; } michael@0: void SetTaskbarPreview(nsITaskbarWindowPreview *preview) { } michael@0: WindowHook& GetWindowHook() { return mWindowHook; } michael@0: michael@0: void SetView(FrameworkView* aView); michael@0: void FindMetroWindow(); michael@0: virtual void SetTransparencyMode(nsTransparencyMode aMode); michael@0: virtual nsTransparencyMode GetTransparencyMode(); michael@0: michael@0: TouchBehaviorFlags ContentGetAllowedTouchBehavior(const nsIntPoint& aPoint); michael@0: michael@0: // apzc controller related api michael@0: void ApzcGetAllowedTouchBehavior(mozilla::WidgetInputEvent* aTransformedEvent, nsTArray& aOutBehaviors); michael@0: void ApzcSetAllowedTouchBehavior(const ScrollableLayerGuid& aGuid, nsTArray& aBehaviors); michael@0: michael@0: // Hit test a point to see if an apzc would consume input there michael@0: bool ApzHitTest(mozilla::ScreenIntPoint& pt); michael@0: // Transforms a coord so that it properly targets gecko content based michael@0: // on apzc transforms currently applied. michael@0: void ApzTransformGeckoCoordinate(const mozilla::ScreenIntPoint& pt, michael@0: mozilla::LayoutDeviceIntPoint* aRefPointOut); michael@0: // send ContentRecievedTouch calls to the apz with appropriate preventDefault params michael@0: void ApzContentConsumingTouch(const ScrollableLayerGuid& aGuid); michael@0: void ApzContentIgnoringTouch(const ScrollableLayerGuid& aGuid); michael@0: // Input handling michael@0: nsEventStatus ApzReceiveInputEvent(mozilla::WidgetInputEvent* aEvent, michael@0: ScrollableLayerGuid* aOutTargetGuid); michael@0: michael@0: protected: michael@0: friend class FrameworkView; michael@0: michael@0: struct OleInitializeWrapper { michael@0: HRESULT const hr; michael@0: michael@0: OleInitializeWrapper() michael@0: : hr(::OleInitialize(nullptr)) michael@0: { michael@0: } michael@0: michael@0: ~OleInitializeWrapper() { michael@0: if (SUCCEEDED(hr)) { michael@0: ::OleFlushClipboard(); michael@0: ::OleUninitialize(); michael@0: } michael@0: } michael@0: }; michael@0: michael@0: void SetSubclass(); michael@0: void RemoveSubclass(); michael@0: nsIWidgetListener* GetPaintListener(); michael@0: michael@0: // Async event dispatching michael@0: void DispatchAsyncScrollEvent(DispatchMsg* aEvent); michael@0: void DeliverNextScrollEvent(); michael@0: void DeliverNextKeyboardEvent(); michael@0: michael@0: protected: michael@0: OleInitializeWrapper mOleInitializeWrapper; michael@0: WindowHook mWindowHook; michael@0: Microsoft::WRL::ComPtr mView; michael@0: nsTransparencyMode mTransparencyMode; michael@0: nsIntRegion mInvalidatedRegion; michael@0: nsCOMPtr mIdleService; michael@0: HWND mWnd; michael@0: static HWND sICoreHwnd; michael@0: WNDPROC mMetroWndProc; michael@0: bool mTempBasicLayerInUse; michael@0: uint64_t mRootLayerTreeId; michael@0: nsDeque mEventQueue; michael@0: nsDeque mKeyEventQueue; michael@0: nsRefPtr mController; michael@0: nsRefPtr mNativeDragTarget; michael@0: };