OLD | NEW |
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (haveSelection && !paintsCompositionMarkers(textBoxLayoutObject)) { | 142 if (haveSelection && !paintsCompositionMarkers(textBoxLayoutObject)) { |
143 if (combinedText) | 143 if (combinedText) |
144 paintSelection<InlineTextBoxPainter::PaintOptions::CombinedText>
(context, boxRect, styleToUse, font, selectionStyle.fillColor, combinedText); | 144 paintSelection<InlineTextBoxPainter::PaintOptions::CombinedText>
(context, boxRect, styleToUse, font, selectionStyle.fillColor, combinedText); |
145 else | 145 else |
146 paintSelection<InlineTextBoxPainter::PaintOptions::Normal>(conte
xt, boxRect, styleToUse, font, selectionStyle.fillColor); | 146 paintSelection<InlineTextBoxPainter::PaintOptions::Normal>(conte
xt, boxRect, styleToUse, font, selectionStyle.fillColor); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 // 2. Now paint the foreground, including text and decorations like underlin
e/overline (in quirks mode only). | 150 // 2. Now paint the foreground, including text and decorations like underlin
e/overline (in quirks mode only). |
151 int length = m_inlineTextBox.len(); | 151 int length = m_inlineTextBox.len(); |
152 StringView string = StringView(m_inlineTextBox.getLineLayoutItem().text(), m
_inlineTextBox.start(), length); | 152 StringView string = m_inlineTextBox.getLineLayoutItem().text().createView(); |
| 153 ASSERT(m_inlineTextBox.start() + length <= string.length()); |
| 154 if (static_cast<unsigned>(length) != string.length() || m_inlineTextBox.star
t()) |
| 155 string.narrow(m_inlineTextBox.start(), length); |
153 int maximumLength = m_inlineTextBox.getLineLayoutItem().textLength() - m_inl
ineTextBox.start(); | 156 int maximumLength = m_inlineTextBox.getLineLayoutItem().textLength() - m_inl
ineTextBox.start(); |
154 | 157 |
155 StringBuilder charactersWithHyphen; | 158 StringBuilder charactersWithHyphen; |
156 TextRun textRun = m_inlineTextBox.constructTextRun(styleToUse, font, string,
maximumLength, m_inlineTextBox.hasHyphen() ? &charactersWithHyphen : 0); | 159 TextRun textRun = m_inlineTextBox.constructTextRun(styleToUse, font, string,
maximumLength, m_inlineTextBox.hasHyphen() ? &charactersWithHyphen : 0); |
157 if (m_inlineTextBox.hasHyphen()) | 160 if (m_inlineTextBox.hasHyphen()) |
158 length = textRun.length(); | 161 length = textRun.length(); |
159 | 162 |
160 int selectionStart = 0; | 163 int selectionStart = 0; |
161 int selectionEnd = 0; | 164 int selectionEnd = 0; |
162 if (paintSelectedTextOnly || paintSelectedTextSeparately) | 165 if (paintSelectedTextOnly || paintSelectedTextSeparately) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 return; | 434 return; |
432 | 435 |
433 // If the text color ends up being the same as the selection background, inv
ert the selection | 436 // If the text color ends up being the same as the selection background, inv
ert the selection |
434 // background. | 437 // background. |
435 if (textColor == c) | 438 if (textColor == c) |
436 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); | 439 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); |
437 | 440 |
438 // If the text is truncated, let the thing being painted in the truncation | 441 // If the text is truncated, let the thing being painted in the truncation |
439 // draw its own highlight. | 442 // draw its own highlight. |
440 int length = m_inlineTextBox.truncation() != cNoTruncation ? m_inlineTextBox
.truncation() : m_inlineTextBox.len(); | 443 int length = m_inlineTextBox.truncation() != cNoTruncation ? m_inlineTextBox
.truncation() : m_inlineTextBox.len(); |
441 StringView string(m_inlineTextBox.getLineLayoutItem().text(), m_inlineTextBo
x.start(), static_cast<unsigned>(length)); | 444 StringView string = m_inlineTextBox.getLineLayoutItem().text().createView(); |
| 445 |
| 446 if (string.length() != static_cast<unsigned>(length) || m_inlineTextBox.star
t()) |
| 447 string.narrow(m_inlineTextBox.start(), length); |
442 | 448 |
443 StringBuilder charactersWithHyphen; | 449 StringBuilder charactersWithHyphen; |
444 bool respectHyphen = ePos == length && m_inlineTextBox.hasHyphen(); | 450 bool respectHyphen = ePos == length && m_inlineTextBox.hasHyphen(); |
445 TextRun textRun = m_inlineTextBox.constructTextRun(style, font, string, m_in
lineTextBox.getLineLayoutItem().textLength() - m_inlineTextBox.start(), respectH
yphen ? &charactersWithHyphen : 0); | 451 TextRun textRun = m_inlineTextBox.constructTextRun(style, font, string, m_in
lineTextBox.getLineLayoutItem().textLength() - m_inlineTextBox.start(), respectH
yphen ? &charactersWithHyphen : 0); |
446 if (respectHyphen) | 452 if (respectHyphen) |
447 ePos = textRun.length(); | 453 ePos = textRun.length(); |
448 | 454 |
449 GraphicsContextStateSaver stateSaver(context); | 455 GraphicsContextStateSaver stateSaver(context); |
450 | 456 |
451 if (options == InlineTextBoxPainter::PaintOptions::CombinedText) { | 457 if (options == InlineTextBoxPainter::PaintOptions::CombinedText) { |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 | 853 |
848 Color color = LayoutTheme::theme().platformTextSearchHighlightColor(marker->
activeMatch()); | 854 Color color = LayoutTheme::theme().platformTextSearchHighlightColor(marker->
activeMatch()); |
849 GraphicsContext& context = paintInfo.context; | 855 GraphicsContext& context = paintInfo.context; |
850 GraphicsContextStateSaver stateSaver(context); | 856 GraphicsContextStateSaver stateSaver(context); |
851 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)); |
852 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); |
853 } | 859 } |
854 | 860 |
855 | 861 |
856 } // namespace blink | 862 } // namespace blink |
OLD | NEW |