widget/windows/winrt/MetroUtils.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial