Flutter macOS Embedder
FlutterMenuPlugin.mm File Reference

Go to the source code of this file.

Classes

class  FlutterMenuDelegate
 

Functions

static NSDictionary< NSNumber *, NSNumber * > * GetMacOsSpecialKeys ()
 
static const std::map< flutter::PlatformProvidedMenu, SEL > GetMacOSProvidedMenus ()
 
static NSEventModifierFlags KeyEquivalentModifierMaskForModifiers (NSNumber *modifiers)
 

Variables

static NSString *const kChannelName = @"@"flutter/menu"
 
static NSString *const kIsPluginAvailableMethod = @"@"Menu.isPluginAvailable"
 
static NSString *const kMenuSetMenusMethod = @"@"Menu.setMenus"
 
static NSString *const kMenuSelectedCallbackMethod = @"@"Menu.selectedCallback"
 
static NSString *const kMenuOpenedMethod = @"@"Menu.opened"
 
static NSString *const kMenuClosedMethod = @"@"Menu.closed"
 
static NSString *const kIdKey = @"@"id"
 
static NSString *const kLabelKey = @"@"label"
 
static NSString *const kEnabledKey = @"@"enabled"
 
static NSString *const kChildrenKey = @"@"children"
 
static NSString *const kDividerKey = @"@"isDivider"
 
static NSString *const kShortcutCharacterKey = @"@"shortcutCharacter"
 
static NSString *const kShortcutTriggerKey = @"@"shortcutTrigger"
 
static NSString *const kShortcutModifiersKey = @"@"shortcutModifiers"
 
static NSString *const kPlatformProvidedMenuKey = @"@"platformProvidedMenu"
 
constexpr int kFlutterShortcutModifierMeta = 1 << 0
 
constexpr int kFlutterShortcutModifierShift = 1 << 1
 
constexpr int kFlutterShortcutModifierAlt = 1 << 2
 
constexpr int kFlutterShortcutModifierControl = 1 << 3
 
constexpr uint64_t kFlutterKeyIdPlaneMask = 0xff00000000l
 
constexpr uint64_t kFlutterKeyIdUnicodePlane = 0x0000000000l
 
constexpr uint64_t kFlutterKeyIdValueMask = 0x00ffffffffl
 
static const NSDictionary * logicalKeyToKeyCode = {}
 
static NSString *const kAppName = @"@"APP_NAME"
 
int64_t _identifier
 
NSArray< NSMenuItem * > * _platformProvidedItems
 
NSMutableArray< FlutterMenuDelegate * > * _menuDelegates
 

Function Documentation

◆ GetMacOSProvidedMenus()

static const std::map<flutter::PlatformProvidedMenu, SEL> GetMacOSProvidedMenus ( )
static

The mapping from the PlatformProvidedMenu enum to the macOS selectors for the provided menus.

Definition at line 111 of file FlutterMenuPlugin.mm.

111  {
112  return {
113  {flutter::PlatformProvidedMenu::kAbout, @selector(orderFrontStandardAboutPanel:)},
114  {flutter::PlatformProvidedMenu::kQuit, @selector(terminate:)},
115  // servicesSubmenu is handled specially below: it is assumed to be the first
116  // submenu in the preserved platform provided menus, since it doesn't have a
117  // definitive selector like the rest.
118  {flutter::PlatformProvidedMenu::kServicesSubmenu, @selector(submenuAction:)},
119  {flutter::PlatformProvidedMenu::kHide, @selector(hide:)},
120  {flutter::PlatformProvidedMenu::kHideOtherApplications, @selector(hideOtherApplications:)},
121  {flutter::PlatformProvidedMenu::kShowAllApplications, @selector(unhideAllApplications:)},
122  {flutter::PlatformProvidedMenu::kStartSpeaking, @selector(startSpeaking:)},
123  {flutter::PlatformProvidedMenu::kStopSpeaking, @selector(stopSpeaking:)},
124  {flutter::PlatformProvidedMenu::kToggleFullScreen, @selector(toggleFullScreen:)},
125  {flutter::PlatformProvidedMenu::kMinimizeWindow, @selector(performMiniaturize:)},
126  {flutter::PlatformProvidedMenu::kZoomWindow, @selector(performZoom:)},
127  {flutter::PlatformProvidedMenu::kArrangeWindowsInFront, @selector(arrangeInFront:)},
128  };
129 }

