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

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: . 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
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_dialog_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
10 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autofill/wallet/wallet_service_url.h" 10 #include "chrome/browser/autofill/wallet/wallet_service_url.h"
12 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" 12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
14 #include "chrome/browser/ui/views/constrained_window_views.h" 13 #include "chrome/browser/ui/views/constrained_window_views.h"
15 #include "content/public/browser/native_web_keyboard_event.h" 14 #include "content/public/browser/native_web_keyboard_event.h"
16 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_controller.h"
17 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
18 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
19 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
(...skipping 23 matching lines...) Expand all
43 namespace { 42 namespace {
44 43
45 // Size of the triangular mark that indicates an invalid textfield. 44 // Size of the triangular mark that indicates an invalid textfield.
46 const size_t kDogEarSize = 10; 45 const size_t kDogEarSize = 10;
47 46
48 const size_t kAutocheckoutProgressBarWidth = 300; 47 const size_t kAutocheckoutProgressBarWidth = 300;
49 const size_t kAutocheckoutProgressBarHeight = 11; 48 const size_t kAutocheckoutProgressBarHeight = 11;
50 49
51 const size_t kArrowHeight = 7; 50 const size_t kArrowHeight = 7;
52 const size_t kArrowWidth = 2 * kArrowHeight; 51 const size_t kArrowWidth = 2 * kArrowHeight;
53 const int kArrowEndOffset = 83;
54 52
55 const char kDecoratedTextfieldClassName[] = "autofill/DecoratedTextfield"; 53 const char kDecoratedTextfieldClassName[] = "autofill/DecoratedTextfield";
56 const char kNotificationAreaClassName[] = "autofill/NotificationArea"; 54 const char kNotificationAreaClassName[] = "autofill/NotificationArea";
57 55
58 // Returns a label that describes a details section. 56 // Returns a label that describes a details section.
59 views::Label* CreateDetailsSectionLabel(const string16& text) { 57 views::Label* CreateDetailsSectionLabel(const string16& text) {
60 views::Label* label = new views::Label(text); 58 views::Label* label = new views::Label(text);
61 label->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 59 label->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
62 label->SetFont(label->font().DeriveFont(0, gfx::Font::BOLD)); 60 label->SetFont(label->font().DeriveFont(0, gfx::Font::BOLD));
63 // TODO(estade): this should be made to match the native textfield top 61 // TODO(estade): this should be made to match the native textfield top
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 162 }
165 163
166 std::string AutofillDialogViews::NotificationArea::GetClassName() const { 164 std::string AutofillDialogViews::NotificationArea::GetClassName() const {
167 return kNotificationAreaClassName; 165 return kNotificationAreaClassName;
168 } 166 }
169 167
170 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) { 168 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) {
171 views::View::OnPaint(canvas); 169 views::View::OnPaint(canvas);
172 170
173 if (notification_.HasArrow()) { 171 if (notification_.HasArrow()) {
174 // Not using GetMirroredXWithWidthInView() here because the code would still 172 const int arrow_half_width = kArrowWidth / 2.0f;
175 // need to subtract the width of the arrow from the result in RTL. 173 const int anchor_half_width = arrow_centering_anchor_ ?
176 const int start_x = base::i18n::IsRTL() ? kArrowEndOffset : 174 arrow_centering_anchor_->width() / 2.0f : 0;
177 width() - kArrowEndOffset - kArrowWidth; 175 const int arrow_middle =
176 GetMirroredXInView(width() - anchor_half_width - arrow_half_width);
177
178 SkPath arrow; 178 SkPath arrow;
179 arrow.moveTo(start_x, kArrowHeight); 179 arrow.moveTo(arrow_middle - arrow_half_width, kArrowHeight);
180 arrow.lineTo(start_x + kArrowWidth, kArrowHeight); 180 arrow.lineTo(arrow_middle + arrow_half_width, kArrowHeight);
181 arrow.lineTo(start_x + kArrowWidth / 2.0f, 0); 181 arrow.lineTo(arrow_middle, 0);
182 arrow.close(); 182 arrow.close();
183 canvas->ClipPath(arrow); 183 canvas->ClipPath(arrow);
184 canvas->DrawColor(notification_.GetBackgroundColor()); 184 canvas->DrawColor(notification_.GetBackgroundColor());
185 } 185 }
186 } 186 }
187 187
188 // AutofillDialogViews::SectionContainer --------------------------------------- 188 // AutofillDialogViews::SectionContainer ---------------------------------------
189 189
190 AutofillDialogViews::SectionContainer::SectionContainer( 190 AutofillDialogViews::SectionContainer::SectionContainer(
191 const string16& label, 191 const string16& label,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 // AutofillDialogViews --------------------------------------------------------- 350 // AutofillDialogViews ---------------------------------------------------------
351 351
352 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller) 352 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller)
353 : controller_(controller), 353 : controller_(controller),
354 did_submit_(false), 354 did_submit_(false),
355 window_(NULL), 355 window_(NULL),
356 contents_(NULL), 356 contents_(NULL),
357 notification_area_(NULL), 357 notification_area_(NULL),
358 use_billing_for_shipping_(NULL), 358 use_billing_for_shipping_(NULL),
359 sign_in_link_(NULL), 359 account_chooser_link_(NULL),
360 sign_in_container_(NULL), 360 sign_in_container_(NULL),
361 cancel_sign_in_(NULL), 361 cancel_sign_in_(NULL),
362 sign_in_webview_(NULL), 362 sign_in_webview_(NULL),
363 main_container_(NULL), 363 main_container_(NULL),
364 button_strip_extra_view_(NULL), 364 button_strip_extra_view_(NULL),
365 save_in_chrome_checkbox_(NULL), 365 save_in_chrome_checkbox_(NULL),
366 autocheckout_progress_bar_view_(NULL), 366 autocheckout_progress_bar_view_(NULL),
367 autocheckout_progress_bar_(NULL), 367 autocheckout_progress_bar_(NULL),
368 focus_manager_(NULL) { 368 focus_manager_(NULL) {
369 DCHECK(controller); 369 DCHECK(controller);
370 detail_groups_.insert(std::make_pair(SECTION_EMAIL, 370 detail_groups_.insert(std::make_pair(SECTION_EMAIL,
371 DetailsGroup(SECTION_EMAIL))); 371 DetailsGroup(SECTION_EMAIL)));
372 detail_groups_.insert(std::make_pair(SECTION_CC, 372 detail_groups_.insert(std::make_pair(SECTION_CC,
373 DetailsGroup(SECTION_CC))); 373 DetailsGroup(SECTION_CC)));
374 detail_groups_.insert(std::make_pair(SECTION_BILLING, 374 detail_groups_.insert(std::make_pair(SECTION_BILLING,
375 DetailsGroup(SECTION_BILLING))); 375 DetailsGroup(SECTION_BILLING)));
376 detail_groups_.insert(std::make_pair(SECTION_SHIPPING, 376 detail_groups_.insert(std::make_pair(SECTION_SHIPPING,
377 DetailsGroup(SECTION_SHIPPING))); 377 DetailsGroup(SECTION_SHIPPING)));
378 } 378 }
379 379
380 AutofillDialogViews::~AutofillDialogViews() { 380 AutofillDialogViews::~AutofillDialogViews() {
381 DCHECK(!window_); 381 DCHECK(!window_);
382
383 // |notification_area_| could be NULL if |Show()| was never called.
384 if (notification_area_)
385 notification_area_->set_arrow_centering_anchor(NULL);
382 } 386 }
383 387
384 void AutofillDialogViews::Show() { 388 void AutofillDialogViews::Show() {
385 InitChildViews(); 389 InitChildViews();
386 UpdateAccountChooser(); 390 UpdateAccountChooser();
387 UpdateNotificationArea(); 391 UpdateNotificationArea();
388 392
389 // Ownership of |contents_| is handed off by this call. The 393 // Ownership of |contents_| is handed off by this call. The
390 // WebContentsModalDialog will take care of deleting itself after calling 394 // WebContentsModalDialog will take care of deleting itself after calling
391 // DeleteDelegate(). 395 // DeleteDelegate().
392 window_ = ConstrainedWindowViews::Create(controller_->web_contents(), this); 396 window_ = ConstrainedWindowViews::Create(controller_->web_contents(), this);
393 focus_manager_ = window_->GetFocusManager(); 397 focus_manager_ = window_->GetFocusManager();
394 focus_manager_->AddFocusChangeListener(this); 398 focus_manager_->AddFocusChangeListener(this);
395 } 399 }
396 400
397 void AutofillDialogViews::Hide() { 401 void AutofillDialogViews::Hide() {
398 if (window_) 402 if (window_)
399 window_->CloseWebContentsModalDialog(); 403 window_->CloseWebContentsModalDialog();
400 } 404 }
401 405
402 void AutofillDialogViews::UpdateAccountChooser() { 406 void AutofillDialogViews::UpdateAccountChooser() {
403 DialogSignedInState state = controller_->SignedInState(); 407 // TODO(dbeam): show/hide account chooser combobox when it exists?
404 sign_in_link_->SetEnabled(state != REQUIRES_RESPONSE); 408 // TODO(dbeam): show/hide fancy Google Wallet logo when it exists.
405 sign_in_link_->SetVisible(state != SIGNED_IN); 409 account_chooser_link_->SetText(controller_->AccountChooserText());
410 account_chooser_link_->SetEnabled(controller_->AccountChooserEnabled());
406 } 411 }
407 412
408 void AutofillDialogViews::UpdateNotificationArea() { 413 void AutofillDialogViews::UpdateNotificationArea() {
409 DCHECK(notification_area_); 414 DCHECK(notification_area_);
410 notification_area_->SetNotification(controller_->CurrentNotification()); 415 notification_area_->SetNotification(controller_->CurrentNotification());
411 416
412 if (GetWidget()) 417 if (GetWidget())
413 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); 418 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
414 419
415 contents_->Layout(); 420 contents_->Layout();
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 views::View* focused_now) { 601 views::View* focused_now) {
597 controller_->FocusMoved(); 602 controller_->FocusMoved();
598 } 603 }
599 604
600 void AutofillDialogViews::OnDidChangeFocus( 605 void AutofillDialogViews::OnDidChangeFocus(
601 views::View* focused_before, 606 views::View* focused_before,
602 views::View* focused_now) {} 607 views::View* focused_now) {}
603 608
604 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { 609 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) {
605 // Sign in link. 610 // Sign in link.
606 if (source == sign_in_link_) { 611 if (source == account_chooser_link_) {
607 controller_->StartSignInFlow(); 612 if (controller_->SignedInState() != SIGNED_IN) {
613 DCHECK(controller_->CanPayWithWallet());
614 controller_->StartSignInFlow();
615 }
616 // TODO(dbeam): handle other clicks on the account chooser (i.e. combobox).
608 return; 617 return;
609 } 618 }
610 619
611 // Edit links. 620 // Edit links.
612 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 621 for (DetailGroupMap::iterator iter = detail_groups_.begin();
613 iter != detail_groups_.end(); ++iter) { 622 iter != detail_groups_.end(); ++iter) {
614 if (iter->second.suggested_info->Contains(source)) { 623 if (iter->second.suggested_info->Contains(source)) {
615 controller_->EditClickedForSection(iter->first); 624 controller_->EditClickedForSection(iter->first);
616 return; 625 return;
617 } 626 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 column_set->AddColumn(views::GridLayout::FILL, 681 column_set->AddColumn(views::GridLayout::FILL,
673 views::GridLayout::FILL, 682 views::GridLayout::FILL,
674 1, 683 1,
675 views::GridLayout::USE_PREF, 684 views::GridLayout::USE_PREF,
676 0, 685 0,
677 0); 686 0);
678 687
679 layout->StartRow(0, single_column_set); 688 layout->StartRow(0, single_column_set);
680 // TODO(abodenha) Create a chooser control to allow account selection. 689 // TODO(abodenha) Create a chooser control to allow account selection.
681 // See http://crbug.com/169858 690 // See http://crbug.com/169858
682 sign_in_link_ = new views::Link(controller_->SignInText()); 691 account_chooser_link_ = new views::Link();
683 sign_in_link_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 692 account_chooser_link_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
684 sign_in_link_->set_listener(this); 693 account_chooser_link_->set_listener(this);
685 layout->AddView(sign_in_link_); 694 layout->AddView(account_chooser_link_);
686 695
687 layout->StartRow(0, single_column_set); 696 layout->StartRowWithPadding(0, single_column_set,
697 0, views::kRelatedControlVerticalSpacing);
688 notification_area_ = new NotificationArea(); 698 notification_area_ = new NotificationArea();
699 notification_area_->set_arrow_centering_anchor(account_chooser_link_);
689 layout->AddView(notification_area_); 700 layout->AddView(notification_area_);
690 701
691 layout->StartRowWithPadding(0, single_column_set, 702 layout->StartRowWithPadding(0, single_column_set,
692 0, views::kUnrelatedControlVerticalSpacing); 703 0, views::kUnrelatedControlVerticalSpacing);
693 layout->AddView(CreateDetailsContainer()); 704 layout->AddView(CreateDetailsContainer());
694 return main_container_; 705 return main_container_;
695 } 706 }
696 707
697 views::View* AutofillDialogViews::CreateDetailsContainer() { 708 views::View* AutofillDialogViews::CreateDetailsContainer() {
698 views::View* view = new views::View(); 709 views::View* view = new views::View();
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 989 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
979 : section(section), 990 : section(section),
980 container(NULL), 991 container(NULL),
981 manual_input(NULL), 992 manual_input(NULL),
982 suggested_info(NULL), 993 suggested_info(NULL),
983 suggested_button(NULL) {} 994 suggested_button(NULL) {}
984 995
985 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 996 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
986 997
987 } // namespace autofill 998 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_dialog_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698