Commit 76e7ac4c authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

[PaintWorklet] Fix shadow offset when page zooms

When the page zooms, for example, to 200%, the offset of the shadow
remains the same as when the page scale is 100%. The problem here is
that whenever we zoom the page, we queue a paint call back. Then the
new paint call back will set the shadow offset with the size that doesn't
account for the page zoom.

The fix is to override the BaseRenderingContext2d::setShadowOffset
method with the zoom.

This CL also includes a layout test to verify the correctness of the fix.

Bug: 849706
Change-Id: I427209fca397a7540936bccd9e8fb18ba7c018ba
Reviewed-on: https://chromium-review.googlesource.com/1087874Reviewed-by: default avatarStephen McGruer <smcgruer@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Xida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564955}
parent e4b8cc1b
......@@ -10,6 +10,8 @@ var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
context.shadowBlur = 40;
context.shadowColor = 'red';
context.shadowOffsetX = 60;
context.shadowOffsetY = 80;
context.fillRect(40, 40, 100, 100);
</script>
</body>
......
......@@ -21,7 +21,16 @@ registerPaint('shadow', class {
paint(ctx) {
ctx.shadowBlur = 20;
ctx.shadowColor = 'red';
ctx.fillRect(20, 20, 50, 50);
ctx.shadowOffsetX = 30;
ctx.shadowOffsetY = 40;
// When we query these things from JS they should not be affected by
// the page zoom.
if (ctx.shadowBlur == 20 && ctx.shadowOffsetX == 30 &&
ctx.shadowOffsetY == 40) {
ctx.fillRect(20, 20, 50, 50);
} else {
ctx.fillRect(0, 0, 10, 10);
}
}
});
</script>
......
......@@ -64,13 +64,13 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
double lineDashOffset() const;
void setLineDashOffset(double);
double shadowOffsetX() const;
void setShadowOffsetX(double);
virtual double shadowOffsetX() const;
virtual void setShadowOffsetX(double);
double shadowOffsetY() const;
void setShadowOffsetY(double);
virtual double shadowOffsetY() const;
virtual void setShadowOffsetY(double);
double shadowBlur() const;
virtual double shadowBlur() const;
virtual void setShadowBlur(double);
String shadowColor() const;
......
......@@ -69,10 +69,30 @@ bool PaintRenderingContext2D::ParseColorOrCurrentColor(
return ::blink::ParseColorOrCurrentColor(color, color_string, nullptr);
}
double PaintRenderingContext2D::shadowBlur() const {
return BaseRenderingContext2D::shadowBlur() / effective_zoom_;
}
void PaintRenderingContext2D::setShadowBlur(double blur) {
BaseRenderingContext2D::setShadowBlur(blur * effective_zoom_);
}
double PaintRenderingContext2D::shadowOffsetX() const {
return BaseRenderingContext2D::shadowOffsetX() / effective_zoom_;
}
void PaintRenderingContext2D::setShadowOffsetX(double x) {
BaseRenderingContext2D::setShadowOffsetX(x * effective_zoom_);
}
double PaintRenderingContext2D::shadowOffsetY() const {
return BaseRenderingContext2D::shadowOffsetY() / effective_zoom_;
}
void PaintRenderingContext2D::setShadowOffsetY(double y) {
BaseRenderingContext2D::setShadowOffsetY(y * effective_zoom_);
}
PaintCanvas* PaintRenderingContext2D::DrawingCanvas() const {
return Canvas();
}
......
......@@ -58,6 +58,13 @@ class MODULES_EXPORT PaintRenderingContext2D : public ScriptWrappable,
void DidDraw(const SkIRect&) final;
double shadowOffsetX() const final;
void setShadowOffsetX(double) final;
double shadowOffsetY() const final;
void setShadowOffsetY(double) final;
double shadowBlur() const final;
void setShadowBlur(double) final;
bool StateHasFilter() final;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment