| 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 | |
| 94 bool SuggestionsMenuModel::IsCommandIdChecked( | 78 bool SuggestionsMenuModel::IsCommandIdChecked( |
| 95 int command_id) const { | 79 int command_id) const { |
| 96 return checked_item_ == command_id; | 80 return checked_item_ == command_id; |
| 97 } | 81 } |
| 98 | 82 |
| 99 bool SuggestionsMenuModel::IsCommandIdEnabled( | 83 bool SuggestionsMenuModel::IsCommandIdEnabled( |
| 100 int command_id) const { | 84 int command_id) const { |
| 101 return true; | 85 return true; |
| 102 } | 86 } |
| 103 | 87 |
| 104 bool SuggestionsMenuModel::GetAcceleratorForCommandId( | 88 bool SuggestionsMenuModel::GetAcceleratorForCommandId( |
| 105 int command_id, | 89 int command_id, |
| 106 ui::Accelerator* accelerator) { | 90 ui::Accelerator* accelerator) { |
| 107 return false; | 91 return false; |
| 108 } | 92 } |
| 109 | 93 |
| 110 void SuggestionsMenuModel::ExecuteCommand(int command_id, int event_flags) { | 94 void SuggestionsMenuModel::ExecuteCommand(int command_id, int event_flags) { |
| 111 delegate_->SuggestionItemSelected(this, command_id); | 95 checked_item_ = command_id; |
| 96 delegate_->SuggestionItemSelected(*this); |
| 112 } | 97 } |
| 113 | 98 |
| 114 // MonthComboboxModel ---------------------------------------------------------- | 99 // MonthComboboxModel ---------------------------------------------------------- |
| 115 | 100 |
| 116 MonthComboboxModel::MonthComboboxModel() {} | 101 MonthComboboxModel::MonthComboboxModel() {} |
| 117 | 102 |
| 118 MonthComboboxModel::~MonthComboboxModel() {} | 103 MonthComboboxModel::~MonthComboboxModel() {} |
| 119 | 104 |
| 120 int MonthComboboxModel::GetItemCount() const { | 105 int MonthComboboxModel::GetItemCount() const { |
| 121 // 12 months plus the empty entry. | 106 // 12 months plus the empty entry. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 148 } | 133 } |
| 149 | 134 |
| 150 string16 YearComboboxModel::GetItemAt(int index) { | 135 string16 YearComboboxModel::GetItemAt(int index) { |
| 151 if (index == 0) | 136 if (index == 0) |
| 152 return string16(); | 137 return string16(); |
| 153 | 138 |
| 154 return base::IntToString16(this_year_ + index - 1); | 139 return base::IntToString16(this_year_ + index - 1); |
| 155 } | 140 } |
| 156 | 141 |
| 157 } // autofill | 142 } // autofill |
| OLD | NEW |