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

Side by Side Diff: mojo/public/cpp/bindings/tests/rect_blink.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_BLINK_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_
7
8 #include "base/logging.h"
9 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h"
10
11 namespace mojo {
12 namespace test {
13
14 // 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
16 // support negative origin coordinates and is not copyable.
17 class RectBlink {
18 public:
19 RectBlink() {}
20 RectBlink(int x, int y, int width, int height) :
21 x_(x), y_(y), width_(width), height_(height) {
22 DCHECK_GE(x_, 0);
23 DCHECK_GE(y_, 0);
24 DCHECK_GE(width_, 0);
25 DCHECK_GE(height_, 0);
26 }
27 ~RectBlink() {}
28
29 int x() const { return x_; }
30 void setX(int x) {
31 DCHECK_GE(x, 0);
32 x_ = x;
33 }
34
35 int y() const { return y_; }
36 void setY(int y) {
37 DCHECK_GE(y, 0);
38 y_ = y;
39 }
40
41 int width() const { return width_; }
42 void setWidth(int width) {
43 DCHECK_GE(width, 0);
44 width_ = width;
45 }
46
47 int height() const { return height_; }
48 void setHeight(int height) {
49 DCHECK_GE(height, 0);
50 height_ = height;
51 }
52
53 int computeArea() const { return width_ * height_; }
54
55 private:
56 int x_ = 0;
57 int y_ = 0;
58 int width_ = 0;
59 int height_ = 0;
60 };
61
62 } // 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
84
85 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698