| 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 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 { | 770 { |
| 771 if (underline.color == Color::transparent) | 771 if (underline.color == Color::transparent) |
| 772 return; | 772 return; |
| 773 | 773 |
| 774 if (m_inlineTextBox.truncation() == cFullTruncation) | 774 if (m_inlineTextBox.truncation() == cFullTruncation) |
| 775 return; | 775 return; |
| 776 | 776 |
| 777 unsigned paintStart = underlinePaintStart(underline); | 777 unsigned paintStart = underlinePaintStart(underline); |
| 778 unsigned paintEnd = underlinePaintEnd(underline); | 778 unsigned paintEnd = underlinePaintEnd(underline); |
| 779 | 779 |
| 780 // TODO(crbug.com/636060): Handle mixed-flow contexts correctly. | |
| 781 // start of line to draw | 780 // start of line to draw |
| 782 float start = paintStart == static_cast<unsigned>(m_inlineTextBox.start()) ?
0 : | 781 float start = paintStart == static_cast<unsigned>(m_inlineTextBox.start()) ?
0 : |
| 783 m_inlineTextBox.getLineLayoutItem().width(m_inlineTextBox.start(), paint
Start - m_inlineTextBox.start(), m_inlineTextBox.textPos(), m_inlineTextBox.isLe
ftToRightDirection() ? LTR : RTL, m_inlineTextBox.isFirstLineStyle()); | 782 m_inlineTextBox.getLineLayoutItem().width(m_inlineTextBox.start(), paint
Start - m_inlineTextBox.start(), m_inlineTextBox.textPos(), m_inlineTextBox.isLe
ftToRightDirection() ? LTR : RTL, m_inlineTextBox.isFirstLineStyle()); |
| 784 // how much line to draw | 783 // how much line to draw |
| 785 float width = (paintStart == static_cast<unsigned>(m_inlineTextBox.start())
&& paintEnd == static_cast<unsigned>(m_inlineTextBox.end()) + 1) ? m_inlineTextB
ox.logicalWidth().toFloat() : | 784 float width; |
| 786 m_inlineTextBox.getLineLayoutItem().width(paintStart, paintEnd - paintSt
art, LayoutUnit(m_inlineTextBox.textPos() + start), m_inlineTextBox.isLeftToRigh
tDirection() ? LTR : RTL, m_inlineTextBox.isFirstLineStyle()); | 785 bool ltr = m_inlineTextBox.isLeftToRightDirection(); |
| 786 bool flowIsLTR = m_inlineTextBox.getLineLayoutItem().style()->isLeftToRightD
irection(); |
| 787 if (paintStart == static_cast<unsigned>(m_inlineTextBox.start()) && paintEnd
== static_cast<unsigned>(m_inlineTextBox.end()) + 1) { |
| 788 width = m_inlineTextBox.logicalWidth().toFloat(); |
| 789 } else { |
| 790 width = m_inlineTextBox.getLineLayoutItem().width(ltr == flowIsLTR ? pai
ntStart : paintEnd, ltr == flowIsLTR ? paintEnd - paintStart : m_inlineTextBox.l
en() - paintEnd, LayoutUnit(m_inlineTextBox.textPos() + start), flowIsLTR ? LTR
: RTL, m_inlineTextBox.isFirstLineStyle()); |
| 791 } |
| 787 // In RTL mode, start and width are computed from the right end of the text
box: | 792 // In RTL mode, start and width are computed from the right end of the text
box: |
| 788 // starting at |logicalWidth| - |start| and continuing left by |width| to | 793 // starting at |logicalWidth| - |start| and continuing left by |width| to |
| 789 // |logicalWidth| - |start| - |width|. We will draw that line, but | 794 // |logicalWidth| - |start| - |width|. We will draw that line, but |
| 790 // backwards: |logicalWidth| - |start| - |width| to |logicalWidth| - |start|
. | 795 // backwards: |logicalWidth| - |start| - |width| to |logicalWidth| - |start|
. |
| 791 if (!m_inlineTextBox.isLeftToRightDirection()) | 796 if (!flowIsLTR) |
| 792 start = m_inlineTextBox.logicalWidth().toFloat() - width - start; | 797 start = m_inlineTextBox.logicalWidth().toFloat() - width - start; |
| 793 | 798 |
| 794 | 799 |
| 795 // Thick marked text underlines are 2px thick as long as there is room for t
he 2px line under the baseline. | 800 // Thick marked text underlines are 2px thick as long as there is room for t
he 2px line under the baseline. |
| 796 // All other marked text underlines are 1px thick. | 801 // All other marked text underlines are 1px thick. |
| 797 // If there's not enough space the underline will touch or overlap character
s. | 802 // If there's not enough space the underline will touch or overlap character
s. |
| 798 int lineThickness = 1; | 803 int lineThickness = 1; |
| 799 int baseline = m_inlineTextBox.getLineLayoutItem().style(m_inlineTextBox.isF
irstLineStyle())->getFontMetrics().ascent(); | 804 int baseline = m_inlineTextBox.getLineLayoutItem().style(m_inlineTextBox.isF
irstLineStyle())->getFontMetrics().ascent(); |
| 800 if (underline.thick && m_inlineTextBox.logicalHeight() - baseline >= 2) | 805 if (underline.thick && m_inlineTextBox.logicalHeight() - baseline >= 2) |
| 801 lineThickness = 2; | 806 lineThickness = 2; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 GraphicsContext& context = paintInfo.context; | 853 GraphicsContext& context = paintInfo.context; |
| 849 GraphicsContextStateSaver stateSaver(context); | 854 GraphicsContextStateSaver stateSaver(context); |
| 850 | 855 |
| 851 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_i
nlineTextBox.logicalHeight())); | 856 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), m_i
nlineTextBox.logicalHeight())); |
| 852 context.clip(FloatRect(boxRect)); | 857 context.clip(FloatRect(boxRect)); |
| 853 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), boxRect.heigh
t(), color, sPos, ePos); | 858 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), boxRect.heigh
t(), color, sPos, ePos); |
| 854 } | 859 } |
| 855 | 860 |
| 856 | 861 |
| 857 } // namespace blink | 862 } // namespace blink |
| OLD | NEW |