diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 926caf765ab9..42f24ccf169f 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -17,6 +17,7 @@ @class AtomNSWindow; @class AtomNSWindowDelegate; +@class AtomPreviewItem; @class AtomTouchBar; @class FullSizeContentView; @@ -137,7 +138,8 @@ class NativeWindowMac : public NativeWindow { }; TitleBarStyle title_bar_style() const { return title_bar_style_; } - AtomTouchBar* atom_touch_bar() const { return atom_touch_bar_.get(); } + AtomPreviewItem* preview_item() const { return preview_item_.get(); } + AtomTouchBar* touch_bar() const { return touch_bar_.get(); } bool zoom_to_page_width() const { return zoom_to_page_width_; } bool fullscreen_window_title() const { return fullscreen_window_title_; } bool simple_fullscreen() const { return always_simple_fullscreen_; } @@ -150,7 +152,8 @@ class NativeWindowMac : public NativeWindow { base::scoped_nsobject window_; base::scoped_nsobject window_delegate_; - base::scoped_nsobject atom_touch_bar_; + base::scoped_nsobject preview_item_; + base::scoped_nsobject touch_bar_; std::unique_ptr widget_; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index fa4bffc9cc43..edd9e4b27040 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -5,11 +5,12 @@ #include "atom/browser/native_window_mac.h" #include -#include + #include #include "atom/browser/native_browser_view_mac.h" #include "atom/browser/ui/cocoa/atom_ns_window_delegate.h" +#include "atom/browser/ui/cocoa/atom_preview_item.h" #include "atom/browser/ui/cocoa/atom_touch_bar.h" #include "atom/browser/window_list.h" #include "atom/common/options_switches.h" @@ -165,31 +166,6 @@ bool ScopedDisableResize::disable_resize_ = false; @end -@interface AtomPreviewItem : NSObject - -@property (nonatomic, retain) NSURL* previewItemURL; -@property (nonatomic, retain) NSString* previewItemTitle; - -- (id)initWithURL:(NSURL*)url title:(NSString*)title; - -@end - -@implementation AtomPreviewItem - -@synthesize previewItemURL; -@synthesize previewItemTitle; - -- (id)initWithURL:(NSURL*)url title:(NSString*)title { - self = [super init]; - if (self) { - self.previewItemURL = url; - self.previewItemTitle = title; - } - return self; -} - -@end - #if !defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER) enum { @@ -209,7 +185,7 @@ enum { #endif -@interface AtomNSWindow : EventDispatchingWindow { +@interface AtomNSWindow : EventDispatchingWindow { @private atom::NativeWindowMac* shell_; bool enable_larger_than_screen_; @@ -219,7 +195,6 @@ enum { @property BOOL disableAutoHideCursor; @property BOOL disableKeyOrMainWindow; @property NSPoint windowButtonsOffset; -@property (nonatomic, retain) AtomPreviewItem* quickLookItem; @property (nonatomic, retain) NSView* vibrantView; - (void)setShell:(atom::NativeWindowMac*)shell; @@ -246,8 +221,8 @@ enum { } - (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)) { - if (shell_->atom_touch_bar()) - return [shell_->atom_touch_bar() makeTouchBar]; + if (shell_->touch_bar()) + return [shell_->touch_bar() makeTouchBar]; else return nil; } @@ -400,8 +375,8 @@ enum { } - (void)beginPreviewPanelControl:(QLPreviewPanel*)panel { - panel.delegate = self; - panel.dataSource = self; + panel.delegate = [self delegate]; + panel.dataSource = static_cast>([self delegate]); } - (void)endPreviewPanelControl:(QLPreviewPanel*)panel { @@ -409,20 +384,6 @@ enum { panel.dataSource = nil; } -- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel*)panel { - return 1; -} - -- (id )previewPanel:(QLPreviewPanel*)panel previewItemAtIndex:(NSInteger)index { - return [self quickLookItem]; -} - -- (void)previewFileAtPath:(NSString*)path withName:(NSString*) fileName { - NSURL* url = [[[NSURL alloc] initFileURLWithPath:path] autorelease]; - [self setQuickLookItem:[[[AtomPreviewItem alloc] initWithURL:url title:fileName] autorelease]]; - [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil]; -} - // Custom window button methods - (void)performClose:(id)sender { @@ -1007,9 +968,10 @@ void NativeWindowMac::SetAspectRatio(double aspect_ratio, void NativeWindowMac::PreviewFile(const std::string& path, const std::string& display_name) { - NSString* path_ns = [NSString stringWithUTF8String:path.c_str()]; - NSString* name_ns = [NSString stringWithUTF8String:display_name.c_str()]; - [window_ previewFileAtPath:path_ns withName:name_ns]; + preview_item_.reset([[AtomPreviewItem alloc] + initWithURL:[NSURL fileURLWithPath:base::SysUTF8ToNSString(path)] + title:base::SysUTF8ToNSString(display_name)]); + [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil]; } void NativeWindowMac::CloseFilePreview() { @@ -1507,7 +1469,7 @@ void NativeWindowMac::SetTouchBar( if (![window_ respondsToSelector:@selector(touchBar)]) return; - atom_touch_bar_.reset([[AtomTouchBar alloc] + touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:window_delegate_.get() window:this settings:items]); @@ -1515,14 +1477,14 @@ void NativeWindowMac::SetTouchBar( } void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) { - if (atom_touch_bar_ && [window_ touchBar]) - [atom_touch_bar_ refreshTouchBarItem:[window_ touchBar] id:item_id]; + if (touch_bar_ && [window_ touchBar]) + [touch_bar_ refreshTouchBarItem:[window_ touchBar] id:item_id]; } void NativeWindowMac::SetEscapeTouchBarItem( const mate::PersistentDictionary& item) { - if (atom_touch_bar_ && [window_ touchBar]) - [atom_touch_bar_ setEscapeTouchBarItem:item forTouchBar:[window_ touchBar]]; + if (touch_bar_ && [window_ touchBar]) + [touch_bar_ setEscapeTouchBarItem:item forTouchBar:[window_ touchBar]]; } gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds( diff --git a/atom/browser/ui/cocoa/atom_ns_window_delegate.h b/atom/browser/ui/cocoa/atom_ns_window_delegate.h index 62bcbee35723..0947b0392147 100644 --- a/atom/browser/ui/cocoa/atom_ns_window_delegate.h +++ b/atom/browser/ui/cocoa/atom_ns_window_delegate.h @@ -5,6 +5,8 @@ #ifndef ATOM_BROWSER_UI_COCOA_ATOM_NS_WINDOW_DELEGATE_H_ #define ATOM_BROWSER_UI_COCOA_ATOM_NS_WINDOW_DELEGATE_H_ +#include + #include "ui/views/cocoa/views_nswindow_delegate.h" namespace atom { @@ -12,7 +14,8 @@ class NativeWindowMac; } @interface AtomNSWindowDelegate : NSObject { + NSTouchBarDelegate, + QLPreviewPanelDataSource> { @private atom::NativeWindowMac* shell_; bool is_zooming_; diff --git a/atom/browser/ui/cocoa/atom_ns_window_delegate.mm b/atom/browser/ui/cocoa/atom_ns_window_delegate.mm index 0b71c6af79a5..14857758a77b 100644 --- a/atom/browser/ui/cocoa/atom_ns_window_delegate.mm +++ b/atom/browser/ui/cocoa/atom_ns_window_delegate.mm @@ -6,6 +6,7 @@ #include "atom/browser/browser.h" #include "atom/browser/native_window_mac.h" +#include "atom/browser/ui/cocoa/atom_preview_item.h" #include "atom/browser/ui/cocoa/atom_touch_bar.h" #include "base/mac/mac_util.h" @@ -253,10 +254,21 @@ - (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier API_AVAILABLE(macosx(10.12.2)) { - if (touchBar && shell_->atom_touch_bar()) - return [shell_->atom_touch_bar() makeItemForIdentifier:identifier]; + if (touchBar && shell_->touch_bar()) + return [shell_->touch_bar() makeItemForIdentifier:identifier]; else return nil; } +#pragma mark - QLPreviewPanelDataSource + +- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel*)panel { + return 1; +} + +- (id )previewPanel:(QLPreviewPanel*)panel + previewItemAtIndex:(NSInteger)index { + return shell_->preview_item(); +} + @end diff --git a/atom/browser/ui/cocoa/atom_preview_item.h b/atom/browser/ui/cocoa/atom_preview_item.h new file mode 100644 index 000000000000..aef1d3ff6e2a --- /dev/null +++ b/atom/browser/ui/cocoa/atom_preview_item.h @@ -0,0 +1,17 @@ +// Copyright (c) 2018 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_UI_COCOA_ATOM_PREVIEW_ITEM_H_ +#define ATOM_BROWSER_UI_COCOA_ATOM_PREVIEW_ITEM_H_ + +#import +#import + +@interface AtomPreviewItem : NSObject +@property (nonatomic, retain) NSURL* previewItemURL; +@property (nonatomic, retain) NSString* previewItemTitle; +- (id)initWithURL:(NSURL*)url title:(NSString*)title; +@end + +#endif // ATOM_BROWSER_UI_COCOA_ATOM_PREVIEW_ITEM_H_ diff --git a/atom/browser/ui/cocoa/atom_preview_item.mm b/atom/browser/ui/cocoa/atom_preview_item.mm new file mode 100644 index 000000000000..2bd273d444da --- /dev/null +++ b/atom/browser/ui/cocoa/atom_preview_item.mm @@ -0,0 +1,21 @@ +// Copyright (c) 2018 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/ui/cocoa/atom_preview_item.h" + +@implementation AtomPreviewItem + +@synthesize previewItemURL; +@synthesize previewItemTitle; + +- (id)initWithURL:(NSURL*)url title:(NSString*)title { + self = [super init]; + if (self) { + self.previewItemURL = url; + self.previewItemTitle = title; + } + return self; +} + +@end diff --git a/filenames.gypi b/filenames.gypi index afed5285aa2f..f7d710bf6290 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -320,6 +320,8 @@ 'atom/browser/ui/cocoa/atom_native_widget_mac.mm', 'atom/browser/ui/cocoa/atom_ns_window_delegate.h', 'atom/browser/ui/cocoa/atom_ns_window_delegate.mm', + 'atom/browser/ui/cocoa/atom_preview_item.h', + 'atom/browser/ui/cocoa/atom_preview_item.mm', 'atom/browser/ui/cocoa/atom_touch_bar.h', 'atom/browser/ui/cocoa/atom_touch_bar.mm', 'atom/browser/ui/cocoa/views_delegate_mac.h', diff --git a/script/cpplint.py b/script/cpplint.py index 346a3c18a877..4521c0031154 100755 --- a/script/cpplint.py +++ b/script/cpplint.py @@ -13,6 +13,7 @@ IGNORE_FILES = set(os.path.join(*components) for components in [ ['atom', 'browser', 'resources', 'win', 'resource.h'], ['atom', 'browser', 'ui', 'cocoa', 'atom_menu_controller.h'], ['atom', 'browser', 'ui', 'cocoa', 'atom_ns_window_delegate.h'], + ['atom', 'browser', 'ui', 'cocoa', 'atom_preview_item.h'], ['atom', 'browser', 'ui', 'cocoa', 'atom_touch_bar.h'], ['atom', 'browser', 'ui', 'cocoa', 'touch_bar_forward_declarations.h'], ['atom', 'browser', 'ui', 'cocoa', 'NSColor+Hex.h'],