Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose window.invalidateShadow() #32452

Merged
merged 5 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,13 @@ screen readers
Sets a 16 x 16 pixel overlay onto the current taskbar icon, usually used to
convey some sort of application status or to passively notify the user.

#### `win.invalidateShadow()` _macOS_

Invalidates the window shadow so that it is recomputed based on the current window shape.

`BrowserWindows` that are transparent and frameless can sometimes leave behind visual artifacts on macOS.
nornagon marked this conversation as resolved.
Show resolved Hide resolved
This method can be used to clear these artifacts when, for example, performing an animation.

#### `win.setHasShadow(hasShadow)`

* `hasShadow` boolean
Expand Down
5 changes: 5 additions & 0 deletions shell/browser/api/electron_api_base_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,10 @@ std::string BaseWindow::GetBackgroundColor(gin_helper::Arguments* args) {
return ToRGBHex(window_->GetBackgroundColor());
}

void BaseWindow::InvalidateShadow() {
window_->InvalidateShadow();
}

void BaseWindow::SetHasShadow(bool has_shadow) {
window_->SetHasShadow(has_shadow);
}
Expand Down Expand Up @@ -1267,6 +1271,7 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isVisibleOnAllWorkspaces",
&BaseWindow::IsVisibleOnAllWorkspaces)
#if BUILDFLAG(IS_MAC)
.SetMethod("invalidateShadow", &BaseWindow::InvalidateShadow)
.SetMethod("_getAlwaysOnTopLevel", &BaseWindow::GetAlwaysOnTopLevel)
.SetMethod("setAutoHideCursor", &BaseWindow::SetAutoHideCursor)
#endif
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/electron_api_base_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
bool IsTabletMode() const;
virtual void SetBackgroundColor(const std::string& color_name);
std::string GetBackgroundColor(gin_helper::Arguments* args);
void InvalidateShadow();
void SetHasShadow(bool has_shadow);
bool HasShadow();
void SetOpacity(const double opacity);
Expand Down
2 changes: 2 additions & 0 deletions shell/browser/native_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ void NativeWindow::SetParentWindow(NativeWindow* parent) {
parent_ = parent;
}

void NativeWindow::InvalidateShadow() {}

void NativeWindow::SetAutoHideCursor(bool auto_hide) {}

void NativeWindow::SelectPreviousTab() {}
Expand Down
1 change: 1 addition & 0 deletions shell/browser/native_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class NativeWindow : public base::SupportsUserData,
virtual bool IsTabletMode() const;
virtual void SetBackgroundColor(SkColor color) = 0;
virtual SkColor GetBackgroundColor() = 0;
virtual void InvalidateShadow();
virtual void SetHasShadow(bool has_shadow) = 0;
virtual bool HasShadow() = 0;
virtual void SetOpacity(const double opacity) = 0;
Expand Down
1 change: 1 addition & 0 deletions shell/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class NativeWindowMac : public NativeWindow,
bool IsKiosk() override;
void SetBackgroundColor(SkColor color) override;
SkColor GetBackgroundColor() override;
void InvalidateShadow() override;
void SetHasShadow(bool has_shadow) override;
bool HasShadow() override;
void SetOpacity(const double opacity) override;
Expand Down
8 changes: 6 additions & 2 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

NSUInteger styleMask = NSWindowStyleMaskTitled;

// Removing NSWindowStyleMaskTitled removes window title, which removes
// rounded corners of window.
// The NSWindowStyleMaskFullSizeContentView style removes rounded corners
// for frameless window.
bool rounded_corner = true;
options.Get(options::kRoundedCorners, &rounded_corner);
if (!rounded_corner && !has_frame())
Expand Down Expand Up @@ -1115,6 +1115,10 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
return [window_ hasShadow];
}

void NativeWindowMac::InvalidateShadow() {
[window_ invalidateShadow];
}

void NativeWindowMac::SetOpacity(const double opacity) {
const double boundedOpacity = base::clamp(opacity, 0.0, 1.0);
[window_ setAlphaValue:boundedOpacity];
Expand Down