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

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: . Created 7 years 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 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 } 1733 }
1734 1734
1735 // Show an error bubble when the user focuses the input. 1735 // Show an error bubble when the user focuses the input.
1736 if (focused_now) { 1736 if (focused_now) {
1737 focused_now->ScrollRectToVisible(focused_now->GetLocalBounds()); 1737 focused_now->ScrollRectToVisible(focused_now->GetLocalBounds());
1738 ShowErrorBubbleForViewIfNecessary(focused_now); 1738 ShowErrorBubbleForViewIfNecessary(focused_now);
1739 } 1739 }
1740 } 1740 }
1741 1741
1742 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) { 1742 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) {
1743 DetailsGroup* group = GroupForView(combobox); 1743 DialogSection section = GroupForView(combobox)->section;
1744 ValidateGroup(*group, VALIDATE_EDIT); 1744 int index = combobox->selected_index();
1745 SetEditabilityForSection(group->section); 1745 delegate_->ComboboxItemSelected(combobox->model(), section, index);
1746 ValidateGroup(*GroupForSection(section), VALIDATE_EDIT);
1747 SetEditabilityForSection(section);
1746 } 1748 }
1747 1749
1748 void AutofillDialogViews::StyledLabelLinkClicked(const gfx::Range& range, 1750 void AutofillDialogViews::StyledLabelLinkClicked(const gfx::Range& range,
1749 int event_flags) { 1751 int event_flags) {
1750 delegate_->LegalDocumentLinkClicked(range); 1752 delegate_->LegalDocumentLinkClicked(range);
1751 } 1753 }
1752 1754
1753 void AutofillDialogViews::OnMenuButtonClicked(views::View* source, 1755 void AutofillDialogViews::OnMenuButtonClicked(views::View* source,
1754 const gfx::Point& point) { 1756 const gfx::Point& point) {
1755 DCHECK_EQ(kSuggestedButtonClassName, source->GetClassName()); 1757 DCHECK_EQ(kSuggestedButtonClassName, source->GetClassName());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 AddChildView(sign_in_web_view_); 1895 AddChildView(sign_in_web_view_);
1894 1896
1895 overlay_view_ = new OverlayView(delegate_); 1897 overlay_view_ = new OverlayView(delegate_);
1896 overlay_view_->SetVisible(false); 1898 overlay_view_->SetVisible(false);
1897 } 1899 }
1898 1900
1899 views::View* AutofillDialogViews::CreateDetailsContainer() { 1901 views::View* AutofillDialogViews::CreateDetailsContainer() {
1900 details_container_ = new DetailsContainerView( 1902 details_container_ = new DetailsContainerView(
1901 base::Bind(&AutofillDialogViews::DetailsContainerBoundsChanged, 1903 base::Bind(&AutofillDialogViews::DetailsContainerBoundsChanged,
1902 base::Unretained(this))); 1904 base::Unretained(this)));
1905
1903 // A box layout is used because it respects widget visibility. 1906 // A box layout is used because it respects widget visibility.
1904 details_container_->SetLayoutManager( 1907 details_container_->SetLayoutManager(
1905 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 1908 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
1906 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1909 for (DetailGroupMap::iterator iter = detail_groups_.begin();
1907 iter != detail_groups_.end(); ++iter) { 1910 iter != detail_groups_.end(); ++iter) {
1908 CreateDetailsSection(iter->second.section); 1911 CreateDetailsSection(iter->second.section);
1909 details_container_->AddChildView(iter->second.container); 1912 details_container_->AddChildView(iter->second.container);
1910 } 1913 }
1911 1914
1912 return details_container_; 1915 return details_container_;
1913 } 1916 }
1914 1917
1915 void AutofillDialogViews::CreateDetailsSection(DialogSection section) { 1918 void AutofillDialogViews::CreateDetailsSection(DialogSection section) {
1916 // Inputs container (manual inputs + combobox). 1919 // Inputs container (manual inputs + combobox).
1917 views::View* inputs_container = CreateInputsContainer(section); 1920 views::View* inputs_container = CreateInputsContainer(section);
Evan Stade 2013/12/02 23:30:34 nit (although you didn't change this), please inli
Dan Beam 2013/12/03 02:11:19 Done.
1921 DetailsGroup* group = GroupForSection(section);
1918 1922
1919 DetailsGroup* group = GroupForSection(section);
1920 // Container (holds label + inputs). 1923 // Container (holds label + inputs).
1921 group->container = new SectionContainer( 1924 group->container = new SectionContainer(
1922 delegate_->LabelForSection(section), 1925 delegate_->LabelForSection(section),
1923 inputs_container, 1926 inputs_container,
1924 group->suggested_button); 1927 group->suggested_button);
1925 DCHECK(group->suggested_button->parent()); 1928 DCHECK(group->suggested_button->parent());
1926 UpdateDetailsGroupState(*group); 1929 UpdateDetailsGroupState(*group);
1927 } 1930 }
1928 1931
1929 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) { 1932 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) {
1930 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the 1933 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the
1931 // dialog to toggle which is shown. 1934 // dialog to toggle which is shown.
1932 views::View* info_view = new views::View(); 1935 views::View* info_view = new views::View();
1933 info_view->SetLayoutManager( 1936 info_view->SetLayoutManager(
1934 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 1937 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
1935 1938
1936 views::View* manual_inputs = InitInputsView(section); 1939 DetailsGroup* group = GroupForSection(section);
1937 info_view->AddChildView(manual_inputs); 1940 group->manual_input = new views::View();
1938 SuggestionView* suggested_info = new SuggestionView(this); 1941 InitInputsView(section);
1939 info_view->AddChildView(suggested_info); 1942 info_view->AddChildView(group->manual_input);
1940 1943
1941 DetailsGroup* group = GroupForSection(section); 1944 group->suggested_info = new SuggestionView(this);
1945 info_view->AddChildView(group->suggested_info);
1946
1942 // TODO(estade): It might be slightly more OO if this button were created 1947 // TODO(estade): It might be slightly more OO if this button were created
1943 // and listened to by the section container. 1948 // and listened to by the section container.
1944 group->suggested_button = new SuggestedButton(this); 1949 group->suggested_button = new SuggestedButton(this);
1945 group->manual_input = manual_inputs;
1946 group->suggested_info = suggested_info;
1947 1950
1948 return info_view; 1951 return info_view;
1949 } 1952 }
1950 1953
1951 // TODO(estade): we should be using Chrome-style constrained window padding 1954 // TODO(estade): we should be using Chrome-style constrained window padding
1952 // values. 1955 // values.
1953 views::View* AutofillDialogViews::InitInputsView(DialogSection section) { 1956 void AutofillDialogViews::InitInputsView(DialogSection section) {
1954 const DetailInputs& inputs = delegate_->RequestedFieldsForSection(section); 1957 DetailsGroup* group = GroupForSection(section);
1955 TextfieldMap* textfields = &GroupForSection(section)->textfields; 1958 TextfieldMap* textfields = &group->textfields;
1956 ComboboxMap* comboboxes = &GroupForSection(section)->comboboxes; 1959 textfields->clear();
1957 1960
1958 views::View* view = new views::View(); 1961 ComboboxMap* comboboxes = &group->comboboxes;
1962 comboboxes->clear();
1963
1964 views::View* view = group->manual_input;
1965 view->RemoveAllChildViews(true);
1966
1959 views::GridLayout* layout = new views::GridLayout(view); 1967 views::GridLayout* layout = new views::GridLayout(view);
1960 view->SetLayoutManager(layout); 1968 view->SetLayoutManager(layout);
1961 1969
1970 const DetailInputs& inputs = delegate_->RequestedFieldsForSection(section);
1962 for (DetailInputs::const_iterator it = inputs.begin(); 1971 for (DetailInputs::const_iterator it = inputs.begin();
1963 it != inputs.end(); ++it) { 1972 it != inputs.end(); ++it) {
1964 const DetailInput& input = *it; 1973 const DetailInput& input = *it;
1974
1965 ui::ComboboxModel* input_model = 1975 ui::ComboboxModel* input_model =
1966 delegate_->ComboboxModelForAutofillType(input.type); 1976 delegate_->ComboboxModelForAutofillType(input.type);
1967 scoped_ptr<views::View> view_to_add; 1977 scoped_ptr<views::View> view_to_add;
1968 if (input_model) { 1978 if (input_model) {
1969 views::Combobox* combobox = new views::Combobox(input_model); 1979 views::Combobox* combobox = new views::Combobox(input_model);
1970 combobox->set_listener(this); 1980 combobox->set_listener(this);
1971 comboboxes->insert(std::make_pair(input.type, combobox)); 1981 comboboxes->insert(std::make_pair(input.type, combobox));
1972 SelectComboboxValueOrSetToDefault(combobox, input.initial_value); 1982 SelectComboboxValueOrSetToDefault(combobox, input.initial_value);
1973 view_to_add.reset(combobox); 1983 view_to_add.reset(combobox);
1974 } else { 1984 } else {
1975 DecoratedTextfield* field = new DecoratedTextfield( 1985 DecoratedTextfield* field = new DecoratedTextfield(input.initial_value,
1976 input.initial_value, 1986 input.placeholder_text,
1977 l10n_util::GetStringUTF16(input.placeholder_text_rid), 1987 this);
1978 this);
1979
1980 textfields->insert(std::make_pair(input.type, field)); 1988 textfields->insert(std::make_pair(input.type, field));
1981 view_to_add.reset(field); 1989 view_to_add.reset(field);
1982 } 1990 }
1983 1991
1984 int kColumnSetId = input.row_id; 1992 int kColumnSetId = input.row_id;
1985 if (kColumnSetId < 0) { 1993 if (kColumnSetId < 0) {
1986 other_owned_views_.push_back(view_to_add.release()); 1994 other_owned_views_.push_back(view_to_add.release());
1987 continue; 1995 continue;
1988 } 1996 }
1989 1997
(...skipping 22 matching lines...) Expand all
2012 2020
2013 // This is the same as AddView(view_to_add), except that 1 is used for the 2021 // This is the same as AddView(view_to_add), except that 1 is used for the
2014 // view's preferred width. Thus the width of the column completely depends 2022 // view's preferred width. Thus the width of the column completely depends
2015 // on |expand|. 2023 // on |expand|.
2016 layout->AddView(view_to_add.release(), 1, 1, 2024 layout->AddView(view_to_add.release(), 1, 1,
2017 views::GridLayout::FILL, views::GridLayout::FILL, 2025 views::GridLayout::FILL, views::GridLayout::FILL,
2018 1, 0); 2026 1, 0);
2019 } 2027 }
2020 2028
2021 SetIconsForSection(section); 2029 SetIconsForSection(section);
2022
2023 return view;
2024 } 2030 }
2025 2031
2026 void AutofillDialogViews::ShowDialogInMode(DialogMode dialog_mode) { 2032 void AutofillDialogViews::ShowDialogInMode(DialogMode dialog_mode) {
2027 loading_shield_->SetVisible(dialog_mode == LOADING); 2033 loading_shield_->SetVisible(dialog_mode == LOADING);
2028 sign_in_web_view_->SetVisible(dialog_mode == SIGN_IN); 2034 sign_in_web_view_->SetVisible(dialog_mode == SIGN_IN);
2029 notification_area_->SetVisible(dialog_mode == DETAIL_INPUT); 2035 notification_area_->SetVisible(dialog_mode == DETAIL_INPUT);
2030 scrollable_area_->SetVisible(dialog_mode == DETAIL_INPUT); 2036 scrollable_area_->SetVisible(dialog_mode == DETAIL_INPUT);
2031 FocusInitialView(); 2037 FocusInitialView();
2032 } 2038 }
2033 2039
2034 void AutofillDialogViews::UpdateSectionImpl( 2040 void AutofillDialogViews::UpdateSectionImpl(
2035 DialogSection section, 2041 DialogSection section,
2036 bool clobber_inputs) { 2042 bool clobber_inputs) {
2037 // Reset all validity marks for this section. 2043 DetailsGroup* group = GroupForSection(section);
2038 if (clobber_inputs) 2044
2039 MarkInputsInvalid(section, ValidityMessages(), true); 2045 if (clobber_inputs) {
2046 InitInputsView(section);
2047 details_container_->Layout();
Evan Stade 2013/12/02 23:30:34 This isn't what I meant, I meant for you to call L
2048 }
2040 2049
2041 const DetailInputs& updated_inputs = 2050 const DetailInputs& updated_inputs =
2042 delegate_->RequestedFieldsForSection(section); 2051 delegate_->RequestedFieldsForSection(section);
2043 DetailsGroup* group = GroupForSection(section);
2044 2052
2045 for (DetailInputs::const_iterator iter = updated_inputs.begin(); 2053 for (DetailInputs::const_iterator iter = updated_inputs.begin();
2046 iter != updated_inputs.end(); ++iter) { 2054 iter != updated_inputs.end(); ++iter) {
2047 const DetailInput& input = *iter; 2055 const DetailInput& input = *iter;
2056
2048 TextfieldMap::iterator text_mapping = group->textfields.find(input.type); 2057 TextfieldMap::iterator text_mapping = group->textfields.find(input.type);
2049
2050 if (text_mapping != group->textfields.end()) { 2058 if (text_mapping != group->textfields.end()) {
2051 DecoratedTextfield* decorated = text_mapping->second; 2059 DecoratedTextfield* decorated = text_mapping->second;
2052 if (decorated->text().empty() || clobber_inputs) 2060 if (decorated->text().empty() || clobber_inputs)
2053 decorated->SetText(input.initial_value); 2061 decorated->SetText(input.initial_value);
2054 } 2062 }
2055 2063
2056 ComboboxMap::iterator combo_mapping = group->comboboxes.find(input.type); 2064 ComboboxMap::iterator combo_mapping = group->comboboxes.find(input.type);
2057 if (combo_mapping != group->comboboxes.end()) { 2065 if (combo_mapping != group->comboboxes.end()) {
2058 views::Combobox* combobox = combo_mapping->second; 2066 views::Combobox* combobox = combo_mapping->second;
2059 if (combobox->selected_index() == combobox->model()->GetDefaultIndex() || 2067 if (combobox->selected_index() == combobox->model()->GetDefaultIndex() ||
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 iter != group->comboboxes.end(); ++iter) { 2182 iter != group->comboboxes.end(); ++iter) {
2175 const ValidityMessage& message = 2183 const ValidityMessage& message =
2176 messages.GetMessageOrDefault(iter->first); 2184 messages.GetMessageOrDefault(iter->first);
2177 if (overwrite_unsure || message.sure) 2185 if (overwrite_unsure || message.sure)
2178 SetValidityForInput(iter->second, message.text); 2186 SetValidityForInput(iter->second, message.text);
2179 } 2187 }
2180 } else { 2188 } else {
2181 // Purge invisible views from |validity_map_|. 2189 // Purge invisible views from |validity_map_|.
2182 std::map<views::View*, base::string16>::iterator it; 2190 std::map<views::View*, base::string16>::iterator it;
2183 for (it = validity_map_.begin(); it != validity_map_.end();) { 2191 for (it = validity_map_.begin(); it != validity_map_.end();) {
2184 DCHECK(GroupForView(it->first));
2185 if (GroupForView(it->first) == group) 2192 if (GroupForView(it->first) == group)
2186 validity_map_.erase(it++); 2193 validity_map_.erase(it++);
2187 else 2194 else
2188 ++it; 2195 ++it;
2189 } 2196 }
2190 2197
2191 if (section == GetCreditCardSection()) { 2198 if (section == GetCreditCardSection()) {
2192 // Special case CVC as it's not part of |group->manual_input|. 2199 // Special case CVC as it's not part of |group->manual_input|.
2193 const ValidityMessage& message = 2200 const ValidityMessage& message =
2194 messages.GetMessageOrDefault(CREDIT_CARD_VERIFICATION_CODE); 2201 messages.GetMessageOrDefault(CREDIT_CARD_VERIFICATION_CODE);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 2454 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
2448 : section(section), 2455 : section(section),
2449 container(NULL), 2456 container(NULL),
2450 manual_input(NULL), 2457 manual_input(NULL),
2451 suggested_info(NULL), 2458 suggested_info(NULL),
2452 suggested_button(NULL) {} 2459 suggested_button(NULL) {}
2453 2460
2454 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 2461 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
2455 2462
2456 } // namespace autofill 2463 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698