diff options
author | Iain Merrick <husky@google.com> | 2010-10-19 14:37:37 +0100 |
---|---|---|
committer | Iain Merrick <husky@google.com> | 2010-10-19 14:37:37 +0100 |
commit | 3345a6884c488ff3a535c2c9acdd33d74b37e311 (patch) | |
tree | 7784b988ef1698cb6967ea1bdf07616237716c6c /chrome/browser/views/status_icons | |
parent | efc8475837ec58186051f23bb03542620424f6ce (diff) | |
download | external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.zip external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.tar.gz external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.tar.bz2 |
Merge Chromium at 7.0.540.0 : Initial merge by git
Not including third_party/icu as it contains huge data files that break Gerrit, and aren't actually used.
Change-Id: I428a386e70f3b58cacd28677b8cfda282e891e15
Diffstat (limited to 'chrome/browser/views/status_icons')
5 files changed, 73 insertions, 16 deletions
diff --git a/chrome/browser/views/status_icons/status_icon_win.cc b/chrome/browser/views/status_icons/status_icon_win.cc index 53cfcad..5545560 100644 --- a/chrome/browser/views/status_icons/status_icon_win.cc +++ b/chrome/browser/views/status_icons/status_icon_win.cc @@ -4,9 +4,11 @@ #include "chrome/browser/views/status_icons/status_icon_win.h" -#include "gfx/icon_util.h" #include "base/sys_string_conversions.h" +#include "gfx/icon_util.h" +#include "gfx/point.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "views/controls/menu/menu_2.h" StatusIconWin::StatusIconWin(UINT id, HWND window, UINT message) : icon_id_(id), @@ -58,3 +60,30 @@ void StatusIconWin::InitIconData(NOTIFYICONDATA* icon_data) { icon_data->hWnd = window_; icon_data->uID = icon_id_; } + +void StatusIconWin::UpdatePlatformContextMenu(menus::MenuModel* menu) { + // If no items are passed, blow away our context menu. + if (!menu) { + context_menu_.reset(); + return; + } + + // Create context menu with the new contents. + context_menu_.reset(new views::Menu2(menu)); +} + +void StatusIconWin::HandleClickEvent(int x, int y, bool left_mouse_click) { + // Pass to the observer if appropriate. + if (left_mouse_click && HasObservers()) { + DispatchClickEvent(); + return; + } + + // Event not sent to the observer, so display the context menu if one exists. + if (context_menu_.get()) { + // Set our window as the foreground window, so the context menu closes when + // we click away from it. + SetForegroundWindow(window_); + context_menu_->RunContextMenuAt(gfx::Point(x, y)); + } +} diff --git a/chrome/browser/views/status_icons/status_icon_win.h b/chrome/browser/views/status_icons/status_icon_win.h index 46be5ae..08545ac 100644 --- a/chrome/browser/views/status_icons/status_icon_win.h +++ b/chrome/browser/views/status_icons/status_icon_win.h @@ -4,13 +4,19 @@ #ifndef CHROME_BROWSER_VIEWS_STATUS_ICONS_STATUS_ICON_WIN_H_ #define CHROME_BROWSER_VIEWS_STATUS_ICONS_STATUS_ICON_WIN_H_ +#pragma once #include <windows.h> #include <shellapi.h> #include "base/scoped_handle_win.h" +#include "base/scoped_ptr.h" #include "chrome/browser/status_icons/status_icon.h" +namespace views { +class Menu2; +} + class StatusIconWin : public StatusIcon { public: // Constructor which provides this icon's unique ID and messaging window. @@ -26,6 +32,15 @@ class StatusIconWin : public StatusIcon { UINT message_id() const { return message_id_; } + // Handles a click event from the user - if |left_button_click| is true and + // there is a registered observer, passes the click event to the observer, + // otherwise displays the context menu if there is one. + void HandleClickEvent(int x, int y, bool left_button_click); + + protected: + // Overridden from StatusIcon. + virtual void UpdatePlatformContextMenu(menus::MenuModel* menu); + private: void InitIconData(NOTIFYICONDATA* icon_data); @@ -41,6 +56,9 @@ class StatusIconWin : public StatusIcon { // The currently-displayed icon for the window. ScopedHICON icon_; + // Context menu associated with this icon (if any). + scoped_ptr<views::Menu2> context_menu_; + DISALLOW_COPY_AND_ASSIGN(StatusIconWin); }; diff --git a/chrome/browser/views/status_icons/status_tray_win.cc b/chrome/browser/views/status_icons/status_tray_win.cc index 8c1a998..29ed025 100644 --- a/chrome/browser/views/status_icons/status_tray_win.cc +++ b/chrome/browser/views/status_icons/status_tray_win.cc @@ -41,21 +41,23 @@ LRESULT CALLBACK StatusTrayWin::WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { - // TODO(atwilson): Add support for right clicks and context menu messages - // (tracked in http://crbug.com/37375). switch (message) { case kStatusIconMessage: switch (lparam) { case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_CONTEXTMENU: // Walk our icons, find which one was clicked on, and invoke its - // DispatchClickEvent() method. - for (StatusIconMap::const_iterator iter = status_icons().begin(); + // HandleClickEvent() method. + for (StatusIconList::const_iterator iter = status_icons().begin(); iter != status_icons().end(); ++iter) { - StatusIconWin* win_icon = - static_cast<StatusIconWin*>(iter->second); - if (win_icon->icon_id() == wparam) - win_icon->DispatchClickEvent(); + StatusIconWin* win_icon = static_cast<StatusIconWin*>(*iter); + if (win_icon->icon_id() == wparam) { + POINT p; + GetCursorPos(&p); + win_icon->HandleClickEvent(p.x, p.y, lparam == WM_LBUTTONDOWN); + } } return TRUE; } @@ -70,7 +72,7 @@ StatusTrayWin::~StatusTrayWin() { UnregisterClass(chrome::kStatusTrayWindowClass, GetModuleHandle(NULL)); } -StatusIcon* StatusTrayWin::CreateStatusIcon() { +StatusIcon* StatusTrayWin::CreatePlatformStatusIcon() { return new StatusIconWin(next_icon_id_++, window_, kStatusIconMessage); } diff --git a/chrome/browser/views/status_icons/status_tray_win.h b/chrome/browser/views/status_icons/status_tray_win.h index f3aa9d1..a2e322c 100644 --- a/chrome/browser/views/status_icons/status_tray_win.h +++ b/chrome/browser/views/status_icons/status_tray_win.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_VIEWS_STATUS_ICONS_STATUS_TRAY_WIN_H_ #define CHROME_BROWSER_VIEWS_STATUS_ICONS_STATUS_TRAY_WIN_H_ +#pragma once #include <windows.h> @@ -21,7 +22,7 @@ class StatusTrayWin : public StatusTray { LPARAM lparam); protected: // Overriden from StatusTray: - virtual StatusIcon* CreateStatusIcon(); + virtual StatusIcon* CreatePlatformStatusIcon(); private: // Static callback invoked when a message comes in to our messaging window. diff --git a/chrome/browser/views/status_icons/status_tray_win_unittest.cc b/chrome/browser/views/status_icons/status_tray_win_unittest.cc index 073e50b..c824755 100644 --- a/chrome/browser/views/status_icons/status_tray_win_unittest.cc +++ b/chrome/browser/views/status_icons/status_tray_win_unittest.cc @@ -2,8 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/menus/simple_menu_model.h" #include "app/resource_bundle.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/views/status_icons/status_icon_win.h" #include "chrome/browser/views/status_icons/status_tray_win.h" #include "grit/browser_resources.h" @@ -23,26 +25,31 @@ TEST(StatusTrayWinTest, CreateTray) { StatusTrayWin tray; } -TEST(StatusTrayWinTest, CreateIcon) { - // Create an icon, set the images and tooltip, then shut it down. +TEST(StatusTrayWinTest, CreateIconAndMenu) { + // Create an icon, set the images, tooltip, and context menu, then shut it + // down. StatusTrayWin tray; - StatusIcon* icon = tray.GetStatusIcon(ASCIIToUTF16("test")); + StatusIcon* icon = tray.CreateStatusIcon(); SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_STATUS_TRAY_ICON); icon->SetImage(*bitmap); icon->SetPressedImage(*bitmap); icon->SetToolTip(ASCIIToUTF16("tool tip")); + menus::SimpleMenuModel* menu = new menus::SimpleMenuModel(NULL); + menu->AddItem(0, L"foo"); + icon->SetContextMenu(menu); } TEST(StatusTrayWinTest, ClickOnIcon) { // Create an icon, send a fake click event, make sure observer is called. StatusTrayWin tray; - StatusIconWin* icon = static_cast<StatusIconWin*>( - tray.GetStatusIcon(ASCIIToUTF16("test"))); + StatusIconWin* icon = static_cast<StatusIconWin*>(tray.CreateStatusIcon()); MockStatusIconObserver observer; icon->AddObserver(&observer); EXPECT_CALL(observer, OnClicked()); // Mimic a click. tray.WndProc(NULL, icon->message_id(), icon->icon_id(), WM_LBUTTONDOWN); + // Mimic a right-click - observer should not be called. + tray.WndProc(NULL, icon->message_id(), icon->icon_id(), WM_RBUTTONDOWN); icon->RemoveObserver(&observer); } |