1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/src/nsSize.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef NSSIZE_H 1.10 +#define NSSIZE_H 1.11 + 1.12 +#include "nsCoord.h" 1.13 +#include "mozilla/gfx/BaseSize.h" 1.14 +#include "mozilla/gfx/Point.h" 1.15 + 1.16 +// Maximum allowable size 1.17 +#define NS_MAXSIZE nscoord_MAX 1.18 + 1.19 +struct nsIntSize; 1.20 +typedef nsIntSize gfxIntSize; 1.21 + 1.22 +struct nsSize : public mozilla::gfx::BaseSize<nscoord, nsSize> { 1.23 + typedef mozilla::gfx::BaseSize<nscoord, nsSize> Super; 1.24 + 1.25 + nsSize() : Super() {} 1.26 + nsSize(nscoord aWidth, nscoord aHeight) : Super(aWidth, aHeight) {} 1.27 + 1.28 + inline nsIntSize ScaleToNearestPixels(float aXScale, float aYScale, 1.29 + nscoord aAppUnitsPerPixel) const; 1.30 + inline nsIntSize ToNearestPixels(nscoord aAppUnitsPerPixel) const; 1.31 + 1.32 + // Converts this size from aFromAPP, an appunits per pixel ratio, to aToAPP. 1.33 + inline nsSize ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const; 1.34 +}; 1.35 + 1.36 +struct nsIntSize : public mozilla::gfx::BaseSize<int32_t, nsIntSize> { 1.37 + typedef mozilla::gfx::BaseSize<int32_t, nsIntSize> Super; 1.38 + 1.39 + nsIntSize() : Super() {} 1.40 + nsIntSize(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {} 1.41 + 1.42 + inline nsSize ToAppUnits(nscoord aAppUnitsPerPixel) const; 1.43 + mozilla::gfx::IntSize ToIntSize() const 1.44 + { 1.45 + return mozilla::gfx::IntSize(width, height); 1.46 + }; 1.47 +}; 1.48 + 1.49 +inline nsIntSize 1.50 +nsSize::ScaleToNearestPixels(float aXScale, float aYScale, 1.51 + nscoord aAppUnitsPerPixel) const 1.52 +{ 1.53 + return nsIntSize( 1.54 + NSToIntRoundUp(NSAppUnitsToDoublePixels(width, aAppUnitsPerPixel) * aXScale), 1.55 + NSToIntRoundUp(NSAppUnitsToDoublePixels(height, aAppUnitsPerPixel) * aYScale)); 1.56 +} 1.57 + 1.58 +inline nsIntSize 1.59 +nsSize::ToNearestPixels(nscoord aAppUnitsPerPixel) const 1.60 +{ 1.61 + return ScaleToNearestPixels(1.0f, 1.0f, aAppUnitsPerPixel); 1.62 +} 1.63 + 1.64 +inline nsSize 1.65 +nsSize::ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const { 1.66 + if (aFromAPP != aToAPP) { 1.67 + nsSize size; 1.68 + size.width = NSToCoordRound(NSCoordScale(width, aFromAPP, aToAPP)); 1.69 + size.height = NSToCoordRound(NSCoordScale(height, aFromAPP, aToAPP)); 1.70 + return size; 1.71 + } 1.72 + return *this; 1.73 +} 1.74 + 1.75 +inline nsSize 1.76 +nsIntSize::ToAppUnits(nscoord aAppUnitsPerPixel) const 1.77 +{ 1.78 + return nsSize(NSIntPixelsToAppUnits(width, aAppUnitsPerPixel), 1.79 + NSIntPixelsToAppUnits(height, aAppUnitsPerPixel)); 1.80 +} 1.81 + 1.82 +#endif /* NSSIZE_H */