OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * (C) 2000 Dirk Mueller (mueller@kde.org) |
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 | 768 |
769 Color c = renderer().selectionBackgroundColor(); | 769 Color c = renderer().selectionBackgroundColor(); |
770 if (!c.alpha()) | 770 if (!c.alpha()) |
771 return; | 771 return; |
772 | 772 |
773 // If the text color ends up being the same as the selection background, inv
ert the selection | 773 // If the text color ends up being the same as the selection background, inv
ert the selection |
774 // background. | 774 // background. |
775 if (textColor == c) | 775 if (textColor == c) |
776 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); | 776 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); |
777 | 777 |
778 GraphicsContextStateSaver stateSaver(*context); | |
779 updateGraphicsContext(context, c, c, 0); // Don't draw text at all! | |
780 | 778 |
781 // If the text is truncated, let the thing being painted in the truncation | 779 // If the text is truncated, let the thing being painted in the truncation |
782 // draw its own highlight. | 780 // draw its own highlight. |
783 int length = m_truncation != cNoTruncation ? m_truncation : m_len; | 781 int length = m_truncation != cNoTruncation ? m_truncation : m_len; |
784 StringView string = renderer().text().createView(); | 782 StringView string = renderer().text().createView(); |
785 | 783 |
786 if (string.length() != static_cast<unsigned>(length) || m_start) | 784 if (string.length() != static_cast<unsigned>(length) || m_start) |
787 string.narrow(m_start, length); | 785 string.narrow(m_start, length); |
788 | 786 |
789 StringBuilder charactersWithHyphen; | 787 StringBuilder charactersWithHyphen; |
790 bool respectHyphen = ePos == length && hasHyphen(); | 788 bool respectHyphen = ePos == length && hasHyphen(); |
791 TextRun textRun = constructTextRun(style, font, string, renderer().textLengt
h() - m_start, respectHyphen ? &charactersWithHyphen : 0); | 789 TextRun textRun = constructTextRun(style, font, string, renderer().textLengt
h() - m_start, respectHyphen ? &charactersWithHyphen : 0); |
792 if (respectHyphen) | 790 if (respectHyphen) |
793 ePos = textRun.length(); | 791 ePos = textRun.length(); |
794 | 792 |
795 LayoutUnit selectionBottom = root().selectionBottom(); | 793 LayoutUnit selectionBottom = root().selectionBottom(); |
796 LayoutUnit selectionTop = root().selectionTopAdjustedForPrecedingBlock(); | 794 LayoutUnit selectionTop = root().selectionTopAdjustedForPrecedingBlock(); |
797 | 795 |
798 int deltaY = roundToInt(renderer().style()->isFlippedLinesWritingMode() ? se
lectionBottom - logicalBottom() : logicalTop() - selectionTop); | 796 int deltaY = roundToInt(renderer().style()->isFlippedLinesWritingMode() ? se
lectionBottom - logicalBottom() : logicalTop() - selectionTop); |
799 int selHeight = std::max(0, roundToInt(selectionBottom - selectionTop)); | 797 int selHeight = std::max(0, roundToInt(selectionBottom - selectionTop)); |
800 | 798 |
801 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); | 799 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); |
802 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight)); | 800 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight)); |
| 801 |
| 802 GraphicsContextStateSaver stateSaver(*context); |
803 context->clip(clipRect); | 803 context->clip(clipRect); |
804 | |
805 context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, sPos
, ePos); | 804 context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, sPos
, ePos); |
806 } | 805 } |
807 | 806 |
808 unsigned InlineTextBox::underlinePaintStart(const CompositionUnderline& underlin
e) | 807 unsigned InlineTextBox::underlinePaintStart(const CompositionUnderline& underlin
e) |
809 { | 808 { |
810 return std::max(static_cast<unsigned>(m_start), underline.startOffset); | 809 return std::max(static_cast<unsigned>(m_start), underline.startOffset); |
811 } | 810 } |
812 | 811 |
813 unsigned InlineTextBox::underlinePaintEnd(const CompositionUnderline& underline) | 812 unsigned InlineTextBox::underlinePaintEnd(const CompositionUnderline& underline) |
814 { | 813 { |
815 unsigned paintEnd = std::min(end() + 1, underline.endOffset); // end() point
s at the last char, not past it. | 814 unsigned paintEnd = std::min(end() + 1, underline.endOffset); // end() point
s at the last char, not past it. |
816 if (m_truncation != cNoTruncation) | 815 if (m_truncation != cNoTruncation) |
817 paintEnd = std::min(paintEnd, static_cast<unsigned>(m_start + m_truncati
on)); | 816 paintEnd = std::min(paintEnd, static_cast<unsigned>(m_start + m_truncati
on)); |
818 return paintEnd; | 817 return paintEnd; |
819 } | 818 } |
820 | 819 |
821 void InlineTextBox::paintSingleCompositionBackgroundRun(GraphicsContext* context
, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, Color backg
roundColor, int startPos, int endPos) | 820 void InlineTextBox::paintSingleCompositionBackgroundRun(GraphicsContext* context
, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, Color backg
roundColor, int startPos, int endPos) |
822 { | 821 { |
823 int sPos = std::max(startPos - m_start, 0); | 822 int sPos = std::max(startPos - m_start, 0); |
824 int ePos = std::min(endPos - m_start, static_cast<int>(m_len)); | 823 int ePos = std::min(endPos - m_start, static_cast<int>(m_len)); |
825 if (sPos >= ePos) | 824 if (sPos >= ePos) |
826 return; | 825 return; |
827 | 826 |
828 GraphicsContextStateSaver stateSaver(*context); | |
829 | |
830 updateGraphicsContext(context, backgroundColor, backgroundColor, 0); // Don'
t draw text at all! | |
831 | |
832 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott
om() - logicalBottom() : logicalTop() - selectionTop(); | 827 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott
om() - logicalBottom() : logicalTop() - selectionTop(); |
833 int selHeight = selectionHeight(); | 828 int selHeight = selectionHeight(); |
834 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); | 829 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); |
835 context->drawHighlightForText(font, constructTextRun(style, font), localOrig
in, selHeight, backgroundColor, sPos, ePos); | 830 context->drawHighlightForText(font, constructTextRun(style, font), localOrig
in, selHeight, backgroundColor, sPos, ePos); |
836 } | 831 } |
837 | 832 |
838 static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorati
onStyle) | 833 static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorati
onStyle) |
839 { | 834 { |
840 StrokeStyle strokeStyle = SolidStroke; | 835 StrokeStyle strokeStyle = SolidStroke; |
841 switch (decorationStyle) { | 836 switch (decorationStyle) { |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoin
t(x(), selectionTop()), selHeight, sPos, ePos)); | 1233 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoin
t(x(), selectionTop()), selHeight, sPos, ePos)); |
1239 markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).enclosing
BoundingBox(); | 1234 markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).enclosing
BoundingBox(); |
1240 toRenderedDocumentMarker(marker)->setRenderedRect(markerRect); | 1235 toRenderedDocumentMarker(marker)->setRenderedRect(markerRect); |
1241 | 1236 |
1242 // Optionally highlight the text | 1237 // Optionally highlight the text |
1243 if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) { | 1238 if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) { |
1244 Color color = marker->activeMatch() ? | 1239 Color color = marker->activeMatch() ? |
1245 RenderTheme::theme().platformActiveTextSearchHighlightColor() : | 1240 RenderTheme::theme().platformActiveTextSearchHighlightColor() : |
1246 RenderTheme::theme().platformInactiveTextSearchHighlightColor(); | 1241 RenderTheme::theme().platformInactiveTextSearchHighlightColor(); |
1247 GraphicsContextStateSaver stateSaver(*pt); | 1242 GraphicsContextStateSaver stateSaver(*pt); |
1248 updateGraphicsContext(pt, color, color, 0); // Don't draw text at all! | |
1249 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_logicalWidth
, selHeight)); | 1243 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_logicalWidth
, selHeight)); |
1250 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.
y() - deltaY), selHeight, color, sPos, ePos); | 1244 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.
y() - deltaY), selHeight, color, sPos, ePos); |
1251 } | 1245 } |
1252 } | 1246 } |
1253 | 1247 |
1254 void InlineTextBox::paintCompositionBackgrounds(GraphicsContext* pt, const Float
Point& boxOrigin, RenderStyle* style, const Font& font, bool useCustomUnderlines
) | 1248 void InlineTextBox::paintCompositionBackgrounds(GraphicsContext* pt, const Float
Point& boxOrigin, RenderStyle* style, const Font& font, bool useCustomUnderlines
) |
1255 { | 1249 { |
1256 if (useCustomUnderlines) { | 1250 if (useCustomUnderlines) { |
1257 // Paint custom background highlights for compositions. | 1251 // Paint custom background highlights for compositions. |
1258 const Vector<CompositionUnderline>& underlines = renderer().frame()->inp
utMethodController().customCompositionUnderlines(); | 1252 const Vector<CompositionUnderline>& underlines = renderer().frame()->inp
utMethodController().customCompositionUnderlines(); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); | 1520 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); |
1527 const int rendererCharacterOffset = 24; | 1521 const int rendererCharacterOffset = 24; |
1528 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) | 1522 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) |
1529 fputc(' ', stderr); | 1523 fputc(' ', stderr); |
1530 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d
ata()); | 1524 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d
ata()); |
1531 } | 1525 } |
1532 | 1526 |
1533 #endif | 1527 #endif |
1534 | 1528 |
1535 } // namespace blink | 1529 } // namespace blink |
OLD | NEW |