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

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

Issue 1966933002: Mojo C++ bindings: switch the existing usage of StructTraits to use the new data view interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@26_reader
Patch Set: Created 4 years, 7 months 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
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_TRAITS_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_TRAITS_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_TRAITS_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_TRAITS_H_
7 7
8 #include "mojo/public/cpp/bindings/struct_traits.h" 8 #include "mojo/public/cpp/bindings/struct_traits.h"
9 #include "mojo/public/cpp/bindings/tests/rect_chromium.h" 9 #include "mojo/public/cpp/bindings/tests/rect_chromium.h"
10 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h" 10 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 13
14 template <> 14 template <>
15 struct StructTraits<test::TypemappedRect, test::RectChromium> { 15 struct StructTraits<test::TypemappedRect, test::RectChromium> {
16 static int x(const test::RectChromium& r) { return r.x(); } 16 static int x(const test::RectChromium& r) { return r.x(); }
17 static int y(const test::RectChromium& r) { return r.y(); } 17 static int y(const test::RectChromium& r) { return r.y(); }
18 static int width(const test::RectChromium& r) { return r.width(); } 18 static int width(const test::RectChromium& r) { return r.width(); }
19 static int height(const test::RectChromium& r) { return r.height(); } 19 static int height(const test::RectChromium& r) { return r.height(); }
20 20
21 static bool Read(test::TypemappedRect::Reader r, test::RectChromium* out) { 21 static bool Read(test::TypemappedRectDataView r, test::RectChromium* out) {
22 if (r.is_null()) {
23 *out = test::RectChromium();
24 return true;
25 }
26
22 if (r.width() < 0 || r.height() < 0) 27 if (r.width() < 0 || r.height() < 0)
23 return false; 28 return false;
24 out->set_x(r.x()); 29 out->set_x(r.x());
25 out->set_y(r.y()); 30 out->set_y(r.y());
26 out->set_width(r.width()); 31 out->set_width(r.width());
27 out->set_height(r.height()); 32 out->set_height(r.height());
28 return true; 33 return true;
29 } 34 }
30 }; 35 };
31 36
32 } // namespace mojo 37 } // namespace mojo
33 38
34 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_TRAITS_H_ 39 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_CHROMIUM_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698