Bug 1816628 Part 1 - Account for horizontal overflow caused by text-shadow r=jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D200435
This commit is contained in:
Robert Longson 2024-02-28 18:51:23 +00:00
parent 7d719a0f5f
commit 1cdd9ca5d0
7 changed files with 25 additions and 26 deletions

View File

@ -115,7 +115,7 @@ function runTest() {
const sin45 = Math.sin(Math.PI / 4);
isfuzzy(text1Bounds.left, 24, 1, "text1.getBoundingClientRect().left");
isfuzzy(text1Bounds.left, 23, 1, "text1.getBoundingClientRect().left");
is(text2Bounds.left, text1Bounds.left + 100, "text2.getBoundingClientRect().left");
is(text2Bounds.top, text1Bounds.top, "text2.getBoundingClientRect().top");
@ -194,9 +194,9 @@ function runTest() {
var text2aBounds = doc.getElementById("text2a").getBoundingClientRect();
isfuzzy(text1aBounds.left, 82, 1, "text1a.getBoundingClientRect().left");
isfuzzy(text1aBounds.left, 81, 1, "text1a.getBoundingClientRect().left");
is(text1aBounds.width, text1Bounds.width + 4, "text1a.getBoundingClientRect().width");
is(text1bBounds.width, text1Bounds.width, "text1b.getBoundingClientRect().width");
isfuzzy(text1bBounds.width, text1Bounds.width + 170, 1, "text1b.getBoundingClientRect().width");
isfuzzy(text1bBounds.height, 196, 5, "text1b.getBoundingClientRect().height");
is(text2aBounds.left, text1aBounds.left + 100 - 3, "text2a.getBoundingClientRect().left");

View File

@ -12,10 +12,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1426594
function runTests() {
let textElement = document.getElementById("textId"),
tspanElement = document.getElementById("tspanId");
textClientRect = textElement.getBoundingClientRect(),
tspanClientRect = document.getElementById("tspanId").getBoundingClientRect();
isfuzzy(textElement.getBoundingClientRect().width, tspanElement.getBoundingClientRect().width, 5);
isfuzzy(textElement.getBoundingClientRect().height, tspanElement.getBoundingClientRect().height, 5);
// TODO: tspan bounds should account for stroke, decorations and text-shadow
isfuzzy(textClientRect.width, tspanClientRect.width, 6, "unexpected width");
isfuzzy(textClientRect.height, tspanClientRect.height, 6, "unexpected height");
SimpleTest.finish();
}

View File

@ -78,7 +78,7 @@ function testSelection() {
deselect();
// Drag from left of the text to the right of the text to select it.
drag(90, 50, 110 + text[0].getComputedTextLength(), 50);
drag(101, 50, 99 + text[0].getComputedTextLength(), 50);
selection_is("hello there", "selecting entire simple text by dragging around it");
deselect();

View File

@ -165,8 +165,7 @@ class nsDisplayTextOverflowMarker final : public nsPaintedDisplayItem {
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
bool* aSnap) const override {
*aSnap = false;
nsRect shadowRect = nsLayoutUtils::GetTextShadowRectsUnion(mRect, mFrame);
return mRect.Union(shadowRect);
return nsLayoutUtils::GetTextShadowRectsUnion(mRect, mFrame);
}
virtual nsRect GetComponentAlphaBounds(

View File

@ -5374,9 +5374,8 @@ void nsTextFrame::UnionAdditionalOverflow(nsPresContext* aPresContext,
// Text-shadow overflows
if (aIncludeShadows) {
nsRect shadowRect =
*aInkOverflowRect =
nsLayoutUtils::GetTextShadowRectsUnion(*aInkOverflowRect, this);
aInkOverflowRect->UnionRect(*aInkOverflowRect, shadowRect);
}
// When this frame is not selected, the text-decoration area must be in

View File

@ -133,7 +133,7 @@ fuzzy(0-4,0-100) == textLength-3.svg textLength-3-ref.svg
== textLength-6.svg textLength-6-ref.svg
# text-shadow
fuzzy(0-127,0-5) fuzzy-if(Android,0-127,0-12) == text-shadow.svg text-shadow-ref.svg
== text-shadow.svg text-shadow-ref.svg
# vertical text
== vertical-01.svg vertical-01-ref.svg
@ -173,7 +173,7 @@ fuzzy(0-127,0-5) fuzzy-if(Android,0-127,0-12) == text-shadow.svg text-shadow-ref
== dynamic-dominant-baseline.svg dynamic-dominant-baseline-ref.svg
== dynamic-multiple-x.svg dynamic-multiple-x-ref.svg
fuzzy(0-1,0-200) == dynamic-non-scaling-stroke.svg dynamic-non-scaling-stroke-ref.svg #Bug 885316
fuzzy(0-127,0-5) fuzzy-if(Android,0-127,0-41) == dynamic-text-shadow.svg text-shadow-ref.svg
== dynamic-text-shadow.svg text-shadow-ref.svg
# text and masks
fuzzy-if(winWidget,0-50,0-224) == mask-applied.svg mask-applied-ref.svg

View File

@ -800,18 +800,18 @@ SVGBBox TextRenderedRun::GetRunUserSpaceRect(nsPresContext* aContext,
return r;
}
// Determine the amount of overflow above and below the frame's mRect.
// Determine the amount of overflow around frame's mRect.
//
// We need to call InkOverflowRectRelativeToSelf because this includes
// overflowing decorations, which the MeasureText call below does not. We
// assume here the decorations only overflow above and below the frame, never
// horizontally.
// overflowing decorations, which the MeasureText call below does not.
nsRect self = mFrame->InkOverflowRectRelativeToSelf();
nsRect rect = mFrame->GetRect();
bool vertical = IsVertical();
nscoord above = vertical ? -self.x : -self.y;
nscoord below =
vertical ? self.XMost() - rect.width : self.YMost() - rect.height;
nsMargin inkOverflow(
vertical ? -self.x : -self.y,
vertical ? self.YMost() - rect.height : self.XMost() - rect.width,
vertical ? self.XMost() - rect.width : self.YMost() - rect.height,
vertical ? -self.y : -self.x);
gfxSkipCharsIterator it = mFrame->EnsureTextRun(nsTextFrame::eInflated);
gfxSkipCharsIterator start = it;
@ -838,8 +838,7 @@ SVGBBox TextRenderedRun::GetRunUserSpaceRect(nsPresContext* aContext,
metrics.mBoundingBox.UnionRect(metrics.mBoundingBox, fontBox);
// Determine the rectangle that covers the rendered run's fill,
// taking into account the measured vertical overflow due to
// decorations.
// taking into account the measured overflow due to decorations.
nscoord baseline =
NSToCoordRoundWithClamp(metrics.mBoundingBox.y + metrics.mAscent);
gfxFloat x, width;
@ -854,10 +853,10 @@ SVGBBox TextRenderedRun::GetRunUserSpaceRect(nsPresContext* aContext,
x = metrics.mBoundingBox.x;
width = metrics.mBoundingBox.width;
}
nsRect fillInAppUnits(
NSToCoordRoundWithClamp(x), baseline - above,
NSToCoordRoundWithClamp(width),
NSToCoordRoundWithClamp(metrics.mBoundingBox.height) + above + below);
nsRect fillInAppUnits(NSToCoordRoundWithClamp(x), baseline,
NSToCoordRoundWithClamp(width),
NSToCoordRoundWithClamp(metrics.mBoundingBox.height));
fillInAppUnits.Inflate(inkOverflow);
if (textRun->IsVertical()) {
// Swap line-relative textMetrics dimensions to physical coordinates.
std::swap(fillInAppUnits.x, fillInAppUnits.y);