BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / autofill / autofill_dialog_models.h
blob37b2f73e4c79fe2e6aec211d4bf0c277fe652ed5
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/strings/string16.h"
14 #include "ui/base/models/combobox_model.h"
15 #include "ui/base/models/simple_menu_model.h"
17 namespace autofill {
19 class SuggestionsMenuModel;
21 class SuggestionsMenuModelDelegate {
22 public:
23 virtual ~SuggestionsMenuModelDelegate();
25 // Called when a menu item has been activated.
26 virtual void SuggestionItemSelected(SuggestionsMenuModel* model,
27 size_t index) = 0;
30 // A model for the dropdowns that allow the user to select from different
31 // sets of known data. It wraps a SimpleMenuModel, providing a mapping between
32 // index and item GUID.
33 class SuggestionsMenuModel : public ui::SimpleMenuModel,
34 public ui::SimpleMenuModel::Delegate {
35 public:
36 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate* delegate);
37 ~SuggestionsMenuModel() override;
39 // Adds an item and its identifying key to the model. Keys needn't be unique.
40 void AddKeyedItem(const std::string& key,
41 const base::string16& display_label);
43 // As above, but also accepts an image which will be displayed alongside the
44 // text.
45 void AddKeyedItemWithIcon(const std::string& key,
46 const base::string16& display_label,
47 const gfx::Image& icon);
49 // Adds a label with a minor text and its identifying key to the model.
50 // Keys needn't be unique.
51 void AddKeyedItemWithMinorText(const std::string& key,
52 const base::string16& display_label,
53 const base::string16& display_minor_text);
55 // As above, but also accepts an image which will be displayed alongside the
56 // text.
57 void AddKeyedItemWithMinorTextAndIcon(
58 const std::string& key,
59 const base::string16& display_label,
60 const base::string16& display_minor_text,
61 const gfx::Image& icon);
63 // Resets the model to empty.
64 void Reset();
66 // Returns the ID key for the item at |index|.
67 std::string GetItemKeyAt(int index) const;
69 // Returns the ID key for the item at |checked_item_|, or an empty string if
70 // there are no items.
71 std::string GetItemKeyForCheckedItem() const;
73 // Sets which item is checked.
74 void SetCheckedItem(const std::string& item_key);
75 void SetCheckedIndex(size_t index);
77 int checked_item() const { return checked_item_; }
79 // Enable/disable an item by key.
80 void SetEnabled(const std::string& item_key, bool enabled);
82 // ui::SimpleMenuModel::Delegate implementation.
83 bool IsCommandIdChecked(int command_id) const override;
84 bool IsCommandIdEnabled(int command_id) const override;
85 bool GetAcceleratorForCommandId(int command_id,
86 ui::Accelerator* accelerator) override;
87 void ExecuteCommand(int command_id, int event_flags) override;
89 private:
90 // Represents an item in this model.
91 struct Item {
92 std::string key; // The key of the item.
93 bool enabled; // Whether the item is selectable.
95 // The items this model represents in presentation order.
96 // Note: the index in this vector is the |command_id| of the item.
97 std::vector<Item> items_;
99 // Returns the command id (and index) of the item by the |key|.
100 size_t GetItemIndex(const std::string& item_key);
102 SuggestionsMenuModelDelegate* delegate_;
104 // The command id (and index) of the item which is currently checked. Only one
105 // item is checked at a time.
106 int checked_item_;
108 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel);
111 // A model for possible months in the Gregorian calendar.
112 class MonthComboboxModel : public ui::ComboboxModel {
113 public:
114 MonthComboboxModel();
115 ~MonthComboboxModel() override;
117 static base::string16 FormatMonth(int index);
119 // ui::Combobox implementation:
120 int GetItemCount() const override;
121 base::string16 GetItemAt(int index) override;
123 private:
124 DISALLOW_COPY_AND_ASSIGN(MonthComboboxModel);
127 // A model for years between now and a decade hence.
128 class YearComboboxModel : public ui::ComboboxModel {
129 public:
130 YearComboboxModel();
131 ~YearComboboxModel() override;
133 // ui::Combobox implementation:
134 int GetItemCount() const override;
135 base::string16 GetItemAt(int index) override;
137 private:
138 // The current year (e.g., 2012).
139 int this_year_;
141 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel);
144 } // namespace autofill
146 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_