]> khamidou — GitHub mirrors - electron.git/commitdiff
Merge branch 'feature/modifiers-click-tray' of https://github.com/nishanths/electron...
authorCheng Zhao <zcbenz@gmail.com>
Wed, 29 Jul 2015 04:01:27 +0000 (12:01 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 29 Jul 2015 04:19:17 +0000 (12:19 +0800)
1  2 
atom/browser/ui/cocoa/atom_menu_controller.mm
atom/browser/ui/tray_icon.cc
atom/browser/ui/tray_icon.h
atom/browser/ui/tray_icon_cocoa.mm
docs/api/tray.md

index 176f2db7e1453b5a15df04936440ccd4eb624842,fbfaea94110f9ec5d932d14e81d46bd84fe4d2f0..962dd6b0ad365ce3862e67f9e180cde856b1105a
  #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]));
    }
  }
  
index b22250d35c8f6978f21f406a54e6e46dd0d58b93,d706d81868ebfe6abe6f143614a7dcdb07a49890..cc19be6d8d864c11c99417d26d34e291fab1789a
@@@ -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<std::string>& files) {
index 5e362806f5d61b0f4ac1e20b5aae7c32a422abf8,a60622db9505dd2e3a2210927320b11fa4426700..6d917a53467cb4b066688dbb87a0a24373e9de8b
@@@ -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<std::string>& files);
  
   protected:
index 59386ff8eb4108d20f1ffc2f166d1e9de089cd54,3329619c99a74ca517a5fefcfcf14dc358d98845..0f5a768e5d593289ed4694db37a3c04f56cb18c4
@@@ -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];
  }
  }
  
  - (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 {
index dcb88dd4f75ab6492824e48d73dade7349c2991b,e35a43587331df06c20ce55d1fe785132ba8cccf..47b5d7e3fed69067d12279b0cb29cac562f07fe7
@@@ -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