Add keyboard modifiers payload to tray click events
* Add keyboard and mouse button bitsum to Tray click events payload * Move getBoundsFromRect: to common event_util file * Update documentation
This commit is contained in:
parent
99a8f29de9
commit
74b4522195
9 changed files with 70 additions and 42 deletions
|
@ -40,12 +40,12 @@ mate::Wrappable* Tray::New(v8::Isolate* isolate, const gfx::Image& image) {
|
|||
return new Tray(image);
|
||||
}
|
||||
|
||||
void Tray::OnClicked(const gfx::Rect& bounds) {
|
||||
Emit("clicked", bounds);
|
||||
void Tray::OnClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
Emit("clicked", bounds, modifiers);
|
||||
}
|
||||
|
||||
void Tray::OnDoubleClicked(const gfx::Rect& bounds) {
|
||||
Emit("double-clicked", bounds);
|
||||
void Tray::OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
Emit("double-clicked", bounds, modifiers);
|
||||
}
|
||||
|
||||
void Tray::OnBalloonShow() {
|
||||
|
@ -60,8 +60,8 @@ void Tray::OnBalloonClosed() {
|
|||
Emit("balloon-closed");
|
||||
}
|
||||
|
||||
void Tray::OnRightClicked(const gfx::Rect& bounds) {
|
||||
Emit("right-clicked", bounds);
|
||||
void Tray::OnRightClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
Emit("right-clicked", bounds, modifiers);
|
||||
}
|
||||
|
||||
void Tray::OnDropFiles(const std::vector<std::string>& files) {
|
||||
|
|
|
@ -42,12 +42,12 @@ class Tray : public mate::EventEmitter,
|
|||
virtual ~Tray();
|
||||
|
||||
// TrayIconObserver:
|
||||
void OnClicked(const gfx::Rect& bounds) override;
|
||||
void OnDoubleClicked(const gfx::Rect& bounds) override;
|
||||
void OnClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||
void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||
void OnBalloonShow() override;
|
||||
void OnBalloonClicked() override;
|
||||
void OnBalloonClosed() override;
|
||||
void OnRightClicked(const gfx::Rect& bounds) override;
|
||||
void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||
void OnDropFiles(const std::vector<std::string>& files) override;
|
||||
|
||||
// mate::Wrappable:
|
||||
|
|
|
@ -2,16 +2,19 @@
|
|||
#define ATOM_BROWSER_UI_EVENT_UTIL_H_
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
namespace event_util {
|
||||
|
||||
bool isLeftButtonEvent(NSEvent* event);
|
||||
bool isRightButtonEvent(NSEvent* event);
|
||||
bool isMiddleButtonEvent(NSEvent* event);
|
||||
bool IsLeftButtonEvent(NSEvent* event);
|
||||
bool IsRightButtonEvent(NSEvent* event);
|
||||
bool IsMiddleButtonEvent(NSEvent* event);
|
||||
|
||||
// Retrieves a bitsum of ui::EventFlags from NSEvent.
|
||||
int EventFlagsFromNSEvent(NSEvent* event);
|
||||
|
||||
gfx::Rect GetBoundsFromEvent(NSEvent* event);
|
||||
|
||||
} // namespace event_util
|
||||
|
||||
#endif // ATOM_BROWSER_UI_EVENT_UTIL_H_
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
#include "atom/browser/ui/event_util.h"
|
||||
#include "ui/base/accelerators/accelerator.h"
|
||||
|
||||
#include "ui/events/event_constants.h"
|
||||
|
||||
namespace event_util {
|
||||
bool isLeftButtonEvent(NSEvent* event) {
|
||||
|
||||
bool IsLeftButtonEvent(NSEvent* event) {
|
||||
NSEventType type = [event type];
|
||||
return type == NSLeftMouseDown ||
|
||||
type == NSLeftMouseDragged ||
|
||||
type == NSLeftMouseUp;
|
||||
}
|
||||
|
||||
bool isRightButtonEvent(NSEvent* event) {
|
||||
bool IsRightButtonEvent(NSEvent* event) {
|
||||
NSEventType type = [event type];
|
||||
return type == NSRightMouseDown ||
|
||||
type == NSRightMouseDragged ||
|
||||
type == NSRightMouseUp;
|
||||
}
|
||||
|
||||
bool isMiddleButtonEvent(NSEvent* event) {
|
||||
bool IsMiddleButtonEvent(NSEvent* event) {
|
||||
if ([event buttonNumber] != 2)
|
||||
return false;
|
||||
|
||||
|
@ -33,9 +35,9 @@ namespace event_util {
|
|||
flags |= (modifiers & NSControlKeyMask) ? ui::EF_CONTROL_DOWN : 0;
|
||||
flags |= (modifiers & NSAlternateKeyMask) ? ui::EF_ALT_DOWN : 0;
|
||||
flags |= (modifiers & NSCommandKeyMask) ? ui::EF_COMMAND_DOWN : 0;
|
||||
flags |= isLeftButtonEvent(event) ? ui::EF_LEFT_MOUSE_BUTTON : 0;
|
||||
flags |= isRightButtonEvent(event) ? ui::EF_RIGHT_MOUSE_BUTTON : 0;
|
||||
flags |= isMiddleButtonEvent(event) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0;
|
||||
flags |= IsLeftButtonEvent(event) ? ui::EF_LEFT_MOUSE_BUTTON : 0;
|
||||
flags |= IsRightButtonEvent(event) ? ui::EF_RIGHT_MOUSE_BUTTON : 0;
|
||||
flags |= IsMiddleButtonEvent(event) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0;
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
@ -44,4 +46,20 @@ namespace event_util {
|
|||
NSUInteger modifiers = [event modifierFlags];
|
||||
return EventFlagsFromNSEventWithModifiers(event, modifiers);
|
||||
}
|
||||
|
||||
gfx::Rect GetBoundsFromEvent(NSEvent* event) {
|
||||
NSRect frame = event.window.frame;
|
||||
|
||||
gfx::Rect bounds(
|
||||
frame.origin.x,
|
||||
0,
|
||||
NSWidth(frame),
|
||||
NSHeight(frame)
|
||||
);
|
||||
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
|
||||
return bounds;
|
||||
}
|
||||
|
||||
} // namespace event_util
|
||||
|
|
|
@ -29,12 +29,14 @@ void TrayIcon::DisplayBalloon(const gfx::Image& icon,
|
|||
void TrayIcon::PopContextMenu(const gfx::Point& pos) {
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyClicked(const gfx::Rect& bounds) {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked(bounds));
|
||||
void TrayIcon::NotifyClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_,
|
||||
OnClicked(bounds, modifiers));
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyDoubleClicked(const gfx::Rect& bounds) {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDoubleClicked(bounds));
|
||||
void TrayIcon::NotifyDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_,
|
||||
OnDoubleClicked(bounds, modifiers));
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyBalloonShow() {
|
||||
|
@ -49,8 +51,9 @@ void TrayIcon::NotifyBalloonClosed() {
|
|||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnBalloonClosed());
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyRightClicked(const gfx::Rect& bounds) {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnRightClicked(bounds));
|
||||
void TrayIcon::NotifyRightClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
FOR_EACH_OBSERVER(TrayIconObserver, observers_,
|
||||
OnRightClicked(bounds, modifiers));
|
||||
}
|
||||
|
||||
void TrayIcon::NotfiyDropFiles(const std::vector<std::string>& files) {
|
||||
|
|
|
@ -54,12 +54,13 @@ class TrayIcon {
|
|||
|
||||
void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
|
||||
void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
|
||||
void NotifyClicked(const gfx::Rect& = gfx::Rect());
|
||||
void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect());
|
||||
void NotifyClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
|
||||
void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
|
||||
void NotifyBalloonShow();
|
||||
void NotifyBalloonClicked();
|
||||
void NotifyBalloonClosed();
|
||||
void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect());
|
||||
void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(),
|
||||
int modifiers = 0);
|
||||
void NotfiyDropFiles(const std::vector<std::string>& files);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "atom/browser/ui/tray_icon_cocoa.h"
|
||||
|
||||
#include "atom/browser/ui/cocoa/atom_menu_controller.h"
|
||||
#include "atom/browser/ui/event_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "ui/gfx/screen.h"
|
||||
|
@ -147,16 +148,21 @@ const CGFloat kMargin = 3;
|
|||
return;
|
||||
}
|
||||
inMouseEventSequence_ = NO;
|
||||
|
||||
// Single click
|
||||
if (event.clickCount == 1) {
|
||||
if (menuController_) {
|
||||
[statusItem_ popUpStatusItemMenu:[menuController_ menu]];
|
||||
}
|
||||
|
||||
trayIcon_->NotifyClicked([self getBoundsFromEvent:event]);
|
||||
trayIcon_->NotifyClicked(event_util::GetBoundsFromEvent(event),
|
||||
event_util::EventFlagsFromNSEvent(event));
|
||||
}
|
||||
|
||||
// Double click
|
||||
if (event.clickCount == 2 && !menuController_) {
|
||||
trayIcon_->NotifyDoubleClicked([self getBoundsFromEvent:event]);
|
||||
trayIcon_->NotifyDoubleClicked(event_util::GetBoundsFromEvent(event),
|
||||
event_util::EventFlagsFromNSEvent(event));
|
||||
}
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
@ -173,7 +179,8 @@ const CGFloat kMargin = 3;
|
|||
}
|
||||
|
||||
- (void)rightMouseUp:(NSEvent*)event {
|
||||
trayIcon_->NotifyRightClicked([self getBoundsFromEvent:event]);
|
||||
trayIcon_->NotifyRightClicked(event_util::GetBoundsFromEvent(event),
|
||||
event_util::EventFlagsFromNSEvent(event));
|
||||
}
|
||||
|
||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
|
||||
|
@ -199,13 +206,6 @@ const CGFloat kMargin = 3;
|
|||
return isHighlightEnable_ && (inMouseEventSequence_ || is_menu_open);
|
||||
}
|
||||
|
||||
- (gfx::Rect)getBoundsFromEvent:(NSEvent*)event {
|
||||
NSRect frame = event.window.frame;
|
||||
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
|
||||
return bounds;
|
||||
}
|
||||
@end
|
||||
|
||||
namespace atom {
|
||||
|
|
|
@ -16,12 +16,12 @@ namespace atom {
|
|||
|
||||
class TrayIconObserver {
|
||||
public:
|
||||
virtual void OnClicked(const gfx::Rect& bounds) {}
|
||||
virtual void OnDoubleClicked(const gfx::Rect& bounds) {}
|
||||
virtual void OnClicked(const gfx::Rect& bounds, int modifiers) {}
|
||||
virtual void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {}
|
||||
virtual void OnBalloonShow() {}
|
||||
virtual void OnBalloonClicked() {}
|
||||
virtual void OnBalloonClosed() {}
|
||||
virtual void OnRightClicked(const gfx::Rect& bounds) {}
|
||||
virtual void OnRightClicked(const gfx::Rect& bounds, int modifiers) {}
|
||||
virtual void OnDropFiles(const std::vector<std::string>& files) {}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -53,6 +53,7 @@ Creates a new tray icon associated with the `image`.
|
|||
* `y` Integer
|
||||
* `width` Integer
|
||||
* `height` Integer
|
||||
* [`modifiers`](https://code.google.com/p/chromium/codesearch#chromium/src/ui/events/event_constants.h&l=77) number - bitsum of keyboard modifiers and mouse keys
|
||||
|
||||
Emitted when the tray icon is clicked.
|
||||
|
||||
|
@ -66,6 +67,7 @@ __Note:__ The `bounds` payload is only implemented on OS X and Windows 7 or newe
|
|||
* `y` Integer
|
||||
* `width` Integer
|
||||
* `height` Integer
|
||||
* [`modifiers`](https://code.google.com/p/chromium/codesearch#chromium/src/ui/events/event_constants.h&l=77) number - bitsum of keyboard modifiers and mouse keys
|
||||
|
||||
Emitted when the tray icon is right clicked.
|
||||
|
||||
|
@ -82,7 +84,8 @@ Emitted when the tray icon is double clicked.
|
|||
* `y` Integer
|
||||
* `width` Integer
|
||||
* `height` Integer
|
||||
|
||||
* [`modifiers`](https://code.google.com/p/chromium/codesearch#chromium/src/ui/events/event_constants.h&l=77) number - bitsum of keyboard modifiers and mouse keys
|
||||
|
||||
__Note:__ This is only implemented on OS X.
|
||||
|
||||
### Event: 'balloon-show'
|
||||
|
|
Loading…
Reference in a new issue