#include "ui/base/accelerators/platform_accelerator_cocoa.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/models/simple_menu_model.h"
++#include "ui/events/cocoa/cocoa_event_utils.h"
#include "ui/gfx/image/image.h"
- namespace {
-
- bool isLeftButtonEvent(NSEvent* event) {
- NSEventType type = [event type];
- return type == NSLeftMouseDown ||
- type == NSLeftMouseDragged ||
- type == NSLeftMouseUp;
- }
-
- bool isRightButtonEvent(NSEvent* event) {
- NSEventType type = [event type];
- return type == NSRightMouseDown ||
- type == NSRightMouseDragged ||
- type == NSRightMouseUp;
- }
-
- bool isMiddleButtonEvent(NSEvent* event) {
- if ([event buttonNumber] != 2)
- return false;
-
- NSEventType type = [event type];
- return type == NSOtherMouseDown ||
- type == NSOtherMouseDragged ||
- type == NSOtherMouseUp;
- }
-
- int EventFlagsFromNSEventWithModifiers(NSEvent* event, NSUInteger modifiers) {
- int flags = 0;
- flags |= (modifiers & NSAlphaShiftKeyMask) ? ui::EF_CAPS_LOCK_DOWN : 0;
- flags |= (modifiers & NSShiftKeyMask) ? ui::EF_SHIFT_DOWN : 0;
- 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;
- return flags;
- }
-
- // Retrieves a bitsum of ui::EventFlags from NSEvent.
- int EventFlagsFromNSEvent(NSEvent* event) {
- NSUInteger modifiers = [event modifierFlags];
- return EventFlagsFromNSEventWithModifiers(event, modifiers);
- }
-
- } // namespace
-
@interface AtomMenuController (Private)
- (void)addSeparatorToMenu:(NSMenu*)menu
atIndex:(int)index;
[[sender representedObject] pointerValue]);
DCHECK(model);
if (model) {
- int event_flags = EventFlagsFromNSEvent([NSApp currentEvent]);
- int event_flags = event_util::EventFlagsFromNSEvent([NSApp currentEvent]);
-- model->ActivatedAt(modelIndex, event_flags);
++ NSEvent* event = [NSApp currentEvent];
++ model->ActivatedAt(modelIndex,
++ ui::EventFlagsFromModifiers([event modifierFlags]));
}
}
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));
++ 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));
++ 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));
++ OnRightClicked(bounds, modifiers));
}
void TrayIcon::NotfiyDropFiles(const std::vector<std::string>& files) {
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);
++ 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/events/cocoa/cocoa_event_utils.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/screen.h"
[statusItem_ popUpStatusItemMenu:[menuController_ menu]];
}
- trayIcon_->NotifyClicked([self getBoundsFromEvent:event]);
- trayIcon_->NotifyClicked(event_util::GetBoundsFromEvent(event),
- event_util::EventFlagsFromNSEvent(event));
++ trayIcon_->NotifyClicked(
++ [self getBoundsFromEvent:event],
++ ui::EventFlagsFromModifiers([event modifierFlags]));
}
+ // Double click
if (event.clickCount == 2 && !menuController_) {
- trayIcon_->NotifyDoubleClicked([self getBoundsFromEvent:event]);
- trayIcon_->NotifyDoubleClicked(event_util::GetBoundsFromEvent(event),
- event_util::EventFlagsFromNSEvent(event));
++ trayIcon_->NotifyDoubleClicked(
++ [self getBoundsFromEvent:event],
++ ui::EventFlagsFromModifiers([event modifierFlags]));
}
[self setNeedsDisplay:YES];
}
}
- (void)rightMouseUp:(NSEvent*)event {
- trayIcon_->NotifyRightClicked([self getBoundsFromEvent:event]);
- trayIcon_->NotifyRightClicked(event_util::GetBoundsFromEvent(event),
- event_util::EventFlagsFromNSEvent(event));
++ trayIcon_->NotifyRightClicked(
++ [self getBoundsFromEvent:event],
++ ui::EventFlagsFromModifiers([event modifierFlags]));
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
* `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
++* [`modifiers`][modifiers] Integer - 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
++* [`modifiers`][modifiers] Integer - 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
++* [`modifiers`][modifiers] Integer - bitsum of keyboard modifiers and mouse keys
+
+Emitted when the tray icon is double clicked.
__Note:__ This is only implemented on OS X.
Sets the context menu for this icon.
[event-emitter]: http://nodejs.org/api/events.html#events_class_events_eventemitter
++[modifiers]: https://code.google.com/p/chromium/codesearch#chromium/src/ui/events/event_constants.h&l=77