Skip to content

Commit

Permalink
feat: expose new vibrancy types (#19073)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jul 11, 2019
1 parent c756b95 commit 75a020e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
7 changes: 3 additions & 4 deletions docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,8 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
Windows, which adds standard window frame. Setting it to `false` will remove
window shadow and window animations. Default is `true`.
* `vibrancy` String (optional) - Add a type of vibrancy effect to the window, only on
macOS. Can be `appearance-based`, `light`, `dark`, `titlebar`, `selection`, `menu`,
`popover`, `sidebar`, `medium-light` or `ultra-dark`. Please note that using `frame: false` in combination with a vibrancy value requires that you use a non-default `titleBarStyle` as well.
Also note that `appearance-based`, `light`, `dark`, `medium-light`, and `ultra-dark` have been deprecated and will be removed in an upcoming version of macOS.
macOS. Can be `appearance-based`, `light`, `dark`, `titlebar`, `selection`,
`menu`, `popover`, `sidebar`, `medium-light`, `ultra-dark`, `header`, `sheet`, `window`, `hud`, `fullscreen-ui`, `tooltip`, `content`, `under-window`, or `under-page`. Please note that using `frame: false` in combination with a vibrancy value requires that you use a non-default `titleBarStyle` as well. Also note that `appearance-based`, `light`, `dark`, `medium-light`, and `ultra-dark` have been deprecated and will be removed in an upcoming version of macOS.
* `zoomToPageWidth` Boolean (optional) - Controls the behavior on macOS when
option-clicking the green stoplight button on the toolbar or by clicking the
Window > Zoom menu item. If `true`, the window will grow to the preferred
Expand Down Expand Up @@ -1620,7 +1619,7 @@ Adds a window as a tab on this window, after the tab for the window instance.
#### `win.setVibrancy(type)` _macOS_

* `type` String | null - Can be `appearance-based`, `light`, `dark`, `titlebar`,
`selection`, `menu`, `popover`, `sidebar`, `medium-light` or `ultra-dark`. See
`selection`, `menu`, `popover`, `sidebar`, `medium-light`, `ultra-dark`, `header`, `sheet`, `window`, `hud`, `fullscreen-ui`, `tooltip`, `content`, `under-window`, or `under-page`. See
the [macOS documentation][vibrancy-docs] for more details.

Adds a vibrancy effect to the browser window. Passing `null` or an empty string
Expand Down
31 changes: 31 additions & 0 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,37 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}
}

if (@available(macOS 10.14, *)) {
if (type == "header") {
// NSVisualEffectMaterialHeaderView
vibrancyType = static_cast<NSVisualEffectMaterial>(10);
} else if (type == "sheet") {
// NSVisualEffectMaterialSheet
vibrancyType = static_cast<NSVisualEffectMaterial>(11);
} else if (type == "window") {
// NSVisualEffectMaterialWindowBackground
vibrancyType = static_cast<NSVisualEffectMaterial>(12);
} else if (type == "hud") {
// NSVisualEffectMaterialHUDWindow
vibrancyType = static_cast<NSVisualEffectMaterial>(13);
} else if (type == "fullscreen-ui") {
// NSVisualEffectMaterialFullScreenUI
vibrancyType = static_cast<NSVisualEffectMaterial>(16);
} else if (type == "tooltip") {
// NSVisualEffectMaterialToolTip
vibrancyType = static_cast<NSVisualEffectMaterial>(17);
} else if (type == "content") {
// NSVisualEffectMaterialContentBackground
vibrancyType = static_cast<NSVisualEffectMaterial>(18);
} else if (type == "under-window") {
// NSVisualEffectMaterialUnderWindowBackground
vibrancyType = static_cast<NSVisualEffectMaterial>(21);
} else if (type == "under-page") {
// NSVisualEffectMaterialUnderPageBackground
vibrancyType = static_cast<NSVisualEffectMaterial>(22);
}
}

if (vibrancyType)
[effect_view setMaterial:vibrancyType];
}
Expand Down

0 comments on commit 75a020e

Please sign in to comment.