michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NSSIZE_H michael@0: #define NSSIZE_H michael@0: michael@0: #include "nsCoord.h" michael@0: #include "mozilla/gfx/BaseSize.h" michael@0: #include "mozilla/gfx/Point.h" michael@0: michael@0: // Maximum allowable size michael@0: #define NS_MAXSIZE nscoord_MAX michael@0: michael@0: struct nsIntSize; michael@0: typedef nsIntSize gfxIntSize; michael@0: michael@0: struct nsSize : public mozilla::gfx::BaseSize { michael@0: typedef mozilla::gfx::BaseSize Super; michael@0: michael@0: nsSize() : Super() {} michael@0: nsSize(nscoord aWidth, nscoord aHeight) : Super(aWidth, aHeight) {} michael@0: michael@0: inline nsIntSize ScaleToNearestPixels(float aXScale, float aYScale, michael@0: nscoord aAppUnitsPerPixel) const; michael@0: inline nsIntSize ToNearestPixels(nscoord aAppUnitsPerPixel) const; michael@0: michael@0: // Converts this size from aFromAPP, an appunits per pixel ratio, to aToAPP. michael@0: inline nsSize ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const; michael@0: }; michael@0: michael@0: struct nsIntSize : public mozilla::gfx::BaseSize { michael@0: typedef mozilla::gfx::BaseSize Super; michael@0: michael@0: nsIntSize() : Super() {} michael@0: nsIntSize(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {} michael@0: michael@0: inline nsSize ToAppUnits(nscoord aAppUnitsPerPixel) const; michael@0: mozilla::gfx::IntSize ToIntSize() const michael@0: { michael@0: return mozilla::gfx::IntSize(width, height); michael@0: }; michael@0: }; michael@0: michael@0: inline nsIntSize michael@0: nsSize::ScaleToNearestPixels(float aXScale, float aYScale, michael@0: nscoord aAppUnitsPerPixel) const michael@0: { michael@0: return nsIntSize( michael@0: NSToIntRoundUp(NSAppUnitsToDoublePixels(width, aAppUnitsPerPixel) * aXScale), michael@0: NSToIntRoundUp(NSAppUnitsToDoublePixels(height, aAppUnitsPerPixel) * aYScale)); michael@0: } michael@0: michael@0: inline nsIntSize michael@0: nsSize::ToNearestPixels(nscoord aAppUnitsPerPixel) const michael@0: { michael@0: return ScaleToNearestPixels(1.0f, 1.0f, aAppUnitsPerPixel); michael@0: } michael@0: michael@0: inline nsSize michael@0: nsSize::ConvertAppUnits(int32_t aFromAPP, int32_t aToAPP) const { michael@0: if (aFromAPP != aToAPP) { michael@0: nsSize size; michael@0: size.width = NSToCoordRound(NSCoordScale(width, aFromAPP, aToAPP)); michael@0: size.height = NSToCoordRound(NSCoordScale(height, aFromAPP, aToAPP)); michael@0: return size; michael@0: } michael@0: return *this; michael@0: } michael@0: michael@0: inline nsSize michael@0: nsIntSize::ToAppUnits(nscoord aAppUnitsPerPixel) const michael@0: { michael@0: return nsSize(NSIntPixelsToAppUnits(width, aAppUnitsPerPixel), michael@0: NSIntPixelsToAppUnits(height, aAppUnitsPerPixel)); michael@0: } michael@0: michael@0: #endif /* NSSIZE_H */