Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: mojo/public/cpp/bindings/tests/rect_chromium.h

Issue 1524703002: [mojo] Support native types with mojom wire format (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindings-5-pickles
Patch Set: doc Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_
7
8 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h"
9
10 namespace mojo {
11 namespace test {
12
13 // An implementation of a hypothetical Rect type specifically for consumers in
14 // in Chromium.
15 class RectChromium {
16 public:
17 RectChromium() {}
18 RectChromium(const RectChromium& other)
19 : x_(other.x_),
20 y_(other.y_),
21 width_(other.width_),
22 height_(other.height_) {}
23 RectChromium(int x, int y, int width, int height) :
24 x_(x), y_(y), width_(width), height_(height) {
25 DCHECK_GE(width_, 0);
26 DCHECK_GE(height_, 0);
27 }
28 ~RectChromium() {}
29
30 RectChromium& operator=(const RectChromium& other) {
31 x_ = other.x_;
32 y_ = other.y_;
33 width_ = other.width_;
34 height_ = other.height_;
35 return *this;
36 }
37
38 int x() const { return x_; }
39 void set_x(int x) { x_ = x; }
40
41 int y() const { return y_; }
42 void set_y(int y) { y_ = y; }
43
44 int width() const { return width_; }
45 void set_width(int width) {
46 DCHECK_GE(width, 0);
47 width_ = width;
48 }
49
50 int height() const { return height_; }
51 void set_height(int height) {
52 DCHECK_GE(height, 0);
53 height_ = height;
54 }
55
56 int GetArea() const { return width_ * height_; }
57
58 private:
59 int x_ = 0;
60 int y_ = 0;
61 int width_ = 0;
62 int height_ = 0;
63 };
64
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
86
87 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698