Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/avatar_menu_button.h" | 5 #include "chrome/browser/ui/views/avatar_menu_button.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/command_updater.h" | 9 #include "chrome/browser/command_updater.h" |
| 10 #include "chrome/browser/managed_mode/managed_mode.h" | 10 #include "chrome/browser/managed_mode/managed_mode.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 : MenuButton(NULL, string16(), this, false), | 93 : MenuButton(NULL, string16(), this, false), |
| 94 browser_(browser), | 94 browser_(browser), |
| 95 incognito_(incognito), | 95 incognito_(incognito), |
| 96 is_gaia_picture_(false), | 96 is_gaia_picture_(false), |
| 97 old_height_(0) { | 97 old_height_(0) { |
| 98 // In RTL mode, the avatar icon should be looking the opposite direction. | 98 // In RTL mode, the avatar icon should be looking the opposite direction. |
| 99 EnableCanvasFlippingForRTLUI(true); | 99 EnableCanvasFlippingForRTLUI(true); |
| 100 } | 100 } |
| 101 | 101 |
| 102 AvatarMenuButton::~AvatarMenuButton() { | 102 AvatarMenuButton::~AvatarMenuButton() { |
| 103 if (bubble_widget_) | |
| 104 OnWidgetClosing(bubble_widget_); | |
| 103 } | 105 } |
| 104 | 106 |
| 105 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { | 107 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
| 106 if (!icon_.get()) | 108 if (!icon_.get()) |
| 107 return; | 109 return; |
| 108 | 110 |
| 109 if (old_height_ != height() || button_icon_.isNull()) { | 111 if (old_height_ != height() || button_icon_.isNull()) { |
| 110 old_height_ = height(); | 112 old_height_ = height(); |
| 111 button_icon_ = *profiles::GetAvatarIconForTitleBar( | 113 button_icon_ = *profiles::GetAvatarIconForTitleBar( |
| 112 *icon_, is_gaia_picture_, width(), height()).ToImageSkia(); | 114 *icon_, is_gaia_picture_, width(), height()).ToImageSkia(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 const gfx::Point& point) { | 154 const gfx::Point& point) { |
| 153 if (incognito_) | 155 if (incognito_) |
| 154 return; | 156 return; |
| 155 | 157 |
| 156 if (ManagedMode::IsInManagedMode()) | 158 if (ManagedMode::IsInManagedMode()) |
| 157 ManagedMode::LeaveManagedMode(); | 159 ManagedMode::LeaveManagedMode(); |
| 158 else | 160 else |
| 159 ShowAvatarBubble(); | 161 ShowAvatarBubble(); |
| 160 } | 162 } |
| 161 | 163 |
| 164 void AvatarMenuButton::OnWidgetClosing(views::Widget* widget) { | |
| 165 bubble_widget_->RemoveObserver(this); | |
| 166 bubble_widget_ = NULL; | |
| 167 // If the avatar bubble is about to be shown the cancel the operation. This | |
| 168 // prevents the bubble from closing and immediately reopening when the user | |
| 169 // clicks the avatar button a second time. | |
| 170 show_avatar_bubble_closure_.Cancel(); | |
| 171 } | |
| 172 | |
| 162 void AvatarMenuButton::ShowAvatarBubble() { | 173 void AvatarMenuButton::ShowAvatarBubble() { |
| 174 show_avatar_bubble_closure_.Reset( | |
| 175 base::Bind(&AvatarMenuButton::ShowAvatarBubbleImpl, | |
| 176 base::Unretained(this))); | |
| 177 MessageLoop::current()->PostTask(FROM_HERE, | |
| 178 show_avatar_bubble_closure_.callback()); | |
|
Peter Kasting
2012/12/28 18:55:55
This has three problems:
(1) It makes the menu op
sail
2013/01/02 21:06:01
Done.
I changed this to match the bookmark code by
| |
| 179 } | |
| 180 | |
| 181 void AvatarMenuButton::ShowAvatarBubbleImpl() { | |
|
Peter Kasting
2012/12/28 18:55:55
There's nearly identical code to this in browser_v
sail
2013/01/02 21:06:01
Done.
| |
| 182 if (bubble_widget_) | |
| 183 return; | |
| 184 | |
| 163 DCHECK(chrome::IsCommandEnabled(browser_, IDC_SHOW_AVATAR_MENU)); | 185 DCHECK(chrome::IsCommandEnabled(browser_, IDC_SHOW_AVATAR_MENU)); |
| 164 | 186 |
| 165 gfx::Point origin; | 187 gfx::Point origin; |
| 166 views::View::ConvertPointToScreen(this, &origin); | 188 views::View::ConvertPointToScreen(this, &origin); |
| 167 gfx::Rect bounds(origin, size()); | 189 gfx::Rect bounds(origin, size()); |
| 168 | 190 |
| 169 AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this, | 191 AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this, |
| 170 views::BubbleBorder::TOP_LEFT, bounds, browser_); | 192 views::BubbleBorder::TOP_LEFT, bounds, browser_); |
| 171 views::BubbleDelegateView::CreateBubble(bubble); | 193 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble); |
| 194 bubble_widget_->AddObserver(this); | |
| 172 bubble->Show(); | 195 bubble->Show(); |
| 173 | 196 |
| 174 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); | 197 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); |
| 175 } | 198 } |
| OLD | NEW |