diff --git a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index e851eaeed87..24cc27d27b2 100644 --- a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -1062,12 +1062,19 @@ void CanvasRenderingContext2D::paint_shadow_for_fill_internal(Gfx::Path const& p if (state.current_compositing_and_blending_operator == Gfx::CompositingAndBlendingOperator::Copy) return; + auto alpha = state.global_alpha * (state.shadow_color.alpha() / 255.0f); + auto fill_style_color = state.fill_style.as_color(); + if (fill_style_color.has_value() && fill_style_color->alpha() > 0) + alpha = (fill_style_color->alpha() / 255.0f) * state.global_alpha; + if (alpha == 0.0f) + return; + painter->save(); Gfx::AffineTransform transform; transform.translate(state.shadow_offset_x, state.shadow_offset_y); painter->set_transform(transform); - painter->fill_path(path, state.shadow_color.with_opacity(state.global_alpha), winding_rule, state.shadow_blur, state.current_compositing_and_blending_operator); + painter->fill_path(path, state.shadow_color.with_opacity(alpha), winding_rule, state.shadow_blur, state.current_compositing_and_blending_operator); painter->restore(); @@ -1085,12 +1092,19 @@ void CanvasRenderingContext2D::paint_shadow_for_stroke_internal(Gfx::Path const& if (state.current_compositing_and_blending_operator == Gfx::CompositingAndBlendingOperator::Copy) return; + auto alpha = state.global_alpha * (state.shadow_color.alpha() / 255.0f); + auto fill_style_color = state.fill_style.as_color(); + if (fill_style_color.has_value() && fill_style_color->alpha() > 0) + alpha = (fill_style_color->alpha() / 255.0f) * state.global_alpha; + if (alpha == 0.0f) + return; + painter->save(); Gfx::AffineTransform transform; transform.translate(state.shadow_offset_x, state.shadow_offset_y); painter->set_transform(transform); - painter->stroke_path(path, state.shadow_color.with_opacity(state.global_alpha), state.line_width, state.shadow_blur, state.current_compositing_and_blending_operator); + painter->stroke_path(path, state.shadow_color.with_opacity(alpha), state.line_width, state.shadow_blur, state.current_compositing_and_blending_operator); painter->restore(); diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.1.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.1.txt new file mode 100644 index 00000000000..04bdedfed89 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.1.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Shadow color alpha components are used \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.2.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.2.txt new file mode 100644 index 00000000000..04bdedfed89 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.2.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Shadow color alpha components are used \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.3.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.3.txt new file mode 100644 index 00000000000..70b5cfd29e8 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.3.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Shadows are affected by globalAlpha \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.4.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.4.txt new file mode 100644 index 00000000000..d9404b2aa7e --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.4.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Shadows with alpha components are correctly affected by globalAlpha \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.5.txt b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.5.txt new file mode 100644 index 00000000000..2128d541275 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.5.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Shadows of shapes with alpha components are drawn correctly \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.1.html b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.1.html new file mode 100644 index 00000000000..1cb62d5418b --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/canvas/element/shadows/2d.shadow.alpha.1.html @@ -0,0 +1,33 @@ + + + +
Shadow color alpha components are used
+ + +Actual output:
+ +Expected output:
+
Shadow color alpha components are used
+ + +Actual output:
+ +Expected output:
+
Shadows are affected by globalAlpha
+ + +Actual output:
+ +Expected output:
+
Shadows with alpha components are correctly affected by globalAlpha
+ + +Actual output:
+ +Expected output:
+
Shadows of shapes with alpha components are drawn correctly
+ + +Actual output:
+ +Expected output:
+