Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / gfx / thebes / src / gfxRect.cpp
blobeda6f42948fb21d1a04810378794d9e5cae4050e
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Novell code.
17 * The Initial Developer of the Original Code is Novell Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Robert O'Callahan (rocallahan@novell.com)
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "gfxRect.h"
40 #include "nsMathUtils.h"
42 gfxRect
43 gfxRect::Intersect(const gfxRect& aRect) const
45 gfxRect result(0,0,0,0);
47 gfxFloat x = PR_MAX(aRect.X(), X());
48 gfxFloat xmost = PR_MIN(aRect.XMost(), XMost());
49 if (x >= xmost)
50 return result;
52 gfxFloat y = PR_MAX(aRect.Y(), Y());
53 gfxFloat ymost = PR_MIN(aRect.YMost(), YMost());
54 if (y >= ymost)
55 return result;
57 result = gfxRect(x, y, xmost - x, ymost - y);
58 return result;
61 gfxRect
62 gfxRect::Union(const gfxRect& aRect) const
64 if (IsEmpty())
65 return aRect;
66 if (aRect.IsEmpty())
67 return *this;
69 gfxFloat x = PR_MIN(aRect.X(), X());
70 gfxFloat xmost = PR_MAX(aRect.XMost(), XMost());
71 gfxFloat y = PR_MIN(aRect.Y(), Y());
72 gfxFloat ymost = PR_MAX(aRect.YMost(), YMost());
73 return gfxRect(x, y, xmost - x, ymost - y);
76 PRBool
77 gfxRect::Contains(const gfxRect& aRect) const
79 return aRect.X() >= X() && aRect.XMost() <= XMost() &&
80 aRect.Y() >= Y() && aRect.YMost() <= YMost();
83 void
84 gfxRect::Round()
86 // Note that don't use NS_round here. See the comment for this method in gfxRect.h
87 gfxFloat x0 = NS_floor(X() + 0.5);
88 gfxFloat y0 = NS_floor(Y() + 0.5);
89 gfxFloat x1 = NS_floor(XMost() + 0.5);
90 gfxFloat y1 = NS_floor(YMost() + 0.5);
92 pos.x = x0;
93 pos.y = y0;
95 size.width = x1 - x0;
96 size.height = y1 - y0;
99 void
100 gfxRect::RoundOut()
102 gfxFloat x0 = NS_floor(X());
103 gfxFloat y0 = NS_floor(Y());
104 gfxFloat x1 = NS_ceil(XMost());
105 gfxFloat y1 = NS_ceil(YMost());
107 pos.x = x0;
108 pos.y = y0;
110 size.width = x1 - x0;
111 size.height = y1 - y0;
114 /* Clamp r to CAIRO_COORD_MIN .. CAIRO_COORD_MAX
115 * these are to be device coordinates.
117 * Cairo is currently using 24.8 fixed point,
118 * so -2^24 .. 2^24-1 is our valid
121 #define CAIRO_COORD_MAX (16777215.0)
122 #define CAIRO_COORD_MIN (-16777216.0)
124 void
125 gfxRect::Condition()
127 // if either x or y is way out of bounds;
128 // note that we don't handle negative w/h here
129 if (pos.x > CAIRO_COORD_MAX) {
130 pos.x = CAIRO_COORD_MAX;
131 size.width = 0.0;
134 if (pos.y > CAIRO_COORD_MAX) {
135 pos.y = CAIRO_COORD_MAX;
136 size.height = 0.0;
139 if (pos.x < CAIRO_COORD_MIN) {
140 size.width += pos.x - CAIRO_COORD_MIN;
141 if (size.width < 0.0)
142 size.width = 0.0;
143 pos.x = CAIRO_COORD_MIN;
146 if (pos.y < CAIRO_COORD_MIN) {
147 size.height += pos.y - CAIRO_COORD_MIN;
148 if (size.height < 0.0)
149 size.height = 0.0;
150 pos.y = CAIRO_COORD_MIN;
153 if (pos.x + size.width > CAIRO_COORD_MAX) {
154 size.width = CAIRO_COORD_MAX - pos.x;
157 if (pos.y + size.height > CAIRO_COORD_MAX) {
158 size.height = CAIRO_COORD_MAX - pos.y;