Commit 12e4f945 authored by Wei Li's avatar Wei Li Committed by Commit Bot

Rename Combobox's model() to GetModel()

This prepares to have Combobox's model be used as a metadata and builder
property.

Bug: 938501
Change-Id: I5721408ab0059c2b6b54863b897005ef77e27bb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2476514Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Wei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817709}
parent a68d774e
......@@ -72,10 +72,10 @@ bool SaveCardOfferBubbleViews::Accept() {
controller()->OnSaveButton(
{cardholder_name_textfield_ ? cardholder_name_textfield_->GetText()
: base::string16(),
month_input_dropdown_ ? month_input_dropdown_->model()->GetItemAt(
month_input_dropdown_ ? month_input_dropdown_->GetModel()->GetItemAt(
month_input_dropdown_->GetSelectedIndex())
: base::string16(),
year_input_dropdown_ ? year_input_dropdown_->model()->GetItemAt(
year_input_dropdown_ ? year_input_dropdown_->GetModel()->GetItemAt(
year_input_dropdown_->GetSelectedIndex())
: base::string16()});
}
......@@ -105,10 +105,10 @@ bool SaveCardOfferBubbleViews::IsDialogButtonEnabled(
// the same time.
DCHECK(!cardholder_name_textfield_);
int month_value = 0, year_value = 0;
if (!base::StringToInt(month_input_dropdown_->model()->GetItemAt(
if (!base::StringToInt(month_input_dropdown_->GetModel()->GetItemAt(
month_input_dropdown_->GetSelectedIndex()),
&month_value) ||
!base::StringToInt(year_input_dropdown_->model()->GetItemAt(
!base::StringToInt(year_input_dropdown_->GetModel()->GetItemAt(
year_input_dropdown_->GetSelectedIndex()),
&year_value)) {
return false;
......
......@@ -678,7 +678,7 @@ void ContentSettingBubbleContents::ButtonPressed(views::Button* sender,
void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) {
DCHECK(content_setting_bubble_model_);
MediaComboboxModel* model =
static_cast<MediaComboboxModel*>(combobox->model());
static_cast<MediaComboboxModel*>(combobox->GetModel());
content_setting_bubble_model_->OnMediaMenuClicked(
model->type(), model->GetDevices()[combobox->GetSelectedIndex()].id);
}
......@@ -109,14 +109,14 @@ class ExpirationDateValidationDelegate : public ValidationDelegate {
views::Combobox* month_combobox = static_cast<views::Combobox*>(
view_parent->GetViewByID(EditorViewController::GetInputFieldViewId(
autofill::CREDIT_CARD_EXP_MONTH)));
base::string16 month =
month_combobox->model()->GetItemAt(month_combobox->GetSelectedIndex());
base::string16 month = month_combobox->GetModel()->GetItemAt(
month_combobox->GetSelectedIndex());
views::Combobox* year_combobox = static_cast<views::Combobox*>(
view_parent->GetViewByID(EditorViewController::GetInputFieldViewId(
autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR)));
base::string16 year =
year_combobox->model()->GetItemAt(year_combobox->GetSelectedIndex());
year_combobox->GetModel()->GetItemAt(year_combobox->GetSelectedIndex());
bool is_expired = IsCardExpired(month, year, app_locale_);
month_combobox->SetInvalid(is_expired);
......@@ -417,7 +417,8 @@ bool CreditCardEditorViewController::ValidateModelAndSave() {
return false;
autofill::AddressComboboxModel* model =
static_cast<autofill::AddressComboboxModel*>(address_combobox->model());
static_cast<autofill::AddressComboboxModel*>(
address_combobox->GetModel());
credit_card_to_edit_->set_billing_address_id(
model->GetItemIdentifierAt(address_combobox->GetSelectedIndex()));
......@@ -449,7 +450,7 @@ bool CreditCardEditorViewController::ValidateModelAndSave() {
if (field.second.type == kBillingAddressType) {
autofill::AddressComboboxModel* model =
static_cast<autofill::AddressComboboxModel*>(combobox->model());
static_cast<autofill::AddressComboboxModel*>(combobox->GetModel());
credit_card.set_billing_address_id(
model->GetItemIdentifierAt(combobox->GetSelectedIndex()));
......@@ -627,7 +628,8 @@ void CreditCardEditorViewController::AddAndSelectNewBillingAddress(
views::Combobox* address_combobox = static_cast<views::Combobox*>(
dialog()->GetViewByID(GetInputFieldViewId(kBillingAddressType)));
autofill::AddressComboboxModel* model =
static_cast<autofill::AddressComboboxModel*>(address_combobox->model());
static_cast<autofill::AddressComboboxModel*>(
address_combobox->GetModel());
int index = model->AddNewProfile(profile);
// SetSelectedIndex doesn't trigger a perform action notification, which is
// needed to update the valid state.
......@@ -738,7 +740,7 @@ bool CreditCardEditorViewController::CreditCardValidationDelegate::
// TODO(crbug.com/718905) Find a way to deal with existing incomplete
// addresses when choosing them as billing addresses.
autofill::AddressComboboxModel* model =
static_cast<autofill::AddressComboboxModel*>(combobox->model());
static_cast<autofill::AddressComboboxModel*>(combobox->GetModel());
if (model->GetItemIdentifierAt(combobox->GetSelectedIndex()).empty()) {
if (error_message) {
*error_message =
......
......@@ -291,7 +291,7 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestCreditCardEditorTestWithGooglePayEnabled,
EXPECT_TRUE(billing_address_combobox->GetEnabled());
autofill::AddressComboboxModel* model =
static_cast<autofill::AddressComboboxModel*>(
billing_address_combobox->model());
billing_address_combobox->GetModel());
EXPECT_EQ(
billing_profile.guid(),
model->GetItemIdentifierAt(billing_address_combobox->GetSelectedIndex()));
......
......@@ -718,7 +718,7 @@ base::string16 PaymentRequestBrowserTestBase::GetComboboxValue(
static_cast<ValidatingCombobox*>(delegate_->dialog_view()->GetViewByID(
EditorViewController::GetInputFieldViewId(type)));
DCHECK(combobox);
return combobox->model()->GetItemAt(combobox->GetSelectedIndex());
return combobox->GetModel()->GetItemAt(combobox->GetSelectedIndex());
}
void PaymentRequestBrowserTestBase::SetComboboxValue(
......@@ -739,7 +739,8 @@ void PaymentRequestBrowserTestBase::SelectBillingAddress(
EditorViewController::GetInputFieldViewId(kBillingAddressType))));
ASSERT_NE(address_combobox, nullptr);
autofill::AddressComboboxModel* address_combobox_model(
static_cast<autofill::AddressComboboxModel*>(address_combobox->model()));
static_cast<autofill::AddressComboboxModel*>(
address_combobox->GetModel()));
address_combobox->SetSelectedRow(
address_combobox_model->GetIndexOfIdentifier(billing_address_id));
address_combobox->OnBlur();
......
......@@ -587,7 +587,7 @@ void ShippingAddressEditorViewController::OnComboboxModelChanged(
if (combobox->GetID() != GetInputFieldViewId(autofill::ADDRESS_HOME_STATE))
return;
autofill::RegionComboboxModel* model =
static_cast<autofill::RegionComboboxModel*>(combobox->model());
static_cast<autofill::RegionComboboxModel*>(combobox->GetModel());
if (model->IsPendingRegionDataLoad())
return;
if (model->failed_to_load_data()) {
......
......@@ -166,7 +166,8 @@ class PaymentRequestShippingAddressEditorTest
DCHECK(country_combobox);
int selected_country_row = country_combobox->GetSelectedRow();
autofill::CountryComboboxModel* country_model =
static_cast<autofill::CountryComboboxModel*>(country_combobox->model());
static_cast<autofill::CountryComboboxModel*>(
country_combobox->GetModel());
return country_model->countries()[selected_country_row]->country_code();
}
......@@ -178,7 +179,8 @@ class PaymentRequestShippingAddressEditorTest
autofill::ADDRESS_HOME_COUNTRY)));
ASSERT_NE(nullptr, country_combobox);
autofill::CountryComboboxModel* country_model =
static_cast<autofill::CountryComboboxModel*>(country_combobox->model());
static_cast<autofill::CountryComboboxModel*>(
country_combobox->GetModel());
int i = 0;
for (; i < country_model->GetItemCount(); i++) {
if (country_model->GetItemAt(i) == country_name)
......@@ -362,7 +364,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest,
ASSERT_NE(nullptr, country_combobox);
ASSERT_EQ(0, country_combobox->GetSelectedRow());
autofill::CountryComboboxModel* country_model =
static_cast<autofill::CountryComboboxModel*>(country_combobox->model());
static_cast<autofill::CountryComboboxModel*>(
country_combobox->GetModel());
size_t num_countries = country_model->countries().size();
ASSERT_GT(num_countries, 10UL);
......@@ -383,7 +386,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest,
// Some countries don't have a state combobox.
if (region_combobox) {
autofill::RegionComboboxModel* region_model =
static_cast<autofill::RegionComboboxModel*>(region_combobox->model());
static_cast<autofill::RegionComboboxModel*>(
region_combobox->GetModel());
if (use_regions1) {
ASSERT_EQ(2, region_model->GetItemCount());
EXPECT_EQ(base::ASCIIToUTF16("---"), region_model->GetItemAt(0));
......@@ -435,8 +439,8 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest,
DCHECK(country_combobox);
EXPECT_EQ(country_index,
static_cast<size_t>(country_combobox->GetSelectedRow()));
country_model =
static_cast<autofill::CountryComboboxModel*>(country_combobox->model());
country_model = static_cast<autofill::CountryComboboxModel*>(
country_combobox->GetModel());
ASSERT_EQ(num_countries, country_model->countries().size());
// Update regions.
......
......@@ -287,8 +287,8 @@ void Combobox::SetSelectedIndex(int index) {
}
bool Combobox::SelectValue(const base::string16& value) {
for (int i = 0; i < model()->GetItemCount(); ++i) {
if (value == model()->GetItemAt(i)) {
for (int i = 0; i < GetModel()->GetItemCount(); ++i) {
if (value == GetModel()->GetItemAt(i)) {
SetSelectedIndex(i);
return true;
}
......@@ -369,7 +369,7 @@ void Combobox::OnThemeChanged() {
}
int Combobox::GetRowCount() {
return model()->GetItemCount();
return GetModel()->GetItemCount();
}
int Combobox::GetSelectedRow() {
......@@ -384,8 +384,8 @@ void Combobox::SetSelectedRow(int row) {
}
base::string16 Combobox::GetTextForRow(int row) {
return model()->IsItemSeparatorAt(row) ? base::string16()
: model()->GetItemAt(row);
return GetModel()->IsItemSeparatorAt(row) ? base::string16()
: GetModel()->GetItemAt(row);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -425,8 +425,8 @@ bool Combobox::OnKeyPressed(const ui::KeyEvent& e) {
DCHECK_EQ(e.type(), ui::ET_KEY_PRESSED);
DCHECK_GE(selected_index_, 0);
DCHECK_LT(selected_index_, model()->GetItemCount());
if (selected_index_ < 0 || selected_index_ > model()->GetItemCount())
DCHECK_LT(selected_index_, GetModel()->GetItemCount());
if (selected_index_ < 0 || selected_index_ > GetModel()->GetItemCount())
selected_index_ = 0;
bool show_menu = false;
......@@ -454,24 +454,24 @@ bool Combobox::OnKeyPressed(const ui::KeyEvent& e) {
if (e.IsAltDown())
show_menu = true;
else
new_index = GetAdjacentIndex(model(), 1, selected_index_);
new_index = GetAdjacentIndex(GetModel(), 1, selected_index_);
break;
// Move to the end of the list.
case ui::VKEY_END:
case ui::VKEY_NEXT: // Page down.
new_index = GetAdjacentIndex(model(), -1, model()->GetItemCount());
new_index = GetAdjacentIndex(GetModel(), -1, GetModel()->GetItemCount());
break;
// Move to the beginning of the list.
case ui::VKEY_HOME:
case ui::VKEY_PRIOR: // Page up.
new_index = GetAdjacentIndex(model(), 1, -1);
new_index = GetAdjacentIndex(GetModel(), 1, -1);
break;
// Move to the previous item if any.
case ui::VKEY_UP:
new_index = GetAdjacentIndex(model(), -1, selected_index_);
new_index = GetAdjacentIndex(GetModel(), -1, selected_index_);
break;
case ui::VKEY_RETURN:
......@@ -486,7 +486,7 @@ bool Combobox::OnKeyPressed(const ui::KeyEvent& e) {
if (show_menu) {
ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD);
} else if (new_index != selected_index_ && new_index != kNoSelection) {
DCHECK(!model()->IsItemSeparatorAt(new_index));
DCHECK(!GetModel()->IsItemSeparatorAt(new_index));
selected_index_ = new_index;
OnPerformAction();
}
......@@ -601,7 +601,7 @@ void Combobox::PaintIconAndText(gfx::Canvas* canvas) {
int contents_height = height() - insets.height();
// Draw the icon.
ui::ImageModel icon = model()->GetIconAt(selected_index_);
ui::ImageModel icon = GetModel()->GetIconAt(selected_index_);
if (!icon.IsEmpty()) {
gfx::ImageSkia icon_skia =
GetImageSkiaFromImageModel(&icon, GetNativeTheme());
......@@ -616,10 +616,10 @@ void Combobox::PaintIconAndText(gfx::Canvas* canvas) {
// Draw the text.
SkColor text_color = GetTextColorForEnableState(*this, GetEnabled());
DCHECK_GE(selected_index_, 0);
DCHECK_LT(selected_index_, model()->GetItemCount());
if (selected_index_ < 0 || selected_index_ > model()->GetItemCount())
DCHECK_LT(selected_index_, GetModel()->GetItemCount());
if (selected_index_ < 0 || selected_index_ > GetModel()->GetItemCount())
selected_index_ = 0;
base::string16 text = model()->GetItemAt(selected_index_);
base::string16 text = GetModel()->GetItemAt(selected_index_);
int disclosure_arrow_offset = width() - kComboboxArrowContainerWidth;
......@@ -689,13 +689,13 @@ gfx::Size Combobox::GetContentSize() const {
const gfx::FontList& font_list = GetFontList();
int height = font_list.GetHeight();
int width = 0;
for (int i = 0; i < model()->GetItemCount(); ++i) {
for (int i = 0; i < GetModel()->GetItemCount(); ++i) {
if (model_->IsItemSeparatorAt(i))
continue;
if (size_to_largest_label_ || i == selected_index_) {
int item_width = gfx::GetStringWidth(model()->GetItemAt(i), font_list);
ui::ImageModel icon = model()->GetIconAt(i);
int item_width = gfx::GetStringWidth(GetModel()->GetItemAt(i), font_list);
ui::ImageModel icon = GetModel()->GetIconAt(i);
if (!icon.IsEmpty()) {
gfx::ImageSkia icon_skia =
GetImageSkiaFromImageModel(&icon, GetNativeTheme());
......
......@@ -79,8 +79,7 @@ class VIEWS_EXPORT Combobox : public View,
void SetOwnedModel(std::unique_ptr<ui::ComboboxModel> model);
void SetModel(ui::ComboboxModel* model);
ui::ComboboxModel* model() const { return model_; }
ui::ComboboxModel* GetModel() const { return model_; }
// Gets/Sets the tooltip text, and the accessible name if it is currently
// empty.
......
......@@ -74,8 +74,8 @@ void ComboboxExample::CreateExampleView(View* container) {
void ComboboxExample::ValueChanged() {
PrintStatus("Selected: %s",
base::UTF16ToUTF8(
combobox_->model()->GetItemAt(combobox_->GetSelectedIndex()))
base::UTF16ToUTF8(combobox_->GetModel()->GetItemAt(
combobox_->GetSelectedIndex()))
.c_str());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment