// 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/string_number_conversions.h" #include "base/stringprintf.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