Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: Source/core/paint/InlineTextBoxPainter.cpp

Issue 988903002: [S.P.] Fix cull rects for InlineTextBox to account for vertical text. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/paint/InlineTextBoxPainter.h" 6 #include "core/paint/InlineTextBoxPainter.h"
7 7
8 #include "core/dom/DocumentMarkerController.h" 8 #include "core/dom/DocumentMarkerController.h"
9 #include "core/dom/RenderedDocumentMarker.h" 9 #include "core/dom/RenderedDocumentMarker.h"
10 #include "core/editing/CompositionUnderline.h" 10 #include "core/editing/CompositionUnderline.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 void InlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) 44 void InlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
45 { 45 {
46 if (m_inlineTextBox.isLineBreak() || !paintInfo.shouldPaintWithinRoot(&m_inl ineTextBox.renderer()) || m_inlineTextBox.renderer().style()->visibility() != VI SIBLE 46 if (m_inlineTextBox.isLineBreak() || !paintInfo.shouldPaintWithinRoot(&m_inl ineTextBox.renderer()) || m_inlineTextBox.renderer().style()->visibility() != VI SIBLE
47 || m_inlineTextBox.truncation() == cFullTruncation || paintInfo.phase == PaintPhaseOutline || !m_inlineTextBox.len()) 47 || m_inlineTextBox.truncation() == cFullTruncation || paintInfo.phase == PaintPhaseOutline || !m_inlineTextBox.len())
48 return; 48 return;
49 49
50 ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintP haseChildOutlines); 50 ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintP haseChildOutlines);
51 51
52 LayoutRect logicalVisualOverflow = m_inlineTextBox.logicalOverflowRect(); 52 const LayoutStyle& styleToUse = m_inlineTextBox.renderer().styleRef(m_inline TextBox.isFirstLineStyle());
53 LayoutUnit logicalStart = logicalVisualOverflow.x() + (m_inlineTextBox.isHor izontal() ? paintOffset.x() : paintOffset.y()); 53 GraphicsContext* context = paintInfo.context;
54 LayoutUnit logicalExtent = logicalVisualOverflow.width();
55
56 LayoutUnit paintEnd = m_inlineTextBox.isHorizontal() ? paintInfo.rect.maxX() : paintInfo.rect.maxY();
57 LayoutUnit paintStart = m_inlineTextBox.isHorizontal() ? paintInfo.rect.x() : paintInfo.rect.y();
58 54
59 // We round the y-axis to ensure consistent line heights. 55 // We round the y-axis to ensure consistent line heights.
60 LayoutPoint adjustedPaintOffset = LayoutPoint(paintOffset.x(), paintOffset.y ().round()); 56 LayoutPoint adjustedPaintOffset = LayoutPoint(paintOffset.x(), paintOffset.y ().round());
61 57
62 if (logicalStart >= paintEnd || logicalStart + logicalExtent <= paintStart) 58 FloatPoint boxOrigin = m_inlineTextBox.locationIncludingFlipping().toFloatPo int();
63 return; 59 boxOrigin.move(adjustedPaintOffset.x().toFloat(), adjustedPaintOffset.y().to Float());
60 FloatRect boxRect(boxOrigin, FloatSize(m_inlineTextBox.logicalWidth(), m_inl ineTextBox.logicalHeight()));
Xianzhu 2015/03/06 23:17:06 It seems that we used overflowRect to check for ea
chrishtr 2015/03/06 23:19:22 Yes. Part of this CL is unifying that code, since
Xianzhu 2015/03/06 23:31:33 Based on InlineBox.cpp, it seems that logicalFrame
chrishtr 2015/03/07 00:52:35 Sigh. Yes it does. Oh well. Going to make this CL
61 bool shouldRotate = false;
62 LayoutTextCombine* combinedText = nullptr;
63 if (!m_inlineTextBox.isHorizontal()) {
64 if (styleToUse.hasTextCombine() && m_inlineTextBox.renderer().isCombineT ext()) {
65 combinedText = &toLayoutTextCombine(m_inlineTextBox.renderer());
66 if (!combinedText->isCombined())
67 combinedText = nullptr;
68 }
69 if (combinedText) {
70 combinedText->updateFont();
71 boxRect.setWidth(combinedText->inlineWidthForLayout());
72 } else {
73 shouldRotate = true;
74 }
75 }
76
77 if (m_inlineTextBox.isHorizontal()) {
78 if (boxRect.x() >= paintInfo.rect.maxX() || boxRect.x() + boxRect.width( ) <= paintInfo.rect.x())
79 return;
80 } else {
81 if (boxRect.y() >= paintInfo.rect.maxY() || boxRect.y() + boxRect.width( ) <= paintInfo.rect.y())
82 return;
83 }
64 84
65 bool isPrinting = m_inlineTextBox.renderer().document().printing(); 85 bool isPrinting = m_inlineTextBox.renderer().document().printing();
66 86
67 // Determine whether or not we're selected. 87 // Determine whether or not we're selected.
68 bool haveSelection = !isPrinting && paintInfo.phase != PaintPhaseTextClip && m_inlineTextBox.selectionState() != LayoutObject::SelectionNone; 88 bool haveSelection = !isPrinting && paintInfo.phase != PaintPhaseTextClip && m_inlineTextBox.selectionState() != LayoutObject::SelectionNone;
69 if (!haveSelection && paintInfo.phase == PaintPhaseSelection) { 89 if (!haveSelection && paintInfo.phase == PaintPhaseSelection) {
70 // When only painting the selection, don't bother to paint if there is n one. 90 // When only painting the selection, don't bother to paint if there is n one.
71 return; 91 return;
72 } 92 }
73 93
74 // The text clip phase already has a DrawingRecorder. Text clips are initiat ed only in BoxPainter::paintLayerExtended, which is already 94 // The text clip phase already has a DrawingRecorder. Text clips are initiat ed only in BoxPainter::paintLayerExtended, which is already
75 // within a DrawingRecorder. 95 // within a DrawingRecorder.
76 OwnPtr<DrawingRecorder> drawingRecorder; 96 OwnPtr<DrawingRecorder> drawingRecorder;
77 if (RuntimeEnabledFeatures::slimmingPaintEnabled() && paintInfo.phase != Pai ntPhaseTextClip) { 97 if (RuntimeEnabledFeatures::slimmingPaintEnabled() && paintInfo.phase != Pai ntPhaseTextClip) {
78 LayoutRect paintRect = logicalVisualOverflow; 98 drawingRecorder = adoptPtr(new DrawingRecorder(paintInfo.context, m_inli neTextBox.displayItemClient(), DisplayItem::paintPhaseToDrawingType(paintInfo.ph ase), boxRect));
Xianzhu 2015/03/06 23:17:06 Ditto.
79 paintRect.moveBy(adjustedPaintOffset);
80 drawingRecorder = adoptPtr(new DrawingRecorder(paintInfo.context, m_inli neTextBox.displayItemClient(), DisplayItem::paintPhaseToDrawingType(paintInfo.ph ase), paintRect));
81 if (drawingRecorder->canUseCachedDrawing()) 99 if (drawingRecorder->canUseCachedDrawing())
82 return; 100 return;
83 } 101 }
84 102
103 if (shouldRotate)
104 context->concatCTM(TextPainter::rotation(boxRect, TextPainter::Clockwise ));
105
106
85 if (m_inlineTextBox.truncation() != cNoTruncation) { 107 if (m_inlineTextBox.truncation() != cNoTruncation) {
86 if (m_inlineTextBox.renderer().containingBlock()->style()->isLeftToRight Direction() != m_inlineTextBox.isLeftToRightDirection()) { 108 if (m_inlineTextBox.renderer().containingBlock()->style()->isLeftToRight Direction() != m_inlineTextBox.isLeftToRightDirection()) {
87 // Make the visible fragment of text hug the edge closest to the res t of the run by moving the origin 109 // Make the visible fragment of text hug the edge closest to the res t of the run by moving the origin
88 // at which we start drawing text. 110 // at which we start drawing text.
89 // e.g. In the case of LTR text truncated in an RTL Context, the cor rect behavior is: 111 // e.g. In the case of LTR text truncated in an RTL Context, the cor rect behavior is:
90 // |Hello|CBA| -> |...He|CBA| 112 // |Hello|CBA| -> |...He|CBA|
91 // In order to draw the fragment "He" aligned to the right edge of i t's box, we need to start drawing 113 // In order to draw the fragment "He" aligned to the right edge of i t's box, we need to start drawing
92 // farther to the right. 114 // farther to the right.
93 // NOTE: WebKit's behavior differs from that of IE which appears to just overlay the ellipsis on top of the 115 // NOTE: WebKit's behavior differs from that of IE which appears to just overlay the ellipsis on top of the
94 // truncated string i.e. |Hello|CBA| -> |...lo|CBA| 116 // truncated string i.e. |Hello|CBA| -> |...lo|CBA|
95 LayoutUnit widthOfVisibleText = m_inlineTextBox.renderer().width(m_i nlineTextBox.start(), m_inlineTextBox.truncation(), m_inlineTextBox.textPos(), m _inlineTextBox.isLeftToRightDirection() ? LTR : RTL, m_inlineTextBox.isFirstLine Style()); 117 LayoutUnit widthOfVisibleText = m_inlineTextBox.renderer().width(m_i nlineTextBox.start(), m_inlineTextBox.truncation(), m_inlineTextBox.textPos(), m _inlineTextBox.isLeftToRightDirection() ? LTR : RTL, m_inlineTextBox.isFirstLine Style());
96 LayoutUnit widthOfHiddenText = m_inlineTextBox.logicalWidth() - widt hOfVisibleText; 118 LayoutUnit widthOfHiddenText = m_inlineTextBox.logicalWidth() - widt hOfVisibleText;
97 // FIXME: The hit testing logic also needs to take this translation into account. 119 // FIXME: The hit testing logic also needs to take this translation into account.
98 LayoutSize truncationOffset(m_inlineTextBox.isLeftToRightDirection() ? widthOfHiddenText : -widthOfHiddenText, 0); 120 LayoutSize truncationOffset(m_inlineTextBox.isLeftToRightDirection() ? widthOfHiddenText : -widthOfHiddenText, 0);
99 adjustedPaintOffset.move(m_inlineTextBox.isHorizontal() ? truncation Offset : truncationOffset.transposedSize()); 121 adjustedPaintOffset.move(m_inlineTextBox.isHorizontal() ? truncation Offset : truncationOffset.transposedSize());
100 } 122 }
101 } 123 }
102 124
103 GraphicsContext* context = paintInfo.context;
104 const LayoutStyle& styleToUse = m_inlineTextBox.renderer().styleRef(m_inline TextBox.isFirstLineStyle());
105
106 FloatPoint boxOrigin = m_inlineTextBox.locationIncludingFlipping().toFloatPo int();
107 boxOrigin.move(adjustedPaintOffset.x().toFloat(), adjustedPaintOffset.y().to Float());
108 FloatRect boxRect(boxOrigin, FloatSize(m_inlineTextBox.logicalWidth(), m_inl ineTextBox.logicalHeight()));
109
110 bool shouldRotate = false;
111 LayoutTextCombine* combinedText = nullptr;
112 if (!m_inlineTextBox.isHorizontal()) {
113 if (styleToUse.hasTextCombine() && m_inlineTextBox.renderer().isCombineT ext()) {
114 combinedText = &toLayoutTextCombine(m_inlineTextBox.renderer());
115 if (!combinedText->isCombined())
116 combinedText = nullptr;
117 }
118 if (combinedText) {
119 combinedText->updateFont();
120 boxRect.setWidth(combinedText->inlineWidthForLayout());
121 } else {
122 shouldRotate = true;
123 context->concatCTM(TextPainter::rotation(boxRect, TextPainter::Clock wise));
124 }
125 }
126
127 // Determine whether or not we have composition underlines to draw. 125 // Determine whether or not we have composition underlines to draw.
128 bool containsComposition = m_inlineTextBox.renderer().node() && m_inlineText Box.renderer().frame()->inputMethodController().compositionNode() == m_inlineTex tBox.renderer().node(); 126 bool containsComposition = m_inlineTextBox.renderer().node() && m_inlineText Box.renderer().frame()->inputMethodController().compositionNode() == m_inlineTex tBox.renderer().node();
129 bool useCustomUnderlines = containsComposition && m_inlineTextBox.renderer() .frame()->inputMethodController().compositionUsesCustomUnderlines(); 127 bool useCustomUnderlines = containsComposition && m_inlineTextBox.renderer() .frame()->inputMethodController().compositionUsesCustomUnderlines();
130 128
131 // Determine text colors. 129 // Determine text colors.
132 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_inlineTextBo x.renderer(), styleToUse, paintInfo.forceBlackText(), isPrinting); 130 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_inlineTextBo x.renderer(), styleToUse, paintInfo.forceBlackText(), isPrinting);
133 TextPainter::Style selectionStyle = TextPainter::selectionPaintingStyle(m_in lineTextBox.renderer(), haveSelection, paintInfo.forceBlackText(), isPrinting, t extStyle); 131 TextPainter::Style selectionStyle = TextPainter::selectionPaintingStyle(m_in lineTextBox.renderer(), haveSelection, paintInfo.forceBlackText(), isPrinting, t extStyle);
134 bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection); 132 bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection);
135 bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != se lectionStyle; 133 bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != se lectionStyle;
136 134
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 LayoutTheme::theme().platformActiveTextSearchHighlightColor() : 813 LayoutTheme::theme().platformActiveTextSearchHighlightColor() :
816 LayoutTheme::theme().platformInactiveTextSearchHighlightColor(); 814 LayoutTheme::theme().platformInactiveTextSearchHighlightColor();
817 GraphicsContextStateSaver stateSaver(*pt); 815 GraphicsContextStateSaver stateSaver(*pt);
818 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_inlineTextBo x.logicalWidth(), selHeight)); 816 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_inlineTextBo x.logicalWidth(), selHeight));
819 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin. y() - deltaY), selHeight, color, sPos, ePos); 817 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin. y() - deltaY), selHeight, color, sPos, ePos);
820 } 818 }
821 } 819 }
822 820
823 821
824 } // namespace blink 822 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698