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_
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"
19 class SuggestionsMenuModel;
21 class SuggestionsMenuModelDelegate {
23 virtual ~SuggestionsMenuModelDelegate();
25 // Called when a suggestions menu is about to show.
26 virtual void SuggestionsMenuWillShow() = 0;
28 // Called when a menu item has been activated.
29 virtual void SuggestionItemSelected(SuggestionsMenuModel* model,
33 // A model for the dropdowns that allow the user to select from different
34 // sets of known data. It wraps a SimpleMenuModel, providing a mapping between
35 // index and item GUID.
36 class SuggestionsMenuModel : public ui::SimpleMenuModel,
37 public ui::SimpleMenuModel::Delegate {
39 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate* delegate);
40 virtual ~SuggestionsMenuModel();
42 // Adds an item and its identifying key to the model. Keys needn't be unique.
43 void AddKeyedItem(const std::string& key, const string16& display_label);
45 // As above, but also accepts an image which will be displayed alongside the
47 void AddKeyedItemWithIcon(const std::string& key,
48 const string16& display_label,
49 const gfx::Image& icon);
51 // Adds a label with a minor text and its identifying key to the model.
52 // Keys needn't be unique.
53 void AddKeyedItemWithMinorText(const std::string& key,
54 const string16& display_label,
55 const string16& display_minor_text);
57 // As above, but also accepts an image which will be displayed alongside the
59 void AddKeyedItemWithMinorTextAndIcon(const std::string& key,
60 const string16& display_label,
61 const string16& display_minor_text,
62 const gfx::Image& icon);
64 // Resets the model to empty.
67 // Returns the ID key for the item at |index|.
68 std::string GetItemKeyAt(int index) const;
70 // Returns the ID key for the item at |checked_item_|, or an empty string if
71 // there are no items.
72 std::string GetItemKeyForCheckedItem() const;
74 // Sets which item is checked.
75 void SetCheckedItem(const std::string& item_key);
76 void SetCheckedIndex(size_t index);
78 int checked_item() const { return checked_item_; }
80 // Enable/disable an item by key.
81 void SetEnabled(const std::string& item_key, bool enabled);
83 // ui::SimpleMenuModel implementation.
84 virtual void MenuWillShow() OVERRIDE;
86 // ui::SimpleMenuModel::Delegate implementation.
87 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
88 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
89 virtual bool GetAcceleratorForCommandId(
91 ui::Accelerator* accelerator) OVERRIDE;
92 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
93 virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE;
96 // Represents an item in this model.
98 std::string key; // The key of the item.
99 bool enabled; // Whether the item is selectable.
101 // The items this model represents in presentation order.
102 // Note: the index in this vector is the |command_id| of the item.
103 std::vector<Item> items_;
105 // Returns the command id (and index) of the item by the |key|.
106 size_t GetItemIndex(const std::string& item_key);
108 SuggestionsMenuModelDelegate* delegate_;
110 // The command id (and index) of the item which is currently checked. Only one
111 // item is checked at a time.
114 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel);
117 // A model for possible months in the Gregorian calendar.
118 class MonthComboboxModel : public ui::ComboboxModel {
120 MonthComboboxModel();
121 virtual ~MonthComboboxModel();
123 static string16 FormatMonth(int index);
125 // ui::Combobox implementation:
126 virtual int GetItemCount() const OVERRIDE;
127 virtual string16 GetItemAt(int index) OVERRIDE;
130 DISALLOW_COPY_AND_ASSIGN(MonthComboboxModel);
133 // A model for years between now and a decade hence.
134 class YearComboboxModel : public ui::ComboboxModel {
137 virtual ~YearComboboxModel();
139 // ui::Combobox implementation:
140 virtual int GetItemCount() const OVERRIDE;
141 virtual string16 GetItemAt(int index) OVERRIDE;
144 // The current year (e.g., 2012).
147 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel);
150 } // namespace autofill
152 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_