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

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

Issue 2907983002: Allow dialogs to use a custom View as their title. (Closed)
Patch Set: merge Created 3 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/metrics/user_metrics.h" 8 #include "base/metrics/user_metrics.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
(...skipping 20 matching lines...) Expand all
31 #include "ui/base/ui_features.h" 31 #include "ui/base/ui_features.h"
32 #include "ui/gfx/color_palette.h" 32 #include "ui/gfx/color_palette.h"
33 #include "ui/gfx/image/image_skia.h" 33 #include "ui/gfx/image/image_skia.h"
34 #include "ui/native_theme/native_theme.h" 34 #include "ui/native_theme/native_theme.h"
35 #include "ui/views/controls/button/blue_button.h" 35 #include "ui/views/controls/button/blue_button.h"
36 #include "ui/views/controls/button/md_text_button.h" 36 #include "ui/views/controls/button/md_text_button.h"
37 #include "ui/views/controls/link.h" 37 #include "ui/views/controls/link.h"
38 #include "ui/views/controls/link_listener.h" 38 #include "ui/views/controls/link_listener.h"
39 #include "ui/views/controls/separator.h" 39 #include "ui/views/controls/separator.h"
40 #include "ui/views/controls/styled_label.h" 40 #include "ui/views/controls/styled_label.h"
41 #include "ui/views/controls/styled_label_listener.h"
42 #include "ui/views/layout/fill_layout.h" 41 #include "ui/views/layout/fill_layout.h"
43 #include "ui/views/layout/grid_layout.h" 42 #include "ui/views/layout/grid_layout.h"
44 #include "ui/views/widget/widget.h" 43 #include "ui/views/widget/widget.h"
45 44
46 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) 45 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
47 #include "chrome/browser/ui/views/frame/browser_view.h" 46 #include "chrome/browser/ui/views/frame/browser_view.h"
48 #endif 47 #endif
49 48
50 #if defined(OS_WIN) 49 #if defined(OS_WIN)
51 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h" 50 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 break; 162 break;
164 } 163 }
165 } 164 }
166 165
167 views::StyledLabel::RangeStyleInfo GetLinkStyle() { 166 views::StyledLabel::RangeStyleInfo GetLinkStyle() {
168 auto result = views::StyledLabel::RangeStyleInfo::CreateForLink(); 167 auto result = views::StyledLabel::RangeStyleInfo::CreateForLink();
169 result.disable_line_wrapping = false; 168 result.disable_line_wrapping = false;
170 return result; 169 return result;
171 } 170 }
172 171
173 // If a special title is required (i.e. one that contains links), creates a
174 // title view and a row for it in |layout|.
175 // TODO(estade): this should be removed and a replaced by a normal title (via
176 // GetWindowTitle).
177 void AddTitleRowWithLink(views::GridLayout* layout,
178 ManagePasswordsBubbleModel* model,
179 views::StyledLabelListener* listener) {
180 if (model->title_brand_link_range().is_empty())
181 return;
182
183 views::StyledLabel* title_label =
184 new views::StyledLabel(model->title(), listener);
185 title_label->SetBaseFontList(views::style::GetFont(
186 views::style::CONTEXT_DIALOG_TITLE, views::style::STYLE_PRIMARY));
187 title_label->AddStyleRange(model->title_brand_link_range(), GetLinkStyle());
188 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
189 layout->AddView(title_label);
190 layout->AddPaddingRow(0, ChromeLayoutProvider::Get()
191 ->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS)
192 .top());
193 }
194
195 } // namespace 172 } // namespace
196 173
197 // ManagePasswordsBubbleView::AutoSigninView ---------------------------------- 174 // ManagePasswordsBubbleView::AutoSigninView ----------------------------------
198 175
199 // A view containing just one credential that was used for for automatic signing 176 // A view containing just one credential that was used for for automatic signing
200 // in. 177 // in.
201 class ManagePasswordsBubbleView::AutoSigninView 178 class ManagePasswordsBubbleView::AutoSigninView
202 : public views::View, 179 : public views::View,
203 public views::ButtonListener, 180 public views::ButtonListener,
204 public views::WidgetObserver { 181 public views::WidgetObserver {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { 260 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() {
284 parent_->model()->OnAutoSignInToastTimeout(); 261 parent_->model()->OnAutoSignInToastTimeout();
285 parent_->CloseBubble(); 262 parent_->CloseBubble();
286 } 263 }
287 264
288 // ManagePasswordsBubbleView::PendingView ------------------------------------- 265 // ManagePasswordsBubbleView::PendingView -------------------------------------
289 266
290 // A view offering the user the ability to save credentials. Contains a 267 // A view offering the user the ability to save credentials. Contains a
291 // single ManagePasswordItemsView, along with a "Save Passwords" button 268 // single ManagePasswordItemsView, along with a "Save Passwords" button
292 // and a "Never" button. 269 // and a "Never" button.
293 class ManagePasswordsBubbleView::PendingView 270 class ManagePasswordsBubbleView::PendingView : public views::View,
294 : public views::View, 271 public views::ButtonListener {
295 public views::ButtonListener,
296 public views::StyledLabelListener {
297 public: 272 public:
298 explicit PendingView(ManagePasswordsBubbleView* parent); 273 explicit PendingView(ManagePasswordsBubbleView* parent);
299 ~PendingView() override; 274 ~PendingView() override;
300 275
301 private: 276 private:
302 // views::ButtonListener: 277 // views::ButtonListener:
303 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 278 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
304 279
305 // views::StyledLabelListener:
306 void StyledLabelLinkClicked(views::StyledLabel* label,
307 const gfx::Range& range,
308 int event_flags) override;
309
310 ManagePasswordsBubbleView* parent_; 280 ManagePasswordsBubbleView* parent_;
311 281
312 views::Button* save_button_; 282 views::Button* save_button_;
313 views::Button* never_button_; 283 views::Button* never_button_;
314 284
315 DISALLOW_COPY_AND_ASSIGN(PendingView); 285 DISALLOW_COPY_AND_ASSIGN(PendingView);
316 }; 286 };
317 287
318 ManagePasswordsBubbleView::PendingView::PendingView( 288 ManagePasswordsBubbleView::PendingView::PendingView(
319 ManagePasswordsBubbleView* parent) 289 ManagePasswordsBubbleView* parent)
320 : parent_(parent) { 290 : parent_(parent) {
321 views::GridLayout* layout = new views::GridLayout(this); 291 views::GridLayout* layout = new views::GridLayout(this);
322 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); 292 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0));
323 SetLayoutManager(layout); 293 SetLayoutManager(layout);
324 294
325 // Create the pending credential item, save button and refusal combobox. 295 // Create the pending credential item, save button and refusal combobox.
326 ManagePasswordItemsView* item = nullptr; 296 ManagePasswordItemsView* item = nullptr;
327 if (!parent->model()->pending_password().username_value.empty()) { 297 if (!parent->model()->pending_password().username_value.empty()) {
328 item = new ManagePasswordItemsView(parent_->model(), 298 item = new ManagePasswordItemsView(parent_->model(),
329 &parent->model()->pending_password()); 299 &parent->model()->pending_password());
330 } 300 }
331 save_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( 301 save_button_ = views::MdTextButton::CreateSecondaryUiBlueButton(
332 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); 302 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON));
333 never_button_ = views::MdTextButton::CreateSecondaryUiButton( 303 never_button_ = views::MdTextButton::CreateSecondaryUiButton(
334 this, 304 this,
335 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BUBBLE_BLACKLIST_BUTTON)); 305 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BUBBLE_BLACKLIST_BUTTON));
336 306
337 // Title row.
338 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); 307 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET);
339 AddTitleRowWithLink(layout, parent_->model(), this);
340 308
341 // Credential row. 309 // Credential row.
342 if (item) { 310 if (item) {
343 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); 311 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
344 layout->AddView(item); 312 layout->AddView(item);
345 layout->AddPaddingRow(0, 313 layout->AddPaddingRow(0,
346 ChromeLayoutProvider::Get() 314 ChromeLayoutProvider::Get()
347 ->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS) 315 ->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS)
348 .bottom()); 316 .bottom());
349 } 317 }
(...skipping 21 matching lines...) Expand all
371 } 339 }
372 } else if (sender == never_button_) { 340 } else if (sender == never_button_) {
373 parent_->model()->OnNeverForThisSiteClicked(); 341 parent_->model()->OnNeverForThisSiteClicked();
374 } else { 342 } else {
375 NOTREACHED(); 343 NOTREACHED();
376 } 344 }
377 345
378 parent_->CloseBubble(); 346 parent_->CloseBubble();
379 } 347 }
380 348
381 void ManagePasswordsBubbleView::PendingView::StyledLabelLinkClicked(
382 views::StyledLabel* label,
383 const gfx::Range& range,
384 int event_flags) {
385 DCHECK_EQ(range, parent_->model()->title_brand_link_range());
386 parent_->model()->OnBrandLinkClicked();
387 }
388
389 // ManagePasswordsBubbleView::ManageView -------------------------------------- 349 // ManagePasswordsBubbleView::ManageView --------------------------------------
390 350
391 // A view offering the user a list of their currently saved credentials 351 // A view offering the user a list of their currently saved credentials
392 // for the current page, along with a "Manage passwords" link and a 352 // for the current page, along with a "Manage passwords" link and a
393 // "Done" button. 353 // "Done" button.
394 class ManagePasswordsBubbleView::ManageView : public views::View, 354 class ManagePasswordsBubbleView::ManageView : public views::View,
395 public views::ButtonListener, 355 public views::ButtonListener,
396 public views::LinkListener { 356 public views::LinkListener {
397 public: 357 public:
398 explicit ManageView(ManagePasswordsBubbleView* parent); 358 explicit ManageView(ManagePasswordsBubbleView* parent);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 579 }
620 580
621 // ManagePasswordsBubbleView::UpdatePendingView ------------------------------- 581 // ManagePasswordsBubbleView::UpdatePendingView -------------------------------
622 582
623 // A view offering the user the ability to update credentials. Contains a 583 // A view offering the user the ability to update credentials. Contains a
624 // single ManagePasswordItemsView (in case of one credentials) or 584 // single ManagePasswordItemsView (in case of one credentials) or
625 // CredentialsSelectionView otherwise, along with a "Update Passwords" button 585 // CredentialsSelectionView otherwise, along with a "Update Passwords" button
626 // and a rejection button. 586 // and a rejection button.
627 class ManagePasswordsBubbleView::UpdatePendingView 587 class ManagePasswordsBubbleView::UpdatePendingView
628 : public views::View, 588 : public views::View,
629 public views::ButtonListener, 589 public views::ButtonListener {
630 public views::StyledLabelListener {
631 public: 590 public:
632 explicit UpdatePendingView(ManagePasswordsBubbleView* parent); 591 explicit UpdatePendingView(ManagePasswordsBubbleView* parent);
633 ~UpdatePendingView() override; 592 ~UpdatePendingView() override;
634 593
635 private: 594 private:
636 // views::ButtonListener: 595 // views::ButtonListener:
637 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 596 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
638 597
639 // views::StyledLabelListener:
640 void StyledLabelLinkClicked(views::StyledLabel* label,
641 const gfx::Range& range,
642 int event_flags) override;
643
644 ManagePasswordsBubbleView* parent_; 598 ManagePasswordsBubbleView* parent_;
645 599
646 CredentialsSelectionView* selection_view_; 600 CredentialsSelectionView* selection_view_;
647 601
648 views::Button* update_button_; 602 views::Button* update_button_;
649 views::Button* nope_button_; 603 views::Button* nope_button_;
650 604
651 DISALLOW_COPY_AND_ASSIGN(UpdatePendingView); 605 DISALLOW_COPY_AND_ASSIGN(UpdatePendingView);
652 }; 606 };
653 607
(...skipping 13 matching lines...) Expand all
667 } else { 621 } else {
668 item = new ManagePasswordItemsView(parent_->model(), 622 item = new ManagePasswordItemsView(parent_->model(),
669 &parent->model()->pending_password()); 623 &parent->model()->pending_password());
670 } 624 }
671 nope_button_ = views::MdTextButton::CreateSecondaryUiButton( 625 nope_button_ = views::MdTextButton::CreateSecondaryUiButton(
672 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON)); 626 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON));
673 627
674 update_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( 628 update_button_ = views::MdTextButton::CreateSecondaryUiBlueButton(
675 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_UPDATE_BUTTON)); 629 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_UPDATE_BUTTON));
676 630
677 // Title row.
678 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); 631 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET);
679 AddTitleRowWithLink(layout, parent_->model(), this);
680 632
681 // Credential row. 633 // Credential row.
682 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); 634 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
683 layout->AddView(item); 635 layout->AddView(item);
684 layout->AddPaddingRow( 636 layout->AddPaddingRow(
685 0, 637 0,
686 layout_provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS).bottom()); 638 layout_provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS).bottom());
687 639
688 // Button row. 640 // Button row.
689 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); 641 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET);
(...skipping 19 matching lines...) Expand all
709 *selection_view_->GetSelectedCredentials()); 661 *selection_view_->GetSelectedCredentials());
710 } else { 662 } else {
711 parent_->model()->OnUpdateClicked(parent_->model()->pending_password()); 663 parent_->model()->OnUpdateClicked(parent_->model()->pending_password());
712 } 664 }
713 } else { 665 } else {
714 parent_->model()->OnNopeUpdateClicked(); 666 parent_->model()->OnNopeUpdateClicked();
715 } 667 }
716 parent_->CloseBubble(); 668 parent_->CloseBubble();
717 } 669 }
718 670
719 void ManagePasswordsBubbleView::UpdatePendingView::StyledLabelLinkClicked(
720 views::StyledLabel* label,
721 const gfx::Range& range,
722 int event_flags) {
723 DCHECK_EQ(range, parent_->model()->title_brand_link_range());
724 parent_->model()->OnBrandLinkClicked();
725 }
726
727 // ManagePasswordsBubbleView -------------------------------------------------- 671 // ManagePasswordsBubbleView --------------------------------------------------
728 672
729 // static 673 // static
730 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 674 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
731 NULL; 675 NULL;
732 676
733 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) 677 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
734 // static 678 // static
735 void ManagePasswordsBubbleView::ShowBubble( 679 void ManagePasswordsBubbleView::ShowBubble(
736 content::WebContents* web_contents, 680 content::WebContents* web_contents,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 774
831 void ManagePasswordsBubbleView::CloseBubble() { 775 void ManagePasswordsBubbleView::CloseBubble() {
832 mouse_handler_.reset(); 776 mouse_handler_.reset();
833 LocationBarBubbleDelegateView::CloseBubble(); 777 LocationBarBubbleDelegateView::CloseBubble();
834 } 778 }
835 779
836 base::string16 ManagePasswordsBubbleView::GetWindowTitle() const { 780 base::string16 ManagePasswordsBubbleView::GetWindowTitle() const {
837 return model_.title(); 781 return model_.title();
838 } 782 }
839 783
784 views::StyledLabel* ManagePasswordsBubbleView::CreateTitleView() {
785 views::StyledLabel* title_label =
786 new views::StyledLabel(model_.title(), this);
787 if (!model_.title_brand_link_range().is_empty())
788 title_label->AddStyleRange(model_.title_brand_link_range(), GetLinkStyle());
789 return title_label;
790 }
791
840 gfx::ImageSkia ManagePasswordsBubbleView::GetWindowIcon() { 792 gfx::ImageSkia ManagePasswordsBubbleView::GetWindowIcon() {
841 #if defined(OS_WIN) 793 #if defined(OS_WIN)
842 if (model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { 794 if (model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) {
843 return desktop_ios_promotion::GetPromoImage( 795 return desktop_ios_promotion::GetPromoImage(
844 GetNativeTheme()->GetSystemColor( 796 GetNativeTheme()->GetSystemColor(
845 ui::NativeTheme::kColorId_TextfieldDefaultColor)); 797 ui::NativeTheme::kColorId_TextfieldDefaultColor));
846 } 798 }
847 #endif 799 #endif
848 return gfx::ImageSkia(); 800 return gfx::ImageSkia();
849 } 801 }
850 802
851 bool ManagePasswordsBubbleView::ShouldShowWindowTitle() const {
852 // Since bubble titles don't support links, fall back to a custom title view
853 // if we need to show a link. Only use the normal title path if there's no
854 // link.
855 return model_.title_brand_link_range().is_empty();
856 }
857
858 bool ManagePasswordsBubbleView::ShouldShowWindowIcon() const { 803 bool ManagePasswordsBubbleView::ShouldShowWindowIcon() const {
859 return model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE; 804 return model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE;
860 } 805 }
861 806
862 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const { 807 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const {
863 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE || 808 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE ||
864 model_.state() == password_manager::ui::CHROME_SIGN_IN_PROMO_STATE || 809 model_.state() == password_manager::ui::CHROME_SIGN_IN_PROMO_STATE ||
865 model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE; 810 model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE;
866 } 811 }
867 812
813 void ManagePasswordsBubbleView::StyledLabelLinkClicked(
814 views::StyledLabel* label,
815 const gfx::Range& range,
816 int event_flags) {
817 DCHECK_EQ(range, model_.title_brand_link_range());
818 model_.OnBrandLinkClicked();
819 }
820
868 void ManagePasswordsBubbleView::Refresh() { 821 void ManagePasswordsBubbleView::Refresh() {
869 RemoveAllChildViews(true); 822 RemoveAllChildViews(true);
870 initially_focused_view_ = NULL; 823 initially_focused_view_ = NULL;
871 CreateChild(); 824 CreateChild();
872 // Show/hide the close button. 825 // Show/hide the close button.
873 GetWidget()->non_client_view()->ResetWindowControls(); 826 GetWidget()->non_client_view()->ResetWindowControls();
874 GetWidget()->UpdateWindowIcon(); 827 GetWidget()->UpdateWindowIcon();
875 GetWidget()->UpdateWindowTitle(); 828 GetWidget()->UpdateWindowTitle();
876 if (model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { 829 if (model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) {
877 // Update the height and keep the existing width. 830 // Update the height and keep the existing width.
(...skipping 23 matching lines...) Expand all
901 } else if (model_.state() == 854 } else if (model_.state() ==
902 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { 855 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) {
903 AddChildView(new DesktopIOSPromotionBubbleView( 856 AddChildView(new DesktopIOSPromotionBubbleView(
904 model_.GetProfile(), 857 model_.GetProfile(),
905 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); 858 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE));
906 #endif 859 #endif
907 } else { 860 } else {
908 AddChildView(new ManageView(this)); 861 AddChildView(new ManageView(this));
909 } 862 }
910 } 863 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698