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

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: let's try this again, android 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 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 AutofillDialogViewDelegate* delegate) { 1143 AutofillDialogViewDelegate* delegate) {
1144 return new AutofillDialogViews(delegate); 1144 return new AutofillDialogViews(delegate);
1145 } 1145 }
1146 1146
1147 // AutofillDialogViews --------------------------------------------------------- 1147 // AutofillDialogViews ---------------------------------------------------------
1148 1148
1149 AutofillDialogViews::AutofillDialogViews(AutofillDialogViewDelegate* delegate) 1149 AutofillDialogViews::AutofillDialogViews(AutofillDialogViewDelegate* delegate)
1150 : delegate_(delegate), 1150 : delegate_(delegate),
1151 updates_scope_(0), 1151 updates_scope_(0),
1152 needs_update_(false), 1152 needs_update_(false),
1153 details_container_needs_layout_(false),
1153 window_(NULL), 1154 window_(NULL),
1154 notification_area_(NULL), 1155 notification_area_(NULL),
1155 account_chooser_(NULL), 1156 account_chooser_(NULL),
1156 sign_in_web_view_(NULL), 1157 sign_in_web_view_(NULL),
1157 scrollable_area_(NULL), 1158 scrollable_area_(NULL),
1158 details_container_(NULL), 1159 details_container_(NULL),
1159 loading_shield_(NULL), 1160 loading_shield_(NULL),
1160 loading_shield_height_(0), 1161 loading_shield_height_(0),
1161 overlay_view_(NULL), 1162 overlay_view_(NULL),
1162 button_strip_extra_view_(NULL), 1163 button_strip_extra_view_(NULL),
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 // The rest (the |scrollable_area_|) takes up whatever's left. 1528 // The rest (the |scrollable_area_|) takes up whatever's left.
1528 if (scrollable_area_->visible()) { 1529 if (scrollable_area_->visible()) {
1529 int scroll_y = y; 1530 int scroll_y = y;
1530 if (notification_height > notification_area_->GetInsets().height()) 1531 if (notification_height > notification_area_->GetInsets().height())
1531 scroll_y += notification_height + views::kRelatedControlVerticalSpacing; 1532 scroll_y += notification_height + views::kRelatedControlVerticalSpacing;
1532 1533
1533 int scroll_bottom = content_bounds.bottom(); 1534 int scroll_bottom = content_bounds.bottom();
1534 DCHECK_EQ(scrollable_area_->contents(), details_container_); 1535 DCHECK_EQ(scrollable_area_->contents(), details_container_);
1535 details_container_->SizeToPreferredSize(); 1536 details_container_->SizeToPreferredSize();
1536 // TODO(estade): remove this hack. See crbug.com/285996 1537 // TODO(estade): remove this hack. See crbug.com/285996
1537 details_container_->set_ignore_layouts(true); 1538 details_container_->set_ignore_layouts(!details_container_needs_layout_);
Evan Stade 2013/12/02 17:57:33 instead of this, explicitly call layout on the con
Dan Beam 2013/12/02 22:37:54 Done.
1538 scrollable_area_->SetBounds(x, scroll_y, width, scroll_bottom - scroll_y); 1539 scrollable_area_->SetBounds(x, scroll_y, width, scroll_bottom - scroll_y);
1539 details_container_->set_ignore_layouts(false); 1540 details_container_->set_ignore_layouts(false);
1541 details_container_needs_layout_ = false;
1540 } 1542 }
1541 1543
1542 if (error_bubble_) 1544 if (error_bubble_)
1543 error_bubble_->UpdatePosition(); 1545 error_bubble_->UpdatePosition();
1544 } 1546 }
1545 1547
1546 void AutofillDialogViews::OnNativeThemeChanged( 1548 void AutofillDialogViews::OnNativeThemeChanged(
1547 const ui::NativeTheme* theme) { 1549 const ui::NativeTheme* theme) {
1548 if (!legal_document_view_) 1550 if (!legal_document_view_)
1549 return; 1551 return;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 } 1735 }
1734 1736
1735 // Show an error bubble when the user focuses the input. 1737 // Show an error bubble when the user focuses the input.
1736 if (focused_now) { 1738 if (focused_now) {
1737 focused_now->ScrollRectToVisible(focused_now->GetLocalBounds()); 1739 focused_now->ScrollRectToVisible(focused_now->GetLocalBounds());
1738 ShowErrorBubbleForViewIfNecessary(focused_now); 1740 ShowErrorBubbleForViewIfNecessary(focused_now);
1739 } 1741 }
1740 } 1742 }
1741 1743
1742 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) { 1744 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) {
1743 DetailsGroup* group = GroupForView(combobox); 1745 DialogSection section = GroupForView(combobox)->section;
1744 ValidateGroup(*group, VALIDATE_EDIT); 1746 int index = combobox->selected_index();
1745 SetEditabilityForSection(group->section); 1747 delegate_->ComboboxItemSelected(combobox->model(), section, index);
1748 ValidateGroup(*GroupForSection(section), VALIDATE_EDIT);
1749 SetEditabilityForSection(section);
1746 } 1750 }
1747 1751
1748 void AutofillDialogViews::StyledLabelLinkClicked(const gfx::Range& range, 1752 void AutofillDialogViews::StyledLabelLinkClicked(const gfx::Range& range,
1749 int event_flags) { 1753 int event_flags) {
1750 delegate_->LegalDocumentLinkClicked(range); 1754 delegate_->LegalDocumentLinkClicked(range);
1751 } 1755 }
1752 1756
1753 void AutofillDialogViews::OnMenuButtonClicked(views::View* source, 1757 void AutofillDialogViews::OnMenuButtonClicked(views::View* source,
1754 const gfx::Point& point) { 1758 const gfx::Point& point) {
1755 DCHECK_EQ(kSuggestedButtonClassName, source->GetClassName()); 1759 DCHECK_EQ(kSuggestedButtonClassName, source->GetClassName());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 AddChildView(sign_in_web_view_); 1897 AddChildView(sign_in_web_view_);
1894 1898
1895 overlay_view_ = new OverlayView(delegate_); 1899 overlay_view_ = new OverlayView(delegate_);
1896 overlay_view_->SetVisible(false); 1900 overlay_view_->SetVisible(false);
1897 } 1901 }
1898 1902
1899 views::View* AutofillDialogViews::CreateDetailsContainer() { 1903 views::View* AutofillDialogViews::CreateDetailsContainer() {
1900 details_container_ = new DetailsContainerView( 1904 details_container_ = new DetailsContainerView(
1901 base::Bind(&AutofillDialogViews::DetailsContainerBoundsChanged, 1905 base::Bind(&AutofillDialogViews::DetailsContainerBoundsChanged,
1902 base::Unretained(this))); 1906 base::Unretained(this)));
1907
1903 // A box layout is used because it respects widget visibility. 1908 // A box layout is used because it respects widget visibility.
1904 details_container_->SetLayoutManager( 1909 details_container_->SetLayoutManager(
1905 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 1910 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
1906 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1911 for (DetailGroupMap::iterator iter = detail_groups_.begin();
1907 iter != detail_groups_.end(); ++iter) { 1912 iter != detail_groups_.end(); ++iter) {
1908 CreateDetailsSection(iter->second.section); 1913 CreateDetailsSection(iter->second.section);
1909 details_container_->AddChildView(iter->second.container); 1914 details_container_->AddChildView(iter->second.container);
1910 } 1915 }
1911 1916
1912 return details_container_; 1917 return details_container_;
1913 } 1918 }
1914 1919
1915 void AutofillDialogViews::CreateDetailsSection(DialogSection section) { 1920 void AutofillDialogViews::CreateDetailsSection(DialogSection section) {
1916 // Inputs container (manual inputs + combobox). 1921 // Inputs container (manual inputs + combobox).
1917 views::View* inputs_container = CreateInputsContainer(section); 1922 views::View* inputs_container = CreateInputsContainer(section);
1923 DetailsGroup* group = GroupForSection(section);
1918 1924
1919 DetailsGroup* group = GroupForSection(section);
1920 // Container (holds label + inputs). 1925 // Container (holds label + inputs).
1921 group->container = new SectionContainer( 1926 group->container = new SectionContainer(
1922 delegate_->LabelForSection(section), 1927 delegate_->LabelForSection(section),
1923 inputs_container, 1928 inputs_container,
1924 group->suggested_button); 1929 group->suggested_button);
1925 DCHECK(group->suggested_button->parent()); 1930 DCHECK(group->suggested_button->parent());
1926 UpdateDetailsGroupState(*group); 1931 UpdateDetailsGroupState(*group);
1927 } 1932 }
1928 1933
1929 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) { 1934 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) {
(...skipping 14 matching lines...) Expand all
1944 group->suggested_button = new SuggestedButton(this); 1949 group->suggested_button = new SuggestedButton(this);
1945 group->manual_input = manual_inputs; 1950 group->manual_input = manual_inputs;
1946 group->suggested_info = suggested_info; 1951 group->suggested_info = suggested_info;
1947 1952
1948 return info_view; 1953 return info_view;
1949 } 1954 }
1950 1955
1951 // TODO(estade): we should be using Chrome-style constrained window padding 1956 // TODO(estade): we should be using Chrome-style constrained window padding
1952 // values. 1957 // values.
1953 views::View* AutofillDialogViews::InitInputsView(DialogSection section) { 1958 views::View* AutofillDialogViews::InitInputsView(DialogSection section) {
1954 const DetailInputs& inputs = delegate_->RequestedFieldsForSection(section);
1955 TextfieldMap* textfields = &GroupForSection(section)->textfields; 1959 TextfieldMap* textfields = &GroupForSection(section)->textfields;
1960 textfields->clear();
1961
1956 ComboboxMap* comboboxes = &GroupForSection(section)->comboboxes; 1962 ComboboxMap* comboboxes = &GroupForSection(section)->comboboxes;
1963 comboboxes->clear();
1957 1964
1958 views::View* view = new views::View(); 1965 views::View* view = new views::View();
1959 views::GridLayout* layout = new views::GridLayout(view); 1966 views::GridLayout* layout = new views::GridLayout(view);
1960 view->SetLayoutManager(layout); 1967 view->SetLayoutManager(layout);
1961 1968
1969 const DetailInputs& inputs = delegate_->RequestedFieldsForSection(section);
1962 for (DetailInputs::const_iterator it = inputs.begin(); 1970 for (DetailInputs::const_iterator it = inputs.begin();
1963 it != inputs.end(); ++it) { 1971 it != inputs.end(); ++it) {
1964 const DetailInput& input = *it; 1972 const DetailInput& input = *it;
1965 ui::ComboboxModel* input_model = 1973 ui::ComboboxModel* input_model =
1966 delegate_->ComboboxModelForAutofillType(input.type); 1974 delegate_->ComboboxModelForAutofillType(input.type);
1967 scoped_ptr<views::View> view_to_add; 1975 scoped_ptr<views::View> view_to_add;
1968 if (input_model) { 1976 if (input_model) {
1969 views::Combobox* combobox = new views::Combobox(input_model); 1977 views::Combobox* combobox = new views::Combobox(input_model);
1970 combobox->set_listener(this); 1978 combobox->set_listener(this);
1971 comboboxes->insert(std::make_pair(input.type, combobox)); 1979 comboboxes->insert(std::make_pair(input.type, combobox));
1972 SelectComboboxValueOrSetToDefault(combobox, input.initial_value); 1980 SelectComboboxValueOrSetToDefault(combobox, input.initial_value);
1973 view_to_add.reset(combobox); 1981 view_to_add.reset(combobox);
1974 } else { 1982 } else {
1975 DecoratedTextfield* field = new DecoratedTextfield( 1983 DecoratedTextfield* field = new DecoratedTextfield(input.initial_value,
1976 input.initial_value, 1984 input.placeholder_text,
1977 l10n_util::GetStringUTF16(input.placeholder_text_rid), 1985 this);
1978 this);
1979
1980 textfields->insert(std::make_pair(input.type, field)); 1986 textfields->insert(std::make_pair(input.type, field));
1981 view_to_add.reset(field); 1987 view_to_add.reset(field);
1982 } 1988 }
1983 1989
1984 int kColumnSetId = input.row_id; 1990 int kColumnSetId = input.row_id;
1985 if (kColumnSetId < 0) { 1991 if (kColumnSetId < 0) {
1986 other_owned_views_.push_back(view_to_add.release()); 1992 other_owned_views_.push_back(view_to_add.release());
1987 continue; 1993 continue;
1988 } 1994 }
1989 1995
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
Evan Stade 2013/12/02 17:57:33 will the rest of the address get clobbered if you
Dan Beam 2013/12/02 22:37:54 it's preserved by the same mechanism as changing a
2046 views::View* parent = group->manual_input->parent();
2047 int add_index = parent->GetIndexOf(group->manual_input);
2048 parent->RemoveChildView(group->manual_input);
Evan Stade 2013/12/02 17:57:33 I believe you're leaking group->manual_input. Any
Dan Beam 2013/12/02 22:37:54 you're right, this was hiding a segfault that i've
2049 group->manual_input = InitInputsView(section);
2050 parent->AddChildViewAt(group->manual_input, add_index);
2051 details_container_needs_layout_ = true;
2052 }
2040 2053
2041 const DetailInputs& updated_inputs = 2054 const DetailInputs& updated_inputs =
2042 delegate_->RequestedFieldsForSection(section); 2055 delegate_->RequestedFieldsForSection(section);
2043 DetailsGroup* group = GroupForSection(section);
2044 2056
2045 for (DetailInputs::const_iterator iter = updated_inputs.begin(); 2057 for (DetailInputs::const_iterator iter = updated_inputs.begin();
2046 iter != updated_inputs.end(); ++iter) { 2058 iter != updated_inputs.end(); ++iter) {
2047 const DetailInput& input = *iter; 2059 const DetailInput& input = *iter;
2060
2048 TextfieldMap::iterator text_mapping = group->textfields.find(input.type); 2061 TextfieldMap::iterator text_mapping = group->textfields.find(input.type);
2049
2050 if (text_mapping != group->textfields.end()) { 2062 if (text_mapping != group->textfields.end()) {
2051 DecoratedTextfield* decorated = text_mapping->second; 2063 DecoratedTextfield* decorated = text_mapping->second;
2052 if (decorated->text().empty() || clobber_inputs) 2064 if (decorated->text().empty() || clobber_inputs)
2053 decorated->SetText(input.initial_value); 2065 decorated->SetText(input.initial_value);
2054 } 2066 }
2055 2067
2056 ComboboxMap::iterator combo_mapping = group->comboboxes.find(input.type); 2068 ComboboxMap::iterator combo_mapping = group->comboboxes.find(input.type);
2057 if (combo_mapping != group->comboboxes.end()) { 2069 if (combo_mapping != group->comboboxes.end()) {
2058 views::Combobox* combobox = combo_mapping->second; 2070 views::Combobox* combobox = combo_mapping->second;
2059 if (combobox->selected_index() == combobox->model()->GetDefaultIndex() || 2071 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) { 2186 iter != group->comboboxes.end(); ++iter) {
2175 const ValidityMessage& message = 2187 const ValidityMessage& message =
2176 messages.GetMessageOrDefault(iter->first); 2188 messages.GetMessageOrDefault(iter->first);
2177 if (overwrite_unsure || message.sure) 2189 if (overwrite_unsure || message.sure)
2178 SetValidityForInput(iter->second, message.text); 2190 SetValidityForInput(iter->second, message.text);
2179 } 2191 }
2180 } else { 2192 } else {
2181 // Purge invisible views from |validity_map_|. 2193 // Purge invisible views from |validity_map_|.
2182 std::map<views::View*, base::string16>::iterator it; 2194 std::map<views::View*, base::string16>::iterator it;
2183 for (it = validity_map_.begin(); it != validity_map_.end();) { 2195 for (it = validity_map_.begin(); it != validity_map_.end();) {
2184 DCHECK(GroupForView(it->first));
2185 if (GroupForView(it->first) == group) 2196 if (GroupForView(it->first) == group)
2186 validity_map_.erase(it++); 2197 validity_map_.erase(it++);
2187 else 2198 else
2188 ++it; 2199 ++it;
2189 } 2200 }
2190 2201
2191 if (section == GetCreditCardSection()) { 2202 if (section == GetCreditCardSection()) {
2192 // Special case CVC as it's not part of |group->manual_input|. 2203 // Special case CVC as it's not part of |group->manual_input|.
2193 const ValidityMessage& message = 2204 const ValidityMessage& message =
2194 messages.GetMessageOrDefault(CREDIT_CARD_VERIFICATION_CODE); 2205 messages.GetMessageOrDefault(CREDIT_CARD_VERIFICATION_CODE);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 2458 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
2448 : section(section), 2459 : section(section),
2449 container(NULL), 2460 container(NULL),
2450 manual_input(NULL), 2461 manual_input(NULL),
2451 suggested_info(NULL), 2462 suggested_info(NULL),
2452 suggested_button(NULL) {} 2463 suggested_button(NULL) {}
2453 2464
2454 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 2465 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
2455 2466
2456 } // namespace autofill 2467 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698