widget/Screen.cpp
author Mike Hommey <mh+mozilla@glandium.org>
Fri, 11 Jan 2019 16:01:15 +0000
changeset 453570 daf50f25895db073e44d50fecf2e4f6fe873865d
parent 449028 e4712449ba4303cef134ba0b3f1bea13fbd50c4a
permissions -rw-r--r--
Bug 1519307 - Add a new project to build useful parts of breakpad independently. r=froydnj With `ac_add_options --enable-project=tools/crashreporter` in a mozconfig, `./mach build` builds minidump_stackwalk, dump_syms and fileid. One caveat is that due to limitation in how the build system works currently, it's cumbersome to keep dump_syms as a host program for Gecko, and to make it a target program for this project. For now, keep it as a host program. We're not going to use it on automation, but it's still convenient to have for quick local builds (I've had to resort to awful hacks downstream). Differential Revision: https://phabricator.services.mozilla.com/D16299

/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* 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/. */

#include "Screen.h"

#include "mozilla/dom/DOMTypes.h"

namespace mozilla {
namespace widget {

NS_IMPL_ISUPPORTS(Screen, nsIScreen)

Screen::Screen(LayoutDeviceIntRect aRect, LayoutDeviceIntRect aAvailRect,
               uint32_t aPixelDepth, uint32_t aColorDepth,
               DesktopToLayoutDeviceScale aContentsScale,
               CSSToLayoutDeviceScale aDefaultCssScale, float aDPI)
    : mRect(aRect),
      mAvailRect(aAvailRect),
      mRectDisplayPix(RoundedToInt(aRect / aContentsScale)),
      mAvailRectDisplayPix(RoundedToInt(aAvailRect / aContentsScale)),
      mPixelDepth(aPixelDepth),
      mColorDepth(aColorDepth),
      mContentsScale(aContentsScale),
      mDefaultCssScale(aDefaultCssScale),
      mDPI(aDPI) {}

Screen::Screen(const mozilla::dom::ScreenDetails& aScreen)
    : mRect(aScreen.rect()),
      mAvailRect(aScreen.availRect()),
      mRectDisplayPix(aScreen.rectDisplayPix()),
      mAvailRectDisplayPix(aScreen.availRectDisplayPix()),
      mPixelDepth(aScreen.pixelDepth()),
      mColorDepth(aScreen.colorDepth()),
      mContentsScale(aScreen.contentsScaleFactor()),
      mDefaultCssScale(aScreen.defaultCSSScaleFactor()),
      mDPI(aScreen.dpi()) {}

Screen::Screen(const Screen& aOther)
    : mRect(aOther.mRect),
      mAvailRect(aOther.mAvailRect),
      mRectDisplayPix(aOther.mRectDisplayPix),
      mAvailRectDisplayPix(aOther.mAvailRectDisplayPix),
      mPixelDepth(aOther.mPixelDepth),
      mColorDepth(aOther.mColorDepth),
      mContentsScale(aOther.mContentsScale),
      mDefaultCssScale(aOther.mDefaultCssScale),
      mDPI(aOther.mDPI) {}

mozilla::dom::ScreenDetails Screen::ToScreenDetails() {
  return mozilla::dom::ScreenDetails(
      mRect, mRectDisplayPix, mAvailRect, mAvailRectDisplayPix, mPixelDepth,
      mColorDepth, mContentsScale, mDefaultCssScale, mDPI);
}

NS_IMETHODIMP
Screen::GetRect(int32_t* aOutLeft, int32_t* aOutTop, int32_t* aOutWidth,
                int32_t* aOutHeight) {
  mRect.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
  return NS_OK;
}

NS_IMETHODIMP
Screen::GetRectDisplayPix(int32_t* aOutLeft, int32_t* aOutTop,
                          int32_t* aOutWidth, int32_t* aOutHeight) {
  mRectDisplayPix.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
  return NS_OK;
}

NS_IMETHODIMP
Screen::GetAvailRect(int32_t* aOutLeft, int32_t* aOutTop, int32_t* aOutWidth,
                     int32_t* aOutHeight) {
  mAvailRect.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
  return NS_OK;
}

NS_IMETHODIMP
Screen::GetAvailRectDisplayPix(int32_t* aOutLeft, int32_t* aOutTop,
                               int32_t* aOutWidth, int32_t* aOutHeight) {
  mAvailRectDisplayPix.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
  return NS_OK;
}

NS_IMETHODIMP
Screen::GetPixelDepth(int32_t* aPixelDepth) {
  *aPixelDepth = mPixelDepth;
  return NS_OK;
}

NS_IMETHODIMP
Screen::GetColorDepth(int32_t* aColorDepth) {
  *aColorDepth = mColorDepth;
  return NS_OK;
}

NS_IMETHODIMP
Screen::GetContentsScaleFactor(double* aOutScale) {
  *aOutScale = mContentsScale.scale;
  return NS_OK;
}

NS_IMETHODIMP
Screen::GetDefaultCSSScaleFactor(double* aOutScale) {
  double scale = nsIWidget::DefaultScaleOverride();
  if (scale > 0.0) {
    *aOutScale = scale;
  } else {
    *aOutScale = mDefaultCssScale.scale;
  }
  return NS_OK;
}

NS_IMETHODIMP
Screen::GetDpi(float* aDPI) {
  *aDPI = mDPI;
  return NS_OK;
}

}  // namespace widget
}  // namespace mozilla