| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef IntRect_h | 26 #ifndef IntRect_h |
| 27 #define IntRect_h | 27 #define IntRect_h |
| 28 | 28 |
| 29 #include "core/platform/graphics/IntPoint.h" | 29 #include "core/platform/graphics/IntPoint.h" |
| 30 #include <wtf/Vector.h> | 30 #include "wtf/FastAllocBase.h" |
| 31 #include "wtf/Vector.h" |
| 31 | 32 |
| 32 #if OS(DARWIN) | 33 #if OS(DARWIN) |
| 33 typedef struct CGRect CGRect; | 34 typedef struct CGRect CGRect; |
| 34 | 35 |
| 35 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES | 36 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES |
| 36 typedef struct CGRect NSRect; | 37 typedef struct CGRect NSRect; |
| 37 #else | 38 #else |
| 38 typedef struct _NSRect NSRect; | 39 typedef struct _NSRect NSRect; |
| 39 #endif | 40 #endif |
| 40 #endif | 41 #endif |
| (...skipping 10 matching lines...) Expand all Loading... |
| 51 WTF_MAKE_FAST_ALLOCATED; | 52 WTF_MAKE_FAST_ALLOCATED; |
| 52 public: | 53 public: |
| 53 IntRect() { } | 54 IntRect() { } |
| 54 IntRect(const IntPoint& location, const IntSize& size) | 55 IntRect(const IntPoint& location, const IntSize& size) |
| 55 : m_location(location), m_size(size) { } | 56 : m_location(location), m_size(size) { } |
| 56 IntRect(int x, int y, int width, int height) | 57 IntRect(int x, int y, int width, int height) |
| 57 : m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { } | 58 : m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { } |
| 58 | 59 |
| 59 explicit IntRect(const FloatRect&); // don't do this implicitly since it's l
ossy | 60 explicit IntRect(const FloatRect&); // don't do this implicitly since it's l
ossy |
| 60 explicit IntRect(const LayoutRect&); // don't do this implicitly since it's
lossy | 61 explicit IntRect(const LayoutRect&); // don't do this implicitly since it's
lossy |
| 61 | 62 |
| 62 IntPoint location() const { return m_location; } | 63 IntPoint location() const { return m_location; } |
| 63 IntSize size() const { return m_size; } | 64 IntSize size() const { return m_size; } |
| 64 | 65 |
| 65 void setLocation(const IntPoint& location) { m_location = location; } | 66 void setLocation(const IntPoint& location) { m_location = location; } |
| 66 void setSize(const IntSize& size) { m_size = size; } | 67 void setSize(const IntSize& size) { m_size = size; } |
| 67 | 68 |
| 68 int x() const { return m_location.x(); } | 69 int x() const { return m_location.x(); } |
| 69 int y() const { return m_location.y(); } | 70 int y() const { return m_location.y(); } |
| 70 int maxX() const { return x() + width(); } | 71 int maxX() const { return x() + width(); } |
| 71 int maxY() const { return y() + height(); } | 72 int maxY() const { return y() + height(); } |
| 72 int width() const { return m_size.width(); } | 73 int width() const { return m_size.width(); } |
| 73 int height() const { return m_size.height(); } | 74 int height() const { return m_size.height(); } |
| 74 | 75 |
| 75 // FIXME: These methods are here only to ease the transition to sub-pixel la
yout. They should | |
| 76 // be removed when we close http://webkit.org/b/60318 | |
| 77 int pixelSnappedX() const { return m_location.x(); } | |
| 78 int pixelSnappedY() const { return m_location.y(); } | |
| 79 int pixelSnappedMaxX() const { return x() + width(); } | |
| 80 int pixelSnappedMaxY() const { return y() + height(); } | |
| 81 int pixelSnappedWidth() const { return m_size.width(); } | |
| 82 int pixelSnappedHeight() const { return m_size.height(); } | |
| 83 IntPoint pixelSnappedLocation() const { return location(); } | |
| 84 IntSize pixelSnappedSize() const { return size(); } | |
| 85 | |
| 86 void setX(int x) { m_location.setX(x); } | 76 void setX(int x) { m_location.setX(x); } |
| 87 void setY(int y) { m_location.setY(y); } | 77 void setY(int y) { m_location.setY(y); } |
| 88 void setWidth(int width) { m_size.setWidth(width); } | 78 void setWidth(int width) { m_size.setWidth(width); } |
| 89 void setHeight(int height) { m_size.setHeight(height); } | 79 void setHeight(int height) { m_size.setHeight(height); } |
| 90 | 80 |
| 91 bool isEmpty() const { return m_size.isEmpty(); } | 81 bool isEmpty() const { return m_size.isEmpty(); } |
| 92 | 82 |
| 93 // NOTE: The result is rounded to integer values, and thus may be not the ex
act | 83 // NOTE: The result is rounded to integer values, and thus may be not the ex
act |
| 94 // center point. | 84 // center point. |
| 95 IntPoint center() const { return IntPoint(x() + width() / 2, y() + height()
/ 2); } | 85 IntPoint center() const { return IntPoint(x() + width() / 2, y() + height()
/ 2); } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 123 void shiftMaxYEdgeTo(int edge) | 113 void shiftMaxYEdgeTo(int edge) |
| 124 { | 114 { |
| 125 int delta = edge - maxY(); | 115 int delta = edge - maxY(); |
| 126 setHeight(std::max(0, height() + delta)); | 116 setHeight(std::max(0, height() + delta)); |
| 127 } | 117 } |
| 128 | 118 |
| 129 IntPoint minXMinYCorner() const { return m_location; } // typically topLeft | 119 IntPoint minXMinYCorner() const { return m_location; } // typically topLeft |
| 130 IntPoint maxXMinYCorner() const { return IntPoint(m_location.x() + m_size.wi
dth(), m_location.y()); } // typically topRight | 120 IntPoint maxXMinYCorner() const { return IntPoint(m_location.x() + m_size.wi
dth(), m_location.y()); } // typically topRight |
| 131 IntPoint minXMaxYCorner() const { return IntPoint(m_location.x(), m_location
.y() + m_size.height()); } // typically bottomLeft | 121 IntPoint minXMaxYCorner() const { return IntPoint(m_location.x(), m_location
.y() + m_size.height()); } // typically bottomLeft |
| 132 IntPoint maxXMaxYCorner() const { return IntPoint(m_location.x() + m_size.wi
dth(), m_location.y() + m_size.height()); } // typically bottomRight | 122 IntPoint maxXMaxYCorner() const { return IntPoint(m_location.x() + m_size.wi
dth(), m_location.y() + m_size.height()); } // typically bottomRight |
| 133 | 123 |
| 134 bool intersects(const IntRect&) const; | 124 bool intersects(const IntRect&) const; |
| 135 bool contains(const IntRect&) const; | 125 bool contains(const IntRect&) const; |
| 136 | 126 |
| 137 // This checks to see if the rect contains x,y in the traditional sense. | 127 // This checks to see if the rect contains x,y in the traditional sense. |
| 138 // Equivalent to checking if the rect contains a 1x1 rect below and to the r
ight of (px,py). | 128 // Equivalent to checking if the rect contains a 1x1 rect below and to the r
ight of (px,py). |
| 139 bool contains(int px, int py) const | 129 bool contains(int px, int py) const |
| 140 { return px >= x() && px < maxX() && py >= y() && py < maxY(); } | 130 { return px >= x() && px < maxX() && py >= y() && py < maxY(); } |
| 141 bool contains(const IntPoint& point) const { return contains(point.x(), poin
t.y()); } | 131 bool contains(const IntPoint& point) const { return contains(point.x(), poin
t.y()); } |
| 142 | 132 |
| 143 void intersect(const IntRect&); | 133 void intersect(const IntRect&); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 #if OS(DARWIN) | 204 #if OS(DARWIN) |
| 215 IntRect enclosingIntRect(const CGRect&); | 205 IntRect enclosingIntRect(const CGRect&); |
| 216 #if !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES) | 206 #if !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES) |
| 217 IntRect enclosingIntRect(const NSRect&); | 207 IntRect enclosingIntRect(const NSRect&); |
| 218 #endif | 208 #endif |
| 219 #endif | 209 #endif |
| 220 | 210 |
| 221 } // namespace WebCore | 211 } // namespace WebCore |
| 222 | 212 |
| 223 #endif // IntRect_h | 213 #endif // IntRect_h |
| OLD | NEW |