LibWeb: Don't require layout node when setting canvas 2D shadowColor
Use update_style_if_needed_for_element() and resolve colors via computed properties instead of forcing a full layout update.
This commit is contained in:
parent
cbf8b70d42
commit
ca72156497
4 changed files with 20 additions and 5 deletions
|
|
@ -67,7 +67,6 @@ enum class InvalidateLayoutTreeReason {
|
|||
#define ENUMERATE_UPDATE_LAYOUT_REASONS(X) \
|
||||
X(AutoScrollSelection) \
|
||||
X(CanvasRenderingContext2DSetFillStyle) \
|
||||
X(CanvasRenderingContext2DSetShadowColor) \
|
||||
X(CanvasRenderingContext2DSetStrokeStyle) \
|
||||
X(CanvasSetFillStyle) \
|
||||
X(CursorBlinkTimer) \
|
||||
|
|
|
|||
|
|
@ -1107,11 +1107,12 @@ void CanvasRenderingContext2D::set_shadow_color(String color)
|
|||
// 2. Let parsedValue be the result of parsing the given value with context if non-null.
|
||||
auto style_value = parse_css_value(CSS::Parser::ParsingParams(), color, CSS::PropertyID::Color);
|
||||
if (style_value && style_value->has_color()) {
|
||||
DOM::AbstractElement abstract_element { context };
|
||||
context.document().update_style_if_needed_for_element(abstract_element);
|
||||
|
||||
CSS::ColorResolutionContext color_resolution_context {};
|
||||
context.document().update_layout(DOM::UpdateLayoutReason::CanvasRenderingContext2DSetShadowColor);
|
||||
if (auto node = context.layout_node()) {
|
||||
color_resolution_context = CSS::ColorResolutionContext::for_layout_node_with_style(*node);
|
||||
}
|
||||
if (context.computed_properties())
|
||||
color_resolution_context = CSS::ColorResolutionContext::for_element(abstract_element);
|
||||
|
||||
auto parsedValue = style_value->to_color(color_resolution_context).value_or(Color::Black);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
#ff0000
|
||||
rgba(0, 128, 255, 0.5)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
// Setting shadowColor on a detached canvas (no layout node) should not crash.
|
||||
const canvas = document.createElement("canvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
ctx.shadowColor = "red";
|
||||
println(ctx.shadowColor);
|
||||
ctx.shadowColor = "rgba(0, 128, 255, 0.5)";
|
||||
println(ctx.shadowColor);
|
||||
});
|
||||
</script>
|
||||
Loading…
Reference in a new issue