From cc47ff48ae85ab49e5cce95e0101cdd4bbc05db2 Mon Sep 17 00:00:00 2001 From: Vitor Menezes Date: Wed, 10 Aug 2011 12:44:17 -0700 Subject: [PATCH] Bug 676538: Fix regression that caused text-decorations on inline *child* of block to draw at the offset for the block rather than the inline. r=dbaron The FrameProperty representing baseline is set when a block defines text-decorations and has vertically-aligned children, but we were retrieving it whether the block or the vertically-aligned frame itself defined the decorations. As a result, we "undo" the frame offset to get the baseline from the child in that case. --- layout/generic/nsLineLayout.cpp | 2 +- layout/generic/nsTextFrameThebes.cpp | 35 ++++++++++++++++++---------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/layout/generic/nsLineLayout.cpp b/layout/generic/nsLineLayout.cpp index 94f9e9114451..99db1aed7aaf 100644 --- a/layout/generic/nsLineLayout.cpp +++ b/layout/generic/nsLineLayout.cpp @@ -1495,7 +1495,7 @@ nsLineLayout::VerticalAlignLine() if (vAlign.GetUnit() != eStyleUnit_Enumerated || vAlign.GetIntValue() != NS_STYLE_VERTICAL_ALIGN_BASELINE) { - const nscoord offset = baselineY - (pfd->mBounds.y); + const nscoord offset = baselineY - pfd->mBounds.y; f->Properties().Set(nsIFrame::LineBaselineOffset(), NS_INT32_TO_PTR(offset)); } diff --git a/layout/generic/nsTextFrameThebes.cpp b/layout/generic/nsTextFrameThebes.cpp index 00f188b8de9d..2255b53f02e6 100644 --- a/layout/generic/nsTextFrameThebes.cpp +++ b/layout/generic/nsTextFrameThebes.cpp @@ -4279,7 +4279,12 @@ nsTextFrame::GetTextDecorations(nsPresContext* aPresContext, bool nearestBlockFound = false; - for (nsIFrame* f = this, *fParent; f; f = fParent) { + for (nsIFrame* f = this, *fChild = nsnull; + f; + fChild = f, + f = nsLayoutUtils::GetParentOrPlaceholderFor( + aPresContext->FrameManager(), f)) + { nsStyleContext *const context = f->GetStyleContext(); if (!context->HasTextDecorationLines()) { break; @@ -4297,10 +4302,7 @@ nsTextFrame::GetTextDecorations(nsPresContext* aPresContext, nsLayoutUtils::GetColor(f, eCSSProperty_text_decoration_color); } - fParent = nsLayoutUtils::GetParentOrPlaceholderFor( - aPresContext->FrameManager(), f); - const bool firstBlock = !nearestBlockFound && - nsLayoutUtils::GetAsBlock(fParent); + const bool firstBlock = !nearestBlockFound && nsLayoutUtils::GetAsBlock(f); // Not updating positions once we hit a parent block is equivalent to // the CSS 2.1 spec that blocks should propagate decorations down to their @@ -4308,19 +4310,28 @@ nsTextFrame::GetTextDecorations(nsPresContext* aPresContext, // However, if we're vertically aligned within a block, then we need to // recover the right baseline from the line by querying the FrameProperty // that should be set (see nsLineLayout::VerticalAlignLine). - if (firstBlock && - (styleText->mVerticalAlign.GetUnit() != eStyleUnit_Enumerated || - styleText->mVerticalAlign.GetIntValue() != - NS_STYLE_VERTICAL_ALIGN_BASELINE)) { - baselineOffset = frameTopOffset - - NS_PTR_TO_INT32(f->Properties().Get(nsIFrame::LineBaselineOffset())); + if (firstBlock) { + // At this point, fChild can't be null since TextFrames can't be blocks + const nsStyleCoord& vAlign = + fChild->GetStyleContext()->GetStyleTextReset()->mVerticalAlign; + if (vAlign.GetUnit() != eStyleUnit_Enumerated || + vAlign.GetIntValue() != NS_STYLE_VERTICAL_ALIGN_BASELINE) + { + // Since offset is the offset in the child's coordinate space, we have + // to undo the accumulation to bring the transform out of the block's + // coordinate space + baselineOffset = + frameTopOffset - (fChild->GetRect().y - fChild->GetRelativeOffset().y) + - NS_PTR_TO_INT32( + fChild->Properties().Get(nsIFrame::LineBaselineOffset())); + } } else if (!nearestBlockFound) { baselineOffset = frameTopOffset - f->GetBaseline(); } nearestBlockFound = nearestBlockFound || firstBlock; - frameTopOffset += f->GetRect().Y() - f->GetRelativeOffset().y; + frameTopOffset += f->GetRect().y - f->GetRelativeOffset().y; const PRUint8 style = styleText->GetDecorationStyle(); // Accumulate only elements that have decorations with a genuine style