blob: 653c02314f55331cc5a4bebd2c1e351cb0993d8d [file] [log] [blame]
Ben Murdocheb525c52013-07-10 11:40:50 +01001// Copyright 2013 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 COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TYPE_H_
6#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TYPE_H_
7
Ben Murdocheb525c52013-07-10 11:40:50 +01008#include <string>
9
Ben Murdocheb525c52013-07-10 11:40:50 +010010#include "components/autofill/core/browser/field_types.h"
11
12namespace autofill {
13
14// The high-level description of Autofill types, used to categorize form fields
15// and for associating form fields with form values in the Web Database.
16class AutofillType {
17 public:
Ben Murdoch32409262013-08-07 11:04:47 +010018 explicit AutofillType(ServerFieldType field_type);
Ben Murdochbb1529c2013-08-08 10:24:53 +010019 AutofillType(HtmlFieldType field_type, HtmlFieldMode mode);
Ben Murdocheb525c52013-07-10 11:40:50 +010020 AutofillType(const AutofillType& autofill_type);
21 AutofillType& operator=(const AutofillType& autofill_type);
22
Ben Murdocheb525c52013-07-10 11:40:50 +010023 FieldTypeGroup group() const;
24
Ben Murdochbb1529c2013-08-08 10:24:53 +010025 // Returns true if both the |server_type_| and the |html_type_| are set to
26 // their respective enum's unknown value.
27 bool IsUnknown() const;
28
29 // Maps |this| type to a field type that can be directly stored in an Autofill
30 // data model (in the sense that it makes sense to call
31 // |AutofillDataModel::SetRawInfo()| with the returned field type as the first
32 // parameter).
33 ServerFieldType GetStorableType() const;
34
35 // Serializes |this| type to a string.
36 std::string ToString() const;
Ben Murdocheb525c52013-07-10 11:40:50 +010037
38 // Maps |field_type| to a field type from ADDRESS_BILLING FieldTypeGroup if
39 // field type is an Address type.
Ben Murdochbb1529c2013-08-08 10:24:53 +010040 // TODO(isherman): This method is only used by the
41 // AutofillDialogControllerImpl class. Consider moving it to a more focused
42 // location.
Ben Murdoch32409262013-08-07 11:04:47 +010043 static ServerFieldType GetEquivalentBillingFieldType(
44 ServerFieldType field_type);
Ben Murdocheb525c52013-07-10 11:40:50 +010045
Ben Murdochbb1529c2013-08-08 10:24:53 +010046 // TODO(isherman): This method is only used be a single test class. Move the
47 // logic into there or something, eh?
Ben Murdoch32409262013-08-07 11:04:47 +010048 static ServerFieldType StringToFieldType(const std::string& str);
Ben Murdocheb525c52013-07-10 11:40:50 +010049
50 private:
Ben Murdochbb1529c2013-08-08 10:24:53 +010051 // The server-native field type, or UNKNOWN_TYPE if unset.
Ben Murdoch32409262013-08-07 11:04:47 +010052 ServerFieldType server_type_;
Ben Murdochbb1529c2013-08-08 10:24:53 +010053
54 // The HTML autocomplete field type and mode hints, or HTML_TYPE_UNKNOWN and
55 // HTML_MODE_NONE if unset.
56 HtmlFieldType html_type_;
57 HtmlFieldMode html_mode_;
Ben Murdocheb525c52013-07-10 11:40:50 +010058};
59
Ben Murdocheb525c52013-07-10 11:40:50 +010060} // namespace autofill
61
62#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TYPE_H_