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 virtual ~SuggestionsMenuModel();
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 virtual bool IsCommandIdChecked(int command_id
) const OVERRIDE
;
84 virtual bool IsCommandIdEnabled(int command_id
) const OVERRIDE
;
85 virtual bool GetAcceleratorForCommandId(
87 ui::Accelerator
* accelerator
) OVERRIDE
;
88 virtual void ExecuteCommand(int command_id
, int event_flags
) OVERRIDE
;
91 // Represents an item in this model.
93 std::string key
; // The key of the item.
94 bool enabled
; // Whether the item is selectable.
96 // The items this model represents in presentation order.
97 // Note: the index in this vector is the |command_id| of the item.
98 std::vector
<Item
> items_
;
100 // Returns the command id (and index) of the item by the |key|.
101 size_t GetItemIndex(const std::string
& item_key
);
103 SuggestionsMenuModelDelegate
* delegate_
;
105 // The command id (and index) of the item which is currently checked. Only one
106 // item is checked at a time.
109 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel
);
112 // A model for possible months in the Gregorian calendar.
113 class MonthComboboxModel
: public ui::ComboboxModel
{
115 MonthComboboxModel();
116 virtual ~MonthComboboxModel();
118 static base::string16
FormatMonth(int index
);
120 // ui::Combobox implementation:
121 virtual int GetItemCount() const OVERRIDE
;
122 virtual base::string16
GetItemAt(int index
) OVERRIDE
;
125 DISALLOW_COPY_AND_ASSIGN(MonthComboboxModel
);
128 // A model for years between now and a decade hence.
129 class YearComboboxModel
: public ui::ComboboxModel
{
132 virtual ~YearComboboxModel();
134 // ui::Combobox implementation:
135 virtual int GetItemCount() const OVERRIDE
;
136 virtual base::string16
GetItemAt(int index
) OVERRIDE
;
139 // The current year (e.g., 2012).
142 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel
);
145 } // namespace autofill
147 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_