| 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_CHROMIUM_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ |
| 7 | 7 |
| 8 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| 11 namespace test { | 11 namespace test { |
| 12 | 12 |
| 13 // An implementation of a hypothetical Rect type specifically for consumers in | 13 // An implementation of a hypothetical Rect type specifically for consumers in |
| 14 // in Chromium. | 14 // in Chromium. |
| 15 class RectChromium { | 15 class RectChromium { |
| 16 public: | 16 public: |
| 17 RectChromium() {} | 17 RectChromium() {} |
| 18 RectChromium(const RectChromium& other) | 18 RectChromium(const RectChromium& other) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 int GetArea() const { return width_ * height_; } | 56 int GetArea() const { return width_ * height_; } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 int x_ = 0; | 59 int x_ = 0; |
| 60 int y_ = 0; | 60 int y_ = 0; |
| 61 int width_ = 0; | 61 int width_ = 0; |
| 62 int height_ = 0; | 62 int height_ = 0; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 } // namespace test | 65 } // namespace test |
| 66 | |
| 67 template <> | |
| 68 struct StructTraits<test::Rect, test::RectChromium> { | |
| 69 static int x(const test::RectChromium& r) { return r.x(); } | |
| 70 static int y(const test::RectChromium& r) { return r.y(); } | |
| 71 static int width(const test::RectChromium& r) { return r.width(); } | |
| 72 static int height(const test::RectChromium& r) { return r.height(); } | |
| 73 | |
| 74 static bool Read(test::Rect::Reader r, test::RectChromium* out) { | |
| 75 if (r.width() < 0 || r.height() < 0) | |
| 76 return false; | |
| 77 out->set_x(r.x()); | |
| 78 out->set_y(r.y()); | |
| 79 out->set_width(r.width()); | |
| 80 out->set_height(r.height()); | |
| 81 return true; | |
| 82 } | |
| 83 }; | |
| 84 | |
| 85 } // namespace mojo | 66 } // namespace mojo |
| 86 | 67 |
| 87 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ | 68 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_ |
| OLD | NEW |