diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index fd44588098fb..a9eddb0ca04b 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -7,6 +7,7 @@ #include #include +#include "atom/browser/ui/cocoa/touch_bar_forward_declarations.h" #include "atom/browser/window_list.h" #include "atom/common/color_util.h" #include "atom/common/draggable_region.h" @@ -355,14 +356,14 @@ bool ScopedDisableResize::disable_resize_ = false; - (void)reloadTouchBar; - (void)refreshTouchBarItem:(mate::Arguments*)args; - (void)resetTouchBar; -- (NSTouchBar*)touchBarFromMutatableArray:(NSMutableArray*)items; +- (NSTouchBar*)touchBarFromMutatableArray:(NSMutableArray*)items; @end @interface AtomNSWindow () @end @implementation AtomNSWindow - NSMutableArray* bar_items_ = [[NSMutableArray alloc] init]; + NSMutableArray* bar_items_ = [[NSMutableArray alloc] init]; std::map item_id_map; std::map item_map; @@ -376,11 +377,11 @@ bool ScopedDisableResize::disable_resize_ = false; - (void)resetTouchBar { bar_items_ = [[NSMutableArray alloc] init]; - self.touchBar = nil; + // self.touchBar = nil; } -- (NSMutableArray*)identifierArrayFromDicts:(std::vector)dicts { - NSMutableArray* idents = [[NSMutableArray alloc] init]; +- (NSMutableArray*)identifierArrayFromDicts:(std::vector)dicts { + NSMutableArray* idents = [[NSMutableArray alloc] init]; for (mate::PersistentDictionary &item : dicts) { std::string type; @@ -434,15 +435,15 @@ bool ScopedDisableResize::disable_resize_ = false; std::map new_map; item_id_map = new_map; bar_items_ = [self identifierArrayFromDicts:shell_->GetTouchBarItems()]; - self.touchBar = nil; + // self.touchBar = nil; } -- (NSTouchBar *)makeTouchBar { +- (NSTouchBar*)makeTouchBar { return [self touchBarFromMutatableArray:bar_items_]; } -- (NSTouchBar *)touchBarFromMutatableArray:(NSMutableArray*)items { - NSTouchBar* bar = [[NSTouchBar alloc] init]; +- (NSTouchBar*)touchBarFromMutatableArray:(NSMutableArray*)items { + NSTouchBar* bar = [[NSClassFromString(@"NSTouchBar") alloc] init]; bar.delegate = self; bar.defaultItemIdentifiers = [items copy]; @@ -534,7 +535,7 @@ bool ScopedDisableResize::disable_resize_ = false; std::string s_id = std::string([id UTF8String]); if (![self hasTBDict:s_id]) return nil; mate::PersistentDictionary item = item_id_map[s_id]; - NSCustomTouchBarItem *customItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + NSCustomTouchBarItem *customItem = [[NSClassFromString(@"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]; return [self updateButton:customItem withOpts:item withID:id andCreate:true]; } @@ -566,7 +567,7 @@ bool ScopedDisableResize::disable_resize_ = false; std::string s_id = std::string([id UTF8String]); if (![self hasTBDict:s_id]) return nil; mate::PersistentDictionary item = item_id_map[s_id]; - NSCustomTouchBarItem *customItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + NSCustomTouchBarItem *customItem = [[NSClassFromString(@"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]; return [self updateLabel:customItem withOpts:item]; } @@ -591,7 +592,7 @@ bool ScopedDisableResize::disable_resize_ = false; std::string s_id = std::string([id UTF8String]); if (![self hasTBDict:s_id]) return nil; mate::PersistentDictionary item = item_id_map[s_id]; - NSColorPickerTouchBarItem *colorPickerItem = [[NSColorPickerTouchBarItem alloc] initWithIdentifier:identifier]; + NSColorPickerTouchBarItem *colorPickerItem = [[NSClassFromString(@"NSColorPickerTouchBarItem") alloc] initWithIdentifier:identifier]; return [self updateColorPicker:colorPickerItem withOpts:item]; } @@ -611,7 +612,7 @@ bool ScopedDisableResize::disable_resize_ = false; std::string s_id = std::string([id UTF8String]); if (![self hasTBDict:s_id]) return nil; mate::PersistentDictionary item = item_id_map[s_id]; - NSSliderTouchBarItem *sliderItem = [[NSSliderTouchBarItem alloc] initWithIdentifier:identifier]; + NSSliderTouchBarItem *sliderItem = [[NSClassFromString(@"NSSliderTouchBarItem") alloc] initWithIdentifier:identifier]; return [self updateSlider:sliderItem withOpts:item]; } @@ -647,7 +648,7 @@ bool ScopedDisableResize::disable_resize_ = false; std::string s_id = std::string([id UTF8String]); if (![self hasTBDict:s_id]) return nil; mate::PersistentDictionary item = item_id_map[s_id]; - NSPopoverTouchBarItem *popOverItem = [[NSPopoverTouchBarItem alloc] initWithIdentifier:identifier]; + NSPopoverTouchBarItem *popOverItem = [[NSClassFromString(@"NSPopoverTouchBarItem") alloc] initWithIdentifier:identifier]; return [self updatePopOver:popOverItem withOpts:item]; } @@ -690,8 +691,8 @@ bool ScopedDisableResize::disable_resize_ = false; return nil; } - NSMutableArray* generatedItems = [[NSMutableArray alloc] init]; - NSMutableArray* identList = [self identifierArrayFromDicts:items]; + NSMutableArray* generatedItems = [[NSMutableArray alloc] init]; + NSMutableArray* identList = [self identifierArrayFromDicts:items]; for (NSUInteger i = 0; i < [identList count]; i++) { if ([identList objectAtIndex:i] != NSTouchBarItemIdentifierOtherItemsProxy) { NSTouchBarItem* generatedItem = [self makeItemForIdentifier:[identList objectAtIndex:i]]; @@ -700,7 +701,7 @@ bool ScopedDisableResize::disable_resize_ = false; } } } - NSGroupTouchBarItem *groupItem = [NSGroupTouchBarItem groupItemWithIdentifier:identifier items:generatedItems]; + NSGroupTouchBarItem *groupItem = [NSClassFromString(@"NSGroupTouchBarItem") groupItemWithIdentifier:identifier items:generatedItems]; std::string customizationLabel; if (item.Get("customizationLabel", &customizationLabel)) { diff --git a/atom/browser/ui/cocoa/touch_bar_forward_declarations.h b/atom/browser/ui/cocoa/touch_bar_forward_declarations.h new file mode 100644 index 000000000000..c6fdd1f79137 --- /dev/null +++ b/atom/browser/ui/cocoa/touch_bar_forward_declarations.h @@ -0,0 +1,169 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_UI_COCOA_TOUCH_BAR_FORWARD_DECLARATIONS_H_ +#define ATOM_BROWSER_UI_COCOA_TOUCH_BAR_FORWARD_DECLARATIONS_H_ + +// Once Chrome no longer supports OSX 10.12.0, this file can be deleted. + +#import + +#if !defined(MAC_OS_X_VERSION_10_12_1) + +#pragma clang assume_nonnull begin + +@class NSTouchBar, NSTouchBarItem; +@protocol NSTouchBarDelegate; + +typedef float NSTouchBarItemPriority; +static const NSTouchBarItemPriority NSTouchBarItemPriorityHigh = 1000; +static const NSTouchBarItemPriority NSTouchBarItemPriorityNormal = 0; +static const NSTouchBarItemPriority NSTouchBarItemPriorityLow = -1000; + +typedef NSString* NSTouchBarItemIdentifier; +typedef NSString* NSTouchBarCustomizationIdentifier; + +static const NSTouchBarItemIdentifier NSTouchBarItemIdentifierFixedSpaceSmall = + @"NSTouchBarItemIdentifierFixedSpaceSmall"; + +static const NSTouchBarItemIdentifier NSTouchBarItemIdentifierFlexibleSpace = + @"NSTouchBarItemIdentifierFlexibleSpace"; + +static const NSTouchBarItemIdentifier NSTouchBarItemIdentifierOtherItemsProxy = + @"NSTouchBarItemIdentifierOtherItemsProxy"; + +@interface NSTouchBar : NSObject + +- (instancetype)init NS_DESIGNATED_INITIALIZER; +- (nullable instancetype)initWithCoder:(NSCoder*)aDecoder + NS_DESIGNATED_INITIALIZER; + +@property(copy, nullable) + NSTouchBarCustomizationIdentifier customizationIdentifier; +@property(copy) NSArray* customizationAllowedItemIdentifiers; +@property(copy) NSArray* customizationRequiredItemIdentifiers; +@property(copy) NSArray* defaultItemIdentifiers; +@property(copy, readonly) NSArray* itemIdentifiers; +@property(copy, nullable) NSTouchBarItemIdentifier principalItemIdentifier; +@property(copy) NSSet* templateItems; +@property(nullable, weak) id delegate; + +- (nullable __kindof NSTouchBarItem*)itemForIdentifier: + (NSTouchBarItemIdentifier)identifier; + +@property(readonly, getter=isVisible) BOOL visible; + +@end + +@interface NSTouchBarItem : NSObject + +- (instancetype)initWithIdentifier:(NSTouchBarItemIdentifier)identifier + NS_DESIGNATED_INITIALIZER; +- (nullable instancetype)initWithCoder:(NSCoder*)coder + NS_DESIGNATED_INITIALIZER; +- (instancetype)init NS_UNAVAILABLE; + +@property(readonly, copy) NSTouchBarItemIdentifier identifier; +@property NSTouchBarItemPriority visibilityPriority; +@property(readonly, nullable) NSView* view; +@property(readonly, nullable) NSViewController* viewController; +@property(readwrite, copy) NSString* customizationLabel; +@property(readonly, getter=isVisible) BOOL visible; + +@end + +@interface NSGroupTouchBarItem : NSTouchBarItem + ++ (NSGroupTouchBarItem*)groupItemWithIdentifier: + (NSTouchBarItemIdentifier)identifier + items:(NSArray*)items; + +@property(strong) NSTouchBar* groupTouchBar; +@property(readwrite, copy, null_resettable) NSString* customizationLabel; + +@end + +@interface NSCustomTouchBarItem : NSTouchBarItem + +@property(readwrite, strong) __kindof NSView* view; +@property(readwrite, strong, nullable) + __kindof NSViewController* viewController; +@property(readwrite, copy, null_resettable) NSString* customizationLabel; + +@end + +@interface NSColorPickerTouchBarItem : NSTouchBarItem + +@property SEL action; +@property(weak) id target; +@property(copy) NSColor *color; + +@end + +@interface NSPopoverTouchBarItem : NSTouchBarItem + +@property BOOL showsCloseButton; +@property(strong) NSImage *collapsedRepresentationImage; +@property(strong) NSString *collapsedRepresentationLabel; +@property(strong) NSTouchBar *popoverTouchBar; + +@end + +@interface NSSliderTouchBarItem : NSTouchBarItem + +@property SEL action; +@property(weak) id target; +@property(copy) NSString *label; +@property(strong) NSSlider *slider; + +@end + +@interface NSWindow (TouchBarSDK) + +@property(strong, readonly) NSTouchBar* touchBar; + +@end + +@interface NSButton (TouchBarSDK) + +@property(copy) NSColor *bezelColor; ++ (instancetype)buttonWithTitle:(NSString *)title + target:(id)target + action:(SEL)action; + +@end + +@interface NSTextField (TouchBarSDK) + ++ (instancetype)labelWithString:(NSString *)stringValue; + +@end + +@protocol NSTouchBarDelegate + +@optional +- (nullable NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar + makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier; +@end + +#pragma clang assume_nonnull end + +#elif MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12_1 + +// When compiling against the 10.12.1 SDK or later, just provide forward +// declarations to suppress the partial availability warnings. + +@class NSCustomTouchBarItem; +@class NSGroupTouchBarItem; +@class NSTouchBar; +@protocol NSTouchBarDelegate; +@class NSTouchBarItem; + +@interface NSWindow (TouchBarSDK) +@property(strong, readonly) NSTouchBar* touchBar; +@end + +#endif // MAC_OS_X_VERSION_10_12_1 + +#endif // ATOM_BROWSER_UI_COCOA_TOUCH_BAR_FORWARD_DECLARATIONS_H_ diff --git a/filenames.gypi b/filenames.gypi index 0e4ad206267c..a1758e2acff0 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -281,6 +281,7 @@ 'atom/browser/ui/atom_menu_model.h', 'atom/browser/ui/cocoa/atom_menu_controller.h', 'atom/browser/ui/cocoa/atom_menu_controller.mm', + 'atom/browser/ui/cocoa/touch_bar_forward_declarations.h', 'atom/browser/ui/drag_util_mac.mm', 'atom/browser/ui/drag_util_views.cc', 'atom/browser/ui/drag_util.h',