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 "nsDebug.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "nsString.h" michael@0: #include "nsPoint.h" michael@0: #include "WinUtils.h" michael@0: michael@0: #include "mozwrlbase.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: // HRESULT checkers, these warn on failure in debug builds michael@0: #ifdef DEBUG michael@0: #define DebugLogHR(hr) LogHRESULT(hr) michael@0: #else michael@0: #define DebugLogHR(hr) michael@0: #endif michael@0: #define AssertHRESULT(hr) \ michael@0: if (FAILED(hr)) { \ michael@0: DebugLogHR(hr); \ michael@0: return; \ michael@0: } michael@0: #define AssertRetHRESULT(hr, res) \ michael@0: if (FAILED(hr)) { \ michael@0: DebugLogHR(hr); \ michael@0: return res; \ michael@0: } michael@0: michael@0: // MS Point helpers michael@0: #define POINT_CEIL_X(position) (uint32_t)ceil(position.X) michael@0: #define POINT_CEIL_Y(position) (uint32_t)ceil(position.Y) michael@0: michael@0: class nsIBrowserDOMWindow; michael@0: class nsIDOMWindow; michael@0: struct nsIntRect; michael@0: michael@0: namespace mozilla { michael@0: namespace widget { michael@0: namespace winrt { michael@0: michael@0: template michael@0: HRESULT ActivateGenericInstance(wchar_t const (&RuntimeClassName)[size], Microsoft::WRL::ComPtr& aOutObject) { michael@0: Microsoft::WRL::ComPtr factory; michael@0: HRESULT hr = ABI::Windows::Foundation::GetActivationFactory(Microsoft::WRL::Wrappers::HStringReference(RuntimeClassName).Get(), michael@0: factory.GetAddressOf()); michael@0: if (FAILED(hr)) michael@0: return hr; michael@0: Microsoft::WRL::ComPtr inspect; michael@0: hr = factory->ActivateInstance(inspect.GetAddressOf()); michael@0: if (FAILED(hr)) michael@0: return hr; michael@0: return inspect.As(&aOutObject); michael@0: } michael@0: michael@0: } } } michael@0: michael@0: class MetroUtils michael@0: { michael@0: typedef ABI::Windows::Foundation::IUriRuntimeClass IUriRuntimeClass; michael@0: typedef Microsoft::WRL::Wrappers::HString HString; michael@0: typedef ABI::Windows::UI::ViewManagement::ApplicationViewState ApplicationViewState; michael@0: typedef ABI::Windows::Foundation::Point Point; michael@0: typedef ABI::Windows::Foundation::Rect Rect; michael@0: michael@0: public: michael@0: // Functions to convert between logical pixels as used by most Windows APIs michael@0: // and physical (device) pixels. michael@0: static double LogToPhysFactor(); michael@0: static double PhysToLogFactor(); michael@0: static nsIntPoint LogToPhys(const Point& aPt); michael@0: static nsIntRect LogToPhys(const Rect& aRect); michael@0: static Point PhysToLog(const nsIntPoint& aPt); michael@0: michael@0: // Resolution scale factor michael@0: static double ScaleFactor(); michael@0: michael@0: static nsresult FireObserver(const char* aMessage, const char16_t* aData = nullptr); michael@0: michael@0: static HRESULT CreateUri(HSTRING aUriStr, Microsoft::WRL::ComPtr& aUriOut); michael@0: static HRESULT CreateUri(HString& aHString, Microsoft::WRL::ComPtr& aUriOut); michael@0: static HRESULT GetViewState(ApplicationViewState& aState); michael@0: static HRESULT TryUnsnap(bool* aResult = nullptr); michael@0: static HRESULT ShowSettingsFlyout(); michael@0: michael@0: private: michael@0: static nsresult GetBrowserDOMWindow(nsCOMPtr &aBWin); michael@0: static nsresult GetMostRecentWindow(const char16_t* aType, nsIDOMWindow** aWindow); michael@0: };