1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 #include "mozilla/gfx/BaseSize.h"
12 #include "mozilla/gfx/Point.h"
14 // Maximum allowable size
15 #define NS_MAXSIZE nscoord_MAX
17 typedef mozilla::gfx::IntSize nsIntSize
;
19 struct nsSize
: public mozilla::gfx::BaseSize
<nscoord
, nsSize
> {
20 typedef mozilla::gfx::BaseSize
<nscoord
, nsSize
> Super
;
22 constexpr nsSize() : Super() {}
23 constexpr nsSize(nscoord aWidth
, nscoord aHeight
) : Super(aWidth
, aHeight
) {}
25 inline mozilla::gfx::IntSize
ScaleToNearestPixels(
26 float aXScale
, float aYScale
, nscoord aAppUnitsPerPixel
) const;
27 inline mozilla::gfx::IntSize
ToNearestPixels(nscoord aAppUnitsPerPixel
) const;
30 * Return this size scaled to a different appunits per pixel (APP) ratio.
31 * @param aFromAPP the APP to scale from
32 * @param aToAPP the APP to scale to
34 [[nodiscard
]] inline nsSize
ScaleToOtherAppUnits(int32_t aFromAPP
,
35 int32_t aToAPP
) const;
38 inline mozilla::gfx::IntSize
nsSize::ScaleToNearestPixels(
39 float aXScale
, float aYScale
, nscoord aAppUnitsPerPixel
) const {
40 return mozilla::gfx::IntSize(
41 NSToIntRoundUp(NSAppUnitsToDoublePixels(width
, aAppUnitsPerPixel
) *
43 NSToIntRoundUp(NSAppUnitsToDoublePixels(height
, aAppUnitsPerPixel
) *
47 inline mozilla::gfx::IntSize
nsSize::ToNearestPixels(
48 nscoord aAppUnitsPerPixel
) const {
49 return ScaleToNearestPixels(1.0f
, 1.0f
, aAppUnitsPerPixel
);
52 inline nsSize
nsSize::ScaleToOtherAppUnits(int32_t aFromAPP
,
53 int32_t aToAPP
) const {
54 if (aFromAPP
!= aToAPP
) {
56 size
.width
= NSToCoordRound(NSCoordScale(width
, aFromAPP
, aToAPP
));
57 size
.height
= NSToCoordRound(NSCoordScale(height
, aFromAPP
, aToAPP
));
63 inline nsSize
IntSizeToAppUnits(mozilla::gfx::IntSize aSize
,
64 nscoord aAppUnitsPerPixel
) {
65 return nsSize(NSIntPixelsToAppUnits(aSize
.width
, aAppUnitsPerPixel
),
66 NSIntPixelsToAppUnits(aSize
.height
, aAppUnitsPerPixel
));