mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: WebContentsView background color incorrectly set
This commit is contained in:
@@ -77,9 +77,11 @@ void WebContentsView::SetBackgroundColor(std::optional<WrappedSkColor> color) {
|
||||
// on the next load URL call
|
||||
auto* web_preferences =
|
||||
WebContentsPreferences::From(api_web_contents_->web_contents());
|
||||
if (web_preferences) {
|
||||
if (web_preferences)
|
||||
web_preferences->SetBackgroundColor(color);
|
||||
}
|
||||
|
||||
auto* iwcv = api_web_contents_->inspectable_web_contents()->GetView();
|
||||
iwcv->SetBackgroundColor(color.value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ using electron::InspectableWebContentsViewMac;
|
||||
(InspectableWebContentsViewMac*)view;
|
||||
- (void)notifyDevToolsFocused;
|
||||
- (void)setCornerRadii:(CGFloat)cornerRadius;
|
||||
- (void)setBackgroundColor:(CGColorRef)color;
|
||||
- (void)setDevToolsVisible:(BOOL)visible activate:(BOOL)activate;
|
||||
- (BOOL)isDevToolsVisible;
|
||||
- (BOOL)isDevToolsFocused;
|
||||
|
||||
@@ -81,16 +81,28 @@
|
||||
inspectableWebContentsView_->GetDelegate()->DevToolsFocused();
|
||||
}
|
||||
|
||||
- (void)setBackgroundColor:(CGColorRef)color {
|
||||
auto* inspectable_web_contents =
|
||||
inspectableWebContentsView_->inspectable_web_contents();
|
||||
DCHECK(inspectable_web_contents);
|
||||
|
||||
if (auto* webContents = inspectable_web_contents->GetWebContents()) {
|
||||
auto* webContentsView = webContents->GetNativeView().GetNativeNSView();
|
||||
webContentsView.wantsLayer = YES;
|
||||
webContentsView.layer.backgroundColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setCornerRadii:(CGFloat)cornerRadius {
|
||||
auto* inspectable_web_contents =
|
||||
inspectableWebContentsView_->inspectable_web_contents();
|
||||
DCHECK(inspectable_web_contents);
|
||||
auto* webContents = inspectable_web_contents->GetWebContents();
|
||||
if (!webContents)
|
||||
return;
|
||||
auto* webContentsView = webContents->GetNativeView().GetNativeNSView();
|
||||
webContentsView.wantsLayer = YES;
|
||||
webContentsView.layer.cornerRadius = cornerRadius;
|
||||
|
||||
if (auto* webContents = inspectable_web_contents->GetWebContents()) {
|
||||
auto* webContentsView = webContents->GetNativeView().GetNativeNSView();
|
||||
webContentsView.wantsLayer = YES;
|
||||
webContentsView.layer.cornerRadius = cornerRadius;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)notifyDevToolsResized {
|
||||
|
||||
@@ -60,6 +60,7 @@ class InspectableWebContentsView {
|
||||
|
||||
virtual void ShowDevTools(bool activate) = 0;
|
||||
virtual void SetCornerRadii(const gfx::RoundedCornersF& corner_radii) = 0;
|
||||
virtual void SetBackgroundColor(std::optional<SkColor> color) = 0;
|
||||
// Hide the DevTools view.
|
||||
virtual void CloseDevTools() = 0;
|
||||
virtual bool IsDevToolsViewShowing() = 0;
|
||||
|
||||
@@ -23,6 +23,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView {
|
||||
|
||||
gfx::NativeView GetNativeView() const override;
|
||||
void SetCornerRadii(const gfx::RoundedCornersF& corner_radii) override;
|
||||
void SetBackgroundColor(std::optional<SkColor> color) override;
|
||||
void ShowDevTools(bool activate) override;
|
||||
void CloseDevTools() override;
|
||||
bool IsDevToolsViewShowing() override;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#import "shell/browser/ui/cocoa/electron_inspectable_web_contents_view.h"
|
||||
#include "shell/browser/ui/inspectable_web_contents.h"
|
||||
#include "shell/browser/ui/inspectable_web_contents_view_delegate.h"
|
||||
#import "skia/ext/skia_utils_mac.h"
|
||||
#include "ui/gfx/geometry/rounded_corners_f.h"
|
||||
|
||||
namespace electron {
|
||||
@@ -33,6 +34,16 @@ gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const {
|
||||
return view_;
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewMac::SetBackgroundColor(
|
||||
std::optional<SkColor> color) {
|
||||
if (!color.has_value())
|
||||
return;
|
||||
|
||||
base::apple::ScopedCFTypeRef<CGColorRef> cgcolor(
|
||||
skia::CGColorCreateFromSkColor(color.value()));
|
||||
[view_ setBackgroundColor:cgcolor.get()];
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewMac::SetCornerRadii(
|
||||
const gfx::RoundedCornersF& corner_radii) {
|
||||
// We can assume all four values are identical.
|
||||
|
||||
@@ -118,6 +118,11 @@ void InspectableWebContentsViewViews::SetCornerRadii(
|
||||
}
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::SetBackgroundColor(
|
||||
std::optional<SkColor> color) {
|
||||
// TODO(codebytere): implement this
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::ShowDevTools(bool activate) {
|
||||
if (devtools_visible_)
|
||||
return;
|
||||
|
||||
@@ -33,6 +33,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView,
|
||||
views::View* GetView() override;
|
||||
void ShowDevTools(bool activate) override;
|
||||
void SetCornerRadii(const gfx::RoundedCornersF& corner_radii) override;
|
||||
void SetBackgroundColor(std::optional<SkColor> color) override;
|
||||
void CloseDevTools() override;
|
||||
bool IsDevToolsViewShowing() override;
|
||||
bool IsDevToolsViewFocused() override;
|
||||
|
||||
Reference in New Issue
Block a user