diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 22:20:40 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 22:20:40 +0000 |
commit | daad3e3df35f5ae7e2aecb4ca1166a8bd6875af2 (patch) | |
tree | c37575ea5e5f1b67f2b4b6ccf0b25768ccf80736 | |
parent | d3eee07b9fe46ba6c0ebbe2dd040ead5961d50c6 (diff) | |
download | chromium_src-daad3e3df35f5ae7e2aecb4ca1166a8bd6875af2.zip chromium_src-daad3e3df35f5ae7e2aecb4ca1166a8bd6875af2.tar.gz chromium_src-daad3e3df35f5ae7e2aecb4ca1166a8bd6875af2.tar.bz2 |
Revert 258394 "requestAutocomplete -- accept arbitrarily long st..."
caused android test failures
> requestAutocomplete -- accept arbitrarily long street addresses
>
> This only fixes views. Mac will need to be updated as well (this change introduces ifdefs to leave the mac on its current behavior).
>
> BUG=335733
> R=groby@chromium.org, sky@chromium.org
>
> Review URL: https://codereview.chromium.org/196213003
TBR=estade@chromium.org
Review URL: https://codereview.chromium.org/207033002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258435 0039d316-1c4b-4281-b951-d872f2087c98
16 files changed, 104 insertions, 407 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_common.cc b/chrome/browser/ui/autofill/autofill_dialog_common.cc index b2e71c7..1570815 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_common.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_common.cc @@ -23,8 +23,9 @@ namespace autofill { namespace common { -bool ServerTypeEncompassesFieldType(ServerFieldType type, - const AutofillType& field_type) { +// Returns true if |input| should be shown when |field_type| has been requested. +bool ServerTypeMatchesFieldType(ServerFieldType type, + const AutofillType& field_type) { // If any credit card expiration info is asked for, show both month and year // inputs. ServerFieldType server_type = field_type.GetStorableType(); @@ -45,20 +46,15 @@ bool ServerTypeEncompassesFieldType(ServerFieldType type, if (autofill_type.group() != field_type.group()) return false; -#if defined(OS_MACOSX) // Street address (all lines) is matched to the first input address line. if (server_type == ADDRESS_HOME_STREET_ADDRESS) return autofill_type.GetStorableType() == ADDRESS_HOME_LINE1; -#else - // The page may ask for individual address lines; this roughly matches the - // street address blob. - if (server_type == ADDRESS_HOME_LINE1 || server_type == ADDRESS_HOME_LINE2) - return autofill_type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS; -#endif return autofill_type.GetStorableType() == server_type; } +// Returns true if |input| in the given |section| should be used for a +// site-requested |field|. bool ServerTypeMatchesField(DialogSection section, ServerFieldType type, const AutofillField& field) { @@ -70,13 +66,14 @@ bool ServerTypeMatchesField(DialogSection section, return type == NAME_BILLING_FULL; } - return ServerTypeEncompassesFieldType(type, field_type); + return ServerTypeMatchesFieldType(type, field_type); } bool IsCreditCardType(ServerFieldType type) { return AutofillType(type).group() == CREDIT_CARD; } +// Constructs |inputs| from template data. void BuildInputs(const DetailInput* input_template, size_t template_size, DetailInputs* inputs) { diff --git a/chrome/browser/ui/autofill/autofill_dialog_common.h b/chrome/browser/ui/autofill/autofill_dialog_common.h index f4195f8..34bc1eb 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_common.h +++ b/chrome/browser/ui/autofill/autofill_dialog_common.h @@ -27,12 +27,8 @@ enum AddressType { }; // Returns true if |type| should be shown when |field_type| has been requested. -// This filters the types that we fill into the page to match the ones the -// dialog actually cares about, preventing rAc from giving away data that an -// AutofillProfile or other data source might know about the user which isn't -// represented in the dialog. -bool ServerTypeEncompassesFieldType(ServerFieldType type, - const AutofillType& field_type); +bool ServerTypeMatchesFieldType(ServerFieldType type, + const AutofillType& field_type); // Returns true if |type| in the given |section| should be used for a // site-requested |field|. diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index 785a297..947ccab 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -189,7 +189,7 @@ bool ServerTypeMatchesShippingField(ServerFieldType type, const AutofillField& field) { // Equivalent billing field type is used to support UseBillingAsShipping // usecase. - return common::ServerTypeEncompassesFieldType( + return common::ServerTypeMatchesFieldType( type, AutofillType(AutofillType::GetEquivalentBillingFieldType( field.Type().GetStorableType()))); @@ -3269,7 +3269,7 @@ bool AutofillDialogControllerImpl::RebuildInputsForCountry( std::string country_code = AutofillCountry::GetCountryCode( country_name, g_browser_process->GetApplicationLocale()); - DCHECK(CanAcceptCountry(section, country_code)) << country_code; + DCHECK(CanAcceptCountry(section, country_code)); if (view_ && !should_clobber) { FieldValueMap outputs; diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index c041b27a..e5c40e9 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -1801,11 +1801,7 @@ TEST_F(AutofillDialogControllerTest, SaveInstrumentSameAsBilling) { CreditCard full_card(test::GetCreditCard()); for (size_t i = 0; i < inputs.size(); ++i) { const ServerFieldType type = inputs[i].type; -#if defined(OS_MACOSX) if (type == ADDRESS_BILLING_LINE1) -#else - if (type == ADDRESS_BILLING_STREET_ADDRESS) -#endif outputs[type] = ASCIIToUTF16(kEditedBillingAddress); else outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); diff --git a/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc b/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc index 8792391..c3a3900 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_i18n_input.cc @@ -56,7 +56,6 @@ void BuildAddressInputs(common::AddressType address_type, DetailInput input = { length, server_type, placeholder }; inputs->push_back(input); -#if defined(OS_MACOSX) || defined(OS_ANDROID) if (component.field == ::i18n::addressinput::STREET_ADDRESS && component.length_hint == AddressUiComponent::HINT_LONG) { // TODO(dbeam): support more than 2 address lines. http://crbug.com/324889 @@ -66,7 +65,6 @@ void BuildAddressInputs(common::AddressType address_type, DetailInput input = { length, server_type, placeholder }; inputs->push_back(input); } -#endif } ServerFieldType server_type = @@ -143,14 +141,8 @@ ServerFieldType TypeForField(AddressField address_field, return billing ? ADDRESS_BILLING_ZIP : ADDRESS_HOME_ZIP; case ::i18n::addressinput::SORTING_CODE: return billing ? ADDRESS_BILLING_SORTING_CODE : ADDRESS_HOME_SORTING_CODE; -#if defined(OS_MACOSX) || defined(OS_ANDROID) case ::i18n::addressinput::STREET_ADDRESS: return billing ? ADDRESS_BILLING_LINE1 : ADDRESS_HOME_LINE1; -#else - case ::i18n::addressinput::STREET_ADDRESS: - return billing ? ADDRESS_BILLING_STREET_ADDRESS : - ADDRESS_HOME_STREET_ADDRESS; -#endif case ::i18n::addressinput::RECIPIENT: return billing ? NAME_BILLING_FULL : NAME_FULL; case ::i18n::addressinput::ORGANIZATION: diff --git a/chrome/browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc index a78db232..87a7faf 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_i18n_input_unittest.cc @@ -13,11 +13,7 @@ namespace i18ninput { namespace { -#if defined(OS_MACOSX) const size_t kNumberOfAddressLinesUS = 7; -#else -const size_t kNumberOfAddressLinesUS = 6; -#endif } // namespace @@ -44,28 +40,22 @@ TEST(AutofillDialogI18nInput, USCityStateAndZipCodeShareInputRow) { BuildAddressInputs(common::ADDRESS_TYPE_SHIPPING, "US", &inputs); ASSERT_EQ(kNumberOfAddressLinesUS, inputs.size()); -#if defined(OS_MACOSX) - int input_index = 3; -#else - int input_index = 2; -#endif - // Inputs before or after [ City ] [ State ] [ Zip ] should be on other lines. - EXPECT_NE(inputs[input_index - 1].length, DetailInput::SHORT); + EXPECT_NE(inputs[2].length, DetailInput::SHORT); - const DetailInput& city = inputs[input_index++]; - EXPECT_EQ(ADDRESS_HOME_CITY, city.type); + const DetailInput& city = inputs[3]; + ASSERT_EQ(ADDRESS_HOME_CITY, city.type); EXPECT_EQ(city.length, DetailInput::SHORT); - const DetailInput& state = inputs[input_index++]; - EXPECT_EQ(ADDRESS_HOME_STATE, state.type); + const DetailInput& state = inputs[4]; + ASSERT_EQ(ADDRESS_HOME_STATE, state.type); EXPECT_EQ(state.length, DetailInput::SHORT); - const DetailInput& zip = inputs[input_index++]; - EXPECT_EQ(ADDRESS_HOME_ZIP, zip.type); + const DetailInput& zip = inputs[5]; + ASSERT_EQ(ADDRESS_HOME_ZIP, zip.type); EXPECT_EQ(zip.length, DetailInput::SHORT); - EXPECT_NE(inputs[input_index].length, DetailInput::SHORT); + EXPECT_NE(inputs[6].length, DetailInput::SHORT); } TEST(AutofillDialogI18nInput, IvoryCoastNoStreetLine2) { diff --git a/chrome/browser/ui/autofill/autofill_dialog_types.cc b/chrome/browser/ui/autofill/autofill_dialog_types.cc index c1a33dc..597cea5 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_types.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_types.cc @@ -22,14 +22,6 @@ namespace autofill { static const base::char16 kRangeSeparator = '|'; -// Street address is multi-line, except in countries where it shares a line -// with other inputs (such as Coite d'Ivoire). -bool DetailInput::IsMultiline() const { - return (type == ADDRESS_HOME_STREET_ADDRESS || - type == ADDRESS_BILLING_STREET_ADDRESS) && - length == DetailInput::LONG; -} - DialogNotification::DialogNotification() : type_(NONE) {} DialogNotification::DialogNotification(Type type, diff --git a/chrome/browser/ui/autofill/autofill_dialog_types.h b/chrome/browser/ui/autofill/autofill_dialog_types.h index 97926f2..c7ebcea 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_types.h +++ b/chrome/browser/ui/autofill/autofill_dialog_types.h @@ -28,16 +28,13 @@ class AutofillField; // dialog. struct DetailInput { enum Length { - SHORT, // Shares a line with other short inputs, like display: inline. - SHORT_EOL, // Like SHORT but starts a new line directly afterward. Used to - // separate groups of short inputs into different lines. - LONG, // Will be given its own full line, like display: block. - NONE, // Input will not be shown. + SHORT, // Shares a line with other short inputs, like display: inline. + SHORT_EOL, // Like SHORT but starts a new line directly afterward. Used to + // separate groups of short inputs into different lines. + LONG, // Will be given its own full line, like display: block. + NONE, // Input will not be shown. }; - // Returns whether this input can spread across multiple lines. - bool IsMultiline() const; - // Used to determine which inputs share lines when laying out. Length length; diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_view_tester_views.cc b/chrome/browser/ui/views/autofill/autofill_dialog_view_tester_views.cc index 1508425..135b151 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_view_tester_views.cc +++ b/chrome/browser/ui/views/autofill/autofill_dialog_view_tester_views.cc @@ -6,7 +6,7 @@ #include "base/logging.h" #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h" -#include "chrome/browser/ui/views/autofill/expanding_textfield.h" +#include "chrome/browser/ui/views/autofill/decorated_textfield.h" #include "ui/base/models/combobox_model.h" #include "ui/views/controls/combobox/combobox.h" #include "ui/views/controls/textfield/textfield.h" @@ -38,9 +38,9 @@ void AutofillDialogViewTesterViews::CancelForTesting() { base::string16 AutofillDialogViewTesterViews::GetTextContentsOfInput( ServerFieldType type) { - ExpandingTextfield* textfield = view_->TextfieldForType(type); + views::Textfield* textfield = view_->TextfieldForType(type); if (textfield) - return textfield->GetText(); + return textfield->text(); views::Combobox* combobox = view_->ComboboxForType(type); if (combobox) @@ -53,7 +53,7 @@ base::string16 AutofillDialogViewTesterViews::GetTextContentsOfInput( void AutofillDialogViewTesterViews::SetTextContentsOfInput( ServerFieldType type, const base::string16& contents) { - ExpandingTextfield* textfield = view_->TextfieldForType(type); + views::Textfield* textfield = view_->TextfieldForType(type); if (textfield) { textfield->SetText(contents); return; @@ -72,7 +72,8 @@ void AutofillDialogViewTesterViews::SetTextContentsOfInput( void AutofillDialogViewTesterViews::SetTextContentsOfSuggestionInput( DialogSection section, const base::string16& text) { - view_->GroupForSection(section)->suggested_info->textfield()->SetText(text); + view_->GroupForSection(section)->suggested_info->decorated_textfield()-> + SetText(text); } void AutofillDialogViewTesterViews::ActivateInput(ServerFieldType type) { diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc index 62cbe07..5d549a0 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc @@ -13,7 +13,7 @@ #include "chrome/browser/ui/autofill/autofill_dialog_sign_in_delegate.h" #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" #include "chrome/browser/ui/autofill/loading_animation.h" -#include "chrome/browser/ui/views/autofill/expanding_textfield.h" +#include "chrome/browser/ui/views/autofill/decorated_textfield.h" #include "chrome/browser/ui/views/autofill/info_bubble.h" #include "chrome/browser/ui/views/autofill/tooltip_icon.h" #include "chrome/browser/ui/views/constrained_window_views.h" @@ -147,6 +147,12 @@ void DrawArrow(gfx::Canvas* canvas, } } +// Returns whether |view| is an input (e.g. textfield, combobox). +bool IsInput(views::View* view) { + return view->GetClassName() == DecoratedTextfield::kViewClassName || + view->GetClassName() == views::Combobox::kViewClassName; +} + void SelectComboboxValueOrSetToDefault(views::Combobox* combobox, const base::string16& value) { if (!combobox->SelectValue(value)) @@ -198,12 +204,12 @@ class SectionRowView : public views::View { // Textfield is right aligned. int end_x = bounds.width(); - views::View* textfield = child_at(2); - if (textfield->visible()) { - const int preferred_width = textfield->GetPreferredSize().width(); - textfield->SetBounds(bounds.width() - preferred_width, bounds.y(), + views::View* decorated = child_at(2); + if (decorated->visible()) { + const int preferred_width = decorated->GetPreferredSize().width(); + decorated->SetBounds(bounds.width() - preferred_width, bounds.y(), preferred_width, bounds.height()); - end_x = textfield->bounds().x() - kAroundTextPadding; + end_x = decorated->bounds().x() - kAroundTextPadding; } // Label takes up all the space in between. @@ -448,15 +454,6 @@ class LoadingAnimationView : public views::View, DISALLOW_COPY_AND_ASSIGN(LoadingAnimationView); }; -// Gets either the Combobox or ExpandingTextfield that is an ancestor (including -// self) of |view|. -views::View* GetAncestralInputView(views::View* view) { - if (view->GetClassName() == views::Combobox::kViewClassName) - return view; - - return view->GetAncestorWithClassName(ExpandingTextfield::kViewClassName); -} - } // namespace // AutofillDialogViews::AccountChooser ----------------------------------------- @@ -923,7 +920,7 @@ views::View* AutofillDialogViews::SectionContainer::GetEventHandlerForRect( // Special case for (CVC) inputs in the suggestion view. if (forward_mouse_events_ && - handler->GetAncestorWithClassName(ExpandingTextfield::kViewClassName)) { + handler->GetAncestorWithClassName(DecoratedTextfield::kViewClassName)) { return handler; } @@ -1028,10 +1025,9 @@ AutofillDialogViews::SuggestionView::SuggestionView( : label_(new views::Label()), label_line_2_(new views::Label()), icon_(new views::ImageView()), - textfield_( - new ExpandingTextfield(base::string16(), + decorated_( + new DecoratedTextfield(base::string16(), base::string16(), - false, autofill_dialog)) { // TODO(estade): Make this the correct color. SetBorder(views::Border::CreateSolidSidedBorder(1, 0, 0, 0, SK_ColorLTGRAY)); @@ -1045,9 +1041,9 @@ AutofillDialogViews::SuggestionView::SuggestionView( label_container->AddChildView(label_); // TODO(estade): get the sizing and spacing right on this textfield. - textfield_->SetVisible(false); - textfield_->SetDefaultWidthInCharacters(15); - label_container->AddChildView(textfield_); + decorated_->SetVisible(false); + decorated_->set_default_width_in_chars(15); + label_container->AddChildView(decorated_); label_line_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); label_line_2_->SetVisible(false); @@ -1147,9 +1143,9 @@ void AutofillDialogViews::SuggestionView::SetIcon( void AutofillDialogViews::SuggestionView::SetTextfield( const base::string16& placeholder_text, const gfx::Image& icon) { - textfield_->SetPlaceholderText(placeholder_text); - textfield_->SetIcon(icon); - textfield_->SetVisible(!placeholder_text.empty()); + decorated_->set_placeholder_text(placeholder_text); + decorated_->SetIcon(icon); + decorated_->SetVisible(!placeholder_text.empty()); } void AutofillDialogViews::SuggestionView::UpdateLabelText() { @@ -1363,7 +1359,7 @@ void AutofillDialogViews::GetUserInput(DialogSection section, DetailsGroup* group = GroupForSection(section); for (TextfieldMap::const_iterator it = group->textfields.begin(); it != group->textfields.end(); ++it) { - output->insert(std::make_pair(it->first, it->second->GetText())); + output->insert(std::make_pair(it->first, it->second->text())); } for (ComboboxMap::const_iterator it = group->comboboxes.begin(); it != group->comboboxes.end(); ++it) { @@ -1374,7 +1370,7 @@ void AutofillDialogViews::GetUserInput(DialogSection section, base::string16 AutofillDialogViews::GetCvc() { return GroupForSection(GetCreditCardSection())->suggested_info-> - textfield()->GetText(); + decorated_textfield()->text(); } bool AutofillDialogViews::HitTestInput(ServerFieldType type, @@ -1577,14 +1573,13 @@ views::View* AutofillDialogViews::GetInitiallyFocusedView() { for (views::View* next = scrollable_area_; next; next = manager->GetNextFocusableView(next, window_, false, true)) { - views::View* input_view = GetAncestralInputView(next); - if (!input_view) + if (!IsInput(next)) continue; // If there are no invalid inputs, return the first input found. Otherwise, // return the first invalid input found. if (validity_map_.empty() || - validity_map_.find(input_view) != validity_map_.end()) { + validity_map_.find(next) != validity_map_.end()) { return next; } } @@ -1645,11 +1640,6 @@ void AutofillDialogViews::ContentsChanged(views::Textfield* sender, InputEditedOrActivated(TypeForTextfield(sender), sender->GetBoundsInScreen(), true); - - const ExpandingTextfield* expanding = static_cast<ExpandingTextfield*>( - sender->GetAncestorWithClassName(ExpandingTextfield::kViewClassName)); - if (expanding && expanding->needs_layout()) - ContentsPreferredSizeChanged(); } bool AutofillDialogViews::HandleKeyEvent(views::Textfield* sender, @@ -1942,9 +1932,8 @@ void AutofillDialogViews::InitInputsView(DialogSection section) { SelectComboboxValueOrSetToDefault(combobox, input.initial_value); view_to_add.reset(combobox); } else { - ExpandingTextfield* field = new ExpandingTextfield(input.initial_value, + DecoratedTextfield* field = new DecoratedTextfield(input.initial_value, input.placeholder_text, - input.IsMultiline(), this); textfields->insert(std::make_pair(input.type, field)); view_to_add.reset(field); @@ -2015,8 +2004,8 @@ void AutofillDialogViews::UpdateSectionImpl( views::View* focused = GetFocusManager()->GetFocusedView(); if (focused && group->container->Contains(focused)) { // Remember which view was focused before the inputs are clobbered. - if (focused->GetClassName() == ExpandingTextfield::kViewClassName) - type = TypeForTextfield(focused); + if (focused->GetClassName() == DecoratedTextfield::kViewClassName) + type = TypeForTextfield(static_cast<DecoratedTextfield*>(focused)); else if (focused->GetClassName() == views::Combobox::kViewClassName) type = TypeForCombobox(static_cast<views::Combobox*>(focused)); } @@ -2040,9 +2029,9 @@ void AutofillDialogViews::UpdateSectionImpl( TextfieldMap::iterator text_mapping = group->textfields.find(input.type); if (text_mapping != group->textfields.end()) { - ExpandingTextfield* textfield = text_mapping->second; - if (textfield->GetText().empty()) - textfield->SetText(input.initial_value); + DecoratedTextfield* decorated = text_mapping->second; + if (decorated->text().empty()) + decorated->SetText(input.initial_value); } ComboboxMap::iterator combo_mapping = group->comboboxes.find(input.type); @@ -2102,9 +2091,7 @@ void AutofillDialogViews::SetValidityForInput( } else { validity_map_.erase(input); - if (error_bubble_ && - error_bubble_->anchor()->GetAncestorWithClassName( - input->GetClassName()) == input) { + if (error_bubble_ && error_bubble_->anchor() == input) { validity_map_.erase(input); HideErrorBubble(); } @@ -2120,16 +2107,10 @@ void AutofillDialogViews::ShowErrorBubbleForViewIfNecessary(views::View* view) { return; } - if (view->GetClassName() == DecoratedTextfield::kViewClassName && - !static_cast<DecoratedTextfield*>(view)->invalid()) { - return; - } - - views::View* input_view = GetAncestralInputView(view); std::map<views::View*, base::string16>::iterator error_message = - validity_map_.find(input_view); + validity_map_.find(view); if (error_message != validity_map_.end()) { - input_view->ScrollRectToVisible(input_view->GetLocalBounds()); + view->ScrollRectToVisible(view->GetLocalBounds()); if (!error_bubble_ || error_bubble_->anchor() != view) { HideErrorBubble(); @@ -2180,7 +2161,8 @@ void AutofillDialogViews::MarkInputsInvalid( const ValidityMessage& message = messages.GetMessageOrDefault(CREDIT_CARD_VERIFICATION_CODE); if (overwrite_unsure || message.sure) { - SetValidityForInput(group->suggested_info->textfield(), message.text); + SetValidityForInput(group->suggested_info->decorated_textfield(), + message.text); } } } @@ -2198,7 +2180,7 @@ bool AutofillDialogViews::ValidateGroup(const DetailsGroup& group, if (!iter->second->editable()) continue; - detail_outputs[iter->first] = iter->second->GetText(); + detail_outputs[iter->first] = iter->second->text(); } for (ComboboxMap::const_iterator iter = group.comboboxes.begin(); iter != group.comboboxes.end(); ++iter) { @@ -2211,9 +2193,10 @@ bool AutofillDialogViews::ValidateGroup(const DetailsGroup& group, detail_outputs[iter->first] = item; } } else if (group.section == GetCreditCardSection()) { - ExpandingTextfield* cvc = group.suggested_info->textfield(); - if (cvc->visible()) - detail_outputs[CREDIT_CARD_VERIFICATION_CODE] = cvc->GetText(); + DecoratedTextfield* decorated_cvc = + group.suggested_info->decorated_textfield(); + if (decorated_cvc->visible()) + detail_outputs[CREDIT_CARD_VERIFICATION_CODE] = decorated_cvc->text(); } ValidityMessages validity = delegate_->InputsAreValid(group.section, @@ -2246,19 +2229,19 @@ void AutofillDialogViews::InputEditedOrActivated(ServerFieldType type, bool was_edit) { DCHECK_NE(UNKNOWN_TYPE, type); - ExpandingTextfield* textfield = TextfieldForType(type); + DecoratedTextfield* decorated = TextfieldForType(type); views::Combobox* combobox = ComboboxForType(type); // Both views may be NULL if the event comes from an inactive section, which // may occur when using an IME. - if (!combobox && !textfield) + if (!combobox && !decorated) return; - DCHECK_NE(!!combobox, !!textfield); - DetailsGroup* group = textfield ? GroupForView(textfield) : + DCHECK_NE(!!combobox, !!decorated); + DetailsGroup* group = decorated ? GroupForView(decorated) : GroupForView(combobox); - base::string16 text = textfield ? - textfield->GetText() : + base::string16 text = decorated ? + decorated->text() : combobox->model()->GetItemAt(combobox->selected_index()); DCHECK(group); @@ -2274,15 +2257,15 @@ void AutofillDialogViews::InputEditedOrActivated(ServerFieldType type, // so flagging them as invalid prematurely is not helpful. However, // correcting a minor mistake (i.e. a wrong CC digit) should immediately // result in validation - positive user feedback. - if (textfield && textfield->invalid() && was_edit) { + if (decorated && decorated->invalid() && was_edit) { SetValidityForInput( - textfield, + decorated, delegate_->InputValidityMessage( - group->section, type, textfield->GetText())); + group->section, type, decorated->text())); // If the field transitioned from invalid to valid, re-validate the group, // since inter-field checks become meaningful with valid fields. - if (!textfield->invalid()) + if (!decorated->invalid()) ValidateGroup(*group, VALIDATE_EDIT); } @@ -2328,20 +2311,20 @@ AutofillDialogViews::DetailsGroup* AutofillDialogViews::GroupForView( views::View* view) { DCHECK(view); - views::View* input_view = GetAncestralInputView(view); - if (!input_view) - return NULL; - for (DetailGroupMap::iterator iter = detail_groups_.begin(); iter != detail_groups_.end(); ++iter) { DetailsGroup* group = &iter->second; - if (input_view->parent() == group->manual_input) + if (view->parent() == group->manual_input) return group; + views::View* decorated = + view->GetAncestorWithClassName(DecoratedTextfield::kViewClassName); + // Textfields need to check a second case, since they can be suggested // inputs instead of directly editable inputs. Those are accessed via // |suggested_info|. - if (input_view == group->suggested_info->textfield()) { + if (decorated && + decorated == group->suggested_info->decorated_textfield()) { return group; } } @@ -2359,12 +2342,12 @@ void AutofillDialogViews::EraseInvalidViewsInGroup(const DetailsGroup* group) { } } -ExpandingTextfield* AutofillDialogViews::TextfieldForType( +DecoratedTextfield* AutofillDialogViews::TextfieldForType( ServerFieldType type) { if (type == CREDIT_CARD_VERIFICATION_CODE) { DetailsGroup* group = GroupForSection(GetCreditCardSection()); if (!group->manual_input->visible()) - return group->suggested_info->textfield(); + return group->suggested_info->decorated_textfield(); } for (DetailGroupMap::iterator iter = detail_groups_.begin(); @@ -2382,12 +2365,9 @@ ExpandingTextfield* AutofillDialogViews::TextfieldForType( } ServerFieldType AutofillDialogViews::TypeForTextfield( - const views::View* textfield) { - const views::View* expanding = - textfield->GetAncestorWithClassName(ExpandingTextfield::kViewClassName); - + const views::Textfield* textfield) { DetailsGroup* cc_group = GroupForSection(GetCreditCardSection()); - if (expanding == cc_group->suggested_info->textfield()) + if (textfield == cc_group->suggested_info->decorated_textfield()) return CREDIT_CARD_VERIFICATION_CODE; for (DetailGroupMap::const_iterator it = detail_groups_.begin(); @@ -2397,7 +2377,7 @@ ServerFieldType AutofillDialogViews::TypeForTextfield( for (TextfieldMap::const_iterator text_it = it->second.textfields.begin(); text_it != it->second.textfields.end(); ++text_it) { - if (expanding == text_it->second) + if (textfield == text_it->second) return text_it->first; } } @@ -2454,7 +2434,7 @@ void AutofillDialogViews::SetIconsForSection(DialogSection section) { ++textfield_it) { ServerFieldType field_type = textfield_it->first; FieldIconMap::const_iterator field_icon_it = field_icons.find(field_type); - ExpandingTextfield* textfield = textfield_it->second; + DecoratedTextfield* textfield = textfield_it->second; if (field_icon_it != field_icons.end()) textfield->SetIcon(field_icon_it->second); else @@ -2474,8 +2454,8 @@ void AutofillDialogViews::SetEditabilityForSection(DialogSection section) { TextfieldMap::iterator text_mapping = group->textfields.find(input.type); if (text_mapping != group->textfields.end()) { - ExpandingTextfield* textfield= text_mapping->second; - textfield->SetEditable(editable); + DecoratedTextfield* decorated = text_mapping->second; + decorated->SetEditable(editable); continue; } diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.h b/chrome/browser/ui/views/autofill/autofill_dialog_views.h index 5b0d8e3..0c6270c 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.h +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.h @@ -54,7 +54,7 @@ class KeyEvent; namespace autofill { class AutofillDialogSignInDelegate; -class ExpandingTextfield; +class DecoratedTextfield; class InfoBubble; // Views toolkit implementation of the Autofill dialog that handles the @@ -286,7 +286,7 @@ class AutofillDialogViews : public AutofillDialogView, DISALLOW_COPY_AND_ASSIGN(NotificationArea); }; - typedef std::map<ServerFieldType, ExpandingTextfield*> TextfieldMap; + typedef std::map<ServerFieldType, DecoratedTextfield*> TextfieldMap; typedef std::map<ServerFieldType, views::Combobox*> ComboboxMap; // A view that packs a label on the left and some related controls @@ -389,7 +389,7 @@ class AutofillDialogViews : public AutofillDialogView, virtual int GetHeightForWidth(int width) OVERRIDE; virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; - ExpandingTextfield* textfield() { return textfield_; } + DecoratedTextfield* decorated_textfield() { return decorated_; } private: // Returns whether there's room to display |state_.vertically_compact_text| @@ -428,7 +428,7 @@ class AutofillDialogViews : public AutofillDialogView, // The icon that comes just before |label_|. views::ImageView* icon_; // The input set by ShowTextfield. - ExpandingTextfield* textfield_; + DecoratedTextfield* decorated_; // An "Edit" link that flips to editable inputs rather than suggestion text. views::Link* edit_link_; @@ -522,7 +522,7 @@ class AutofillDialogViews : public AutofillDialogView, void FocusInitialView(); // Sets the visual state for an input to be either valid or invalid. This - // should work on Comboboxes or ExpandingTextfields. If |message| is empty, + // should work on Comboboxes or DecoratedTextfields. If |message| is empty, // the input is valid. template<class T> void SetValidityForInput(T* input, const base::string16& message); @@ -564,10 +564,10 @@ class AutofillDialogViews : public AutofillDialogView, void DoContentsPreferredSizeChanged(); // Gets the textfield view that is shown for the given |type| or NULL. - ExpandingTextfield* TextfieldForType(ServerFieldType type); + DecoratedTextfield* TextfieldForType(ServerFieldType type); // Returns the associated ServerFieldType for |textfield|. - ServerFieldType TypeForTextfield(const views::View* textfield); + ServerFieldType TypeForTextfield(const views::Textfield* textfield); // Gets the combobox view that is shown for the given |type|, or NULL. views::Combobox* ComboboxForType(ServerFieldType type); diff --git a/chrome/browser/ui/views/autofill/expanding_textfield.cc b/chrome/browser/ui/views/autofill/expanding_textfield.cc deleted file mode 100644 index 147742b..0000000 --- a/chrome/browser/ui/views/autofill/expanding_textfield.cc +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright 2014 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/views/autofill/expanding_textfield.h" - -#include "base/bind.h" -#include "base/strings/string_split.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "chrome/browser/ui/views/autofill/decorated_textfield.h" -#include "ui/views/layout/box_layout.h" - -namespace autofill { - -namespace { - -// The vertical padding between textfields. -const int kManualInputRowPadding = 10; - -} // namespace - -// static -const char ExpandingTextfield::kViewClassName[] = "autofill/ExpandingTextfield"; - -ExpandingTextfield::ExpandingTextfield( - const base::string16& default_value, - const base::string16& placeholder, - bool multiline, - views::TextfieldController* controller) - : controller_(controller) { - textfields_.push_back( - new DecoratedTextfield(base::string16(), placeholder, this)); - if (multiline) { - textfields_.push_back( - new DecoratedTextfield(base::string16(), placeholder, this)); - } - SetText(default_value); - - for (std::list<DecoratedTextfield*>::iterator iter = textfields_.begin(); - iter != textfields_.end(); ++iter) { - AddChildView(*iter); - } - - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, - kManualInputRowPadding)); -} - -ExpandingTextfield::~ExpandingTextfield() {} - -void ExpandingTextfield::SetText(const base::string16& text) { - textfields_.front()->SetText(text); - std::vector<base::string16> strings; - base::SplitStringDontTrim(text, '\n', &strings); - - size_t i = 0; - for (std::list<DecoratedTextfield*>::iterator iter = textfields_.begin(); - iter != textfields_.end(); ++iter) { - (*iter)->SetText(i < strings.size() ? strings[i++] : base::string16()); - } - - for (; i < strings.size(); ++i) { - textfields_.push_back(new DecoratedTextfield( - strings[i], - textfields_.front()->GetPlaceholderText(), - this)); - AddChildView(textfields_.back()); - PreferredSizeChanged(); - } -} - -base::string16 ExpandingTextfield::GetText() { - base::string16 text = textfields_.front()->text(); - std::list<DecoratedTextfield*>::const_iterator iter = ++textfields_.begin(); - while (iter != textfields_.end()) { - text += base::ASCIIToUTF16("\n") + (*iter++)->text(); - } - base::TrimWhitespace(text, base::TRIM_ALL, &text); - return text; -} - -void ExpandingTextfield::SetInvalid(bool invalid) { - textfields_.front()->SetInvalid(invalid); -} - -void ExpandingTextfield::SetDefaultWidthInCharacters(int chars) { - ForEachTextfield(&DecoratedTextfield::set_default_width_in_chars, chars); -} - -void ExpandingTextfield::SetPlaceholderText(const base::string16& placeholder) { - ForEachTextfield<views::Textfield, const base::string16&>( - &DecoratedTextfield::set_placeholder_text, placeholder); -} - -void ExpandingTextfield::SetIcon(const gfx::Image& icon) { - textfields_.front()->SetIcon(icon); -} - -void ExpandingTextfield::SetTooltipIcon(const base::string16& text) { - textfields_.front()->SetTooltipIcon(text); -} - -void ExpandingTextfield::SetEditable(bool editable) { - ForEachTextfield(&DecoratedTextfield::SetEditable, editable); -} - -const char* ExpandingTextfield::GetClassName() const { - return kViewClassName; -} - -void ExpandingTextfield::ContentsChanged(views::Textfield* sender, - const base::string16& new_contents) { - if (textfields_.size() > 1 && sender == textfields_.back() && - !new_contents.empty()) { - textfields_.push_back( - new DecoratedTextfield(base::string16(), - sender->GetPlaceholderText(), - this)); - AddChildView(textfields_.back()); - PreferredSizeChanged(); - } - - controller_->ContentsChanged(sender, new_contents); -} - -bool ExpandingTextfield::HandleKeyEvent(views::Textfield* sender, - const ui::KeyEvent& key_event) { - return controller_->HandleKeyEvent(sender, key_event); -} - -bool ExpandingTextfield::HandleMouseEvent(views::Textfield* sender, - const ui::MouseEvent& mouse_event) { - return controller_->HandleMouseEvent(sender, mouse_event); -} - -template <typename BaseType, typename Param> -void ExpandingTextfield::ForEachTextfield( - void (BaseType::* f)(Param), Param p) const { - for (std::list<DecoratedTextfield*>::const_iterator iter = - textfields_.begin(); - iter != textfields_.end(); ++iter) { - base::Bind(f, base::Unretained(*iter), p).Run(); - } -} - -} // namespace autofill diff --git a/chrome/browser/ui/views/autofill/expanding_textfield.h b/chrome/browser/ui/views/autofill/expanding_textfield.h deleted file mode 100644 index c34bf76..0000000 --- a/chrome/browser/ui/views/autofill/expanding_textfield.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2014 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. - -#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_EXPANDING_TEXTFIELD_H_ -#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_EXPANDING_TEXTFIELD_H_ - -#include <list> - -#include "base/strings/string16.h" -#include "chrome/browser/ui/views/autofill/decorated_textfield.h" -#include "ui/views/controls/textfield/textfield_controller.h" -#include "ui/views/view.h" - -namespace gfx { -class Image; -} - -namespace autofill { - -// A view that houses a stack of textfields. The stack grows as needed. -class ExpandingTextfield : public views::View, - public views::TextfieldController { - public: - static const char kViewClassName[]; - - // When |multiline| is false, the view acts pretty much like a normal - // DecoratedTextfield. - ExpandingTextfield(const base::string16& default_value, - const base::string16& placeholder, - bool multiline, - views::TextfieldController* controller); - virtual ~ExpandingTextfield(); - - // Sets the contents of the textfields. Textfield n is set to the nth line - // of |text|, as separated by line returns. - void SetText(const base::string16& text); - // Concatenates text contents of all textfields (with line returns as the - // joining character) and returns it. - base::string16 GetText(); - - // Sets whether to indicate the first textfield has invalid content. Latter - // textfields are always valid. - void SetInvalid(bool invalid); - bool invalid() { - return textfields_.front()->invalid(); - } - - // Like validity, this only cares about the first textfield. - void SetEditable(bool editable); - bool editable() { - return textfields_.front()->editable(); - } - - // DecoratedTextfield pass-throughs. - void SetDefaultWidthInCharacters(int chars); - void SetPlaceholderText(const base::string16& placeholder); - void SetIcon(const gfx::Image& icon); - void SetTooltipIcon(const base::string16& text); - - // View implementation. - virtual const char* GetClassName() const OVERRIDE; - using views::View::needs_layout; - - // TextfieldController implementation. - virtual void ContentsChanged(views::Textfield* sender, - const base::string16& new_contents) OVERRIDE; - virtual bool HandleKeyEvent(views::Textfield* sender, - const ui::KeyEvent& key_event) OVERRIDE; - virtual bool HandleMouseEvent(views::Textfield* sender, - const ui::MouseEvent& mouse_event) OVERRIDE; - - private: - // Calls a given function on every textfield. - template <typename BaseType, typename Param> - void ForEachTextfield(void (BaseType::* f)(Param), Param p) const; - - // The list of textfields. Owned as child views. - std::list<DecoratedTextfield*> textfields_; - - TextfieldController* controller_; - - DISALLOW_COPY_AND_ASSIGN(ExpandingTextfield); -}; - -} // namespace autofill - -#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_EXPANDING_TEXTFIELD_H_ diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index eb86d2f..4ee4ae8 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -1748,8 +1748,6 @@ 'browser/ui/views/autofill/new_credit_card_bubble_views.h', 'browser/ui/views/autofill/decorated_textfield.cc', 'browser/ui/views/autofill/decorated_textfield.h', - 'browser/ui/views/autofill/expanding_textfield.cc', - 'browser/ui/views/autofill/expanding_textfield.h', 'browser/ui/views/autofill/info_bubble.cc', 'browser/ui/views/autofill/info_bubble.h', 'browser/ui/views/autofill/password_generation_popup_view_views.cc', diff --git a/ui/views/view.cc b/ui/views/view.cc index 02b5603..5875c7c 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -590,19 +590,14 @@ const char* View::GetClassName() const { return kViewClassName; } -const View* View::GetAncestorWithClassName(const std::string& name) const { - for (const View* view = this; view; view = view->parent_) { +View* View::GetAncestorWithClassName(const std::string& name) { + for (View* view = this; view; view = view->parent_) { if (!strcmp(view->GetClassName(), name.c_str())) return view; } return NULL; } -View* View::GetAncestorWithClassName(const std::string& name) { - return const_cast<View*>(const_cast<const View*>(this)-> - GetAncestorWithClassName(name)); -} - const View* View::GetViewByID(int id) const { if (id == id_) return const_cast<View*>(this); diff --git a/ui/views/view.h b/ui/views/view.h index ac90d7e..cc4c9a1 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -404,7 +404,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Returns the first ancestor, starting at this, whose class name is |name|. // Returns null if no ancestor has the class name |name|. - const View* GetAncestorWithClassName(const std::string& name) const; View* GetAncestorWithClassName(const std::string& name); // Recursively descends the view tree starting at this view, and returns @@ -1025,8 +1024,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // changed. The default implementation calls SchedulePaint() on this View. virtual void OnEnabledChanged(); - bool needs_layout() const { return needs_layout_; } - // Tree operations ----------------------------------------------------------- // This method is invoked when the tree changes. |