diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index bb1bd5683ae..2a4b322bf52 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -5551,16 +5551,18 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx, return false; } - const gfxFloat startXOffset = aTextBaselinePt.x - aFramePt.x; - gfxFloat xOffset, hyphenWidth; + bool vertical = mTextRun->IsVertical(); + const gfxFloat startIOffset = vertical ? + aTextBaselinePt.y - aFramePt.y : aTextBaselinePt.x - aFramePt.x; + gfxFloat iOffset, hyphenWidth; uint32_t offset, length; // in transformed string SelectionType type; TextRangeStyle rangeStyle; // Draw background colors if (anyBackgrounds) { SelectionIterator iterator(prevailingSelections, aContentOffset, aContentLength, - aProvider, mTextRun, startXOffset); - while (iterator.GetNextSegment(&xOffset, &offset, &length, &hyphenWidth, + aProvider, mTextRun, startIOffset); + while (iterator.GetNextSegment(&iOffset, &offset, &length, &hyphenWidth, &type, &rangeStyle)) { nscolor foreground, background; GetSelectionTextColors(type, aTextPaintStyle, rangeStyle, @@ -5569,11 +5571,18 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx, gfxFloat advance = hyphenWidth + mTextRun->GetAdvanceWidth(offset, length, &aProvider); if (NS_GET_A(background) > 0) { - gfxFloat x = xOffset - (mTextRun->IsRightToLeft() ? advance : 0); + gfxRect bgRect; + gfxFloat offs = iOffset - (mTextRun->IsRightToLeft() ? advance : 0); + if (vertical) { + bgRect = gfxRect(aFramePt.x, aFramePt.y + offs, + GetSize().width, advance); + } else { + bgRect = gfxRect(aFramePt.x + offs, aFramePt.y, + advance, GetSize().height); + } PaintSelectionBackground(aCtx, aTextPaintStyle.PresContext(), background, aDirtyRect, - gfxRect(aFramePt.x + x, aFramePt.y, advance, - GetSize().height), aCallbacks); + bgRect, aCallbacks); } iterator.UpdateWithAdvance(advance); } @@ -5584,13 +5593,15 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx, nsRect dirtyRect(aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height); SelectionIterator iterator(prevailingSelections, aContentOffset, aContentLength, - aProvider, mTextRun, startXOffset); - while (iterator.GetNextSegment(&xOffset, &offset, &length, &hyphenWidth, + aProvider, mTextRun, startIOffset); + while (iterator.GetNextSegment(&iOffset, &offset, &length, &hyphenWidth, &type, &rangeStyle)) { nscolor foreground, background; GetSelectionTextColors(type, aTextPaintStyle, rangeStyle, &foreground, &background); - gfxPoint textBaselinePt(aFramePt.x + xOffset, aTextBaselinePt.y); + gfxPoint textBaselinePt = vertical ? + gfxPoint(aTextBaselinePt.x, aFramePt.y + iOffset) : + gfxPoint(aFramePt.x + iOffset, aTextBaselinePt.y); // Determine what shadow, if any, to draw - either from textStyle // or from the ::-moz-selection pseudo-class if specified there @@ -5611,7 +5622,7 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx, shadow->ShadowAt(i - 1), &aProvider, dirtyRect, aFramePt, textBaselinePt, aCtx, foreground, aClipEdges, - xOffset - (mTextRun->IsRightToLeft() ? + iOffset - (mTextRun->IsRightToLeft() ? shadowMetrics.mBoundingBox.width : 0), shadowMetrics.mBoundingBox); } @@ -5945,10 +5956,17 @@ nsTextFrame::PaintText(nsRenderingContext* aRenderingContext, nsPoint aPt, gfxContext* ctx = aRenderingContext->ThebesContext(); const bool rtl = mTextRun->IsRightToLeft(); + const bool vertical = mTextRun->IsVertical(); const nscoord frameWidth = GetSize().width; gfxPoint framePt(aPt.x, aPt.y); - gfxPoint textBaselinePt(rtl ? gfxFloat(aPt.x + frameWidth) : framePt.x, + gfxPoint textBaselinePt; + if (vertical) { + textBaselinePt = gfxPoint(aPt.x + mAscent, + rtl ? gfxFloat(aPt.y + GetSize().height) : aPt.y); + } else { + textBaselinePt = gfxPoint(rtl ? gfxFloat(aPt.x + frameWidth) : framePt.x, nsLayoutUtils::GetSnappedBaselineY(this, ctx, aPt.y, mAscent)); + } uint32_t startOffset = provider.GetStart().GetSkippedOffset(); uint32_t maxLength = ComputeTransformedLength(provider); nscoord snappedLeftEdge, snappedRightEdge; @@ -5956,7 +5974,11 @@ nsTextFrame::PaintText(nsRenderingContext* aRenderingContext, nsPoint aPt, &startOffset, &maxLength, &snappedLeftEdge, &snappedRightEdge)) { return; } - textBaselinePt.x += rtl ? -snappedRightEdge : snappedLeftEdge; + if (vertical) { + textBaselinePt.y += rtl ? -snappedRightEdge : snappedLeftEdge; + } else { + textBaselinePt.x += rtl ? -snappedRightEdge : snappedLeftEdge; + } nsCharClipDisplayItem::ClipEdges clipEdges(aItem, snappedLeftEdge, snappedRightEdge); nsTextPaintStyle textPaintStyle(this);