blob: 30fa0e1d62986936042d8aa9097d0e4c4107a6cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/autofill/autofill_dialog_models.h"
#include "base/stringprintf.h"
#include "base/strings/string_number_conversions.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
namespace autofill {
SuggestionsMenuModelDelegate::~SuggestionsMenuModelDelegate() {}
// SuggestionsMenuModel ----------------------------------------------------
SuggestionsMenuModel::SuggestionsMenuModel(
SuggestionsMenuModelDelegate* delegate)
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
delegate_(delegate),
checked_item_(0) {}
SuggestionsMenuModel::~SuggestionsMenuModel() {}
void SuggestionsMenuModel::AddKeyedItem(
const std::string& key, const string16& item) {
items_.push_back(std::make_pair(key, item));
AddCheckItem(items_.size() - 1, item);
}
std::string SuggestionsMenuModel::GetItemKeyAt(int index) const {
return items_[index].first;
}
bool SuggestionsMenuModel::IsCommandIdChecked(
int command_id) const {
return checked_item_ == command_id;
}
bool SuggestionsMenuModel::IsCommandIdEnabled(
int command_id) const {
return true;
}
bool SuggestionsMenuModel::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) {
return false;
}
void SuggestionsMenuModel::ExecuteCommand(int command_id) {
checked_item_ = command_id;
delegate_->SuggestionItemSelected(*this);
}
// MonthComboboxModel ----------------------------------------------------------
MonthComboboxModel::MonthComboboxModel() {}
MonthComboboxModel::~MonthComboboxModel() {}
int MonthComboboxModel::GetItemCount() const {
return 12;
}
string16 MonthComboboxModel::GetItemAt(int index) {
return ASCIIToUTF16(StringPrintf("%2d", index + 1));
}
// YearComboboxModel -----------------------------------------------------------
YearComboboxModel::YearComboboxModel() : this_year_(0) {
base::Time time = base::Time::Now();
base::Time::Exploded exploded;
time.LocalExplode(&exploded);
this_year_ = exploded.year;
}
YearComboboxModel::~YearComboboxModel() {}
int YearComboboxModel::GetItemCount() const {
return 10;
}
string16 YearComboboxModel::GetItemAt(int index) {
return base::IntToString16(this_year_ + index);
}
} // autofill
|