From 2cf30c0d630163a0f9930b9efe066976a679e6fc Mon Sep 17 00:00:00 2001 From: gellert Date: Thu, 10 Nov 2016 11:59:25 +0100 Subject: [PATCH] remove method transferred to set with null --- atom/browser/api/atom_api_window.cc | 15 +++++++----- atom/browser/api/atom_api_window.h | 3 +-- atom/browser/native_window.cc | 3 +++ atom/browser/native_window.h | 3 +-- atom/browser/native_window_mac.h | 1 - atom/browser/native_window_mac.mm | 36 +++++++++++++++-------------- docs/api/browser-window.md | 7 ++---- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 352621efafd1..5daf42910990 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -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 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) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index a70688457940..fcb3fac628b9 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -196,8 +196,7 @@ class Window : public mate::TrackableObject, void SetVisibleOnAllWorkspaces(bool visible); bool IsVisibleOnAllWorkspaces(); - void SetVibrancy(const std::string& type); - void RemoveVibrancy(); + void SetVibrancy(v8::Local value, 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 fa537e815b00..c1be5898ea29 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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(); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 13ebdbfa54f1..b5e2cf3bac31 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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(); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index c5206dd6dae3..9fe78f672a64 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -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; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 67c705bb4814..a1dab3f44589 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -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: - [[window_ contentView] bounds]]; - vibrant_view_ = (NSView *)vview; + if (type.empty()) { + if (vibrant_view_ == nil) return; - [vview setAutoresizingMask: + [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*)effect_view; + + [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) { diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 1600b7f83bfc..25c4823bb8bd 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -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.