Bug 1891710: part 2) Enable <Element-outerHTML.html> WPT for Trusted Types. r=smaug
[gecko.git] / gfx / src / nsSize.h
blobdf1fa5570e461ae0dd4a6b0fb2256392b682afb3
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/. */
7 #ifndef NSSIZE_H
8 #define NSSIZE_H
10 #include "nsCoord.h"
11 #include "mozilla/gfx/BaseSize.h"
12 #include "mozilla/gfx/Point.h"
14 // Maximum allowable size
15 inline constexpr nscoord 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() {}
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;
29 /**
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) *
42 aXScale),
43 NSToIntRoundUp(NSAppUnitsToDoublePixels(height, aAppUnitsPerPixel) *
44 aYScale));
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) {
55 nsSize size;
56 size.width = NSToCoordRound(NSCoordScale(width, aFromAPP, aToAPP));
57 size.height = NSToCoordRound(NSCoordScale(height, aFromAPP, aToAPP));
58 return size;
60 return *this;
63 inline nsSize IntSizeToAppUnits(mozilla::gfx::IntSize aSize,
64 nscoord aAppUnitsPerPixel) {
65 return nsSize(NSIntPixelsToAppUnits(aSize.width, aAppUnitsPerPixel),
66 NSIntPixelsToAppUnits(aSize.height, aAppUnitsPerPixel));
69 #endif /* NSSIZE_H */