Browse Source

adds test, adds view to AtomNSWindow and minor fixes

gellert 8 years ago
parent
commit
5e62d28e50

+ 3 - 8
atom/browser/api/atom_api_window.cc

@@ -786,16 +786,11 @@ bool Window::IsVisibleOnAllWorkspaces() {
   return window_->IsVisibleOnAllWorkspaces();
 }
 
-void Window::SetVibrancy(v8::Local<v8::Value> 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 {

+ 1 - 1
atom/browser/api/atom_api_window.h

@@ -196,7 +196,7 @@ class Window : public mate::TrackableObject<Window>,
   void SetVisibleOnAllWorkspaces(bool visible);
   bool IsVisibleOnAllWorkspaces();
 
-  void SetVibrancy(v8::Local<v8::Value> value, mate::Arguments* args);
+  void SetVibrancy(mate::Arguments* args);
 
   int32_t ID() const;
   v8::Local<v8::Value> WebContents(v8::Isolate* isolate);

+ 0 - 7
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) {

+ 0 - 3
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);
 };
 

+ 13 - 5
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;
 
+  NSView* vibrant_view = [window_ vibrantView];
+
   if (type.empty()) {
-    if (vibrant_view_ == nil) return;
+    if (vibrant_view == nil) return;
 
-    [vibrant_view_ removeFromSuperview];
-    vibrant_view_ = nil;
+    [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];

+ 12 - 0
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)