adds vibrancy effect for macos
This commit is contained in:
parent
ad638097b6
commit
8ad50d1e35
9 changed files with 105 additions and 0 deletions
|
@ -786,6 +786,14 @@ bool Window::IsVisibleOnAllWorkspaces() {
|
||||||
return window_->IsVisibleOnAllWorkspaces();
|
return window_->IsVisibleOnAllWorkspaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::SetVibrancy(const std::string& type) {
|
||||||
|
window_->SetVibrancy(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::RemoveVibrancy() {
|
||||||
|
window_->RemoveVibrancy();
|
||||||
|
}
|
||||||
|
|
||||||
int32_t Window::ID() const {
|
int32_t Window::ID() const {
|
||||||
return weak_map_id();
|
return weak_map_id();
|
||||||
}
|
}
|
||||||
|
@ -901,6 +909,8 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
&Window::SetVisibleOnAllWorkspaces)
|
&Window::SetVisibleOnAllWorkspaces)
|
||||||
.SetMethod("isVisibleOnAllWorkspaces",
|
.SetMethod("isVisibleOnAllWorkspaces",
|
||||||
&Window::IsVisibleOnAllWorkspaces)
|
&Window::IsVisibleOnAllWorkspaces)
|
||||||
|
.SetMethod("setVibrancy", &Window::SetVibrancy)
|
||||||
|
.SetMethod("removeVibrancy", &Window::RemoveVibrancy)
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
.SetMethod("hookWindowMessage", &Window::HookWindowMessage)
|
.SetMethod("hookWindowMessage", &Window::HookWindowMessage)
|
||||||
.SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked)
|
.SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked)
|
||||||
|
|
|
@ -196,6 +196,9 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
void SetVisibleOnAllWorkspaces(bool visible);
|
void SetVisibleOnAllWorkspaces(bool visible);
|
||||||
bool IsVisibleOnAllWorkspaces();
|
bool IsVisibleOnAllWorkspaces();
|
||||||
|
|
||||||
|
void SetVibrancy(const std::string& type);
|
||||||
|
void RemoveVibrancy();
|
||||||
|
|
||||||
int32_t ID() const;
|
int32_t ID() const;
|
||||||
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
|
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
|
||||||
|
|
||||||
|
|
|
@ -201,6 +201,13 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
||||||
options.Get(options::kShow, &show);
|
options.Get(options::kShow, &show);
|
||||||
if (show)
|
if (show)
|
||||||
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) {
|
void NativeWindow::SetSize(const gfx::Size& size, bool animate) {
|
||||||
|
|
|
@ -161,6 +161,10 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
virtual void SetVisibleOnAllWorkspaces(bool visible) = 0;
|
virtual void SetVisibleOnAllWorkspaces(bool visible) = 0;
|
||||||
virtual bool IsVisibleOnAllWorkspaces() = 0;
|
virtual bool IsVisibleOnAllWorkspaces() = 0;
|
||||||
|
|
||||||
|
// Vibrancy API
|
||||||
|
virtual void SetVibrancy(const std::string& type) = 0;
|
||||||
|
virtual void RemoveVibrancy() = 0;
|
||||||
|
|
||||||
// Webview APIs.
|
// Webview APIs.
|
||||||
virtual void FocusOnWebView();
|
virtual void FocusOnWebView();
|
||||||
virtual void BlurWebView();
|
virtual void BlurWebView();
|
||||||
|
|
|
@ -92,6 +92,8 @@ class NativeWindowMac : public NativeWindow,
|
||||||
const std::string& description) override;
|
const std::string& description) override;
|
||||||
void SetVisibleOnAllWorkspaces(bool visible) override;
|
void SetVisibleOnAllWorkspaces(bool visible) override;
|
||||||
bool IsVisibleOnAllWorkspaces() override;
|
bool IsVisibleOnAllWorkspaces() override;
|
||||||
|
void SetVibrancy(const std::string& type) override;
|
||||||
|
void RemoveVibrancy() override;
|
||||||
|
|
||||||
// content::RenderWidgetHost::InputEventObserver:
|
// content::RenderWidgetHost::InputEventObserver:
|
||||||
void OnInputEvent(const blink::WebInputEvent& event) override;
|
void OnInputEvent(const blink::WebInputEvent& event) override;
|
||||||
|
@ -162,6 +164,9 @@ class NativeWindowMac : public NativeWindow,
|
||||||
// The "titleBarStyle" option.
|
// The "titleBarStyle" option.
|
||||||
TitleBarStyle title_bar_style_;
|
TitleBarStyle title_bar_style_;
|
||||||
|
|
||||||
|
// Vibrancy view
|
||||||
|
NSView* vibrant_view_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);
|
DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1205,6 +1205,63 @@ bool NativeWindowMac::IsVisibleOnAllWorkspaces() {
|
||||||
return collectionBehavior & NSWindowCollectionBehaviorCanJoinAllSpaces;
|
return collectionBehavior & NSWindowCollectionBehaviorCanJoinAllSpaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
[vview setAutoresizingMask:
|
||||||
|
NSViewWidthSizable | NSViewHeightSizable];
|
||||||
|
|
||||||
|
[vview setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
|
||||||
|
[vview setState:NSVisualEffectStateActive];
|
||||||
|
[[window_ contentView] addSubview:vview
|
||||||
|
positioned:NSWindowBelow
|
||||||
|
relativeTo:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSVisualEffectMaterial vibrancyType = NSVisualEffectMaterialLight;
|
||||||
|
|
||||||
|
if (type == "appearance-based") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialAppearanceBased;
|
||||||
|
} else if (type == "light") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialLight;
|
||||||
|
} else if (type == "dark") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialDark;
|
||||||
|
} else if (type == "titlebar") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialTitlebar;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (base::mac::IsOSYosemiteOrLater()) {
|
||||||
|
if (type == "selection") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialSelection;
|
||||||
|
} else if (type == "menu") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialMenu;
|
||||||
|
} else if (type == "popover") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialPopover;
|
||||||
|
} else if (type == "sidebar") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialSidebar;
|
||||||
|
} else if (type == "medium-light") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialMediumLight;
|
||||||
|
} else if (type == "ultra-dark") {
|
||||||
|
vibrancyType = NSVisualEffectMaterialUltraDark;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[vview setMaterial:vibrancyType];
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::RemoveVibrancy() {
|
||||||
|
if (vibrant_view_ == nil) return;
|
||||||
|
|
||||||
|
[vibrant_view_ removeFromSuperview];
|
||||||
|
vibrant_view_ = nil;
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) {
|
void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case blink::WebInputEvent::GestureScrollBegin:
|
case blink::WebInputEvent::GestureScrollBegin:
|
||||||
|
|
|
@ -81,6 +81,9 @@ const char kFocusable[] = "focusable";
|
||||||
// The WebPreferences.
|
// The WebPreferences.
|
||||||
const char kWebPreferences[] = "webPreferences";
|
const char kWebPreferences[] = "webPreferences";
|
||||||
|
|
||||||
|
// Add a vibrancy effect to the browser window
|
||||||
|
const char kVibrancyType[] = "vibrancy";
|
||||||
|
|
||||||
// The factor of which page should be zoomed.
|
// The factor of which page should be zoomed.
|
||||||
const char kZoomFactor[] = "zoomFactor";
|
const char kZoomFactor[] = "zoomFactor";
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ extern const char kBackgroundColor[];
|
||||||
extern const char kHasShadow[];
|
extern const char kHasShadow[];
|
||||||
extern const char kFocusable[];
|
extern const char kFocusable[];
|
||||||
extern const char kWebPreferences[];
|
extern const char kWebPreferences[];
|
||||||
|
extern const char kVibrancyType[];
|
||||||
|
|
||||||
// WebPreferences.
|
// WebPreferences.
|
||||||
extern const char kZoomFactor[];
|
extern const char kZoomFactor[];
|
||||||
|
|
|
@ -265,6 +265,8 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||||
* `offscreen` Boolean - Whether to enable offscreen rendering for the browser
|
* `offscreen` Boolean - Whether to enable offscreen rendering for the browser
|
||||||
window. Defaults to `false`.
|
window. Defaults to `false`.
|
||||||
* `sandbox` Boolean - Whether to enable Chromium OS-level sandbox.
|
* `sandbox` Boolean - Whether to enable Chromium OS-level sandbox.
|
||||||
|
* `vibrancy` String - Add a type of vibrancy effect to the window, only on
|
||||||
|
macOS. See supported types at the `setVibrancy` method.
|
||||||
|
|
||||||
When setting minimum or maximum window size with `minWidth`/`maxWidth`/
|
When setting minimum or maximum window size with `minWidth`/`maxWidth`/
|
||||||
`minHeight`/`maxHeight`, it only constrains the users. It won't prevent you from
|
`minHeight`/`maxHeight`, it only constrains the users. It won't prevent you from
|
||||||
|
@ -1188,3 +1190,16 @@ Returns `BrowserWindow[]` - All child windows.
|
||||||
|
|
||||||
[window-levels]: https://developer.apple.com/reference/appkit/nswindow/1664726-window_levels
|
[window-levels]: https://developer.apple.com/reference/appkit/nswindow/1664726-window_levels
|
||||||
[quick-look]: https://en.wikipedia.org/wiki/Quick_Look
|
[quick-look]: https://en.wikipedia.org/wiki/Quick_Look
|
||||||
|
|
||||||
|
#### `win.setVibrancy(type)` _macOS_
|
||||||
|
|
||||||
|
* `type` String - Adds a vibrancy effect to the browser window. Values include
|
||||||
|
`appearance-based`, `light`, `dark`, `titlebar`, `selection`, `menu`,
|
||||||
|
`popover`, `sidebar`, `medium-light`, `ultra-dark`. See the
|
||||||
|
[macOS documentation][vibrancy-docs] for more details.
|
||||||
|
|
||||||
|
[vibrancy-docs]: https://developer.apple.com/reference/appkit/nsvisualeffectview?language=objc
|
||||||
|
|
||||||
|
#### `win.removeVibrancy()` _macOS_
|
||||||
|
|
||||||
|
Removes the vibrancy effect on the window.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue