Compare commits

...

1 Commits

Author SHA1 Message Date
Shelley Vohr
5072557889 fix: WebContentsView background color incorrectly set 2024-08-13 20:30:17 +02:00
8 changed files with 42 additions and 8 deletions

View File

@@ -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());
}
}

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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.

View File

@@ -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;

View File

@@ -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;