References flutter::kAbout, flutter::kArrangeWindowsInFront, flutter::kHide, flutter::kHideOtherApplications, flutter::kMinimizeWindow, flutter::kQuit, flutter::kServicesSubmenu, flutter::kShowAllApplications, flutter::kStartSpeaking, flutter::kStopSpeaking, flutter::kToggleFullScreen, and flutter::kZoomWindow.

◆ GetMacOsSpecialKeys()

static NSDictionary<NSNumber*, NSNumber*>* GetMacOsSpecialKeys ( )
static

Maps the string used by NSMenuItem for the given special key equivalent. Keys are the logical key ids of matching trigger keys.

Definition at line 63 of file FlutterMenuPlugin.mm.

63  {
64  return @{
65  @0x00100000008 : [NSNumber numberWithInt:NSBackspaceCharacter],
66  @0x00100000009 : [NSNumber numberWithInt:NSTabCharacter],
67  @0x0010000000a : [NSNumber numberWithInt:NSNewlineCharacter],
68  @0x0010000000c : [NSNumber numberWithInt:NSFormFeedCharacter],
69  @0x0010000000d : [NSNumber numberWithInt:NSCarriageReturnCharacter],
70  @0x0010000007f : [NSNumber numberWithInt:NSDeleteCharacter],
71  @0x00100000801 : [NSNumber numberWithInt:NSF1FunctionKey],
72  @0x00100000802 : [NSNumber numberWithInt:NSF2FunctionKey],
73  @0x00100000803 : [NSNumber numberWithInt:NSF3FunctionKey],
74  @0x00100000804 : [NSNumber numberWithInt:NSF4FunctionKey],
75  @0x00100000805 : [NSNumber numberWithInt:NSF5FunctionKey],
76  @0x00100000806 : [NSNumber numberWithInt:NSF6FunctionKey],
77  @0x00100000807 : [NSNumber numberWithInt:NSF7FunctionKey],
78  @0x00100000808 : [NSNumber numberWithInt:NSF8FunctionKey],
79  @0x00100000809 : [NSNumber numberWithInt:NSF9FunctionKey],
80  @0x0010000080a : [NSNumber numberWithInt:NSF10FunctionKey],
81  @0x0010000080b : [NSNumber numberWithInt:NSF11FunctionKey],
82  @0x0010000080c : [NSNumber numberWithInt:NSF12FunctionKey],
83  @0x0010000080d : [NSNumber numberWithInt:NSF13FunctionKey],
84  @0x0010000080e : [NSNumber numberWithInt:NSF14FunctionKey],
85  @0x0010000080f : [NSNumber numberWithInt:NSF15FunctionKey],
86  @0x00100000810 : [NSNumber numberWithInt:NSF16FunctionKey],
87  @0x00100000811 : [NSNumber numberWithInt:NSF17FunctionKey],
88  @0x00100000812 : [NSNumber numberWithInt:NSF18FunctionKey],
89  @0x00100000813 : [NSNumber numberWithInt:NSF19FunctionKey],
90  @0x00100000814 : [NSNumber numberWithInt:NSF20FunctionKey],
91 
92  // For some reason, there don't appear to be constants for these in ObjC. In
93  // Swift, there is a class with static members for these: KeyEquivalent. The
94  // values below are taken from that (where they don't already appear above).
95  @0x00100000302 : @0xf702, // ArrowLeft
96  @0x00100000303 : @0xf703, // ArrowRight
97  @0x00100000304 : @0xf700, // ArrowUp
98  @0x00100000301 : @0xf701, // ArrowDown
99  @0x00100000306 : @0xf729, // Home
100  @0x00100000305 : @0xf72B, // End
101  @0x00100000308 : @0xf72c, // PageUp
102  @0x00100000307 : @0xf72d, // PageDown
103  @0x0010000001b : @0x001B, // Escape
104  };
105 }

