| 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 15 matching lines...) Expand all Loading... |
| 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 "platform/geometry/LayoutRect.h" | 31 #include "platform/geometry/LayoutRect.h" |
| 32 | 32 |
| 33 #include "platform/LayoutUnit.h" | 33 #include "platform/LayoutUnit.h" |
| 34 #include "platform/geometry/DoubleRect.h" | 34 #include "platform/geometry/DoubleRect.h" |
| 35 #include "platform/geometry/FloatRect.h" | 35 #include "platform/geometry/FloatRect.h" |
| 36 #include "wtf/text/WTFString.h" | |
| 37 #include <algorithm> | 36 #include <algorithm> |
| 38 #include <stdio.h> | 37 #include <ostream> // NOLINT |
| 39 | 38 |
| 40 namespace blink { | 39 namespace blink { |
| 41 | 40 |
| 42 LayoutRect::LayoutRect(const FloatRect& r) | 41 LayoutRect::LayoutRect(const FloatRect& r) |
| 43 : m_location(LayoutPoint(r.location())) | 42 : m_location(LayoutPoint(r.location())) |
| 44 , m_size(LayoutSize(r.size())) | 43 , m_size(LayoutSize(r.size())) |
| 45 { | 44 { |
| 46 } | 45 } |
| 47 | 46 |
| 48 LayoutRect::LayoutRect(const DoubleRect& r) | 47 LayoutRect::LayoutRect(const DoubleRect& r) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 m_location.scale(s, s); | 134 m_location.scale(s, s); |
| 136 m_size.scale(s); | 135 m_size.scale(s); |
| 137 } | 136 } |
| 138 | 137 |
| 139 void LayoutRect::scale(float xAxisScale, float yAxisScale) | 138 void LayoutRect::scale(float xAxisScale, float yAxisScale) |
| 140 { | 139 { |
| 141 m_location.scale(xAxisScale, yAxisScale); | 140 m_location.scale(xAxisScale, yAxisScale); |
| 142 m_size.scale(xAxisScale, yAxisScale); | 141 m_size.scale(xAxisScale, yAxisScale); |
| 143 } | 142 } |
| 144 | 143 |
| 145 #ifndef NDEBUG | |
| 146 void LayoutRect::show(bool showRawValue) const | |
| 147 { | |
| 148 if (showRawValue) | |
| 149 printf("Rect (in raw layout units): [x=%d y=%d maxX=%d maxY=%d]\n", x().
rawValue(), y().rawValue(), maxX().rawValue(), maxY().rawValue()); | |
| 150 else | |
| 151 printf("Rect (in pixels): [x=%lf y=%lf maxX=%lf maxY=%lf]\n", x().toDoub
le(), y().toDouble(), maxX().toDouble(), maxY().toDouble()); | |
| 152 } | |
| 153 | |
| 154 String LayoutRect::toString() const | |
| 155 { | |
| 156 return String::format("%s %s", location().toString().ascii().data(), size().
toString().ascii().data()); | |
| 157 } | |
| 158 #endif | |
| 159 | |
| 160 LayoutRect unionRect(const Vector<LayoutRect>& rects) | 144 LayoutRect unionRect(const Vector<LayoutRect>& rects) |
| 161 { | 145 { |
| 162 LayoutRect result; | 146 LayoutRect result; |
| 163 | 147 |
| 164 size_t count = rects.size(); | 148 size_t count = rects.size(); |
| 165 for (size_t i = 0; i < count; ++i) | 149 for (size_t i = 0; i < count; ++i) |
| 166 result.unite(rects[i]); | 150 result.unite(rects[i]); |
| 167 | 151 |
| 168 return result; | 152 return result; |
| 169 } | 153 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 189 return IntRect(location, maxPoint - location); | 173 return IntRect(location, maxPoint - location); |
| 190 } | 174 } |
| 191 | 175 |
| 192 LayoutRect enclosingLayoutRect(const FloatRect& rect) | 176 LayoutRect enclosingLayoutRect(const FloatRect& rect) |
| 193 { | 177 { |
| 194 LayoutPoint location = flooredLayoutPoint(rect.minXMinYCorner()); | 178 LayoutPoint location = flooredLayoutPoint(rect.minXMinYCorner()); |
| 195 LayoutPoint maxPoint = ceiledLayoutPoint(rect.maxXMaxYCorner()); | 179 LayoutPoint maxPoint = ceiledLayoutPoint(rect.maxXMaxYCorner()); |
| 196 return LayoutRect(location, maxPoint - location); | 180 return LayoutRect(location, maxPoint - location); |
| 197 } | 181 } |
| 198 | 182 |
| 183 std::ostream& operator<<(std::ostream& os, const LayoutRect& rect) |
| 184 { |
| 185 os << "LayoutRect(" |
| 186 << "x=" << rect.x() << ", " |
| 187 << "y=" << rect.y() << ", " |
| 188 << "width=" << rect.width() << ", " |
| 189 << "height=" << rect.height() << ")"; |
| 190 return os; |
| 191 } |
| 192 |
| 199 } // namespace blink | 193 } // namespace blink |
| OLD | NEW |