OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 return items_[index].first; | 68 return items_[index].first; |
69 } | 69 } |
70 | 70 |
71 std::string SuggestionsMenuModel::GetItemKeyForCheckedItem() const { | 71 std::string SuggestionsMenuModel::GetItemKeyForCheckedItem() const { |
72 if (items_.empty()) | 72 if (items_.empty()) |
73 return std::string(); | 73 return std::string(); |
74 | 74 |
75 return items_[checked_item_].first; | 75 return items_[checked_item_].first; |
76 } | 76 } |
77 | 77 |
| 78 void SuggestionsMenuModel::SetCheckedItem(const std::string& item_key) { |
| 79 for (size_t i = 0; i < items_.size(); ++i) { |
| 80 if (items_[i].first == item_key) { |
| 81 checked_item_ = i; |
| 82 return; |
| 83 } |
| 84 } |
| 85 |
| 86 NOTREACHED(); |
| 87 } |
| 88 |
| 89 void SuggestionsMenuModel::SetCheckedIndex(size_t index) { |
| 90 DCHECK_LE(index, items_.size()); |
| 91 checked_item_ = index; |
| 92 } |
| 93 |
78 bool SuggestionsMenuModel::IsCommandIdChecked( | 94 bool SuggestionsMenuModel::IsCommandIdChecked( |
79 int command_id) const { | 95 int command_id) const { |
80 return checked_item_ == command_id; | 96 return checked_item_ == command_id; |
81 } | 97 } |
82 | 98 |
83 bool SuggestionsMenuModel::IsCommandIdEnabled( | 99 bool SuggestionsMenuModel::IsCommandIdEnabled( |
84 int command_id) const { | 100 int command_id) const { |
85 return true; | 101 return true; |
86 } | 102 } |
87 | 103 |
88 bool SuggestionsMenuModel::GetAcceleratorForCommandId( | 104 bool SuggestionsMenuModel::GetAcceleratorForCommandId( |
89 int command_id, | 105 int command_id, |
90 ui::Accelerator* accelerator) { | 106 ui::Accelerator* accelerator) { |
91 return false; | 107 return false; |
92 } | 108 } |
93 | 109 |
94 void SuggestionsMenuModel::ExecuteCommand(int command_id, int event_flags) { | 110 void SuggestionsMenuModel::ExecuteCommand(int command_id, int event_flags) { |
95 checked_item_ = command_id; | 111 delegate_->SuggestionItemSelected(this, command_id); |
96 delegate_->SuggestionItemSelected(*this); | |
97 } | 112 } |
98 | 113 |
99 // MonthComboboxModel ---------------------------------------------------------- | 114 // MonthComboboxModel ---------------------------------------------------------- |
100 | 115 |
101 MonthComboboxModel::MonthComboboxModel() {} | 116 MonthComboboxModel::MonthComboboxModel() {} |
102 | 117 |
103 MonthComboboxModel::~MonthComboboxModel() {} | 118 MonthComboboxModel::~MonthComboboxModel() {} |
104 | 119 |
105 int MonthComboboxModel::GetItemCount() const { | 120 int MonthComboboxModel::GetItemCount() const { |
106 // 12 months plus the empty entry. | 121 // 12 months plus the empty entry. |
(...skipping 26 matching lines...) Expand all Loading... |
133 } | 148 } |
134 | 149 |
135 string16 YearComboboxModel::GetItemAt(int index) { | 150 string16 YearComboboxModel::GetItemAt(int index) { |
136 if (index == 0) | 151 if (index == 0) |
137 return string16(); | 152 return string16(); |
138 | 153 |
139 return base::IntToString16(this_year_ + index - 1); | 154 return base::IntToString16(this_year_ + index - 1); |
140 } | 155 } |
141 | 156 |
142 } // autofill | 157 } // autofill |
OLD | NEW |