◆ KeyEquivalentModifierMaskForModifiers()

static NSEventModifierFlags KeyEquivalentModifierMaskForModifiers ( NSNumber *  modifiers)
static

Returns the NSEventModifierFlags of |modifiers|, a value from kShortcutKeyModifiers.

Definition at line 135 of file FlutterMenuPlugin.mm.

135  {
136  int flutterModifierFlags = modifiers.intValue;
137  NSEventModifierFlags flags = 0;
138  if (flutterModifierFlags & kFlutterShortcutModifierMeta) {
139  flags |= NSEventModifierFlagCommand;
140  }
141  if (flutterModifierFlags & kFlutterShortcutModifierShift) {
142  flags |= NSEventModifierFlagShift;
143  }
144  if (flutterModifierFlags & kFlutterShortcutModifierAlt) {
145  flags |= NSEventModifierFlagOption;
146  }
147  if (flutterModifierFlags & kFlutterShortcutModifierControl) {
148  flags |= NSEventModifierFlagControl;
149  }
150  // There are also modifier flags for things like the function (Fn) key, but
151  // the framework doesn't support those.
152  return flags;
153 }

References kFlutterShortcutModifierAlt, kFlutterShortcutModifierControl, kFlutterShortcutModifierMeta, and kFlutterShortcutModifierShift.

Variable Documentation

◆ _identifier

int64_t _identifier
Initial value:

Definition at line 169 of file FlutterMenuPlugin.mm.

Referenced by FlutterMenuDelegate::initWithIdentifier:channel:.

◆ _menuDelegates

NSMutableArray<FlutterMenuDelegate*>* _menuDelegates

Definition at line 229 of file FlutterMenuPlugin.mm.

◆ _platformProvidedItems

NSArray<NSMenuItem*>* _platformProvidedItems
Initial value:

Definition at line 220 of file FlutterMenuPlugin.mm.

◆ kAppName

NSString* const kAppName = @"@"APP_NAME"
static

Definition at line 45 of file FlutterMenuPlugin.mm.

◆ kChannelName

NSString* const kChannelName = @"@"flutter/menu"
static

Definition at line 14 of file FlutterMenuPlugin.mm.

◆ kChildrenKey

NSString* const kChildrenKey = @"@"children"
static

Definition at line 25 of file FlutterMenuPlugin.mm.

◆ kDividerKey

NSString* const kDividerKey = @"@"isDivider"
static

Definition at line 26 of file FlutterMenuPlugin.mm.

◆ kEnabledKey

NSString* const kEnabledKey = @"@"enabled"
static

Definition at line 24 of file FlutterMenuPlugin.mm.

◆ kFlutterKeyIdPlaneMask

constexpr uint64_t kFlutterKeyIdPlaneMask = 0xff00000000l
constexpr

Definition at line 38 of file FlutterMenuPlugin.mm.

◆ kFlutterKeyIdUnicodePlane

constexpr uint64_t kFlutterKeyIdUnicodePlane = 0x0000000000l
constexpr

Definition at line 39 of file FlutterMenuPlugin.mm.

◆ kFlutterKeyIdValueMask

constexpr uint64_t kFlutterKeyIdValueMask = 0x00ffffffffl
constexpr

Definition at line 40 of file FlutterMenuPlugin.mm.

◆ kFlutterShortcutModifierAlt

constexpr int kFlutterShortcutModifierAlt = 1 << 2
constexpr

Definition at line 35 of file FlutterMenuPlugin.mm.

Referenced by KeyEquivalentModifierMaskForModifiers().

◆ kFlutterShortcutModifierControl

constexpr int kFlutterShortcutModifierControl = 1 << 3
constexpr

Definition at line 36 of file FlutterMenuPlugin.mm.

Referenced by KeyEquivalentModifierMaskForModifiers().

◆ kFlutterShortcutModifierMeta

constexpr int kFlutterShortcutModifierMeta = 1 << 0
constexpr

Definition at line 33 of file FlutterMenuPlugin.mm.

Referenced by KeyEquivalentModifierMaskForModifiers().

◆ kFlutterShortcutModifierShift

