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

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc

Issue 2033713002: Implement the Chrome Sign-in promo bubble for password manager on Views. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix model Created 4 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/passwords/manage_passwords_bubble_view.h" 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 345
346 parent_->set_initially_focused_view(save_button_); 346 parent_->set_initially_focused_view(save_button_);
347 } 347 }
348 348
349 ManagePasswordsBubbleView::PendingView::~PendingView() { 349 ManagePasswordsBubbleView::PendingView::~PendingView() {
350 } 350 }
351 351
352 void ManagePasswordsBubbleView::PendingView::ButtonPressed( 352 void ManagePasswordsBubbleView::PendingView::ButtonPressed(
353 views::Button* sender, 353 views::Button* sender,
354 const ui::Event& event) { 354 const ui::Event& event) {
355 if (sender == save_button_) 355 if (sender == save_button_) {
356 parent_->model()->OnSaveClicked(); 356 parent_->model()->OnSaveClicked();
357 else if (sender == never_button_) 357 if (parent_->model()->ShouldShowSignInPromo()) {
358 parent_->Refresh();
359 return;
360 }
361 } else if (sender == never_button_) {
358 parent_->model()->OnNeverForThisSiteClicked(); 362 parent_->model()->OnNeverForThisSiteClicked();
359 else 363 } else {
360 NOTREACHED(); 364 NOTREACHED();
365 }
361 366
362 parent_->CloseBubble(); 367 parent_->CloseBubble();
363 } 368 }
364 369
365 void ManagePasswordsBubbleView::PendingView::StyledLabelLinkClicked( 370 void ManagePasswordsBubbleView::PendingView::StyledLabelLinkClicked(
366 views::StyledLabel* label, 371 views::StyledLabel* label,
367 const gfx::Range& range, 372 const gfx::Range& range,
368 int event_flags) { 373 int event_flags) {
369 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); 374 DCHECK_EQ(range, parent_->model()->title_brand_link_range());
370 parent_->model()->OnBrandLinkClicked(); 375 parent_->model()->OnBrandLinkClicked();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 parent_->CloseBubble(); 546 parent_->CloseBubble();
542 } 547 }
543 548
544 void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed( 549 void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed(
545 views::Button* sender, const ui::Event& event) { 550 views::Button* sender, const ui::Event& event) {
546 DCHECK_EQ(sender, ok_button_); 551 DCHECK_EQ(sender, ok_button_);
547 parent_->model()->OnOKClicked(); 552 parent_->model()->OnOKClicked();
548 parent_->CloseBubble(); 553 parent_->CloseBubble();
549 } 554 }
550 555
556 // ManagePasswordsBubbleView::SignInPromoView ---------------------------------
557
558 // A view that offers user to sign in to Chrome.
559 class ManagePasswordsBubbleView::SignInPromoView
560 : public views::View,
561 public views::ButtonListener {
562 public:
563 explicit SignInPromoView(ManagePasswordsBubbleView* parent);
564
565 private:
566 // views::ButtonListener:
567 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
568
569 ManagePasswordsBubbleView* parent_;
570
571 views::Button* signin_button_;
572 views::Button* no_button_;
573
574 DISALLOW_COPY_AND_ASSIGN(SignInPromoView);
575 };
576
577 ManagePasswordsBubbleView::SignInPromoView::SignInPromoView(
578 ManagePasswordsBubbleView* parent)
579 : parent_(parent) {
580 views::GridLayout* layout = new views::GridLayout(this);
581 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0));
582 SetLayoutManager(layout);
583
584 // Reuse the string because it has the same meaning.
vabr (Chromium) 2016/06/02 13:10:55 Are you sure the meaning is the same? Here it mean
vasilii 2016/06/02 13:36:18 I split the strings.
585 signin_button_ = views::MdTextButton::CreateSecondaryUiBlueButton(
586 this,
587 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_ACCOUNT_CHOOSER_SIGN_IN));
588 no_button_ = views::MdTextButton::CreateSecondaryUiButton(
589 this,
590 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_NO_THANKS));
591
592 // Button row.
593 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET);
594 layout->StartRow(0, DOUBLE_BUTTON_COLUMN_SET);
595 layout->AddView(signin_button_);
596 layout->AddView(no_button_);
597
598 parent_->set_initially_focused_view(signin_button_);
599 }
600
601 void ManagePasswordsBubbleView::SignInPromoView::ButtonPressed(
602 views::Button* sender,
603 const ui::Event& event) {
604 if (sender == signin_button_)
605 parent_->model()->OnSignInToChromeClicked();
606 else if (sender == no_button_)
607 parent_->model()->OnSkipSignInClicked();
608 else
609 NOTREACHED();
610
611 parent_->CloseBubble();
612 }
613
551 // ManagePasswordsBubbleView::WebContentMouseHandler -------------------------- 614 // ManagePasswordsBubbleView::WebContentMouseHandler --------------------------
552 615
553 // The class listens for WebContentsView events and notifies the bubble if the 616 // The class listens for WebContentsView events and notifies the bubble if the
554 // view was clicked on or received keystrokes. 617 // view was clicked on or received keystrokes.
555 class ManagePasswordsBubbleView::WebContentMouseHandler 618 class ManagePasswordsBubbleView::WebContentMouseHandler
556 : public ui::EventHandler { 619 : public ui::EventHandler {
557 public: 620 public:
558 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble); 621 explicit WebContentMouseHandler(ManagePasswordsBubbleView* bubble);
559 622
560 void OnKeyEvent(ui::KeyEvent* event) override; 623 void OnKeyEvent(ui::KeyEvent* event) override;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { 839 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {
777 if (manage_passwords_bubble_ == this) 840 if (manage_passwords_bubble_ == this)
778 manage_passwords_bubble_ = NULL; 841 manage_passwords_bubble_ = NULL;
779 } 842 }
780 843
781 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { 844 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() {
782 return initially_focused_view_; 845 return initially_focused_view_;
783 } 846 }
784 847
785 void ManagePasswordsBubbleView::Init() { 848 void ManagePasswordsBubbleView::Init() {
786 views::FillLayout* layout = new views::FillLayout(); 849 SetLayoutManager(new views::FillLayout);
787 SetLayoutManager(layout);
788 850
789 Refresh(); 851 CreateChild();
790 } 852 }
791 853
792 void ManagePasswordsBubbleView::CloseBubble() { 854 void ManagePasswordsBubbleView::CloseBubble() {
793 mouse_handler_.reset(); 855 mouse_handler_.reset();
794 LocationBarBubbleDelegateView::CloseBubble(); 856 LocationBarBubbleDelegateView::CloseBubble();
795 } 857 }
796 858
797 base::string16 ManagePasswordsBubbleView::GetWindowTitle() const { 859 base::string16 ManagePasswordsBubbleView::GetWindowTitle() const {
798 return model_.title(); 860 return model_.title();
799 } 861 }
800 862
801 bool ManagePasswordsBubbleView::ShouldShowWindowTitle() const { 863 bool ManagePasswordsBubbleView::ShouldShowWindowTitle() const {
802 // Since bubble titles don't support links, fall back to a custom title view 864 // Since bubble titles don't support links, fall back to a custom title view
803 // if we need to show a link. Only use the normal title path if there's no 865 // if we need to show a link. Only use the normal title path if there's no
804 // link. 866 // link.
805 return model_.title_brand_link_range().is_empty(); 867 return model_.title_brand_link_range().is_empty();
806 } 868 }
807 869
808 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const { 870 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const {
809 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE; 871 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE;
810 } 872 }
811 873
812 void ManagePasswordsBubbleView::Refresh() { 874 void ManagePasswordsBubbleView::Refresh() {
813 RemoveAllChildViews(true); 875 RemoveAllChildViews(true);
814 initially_focused_view_ = NULL; 876 initially_focused_view_ = NULL;
877 CreateChild();
878
879 // Show/hide the close button.
880 GetWidget()->non_client_view()->ResetWindowControls();
881 GetWidget()->UpdateWindowTitle();
882 SizeToContents();
883 }
884
885 void ManagePasswordsBubbleView::CreateChild() {
815 if (model_.state() == password_manager::ui::PENDING_PASSWORD_STATE) { 886 if (model_.state() == password_manager::ui::PENDING_PASSWORD_STATE) {
816 AddChildView(new PendingView(this)); 887 AddChildView(new PendingView(this));
817 } else if (model_.state() == 888 } else if (model_.state() ==
818 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { 889 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) {
819 AddChildView(new UpdatePendingView(this)); 890 AddChildView(new UpdatePendingView(this));
820 } else if (model_.state() == password_manager::ui::CONFIRMATION_STATE) { 891 } else if (model_.state() == password_manager::ui::CONFIRMATION_STATE) {
821 AddChildView(new SaveConfirmationView(this)); 892 AddChildView(new SaveConfirmationView(this));
822 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) { 893 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) {
823 AddChildView(new AutoSigninView(this)); 894 AddChildView(new AutoSigninView(this));
895 } else if (model_.state() ==
896 password_manager::ui::CHROME_SIGN_IN_PROMO_STATE) {
897 AddChildView(new SignInPromoView(this));
824 } else { 898 } else {
825 AddChildView(new ManageView(this)); 899 AddChildView(new ManageView(this));
826 } 900 }
827 if (GetWidget())
828 GetWidget()->UpdateWindowTitle();
829 GetLayoutManager()->Layout(this);
830 } 901 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698