Chromium Code Reviews| Index: components/autofill/content/public/cpp/autofill_types_struct_traits.cc |
| diff --git a/components/autofill/content/public/cpp/autofill_types_struct_traits.cc b/components/autofill/content/public/cpp/autofill_types_struct_traits.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba66563fe1df1e66117d339b64c9b06e95b383f1 |
| --- /dev/null |
| +++ b/components/autofill/content/public/cpp/autofill_types_struct_traits.cc |
| @@ -0,0 +1,128 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/autofill/content/public/cpp/autofill_types_struct_traits.h" |
| + |
| +#include "base/i18n/rtl.h" |
| +#include "url/mojo/url_gurl_struct_traits.h" |
| + |
| +using namespace autofill; |
| + |
| +namespace mojo { |
| + |
| +// static |
| +mojom::RoleAttribute StructTraits<mojom::FormFieldData, FormFieldData>::role( |
| + const FormFieldData& r) { |
| + switch (r.role) { |
| + 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
|
| + return mojom::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION; |
| + case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_OTHER: |
| + return mojom::RoleAttribute::ROLE_ATTRIBUTE_OTHER; |
| + } |
| + |
| + NOTREACHED(); |
| + return mojom::RoleAttribute::ROLE_ATTRIBUTE_OTHER; |
| +} |
| + |
| +// static |
| +mojom::TextDirection |
| +StructTraits<mojom::FormFieldData, FormFieldData>::text_direction( |
| + const FormFieldData& r) { |
| + switch (r.text_direction) { |
| + case base::i18n::TextDirection::UNKNOWN_DIRECTION: |
| + return mojom::TextDirection::UNKNOWN_DIRECTION; |
| + case base::i18n::TextDirection::RIGHT_TO_LEFT: |
| + return mojom::TextDirection::RIGHT_TO_LEFT; |
| + case base::i18n::TextDirection::LEFT_TO_RIGHT: |
| + return mojom::TextDirection::LEFT_TO_RIGHT; |
| + case base::i18n::TextDirection::TEXT_DIRECTION_NUM_DIRECTIONS: |
| + return mojom::TextDirection::TEXT_DIRECTION_NUM_DIRECTIONS; |
| + } |
| + |
| + NOTREACHED(); |
| + return mojom::TextDirection::UNKNOWN_DIRECTION; |
| +} |
| + |
| +// static |
| +bool StructTraits<mojom::FormFieldData, FormFieldData>::Read( |
| + mojom::FormFieldDataDataView data, |
| + FormFieldData* out) { |
| + if (!data.ReadLabel(&out->label)) |
| + return false; |
| + if (!data.ReadName(&out->name)) |
| + return false; |
| + if (!data.ReadValue(&out->value)) |
| + return false; |
| + |
| + if (!data.ReadFormControlType(&out->form_control_type)) |
| + return false; |
| + if (!data.ReadAutocompleteAttribute(&out->autocomplete_attribute)) |
| + return false; |
| + |
| + if (!data.ReadPlaceholder(&out->placeholder)) |
| + return false; |
| + |
| + out->max_length = data.max_length(); |
| + out->is_autofilled = data.is_autofilled(); |
| + out->is_checked = data.is_checked(); |
| + out->is_checkable = data.is_checkable(); |
| + out->is_focusable = data.is_focusable(); |
| + out->should_autocomplete = data.should_autocomplete(); |
| + |
| + switch (data.role()) { |
| + case mojom::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION: |
| + out->role = FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION; |
| + break; |
| + case mojom::RoleAttribute::ROLE_ATTRIBUTE_OTHER: |
| + out->role = FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_OTHER; |
| + break; |
| + default: |
| + return false; |
| + } |
| + switch (data.text_direction()) { |
| + case mojom::TextDirection::UNKNOWN_DIRECTION: |
| + out->text_direction = base::i18n::TextDirection::UNKNOWN_DIRECTION; |
| + break; |
| + case mojom::TextDirection::RIGHT_TO_LEFT: |
| + out->text_direction = base::i18n::TextDirection::RIGHT_TO_LEFT; |
| + break; |
| + case mojom::TextDirection::LEFT_TO_RIGHT: |
| + out->text_direction = base::i18n::TextDirection::LEFT_TO_RIGHT; |
| + break; |
| + case mojom::TextDirection::TEXT_DIRECTION_NUM_DIRECTIONS: |
| + out->text_direction = |
| + base::i18n::TextDirection::TEXT_DIRECTION_NUM_DIRECTIONS; |
| + break; |
| + default: |
| + return false; |
| + } |
| + |
| + if (!data.ReadOptionValues(&out->option_values)) |
| + return false; |
| + if (!data.ReadOptionContents(&out->option_contents)) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +// static |
| +bool StructTraits<mojom::FormData, FormData>::Read(mojom::FormDataDataView data, |
| + FormData* out) { |
| + if (!data.ReadName(&out->name)) |
| + return false; |
| + if (!data.ReadOrigin(&out->origin)) |
| + return false; |
| + if (!data.ReadAction(&out->action)) |
| + return false; |
| + |
| + out->is_form_tag = data.is_form_tag(); |
| + out->is_formless_checkout = data.is_formless_checkout(); |
| + |
| + if (!data.ReadFields(&out->fields)) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +} // namespace mojo |