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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h" | |
10 | 9 |
11 namespace mojo { | 10 namespace mojo { |
12 namespace test { | 11 namespace test { |
13 | 12 |
14 // An implementation of a hypothetical Rect type specifically for consumers in | 13 // An implementation of a hypothetical Rect type specifically for consumers in |
15 // in Blink. Unlike the Chromium variant (see rect_chromium.h) this does not | 14 // in Blink. Unlike the Chromium variant (see rect_chromium.h) this does not |
16 // support negative origin coordinates and is not copyable. | 15 // support negative origin coordinates and is not copyable. |
17 class RectBlink { | 16 class RectBlink { |
18 public: | 17 public: |
19 RectBlink() {} | 18 RectBlink() {} |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 int computeArea() const { return width_ * height_; } | 52 int computeArea() const { return width_ * height_; } |
54 | 53 |
55 private: | 54 private: |
56 int x_ = 0; | 55 int x_ = 0; |
57 int y_ = 0; | 56 int y_ = 0; |
58 int width_ = 0; | 57 int width_ = 0; |
59 int height_ = 0; | 58 int height_ = 0; |
60 }; | 59 }; |
61 | 60 |
62 } // namespace test | 61 } // namespace test |
63 | |
64 template <> | |
65 struct StructTraits<test::Rect, test::RectBlink> { | |
66 static int x(const test::RectBlink& r) { return r.x(); } | |
67 static int y(const test::RectBlink& r) { return r.y(); } | |
68 static int width(const test::RectBlink& r) { return r.width(); } | |
69 static int height(const test::RectBlink& r) { return r.height(); } | |
70 | |
71 static bool Read(test::Rect::Reader r, test::RectBlink* out) { | |
72 if (r.x() < 0 || r.y() < 0 || r.width() < 0 || r.height() < 0) { | |
73 return false; | |
74 } | |
75 out->setX(r.x()); | |
76 out->setY(r.y()); | |
77 out->setWidth(r.width()); | |
78 out->setHeight(r.height()); | |
79 return true; | |
80 } | |
81 }; | |
82 | |
83 } // namespace mojo | 62 } // namespace mojo |
84 | 63 |
85 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_ | 64 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_ |
OLD | NEW |