OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "platform/testing/GeometryPrinters.h" |
| 7 |
| 8 #include "platform/geometry/FloatBox.h" |
| 9 #include "platform/geometry/FloatPoint.h" |
| 10 #include "platform/geometry/FloatQuad.h" |
| 11 #include "platform/geometry/FloatRect.h" |
| 12 #include "platform/geometry/FloatSize.h" |
| 13 #include "platform/geometry/LayoutRect.h" |
| 14 #include <ostream> // NOLINT |
| 15 |
| 16 namespace blink { |
| 17 |
| 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) |
| 43 { |
| 44 ScopedFloatFlags scope(*os); |
| 45 *os << "FloatBox(" |
| 46 << box.x() << ", " |
| 47 << box.y() << ", " |
| 48 << box.z() << ", " |
| 49 << box.width() << ", " |
| 50 << box.height() << ", " |
| 51 << box.depth() << ")"; |
| 52 } |
| 53 |
| 54 void PrintTo(const FloatPoint& point, std::ostream* os) |
| 55 { |
| 56 ScopedFloatFlags scope(*os); |
| 57 *os << "FloatPoint(" |
| 58 << point.x() << ", " |
| 59 << point.y() << ")"; |
| 60 } |
| 61 |
| 62 void PrintTo(const FloatQuad& quad, std::ostream* os) |
| 63 { |
| 64 ScopedFloatFlags scope(*os); |
| 65 *os << "FloatQuad(" |
| 66 << "(" << quad.p1().x() << ", " << quad.p1().y() << "), " |
| 67 << "(" << quad.p2().x() << ", " << quad.p2().y() << "), " |
| 68 << "(" << quad.p3().x() << ", " << quad.p3().y() << "), " |
| 69 << "(" << quad.p4().x() << ", " << quad.p4().y() << "))"; |
| 70 } |
| 71 |
| 72 void PrintTo(const FloatRect& rect, std::ostream* os) |
| 73 { |
| 74 ScopedFloatFlags scope(*os); |
| 75 *os << "FloatRect(" |
| 76 << rect.x() << ", " |
| 77 << rect.y() << ", " |
| 78 << rect.width() << ", " |
| 79 << rect.height() << ")"; |
| 80 } |
| 81 |
| 82 void PrintTo(const FloatRoundedRect& roundedRect, std::ostream* os) |
| 83 { |
| 84 *os << "FloatRoundedRect("; |
| 85 PrintTo(roundedRect.rect(), os); |
| 86 *os << ", "; |
| 87 PrintTo(roundedRect.radii(), os); |
| 88 *os << ")"; |
| 89 } |
| 90 |
| 91 void PrintTo(const FloatRoundedRect::Radii& radii, std::ostream* os) |
| 92 { |
| 93 *os << "FloatRoundedRect::Radii("; |
| 94 PrintTo(radii.topLeft(), os); |
| 95 *os << ", "; |
| 96 PrintTo(radii.topRight(), os); |
| 97 *os << ", "; |
| 98 PrintTo(radii.bottomRight(), os); |
| 99 *os << ", "; |
| 100 PrintTo(radii.bottomLeft(), os); |
| 101 *os << ")"; |
| 102 } |
| 103 |
| 104 void PrintTo(const FloatSize& size, std::ostream* os) |
| 105 { |
| 106 ScopedFloatFlags scope(*os); |
| 107 *os << "FloatSize(" |
| 108 << size.width() << ", " |
| 109 << size.height() << ")"; |
| 110 } |
| 111 |
| 112 void PrintTo(const LayoutRect& rect, std::ostream* os) |
| 113 { |
| 114 ScopedFloatFlags scope(*os); |
| 115 *os << "LayoutRect(" |
| 116 << rect.x().toFloat() << ", " |
| 117 << rect.y().toFloat() << ", " |
| 118 << rect.width().toFloat() << ", " |
| 119 << rect.height().toFloat() << ")"; |
| 120 } |
| 121 |
| 122 } // namespace blink |
OLD | NEW |