#include "ui/gfx/image/image.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/screen.h"
#include "ui/views/controls/menu/menu_runner.h"
namespace atom {
Shell_NotifyIcon(NIM_DELETE, &icon_data);
}
-void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
- int modifiers,
+void NotifyIcon::HandleClickEvent(int modifiers,
bool left_mouse_click,
bool double_button_click) {
NOTIFYICONIDENTIFIER icon_id;
return;
} else if (!double_button_click) { // single right click
if (menu_model_)
- PopUpContextMenu(cursor_pos, menu_model_);
+ PopUpContextMenu(gfx::Point(), menu_model_);
else
NotifyRightClicked(gfx::Rect(rect), modifiers);
}
void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
ui::SimpleMenuModel* menu_model) {
// Returns if context menu isn't set.
- if (!menu_model_)
+ if (!menu_model)
return;
// Set our window as the foreground window, so the context menu closes when
// we click away from it.
if (!SetForegroundWindow(window_))
return;
+ // Show menu at mouse's position by default.
+ gfx::Rect rect(pos, gfx::Size());
+ if (pos.IsOrigin())
+ rect.set_origin(gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
+
views::MenuRunner menu_runner(
- menu_model_,
+ menu_model,
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
ignore_result(menu_runner.RunMenuAt(
- NULL,
- NULL,
- gfx::Rect(pos, gfx::Size()),
- views::MENU_ANCHOR_TOPLEFT,
- ui::MENU_SOURCE_MOUSE));
+ NULL, NULL, rect, views::MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_MOUSE));
}
void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
// 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(const gfx::Point& cursor_pos,
- int modifiers,
+ void HandleClickEvent(int modifiers,
bool left_button_click,
bool double_button_click);
#include "base/win/win_util.h"
#include "base/win/wrapped_window_proc.h"
#include "ui/events/event_constants.h"
-#include "ui/gfx/screen.h"
#include "ui/gfx/win/hwnd_util.h"
namespace atom {
case WM_CONTEXTMENU:
// Walk our icons, find which one was clicked on, and invoke its
// HandleClickEvent() method.
- gfx::Point cursor_pos(
- gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
win_icon->HandleClickEvent(
- cursor_pos,
GetKeyboardModifers(),
(lparam == WM_LBUTTONDOWN || lparam == WM_LBUTTONDBLCLK),
(lparam == WM_LBUTTONDBLCLK || lparam == WM_RBUTTONDBLCLK));