2001-09-26 04:16:04 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-26 01:16:47 +03:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-01-26 01:16:47 +03:00
|
|
|
*
|
2001-09-26 04:16:04 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-01-26 01:16:47 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-26 04:16:04 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-26 04:16:04 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-26 04:16:04 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-26 04:16:04 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-26 04:16:04 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-01-26 01:16:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef NSRECT_H
|
|
|
|
#define NSRECT_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsCoord.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsSize.h"
|
|
|
|
#include "nsMargin.h"
|
2004-05-18 22:09:16 +04:00
|
|
|
#include "gfxCore.h"
|
2006-03-01 06:57:24 +03:00
|
|
|
#include "nsTraceRefcnt.h"
|
1999-01-26 01:16:47 +03:00
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
struct nsIntRect;
|
|
|
|
|
1999-01-26 01:16:47 +03:00
|
|
|
struct NS_GFX nsRect {
|
|
|
|
nscoord x, y;
|
|
|
|
nscoord width, height;
|
|
|
|
|
|
|
|
// Constructors
|
2006-03-01 06:57:24 +03:00
|
|
|
nsRect() : x(0), y(0), width(0), height(0) {
|
|
|
|
MOZ_COUNT_CTOR(nsRect);
|
|
|
|
}
|
|
|
|
nsRect(const nsRect& aRect) {
|
|
|
|
MOZ_COUNT_CTOR(nsRect);
|
|
|
|
*this = aRect;
|
|
|
|
}
|
|
|
|
nsRect(const nsPoint& aOrigin, const nsSize &aSize) {
|
|
|
|
MOZ_COUNT_CTOR(nsRect);
|
|
|
|
x = aOrigin.x; y = aOrigin.y;
|
|
|
|
width = aSize.width; height = aSize.height;
|
|
|
|
}
|
2004-11-03 05:48:04 +03:00
|
|
|
nsRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) {
|
2006-03-01 06:57:24 +03:00
|
|
|
MOZ_COUNT_CTOR(nsRect);
|
2004-11-03 05:48:04 +03:00
|
|
|
x = aX; y = aY; width = aWidth; height = aHeight;
|
|
|
|
VERIFY_COORD(x); VERIFY_COORD(y); VERIFY_COORD(width); VERIFY_COORD(height);
|
|
|
|
}
|
1999-01-26 01:16:47 +03:00
|
|
|
|
2006-03-01 06:57:24 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
~nsRect() {
|
|
|
|
MOZ_COUNT_DTOR(nsRect);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-11-06 04:48:36 +03:00
|
|
|
// Emptiness. An empty rect is one that has no area, i.e. its height or width
|
1999-01-26 01:16:47 +03:00
|
|
|
// is <= 0
|
|
|
|
PRBool IsEmpty() const {
|
2001-11-06 04:48:36 +03:00
|
|
|
return (PRBool) ((height <= 0) || (width <= 0));
|
1999-01-26 01:16:47 +03:00
|
|
|
}
|
|
|
|
void Empty() {width = height = 0;}
|
|
|
|
|
|
|
|
// Containment
|
|
|
|
PRBool Contains(const nsRect& aRect) const;
|
|
|
|
PRBool Contains(nscoord aX, nscoord aY) const;
|
|
|
|
PRBool Contains(const nsPoint& aPoint) const {return Contains(aPoint.x, aPoint.y);}
|
|
|
|
|
|
|
|
// Intersection. Returns TRUE if the receiver overlaps aRect and
|
|
|
|
// FALSE otherwise
|
|
|
|
PRBool Intersects(const nsRect& aRect) const;
|
|
|
|
|
|
|
|
// Computes the area in which aRect1 and aRect2 overlap, and fills 'this' with
|
|
|
|
// the result. Returns FALSE if the rectangles don't intersect, and sets 'this'
|
|
|
|
// rect to be an empty rect.
|
|
|
|
//
|
|
|
|
// 'this' can be the same object as either aRect1 or aRect2
|
|
|
|
PRBool IntersectRect(const nsRect& aRect1, const nsRect& aRect2);
|
|
|
|
|
|
|
|
// Computes the smallest rectangle that contains both aRect1 and aRect2 and
|
2008-02-27 12:46:22 +03:00
|
|
|
// fills 'this' with the result, ignoring empty input rectangles.
|
|
|
|
// Returns FALSE and sets 'this' rect to be an empty rect if both aRect1
|
|
|
|
// and aRect2 are empty.
|
1999-01-26 01:16:47 +03:00
|
|
|
//
|
|
|
|
// 'this' can be the same object as either aRect1 or aRect2
|
|
|
|
PRBool UnionRect(const nsRect& aRect1, const nsRect& aRect2);
|
|
|
|
|
2008-02-27 12:46:22 +03:00
|
|
|
// Computes the smallest rectangle that contains both aRect1 and aRect2,
|
|
|
|
// where empty input rectangles are allowed to affect the result; the
|
|
|
|
// top-left of an empty input rectangle will be inside or on the edge of
|
|
|
|
// the result.
|
|
|
|
//
|
|
|
|
// 'this' can be the same object as either aRect1 or aRect2
|
|
|
|
void UnionRectIncludeEmpty(const nsRect& aRect1, const nsRect& aRect2);
|
|
|
|
|
1999-01-26 01:16:47 +03:00
|
|
|
// Accessors
|
|
|
|
void SetRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) {
|
|
|
|
x = aX; y = aY; width = aWidth; height = aHeight;
|
|
|
|
}
|
2006-01-26 09:10:52 +03:00
|
|
|
void SetRect(const nsPoint& aPt, const nsSize& aSize) {
|
2006-01-26 05:29:17 +03:00
|
|
|
SetRect(aPt.x, aPt.y, aSize.width, aSize.height);
|
|
|
|
}
|
1999-01-26 01:16:47 +03:00
|
|
|
void MoveTo(nscoord aX, nscoord aY) {x = aX; y = aY;}
|
1999-11-12 18:10:40 +03:00
|
|
|
void MoveTo(const nsPoint& aPoint) {x = aPoint.x; y = aPoint.y;}
|
1999-01-26 01:16:47 +03:00
|
|
|
void MoveBy(nscoord aDx, nscoord aDy) {x += aDx; y += aDy;}
|
2003-09-13 20:21:41 +04:00
|
|
|
void MoveBy(const nsPoint& aPoint) {x += aPoint.x; y += aPoint.y;}
|
1999-01-26 01:16:47 +03:00
|
|
|
void SizeTo(nscoord aWidth, nscoord aHeight) {width = aWidth; height = aHeight;}
|
|
|
|
void SizeTo(const nsSize& aSize) {SizeTo(aSize.width, aSize.height);}
|
|
|
|
void SizeBy(nscoord aDeltaWidth, nscoord aDeltaHeight) {width += aDeltaWidth;
|
|
|
|
height += aDeltaHeight;}
|
|
|
|
|
|
|
|
// Inflate the rect by the specified width/height or margin
|
|
|
|
void Inflate(nscoord aDx, nscoord aDy);
|
|
|
|
void Inflate(const nsSize& aSize) {Inflate(aSize.width, aSize.height);}
|
|
|
|
void Inflate(const nsMargin& aMargin);
|
|
|
|
|
|
|
|
// Deflate the rect by the specified width/height or margin
|
|
|
|
void Deflate(nscoord aDx, nscoord aDy);
|
|
|
|
void Deflate(const nsSize& aSize) {Deflate(aSize.width, aSize.height);}
|
|
|
|
void Deflate(const nsMargin& aMargin);
|
|
|
|
|
|
|
|
// Overloaded operators. Note that '=' isn't defined so we'll get the
|
|
|
|
// compiler generated default assignment operator.
|
|
|
|
PRBool operator==(const nsRect& aRect) const {
|
|
|
|
return (PRBool) ((IsEmpty() && aRect.IsEmpty()) ||
|
|
|
|
((x == aRect.x) && (y == aRect.y) &&
|
|
|
|
(width == aRect.width) && (height == aRect.height)));
|
|
|
|
}
|
|
|
|
PRBool operator!=(const nsRect& aRect) const {
|
|
|
|
return (PRBool) !operator==(aRect);
|
|
|
|
}
|
2004-02-22 06:31:30 +03:00
|
|
|
|
2008-02-27 12:46:22 +03:00
|
|
|
// Useful when we care about the exact x/y/width/height values being
|
|
|
|
// equal (i.e. we care about differences in empty rectangles)
|
|
|
|
PRBool IsExactEqual(const nsRect& aRect) const {
|
|
|
|
return x == aRect.x && y == aRect.y &&
|
|
|
|
width == aRect.width && height == aRect.height;
|
|
|
|
}
|
|
|
|
|
2004-02-22 06:31:30 +03:00
|
|
|
nsRect operator+(const nsPoint& aPoint) const {
|
|
|
|
return nsRect(x + aPoint.x, y + aPoint.y, width, height);
|
|
|
|
}
|
|
|
|
nsRect operator-(const nsPoint& aPoint) const {
|
|
|
|
return nsRect(x - aPoint.x, y - aPoint.y, width, height);
|
|
|
|
}
|
1999-01-26 01:16:47 +03:00
|
|
|
nsRect& operator+=(const nsPoint& aPoint) {x += aPoint.x; y += aPoint.y; return *this;}
|
|
|
|
nsRect& operator-=(const nsPoint& aPoint) {x -= aPoint.x; y -= aPoint.y; return *this;}
|
|
|
|
|
2007-05-23 07:45:59 +04:00
|
|
|
// Scale by aScale, converting coordinates to integers so that the result
|
|
|
|
// is the smallest integer-coordinate rectangle containing the unrounded result
|
|
|
|
nsRect& ScaleRoundOut(float aScale);
|
1999-01-26 01:16:47 +03:00
|
|
|
|
2004-03-10 04:59:16 +03:00
|
|
|
// Helpers for accessing the vertices
|
|
|
|
nsPoint TopLeft() const { return nsPoint(x, y); }
|
|
|
|
nsPoint TopRight() const { return nsPoint(XMost(), y); }
|
|
|
|
nsPoint BottomLeft() const { return nsPoint(x, YMost()); }
|
|
|
|
nsPoint BottomRight() const { return nsPoint(XMost(), YMost()); }
|
|
|
|
|
2004-10-12 00:35:51 +04:00
|
|
|
nsSize Size() const { return nsSize(width, height); }
|
|
|
|
|
1999-01-26 01:16:47 +03:00
|
|
|
// Helper methods for computing the extents
|
|
|
|
nscoord XMost() const {return x + width;}
|
|
|
|
nscoord YMost() const {return y + height;}
|
2009-01-15 06:27:09 +03:00
|
|
|
|
|
|
|
static inline nsIntRect ToNearestPixels(const nsRect &aRect, nscoord aAppUnitsPerPixel);
|
|
|
|
static inline nsIntRect ToOutsidePixels(const nsRect &aRect, nscoord aAppUnitsPerPixel);
|
|
|
|
static inline nsIntRect ToInsidePixels(const nsRect &aRect, nscoord aAppUnitsPerPixel);
|
1999-01-26 01:16:47 +03:00
|
|
|
};
|
|
|
|
|
2004-11-03 05:48:04 +03:00
|
|
|
struct NS_GFX nsIntRect {
|
|
|
|
PRInt32 x, y;
|
|
|
|
PRInt32 width, height;
|
|
|
|
|
|
|
|
// Constructors
|
|
|
|
nsIntRect() : x(0), y(0), width(0), height(0) {}
|
|
|
|
nsIntRect(const nsIntRect& aRect) {*this = aRect;}
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect(const nsIntPoint& aOrigin, const nsIntSize &aSize) {
|
|
|
|
x = aOrigin.x; y = aOrigin.y;
|
|
|
|
width = aSize.width; height = aSize.height;
|
|
|
|
}
|
2004-11-03 05:48:04 +03:00
|
|
|
nsIntRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) {
|
|
|
|
x = aX; y = aY; width = aWidth; height = aHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emptiness. An empty rect is one that has no area, i.e. its height or width
|
|
|
|
// is <= 0
|
|
|
|
PRBool IsEmpty() const {
|
|
|
|
return (PRBool) ((height <= 0) || (width <= 0));
|
|
|
|
}
|
2009-01-15 06:27:09 +03:00
|
|
|
void Empty() {width = height = 0;}
|
|
|
|
|
|
|
|
// Inflate the rect by the specified width/height or margin
|
|
|
|
void Inflate(PRInt32 aDx, PRInt32 aDy) {
|
|
|
|
x -= aDx;
|
|
|
|
y -= aDy;
|
|
|
|
width += aDx*2;
|
|
|
|
height += aDy*2;
|
|
|
|
}
|
|
|
|
void Inflate(const nsIntMargin &aMargin) {
|
|
|
|
x -= aMargin.left;
|
|
|
|
y -= aMargin.top;
|
|
|
|
width += aMargin.left + aMargin.right;
|
|
|
|
height += aMargin.top + aMargin.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overloaded operators. Note that '=' isn't defined so we'll get the
|
|
|
|
// compiler generated default assignment operator.
|
|
|
|
PRBool operator==(const nsIntRect& aRect) const {
|
|
|
|
return (PRBool) ((IsEmpty() && aRect.IsEmpty()) ||
|
|
|
|
((x == aRect.x) && (y == aRect.y) &&
|
|
|
|
(width == aRect.width) && (height == aRect.height)));
|
|
|
|
}
|
|
|
|
PRBool operator!=(const nsIntRect& aRect) const {
|
|
|
|
return (PRBool) !operator==(aRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect operator+(const nsIntPoint& aPoint) const {
|
|
|
|
return nsIntRect(x + aPoint.x, y + aPoint.y, width, height);
|
|
|
|
}
|
|
|
|
nsIntRect operator-(const nsIntPoint& aPoint) const {
|
|
|
|
return nsIntRect(x - aPoint.x, y - aPoint.y, width, height);
|
|
|
|
}
|
|
|
|
nsIntRect& operator+=(const nsIntPoint& aPoint) {x += aPoint.x; y += aPoint.y; return *this;}
|
|
|
|
nsIntRect& operator-=(const nsIntPoint& aPoint) {x -= aPoint.x; y -= aPoint.y; return *this;}
|
2004-11-03 05:48:04 +03:00
|
|
|
|
|
|
|
void SetRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) {
|
|
|
|
x = aX; y = aY; width = aWidth; height = aHeight;
|
|
|
|
}
|
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
void MoveTo(PRInt32 aX, PRInt32 aY) {x = aX; y = aY;}
|
|
|
|
void MoveTo(const nsIntPoint& aPoint) {x = aPoint.x; y = aPoint.y;}
|
|
|
|
void MoveBy(PRInt32 aDx, PRInt32 aDy) {x += aDx; y += aDy;}
|
|
|
|
void MoveBy(const nsIntPoint& aPoint) {x += aPoint.x; y += aPoint.y;}
|
|
|
|
void SizeTo(PRInt32 aWidth, PRInt32 aHeight) {width = aWidth; height = aHeight;}
|
|
|
|
void SizeTo(const nsIntSize& aSize) {SizeTo(aSize.width, aSize.height);}
|
|
|
|
void SizeBy(PRInt32 aDeltaWidth, PRInt32 aDeltaHeight) {width += aDeltaWidth;
|
|
|
|
height += aDeltaHeight;}
|
|
|
|
|
|
|
|
PRBool Contains(const nsIntRect& aRect) const
|
|
|
|
{
|
|
|
|
return (PRBool) ((aRect.x >= x) && (aRect.y >= y) &&
|
|
|
|
(aRect.XMost() <= XMost()) && (aRect.YMost() <= YMost()));
|
|
|
|
}
|
|
|
|
PRBool Contains(PRInt32 aX, PRInt32 aY) const
|
|
|
|
{
|
|
|
|
return (PRBool) ((aX >= x) && (aY >= y) &&
|
|
|
|
(aX < XMost()) && (aY < YMost()));
|
|
|
|
}
|
|
|
|
PRBool Contains(const nsIntPoint& aPoint) const { return Contains(aPoint.x, aPoint.y); }
|
|
|
|
|
|
|
|
// Intersection. Returns TRUE if the receiver overlaps aRect and
|
|
|
|
// FALSE otherwise
|
|
|
|
PRBool Intersects(const nsIntRect& aRect) const {
|
|
|
|
return (PRBool) ((x < aRect.XMost()) && (y < aRect.YMost()) &&
|
|
|
|
(aRect.x < XMost()) && (aRect.y < YMost()));
|
|
|
|
}
|
|
|
|
|
2004-11-03 05:48:04 +03:00
|
|
|
// Computes the area in which aRect1 and aRect2 overlap, and fills 'this' with
|
|
|
|
// the result. Returns FALSE if the rectangles don't intersect, and sets 'this'
|
|
|
|
// rect to be an empty rect.
|
|
|
|
//
|
|
|
|
// 'this' can be the same object as either aRect1 or aRect2
|
|
|
|
PRBool IntersectRect(const nsIntRect& aRect1, const nsIntRect& aRect2);
|
|
|
|
|
|
|
|
// Computes the smallest rectangle that contains both aRect1 and aRect2 and
|
|
|
|
// fills 'this' with the result. Returns FALSE and sets 'this' rect to be an
|
|
|
|
// empty rect if both aRect1 and aRect2 are empty
|
|
|
|
//
|
|
|
|
// 'this' can be the same object as either aRect1 or aRect2
|
|
|
|
PRBool UnionRect(const nsIntRect& aRect1, const nsIntRect& aRect2);
|
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
// Helpers for accessing the vertices
|
|
|
|
nsIntPoint TopLeft() const { return nsIntPoint(x, y); }
|
|
|
|
nsIntPoint TopRight() const { return nsIntPoint(XMost(), y); }
|
|
|
|
nsIntPoint BottomLeft() const { return nsIntPoint(x, YMost()); }
|
|
|
|
nsIntPoint BottomRight() const { return nsIntPoint(XMost(), YMost()); }
|
|
|
|
|
|
|
|
nsIntSize Size() const { return nsIntSize(width, height); }
|
|
|
|
|
2004-11-03 05:48:04 +03:00
|
|
|
// Helper methods for computing the extents
|
|
|
|
PRInt32 XMost() const {return x + width;}
|
|
|
|
PRInt32 YMost() const {return y + height;}
|
2009-01-15 06:27:09 +03:00
|
|
|
|
|
|
|
static inline nsRect ToAppUnits(const nsIntRect &aRect, nscoord aAppUnitsPerPixel);
|
2004-11-03 05:48:04 +03:00
|
|
|
};
|
2009-01-15 06:27:09 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* App Unit/Pixel conversions
|
|
|
|
*/
|
|
|
|
// scale the rect but round to preserve centers
|
|
|
|
inline nsIntRect
|
|
|
|
nsRect::ToNearestPixels(const nsRect &aRect, nscoord aAppUnitsPerPixel)
|
|
|
|
{
|
|
|
|
nsIntRect rect;
|
|
|
|
rect.x = NSToIntRound(NSAppUnitsToFloatPixels(aRect.x, float(aAppUnitsPerPixel)));
|
|
|
|
rect.y = NSToIntRound(NSAppUnitsToFloatPixels(aRect.y, float(aAppUnitsPerPixel)));
|
|
|
|
rect.width = NSToIntRound(NSAppUnitsToFloatPixels(aRect.XMost(),
|
|
|
|
float(aAppUnitsPerPixel))) - rect.x;
|
|
|
|
rect.height = NSToIntRound(NSAppUnitsToFloatPixels(aRect.YMost(),
|
|
|
|
float(aAppUnitsPerPixel))) - rect.y;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
// scale the rect but round to smallest containing rect
|
|
|
|
inline nsIntRect
|
|
|
|
nsRect::ToOutsidePixels(const nsRect &aRect, nscoord aAppUnitsPerPixel)
|
|
|
|
{
|
|
|
|
nsIntRect rect;
|
|
|
|
rect.x = NSToIntFloor(NSAppUnitsToFloatPixels(aRect.x, float(aAppUnitsPerPixel)));
|
|
|
|
rect.y = NSToIntFloor(NSAppUnitsToFloatPixels(aRect.y, float(aAppUnitsPerPixel)));
|
|
|
|
rect.width = NSToIntCeil(NSAppUnitsToFloatPixels(aRect.XMost(),
|
|
|
|
float(aAppUnitsPerPixel))) - rect.x;
|
|
|
|
rect.height = NSToIntCeil(NSAppUnitsToFloatPixels(aRect.YMost(),
|
|
|
|
float(aAppUnitsPerPixel))) - rect.y;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
// scale the rect but round to largest contained rect
|
|
|
|
inline nsIntRect
|
|
|
|
nsRect::ToInsidePixels(const nsRect &aRect, nscoord aAppUnitsPerPixel)
|
|
|
|
{
|
|
|
|
nsIntRect rect;
|
|
|
|
rect.x = NSToIntCeil(NSAppUnitsToFloatPixels(aRect.x, float(aAppUnitsPerPixel)));
|
|
|
|
rect.y = NSToIntCeil(NSAppUnitsToFloatPixels(aRect.y, float(aAppUnitsPerPixel)));
|
|
|
|
rect.width = NSToIntFloor(NSAppUnitsToFloatPixels(aRect.XMost(),
|
|
|
|
float(aAppUnitsPerPixel))) - rect.x;
|
|
|
|
rect.height = NSToIntFloor(NSAppUnitsToFloatPixels(aRect.YMost(),
|
|
|
|
float(aAppUnitsPerPixel))) - rect.y;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
// app units are integer multiples of pixels, so no rounding needed
|
|
|
|
inline nsRect
|
|
|
|
nsIntRect::ToAppUnits(const nsIntRect &aRect, nscoord aAppUnitsPerPixel)
|
|
|
|
{
|
|
|
|
return nsRect(NSIntPixelsToAppUnits(aRect.x, aAppUnitsPerPixel),
|
|
|
|
NSIntPixelsToAppUnits(aRect.y, aAppUnitsPerPixel),
|
|
|
|
NSIntPixelsToAppUnits(aRect.width, aAppUnitsPerPixel),
|
|
|
|
NSIntPixelsToAppUnits(aRect.height, aAppUnitsPerPixel));
|
|
|
|
}
|
2004-11-03 05:48:04 +03:00
|
|
|
|
2004-04-23 01:36:53 +04:00
|
|
|
#ifdef DEBUG
|
1999-01-26 01:16:47 +03:00
|
|
|
// Diagnostics
|
|
|
|
extern NS_GFX FILE* operator<<(FILE* out, const nsRect& rect);
|
2004-04-23 01:36:53 +04:00
|
|
|
#endif // DEBUG
|
1999-01-26 01:16:47 +03:00
|
|
|
|
|
|
|
#endif /* NSRECT_H */
|