| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012, Google Inc. All rights reserved. | 2 * Copyright (c) 2012, Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 int pixelSnappedWidth() const { return snapSizeToPixel(width(), x()); } | 91 int pixelSnappedWidth() const { return snapSizeToPixel(width(), x()); } |
| 92 int pixelSnappedHeight() const { return snapSizeToPixel(height(), y()); } | 92 int pixelSnappedHeight() const { return snapSizeToPixel(height(), y()); } |
| 93 | 93 |
| 94 void setX(LayoutUnit x) { m_location.setX(x); } | 94 void setX(LayoutUnit x) { m_location.setX(x); } |
| 95 void setY(LayoutUnit y) { m_location.setY(y); } | 95 void setY(LayoutUnit y) { m_location.setY(y); } |
| 96 void setWidth(LayoutUnit width) { m_size.setWidth(width); } | 96 void setWidth(LayoutUnit width) { m_size.setWidth(width); } |
| 97 void setHeight(LayoutUnit height) { m_size.setHeight(height); } | 97 void setHeight(LayoutUnit height) { m_size.setHeight(height); } |
| 98 | 98 |
| 99 ALWAYS_INLINE bool isEmpty() const { return m_size.isEmpty(); } | 99 ALWAYS_INLINE bool isEmpty() const { return m_size.isEmpty(); } |
| 100 | 100 |
| 101 // NOTE: The result is rounded to integer values, and thus may be not the exac
t | 101 // NOTE: The result is rounded to integer values, and thus may be not the |
| 102 // center point. | 102 // exact center point. |
| 103 LayoutPoint center() const { | 103 LayoutPoint center() const { |
| 104 return LayoutPoint(x() + width() / 2, y() + height() / 2); | 104 return LayoutPoint(x() + width() / 2, y() + height() / 2); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void move(const LayoutSize& size) { m_location += size; } | 107 void move(const LayoutSize& size) { m_location += size; } |
| 108 void move(const IntSize& size) { | 108 void move(const IntSize& size) { |
| 109 m_location.move(LayoutUnit(size.width()), LayoutUnit(size.height())); | 109 m_location.move(LayoutUnit(size.width()), LayoutUnit(size.height())); |
| 110 } | 110 } |
| 111 void moveBy(const LayoutPoint& offset) { | 111 void moveBy(const LayoutPoint& offset) { |
| 112 m_location.move(offset.x(), offset.y()); | 112 m_location.move(offset.x(), offset.y()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } // typically bottomLeft | 171 } // typically bottomLeft |
| 172 LayoutPoint maxXMaxYCorner() const { | 172 LayoutPoint maxXMaxYCorner() const { |
| 173 return LayoutPoint(m_location.x() + m_size.width(), | 173 return LayoutPoint(m_location.x() + m_size.width(), |
| 174 m_location.y() + m_size.height()); | 174 m_location.y() + m_size.height()); |
| 175 } // typically bottomRight | 175 } // typically bottomRight |
| 176 | 176 |
| 177 bool intersects(const LayoutRect&) const; | 177 bool intersects(const LayoutRect&) const; |
| 178 bool contains(const LayoutRect&) const; | 178 bool contains(const LayoutRect&) const; |
| 179 | 179 |
| 180 // This checks to see if the rect contains x,y in the traditional sense. | 180 // This checks to see if the rect contains x,y in the traditional sense. |
| 181 // Equivalent to checking if the rect contains a 1x1 rect below and to the rig
ht of (px,py). | 181 // Equivalent to checking if the rect contains a 1x1 rect below and to the |
| 182 // right of (px,py). |
| 182 bool contains(LayoutUnit px, LayoutUnit py) const { | 183 bool contains(LayoutUnit px, LayoutUnit py) const { |
| 183 return px >= x() && px < maxX() && py >= y() && py < maxY(); | 184 return px >= x() && px < maxX() && py >= y() && py < maxY(); |
| 184 } | 185 } |
| 185 bool contains(const LayoutPoint& point) const { | 186 bool contains(const LayoutPoint& point) const { |
| 186 return contains(point.x(), point.y()); | 187 return contains(point.x(), point.y()); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void intersect(const LayoutRect&); | 190 void intersect(const LayoutRect&); |
| 190 void unite(const LayoutRect&); | 191 void unite(const LayoutRect&); |
| 191 void uniteIfNonZero(const LayoutRect&); | 192 void uniteIfNonZero(const LayoutRect&); |
| 192 | 193 |
| 193 // Set this rect to be the intersection of itself and the argument rect | 194 // Set this rect to be the intersection of itself and the argument rect |
| 194 // using edge-inclusive geometry. If the two rectangles overlap but the | 195 // using edge-inclusive geometry. If the two rectangles overlap but the |
| 195 // overlap region is zero-area (either because one of the two rectangles | 196 // overlap region is zero-area (either because one of the two rectangles |
| 196 // is zero-area, or because the rectangles overlap at an edge or a corner), | 197 // is zero-area, or because the rectangles overlap at an edge or a corner), |
| 197 // the result is the zero-area intersection. The return value indicates | 198 // the result is the zero-area intersection. The return value indicates |
| 198 // whether the two rectangle actually have an intersection, since checking | 199 // whether the two rectangle actually have an intersection, since checking |
| 199 // the result for isEmpty() is not conclusive. | 200 // the result for isEmpty() is not conclusive. |
| 200 bool inclusiveIntersect(const LayoutRect&); | 201 bool inclusiveIntersect(const LayoutRect&); |
| 201 | 202 |
| 202 // Besides non-empty rects, this method also unites empty rects (as points or
line segments). | 203 // Besides non-empty rects, this method also unites empty rects (as points or |
| 203 // For example, union of (100, 100, 0x0) and (200, 200, 50x0) is (100, 100, 15
0x100). | 204 // line segments). For example, union of (100, 100, 0x0) and (200, 200, 50x0) |
| 205 // is (100, 100, 150x100). |
| 204 void uniteEvenIfEmpty(const LayoutRect&); | 206 void uniteEvenIfEmpty(const LayoutRect&); |
| 205 | 207 |
| 206 void inflateX(LayoutUnit dx) { | 208 void inflateX(LayoutUnit dx) { |
| 207 m_location.setX(m_location.x() - dx); | 209 m_location.setX(m_location.x() - dx); |
| 208 m_size.setWidth(m_size.width() + dx + dx); | 210 m_size.setWidth(m_size.width() + dx + dx); |
| 209 } | 211 } |
| 210 void inflateY(LayoutUnit dy) { | 212 void inflateY(LayoutUnit dy) { |
| 211 m_location.setY(m_location.y() - dy); | 213 m_location.setY(m_location.y() - dy); |
| 212 m_size.setHeight(m_size.height() + dy + dy); | 214 m_size.setHeight(m_size.height() + dy + dy); |
| 213 } | 215 } |
| 214 void inflate(LayoutUnit d) { | 216 void inflate(LayoutUnit d) { |
| 215 inflateX(d); | 217 inflateX(d); |
| 216 inflateY(d); | 218 inflateY(d); |
| 217 } | 219 } |
| 218 void inflate(int d) { inflate(LayoutUnit(d)); } | 220 void inflate(int d) { inflate(LayoutUnit(d)); } |
| 219 void scale(float s); | 221 void scale(float s); |
| 220 void scale(float xAxisScale, float yAxisScale); | 222 void scale(float xAxisScale, float yAxisScale); |
| 221 | 223 |
| 222 LayoutRect transposedRect() const { | 224 LayoutRect transposedRect() const { |
| 223 return LayoutRect(m_location.transposedPoint(), m_size.transposedSize()); | 225 return LayoutRect(m_location.transposedPoint(), m_size.transposedSize()); |
| 224 } | 226 } |
| 225 | 227 |
| 226 static IntRect infiniteIntRect() { | 228 static IntRect infiniteIntRect() { |
| 227 // Due to saturated arithemetic this value is not the same as LayoutRect(Int
Rect(INT_MIN/2, INT_MIN/2, INT_MAX, INT_MAX)). | 229 // Due to saturated arithemetic this value is not the same as |
| 230 // LayoutRect(IntRect(INT_MIN/2, INT_MIN/2, INT_MAX, INT_MAX)). |
| 228 static IntRect infiniteIntRect( | 231 static IntRect infiniteIntRect( |
| 229 LayoutRect(LayoutUnit::nearlyMin() / 2, LayoutUnit::nearlyMin() / 2, | 232 LayoutRect(LayoutUnit::nearlyMin() / 2, LayoutUnit::nearlyMin() / 2, |
| 230 LayoutUnit::nearlyMax(), LayoutUnit::nearlyMax())); | 233 LayoutUnit::nearlyMax(), LayoutUnit::nearlyMax())); |
| 231 return infiniteIntRect; | 234 return infiniteIntRect; |
| 232 } | 235 } |
| 233 | 236 |
| 234 String toString() const; | 237 String toString() const; |
| 235 | 238 |
| 236 private: | 239 private: |
| 237 LayoutPoint m_location; | 240 LayoutPoint m_location; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 pixelSnappedIntSize(size, location)); | 302 pixelSnappedIntSize(size, location)); |
| 300 } | 303 } |
| 301 | 304 |
| 302 // Redeclared here to avoid ODR issues. | 305 // Redeclared here to avoid ODR issues. |
| 303 // See platform/testing/GeometryPrinters.h. | 306 // See platform/testing/GeometryPrinters.h. |
| 304 void PrintTo(const LayoutRect&, std::ostream*); | 307 void PrintTo(const LayoutRect&, std::ostream*); |
| 305 | 308 |
| 306 } // namespace blink | 309 } // namespace blink |
| 307 | 310 |
| 308 #endif // LayoutRect_h | 311 #endif // LayoutRect_h |
| OLD | NEW |