| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/profile_menu_model.h" | 8 #include "chrome/browser/ui/profile_menu_model.h" |
| 9 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 9 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" | 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // The Windows 7 taskbar supports dynamic overlays and effects, we use this | 27 // The Windows 7 taskbar supports dynamic overlays and effects, we use this |
| 28 // to ovelay the avatar icon there. The overlay only applies if the taskbar | 28 // to ovelay the avatar icon there. The overlay only applies if the taskbar |
| 29 // is in "default large icon mode". This function is a best effort deal so | 29 // is in "default large icon mode". This function is a best effort deal so |
| 30 // we bail out silently at any error condition. | 30 // we bail out silently at any error condition. |
| 31 // See http://msdn.microsoft.com/en-us/library/dd391696(VS.85).aspx for | 31 // See http://msdn.microsoft.com/en-us/library/dd391696(VS.85).aspx for |
| 32 // more information. | 32 // more information. |
| 33 void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) { | 33 void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) { |
| 34 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 35 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 35 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 36 return; | 36 return; |
| 37 // During destruction of the browser frame, we might not have a window | |
| 38 // so the taksbar button will be removed by windows anyway. | |
| 39 BrowserWindow* bw = browser->window(); | 37 BrowserWindow* bw = browser->window(); |
| 40 if (!bw) | 38 if (!bw) |
| 41 return; | 39 return; |
| 42 gfx::NativeWindow window = bw->GetNativeHandle(); | 40 gfx::NativeWindow window = bw->GetNativeHandle(); |
| 43 if (!window) | 41 if (!window) |
| 44 return; | 42 return; |
| 45 | 43 |
| 46 base::win::ScopedComPtr<ITaskbarList3> taskbar; | 44 base::win::ScopedComPtr<ITaskbarList3> taskbar; |
| 47 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, | 45 HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, |
| 48 CLSCTX_INPROC_SERVER); | 46 CLSCTX_INPROC_SERVER); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 68 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) | 66 AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) |
| 69 : MenuButton(NULL, std::wstring(), this, false), | 67 : MenuButton(NULL, std::wstring(), this, false), |
| 70 browser_(browser), | 68 browser_(browser), |
| 71 has_menu_(has_menu), | 69 has_menu_(has_menu), |
| 72 set_taskbar_decoration_(false) { | 70 set_taskbar_decoration_(false) { |
| 73 // In RTL mode, the avatar icon should be looking the opposite direction. | 71 // In RTL mode, the avatar icon should be looking the opposite direction. |
| 74 EnableCanvasFlippingForRTLUI(true); | 72 EnableCanvasFlippingForRTLUI(true); |
| 75 } | 73 } |
| 76 | 74 |
| 77 AvatarMenuButton::~AvatarMenuButton() { | 75 AvatarMenuButton::~AvatarMenuButton() { |
| 76 // During destruction of the browser frame, we might not have a window |
| 77 // so the taskbar button will be removed by windows anyway. |
| 78 if (browser_->IsAttemptingToCloseBrowser()) |
| 79 return; |
| 78 DrawTaskBarDecoration(browser_, NULL); | 80 DrawTaskBarDecoration(browser_, NULL); |
| 79 } | 81 } |
| 80 | 82 |
| 81 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { | 83 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
| 82 const SkBitmap& icon = GetImageToPaint(); | 84 const SkBitmap& icon = GetImageToPaint(); |
| 83 if (icon.isNull()) | 85 if (icon.isNull()) |
| 84 return; | 86 return; |
| 85 | 87 |
| 86 // Scale the image to fit the width of the button. | 88 // Scale the image to fit the width of the button. |
| 87 int dst_width = std::min(icon.width(), width()); | 89 int dst_width = std::min(icon.width(), width()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 views::View::ConvertPointToScreen(this, &origin); | 138 views::View::ConvertPointToScreen(this, &origin); |
| 137 gfx::Rect bounds(0, 0, width(), height()); | 139 gfx::Rect bounds(0, 0, width(), height()); |
| 138 bounds.set_origin(origin); | 140 bounds.set_origin(origin); |
| 139 | 141 |
| 140 AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_); | 142 AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_); |
| 141 // Bubble::Show() takes ownership of the view. | 143 // Bubble::Show() takes ownership of the view. |
| 142 Bubble::Show(browser_view->GetWidget(), bounds, | 144 Bubble::Show(browser_view->GetWidget(), bounds, |
| 143 views::BubbleBorder::TOP_LEFT, | 145 views::BubbleBorder::TOP_LEFT, |
| 144 bubble_view, bubble_view); | 146 bubble_view, bubble_view); |
| 145 } | 147 } |
| OLD | NEW |