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
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue