add mouse-move event and click event position for tray
This commit is contained in:
parent
ee519b7552
commit
0b205019b6
7 changed files with 41 additions and 9 deletions
|
@ -86,8 +86,8 @@ mate::WrappableBase* Tray::New(mate::Handle<NativeImage> image,
|
|||
return new Tray(args->isolate(), args->GetThis(), image);
|
||||
}
|
||||
|
||||
void Tray::OnClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
EmitWithFlags("click", modifiers, bounds);
|
||||
void Tray::OnClicked(const gfx::Rect& bounds, const gfx::Point& location, int modifiers) {
|
||||
EmitWithFlags("click", modifiers, bounds, location);
|
||||
}
|
||||
|
||||
void Tray::OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
|
@ -130,6 +130,10 @@ void Tray::OnMouseExited(const gfx::Point& location, int modifiers) {
|
|||
EmitWithFlags("mouse-leave", modifiers, location);
|
||||
}
|
||||
|
||||
void Tray::OnMouseMoved(const gfx::Point& location, int modifiers) {
|
||||
EmitWithFlags("mouse-move", modifiers, location);
|
||||
}
|
||||
|
||||
void Tray::OnDragEntered() {
|
||||
Emit("drag-enter");
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class Tray : public mate::TrackableObject<Tray>,
|
|||
~Tray() override;
|
||||
|
||||
// TrayIconObserver:
|
||||
void OnClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||
void OnClicked(const gfx::Rect& bounds, const gfx::Point& location, int modifiers) override;
|
||||
void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||
void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
|
||||
void OnBalloonShow() override;
|
||||
|
@ -61,6 +61,7 @@ class Tray : public mate::TrackableObject<Tray>,
|
|||
void OnDragEnded() override;
|
||||
void OnMouseEntered(const gfx::Point& location, int modifiers) override;
|
||||
void OnMouseExited(const gfx::Point& location, int modifiers) override;
|
||||
void OnMouseMoved(const gfx::Point& location, int modifiers) override;
|
||||
|
||||
void SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
||||
void SetPressedImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
|
||||
|
|
|
@ -34,9 +34,9 @@ gfx::Rect TrayIcon::GetBounds() {
|
|||
return gfx::Rect();
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
void TrayIcon::NotifyClicked(const gfx::Rect& bounds, const gfx::Point& location, int modifiers) {
|
||||
for (TrayIconObserver& observer : observers_)
|
||||
observer.OnClicked(bounds, modifiers);
|
||||
observer.OnClicked(bounds, location, modifiers);
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyDoubleClicked(const gfx::Rect& bounds, int modifiers) {
|
||||
|
@ -89,6 +89,11 @@ void TrayIcon::NotifyMouseExited(const gfx::Point& location, int modifiers) {
|
|||
observer.OnMouseExited(location, modifiers);
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyMouseMoved(const gfx::Point& location, int modifiers) {
|
||||
for (TrayIconObserver& observer : observers_)
|
||||
observer.OnMouseMoved(location, modifiers);
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyDragEntered() {
|
||||
for (TrayIconObserver& observer : observers_)
|
||||
observer.OnDragEntered();
|
||||
|
|
|
@ -70,7 +70,7 @@ class TrayIcon {
|
|||
void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
|
||||
void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
|
||||
|
||||
void NotifyClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
|
||||
void NotifyClicked(const gfx::Rect& = gfx::Rect(), const gfx::Point& location = gfx::Point(), int modifiers = 0);
|
||||
void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
|
||||
void NotifyBalloonShow();
|
||||
void NotifyBalloonClicked();
|
||||
|
@ -87,6 +87,8 @@ class TrayIcon {
|
|||
int modifiers = 0);
|
||||
void NotifyMouseExited(const gfx::Point& location = gfx::Point(),
|
||||
int modifiers = 0);
|
||||
void NotifyMouseMoved(const gfx::Point& location = gfx::Point(),
|
||||
int modifiers = 0);
|
||||
|
||||
protected:
|
||||
TrayIcon();
|
||||
|
|
|
@ -57,10 +57,10 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
// Finalize setup by sizing our views
|
||||
[self updateDimensions];
|
||||
|
||||
// Add NSTrackingArea for listening to mouseEnter and mouseExit events
|
||||
// Add NSTrackingArea for listening to mouseEnter, mouseExit, and mouseMove events
|
||||
auto trackingArea = [[[NSTrackingArea alloc]
|
||||
initWithRect:[self bounds]
|
||||
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways
|
||||
options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveAlways
|
||||
owner:self
|
||||
userInfo:nil] autorelease];
|
||||
[self addTrackingArea:trackingArea];
|
||||
|
@ -249,6 +249,7 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
if (event.clickCount == 1)
|
||||
trayIcon_->NotifyClicked(
|
||||
gfx::ScreenRectFromNSRect(event.window.frame),
|
||||
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
||||
ui::EventFlagsFromModifiers([event modifierFlags]));
|
||||
|
||||
// Double click event.
|
||||
|
@ -307,6 +308,12 @@ const CGFloat kVerticalTitleMargin = 2;
|
|||
ui::EventFlagsFromModifiers([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)mouseMoved:(NSEvent*)event {
|
||||
trayIcon_->NotifyMouseMoved(
|
||||
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
||||
ui::EventFlagsFromModifiers([event modifierFlags]));
|
||||
}
|
||||
|
||||
- (void)draggingExited:(id <NSDraggingInfo>)sender {
|
||||
trayIcon_->NotifyDragExited();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace atom {
|
|||
|
||||
class TrayIconObserver {
|
||||
public:
|
||||
virtual void OnClicked(const gfx::Rect& bounds, int modifiers) {}
|
||||
virtual void OnClicked(const gfx::Rect& bounds, const gfx::Point& location, int modifiers) {}
|
||||
virtual void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) {}
|
||||
virtual void OnBalloonShow() {}
|
||||
virtual void OnBalloonClicked() {}
|
||||
|
@ -31,6 +31,7 @@ class TrayIconObserver {
|
|||
virtual void OnDragEnded() {}
|
||||
virtual void OnMouseEntered(const gfx::Point& location, int modifiers) {}
|
||||
virtual void OnMouseExited(const gfx::Point& location, int modifiers) {}
|
||||
virtual void OnMouseMoved(const gfx::Point& location, int modifiers) {}
|
||||
|
||||
protected:
|
||||
virtual ~TrayIconObserver() {}
|
||||
|
|
|
@ -76,6 +76,7 @@ The `Tray` module emits the following events:
|
|||
* `ctrlKey` Boolean
|
||||
* `metaKey` Boolean
|
||||
* `bounds` [Rectangle](structures/rectangle.md) - The bounds of tray icon
|
||||
* `position` [Point](structures/point.md) - The position of the event
|
||||
|
||||
Emitted when the tray icon is clicked.
|
||||
|
||||
|
@ -166,6 +167,17 @@ Emitted when the mouse enters the tray icon.
|
|||
|
||||
Emitted when the mouse exits the tray icon.
|
||||
|
||||
#### Event: 'mouse-move' _macOS_
|
||||
|
||||
* `event` Event
|
||||
* `altKey` Boolean
|
||||
* `shiftKey` Boolean
|
||||
* `ctrlKey` Boolean
|
||||
* `metaKey` Boolean
|
||||
* `position` [Point](structures/point.md) - The position of the event
|
||||
|
||||
Emitted when the mouse moves in the tray icon.
|
||||
|
||||
### Instance Methods
|
||||
|
||||
The `Tray` class has the following methods:
|
||||
|
|
Loading…
Reference in a new issue