constexpr int kFlutterShortcutModifierShift = 1 << 1
constexpr

Definition at line 34 of file FlutterMenuPlugin.mm.

Referenced by KeyEquivalentModifierMaskForModifiers().

◆ kIdKey

NSString* const kIdKey = @"@"id"
static

Definition at line 22 of file FlutterMenuPlugin.mm.

◆ kIsPluginAvailableMethod

NSString* const kIsPluginAvailableMethod = @"@"Menu.isPluginAvailable"
static

Definition at line 15 of file FlutterMenuPlugin.mm.

◆ kLabelKey

NSString* const kLabelKey = @"@"label"
static

Definition at line 23 of file FlutterMenuPlugin.mm.

◆ kMenuClosedMethod

NSString* const kMenuClosedMethod = @"@"Menu.closed"
static

Definition at line 19 of file FlutterMenuPlugin.mm.

◆ kMenuOpenedMethod

NSString* const kMenuOpenedMethod = @"@"Menu.opened"
static

Definition at line 18 of file FlutterMenuPlugin.mm.

◆ kMenuSelectedCallbackMethod

NSString* const kMenuSelectedCallbackMethod = @"@"Menu.selectedCallback"
static

Definition at line 17 of file FlutterMenuPlugin.mm.

◆ kMenuSetMenusMethod

NSString* const kMenuSetMenusMethod = @"@"Menu.setMenus"
static

Definition at line 16 of file FlutterMenuPlugin.mm.

◆ kPlatformProvidedMenuKey

NSString* const kPlatformProvidedMenuKey = @"@"platformProvidedMenu"
static

Definition at line 30 of file FlutterMenuPlugin.mm.

◆ kShortcutCharacterKey

NSString* const kShortcutCharacterKey = @"@"shortcutCharacter"
static

Definition at line 27 of file FlutterMenuPlugin.mm.

◆ kShortcutModifiersKey

NSString* const kShortcutModifiersKey = @"@"shortcutModifiers"
static

Definition at line 29 of file FlutterMenuPlugin.mm.

◆ kShortcutTriggerKey

NSString* const kShortcutTriggerKey = @"@"shortcutTrigger"
static

Definition at line 28 of file FlutterMenuPlugin.mm.

◆ logicalKeyToKeyCode

const NSDictionary* logicalKeyToKeyCode = {}
static

Definition at line 42 of file FlutterMenuPlugin.mm.

kFlutterShortcutModifierAlt
constexpr int kFlutterShortcutModifierAlt
Definition: FlutterMenuPlugin.mm:35
flutter::PlatformProvidedMenu::kServicesSubmenu
@ kServicesSubmenu
kFlutterShortcutModifierShift
constexpr int kFlutterShortcutModifierShift
Definition: FlutterMenuPlugin.mm:34
FlutterMethodChannel
Definition: FlutterChannels.h:220
flutter::PlatformProvidedMenu::kStopSpeaking
@ kStopSpeaking
kFlutterShortcutModifierControl
constexpr int kFlutterShortcutModifierControl
Definition: FlutterMenuPlugin.mm:36
flutter::PlatformProvidedMenu::kMinimizeWindow
@ kMinimizeWindow
kFlutterShortcutModifierMeta
constexpr int kFlutterShortcutModifierMeta
Definition: FlutterMenuPlugin.mm:33
flutter::PlatformProvidedMenu::kToggleFullScreen
@ kToggleFullScreen
flutter::PlatformProvidedMenu::kStartSpeaking
@ kStartSpeaking
flutter::PlatformProvidedMenu::kHideOtherApplications
@ kHideOtherApplications
flutter::PlatformProvidedMenu::kArrangeWindowsInFront
@ kArrangeWindowsInFront
flutter::PlatformProvidedMenu::kAbout
@ kAbout
flutter::PlatformProvidedMenu::kShowAllApplications
@ kShowAllApplications
flutter::PlatformProvidedMenu::kQuit
@ kQuit
flutter::PlatformProvidedMenu::kZoomWindow
@ kZoomWindow
flutter::PlatformProvidedMenu::kHide
@ kHide