Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_dialog_views.cc

Issue 63053003: Ask libaddressinput for address components to use in requestAutocomplete(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: base:: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/views/autofill/autofill_dialog_views.h" 5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 1535
1536 // The rest (the |scrollable_area_|) takes up whatever's left. 1536 // The rest (the |scrollable_area_|) takes up whatever's left.
1537 if (scrollable_area_->visible()) { 1537 if (scrollable_area_->visible()) {
1538 int scroll_y = y; 1538 int scroll_y = y;
1539 if (notification_height > notification_area_->GetInsets().height()) 1539 if (notification_height > notification_area_->GetInsets().height())
1540 scroll_y += notification_height + views::kRelatedControlVerticalSpacing; 1540 scroll_y += notification_height + views::kRelatedControlVerticalSpacing;
1541 1541
1542 int scroll_bottom = content_bounds.bottom(); 1542 int scroll_bottom = content_bounds.bottom();
1543 DCHECK_EQ(scrollable_area_->contents(), details_container_); 1543 DCHECK_EQ(scrollable_area_->contents(), details_container_);
1544 details_container_->SizeToPreferredSize(); 1544 details_container_->SizeToPreferredSize();
1545 details_container_->Layout();
1545 // TODO(estade): remove this hack. See crbug.com/285996 1546 // TODO(estade): remove this hack. See crbug.com/285996
1546 details_container_->set_ignore_layouts(true); 1547 details_container_->set_ignore_layouts(true);
1547 scrollable_area_->SetBounds(x, scroll_y, width, scroll_bottom - scroll_y); 1548 scrollable_area_->SetBounds(x, scroll_y, width, scroll_bottom - scroll_y);
1548 details_container_->set_ignore_layouts(false); 1549 details_container_->set_ignore_layouts(false);
1549 } 1550 }
1550 1551
1551 if (error_bubble_) 1552 if (error_bubble_)
1552 error_bubble_->UpdatePosition(); 1553 error_bubble_->UpdatePosition();
1553 } 1554 }
1554 1555
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 } 1743 }
1743 1744
1744 // Show an error bubble when the user focuses the input. 1745 // Show an error bubble when the user focuses the input.
1745 if (focused_now) { 1746 if (focused_now) {
1746 focused_now->ScrollRectToVisible(focused_now->GetLocalBounds()); 1747 focused_now->ScrollRectToVisible(focused_now->GetLocalBounds());
1747 ShowErrorBubbleForViewIfNecessary(focused_now); 1748 ShowErrorBubbleForViewIfNecessary(focused_now);
1748 } 1749 }
1749 } 1750 }
1750 1751
1751 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) { 1752 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) {
1752 DetailsGroup* group = GroupForView(combobox); 1753 DialogSection section = GroupForView(combobox)->section;
1753 ValidateGroup(*group, VALIDATE_EDIT); 1754 ServerFieldType type = TypeForCombobox(combobox);
1754 SetEditabilityForSection(group->section); 1755
1756 int index = combobox->selected_index();
1757 delegate_->ComboboxItemSelected(type, index);
1758 // NOTE: |combobox| may have been deleted.
1759 combobox = ComboboxForType(type);
1760 combobox->SetSelectedIndex(combobox->model()->GetDefaultIndex());
1761
1762 ValidateGroup(*GroupForSection(section), VALIDATE_EDIT);
1763 SetEditabilityForSection(section);
1755 } 1764 }
1756 1765
1757 void AutofillDialogViews::StyledLabelLinkClicked(const gfx::Range& range, 1766 void AutofillDialogViews::StyledLabelLinkClicked(const gfx::Range& range,
1758 int event_flags) { 1767 int event_flags) {
1759 delegate_->LegalDocumentLinkClicked(range); 1768 delegate_->LegalDocumentLinkClicked(range);
1760 } 1769 }
1761 1770
1762 void AutofillDialogViews::OnMenuButtonClicked(views::View* source, 1771 void AutofillDialogViews::OnMenuButtonClicked(views::View* source,
1763 const gfx::Point& point) { 1772 const gfx::Point& point) {
1764 DCHECK_EQ(kSuggestedButtonClassName, source->GetClassName()); 1773 DCHECK_EQ(kSuggestedButtonClassName, source->GetClassName());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 AddChildView(sign_in_web_view_); 1911 AddChildView(sign_in_web_view_);
1903 1912
1904 overlay_view_ = new OverlayView(delegate_); 1913 overlay_view_ = new OverlayView(delegate_);
1905 overlay_view_->SetVisible(false); 1914 overlay_view_->SetVisible(false);
1906 } 1915 }
1907 1916
1908 views::View* AutofillDialogViews::CreateDetailsContainer() { 1917 views::View* AutofillDialogViews::CreateDetailsContainer() {
1909 details_container_ = new DetailsContainerView( 1918 details_container_ = new DetailsContainerView(
1910 base::Bind(&AutofillDialogViews::DetailsContainerBoundsChanged, 1919 base::Bind(&AutofillDialogViews::DetailsContainerBoundsChanged,
1911 base::Unretained(this))); 1920 base::Unretained(this)));
1921
1912 // A box layout is used because it respects widget visibility. 1922 // A box layout is used because it respects widget visibility.
1913 details_container_->SetLayoutManager( 1923 details_container_->SetLayoutManager(
1914 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 1924 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
1915 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1925 for (DetailGroupMap::iterator iter = detail_groups_.begin();
1916 iter != detail_groups_.end(); ++iter) { 1926 iter != detail_groups_.end(); ++iter) {
1917 CreateDetailsSection(iter->second.section); 1927 CreateDetailsSection(iter->second.section);
1918 details_container_->AddChildView(iter->second.container); 1928 details_container_->AddChildView(iter->second.container);
1919 } 1929 }
1920 1930
1921 return details_container_; 1931 return details_container_;
1922 } 1932 }
1923 1933
1924 void AutofillDialogViews::CreateDetailsSection(DialogSection section) { 1934 void AutofillDialogViews::CreateDetailsSection(DialogSection section) {
1925 // Inputs container (manual inputs + combobox).
1926 views::View* inputs_container = CreateInputsContainer(section);
1927
1928 DetailsGroup* group = GroupForSection(section); 1935 DetailsGroup* group = GroupForSection(section);
1929 // Container (holds label + inputs). 1936 // Container (holds label + inputs).
1930 group->container = new SectionContainer( 1937 group->container = new SectionContainer(delegate_->LabelForSection(section),
1931 delegate_->LabelForSection(section), 1938 CreateInputsContainer(section),
1932 inputs_container, 1939 group->suggested_button);
1933 group->suggested_button);
1934 DCHECK(group->suggested_button->parent()); 1940 DCHECK(group->suggested_button->parent());
1935 UpdateDetailsGroupState(*group); 1941 UpdateDetailsGroupState(*group);
1936 } 1942 }
1937 1943
1938 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) { 1944 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) {
1939 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the 1945 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the
1940 // dialog to toggle which is shown. 1946 // dialog to toggle which is shown.
1941 views::View* info_view = new views::View(); 1947 views::View* info_view = new views::View();
1942 info_view->SetLayoutManager( 1948 info_view->SetLayoutManager(
1943 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 1949 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
1944 1950
1945 views::View* manual_inputs = InitInputsView(section); 1951 DetailsGroup* group = GroupForSection(section);
1946 info_view->AddChildView(manual_inputs); 1952 group->manual_input = new views::View();
1947 SuggestionView* suggested_info = new SuggestionView(this); 1953 InitInputsView(section);
1948 info_view->AddChildView(suggested_info); 1954 info_view->AddChildView(group->manual_input);
1949 1955
1950 DetailsGroup* group = GroupForSection(section); 1956 group->suggested_info = new SuggestionView(this);
1957 info_view->AddChildView(group->suggested_info);
1958
1951 // TODO(estade): It might be slightly more OO if this button were created 1959 // TODO(estade): It might be slightly more OO if this button were created
1952 // and listened to by the section container. 1960 // and listened to by the section container.
1953 group->suggested_button = new SuggestedButton(this); 1961 group->suggested_button = new SuggestedButton(this);
1954 group->manual_input = manual_inputs;
1955 group->suggested_info = suggested_info;
1956 1962
1957 return info_view; 1963 return info_view;
1958 } 1964 }
1959 1965
1960 // TODO(estade): we should be using Chrome-style constrained window padding 1966 // TODO(estade): we should be using Chrome-style constrained window padding
1961 // values. 1967 // values.
1962 views::View* AutofillDialogViews::InitInputsView(DialogSection section) { 1968 void AutofillDialogViews::InitInputsView(DialogSection section) {
1963 const DetailInputs& inputs = delegate_->RequestedFieldsForSection(section); 1969 DetailsGroup* group = GroupForSection(section);
1964 TextfieldMap* textfields = &GroupForSection(section)->textfields; 1970 TextfieldMap* textfields = &group->textfields;
1965 ComboboxMap* comboboxes = &GroupForSection(section)->comboboxes; 1971 textfields->clear();
1966 1972
1967 views::View* view = new views::View(); 1973 ComboboxMap* comboboxes = &group->comboboxes;
1974 comboboxes->clear();
1975
1976 views::View* view = group->manual_input;
1977 view->RemoveAllChildViews(true);
1978
1968 views::GridLayout* layout = new views::GridLayout(view); 1979 views::GridLayout* layout = new views::GridLayout(view);
1969 view->SetLayoutManager(layout); 1980 view->SetLayoutManager(layout);
1970 1981
1971 int column_set_id = 0; 1982 int column_set_id = 0;
1983 const DetailInputs& inputs = delegate_->RequestedFieldsForSection(section);
1972 for (DetailInputs::const_iterator it = inputs.begin(); 1984 for (DetailInputs::const_iterator it = inputs.begin();
1973 it != inputs.end(); ++it) { 1985 it != inputs.end(); ++it) {
1974 const DetailInput& input = *it; 1986 const DetailInput& input = *it;
1987
1975 ui::ComboboxModel* input_model = 1988 ui::ComboboxModel* input_model =
1976 delegate_->ComboboxModelForAutofillType(input.type); 1989 delegate_->ComboboxModelForAutofillType(input.type);
1977 scoped_ptr<views::View> view_to_add; 1990 scoped_ptr<views::View> view_to_add;
1978 if (input_model) { 1991 if (input_model) {
1979 views::Combobox* combobox = new views::Combobox(input_model); 1992 views::Combobox* combobox = new views::Combobox(input_model);
1980 combobox->set_listener(this); 1993 combobox->set_listener(this);
1981 comboboxes->insert(std::make_pair(input.type, combobox)); 1994 comboboxes->insert(std::make_pair(input.type, combobox));
1982 SelectComboboxValueOrSetToDefault(combobox, input.initial_value); 1995 SelectComboboxValueOrSetToDefault(combobox, input.initial_value);
1983 view_to_add.reset(combobox); 1996 view_to_add.reset(combobox);
1984 } else { 1997 } else {
1985 DecoratedTextfield* field = new DecoratedTextfield( 1998 DecoratedTextfield* field = new DecoratedTextfield(input.initial_value,
1986 input.initial_value, 1999 input.placeholder_text,
1987 l10n_util::GetStringUTF16(input.placeholder_text_rid), 2000 this);
1988 this);
1989
1990 textfields->insert(std::make_pair(input.type, field)); 2001 textfields->insert(std::make_pair(input.type, field));
1991 view_to_add.reset(field); 2002 view_to_add.reset(field);
1992 } 2003 }
1993 2004
1994 if (input.length == DetailInput::NONE) { 2005 if (input.length == DetailInput::NONE) {
1995 other_owned_views_.push_back(view_to_add.release()); 2006 other_owned_views_.push_back(view_to_add.release());
1996 continue; 2007 continue;
1997 } 2008 }
1998 2009
1999 if (input.length == DetailInput::LONG) 2010 if (input.length == DetailInput::LONG)
(...skipping 22 matching lines...) Expand all
2022 0, 2033 0,
2023 0); 2034 0);
2024 2035
2025 // This is the same as AddView(view_to_add), except that 1 is used for the 2036 // This is the same as AddView(view_to_add), except that 1 is used for the
2026 // view's preferred width. Thus the width of the column completely depends 2037 // view's preferred width. Thus the width of the column completely depends
2027 // on |expand|. 2038 // on |expand|.
2028 layout->AddView(view_to_add.release(), 1, 1, 2039 layout->AddView(view_to_add.release(), 1, 1,
2029 views::GridLayout::FILL, views::GridLayout::FILL, 2040 views::GridLayout::FILL, views::GridLayout::FILL,
2030 1, 0); 2041 1, 0);
2031 2042
2032 if (input.length == DetailInput::LONG) 2043 if (input.length == DetailInput::LONG ||
2044 input.length == DetailInput::SHORT_EOL) {
2033 ++column_set_id; 2045 ++column_set_id;
2046 }
2034 } 2047 }
2035 2048
2036 SetIconsForSection(section); 2049 SetIconsForSection(section);
2037
2038 return view;
2039 } 2050 }
2040 2051
2041 void AutofillDialogViews::ShowDialogInMode(DialogMode dialog_mode) { 2052 void AutofillDialogViews::ShowDialogInMode(DialogMode dialog_mode) {
2042 loading_shield_->SetVisible(dialog_mode == LOADING); 2053 loading_shield_->SetVisible(dialog_mode == LOADING);
2043 sign_in_web_view_->SetVisible(dialog_mode == SIGN_IN); 2054 sign_in_web_view_->SetVisible(dialog_mode == SIGN_IN);
2044 notification_area_->SetVisible(dialog_mode == DETAIL_INPUT); 2055 notification_area_->SetVisible(dialog_mode == DETAIL_INPUT);
2045 scrollable_area_->SetVisible(dialog_mode == DETAIL_INPUT); 2056 scrollable_area_->SetVisible(dialog_mode == DETAIL_INPUT);
2046 FocusInitialView(); 2057 FocusInitialView();
2047 } 2058 }
2048 2059
2049 void AutofillDialogViews::UpdateSectionImpl( 2060 void AutofillDialogViews::UpdateSectionImpl(
2050 DialogSection section, 2061 DialogSection section,
2051 bool clobber_inputs) { 2062 bool clobber_inputs) {
2052 // Reset all validity marks for this section.
2053 if (clobber_inputs)
2054 MarkInputsInvalid(section, ValidityMessages(), true);
2055
2056 const DetailInputs& updated_inputs =
2057 delegate_->RequestedFieldsForSection(section);
2058 DetailsGroup* group = GroupForSection(section); 2063 DetailsGroup* group = GroupForSection(section);
2059 2064
2060 for (DetailInputs::const_iterator iter = updated_inputs.begin(); 2065 if (clobber_inputs) {
2061 iter != updated_inputs.end(); ++iter) { 2066 InitInputsView(section);
2062 const DetailInput& input = *iter; 2067 } else {
2063 TextfieldMap::iterator text_mapping = group->textfields.find(input.type); 2068 const DetailInputs& updated_inputs =
2069 delegate_->RequestedFieldsForSection(section);
2064 2070
2065 if (text_mapping != group->textfields.end()) { 2071 for (DetailInputs::const_iterator iter = updated_inputs.begin();
2066 DecoratedTextfield* decorated = text_mapping->second; 2072 iter != updated_inputs.end(); ++iter) {
2067 if (decorated->text().empty() || clobber_inputs) 2073 const DetailInput& input = *iter;
2068 decorated->SetText(input.initial_value); 2074
2075 TextfieldMap::iterator text_mapping = group->textfields.find(input.type);
2076 if (text_mapping != group->textfields.end()) {
2077 DecoratedTextfield* decorated = text_mapping->second;
2078 if (decorated->text().empty())
2079 decorated->SetText(input.initial_value);
2080 }
2081
2082 ComboboxMap::iterator combo_mapping = group->comboboxes.find(input.type);
2083 if (combo_mapping != group->comboboxes.end()) {
2084 views::Combobox* combobox = combo_mapping->second;
2085 if (combobox->selected_index() == combobox->model()->GetDefaultIndex())
2086 SelectComboboxValueOrSetToDefault(combobox, input.initial_value);
2087 }
2069 } 2088 }
2070 2089
2071 ComboboxMap::iterator combo_mapping = group->comboboxes.find(input.type); 2090 SetIconsForSection(section);
2072 if (combo_mapping != group->comboboxes.end()) {
2073 views::Combobox* combobox = combo_mapping->second;
2074 if (combobox->selected_index() == combobox->model()->GetDefaultIndex() ||
2075 clobber_inputs) {
2076 SelectComboboxValueOrSetToDefault(combobox, input.initial_value);
2077 }
2078 }
2079 } 2091 }
2080 2092
2081 SetIconsForSection(section);
2082 SetEditabilityForSection(section); 2093 SetEditabilityForSection(section);
2083 UpdateDetailsGroupState(*group); 2094 UpdateDetailsGroupState(*group);
2084 } 2095 }
2085 2096
2086 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { 2097 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) {
2087 const SuggestionState& suggestion_state = 2098 const SuggestionState& suggestion_state =
2088 delegate_->SuggestionStateForSection(group.section); 2099 delegate_->SuggestionStateForSection(group.section);
2089 group.suggested_info->SetState(suggestion_state); 2100 group.suggested_info->SetState(suggestion_state);
2090 group.manual_input->SetVisible(!suggestion_state.visible); 2101 group.manual_input->SetVisible(!suggestion_state.visible);
2091 2102
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2184 iter != group->comboboxes.end(); ++iter) { 2195 iter != group->comboboxes.end(); ++iter) {
2185 const ValidityMessage& message = 2196 const ValidityMessage& message =
2186 messages.GetMessageOrDefault(iter->first); 2197 messages.GetMessageOrDefault(iter->first);
2187 if (overwrite_unsure || message.sure) 2198 if (overwrite_unsure || message.sure)
2188 SetValidityForInput(iter->second, message.text); 2199 SetValidityForInput(iter->second, message.text);
2189 } 2200 }
2190 } else { 2201 } else {
2191 // Purge invisible views from |validity_map_|. 2202 // Purge invisible views from |validity_map_|.
2192 std::map<views::View*, base::string16>::iterator it; 2203 std::map<views::View*, base::string16>::iterator it;
2193 for (it = validity_map_.begin(); it != validity_map_.end();) { 2204 for (it = validity_map_.begin(); it != validity_map_.end();) {
2194 DCHECK(GroupForView(it->first));
2195 if (GroupForView(it->first) == group) 2205 if (GroupForView(it->first) == group)
2196 validity_map_.erase(it++); 2206 validity_map_.erase(it++);
2197 else 2207 else
2198 ++it; 2208 ++it;
2199 } 2209 }
2200 2210
2201 if (section == GetCreditCardSection()) { 2211 if (section == GetCreditCardSection()) {
2202 // Special case CVC as it's not part of |group->manual_input|. 2212 // Special case CVC as it's not part of |group->manual_input|.
2203 const ValidityMessage& message = 2213 const ValidityMessage& message =
2204 messages.GetMessageOrDefault(CREDIT_CARD_VERIFICATION_CODE); 2214 messages.GetMessageOrDefault(CREDIT_CARD_VERIFICATION_CODE);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 iter != detail_groups_.end(); ++iter) { 2407 iter != detail_groups_.end(); ++iter) {
2398 const DetailsGroup& group = iter->second; 2408 const DetailsGroup& group = iter->second;
2399 ComboboxMap::const_iterator combo_mapping = group.comboboxes.find(type); 2409 ComboboxMap::const_iterator combo_mapping = group.comboboxes.find(type);
2400 if (combo_mapping != group.comboboxes.end()) 2410 if (combo_mapping != group.comboboxes.end())
2401 return combo_mapping->second; 2411 return combo_mapping->second;
2402 } 2412 }
2403 2413
2404 return NULL; 2414 return NULL;
2405 } 2415 }
2406 2416
2417 ServerFieldType AutofillDialogViews::TypeForCombobox(
2418 const views::Combobox* combobox) const {
2419 for (DetailGroupMap::const_iterator it = detail_groups_.begin();
2420 it != detail_groups_.end(); ++it) {
2421 const DetailsGroup& group = it->second;
2422 for (ComboboxMap::const_iterator combo_it = group.comboboxes.begin();
2423 combo_it != group.comboboxes.end(); ++combo_it) {
2424 if (combo_it->second == combobox)
2425 return combo_it->first;
2426 }
2427 }
2428 NOTREACHED();
2429 return UNKNOWN_TYPE;
2430 }
2431
2407 void AutofillDialogViews::DetailsContainerBoundsChanged() { 2432 void AutofillDialogViews::DetailsContainerBoundsChanged() {
2408 if (error_bubble_) 2433 if (error_bubble_)
2409 error_bubble_->UpdatePosition(); 2434 error_bubble_->UpdatePosition();
2410 } 2435 }
2411 2436
2412 void AutofillDialogViews::SetIconsForSection(DialogSection section) { 2437 void AutofillDialogViews::SetIconsForSection(DialogSection section) {
2413 FieldValueMap user_input; 2438 FieldValueMap user_input;
2414 GetUserInput(section, &user_input); 2439 GetUserInput(section, &user_input);
2415 FieldIconMap field_icons = delegate_->IconsForFields(user_input); 2440 FieldIconMap field_icons = delegate_->IconsForFields(user_input);
2416 TextfieldMap* textfields = &GroupForSection(section)->textfields; 2441 TextfieldMap* textfields = &GroupForSection(section)->textfields;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 2480 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
2456 : section(section), 2481 : section(section),
2457 container(NULL), 2482 container(NULL),
2458 manual_input(NULL), 2483 manual_input(NULL),
2459 suggested_info(NULL), 2484 suggested_info(NULL),
2460 suggested_button(NULL) {} 2485 suggested_button(NULL) {}
2461 2486
2462 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 2487 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
2463 2488
2464 } // namespace autofill 2489 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698