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 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/stringprintf.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/time.h"
12 #include "base/utf_string_conversions.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/autofill/browser/autofill_country.h"
15 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h"
22 SuggestionsMenuModelDelegate::~SuggestionsMenuModelDelegate() {}
24 // SuggestionsMenuModel ----------------------------------------------------
26 SuggestionsMenuModel::SuggestionsMenuModel(
27 SuggestionsMenuModelDelegate
* delegate
)
28 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
32 SuggestionsMenuModel::~SuggestionsMenuModel() {}
34 void SuggestionsMenuModel::AddKeyedItem(
35 const std::string
& key
, const string16
& item
) {
36 items_
.push_back(std::make_pair(key
, item
));
37 AddCheckItem(items_
.size() - 1, item
);
40 void SuggestionsMenuModel::AddKeyedItemWithIcon(
41 const std::string
& key
, const string16
& item
, const gfx::Image
& icon
) {
42 AddKeyedItem(key
, item
);
43 SetIcon(items_
.size() - 1, icon
);
46 void SuggestionsMenuModel::AddKeyedItemWithSublabel(
47 const std::string
& key
,
48 const string16
& display_label
, const string16
& display_sublabel
) {
49 AddKeyedItem(key
, display_label
);
50 SetSublabel(items_
.size() - 1, display_sublabel
);
53 void SuggestionsMenuModel::AddKeyedItemWithSublabelAndIcon(
54 const std::string
& key
,
55 const string16
& display_label
, const string16
& display_sublabel
,
56 const gfx::Image
& icon
) {
57 AddKeyedItemWithIcon(key
, display_label
, icon
);
58 SetSublabel(items_
.size() - 1, display_sublabel
);
61 void SuggestionsMenuModel::Reset() {
67 std::string
SuggestionsMenuModel::GetItemKeyAt(int index
) const {
68 return items_
[index
].first
;
71 std::string
SuggestionsMenuModel::GetItemKeyForCheckedItem() const {
75 return items_
[checked_item_
].first
;
78 bool SuggestionsMenuModel::IsCommandIdChecked(
79 int command_id
) const {
80 return checked_item_
== command_id
;
83 bool SuggestionsMenuModel::IsCommandIdEnabled(
84 int command_id
) const {
88 bool SuggestionsMenuModel::GetAcceleratorForCommandId(
90 ui::Accelerator
* accelerator
) {
94 void SuggestionsMenuModel::ExecuteCommand(int command_id
, int event_flags
) {
95 checked_item_
= command_id
;
96 delegate_
->SuggestionItemSelected(*this);
99 // MonthComboboxModel ----------------------------------------------------------
101 MonthComboboxModel::MonthComboboxModel() {}
103 MonthComboboxModel::~MonthComboboxModel() {}
105 int MonthComboboxModel::GetItemCount() const {
106 // 12 months plus the empty entry.
111 string16
MonthComboboxModel::FormatMonth(int index
) {
112 return ASCIIToUTF16(base::StringPrintf("%.2d", index
));
115 string16
MonthComboboxModel::GetItemAt(int index
) {
116 return index
== 0 ? string16() : FormatMonth(index
);
119 // YearComboboxModel -----------------------------------------------------------
121 YearComboboxModel::YearComboboxModel() : this_year_(0) {
122 base::Time time
= base::Time::Now();
123 base::Time::Exploded exploded
;
124 time
.LocalExplode(&exploded
);
125 this_year_
= exploded
.year
;
128 YearComboboxModel::~YearComboboxModel() {}
130 int YearComboboxModel::GetItemCount() const {
131 // 10 years plus the empty entry.
135 string16
YearComboboxModel::GetItemAt(int index
) {
139 return base::IntToString16(this_year_
+ index
- 1);