From: Cheng Zhao Date: Wed, 29 Jul 2015 04:01:27 +0000 (+0800) Subject: Merge branch 'feature/modifiers-click-tray' of https://github.com/nishanths/electron... X-Git-Tag: v0.30.2~17 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=edde653d60c46eeebd7d07e60f755ef68f858e55;p=electron.git Merge branch 'feature/modifiers-click-tray' of https://github.com/nishanths/electron into nishanths-feature/modifiers-click-tray --- edde653d60c46eeebd7d07e60f755ef68f858e55 diff --cc atom/browser/ui/cocoa/atom_menu_controller.mm index 176f2db7,fbfaea94..962dd6b0 --- a/atom/browser/ui/cocoa/atom_menu_controller.mm +++ b/atom/browser/ui/cocoa/atom_menu_controller.mm @@@ -11,55 -12,8 +11,9 @@@ #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; @@@ -246,8 -200,8 +200,9 @@@ [[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])); } } diff --cc atom/browser/ui/tray_icon.cc index b22250d3,d706d818..cc19be6d --- a/atom/browser/ui/tray_icon.cc +++ b/atom/browser/ui/tray_icon.cc @@@ -29,12 -29,14 +29,13 @@@ void TrayIcon::DisplayBalloon(const gfx 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() { @@@ -49,8 -51,9 +50,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)); ++ OnRightClicked(bounds, modifiers)); } void TrayIcon::NotfiyDropFiles(const std::vector& files) { diff --cc atom/browser/ui/tray_icon.h index 5e362806,a60622db..6d917a53 --- a/atom/browser/ui/tray_icon.h +++ b/atom/browser/ui/tray_icon.h @@@ -59,7 -59,8 +59,8 @@@ class TrayIcon 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& files); protected: diff --cc atom/browser/ui/tray_icon_cocoa.mm index 59386ff8,3329619c..0f5a768e --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@@ -5,7 -5,8 +5,8 @@@ #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" @@@ -152,11 -155,14 +155,16 @@@ const CGFloat kMargin = 3 [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]; } @@@ -173,7 -179,8 +181,9 @@@ } - (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 )sender { diff --cc docs/api/tray.md index dcb88dd4,e35a4358..47b5d7e3 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@@ -53,6 -53,7 +53,7 @@@ Creates a new tray icon associated wit * `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. @@@ -66,6 -67,7 +67,7 @@@ __Note:__ The `bounds` payload is only * `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. @@@ -80,8 -84,7 +82,9 @@@ will be emitted if the tray icon has co * `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. @@@ -178,3 -181,3 +181,4 @@@ The `position` is only available on Win 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