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

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

Issue 1916943002: Show correct part of truncated text before ellipsis in contrary flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@604144
Patch Set: Updated Created 4 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/line/InlineTextBox.cpp ('k') | 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 "core/paint/InlineTextBoxPainter.h" 5 #include "core/paint/InlineTextBoxPainter.h"
6 6
7 #include "core/editing/CompositionUnderline.h" 7 #include "core/editing/CompositionUnderline.h"
8 #include "core/editing/Editor.h" 8 #include "core/editing/Editor.h"
9 #include "core/editing/markers/DocumentMarkerController.h" 9 #include "core/editing/markers/DocumentMarkerController.h"
10 #include "core/editing/markers/RenderedDocumentMarker.h" 10 #include "core/editing/markers/RenderedDocumentMarker.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 if (DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_inl ineTextBox, DisplayItem::paintPhaseToDrawingType(paintInfo.phase))) 91 if (DrawingRecorder::useCachedDrawingIfPossible(paintInfo.context, m_inl ineTextBox, DisplayItem::paintPhaseToDrawingType(paintInfo.phase)))
92 return; 92 return;
93 LayoutRect paintRect(logicalVisualOverflow); 93 LayoutRect paintRect(logicalVisualOverflow);
94 m_inlineTextBox.logicalRectToPhysicalRect(paintRect); 94 m_inlineTextBox.logicalRectToPhysicalRect(paintRect);
95 if (paintInfo.phase != PaintPhaseSelection && (haveSelection || paintsMa rkerHighlights(*LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.getLineLayou tItem())))) 95 if (paintInfo.phase != PaintPhaseSelection && (haveSelection || paintsMa rkerHighlights(*LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.getLineLayou tItem()))))
96 paintRect.unite(m_inlineTextBox.localSelectionRect(m_inlineTextBox.s tart(), m_inlineTextBox.start() + m_inlineTextBox.len())); 96 paintRect.unite(m_inlineTextBox.localSelectionRect(m_inlineTextBox.s tart(), m_inlineTextBox.start() + m_inlineTextBox.len()));
97 paintRect.moveBy(adjustedPaintOffset); 97 paintRect.moveBy(adjustedPaintOffset);
98 drawingRecorder.emplace(paintInfo.context, m_inlineTextBox, DisplayItem: :paintPhaseToDrawingType(paintInfo.phase), FloatRect(paintRect)); 98 drawingRecorder.emplace(paintInfo.context, m_inlineTextBox, DisplayItem: :paintPhaseToDrawingType(paintInfo.phase), FloatRect(paintRect));
99 } 99 }
100 100
101 if (m_inlineTextBox.truncation() != cNoTruncation) {
102 if (m_inlineTextBox.getLineLayoutItem().containingBlock().style()->isLef tToRightDirection() != m_inlineTextBox.isLeftToRightDirection()) {
103 // Make the visible fragment of text hug the edge closest to the res t of the run by moving the origin
104 // at which we start drawing text.
105 // e.g. In the case of LTR text truncated in an RTL Context, the cor rect behavior is:
106 // |Hello|CBA| -> |...He|CBA|
107 // In order to draw the fragment "He" aligned to the right edge of i t's box, we need to start drawing
108 // farther to the right.
109 // NOTE: WebKit's behavior differs from that of IE which appears to just overlay the ellipsis on top of the
110 // truncated string i.e. |Hello|CBA| -> |...lo|CBA|
111 LayoutUnit widthOfVisibleText = LayoutUnit(m_inlineTextBox.getLineLa youtItem().width(
112 m_inlineTextBox.start(), m_inlineTextBox.truncation(), m_inlineT extBox.textPos(),
113 m_inlineTextBox.isLeftToRightDirection() ? LTR : RTL, m_inlineTe xtBox.isFirstLineStyle()));
114 LayoutUnit widthOfHiddenText = m_inlineTextBox.logicalWidth() - widt hOfVisibleText;
115 // FIXME: The hit testing logic also needs to take this translation into account.
116 LayoutSize truncationOffset(m_inlineTextBox.isLeftToRightDirection() ? widthOfHiddenText : -widthOfHiddenText, LayoutUnit());
117 adjustedPaintOffset.move(m_inlineTextBox.isHorizontal() ? truncation Offset : truncationOffset.transposedSize());
118 }
119 }
120
121 GraphicsContext& context = paintInfo.context; 101 GraphicsContext& context = paintInfo.context;
122 const ComputedStyle& styleToUse = m_inlineTextBox.getLineLayoutItem().styleR ef(m_inlineTextBox.isFirstLineStyle()); 102 const ComputedStyle& styleToUse = m_inlineTextBox.getLineLayoutItem().styleR ef(m_inlineTextBox.isFirstLineStyle());
123 103
124 LayoutPoint boxOrigin(m_inlineTextBox.locationIncludingFlipping()); 104 LayoutPoint boxOrigin(m_inlineTextBox.locationIncludingFlipping());
125 boxOrigin.move(adjustedPaintOffset.x(), adjustedPaintOffset.y()); 105 boxOrigin.move(adjustedPaintOffset.x(), adjustedPaintOffset.y());
126 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_i nlineTextBox.logicalHeight())); 106 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_i nlineTextBox.logicalHeight()));
127 107
128 bool shouldRotate = false; 108 bool shouldRotate = false;
129 LayoutTextCombine* combinedText = nullptr; 109 LayoutTextCombine* combinedText = nullptr;
130 if (!m_inlineTextBox.isHorizontal()) { 110 if (!m_inlineTextBox.isHorizontal()) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 177
198 TextPainter textPainter(context, font, textRun, textOrigin, boxRect, m_inlin eTextBox.isHorizontal()); 178 TextPainter textPainter(context, font, textRun, textOrigin, boxRect, m_inlin eTextBox.isHorizontal());
199 TextEmphasisPosition emphasisMarkPosition; 179 TextEmphasisPosition emphasisMarkPosition;
200 bool hasTextEmphasis = m_inlineTextBox.getEmphasisMarkPosition(styleToUse, e mphasisMarkPosition); 180 bool hasTextEmphasis = m_inlineTextBox.getEmphasisMarkPosition(styleToUse, e mphasisMarkPosition);
201 if (hasTextEmphasis) 181 if (hasTextEmphasis)
202 textPainter.setEmphasisMark(styleToUse.textEmphasisMarkString(), emphasi sMarkPosition); 182 textPainter.setEmphasisMark(styleToUse.textEmphasisMarkString(), emphasi sMarkPosition);
203 if (combinedText) 183 if (combinedText)
204 textPainter.setCombinedText(combinedText); 184 textPainter.setCombinedText(combinedText);
205 185
206 if (!paintSelectedTextOnly) { 186 if (!paintSelectedTextOnly) {
207 // FIXME: Truncate right-to-left text correctly.
208 int startOffset = 0; 187 int startOffset = 0;
209 int endOffset = length; 188 int endOffset = length;
210 if (paintSelectedTextSeparately && selectionStart < selectionEnd) { 189 if (paintSelectedTextSeparately && selectionStart < selectionEnd) {
211 startOffset = selectionEnd; 190 startOffset = selectionEnd;
212 endOffset = selectionStart; 191 endOffset = selectionStart;
213 } 192 }
193 // Where the text and its flow have opposite directions then our offset into the text given by |truncation| is at
194 // the start of the part that will be visible.
195 if (m_inlineTextBox.truncation() != cNoTruncation && m_inlineTextBox.get LineLayoutItem().containingBlock().style()->isLeftToRightDirection() != m_inline TextBox.isLeftToRightDirection()) {
196 startOffset = m_inlineTextBox.truncation();
197 endOffset = textRun.length();
198 }
214 199
215 // FIXME: This cache should probably ultimately be held somewhere else. 200 // FIXME: This cache should probably ultimately be held somewhere else.
216 // A hashmap is convenient to avoid a memory hit when the 201 // A hashmap is convenient to avoid a memory hit when the
217 // RuntimeEnabledFeature is off. 202 // RuntimeEnabledFeature is off.
218 bool textBlobIsCacheable = startOffset == 0 && endOffset == length; 203 bool textBlobIsCacheable = startOffset == 0 && endOffset == length;
219 TextBlobPtr* cachedTextBlob = 0; 204 TextBlobPtr* cachedTextBlob = 0;
220 if (textBlobIsCacheable) 205 if (textBlobIsCacheable)
221 cachedTextBlob = addToTextBlobCache(m_inlineTextBox); 206 cachedTextBlob = addToTextBlobCache(m_inlineTextBox);
222 textPainter.paint(startOffset, endOffset, length, textStyle, cachedTextB lob); 207 textPainter.paint(startOffset, endOffset, length, textStyle, cachedTextB lob);
223 } 208 }
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 853
869 Color color = LayoutTheme::theme().platformTextSearchHighlightColor(marker-> activeMatch()); 854 Color color = LayoutTheme::theme().platformTextSearchHighlightColor(marker-> activeMatch());
870 GraphicsContext& context = paintInfo.context; 855 GraphicsContext& context = paintInfo.context;
871 GraphicsContextStateSaver stateSaver(context); 856 GraphicsContextStateSaver stateSaver(context);
872 context.clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toF loat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight)); 857 context.clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toF loat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight));
873 context.drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos); 858 context.drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos);
874 } 859 }
875 860
876 861
877 } // namespace blink 862 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/line/InlineTextBox.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698