| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/testing/GeometryPrinters.h" | 5 #include "platform/testing/GeometryPrinters.h" |
| 6 | 6 |
| 7 #include "platform/geometry/FloatBox.h" | 7 #include "platform/geometry/FloatBox.h" |
| 8 #include "platform/geometry/FloatPoint.h" | 8 #include "platform/geometry/FloatPoint.h" |
| 9 #include "platform/geometry/FloatPoint3D.h" | 9 #include "platform/geometry/FloatPoint3D.h" |
| 10 #include "platform/geometry/FloatQuad.h" | 10 #include "platform/geometry/FloatQuad.h" |
| 11 #include "platform/geometry/FloatRect.h" | 11 #include "platform/geometry/FloatRect.h" |
| 12 #include "platform/geometry/FloatSize.h" | 12 #include "platform/geometry/FloatSize.h" |
| 13 #include "platform/geometry/IntPoint.h" |
| 14 #include "platform/geometry/IntRect.h" |
| 15 #include "platform/geometry/IntSize.h" |
| 16 #include "platform/geometry/LayoutPoint.h" |
| 13 #include "platform/geometry/LayoutRect.h" | 17 #include "platform/geometry/LayoutRect.h" |
| 18 #include "platform/geometry/LayoutSize.h" |
| 14 #include <ostream> // NOLINT | 19 #include <ostream> // NOLINT |
| 15 | 20 |
| 16 namespace blink { | 21 namespace blink { |
| 17 | 22 |
| 18 namespace { | |
| 19 | |
| 20 class ScopedFloatFlags { | |
| 21 public: | |
| 22 ScopedFloatFlags(std::ostream& out) : m_out(out), m_flags(out.flags()) | |
| 23 { | |
| 24 out.unsetf(std::ios::floatfield); | |
| 25 m_precision = out.precision(4); | |
| 26 } | |
| 27 | |
| 28 ~ScopedFloatFlags() | |
| 29 { | |
| 30 m_out.flags(m_flags); | |
| 31 m_out.precision(m_precision); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 std::ostream& m_out; | |
| 36 std::ios::fmtflags m_flags; | |
| 37 std::streamsize m_precision; | |
| 38 }; | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 void PrintTo(const FloatBox& box, std::ostream* os) | 23 void PrintTo(const FloatBox& box, std::ostream* os) |
| 43 { | 24 { |
| 44 ScopedFloatFlags scope(*os); | 25 *os << box.toString(); |
| 45 *os << "FloatBox(" | |
| 46 << box.x() << ", " | |
| 47 << box.y() << ", " | |
| 48 << box.z() << ", " | |
| 49 << box.width() << ", " | |
| 50 << box.height() << ", " | |
| 51 << box.depth() << ")"; | |
| 52 } | 26 } |
| 53 | 27 |
| 54 void PrintTo(const FloatPoint& point, std::ostream* os) | 28 void PrintTo(const FloatPoint& point, std::ostream* os) |
| 55 { | 29 { |
| 56 ScopedFloatFlags scope(*os); | 30 *os << point.toString(); |
| 57 *os << "FloatPoint(" | |
| 58 << point.x() << ", " | |
| 59 << point.y() << ")"; | |
| 60 } | 31 } |
| 61 | 32 |
| 62 void PrintTo(const FloatPoint3D& point, std::ostream* os) | 33 void PrintTo(const FloatPoint3D& point, std::ostream* os) |
| 63 { | 34 { |
| 64 ScopedFloatFlags scope(*os); | 35 *os << point.toString(); |
| 65 *os << "FloatPoint3D(" | |
| 66 << point.x() << ", " | |
| 67 << point.y() << ", " | |
| 68 << point.z() << ")"; | |
| 69 } | 36 } |
| 70 | 37 |
| 71 void PrintTo(const FloatQuad& quad, std::ostream* os) | 38 void PrintTo(const FloatQuad& quad, std::ostream* os) |
| 72 { | 39 { |
| 73 ScopedFloatFlags scope(*os); | 40 *os << quad.toString(); |
| 74 *os << "FloatQuad(" | |
| 75 << "(" << quad.p1().x() << ", " << quad.p1().y() << "), " | |
| 76 << "(" << quad.p2().x() << ", " << quad.p2().y() << "), " | |
| 77 << "(" << quad.p3().x() << ", " << quad.p3().y() << "), " | |
| 78 << "(" << quad.p4().x() << ", " << quad.p4().y() << "))"; | |
| 79 } | 41 } |
| 80 | 42 |
| 81 void PrintTo(const FloatRect& rect, std::ostream* os) | 43 void PrintTo(const FloatRect& rect, std::ostream* os) |
| 82 { | 44 { |
| 83 ScopedFloatFlags scope(*os); | 45 *os << rect.toString(); |
| 84 *os << "FloatRect(" | |
| 85 << rect.x() << ", " | |
| 86 << rect.y() << ", " | |
| 87 << rect.width() << ", " | |
| 88 << rect.height() << ")"; | |
| 89 } | 46 } |
| 90 | 47 |
| 91 void PrintTo(const FloatRoundedRect& roundedRect, std::ostream* os) | 48 void PrintTo(const FloatRoundedRect& roundedRect, std::ostream* os) |
| 92 { | 49 { |
| 93 *os << "FloatRoundedRect("; | 50 *os << roundedRect.toString(); |
| 94 PrintTo(roundedRect.rect(), os); | |
| 95 *os << ", "; | |
| 96 PrintTo(roundedRect.getRadii(), os); | |
| 97 *os << ")"; | |
| 98 } | 51 } |
| 99 | 52 |
| 100 void PrintTo(const FloatRoundedRect::Radii& radii, std::ostream* os) | 53 void PrintTo(const FloatRoundedRect::Radii& radii, std::ostream* os) |
| 101 { | 54 { |
| 102 *os << "FloatRoundedRect::Radii("; | 55 *os << radii.toString(); |
| 103 PrintTo(radii.topLeft(), os); | |
| 104 *os << ", "; | |
| 105 PrintTo(radii.topRight(), os); | |
| 106 *os << ", "; | |
| 107 PrintTo(radii.bottomLeft(), os); | |
| 108 *os << ", "; | |
| 109 PrintTo(radii.bottomRight(), os); | |
| 110 *os << ")"; | |
| 111 } | 56 } |
| 112 | 57 |
| 113 void PrintTo(const FloatSize& size, std::ostream* os) | 58 void PrintTo(const FloatSize& size, std::ostream* os) |
| 114 { | 59 { |
| 115 ScopedFloatFlags scope(*os); | 60 *os << size.toString(); |
| 116 *os << "FloatSize(" | 61 } |
| 117 << size.width() << ", " | 62 |
| 118 << size.height() << ")"; | 63 void PrintTo(const IntPoint& point, std::ostream* os) |
| 64 { |
| 65 *os << point.toString(); |
| 119 } | 66 } |
| 120 | 67 |
| 121 void PrintTo(const IntRect& rect, std::ostream* os) | 68 void PrintTo(const IntRect& rect, std::ostream* os) |
| 122 { | 69 { |
| 123 *os << "IntRect(" | 70 *os << rect.toString(); |
| 124 << rect.x() << ", " | 71 } |
| 125 << rect.y() << ", " | 72 |
| 126 << rect.width() << ", " | 73 void PrintTo(const IntSize& size, std::ostream* os) |
| 127 << rect.height() << ")"; | 74 { |
| 75 *os << size.toString(); |
| 76 } |
| 77 |
| 78 void PrintTo(const LayoutPoint& point, std::ostream* os) |
| 79 { |
| 80 *os << point.toString(); |
| 128 } | 81 } |
| 129 | 82 |
| 130 void PrintTo(const LayoutRect& rect, std::ostream* os) | 83 void PrintTo(const LayoutRect& rect, std::ostream* os) |
| 131 { | 84 { |
| 132 ScopedFloatFlags scope(*os); | 85 *os << rect.toString(); |
| 133 *os << "LayoutRect(" | 86 } |
| 134 << rect.x().toFloat() << ", " | 87 |
| 135 << rect.y().toFloat() << ", " | 88 void PrintTo(const LayoutSize& size, std::ostream* os) |
| 136 << rect.width().toFloat() << ", " | 89 { |
| 137 << rect.height().toFloat() << ")"; | 90 *os << size.toString(); |
| 138 } | 91 } |
| 139 | 92 |
| 140 } // namespace blink | 93 } // namespace blink |
| OLD | NEW |