1// Copyright (c) 2011 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 CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_
6#define CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_
7#pragma once
8
9#include <vector>
10
11#include "base/string16.h"
12#include "base/string_util.h"
13#include "chrome/browser/autofill/field_types.h"
14
15// This class is an interface for collections of form fields, grouped by type.
16// The information in objects of this class is managed by the
17// PersonalDataManager.
18class FormGroup {
19 public:
20  virtual ~FormGroup() {}
21
22  // Used to determine the type of a field based on the text that a user enters
23  // into the field. The field types can then be reported back to the server.
24  // This method is additive on |possible_types|.
25  virtual void GetPossibleFieldTypes(const string16& text,
26                                     FieldTypeSet* possible_types) const = 0;
27
28  // Returns a set of AutofillFieldTypes for which this FormGroup has non-empty
29  // data.
30  virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const = 0;
31
32  // Returns the string that should be auto-filled into a text field given the
33  // type of that field.
34  virtual string16 GetInfo(AutofillFieldType type) const = 0;
35
36  // Used to populate this FormGroup object with data.
37  virtual void SetInfo(AutofillFieldType type, const string16& value) = 0;
38
39  // Returns the label for this FormGroup item. This should be overridden for
40  // form group items that implement a label.
41  virtual const string16 Label() const;
42
43  // Returns true if the field data in |form_group| does not match the field
44  // data in this FormGroup.
45  virtual bool operator!=(const FormGroup& form_group) const;
46
47  // Returns true if the data in this FormGroup is a subset of the data in
48  // |form_group|.
49  bool IsSubsetOf(const FormGroup& form_group) const;
50
51  // Returns true if the values of the intersection of the available field types
52  // are equal.  If the intersection is empty, the method returns false.
53  bool IntersectionOfTypesHasEqualValues(const FormGroup& form_group) const;
54
55  // Merges the field data in |form_group| with this FormGroup.
56  void MergeWith(const FormGroup& form_group);
57
58  // Overwrites the field data in |form_group| with this FormGroup.
59  void OverwriteWith(const FormGroup& form_group);
60};
61
62#endif  // CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_
63