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