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() {
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) {
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:
#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_
#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;
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;
}
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
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() {
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) {
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:
#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"
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];
}
}
- (void)rightMouseUp:(NSEvent*)event {
- trayIcon_->NotifyRightClicked([self getBoundsFromEvent:event]);
+ trayIcon_->NotifyRightClicked(event_util::GetBoundsFromEvent(event),
+ event_util::EventFlagsFromNSEvent(event));
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
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 {
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:
* `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.
* `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.
* `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'