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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 FloatRect(paintRect)); | 540 FloatRect(paintRect)); |
541 } | 541 } |
542 | 542 |
543 GraphicsContext& context = paintInfo.context; | 543 GraphicsContext& context = paintInfo.context; |
544 const ComputedStyle& styleToUse = | 544 const ComputedStyle& styleToUse = |
545 m_inlineTextBox.getLineLayoutItem().styleRef( | 545 m_inlineTextBox.getLineLayoutItem().styleRef( |
546 m_inlineTextBox.isFirstLineStyle()); | 546 m_inlineTextBox.isFirstLineStyle()); |
547 | 547 |
548 LayoutPoint boxOrigin(m_inlineTextBox.physicalLocation()); | 548 LayoutPoint boxOrigin(m_inlineTextBox.physicalLocation()); |
549 boxOrigin.move(adjustedPaintOffset.x(), adjustedPaintOffset.y()); | 549 boxOrigin.move(adjustedPaintOffset.x(), adjustedPaintOffset.y()); |
550 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), | 550 LayoutRect boxRect(boxOrigin, |
551 m_inlineTextBox.logicalHeight())); | 551 LayoutSize(m_inlineTextBox.logicalWidth(), |
| 552 m_inlineTextBox.logicalHeight())); |
552 | 553 |
553 int length = m_inlineTextBox.len(); | 554 int length = m_inlineTextBox.len(); |
554 StringView string = StringView(m_inlineTextBox.getLineLayoutItem().text(), | 555 StringView string = StringView(m_inlineTextBox.getLineLayoutItem().text(), |
555 m_inlineTextBox.start(), length); | 556 m_inlineTextBox.start(), length); |
556 int maximumLength = m_inlineTextBox.getLineLayoutItem().textLength() - | 557 int maximumLength = m_inlineTextBox.getLineLayoutItem().textLength() - |
557 m_inlineTextBox.start(); | 558 m_inlineTextBox.start(); |
558 | 559 |
559 StringBuilder charactersWithHyphen; | 560 StringBuilder charactersWithHyphen; |
560 TextRun textRun = m_inlineTextBox.constructTextRun( | 561 TextRun textRun = m_inlineTextBox.constructTextRun( |
561 styleToUse, string, maximumLength, | 562 styleToUse, string, maximumLength, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 const CompositionUnderline& underline) { | 761 const CompositionUnderline& underline) { |
761 DCHECK(m_inlineTextBox.truncation() != cFullTruncation); | 762 DCHECK(m_inlineTextBox.truncation() != cFullTruncation); |
762 DCHECK(m_inlineTextBox.len()); | 763 DCHECK(m_inlineTextBox.len()); |
763 | 764 |
764 // Start painting at the beginning of the text or the specified underline | 765 // Start painting at the beginning of the text or the specified underline |
765 // start offset, whichever is higher. | 766 // start offset, whichever is higher. |
766 unsigned paintStart = | 767 unsigned paintStart = |
767 std::max(m_inlineTextBox.start(), underline.startOffset()); | 768 std::max(m_inlineTextBox.start(), underline.startOffset()); |
768 // Cap the maximum paint start to (if no truncation) the last character, | 769 // Cap the maximum paint start to (if no truncation) the last character, |
769 // else the last character before the truncation ellipsis. | 770 // else the last character before the truncation ellipsis. |
770 return std::min(paintStart, (m_inlineTextBox.truncation() == cNoTruncation) | 771 return std::min( |
771 ? m_inlineTextBox.end() | 772 paintStart, |
772 : m_inlineTextBox.start() + | 773 (m_inlineTextBox.truncation() == cNoTruncation) |
773 m_inlineTextBox.truncation() - 1); | 774 ? m_inlineTextBox.end() |
| 775 : m_inlineTextBox.start() + m_inlineTextBox.truncation() - 1); |
774 } | 776 } |
775 | 777 |
776 unsigned InlineTextBoxPainter::underlinePaintEnd( | 778 unsigned InlineTextBoxPainter::underlinePaintEnd( |
777 const CompositionUnderline& underline) { | 779 const CompositionUnderline& underline) { |
778 DCHECK(m_inlineTextBox.truncation() != cFullTruncation); | 780 DCHECK(m_inlineTextBox.truncation() != cFullTruncation); |
779 DCHECK(m_inlineTextBox.len()); | 781 DCHECK(m_inlineTextBox.len()); |
780 | 782 |
781 // End painting just past the end of the text or the specified underline end | 783 // End painting just past the end of the text or the specified underline end |
782 // offset, whichever is lower. | 784 // offset, whichever is lower. |
783 unsigned paintEnd = std::min( | 785 unsigned paintEnd = std::min( |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 sPos = std::max<int>(sPos, m_inlineTextBox.truncation()); | 1052 sPos = std::max<int>(sPos, m_inlineTextBox.truncation()); |
1051 else | 1053 else |
1052 length = m_inlineTextBox.truncation(); | 1054 length = m_inlineTextBox.truncation(); |
1053 } | 1055 } |
1054 StringView string(m_inlineTextBox.getLineLayoutItem().text(), start, | 1056 StringView string(m_inlineTextBox.getLineLayoutItem().text(), start, |
1055 static_cast<unsigned>(length)); | 1057 static_cast<unsigned>(length)); |
1056 | 1058 |
1057 StringBuilder charactersWithHyphen; | 1059 StringBuilder charactersWithHyphen; |
1058 bool respectHyphen = ePos == length && m_inlineTextBox.hasHyphen(); | 1060 bool respectHyphen = ePos == length && m_inlineTextBox.hasHyphen(); |
1059 TextRun textRun = m_inlineTextBox.constructTextRun( | 1061 TextRun textRun = m_inlineTextBox.constructTextRun( |
1060 style, string, m_inlineTextBox.getLineLayoutItem().textLength() - | 1062 style, string, |
1061 m_inlineTextBox.start(), | 1063 m_inlineTextBox.getLineLayoutItem().textLength() - |
| 1064 m_inlineTextBox.start(), |
1062 respectHyphen ? &charactersWithHyphen : 0); | 1065 respectHyphen ? &charactersWithHyphen : 0); |
1063 if (respectHyphen) | 1066 if (respectHyphen) |
1064 ePos = textRun.length(); | 1067 ePos = textRun.length(); |
1065 | 1068 |
1066 GraphicsContextStateSaver stateSaver(context); | 1069 GraphicsContextStateSaver stateSaver(context); |
1067 | 1070 |
1068 if (options == InlineTextBoxPainter::PaintOptions::CombinedText) { | 1071 if (options == InlineTextBoxPainter::PaintOptions::CombinedText) { |
1069 DCHECK(combinedText); | 1072 DCHECK(combinedText); |
1070 // We can't use the height of m_inlineTextBox because LayoutTextCombine's | 1073 // We can't use the height of m_inlineTextBox because LayoutTextCombine's |
1071 // inlineTextBox is horizontal within vertical flow | 1074 // inlineTextBox is horizontal within vertical flow |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 DCHECK(fontData); | 1353 DCHECK(fontData); |
1351 if (!fontData) | 1354 if (!fontData) |
1352 return; | 1355 return; |
1353 | 1356 |
1354 TextPainter::Style textStyle; | 1357 TextPainter::Style textStyle; |
1355 textStyle.currentColor = textStyle.fillColor = textStyle.strokeColor = | 1358 textStyle.currentColor = textStyle.fillColor = textStyle.strokeColor = |
1356 textStyle.emphasisMarkColor = textColor; | 1359 textStyle.emphasisMarkColor = textColor; |
1357 textStyle.strokeWidth = style.textStrokeWidth(); | 1360 textStyle.strokeWidth = style.textStrokeWidth(); |
1358 textStyle.shadow = 0; | 1361 textStyle.shadow = 0; |
1359 | 1362 |
1360 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), | 1363 LayoutRect boxRect(boxOrigin, |
1361 m_inlineTextBox.logicalHeight())); | 1364 LayoutSize(m_inlineTextBox.logicalWidth(), |
| 1365 m_inlineTextBox.logicalHeight())); |
1362 LayoutPoint textOrigin(boxOrigin.x(), | 1366 LayoutPoint textOrigin(boxOrigin.x(), |
1363 boxOrigin.y() + fontData->getFontMetrics().ascent()); | 1367 boxOrigin.y() + fontData->getFontMetrics().ascent()); |
1364 TextPainter textPainter(paintInfo.context, font, run, textOrigin, boxRect, | 1368 TextPainter textPainter(paintInfo.context, font, run, textOrigin, boxRect, |
1365 m_inlineTextBox.isHorizontal()); | 1369 m_inlineTextBox.isHorizontal()); |
1366 | 1370 |
1367 textPainter.paint(paintOffsets.first, paintOffsets.second, | 1371 textPainter.paint(paintOffsets.first, paintOffsets.second, |
1368 m_inlineTextBox.len(), textStyle, 0); | 1372 m_inlineTextBox.len(), textStyle, 0); |
1369 } | 1373 } |
1370 | 1374 |
1371 void InlineTextBoxPainter::paintTextMatchMarkerBackground( | 1375 void InlineTextBoxPainter::paintTextMatchMarkerBackground( |
1372 const PaintInfo& paintInfo, | 1376 const PaintInfo& paintInfo, |
1373 const LayoutPoint& boxOrigin, | 1377 const LayoutPoint& boxOrigin, |
1374 const DocumentMarker& marker, | 1378 const DocumentMarker& marker, |
1375 const ComputedStyle& style, | 1379 const ComputedStyle& style, |
1376 const Font& font) { | 1380 const Font& font) { |
1377 if (!LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.getLineLayoutItem()) | 1381 if (!LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.getLineLayoutItem()) |
1378 ->frame() | 1382 ->frame() |
1379 ->editor() | 1383 ->editor() |
1380 .markedTextMatchesAreHighlighted()) | 1384 .markedTextMatchesAreHighlighted()) |
1381 return; | 1385 return; |
1382 | 1386 |
1383 const auto paintOffsets = GetMarkerPaintOffsets(marker, m_inlineTextBox); | 1387 const auto paintOffsets = GetMarkerPaintOffsets(marker, m_inlineTextBox); |
1384 TextRun run = m_inlineTextBox.constructTextRun(style); | 1388 TextRun run = m_inlineTextBox.constructTextRun(style); |
1385 | 1389 |
1386 Color color = LayoutTheme::theme().platformTextSearchHighlightColor( | 1390 Color color = LayoutTheme::theme().platformTextSearchHighlightColor( |
1387 marker.activeMatch()); | 1391 marker.activeMatch()); |
1388 GraphicsContext& context = paintInfo.context; | 1392 GraphicsContext& context = paintInfo.context; |
1389 GraphicsContextStateSaver stateSaver(context); | 1393 GraphicsContextStateSaver stateSaver(context); |
1390 | 1394 |
1391 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), | 1395 LayoutRect boxRect(boxOrigin, |
1392 m_inlineTextBox.logicalHeight())); | 1396 LayoutSize(m_inlineTextBox.logicalWidth(), |
| 1397 m_inlineTextBox.logicalHeight())); |
1393 context.clip(FloatRect(boxRect)); | 1398 context.clip(FloatRect(boxRect)); |
1394 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), | 1399 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), |
1395 boxRect.height().toInt(), color, | 1400 boxRect.height().toInt(), color, |
1396 paintOffsets.first, paintOffsets.second); | 1401 paintOffsets.first, paintOffsets.second); |
1397 } | 1402 } |
1398 | 1403 |
1399 } // namespace blink | 1404 } // namespace blink |
OLD | NEW |