| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/InlineTextBoxPainter.h" | 6 #include "core/paint/InlineTextBoxPainter.h" |
| 7 | 7 |
| 8 #include "core/editing/CompositionUnderline.h" | 8 #include "core/editing/CompositionUnderline.h" |
| 9 #include "core/editing/Editor.h" | 9 #include "core/editing/Editor.h" |
| 10 #include "core/editing/markers/DocumentMarkerController.h" | 10 #include "core/editing/markers/DocumentMarkerController.h" |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 DocumentMarker* marker = *markerIt; | 312 DocumentMarker* marker = *markerIt; |
| 313 | 313 |
| 314 // Paint either the background markers or the foreground markers, but no
t both | 314 // Paint either the background markers or the foreground markers, but no
t both |
| 315 switch (marker->type()) { | 315 switch (marker->type()) { |
| 316 case DocumentMarker::Grammar: | 316 case DocumentMarker::Grammar: |
| 317 case DocumentMarker::Spelling: | 317 case DocumentMarker::Spelling: |
| 318 if (background) | 318 if (background) |
| 319 continue; | 319 continue; |
| 320 break; | 320 break; |
| 321 case DocumentMarker::TextMatch: | 321 case DocumentMarker::TextMatch: |
| 322 if (!background) | |
| 323 continue; | |
| 324 break; | 322 break; |
| 325 case DocumentMarker::Composition: | 323 case DocumentMarker::Composition: |
| 326 break; | 324 break; |
| 327 default: | 325 default: |
| 328 continue; | 326 continue; |
| 329 } | 327 } |
| 330 | 328 |
| 331 if (marker->endOffset() <= m_inlineTextBox.start()) { | 329 if (marker->endOffset() <= m_inlineTextBox.start()) { |
| 332 // marker is completely before this run. This might be a marker tha
t sits before the | 330 // marker is completely before this run. This might be a marker tha
t sits before the |
| 333 // first run we draw, or markers that were within runs we skipped du
e to truncation. | 331 // first run we draw, or markers that were within runs we skipped du
e to truncation. |
| 334 continue; | 332 continue; |
| 335 } | 333 } |
| 336 if (marker->startOffset() > m_inlineTextBox.end()) { | 334 if (marker->startOffset() > m_inlineTextBox.end()) { |
| 337 // marker is completely after this run, bail. A later run will pain
t it. | 335 // marker is completely after this run, bail. A later run will pain
t it. |
| 338 break; | 336 break; |
| 339 } | 337 } |
| 340 | 338 |
| 341 // marker intersects this run. Paint it. | 339 // marker intersects this run. Paint it. |
| 342 switch (marker->type()) { | 340 switch (marker->type()) { |
| 343 case DocumentMarker::Spelling: | 341 case DocumentMarker::Spelling: |
| 344 m_inlineTextBox.paintDocumentMarker(pt, boxOrigin, marker, style, fo
nt, false); | 342 m_inlineTextBox.paintDocumentMarker(pt, boxOrigin, marker, style, fo
nt, false); |
| 345 break; | 343 break; |
| 346 case DocumentMarker::Grammar: | 344 case DocumentMarker::Grammar: |
| 347 m_inlineTextBox.paintDocumentMarker(pt, boxOrigin, marker, style, fo
nt, true); | 345 m_inlineTextBox.paintDocumentMarker(pt, boxOrigin, marker, style, fo
nt, true); |
| 348 break; | 346 break; |
| 349 case DocumentMarker::TextMatch: | 347 case DocumentMarker::TextMatch: |
| 350 m_inlineTextBox.paintTextMatchMarker(pt, boxOrigin, marker, style, f
ont); | 348 m_inlineTextBox.paintTextMatchMarker(pt, boxOrigin, marker, style, f
ont, background); |
| 351 break; | 349 break; |
| 352 case DocumentMarker::Composition: | 350 case DocumentMarker::Composition: |
| 353 { | 351 { |
| 354 CompositionUnderline underline(marker->startOffset(), marker->en
dOffset(), marker->underlineColor(), marker->thick(), marker->backgroundColor())
; | 352 CompositionUnderline underline(marker->startOffset(), marker->en
dOffset(), marker->underlineColor(), marker->thick(), marker->backgroundColor())
; |
| 355 if (background) | 353 if (background) |
| 356 paintSingleCompositionBackgroundRun(pt, boxOrigin, style, fo
nt, underline.backgroundColor, underlinePaintStart(underline), underlinePaintEnd
(underline)); | 354 paintSingleCompositionBackgroundRun(pt, boxOrigin, style, fo
nt, underline.backgroundColor, underlinePaintStart(underline), underlinePaintEnd
(underline)); |
| 357 else | 355 else |
| 358 paintCompositionUnderline(pt, boxOrigin, underline); | 356 paintCompositionUnderline(pt, boxOrigin, underline); |
| 359 } | 357 } |
| 360 break; | 358 break; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 // We need to have some space between underlines of subsequent clauses, beca
use some input methods do not use different underline styles for those. | 821 // We need to have some space between underlines of subsequent clauses, beca
use some input methods do not use different underline styles for those. |
| 824 // We make each line shorter, which has a harmless side effect of shortening
the first and last clauses, too. | 822 // We make each line shorter, which has a harmless side effect of shortening
the first and last clauses, too. |
| 825 start += 1; | 823 start += 1; |
| 826 width -= 2; | 824 width -= 2; |
| 827 | 825 |
| 828 ctx->setStrokeColor(underline.color); | 826 ctx->setStrokeColor(underline.color); |
| 829 ctx->setStrokeThickness(lineThickness); | 827 ctx->setStrokeThickness(lineThickness); |
| 830 ctx->drawLineForText(FloatPoint(boxOrigin.x() + start, (boxOrigin.y() + m_in
lineTextBox.logicalHeight() - lineThickness).toFloat()), width, m_inlineTextBox.
lineLayoutItem().document().printing()); | 828 ctx->drawLineForText(FloatPoint(boxOrigin.x() + start, (boxOrigin.y() + m_in
lineTextBox.logicalHeight() - lineThickness).toFloat()), width, m_inlineTextBox.
lineLayoutItem().document().printing()); |
| 831 } | 829 } |
| 832 | 830 |
| 833 void InlineTextBoxPainter::paintTextMatchMarker(GraphicsContext* pt, const Layou
tPoint& boxOrigin, DocumentMarker* marker, const ComputedStyle& style, const Fon
t& font) | 831 void InlineTextBoxPainter::paintTextMatchMarker(GraphicsContext* pt, const Layou
tPoint& boxOrigin, DocumentMarker* marker, const ComputedStyle& style, const Fon
t& font, bool background) |
| 834 { | 832 { |
| 835 // Use same y positioning and height as for selection, so that when the sele
ction and this highlight are on | 833 // Use same y positioning and height as for selection, so that when the sele
ction and this highlight are on |
| 836 // the same word there are no pieces sticking out. | 834 // the same word there are no pieces sticking out. |
| 837 int deltaY = m_inlineTextBox.lineLayoutItem().style()->isFlippedLinesWriting
Mode() ? m_inlineTextBox.root().selectionBottom() - m_inlineTextBox.logicalBotto
m() : m_inlineTextBox.logicalTop() - m_inlineTextBox.root().selectionTop(); | 835 int deltaY = m_inlineTextBox.lineLayoutItem().style()->isFlippedLinesWriting
Mode() ? m_inlineTextBox.root().selectionBottom() - m_inlineTextBox.logicalBotto
m() : m_inlineTextBox.logicalTop() - m_inlineTextBox.root().selectionTop(); |
| 838 int selHeight = m_inlineTextBox.root().selectionHeight(); | 836 int selHeight = m_inlineTextBox.root().selectionHeight(); |
| 839 | 837 |
| 840 int sPos = std::max(marker->startOffset() - m_inlineTextBox.start(), (unsign
ed)0); | 838 int sPos = std::max(marker->startOffset() - m_inlineTextBox.start(), (unsign
ed)0); |
| 841 int ePos = std::min(marker->endOffset() - m_inlineTextBox.start(), m_inlineT
extBox.len()); | 839 int ePos = std::min(marker->endOffset() - m_inlineTextBox.start(), m_inlineT
extBox.len()); |
| 842 TextRun run = m_inlineTextBox.constructTextRun(style, font); | 840 TextRun run = m_inlineTextBox.constructTextRun(style, font); |
| 843 | 841 |
| 844 // Optionally highlight the text | 842 // Optionally highlight the text |
| 845 if (LineLayoutPaintShim::layoutObjectFrom(m_inlineTextBox.lineLayoutItem())-
>frame()->editor().markedTextMatchesAreHighlighted()) { | 843 if (LineLayoutPaintShim::layoutObjectFrom(m_inlineTextBox.lineLayoutItem())-
>frame()->editor().markedTextMatchesAreHighlighted()) { |
| 846 Color color = marker->activeMatch() ? | 844 if (background) { |
| 845 Color color = marker->activeMatch() ? |
| 847 LayoutTheme::theme().platformActiveTextSearchHighlightColor() : | 846 LayoutTheme::theme().platformActiveTextSearchHighlightColor() : |
| 848 LayoutTheme::theme().platformInactiveTextSearchHighlightColor(); | 847 LayoutTheme::theme().platformInactiveTextSearchHighlightColor(); |
| 849 GraphicsContextStateSaver stateSaver(*pt); | 848 GraphicsContextStateSaver stateSaver(*pt); |
| 850 pt->clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toF
loat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight)); | 849 pt->clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY)
.toFloat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight)); |
| 851 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat(),
(boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos); | 850 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat
(), (boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos); |
| 852 | 851 } else { |
| 853 // Also Highlight the text with color:transparent | 852 // Change the text color |
| 854 if (style.visitedDependentColor(CSSPropertyColor) == Color::transparent)
{ | |
| 855 int length = m_inlineTextBox.len(); | 853 int length = m_inlineTextBox.len(); |
| 854 Color textColor = marker->activeMatch() ? |
| 855 LayoutTheme::theme().platformActiveTextSearchColor() : |
| 856 LayoutTheme::theme().platformInactiveTextSearchColor(); |
| 857 if (style.visitedDependentColor(CSSPropertyColor) == textColor) |
| 858 return; |
| 856 TextPainter::Style textStyle; | 859 TextPainter::Style textStyle; |
| 857 // When we use the text as a clip, we only care about the alpha, thu
s we make all the colors black. | 860 // When we use the text as a clip, we only care about the alpha, thu
s we make all the colors black. |
| 858 textStyle.currentColor = textStyle.fillColor = textStyle.strokeColor
= textStyle.emphasisMarkColor = Color::black; | 861 textStyle.currentColor = textStyle.fillColor = textStyle.strokeColor
= textStyle.emphasisMarkColor = textColor; |
| 859 textStyle.strokeWidth = style.textStrokeWidth(); | 862 textStyle.strokeWidth = style.textStrokeWidth(); |
| 860 textStyle.shadow = 0; | 863 textStyle.shadow = 0; |
| 861 | 864 |
| 862 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidt
h(), m_inlineTextBox.logicalHeight())); | 865 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidt
h(), m_inlineTextBox.logicalHeight())); |
| 863 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetri
cs().ascent()); | 866 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetri
cs().ascent()); |
| 864 TextPainter textPainter(pt, font, run, textOrigin, boxRect, m_inline
TextBox.isHorizontal()); | 867 TextPainter textPainter(pt, font, run, textOrigin, boxRect, m_inline
TextBox.isHorizontal()); |
| 865 | 868 |
| 866 textPainter.paint(sPos, ePos, length, textStyle, 0); | 869 textPainter.paint(sPos, ePos, length, textStyle, 0); |
| 867 } | 870 } |
| 868 } | 871 } |
| 869 } | 872 } |
| 870 | 873 |
| 871 | 874 |
| 872 } // namespace blink | 875 } // namespace blink |
| OLD | NEW |