Add 'tray.popContextMenu()' Windows implementation.
This commit is contained in:
parent
4421fbf9f3
commit
ed4c69343f
6 changed files with 26 additions and 23 deletions
|
@ -106,8 +106,10 @@ void Tray::DisplayBalloon(mate::Arguments* args,
|
|||
tray_icon_->DisplayBalloon(icon, title, content);
|
||||
}
|
||||
|
||||
void Tray::PopContextMenu() {
|
||||
tray_icon_->PopContextMenu();
|
||||
void Tray::PopContextMenu(mate::Arguments* args) {
|
||||
gfx::Point pos;
|
||||
args->GetNext(&pos);
|
||||
tray_icon_->PopContextMenu(pos);
|
||||
}
|
||||
|
||||
void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) {
|
||||
|
|
|
@ -58,7 +58,7 @@ class Tray : public mate::EventEmitter,
|
|||
void SetTitle(mate::Arguments* args, const std::string& title);
|
||||
void SetHighlightMode(mate::Arguments* args, bool highlight);
|
||||
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
|
||||
void PopContextMenu();
|
||||
void PopContextMenu(mate::Arguments* args);
|
||||
void SetContextMenu(mate::Arguments* args, Menu* menu);
|
||||
|
||||
private:
|
||||
|
|
|
@ -26,7 +26,7 @@ void TrayIcon::DisplayBalloon(const gfx::Image& icon,
|
|||
const base::string16& contents) {
|
||||
}
|
||||
|
||||
void TrayIcon::PopContextMenu() {
|
||||
void TrayIcon::PopContextMenu(const gfx::Point& pos) {
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyClicked(const gfx::Rect& bounds) {
|
||||
|
|
|
@ -46,7 +46,7 @@ class TrayIcon {
|
|||
const base::string16& title,
|
||||
const base::string16& contents);
|
||||
|
||||
virtual void PopContextMenu();
|
||||
virtual void PopContextMenu(const gfx::Point& pos);
|
||||
|
||||
// Set the context menu for this icon.
|
||||
virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
|
||||
|
|
|
@ -62,24 +62,7 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
|
|||
}
|
||||
|
||||
NotifyRightClicked(gfx::Rect(rect));
|
||||
|
||||
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;
|
||||
|
||||
views::MenuRunner menu_runner(
|
||||
menu_model_,
|
||||
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
|
||||
ignore_result(menu_runner.RunMenuAt(
|
||||
NULL,
|
||||
NULL,
|
||||
gfx::Rect(cursor_pos, gfx::Size()),
|
||||
views::MENU_ANCHOR_TOPLEFT,
|
||||
ui::MENU_SOURCE_MOUSE));
|
||||
PopContextMenu(cursor_pos);
|
||||
}
|
||||
|
||||
void NotifyIcon::ResetIcon() {
|
||||
|
@ -152,6 +135,23 @@ void NotifyIcon::DisplayBalloon(const gfx::Image& icon,
|
|||
LOG(WARNING) << "Unable to create status tray balloon.";
|
||||
}
|
||||
|
||||
void NotifyIcon::PopContextMenu(const gfx::Point& pos) {
|
||||
// Set our window as the foreground window, so the context menu closes when
|
||||
// we click away from it.
|
||||
if (!SetForegroundWindow(window_))
|
||||
return;
|
||||
|
||||
views::MenuRunner menu_runner(
|
||||
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));
|
||||
}
|
||||
|
||||
void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
menu_model_ = menu_model;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ class NotifyIcon : public TrayIcon {
|
|||
void DisplayBalloon(const gfx::Image& icon,
|
||||
const base::string16& title,
|
||||
const base::string16& contents) override;
|
||||
void PopContextMenu(const gfx::Point& pos) override;
|
||||
void SetContextMenu(ui::SimpleMenuModel* menu_model) override;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue