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 AtomNSWindowDelegate;
@class AtomTouchBar;
@class FullSizeContentView;
namespace atom {
@ -136,6 +137,7 @@ class NativeWindowMac : public NativeWindow {
};
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 fullscreen_window_title() const { return fullscreen_window_title_; }
bool simple_fullscreen() const { return always_simple_fullscreen_; }
@ -148,6 +150,7 @@ class NativeWindowMac : public NativeWindow {
base::scoped_nsobject<AtomNSWindow> window_;
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
base::scoped_nsobject<AtomTouchBar> atom_touch_bar_;
std::unique_ptr<views::Widget> widget_;

View file

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