|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef NSSIZE_H |
|
7 #define NSSIZE_H |
|
8 |
|
9 #include "nsCoord.h" |
|
10 #include "mozilla/gfx/BaseSize.h" |
|
11 #include "mozilla/gfx/Point.h" |
|
12 |
|
13 // Maximum allowable size |
|
14 #define NS_MAXSIZE nscoord_MAX |
|
15 |
|
16 struct nsIntSize; |
|
17 typedef nsIntSize gfxIntSize; |
|
18 |
|
19 struct nsSize : public mozilla::gfx::BaseSize<nscoord, nsSize> { |
|
20 typedef mozilla::gfx::BaseSize<nscoord, nsSize> Super; |
|
21 |
|
22 nsSize() : Super() {} |
|
23 nsSize(nscoord aWidth, nscoord aHeight) : Super(aWidth, aHeight) {} |
|
24 |
|
25 inline nsIntSize ScaleToNearestPixels(float aXScale, float aYScale, |
|
26 nscoord aAppUnitsPerPixel) const; |
|
27 inline nsIntSize ToNearestPixels(nscoord aAppUnitsPerPixel) const; |
|
28 |
|
29 // Converts this size from aFromAPP, an appunits per pixel ratio, to aToAPP. |
|
30 inline nsSize ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const; |
|
31 }; |
|
32 |
|
33 struct nsIntSize : public mozilla::gfx::BaseSize<int32_t, nsIntSize> { |
|
34 typedef mozilla::gfx::BaseSize<int32_t, nsIntSize> Super; |
|
35 |
|
36 nsIntSize() : Super() {} |
|
37 nsIntSize(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {} |
|
38 |
|
39 inline nsSize ToAppUnits(nscoord aAppUnitsPerPixel) const; |
|
40 mozilla::gfx::IntSize ToIntSize() const |
|
41 { |
|
42 return mozilla::gfx::IntSize(width, height); |
|
43 }; |
|
44 }; |
|
45 |
|
46 inline nsIntSize |
|
47 nsSize::ScaleToNearestPixels(float aXScale, float aYScale, |
|
48 nscoord aAppUnitsPerPixel) const |
|
49 { |
|
50 return nsIntSize( |
|
51 NSToIntRoundUp(NSAppUnitsToDoublePixels(width, aAppUnitsPerPixel) * aXScale), |
|
52 NSToIntRoundUp(NSAppUnitsToDoublePixels(height, aAppUnitsPerPixel) * aYScale)); |
|
53 } |
|
54 |
|
55 inline nsIntSize |
|
56 nsSize::ToNearestPixels(nscoord aAppUnitsPerPixel) const |
|
57 { |
|
58 return ScaleToNearestPixels(1.0f, 1.0f, aAppUnitsPerPixel); |
|
59 } |
|
60 |
|
61 inline nsSize |
|
62 nsSize::ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const { |
|
63 if (aFromAPP != aToAPP) { |
|
64 nsSize size; |
|
65 size.width = NSToCoordRound(NSCoordScale(width, aFromAPP, aToAPP)); |
|
66 size.height = NSToCoordRound(NSCoordScale(height, aFromAPP, aToAPP)); |
|
67 return size; |
|
68 } |
|
69 return *this; |
|
70 } |
|
71 |
|
72 inline nsSize |
|
73 nsIntSize::ToAppUnits(nscoord aAppUnitsPerPixel) const |
|
74 { |
|
75 return nsSize(NSIntPixelsToAppUnits(width, aAppUnitsPerPixel), |
|
76 NSIntPixelsToAppUnits(height, aAppUnitsPerPixel)); |
|
77 } |
|
78 |
|
79 #endif /* NSSIZE_H */ |