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