OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/status_icons/status_icon_win.h" | 5 #include "chrome/browser/views/status_icons/status_icon_win.h" |
6 | 6 |
| 7 #include "base/sys_string_conversions.h" |
7 #include "gfx/icon_util.h" | 8 #include "gfx/icon_util.h" |
8 #include "base/sys_string_conversions.h" | 9 #include "gfx/point.h" |
9 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 #include "views/controls/menu/menu_2.h" |
10 | 12 |
11 StatusIconWin::StatusIconWin(UINT id, HWND window, UINT message) | 13 StatusIconWin::StatusIconWin(UINT id, HWND window, UINT message) |
12 : icon_id_(id), | 14 : icon_id_(id), |
13 window_(window), | 15 window_(window), |
14 message_id_(message) { | 16 message_id_(message) { |
15 NOTIFYICONDATA icon_data; | 17 NOTIFYICONDATA icon_data; |
16 InitIconData(&icon_data); | 18 InitIconData(&icon_data); |
17 icon_data.uFlags = NIF_MESSAGE; | 19 icon_data.uFlags = NIF_MESSAGE; |
18 icon_data.uCallbackMessage = message_id_; | 20 icon_data.uCallbackMessage = message_id_; |
19 BOOL result = Shell_NotifyIcon(NIM_ADD, &icon_data); | 21 BOOL result = Shell_NotifyIcon(NIM_ADD, &icon_data); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 wcscpy_s(icon_data.szTip, tool_tip.c_str()); | 53 wcscpy_s(icon_data.szTip, tool_tip.c_str()); |
52 BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data); | 54 BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data); |
53 DCHECK(result); | 55 DCHECK(result); |
54 } | 56 } |
55 | 57 |
56 void StatusIconWin::InitIconData(NOTIFYICONDATA* icon_data) { | 58 void StatusIconWin::InitIconData(NOTIFYICONDATA* icon_data) { |
57 icon_data->cbSize = sizeof(icon_data); | 59 icon_data->cbSize = sizeof(icon_data); |
58 icon_data->hWnd = window_; | 60 icon_data->hWnd = window_; |
59 icon_data->uID = icon_id_; | 61 icon_data->uID = icon_id_; |
60 } | 62 } |
| 63 |
| 64 void StatusIconWin::ResetContextMenu(menus::MenuModel* menu) { |
| 65 // If no items are passed, blow away our context menu. |
| 66 if (!menu) { |
| 67 context_menu_.reset(); |
| 68 return; |
| 69 } |
| 70 |
| 71 // Create context menu with the new contents. |
| 72 context_menu_.reset(new views::Menu2(menu)); |
| 73 } |
| 74 |
| 75 void StatusIconWin::HandleClickEvent(int x, int y, bool left_mouse_click) { |
| 76 // Pass to the observer if appropriate. |
| 77 if (left_mouse_click && HasObservers()) { |
| 78 DispatchClickEvent(); |
| 79 return; |
| 80 } |
| 81 |
| 82 // Event not sent to the observer, so display the context menu if one exists. |
| 83 if (context_menu_.get()) { |
| 84 // Set our window as the foreground window, so the context menu closes when |
| 85 // we click away from it. |
| 86 SetForegroundWindow(window_); |
| 87 context_menu_->RunContextMenuAt(gfx::Point(x, y)); |
| 88 } |
| 89 } |
OLD | NEW |