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

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

Issue 11818006: requestAutocomplete: move billing/shipping checkbox to shipping section (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 7 years, 11 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/autofill/autofill_dialog_controller.cc ('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/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 240 }
241 241
242 bool AutofillDialogViews::Accept() { 242 bool AutofillDialogViews::Accept() {
243 did_submit_ = true; 243 did_submit_ = true;
244 return true; 244 return true;
245 } 245 }
246 246
247 void AutofillDialogViews::ButtonPressed(views::Button* sender, 247 void AutofillDialogViews::ButtonPressed(views::Button* sender,
248 const ui::Event& event) { 248 const ui::Event& event) {
249 if (sender == use_billing_for_shipping_) { 249 if (sender == use_billing_for_shipping_) {
250 shipping_.container->SetVisible(!use_billing_for_shipping_->checked()); 250 UpdateDetailsGroupState(shipping_);
251 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
252 } else { 251 } else {
253 // TODO(estade): Should the menu be shown on mouse down? 252 // TODO(estade): Should the menu be shown on mouse down?
254 DetailsGroup* group = 253 DetailsGroup* group =
255 sender == email_.suggested_button ? &email_ : 254 sender == email_.suggested_button ? &email_ :
256 sender == cc_.suggested_button ? &cc_ : 255 sender == cc_.suggested_button ? &cc_ :
257 sender == billing_.suggested_button ? &billing_ : 256 sender == billing_.suggested_button ? &billing_ :
258 sender == shipping_.suggested_button ? &shipping_ : NULL; 257 sender == shipping_.suggested_button ? &shipping_ : NULL;
259 DCHECK(group); 258 DCHECK(group);
260 259
261 views::MenuModelAdapter adapter( 260 views::MenuModelAdapter adapter(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 views::View* AutofillDialogViews::CreateDetailsContainer() { 364 views::View* AutofillDialogViews::CreateDetailsContainer() {
366 views::View* view = new views::View(); 365 views::View* view = new views::View();
367 // A box layout is used because it respects widget visibility. 366 // A box layout is used because it respects widget visibility.
368 view->SetLayoutManager( 367 view->SetLayoutManager(
369 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 368 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
370 views::kRelatedControlVerticalSpacing)); 369 views::kRelatedControlVerticalSpacing));
371 370
372 // Email. 371 // Email.
373 CreateDetailsSection(SECTION_EMAIL); 372 CreateDetailsSection(SECTION_EMAIL);
374 view->AddChildView(email_.container); 373 view->AddChildView(email_.container);
374 // Credit card.
375 CreateDetailsSection(SECTION_CC);
376 view->AddChildView(cc_.container);
375 // Billing. 377 // Billing.
376 CreateBillingSection(); 378 CreateDetailsSection(SECTION_BILLING);
377 view->AddChildView(billing_.container); 379 view->AddChildView(billing_.container);
378 // Shipping. 380 // Shipping.
379 CreateDetailsSection(SECTION_SHIPPING); 381 CreateDetailsSection(SECTION_SHIPPING);
380 view->AddChildView(shipping_.container); 382 view->AddChildView(shipping_.container);
381 shipping_.container->SetVisible(!use_billing_for_shipping_->checked());
382 383
383 return view; 384 return view;
384 } 385 }
385 386
386 void AutofillDialogViews::CreateDetailsSection(DialogSection section) { 387 void AutofillDialogViews::CreateDetailsSection(DialogSection section) {
387 DCHECK_NE(SECTION_CC, section);
388 DCHECK_NE(SECTION_BILLING, section);
389
390 // Inputs container (manual inputs + combobox). 388 // Inputs container (manual inputs + combobox).
391 views::View* inputs_container = CreateInputsContainer(section); 389 views::View* inputs_container = CreateInputsContainer(section);
392 390
393 DetailsGroup* group = GroupForSection(section); 391 DetailsGroup* group = GroupForSection(section);
394 // Container (holds label + inputs). 392 // Container (holds label + inputs).
395 group->container = new SectionContainer( 393 group->container = new SectionContainer(
396 controller_->LabelForSection(section), 394 controller_->LabelForSection(section),
397 inputs_container, 395 inputs_container,
398 group->suggested_button); 396 group->suggested_button);
399 UpdateDetailsGroupState(*group); 397 UpdateDetailsGroupState(*group);
400 } 398 }
401 399
402 void AutofillDialogViews::CreateBillingSection() {
403 views::View* billing = new views::View();
404 billing->SetLayoutManager(new views::BoxLayout(
405 views::BoxLayout::kVertical, 0, 0,
406 views::kRelatedControlVerticalSpacing));
407
408 static const DialogSection sections[] = { SECTION_CC, SECTION_BILLING };
409 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(sections); ++i) {
410 // Inputs container (manual inputs + combobox).
411 views::View* inputs_container = CreateInputsContainer(sections[i]);
412 billing->AddChildView(inputs_container);
413 }
414
415 use_billing_for_shipping_ =
416 new views::Checkbox(controller_->UseBillingForShippingText());
417 use_billing_for_shipping_->SetChecked(true);
418 use_billing_for_shipping_->set_listener(this);
419 billing->AddChildView(use_billing_for_shipping_);
420
421 // Container (holds label + inputs).
422 billing_.container = new SectionContainer(
423 controller_->LabelForSection(SECTION_BILLING),
424 billing,
425 billing_.suggested_button);
426 UpdateDetailsGroupState(billing_);
427 UpdateDetailsGroupState(cc_);
428 }
429
430 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) { 400 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) {
431 views::View* inputs_container = new views::View(); 401 views::View* inputs_container = new views::View();
432 views::GridLayout* layout = new views::GridLayout(inputs_container); 402 views::GridLayout* layout = new views::GridLayout(inputs_container);
433 inputs_container->SetLayoutManager(layout); 403 inputs_container->SetLayoutManager(layout);
434 404
435 int kColumnSetId = 0; 405 int kColumnSetId = 0;
436 views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); 406 views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId);
437 column_set->AddColumn(views::GridLayout::FILL, 407 column_set->AddColumn(views::GridLayout::FILL,
438 views::GridLayout::LEADING, 408 views::GridLayout::LEADING,
439 1, 409 1,
440 views::GridLayout::USE_PREF, 410 views::GridLayout::USE_PREF,
441 0, 411 0,
442 0); 412 0);
443 column_set->AddColumn(views::GridLayout::CENTER, 413 column_set->AddColumn(views::GridLayout::CENTER,
444 views::GridLayout::LEADING, 414 views::GridLayout::LEADING,
445 0, 415 0,
446 views::GridLayout::USE_PREF, 416 views::GridLayout::USE_PREF,
447 0, 417 0,
448 0); 418 0);
449 layout->StartRow(0, kColumnSetId); 419 layout->StartRow(0, kColumnSetId);
450 420
451 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the 421 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the
452 // dialog toggle which is shown. 422 // dialog toggle which is shown.
453 views::View* info_view = new views::View(); 423 views::View* info_view = new views::View();
454 info_view->SetLayoutManager( 424 info_view->SetLayoutManager(
455 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 425 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
426
427 if (section == SECTION_SHIPPING) {
428 use_billing_for_shipping_ =
429 new views::Checkbox(controller_->UseBillingForShippingText());
430 use_billing_for_shipping_->SetChecked(true);
431 use_billing_for_shipping_->set_listener(this);
432 info_view->AddChildView(use_billing_for_shipping_);
433 }
434
456 views::View* manual_inputs = InitInputsView(section); 435 views::View* manual_inputs = InitInputsView(section);
457 info_view->AddChildView(manual_inputs); 436 info_view->AddChildView(manual_inputs);
458 views::Label* suggested_info = new views::Label(); 437 views::Label* suggested_info = new views::Label();
459 suggested_info->SetHorizontalAlignment(gfx::ALIGN_LEFT); 438 suggested_info->SetHorizontalAlignment(gfx::ALIGN_LEFT);
460 info_view->AddChildView(suggested_info); 439 info_view->AddChildView(suggested_info);
461 layout->AddView(info_view); 440 layout->AddView(info_view);
462 441
463 // TODO(estade): Fix the appearance of this button. 442 // TODO(estade): Fix the appearance of this button.
464 views::ImageButton* menu_button = new views::ImageButton(this); 443 views::ImageButton* menu_button = new views::ImageButton(this);
465 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 444 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 517 }
539 } 518 }
540 519
541 return view; 520 return view;
542 } 521 }
543 522
544 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { 523 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) {
545 string16 suggestion_text = 524 string16 suggestion_text =
546 controller_->SuggestionTextForSection(group.section); 525 controller_->SuggestionTextForSection(group.section);
547 bool show_suggestions = !suggestion_text.empty(); 526 bool show_suggestions = !suggestion_text.empty();
548 group.manual_input->SetVisible(!show_suggestions);
549 group.suggested_info->SetVisible(show_suggestions); 527 group.suggested_info->SetVisible(show_suggestions);
550 group.suggested_info->SetText(suggestion_text); 528 group.suggested_info->SetText(suggestion_text);
551 529
530 if (group.section == SECTION_SHIPPING) {
531 bool show_checkbox = !show_suggestions;
532 // When the checkbox is going from hidden to visible, it's because the
533 // user clicked "Enter new address". Reset the checkbox to unchecked in this
534 // case.
535 if (show_checkbox && !use_billing_for_shipping_->visible())
536 use_billing_for_shipping_->SetChecked(false);
537
538 use_billing_for_shipping_->SetVisible(show_checkbox);
539 group.manual_input->SetVisible(
540 show_checkbox && !use_billing_for_shipping_->checked());
541 } else {
542 group.manual_input->SetVisible(!show_suggestions);
543 }
544
552 if (group.container) 545 if (group.container)
553 group.container->SetForwardMouseEvents(show_suggestions); 546 group.container->SetForwardMouseEvents(show_suggestions);
554 547
555 if (GetWidget()) 548 if (GetWidget())
556 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); 549 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
557 } 550 }
558 551
559 AutofillDialogViews::DetailsGroup* AutofillDialogViews:: 552 AutofillDialogViews::DetailsGroup* AutofillDialogViews::
560 GroupForSection(DialogSection section) { 553 GroupForSection(DialogSection section) {
561 switch (section) { 554 switch (section) {
(...skipping 14 matching lines...) Expand all
576 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 569 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
577 : section(section), 570 : section(section),
578 container(NULL), 571 container(NULL),
579 manual_input(NULL), 572 manual_input(NULL),
580 suggested_info(NULL), 573 suggested_info(NULL),
581 suggested_button(NULL) {} 574 suggested_button(NULL) {}
582 575
583 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 576 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
584 577
585 } // namespace autofill 578 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698