/work/obj-fuzz/dist/include/nsSize.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef NSSIZE_H |
8 | | #define NSSIZE_H |
9 | | |
10 | | #include "nsCoord.h" |
11 | | #include "mozilla/gfx/BaseSize.h" |
12 | | #include "mozilla/gfx/Point.h" |
13 | | |
14 | | // Maximum allowable size |
15 | 0 | #define NS_MAXSIZE nscoord_MAX |
16 | | |
17 | | typedef mozilla::gfx::IntSize nsIntSize; |
18 | | |
19 | | struct nsSize : public mozilla::gfx::BaseSize<nscoord, nsSize> { |
20 | | typedef mozilla::gfx::BaseSize<nscoord, nsSize> Super; |
21 | | |
22 | 0 | nsSize() : Super() {} |
23 | 0 | nsSize(nscoord aWidth, nscoord aHeight) : Super(aWidth, aHeight) {} |
24 | | |
25 | | inline mozilla::gfx::IntSize ScaleToNearestPixels(float aXScale, float aYScale, |
26 | | nscoord aAppUnitsPerPixel) const; |
27 | | inline mozilla::gfx::IntSize ToNearestPixels(nscoord aAppUnitsPerPixel) const; |
28 | | |
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 |
33 | | */ |
34 | | MOZ_MUST_USE inline nsSize |
35 | | ScaleToOtherAppUnits(int32_t aFromAPP, int32_t aToAPP) const; |
36 | | }; |
37 | | |
38 | | inline mozilla::gfx::IntSize |
39 | | nsSize::ScaleToNearestPixels(float aXScale, float aYScale, |
40 | | nscoord aAppUnitsPerPixel) const |
41 | 0 | { |
42 | 0 | return mozilla::gfx::IntSize( |
43 | 0 | NSToIntRoundUp(NSAppUnitsToDoublePixels(width, aAppUnitsPerPixel) * aXScale), |
44 | 0 | NSToIntRoundUp(NSAppUnitsToDoublePixels(height, aAppUnitsPerPixel) * aYScale)); |
45 | 0 | } |
46 | | |
47 | | inline mozilla::gfx::IntSize |
48 | | nsSize::ToNearestPixels(nscoord aAppUnitsPerPixel) const |
49 | 0 | { |
50 | 0 | return ScaleToNearestPixels(1.0f, 1.0f, aAppUnitsPerPixel); |
51 | 0 | } |
52 | | |
53 | | inline nsSize |
54 | 0 | nsSize::ScaleToOtherAppUnits(int32_t aFromAPP, int32_t aToAPP) const { |
55 | 0 | if (aFromAPP != aToAPP) { |
56 | 0 | nsSize size; |
57 | 0 | size.width = NSToCoordRound(NSCoordScale(width, aFromAPP, aToAPP)); |
58 | 0 | size.height = NSToCoordRound(NSCoordScale(height, aFromAPP, aToAPP)); |
59 | 0 | return size; |
60 | 0 | } |
61 | 0 | return *this; |
62 | 0 | } |
63 | | |
64 | | inline nsSize |
65 | | IntSizeToAppUnits(mozilla::gfx::IntSize aSize, nscoord aAppUnitsPerPixel) |
66 | 0 | { |
67 | 0 | return nsSize(NSIntPixelsToAppUnits(aSize.width, aAppUnitsPerPixel), |
68 | 0 | NSIntPixelsToAppUnits(aSize.height, aAppUnitsPerPixel)); |
69 | 0 | } |
70 | | |
71 | | #endif /* NSSIZE_H */ |