| 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 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/platform/graphics/LayoutRect.h" | 32 #include "platform/geometry/LayoutRect.h" |
| 33 | 33 |
| 34 #include "platform/LayoutUnit.h" |
| 35 #include "platform/geometry/FloatRect.h" |
| 34 #include <algorithm> | 36 #include <algorithm> |
| 35 #include "core/platform/graphics/FloatRect.h" | |
| 36 #include "platform/LayoutUnit.h" | |
| 37 | |
| 38 using std::max; | |
| 39 using std::min; | |
| 40 | 37 |
| 41 namespace WebCore { | 38 namespace WebCore { |
| 42 | 39 |
| 43 LayoutRect::LayoutRect(const FloatRect& r) | 40 LayoutRect::LayoutRect(const FloatRect& r) |
| 44 : m_location(LayoutPoint(r.location())) | 41 : m_location(LayoutPoint(r.location())) |
| 45 , m_size(LayoutSize(r.size())) | 42 , m_size(LayoutSize(r.size())) |
| 46 { | 43 { |
| 47 } | 44 } |
| 48 | 45 |
| 49 bool LayoutRect::intersects(const LayoutRect& other) const | 46 bool LayoutRect::intersects(const LayoutRect& other) const |
| 50 { | 47 { |
| 51 // Checking emptiness handles negative widths as well as zero. | 48 // Checking emptiness handles negative widths as well as zero. |
| 52 return !isEmpty() && !other.isEmpty() | 49 return !isEmpty() && !other.isEmpty() |
| 53 && x() < other.maxX() && other.x() < maxX() | 50 && x() < other.maxX() && other.x() < maxX() |
| 54 && y() < other.maxY() && other.y() < maxY(); | 51 && y() < other.maxY() && other.y() < maxY(); |
| 55 } | 52 } |
| 56 | 53 |
| 57 bool LayoutRect::contains(const LayoutRect& other) const | 54 bool LayoutRect::contains(const LayoutRect& other) const |
| 58 { | 55 { |
| 59 return x() <= other.x() && maxX() >= other.maxX() | 56 return x() <= other.x() && maxX() >= other.maxX() |
| 60 && y() <= other.y() && maxY() >= other.maxY(); | 57 && y() <= other.y() && maxY() >= other.maxY(); |
| 61 } | 58 } |
| 62 | 59 |
| 63 void LayoutRect::intersect(const LayoutRect& other) | 60 void LayoutRect::intersect(const LayoutRect& other) |
| 64 { | 61 { |
| 65 LayoutPoint newLocation(max(x(), other.x()), max(y(), other.y())); | 62 LayoutPoint newLocation(std::max(x(), other.x()), std::max(y(), other.y())); |
| 66 LayoutPoint newMaxPoint(min(maxX(), other.maxX()), min(maxY(), other.maxY())
); | 63 LayoutPoint newMaxPoint(std::min(maxX(), other.maxX()), std::min(maxY(), oth
er.maxY())); |
| 67 | 64 |
| 68 // Return a clean empty rectangle for non-intersecting cases. | 65 // Return a clean empty rectangle for non-intersecting cases. |
| 69 if (newLocation.x() >= newMaxPoint.x() || newLocation.y() >= newMaxPoint.y()
) { | 66 if (newLocation.x() >= newMaxPoint.x() || newLocation.y() >= newMaxPoint.y()
) { |
| 70 newLocation = LayoutPoint(0, 0); | 67 newLocation = LayoutPoint(0, 0); |
| 71 newMaxPoint = LayoutPoint(0, 0); | 68 newMaxPoint = LayoutPoint(0, 0); |
| 72 } | 69 } |
| 73 | 70 |
| 74 m_location = newLocation; | 71 m_location = newLocation; |
| 75 m_size = newMaxPoint - newLocation; | 72 m_size = newMaxPoint - newLocation; |
| 76 } | 73 } |
| 77 | 74 |
| 78 void LayoutRect::unite(const LayoutRect& other) | 75 void LayoutRect::unite(const LayoutRect& other) |
| 79 { | 76 { |
| 80 // Handle empty special cases first. | 77 // Handle empty special cases first. |
| 81 if (other.isEmpty()) | 78 if (other.isEmpty()) |
| 82 return; | 79 return; |
| 83 if (isEmpty()) { | 80 if (isEmpty()) { |
| 84 *this = other; | 81 *this = other; |
| 85 return; | 82 return; |
| 86 } | 83 } |
| 87 | 84 |
| 88 LayoutPoint newLocation(min(x(), other.x()), min(y(), other.y())); | 85 LayoutPoint newLocation(std::min(x(), other.x()), std::min(y(), other.y())); |
| 89 LayoutPoint newMaxPoint(max(maxX(), other.maxX()), max(maxY(), other.maxY())
); | 86 LayoutPoint newMaxPoint(std::max(maxX(), other.maxX()), std::max(maxY(), oth
er.maxY())); |
| 90 | 87 |
| 91 m_location = newLocation; | 88 m_location = newLocation; |
| 92 m_size = newMaxPoint - newLocation; | 89 m_size = newMaxPoint - newLocation; |
| 93 } | 90 } |
| 94 | 91 |
| 95 void LayoutRect::uniteIfNonZero(const LayoutRect& other) | 92 void LayoutRect::uniteIfNonZero(const LayoutRect& other) |
| 96 { | 93 { |
| 97 // Handle empty special cases first. | 94 // Handle empty special cases first. |
| 98 if (!other.width() && !other.height()) | 95 if (!other.width() && !other.height()) |
| 99 return; | 96 return; |
| 100 if (!width() && !height()) { | 97 if (!width() && !height()) { |
| 101 *this = other; | 98 *this = other; |
| 102 return; | 99 return; |
| 103 } | 100 } |
| 104 | 101 |
| 105 LayoutPoint newLocation(min(x(), other.x()), min(y(), other.y())); | 102 LayoutPoint newLocation(std::min(x(), other.x()), std::min(y(), other.y())); |
| 106 LayoutPoint newMaxPoint(max(maxX(), other.maxX()), max(maxY(), other.maxY())
); | 103 LayoutPoint newMaxPoint(std::max(maxX(), other.maxX()), std::max(maxY(), oth
er.maxY())); |
| 107 | 104 |
| 108 m_location = newLocation; | 105 m_location = newLocation; |
| 109 m_size = newMaxPoint - newLocation; | 106 m_size = newMaxPoint - newLocation; |
| 110 } | 107 } |
| 111 | 108 |
| 112 void LayoutRect::scale(float s) | 109 void LayoutRect::scale(float s) |
| 113 { | 110 { |
| 114 m_location.scale(s, s); | 111 m_location.scale(s, s); |
| 115 m_size.scale(s); | 112 m_size.scale(s); |
| 116 } | 113 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 141 } | 138 } |
| 142 | 139 |
| 143 LayoutRect enclosingLayoutRect(const FloatRect& rect) | 140 LayoutRect enclosingLayoutRect(const FloatRect& rect) |
| 144 { | 141 { |
| 145 LayoutPoint location = flooredLayoutPoint(rect.minXMinYCorner()); | 142 LayoutPoint location = flooredLayoutPoint(rect.minXMinYCorner()); |
| 146 LayoutPoint maxPoint = ceiledLayoutPoint(rect.maxXMaxYCorner()); | 143 LayoutPoint maxPoint = ceiledLayoutPoint(rect.maxXMaxYCorner()); |
| 147 return LayoutRect(location, maxPoint - location); | 144 return LayoutRect(location, maxPoint - location); |
| 148 } | 145 } |
| 149 | 146 |
| 150 } // namespace WebCore | 147 } // namespace WebCore |
| OLD | NEW |