| 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/dom/DocumentMarkerController.h" | 8 #include "core/dom/DocumentMarkerController.h" |
| 9 #include "core/dom/RenderedDocumentMarker.h" | 9 #include "core/dom/RenderedDocumentMarker.h" |
| 10 #include "core/editing/CompositionUnderline.h" | 10 #include "core/editing/CompositionUnderline.h" |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 x += 2 * step; | 674 x += 2 * step; |
| 675 path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(x, yA
xis)); | 675 path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(x, yA
xis)); |
| 676 } | 676 } |
| 677 } | 677 } |
| 678 | 678 |
| 679 context->setShouldAntialias(true); | 679 context->setShouldAntialias(true); |
| 680 context->strokePath(path); | 680 context->strokePath(path); |
| 681 } | 681 } |
| 682 | 682 |
| 683 static void paintAppliedDecoration(GraphicsContext* context, FloatPoint start, f
loat width, float doubleOffset, int wavyOffsetFactor, | 683 static void paintAppliedDecoration(GraphicsContext* context, FloatPoint start, f
loat width, float doubleOffset, int wavyOffsetFactor, |
| 684 LayoutObject::AppliedTextDecoration decoration, float thickness, bool antial
iasDecoration, bool isPrinting) | 684 AppliedTextDecoration decoration, float thickness, bool antialiasDecoration,
bool isPrinting) |
| 685 { | 685 { |
| 686 context->setStrokeStyle(textDecorationStyleToStrokeStyle(decoration.style)); | 686 context->setStrokeStyle(textDecorationStyleToStrokeStyle(decoration.style())
); |
| 687 context->setStrokeColor(decoration.color); | 687 context->setStrokeColor(decoration.color()); |
| 688 | 688 |
| 689 switch (decoration.style) { | 689 switch (decoration.style()) { |
| 690 case TextDecorationStyleWavy: | 690 case TextDecorationStyleWavy: |
| 691 strokeWavyTextDecoration(context, start + FloatPoint(0, doubleOffset * w
avyOffsetFactor), start + FloatPoint(width, doubleOffset * wavyOffsetFactor), th
ickness); | 691 strokeWavyTextDecoration(context, start + FloatPoint(0, doubleOffset * w
avyOffsetFactor), start + FloatPoint(width, doubleOffset * wavyOffsetFactor), th
ickness); |
| 692 break; | 692 break; |
| 693 case TextDecorationStyleDotted: | 693 case TextDecorationStyleDotted: |
| 694 case TextDecorationStyleDashed: | 694 case TextDecorationStyleDashed: |
| 695 context->setShouldAntialias(antialiasDecoration); | 695 context->setShouldAntialias(antialiasDecoration); |
| 696 // Fall through | 696 // Fall through |
| 697 default: | 697 default: |
| 698 context->drawLineForText(start, width, isPrinting); | 698 context->drawLineForText(start, width, isPrinting); |
| 699 | 699 |
| 700 if (decoration.style == TextDecorationStyleDouble) | 700 if (decoration.style() == TextDecorationStyleDouble) |
| 701 context->drawLineForText(start + FloatPoint(0, doubleOffset), width,
isPrinting); | 701 context->drawLineForText(start + FloatPoint(0, doubleOffset), width,
isPrinting); |
| 702 } | 702 } |
| 703 } | 703 } |
| 704 | 704 |
| 705 void InlineTextBoxPainter::paintDecoration(GraphicsContext* context, const Float
Point& boxOrigin, TextDecoration deco) | 705 void InlineTextBoxPainter::paintDecoration(GraphicsContext* context, const Float
Point& boxOrigin, TextDecoration deco) |
| 706 { | 706 { |
| 707 GraphicsContextStateSaver stateSaver(*context); | 707 GraphicsContextStateSaver stateSaver(*context); |
| 708 | 708 |
| 709 if (m_inlineTextBox.truncation() == cFullTruncation) | 709 if (m_inlineTextBox.truncation() == cFullTruncation) |
| 710 return; | 710 return; |
| 711 | 711 |
| 712 FloatPoint localOrigin = boxOrigin; | 712 FloatPoint localOrigin = boxOrigin; |
| 713 | 713 |
| 714 float width = m_inlineTextBox.logicalWidth(); | 714 float width = m_inlineTextBox.logicalWidth(); |
| 715 if (m_inlineTextBox.truncation() != cNoTruncation) { | 715 if (m_inlineTextBox.truncation() != cNoTruncation) { |
| 716 width = m_inlineTextBox.layoutObject().width(m_inlineTextBox.start(), m_
inlineTextBox.truncation(), m_inlineTextBox.textPos(), m_inlineTextBox.isLeftToR
ightDirection() ? LTR : RTL, m_inlineTextBox.isFirstLineStyle()); | 716 width = m_inlineTextBox.layoutObject().width(m_inlineTextBox.start(), m_
inlineTextBox.truncation(), m_inlineTextBox.textPos(), m_inlineTextBox.isLeftToR
ightDirection() ? LTR : RTL, m_inlineTextBox.isFirstLineStyle()); |
| 717 if (!m_inlineTextBox.isLeftToRightDirection()) | 717 if (!m_inlineTextBox.isLeftToRightDirection()) |
| 718 localOrigin.move(m_inlineTextBox.logicalWidth() - width, 0); | 718 localOrigin.move(m_inlineTextBox.logicalWidth() - width, 0); |
| 719 } | 719 } |
| 720 | 720 |
| 721 // Get the text decoration colors. | 721 // Get the text decoration colors. |
| 722 LayoutObject::AppliedTextDecoration underline, overline, linethrough; | 722 AppliedTextDecoration underline, overline, linethrough; |
| 723 m_inlineTextBox.layoutObject().getTextDecorations(deco, underline, overline,
linethrough, true); | 723 m_inlineTextBox.layoutObject().getTextDecorations(deco, underline, overline,
linethrough, true); |
| 724 if (m_inlineTextBox.isFirstLineStyle()) | 724 if (m_inlineTextBox.isFirstLineStyle()) |
| 725 m_inlineTextBox.layoutObject().getTextDecorations(deco, underline, overl
ine, linethrough, true, true); | 725 m_inlineTextBox.layoutObject().getTextDecorations(deco, underline, overl
ine, linethrough, true, true); |
| 726 | 726 |
| 727 // Use a special function for underlines to get the positioning exactly righ
t. | 727 // Use a special function for underlines to get the positioning exactly righ
t. |
| 728 bool isPrinting = m_inlineTextBox.layoutObject().document().printing(); | 728 bool isPrinting = m_inlineTextBox.layoutObject().document().printing(); |
| 729 | 729 |
| 730 const LayoutStyle& styleToUse = m_inlineTextBox.layoutObject().styleRef(m_in
lineTextBox.isFirstLineStyle()); | 730 const LayoutStyle& styleToUse = m_inlineTextBox.layoutObject().styleRef(m_in
lineTextBox.isFirstLineStyle()); |
| 731 int baseline = styleToUse.fontMetrics().ascent(); | 731 int baseline = styleToUse.fontMetrics().ascent(); |
| 732 | 732 |
| 733 // Set the thick of the line to be 10% (or something else ?)of the computed
font size and not less than 1px. | 733 // Set the thick of the line to be 10% (or something else ?)of the computed
font size and not less than 1px. |
| 734 // Using computedFontSize should take care of zoom as well. | 734 // Using computedFontSize should take care of zoom as well. |
| 735 | 735 |
| 736 // Update Underline thickness, in case we have Faulty Font Metrics calculati
ng underline thickness by old method. | 736 // Update Underline thickness, in case we have Faulty Font Metrics calculati
ng underline thickness by old method. |
| 737 float textDecorationThickness = styleToUse.fontMetrics().underlineThickness(
); | 737 float textDecorationThickness = styleToUse.fontMetrics().underlineThickness(
); |
| 738 int fontHeightInt = (int)(styleToUse.fontMetrics().floatHeight() + 0.5); | 738 int fontHeightInt = (int)(styleToUse.fontMetrics().floatHeight() + 0.5); |
| 739 if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHei
ghtInt >> 1))) | 739 if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHei
ghtInt >> 1))) |
| 740 textDecorationThickness = std::max(1.f, styleToUse.computedFontSize() /
10.f); | 740 textDecorationThickness = std::max(1.f, styleToUse.computedFontSize() /
10.f); |
| 741 | 741 |
| 742 context->setStrokeThickness(textDecorationThickness); | 742 context->setStrokeThickness(textDecorationThickness); |
| 743 | 743 |
| 744 bool antialiasDecoration = shouldSetDecorationAntialias(overline.style, unde
rline.style, linethrough.style) | 744 bool antialiasDecoration = shouldSetDecorationAntialias(overline.style(), un
derline.style(), linethrough.style()) |
| 745 && BoxPainter::shouldAntialiasLines(context); | 745 && BoxPainter::shouldAntialiasLines(context); |
| 746 | 746 |
| 747 // Offset between lines - always non-zero, so lines never cross each other. | 747 // Offset between lines - always non-zero, so lines never cross each other. |
| 748 float doubleOffset = textDecorationThickness + 1.f; | 748 float doubleOffset = textDecorationThickness + 1.f; |
| 749 | 749 |
| 750 if (deco & TextDecorationUnderline) { | 750 if (deco & TextDecorationUnderline) { |
| 751 const int underlineOffset = computeUnderlineOffset(styleToUse.textUnderl
inePosition(), styleToUse.fontMetrics(), &m_inlineTextBox, textDecorationThickne
ss); | 751 const int underlineOffset = computeUnderlineOffset(styleToUse.textUnderl
inePosition(), styleToUse.fontMetrics(), &m_inlineTextBox, textDecorationThickne
ss); |
| 752 paintAppliedDecoration(context, localOrigin + FloatPoint(0, underlineOff
set), width, doubleOffset, 1, underline, textDecorationThickness, antialiasDecor
ation, isPrinting); | 752 paintAppliedDecoration(context, localOrigin + FloatPoint(0, underlineOff
set), width, doubleOffset, 1, underline, textDecorationThickness, antialiasDecor
ation, isPrinting); |
| 753 } | 753 } |
| 754 if (deco & TextDecorationOverline) { | 754 if (deco & TextDecorationOverline) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 LayoutTheme::theme().platformActiveTextSearchHighlightColor() : | 815 LayoutTheme::theme().platformActiveTextSearchHighlightColor() : |
| 816 LayoutTheme::theme().platformInactiveTextSearchHighlightColor(); | 816 LayoutTheme::theme().platformInactiveTextSearchHighlightColor(); |
| 817 GraphicsContextStateSaver stateSaver(*pt); | 817 GraphicsContextStateSaver stateSaver(*pt); |
| 818 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_inlineTextBo
x.logicalWidth(), selHeight)); | 818 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_inlineTextBo
x.logicalWidth(), selHeight)); |
| 819 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.
y() - deltaY), selHeight, color, sPos, ePos); | 819 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.
y() - deltaY), selHeight, color, sPos, ePos); |
| 820 } | 820 } |
| 821 } | 821 } |
| 822 | 822 |
| 823 | 823 |
| 824 } // namespace blink | 824 } // namespace blink |
| OLD | NEW |