widget/windows/winrt/MetroUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/windows/winrt/MetroUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#pragma once
    1.10 +
    1.11 +#include "nsDebug.h"
    1.12 +#include "nsThreadUtils.h"
    1.13 +#include "nsString.h"
    1.14 +#include "nsPoint.h"
    1.15 +#include "WinUtils.h"
    1.16 +
    1.17 +#include "mozwrlbase.h"
    1.18 +
    1.19 +#include <stdio.h>
    1.20 +#include <windows.foundation.h>
    1.21 +#include <windows.ui.viewmanagement.h>
    1.22 +
    1.23 +// HRESULT checkers, these warn on failure in debug builds
    1.24 +#ifdef DEBUG
    1.25 +#define DebugLogHR(hr) LogHRESULT(hr)
    1.26 +#else
    1.27 +#define DebugLogHR(hr)
    1.28 +#endif
    1.29 +#define AssertHRESULT(hr)           \
    1.30 +  if (FAILED(hr)) {                 \
    1.31 +    DebugLogHR(hr);                 \
    1.32 +    return;                         \
    1.33 +  }
    1.34 +#define AssertRetHRESULT(hr, res)   \
    1.35 +  if (FAILED(hr)) {                 \
    1.36 +    DebugLogHR(hr);                 \
    1.37 +    return res;                     \
    1.38 +  }
    1.39 +
    1.40 +// MS Point helpers
    1.41 +#define POINT_CEIL_X(position) (uint32_t)ceil(position.X)
    1.42 +#define POINT_CEIL_Y(position) (uint32_t)ceil(position.Y)
    1.43 +
    1.44 +class nsIBrowserDOMWindow;
    1.45 +class nsIDOMWindow;
    1.46 +struct nsIntRect;
    1.47 +
    1.48 +namespace mozilla {
    1.49 +namespace widget {
    1.50 +namespace winrt {
    1.51 +
    1.52 +template<unsigned int size, typename T>
    1.53 +HRESULT ActivateGenericInstance(wchar_t const (&RuntimeClassName)[size], Microsoft::WRL::ComPtr<T>& aOutObject) {
    1.54 +  Microsoft::WRL::ComPtr<IActivationFactory> factory;
    1.55 +  HRESULT hr = ABI::Windows::Foundation::GetActivationFactory(Microsoft::WRL::Wrappers::HStringReference(RuntimeClassName).Get(),
    1.56 +                                                              factory.GetAddressOf());
    1.57 +  if (FAILED(hr))
    1.58 +    return hr;
    1.59 +  Microsoft::WRL::ComPtr<IInspectable> inspect;
    1.60 +  hr = factory->ActivateInstance(inspect.GetAddressOf());
    1.61 +  if (FAILED(hr))
    1.62 +    return hr;
    1.63 +  return inspect.As(&aOutObject);
    1.64 +}
    1.65 +
    1.66 +} } }
    1.67 +
    1.68 +class MetroUtils
    1.69 +{
    1.70 +  typedef ABI::Windows::Foundation::IUriRuntimeClass IUriRuntimeClass;
    1.71 +  typedef Microsoft::WRL::Wrappers::HString HString;
    1.72 +  typedef ABI::Windows::UI::ViewManagement::ApplicationViewState ApplicationViewState;
    1.73 +  typedef ABI::Windows::Foundation::Point Point;
    1.74 +  typedef ABI::Windows::Foundation::Rect Rect;
    1.75 +
    1.76 +public:
    1.77 +  // Functions to convert between logical pixels as used by most Windows APIs
    1.78 +  // and physical (device) pixels.
    1.79 +  static double LogToPhysFactor();
    1.80 +  static double PhysToLogFactor();
    1.81 +  static nsIntPoint LogToPhys(const Point& aPt);
    1.82 +  static nsIntRect LogToPhys(const Rect& aRect);
    1.83 +  static Point PhysToLog(const nsIntPoint& aPt);
    1.84 +
    1.85 +  // Resolution scale factor
    1.86 +  static double ScaleFactor();
    1.87 +
    1.88 +  static nsresult FireObserver(const char* aMessage, const char16_t* aData = nullptr);
    1.89 +
    1.90 +  static HRESULT CreateUri(HSTRING aUriStr, Microsoft::WRL::ComPtr<IUriRuntimeClass>& aUriOut);
    1.91 +  static HRESULT CreateUri(HString& aHString, Microsoft::WRL::ComPtr<IUriRuntimeClass>& aUriOut);
    1.92 +  static HRESULT GetViewState(ApplicationViewState& aState);
    1.93 +  static HRESULT TryUnsnap(bool* aResult = nullptr);
    1.94 +  static HRESULT ShowSettingsFlyout();
    1.95 +
    1.96 +private:
    1.97 +  static nsresult GetBrowserDOMWindow(nsCOMPtr<nsIBrowserDOMWindow> &aBWin);
    1.98 +  static nsresult GetMostRecentWindow(const char16_t* aType, nsIDOMWindow** aWindow);
    1.99 +};

mercurial