Manage AtomTouchBar in NativeWindow instead of AtomNSWindow

This commit is contained in:
Cheng Zhao 2018-04-19 16:12:11 +09:00
parent ce54fd334d
commit 8e9667d86c
2 changed files with 20 additions and 34 deletions

View file

@ -17,6 +17,7 @@
@class AtomNSWindow; @class AtomNSWindow;
@class AtomNSWindowDelegate; @class AtomNSWindowDelegate;
@class AtomTouchBar;
@class FullSizeContentView; @class FullSizeContentView;
namespace atom { namespace atom {
@ -136,6 +137,7 @@ 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(); }
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_; }
@ -148,6 +150,7 @@ 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_;
std::unique_ptr<views::Widget> widget_; std::unique_ptr<views::Widget> widget_;

View file

@ -213,7 +213,6 @@ enum {
@private @private
atom::NativeWindowMac* shell_; atom::NativeWindowMac* shell_;
bool enable_larger_than_screen_; bool enable_larger_than_screen_;
base::scoped_nsobject<AtomTouchBar> atom_touch_bar_;
CGFloat windowButtonsInterButtonSpacing_; CGFloat windowButtonsInterButtonSpacing_;
} }
@property BOOL acceptsFirstMouse; @property BOOL acceptsFirstMouse;
@ -226,9 +225,6 @@ enum {
- (void)setShell:(atom::NativeWindowMac*)shell; - (void)setShell:(atom::NativeWindowMac*)shell;
- (void)setEnableLargerThanScreen:(bool)enable; - (void)setEnableLargerThanScreen:(bool)enable;
- (void)enableWindowButtonsOffset; - (void)enableWindowButtonsOffset;
- (void)resetTouchBar:(const std::vector<mate::PersistentDictionary>&)settings;
- (void)refreshTouchBarItem:(const std::string&)item_id;
- (void)setEscapeTouchBarItem:(const mate::PersistentDictionary&)item;
@end @end
@ -249,43 +245,21 @@ enum {
enable_larger_than_screen_ = enable; enable_larger_than_screen_ = enable;
} }
- (void)resetTouchBar:(const std::vector<mate::PersistentDictionary>&)settings
API_AVAILABLE(macosx(10.12.2)) {
if (![self respondsToSelector:@selector(touchBar)]) return;
atom_touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:self
window:shell_
settings:settings]);
self.touchBar = nil;
}
- (void)refreshTouchBarItem:(const std::string&)item_id
API_AVAILABLE(macosx(10.12.2)) {
if (atom_touch_bar_ && self.touchBar)
[atom_touch_bar_ refreshTouchBarItem:self.touchBar id:item_id];
}
- (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)) { - (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)) {
if (atom_touch_bar_) if (shell_->atom_touch_bar())
return [atom_touch_bar_ makeTouchBar]; return [shell_->atom_touch_bar() makeTouchBar];
else else
return nil; return nil;
} }
- (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 && atom_touch_bar_) if (touchBar && shell_->atom_touch_bar())
return [atom_touch_bar_ makeItemForIdentifier:identifier]; return [shell_->atom_touch_bar() makeItemForIdentifier:identifier];
else else
return nil; return nil;
} }
- (void)setEscapeTouchBarItem:(const mate::PersistentDictionary&)item
API_AVAILABLE(macosx(10.12.2)) {
if (atom_touch_bar_ && self.touchBar)
[atom_touch_bar_ setEscapeTouchBarItem:item forTouchBar:self.touchBar];
}
// NSWindow overrides. // NSWindow overrides.
- (void)swipeWithEvent:(NSEvent *)event { - (void)swipeWithEvent:(NSEvent *)event {
@ -1538,15 +1512,24 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
void NativeWindowMac::SetTouchBar( void NativeWindowMac::SetTouchBar(
const std::vector<mate::PersistentDictionary>& items) { const std::vector<mate::PersistentDictionary>& items) {
[window_ resetTouchBar:items]; if (![window_ respondsToSelector:@selector(touchBar)])
return;
atom_touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:window_.get()
window:this
settings:items]);
[window_ setTouchBar:nil];
} }
void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) { void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) {
[window_ refreshTouchBarItem:item_id]; if (atom_touch_bar_ && [window_ touchBar])
[atom_touch_bar_ refreshTouchBarItem:[window_ touchBar] id:item_id];
} }
void NativeWindowMac::SetEscapeTouchBarItem(const mate::PersistentDictionary& item) { void NativeWindowMac::SetEscapeTouchBarItem(
[window_ setEscapeTouchBarItem:item]; const mate::PersistentDictionary& item) {
if (atom_touch_bar_ && [window_ touchBar])
[atom_touch_bar_ setEscapeTouchBarItem:item forTouchBar:[window_ touchBar]];
} }
gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds( gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(