| 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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 bool InlineTextBoxPainter::shouldPaintTextBox(const PaintInfo& paintInfo) { | 656 bool InlineTextBoxPainter::shouldPaintTextBox(const PaintInfo& paintInfo) { |
| 657 // When painting selection, we want to include a highlight when the | 657 // When painting selection, we want to include a highlight when the |
| 658 // selection spans line breaks. In other cases such as invisible elements | 658 // selection spans line breaks. In other cases such as invisible elements |
| 659 // or those with no text that are not line breaks, we can skip painting | 659 // or those with no text that are not line breaks, we can skip painting |
| 660 // wholesale. | 660 // wholesale. |
| 661 // TODO(wkorman): Constrain line break painting to appropriate paint phase. | 661 // TODO(wkorman): Constrain line break painting to appropriate paint phase. |
| 662 // This code path is only called in PaintPhaseForeground whereas we would | 662 // This code path is only called in PaintPhaseForeground whereas we would |
| 663 // expect PaintPhaseSelection. The existing haveSelection logic in paint() | 663 // expect PaintPhaseSelection. The existing haveSelection logic in paint() |
| 664 // tests for != PaintPhaseTextClip. | 664 // tests for != PaintPhaseTextClip. |
| 665 if (m_inlineTextBox.getLineLayoutItem().style()->visibility() != | 665 if (m_inlineTextBox.getLineLayoutItem().style()->visibility() != |
| 666 EVisibility::Visible || | 666 EVisibility::kVisible || |
| 667 m_inlineTextBox.truncation() == cFullTruncation || !m_inlineTextBox.len()) | 667 m_inlineTextBox.truncation() == cFullTruncation || !m_inlineTextBox.len()) |
| 668 return false; | 668 return false; |
| 669 return true; | 669 return true; |
| 670 } | 670 } |
| 671 | 671 |
| 672 unsigned InlineTextBoxPainter::underlinePaintStart( | 672 unsigned InlineTextBoxPainter::underlinePaintStart( |
| 673 const CompositionUnderline& underline) { | 673 const CompositionUnderline& underline) { |
| 674 DCHECK(m_inlineTextBox.truncation() != cFullTruncation); | 674 DCHECK(m_inlineTextBox.truncation() != cFullTruncation); |
| 675 DCHECK(m_inlineTextBox.len()); | 675 DCHECK(m_inlineTextBox.len()); |
| 676 | 676 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 bool ltr = m_inlineTextBox.isLeftToRightDirection(); | 1049 bool ltr = m_inlineTextBox.isLeftToRightDirection(); |
| 1050 bool flowIsLTR = | 1050 bool flowIsLTR = |
| 1051 m_inlineTextBox.getLineLayoutItem().style()->isLeftToRightDirection(); | 1051 m_inlineTextBox.getLineLayoutItem().style()->isLeftToRightDirection(); |
| 1052 width = LayoutUnit(m_inlineTextBox.getLineLayoutItem().width( | 1052 width = LayoutUnit(m_inlineTextBox.getLineLayoutItem().width( |
| 1053 ltr == flowIsLTR | 1053 ltr == flowIsLTR |
| 1054 ? m_inlineTextBox.start() | 1054 ? m_inlineTextBox.start() |
| 1055 : m_inlineTextBox.start() + m_inlineTextBox.truncation(), | 1055 : m_inlineTextBox.start() + m_inlineTextBox.truncation(), |
| 1056 ltr == flowIsLTR ? m_inlineTextBox.truncation() | 1056 ltr == flowIsLTR ? m_inlineTextBox.truncation() |
| 1057 : m_inlineTextBox.len() - m_inlineTextBox.truncation(), | 1057 : m_inlineTextBox.len() - m_inlineTextBox.truncation(), |
| 1058 m_inlineTextBox.textPos(), | 1058 m_inlineTextBox.textPos(), |
| 1059 flowIsLTR ? TextDirection::Ltr : TextDirection::Rtl, | 1059 flowIsLTR ? TextDirection::kLtr : TextDirection::kRtl, |
| 1060 m_inlineTextBox.isFirstLineStyle())); | 1060 m_inlineTextBox.isFirstLineStyle())); |
| 1061 if (!flowIsLTR) | 1061 if (!flowIsLTR) |
| 1062 localOrigin.move(m_inlineTextBox.logicalWidth() - width, LayoutUnit()); | 1062 localOrigin.move(m_inlineTextBox.logicalWidth() - width, LayoutUnit()); |
| 1063 } | 1063 } |
| 1064 | 1064 |
| 1065 LayoutObject& textBoxLayoutObject = inlineLayoutObject(); | 1065 LayoutObject& textBoxLayoutObject = inlineLayoutObject(); |
| 1066 | 1066 |
| 1067 const ComputedStyle& styleToUse = | 1067 const ComputedStyle& styleToUse = |
| 1068 textBoxLayoutObject.styleRef(m_inlineTextBox.isFirstLineStyle()); | 1068 textBoxLayoutObject.styleRef(m_inlineTextBox.isFirstLineStyle()); |
| 1069 const SimpleFontData* fontData = styleToUse.font().primaryFont(); | 1069 const SimpleFontData* fontData = styleToUse.font().primaryFont(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 unsigned paintEnd = underlinePaintEnd(underline); | 1160 unsigned paintEnd = underlinePaintEnd(underline); |
| 1161 DCHECK_LT(paintStart, paintEnd); | 1161 DCHECK_LT(paintStart, paintEnd); |
| 1162 | 1162 |
| 1163 // start of line to draw | 1163 // start of line to draw |
| 1164 float start = | 1164 float start = |
| 1165 paintStart == m_inlineTextBox.start() | 1165 paintStart == m_inlineTextBox.start() |
| 1166 ? 0 | 1166 ? 0 |
| 1167 : m_inlineTextBox.getLineLayoutItem().width( | 1167 : m_inlineTextBox.getLineLayoutItem().width( |
| 1168 m_inlineTextBox.start(), paintStart - m_inlineTextBox.start(), | 1168 m_inlineTextBox.start(), paintStart - m_inlineTextBox.start(), |
| 1169 m_inlineTextBox.textPos(), | 1169 m_inlineTextBox.textPos(), |
| 1170 m_inlineTextBox.isLeftToRightDirection() ? TextDirection::Ltr | 1170 m_inlineTextBox.isLeftToRightDirection() ? TextDirection::kLtr |
| 1171 : TextDirection::Rtl, | 1171 : TextDirection::kRtl, |
| 1172 m_inlineTextBox.isFirstLineStyle()); | 1172 m_inlineTextBox.isFirstLineStyle()); |
| 1173 // how much line to draw | 1173 // how much line to draw |
| 1174 float width; | 1174 float width; |
| 1175 bool ltr = m_inlineTextBox.isLeftToRightDirection(); | 1175 bool ltr = m_inlineTextBox.isLeftToRightDirection(); |
| 1176 bool flowIsLTR = | 1176 bool flowIsLTR = |
| 1177 m_inlineTextBox.getLineLayoutItem().style()->isLeftToRightDirection(); | 1177 m_inlineTextBox.getLineLayoutItem().style()->isLeftToRightDirection(); |
| 1178 if (paintStart == m_inlineTextBox.start() && | 1178 if (paintStart == m_inlineTextBox.start() && |
| 1179 paintEnd == m_inlineTextBox.end() + 1) { | 1179 paintEnd == m_inlineTextBox.end() + 1) { |
| 1180 width = m_inlineTextBox.logicalWidth().toFloat(); | 1180 width = m_inlineTextBox.logicalWidth().toFloat(); |
| 1181 } else { | 1181 } else { |
| 1182 unsigned paintFrom = ltr == flowIsLTR ? paintStart : paintEnd; | 1182 unsigned paintFrom = ltr == flowIsLTR ? paintStart : paintEnd; |
| 1183 unsigned paintLength = | 1183 unsigned paintLength = |
| 1184 ltr == flowIsLTR | 1184 ltr == flowIsLTR |
| 1185 ? paintEnd - paintStart | 1185 ? paintEnd - paintStart |
| 1186 : m_inlineTextBox.start() + m_inlineTextBox.len() - paintEnd; | 1186 : m_inlineTextBox.start() + m_inlineTextBox.len() - paintEnd; |
| 1187 width = m_inlineTextBox.getLineLayoutItem().width( | 1187 width = m_inlineTextBox.getLineLayoutItem().width( |
| 1188 paintFrom, paintLength, LayoutUnit(m_inlineTextBox.textPos() + start), | 1188 paintFrom, paintLength, LayoutUnit(m_inlineTextBox.textPos() + start), |
| 1189 flowIsLTR ? TextDirection::Ltr : TextDirection::Rtl, | 1189 flowIsLTR ? TextDirection::kLtr : TextDirection::kRtl, |
| 1190 m_inlineTextBox.isFirstLineStyle()); | 1190 m_inlineTextBox.isFirstLineStyle()); |
| 1191 } | 1191 } |
| 1192 // In RTL mode, start and width are computed from the right end of the text | 1192 // In RTL mode, start and width are computed from the right end of the text |
| 1193 // box: starting at |logicalWidth| - |start| and continuing left by |width| to | 1193 // box: starting at |logicalWidth| - |start| and continuing left by |width| to |
| 1194 // |logicalWidth| - |start| - |width|. We will draw that line, but backwards: | 1194 // |logicalWidth| - |start| - |width|. We will draw that line, but backwards: |
| 1195 // |logicalWidth| - |start| - |width| to |logicalWidth| - |start|. | 1195 // |logicalWidth| - |start| - |width| to |logicalWidth| - |start|. |
| 1196 if (!flowIsLTR) | 1196 if (!flowIsLTR) |
| 1197 start = m_inlineTextBox.logicalWidth().toFloat() - width - start; | 1197 start = m_inlineTextBox.logicalWidth().toFloat() - width - start; |
| 1198 | 1198 |
| 1199 // Thick marked text underlines are 2px thick as long as there is room for the | 1199 // Thick marked text underlines are 2px thick as long as there is room for the |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 | 1289 |
| 1290 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), | 1290 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), |
| 1291 m_inlineTextBox.logicalHeight())); | 1291 m_inlineTextBox.logicalHeight())); |
| 1292 context.clip(FloatRect(boxRect)); | 1292 context.clip(FloatRect(boxRect)); |
| 1293 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), | 1293 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), |
| 1294 boxRect.height().toInt(), color, | 1294 boxRect.height().toInt(), color, |
| 1295 paintOffsets.first, paintOffsets.second); | 1295 paintOffsets.first, paintOffsets.second); |
| 1296 } | 1296 } |
| 1297 | 1297 |
| 1298 } // namespace blink | 1298 } // namespace blink |
| OLD | NEW |