feat: Corner Smoothing CSS rule (Reland) (#46278)

* feat: Corner Smoothing CSS rule (Reland)

Reland of #45185

* Fix patch conflicts

* fixup! Fix patch conflicts

* Update expected image

The dashed border is subtly different. The new version is correct and the old one was incorrect.
This commit is contained in:
Calvin 2025-03-31 10:22:23 -06:00 committed by GitHub
parent fcd836e34f
commit 09135443a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 1276 additions and 1 deletions

View file

@ -134,6 +134,7 @@ fix_software_compositing_infinite_loop.patch
fix_add_method_which_disables_headless_mode_on_native_widget.patch
refactor_unfilter_unresponsive_events.patch
build_disable_thin_lto_mac.patch
feat_corner_smoothing_css_rule_and_blink_painting.patch
build_add_public_config_simdutf_config.patch
fix_multiple_scopedpumpmessagesinprivatemodes_instances.patch
revert_code_health_clean_up_stale_macwebcontentsocclusion.patch

View file

@ -0,0 +1,485 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Calvin Watford <watfordcalvin@gmail.com>
Date: Mon, 9 Dec 2024 16:58:15 -0700
Subject: feat: Corner Smoothing CSS rule and Blink painting
This patch implements the `-electron-corner-smoothing` CSS rule by
making three primary changes to Blink:
1. Adds the `-electron-corner-smoothing` CSS rule:
* Metadata in `blink/renderer/core/css/css_properties.json5`
* Parsing in `blink/renderer/core/css/properties/longhands/longhands_custom.cc`
* Other required definitions for all CSS rules (`css_property_id.mojom`, `css_property_equality.cc`)
2. Modifies how Blink paints rounded rectangles:
* Augments `blink::ContouredRect` to add smoothness.
* Modifies graphics to handle smooth `ContouredRect`s, delegating to
`//electron/shell/renderer/electron_smooth_round_rect`.
3. Adds a renderer preference / web setting:
* Controls whether the CSS rule is available.
* Mostly simple "plumbing" for the setting through blink.
diff --git a/third_party/blink/common/renderer_preferences/renderer_preferences_mojom_traits.cc b/third_party/blink/common/renderer_preferences/renderer_preferences_mojom_traits.cc
index 25cf6b544dcee15a9616b6963eaae0264aba3db6..13d5b30d00ce8dca96eb3bc5454f9d353375d4c6 100644
--- a/third_party/blink/common/renderer_preferences/renderer_preferences_mojom_traits.cc
+++ b/third_party/blink/common/renderer_preferences/renderer_preferences_mojom_traits.cc
@@ -128,6 +128,8 @@ bool StructTraits<blink::mojom::RendererPreferencesDataView,
return false;
}
+ out->electron_corner_smoothing_css = data.electron_corner_smoothing_css();
+
return true;
}
diff --git a/third_party/blink/public/common/renderer_preferences/renderer_preferences.h b/third_party/blink/public/common/renderer_preferences/renderer_preferences.h
index cae096396b0635f1c4bba6ac8fee47fd957dc698..03db6cddab5cd1b9f3f7c90390bc53baa9e14b65 100644
--- a/third_party/blink/public/common/renderer_preferences/renderer_preferences.h
+++ b/third_party/blink/public/common/renderer_preferences/renderer_preferences.h
@@ -91,6 +91,7 @@ struct BLINK_COMMON_EXPORT RendererPreferences {
bool caret_browsing_enabled{false};
bool uses_platform_autofill{false};
std::vector<uint16_t> explicitly_allowed_network_ports;
+ bool electron_corner_smoothing_css;
RendererPreferences();
RendererPreferences(const RendererPreferences& other);
diff --git a/third_party/blink/public/common/renderer_preferences/renderer_preferences_mojom_traits.h b/third_party/blink/public/common/renderer_preferences/renderer_preferences_mojom_traits.h
index 33b4bd3f0c9488f1013aea026c7fe559ba750cd8..6b4157199c14a4c276e65512e89f2429253aec5c 100644
--- a/third_party/blink/public/common/renderer_preferences/renderer_preferences_mojom_traits.h
+++ b/third_party/blink/public/common/renderer_preferences/renderer_preferences_mojom_traits.h
@@ -275,6 +275,11 @@ struct BLINK_COMMON_EXPORT
return data.explicitly_allowed_network_ports;
}
+ static const bool& electron_corner_smoothing_css(
+ const ::blink::RendererPreferences& data) {
+ return data.electron_corner_smoothing_css;
+ }
+
static bool Read(blink::mojom::RendererPreferencesDataView,
::blink::RendererPreferences* out);
};
diff --git a/third_party/blink/public/mojom/renderer_preferences.mojom b/third_party/blink/public/mojom/renderer_preferences.mojom
index bbcec1dcdaaaf932b3d82c64e8aeb2e7c04b05bf..689205607a763c1d6e040069b1357d84e8ba4bd5 100644
--- a/third_party/blink/public/mojom/renderer_preferences.mojom
+++ b/third_party/blink/public/mojom/renderer_preferences.mojom
@@ -201,4 +201,6 @@ struct RendererPreferences {
bool uses_platform_autofill = false;
array<uint16> explicitly_allowed_network_ports;
+
+ bool electron_corner_smoothing_css;
};
diff --git a/third_party/blink/public/mojom/use_counter/metrics/css_property_id.mojom b/third_party/blink/public/mojom/use_counter/metrics/css_property_id.mojom
index 3e3d56992ab135ee88257681f93e39a470192857..26e87c2be381c0fd7d5116d95a107082e2549eae 100644
--- a/third_party/blink/public/mojom/use_counter/metrics/css_property_id.mojom
+++ b/third_party/blink/public/mojom/use_counter/metrics/css_property_id.mojom
@@ -48,6 +48,7 @@ enum CSSSampleId {
kInternalForcedVisitedColor = 0,
kInternalOverflowBlock = 0,
kInternalOverflowInline = 0,
+ kElectronCornerSmoothing = 0,
// This CSSSampleId represents page load for CSS histograms. It is recorded once
// per page visit for each CSS histogram being logged on the blink side and the
diff --git a/third_party/blink/public/web/web_settings.h b/third_party/blink/public/web/web_settings.h
index a53b4901dde0dc83dce6c9b56616eef0d02d94a5..b419672af985f673f375fbb63b4d2b2c419e3e03 100644
--- a/third_party/blink/public/web/web_settings.h
+++ b/third_party/blink/public/web/web_settings.h
@@ -285,6 +285,7 @@ class WebSettings {
virtual void SetRequireTransientActivationAndAuthorizationForSubAppsAPIs(
bool) = 0;
virtual void SetRootScrollbarThemeColor(std::optional<SkColor>) = 0;
+ virtual void SetCornerSmoothingCSS(bool) = 0;
protected:
~WebSettings() = default;
diff --git a/third_party/blink/renderer/build/scripts/core/css/css_properties.py b/third_party/blink/renderer/build/scripts/core/css/css_properties.py
index 753ba8990f722bafd1770a5e70307cff3764d3f1..16cec517d72887c089f85867e8e37c03199ab394 100755
--- a/third_party/blink/renderer/build/scripts/core/css/css_properties.py
+++ b/third_party/blink/renderer/build/scripts/core/css/css_properties.py
@@ -311,7 +311,13 @@ class CSSProperties(object):
name_without_leading_dash = property_.name.original
if name_without_leading_dash.startswith('-'):
name_without_leading_dash = name_without_leading_dash[1:]
+ # Extra sort level to avoid -internal-* properties being assigned
+ # values too large to fit in a byte.
+ internal_weight = 0
+ if property_.name.original.startswith('-internal'):
+ internal_weight = -1
property_.sorting_key = (-property_.priority,
+ internal_weight,
name_without_leading_dash)
sorting_keys = {}
diff --git a/third_party/blink/renderer/core/css/css_properties.json5 b/third_party/blink/renderer/core/css/css_properties.json5
index 6cf39b4a15ac290891d56a8d1d7b30846a329f79..5a0d840d5c01fb1ed95bacd36cc4f01443afdf94 100644
--- a/third_party/blink/renderer/core/css/css_properties.json5
+++ b/third_party/blink/renderer/core/css/css_properties.json5
@@ -8724,6 +8724,24 @@
property_methods: ["ParseShorthand", "CSSValueFromComputedStyleInternal"],
},
+ {
+ name: "-electron-corner-smoothing",
+ property_methods: ["ParseSingleValue"],
+ field_group: "*",
+ field_template: "external",
+ // To keep this patch small, Length is used instead of a more descriptive
+ // custom type.
+ // - `system-ui` = `Length::Auto()`
+ // - percent = `Length::Percent`
+ type_name: "Length",
+ converter: "ConvertCornerSmoothing",
+ keywords: ["system-ui"],
+ default_value: "Length::None()",
+ typedom_types: ["Keyword", "Percentage"],
+ is_border_radius: true,
+ invalidate: ["paint", "border-radius", "clip"],
+ },
+
// Visited properties.
{
name: "-internal-visited-color",
diff --git a/third_party/blink/renderer/core/css/css_property_equality.cc b/third_party/blink/renderer/core/css/css_property_equality.cc
index 998fb2cfb682e61d89bb6f832cd91efa658f9773..8ad689bd9327569d26eb5f449a707d6b0d7c2536 100644
--- a/third_party/blink/renderer/core/css/css_property_equality.cc
+++ b/third_party/blink/renderer/core/css/css_property_equality.cc
@@ -346,6 +346,8 @@ bool CSSPropertyEquality::PropertiesEqual(const PropertyHandle& property,
return a.DominantBaseline() == b.DominantBaseline();
case CSSPropertyID::kDynamicRangeLimit:
return a.GetDynamicRangeLimit() == b.GetDynamicRangeLimit();
+ case CSSPropertyID::kElectronCornerSmoothing:
+ return a.ElectronCornerSmoothing() == b.ElectronCornerSmoothing();
case CSSPropertyID::kEmptyCells:
return a.EmptyCells() == b.EmptyCells();
case CSSPropertyID::kFill:
diff --git a/third_party/blink/renderer/core/css/properties/longhands/longhands_custom.cc b/third_party/blink/renderer/core/css/properties/longhands/longhands_custom.cc
index c1aa3851a8530f1993de160773d3fae107c4d8bd..d0b87808b0d0466473d21720e44366228daed218 100644
--- a/third_party/blink/renderer/core/css/properties/longhands/longhands_custom.cc
+++ b/third_party/blink/renderer/core/css/properties/longhands/longhands_custom.cc
@@ -11857,5 +11857,25 @@ const CSSValue* InternalEmptyLineHeight::ParseSingleValue(
CSSValueID::kNone>(stream);
}
+const CSSValue* ElectronCornerSmoothing::ParseSingleValue(
+ CSSParserTokenStream& stream,
+ const CSSParserContext& context,
+ const CSSParserLocalContext&) const {
+ // Fail parsing if this rule is disabled by document settings.
+ if (Settings* settings = context.GetDocument()->GetSettings();
+ settings && !settings->GetElectronCornerSmoothingCSS()) {
+ return nullptr;
+ }
+
+ // Try to parse `system-ui` keyword first.
+ if (auto* ident =
+ css_parsing_utils::ConsumeIdent<CSSValueID::kSystemUi>(stream)) {
+ return ident;
+ }
+ // Try to parse as percent.
+ return css_parsing_utils::ConsumePercent(
+ stream, context, CSSPrimitiveValue::ValueRange::kNonNegative);
+}
+
} // namespace css_longhand
} // namespace blink
diff --git a/third_party/blink/renderer/core/css/resolver/style_builder_converter.cc b/third_party/blink/renderer/core/css/resolver/style_builder_converter.cc
index 797c8e2d7ee777bcd88e0e4e6a65992342c2a098..c8d024213eb4dfe1ae82e0543f066df55555213e 100644
--- a/third_party/blink/renderer/core/css/resolver/style_builder_converter.cc
+++ b/third_party/blink/renderer/core/css/resolver/style_builder_converter.cc
@@ -3861,4 +3861,12 @@ PositionArea StyleBuilderConverter::ConvertPositionArea(
return PositionArea(span[0], span[1], span[2], span[3]);
}
+Length StyleBuilderConverter::ConvertCornerSmoothing(StyleResolverState& state, const CSSValue& value) {
+ auto* ident = DynamicTo<CSSIdentifierValue>(value);
+ if (ident && ident->GetValueID() == CSSValueID::kSystemUi) {
+ return Length::Auto();
+ }
+ return ConvertLength(state, value);
+}
+
} // namespace blink
diff --git a/third_party/blink/renderer/core/css/resolver/style_builder_converter.h b/third_party/blink/renderer/core/css/resolver/style_builder_converter.h
index c0f4544a38dc486708dec5a4b3646fb3f15ff2e0..8b3d4e95fb690f9e7b38265be0a77d6e49271944 100644
--- a/third_party/blink/renderer/core/css/resolver/style_builder_converter.h
+++ b/third_party/blink/renderer/core/css/resolver/style_builder_converter.h
@@ -421,6 +421,8 @@ class StyleBuilderConverter {
const CSSValue&);
static PositionArea ConvertPositionArea(StyleResolverState&, const CSSValue&);
+
+ static Length ConvertCornerSmoothing(StyleResolverState&, const CSSValue&);
};
template <typename T>
diff --git a/third_party/blink/renderer/core/exported/web_settings_impl.cc b/third_party/blink/renderer/core/exported/web_settings_impl.cc
index 4a29a2200eaab5084078e928a68c862296c6ff91..fcd879deec0e68b3b6988402d19570cf0065daa2 100644
--- a/third_party/blink/renderer/core/exported/web_settings_impl.cc
+++ b/third_party/blink/renderer/core/exported/web_settings_impl.cc
@@ -816,4 +816,8 @@ void WebSettingsImpl::SetRootScrollbarThemeColor(
settings_->SetRootScrollbarThemeColor(theme_color);
}
+void WebSettingsImpl::SetCornerSmoothingCSS(bool available) {
+ settings_->SetElectronCornerSmoothingCSS(available);
+}
+
} // namespace blink
diff --git a/third_party/blink/renderer/core/exported/web_settings_impl.h b/third_party/blink/renderer/core/exported/web_settings_impl.h
index eabcddfa5f17497ef0611fa43f77dd13e2a54e00..96266c4f8c17b589f3d9c549e2836a147b7401ce 100644
--- a/third_party/blink/renderer/core/exported/web_settings_impl.h
+++ b/third_party/blink/renderer/core/exported/web_settings_impl.h
@@ -237,6 +237,7 @@ class CORE_EXPORT WebSettingsImpl final : public WebSettings {
void SetRequireTransientActivationAndAuthorizationForSubAppsAPIs(
bool) override;
void SetRootScrollbarThemeColor(std::optional<SkColor>) override;
+ void SetCornerSmoothingCSS(bool) override;
bool RenderVSyncNotificationEnabled() const {
return render_v_sync_notification_enabled_;
diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
index 9810991e0a5d8b931a70e056b6651b8e5fdb9881..2b37a0209d370629f08e9065a22b92ff52053141 100644
--- a/third_party/blink/renderer/core/exported/web_view_impl.cc
+++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
@@ -3574,6 +3574,9 @@ void WebViewImpl::UpdateRendererPreferences(
#endif
MaybePreloadSystemFonts(GetPage());
+
+ GetSettings()->SetCornerSmoothingCSS(
+ renderer_preferences_.electron_corner_smoothing_css);
}
void WebViewImpl::SetHistoryIndexAndLength(int32_t history_index,
diff --git a/third_party/blink/renderer/core/frame/settings.json5 b/third_party/blink/renderer/core/frame/settings.json5
index f4cdee12ea4352067f5de3e074e43d51ef56d2e5..6377e4b1ea8aa46b0bf69f8420b6c439bea70dba 100644
--- a/third_party/blink/renderer/core/frame/settings.json5
+++ b/third_party/blink/renderer/core/frame/settings.json5
@@ -1261,5 +1261,10 @@
initial: false,
type: "bool"
},
+ {
+ name: "electronCornerSmoothingCSS",
+ initial: true,
+ invalidate: ["Style"],
+ },
],
}
diff --git a/third_party/blink/renderer/core/paint/box_painter_base.cc b/third_party/blink/renderer/core/paint/box_painter_base.cc
index 68dbf4accafc0ce8100d6d488195e9dcde8b1502..dcd13e67acde42b181b219b2f690e2fc76ad917d 100644
--- a/third_party/blink/renderer/core/paint/box_painter_base.cc
+++ b/third_party/blink/renderer/core/paint/box_painter_base.cc
@@ -324,8 +324,9 @@ void BoxPainterBase::PaintNormalBoxShadow(const PaintInfo& info,
if (has_border_radius) {
FloatRoundedRect rounded_fill_rect(fill_rect, border.GetRadii());
ApplySpreadToShadowShape(rounded_fill_rect, shadow.Spread());
- context.FillRoundedRect(
- rounded_fill_rect, Color::kBlack,
+ ContouredRect contoured_fill_rect(rounded_fill_rect, border.GetCornerCurvature());
+ context.FillContouredRect(
+ contoured_fill_rect, Color::kBlack,
PaintAutoDarkMode(style, DarkModeFilter::ElementRole::kBackground));
} else {
fill_rect.Outset(shadow.Spread());
@@ -413,16 +414,20 @@ void BoxPainterBase::PaintInsetBoxShadow(const PaintInfo& info,
AdjustRectForSideClipping(inner_rect, shadow, sides_to_include);
FloatRoundedRect inner_rounded_rect(inner_rect, bounds.GetRadii());
ApplySpreadToShadowShape(inner_rounded_rect, -shadow.Spread());
+ ContouredRect contoured_bounds(
+ bounds, ContouredBorderGeometry::ContouredBorder(
+ style, PhysicalRect::EnclosingRect(bounds.Rect()))
+ .GetCornerCurvature());
if (inner_rounded_rect.IsEmpty()) {
// |AutoDarkMode::Disabled()| is used because |shadow_color| has already
// been adjusted for dark mode.
- context.FillRoundedRect(bounds, shadow_color, AutoDarkMode::Disabled());
+ context.FillContouredRect(contoured_bounds, shadow_color, AutoDarkMode::Disabled());
continue;
}
GraphicsContextStateSaver state_saver(context);
if (bounds.IsRounded()) {
// TODO(crbug.com/397459628) render corner-shape with box-shadow
- context.ClipContouredRect(ContouredRect(bounds));
+ context.ClipContouredRect(contoured_bounds);
} else {
context.Clip(bounds.Rect());
}
diff --git a/third_party/blink/renderer/core/paint/contoured_border_geometry.cc b/third_party/blink/renderer/core/paint/contoured_border_geometry.cc
index b96a3ba1e16b15807086c8e6a256b256b48e8adb..1396fd3214e18e1ded8fd8a83d964c8c824fbc5e 100644
--- a/third_party/blink/renderer/core/paint/contoured_border_geometry.cc
+++ b/third_party/blink/renderer/core/paint/contoured_border_geometry.cc
@@ -43,6 +43,24 @@ float EffectiveCurvature(Superellipse superellipse, const gfx::SizeF& radius) {
: superellipse.Exponent();
}
+float SmoothnessFromLength(const Length& length) {
+ // `none` = 0%
+ if (length.IsNone()) {
+ return 0.0f;
+ }
+
+ // `system-ui` keyword, represented internally as "auto" length
+ if (length.HasAuto()) {
+#if BUILDFLAG(IS_MAC)
+ return 0.6f;
+#else
+ return 0.0f;
+#endif // BUILDFLAG(IS_MAC)
+ }
+
+ return length.Percent() / 100.0f;
+}
+
ContouredRect::CornerCurvature CalcCurvatureFor(
const ComputedStyle& style,
const FloatRoundedRect::Radii& radii) {
@@ -50,7 +68,8 @@ ContouredRect::CornerCurvature CalcCurvatureFor(
EffectiveCurvature(style.CornerTopLeftShape(), radii.TopLeft()),
EffectiveCurvature(style.CornerTopRightShape(), radii.TopRight()),
EffectiveCurvature(style.CornerBottomRightShape(), radii.BottomRight()),
- EffectiveCurvature(style.CornerBottomLeftShape(), radii.BottomLeft()));
+ EffectiveCurvature(style.CornerBottomLeftShape(), radii.BottomLeft()),
+ SmoothnessFromLength(style.ElectronCornerSmoothing()));
}
ContouredRect PixelSnappedContouredBorderInternal(
diff --git a/third_party/blink/renderer/platform/BUILD.gn b/third_party/blink/renderer/platform/BUILD.gn
index ae923ecf6c58d608ed3583312edb48ecb6b7f576..759d991162702d31e77590474bc5764c8fd8229b 100644
--- a/third_party/blink/renderer/platform/BUILD.gn
+++ b/third_party/blink/renderer/platform/BUILD.gn
@@ -1642,6 +1642,8 @@ component("platform") {
"widget/widget_base.h",
"widget/widget_base_client.h",
"windows_keyboard_codes.h",
+ "//electron/shell/renderer/electron_smooth_round_rect.h",
+ "//electron/shell/renderer/electron_smooth_round_rect.cc",
]
sources -= blink_platform_avx_files
diff --git a/third_party/blink/renderer/platform/geometry/contoured_rect.h b/third_party/blink/renderer/platform/geometry/contoured_rect.h
index 1a5d76b145307c11ac71cd5840f7ca166655fde2..a40aee431d9ecf8bdb011ccc4e8a9ecd813ffe3a 100644
--- a/third_party/blink/renderer/platform/geometry/contoured_rect.h
+++ b/third_party/blink/renderer/platform/geometry/contoured_rect.h
@@ -42,19 +42,29 @@ class PLATFORM_EXPORT ContouredRect {
constexpr CornerCurvature(float top_left,
float top_right,
float bottom_right,
- float bottom_left)
+ float bottom_left,
+ float smoothness)
: top_left_(top_left),
top_right_(top_right),
bottom_right_(bottom_right),
- bottom_left_(bottom_left) {
+ bottom_left_(bottom_left),
+ smoothness_(smoothness) {
DCHECK_GE(top_left, 0);
DCHECK_GE(top_right, 0);
DCHECK_GE(bottom_right, 0);
DCHECK_GE(bottom_left, 0);
+ DCHECK_GE(smoothness, 0);
}
+ constexpr CornerCurvature(float top_left,
+ float top_right,
+ float bottom_right,
+ float bottom_left)
+ : CornerCurvature(top_left, top_right, bottom_right, bottom_left, 0) {}
+
+ constexpr bool IsSmooth() const { return smoothness_ > 0.0f; }
constexpr bool IsRound() const {
- return (top_left_ == kRound) && IsUniform();
+ return (top_left_ == kRound) && IsUniform() && !IsSmooth();
}
constexpr bool IsUniform() const {
@@ -66,6 +76,7 @@ class PLATFORM_EXPORT ContouredRect {
constexpr float TopRight() const { return top_right_; }
constexpr float BottomRight() const { return bottom_right_; }
constexpr float BottomLeft() const { return bottom_left_; }
+ constexpr float Smoothness() const { return smoothness_; }
constexpr bool operator==(const CornerCurvature&) const = default;
@@ -76,6 +87,7 @@ class PLATFORM_EXPORT ContouredRect {
float top_right_ = kRound;
float bottom_right_ = kRound;
float bottom_left_ = kRound;
+ float smoothness_ = 0.0f;
};
constexpr ContouredRect() = default;
diff --git a/third_party/blink/renderer/platform/geometry/path.cc b/third_party/blink/renderer/platform/geometry/path.cc
index 4b63f7f3e113e77bf91810b91c5fad1b6bf5de92..6121bd490717ce6bf4ba7d933e1a9f3eae1752e1 100644
--- a/third_party/blink/renderer/platform/geometry/path.cc
+++ b/third_party/blink/renderer/platform/geometry/path.cc
@@ -33,6 +33,7 @@
#include <algorithm>
+#include "electron/shell/renderer/electron_smooth_round_rect.h"
#include "third_party/blink/renderer/platform/geometry/contoured_rect.h"
#include "third_party/blink/renderer/platform/geometry/float_rounded_rect.h"
#include "third_party/blink/renderer/platform/geometry/skia_geometry_utils.h"
@@ -660,6 +661,18 @@ void Path::AddContouredRect(const ContouredRect& contoured_rect) {
return;
}
+ // TODO(clavin): decompose `electron::DrawSmoothRoundRect` into corners
+ if (contoured_rect.GetCornerCurvature().IsSmooth()) {
+ const gfx::RectF& box = rect.Rect();
+ const FloatRoundedRect::Radii& radii = rect.GetRadii();
+ path_.addPath(electron::DrawSmoothRoundRect(
+ box.x(), box.y(), box.width(), box.height(),
+ std::min(contoured_rect.GetCornerCurvature().Smoothness(), 1.0f),
+ radii.TopLeft().width(), radii.TopRight().width(),
+ radii.BottomRight().width(), radii.BottomLeft().width()));
+ return;
+ }
+
const ContouredRect::CornerCurvature& curvature =
contoured_rect.GetCornerCurvature();
path_.moveTo(gfx::PointFToSkPoint(rect.TopLeftCorner().top_right()));
diff --git a/third_party/blink/renderer/platform/graphics/graphics_context.cc b/third_party/blink/renderer/platform/graphics/graphics_context.cc
index 6361cc655af8c2bef6803efe6f3c382c1eadb851..9439df63a7d265d1f93c89c275d84a8a1dde30c6 100644
--- a/third_party/blink/renderer/platform/graphics/graphics_context.cc
+++ b/third_party/blink/renderer/platform/graphics/graphics_context.cc
@@ -924,6 +924,19 @@ void GraphicsContext::FillRectWithRoundedHole(
DarkModeFlags(this, auto_dark_mode, flags));
}
+void GraphicsContext::FillContouredRect(const ContouredRect& contoured_rect,
+ const Color& color,
+ const AutoDarkMode& auto_dark_mode) {
+ if (contoured_rect.HasRoundCurvature()) {
+ FillRoundedRect(contoured_rect.AsRoundedRect(), color, auto_dark_mode);
+ return;
+ }
+
+ cc::PaintFlags flags = ImmutableState()->FillFlags();
+ flags.setColor(color.toSkColor4f());
+ canvas_->drawPath(contoured_rect.GetPath().GetSkPath(), flags);
+}
+
void GraphicsContext::FillEllipse(const gfx::RectF& ellipse,
const AutoDarkMode& auto_dark_mode) {
DrawOval(gfx::RectFToSkRect(ellipse), ImmutableState()->FillFlags(),
diff --git a/third_party/blink/renderer/platform/graphics/graphics_context.h b/third_party/blink/renderer/platform/graphics/graphics_context.h
index 632b0ec1faebc87d13a5538812333bf14f9e402a..ee51cb455600f507e3a97fe3e6f293ff0f47bbd6 100644
--- a/third_party/blink/renderer/platform/graphics/graphics_context.h
+++ b/third_party/blink/renderer/platform/graphics/graphics_context.h
@@ -318,6 +318,9 @@ class PLATFORM_EXPORT GraphicsContext {
const FloatRoundedRect& rounded_hole_rect,
const Color&,
const AutoDarkMode& auto_dark_mode);
+ void FillContouredRect(const ContouredRect& contoured_rect,
+ const Color& color,
+ const AutoDarkMode& auto_dark_mode);
void StrokeRect(const gfx::RectF&,
const AutoDarkMode& auto_dark_mode);