1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/windows/winrt/FrameworkView.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,205 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; 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 "MetroWidget.h" 1.12 +#include "MetroInput.h" 1.13 +#include "gfxWindowsPlatform.h" 1.14 +#include "nsDataHashtable.h" 1.15 + 1.16 +#include "mozwrlbase.h" 1.17 + 1.18 +#include <windows.system.h> 1.19 +#include <Windows.ApplicationModel.core.h> 1.20 +#include <Windows.ApplicationModel.h> 1.21 +#include <Windows.Applicationmodel.Activation.h> 1.22 +#include <Windows.ApplicationModel.search.h> 1.23 +#include <windows.ui.core.h> 1.24 +#include <windows.ui.viewmanagement.h> 1.25 +#include <windows.ui.applicationsettings.h> 1.26 +#include <windows.ui.popups.h> 1.27 +#include <windows.graphics.printing.h> 1.28 +#include <windows.graphics.display.h> 1.29 +#include <windows.media.playto.h> 1.30 +#include <d2d1_1.h> 1.31 + 1.32 +namespace mozilla { 1.33 +namespace widget { 1.34 +namespace winrt { 1.35 + 1.36 +class MetroApp; 1.37 + 1.38 +class FrameworkView : public Microsoft::WRL::RuntimeClass<ABI::Windows::ApplicationModel::Core::IFrameworkView> 1.39 +{ 1.40 + InspectableClass(L"FrameworkView", TrustLevel::BaseTrust) 1.41 + 1.42 + typedef mozilla::layers::LayerManager LayerManager; 1.43 + 1.44 + typedef ABI::Windows::Foundation::Rect Rect; 1.45 + typedef ABI::Windows::UI::Core::IWindowSizeChangedEventArgs IWindowSizeChangedEventArgs; 1.46 + typedef ABI::Windows::UI::Core::ICoreWindowEventArgs ICoreWindowEventArgs; 1.47 + typedef ABI::Windows::UI::Core::IWindowActivatedEventArgs IWindowActivatedEventArgs; 1.48 + typedef ABI::Windows::UI::Core::IAutomationProviderRequestedEventArgs IAutomationProviderRequestedEventArgs; 1.49 + typedef ABI::Windows::UI::Core::ICoreWindow ICoreWindow; 1.50 + typedef ABI::Windows::UI::Core::ICoreDispatcher ICoreDispatcher; 1.51 + typedef ABI::Windows::UI::Core::IVisibilityChangedEventArgs IVisibilityChangedEventArgs; 1.52 + typedef ABI::Windows::UI::ViewManagement::IInputPaneVisibilityEventArgs IInputPaneVisibilityEventArgs; 1.53 + typedef ABI::Windows::UI::ViewManagement::IInputPane IInputPane; 1.54 + typedef ABI::Windows::UI::ViewManagement::ApplicationViewState ApplicationViewState; 1.55 + typedef ABI::Windows::UI::ApplicationSettings::ISettingsPane ISettingsPane; 1.56 + typedef ABI::Windows::UI::ApplicationSettings::ISettingsPaneCommandsRequestedEventArgs ISettingsPaneCommandsRequestedEventArgs; 1.57 + typedef ABI::Windows::UI::Popups::IUICommand IUICommand; 1.58 + typedef ABI::Windows::ApplicationModel::Activation::ILaunchActivatedEventArgs ILaunchActivatedEventArgs; 1.59 + typedef ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs IActivatedEventArgs; 1.60 + typedef ABI::Windows::ApplicationModel::Activation::ISearchActivatedEventArgs ISearchActivatedEventArgs; 1.61 + typedef ABI::Windows::ApplicationModel::Activation::IFileActivatedEventArgs IFileActivatedEventArgs; 1.62 + typedef ABI::Windows::ApplicationModel::Core::ICoreApplicationView ICoreApplicationView; 1.63 + typedef ABI::Windows::ApplicationModel::DataTransfer::IDataTransferManager IDataTransferManager; 1.64 + typedef ABI::Windows::ApplicationModel::DataTransfer::IDataRequestedEventArgs IDataRequestedEventArgs; 1.65 + typedef ABI::Windows::ApplicationModel::Search::ISearchPane ISearchPane; 1.66 + typedef ABI::Windows::ApplicationModel::Search::ISearchPaneQuerySubmittedEventArgs ISearchPaneQuerySubmittedEventArgs; 1.67 + typedef ABI::Windows::Media::PlayTo::IPlayToManager IPlayToManager; 1.68 + typedef ABI::Windows::Media::PlayTo::IPlayToSourceRequestedEventArgs IPlayToSourceRequestedEventArgs; 1.69 + typedef ABI::Windows::Graphics::Printing::IPrintManager IPrintManager; 1.70 + typedef ABI::Windows::Graphics::Printing::IPrintTaskRequestedEventArgs IPrintTaskRequestedEventArgs; 1.71 + typedef ABI::Windows::Graphics::Printing::IPrintTaskSourceRequestedArgs IPrintTaskSourceRequestedArgs; 1.72 + 1.73 +public: 1.74 + FrameworkView(MetroApp* aMetroApp); 1.75 + 1.76 + // IFrameworkView Methods 1.77 + STDMETHODIMP Initialize(ICoreApplicationView* aAppView); 1.78 + STDMETHODIMP SetWindow(ICoreWindow* aWindow); 1.79 + STDMETHODIMP Load(HSTRING aEntryPoint); 1.80 + STDMETHODIMP Run(); 1.81 + STDMETHODIMP Uninitialize(); 1.82 + 1.83 + HRESULT ActivateView(); 1.84 + 1.85 + // Public apis for MetroWidget 1.86 + float GetDPI() { return mDPI; } 1.87 + ICoreWindow* GetCoreWindow() { return mWindow.Get(); } 1.88 + void SetWidget(MetroWidget* aWidget); 1.89 + MetroWidget* GetWidget() { return mWidget.Get(); } 1.90 + void GetBounds(nsIntRect &aRect); 1.91 + void SetCursor(ABI::Windows::UI::Core::CoreCursorType aCursorType, DWORD aCustomId = 0); 1.92 + void ClearCursor(); 1.93 + bool IsEnabled() const; 1.94 + bool IsVisible() const; 1.95 + 1.96 + // Activation apis for nsIWinMetroUtils 1.97 + static int GetPreviousExecutionState() { return sPreviousExecutionState; } 1.98 + static void GetActivationURI(nsAString &aActivationURI) { 1.99 + unsigned int length; 1.100 + aActivationURI = WindowsGetStringRawBuffer(sActivationURI, &length); 1.101 + } 1.102 + 1.103 + // Soft keyboard info for nsIWinMetroUtils 1.104 + static bool IsKeyboardVisible() { return sKeyboardIsVisible; } 1.105 + static ABI::Windows::Foundation::Rect KeyboardVisibleRect() { return sKeyboardRect; } 1.106 + 1.107 + // MetroApp apis 1.108 + void SetupContracts(); 1.109 + void Shutdown(); 1.110 + 1.111 + // MetroContracts settings panel enumerator entry 1.112 + void AddSetting(ISettingsPaneCommandsRequestedEventArgs* aArgs, uint32_t aId, 1.113 + Microsoft::WRL::Wrappers::HString& aSettingName); 1.114 +protected: 1.115 + // Event Handlers 1.116 + HRESULT OnActivated(ICoreApplicationView* aApplicationView, 1.117 + IActivatedEventArgs* aArgs); 1.118 + HRESULT OnWindowVisibilityChanged(ICoreWindow* aCoreWindow, 1.119 + IVisibilityChangedEventArgs* aArgs); 1.120 + 1.121 + HRESULT OnWindowSizeChanged(ICoreWindow* aSender, 1.122 + IWindowSizeChangedEventArgs* aArgs); 1.123 + HRESULT OnWindowActivated(ICoreWindow* aSender, 1.124 + IWindowActivatedEventArgs* aArgs); 1.125 + HRESULT OnLogicalDpiChanged(IInspectable* aSender); 1.126 + 1.127 + HRESULT OnAutomationProviderRequested(ICoreWindow* aSender, 1.128 + IAutomationProviderRequestedEventArgs* aArgs); 1.129 + 1.130 + HRESULT OnSoftkeyboardHidden(IInputPane* aSender, 1.131 + IInputPaneVisibilityEventArgs* aArgs); 1.132 + HRESULT OnSoftkeyboardShown(IInputPane* aSender, 1.133 + IInputPaneVisibilityEventArgs* aArgs); 1.134 + 1.135 + HRESULT OnDataShareRequested(IDataTransferManager*, IDataRequestedEventArgs* aArgs); 1.136 + HRESULT OnSearchQuerySubmitted(ISearchPane* aPane, ISearchPaneQuerySubmittedEventArgs* aArgs); 1.137 + HRESULT OnSettingsCommandsRequested(ISettingsPane* aPane, ISettingsPaneCommandsRequestedEventArgs* aArgs); 1.138 + HRESULT OnPlayToSourceRequested(IPlayToManager* aPane, IPlayToSourceRequestedEventArgs* aArgs); 1.139 + HRESULT OnSettingsCommandInvoked(IUICommand* aCommand); 1.140 + HRESULT OnPrintTaskRequested(IPrintManager* aMgr, IPrintTaskRequestedEventArgs* aArgs); 1.141 + HRESULT OnPrintTaskSourceRequested(IPrintTaskSourceRequestedArgs* aArgs); 1.142 + 1.143 +protected: 1.144 + void SetDpi(float aDpi); 1.145 + void UpdateWidgetSizeAndPosition(); 1.146 + void PerformURILoad(Microsoft::WRL::Wrappers::HString& aString); 1.147 + void PerformSearch(Microsoft::WRL::Wrappers::HString& aQuery); 1.148 + void PerformURILoadOrSearch(Microsoft::WRL::Wrappers::HString& aString); 1.149 + bool EnsureAutomationProviderCreated(); 1.150 + void SearchActivated(Microsoft::WRL::ComPtr<ISearchActivatedEventArgs>& aArgs, bool aStartup); 1.151 + void FileActivated(Microsoft::WRL::ComPtr<IFileActivatedEventArgs>& aArgs, bool aStartup); 1.152 + void LaunchActivated(Microsoft::WRL::ComPtr<ILaunchActivatedEventArgs>& aArgs, bool aStartup); 1.153 + void ProcessActivationArgs(IActivatedEventArgs* aArgs, bool aStartup); 1.154 + void UpdateForWindowSizeChange(); 1.155 + void SendActivationEvent(); 1.156 + void UpdateLogicalDPI(); 1.157 + void FireViewStateObservers(); 1.158 + void ProcessLaunchArguments(); 1.159 + void UpdateBounds(); 1.160 + 1.161 + // Printing and preview 1.162 + void CreatePrintControl(IPrintDocumentPackageTarget* aDocPackageTarget, 1.163 + D2D1_PRINT_CONTROL_PROPERTIES* aPrintControlProperties); 1.164 + HRESULT ClosePrintControl(); 1.165 + void PrintPage(uint32_t aPageNumber, D2D1_RECT_F aImageableArea, 1.166 + D2D1_SIZE_F aPageSize, IStream* aPagePrintTicketStream); 1.167 + void AddEventHandlers(); 1.168 + 1.169 +private: 1.170 + EventRegistrationToken mActivated; 1.171 + EventRegistrationToken mWindowActivated; 1.172 + EventRegistrationToken mWindowVisibilityChanged; 1.173 + EventRegistrationToken mWindowClosed; 1.174 + EventRegistrationToken mWindowSizeChanged; 1.175 + EventRegistrationToken mSoftKeyboardHidden; 1.176 + EventRegistrationToken mSoftKeyboardShown; 1.177 + EventRegistrationToken mDisplayPropertiesChanged; 1.178 + EventRegistrationToken mAutomationProviderRequested; 1.179 + EventRegistrationToken mDataTransferRequested; 1.180 + EventRegistrationToken mSearchQuerySubmitted; 1.181 + EventRegistrationToken mPlayToRequested; 1.182 + EventRegistrationToken mSettingsPane; 1.183 + EventRegistrationToken mPrintManager; 1.184 + 1.185 +private: 1.186 + nsIntRect mWindowBounds; // in device-pixel coordinates 1.187 + float mDPI; 1.188 + bool mShuttingDown; 1.189 + nsAutoString mActivationCommandLine; 1.190 + Microsoft::WRL::ComPtr<IInspectable> mAutomationProvider; 1.191 + //Microsoft::WRL::ComPtr<ID2D1PrintControl> mD2DPrintControl; 1.192 + // Private critical section protects D2D device context for on-screen 1.193 + // rendering from that for print/preview in the different thread. 1.194 + //Microsoft::WRL::ComPtr<IWICImagingFactory2> mWicFactory; 1.195 + Microsoft::WRL::ComPtr<MetroApp> mMetroApp; 1.196 + Microsoft::WRL::ComPtr<ICoreWindow> mWindow; 1.197 + Microsoft::WRL::ComPtr<MetroWidget> mWidget; 1.198 + Microsoft::WRL::ComPtr<MetroInput> mMetroInput; 1.199 + bool mWinVisible; 1.200 + bool mWinActiveState; 1.201 + 1.202 + static bool sKeyboardIsVisible; 1.203 + static Rect sKeyboardRect; 1.204 + static HSTRING sActivationURI; 1.205 + static ABI::Windows::ApplicationModel::Activation::ApplicationExecutionState sPreviousExecutionState; 1.206 +}; 1.207 + 1.208 +} } }