Move QLPreviewPanelDataSource to AtomNSWindowDelegate
This commit is contained in:
parent
f6a7e5ea23
commit
569967ac21
8 changed files with 80 additions and 59 deletions
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
@class AtomNSWindow;
|
@class AtomNSWindow;
|
||||||
@class AtomNSWindowDelegate;
|
@class AtomNSWindowDelegate;
|
||||||
|
@class AtomPreviewItem;
|
||||||
@class AtomTouchBar;
|
@class AtomTouchBar;
|
||||||
@class FullSizeContentView;
|
@class FullSizeContentView;
|
||||||
|
|
||||||
|
@ -137,7 +138,8 @@ class NativeWindowMac : public NativeWindow {
|
||||||
};
|
};
|
||||||
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
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 zoom_to_page_width() const { return zoom_to_page_width_; }
|
||||||
bool fullscreen_window_title() const { return fullscreen_window_title_; }
|
bool fullscreen_window_title() const { return fullscreen_window_title_; }
|
||||||
bool simple_fullscreen() const { return always_simple_fullscreen_; }
|
bool simple_fullscreen() const { return always_simple_fullscreen_; }
|
||||||
|
@ -150,7 +152,8 @@ class NativeWindowMac : public NativeWindow {
|
||||||
|
|
||||||
base::scoped_nsobject<AtomNSWindow> window_;
|
base::scoped_nsobject<AtomNSWindow> window_;
|
||||||
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
||||||
base::scoped_nsobject<AtomTouchBar> atom_touch_bar_;
|
base::scoped_nsobject<AtomPreviewItem> preview_item_;
|
||||||
|
base::scoped_nsobject<AtomTouchBar> touch_bar_;
|
||||||
|
|
||||||
std::unique_ptr<views::Widget> widget_;
|
std::unique_ptr<views::Widget> widget_;
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
#include "atom/browser/native_window_mac.h"
|
#include "atom/browser/native_window_mac.h"
|
||||||
|
|
||||||
#include <AvailabilityMacros.h>
|
#include <AvailabilityMacros.h>
|
||||||
#include <Quartz/Quartz.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "atom/browser/native_browser_view_mac.h"
|
#include "atom/browser/native_browser_view_mac.h"
|
||||||
#include "atom/browser/ui/cocoa/atom_ns_window_delegate.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/ui/cocoa/atom_touch_bar.h"
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
|
@ -165,31 +166,6 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface AtomPreviewItem : NSObject <QLPreviewItem>
|
|
||||||
|
|
||||||
@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)
|
#if !defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -209,7 +185,7 @@ enum {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@interface AtomNSWindow : EventDispatchingWindow<QLPreviewPanelDataSource, QLPreviewPanelDelegate> {
|
@interface AtomNSWindow : EventDispatchingWindow {
|
||||||
@private
|
@private
|
||||||
atom::NativeWindowMac* shell_;
|
atom::NativeWindowMac* shell_;
|
||||||
bool enable_larger_than_screen_;
|
bool enable_larger_than_screen_;
|
||||||
|
@ -219,7 +195,6 @@ enum {
|
||||||
@property BOOL disableAutoHideCursor;
|
@property BOOL disableAutoHideCursor;
|
||||||
@property BOOL disableKeyOrMainWindow;
|
@property BOOL disableKeyOrMainWindow;
|
||||||
@property NSPoint windowButtonsOffset;
|
@property NSPoint windowButtonsOffset;
|
||||||
@property (nonatomic, retain) AtomPreviewItem* quickLookItem;
|
|
||||||
@property (nonatomic, retain) NSView* vibrantView;
|
@property (nonatomic, retain) NSView* vibrantView;
|
||||||
|
|
||||||
- (void)setShell:(atom::NativeWindowMac*)shell;
|
- (void)setShell:(atom::NativeWindowMac*)shell;
|
||||||
|
@ -246,8 +221,8 @@ enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)) {
|
- (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)) {
|
||||||
if (shell_->atom_touch_bar())
|
if (shell_->touch_bar())
|
||||||
return [shell_->atom_touch_bar() makeTouchBar];
|
return [shell_->touch_bar() makeTouchBar];
|
||||||
else
|
else
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -400,8 +375,8 @@ enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)beginPreviewPanelControl:(QLPreviewPanel*)panel {
|
- (void)beginPreviewPanelControl:(QLPreviewPanel*)panel {
|
||||||
panel.delegate = self;
|
panel.delegate = [self delegate];
|
||||||
panel.dataSource = self;
|
panel.dataSource = static_cast<id<QLPreviewPanelDataSource>>([self delegate]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)endPreviewPanelControl:(QLPreviewPanel*)panel {
|
- (void)endPreviewPanelControl:(QLPreviewPanel*)panel {
|
||||||
|
@ -409,20 +384,6 @@ enum {
|
||||||
panel.dataSource = nil;
|
panel.dataSource = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel*)panel {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id <QLPreviewItem>)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
|
// Custom window button methods
|
||||||
|
|
||||||
- (void)performClose:(id)sender {
|
- (void)performClose:(id)sender {
|
||||||
|
@ -1007,9 +968,10 @@ void NativeWindowMac::SetAspectRatio(double aspect_ratio,
|
||||||
|
|
||||||
void NativeWindowMac::PreviewFile(const std::string& path,
|
void NativeWindowMac::PreviewFile(const std::string& path,
|
||||||
const std::string& display_name) {
|
const std::string& display_name) {
|
||||||
NSString* path_ns = [NSString stringWithUTF8String:path.c_str()];
|
preview_item_.reset([[AtomPreviewItem alloc]
|
||||||
NSString* name_ns = [NSString stringWithUTF8String:display_name.c_str()];
|
initWithURL:[NSURL fileURLWithPath:base::SysUTF8ToNSString(path)]
|
||||||
[window_ previewFileAtPath:path_ns withName:name_ns];
|
title:base::SysUTF8ToNSString(display_name)]);
|
||||||
|
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::CloseFilePreview() {
|
void NativeWindowMac::CloseFilePreview() {
|
||||||
|
@ -1507,7 +1469,7 @@ void NativeWindowMac::SetTouchBar(
|
||||||
if (![window_ respondsToSelector:@selector(touchBar)])
|
if (![window_ respondsToSelector:@selector(touchBar)])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
atom_touch_bar_.reset([[AtomTouchBar alloc]
|
touch_bar_.reset([[AtomTouchBar alloc]
|
||||||
initWithDelegate:window_delegate_.get()
|
initWithDelegate:window_delegate_.get()
|
||||||
window:this
|
window:this
|
||||||
settings:items]);
|
settings:items]);
|
||||||
|
@ -1515,14 +1477,14 @@ void NativeWindowMac::SetTouchBar(
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) {
|
void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) {
|
||||||
if (atom_touch_bar_ && [window_ touchBar])
|
if (touch_bar_ && [window_ touchBar])
|
||||||
[atom_touch_bar_ refreshTouchBarItem:[window_ touchBar] id:item_id];
|
[touch_bar_ refreshTouchBarItem:[window_ touchBar] id:item_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetEscapeTouchBarItem(
|
void NativeWindowMac::SetEscapeTouchBarItem(
|
||||||
const mate::PersistentDictionary& item) {
|
const mate::PersistentDictionary& item) {
|
||||||
if (atom_touch_bar_ && [window_ touchBar])
|
if (touch_bar_ && [window_ touchBar])
|
||||||
[atom_touch_bar_ setEscapeTouchBarItem:item forTouchBar:[window_ touchBar]];
|
[touch_bar_ setEscapeTouchBarItem:item forTouchBar:[window_ touchBar]];
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(
|
gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#ifndef ATOM_BROWSER_UI_COCOA_ATOM_NS_WINDOW_DELEGATE_H_
|
#ifndef ATOM_BROWSER_UI_COCOA_ATOM_NS_WINDOW_DELEGATE_H_
|
||||||
#define ATOM_BROWSER_UI_COCOA_ATOM_NS_WINDOW_DELEGATE_H_
|
#define ATOM_BROWSER_UI_COCOA_ATOM_NS_WINDOW_DELEGATE_H_
|
||||||
|
|
||||||
|
#include <Quartz/Quartz.h>
|
||||||
|
|
||||||
#include "ui/views/cocoa/views_nswindow_delegate.h"
|
#include "ui/views/cocoa/views_nswindow_delegate.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -12,7 +14,8 @@ class NativeWindowMac;
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface AtomNSWindowDelegate : NSObject<NSWindowDelegate,
|
@interface AtomNSWindowDelegate : NSObject<NSWindowDelegate,
|
||||||
NSTouchBarDelegate> {
|
NSTouchBarDelegate,
|
||||||
|
QLPreviewPanelDataSource> {
|
||||||
@private
|
@private
|
||||||
atom::NativeWindowMac* shell_;
|
atom::NativeWindowMac* shell_;
|
||||||
bool is_zooming_;
|
bool is_zooming_;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/browser/native_window_mac.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 "atom/browser/ui/cocoa/atom_touch_bar.h"
|
||||||
#include "base/mac/mac_util.h"
|
#include "base/mac/mac_util.h"
|
||||||
|
|
||||||
|
@ -253,10 +254,21 @@
|
||||||
|
|
||||||
- (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
|
- (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
|
||||||
makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier API_AVAILABLE(macosx(10.12.2)) {
|
makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier API_AVAILABLE(macosx(10.12.2)) {
|
||||||
if (touchBar && shell_->atom_touch_bar())
|
if (touchBar && shell_->touch_bar())
|
||||||
return [shell_->atom_touch_bar() makeItemForIdentifier:identifier];
|
return [shell_->touch_bar() makeItemForIdentifier:identifier];
|
||||||
else
|
else
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - QLPreviewPanelDataSource
|
||||||
|
|
||||||
|
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel*)panel {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id <QLPreviewItem>)previewPanel:(QLPreviewPanel*)panel
|
||||||
|
previewItemAtIndex:(NSInteger)index {
|
||||||
|
return shell_->preview_item();
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
17
atom/browser/ui/cocoa/atom_preview_item.h
Normal file
17
atom/browser/ui/cocoa/atom_preview_item.h
Normal file
|
@ -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 <Cocoa/Cocoa.h>
|
||||||
|
#import <Quartz/Quartz.h>
|
||||||
|
|
||||||
|
@interface AtomPreviewItem : NSObject<QLPreviewItem>
|
||||||
|
@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_
|
21
atom/browser/ui/cocoa/atom_preview_item.mm
Normal file
21
atom/browser/ui/cocoa/atom_preview_item.mm
Normal file
|
@ -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
|
|
@ -320,6 +320,8 @@
|
||||||
'atom/browser/ui/cocoa/atom_native_widget_mac.mm',
|
'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.h',
|
||||||
'atom/browser/ui/cocoa/atom_ns_window_delegate.mm',
|
'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.h',
|
||||||
'atom/browser/ui/cocoa/atom_touch_bar.mm',
|
'atom/browser/ui/cocoa/atom_touch_bar.mm',
|
||||||
'atom/browser/ui/cocoa/views_delegate_mac.h',
|
'atom/browser/ui/cocoa/views_delegate_mac.h',
|
||||||
|
|
1
script/cpplint.py
vendored
1
script/cpplint.py
vendored
|
@ -13,6 +13,7 @@ IGNORE_FILES = set(os.path.join(*components) for components in [
|
||||||
['atom', 'browser', 'resources', 'win', 'resource.h'],
|
['atom', 'browser', 'resources', 'win', 'resource.h'],
|
||||||
['atom', 'browser', 'ui', 'cocoa', 'atom_menu_controller.h'],
|
['atom', 'browser', 'ui', 'cocoa', 'atom_menu_controller.h'],
|
||||||
['atom', 'browser', 'ui', 'cocoa', 'atom_ns_window_delegate.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', 'atom_touch_bar.h'],
|
||||||
['atom', 'browser', 'ui', 'cocoa', 'touch_bar_forward_declarations.h'],
|
['atom', 'browser', 'ui', 'cocoa', 'touch_bar_forward_declarations.h'],
|
||||||
['atom', 'browser', 'ui', 'cocoa', 'NSColor+Hex.h'],
|
['atom', 'browser', 'ui', 'cocoa', 'NSColor+Hex.h'],
|
||||||
|
|
Loading…
Reference in a new issue