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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 1344443002: Implement new password separated sign in flow for chrome desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "ui/views/controls/button/image_button.h" 60 #include "ui/views/controls/button/image_button.h"
61 #include "ui/views/controls/button/label_button.h" 61 #include "ui/views/controls/button/label_button.h"
62 #include "ui/views/controls/button/label_button_border.h" 62 #include "ui/views/controls/button/label_button_border.h"
63 #include "ui/views/controls/button/menu_button.h" 63 #include "ui/views/controls/button/menu_button.h"
64 #include "ui/views/controls/label.h" 64 #include "ui/views/controls/label.h"
65 #include "ui/views/controls/link.h" 65 #include "ui/views/controls/link.h"
66 #include "ui/views/controls/separator.h" 66 #include "ui/views/controls/separator.h"
67 #include "ui/views/controls/styled_label.h" 67 #include "ui/views/controls/styled_label.h"
68 #include "ui/views/controls/textfield/textfield.h" 68 #include "ui/views/controls/textfield/textfield.h"
69 #include "ui/views/controls/webview/webview.h" 69 #include "ui/views/controls/webview/webview.h"
70 #include "ui/views/layout/fill_layout.h"
70 #include "ui/views/layout/grid_layout.h" 71 #include "ui/views/layout/grid_layout.h"
71 #include "ui/views/layout/layout_constants.h" 72 #include "ui/views/layout/layout_constants.h"
72 #include "ui/views/widget/widget.h" 73 #include "ui/views/widget/widget.h"
73 74
74 namespace { 75 namespace {
75 76
76 // Helpers -------------------------------------------------------------------- 77 // Helpers --------------------------------------------------------------------
77 78
78 const int kFixedMenuWidth = 250; 79 const int kFixedMenuWidth = 250;
79 const int kButtonHeight = 32; 80 const int kButtonHeight = 32;
80 const int kFixedGaiaViewHeight = 440; 81 const int kOldFixedGaiaViewHeight = 440;
81 const int kFixedGaiaViewWidth = 360; 82 const int kOldFixedGaiaViewWidth = 360;
83 const int kFixedGaiaViewHeight = 512;
84 const int kFixedGaiaViewWidth = 448;
82 const int kFixedAccountRemovalViewWidth = 280; 85 const int kFixedAccountRemovalViewWidth = 280;
83 const int kFixedSwitchUserViewWidth = 320; 86 const int kFixedSwitchUserViewWidth = 320;
84 const int kLargeImageSide = 88; 87 const int kLargeImageSide = 88;
85 88
86 const int kVerticalSpacing = 16; 89 const int kVerticalSpacing = 16;
87 90
91 const int kTitleViewNativeWidgetOffset = 8;
92
88 bool IsProfileChooser(profiles::BubbleViewMode mode) { 93 bool IsProfileChooser(profiles::BubbleViewMode mode) {
89 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || 94 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ||
90 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 95 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
91 } 96 }
92 97
93 // Creates a GridLayout with a single column. This ensures that all the child 98 // Creates a GridLayout with a single column. This ensures that all the child
94 // views added get auto-expanded to fill the full width of the bubble. 99 // views added get auto-expanded to fill the full width of the bubble.
95 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { 100 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) {
96 views::GridLayout* layout = new views::GridLayout(view); 101 views::GridLayout* layout = new views::GridLayout(view);
97 view->SetLayoutManager(layout); 102 view->SetLayoutManager(layout);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 public: 179 public:
175 explicit SizedContainer(const gfx::Size& preferred_size) 180 explicit SizedContainer(const gfx::Size& preferred_size)
176 : preferred_size_(preferred_size) {} 181 : preferred_size_(preferred_size) {}
177 182
178 gfx::Size GetPreferredSize() const override { return preferred_size_; } 183 gfx::Size GetPreferredSize() const override { return preferred_size_; }
179 184
180 private: 185 private:
181 gfx::Size preferred_size_; 186 gfx::Size preferred_size_;
182 }; 187 };
183 188
189 // A view to host the GAIA webview overlapped with a back button. This class
190 // is needed to reparent the back button inside a native view so that on
191 // windows, user input can be be properly routed to the button.
192 class HostView : public views::View {
193 public:
194 HostView() : title_view_(nullptr), title_widget_(nullptr) {}
195 ~HostView() override;
196
197 void Initialize(views::View* title_view, views::View* main_view);
198
199 private:
200 // views::View:
201 void ViewHierarchyChanged(
202 const ViewHierarchyChangedDetails& details) override;
203
204 // The title itself and the overlaped widget that contains it.
205 views::View* title_view_;
206 scoped_ptr<views::Widget> title_widget_;
207
208 DISALLOW_COPY_AND_ASSIGN(HostView);
209 };
210
211 HostView::~HostView() {}
212
213 void HostView::Initialize(views::View* title_view, views::View* main_view) {
214 title_view_ = title_view;
215 title_view_->set_owned_by_client();
216 AddChildView(main_view);
217 SetLayoutManager(new views::FillLayout());
218 }
219
220 void HostView::ViewHierarchyChanged(
221 const ViewHierarchyChangedDetails& details) {
222 if (!details.is_add || details.child != this)
223 return;
224
225 if (title_widget_ != nullptr)
226 return;
227
228 // The title view must be placed within its own widget so that it can
229 // properly receive user input when overlapped on another view.
230 views::Widget::InitParams params(
231 views::Widget::InitParams::TYPE_CONTROL);
232 params.parent = GetWidget()->GetNativeView();
233 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
234 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
235 title_widget_.reset(new views::Widget);
236 title_widget_->Init(params);
237 title_widget_->SetContentsView(title_view_);
238
239 gfx::Rect bounds(title_view_->GetPreferredSize());
240 title_view_->SetBoundsRect(bounds);
241 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset);
242 title_widget_->SetBounds(bounds);
243 }
244
184 } // namespace 245 } // namespace
185 246
186 // RightAlignedIconLabelButton ------------------------------------------------- 247 // RightAlignedIconLabelButton -------------------------------------------------
187 248
188 // A custom LabelButton that has a centered text and right aligned icon. 249 // A custom LabelButton that has a centered text and right aligned icon.
189 class RightAlignedIconLabelButton : public views::LabelButton { 250 class RightAlignedIconLabelButton : public views::LabelButton {
190 public: 251 public:
191 RightAlignedIconLabelButton(views::ButtonListener* listener, 252 RightAlignedIconLabelButton(views::ButtonListener* listener,
192 const base::string16& text) 253 const base::string16& text)
193 : views::LabelButton(listener, text) { 254 : views::LabelButton(listener, text) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 views::Textfield* profile_name_textfield_; 454 views::Textfield* profile_name_textfield_;
394 455
395 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); 456 DISALLOW_COPY_AND_ASSIGN(EditableProfileName);
396 }; 457 };
397 458
398 // A title card with one back button right aligned and one label center aligned. 459 // A title card with one back button right aligned and one label center aligned.
399 class TitleCard : public views::View { 460 class TitleCard : public views::View {
400 public: 461 public:
401 TitleCard(const base::string16& message, views::ButtonListener* listener, 462 TitleCard(const base::string16& message, views::ButtonListener* listener,
402 views::ImageButton** back_button) { 463 views::ImageButton** back_button) {
403 back_button_ = new views::ImageButton(listener); 464 back_button_ = CreateBackButton(listener);
404 back_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
405 views::ImageButton::ALIGN_MIDDLE);
406 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
407 back_button_->SetImage(views::ImageButton::STATE_NORMAL,
408 rb->GetImageSkiaNamed(IDR_BACK));
409 back_button_->SetImage(views::ImageButton::STATE_HOVERED,
410 rb->GetImageSkiaNamed(IDR_BACK_H));
411 back_button_->SetImage(views::ImageButton::STATE_PRESSED,
412 rb->GetImageSkiaNamed(IDR_BACK_P));
413 back_button_->SetImage(views::ImageButton::STATE_DISABLED,
414 rb->GetImageSkiaNamed(IDR_BACK_D));
415 back_button_->SetFocusable(true);
416 *back_button = back_button_; 465 *back_button = back_button_;
417 466
418 title_label_ = new views::Label(message); 467 title_label_ = new views::Label(message);
419 title_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 468 title_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
469 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
420 const gfx::FontList& medium_font_list = 470 const gfx::FontList& medium_font_list =
421 rb->GetFontList(ui::ResourceBundle::MediumFont); 471 rb->GetFontList(ui::ResourceBundle::MediumFont);
422 title_label_->SetFontList(medium_font_list); 472 title_label_->SetFontList(medium_font_list);
423 473
424 AddChildView(back_button_); 474 AddChildView(back_button_);
425 AddChildView(title_label_); 475 AddChildView(title_label_);
426 } 476 }
427 477
478 static views::ImageButton* CreateBackButton(views::ButtonListener* listener) {
479 views::ImageButton* back_button = new views::ImageButton(listener);
480 back_button->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
481 views::ImageButton::ALIGN_MIDDLE);
482 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
483 back_button->SetImage(views::ImageButton::STATE_NORMAL,
484 rb->GetImageSkiaNamed(IDR_BACK));
485 back_button->SetImage(views::ImageButton::STATE_HOVERED,
486 rb->GetImageSkiaNamed(IDR_BACK_H));
487 back_button->SetImage(views::ImageButton::STATE_PRESSED,
488 rb->GetImageSkiaNamed(IDR_BACK_P));
489 back_button->SetImage(views::ImageButton::STATE_DISABLED,
490 rb->GetImageSkiaNamed(IDR_BACK_D));
491 back_button->SetFocusable(true);
492 return back_button;
493 }
494
428 // Creates a new view that has the |title_card| with horizontal padding at the 495 // Creates a new view that has the |title_card| with horizontal padding at the
429 // top, an edge-to-edge separator below, and the specified |view| at the 496 // top, an edge-to-edge separator below, and the specified |view| at the
430 // bottom. 497 // bottom.
431 static views::View* AddPaddedTitleCard(views::View* view, 498 static views::View* AddPaddedTitleCard(views::View* view,
432 TitleCard* title_card, 499 TitleCard* title_card,
433 int width) { 500 int width) {
434 views::View* titled_view = new views::View(); 501 views::View* titled_view = new views::View();
435 views::GridLayout* layout = new views::GridLayout(titled_view); 502 views::GridLayout* layout = new views::GridLayout(titled_view);
436 titled_view->SetLayoutManager(layout); 503 titled_view->SetLayoutManager(layout);
437 504
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 ResetView(); 783 ResetView();
717 RemoveAllChildViews(true); 784 RemoveAllChildViews(true);
718 view_mode_ = view_to_display; 785 view_mode_ = view_to_display;
719 786
720 views::GridLayout* layout = nullptr; 787 views::GridLayout* layout = nullptr;
721 views::View* sub_view = nullptr; 788 views::View* sub_view = nullptr;
722 views::View* view_to_focus = nullptr; 789 views::View* view_to_focus = nullptr;
723 switch (view_mode_) { 790 switch (view_mode_) {
724 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: 791 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN:
725 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: 792 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT:
726 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: 793 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: {
727 layout = CreateSingleColumnLayout(this, kFixedGaiaViewWidth); 794 int width = switches::UseNewGaiaFlow()
795 ? kFixedGaiaViewWidth : kOldFixedGaiaViewWidth;
796 layout = CreateSingleColumnLayout(this, width);
728 sub_view = CreateGaiaSigninView(&view_to_focus); 797 sub_view = CreateGaiaSigninView(&view_to_focus);
729 break; 798 break;
799 }
730 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL: 800 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL:
731 layout = CreateSingleColumnLayout(this, kFixedAccountRemovalViewWidth); 801 layout = CreateSingleColumnLayout(this, kFixedAccountRemovalViewWidth);
732 sub_view = CreateAccountRemovalView(); 802 sub_view = CreateAccountRemovalView();
733 break; 803 break;
734 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: 804 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER:
735 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); 805 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth);
736 sub_view = CreateSwitchUserView(); 806 sub_view = CreateSwitchUserView();
737 ProfileMetrics::LogProfileNewAvatarMenuNotYou( 807 ProfileMetrics::LogProfileNewAvatarMenuNotYou(
738 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW); 808 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW);
739 break; 809 break;
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 url = signin::GetReauthURL(browser_->profile(), 1647 url = signin::GetReauthURL(browser_->profile(),
1578 GetAuthErrorAccountId(browser_->profile())); 1648 GetAuthErrorAccountId(browser_->profile()));
1579 message_id = IDS_PROFILES_GAIA_REAUTH_TITLE; 1649 message_id = IDS_PROFILES_GAIA_REAUTH_TITLE;
1580 break; 1650 break;
1581 } 1651 }
1582 default: 1652 default:
1583 NOTREACHED() << "Called with invalid mode=" << view_mode_; 1653 NOTREACHED() << "Called with invalid mode=" << view_mode_;
1584 return NULL; 1654 return NULL;
1585 } 1655 }
1586 1656
1587 // Adds Gaia signin webview 1657 // Adds Gaia signin webview.
1658 gfx::Size pref_size = switches::UseNewGaiaFlow()
anthonyvd 2015/09/15 18:13:47 Maybe move this before the switch and use pref_siz
Roger Tawa OOO till Jul 10th 2015/09/16 19:27:29 Line 796 is in another function. Maybe I'm missin
anthonyvd 2015/09/16 19:55:32 That's entirely my bad, the lines in between were
1659 ? gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight)
1660 : gfx::Size(kOldFixedGaiaViewWidth, kOldFixedGaiaViewHeight);
1588 Profile* profile = browser_->profile(); 1661 Profile* profile = browser_->profile();
1589 views::WebView* web_view = new views::WebView(profile); 1662 views::WebView* web_view = new views::WebView(profile);
1590 web_view->LoadInitialURL(url); 1663 web_view->LoadInitialURL(url);
1591 web_view->GetWebContents()->SetDelegate(this); 1664 web_view->GetWebContents()->SetDelegate(this);
1592 web_view->SetPreferredSize( 1665 web_view->SetPreferredSize(pref_size);
1593 gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight));
1594 content::RenderWidgetHostView* rwhv = 1666 content::RenderWidgetHostView* rwhv =
1595 web_view->GetWebContents()->GetRenderWidgetHostView(); 1667 web_view->GetWebContents()->GetRenderWidgetHostView();
1596 if (rwhv) 1668 if (rwhv)
1597 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); 1669 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor);
1670
1671 if (signin_content_view)
1672 *signin_content_view = web_view;
1673
1674 if (switches::UseNewGaiaFlow()) {
1675 gaia_signin_cancel_button_ = TitleCard::CreateBackButton(this);
1676 HostView* host = new HostView();
1677 host->Initialize(gaia_signin_cancel_button_, web_view);
1678 return host;
1679 }
1680
1598 TitleCard* title_card = new TitleCard(l10n_util::GetStringUTF16(message_id), 1681 TitleCard* title_card = new TitleCard(l10n_util::GetStringUTF16(message_id),
1599 this, 1682 this,
1600 &gaia_signin_cancel_button_); 1683 &gaia_signin_cancel_button_);
1601 if (signin_content_view)
1602 *signin_content_view = web_view;
1603 return TitleCard::AddPaddedTitleCard( 1684 return TitleCard::AddPaddedTitleCard(
1604 web_view, title_card, kFixedGaiaViewWidth); 1685 web_view, title_card, kOldFixedGaiaViewWidth);
1605 } 1686 }
1606 1687
1607 views::View* ProfileChooserView::CreateAccountRemovalView() { 1688 views::View* ProfileChooserView::CreateAccountRemovalView() {
1608 views::View* view = new views::View(); 1689 views::View* view = new views::View();
1609 views::GridLayout* layout = CreateSingleColumnLayout( 1690 views::GridLayout* layout = CreateSingleColumnLayout(
1610 view, kFixedAccountRemovalViewWidth - 2 * views::kButtonHEdgeMarginNew); 1691 view, kFixedAccountRemovalViewWidth - 2 * views::kButtonHEdgeMarginNew);
1611 layout->SetInsets(0, 1692 layout->SetInsets(0,
1612 views::kButtonHEdgeMarginNew, 1693 views::kButtonHEdgeMarginNew,
1613 views::kButtonVEdgeMarginNew, 1694 views::kButtonVEdgeMarginNew,
1614 views::kButtonHEdgeMarginNew); 1695 views::kButtonHEdgeMarginNew);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1884 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1804 IncognitoModePrefs::DISABLED; 1885 IncognitoModePrefs::DISABLED;
1805 return incognito_available && !browser_->profile()->IsGuestSession(); 1886 return incognito_available && !browser_->profile()->IsGuestSession();
1806 } 1887 }
1807 1888
1808 void ProfileChooserView::PostActionPerformed( 1889 void ProfileChooserView::PostActionPerformed(
1809 ProfileMetrics::ProfileDesktopMenu action_performed) { 1890 ProfileMetrics::ProfileDesktopMenu action_performed) {
1810 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1891 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1811 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1892 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1812 } 1893 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698