| 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/i18n/break_iterator.h" |
| 10 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/autofill/wallet/wallet_service_url.h" | 12 #include "chrome/browser/autofill/wallet/wallet_service_url.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 14 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
| 13 #include "chrome/browser/ui/views/constrained_window_views.h" | 15 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 14 #include "content/public/browser/native_web_keyboard_event.h" | 16 #include "content/public/browser/native_web_keyboard_event.h" |
| 15 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 16 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 17 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 20 #include "third_party/skia/include/core/SkColor.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 45 const size_t kDogEarSize = 10; | 47 const size_t kDogEarSize = 10; |
| 46 | 48 |
| 47 const size_t kAutocheckoutProgressBarWidth = 300; | 49 const size_t kAutocheckoutProgressBarWidth = 300; |
| 48 const size_t kAutocheckoutProgressBarHeight = 11; | 50 const size_t kAutocheckoutProgressBarHeight = 11; |
| 49 | 51 |
| 50 const size_t kArrowHeight = 7; | 52 const size_t kArrowHeight = 7; |
| 51 const size_t kArrowWidth = 2 * kArrowHeight; | 53 const size_t kArrowWidth = 2 * kArrowHeight; |
| 52 | 54 |
| 53 const char kDecoratedTextfieldClassName[] = "autofill/DecoratedTextfield"; | 55 const char kDecoratedTextfieldClassName[] = "autofill/DecoratedTextfield"; |
| 54 const char kNotificationAreaClassName[] = "autofill/NotificationArea"; | 56 const char kNotificationAreaClassName[] = "autofill/NotificationArea"; |
| 57 const char kFootnoteViewClassName[] = "autofill/FootnoteView"; |
| 55 | 58 |
| 56 // Returns a label that describes a details section. | 59 // Returns a label that describes a details section. |
| 57 views::Label* CreateDetailsSectionLabel(const string16& text) { | 60 views::Label* CreateDetailsSectionLabel(const string16& text) { |
| 58 views::Label* label = new views::Label(text); | 61 views::Label* label = new views::Label(text); |
| 59 label->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 62 label->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 60 label->SetFont(label->font().DeriveFont(0, gfx::Font::BOLD)); | 63 label->SetFont(label->font().DeriveFont(0, gfx::Font::BOLD)); |
| 61 // TODO(estade): this should be made to match the native textfield top | 64 // TODO(estade): this should be made to match the native textfield top |
| 62 // inset. It's hard to get at, so for now it's hard-coded. | 65 // inset. It's hard to get at, so for now it's hard-coded. |
| 63 label->set_border(views::Border::CreateEmptyBorder(4, 0, 0, 0)); | 66 label->set_border(views::Border::CreateEmptyBorder(4, 0, 0, 0)); |
| 64 return label; | 67 return label; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 icon_->SetImage(image.AsImageSkia()); | 328 icon_->SetImage(image.AsImageSkia()); |
| 326 } | 329 } |
| 327 | 330 |
| 328 void AutofillDialogViews::SuggestionView::ShowTextfield( | 331 void AutofillDialogViews::SuggestionView::ShowTextfield( |
| 329 const string16& placeholder_text) { | 332 const string16& placeholder_text) { |
| 330 decorated_->textfield()->set_placeholder_text(placeholder_text); | 333 decorated_->textfield()->set_placeholder_text(placeholder_text); |
| 331 decorated_->SetVisible(true); | 334 decorated_->SetVisible(true); |
| 332 } | 335 } |
| 333 | 336 |
| 334 // AutofilDialogViews::AutocheckoutProgressBar --------------------------------- | 337 // AutofilDialogViews::AutocheckoutProgressBar --------------------------------- |
| 338 |
| 335 AutofillDialogViews::AutocheckoutProgressBar::AutocheckoutProgressBar() {} | 339 AutofillDialogViews::AutocheckoutProgressBar::AutocheckoutProgressBar() {} |
| 336 | 340 |
| 337 gfx::Size AutofillDialogViews::AutocheckoutProgressBar::GetPreferredSize() { | 341 gfx::Size AutofillDialogViews::AutocheckoutProgressBar::GetPreferredSize() { |
| 338 return gfx::Size(kAutocheckoutProgressBarWidth, | 342 return gfx::Size(kAutocheckoutProgressBarWidth, |
| 339 kAutocheckoutProgressBarHeight); | 343 kAutocheckoutProgressBarHeight); |
| 340 } | 344 } |
| 341 | 345 |
| 346 // AutofillDialogViews::FootnoteView ------------------------------------------- |
| 347 |
| 348 AutofillDialogViews::FootnoteView::FootnoteView() |
| 349 : current_width_(0), |
| 350 layout_(NULL), |
| 351 previous_parent_width_(-1), |
| 352 single_column_set_(0) { |
| 353 set_border(views::Border::CreateEmptyBorder( |
| 354 views::kUnrelatedControlVerticalSpacing, 0, |
| 355 views::kUnrelatedControlVerticalSpacing, 0)); |
| 356 } |
| 357 |
| 358 AutofillDialogViews::FootnoteView::~FootnoteView() {} |
| 359 |
| 360 std::string AutofillDialogViews::FootnoteView::GetClassName() const { |
| 361 return kFootnoteViewClassName; |
| 362 } |
| 363 |
| 364 void AutofillDialogViews::FootnoteView::AddLabel(views::Label* label, |
| 365 bool is_link) { |
| 366 FootnoteLabel* footnote_label = new FootnoteLabel(); |
| 367 footnote_label->label.reset(label); |
| 368 footnote_label->is_link = is_link; |
| 369 footnote_labels_.push_back(footnote_label); |
| 370 previous_parent_width_ = -1; |
| 371 } |
| 372 |
| 373 int AutofillDialogViews::FootnoteView::IndexOfLink(views::Label* link) { |
| 374 size_t distance = std::distance( |
| 375 links_.begin(), std::find(links_.begin(), links_.end(), link)); |
| 376 return distance < links_.size() ? distance : -1; |
| 377 } |
| 378 |
| 379 void AutofillDialogViews::FootnoteView::StartRow() { |
| 380 layout_->StartRow(0, single_column_set_); |
| 381 views::View* row = new views::View(); |
| 382 row->SetLayoutManager( |
| 383 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 384 layout_->AddView(row); |
| 385 } |
| 386 |
| 387 views::View* AutofillDialogViews::FootnoteView::CurrentRow() { |
| 388 return child_at(child_count() - 1); |
| 389 } |
| 390 |
| 391 void AutofillDialogViews::FootnoteView::ResetRows() { |
| 392 ResetLayoutManager(); |
| 393 RemoveAllChildViews(true); |
| 394 } |
| 395 |
| 396 void AutofillDialogViews::FootnoteView::ResetLayoutManager() { |
| 397 views::GridLayout* layout = new views::GridLayout(this); |
| 398 SetLayoutManager(layout); |
| 399 |
| 400 layout_ = layout; |
| 401 layout_->AddColumnSet(single_column_set_)->AddColumn( |
| 402 views::GridLayout::FILL, |
| 403 views::GridLayout::FILL, |
| 404 1, |
| 405 views::GridLayout::USE_PREF, |
| 406 0, |
| 407 0); |
| 408 } |
| 409 |
| 410 void AutofillDialogViews::FootnoteView::Reset() { |
| 411 ResetRows(); |
| 412 ResetText(); |
| 413 ResetWidth(); |
| 414 StartRow(); |
| 415 } |
| 416 |
| 417 void AutofillDialogViews::FootnoteView::AppendText(const string16& text_part) { |
| 418 current_text_.append(text_part); |
| 419 } |
| 420 |
| 421 const string16& AutofillDialogViews::FootnoteView::CurrentText() const { |
| 422 return current_text_; |
| 423 } |
| 424 |
| 425 void AutofillDialogViews::FootnoteView::ResetWidth() { |
| 426 current_width_ = 0; |
| 427 } |
| 428 |
| 429 size_t AutofillDialogViews::FootnoteView::CurrentWidth() const { |
| 430 return current_width_; |
| 431 } |
| 432 |
| 433 void AutofillDialogViews::FootnoteView::AddWidth(size_t width) { |
| 434 current_width_ += width; |
| 435 } |
| 436 |
| 437 void AutofillDialogViews::FootnoteView::ResetText() { |
| 438 current_text_.clear(); |
| 439 } |
| 440 |
| 441 int AutofillDialogViews::FootnoteView::ParentWidth() { |
| 442 DCHECK(parent()); |
| 443 return parent()->GetPreferredSize().width(); |
| 444 } |
| 445 |
| 446 int AutofillDialogViews::FootnoteView::WidthRemaining() { |
| 447 return ParentWidth() - CurrentWidth(); |
| 448 } |
| 449 |
| 450 void AutofillDialogViews::FootnoteView::AddCloneWithWidth(views::Label* label, |
| 451 size_t width) { |
| 452 AddWidth(width); |
| 453 CurrentRow()->AddChildView(label); |
| 454 } |
| 455 |
| 456 views::Label* AutofillDialogViews::FootnoteView::CloneLabel( |
| 457 const string16& text, const gfx::Font& font, bool is_link) { |
| 458 views::Label* label = is_link ? new views::Link(text) : |
| 459 new views::Label(text); |
| 460 label->SetFont(font); |
| 461 return label; |
| 462 } |
| 463 |
| 464 void AutofillDialogViews::FootnoteView::TransferListener( |
| 465 views::Label* from_label, views::Label* to_label) { |
| 466 views::Link* from = static_cast<views::Link*>(from_label); |
| 467 views::Link* to = static_cast<views::Link*>(to_label); |
| 468 to->set_listener(const_cast<views::LinkListener*>(from->listener())); |
| 469 } |
| 470 |
| 471 void AutofillDialogViews::FootnoteView::Layout() { |
| 472 views::View::Layout(); |
| 473 |
| 474 if (!parent() || previous_parent_width_ == ParentWidth()) |
| 475 return; |
| 476 |
| 477 Reset(); |
| 478 |
| 479 for (size_t i = 0; i < footnote_labels_.size(); ++i) { |
| 480 views::Label* label = footnote_labels_[i]->label.get(); |
| 481 if (!label->visible()) |
| 482 continue; |
| 483 |
| 484 // The label is smaller than the available space. Add it wholesale. |
| 485 int tw = gfx::Canvas::GetStringWidth(label->text(), label->font()); |
| 486 if (tw < WidthRemaining()) { |
| 487 views::Label* clone = CloneLabel(label->text(), |
| 488 label->font(), |
| 489 footnote_labels_[i]->is_link); |
| 490 if (footnote_labels_[i]->is_link) { |
| 491 TransferListener(label, clone); |
| 492 links_.push_back(clone); |
| 493 } |
| 494 AddCloneWithWidth(clone, tw); |
| 495 continue; |
| 496 } |
| 497 |
| 498 // Don't wrap links mid-line. This one's too big, so make a new row. |
| 499 if (footnote_labels_[i]->is_link) { |
| 500 StartRow(); |
| 501 ResetWidth(); |
| 502 links_.push_back(CloneLabel(label->text(), label->font(), true)); |
| 503 TransferListener(label, links_.back()); |
| 504 AddCloneWithWidth(links_.back(), tw); |
| 505 if (tw > ParentWidth()) { |
| 506 StartRow(); |
| 507 ResetWidth(); |
| 508 } |
| 509 continue; |
| 510 } |
| 511 |
| 512 // Go through the text word by word, seeing if each one fits. |
| 513 DCHECK(CurrentText().empty()); |
| 514 base::i18n::BreakIterator iter(label->text(), |
| 515 base::i18n::BreakIterator::BREAK_SPACE); |
| 516 for (bool first_word = true, more_words = iter.Init() && iter.Advance(); |
| 517 more_words; ) { |
| 518 int width = 0; |
| 519 // Iterate until no more words or space left. |
| 520 do { |
| 521 string16 text = iter.GetString(); |
| 522 if (first_word) { |
| 523 TrimWhitespace(text, TRIM_LEADING, &text); |
| 524 first_word = false; |
| 525 } |
| 526 |
| 527 const int w = gfx::Canvas::GetStringWidth(text, label->font()); |
| 528 if (width + w > WidthRemaining()) |
| 529 break; |
| 530 |
| 531 width += w; |
| 532 AppendText(text); |
| 533 } while ((more_words = iter.Advance())); |
| 534 |
| 535 // If we didn't run out of words, the space is full. Start a new row. |
| 536 if (more_words) { |
| 537 StartRow(); |
| 538 ResetWidth(); |
| 539 } |
| 540 |
| 541 AddCloneWithWidth(CloneLabel(CurrentText(), label->font(), false), width); |
| 542 ResetText(); |
| 543 } |
| 544 } |
| 545 |
| 546 previous_parent_width_ = ParentWidth(); |
| 547 } |
| 548 |
| 342 // AutofillDialogView ---------------------------------------------------------- | 549 // AutofillDialogView ---------------------------------------------------------- |
| 343 | 550 |
| 344 // static | 551 // static |
| 345 AutofillDialogView* AutofillDialogView::Create( | 552 AutofillDialogView* AutofillDialogView::Create( |
| 346 AutofillDialogController* controller) { | 553 AutofillDialogController* controller) { |
| 347 return new AutofillDialogViews(controller); | 554 return new AutofillDialogViews(controller); |
| 348 } | 555 } |
| 349 | 556 |
| 350 // AutofillDialogViews --------------------------------------------------------- | 557 // AutofillDialogViews --------------------------------------------------------- |
| 351 | 558 |
| 352 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller) | 559 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller) |
| 353 : controller_(controller), | 560 : controller_(controller), |
| 354 did_submit_(false), | 561 did_submit_(false), |
| 355 window_(NULL), | 562 window_(NULL), |
| 356 contents_(NULL), | 563 contents_(NULL), |
| 357 notification_area_(NULL), | 564 notification_area_(NULL), |
| 358 use_billing_for_shipping_(NULL), | 565 use_billing_for_shipping_(NULL), |
| 359 account_chooser_link_(NULL), | 566 account_chooser_link_(NULL), |
| 360 sign_in_container_(NULL), | 567 sign_in_container_(NULL), |
| 361 cancel_sign_in_(NULL), | 568 cancel_sign_in_(NULL), |
| 362 sign_in_webview_(NULL), | 569 sign_in_webview_(NULL), |
| 363 main_container_(NULL), | 570 main_container_(NULL), |
| 364 button_strip_extra_view_(NULL), | 571 button_strip_extra_view_(NULL), |
| 365 save_in_chrome_checkbox_(NULL), | 572 save_in_chrome_checkbox_(NULL), |
| 366 autocheckout_progress_bar_view_(NULL), | 573 autocheckout_progress_bar_view_(NULL), |
| 367 autocheckout_progress_bar_(NULL), | 574 autocheckout_progress_bar_(NULL), |
| 575 footnote_view_(NULL), |
| 368 focus_manager_(NULL) { | 576 focus_manager_(NULL) { |
| 369 DCHECK(controller); | 577 DCHECK(controller); |
| 370 detail_groups_.insert(std::make_pair(SECTION_EMAIL, | 578 detail_groups_.insert(std::make_pair(SECTION_EMAIL, |
| 371 DetailsGroup(SECTION_EMAIL))); | 579 DetailsGroup(SECTION_EMAIL))); |
| 372 detail_groups_.insert(std::make_pair(SECTION_CC, | 580 detail_groups_.insert(std::make_pair(SECTION_CC, |
| 373 DetailsGroup(SECTION_CC))); | 581 DetailsGroup(SECTION_CC))); |
| 374 detail_groups_.insert(std::make_pair(SECTION_BILLING, | 582 detail_groups_.insert(std::make_pair(SECTION_BILLING, |
| 375 DetailsGroup(SECTION_BILLING))); | 583 DetailsGroup(SECTION_BILLING))); |
| 376 detail_groups_.insert(std::make_pair(SECTION_SHIPPING, | 584 detail_groups_.insert(std::make_pair(SECTION_SHIPPING, |
| 377 DetailsGroup(SECTION_SHIPPING))); | 585 DetailsGroup(SECTION_SHIPPING))); |
| 378 } | 586 } |
| 379 | 587 |
| 380 AutofillDialogViews::~AutofillDialogViews() { | 588 AutofillDialogViews::~AutofillDialogViews() { |
| 381 DCHECK(!window_); | 589 DCHECK(!window_); |
| 382 | 590 |
| 383 // |notification_area_| could be NULL if |Show()| was never called. | 591 // |notification_area_| could be NULL if |Show()| was never called. |
| 384 if (notification_area_) | 592 if (notification_area_) |
| 385 notification_area_->set_arrow_centering_anchor(NULL); | 593 notification_area_->set_arrow_centering_anchor(NULL); |
| 386 } | 594 } |
| 387 | 595 |
| 388 void AutofillDialogViews::Show() { | 596 void AutofillDialogViews::Show() { |
| 389 InitChildViews(); | 597 InitChildViews(); |
| 390 UpdateAccountChooser(); | 598 UpdateAccountChooser(); |
| 391 UpdateNotificationArea(); | 599 UpdateNotificationArea(); |
| 600 UpdateFootnote(); |
| 392 | 601 |
| 393 // Ownership of |contents_| is handed off by this call. The | 602 // Ownership of |contents_| is handed off by this call. The |
| 394 // WebContentsModalDialog will take care of deleting itself after calling | 603 // WebContentsModalDialog will take care of deleting itself after calling |
| 395 // DeleteDelegate(). | 604 // DeleteDelegate(). |
| 396 window_ = ConstrainedWindowViews::Create(controller_->web_contents(), this); | 605 window_ = ConstrainedWindowViews::Create(controller_->web_contents(), this); |
| 397 focus_manager_ = window_->GetFocusManager(); | 606 focus_manager_ = window_->GetFocusManager(); |
| 398 focus_manager_->AddFocusChangeListener(this); | 607 focus_manager_->AddFocusChangeListener(this); |
| 399 } | 608 } |
| 400 | 609 |
| 401 void AutofillDialogViews::Hide() { | 610 void AutofillDialogViews::Hide() { |
| 402 if (window_) | 611 if (window_) |
| 403 window_->CloseWebContentsModalDialog(); | 612 window_->CloseWebContentsModalDialog(); |
| 404 } | 613 } |
| 405 | 614 |
| 406 void AutofillDialogViews::UpdateAccountChooser() { | 615 void AutofillDialogViews::UpdateAccountChooser() { |
| 407 // TODO(dbeam): show/hide account chooser combobox when it exists? | 616 // TODO(dbeam): show/hide account chooser combobox when it exists? |
| 408 // TODO(dbeam): show/hide fancy Google Wallet logo when it exists. | 617 // TODO(dbeam): show/hide fancy Google Wallet logo when it exists. |
| 409 account_chooser_link_->SetText(controller_->AccountChooserText()); | 618 account_chooser_link_->SetText(controller_->AccountChooserText()); |
| 410 account_chooser_link_->SetEnabled(controller_->AccountChooserEnabled()); | 619 account_chooser_link_->SetEnabled(controller_->AccountChooserEnabled()); |
| 411 } | 620 } |
| 412 | 621 |
| 413 void AutofillDialogViews::UpdateNotificationArea() { | 622 void AutofillDialogViews::UpdateNotificationArea() { |
| 414 DCHECK(notification_area_); | 623 DCHECK(notification_area_); |
| 415 notification_area_->SetNotification(controller_->CurrentNotification()); | 624 notification_area_->SetNotification(controller_->CurrentNotification()); |
| 416 | 625 ContentsResized(); |
| 417 if (GetWidget()) | |
| 418 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); | |
| 419 | |
| 420 contents_->Layout(); | |
| 421 } | 626 } |
| 422 | 627 |
| 423 void AutofillDialogViews::UpdateSection(DialogSection section) { | 628 void AutofillDialogViews::UpdateSection(DialogSection section) { |
| 424 const DetailInputs& updated_inputs = | 629 const DetailInputs& updated_inputs = |
| 425 controller_->RequestedFieldsForSection(section); | 630 controller_->RequestedFieldsForSection(section); |
| 426 DetailsGroup* group = GroupForSection(section); | 631 DetailsGroup* group = GroupForSection(section); |
| 427 | 632 |
| 428 for (DetailInputs::const_iterator iter = updated_inputs.begin(); | 633 for (DetailInputs::const_iterator iter = updated_inputs.begin(); |
| 429 iter != updated_inputs.end(); ++iter) { | 634 iter != updated_inputs.end(); ++iter) { |
| 430 TextfieldMap::iterator input = group->textfields.find(&(*iter)); | 635 TextfieldMap::iterator input = group->textfields.find(&(*iter)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 682 |
| 478 void AutofillDialogViews::HideSignIn() { | 683 void AutofillDialogViews::HideSignIn() { |
| 479 sign_in_container_->SetVisible(false); | 684 sign_in_container_->SetVisible(false); |
| 480 main_container_->SetVisible(true); | 685 main_container_->SetVisible(true); |
| 481 } | 686 } |
| 482 | 687 |
| 483 void AutofillDialogViews::UpdateProgressBar(double value) { | 688 void AutofillDialogViews::UpdateProgressBar(double value) { |
| 484 autocheckout_progress_bar_->SetValue(value); | 689 autocheckout_progress_bar_->SetValue(value); |
| 485 } | 690 } |
| 486 | 691 |
| 692 void AutofillDialogViews::UpdateFootnote() { |
| 693 PopulateFootnoteLinks(); |
| 694 ContentsResized(); |
| 695 } |
| 696 |
| 487 string16 AutofillDialogViews::GetWindowTitle() const { | 697 string16 AutofillDialogViews::GetWindowTitle() const { |
| 488 return controller_->DialogTitle(); | 698 return controller_->DialogTitle(); |
| 489 } | 699 } |
| 490 | 700 |
| 491 void AutofillDialogViews::WindowClosing() { | 701 void AutofillDialogViews::WindowClosing() { |
| 492 focus_manager_->RemoveFocusChangeListener(this); | 702 focus_manager_->RemoveFocusChangeListener(this); |
| 493 } | 703 } |
| 494 | 704 |
| 495 void AutofillDialogViews::DeleteDelegate() { | 705 void AutofillDialogViews::DeleteDelegate() { |
| 496 window_ = NULL; | 706 window_ = NULL; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 518 | 728 |
| 519 bool AutofillDialogViews::IsDialogButtonEnabled(ui::DialogButton button) const { | 729 bool AutofillDialogViews::IsDialogButtonEnabled(ui::DialogButton button) const { |
| 520 return true; | 730 return true; |
| 521 } | 731 } |
| 522 | 732 |
| 523 views::View* AutofillDialogViews::GetExtraView() { | 733 views::View* AutofillDialogViews::GetExtraView() { |
| 524 return button_strip_extra_view_; | 734 return button_strip_extra_view_; |
| 525 } | 735 } |
| 526 | 736 |
| 527 views::View* AutofillDialogViews::GetFootnoteView() { | 737 views::View* AutofillDialogViews::GetFootnoteView() { |
| 528 // TODO(estade): add a view to contain the terms of service. | 738 return footnote_view_; |
| 529 return NULL; | |
| 530 } | 739 } |
| 531 | 740 |
| 532 bool AutofillDialogViews::Cancel() { | 741 bool AutofillDialogViews::Cancel() { |
| 533 return true; | 742 return true; |
| 534 } | 743 } |
| 535 | 744 |
| 536 bool AutofillDialogViews::Accept() { | 745 bool AutofillDialogViews::Accept() { |
| 537 if (!ValidateForm()) | 746 if (!ValidateForm()) |
| 538 return false; | 747 return false; |
| 539 | 748 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 views::View* focused_before, | 809 views::View* focused_before, |
| 601 views::View* focused_now) { | 810 views::View* focused_now) { |
| 602 controller_->FocusMoved(); | 811 controller_->FocusMoved(); |
| 603 } | 812 } |
| 604 | 813 |
| 605 void AutofillDialogViews::OnDidChangeFocus( | 814 void AutofillDialogViews::OnDidChangeFocus( |
| 606 views::View* focused_before, | 815 views::View* focused_before, |
| 607 views::View* focused_now) {} | 816 views::View* focused_now) {} |
| 608 | 817 |
| 609 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { | 818 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { |
| 610 // Sign in link. | |
| 611 if (source == account_chooser_link_) { | 819 if (source == account_chooser_link_) { |
| 612 if (controller_->SignedInState() != SIGNED_IN) { | 820 if (controller_->SignedInState() != SIGNED_IN) { |
| 613 DCHECK(controller_->CanPayWithWallet()); | 821 DCHECK(controller_->CanPayWithWallet()); |
| 614 controller_->StartSignInFlow(); | 822 controller_->StartSignInFlow(); |
| 615 } | 823 } |
| 616 // TODO(dbeam): handle other clicks on the account chooser (i.e. combobox). | 824 // TODO(dbeam): handle other clicks on the account chooser (i.e. combobox). |
| 617 return; | 825 } else if (footnote_view_->Contains(source)) { |
| 618 } | 826 controller_->LegalDocumentLinkClicked(footnote_view_->IndexOfLink(source)); |
| 619 | 827 } else { |
| 620 // Edit links. | 828 // Edit links. |
| 621 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 829 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
| 622 iter != detail_groups_.end(); ++iter) { | 830 iter != detail_groups_.end(); ++iter) { |
| 623 if (iter->second.suggested_info->Contains(source)) { | 831 if (iter->second.suggested_info->Contains(source)) { |
| 624 controller_->EditClickedForSection(iter->first); | 832 controller_->EditClickedForSection(iter->first); |
| 625 return; | 833 return; |
| 834 } |
| 626 } | 835 } |
| 627 } | 836 } |
| 628 } | 837 } |
| 629 | 838 |
| 630 void AutofillDialogViews::InitChildViews() { | 839 void AutofillDialogViews::InitChildViews() { |
| 631 button_strip_extra_view_ = new views::View(); | 840 button_strip_extra_view_ = new views::View(); |
| 632 button_strip_extra_view_->SetLayoutManager( | 841 button_strip_extra_view_->SetLayoutManager( |
| 633 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 842 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 634 | 843 |
| 635 save_in_chrome_checkbox_ = | 844 save_in_chrome_checkbox_ = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 649 autocheckout_progress_bar_ = new AutocheckoutProgressBar(); | 858 autocheckout_progress_bar_ = new AutocheckoutProgressBar(); |
| 650 autocheckout_progress_bar_view_->AddChildView(autocheckout_progress_bar_); | 859 autocheckout_progress_bar_view_->AddChildView(autocheckout_progress_bar_); |
| 651 | 860 |
| 652 button_strip_extra_view_->AddChildView(autocheckout_progress_bar_view_); | 861 button_strip_extra_view_->AddChildView(autocheckout_progress_bar_view_); |
| 653 | 862 |
| 654 contents_ = new views::View(); | 863 contents_ = new views::View(); |
| 655 contents_->SetLayoutManager( | 864 contents_->SetLayoutManager( |
| 656 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 865 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 657 contents_->AddChildView(CreateMainContainer()); | 866 contents_->AddChildView(CreateMainContainer()); |
| 658 contents_->AddChildView(CreateSignInContainer()); | 867 contents_->AddChildView(CreateSignInContainer()); |
| 659 } | |
| 660 | 868 |
| 661 views::View* AutofillDialogViews::CreateSignInContainer() { | 869 // |footnote_view_| is added to View hierarchy by |GetFootnoteView()|. |
| 662 sign_in_container_ = new views::View(); | 870 footnote_view_ = new FootnoteView(); |
| 663 sign_in_container_->SetLayoutManager( | |
| 664 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 665 sign_in_container_->SetVisible(false); | |
| 666 sign_in_webview_ = new views::WebView(controller_->profile()); | |
| 667 cancel_sign_in_ = new views::TextButton(this, | |
| 668 controller_->CancelSignInText()); | |
| 669 sign_in_container_->AddChildView(cancel_sign_in_); | |
| 670 sign_in_container_->AddChildView(sign_in_webview_); | |
| 671 return sign_in_container_; | |
| 672 } | 871 } |
| 673 | 872 |
| 674 views::View* AutofillDialogViews::CreateMainContainer() { | 873 views::View* AutofillDialogViews::CreateMainContainer() { |
| 675 main_container_ = new views::View(); | 874 main_container_ = new views::View(); |
| 676 views::GridLayout* layout = new views::GridLayout(main_container_); | 875 views::GridLayout* layout = new views::GridLayout(main_container_); |
| 677 main_container_->SetLayoutManager(layout); | 876 main_container_->SetLayoutManager(layout); |
| 678 | 877 |
| 679 const int single_column_set = 0; | 878 const int single_column_set = 0; |
| 680 views::ColumnSet* column_set = layout->AddColumnSet(single_column_set); | 879 views::ColumnSet* column_set = layout->AddColumnSet(single_column_set); |
| 681 column_set->AddColumn(views::GridLayout::FILL, | 880 column_set->AddColumn(views::GridLayout::FILL, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 698 notification_area_ = new NotificationArea(); | 897 notification_area_ = new NotificationArea(); |
| 699 notification_area_->set_arrow_centering_anchor(account_chooser_link_); | 898 notification_area_->set_arrow_centering_anchor(account_chooser_link_); |
| 700 layout->AddView(notification_area_); | 899 layout->AddView(notification_area_); |
| 701 | 900 |
| 702 layout->StartRowWithPadding(0, single_column_set, | 901 layout->StartRowWithPadding(0, single_column_set, |
| 703 0, views::kUnrelatedControlVerticalSpacing); | 902 0, views::kUnrelatedControlVerticalSpacing); |
| 704 layout->AddView(CreateDetailsContainer()); | 903 layout->AddView(CreateDetailsContainer()); |
| 705 return main_container_; | 904 return main_container_; |
| 706 } | 905 } |
| 707 | 906 |
| 907 views::View* AutofillDialogViews::CreateSignInContainer() { |
| 908 sign_in_container_ = new views::View(); |
| 909 sign_in_container_->SetLayoutManager( |
| 910 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 911 sign_in_container_->SetVisible(false); |
| 912 sign_in_webview_ = new views::WebView(controller_->profile()); |
| 913 cancel_sign_in_ = new views::TextButton(this, |
| 914 controller_->CancelSignInText()); |
| 915 sign_in_container_->AddChildView(cancel_sign_in_); |
| 916 sign_in_container_->AddChildView(sign_in_webview_); |
| 917 return sign_in_container_; |
| 918 } |
| 919 |
| 920 void AutofillDialogViews::PopulateFootnoteLinks() { |
| 921 const std::vector<string16>& link_parts = controller_->FootnoteLinkParts(); |
| 922 for (size_t i = 0; i < link_parts.size(); ++i) { |
| 923 if (i % 2 == 0) { |
| 924 // Text between links. |
| 925 footnote_view_->AddLabel(new views::Label(link_parts[i]), false); |
| 926 } else { |
| 927 // Link to a legal document (i.e. Terms Of Service, Privacy Policy). |
| 928 views::Link* link = new views::Link(link_parts[i]); |
| 929 link->SetEnabledColor(SkColorSetRGB(0x64, 0x64, 0x64)); |
| 930 link->set_listener(this); |
| 931 footnote_view_->AddLabel(link, true); |
| 932 } |
| 933 } |
| 934 footnote_view_->Layout(); |
| 935 ContentsResized(); |
| 936 } |
| 937 |
| 708 views::View* AutofillDialogViews::CreateDetailsContainer() { | 938 views::View* AutofillDialogViews::CreateDetailsContainer() { |
| 709 views::View* view = new views::View(); | 939 views::View* view = new views::View(); |
| 710 // A box layout is used because it respects widget visibility. | 940 // A box layout is used because it respects widget visibility. |
| 711 view->SetLayoutManager( | 941 view->SetLayoutManager( |
| 712 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | 942 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
| 713 views::kRelatedControlVerticalSpacing)); | 943 views::kRelatedControlVerticalSpacing)); |
| 714 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 944 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
| 715 iter != detail_groups_.end(); ++iter) { | 945 iter != detail_groups_.end(); ++iter) { |
| 716 CreateDetailsSection(iter->second.section); | 946 CreateDetailsSection(iter->second.section); |
| 717 view->AddChildView(iter->second.container); | 947 view->AddChildView(iter->second.container); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 731 inputs_container, | 961 inputs_container, |
| 732 group->suggested_button); | 962 group->suggested_button); |
| 733 UpdateDetailsGroupState(*group); | 963 UpdateDetailsGroupState(*group); |
| 734 } | 964 } |
| 735 | 965 |
| 736 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) { | 966 views::View* AutofillDialogViews::CreateInputsContainer(DialogSection section) { |
| 737 views::View* inputs_container = new views::View(); | 967 views::View* inputs_container = new views::View(); |
| 738 views::GridLayout* layout = new views::GridLayout(inputs_container); | 968 views::GridLayout* layout = new views::GridLayout(inputs_container); |
| 739 inputs_container->SetLayoutManager(layout); | 969 inputs_container->SetLayoutManager(layout); |
| 740 | 970 |
| 741 int kColumnSetId = 0; | 971 const int kColumnSetId = 0; |
| 742 views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); | 972 views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); |
| 743 column_set->AddColumn(views::GridLayout::FILL, | 973 column_set->AddColumn(views::GridLayout::FILL, |
| 744 views::GridLayout::LEADING, | 974 views::GridLayout::LEADING, |
| 745 1, | 975 1, |
| 746 views::GridLayout::USE_PREF, | 976 views::GridLayout::USE_PREF, |
| 747 0, | 977 0, |
| 748 0); | 978 0); |
| 749 column_set->AddColumn(views::GridLayout::CENTER, | 979 column_set->AddColumn(views::GridLayout::CENTER, |
| 750 views::GridLayout::LEADING, | 980 views::GridLayout::LEADING, |
| 751 0, | 981 0, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 group.manual_input->SetVisible(!show_suggestions); | 1115 group.manual_input->SetVisible(!show_suggestions); |
| 886 } | 1116 } |
| 887 | 1117 |
| 888 // Show or hide the "Save in chrome" checkbox. If nothing is in editing mode, | 1118 // Show or hide the "Save in chrome" checkbox. If nothing is in editing mode, |
| 889 // hide. | 1119 // hide. |
| 890 save_in_chrome_checkbox_->SetVisible(AtLeastOneSectionIsEditing()); | 1120 save_in_chrome_checkbox_->SetVisible(AtLeastOneSectionIsEditing()); |
| 891 | 1121 |
| 892 if (group.container) | 1122 if (group.container) |
| 893 group.container->SetForwardMouseEvents(show_suggestions); | 1123 group.container->SetForwardMouseEvents(show_suggestions); |
| 894 | 1124 |
| 895 if (GetWidget()) | 1125 ContentsResized(); |
| 896 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); | |
| 897 } | 1126 } |
| 898 | 1127 |
| 899 bool AutofillDialogViews::AtLeastOneSectionIsEditing() { | 1128 bool AutofillDialogViews::AtLeastOneSectionIsEditing() { |
| 900 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 1129 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
| 901 iter != detail_groups_.end(); ++iter) { | 1130 iter != detail_groups_.end(); ++iter) { |
| 902 if (iter->second.manual_input && iter->second.manual_input->visible()) | 1131 if (iter->second.manual_input && iter->second.manual_input->visible()) |
| 903 return true; | 1132 return true; |
| 904 } | 1133 } |
| 905 | 1134 |
| 906 return false; | 1135 return false; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 decorated = group->suggested_info->decorated_textfield(); | 1203 decorated = group->suggested_info->decorated_textfield(); |
| 975 type = CREDIT_CARD_VERIFICATION_CODE; | 1204 type = CREDIT_CARD_VERIFICATION_CODE; |
| 976 } | 1205 } |
| 977 DCHECK_NE(UNKNOWN_TYPE, type); | 1206 DCHECK_NE(UNKNOWN_TYPE, type); |
| 978 | 1207 |
| 979 // If the field is marked as invalid, check if the text is now valid. | 1208 // If the field is marked as invalid, check if the text is now valid. |
| 980 if (decorated->invalid() && was_edit) | 1209 if (decorated->invalid() && was_edit) |
| 981 decorated->SetInvalid(!controller_->InputIsValid(type, textfield->text())); | 1210 decorated->SetInvalid(!controller_->InputIsValid(type, textfield->text())); |
| 982 } | 1211 } |
| 983 | 1212 |
| 1213 void AutofillDialogViews::ContentsResized() { |
| 1214 if (GetWidget()) |
| 1215 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); |
| 1216 } |
| 1217 |
| 984 AutofillDialogViews::DetailsGroup* AutofillDialogViews::GroupForSection( | 1218 AutofillDialogViews::DetailsGroup* AutofillDialogViews::GroupForSection( |
| 985 DialogSection section) { | 1219 DialogSection section) { |
| 986 return &detail_groups_.find(section)->second; | 1220 return &detail_groups_.find(section)->second; |
| 987 } | 1221 } |
| 988 | 1222 |
| 989 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 1223 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
| 990 : section(section), | 1224 : section(section), |
| 991 container(NULL), | 1225 container(NULL), |
| 992 manual_input(NULL), | 1226 manual_input(NULL), |
| 993 suggested_info(NULL), | 1227 suggested_info(NULL), |
| 994 suggested_button(NULL) {} | 1228 suggested_button(NULL) {} |
| 995 | 1229 |
| 996 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 1230 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
| 997 | 1231 |
| 998 } // namespace autofill | 1232 } // namespace autofill |
| OLD | NEW |