From 5e62d28e5097f3a8fbf0052cbcacf291e5927cee Mon Sep 17 00:00:00 2001 From: gellert Date: Thu, 10 Nov 2016 20:36:21 +0100 Subject: [PATCH] adds test, adds view to AtomNSWindow and minor fixes --- atom/browser/api/atom_api_window.cc | 11 +++-------- atom/browser/api/atom_api_window.h | 2 +- atom/browser/native_window.cc | 7 ------- atom/browser/native_window_mac.h | 3 --- atom/browser/native_window_mac.mm | 20 ++++++++++++++------ spec/api-browser-window-spec.js | 12 ++++++++++++ 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 5daf429109..75be28028d 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -786,16 +786,11 @@ bool Window::IsVisibleOnAllWorkspaces() { return window_->IsVisibleOnAllWorkspaces(); } -void Window::SetVibrancy(v8::Local value, mate::Arguments* args) { +void Window::SetVibrancy(mate::Arguments* args) { std::string type; - if (value->IsNull()) { - window_->SetVibrancy(std::string()); - } else if (mate::ConvertFromV8(isolate(), value, &type)) { - window_->SetVibrancy(type); - } else { - args->ThrowError("Must pass a string or null"); - } + args->GetNext(&type); + window_->SetVibrancy(type); } int32_t Window::ID() const { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index fcb3fac628..8a5b95ba8f 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -196,7 +196,7 @@ class Window : public mate::TrackableObject, void SetVisibleOnAllWorkspaces(bool visible); bool IsVisibleOnAllWorkspaces(); - void SetVibrancy(v8::Local value, mate::Arguments* args); + void SetVibrancy(mate::Arguments* args); int32_t ID() const; v8::Local WebContents(v8::Isolate* isolate); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index c1be5898ea..92419d357e 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -201,13 +201,6 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) { options.Get(options::kShow, &show); if (show) Show(); - -#if defined(OS_MACOSX) - std::string type; - if (options.Get(options::kVibrancyType, &type)) { - SetVibrancy(type); - } -#endif } void NativeWindow::SetSize(const gfx::Size& size, bool animate) { diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 9fe78f672a..339e10e853 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -163,9 +163,6 @@ class NativeWindowMac : public NativeWindow, // The "titleBarStyle" option. TitleBarStyle title_bar_style_; - // Vibrancy view - NSView* vibrant_view_; - DISALLOW_COPY_AND_ASSIGN(NativeWindowMac); }; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index a1dab3f445..a4633db574 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -311,6 +311,7 @@ bool ScopedDisableResize::disable_resize_ = false; @property BOOL disableKeyOrMainWindow; @property NSPoint windowButtonsOffset; @property (nonatomic, retain) AtomPreviewItem* quickLookItem; +@property (nonatomic, retain) NSView* vibrantView; - (void)setShell:(atom::NativeWindowMac*)shell; - (void)setEnableLargerThanScreen:(bool)enable; @@ -743,6 +744,11 @@ NativeWindowMac::NativeWindowMac( InstallView(); + std::string type; + if (options.Get(options::kVibrancyType, &type)) { + SetVibrancy(type); + } + // Set maximizable state last to ensure zoom button does not get reset // by calls to other APIs. SetMaximizable(maximizable); @@ -1208,20 +1214,22 @@ bool NativeWindowMac::IsVisibleOnAllWorkspaces() { void NativeWindowMac::SetVibrancy(const std::string& type) { if (!(base::mac::IsOSMavericks() || base::mac::IsOSYosemiteOrLater())) return; - if (type.empty()) { - if (vibrant_view_ == nil) return; + NSView* vibrant_view = [window_ vibrantView]; - [vibrant_view_ removeFromSuperview]; - vibrant_view_ = nil; + if (type.empty()) { + if (vibrant_view == nil) return; + + [vibrant_view removeFromSuperview]; + [window_ setVibrantView:nil]; return; } - NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view_; + NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view; if (effect_view == nil) { effect_view = [[NSVisualEffectView alloc] initWithFrame: [[window_ contentView] bounds]]; - vibrant_view_ = (NSView*)effect_view; + [window_ setVibrantView:(NSView*)effect_view]; [effect_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 9bfede278b..b81ec2f790 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -427,6 +427,18 @@ describe('browser-window module', function () { }) }) + describe('BrowserWindow.setVibrancy(type)', function () { + it('allows setting, changing, and removing the vibrancy', function () { + assert.doesNotThrow(function () { + w.setVibrancy('light') + w.setVibrancy('dark') + w.setVibrancy(null) + w.setVibrancy('ultra-dark') + w.setVibrancy('') + }) + }) + }) + describe('BrowserWindow.fromId(id)', function () { it('returns the window with id', function () { assert.equal(w.id, BrowserWindow.fromId(w.id).id)