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

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: isherman@ review 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"
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 dog_ear.lineTo(width(), 0); 116 dog_ear.lineTo(width(), 0);
119 dog_ear.lineTo(width(), kDogEarSize); 117 dog_ear.lineTo(width(), kDogEarSize);
120 dog_ear.close(); 118 dog_ear.close();
121 canvas->ClipPath(dog_ear); 119 canvas->ClipPath(dog_ear);
122 canvas->DrawColor(SK_ColorRED); 120 canvas->DrawColor(SK_ColorRED);
123 } 121 }
124 } 122 }
125 123
126 // AutofillDialogViews::NotificationArea --------------------------------------- 124 // AutofillDialogViews::NotificationArea ---------------------------------------
127 125
128 AutofillDialogViews::NotificationArea::NotificationArea() 126 AutofillDialogViews::NotificationArea::NotificationArea(
129 : label_(new views::Label()) { 127 views::View* arrow_centering_anchor)
128 : label_(new views::Label()),
129 arrow_centering_anchor_(arrow_centering_anchor) {
sky 2013/02/11 21:07:34 Can you instead get what you need from arrow_cente
Dan Beam 2013/02/11 21:53:54 The width of |arrow_centering_anchor_| varies a lo
sky 2013/02/11 22:05:55 No need to denote more heavily. I was hoping you c
Dan Beam 2013/02/11 23:11:43 It's not guaranteed to, and it probably depends on
130 DCHECK(arrow_centering_anchor_);
131
130 views::BoxLayout* layout = 132 views::BoxLayout* layout =
131 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 133 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
132 layout->set_spread_blank_space(true); 134 layout->set_spread_blank_space(true);
133 SetLayoutManager(layout); 135 SetLayoutManager(layout);
134 136
135 // This background is re-used and the color is changed in |SetNotification()|. 137 // This background is re-used and the color is changed in |SetNotification()|.
136 label_->set_background( 138 label_->set_background(
137 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT)); 139 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
138 label_->set_border(views::Border::CreateEmptyBorder(10, 10, 10, 10)); 140 label_->set_border(views::Border::CreateEmptyBorder(10, 10, 10, 10));
139 label_->set_collapse_when_hidden(true); 141 label_->set_collapse_when_hidden(true);
(...skipping 24 matching lines...) Expand all
164 } 166 }
165 167
166 std::string AutofillDialogViews::NotificationArea::GetClassName() const { 168 std::string AutofillDialogViews::NotificationArea::GetClassName() const {
167 return kNotificationAreaClassName; 169 return kNotificationAreaClassName;
168 } 170 }
169 171
170 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) { 172 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) {
171 views::View::OnPaint(canvas); 173 views::View::OnPaint(canvas);
172 174
173 if (notification_.HasArrow()) { 175 if (notification_.HasArrow()) {
174 // Not using GetMirroredXWithWidthInView() here because the code would still 176 const int half_arrow = kArrowWidth / 2.0f;
175 // need to subtract the width of the arrow from the result in RTL. 177 const int arrow_middle = GetMirroredXInView(
176 const int start_x = base::i18n::IsRTL() ? kArrowEndOffset : 178 width() - arrow_centering_anchor_->width() / 2.0f - half_arrow);
177 width() - kArrowEndOffset - kArrowWidth; 179
178 SkPath arrow; 180 SkPath arrow;
179 arrow.moveTo(start_x, kArrowHeight); 181 arrow.moveTo(arrow_middle - half_arrow, kArrowHeight);
180 arrow.lineTo(start_x + kArrowWidth, kArrowHeight); 182 arrow.lineTo(arrow_middle + half_arrow, kArrowHeight);
181 arrow.lineTo(start_x + kArrowWidth / 2.0f, 0); 183 arrow.lineTo(arrow_middle, 0);
182 arrow.close(); 184 arrow.close();
183 canvas->ClipPath(arrow); 185 canvas->ClipPath(arrow);
184 canvas->DrawColor(notification_.GetBackgroundColor()); 186 canvas->DrawColor(notification_.GetBackgroundColor());
185 } 187 }
186 } 188 }
187 189
188 // AutofillDialogViews::SectionContainer --------------------------------------- 190 // AutofillDialogViews::SectionContainer ---------------------------------------
189 191
190 AutofillDialogViews::SectionContainer::SectionContainer( 192 AutofillDialogViews::SectionContainer::SectionContainer(
191 const string16& label, 193 const string16& label,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 351
350 // AutofillDialogViews --------------------------------------------------------- 352 // AutofillDialogViews ---------------------------------------------------------
351 353
352 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller) 354 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller)
353 : controller_(controller), 355 : controller_(controller),
354 did_submit_(false), 356 did_submit_(false),
355 window_(NULL), 357 window_(NULL),
356 contents_(NULL), 358 contents_(NULL),
357 notification_area_(NULL), 359 notification_area_(NULL),
358 use_billing_for_shipping_(NULL), 360 use_billing_for_shipping_(NULL),
359 sign_in_link_(NULL), 361 account_chooser_link_(NULL),
360 sign_in_container_(NULL), 362 sign_in_container_(NULL),
361 cancel_sign_in_(NULL), 363 cancel_sign_in_(NULL),
362 sign_in_webview_(NULL), 364 sign_in_webview_(NULL),
363 main_container_(NULL), 365 main_container_(NULL),
364 button_strip_extra_view_(NULL), 366 button_strip_extra_view_(NULL),
365 save_in_chrome_checkbox_(NULL), 367 save_in_chrome_checkbox_(NULL),
366 autocheckout_progress_bar_view_(NULL), 368 autocheckout_progress_bar_view_(NULL),
367 autocheckout_progress_bar_(NULL), 369 autocheckout_progress_bar_(NULL),
368 focus_manager_(NULL) { 370 focus_manager_(NULL) {
369 DCHECK(controller); 371 DCHECK(controller);
(...skipping 23 matching lines...) Expand all
393 focus_manager_ = window_->GetFocusManager(); 395 focus_manager_ = window_->GetFocusManager();
394 focus_manager_->AddFocusChangeListener(this); 396 focus_manager_->AddFocusChangeListener(this);
395 } 397 }
396 398
397 void AutofillDialogViews::Hide() { 399 void AutofillDialogViews::Hide() {
398 if (window_) 400 if (window_)
399 window_->CloseWebContentsModalDialog(); 401 window_->CloseWebContentsModalDialog();
400 } 402 }
401 403
402 void AutofillDialogViews::UpdateAccountChooser() { 404 void AutofillDialogViews::UpdateAccountChooser() {
403 DialogSignedInState state = controller_->SignedInState(); 405 // TODO(dbeam): show/hide account chooser combobox when it exists?
404 sign_in_link_->SetEnabled(state != REQUIRES_RESPONSE); 406 // TODO(dbeam): show/hide fancy Google Wallet logo when it exists.
405 sign_in_link_->SetVisible(state != SIGNED_IN); 407 account_chooser_link_->SetText(controller_->AccountChooserText());
408 account_chooser_link_->SetEnabled(controller_->AccountChooserEnabled());
406 } 409 }
407 410
408 void AutofillDialogViews::UpdateNotificationArea() { 411 void AutofillDialogViews::UpdateNotificationArea() {
409 DCHECK(notification_area_); 412 DCHECK(notification_area_);
410 notification_area_->SetNotification(controller_->CurrentNotification()); 413 notification_area_->SetNotification(controller_->CurrentNotification());
411 414
412 if (GetWidget()) 415 if (GetWidget())
413 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); 416 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
414 417
415 contents_->Layout(); 418 contents_->Layout();
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 views::View* focused_now) { 599 views::View* focused_now) {
597 controller_->FocusMoved(); 600 controller_->FocusMoved();
598 } 601 }
599 602
600 void AutofillDialogViews::OnDidChangeFocus( 603 void AutofillDialogViews::OnDidChangeFocus(
601 views::View* focused_before, 604 views::View* focused_before,
602 views::View* focused_now) {} 605 views::View* focused_now) {}
603 606
604 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { 607 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) {
605 // Sign in link. 608 // Sign in link.
606 if (source == sign_in_link_) { 609 if (source == account_chooser_link_) {
607 controller_->StartSignInFlow(); 610 if (controller_->SignedInState() != SIGNED_IN) {
611 DCHECK(controller_->CanPayWithWallet());
612 controller_->StartSignInFlow();
613 }
614 // TODO(dbeam): handle other clicks on the account chooser (i.e. combobox).
608 return; 615 return;
609 } 616 }
610 617
611 // Edit links. 618 // Edit links.
612 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 619 for (DetailGroupMap::iterator iter = detail_groups_.begin();
613 iter != detail_groups_.end(); ++iter) { 620 iter != detail_groups_.end(); ++iter) {
614 if (iter->second.suggested_info->Contains(source)) { 621 if (iter->second.suggested_info->Contains(source)) {
615 controller_->EditClickedForSection(iter->first); 622 controller_->EditClickedForSection(iter->first);
616 return; 623 return;
617 } 624 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 column_set->AddColumn(views::GridLayout::FILL, 679 column_set->AddColumn(views::GridLayout::FILL,
673 views::GridLayout::FILL, 680 views::GridLayout::FILL,
674 1, 681 1,
675 views::GridLayout::USE_PREF, 682 views::GridLayout::USE_PREF,
676 0, 683 0,
677 0); 684 0);
678 685
679 layout->StartRow(0, single_column_set); 686 layout->StartRow(0, single_column_set);
680 // TODO(abodenha) Create a chooser control to allow account selection. 687 // TODO(abodenha) Create a chooser control to allow account selection.
681 // See http://crbug.com/169858 688 // See http://crbug.com/169858
682 sign_in_link_ = new views::Link(controller_->SignInText()); 689 account_chooser_link_ = new views::Link();
683 sign_in_link_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 690 account_chooser_link_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
684 sign_in_link_->set_listener(this); 691 account_chooser_link_->set_listener(this);
685 layout->AddView(sign_in_link_); 692 layout->AddView(account_chooser_link_);
686 693
687 layout->StartRow(0, single_column_set); 694 layout->StartRowWithPadding(0, single_column_set,
688 notification_area_ = new NotificationArea(); 695 0, views::kRelatedControlVerticalSpacing);
696 notification_area_ = new NotificationArea(account_chooser_link_);
689 layout->AddView(notification_area_); 697 layout->AddView(notification_area_);
690 698
691 layout->StartRowWithPadding(0, single_column_set, 699 layout->StartRowWithPadding(0, single_column_set,
692 0, views::kUnrelatedControlVerticalSpacing); 700 0, views::kUnrelatedControlVerticalSpacing);
693 layout->AddView(CreateDetailsContainer()); 701 layout->AddView(CreateDetailsContainer());
694 return main_container_; 702 return main_container_;
695 } 703 }
696 704
697 views::View* AutofillDialogViews::CreateDetailsContainer() { 705 views::View* AutofillDialogViews::CreateDetailsContainer() {
698 views::View* view = new views::View(); 706 views::View* view = new views::View();
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 986 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
979 : section(section), 987 : section(section),
980 container(NULL), 988 container(NULL),
981 manual_input(NULL), 989 manual_input(NULL),
982 suggested_info(NULL), 990 suggested_info(NULL),
983 suggested_button(NULL) {} 991 suggested_button(NULL) {}
984 992
985 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 993 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
986 994
987 } // namespace autofill 995 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698