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/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(const SuggestionsMenuModel
& model
) = 0;
29 // A model for the dropdowns that allow the user to select from different
30 // sets of known data. It wraps a SimpleMenuModel, providing a mapping between
31 // index and item GUID.
32 class SuggestionsMenuModel
: public ui::SimpleMenuModel
,
33 public ui::SimpleMenuModel::Delegate
{
35 explicit SuggestionsMenuModel(SuggestionsMenuModelDelegate
* delegate
);
36 virtual ~SuggestionsMenuModel();
38 // Adds an item and its identifying key to the model. Keys needn't be unique.
39 void AddKeyedItem(const std::string
& key
, const string16
& display_label
);
41 // As above, but also accepts an image which will be displayed alongside the
43 void AddKeyedItemWithIcon(const std::string
& key
,
44 const string16
& display_label
,
45 const gfx::Image
& icon
);
47 // Adds a label with a sublabel and its identifying key to the model.
48 // Keys needn't be unique.
49 void AddKeyedItemWithSublabel(const std::string
& key
,
50 const string16
& display_label
,
51 const string16
& display_sublabel
);
53 // As above, but also accepts an image which will be displayed alongside the
55 void AddKeyedItemWithSublabelAndIcon(const std::string
& key
,
56 const string16
& display_label
,
57 const string16
& display_sublabel
,
58 const gfx::Image
& icon
);
60 // Resets the model to empty.
63 // Returns the ID key for the item at |index|.
64 std::string
GetItemKeyAt(int index
) const;
66 // Returns the ID key for the item at |checked_item_|, or an empty string if
67 // there are no items.
68 std::string
GetItemKeyForCheckedItem() const;
70 int checked_item() { return checked_item_
; }
72 // ui::SimpleMenuModel::Delegate implementation.
73 virtual bool IsCommandIdChecked(int command_id
) const OVERRIDE
;
74 virtual bool IsCommandIdEnabled(int command_id
) const OVERRIDE
;
75 virtual bool GetAcceleratorForCommandId(
77 ui::Accelerator
* accelerator
) OVERRIDE
;
78 virtual void ExecuteCommand(int command_id
, int event_flags
) OVERRIDE
;
81 // The items this model represents, in presentation order. The first
82 // string is the "key" which identifies the item. The second is the
83 // display string for the item.
84 std::vector
<std::pair
<std::string
, string16
> > items_
;
86 SuggestionsMenuModelDelegate
* delegate_
;
88 // The command id (and index) of the item which is currently checked.
91 DISALLOW_COPY_AND_ASSIGN(SuggestionsMenuModel
);
94 // A model for possible months in the Gregorian calendar.
95 class MonthComboboxModel
: public ui::ComboboxModel
{
98 virtual ~MonthComboboxModel();
100 static string16
FormatMonth(int index
);
102 // ui::Combobox implementation:
103 virtual int GetItemCount() const OVERRIDE
;
104 virtual string16
GetItemAt(int index
) OVERRIDE
;
107 DISALLOW_COPY_AND_ASSIGN(MonthComboboxModel
);
110 // A model for years between now and a decade hence.
111 class YearComboboxModel
: public ui::ComboboxModel
{
114 virtual ~YearComboboxModel();
116 // ui::Combobox implementation:
117 virtual int GetItemCount() const OVERRIDE
;
118 virtual string16
GetItemAt(int index
) OVERRIDE
;
121 // The current year (e.g., 2012).
124 DISALLOW_COPY_AND_ASSIGN(YearComboboxModel
);
129 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_MODELS_H_