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 menu item has been activated.
26 virtual void SuggestionItemSelected(SuggestionsMenuModel
* model
,
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
{
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
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
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.
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
;
90 // Represents an item in this model.
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.
108 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel
);
111 // A model for possible months in the Gregorian calendar.
112 class MonthComboboxModel
: public ui::ComboboxModel
{
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
;
124 DISALLOW_COPY_AND_ASSIGN(MonthComboboxModel
);
127 // A model for years between now and a decade hence.
128 class YearComboboxModel
: public ui::ComboboxModel
{
131 ~YearComboboxModel() override
;
133 // ui::Combobox implementation:
134 int GetItemCount() const override
;
135 base::string16
GetItemAt(int index
) override
;
138 // The current year (e.g., 2012).
141 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel
);
144 } // namespace autofill
146 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_