OLD | NEW |
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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/wallet/wallet_service_url.h" | 10 #include "chrome/browser/autofill/wallet/wallet_service_url.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
13 #include "chrome/browser/ui/views/constrained_window_views.h" | 13 #include "chrome/browser/ui/views/constrained_window_views.h" |
14 #include "content/public/browser/native_web_keyboard_event.h" | 14 #include "content/public/browser/native_web_keyboard_event.h" |
15 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
18 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
19 #include "ui/base/models/combobox_model.h" | 19 #include "ui/base/models/combobox_model.h" |
20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
22 #include "ui/views/background.h" | 22 #include "ui/views/background.h" |
23 #include "ui/views/border.h" | 23 #include "ui/views/border.h" |
24 #include "ui/views/controls/button/checkbox.h" | 24 #include "ui/views/controls/button/checkbox.h" |
25 #include "ui/views/controls/button/image_button.h" | 25 #include "ui/views/controls/button/image_button.h" |
26 #include "ui/views/controls/combobox/combobox.h" | 26 #include "ui/views/controls/combobox/combobox.h" |
| 27 #include "ui/views/controls/image_view.h" |
27 #include "ui/views/controls/label.h" | 28 #include "ui/views/controls/label.h" |
28 #include "ui/views/controls/link.h" | 29 #include "ui/views/controls/link.h" |
29 #include "ui/views/controls/menu/menu_model_adapter.h" | 30 #include "ui/views/controls/menu/menu_model_adapter.h" |
30 #include "ui/views/controls/menu/menu_runner.h" | 31 #include "ui/views/controls/menu/menu_runner.h" |
31 #include "ui/views/controls/separator.h" | 32 #include "ui/views/controls/separator.h" |
32 #include "ui/views/controls/textfield/textfield.h" | 33 #include "ui/views/controls/textfield/textfield.h" |
33 #include "ui/views/controls/webview/webview.h" | 34 #include "ui/views/controls/webview/webview.h" |
34 #include "ui/views/layout/box_layout.h" | 35 #include "ui/views/layout/box_layout.h" |
35 #include "ui/views/layout/fill_layout.h" | 36 #include "ui/views/layout/fill_layout.h" |
36 #include "ui/views/layout/grid_layout.h" | 37 #include "ui/views/layout/grid_layout.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 ui::MouseEvent event_copy = event; | 202 ui::MouseEvent event_copy = event; |
202 event_copy.set_location(gfx::Point()); | 203 event_copy.set_location(gfx::Point()); |
203 return event_copy; | 204 return event_copy; |
204 } | 205 } |
205 | 206 |
206 // AutofilDialogViews::SuggestionView ------------------------------------------ | 207 // AutofilDialogViews::SuggestionView ------------------------------------------ |
207 | 208 |
208 AutofillDialogViews::SuggestionView::SuggestionView( | 209 AutofillDialogViews::SuggestionView::SuggestionView( |
209 const string16& edit_label, | 210 const string16& edit_label, |
210 views::LinkListener* edit_listener) | 211 views::LinkListener* edit_listener) |
211 : label_(new views::Label()) { | 212 : label_(new views::Label()), |
| 213 icon_(new views::ImageView()), |
| 214 label_container_(new views::View()) { |
| 215 // Label and icon. |
212 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 216 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
213 AddChildView(label_); | 217 label_container_->SetLayoutManager( |
| 218 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 219 label_container_->AddChildView(icon_); |
| 220 label_container_->AddChildView(label_); |
| 221 AddChildView(label_container_); |
214 | 222 |
215 // TODO(estade): The link needs to have a different color when hovered. | 223 // TODO(estade): The link needs to have a different color when hovered. |
216 views::Link* edit_link = new views::Link(edit_label); | 224 views::Link* edit_link = new views::Link(edit_label); |
217 edit_link->set_listener(edit_listener); | 225 edit_link->set_listener(edit_listener); |
218 edit_link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 226 edit_link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
219 edit_link->SetUnderline(false); | 227 edit_link->SetUnderline(false); |
220 | 228 |
221 // This container prevents the edit link from being horizontally stretched. | 229 // This container prevents the edit link from being horizontally stretched. |
222 views::View* link_container = new views::View(); | 230 views::View* link_container = new views::View(); |
223 link_container->SetLayoutManager( | 231 link_container->SetLayoutManager( |
224 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 232 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
225 link_container->AddChildView(edit_link); | 233 link_container->AddChildView(edit_link); |
226 AddChildView(link_container); | 234 AddChildView(link_container); |
227 | 235 |
228 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 236 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
229 } | 237 } |
230 | 238 |
231 AutofillDialogViews::SuggestionView::~SuggestionView() {} | 239 AutofillDialogViews::SuggestionView::~SuggestionView() {} |
232 | 240 |
233 void AutofillDialogViews::SuggestionView::SetSuggestionText( | 241 void AutofillDialogViews::SuggestionView::SetSuggestionText( |
234 const string16& text) { | 242 const string16& text) { |
235 label_->SetText(text); | 243 label_->SetText(text); |
236 } | 244 } |
237 | 245 |
| 246 void AutofillDialogViews::SuggestionView::SetSuggestionIcon( |
| 247 const gfx::Image& image) { |
| 248 icon_->SetImage(image.AsImageSkia()); |
| 249 } |
| 250 |
238 // AutofillDialogView ---------------------------------------------------------- | 251 // AutofillDialogView ---------------------------------------------------------- |
239 | 252 |
240 // static | 253 // static |
241 AutofillDialogView* AutofillDialogView::Create( | 254 AutofillDialogView* AutofillDialogView::Create( |
242 AutofillDialogController* controller) { | 255 AutofillDialogController* controller) { |
243 return new AutofillDialogViews(controller); | 256 return new AutofillDialogViews(controller); |
244 } | 257 } |
245 | 258 |
246 // AutofillDialogViews --------------------------------------------------------- | 259 // AutofillDialogViews --------------------------------------------------------- |
247 | 260 |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 724 |
712 return view; | 725 return view; |
713 } | 726 } |
714 | 727 |
715 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { | 728 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { |
716 string16 suggestion_text = | 729 string16 suggestion_text = |
717 controller_->SuggestionTextForSection(group.section); | 730 controller_->SuggestionTextForSection(group.section); |
718 bool show_suggestions = !suggestion_text.empty(); | 731 bool show_suggestions = !suggestion_text.empty(); |
719 group.suggested_info->SetVisible(show_suggestions); | 732 group.suggested_info->SetVisible(show_suggestions); |
720 group.suggested_info->SetSuggestionText(suggestion_text); | 733 group.suggested_info->SetSuggestionText(suggestion_text); |
| 734 gfx::Image icon = controller_->SuggestionIconForSection(group.section); |
| 735 group.suggested_info->SetSuggestionIcon(icon); |
721 | 736 |
722 if (group.section == SECTION_SHIPPING) { | 737 if (group.section == SECTION_SHIPPING) { |
723 bool show_checkbox = !show_suggestions; | 738 bool show_checkbox = !show_suggestions; |
724 // When the checkbox is going from hidden to visible, it's because the | 739 // When the checkbox is going from hidden to visible, it's because the |
725 // user clicked "Enter new address". Reset the checkbox to unchecked in this | 740 // user clicked "Enter new address". Reset the checkbox to unchecked in this |
726 // case. | 741 // case. |
727 if (show_checkbox && !use_billing_for_shipping_->visible()) | 742 if (show_checkbox && !use_billing_for_shipping_->visible()) |
728 use_billing_for_shipping_->SetChecked(false); | 743 use_billing_for_shipping_->SetChecked(false); |
729 | 744 |
730 use_billing_for_shipping_->SetVisible(show_checkbox); | 745 use_billing_for_shipping_->SetVisible(show_checkbox); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 835 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
821 : section(section), | 836 : section(section), |
822 container(NULL), | 837 container(NULL), |
823 manual_input(NULL), | 838 manual_input(NULL), |
824 suggested_info(NULL), | 839 suggested_info(NULL), |
825 suggested_button(NULL) {} | 840 suggested_button(NULL) {} |
826 | 841 |
827 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 842 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
828 | 843 |
829 } // namespace autofill | 844 } // namespace autofill |
OLD | NEW |