OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 int width() const { return m_size.width(); } | 81 int width() const { return m_size.width(); } |
82 int height() const { return m_size.height(); } | 82 int height() const { return m_size.height(); } |
83 | 83 |
84 void setX(int x) { m_location.setX(x); } | 84 void setX(int x) { m_location.setX(x); } |
85 void setY(int y) { m_location.setY(y); } | 85 void setY(int y) { m_location.setY(y); } |
86 void setWidth(int width) { m_size.setWidth(width); } | 86 void setWidth(int width) { m_size.setWidth(width); } |
87 void setHeight(int height) { m_size.setHeight(height); } | 87 void setHeight(int height) { m_size.setHeight(height); } |
88 | 88 |
89 bool isEmpty() const { return m_size.isEmpty(); } | 89 bool isEmpty() const { return m_size.isEmpty(); } |
90 | 90 |
91 // NOTE: The result is rounded to integer values, and thus may be not the exac
t | 91 // NOTE: The result is rounded to integer values, and thus may be not the |
92 // center point. | 92 // exact center point. |
93 IntPoint center() const { | 93 IntPoint center() const { |
94 return IntPoint(x() + width() / 2, y() + height() / 2); | 94 return IntPoint(x() + width() / 2, y() + height() / 2); |
95 } | 95 } |
96 | 96 |
97 void move(const IntSize& size) { m_location += size; } | 97 void move(const IntSize& size) { m_location += size; } |
98 void moveBy(const IntPoint& offset) { | 98 void moveBy(const IntPoint& offset) { |
99 m_location.move(offset.x(), offset.y()); | 99 m_location.move(offset.x(), offset.y()); |
100 } | 100 } |
101 void move(int dx, int dy) { m_location.move(dx, dy); } | 101 void move(int dx, int dy) { m_location.move(dx, dy); } |
102 void saturatedMove(int dx, int dy) { m_location.saturatedMove(dx, dy); } | 102 void saturatedMove(int dx, int dy) { m_location.saturatedMove(dx, dy); } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } // typically bottomLeft | 140 } // typically bottomLeft |
141 IntPoint maxXMaxYCorner() const { | 141 IntPoint maxXMaxYCorner() const { |
142 return IntPoint(m_location.x() + m_size.width(), | 142 return IntPoint(m_location.x() + m_size.width(), |
143 m_location.y() + m_size.height()); | 143 m_location.y() + m_size.height()); |
144 } // typically bottomRight | 144 } // typically bottomRight |
145 | 145 |
146 bool intersects(const IntRect&) const; | 146 bool intersects(const IntRect&) const; |
147 bool contains(const IntRect&) const; | 147 bool contains(const IntRect&) const; |
148 | 148 |
149 // This checks to see if the rect contains x,y in the traditional sense. | 149 // This checks to see if the rect contains x,y in the traditional sense. |
150 // Equivalent to checking if the rect contains a 1x1 rect below and to the rig
ht of (px,py). | 150 // Equivalent to checking if the rect contains a 1x1 rect below and to the |
| 151 // right of (px,py). |
151 bool contains(int px, int py) const { | 152 bool contains(int px, int py) const { |
152 return px >= x() && px < maxX() && py >= y() && py < maxY(); | 153 return px >= x() && px < maxX() && py >= y() && py < maxY(); |
153 } | 154 } |
154 bool contains(const IntPoint& point) const { | 155 bool contains(const IntPoint& point) const { |
155 return contains(point.x(), point.y()); | 156 return contains(point.x(), point.y()); |
156 } | 157 } |
157 | 158 |
158 void intersect(const IntRect&); | 159 void intersect(const IntRect&); |
159 void unite(const IntRect&); | 160 void unite(const IntRect&); |
160 void uniteIfNonZero(const IntRect&); | 161 void uniteIfNonZero(const IntRect&); |
161 | 162 |
162 // Besides non-empty rects, this method also unites empty rects (as points or
line segments). | 163 // Besides non-empty rects, this method also unites empty rects (as points or |
163 // For example, union of (100, 100, 0x0) and (200, 200, 50x0) is (100, 100, 15
0x100). | 164 // line segments). For example, union of (100, 100, 0x0) and (200, 200, 50x0) |
| 165 // is (100, 100, 150x100). |
164 void uniteEvenIfEmpty(const IntRect&); | 166 void uniteEvenIfEmpty(const IntRect&); |
165 | 167 |
166 void inflateX(int dx) { | 168 void inflateX(int dx) { |
167 m_location.setX(m_location.x() - dx); | 169 m_location.setX(m_location.x() - dx); |
168 m_size.setWidth(m_size.width() + dx + dx); | 170 m_size.setWidth(m_size.width() + dx + dx); |
169 } | 171 } |
170 void inflateY(int dy) { | 172 void inflateY(int dy) { |
171 m_location.setY(m_location.y() - dy); | 173 m_location.setY(m_location.y() - dy); |
172 m_size.setHeight(m_size.height() + dy + dy); | 174 m_size.setHeight(m_size.height() + dy + dy); |
173 } | 175 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 246 |
245 // Redeclared here to avoid ODR issues. | 247 // Redeclared here to avoid ODR issues. |
246 // See platform/testing/GeometryPrinters.h. | 248 // See platform/testing/GeometryPrinters.h. |
247 void PrintTo(const IntRect&, std::ostream*); | 249 void PrintTo(const IntRect&, std::ostream*); |
248 | 250 |
249 } // namespace blink | 251 } // namespace blink |
250 | 252 |
251 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::IntRect); | 253 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::IntRect); |
252 | 254 |
253 #endif // IntRect_h | 255 #endif // IntRect_h |
OLD | NEW |