OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #include "components/autofill/content/public/cpp/autofill_types_struct_traits.h" | |
6 | |
7 #include "base/i18n/rtl.h" | |
8 #include "url/mojo/url_gurl_struct_traits.h" | |
9 | |
10 using namespace autofill; | |
11 | |
12 namespace mojo { | |
13 | |
14 // static | |
15 mojom::RoleAttribute StructTraits<mojom::FormFieldData, FormFieldData>::role( | |
16 const FormFieldData& r) { | |
17 switch (r.role) { | |
18 case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION: | |
dcheng
2016/05/24 22:03:48
Hm, there's no way to have a separate StructTraits
yzshen1
2016/05/24 22:09:47
No. There isn't support for "EnumTraits" currently
| |
19 return mojom::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION; | |
20 case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_OTHER: | |
21 return mojom::RoleAttribute::ROLE_ATTRIBUTE_OTHER; | |
22 } | |
23 | |
24 NOTREACHED(); | |
25 return mojom::RoleAttribute::ROLE_ATTRIBUTE_OTHER; | |
26 } | |
27 | |
28 // static | |
29 mojom::TextDirection | |
30 StructTraits<mojom::FormFieldData, FormFieldData>::text_direction( | |
31 const FormFieldData& r) { | |
32 switch (r.text_direction) { | |
33 case base::i18n::TextDirection::UNKNOWN_DIRECTION: | |
34 return mojom::TextDirection::UNKNOWN_DIRECTION; | |
35 case base::i18n::TextDirection::RIGHT_TO_LEFT: | |
36 return mojom::TextDirection::RIGHT_TO_LEFT; | |
37 case base::i18n::TextDirection::LEFT_TO_RIGHT: | |
38 return mojom::TextDirection::LEFT_TO_RIGHT; | |
39 case base::i18n::TextDirection::TEXT_DIRECTION_NUM_DIRECTIONS: | |
40 return mojom::TextDirection::TEXT_DIRECTION_NUM_DIRECTIONS; | |
41 } | |
42 | |
43 NOTREACHED(); | |
44 return mojom::TextDirection::UNKNOWN_DIRECTION; | |
45 } | |
46 | |
47 // static | |
48 bool StructTraits<mojom::FormFieldData, FormFieldData>::Read( | |
49 mojom::FormFieldDataDataView data, | |
50 FormFieldData* out) { | |
51 if (!data.ReadLabel(&out->label)) | |
52 return false; | |
53 if (!data.ReadName(&out->name)) | |
54 return false; | |
55 if (!data.ReadValue(&out->value)) | |
56 return false; | |
57 | |
58 if (!data.ReadFormControlType(&out->form_control_type)) | |
59 return false; | |
60 if (!data.ReadAutocompleteAttribute(&out->autocomplete_attribute)) | |
61 return false; | |
62 | |
63 if (!data.ReadPlaceholder(&out->placeholder)) | |
64 return false; | |
65 | |
66 out->max_length = data.max_length(); | |
67 out->is_autofilled = data.is_autofilled(); | |
68 out->is_checked = data.is_checked(); | |
69 out->is_checkable = data.is_checkable(); | |
70 out->is_focusable = data.is_focusable(); | |
71 out->should_autocomplete = data.should_autocomplete(); | |
72 | |
73 switch (data.role()) { | |
74 case mojom::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION: | |
75 out->role = FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION; | |
76 break; | |
77 case mojom::RoleAttribute::ROLE_ATTRIBUTE_OTHER: | |
78 out->role = FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_OTHER; | |
79 break; | |
80 default: | |
81 return false; | |
82 } | |
83 switch (data.text_direction()) { | |
84 case mojom::TextDirection::UNKNOWN_DIRECTION: | |
85 out->text_direction = base::i18n::TextDirection::UNKNOWN_DIRECTION; | |
86 break; | |
87 case mojom::TextDirection::RIGHT_TO_LEFT: | |
88 out->text_direction = base::i18n::TextDirection::RIGHT_TO_LEFT; | |
89 break; | |
90 case mojom::TextDirection::LEFT_TO_RIGHT: | |
91 out->text_direction = base::i18n::TextDirection::LEFT_TO_RIGHT; | |
92 break; | |
93 case mojom::TextDirection::TEXT_DIRECTION_NUM_DIRECTIONS: | |
94 out->text_direction = | |
95 base::i18n::TextDirection::TEXT_DIRECTION_NUM_DIRECTIONS; | |
96 break; | |
97 default: | |
98 return false; | |
99 } | |
100 | |
101 if (!data.ReadOptionValues(&out->option_values)) | |
102 return false; | |
103 if (!data.ReadOptionContents(&out->option_contents)) | |
104 return false; | |
105 | |
106 return true; | |
107 } | |
108 | |
109 // static | |
110 bool StructTraits<mojom::FormData, FormData>::Read(mojom::FormDataDataView data, | |
111 FormData* out) { | |
112 if (!data.ReadName(&out->name)) | |
113 return false; | |
114 if (!data.ReadOrigin(&out->origin)) | |
115 return false; | |
116 if (!data.ReadAction(&out->action)) | |
117 return false; | |
118 | |
119 out->is_form_tag = data.is_form_tag(); | |
120 out->is_formless_checkout = data.is_formless_checkout(); | |
121 | |
122 if (!data.ReadFields(&out->fields)) | |
123 return false; | |
124 | |
125 return true; | |
126 } | |
127 | |
128 } // namespace mojo | |
OLD | NEW |