| OLD | NEW |
| 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/ui/view_ids.h" | 9 #include "chrome/browser/ui/view_ids.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_frame.h" | 10 #include "chrome/browser/ui/views/frame/browser_frame.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 ProfileAttributesEntry* unused; | 24 ProfileAttributesEntry* unused; |
| 25 if ((browser_view->IsBrowserTypeNormal() && | 25 if ((browser_view->IsBrowserTypeNormal() && |
| 26 // Tests may not have a profile manager. | 26 // Tests may not have a profile manager. |
| 27 g_browser_process->profile_manager() && | 27 g_browser_process->profile_manager() && |
| 28 g_browser_process->profile_manager() | 28 g_browser_process->profile_manager() |
| 29 ->GetProfileAttributesStorage() | 29 ->GetProfileAttributesStorage() |
| 30 .GetProfileAttributesWithPath(profile->GetPath(), &unused)) || | 30 .GetProfileAttributesWithPath(profile->GetPath(), &unused)) || |
| 31 // Desktop guest shows the avatar button. | 31 // Desktop guest shows the avatar button. |
| 32 browser_view->IsIncognito()) { | 32 browser_view->IsIncognito()) { |
| 33 if (!view_) { | 33 if (!view_) { |
| 34 view_ = new NewAvatarButton(this, style, profile); | 34 view_ = new AvatarButton(this, style, profile); |
| 35 view_->set_id(VIEW_ID_AVATAR_BUTTON); | 35 view_->set_id(VIEW_ID_AVATAR_BUTTON); |
| 36 frame_view_->AddChildView(view_); | 36 frame_view_->AddChildView(view_); |
| 37 frame->GetRootView()->Layout(); | 37 frame->GetRootView()->Layout(); |
| 38 } | 38 } |
| 39 } else if (view_) { | 39 } else if (view_) { |
| 40 delete view_; | 40 delete view_; |
| 41 view_ = nullptr; | 41 view_ = nullptr; |
| 42 frame->GetRootView()->Layout(); | 42 frame->GetRootView()->Layout(); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 void AvatarButtonManager::ButtonPreferredSizeChanged() { | |
| 47 // Perform a re-layout if the avatar button has changed, since that can affect | |
| 48 // the size of the tabs. | |
| 49 if (!view_ || !frame_view_->browser_view()->initialized()) | |
| 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, | 46 void AvatarButtonManager::ButtonPressed(views::Button* sender, |
| 57 const ui::Event& event) { | 47 const ui::Event& event) { |
| 58 DCHECK_EQ(view_, sender); | 48 DCHECK_EQ(view_, sender); |
| 59 BrowserWindow::AvatarBubbleMode mode = | 49 BrowserWindow::AvatarBubbleMode mode = |
| 60 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT; | 50 BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT; |
| 61 if ((event.IsMouseEvent() && | 51 if ((event.IsMouseEvent() && |
| 62 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) || | 52 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) || |
| 63 (event.type() == ui::ET_GESTURE_LONG_PRESS)) { | 53 (event.type() == ui::ET_GESTURE_LONG_PRESS)) { |
| 64 return; | 54 return; |
| 65 } | 55 } |
| 66 frame_view_->browser_view()->ShowAvatarBubbleFromAvatarButton( | 56 frame_view_->browser_view()->ShowAvatarBubbleFromAvatarButton( |
| 67 mode, signin::ManageAccountsParams(), | 57 mode, signin::ManageAccountsParams(), |
| 68 signin_metrics::AccessPoint::ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN, false); | 58 signin_metrics::AccessPoint::ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN, false); |
| 69 } | 59 } |
| OLD | NEW |