Merge pull request #12496 from mikeykhalil/8952-ignore-tray-double-click-events

8952 option to ignore tray double click events
This commit is contained in:
John Kleinschmidt 2018-05-16 10:17:36 -04:00 коммит произвёл GitHub
Родитель e1c374de6e 3aba515bbc
Коммит 9488ef4867
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 66 добавлений и 3 удалений

Просмотреть файл

@ -176,6 +176,20 @@ void Tray::SetHighlightMode(TrayIcon::HighlightMode mode) {
tray_icon_->SetHighlightMode(mode);
}
void Tray::SetIgnoreDoubleClickEvents(bool ignore) {
#if defined(OS_MACOSX)
tray_icon_->SetIgnoreDoubleClickEvents(ignore);
#endif
}
bool Tray::GetIgnoreDoubleClickEvents() {
#if defined(OS_MACOSX)
return tray_icon_->GetIgnoreDoubleClickEvents();
#else
return false;
#endif
}
void Tray::DisplayBalloon(mate::Arguments* args,
const mate::Dictionary& options) {
mate::Handle<NativeImage> icon;
@ -224,6 +238,10 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setToolTip", &Tray::SetToolTip)
.SetMethod("setTitle", &Tray::SetTitle)
.SetMethod("setHighlightMode", &Tray::SetHighlightMode)
.SetMethod("setIgnoreDoubleClickEvents",
&Tray::SetIgnoreDoubleClickEvents)
.SetMethod("getIgnoreDoubleClickEvents",
&Tray::GetIgnoreDoubleClickEvents)
.SetMethod("displayBalloon", &Tray::DisplayBalloon)
.SetMethod("popUpContextMenu", &Tray::PopUpContextMenu)
.SetMethod("setContextMenu", &Tray::SetContextMenu)

Просмотреть файл

@ -70,6 +70,8 @@ class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
void SetToolTip(const std::string& tool_tip);
void SetTitle(const std::string& title);
void SetHighlightMode(TrayIcon::HighlightMode mode);
void SetIgnoreDoubleClickEvents(bool ignore);
bool GetIgnoreDoubleClickEvents();
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
void PopUpContextMenu(mate::Arguments* args);
void SetContextMenu(v8::Isolate* isolate, mate::Handle<Menu> menu);

Просмотреть файл

@ -51,6 +51,13 @@ class TrayIcon {
};
virtual void SetHighlightMode(HighlightMode mode);
// Setter and getter for the flag which determines whether to ignore double
// click events. These only work on macOS.
#if defined(OS_MACOSX)
virtual void SetIgnoreDoubleClickEvents(bool ignore) = 0;
virtual bool GetIgnoreDoubleClickEvents() = 0;
#endif
// Displays a notification balloon with the specified contents.
// Depending on the platform it might not appear by the icon tray.
virtual void DisplayBalloon(ImageType icon,

Просмотреть файл

@ -27,6 +27,8 @@ class TrayIconCocoa : public TrayIcon, public AtomMenuModel::Observer {
void SetToolTip(const std::string& tool_tip) override;
void SetTitle(const std::string& title) override;
void SetHighlightMode(TrayIcon::HighlightMode mode) override;
void SetIgnoreDoubleClickEvents(bool ignore) override;
bool GetIgnoreDoubleClickEvents() override;
void PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model) override;
void SetContextMenu(AtomMenuModel* menu_model) override;

Просмотреть файл

@ -25,6 +25,7 @@ const CGFloat kVerticalTitleMargin = 2;
atom::TrayIconCocoa* trayIcon_; // weak
AtomMenuController* menuController_; // weak
atom::TrayIcon::HighlightMode highlight_mode_;
BOOL ignoreDoubleClickEvents_;
BOOL forceHighlight_;
BOOL inMouseEventSequence_;
BOOL ANSI_;
@ -44,6 +45,7 @@ const CGFloat kVerticalTitleMargin = 2;
image_.reset([image copy]);
trayIcon_ = icon;
highlight_mode_ = atom::TrayIcon::HighlightMode::SELECTION;
ignoreDoubleClickEvents_ = NO;
forceHighlight_ = NO;
inMouseEventSequence_ = NO;
@ -204,6 +206,14 @@ const CGFloat kVerticalTitleMargin = 2;
[self setNeedsDisplay:YES];
}
- (void)setIgnoreDoubleClickEvents:(BOOL)ignore {
ignoreDoubleClickEvents_ = ignore;
}
- (BOOL)getIgnoreDoubleClickEvents {
return ignoreDoubleClickEvents_;
}
- (void)setTitle:(NSString*)title {
if (title.length > 0) {
title_.reset([title copy]);
@ -279,15 +289,18 @@ const CGFloat kVerticalTitleMargin = 2;
if (menuController_)
return;
// Single click event.
if (event.clickCount == 1)
// If we are ignoring double click events, we should ignore the `clickCount`
// value and immediately emit a click event.
BOOL shouldBeHandledAsASingleClick = (event.clickCount == 1) || ignoreDoubleClickEvents_;
if (shouldBeHandledAsASingleClick)
trayIcon_->NotifyClicked(
gfx::ScreenRectFromNSRect(event.window.frame),
gfx::ScreenPointFromNSPoint([event locationInWindow]),
ui::EventFlagsFromModifiers([event modifierFlags]));
// Double click event.
if (event.clickCount == 2)
BOOL shouldBeHandledAsADoubleClick = (event.clickCount == 2) && !ignoreDoubleClickEvents_;
if (shouldBeHandledAsADoubleClick)
trayIcon_->NotifyDoubleClicked(
gfx::ScreenRectFromNSRect(event.window.frame),
ui::EventFlagsFromModifiers([event modifierFlags]));
@ -437,6 +450,14 @@ void TrayIconCocoa::SetHighlightMode(TrayIcon::HighlightMode mode) {
[status_item_view_ setHighlight:mode];
}
void TrayIconCocoa::SetIgnoreDoubleClickEvents(bool ignore) {
[status_item_view_ setIgnoreDoubleClickEvents:ignore];
}
bool TrayIconCocoa::GetIgnoreDoubleClickEvents() {
return [status_item_view_ getIgnoreDoubleClickEvents];
}
void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model) {
[status_item_view_ popUpContextMenu:menu_model];

Просмотреть файл

@ -241,6 +241,19 @@ win.on('hide', () => {
})
```
#### `tray.setIgnoreDoubleClickEvents(ignore)` _macOS_
* `ignore` Boolean
Sets the option to ignore double click events. Ignoring these events allows you
to detect every individual click of the tray icon.
This value is set to false by default.
### `tray.getIgnoreDoubleClickEvents()` _macOS_
Returns `Boolean` - Whether double click events will be ignored.
#### `tray.displayBalloon(options)` _Windows_
* `options` Object