/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 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/. */ #ifndef MOZ_UNITS_H_ #define MOZ_UNITS_H_ #include "mozilla/gfx/Coord.h" #include "mozilla/gfx/Point.h" #include "mozilla/gfx/Rect.h" #include "mozilla/gfx/RegionTyped.h" #include "mozilla/gfx/ScaleFactor.h" #include "mozilla/gfx/ScaleFactors2D.h" #include "nsRect.h" #include "nsMargin.h" #include "mozilla/AppUnits.h" #include "mozilla/TypeTraits.h" namespace mozilla { template struct IsPixel : FalseType {}; // See struct declaration for a description of each unit type. struct CSSPixel; struct LayoutDevicePixel; struct LayerPixel; struct RenderTargetPixel; struct ScreenPixel; struct ParentLayerPixel; template<> struct IsPixel : TrueType {}; template<> struct IsPixel : TrueType {}; template<> struct IsPixel : TrueType {}; template<> struct IsPixel : TrueType {}; template<> struct IsPixel : TrueType {}; template<> struct IsPixel : TrueType {}; typedef gfx::CoordTyped CSSCoord; typedef gfx::IntCoordTyped CSSIntCoord; typedef gfx::PointTyped CSSPoint; typedef gfx::IntPointTyped CSSIntPoint; typedef gfx::SizeTyped CSSSize; typedef gfx::IntSizeTyped CSSIntSize; typedef gfx::RectTyped CSSRect; typedef gfx::IntRectTyped CSSIntRect; typedef gfx::MarginTyped CSSMargin; typedef gfx::IntMarginTyped CSSIntMargin; typedef gfx::IntRegionTyped CSSIntRegion; typedef gfx::CoordTyped LayoutDeviceCoord; typedef gfx::IntCoordTyped LayoutDeviceIntCoord; typedef gfx::PointTyped LayoutDevicePoint; typedef gfx::IntPointTyped LayoutDeviceIntPoint; typedef gfx::SizeTyped LayoutDeviceSize; typedef gfx::IntSizeTyped LayoutDeviceIntSize; typedef gfx::RectTyped LayoutDeviceRect; typedef gfx::IntRectTyped LayoutDeviceIntRect; typedef gfx::MarginTyped LayoutDeviceMargin; typedef gfx::IntMarginTyped LayoutDeviceIntMargin; typedef gfx::IntRegionTyped LayoutDeviceIntRegion; typedef gfx::CoordTyped LayerCoord; typedef gfx::IntCoordTyped LayerIntCoord; typedef gfx::PointTyped LayerPoint; typedef gfx::IntPointTyped LayerIntPoint; typedef gfx::SizeTyped LayerSize; typedef gfx::IntSizeTyped LayerIntSize; typedef gfx::RectTyped LayerRect; typedef gfx::IntRectTyped LayerIntRect; typedef gfx::MarginTyped LayerMargin; typedef gfx::IntMarginTyped LayerIntMargin; typedef gfx::IntRegionTyped LayerIntRegion; typedef gfx::PointTyped RenderTargetPoint; typedef gfx::IntPointTyped RenderTargetIntPoint; typedef gfx::SizeTyped RenderTargetSize; typedef gfx::IntSizeTyped RenderTargetIntSize; typedef gfx::RectTyped RenderTargetRect; typedef gfx::IntRectTyped RenderTargetIntRect; typedef gfx::MarginTyped RenderTargetMargin; typedef gfx::IntMarginTyped RenderTargetIntMargin; typedef gfx::IntRegionTyped RenderTargetIntRegion; typedef gfx::CoordTyped ScreenCoord; typedef gfx::IntCoordTyped ScreenIntCoord; typedef gfx::PointTyped ScreenPoint; typedef gfx::IntPointTyped ScreenIntPoint; typedef gfx::SizeTyped ScreenSize; typedef gfx::IntSizeTyped ScreenIntSize; typedef gfx::RectTyped ScreenRect; typedef gfx::IntRectTyped ScreenIntRect; typedef gfx::MarginTyped ScreenMargin; typedef gfx::IntMarginTyped ScreenIntMargin; typedef gfx::IntRegionTyped ScreenIntRegion; typedef gfx::CoordTyped ParentLayerCoord; typedef gfx::IntCoordTyped ParentLayerIntCoord; typedef gfx::PointTyped ParentLayerPoint; typedef gfx::IntPointTyped ParentLayerIntPoint; typedef gfx::SizeTyped ParentLayerSize; typedef gfx::IntSizeTyped ParentLayerIntSize; typedef gfx::RectTyped ParentLayerRect; typedef gfx::IntRectTyped ParentLayerIntRect; typedef gfx::MarginTyped ParentLayerMargin; typedef gfx::IntMarginTyped ParentLayerIntMargin; typedef gfx::IntRegionTyped ParentLayerIntRegion; typedef gfx::ScaleFactor CSSToLayoutDeviceScale; typedef gfx::ScaleFactor CSSToLayerScale; typedef gfx::ScaleFactor CSSToScreenScale; typedef gfx::ScaleFactor CSSToParentLayerScale; typedef gfx::ScaleFactor LayoutDeviceToCSSScale; typedef gfx::ScaleFactor LayoutDeviceToLayerScale; typedef gfx::ScaleFactor LayoutDeviceToScreenScale; typedef gfx::ScaleFactor LayoutDeviceToParentLayerScale; typedef gfx::ScaleFactor LayerToCSSScale; typedef gfx::ScaleFactor LayerToLayoutDeviceScale; typedef gfx::ScaleFactor LayerToRenderTargetScale; typedef gfx::ScaleFactor LayerToScreenScale; typedef gfx::ScaleFactor LayerToParentLayerScale; typedef gfx::ScaleFactor RenderTargetToScreenScale; typedef gfx::ScaleFactor ScreenToCSSScale; typedef gfx::ScaleFactor ScreenToLayoutDeviceScale; typedef gfx::ScaleFactor ScreenToLayerScale; typedef gfx::ScaleFactor ScreenToParentLayerScale; typedef gfx::ScaleFactor ParentLayerToLayerScale; typedef gfx::ScaleFactor ParentLayerToScreenScale; typedef gfx::ScaleFactor ParentLayerToParentLayerScale; typedef gfx::ScaleFactors2D CSSToLayoutDeviceScale2D; typedef gfx::ScaleFactors2D CSSToLayerScale2D; typedef gfx::ScaleFactors2D CSSToScreenScale2D; typedef gfx::ScaleFactors2D CSSToParentLayerScale2D; typedef gfx::ScaleFactors2D LayoutDeviceToCSSScale2D; typedef gfx::ScaleFactors2D LayoutDeviceToLayerScale2D; typedef gfx::ScaleFactors2D LayoutDeviceToScreenScale2D; typedef gfx::ScaleFactors2D LayoutDeviceToParentLayerScale2D; typedef gfx::ScaleFactors2D LayerToCSSScale2D; typedef gfx::ScaleFactors2D LayerToLayoutDeviceScale2D; typedef gfx::ScaleFactors2D LayerToRenderTargetScale2D; typedef gfx::ScaleFactors2D LayerToScreenScale2D; typedef gfx::ScaleFactors2D LayerToParentLayerScale2D; typedef gfx::ScaleFactors2D RenderTargetToScreenScale2D; typedef gfx::ScaleFactors2D ScreenToCSSScale2D; typedef gfx::ScaleFactors2D ScreenToLayoutDeviceScale2D; typedef gfx::ScaleFactors2D ScreenToLayerScale2D; typedef gfx::ScaleFactors2D ScreenToParentLayerScale2D; typedef gfx::ScaleFactors2D ParentLayerToLayerScale2D; typedef gfx::ScaleFactors2D ParentLayerToScreenScale2D; typedef gfx::ScaleFactors2D ParentLayerToParentLayerScale2D; /* * The pixels that content authors use to specify sizes in. */ struct CSSPixel { // Conversions from app units static CSSPoint FromAppUnits(const nsPoint& aPoint) { return CSSPoint(NSAppUnitsToFloatPixels(aPoint.x, float(AppUnitsPerCSSPixel())), NSAppUnitsToFloatPixels(aPoint.y, float(AppUnitsPerCSSPixel()))); } static CSSSize FromAppUnits(const nsSize& aSize) { return CSSSize(NSAppUnitsToFloatPixels(aSize.width, float(AppUnitsPerCSSPixel())), NSAppUnitsToFloatPixels(aSize.height, float(AppUnitsPerCSSPixel()))); } static CSSRect FromAppUnits(const nsRect& aRect) { return CSSRect(NSAppUnitsToFloatPixels(aRect.x, float(AppUnitsPerCSSPixel())), NSAppUnitsToFloatPixels(aRect.y, float(AppUnitsPerCSSPixel())), NSAppUnitsToFloatPixels(aRect.width, float(AppUnitsPerCSSPixel())), NSAppUnitsToFloatPixels(aRect.height, float(AppUnitsPerCSSPixel()))); } static CSSMargin FromAppUnits(const nsMargin& aMargin) { return CSSMargin(NSAppUnitsToFloatPixels(aMargin.top, float(AppUnitsPerCSSPixel())), NSAppUnitsToFloatPixels(aMargin.right, float(AppUnitsPerCSSPixel())), NSAppUnitsToFloatPixels(aMargin.bottom, float(AppUnitsPerCSSPixel())), NSAppUnitsToFloatPixels(aMargin.left, float(AppUnitsPerCSSPixel()))); } static CSSIntPoint FromAppUnitsRounded(const nsPoint& aPoint) { return CSSIntPoint(NSAppUnitsToIntPixels(aPoint.x, float(AppUnitsPerCSSPixel())), NSAppUnitsToIntPixels(aPoint.y, float(AppUnitsPerCSSPixel()))); } static CSSIntSize FromAppUnitsRounded(const nsSize& aSize) { return CSSIntSize(NSAppUnitsToIntPixels(aSize.width, float(AppUnitsPerCSSPixel())), NSAppUnitsToIntPixels(aSize.height, float(AppUnitsPerCSSPixel()))); } static CSSIntRect FromAppUnitsRounded(const nsRect& aRect) { return CSSIntRect(NSAppUnitsToIntPixels(aRect.x, float(AppUnitsPerCSSPixel())), NSAppUnitsToIntPixels(aRect.y, float(AppUnitsPerCSSPixel())), NSAppUnitsToIntPixels(aRect.width, float(AppUnitsPerCSSPixel())), NSAppUnitsToIntPixels(aRect.height, float(AppUnitsPerCSSPixel()))); } // Conversions to app units static nsPoint ToAppUnits(const CSSPoint& aPoint) { return nsPoint(NSToCoordRoundWithClamp(aPoint.x * float(AppUnitsPerCSSPixel())), NSToCoordRoundWithClamp(aPoint.y * float(AppUnitsPerCSSPixel()))); } static nsPoint ToAppUnits(const CSSIntPoint& aPoint) { return nsPoint(NSToCoordRoundWithClamp(float(aPoint.x) * float(AppUnitsPerCSSPixel())), NSToCoordRoundWithClamp(float(aPoint.y) * float(AppUnitsPerCSSPixel()))); } static nsSize ToAppUnits(const CSSIntSize& aSize) { return nsSize(NSToCoordRoundWithClamp(float(aSize.width) * float(AppUnitsPerCSSPixel())), NSToCoordRoundWithClamp(float(aSize.height) * float(AppUnitsPerCSSPixel()))); } static nsRect ToAppUnits(const CSSRect& aRect) { return nsRect(NSToCoordRoundWithClamp(aRect.x * float(AppUnitsPerCSSPixel())), NSToCoordRoundWithClamp(aRect.y * float(AppUnitsPerCSSPixel())), NSToCoordRoundWithClamp(aRect.width * float(AppUnitsPerCSSPixel())), NSToCoordRoundWithClamp(aRect.height * float(AppUnitsPerCSSPixel()))); } }; /* * The pixels that are referred to as "device pixels" in layout code. In * general values measured in LayoutDevicePixels are obtained by dividing a * value in app units by AppUnitsPerDevPixel(). Conversion between CSS pixels * and LayoutDevicePixels is affected by: * 1) the "full zoom" (see nsPresContext::SetFullZoom) * 2) the "widget scale" (see nsIWidget::GetDefaultScale) */ struct LayoutDevicePixel { static LayoutDeviceIntPoint FromUntyped(const nsIntPoint& aPoint) { return LayoutDeviceIntPoint(aPoint.x, aPoint.y); } static nsIntPoint ToUntyped(const LayoutDeviceIntPoint& aPoint) { return nsIntPoint(aPoint.x, aPoint.y); } static LayoutDeviceIntRect FromUntyped(const nsIntRect& aRect) { return LayoutDeviceIntRect(aRect.x, aRect.y, aRect.width, aRect.height); } static nsIntRect ToUntyped(const LayoutDeviceIntRect& aRect) { return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height); } static LayoutDeviceRect FromAppUnits(const nsRect& aRect, nscoord aAppUnitsPerDevPixel) { return LayoutDeviceRect(NSAppUnitsToFloatPixels(aRect.x, float(aAppUnitsPerDevPixel)), NSAppUnitsToFloatPixels(aRect.y, float(aAppUnitsPerDevPixel)), NSAppUnitsToFloatPixels(aRect.width, float(aAppUnitsPerDevPixel)), NSAppUnitsToFloatPixels(aRect.height, float(aAppUnitsPerDevPixel))); } static LayoutDevicePoint FromAppUnits(const nsPoint& aPoint, nscoord aAppUnitsPerDevPixel) { return LayoutDevicePoint(NSAppUnitsToFloatPixels(aPoint.x, aAppUnitsPerDevPixel), NSAppUnitsToFloatPixels(aPoint.y, aAppUnitsPerDevPixel)); } static LayoutDeviceIntPoint FromAppUnitsRounded(const nsPoint& aPoint, nscoord aAppUnitsPerDevPixel) { return LayoutDeviceIntPoint(NSAppUnitsToIntPixels(aPoint.x, aAppUnitsPerDevPixel), NSAppUnitsToIntPixels(aPoint.y, aAppUnitsPerDevPixel)); } static LayoutDeviceIntPoint FromAppUnitsToNearest(const nsPoint& aPoint, nscoord aAppUnitsPerDevPixel) { return FromUntyped(aPoint.ToNearestPixels(aAppUnitsPerDevPixel)); } static LayoutDeviceIntRect FromAppUnitsToNearest(const nsRect& aRect, nscoord aAppUnitsPerDevPixel) { return FromUntyped(aRect.ToNearestPixels(aAppUnitsPerDevPixel)); } static LayoutDeviceIntSize FromAppUnitsRounded(const nsSize& aSize, nscoord aAppUnitsPerDevPixel) { return LayoutDeviceIntSize( NSAppUnitsToIntPixels(aSize.width, aAppUnitsPerDevPixel), NSAppUnitsToIntPixels(aSize.height, aAppUnitsPerDevPixel)); } static nsSize ToAppUnits(const LayoutDeviceIntSize& aSize, nscoord aAppUnitsPerDevPixel) { return nsSize(aSize.width * aAppUnitsPerDevPixel, aSize.height * aAppUnitsPerDevPixel); } static nsSize ToAppUnits(const LayoutDeviceSize& aSize, nscoord aAppUnitsPerDevPixel) { return nsSize(NSFloatPixelsToAppUnits(aSize.width, aAppUnitsPerDevPixel), NSFloatPixelsToAppUnits(aSize.height, aAppUnitsPerDevPixel)); } static nsRect ToAppUnits(const LayoutDeviceRect& aRect, nscoord aAppUnitsPerDevPixel) { return nsRect(NSFloatPixelsToAppUnits(aRect.x, aAppUnitsPerDevPixel), NSFloatPixelsToAppUnits(aRect.y, aAppUnitsPerDevPixel), NSFloatPixelsToAppUnits(aRect.width, aAppUnitsPerDevPixel), NSFloatPixelsToAppUnits(aRect.height, aAppUnitsPerDevPixel)); } }; /* * The pixels that layout rasterizes and delivers to the graphics code. * These also are generally referred to as "device pixels" in layout code. * Conversion between CSS pixels and LayerPixels is affected by: * 1) the "display resolution" (see nsIPresShell::SetResolution) * 2) the "full zoom" (see nsPresContext::SetFullZoom) * 3) the "widget scale" (see nsIWidget::GetDefaultScale) * 4) rasterizing at a different scale in the presence of some CSS transforms */ struct LayerPixel { static nsIntRect ToUntyped(const LayerIntRect& aRect) { return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height); } static nsIntPoint ToUntyped(const LayerIntPoint& aPoint) { return nsIntPoint(aPoint.x, aPoint.y); } static gfx::IntRect ToUnknown(const LayerIntRect& aRect) { return gfx::IntRect(aRect.x, aRect.y, aRect.width, aRect.height); } static gfx::Rect ToUnknown(const LayerRect& aRect) { return gfx::Rect(aRect.x, aRect.y, aRect.width, aRect.height); } static LayerIntRect FromUntyped(const nsIntRect& aRect) { return LayerIntRect(aRect.x, aRect.y, aRect.width, aRect.height); } static LayerIntPoint FromUntyped(const nsIntPoint& aPoint) { return LayerIntPoint(aPoint.x, aPoint.y); } }; /* * Layers are always composited to a render target. This unit * represents one pixel in the render target. Note that for the * root render target RenderTargetPixel == ScreenPixel. Also * any ContainerLayer providing an intermediate surface will * have RenderTargetPixel == LayerPixel. */ struct RenderTargetPixel { static nsIntPoint ToUntyped(const RenderTargetIntPoint& aPoint) { return nsIntPoint(aPoint.x, aPoint.y); } static nsIntRect ToUntyped(const RenderTargetIntRect& aRect) { return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height); } static gfx::IntRect ToUnknown(const RenderTargetIntRect& aRect) { return gfx::IntRect(aRect.x, aRect.y, aRect.width, aRect.height); } static gfx::Rect ToUnknown(const RenderTargetRect& aRect) { return gfx::Rect(aRect.x, aRect.y, aRect.width, aRect.height); } static RenderTargetRect FromUnknown(const gfx::Rect& aRect) { return RenderTargetRect(aRect.x, aRect.y, aRect.width, aRect.height); } static RenderTargetIntRect FromUntyped(const nsIntRect& aRect) { return RenderTargetIntRect(aRect.x, aRect.y, aRect.width, aRect.height); } }; /* * The pixels that are displayed on the screen. * On non-OMTC platforms this should be equivalent to LayerPixel units. * On OMTC platforms these may diverge from LayerPixel units temporarily, * while an asynchronous zoom is happening, but should eventually converge * back to LayerPixel units. Some variables (such as those representing * chrome UI element sizes) that are not subject to content zoom should * generally be represented in ScreenPixel units. */ struct ScreenPixel { static nsIntSize ToUntyped(const ScreenIntSize& aSize) { return nsIntSize(aSize.width, aSize.height); } static ScreenIntPoint FromUntyped(const nsIntPoint& aPoint) { return ScreenIntPoint(aPoint.x, aPoint.y); } }; /* The layer coordinates of the parent frame. * This can be arrived at in three ways: * - Start with the CSS coordinates of the parent frame, multiply by the * device scale and the cumulative resolution of the parent frame. * - Start with the CSS coordinates of current frame, multiply by the device * scale, the cumulative resolution of the current frame, and the scales * from the CSS and async transforms of the current frame. * - Start with global screen coordinates and unapply all CSS and async * transforms from the root down to and including the parent. * It's helpful to look at https://wiki.mozilla.org/Platform/GFX/APZ#Coordinate_systems * to get a picture of how the various coordinate systems relate to each other. */ struct ParentLayerPixel { static nsIntRect ToUntyped(const ParentLayerIntRect& aRect) { return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height); } }; // Operators to apply ScaleFactors directly to Coords, Points, Rects, Sizes and Margins template gfx::CoordTyped operator*(const gfx::CoordTyped& aCoord, const gfx::ScaleFactor& aScale) { return gfx::CoordTyped(aCoord.value * aScale.scale); } template gfx::CoordTyped operator/(const gfx::CoordTyped& aCoord, const gfx::ScaleFactor& aScale) { return gfx::CoordTyped(aCoord.value / aScale.scale); } template gfx::PointTyped operator*(const gfx::PointTyped& aPoint, const gfx::ScaleFactor& aScale) { return gfx::PointTyped(aPoint.x * aScale.scale, aPoint.y * aScale.scale); } template gfx::PointTyped operator/(const gfx::PointTyped& aPoint, const gfx::ScaleFactor& aScale) { return gfx::PointTyped(aPoint.x / aScale.scale, aPoint.y / aScale.scale); } template gfx::PointTyped operator*(const gfx::PointTyped& aPoint, const gfx::ScaleFactors2D& aScale) { return gfx::PointTyped(aPoint.x * aScale.xScale, aPoint.y * aScale.yScale); } template gfx::PointTyped operator/(const gfx::PointTyped& aPoint, const gfx::ScaleFactors2D& aScale) { return gfx::PointTyped(aPoint.x / aScale.xScale, aPoint.y / aScale.yScale); } template gfx::RectTyped operator*(const gfx::RectTyped& aRect, const gfx::ScaleFactor& aScale) { return gfx::RectTyped(aRect.x * aScale.scale, aRect.y * aScale.scale, aRect.width * aScale.scale, aRect.height * aScale.scale); } template gfx::RectTyped operator/(const gfx::RectTyped& aRect, const gfx::ScaleFactor& aScale) { return gfx::RectTyped(aRect.x / aScale.scale, aRect.y / aScale.scale, aRect.width / aScale.scale, aRect.height / aScale.scale); } template gfx::RectTyped operator*(const gfx::RectTyped& aRect, const gfx::ScaleFactors2D& aScale) { return gfx::RectTyped(aRect.x * aScale.xScale, aRect.y * aScale.yScale, aRect.width * aScale.xScale, aRect.height * aScale.yScale); } template gfx::RectTyped operator/(const gfx::RectTyped& aRect, const gfx::ScaleFactors2D& aScale) { return gfx::RectTyped(aRect.x / aScale.xScale, aRect.y / aScale.yScale, aRect.width / aScale.xScale, aRect.height / aScale.yScale); } template gfx::RectTyped operator*(const gfx::IntRectTyped& aRect, const gfx::ScaleFactor& aScale) { return gfx::RectTyped(float(aRect.x) * aScale.scale, float(aRect.y) * aScale.scale, float(aRect.width) * aScale.scale, float(aRect.height) * aScale.scale); } template gfx::RectTyped operator/(const gfx::IntRectTyped& aRect, const gfx::ScaleFactor& aScale) { return gfx::RectTyped(float(aRect.x) / aScale.scale, float(aRect.y) / aScale.scale, float(aRect.width) / aScale.scale, float(aRect.height) / aScale.scale); } template gfx::RectTyped operator*(const gfx::IntRectTyped& aRect, const gfx::ScaleFactors2D& aScale) { return gfx::RectTyped(float(aRect.x) * aScale.xScale, float(aRect.y) * aScale.yScale, float(aRect.width) * aScale.xScale, float(aRect.height) * aScale.yScale); } template gfx::RectTyped operator/(const gfx::IntRectTyped& aRect, const gfx::ScaleFactors2D& aScale) { return gfx::RectTyped(float(aRect.x) / aScale.xScale, float(aRect.y) / aScale.yScale, float(aRect.width) / aScale.xScale, float(aRect.height) / aScale.yScale); } template gfx::SizeTyped operator*(const gfx::SizeTyped& aSize, const gfx::ScaleFactor& aScale) { return gfx::SizeTyped(aSize.width * aScale.scale, aSize.height * aScale.scale); } template gfx::SizeTyped operator/(const gfx::SizeTyped& aSize, const gfx::ScaleFactor& aScale) { return gfx::SizeTyped(aSize.width / aScale.scale, aSize.height / aScale.scale); } template gfx::SizeTyped operator*(const gfx::SizeTyped& aSize, const gfx::ScaleFactors2D& aScale) { return gfx::SizeTyped(aSize.width * aScale.xScale, aSize.height * aScale.yScale); } template gfx::SizeTyped operator/(const gfx::SizeTyped& aSize, const gfx::ScaleFactors2D& aScale) { return gfx::SizeTyped(aSize.width / aScale.xScale, aSize.height / aScale.yScale); } template gfx::SizeTyped operator*(const gfx::IntSizeTyped& aSize, const gfx::ScaleFactor& aScale) { return gfx::SizeTyped(float(aSize.width) * aScale.scale, float(aSize.height) * aScale.scale); } template gfx::SizeTyped operator/(const gfx::IntSizeTyped& aSize, const gfx::ScaleFactor& aScale) { return gfx::SizeTyped(float(aSize.width) / aScale.scale, float(aSize.height) / aScale.scale); } template gfx::SizeTyped operator*(const gfx::IntSizeTyped& aSize, const gfx::ScaleFactors2D& aScale) { return gfx::SizeTyped(float(aSize.width) * aScale.xScale, float(aSize.height) * aScale.yScale); } template gfx::SizeTyped operator/(const gfx::IntSizeTyped& aSize, const gfx::ScaleFactors2D& aScale) { return gfx::SizeTyped(float(aSize.width) / aScale.xScale, float(aSize.height) / aScale.yScale); } template gfx::MarginTyped operator*(const gfx::MarginTyped& aMargin, const gfx::ScaleFactor& aScale) { return gfx::MarginTyped(aMargin.top * aScale.scale, aMargin.right * aScale.scale, aMargin.bottom * aScale.scale, aMargin.left * aScale.scale); } template gfx::MarginTyped operator/(const gfx::MarginTyped& aMargin, const gfx::ScaleFactor& aScale) { return gfx::MarginTyped(aMargin.top / aScale.scale, aMargin.right / aScale.scale, aMargin.bottom / aScale.scale, aMargin.left / aScale.scale); } template gfx::MarginTyped operator*(const gfx::MarginTyped& aMargin, const gfx::ScaleFactors2D& aScale) { return gfx::MarginTyped(aMargin.top * aScale.yScale, aMargin.right * aScale.xScale, aMargin.bottom * aScale.yScale, aMargin.left * aScale.xScale); } template gfx::MarginTyped operator/(const gfx::MarginTyped& aMargin, const gfx::ScaleFactors2D& aScale) { return gfx::MarginTyped(aMargin.top / aScale.yScale, aMargin.right / aScale.xScale, aMargin.bottom / aScale.yScale, aMargin.left / aScale.xScale); } // Calculate the max or min or the ratios of the widths and heights of two // sizes, returning a scale factor in the correct units. template gfx::ScaleFactor MaxScaleRatio(const gfx::SizeTyped& aDestSize, const gfx::SizeTyped& aSrcSize) { return gfx::ScaleFactor(std::max(aDestSize.width / aSrcSize.width, aDestSize.height / aSrcSize.height)); } template gfx::ScaleFactor MinScaleRatio(const gfx::SizeTyped& aDestSize, const gfx::SizeTyped& aSrcSize) { return gfx::ScaleFactor(std::min(aDestSize.width / aSrcSize.width, aDestSize.height / aSrcSize.height)); } } // namespace mozilla #endif