|
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/. */ |
|
5 |
|
6 #pragma once |
|
7 |
|
8 #include "nsDebug.h" |
|
9 #include "nsThreadUtils.h" |
|
10 #include "nsString.h" |
|
11 #include "nsPoint.h" |
|
12 #include "WinUtils.h" |
|
13 |
|
14 #include "mozwrlbase.h" |
|
15 |
|
16 #include <stdio.h> |
|
17 #include <windows.foundation.h> |
|
18 #include <windows.ui.viewmanagement.h> |
|
19 |
|
20 // HRESULT checkers, these warn on failure in debug builds |
|
21 #ifdef DEBUG |
|
22 #define DebugLogHR(hr) LogHRESULT(hr) |
|
23 #else |
|
24 #define DebugLogHR(hr) |
|
25 #endif |
|
26 #define AssertHRESULT(hr) \ |
|
27 if (FAILED(hr)) { \ |
|
28 DebugLogHR(hr); \ |
|
29 return; \ |
|
30 } |
|
31 #define AssertRetHRESULT(hr, res) \ |
|
32 if (FAILED(hr)) { \ |
|
33 DebugLogHR(hr); \ |
|
34 return res; \ |
|
35 } |
|
36 |
|
37 // MS Point helpers |
|
38 #define POINT_CEIL_X(position) (uint32_t)ceil(position.X) |
|
39 #define POINT_CEIL_Y(position) (uint32_t)ceil(position.Y) |
|
40 |
|
41 class nsIBrowserDOMWindow; |
|
42 class nsIDOMWindow; |
|
43 struct nsIntRect; |
|
44 |
|
45 namespace mozilla { |
|
46 namespace widget { |
|
47 namespace winrt { |
|
48 |
|
49 template<unsigned int size, typename T> |
|
50 HRESULT ActivateGenericInstance(wchar_t const (&RuntimeClassName)[size], Microsoft::WRL::ComPtr<T>& aOutObject) { |
|
51 Microsoft::WRL::ComPtr<IActivationFactory> factory; |
|
52 HRESULT hr = ABI::Windows::Foundation::GetActivationFactory(Microsoft::WRL::Wrappers::HStringReference(RuntimeClassName).Get(), |
|
53 factory.GetAddressOf()); |
|
54 if (FAILED(hr)) |
|
55 return hr; |
|
56 Microsoft::WRL::ComPtr<IInspectable> inspect; |
|
57 hr = factory->ActivateInstance(inspect.GetAddressOf()); |
|
58 if (FAILED(hr)) |
|
59 return hr; |
|
60 return inspect.As(&aOutObject); |
|
61 } |
|
62 |
|
63 } } } |
|
64 |
|
65 class MetroUtils |
|
66 { |
|
67 typedef ABI::Windows::Foundation::IUriRuntimeClass IUriRuntimeClass; |
|
68 typedef Microsoft::WRL::Wrappers::HString HString; |
|
69 typedef ABI::Windows::UI::ViewManagement::ApplicationViewState ApplicationViewState; |
|
70 typedef ABI::Windows::Foundation::Point Point; |
|
71 typedef ABI::Windows::Foundation::Rect Rect; |
|
72 |
|
73 public: |
|
74 // Functions to convert between logical pixels as used by most Windows APIs |
|
75 // and physical (device) pixels. |
|
76 static double LogToPhysFactor(); |
|
77 static double PhysToLogFactor(); |
|
78 static nsIntPoint LogToPhys(const Point& aPt); |
|
79 static nsIntRect LogToPhys(const Rect& aRect); |
|
80 static Point PhysToLog(const nsIntPoint& aPt); |
|
81 |
|
82 // Resolution scale factor |
|
83 static double ScaleFactor(); |
|
84 |
|
85 static nsresult FireObserver(const char* aMessage, const char16_t* aData = nullptr); |
|
86 |
|
87 static HRESULT CreateUri(HSTRING aUriStr, Microsoft::WRL::ComPtr<IUriRuntimeClass>& aUriOut); |
|
88 static HRESULT CreateUri(HString& aHString, Microsoft::WRL::ComPtr<IUriRuntimeClass>& aUriOut); |
|
89 static HRESULT GetViewState(ApplicationViewState& aState); |
|
90 static HRESULT TryUnsnap(bool* aResult = nullptr); |
|
91 static HRESULT ShowSettingsFlyout(); |
|
92 |
|
93 private: |
|
94 static nsresult GetBrowserDOMWindow(nsCOMPtr<nsIBrowserDOMWindow> &aBWin); |
|
95 static nsresult GetMostRecentWindow(const char16_t* aType, nsIDOMWindow** aWindow); |
|
96 }; |