| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 if (m_inlineTextBox.truncation() != cNoTruncation) { | 101 if (m_inlineTextBox.truncation() != cNoTruncation) { |
| 102 if (m_inlineTextBox.lineLayoutItem().containingBlock().style()->isLeftTo
RightDirection() != m_inlineTextBox.isLeftToRightDirection()) { | 102 if (m_inlineTextBox.lineLayoutItem().containingBlock().style()->isLeftTo
RightDirection() != 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 | 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. | 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: | 105 // e.g. In the case of LTR text truncated in an RTL Context, the cor
rect behavior is: |
| 106 // |Hello|CBA| -> |...He|CBA| | 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 | 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. | 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 | 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| | 110 // truncated string i.e. |Hello|CBA| -> |...lo|CBA| |
| 111 LayoutUnit widthOfVisibleText = m_inlineTextBox.lineLayoutItem().wid
th(m_inlineTextBox.start(), m_inlineTextBox.truncation(), m_inlineTextBox.textPo
s(), m_inlineTextBox.isLeftToRightDirection() ? LTR : RTL, m_inlineTextBox.isFir
stLineStyle()); | 111 LayoutUnit widthOfVisibleText = LayoutUnit(m_inlineTextBox.lineLayou
tItem().width( |
| 112 m_inlineTextBox.start(), m_inlineTextBox.truncation(), m_inlineT
extBox.textPos(), |
| 113 m_inlineTextBox.isLeftToRightDirection() ? LTR : RTL, m_inlineTe
xtBox.isFirstLineStyle())); |
| 112 LayoutUnit widthOfHiddenText = m_inlineTextBox.logicalWidth() - widt
hOfVisibleText; | 114 LayoutUnit widthOfHiddenText = m_inlineTextBox.logicalWidth() - widt
hOfVisibleText; |
| 113 // FIXME: The hit testing logic also needs to take this translation
into account. | 115 // FIXME: The hit testing logic also needs to take this translation
into account. |
| 114 LayoutSize truncationOffset(m_inlineTextBox.isLeftToRightDirection()
? widthOfHiddenText : -widthOfHiddenText, LayoutUnit()); | 116 LayoutSize truncationOffset(m_inlineTextBox.isLeftToRightDirection()
? widthOfHiddenText : -widthOfHiddenText, LayoutUnit()); |
| 115 adjustedPaintOffset.move(m_inlineTextBox.isHorizontal() ? truncation
Offset : truncationOffset.transposedSize()); | 117 adjustedPaintOffset.move(m_inlineTextBox.isHorizontal() ? truncation
Offset : truncationOffset.transposedSize()); |
| 116 } | 118 } |
| 117 } | 119 } |
| 118 | 120 |
| 119 GraphicsContext& context = paintInfo.context; | 121 GraphicsContext& context = paintInfo.context; |
| 120 const ComputedStyle& styleToUse = m_inlineTextBox.lineLayoutItem().styleRef(
m_inlineTextBox.isFirstLineStyle()); | 122 const ComputedStyle& styleToUse = m_inlineTextBox.lineLayoutItem().styleRef(
m_inlineTextBox.isFirstLineStyle()); |
| 121 | 123 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 405 |
| 404 // Calculate start & width | 406 // Calculate start & width |
| 405 int deltaY = m_inlineTextBox.lineLayoutItem().style()->isFlippedLinesWri
tingMode() ? m_inlineTextBox.root().selectionBottom() - m_inlineTextBox.logicalB
ottom() : m_inlineTextBox.logicalTop() - m_inlineTextBox.root().selectionTop(); | 407 int deltaY = m_inlineTextBox.lineLayoutItem().style()->isFlippedLinesWri
tingMode() ? m_inlineTextBox.root().selectionBottom() - m_inlineTextBox.logicalB
ottom() : m_inlineTextBox.logicalTop() - m_inlineTextBox.root().selectionTop(); |
| 406 int selHeight = m_inlineTextBox.root().selectionHeight(); | 408 int selHeight = m_inlineTextBox.root().selectionHeight(); |
| 407 LayoutPoint startPoint(boxOrigin.x(), boxOrigin.y() - deltaY); | 409 LayoutPoint startPoint(boxOrigin.x(), boxOrigin.y() - deltaY); |
| 408 TextRun run = m_inlineTextBox.constructTextRun(style, font); | 410 TextRun run = m_inlineTextBox.constructTextRun(style, font); |
| 409 | 411 |
| 410 // FIXME: Convert the document markers to float rects. | 412 // FIXME: Convert the document markers to float rects. |
| 411 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, Flo
atPoint(startPoint), selHeight, startPosition, endPosition)); | 413 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, Flo
atPoint(startPoint), selHeight, startPosition, endPosition)); |
| 412 start = markerRect.x() - startPoint.x(); | 414 start = markerRect.x() - startPoint.x(); |
| 413 width = markerRect.width(); | 415 width = LayoutUnit(markerRect.width()); |
| 414 } | 416 } |
| 415 | 417 |
| 416 // IMPORTANT: The misspelling underline is not considered when calculating t
he text bounds, so we have to | 418 // IMPORTANT: The misspelling underline is not considered when calculating t
he text bounds, so we have to |
| 417 // make sure to fit within those bounds. This means the top pixel(s) of the
underline will overlap the | 419 // make sure to fit within those bounds. This means the top pixel(s) of the
underline will overlap the |
| 418 // bottom pixel(s) of the glyphs in smaller font sizes. The alternatives ar
e to increase the line spacing (bad!!) | 420 // bottom pixel(s) of the glyphs in smaller font sizes. The alternatives ar
e to increase the line spacing (bad!!) |
| 419 // or decrease the underline thickness. The overlap is actually the most us
eful, and matches what AppKit does. | 421 // or decrease the underline thickness. The overlap is actually the most us
eful, and matches what AppKit does. |
| 420 // So, we generally place the underline at the bottom of the text, but in la
rger fonts that's not so good so | 422 // So, we generally place the underline at the bottom of the text, but in la
rger fonts that's not so good so |
| 421 // we pin to two pixels under the baseline. | 423 // we pin to two pixels under the baseline. |
| 422 int lineThickness = misspellingLineThickness; | 424 int lineThickness = misspellingLineThickness; |
| 423 int baseline = m_inlineTextBox.lineLayoutItem().style(m_inlineTextBox.isFirs
tLineStyle())->fontMetrics().ascent(); | 425 int baseline = m_inlineTextBox.lineLayoutItem().style(m_inlineTextBox.isFirs
tLineStyle())->fontMetrics().ascent(); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 if (m_inlineTextBox.truncation() == cFullTruncation) | 731 if (m_inlineTextBox.truncation() == cFullTruncation) |
| 730 return; | 732 return; |
| 731 | 733 |
| 732 GraphicsContext& context = paintInfo.context; | 734 GraphicsContext& context = paintInfo.context; |
| 733 GraphicsContextStateSaver stateSaver(context); | 735 GraphicsContextStateSaver stateSaver(context); |
| 734 | 736 |
| 735 LayoutPoint localOrigin(boxOrigin); | 737 LayoutPoint localOrigin(boxOrigin); |
| 736 | 738 |
| 737 LayoutUnit width = m_inlineTextBox.logicalWidth(); | 739 LayoutUnit width = m_inlineTextBox.logicalWidth(); |
| 738 if (m_inlineTextBox.truncation() != cNoTruncation) { | 740 if (m_inlineTextBox.truncation() != cNoTruncation) { |
| 739 width = m_inlineTextBox.lineLayoutItem().width(m_inlineTextBox.start(),
m_inlineTextBox.truncation(), m_inlineTextBox.textPos(), m_inlineTextBox.isLeftT
oRightDirection() ? LTR : RTL, m_inlineTextBox.isFirstLineStyle()); | 741 width = LayoutUnit(m_inlineTextBox.lineLayoutItem().width( |
| 742 m_inlineTextBox.start(), m_inlineTextBox.truncation(), m_inlineTextB
ox.textPos(), |
| 743 m_inlineTextBox.isLeftToRightDirection() ? LTR : RTL, m_inlineTextBo
x.isFirstLineStyle())); |
| 740 if (!m_inlineTextBox.isLeftToRightDirection()) | 744 if (!m_inlineTextBox.isLeftToRightDirection()) |
| 741 localOrigin.move(m_inlineTextBox.logicalWidth() - width, LayoutUnit(
)); | 745 localOrigin.move(m_inlineTextBox.logicalWidth() - width, LayoutUnit(
)); |
| 742 } | 746 } |
| 743 | 747 |
| 744 // Get the text decoration colors. | 748 // Get the text decoration colors. |
| 745 LayoutObject::AppliedTextDecoration underline, overline, linethrough; | 749 LayoutObject::AppliedTextDecoration underline, overline, linethrough; |
| 746 LayoutObject& textBoxLayoutObject = *LineLayoutAPIShim::layoutObjectFrom(m_i
nlineTextBox.lineLayoutItem()); | 750 LayoutObject& textBoxLayoutObject = *LineLayoutAPIShim::layoutObjectFrom(m_i
nlineTextBox.lineLayoutItem()); |
| 747 textBoxLayoutObject.getTextDecorations(deco, underline, overline, linethroug
h, true); | 751 textBoxLayoutObject.getTextDecorations(deco, underline, overline, linethroug
h, true); |
| 748 if (m_inlineTextBox.isFirstLineStyle()) | 752 if (m_inlineTextBox.isFirstLineStyle()) |
| 749 textBoxLayoutObject.getTextDecorations(deco, underline, overline, lineth
rough, true, true); | 753 textBoxLayoutObject.getTextDecorations(deco, underline, overline, lineth
rough, true, true); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 return; | 796 return; |
| 793 | 797 |
| 794 unsigned paintStart = underlinePaintStart(underline); | 798 unsigned paintStart = underlinePaintStart(underline); |
| 795 unsigned paintEnd = underlinePaintEnd(underline); | 799 unsigned paintEnd = underlinePaintEnd(underline); |
| 796 | 800 |
| 797 // start of line to draw | 801 // start of line to draw |
| 798 float start = paintStart == static_cast<unsigned>(m_inlineTextBox.start()) ?
0 : | 802 float start = paintStart == static_cast<unsigned>(m_inlineTextBox.start()) ?
0 : |
| 799 m_inlineTextBox.lineLayoutItem().width(m_inlineTextBox.start(), paintSta
rt - m_inlineTextBox.start(), m_inlineTextBox.textPos(), m_inlineTextBox.isLeftT
oRightDirection() ? LTR : RTL, m_inlineTextBox.isFirstLineStyle()); | 803 m_inlineTextBox.lineLayoutItem().width(m_inlineTextBox.start(), paintSta
rt - m_inlineTextBox.start(), m_inlineTextBox.textPos(), m_inlineTextBox.isLeftT
oRightDirection() ? LTR : RTL, m_inlineTextBox.isFirstLineStyle()); |
| 800 // how much line to draw | 804 // how much line to draw |
| 801 float width = (paintStart == static_cast<unsigned>(m_inlineTextBox.start())
&& paintEnd == static_cast<unsigned>(m_inlineTextBox.end()) + 1) ? m_inlineTextB
ox.logicalWidth().toFloat() : | 805 float width = (paintStart == static_cast<unsigned>(m_inlineTextBox.start())
&& paintEnd == static_cast<unsigned>(m_inlineTextBox.end()) + 1) ? m_inlineTextB
ox.logicalWidth().toFloat() : |
| 802 m_inlineTextBox.lineLayoutItem().width(paintStart, paintEnd - paintStart
, m_inlineTextBox.textPos() + start, m_inlineTextBox.isLeftToRightDirection() ?
LTR : RTL, m_inlineTextBox.isFirstLineStyle()); | 806 m_inlineTextBox.lineLayoutItem().width(paintStart, paintEnd - paintStart
, LayoutUnit(m_inlineTextBox.textPos() + start), m_inlineTextBox.isLeftToRightDi
rection() ? LTR : RTL, m_inlineTextBox.isFirstLineStyle()); |
| 803 // In RTL mode, start and width are computed from the right end of the text
box: | 807 // In RTL mode, start and width are computed from the right end of the text
box: |
| 804 // starting at |logicalWidth| - |start| and continuing left by |width| to | 808 // starting at |logicalWidth| - |start| and continuing left by |width| to |
| 805 // |logicalWidth| - |start| - |width|. We will draw that line, but | 809 // |logicalWidth| - |start| - |width|. We will draw that line, but |
| 806 // backwards: |logicalWidth| - |start| - |width| to |logicalWidth| - |start|
. | 810 // backwards: |logicalWidth| - |start| - |width| to |logicalWidth| - |start|
. |
| 807 if (!m_inlineTextBox.isLeftToRightDirection()) | 811 if (!m_inlineTextBox.isLeftToRightDirection()) |
| 808 start = m_inlineTextBox.logicalWidth().toFloat() - width - start; | 812 start = m_inlineTextBox.logicalWidth().toFloat() - width - start; |
| 809 | 813 |
| 810 | 814 |
| 811 // Thick marked text underlines are 2px thick as long as there is room for t
he 2px line under the baseline. | 815 // Thick marked text underlines are 2px thick as long as there is room for t
he 2px line under the baseline. |
| 812 // All other marked text underlines are 1px thick. | 816 // All other marked text underlines are 1px thick. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 | 871 |
| 868 Color color = LayoutTheme::theme().platformTextSearchHighlightColor(marker->
activeMatch()); | 872 Color color = LayoutTheme::theme().platformTextSearchHighlightColor(marker->
activeMatch()); |
| 869 GraphicsContext& context = paintInfo.context; | 873 GraphicsContext& context = paintInfo.context; |
| 870 GraphicsContextStateSaver stateSaver(context); | 874 GraphicsContextStateSaver stateSaver(context); |
| 871 context.clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toF
loat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight)); | 875 context.clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toF
loat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight)); |
| 872 context.drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat(),
(boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos); | 876 context.drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat(),
(boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos); |
| 873 } | 877 } |
| 874 | 878 |
| 875 | 879 |
| 876 } // namespace blink | 880 } // namespace blink |
| OLD | NEW |