feat: expose window.invalidateShadow() (#32452)
Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
		
					parent
					
						
							
								35a7c07306
							
						
					
				
			
			
				commit
				
					
						d092e6bda4
					
				
			
		
					 7 changed files with 23 additions and 2 deletions
				
			
		| 
						 | 
					@ -1565,6 +1565,13 @@ screen readers
 | 
				
			||||||
Sets a 16 x 16 pixel overlay onto the current taskbar icon, usually used to
 | 
					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.
 | 
					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 can sometimes leave behind visual artifacts on macOS.
 | 
				
			||||||
 | 
					This method can be used to clear these artifacts when, for example, performing an animation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### `win.setHasShadow(hasShadow)`
 | 
					#### `win.setHasShadow(hasShadow)`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* `hasShadow` boolean
 | 
					* `hasShadow` boolean
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -639,6 +639,10 @@ std::string BaseWindow::GetBackgroundColor(gin_helper::Arguments* args) {
 | 
				
			||||||
  return ToRGBHex(window_->GetBackgroundColor());
 | 
					  return ToRGBHex(window_->GetBackgroundColor());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void BaseWindow::InvalidateShadow() {
 | 
				
			||||||
 | 
					  window_->InvalidateShadow();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BaseWindow::SetHasShadow(bool has_shadow) {
 | 
					void BaseWindow::SetHasShadow(bool has_shadow) {
 | 
				
			||||||
  window_->SetHasShadow(has_shadow);
 | 
					  window_->SetHasShadow(has_shadow);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1259,6 +1263,7 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
 | 
				
			||||||
      .SetMethod("isVisibleOnAllWorkspaces",
 | 
					      .SetMethod("isVisibleOnAllWorkspaces",
 | 
				
			||||||
                 &BaseWindow::IsVisibleOnAllWorkspaces)
 | 
					                 &BaseWindow::IsVisibleOnAllWorkspaces)
 | 
				
			||||||
#if BUILDFLAG(IS_MAC)
 | 
					#if BUILDFLAG(IS_MAC)
 | 
				
			||||||
 | 
					      .SetMethod("invalidateShadow", &BaseWindow::InvalidateShadow)
 | 
				
			||||||
      .SetMethod("_getAlwaysOnTopLevel", &BaseWindow::GetAlwaysOnTopLevel)
 | 
					      .SetMethod("_getAlwaysOnTopLevel", &BaseWindow::GetAlwaysOnTopLevel)
 | 
				
			||||||
      .SetMethod("setAutoHideCursor", &BaseWindow::SetAutoHideCursor)
 | 
					      .SetMethod("setAutoHideCursor", &BaseWindow::SetAutoHideCursor)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -156,6 +156,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
 | 
				
			||||||
  bool IsTabletMode() const;
 | 
					  bool IsTabletMode() const;
 | 
				
			||||||
  virtual void SetBackgroundColor(const std::string& color_name);
 | 
					  virtual void SetBackgroundColor(const std::string& color_name);
 | 
				
			||||||
  std::string GetBackgroundColor(gin_helper::Arguments* args);
 | 
					  std::string GetBackgroundColor(gin_helper::Arguments* args);
 | 
				
			||||||
 | 
					  void InvalidateShadow();
 | 
				
			||||||
  void SetHasShadow(bool has_shadow);
 | 
					  void SetHasShadow(bool has_shadow);
 | 
				
			||||||
  bool HasShadow();
 | 
					  bool HasShadow();
 | 
				
			||||||
  void SetOpacity(const double opacity);
 | 
					  void SetOpacity(const double opacity);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -421,6 +421,8 @@ void NativeWindow::SetParentWindow(NativeWindow* parent) {
 | 
				
			||||||
  parent_ = parent;
 | 
					  parent_ = parent;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void NativeWindow::InvalidateShadow() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void NativeWindow::SetAutoHideCursor(bool auto_hide) {}
 | 
					void NativeWindow::SetAutoHideCursor(bool auto_hide) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void NativeWindow::SelectPreviousTab() {}
 | 
					void NativeWindow::SelectPreviousTab() {}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -169,6 +169,7 @@ class NativeWindow : public base::SupportsUserData,
 | 
				
			||||||
  virtual bool IsTabletMode() const;
 | 
					  virtual bool IsTabletMode() const;
 | 
				
			||||||
  virtual void SetBackgroundColor(SkColor color) = 0;
 | 
					  virtual void SetBackgroundColor(SkColor color) = 0;
 | 
				
			||||||
  virtual SkColor GetBackgroundColor() = 0;
 | 
					  virtual SkColor GetBackgroundColor() = 0;
 | 
				
			||||||
 | 
					  virtual void InvalidateShadow();
 | 
				
			||||||
  virtual void SetHasShadow(bool has_shadow) = 0;
 | 
					  virtual void SetHasShadow(bool has_shadow) = 0;
 | 
				
			||||||
  virtual bool HasShadow() = 0;
 | 
					  virtual bool HasShadow() = 0;
 | 
				
			||||||
  virtual void SetOpacity(const double opacity) = 0;
 | 
					  virtual void SetOpacity(const double opacity) = 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,6 +94,7 @@ class NativeWindowMac : public NativeWindow,
 | 
				
			||||||
  bool IsKiosk() override;
 | 
					  bool IsKiosk() override;
 | 
				
			||||||
  void SetBackgroundColor(SkColor color) override;
 | 
					  void SetBackgroundColor(SkColor color) override;
 | 
				
			||||||
  SkColor GetBackgroundColor() override;
 | 
					  SkColor GetBackgroundColor() override;
 | 
				
			||||||
 | 
					  void InvalidateShadow() override;
 | 
				
			||||||
  void SetHasShadow(bool has_shadow) override;
 | 
					  void SetHasShadow(bool has_shadow) override;
 | 
				
			||||||
  bool HasShadow() override;
 | 
					  bool HasShadow() override;
 | 
				
			||||||
  void SetOpacity(const double opacity) override;
 | 
					  void SetOpacity(const double opacity) override;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -226,8 +226,8 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  NSUInteger styleMask = NSWindowStyleMaskTitled;
 | 
					  NSUInteger styleMask = NSWindowStyleMaskTitled;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Removing NSWindowStyleMaskTitled removes window title, which removes
 | 
					  // The NSWindowStyleMaskFullSizeContentView style removes rounded corners
 | 
				
			||||||
  // rounded corners of window.
 | 
					  // for frameless window.
 | 
				
			||||||
  bool rounded_corner = true;
 | 
					  bool rounded_corner = true;
 | 
				
			||||||
  options.Get(options::kRoundedCorners, &rounded_corner);
 | 
					  options.Get(options::kRoundedCorners, &rounded_corner);
 | 
				
			||||||
  if (!rounded_corner && !has_frame())
 | 
					  if (!rounded_corner && !has_frame())
 | 
				
			||||||
| 
						 | 
					@ -1061,6 +1061,10 @@ bool NativeWindowMac::HasShadow() {
 | 
				
			||||||
  return [window_ hasShadow];
 | 
					  return [window_ hasShadow];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void NativeWindowMac::InvalidateShadow() {
 | 
				
			||||||
 | 
					  [window_ invalidateShadow];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void NativeWindowMac::SetOpacity(const double opacity) {
 | 
					void NativeWindowMac::SetOpacity(const double opacity) {
 | 
				
			||||||
  const double boundedOpacity = base::clamp(opacity, 0.0, 1.0);
 | 
					  const double boundedOpacity = base::clamp(opacity, 0.0, 1.0);
 | 
				
			||||||
  [window_ setAlphaValue:boundedOpacity];
 | 
					  [window_ setAlphaValue:boundedOpacity];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue