Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: Source/core/rendering/InlineTextBox.cpp

Issue 313233002: Adding backgroundColor to WebCompositionUnderline and using it for InlineTextBox drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Cleanup; renaming CompositionUnderlineVisitor to ...Iterator. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 * 20 *
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24 #include "core/rendering/InlineTextBox.h" 24 #include "core/rendering/InlineTextBox.h"
25 25
26 #include "core/dom/Document.h" 26 #include "core/dom/Document.h"
27 #include "core/dom/DocumentMarkerController.h" 27 #include "core/dom/DocumentMarkerController.h"
28 #include "core/dom/RenderedDocumentMarker.h" 28 #include "core/dom/RenderedDocumentMarker.h"
29 #include "core/dom/Text.h" 29 #include "core/dom/Text.h"
30 #include "core/editing/CompositionUnderline.h"
31 #include "core/editing/CompositionUnderlineIterator.h"
30 #include "core/editing/Editor.h" 32 #include "core/editing/Editor.h"
31 #include "core/editing/InputMethodController.h" 33 #include "core/editing/InputMethodController.h"
32 #include "core/frame/LocalFrame.h" 34 #include "core/frame/LocalFrame.h"
33 #include "core/page/Page.h" 35 #include "core/page/Page.h"
34 #include "core/frame/Settings.h" 36 #include "core/frame/Settings.h"
35 #include "core/rendering/AbstractInlineTextBox.h" 37 #include "core/rendering/AbstractInlineTextBox.h"
36 #include "core/rendering/EllipsisBox.h" 38 #include "core/rendering/EllipsisBox.h"
37 #include "core/rendering/HitTestResult.h" 39 #include "core/rendering/HitTestResult.h"
38 #include "core/rendering/PaintInfo.h" 40 #include "core/rendering/PaintInfo.h"
39 #include "core/rendering/RenderBR.h" 41 #include "core/rendering/RenderBR.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } else 188 } else
187 ellipsis->setSelectionState(RenderObject::SelectionNone); 189 ellipsis->setSelectionState(RenderObject::SelectionNone);
188 } 190 }
189 191
190 return state; 192 return state;
191 } 193 }
192 194
193 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos) 195 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos)
194 { 196 {
195 int sPos = max(startPos - m_start, 0); 197 int sPos = max(startPos - m_start, 0);
196 int ePos = min(endPos - m_start, (int)m_len); 198 int ePos = min(endPos - m_start, static_cast<int>(m_len));
197 199
198 if (sPos > ePos) 200 if (sPos > ePos)
199 return LayoutRect(); 201 return LayoutRect();
200 202
201 FontCachePurgePreventer fontCachePurgePreventer; 203 FontCachePurgePreventer fontCachePurgePreventer;
202 204
203 LayoutUnit selTop = selectionTop(); 205 LayoutUnit selTop = selectionTop();
204 LayoutUnit selHeight = selectionHeight(); 206 LayoutUnit selHeight = selectionHeight();
205 RenderStyle* styleToUse = textRenderer().style(isFirstLineStyle()); 207 RenderStyle* styleToUse = textRenderer().style(isFirstLineStyle());
206 const Font& font = styleToUse->font(); 208 const Font& font = styleToUse->font();
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 625
624 // Set our font. 626 // Set our font.
625 const Font& font = styleToUse->font(); 627 const Font& font = styleToUse->font();
626 628
627 FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontM etrics().ascent()); 629 FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontM etrics().ascent());
628 630
629 if (combinedText) 631 if (combinedText)
630 combinedText->adjustTextOrigin(textOrigin, boxRect); 632 combinedText->adjustTextOrigin(textOrigin, boxRect);
631 633
632 // 1. Paint backgrounds behind text if needed. Examples of such backgrounds include selection 634 // 1. Paint backgrounds behind text if needed. Examples of such backgrounds include selection
633 // and composition underlines. 635 // and composition highlights.
634 if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseT extClip && !isPrinting) { 636 if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseT extClip && !isPrinting) {
637 if (containsComposition) {
638 if (useCustomUnderlines) {
639 // Paint custom background highlights for compositions.
640 const Vector<CompositionUnderline>& underlines = renderer().fram e()->inputMethodController().customCompositionUnderlines();
641 CompositionUnderlineIterator it(underlines, start(), end());
642 const CompositionUnderline* underline;
643 while (it.next(&underline)) {
644 if (underline->backgroundColor != Color::transparent) {
645 unsigned paintStart = getUnderlinePaintStart(*underline) ;
646 unsigned paintEnd = getUnderlinePaintEnd(*underline);
647 paintCompositionBackground(context, boxOrigin, styleToUs e, font, underline->backgroundColor, paintStart, paintEnd);
648 }
649 }
635 650
636 if (containsComposition && !useCustomUnderlines) { 651 } else {
637 paintCompositionBackground(context, boxOrigin, styleToUse, font, 652 paintCompositionBackground(context, boxOrigin, styleToUse, font, RenderTheme::theme().platformDefaultCompositionBackgroundColor(),
638 renderer().frame()->inputMethodController().compositionStart(), 653 renderer().frame()->inputMethodController().compositionStart (),
639 renderer().frame()->inputMethodController().compositionEnd()); 654 renderer().frame()->inputMethodController().compositionEnd() );
655 }
640 } 656 }
641 657
642 paintDocumentMarkers(context, boxOrigin, styleToUse, font, true); 658 paintDocumentMarkers(context, boxOrigin, styleToUse, font, true);
643 659
644 if (haveSelection && !useCustomUnderlines) 660 if (haveSelection && !useCustomUnderlines)
645 paintSelection(context, boxOrigin, styleToUse, font, selectionFillCo lor); 661 paintSelection(context, boxOrigin, styleToUse, font, selectionFillCo lor);
646 } 662 }
647 663
648 // 2. Now paint the foreground, including text and decorations like underlin e/overline (in quirks mode only). 664 // 2. Now paint the foreground, including text and decorations like underlin e/overline (in quirks mode only).
649 int length = m_len; 665 int length = m_len;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 if (combinedText) 771 if (combinedText)
756 context->concatCTM(rotation(boxRect, Clockwise)); 772 context->concatCTM(rotation(boxRect, Clockwise));
757 paintDecoration(context, boxOrigin, textDecorations, textShadow); 773 paintDecoration(context, boxOrigin, textDecorations, textShadow);
758 if (combinedText) 774 if (combinedText)
759 context->concatCTM(rotation(boxRect, Counterclockwise)); 775 context->concatCTM(rotation(boxRect, Counterclockwise));
760 } 776 }
761 777
762 if (paintInfo.phase == PaintPhaseForeground) { 778 if (paintInfo.phase == PaintPhaseForeground) {
763 paintDocumentMarkers(context, boxOrigin, styleToUse, font, false); 779 paintDocumentMarkers(context, boxOrigin, styleToUse, font, false);
764 780
781 // Paint custom underlines for compositions.
765 if (useCustomUnderlines) { 782 if (useCustomUnderlines) {
766 const Vector<CompositionUnderline>& underlines = renderer().frame()- >inputMethodController().customCompositionUnderlines(); 783 const Vector<CompositionUnderline>& underlines = renderer().frame()- >inputMethodController().customCompositionUnderlines();
767 size_t numUnderlines = underlines.size(); 784 CompositionUnderlineIterator it(underlines, start(), end());
768 785 const CompositionUnderline* underline;
769 for (size_t index = 0; index < numUnderlines; ++index) { 786 while (it.next(&underline)) {
770 const CompositionUnderline& underline = underlines[index]; 787 paintCompositionUnderline(context, boxOrigin, *underline);
771
772 if (underline.endOffset <= start())
773 // underline is completely before this run. This might be a n underline that sits
774 // before the first run we draw, or underlines that were wit hin runs we skipped
775 // due to truncation.
776 continue;
777
778 if (underline.startOffset <= end()) {
779 // underline intersects this run. Paint it.
780 paintCompositionUnderline(context, boxOrigin, underline);
781 if (underline.endOffset > end() + 1)
782 // underline also runs into the next run. Bail now, no m ore marker advancement.
783 break;
784 } else
785 // underline is completely after this run, bail. A later ru n will paint it.
786 break;
787 } 788 }
788 } 789 }
789 } 790 }
790 791
791 if (shouldRotate) 792 if (shouldRotate)
792 context->concatCTM(rotation(boxRect, Counterclockwise)); 793 context->concatCTM(rotation(boxRect, Counterclockwise));
793 } 794 }
794 795
795 void InlineTextBox::selectionStartEnd(int& sPos, int& ePos) 796 void InlineTextBox::selectionStartEnd(int& sPos, int& ePos)
796 { 797 {
797 int startPos, endPos; 798 int startPos, endPos;
798 if (renderer().selectionState() == RenderObject::SelectionInside) { 799 if (renderer().selectionState() == RenderObject::SelectionInside) {
799 startPos = 0; 800 startPos = 0;
800 endPos = textRenderer().textLength(); 801 endPos = textRenderer().textLength();
801 } else { 802 } else {
802 textRenderer().selectionStartEnd(startPos, endPos); 803 textRenderer().selectionStartEnd(startPos, endPos);
803 if (renderer().selectionState() == RenderObject::SelectionStart) 804 if (renderer().selectionState() == RenderObject::SelectionStart)
804 endPos = textRenderer().textLength(); 805 endPos = textRenderer().textLength();
805 else if (renderer().selectionState() == RenderObject::SelectionEnd) 806 else if (renderer().selectionState() == RenderObject::SelectionEnd)
806 startPos = 0; 807 startPos = 0;
807 } 808 }
808 809
809 sPos = max(startPos - m_start, 0); 810 sPos = max(startPos - m_start, 0);
810 ePos = min(endPos - m_start, (int)m_len); 811 ePos = min(endPos - m_start, static_cast<int>(m_len));
811 } 812 }
812 813
813 void alignSelectionRectToDevicePixels(FloatRect& rect) 814 void alignSelectionRectToDevicePixels(FloatRect& rect)
814 { 815 {
815 float maxX = floorf(rect.maxX()); 816 float maxX = floorf(rect.maxX());
816 rect.setX(floorf(rect.x())); 817 rect.setX(floorf(rect.x()));
817 rect.setWidth(roundf(maxX - rect.x())); 818 rect.setWidth(roundf(maxX - rect.x()));
818 } 819 }
819 820
820 void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& b oxOrigin, RenderStyle* style, const Font& font, Color textColor) 821 void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& b oxOrigin, RenderStyle* style, const Font& font, Color textColor)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 863
863 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); 864 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
864 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight)); 865 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight));
865 alignSelectionRectToDevicePixels(clipRect); 866 alignSelectionRectToDevicePixels(clipRect);
866 867
867 context->clip(clipRect); 868 context->clip(clipRect);
868 869
869 context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, sPos , ePos); 870 context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, sPos , ePos);
870 } 871 }
871 872
872 void InlineTextBox::paintCompositionBackground(GraphicsContext* context, const F loatPoint& boxOrigin, RenderStyle* style, const Font& font, int startPos, int en dPos) 873 unsigned InlineTextBox::getUnderlinePaintStart(const CompositionUnderline& under line)
873 { 874 {
874 int offset = m_start; 875 return max(static_cast<unsigned>(m_start), underline.startOffset);
875 int sPos = max(startPos - offset, 0); 876 }
876 int ePos = min(endPos - offset, (int)m_len);
877 877
878 unsigned InlineTextBox::getUnderlinePaintEnd(const CompositionUnderline& underli ne)
879 {
880 unsigned paintEnd = min(end() + 1, underline.endOffset); // end() points at the last char, not past it.
881 if (m_truncation != cNoTruncation)
882 paintEnd = min(paintEnd, static_cast<unsigned>(m_start + m_truncation));
883 return paintEnd;
884 }
885
886 void InlineTextBox::paintCompositionBackground(GraphicsContext* context, const F loatPoint& boxOrigin, RenderStyle* style, const Font& font, Color backgroundColo r, int startPos, int endPos)
887 {
888 int sPos = max(startPos - m_start, 0);
889 int ePos = min(endPos - m_start, static_cast<int>(m_len));
878 if (sPos >= ePos) 890 if (sPos >= ePos)
879 return; 891 return;
880 892
881 GraphicsContextStateSaver stateSaver(*context); 893 GraphicsContextStateSaver stateSaver(*context);
882 894
883 Color c = Color(225, 221, 85); 895 updateGraphicsContext(context, backgroundColor, backgroundColor, 0); // Don' t draw text at all!
884
885 updateGraphicsContext(context, c, c, 0); // Don't draw text at all!
886 896
887 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop(); 897 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop();
888 int selHeight = selectionHeight(); 898 int selHeight = selectionHeight();
889 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); 899 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
890 context->drawHighlightForText(font, constructTextRun(style, font), localOrig in, selHeight, c, sPos, ePos); 900 context->drawHighlightForText(font, constructTextRun(style, font), localOrig in, selHeight, backgroundColor, sPos, ePos);
891 } 901 }
892 902
893 static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorati onStyle) 903 static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorati onStyle)
894 { 904 {
895 StrokeStyle strokeStyle = SolidStroke; 905 StrokeStyle strokeStyle = SolidStroke;
896 switch (decorationStyle) { 906 switch (decorationStyle) {
897 case TextDecorationStyleSolid: 907 case TextDecorationStyleSolid:
898 strokeStyle = SolidStroke; 908 strokeStyle = SolidStroke;
899 break; 909 break;
900 case TextDecorationStyleDouble: 910 case TextDecorationStyleDouble:
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 1142
1133 RenderStyle* styleToUse = renderer().style(isFirstLineStyle()); 1143 RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
1134 int baseline = styleToUse->fontMetrics().ascent(); 1144 int baseline = styleToUse->fontMetrics().ascent();
1135 1145
1136 size_t shadowCount = shadowList ? shadowList->shadows().size() : 0; 1146 size_t shadowCount = shadowList ? shadowList->shadows().size() : 0;
1137 // Set the thick of the line to be 10% (or something else ?)of the computed font size and not less than 1px. 1147 // Set the thick of the line to be 10% (or something else ?)of the computed font size and not less than 1px.
1138 // Using computedFontSize should take care of zoom as well. 1148 // Using computedFontSize should take care of zoom as well.
1139 1149
1140 // Update Underline thickness, in case we have Faulty Font Metrics calculati ng underline thickness by old method. 1150 // Update Underline thickness, in case we have Faulty Font Metrics calculati ng underline thickness by old method.
1141 float textDecorationThickness = styleToUse->fontMetrics().underlineThickness (); 1151 float textDecorationThickness = styleToUse->fontMetrics().underlineThickness ();
1142 int fontHeightInt = (int)(styleToUse->fontMetrics().floatHeight() + 0.5); 1152 int fontHeightInt = static_cast<int>(styleToUse->fontMetrics().floatHeight() + 0.5);
1143 if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHei ghtInt >> 1))) 1153 if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHei ghtInt >> 1)))
1144 textDecorationThickness = std::max(1.f, styleToUse->computedFontSize() / 10.f); 1154 textDecorationThickness = std::max(1.f, styleToUse->computedFontSize() / 10.f);
1145 1155
1146 context->setStrokeThickness(textDecorationThickness); 1156 context->setStrokeThickness(textDecorationThickness);
1147 1157
1148 bool antialiasDecoration = shouldSetDecorationAntialias(overline.style, unde rline.style, linethrough.style) 1158 bool antialiasDecoration = shouldSetDecorationAntialias(overline.style, unde rline.style, linethrough.style)
1149 && RenderBoxModelObject::shouldAntialiasLines(context); 1159 && RenderBoxModelObject::shouldAntialiasLines(context);
1150 1160
1151 float extraOffset = 0; 1161 float extraOffset = 0;
1152 if (!linesAreOpaque && shadowCount > 1) { 1162 if (!linesAreOpaque && shadowCount > 1) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 return; 1227 return;
1218 1228
1219 if (m_truncation == cFullTruncation) 1229 if (m_truncation == cFullTruncation)
1220 return; 1230 return;
1221 1231
1222 float start = 0; // start of line to draw, relative to tx 1232 float start = 0; // start of line to draw, relative to tx
1223 float width = m_logicalWidth; // how much line to draw 1233 float width = m_logicalWidth; // how much line to draw
1224 1234
1225 // Determine whether we need to measure text 1235 // Determine whether we need to measure text
1226 bool markerSpansWholeBox = true; 1236 bool markerSpansWholeBox = true;
1227 if (m_start <= (int)marker->startOffset()) 1237 if (m_start <= static_cast<int>(marker->startOffset()))
1228 markerSpansWholeBox = false; 1238 markerSpansWholeBox = false;
1229 if ((end() + 1) != marker->endOffset()) // end points at the last char, not past it 1239 if ((end() + 1) != marker->endOffset()) // end points at the last char, not past it
1230 markerSpansWholeBox = false; 1240 markerSpansWholeBox = false;
1231 if (m_truncation != cNoTruncation) 1241 if (m_truncation != cNoTruncation)
1232 markerSpansWholeBox = false; 1242 markerSpansWholeBox = false;
1233 1243
1234 if (!markerSpansWholeBox || grammar) { 1244 if (!markerSpansWholeBox || grammar) {
1235 int startPosition = max<int>(marker->startOffset() - m_start, 0); 1245 int startPosition = max<int>(marker->startOffset() - m_start, 0);
1236 int endPosition = min<int>(marker->endOffset() - m_start, m_len); 1246 int endPosition = min<int>(marker->endOffset() - m_start, m_len);
1237 1247
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 pt->drawLineForDocumentMarker(FloatPoint(boxOrigin.x() + start, boxOrigin.y( ) + underlineOffset), width, lineStyleForMarkerType(marker->type())); 1288 pt->drawLineForDocumentMarker(FloatPoint(boxOrigin.x() + start, boxOrigin.y( ) + underlineOffset), width, lineStyleForMarkerType(marker->type()));
1279 } 1289 }
1280 1290
1281 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPoint& boxOrigin, DocumentMarker* marker, RenderStyle* style, const Font& font) 1291 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPoint& boxOrigin, DocumentMarker* marker, RenderStyle* style, const Font& font)
1282 { 1292 {
1283 // Use same y positioning and height as for selection, so that when the sele ction and this highlight are on 1293 // Use same y positioning and height as for selection, so that when the sele ction and this highlight are on
1284 // the same word there are no pieces sticking out. 1294 // the same word there are no pieces sticking out.
1285 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop(); 1295 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop();
1286 int selHeight = selectionHeight(); 1296 int selHeight = selectionHeight();
1287 1297
1288 int sPos = max(marker->startOffset() - m_start, (unsigned)0); 1298 int sPos = max(marker->startOffset() - m_start, 0U);
1289 int ePos = min(marker->endOffset() - m_start, (unsigned)m_len); 1299 int ePos = min(marker->endOffset() - m_start, static_cast<unsigned>(m_len));
1290 TextRun run = constructTextRun(style, font); 1300 TextRun run = constructTextRun(style, font);
1291 1301
1292 // Always compute and store the rect associated with this marker. The comput ed rect is in absolute coordinates. 1302 // Always compute and store the rect associated with this marker. The comput ed rect is in absolute coordinates.
1293 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoin t(x(), selectionTop()), selHeight, sPos, ePos)); 1303 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoin t(x(), selectionTop()), selHeight, sPos, ePos));
1294 markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).enclosing BoundingBox(); 1304 markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).enclosing BoundingBox();
1295 toRenderedDocumentMarker(marker)->setRenderedRect(markerRect); 1305 toRenderedDocumentMarker(marker)->setRenderedRect(markerRect);
1296 1306
1297 // Optionally highlight the text 1307 // Optionally highlight the text
1298 if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) { 1308 if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) {
1299 Color color = marker->activeMatch() ? 1309 Color color = marker->activeMatch() ?
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 } 1369 }
1360 1370
1361 } 1371 }
1362 } 1372 }
1363 1373
1364 void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, const FloatP oint& boxOrigin, const CompositionUnderline& underline) 1374 void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, const FloatP oint& boxOrigin, const CompositionUnderline& underline)
1365 { 1375 {
1366 if (m_truncation == cFullTruncation) 1376 if (m_truncation == cFullTruncation)
1367 return; 1377 return;
1368 1378
1369 float start = 0; // start of line to draw, relative to tx 1379 unsigned paintStart = getUnderlinePaintStart(underline);
1370 float width = m_logicalWidth; // how much line to draw 1380 unsigned paintEnd = getUnderlinePaintEnd(underline);
1371 bool useWholeWidth = true; 1381
1372 unsigned paintStart = m_start; 1382 // start of line to draw, relative to tx
1373 unsigned paintEnd = end() + 1; // end points at the last char, not past it 1383 float start = paintStart == static_cast<unsigned>(m_start) ? 0 :
1374 if (paintStart <= underline.startOffset) { 1384 toRenderText(renderer()).width(m_start, paintStart - m_start, textPos(), isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle());
1375 paintStart = underline.startOffset; 1385 // how much line to draw
1376 useWholeWidth = false; 1386 float width = (paintStart == static_cast<unsigned>(m_start) && paintEnd == s tatic_cast<unsigned>(end()) + 1) ? m_logicalWidth :
1377 start = toRenderText(renderer()).width(m_start, paintStart - m_start, te xtPos(), isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle()); 1387 toRenderText(renderer()).width(paintStart, paintEnd - paintStart, textPo s() + start, isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle());
1378 }
1379 if (paintEnd != underline.endOffset) { // end points at the last char, not past it
1380 paintEnd = min(paintEnd, (unsigned)underline.endOffset);
1381 useWholeWidth = false;
1382 }
1383 if (m_truncation != cNoTruncation) {
1384 paintEnd = min(paintEnd, (unsigned)m_start + m_truncation);
1385 useWholeWidth = false;
1386 }
1387 if (!useWholeWidth) {
1388 width = toRenderText(renderer()).width(paintStart, paintEnd - paintStart , textPos() + start, isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle());
1389 }
1390 1388
1391 // Thick marked text underlines are 2px thick as long as there is room for t he 2px line under the baseline. 1389 // Thick marked text underlines are 2px thick as long as there is room for t he 2px line under the baseline.
1392 // All other marked text underlines are 1px thick. 1390 // All other marked text underlines are 1px thick.
1393 // If there's not enough space the underline will touch or overlap character s. 1391 // If there's not enough space the underline will touch or overlap character s.
1394 int lineThickness = 1; 1392 int lineThickness = 1;
1395 int baseline = renderer().style(isFirstLineStyle())->fontMetrics().ascent(); 1393 int baseline = renderer().style(isFirstLineStyle())->fontMetrics().ascent();
1396 if (underline.thick && logicalHeight() - baseline >= 2) 1394 if (underline.thick && logicalHeight() - baseline >= 2)
1397 lineThickness = 2; 1395 lineThickness = 2;
1398 1396
1399 // We need to have some space between underlines of subsequent clauses, beca use some input methods do not use different underline styles for those. 1397 // We need to have some space between underlines of subsequent clauses, beca use some input methods do not use different underline styles for those.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); 1572 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj);
1575 const int rendererCharacterOffset = 24; 1573 const int rendererCharacterOffset = 24;
1576 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) 1574 for (; printedCharacters < rendererCharacterOffset; printedCharacters++)
1577 fputc(' ', stderr); 1575 fputc(' ', stderr);
1578 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); 1576 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata());
1579 } 1577 }
1580 1578
1581 #endif 1579 #endif
1582 1580
1583 } // namespace WebCore 1581 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698