remove method transferred to set with null
authorgellert <gellihegyi@gmail.com>
Thu, 10 Nov 2016 10:59:25 +0000 (11:59 +0100)
committerKevin Sawicki <kevin@github.com>
Fri, 11 Nov 2016 16:49:57 +0000 (08:49 -0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
docs/api/browser-window.md

index 352621e..5daf429 100644 (file)
@@ -786,12 +786,16 @@ bool Window::IsVisibleOnAllWorkspaces() {
   return window_->IsVisibleOnAllWorkspaces();
 }
 
-void Window::SetVibrancy(const std::string& type) {
-  window_->SetVibrancy(type);
-}
+void Window::SetVibrancy(v8::Local<v8::Value> value, mate::Arguments* args) {
+  std::string type;
 
-void Window::RemoveVibrancy() {
-  window_->RemoveVibrancy();
+  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");
+  }
 }
 
 int32_t Window::ID() const {
@@ -910,7 +914,6 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("isVisibleOnAllWorkspaces",
                  &Window::IsVisibleOnAllWorkspaces)
       .SetMethod("setVibrancy", &Window::SetVibrancy)
-      .SetMethod("removeVibrancy", &Window::RemoveVibrancy)
 #if defined(OS_WIN)
       .SetMethod("hookWindowMessage", &Window::HookWindowMessage)
       .SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked)
index a706884..fcb3fac 100644 (file)
@@ -196,8 +196,7 @@ class Window : public mate::TrackableObject<Window>,
   void SetVisibleOnAllWorkspaces(bool visible);
   bool IsVisibleOnAllWorkspaces();
 
-  void SetVibrancy(const std::string& type);
-  void RemoveVibrancy();
+  void SetVibrancy(v8::Local<v8::Value> value, mate::Arguments* args);
 
   int32_t ID() const;
   v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
index fa537e8..c1be589 100644 (file)
@@ -340,6 +340,9 @@ void NativeWindow::SetParentWindow(NativeWindow* parent) {
   parent_ = parent;
 }
 
+void NativeWindow::SetVibrancy(const std::string& filename) {
+}
+
 void NativeWindow::FocusOnWebView() {
   web_contents()->GetRenderViewHost()->GetWidget()->Focus();
 }
index 13ebdbf..b5e2cf3 100644 (file)
@@ -162,8 +162,7 @@ class NativeWindow : public base::SupportsUserData,
   virtual bool IsVisibleOnAllWorkspaces() = 0;
 
   // Vibrancy API
-  virtual void SetVibrancy(const std::string& type) = 0;
-  virtual void RemoveVibrancy() = 0;
+  virtual void SetVibrancy(const std::string& type);
 
   // Webview APIs.
   virtual void FocusOnWebView();
index c5206dd..9fe78f6 100644 (file)
@@ -93,7 +93,6 @@ class NativeWindowMac : public NativeWindow,
   void SetVisibleOnAllWorkspaces(bool visible) override;
   bool IsVisibleOnAllWorkspaces() override;
   void SetVibrancy(const std::string& type) override;
-  void RemoveVibrancy() override;
 
   // content::RenderWidgetHost::InputEventObserver:
   void OnInputEvent(const blink::WebInputEvent& event) override;
index 67c705b..a1dab3f 100644 (file)
@@ -1208,18 +1208,27 @@ bool NativeWindowMac::IsVisibleOnAllWorkspaces() {
 void NativeWindowMac::SetVibrancy(const std::string& type) {
   if (!(base::mac::IsOSMavericks() || base::mac::IsOSYosemiteOrLater())) return;
 
-  NSVisualEffectView *vview = (NSVisualEffectView *)vibrant_view_;
-  if (vview == nil) {
-    vview = [[NSVisualEffectView alloc] initWithFrame:
+  if (type.empty()) {
+    if (vibrant_view_ == nil) return;
+
+    [vibrant_view_ removeFromSuperview];
+    vibrant_view_ = nil;
+
+    return;
+  }
+
+  NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view_;
+  if (effect_view == nil) {
+    effect_view = [[NSVisualEffectView alloc] initWithFrame:
       [[window_ contentView] bounds]];
-    vibrant_view_ = (NSView *)vview;
+    vibrant_view_ = (NSView*)effect_view;
 
-    [vview setAutoresizingMask:
+    [effect_view setAutoresizingMask:
       NSViewWidthSizable | NSViewHeightSizable];
 
-    [vview setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
-    [vview setState:NSVisualEffectStateActive];
-    [[window_ contentView] addSubview:vview
+    [effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
+    [effect_view setState:NSVisualEffectStateActive];
+    [[window_ contentView] addSubview:effect_view
                            positioned:NSWindowBelow
                            relativeTo:nil];
   }
@@ -1252,14 +1261,7 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
     }
   }
 
-  [vview setMaterial:vibrancyType];
-}
-
-void NativeWindowMac::RemoveVibrancy() {
-  if (vibrant_view_ == nil) return;
-
-  [vibrant_view_ removeFromSuperview];
-  vibrant_view_ = nil;
+  [effect_view setMaterial:vibrancyType];
 }
 
 void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) {
index 1600b7f..25c4823 100644 (file)
@@ -1198,10 +1198,7 @@ Returns `BrowserWindow[]` - All child windows.
   `selection`, `menu`, `popover`, `sidebar`, `medium-light` or `ultra-dark`. See
   the [macOS documentation][vibrancy-docs] for more details.
 
-Adds a vibrancy effect to the browser window.
+Adds a vibrancy effect to the browser window. Passing `null` or an empty string
+will remove the vibrancy effect on the window.
 
 [vibrancy-docs]: https://developer.apple.com/reference/appkit/nsvisualeffectview?language=objc
-
-#### `win.removeVibrancy()` _macOS_
-
-Removes the vibrancy effect on the window.