michael@0: /* -*- Mode: C++; tab-width: 4; 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 "MetroWidget.h" michael@0: #include "MetroInput.h" michael@0: #include "gfxWindowsPlatform.h" michael@0: #include "nsDataHashtable.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: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace widget { michael@0: namespace winrt { michael@0: michael@0: class MetroApp; michael@0: michael@0: class FrameworkView : public Microsoft::WRL::RuntimeClass michael@0: { michael@0: InspectableClass(L"FrameworkView", TrustLevel::BaseTrust) michael@0: michael@0: typedef mozilla::layers::LayerManager LayerManager; michael@0: michael@0: typedef ABI::Windows::Foundation::Rect Rect; michael@0: typedef ABI::Windows::UI::Core::IWindowSizeChangedEventArgs IWindowSizeChangedEventArgs; michael@0: typedef ABI::Windows::UI::Core::ICoreWindowEventArgs ICoreWindowEventArgs; michael@0: typedef ABI::Windows::UI::Core::IWindowActivatedEventArgs IWindowActivatedEventArgs; michael@0: typedef ABI::Windows::UI::Core::IAutomationProviderRequestedEventArgs IAutomationProviderRequestedEventArgs; michael@0: typedef ABI::Windows::UI::Core::ICoreWindow ICoreWindow; michael@0: typedef ABI::Windows::UI::Core::ICoreDispatcher ICoreDispatcher; michael@0: typedef ABI::Windows::UI::Core::IVisibilityChangedEventArgs IVisibilityChangedEventArgs; michael@0: typedef ABI::Windows::UI::ViewManagement::IInputPaneVisibilityEventArgs IInputPaneVisibilityEventArgs; michael@0: typedef ABI::Windows::UI::ViewManagement::IInputPane IInputPane; michael@0: typedef ABI::Windows::UI::ViewManagement::ApplicationViewState ApplicationViewState; michael@0: typedef ABI::Windows::UI::ApplicationSettings::ISettingsPane ISettingsPane; michael@0: typedef ABI::Windows::UI::ApplicationSettings::ISettingsPaneCommandsRequestedEventArgs ISettingsPaneCommandsRequestedEventArgs; michael@0: typedef ABI::Windows::UI::Popups::IUICommand IUICommand; michael@0: typedef ABI::Windows::ApplicationModel::Activation::ILaunchActivatedEventArgs ILaunchActivatedEventArgs; michael@0: typedef ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs IActivatedEventArgs; michael@0: typedef ABI::Windows::ApplicationModel::Activation::ISearchActivatedEventArgs ISearchActivatedEventArgs; michael@0: typedef ABI::Windows::ApplicationModel::Activation::IFileActivatedEventArgs IFileActivatedEventArgs; michael@0: typedef ABI::Windows::ApplicationModel::Core::ICoreApplicationView ICoreApplicationView; michael@0: typedef ABI::Windows::ApplicationModel::DataTransfer::IDataTransferManager IDataTransferManager; michael@0: typedef ABI::Windows::ApplicationModel::DataTransfer::IDataRequestedEventArgs IDataRequestedEventArgs; michael@0: typedef ABI::Windows::ApplicationModel::Search::ISearchPane ISearchPane; michael@0: typedef ABI::Windows::ApplicationModel::Search::ISearchPaneQuerySubmittedEventArgs ISearchPaneQuerySubmittedEventArgs; michael@0: typedef ABI::Windows::Media::PlayTo::IPlayToManager IPlayToManager; michael@0: typedef ABI::Windows::Media::PlayTo::IPlayToSourceRequestedEventArgs IPlayToSourceRequestedEventArgs; michael@0: typedef ABI::Windows::Graphics::Printing::IPrintManager IPrintManager; michael@0: typedef ABI::Windows::Graphics::Printing::IPrintTaskRequestedEventArgs IPrintTaskRequestedEventArgs; michael@0: typedef ABI::Windows::Graphics::Printing::IPrintTaskSourceRequestedArgs IPrintTaskSourceRequestedArgs; michael@0: michael@0: public: michael@0: FrameworkView(MetroApp* aMetroApp); michael@0: michael@0: // IFrameworkView Methods michael@0: STDMETHODIMP Initialize(ICoreApplicationView* aAppView); michael@0: STDMETHODIMP SetWindow(ICoreWindow* aWindow); michael@0: STDMETHODIMP Load(HSTRING aEntryPoint); michael@0: STDMETHODIMP Run(); michael@0: STDMETHODIMP Uninitialize(); michael@0: michael@0: HRESULT ActivateView(); michael@0: michael@0: // Public apis for MetroWidget michael@0: float GetDPI() { return mDPI; } michael@0: ICoreWindow* GetCoreWindow() { return mWindow.Get(); } michael@0: void SetWidget(MetroWidget* aWidget); michael@0: MetroWidget* GetWidget() { return mWidget.Get(); } michael@0: void GetBounds(nsIntRect &aRect); michael@0: void SetCursor(ABI::Windows::UI::Core::CoreCursorType aCursorType, DWORD aCustomId = 0); michael@0: void ClearCursor(); michael@0: bool IsEnabled() const; michael@0: bool IsVisible() const; michael@0: michael@0: // Activation apis for nsIWinMetroUtils michael@0: static int GetPreviousExecutionState() { return sPreviousExecutionState; } michael@0: static void GetActivationURI(nsAString &aActivationURI) { michael@0: unsigned int length; michael@0: aActivationURI = WindowsGetStringRawBuffer(sActivationURI, &length); michael@0: } michael@0: michael@0: // Soft keyboard info for nsIWinMetroUtils michael@0: static bool IsKeyboardVisible() { return sKeyboardIsVisible; } michael@0: static ABI::Windows::Foundation::Rect KeyboardVisibleRect() { return sKeyboardRect; } michael@0: michael@0: // MetroApp apis michael@0: void SetupContracts(); michael@0: void Shutdown(); michael@0: michael@0: // MetroContracts settings panel enumerator entry michael@0: void AddSetting(ISettingsPaneCommandsRequestedEventArgs* aArgs, uint32_t aId, michael@0: Microsoft::WRL::Wrappers::HString& aSettingName); michael@0: protected: michael@0: // Event Handlers michael@0: HRESULT OnActivated(ICoreApplicationView* aApplicationView, michael@0: IActivatedEventArgs* aArgs); michael@0: HRESULT OnWindowVisibilityChanged(ICoreWindow* aCoreWindow, michael@0: IVisibilityChangedEventArgs* aArgs); michael@0: michael@0: HRESULT OnWindowSizeChanged(ICoreWindow* aSender, michael@0: IWindowSizeChangedEventArgs* aArgs); michael@0: HRESULT OnWindowActivated(ICoreWindow* aSender, michael@0: IWindowActivatedEventArgs* aArgs); michael@0: HRESULT OnLogicalDpiChanged(IInspectable* aSender); michael@0: michael@0: HRESULT OnAutomationProviderRequested(ICoreWindow* aSender, michael@0: IAutomationProviderRequestedEventArgs* aArgs); michael@0: michael@0: HRESULT OnSoftkeyboardHidden(IInputPane* aSender, michael@0: IInputPaneVisibilityEventArgs* aArgs); michael@0: HRESULT OnSoftkeyboardShown(IInputPane* aSender, michael@0: IInputPaneVisibilityEventArgs* aArgs); michael@0: michael@0: HRESULT OnDataShareRequested(IDataTransferManager*, IDataRequestedEventArgs* aArgs); michael@0: HRESULT OnSearchQuerySubmitted(ISearchPane* aPane, ISearchPaneQuerySubmittedEventArgs* aArgs); michael@0: HRESULT OnSettingsCommandsRequested(ISettingsPane* aPane, ISettingsPaneCommandsRequestedEventArgs* aArgs); michael@0: HRESULT OnPlayToSourceRequested(IPlayToManager* aPane, IPlayToSourceRequestedEventArgs* aArgs); michael@0: HRESULT OnSettingsCommandInvoked(IUICommand* aCommand); michael@0: HRESULT OnPrintTaskRequested(IPrintManager* aMgr, IPrintTaskRequestedEventArgs* aArgs); michael@0: HRESULT OnPrintTaskSourceRequested(IPrintTaskSourceRequestedArgs* aArgs); michael@0: michael@0: protected: michael@0: void SetDpi(float aDpi); michael@0: void UpdateWidgetSizeAndPosition(); michael@0: void PerformURILoad(Microsoft::WRL::Wrappers::HString& aString); michael@0: void PerformSearch(Microsoft::WRL::Wrappers::HString& aQuery); michael@0: void PerformURILoadOrSearch(Microsoft::WRL::Wrappers::HString& aString); michael@0: bool EnsureAutomationProviderCreated(); michael@0: void SearchActivated(Microsoft::WRL::ComPtr& aArgs, bool aStartup); michael@0: void FileActivated(Microsoft::WRL::ComPtr& aArgs, bool aStartup); michael@0: void LaunchActivated(Microsoft::WRL::ComPtr& aArgs, bool aStartup); michael@0: void ProcessActivationArgs(IActivatedEventArgs* aArgs, bool aStartup); michael@0: void UpdateForWindowSizeChange(); michael@0: void SendActivationEvent(); michael@0: void UpdateLogicalDPI(); michael@0: void FireViewStateObservers(); michael@0: void ProcessLaunchArguments(); michael@0: void UpdateBounds(); michael@0: michael@0: // Printing and preview michael@0: void CreatePrintControl(IPrintDocumentPackageTarget* aDocPackageTarget, michael@0: D2D1_PRINT_CONTROL_PROPERTIES* aPrintControlProperties); michael@0: HRESULT ClosePrintControl(); michael@0: void PrintPage(uint32_t aPageNumber, D2D1_RECT_F aImageableArea, michael@0: D2D1_SIZE_F aPageSize, IStream* aPagePrintTicketStream); michael@0: void AddEventHandlers(); michael@0: michael@0: private: michael@0: EventRegistrationToken mActivated; michael@0: EventRegistrationToken mWindowActivated; michael@0: EventRegistrationToken mWindowVisibilityChanged; michael@0: EventRegistrationToken mWindowClosed; michael@0: EventRegistrationToken mWindowSizeChanged; michael@0: EventRegistrationToken mSoftKeyboardHidden; michael@0: EventRegistrationToken mSoftKeyboardShown; michael@0: EventRegistrationToken mDisplayPropertiesChanged; michael@0: EventRegistrationToken mAutomationProviderRequested; michael@0: EventRegistrationToken mDataTransferRequested; michael@0: EventRegistrationToken mSearchQuerySubmitted; michael@0: EventRegistrationToken mPlayToRequested; michael@0: EventRegistrationToken mSettingsPane; michael@0: EventRegistrationToken mPrintManager; michael@0: michael@0: private: michael@0: nsIntRect mWindowBounds; // in device-pixel coordinates michael@0: float mDPI; michael@0: bool mShuttingDown; michael@0: nsAutoString mActivationCommandLine; michael@0: Microsoft::WRL::ComPtr mAutomationProvider; michael@0: //Microsoft::WRL::ComPtr mD2DPrintControl; michael@0: // Private critical section protects D2D device context for on-screen michael@0: // rendering from that for print/preview in the different thread. michael@0: //Microsoft::WRL::ComPtr mWicFactory; michael@0: Microsoft::WRL::ComPtr mMetroApp; michael@0: Microsoft::WRL::ComPtr mWindow; michael@0: Microsoft::WRL::ComPtr mWidget; michael@0: Microsoft::WRL::ComPtr mMetroInput; michael@0: bool mWinVisible; michael@0: bool mWinActiveState; michael@0: michael@0: static bool sKeyboardIsVisible; michael@0: static Rect sKeyboardRect; michael@0: static HSTRING sActivationURI; michael@0: static ABI::Windows::ApplicationModel::Activation::ApplicationExecutionState sPreviousExecutionState; michael@0: }; michael@0: michael@0: } } }