feat: add mouse-down & mouse-up to Tray (#21795)
This commit is contained in:
Родитель
5feafaceee
Коммит
5c6f9a6947
|
@ -143,6 +143,26 @@ Emitted when a drag operation exits the tray icon.
|
|||
|
||||
Emitted when a drag operation ends on the tray or ends at another location.
|
||||
|
||||
#### Event: 'mouse-up' _macOS_
|
||||
|
||||
Returns:
|
||||
|
||||
* `event` [KeyboardEvent](structures/keyboard-event.md)
|
||||
* `position` [Point](structures/point.md) - The position of the event.
|
||||
|
||||
Emitted when the mouse is released from clicking the tray icon.
|
||||
|
||||
Note: This will not be emitted if you have set a context menu for your Tray using `tray.setContextMenu`, as a result of macOS-level constraints.
|
||||
|
||||
#### Event: 'mouse-down' _macOS_
|
||||
|
||||
Returns:
|
||||
|
||||
* `event` [KeyboardEvent](structures/keyboard-event.md)
|
||||
* `position` [Point](structures/point.md) - The position of the event.
|
||||
|
||||
Emitted when the mouse clicks the tray icon.
|
||||
|
||||
#### Event: 'mouse-enter' _macOS_
|
||||
|
||||
Returns:
|
||||
|
|
|
@ -125,6 +125,14 @@ void Tray::OnMouseMoved(const gfx::Point& location, int modifiers) {
|
|||
EmitWithFlags("mouse-move", modifiers, location);
|
||||
}
|
||||
|
||||
void Tray::OnMouseUp(const gfx::Point& location, int modifiers) {
|
||||
EmitWithFlags("mouse-up", modifiers, location);
|
||||
}
|
||||
|
||||
void Tray::OnMouseDown(const gfx::Point& location, int modifiers) {
|
||||
EmitWithFlags("mouse-down", modifiers, location);
|
||||
}
|
||||
|
||||
void Tray::OnDragEntered() {
|
||||
Emit("drag-enter");
|
||||
}
|
||||
|
|
|
@ -60,6 +60,8 @@ class Tray : public gin_helper::TrackableObject<Tray>, public TrayIconObserver {
|
|||
void OnDragEntered() override;
|
||||
void OnDragExited() override;
|
||||
void OnDragEnded() override;
|
||||
void OnMouseUp(const gfx::Point& location, int modifiers) override;
|
||||
void OnMouseDown(const gfx::Point& location, int modifiers) 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;
|
||||
|
|
|
@ -74,6 +74,16 @@ void TrayIcon::NotifyDropText(const std::string& text) {
|
|||
observer.OnDropText(text);
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyMouseUp(const gfx::Point& location, int modifiers) {
|
||||
for (TrayIconObserver& observer : observers_)
|
||||
observer.OnMouseUp(location, modifiers);
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyMouseDown(const gfx::Point& location, int modifiers) {
|
||||
for (TrayIconObserver& observer : observers_)
|
||||
observer.OnMouseDown(location, modifiers);
|
||||
}
|
||||
|
||||
void TrayIcon::NotifyMouseEntered(const gfx::Point& location, int modifiers) {
|
||||
for (TrayIconObserver& observer : observers_)
|
||||
observer.OnMouseEntered(location, modifiers);
|
||||
|
|
|
@ -105,6 +105,10 @@ class TrayIcon {
|
|||
void NotifyDragEntered();
|
||||
void NotifyDragExited();
|
||||
void NotifyDragEnded();
|
||||
void NotifyMouseUp(const gfx::Point& location = gfx::Point(),
|
||||
int modifiers = 0);
|
||||
void NotifyMouseDown(const gfx::Point& location = gfx::Point(),
|
||||
int modifiers = 0);
|
||||
void NotifyMouseEntered(const gfx::Point& location = gfx::Point(),
|
||||
int modifiers = 0);
|
||||
void NotifyMouseExited(const gfx::Point& location = gfx::Point(),
|
||||
|
|
|
@ -131,6 +131,10 @@
|
|||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent*)event {
|
||||
trayIcon_->NotifyMouseDown(
|
||||
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
||||
ui::EventFlagsFromModifiers([event modifierFlags]));
|
||||
|
||||
// Pass click to superclass to show menu. Custom mouseUp handler won't be
|
||||
// invoked.
|
||||
if (menuController_) {
|
||||
|
@ -143,6 +147,10 @@
|
|||
- (void)mouseUp:(NSEvent*)event {
|
||||
[[statusItem_ button] highlight:NO];
|
||||
|
||||
trayIcon_->NotifyMouseUp(
|
||||
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
||||
ui::EventFlagsFromModifiers([event modifierFlags]));
|
||||
|
||||
// If we are ignoring double click events, we should ignore the `clickCount`
|
||||
// value and immediately emit a click event.
|
||||
BOOL shouldBeHandledAsASingleClick =
|
||||
|
|
|
@ -33,6 +33,8 @@ class TrayIconObserver : public base::CheckedObserver {
|
|||
virtual void OnDragEntered() {}
|
||||
virtual void OnDragExited() {}
|
||||
virtual void OnDragEnded() {}
|
||||
virtual void OnMouseUp(const gfx::Point& location, int modifiers) {}
|
||||
virtual void OnMouseDown(const gfx::Point& location, int modifiers) {}
|
||||
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) {}
|
||||
|
|
Загрузка…
Ссылка в новой задаче