Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #pragma once
8 #include "MetroWidget.h"
9 #include "MetroInput.h"
10 #include "gfxWindowsPlatform.h"
11 #include "nsDataHashtable.h"
13 #include "mozwrlbase.h"
15 #include <windows.system.h>
16 #include <Windows.ApplicationModel.core.h>
17 #include <Windows.ApplicationModel.h>
18 #include <Windows.Applicationmodel.Activation.h>
19 #include <Windows.ApplicationModel.search.h>
20 #include <windows.ui.core.h>
21 #include <windows.ui.viewmanagement.h>
22 #include <windows.ui.applicationsettings.h>
23 #include <windows.ui.popups.h>
24 #include <windows.graphics.printing.h>
25 #include <windows.graphics.display.h>
26 #include <windows.media.playto.h>
27 #include <d2d1_1.h>
29 namespace mozilla {
30 namespace widget {
31 namespace winrt {
33 class MetroApp;
35 class FrameworkView : public Microsoft::WRL::RuntimeClass<ABI::Windows::ApplicationModel::Core::IFrameworkView>
36 {
37 InspectableClass(L"FrameworkView", TrustLevel::BaseTrust)
39 typedef mozilla::layers::LayerManager LayerManager;
41 typedef ABI::Windows::Foundation::Rect Rect;
42 typedef ABI::Windows::UI::Core::IWindowSizeChangedEventArgs IWindowSizeChangedEventArgs;
43 typedef ABI::Windows::UI::Core::ICoreWindowEventArgs ICoreWindowEventArgs;
44 typedef ABI::Windows::UI::Core::IWindowActivatedEventArgs IWindowActivatedEventArgs;
45 typedef ABI::Windows::UI::Core::IAutomationProviderRequestedEventArgs IAutomationProviderRequestedEventArgs;
46 typedef ABI::Windows::UI::Core::ICoreWindow ICoreWindow;
47 typedef ABI::Windows::UI::Core::ICoreDispatcher ICoreDispatcher;
48 typedef ABI::Windows::UI::Core::IVisibilityChangedEventArgs IVisibilityChangedEventArgs;
49 typedef ABI::Windows::UI::ViewManagement::IInputPaneVisibilityEventArgs IInputPaneVisibilityEventArgs;
50 typedef ABI::Windows::UI::ViewManagement::IInputPane IInputPane;
51 typedef ABI::Windows::UI::ViewManagement::ApplicationViewState ApplicationViewState;
52 typedef ABI::Windows::UI::ApplicationSettings::ISettingsPane ISettingsPane;
53 typedef ABI::Windows::UI::ApplicationSettings::ISettingsPaneCommandsRequestedEventArgs ISettingsPaneCommandsRequestedEventArgs;
54 typedef ABI::Windows::UI::Popups::IUICommand IUICommand;
55 typedef ABI::Windows::ApplicationModel::Activation::ILaunchActivatedEventArgs ILaunchActivatedEventArgs;
56 typedef ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs IActivatedEventArgs;
57 typedef ABI::Windows::ApplicationModel::Activation::ISearchActivatedEventArgs ISearchActivatedEventArgs;
58 typedef ABI::Windows::ApplicationModel::Activation::IFileActivatedEventArgs IFileActivatedEventArgs;
59 typedef ABI::Windows::ApplicationModel::Core::ICoreApplicationView ICoreApplicationView;
60 typedef ABI::Windows::ApplicationModel::DataTransfer::IDataTransferManager IDataTransferManager;
61 typedef ABI::Windows::ApplicationModel::DataTransfer::IDataRequestedEventArgs IDataRequestedEventArgs;
62 typedef ABI::Windows::ApplicationModel::Search::ISearchPane ISearchPane;
63 typedef ABI::Windows::ApplicationModel::Search::ISearchPaneQuerySubmittedEventArgs ISearchPaneQuerySubmittedEventArgs;
64 typedef ABI::Windows::Media::PlayTo::IPlayToManager IPlayToManager;
65 typedef ABI::Windows::Media::PlayTo::IPlayToSourceRequestedEventArgs IPlayToSourceRequestedEventArgs;
66 typedef ABI::Windows::Graphics::Printing::IPrintManager IPrintManager;
67 typedef ABI::Windows::Graphics::Printing::IPrintTaskRequestedEventArgs IPrintTaskRequestedEventArgs;
68 typedef ABI::Windows::Graphics::Printing::IPrintTaskSourceRequestedArgs IPrintTaskSourceRequestedArgs;
70 public:
71 FrameworkView(MetroApp* aMetroApp);
73 // IFrameworkView Methods
74 STDMETHODIMP Initialize(ICoreApplicationView* aAppView);
75 STDMETHODIMP SetWindow(ICoreWindow* aWindow);
76 STDMETHODIMP Load(HSTRING aEntryPoint);
77 STDMETHODIMP Run();
78 STDMETHODIMP Uninitialize();
80 HRESULT ActivateView();
82 // Public apis for MetroWidget
83 float GetDPI() { return mDPI; }
84 ICoreWindow* GetCoreWindow() { return mWindow.Get(); }
85 void SetWidget(MetroWidget* aWidget);
86 MetroWidget* GetWidget() { return mWidget.Get(); }
87 void GetBounds(nsIntRect &aRect);
88 void SetCursor(ABI::Windows::UI::Core::CoreCursorType aCursorType, DWORD aCustomId = 0);
89 void ClearCursor();
90 bool IsEnabled() const;
91 bool IsVisible() const;
93 // Activation apis for nsIWinMetroUtils
94 static int GetPreviousExecutionState() { return sPreviousExecutionState; }
95 static void GetActivationURI(nsAString &aActivationURI) {
96 unsigned int length;
97 aActivationURI = WindowsGetStringRawBuffer(sActivationURI, &length);
98 }
100 // Soft keyboard info for nsIWinMetroUtils
101 static bool IsKeyboardVisible() { return sKeyboardIsVisible; }
102 static ABI::Windows::Foundation::Rect KeyboardVisibleRect() { return sKeyboardRect; }
104 // MetroApp apis
105 void SetupContracts();
106 void Shutdown();
108 // MetroContracts settings panel enumerator entry
109 void AddSetting(ISettingsPaneCommandsRequestedEventArgs* aArgs, uint32_t aId,
110 Microsoft::WRL::Wrappers::HString& aSettingName);
111 protected:
112 // Event Handlers
113 HRESULT OnActivated(ICoreApplicationView* aApplicationView,
114 IActivatedEventArgs* aArgs);
115 HRESULT OnWindowVisibilityChanged(ICoreWindow* aCoreWindow,
116 IVisibilityChangedEventArgs* aArgs);
118 HRESULT OnWindowSizeChanged(ICoreWindow* aSender,
119 IWindowSizeChangedEventArgs* aArgs);
120 HRESULT OnWindowActivated(ICoreWindow* aSender,
121 IWindowActivatedEventArgs* aArgs);
122 HRESULT OnLogicalDpiChanged(IInspectable* aSender);
124 HRESULT OnAutomationProviderRequested(ICoreWindow* aSender,
125 IAutomationProviderRequestedEventArgs* aArgs);
127 HRESULT OnSoftkeyboardHidden(IInputPane* aSender,
128 IInputPaneVisibilityEventArgs* aArgs);
129 HRESULT OnSoftkeyboardShown(IInputPane* aSender,
130 IInputPaneVisibilityEventArgs* aArgs);
132 HRESULT OnDataShareRequested(IDataTransferManager*, IDataRequestedEventArgs* aArgs);
133 HRESULT OnSearchQuerySubmitted(ISearchPane* aPane, ISearchPaneQuerySubmittedEventArgs* aArgs);
134 HRESULT OnSettingsCommandsRequested(ISettingsPane* aPane, ISettingsPaneCommandsRequestedEventArgs* aArgs);
135 HRESULT OnPlayToSourceRequested(IPlayToManager* aPane, IPlayToSourceRequestedEventArgs* aArgs);
136 HRESULT OnSettingsCommandInvoked(IUICommand* aCommand);
137 HRESULT OnPrintTaskRequested(IPrintManager* aMgr, IPrintTaskRequestedEventArgs* aArgs);
138 HRESULT OnPrintTaskSourceRequested(IPrintTaskSourceRequestedArgs* aArgs);
140 protected:
141 void SetDpi(float aDpi);
142 void UpdateWidgetSizeAndPosition();
143 void PerformURILoad(Microsoft::WRL::Wrappers::HString& aString);
144 void PerformSearch(Microsoft::WRL::Wrappers::HString& aQuery);
145 void PerformURILoadOrSearch(Microsoft::WRL::Wrappers::HString& aString);
146 bool EnsureAutomationProviderCreated();
147 void SearchActivated(Microsoft::WRL::ComPtr<ISearchActivatedEventArgs>& aArgs, bool aStartup);
148 void FileActivated(Microsoft::WRL::ComPtr<IFileActivatedEventArgs>& aArgs, bool aStartup);
149 void LaunchActivated(Microsoft::WRL::ComPtr<ILaunchActivatedEventArgs>& aArgs, bool aStartup);
150 void ProcessActivationArgs(IActivatedEventArgs* aArgs, bool aStartup);
151 void UpdateForWindowSizeChange();
152 void SendActivationEvent();
153 void UpdateLogicalDPI();
154 void FireViewStateObservers();
155 void ProcessLaunchArguments();
156 void UpdateBounds();
158 // Printing and preview
159 void CreatePrintControl(IPrintDocumentPackageTarget* aDocPackageTarget,
160 D2D1_PRINT_CONTROL_PROPERTIES* aPrintControlProperties);
161 HRESULT ClosePrintControl();
162 void PrintPage(uint32_t aPageNumber, D2D1_RECT_F aImageableArea,
163 D2D1_SIZE_F aPageSize, IStream* aPagePrintTicketStream);
164 void AddEventHandlers();
166 private:
167 EventRegistrationToken mActivated;
168 EventRegistrationToken mWindowActivated;
169 EventRegistrationToken mWindowVisibilityChanged;
170 EventRegistrationToken mWindowClosed;
171 EventRegistrationToken mWindowSizeChanged;
172 EventRegistrationToken mSoftKeyboardHidden;
173 EventRegistrationToken mSoftKeyboardShown;
174 EventRegistrationToken mDisplayPropertiesChanged;
175 EventRegistrationToken mAutomationProviderRequested;
176 EventRegistrationToken mDataTransferRequested;
177 EventRegistrationToken mSearchQuerySubmitted;
178 EventRegistrationToken mPlayToRequested;
179 EventRegistrationToken mSettingsPane;
180 EventRegistrationToken mPrintManager;
182 private:
183 nsIntRect mWindowBounds; // in device-pixel coordinates
184 float mDPI;
185 bool mShuttingDown;
186 nsAutoString mActivationCommandLine;
187 Microsoft::WRL::ComPtr<IInspectable> mAutomationProvider;
188 //Microsoft::WRL::ComPtr<ID2D1PrintControl> mD2DPrintControl;
189 // Private critical section protects D2D device context for on-screen
190 // rendering from that for print/preview in the different thread.
191 //Microsoft::WRL::ComPtr<IWICImagingFactory2> mWicFactory;
192 Microsoft::WRL::ComPtr<MetroApp> mMetroApp;
193 Microsoft::WRL::ComPtr<ICoreWindow> mWindow;
194 Microsoft::WRL::ComPtr<MetroWidget> mWidget;
195 Microsoft::WRL::ComPtr<MetroInput> mMetroInput;
196 bool mWinVisible;
197 bool mWinActiveState;
199 static bool sKeyboardIsVisible;
200 static Rect sKeyboardRect;
201 static HSTRING sActivationURI;
202 static ABI::Windows::ApplicationModel::Activation::ApplicationExecutionState sPreviousExecutionState;
203 };
205 } } }