2013-02-12 20:51:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsString.h"
|
2013-03-13 15:09:46 +00:00
|
|
|
#include "nsPoint.h"
|
2013-11-01 10:09:32 +00:00
|
|
|
#include "WinUtils.h"
|
2013-02-12 20:51:25 +00:00
|
|
|
|
|
|
|
#include "mozwrlbase.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <windows.foundation.h>
|
|
|
|
#include <windows.ui.viewmanagement.h>
|
|
|
|
|
|
|
|
// HRESULT checkers, these warn on failure in debug builds
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define DebugLogHR(hr) LogHRESULT(hr)
|
|
|
|
#else
|
|
|
|
#define DebugLogHR(hr)
|
|
|
|
#endif
|
|
|
|
#define AssertHRESULT(hr) \
|
|
|
|
if (FAILED(hr)) { \
|
|
|
|
DebugLogHR(hr); \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
#define AssertRetHRESULT(hr, res) \
|
|
|
|
if (FAILED(hr)) { \
|
|
|
|
DebugLogHR(hr); \
|
|
|
|
return res; \
|
|
|
|
}
|
|
|
|
|
|
|
|
// MS Point helpers
|
|
|
|
#define POINT_CEIL_X(position) (uint32_t)ceil(position.X)
|
|
|
|
#define POINT_CEIL_Y(position) (uint32_t)ceil(position.Y)
|
|
|
|
|
|
|
|
class nsIBrowserDOMWindow;
|
|
|
|
class nsIDOMWindow;
|
2013-09-07 02:15:49 +00:00
|
|
|
struct nsIntRect;
|
2013-02-12 20:51:25 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
namespace winrt {
|
|
|
|
|
|
|
|
template<unsigned int size, typename T>
|
|
|
|
HRESULT ActivateGenericInstance(wchar_t const (&RuntimeClassName)[size], Microsoft::WRL::ComPtr<T>& aOutObject) {
|
|
|
|
Microsoft::WRL::ComPtr<IActivationFactory> factory;
|
|
|
|
HRESULT hr = ABI::Windows::Foundation::GetActivationFactory(Microsoft::WRL::Wrappers::HStringReference(RuntimeClassName).Get(),
|
|
|
|
factory.GetAddressOf());
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
Microsoft::WRL::ComPtr<IInspectable> inspect;
|
|
|
|
hr = factory->ActivateInstance(inspect.GetAddressOf());
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
return inspect.As(&aOutObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
} } }
|
|
|
|
|
|
|
|
class MetroUtils
|
|
|
|
{
|
|
|
|
typedef ABI::Windows::Foundation::IUriRuntimeClass IUriRuntimeClass;
|
|
|
|
typedef Microsoft::WRL::Wrappers::HString HString;
|
|
|
|
typedef ABI::Windows::UI::ViewManagement::ApplicationViewState ApplicationViewState;
|
2013-03-13 15:09:46 +00:00
|
|
|
typedef ABI::Windows::Foundation::Point Point;
|
|
|
|
typedef ABI::Windows::Foundation::Rect Rect;
|
2013-02-12 20:51:25 +00:00
|
|
|
|
|
|
|
public:
|
2013-03-13 15:09:46 +00:00
|
|
|
// Functions to convert between logical pixels as used by most Windows APIs
|
|
|
|
// and physical (device) pixels.
|
2013-12-14 20:40:55 +00:00
|
|
|
static double LogToPhysFactor();
|
|
|
|
static double PhysToLogFactor();
|
2013-03-13 15:09:46 +00:00
|
|
|
static nsIntPoint LogToPhys(const Point& aPt);
|
|
|
|
static nsIntRect LogToPhys(const Rect& aRect);
|
|
|
|
static Point PhysToLog(const nsIntPoint& aPt);
|
|
|
|
|
2013-12-14 20:40:55 +00:00
|
|
|
// Resolution scale factor
|
|
|
|
static double ScaleFactor();
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
static nsresult FireObserver(const char* aMessage, const char16_t* aData = nullptr);
|
2013-02-12 20:51:25 +00:00
|
|
|
|
|
|
|
static HRESULT CreateUri(HSTRING aUriStr, Microsoft::WRL::ComPtr<IUriRuntimeClass>& aUriOut);
|
|
|
|
static HRESULT CreateUri(HString& aHString, Microsoft::WRL::ComPtr<IUriRuntimeClass>& aUriOut);
|
|
|
|
static HRESULT GetViewState(ApplicationViewState& aState);
|
|
|
|
static HRESULT TryUnsnap(bool* aResult = nullptr);
|
|
|
|
static HRESULT ShowSettingsFlyout();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static nsresult GetBrowserDOMWindow(nsCOMPtr<nsIBrowserDOMWindow> &aBWin);
|
2014-01-04 15:02:17 +00:00
|
|
|
static nsresult GetMostRecentWindow(const char16_t* aType, nsIDOMWindow** aWindow);
|
2013-02-12 20:51:25 +00:00
|
|
|
};
|