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

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

Issue 12221040: Interactive autofill: Handle Online Wallet being unavailable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: x Created 7 years, 10 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/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autofill/wallet/wallet_service_url.h" 11 #include "chrome/browser/autofill/wallet/wallet_service_url.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" 13 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
14 #include "chrome/browser/ui/views/constrained_window_views.h" 14 #include "chrome/browser/ui/views/constrained_window_views.h"
15 #include "content/public/browser/native_web_keyboard_event.h" 15 #include "content/public/browser/native_web_keyboard_event.h"
16 #include "content/public/browser/navigation_controller.h" 16 #include "content/public/browser/navigation_controller.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
19 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/base/models/combobox_model.h" 20 #include "ui/base/models/combobox_model.h"
21 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/gfx/canvas.h" 22 #include "ui/gfx/canvas.h"
23 #include "ui/views/background.h" 23 #include "ui/views/background.h"
24 #include "ui/views/border.h" 24 #include "ui/views/border.h"
25 #include "ui/views/controls/button/checkbox.h" 25 #include "ui/views/controls/button/checkbox.h"
26 #include "ui/views/controls/button/image_button.h" 26 #include "ui/views/controls/button/image_button.h"
27 #include "ui/views/controls/combobox/combobox.h" 27 #include "ui/views/controls/combobox/combobox.h"
28 #include "ui/views/controls/image_view.h" 28 #include "ui/views/controls/image_view.h"
29 #include "ui/views/controls/label.h" 29 #include "ui/views/controls/label.h"
30 #include "ui/views/controls/link.h"
31 #include "ui/views/controls/menu/menu_model_adapter.h" 30 #include "ui/views/controls/menu/menu_model_adapter.h"
32 #include "ui/views/controls/menu/menu_runner.h" 31 #include "ui/views/controls/menu/menu_runner.h"
33 #include "ui/views/controls/separator.h" 32 #include "ui/views/controls/separator.h"
34 #include "ui/views/controls/textfield/textfield.h" 33 #include "ui/views/controls/textfield/textfield.h"
35 #include "ui/views/controls/webview/webview.h" 34 #include "ui/views/controls/webview/webview.h"
36 #include "ui/views/layout/box_layout.h" 35 #include "ui/views/layout/box_layout.h"
37 #include "ui/views/layout/fill_layout.h" 36 #include "ui/views/layout/fill_layout.h"
38 #include "ui/views/layout/grid_layout.h" 37 #include "ui/views/layout/grid_layout.h"
39 #include "ui/views/layout/layout_constants.h" 38 #include "ui/views/layout/layout_constants.h"
40 39
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 SkPath dog_ear; 115 SkPath dog_ear;
117 dog_ear.moveTo(width() - kDogEarSize, 0); 116 dog_ear.moveTo(width() - kDogEarSize, 0);
118 dog_ear.lineTo(width(), 0); 117 dog_ear.lineTo(width(), 0);
119 dog_ear.lineTo(width(), kDogEarSize); 118 dog_ear.lineTo(width(), kDogEarSize);
120 dog_ear.close(); 119 dog_ear.close();
121 canvas->ClipPath(dog_ear); 120 canvas->ClipPath(dog_ear);
122 canvas->DrawColor(SK_ColorRED); 121 canvas->DrawColor(SK_ColorRED);
123 } 122 }
124 } 123 }
125 124
125 // AutofillDialogViews::AccountChooserLink -------------------------------------
126
127 AutofillDialogViews::AccountChooserLink::AccountChooserLink() : views::Link() {
128 SetHorizontalAlignment(gfx::ALIGN_RIGHT);
129 }
130
131 AutofillDialogViews::AccountChooserLink::~AccountChooserLink() {}
132
133 size_t AutofillDialogViews::AccountChooserLink::GetTextWidth() const {
Evan Stade 2013/02/06 21:57:49 it doesn't seem like you should need this. Why not
Dan Beam 2013/02/07 01:22:40 The width of the views::Link is always 100% of the
Evan Stade 2013/02/07 01:54:42 I do not think that's by design. Fix that (now or
Dan Beam 2013/02/07 03:26:53 Done.
134 return GetTextSize().width();
135 }
136
126 // AutofillDialogViews::NotificationArea --------------------------------------- 137 // AutofillDialogViews::NotificationArea ---------------------------------------
127 138
128 AutofillDialogViews::NotificationArea::NotificationArea() 139 AutofillDialogViews::NotificationArea::NotificationArea(
129 : label_(new views::Label()) { 140 AccountChooserLink* point_at)
Evan Stade 2013/02/06 21:57:49 not point_at. point_at sounds like a gfx::Point.
Dan Beam 2013/02/07 01:22:40 Done.
141 : label_(new views::Label()),
142 point_at_(point_at) {
143 DCHECK(point_at_);
144
130 views::BoxLayout* layout = 145 views::BoxLayout* layout =
131 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 146 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
132 layout->set_spread_blank_space(true); 147 layout->set_spread_blank_space(true);
133 SetLayoutManager(layout); 148 SetLayoutManager(layout);
134 149
135 // This background is re-used and the color is changed in |SetNotification()|. 150 // This background is re-used and the color is changed in |SetNotification()|.
136 label_->set_background( 151 label_->set_background(
137 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT)); 152 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
138 label_->set_border(views::Border::CreateEmptyBorder(10, 10, 10, 10)); 153 label_->set_border(views::Border::CreateEmptyBorder(10, 10, 10, 10));
139 label_->set_collapse_when_hidden(true); 154 label_->set_collapse_when_hidden(true);
(...skipping 26 matching lines...) Expand all
166 std::string AutofillDialogViews::NotificationArea::GetClassName() const { 181 std::string AutofillDialogViews::NotificationArea::GetClassName() const {
167 return kNotificationAreaClassName; 182 return kNotificationAreaClassName;
168 } 183 }
169 184
170 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) { 185 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) {
171 views::View::OnPaint(canvas); 186 views::View::OnPaint(canvas);
172 187
173 if (notification_.HasArrow()) { 188 if (notification_.HasArrow()) {
174 // Not using GetMirroredXWithWidthInView() here because the code would still 189 // Not using GetMirroredXWithWidthInView() here because the code would still
175 // need to subtract the width of the arrow from the result in RTL. 190 // need to subtract the width of the arrow from the result in RTL.
176 const int start_x = base::i18n::IsRTL() ? kArrowEndOffset : 191 const int half_arrow = kArrowWidth / 2.0f;
177 width() - kArrowEndOffset - kArrowWidth; 192 const int arrow_middle = GetMirroredXInView(
193 width() - point_at_->GetTextWidth() / 2.0f - half_arrow);
194
178 SkPath arrow; 195 SkPath arrow;
179 arrow.moveTo(start_x, kArrowHeight); 196 arrow.moveTo(arrow_middle - half_arrow, kArrowHeight);
180 arrow.lineTo(start_x + kArrowWidth, kArrowHeight); 197 arrow.lineTo(arrow_middle + half_arrow, kArrowHeight);
181 arrow.lineTo(start_x + kArrowWidth / 2.0f, 0); 198 arrow.lineTo(arrow_middle, 0);
182 arrow.close(); 199 arrow.close();
183 canvas->ClipPath(arrow); 200 canvas->ClipPath(arrow);
184 canvas->DrawColor(notification_.GetBackgroundColor()); 201 canvas->DrawColor(notification_.GetBackgroundColor());
185 } 202 }
186 } 203 }
187 204
188 // AutofillDialogViews::SectionContainer --------------------------------------- 205 // AutofillDialogViews::SectionContainer ---------------------------------------
189 206
190 AutofillDialogViews::SectionContainer::SectionContainer( 207 AutofillDialogViews::SectionContainer::SectionContainer(
191 const string16& label, 208 const string16& label,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 356
340 // AutofillDialogViews --------------------------------------------------------- 357 // AutofillDialogViews ---------------------------------------------------------
341 358
342 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller) 359 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller)
343 : controller_(controller), 360 : controller_(controller),
344 did_submit_(false), 361 did_submit_(false),
345 window_(NULL), 362 window_(NULL),
346 contents_(NULL), 363 contents_(NULL),
347 notification_area_(NULL), 364 notification_area_(NULL),
348 use_billing_for_shipping_(NULL), 365 use_billing_for_shipping_(NULL),
349 sign_in_link_(NULL), 366 account_chooser_link_(NULL),
350 sign_in_container_(NULL), 367 sign_in_container_(NULL),
351 cancel_sign_in_(NULL), 368 cancel_sign_in_(NULL),
352 sign_in_webview_(NULL), 369 sign_in_webview_(NULL),
353 main_container_(NULL), 370 main_container_(NULL),
354 button_strip_extra_view_(NULL), 371 button_strip_extra_view_(NULL),
355 save_in_chrome_checkbox_(NULL), 372 save_in_chrome_checkbox_(NULL),
356 autocheckout_progress_bar_view_(NULL), 373 autocheckout_progress_bar_view_(NULL),
357 autocheckout_progress_bar_(NULL), 374 autocheckout_progress_bar_(NULL),
358 focus_manager_(NULL) { 375 focus_manager_(NULL) {
359 DCHECK(controller); 376 DCHECK(controller);
(...skipping 23 matching lines...) Expand all
383 focus_manager_ = window_->GetFocusManager(); 400 focus_manager_ = window_->GetFocusManager();
384 focus_manager_->AddFocusChangeListener(this); 401 focus_manager_->AddFocusChangeListener(this);
385 } 402 }
386 403
387 void AutofillDialogViews::Hide() { 404 void AutofillDialogViews::Hide() {
388 if (window_) 405 if (window_)
389 window_->CloseWebContentsModalDialog(); 406 window_->CloseWebContentsModalDialog();
390 } 407 }
391 408
392 void AutofillDialogViews::UpdateAccountChooser() { 409 void AutofillDialogViews::UpdateAccountChooser() {
393 DialogSignedInState state = controller_->SignedInState(); 410 string16 text;
394 sign_in_link_->SetEnabled(state != REQUIRES_RESPONSE); 411 bool enabled;
395 sign_in_link_->SetVisible(state != SIGNED_IN); 412
413 if (!controller_->IsWalletAvailable()) {
414 // TODO(dbeam): hide account chooser combobox when it exists?
415 // TODO(dbeam): hide Google Wallet logo when it exists.
416 text = controller_->PayWithoutWallet();
417 enabled = false;
418 } else {
419 // TODO(dbeam): show fancy Google Wallet logo.
420 DialogSignedInState state = controller_->SignedInState();
421 text = state != SIGNED_IN ? controller_->SignInText() :
422 controller_->SignedInUser();
423 enabled = state != REQUIRES_RESPONSE && state != SIGNED_IN;
424 }
425
426 account_chooser_link_->SetText(text);
427 account_chooser_link_->SetEnabled(enabled);
396 } 428 }
397 429
398 void AutofillDialogViews::UpdateNotificationArea() { 430 void AutofillDialogViews::UpdateNotificationArea() {
399 DCHECK(notification_area_); 431 DCHECK(notification_area_);
400 notification_area_->SetNotification(controller_->CurrentNotification()); 432 notification_area_->SetNotification(controller_->CurrentNotification());
401 433
402 if (GetWidget()) 434 if (GetWidget())
403 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); 435 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
404 436
405 contents_->Layout(); 437 contents_->Layout();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 views::View* focused_now) { 608 views::View* focused_now) {
577 controller_->FocusMoved(); 609 controller_->FocusMoved();
578 } 610 }
579 611
580 void AutofillDialogViews::OnDidChangeFocus( 612 void AutofillDialogViews::OnDidChangeFocus(
581 views::View* focused_before, 613 views::View* focused_before,
582 views::View* focused_now) {} 614 views::View* focused_now) {}
583 615
584 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { 616 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) {
585 // Sign in link. 617 // Sign in link.
586 if (source == sign_in_link_) { 618 if (source == account_chooser_link_) {
587 controller_->StartSignInFlow(); 619 if (controller_->SignedInState() != SIGNED_IN) {
620 DCHECK(controller_->IsWalletAvailable());
621 controller_->StartSignInFlow();
622 }
623 // TODO(dbeam): handle other clicks on the account chooser (i.e. combobox).
588 return; 624 return;
589 } 625 }
590 626
591 // Edit links. 627 // Edit links.
592 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 628 for (DetailGroupMap::iterator iter = detail_groups_.begin();
593 iter != detail_groups_.end(); ++iter) { 629 iter != detail_groups_.end(); ++iter) {
594 if (iter->second.suggested_info->Contains(source)) { 630 if (iter->second.suggested_info->Contains(source)) {
595 controller_->EditClickedForSection(iter->first); 631 controller_->EditClickedForSection(iter->first);
596 return; 632 return;
597 } 633 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 column_set->AddColumn(views::GridLayout::FILL, 689 column_set->AddColumn(views::GridLayout::FILL,
654 views::GridLayout::FILL, 690 views::GridLayout::FILL,
655 1, 691 1,
656 views::GridLayout::USE_PREF, 692 views::GridLayout::USE_PREF,
657 0, 693 0,
658 0); 694 0);
659 695
660 layout->StartRow(0, single_column_set); 696 layout->StartRow(0, single_column_set);
661 // TODO(abodenha) Create a chooser control to allow account selection. 697 // TODO(abodenha) Create a chooser control to allow account selection.
662 // See http://crbug.com/169858 698 // See http://crbug.com/169858
663 sign_in_link_ = new views::Link(controller_->SignInText()); 699 account_chooser_link_ = new AccountChooserLink();
664 sign_in_link_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 700 account_chooser_link_->set_listener(this);
665 sign_in_link_->set_listener(this); 701 layout->AddView(account_chooser_link_);
666 layout->AddView(sign_in_link_);
667 702
668 layout->StartRow(0, single_column_set); 703 layout->StartRowWithPadding(0, single_column_set,
669 notification_area_ = new NotificationArea(); 704 0, views::kRelatedControlVerticalSpacing);
705 notification_area_ = new NotificationArea(account_chooser_link_);
670 layout->AddView(notification_area_); 706 layout->AddView(notification_area_);
671 707
672 layout->StartRowWithPadding(0, single_column_set, 708 layout->StartRowWithPadding(0, single_column_set,
673 0, views::kUnrelatedControlVerticalSpacing); 709 0, views::kUnrelatedControlVerticalSpacing);
674 layout->AddView(CreateDetailsContainer()); 710 layout->AddView(CreateDetailsContainer());
675 return main_container_; 711 return main_container_;
676 } 712 }
677 713
678 views::View* AutofillDialogViews::CreateDetailsContainer() { 714 views::View* AutofillDialogViews::CreateDetailsContainer() {
679 views::View* view = new views::View(); 715 views::View* view = new views::View();
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 972 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
937 : section(section), 973 : section(section),
938 container(NULL), 974 container(NULL),
939 manual_input(NULL), 975 manual_input(NULL),
940 suggested_info(NULL), 976 suggested_info(NULL),
941 suggested_button(NULL) {} 977 suggested_button(NULL) {}
942 978
943 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 979 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
944 980
945 } // namespace autofill 981 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698