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

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

Issue 2851543002: Update avatar button to MD (part 1) (Closed)
Patch Set: Renamed NewAvatarButton->ThemedAvatarButton and MaterialDesignAvatarButton->Win10NativeAvatarButton… Created 3 years, 7 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 "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/profiles/profile_manager.h" 8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/themes/theme_service.h"
10 #include "chrome/browser/themes/theme_service_factory.h"
9 #include "chrome/browser/ui/view_ids.h" 11 #include "chrome/browser/ui/view_ids.h"
10 #include "chrome/browser/ui/views/frame/browser_frame.h" 12 #include "chrome/browser/ui/views/frame/browser_frame.h"
11 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" 14 #include "chrome/browser/ui/views/profiles/avatar_button.h"
15 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
16 #include "chrome/browser/ui/views/profiles/themed_avatar_button.h"
17 #include "chrome/browser/ui/views/profiles/win10_native_avatar_button.h"
Evan Stade 2017/04/28 18:38:29 nit: only include on windows.
emx 2017/05/02 15:17:11 Done.
18
19 #if defined(OS_WIN)
20 #include "base/win/windows_version.h"
21 #endif
13 22
14 AvatarButtonManager::AvatarButtonManager(BrowserNonClientFrameView* frame_view) 23 AvatarButtonManager::AvatarButtonManager(BrowserNonClientFrameView* frame_view)
15 : frame_view_(frame_view), view_(nullptr) {} 24 : frame_view_(frame_view), button_(nullptr) {}
16 25
17 void AvatarButtonManager::Update(AvatarButtonStyle style) { 26 void AvatarButtonManager::Update(AvatarButtonStyle style) {
18 BrowserView* browser_view = frame_view_->browser_view(); 27 BrowserView* browser_view = frame_view_->browser_view();
19 BrowserFrame* frame = frame_view_->frame(); 28 BrowserFrame* frame = frame_view_->frame();
20 Profile* profile = browser_view->browser()->profile(); 29 Profile* profile = browser_view->browser()->profile();
21 30
22 // This should never be called in incognito mode. 31 // This should never be called in incognito mode.
23 DCHECK(browser_view->IsRegularOrGuestSession()); 32 DCHECK(browser_view->IsRegularOrGuestSession());
24 ProfileAttributesEntry* unused; 33 ProfileAttributesEntry* unused;
25 if ((browser_view->IsBrowserTypeNormal() && 34 if ((browser_view->IsBrowserTypeNormal() &&
26 // Tests may not have a profile manager. 35 // Tests may not have a profile manager.
27 g_browser_process->profile_manager() && 36 g_browser_process->profile_manager() &&
28 g_browser_process->profile_manager() 37 g_browser_process->profile_manager()
29 ->GetProfileAttributesStorage() 38 ->GetProfileAttributesStorage()
30 .GetProfileAttributesWithPath(profile->GetPath(), &unused)) || 39 .GetProfileAttributesWithPath(profile->GetPath(), &unused)) ||
31 // Desktop guest shows the avatar button. 40 // Desktop guest shows the avatar button.
32 browser_view->IsIncognito()) { 41 browser_view->IsIncognito()) {
33 if (!view_) { 42 if (!button_) {
34 view_ = new NewAvatarButton(this, style, profile); 43 #if defined(OS_WIN)
35 view_->set_id(VIEW_ID_AVATAR_BUTTON); 44 // TODO: use MD button in other cases, too [http://crbug.com/591586]
36 frame_view_->AddChildView(view_); 45 if ((base::win::GetVersion() >= base::win::VERSION_WIN10) &&
46 ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) {
47 DCHECK_EQ(AvatarButtonStyle::NATIVE, style);
48 button_ = new Win10NativeAvatarButton(this, profile, browser_view);
49 } else {
50 button_ = new ThemedAvatarButton(this, style, profile);
51 }
52 #else
53 button_ = new ThemedAvatarButton(this, style, profile);
54 #endif // defined(OS_WIN)
55
56 button_->set_id(VIEW_ID_AVATAR_BUTTON);
57 frame_view_->AddChildView(button_);
37 frame->GetRootView()->Layout(); 58 frame->GetRootView()->Layout();
38 } 59 }
39 } else if (view_) { 60 } else if (button_) {
40 delete view_; 61 delete button_;
41 view_ = nullptr; 62 button_ = nullptr;
42 frame->GetRootView()->Layout(); 63 frame->GetRootView()->Layout();
43 } 64 }
44 } 65 }
45 66
46 void AvatarButtonManager::ButtonPreferredSizeChanged() { 67 void AvatarButtonManager::OnMenuButtonClicked(views::MenuButton* source,
47 // Perform a re-layout if the avatar button has changed, since that can affect 68 const gfx::Point& point,
48 // the size of the tabs. 69 const ui::Event* event) {
49 if (!view_ || !frame_view_->browser_view()->initialized()) 70 DCHECK_EQ(button_, source);
50 return; // Ignore the update during view creation.
51
52 frame_view_->InvalidateLayout();
53 frame_view_->frame()->GetRootView()->Layout();
54 }
55
56 void AvatarButtonManager::ButtonPressed(views::Button* sender,
57 const ui::Event& event) {
58 DCHECK_EQ(view_, sender);
59 BrowserWindow::AvatarBubbleMode mode = 71 BrowserWindow::AvatarBubbleMode mode =
60 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT; 72 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT;
61 if ((event.IsMouseEvent() && 73
62 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) || 74 if (event && event->type() == ui::ET_GESTURE_LONG_PRESS)
63 (event.type() == ui::ET_GESTURE_LONG_PRESS)) {
64 return; 75 return;
65 } 76
66 frame_view_->browser_view()->ShowAvatarBubbleFromAvatarButton( 77 frame_view_->browser_view()->ShowAvatarBubbleFromAvatarButton(
67 mode, signin::ManageAccountsParams(), 78 mode, signin::ManageAccountsParams(),
68 signin_metrics::AccessPoint::ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN, false); 79 signin_metrics::AccessPoint::ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN, false);
69 } 80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698