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

Side by Side Diff: chrome/browser/ui/views/frame/avatar_button_manager.cc

Issue 2832823002: Update avatar button to MD (Closed)
Patch Set: Rebased on CL 2833363002 Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/frame/avatar_button_manager.h" 5 #include "chrome/browser/ui/views/frame/avatar_button_manager.h"
6 6
7 #include "base/win/windows_version.h"
Peter Kasting 2017/04/26 02:09:53 Guard this with an #if OS_WIN block.
emx 2017/04/27 16:30:58 Done.
7 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/themes/theme_service.h"
11 #include "chrome/browser/themes/theme_service_factory.h"
9 #include "chrome/browser/ui/view_ids.h" 12 #include "chrome/browser/ui/view_ids.h"
10 #include "chrome/browser/ui/views/frame/browser_frame.h" 13 #include "chrome/browser/ui/views/frame/browser_frame.h"
11 #include "chrome/browser/ui/views/frame/browser_view.h" 14 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" 15 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
13 16
14 AvatarButtonManager::AvatarButtonManager(BrowserNonClientFrameView* frame_view) 17 AvatarButtonManager::AvatarButtonManager(BrowserNonClientFrameView* frame_view)
15 : frame_view_(frame_view), view_(nullptr) {} 18 : frame_view_(frame_view), button_(nullptr) {}
16 19
17 void AvatarButtonManager::Update(AvatarButtonStyle style) { 20 void AvatarButtonManager::Update(AvatarButtonStyle style) {
18 BrowserView* browser_view = frame_view_->browser_view(); 21 BrowserView* browser_view = frame_view_->browser_view();
19 BrowserFrame* frame = frame_view_->frame(); 22 BrowserFrame* frame = frame_view_->frame();
20 Profile* profile = browser_view->browser()->profile(); 23 Profile* profile = browser_view->browser()->profile();
21 24
22 // This should never be called in incognito mode. 25 // This should never be called in incognito mode.
23 DCHECK(browser_view->IsRegularOrGuestSession()); 26 DCHECK(browser_view->IsRegularOrGuestSession());
24 ProfileAttributesEntry* unused; 27 ProfileAttributesEntry* unused;
25 if ((browser_view->IsBrowserTypeNormal() && 28 if ((browser_view->IsBrowserTypeNormal() &&
26 // Tests may not have a profile manager. 29 // Tests may not have a profile manager.
27 g_browser_process->profile_manager() && 30 g_browser_process->profile_manager() &&
28 g_browser_process->profile_manager() 31 g_browser_process->profile_manager()
29 ->GetProfileAttributesStorage() 32 ->GetProfileAttributesStorage()
30 .GetProfileAttributesWithPath(profile->GetPath(), &unused)) || 33 .GetProfileAttributesWithPath(profile->GetPath(), &unused)) ||
31 // Desktop guest shows the avatar button. 34 // Desktop guest shows the avatar button.
32 browser_view->IsIncognito()) { 35 browser_view->IsIncognito()) {
33 if (!view_) { 36 if (!button_) {
34 view_ = new NewAvatarButton(this, style, profile); 37 #if defined(OS_WIN)
35 view_->set_id(VIEW_ID_AVATAR_BUTTON); 38 if ((base::win::GetVersion() >= base::win::VERSION_WIN10) &&
36 frame_view_->AddChildView(view_); 39 ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
Peter Kasting 2017/04/26 02:09:53 Nit: TODO about expanding this beyond Win 10 and s
emx 2017/04/27 16:30:58 Done.
40 DCHECK_EQ(AvatarButtonStyle::NATIVE, style);
41 button_ = new MaterialDesignAvatarButton(this, profile, browser_view);
42 } else {
43 button_ = new NewAvatarButton(this, style, profile);
44 }
45 #else
46 button_ = new NewAvatarButton(this, style, profile);
47 #endif // defined(OS_WIN)
48
49 button_->set_id(VIEW_ID_AVATAR_BUTTON);
50 frame_view_->AddChildView(button_);
37 frame->GetRootView()->Layout(); 51 frame->GetRootView()->Layout();
38 } 52 }
39 } else if (view_) { 53 } else if (button_) {
40 delete view_; 54 delete button_;
41 view_ = nullptr; 55 button_ = nullptr;
42 frame->GetRootView()->Layout(); 56 frame->GetRootView()->Layout();
43 } 57 }
44 } 58 }
45 59
46 void AvatarButtonManager::ButtonPreferredSizeChanged() { 60 void AvatarButtonManager::ButtonPreferredSizeChanged() {
47 // Perform a re-layout if the avatar button has changed, since that can affect 61 // Perform a re-layout if the avatar button has changed, since that can affect
48 // the size of the tabs. 62 // the size of the tabs.
49 if (!view_ || !frame_view_->browser_view()->initialized()) 63 if (!button_ || !frame_view_->browser_view()->initialized())
50 return; // Ignore the update during view creation. 64 return; // Ignore the update during view creation.
51 65
52 frame_view_->InvalidateLayout(); 66 frame_view_->InvalidateLayout();
53 frame_view_->frame()->GetRootView()->Layout(); 67 frame_view_->frame()->GetRootView()->Layout();
54 } 68 }
55 69
56 void AvatarButtonManager::ButtonPressed(views::Button* sender, 70 void AvatarButtonManager::OnMenuButtonClicked(views::MenuButton* source,
57 const ui::Event& event) { 71 const gfx::Point& point,
58 DCHECK_EQ(view_, sender); 72 const ui::Event* event) {
73 DCHECK_EQ(button_, source);
59 BrowserWindow::AvatarBubbleMode mode = 74 BrowserWindow::AvatarBubbleMode mode =
60 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT; 75 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT;
61 if ((event.IsMouseEvent() && 76
62 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) || 77 if (event && event->type() == ui::ET_GESTURE_LONG_PRESS)
Peter Kasting 2017/04/26 02:09:53 This looks like we're showing the dropdown on righ
emx 2017/04/27 16:30:58 We're not - OnMenuButtonClicked is simply not call
63 (event.type() == ui::ET_GESTURE_LONG_PRESS)) {
64 return; 78 return;
65 } 79
66 frame_view_->browser_view()->ShowAvatarBubbleFromAvatarButton( 80 frame_view_->browser_view()->ShowAvatarBubbleFromAvatarButton(
67 mode, signin::ManageAccountsParams(), 81 mode, signin::ManageAccountsParams(),
68 signin_metrics::AccessPoint::ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN, false); 82 signin_metrics::AccessPoint::ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN, false);
83 ProfileChooserView::MakeCallingButtonPressedIfShowing(event);
69 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698