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

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

Issue 620243002: Move painting code from InlineTextBox to InlineTextBoxPainter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Final version. Created 6 years, 2 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
« no previous file with comments | « Source/core/rendering/InlineTextBox.h ('k') | Source/core/rendering/svg/SVGInlineTextBox.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 *
(...skipping 15 matching lines...) Expand all
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" 30 #include "core/editing/CompositionUnderline.h"
31 #include "core/editing/CompositionUnderlineRangeFilter.h" 31 #include "core/editing/CompositionUnderlineRangeFilter.h"
32 #include "core/editing/Editor.h" 32 #include "core/editing/Editor.h"
33 #include "core/editing/InputMethodController.h" 33 #include "core/editing/InputMethodController.h"
34 #include "core/frame/LocalFrame.h" 34 #include "core/frame/LocalFrame.h"
35 #include "core/page/Page.h" 35 #include "core/page/Page.h"
36 #include "core/paint/BoxPainter.h" 36 #include "core/paint/InlineTextBoxPainter.h"
37 #include "core/rendering/AbstractInlineTextBox.h" 37 #include "core/rendering/AbstractInlineTextBox.h"
38 #include "core/rendering/EllipsisBox.h" 38 #include "core/rendering/EllipsisBox.h"
39 #include "core/rendering/HitTestResult.h" 39 #include "core/rendering/HitTestResult.h"
40 #include "core/rendering/PaintInfo.h" 40 #include "core/rendering/PaintInfo.h"
41 #include "core/rendering/RenderBR.h" 41 #include "core/rendering/RenderBR.h"
42 #include "core/rendering/RenderBlock.h" 42 #include "core/rendering/RenderBlock.h"
43 #include "core/rendering/RenderCombineText.h" 43 #include "core/rendering/RenderCombineText.h"
44 #include "core/rendering/RenderRubyRun.h" 44 #include "core/rendering/RenderRubyRun.h"
45 #include "core/rendering/RenderRubyText.h" 45 #include "core/rendering/RenderRubyText.h"
46 #include "core/rendering/RenderTheme.h" 46 #include "core/rendering/RenderTheme.h"
(...skipping 17 matching lines...) Expand all
64 unsigned variables[1]; 64 unsigned variables[1];
65 unsigned short variables2[2]; 65 unsigned short variables2[2];
66 void* pointers[2]; 66 void* pointers[2];
67 }; 67 };
68 68
69 COMPILE_ASSERT(sizeof(InlineTextBox) == sizeof(SameSizeAsInlineTextBox), InlineT extBox_should_stay_small); 69 COMPILE_ASSERT(sizeof(InlineTextBox) == sizeof(SameSizeAsInlineTextBox), InlineT extBox_should_stay_small);
70 70
71 typedef WTF::HashMap<const InlineTextBox*, LayoutRect> InlineTextBoxOverflowMap; 71 typedef WTF::HashMap<const InlineTextBox*, LayoutRect> InlineTextBoxOverflowMap;
72 static InlineTextBoxOverflowMap* gTextBoxesWithOverflow; 72 static InlineTextBoxOverflowMap* gTextBoxesWithOverflow;
73 73
74 typedef WTF::HashMap<const InlineTextBox*, TextBlobPtr> InlineTextBoxBlobCacheMa p;
75 static InlineTextBoxBlobCacheMap* gTextBlobCache;
76
77 static const int misspellingLineThickness = 3;
78 74
79 void InlineTextBox::destroy() 75 void InlineTextBox::destroy()
80 { 76 {
81 AbstractInlineTextBox::willDestroy(this); 77 AbstractInlineTextBox::willDestroy(this);
82 78
83 if (!knownToHaveNoOverflow() && gTextBoxesWithOverflow) 79 if (!knownToHaveNoOverflow() && gTextBoxesWithOverflow)
84 gTextBoxesWithOverflow->remove(this); 80 gTextBoxesWithOverflow->remove(this);
85 if (gTextBlobCache) 81 InlineTextBoxPainter::removeFromTextBlobCache(*this);
86 gTextBlobCache->remove(this);
87 InlineBox::destroy(); 82 InlineBox::destroy();
88 } 83 }
89 84
90 void InlineTextBox::markDirty() 85 void InlineTextBox::markDirty()
91 { 86 {
92 // FIXME: Is it actually possible to try and paint a dirty InlineTextBox? 87 // FIXME: Is it actually possible to try and paint a dirty InlineTextBox?
93 if (gTextBlobCache) 88 InlineTextBoxPainter::removeFromTextBlobCache(*this);
94 gTextBlobCache->remove(this);
95 89
96 m_len = 0; 90 m_len = 0;
97 m_start = 0; 91 m_start = 0;
98 InlineBox::markDirty(); 92 InlineBox::markDirty();
99 } 93 }
100 94
101 LayoutRect InlineTextBox::logicalOverflowRect() const 95 LayoutRect InlineTextBox::logicalOverflowRect() const
102 { 96 {
103 if (knownToHaveNoOverflow() || !gTextBoxesWithOverflow) 97 if (knownToHaveNoOverflow() || !gTextBoxesWithOverflow)
104 return enclosingIntRect(logicalFrameRect()); 98 return enclosingIntRect(logicalFrameRect());
(...skipping 21 matching lines...) Expand all
126 { 120 {
127 if (!isText() || !renderer().parent()) 121 if (!isText() || !renderer().parent())
128 return 0; 122 return 0;
129 if (renderer().isBR()) 123 if (renderer().isBR())
130 return toRenderBR(renderer()).lineHeight(isFirstLineStyle()); 124 return toRenderBR(renderer()).lineHeight(isFirstLineStyle());
131 if (parent()->renderer() == renderer().parent()) 125 if (parent()->renderer() == renderer().parent())
132 return parent()->lineHeight(); 126 return parent()->lineHeight();
133 return toRenderBoxModelObject(renderer().parent())->lineHeight(isFirstLineSt yle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine) ; 127 return toRenderBoxModelObject(renderer().parent())->lineHeight(isFirstLineSt yle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine) ;
134 } 128 }
135 129
136 LayoutUnit InlineTextBox::selectionTop()
137 {
138 return root().selectionTop();
139 }
140
141 LayoutUnit InlineTextBox::selectionBottom()
142 {
143 return root().selectionBottom();
144 }
145
146 LayoutUnit InlineTextBox::selectionHeight()
147 {
148 return root().selectionHeight();
149 }
150
151 bool InlineTextBox::isSelected(int startPos, int endPos) const 130 bool InlineTextBox::isSelected(int startPos, int endPos) const
152 { 131 {
153 int sPos = std::max(startPos - m_start, 0); 132 int sPos = std::max(startPos - m_start, 0);
154 // The position after a hard line break is considered to be past its end. 133 // The position after a hard line break is considered to be past its end.
155 // See the corresponding code in InlineTextBox::selectionState. 134 // See the corresponding code in InlineTextBox::selectionState.
156 int ePos = std::min(endPos - m_start, int(m_len) + (isLineBreak() ? 0 : 1)); 135 int ePos = std::min(endPos - m_start, int(m_len) + (isLineBreak() ? 0 : 1));
157 return (sPos < ePos); 136 return (sPos < ePos);
158 } 137 }
159 138
160 RenderObject::SelectionState InlineTextBox::selectionState() const 139 RenderObject::SelectionState InlineTextBox::selectionState() const
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos) 185 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos)
207 { 186 {
208 int sPos = std::max(startPos - m_start, 0); 187 int sPos = std::max(startPos - m_start, 0);
209 int ePos = std::min(endPos - m_start, (int)m_len); 188 int ePos = std::min(endPos - m_start, (int)m_len);
210 189
211 if (sPos > ePos) 190 if (sPos > ePos)
212 return LayoutRect(); 191 return LayoutRect();
213 192
214 FontCachePurgePreventer fontCachePurgePreventer; 193 FontCachePurgePreventer fontCachePurgePreventer;
215 194
216 LayoutUnit selTop = selectionTop(); 195 LayoutUnit selTop = root().selectionTop();
217 LayoutUnit selHeight = selectionHeight(); 196 LayoutUnit selHeight = root().selectionHeight();
218 RenderStyle* styleToUse = renderer().style(isFirstLineStyle()); 197 RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
219 const Font& font = styleToUse->font(); 198 const Font& font = styleToUse->font();
220 199
221 StringBuilder charactersWithHyphen; 200 StringBuilder charactersWithHyphen;
222 bool respectHyphen = ePos == m_len && hasHyphen(); 201 bool respectHyphen = ePos == m_len && hasHyphen();
223 TextRun textRun = constructTextRun(styleToUse, font, respectHyphen ? &charac tersWithHyphen : 0); 202 TextRun textRun = constructTextRun(styleToUse, font, respectHyphen ? &charac tersWithHyphen : 0);
224 203
225 FloatPoint startingPoint = FloatPoint(logicalLeft(), selTop.toFloat()); 204 FloatPoint startingPoint = FloatPoint(logicalLeft(), selTop.toFloat());
226 LayoutRect r; 205 LayoutRect r;
227 if (sPos || ePos != static_cast<int>(m_len)) 206 if (sPos || ePos != static_cast<int>(m_len))
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return true; // Cannot get the ruby text. 350 return true; // Cannot get the ruby text.
372 351
373 RenderRubyText* rubyText = toRenderRubyRun(containingBlock->parent())->rubyT ext(); 352 RenderRubyText* rubyText = toRenderRubyRun(containingBlock->parent())->rubyT ext();
374 353
375 // The emphasis marks over are suppressed only if there is a ruby text box a nd it not empty. 354 // The emphasis marks over are suppressed only if there is a ruby text box a nd it not empty.
376 return !rubyText || !rubyText->firstLineBox(); 355 return !rubyText || !rubyText->firstLineBox();
377 } 356 }
378 357
379 void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit /*lineTop*/, LayoutUnit /*lineBottom*/) 358 void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit /*lineTop*/, LayoutUnit /*lineBottom*/)
380 { 359 {
381 if (isLineBreak() || !paintInfo.shouldPaintWithinRoot(&renderer()) || render er().style()->visibility() != VISIBLE 360 InlineTextBoxPainter(*this).paint(paintInfo, paintOffset);
382 || m_truncation == cFullTruncation || paintInfo.phase == PaintPhaseOutli ne || !m_len)
383 return;
384
385 ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintP haseChildOutlines);
386
387 LayoutRect logicalVisualOverflow = logicalOverflowRect();
388 LayoutUnit logicalStart = logicalVisualOverflow.x() + (isHorizontal() ? pain tOffset.x() : paintOffset.y());
389 LayoutUnit logicalExtent = logicalVisualOverflow.width();
390
391 LayoutUnit paintEnd = isHorizontal() ? paintInfo.rect.maxX() : paintInfo.rec t.maxY();
392 LayoutUnit paintStart = isHorizontal() ? paintInfo.rect.x() : paintInfo.rect .y();
393
394 // When subpixel font scaling is enabled text runs are positioned at
395 // subpixel boundaries on the x-axis and thus there is no reason to
396 // snap the x value. We still round the y-axis to ensure consistent
397 // line heights.
398 LayoutPoint adjustedPaintOffset = RuntimeEnabledFeatures::subpixelFontScalin gEnabled()
399 ? LayoutPoint(paintOffset.x(), paintOffset.y().round())
400 : roundedIntPoint(paintOffset);
401
402 if (logicalStart >= paintEnd || logicalStart + logicalExtent <= paintStart)
403 return;
404
405 bool isPrinting = renderer().document().printing();
406
407 // Determine whether or not we're selected.
408 bool haveSelection = !isPrinting && paintInfo.phase != PaintPhaseTextClip && selectionState() != RenderObject::SelectionNone;
409 if (!haveSelection && paintInfo.phase == PaintPhaseSelection)
410 // When only painting the selection, don't bother to paint if there is n one.
411 return;
412
413 if (m_truncation != cNoTruncation) {
414 if (renderer().containingBlock()->style()->isLeftToRightDirection() != i sLeftToRightDirection()) {
415 // Make the visible fragment of text hug the edge closest to the res t of the run by moving the origin
416 // at which we start drawing text.
417 // e.g. In the case of LTR text truncated in an RTL Context, the cor rect behavior is:
418 // |Hello|CBA| -> |...He|CBA|
419 // In order to draw the fragment "He" aligned to the right edge of i t's box, we need to start drawing
420 // farther to the right.
421 // NOTE: WebKit's behavior differs from that of IE which appears to just overlay the ellipsis on top of the
422 // truncated string i.e. |Hello|CBA| -> |...lo|CBA|
423 LayoutUnit widthOfVisibleText = renderer().width(m_start, m_truncati on, textPos(), isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle());
424 LayoutUnit widthOfHiddenText = m_logicalWidth - widthOfVisibleText;
425 // FIXME: The hit testing logic also needs to take this translation into account.
426 LayoutSize truncationOffset(isLeftToRightDirection() ? widthOfHidden Text : -widthOfHiddenText, 0);
427 adjustedPaintOffset.move(isHorizontal() ? truncationOffset : truncat ionOffset.transposedSize());
428 }
429 }
430
431 GraphicsContext* context = paintInfo.context;
432 RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
433
434 adjustedPaintOffset.move(0, styleToUse->isHorizontalWritingMode() ? 0 : -log icalHeight());
435
436 FloatPoint boxOrigin = locationIncludingFlipping();
437 boxOrigin.move(adjustedPaintOffset.x().toFloat(), adjustedPaintOffset.y().to Float());
438 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight()));
439
440 RenderCombineText* combinedText = styleToUse->hasTextCombine() && renderer() .isCombineText() && toRenderCombineText(renderer()).isCombined() ? &toRenderComb ineText(renderer()) : 0;
441
442 bool shouldRotate = !isHorizontal() && !combinedText;
443 if (shouldRotate)
444 context->concatCTM(rotation(boxRect, Clockwise));
445
446 // Determine whether or not we have composition underlines to draw.
447 bool containsComposition = renderer().node() && renderer().frame()->inputMet hodController().compositionNode() == renderer().node();
448 bool useCustomUnderlines = containsComposition && renderer().frame()->inputM ethodController().compositionUsesCustomUnderlines();
449
450 // Determine text colors.
451 TextPainter::Style textStyle = TextPainter::textPaintingStyle(renderer(), st yleToUse, paintInfo.forceBlackText(), isPrinting);
452 TextPainter::Style selectionStyle = TextPainter::selectionPaintingStyle(rend erer(), haveSelection, paintInfo.forceBlackText(), isPrinting, textStyle);
453 bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection);
454 bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != se lectionStyle;
455
456 // Set our font.
457 const Font& font = styleToUse->font();
458
459 FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontM etrics().ascent());
460 if (combinedText)
461 combinedText->adjustTextOrigin(textOrigin, boxRect);
462
463 // 1. Paint backgrounds behind text if needed. Examples of such backgrounds include selection
464 // and composition highlights.
465 if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseT extClip && !isPrinting) {
466 if (containsComposition) {
467 paintCompositionBackgrounds(context, boxOrigin, styleToUse, font, us eCustomUnderlines);
468 }
469
470 paintDocumentMarkers(context, boxOrigin, styleToUse, font, true);
471
472 if (haveSelection && !useCustomUnderlines)
473 paintSelection(context, boxOrigin, styleToUse, font, selectionStyle. fillColor);
474 }
475
476 // 2. Now paint the foreground, including text and decorations like underlin e/overline (in quirks mode only).
477 int length = m_len;
478 int maximumLength;
479 StringView string;
480 if (!combinedText) {
481 string = renderer().text().createView();
482 if (static_cast<unsigned>(length) != string.length() || m_start)
483 string.narrow(m_start, length);
484 maximumLength = renderer().textLength() - m_start;
485 } else {
486 combinedText->getStringToRender(m_start, string, length);
487 maximumLength = length;
488 }
489
490 StringBuilder charactersWithHyphen;
491 TextRun textRun = constructTextRun(styleToUse, font, string, maximumLength, hasHyphen() ? &charactersWithHyphen : 0);
492 if (hasHyphen())
493 length = textRun.length();
494
495 int selectionStart = 0;
496 int selectionEnd = 0;
497 if (paintSelectedTextOnly || paintSelectedTextSeparately)
498 selectionStartEnd(selectionStart, selectionEnd);
499
500 bool respectHyphen = selectionEnd == m_len && hasHyphen();
501 if (respectHyphen)
502 selectionEnd = textRun.length();
503
504 if (m_truncation != cNoTruncation) {
505 selectionStart = std::min<int>(selectionStart, m_truncation);
506 selectionEnd = std::min<int>(selectionEnd, m_truncation);
507 length = m_truncation;
508 }
509
510 TextPainter textPainter(context, font, textRun, textOrigin, boxRect, isHoriz ontal());
511 TextEmphasisPosition emphasisMarkPosition;
512 bool hasTextEmphasis = getEmphasisMarkPosition(styleToUse, emphasisMarkPosit ion);
513 if (hasTextEmphasis)
514 textPainter.setEmphasisMark(styleToUse->textEmphasisMarkString(), emphas isMarkPosition);
515 if (combinedText)
516 textPainter.setCombinedText(combinedText);
517
518 if (!paintSelectedTextOnly) {
519 // FIXME: Truncate right-to-left text correctly.
520 int startOffset = 0;
521 int endOffset = length;
522 if (paintSelectedTextSeparately && selectionStart < selectionEnd) {
523 startOffset = selectionEnd;
524 endOffset = selectionStart;
525 }
526
527 // FIXME: This cache should probably ultimately be held somewhere else.
528 // A hashmap is convenient to avoid a memory hit when the
529 // RuntimeEnabledFeature is off.
530 bool textBlobIsCacheable = RuntimeEnabledFeatures::textBlobEnabled() && startOffset == 0 && endOffset == length;
531 TextBlobPtr* cachedTextBlob = 0;
532 if (textBlobIsCacheable) {
533 if (!gTextBlobCache)
534 gTextBlobCache = new InlineTextBoxBlobCacheMap;
535 cachedTextBlob = &gTextBlobCache->add(this, nullptr).storedValue->va lue;
536 }
537 textPainter.paint(startOffset, endOffset, length, textStyle, cachedTextB lob);
538 }
539
540 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && selectionStart < selectionEnd) {
541 // paint only the text that is selected
542 textPainter.paint(selectionStart, selectionEnd, length, selectionStyle);
543 }
544
545 // Paint decorations
546 TextDecoration textDecorations = styleToUse->textDecorationsInEffect();
547 if (textDecorations != TextDecorationNone && !paintSelectedTextOnly) {
548 GraphicsContextStateSaver stateSaver(*context, false);
549 TextPainter::updateGraphicsContext(context, textStyle, isHorizontal(), s tateSaver);
550 if (combinedText)
551 context->concatCTM(rotation(boxRect, Clockwise));
552 paintDecoration(context, boxOrigin, textDecorations);
553 if (combinedText)
554 context->concatCTM(rotation(boxRect, Counterclockwise));
555 }
556
557 if (paintInfo.phase == PaintPhaseForeground) {
558 paintDocumentMarkers(context, boxOrigin, styleToUse, font, false);
559
560 // Paint custom underlines for compositions.
561 if (useCustomUnderlines) {
562 const Vector<CompositionUnderline>& underlines = renderer().frame()- >inputMethodController().customCompositionUnderlines();
563 CompositionUnderlineRangeFilter filter(underlines, start(), end());
564 for (CompositionUnderlineRangeFilter::ConstIterator it = filter.begi n(); it != filter.end(); ++it) {
565 if (it->color == Color::transparent)
566 continue;
567 paintCompositionUnderline(context, boxOrigin, *it);
568 }
569 }
570 }
571
572 if (shouldRotate)
573 context->concatCTM(rotation(boxRect, Counterclockwise));
574 } 361 }
575 362
576 void InlineTextBox::selectionStartEnd(int& sPos, int& ePos) const 363 void InlineTextBox::selectionStartEnd(int& sPos, int& ePos) const
577 { 364 {
578 int startPos, endPos; 365 int startPos, endPos;
579 if (renderer().selectionState() == RenderObject::SelectionInside) { 366 if (renderer().selectionState() == RenderObject::SelectionInside) {
580 startPos = 0; 367 startPos = 0;
581 endPos = renderer().textLength(); 368 endPos = renderer().textLength();
582 } else { 369 } else {
583 renderer().selectionStartEnd(startPos, endPos); 370 renderer().selectionStartEnd(startPos, endPos);
584 if (renderer().selectionState() == RenderObject::SelectionStart) 371 if (renderer().selectionState() == RenderObject::SelectionStart)
585 endPos = renderer().textLength(); 372 endPos = renderer().textLength();
586 else if (renderer().selectionState() == RenderObject::SelectionEnd) 373 else if (renderer().selectionState() == RenderObject::SelectionEnd)
587 startPos = 0; 374 startPos = 0;
588 } 375 }
589 376
590 sPos = std::max(startPos - m_start, 0); 377 sPos = std::max(startPos - m_start, 0);
591 ePos = std::min(endPos - m_start, (int)m_len); 378 ePos = std::min(endPos - m_start, (int)m_len);
592 } 379 }
593 380
594 void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& b oxOrigin, RenderStyle* style, const Font& font, Color textColor)
595 {
596 // See if we have a selection to paint at all.
597 int sPos, ePos;
598 selectionStartEnd(sPos, ePos);
599 if (sPos >= ePos)
600 return;
601
602 Color c = renderer().selectionBackgroundColor();
603 if (!c.alpha())
604 return;
605
606 // If the text color ends up being the same as the selection background, inv ert the selection
607 // background.
608 if (textColor == c)
609 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
610
611 // If the text is truncated, let the thing being painted in the truncation
612 // draw its own highlight.
613 int length = m_truncation != cNoTruncation ? m_truncation : m_len;
614 StringView string = renderer().text().createView();
615
616 if (string.length() != static_cast<unsigned>(length) || m_start)
617 string.narrow(m_start, length);
618
619 StringBuilder charactersWithHyphen;
620 bool respectHyphen = ePos == length && hasHyphen();
621 TextRun textRun = constructTextRun(style, font, string, renderer().textLengt h() - m_start, respectHyphen ? &charactersWithHyphen : 0);
622 if (respectHyphen)
623 ePos = textRun.length();
624
625 LayoutUnit selectionBottom = root().selectionBottom();
626 LayoutUnit selectionTop = root().selectionTopAdjustedForPrecedingBlock();
627
628 int deltaY = roundToInt(renderer().style()->isFlippedLinesWritingMode() ? se lectionBottom - logicalBottom() : logicalTop() - selectionTop);
629 int selHeight = std::max(0, roundToInt(selectionBottom - selectionTop));
630
631 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
632 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight));
633
634 GraphicsContextStateSaver stateSaver(*context);
635 context->clip(clipRect);
636 context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, sPos , ePos);
637 }
638
639 unsigned InlineTextBox::underlinePaintStart(const CompositionUnderline& underlin e)
640 {
641 return std::max(static_cast<unsigned>(m_start), underline.startOffset);
642 }
643
644 unsigned InlineTextBox::underlinePaintEnd(const CompositionUnderline& underline)
645 {
646 unsigned paintEnd = std::min(end() + 1, underline.endOffset); // end() point s at the last char, not past it.
647 if (m_truncation != cNoTruncation)
648 paintEnd = std::min(paintEnd, static_cast<unsigned>(m_start + m_truncati on));
649 return paintEnd;
650 }
651
652 void InlineTextBox::paintSingleCompositionBackgroundRun(GraphicsContext* context , const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, Color backg roundColor, int startPos, int endPos)
653 {
654 int sPos = std::max(startPos - m_start, 0);
655 int ePos = std::min(endPos - m_start, static_cast<int>(m_len));
656 if (sPos >= ePos)
657 return;
658
659 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop();
660 int selHeight = selectionHeight();
661 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
662 context->drawHighlightForText(font, constructTextRun(style, font), localOrig in, selHeight, backgroundColor, sPos, ePos);
663 }
664
665 static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorati onStyle)
666 {
667 StrokeStyle strokeStyle = SolidStroke;
668 switch (decorationStyle) {
669 case TextDecorationStyleSolid:
670 strokeStyle = SolidStroke;
671 break;
672 case TextDecorationStyleDouble:
673 strokeStyle = DoubleStroke;
674 break;
675 case TextDecorationStyleDotted:
676 strokeStyle = DottedStroke;
677 break;
678 case TextDecorationStyleDashed:
679 strokeStyle = DashedStroke;
680 break;
681 case TextDecorationStyleWavy:
682 strokeStyle = WavyStroke;
683 break;
684 }
685
686 return strokeStyle;
687 }
688
689 static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, const FontMetrics& fontMetrics, const InlineTextBox* inlineTextBox, const float textDecorationThickness)
690 {
691 // Compute the gap between the font and the underline. Use at least one
692 // pixel gap, if underline is thick then use a bigger gap.
693 int gap = 0;
694
695 // Underline position of zero means draw underline on Baseline Position,
696 // in Blink we need at least 1-pixel gap to adding following check.
697 // Positive underline Position means underline should be drawn above baselin e
698 // and negative value means drawing below baseline, negating the value as in Blink
699 // downward Y-increases.
700
701 if (fontMetrics.underlinePosition())
702 gap = -fontMetrics.underlinePosition();
703 else
704 gap = std::max<int>(1, ceilf(textDecorationThickness / 2.f));
705
706 // FIXME: We support only horizontal text for now.
707 switch (underlinePosition) {
708 case TextUnderlinePositionAuto:
709 return fontMetrics.ascent() + gap; // Position underline near the alphab etic baseline.
710 case TextUnderlinePositionUnder: {
711 // Position underline relative to the under edge of the lowest element's content box.
712 const float offset = inlineTextBox->root().maxLogicalTop() - inlineTextB ox->logicalTop();
713 if (offset > 0)
714 return inlineTextBox->logicalHeight() + gap + offset;
715 return inlineTextBox->logicalHeight() + gap;
716 }
717 }
718
719 ASSERT_NOT_REACHED();
720 return fontMetrics.ascent() + gap;
721 }
722
723 static void adjustStepToDecorationLength(float& step, float& controlPointDistanc e, float length)
724 {
725 ASSERT(step > 0);
726
727 if (length <= 0)
728 return;
729
730 unsigned stepCount = static_cast<unsigned>(length / step);
731
732 // Each Bezier curve starts at the same pixel that the previous one
733 // ended. We need to subtract (stepCount - 1) pixels when calculating the
734 // length covered to account for that.
735 float uncoveredLength = length - (stepCount * step - (stepCount - 1));
736 float adjustment = uncoveredLength / stepCount;
737 step += adjustment;
738 controlPointDistance += adjustment;
739 }
740
741 /*
742 * Draw one cubic Bezier curve and repeat the same pattern long the the decorati on's axis.
743 * The start point (p1), controlPoint1, controlPoint2 and end point (p2) of the Bezier curve
744 * form a diamond shape:
745 *
746 * step
747 * |-----------|
748 *
749 * controlPoint1
750 * +
751 *
752 *
753 * . .
754 * . .
755 * . .
756 * (x1, y1) p1 + . + p2 (x2, y2) - <--- Decoration's axis
757 * . . |
758 * . . |
759 * . . | controlPointDistance
760 * |
761 * |
762 * + -
763 * controlPoint2
764 *
765 * |-----------|
766 * step
767 */
768 static void strokeWavyTextDecoration(GraphicsContext* context, FloatPoint p1, Fl oatPoint p2, float strokeThickness)
769 {
770 context->adjustLineToPixelBoundaries(p1, p2, strokeThickness, context->strok eStyle());
771
772 Path path;
773 path.moveTo(p1);
774
775 // Distance between decoration's axis and Bezier curve's control points.
776 // The height of the curve is based on this distance. Use a minimum of 6 pix els distance since
777 // the actual curve passes approximately at half of that distance, that is 3 pixels.
778 // The minimum height of the curve is also approximately 3 pixels. Increases the curve's height
779 // as strockThickness increases to make the curve looks better.
780 float controlPointDistance = 3 * std::max<float>(2, strokeThickness);
781
782 // Increment used to form the diamond shape between start point (p1), contro l
783 // points and end point (p2) along the axis of the decoration. Makes the
784 // curve wider as strockThickness increases to make the curve looks better.
785 float step = 2 * std::max<float>(2, strokeThickness);
786
787 bool isVerticalLine = (p1.x() == p2.x());
788
789 if (isVerticalLine) {
790 ASSERT(p1.x() == p2.x());
791
792 float xAxis = p1.x();
793 float y1;
794 float y2;
795
796 if (p1.y() < p2.y()) {
797 y1 = p1.y();
798 y2 = p2.y();
799 } else {
800 y1 = p2.y();
801 y2 = p1.y();
802 }
803
804 adjustStepToDecorationLength(step, controlPointDistance, y2 - y1);
805 FloatPoint controlPoint1(xAxis + controlPointDistance, 0);
806 FloatPoint controlPoint2(xAxis - controlPointDistance, 0);
807
808 for (float y = y1; y + 2 * step <= y2;) {
809 controlPoint1.setY(y + step);
810 controlPoint2.setY(y + step);
811 y += 2 * step;
812 path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(xAxis , y));
813 }
814 } else {
815 ASSERT(p1.y() == p2.y());
816
817 float yAxis = p1.y();
818 float x1;
819 float x2;
820
821 if (p1.x() < p2.x()) {
822 x1 = p1.x();
823 x2 = p2.x();
824 } else {
825 x1 = p2.x();
826 x2 = p1.x();
827 }
828
829 adjustStepToDecorationLength(step, controlPointDistance, x2 - x1);
830 FloatPoint controlPoint1(0, yAxis + controlPointDistance);
831 FloatPoint controlPoint2(0, yAxis - controlPointDistance);
832
833 for (float x = x1; x + 2 * step <= x2;) {
834 controlPoint1.setX(x + step);
835 controlPoint2.setX(x + step);
836 x += 2 * step;
837 path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(x, yA xis));
838 }
839 }
840
841 context->setShouldAntialias(true);
842 context->strokePath(path);
843 }
844
845 static bool shouldSetDecorationAntialias(TextDecorationStyle decorationStyle)
846 {
847 return decorationStyle == TextDecorationStyleDotted || decorationStyle == Te xtDecorationStyleDashed;
848 }
849
850 static bool shouldSetDecorationAntialias(TextDecorationStyle underline, TextDeco rationStyle overline, TextDecorationStyle linethrough)
851 {
852 return shouldSetDecorationAntialias(underline) || shouldSetDecorationAntiali as(overline) || shouldSetDecorationAntialias(linethrough);
853 }
854
855 static void paintAppliedDecoration(GraphicsContext* context, FloatPoint start, f loat width, float doubleOffset, int wavyOffsetFactor,
856 RenderObject::AppliedTextDecoration decoration, float thickness, bool antial iasDecoration, bool isPrinting)
857 {
858 context->setStrokeStyle(textDecorationStyleToStrokeStyle(decoration.style));
859 context->setStrokeColor(decoration.color);
860
861 switch (decoration.style) {
862 case TextDecorationStyleWavy:
863 strokeWavyTextDecoration(context, start + FloatPoint(0, doubleOffset * w avyOffsetFactor), start + FloatPoint(width, doubleOffset * wavyOffsetFactor), th ickness);
864 break;
865 case TextDecorationStyleDotted:
866 case TextDecorationStyleDashed:
867 context->setShouldAntialias(antialiasDecoration);
868 // Fall through
869 default:
870 context->drawLineForText(start, width, isPrinting);
871
872 if (decoration.style == TextDecorationStyleDouble)
873 context->drawLineForText(start + FloatPoint(0, doubleOffset), width, isPrinting);
874 }
875 }
876
877 void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, TextDecoration deco)
878 {
879 GraphicsContextStateSaver stateSaver(*context);
880
881 if (m_truncation == cFullTruncation)
882 return;
883
884 FloatPoint localOrigin = boxOrigin;
885
886 float width = m_logicalWidth;
887 if (m_truncation != cNoTruncation) {
888 width = renderer().width(m_start, m_truncation, textPos(), isLeftToRight Direction() ? LTR : RTL, isFirstLineStyle());
889 if (!isLeftToRightDirection())
890 localOrigin.move(m_logicalWidth - width, 0);
891 }
892
893 // Get the text decoration colors.
894 RenderObject::AppliedTextDecoration underline, overline, linethrough;
895 renderer().getTextDecorations(deco, underline, overline, linethrough, true);
896 if (isFirstLineStyle())
897 renderer().getTextDecorations(deco, underline, overline, linethrough, tr ue, true);
898
899 // Use a special function for underlines to get the positioning exactly righ t.
900 bool isPrinting = renderer().document().printing();
901
902 RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
903 int baseline = styleToUse->fontMetrics().ascent();
904
905 // Set the thick of the line to be 10% (or something else ?)of the computed font size and not less than 1px.
906 // Using computedFontSize should take care of zoom as well.
907
908 // Update Underline thickness, in case we have Faulty Font Metrics calculati ng underline thickness by old method.
909 float textDecorationThickness = styleToUse->fontMetrics().underlineThickness ();
910 int fontHeightInt = (int)(styleToUse->fontMetrics().floatHeight() + 0.5);
911 if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHei ghtInt >> 1)))
912 textDecorationThickness = std::max(1.f, styleToUse->computedFontSize() / 10.f);
913
914 context->setStrokeThickness(textDecorationThickness);
915
916 bool antialiasDecoration = shouldSetDecorationAntialias(overline.style, unde rline.style, linethrough.style)
917 && BoxPainter::shouldAntialiasLines(context);
918
919 // Offset between lines - always non-zero, so lines never cross each other.
920 float doubleOffset = textDecorationThickness + 1.f;
921
922 if (deco & TextDecorationUnderline) {
923 const int underlineOffset = computeUnderlineOffset(styleToUse->textUnder linePosition(), styleToUse->fontMetrics(), this, textDecorationThickness);
924 paintAppliedDecoration(context, localOrigin + FloatPoint(0, underlineOff set), width, doubleOffset, 1, underline, textDecorationThickness, antialiasDecor ation, isPrinting);
925 }
926 if (deco & TextDecorationOverline) {
927 paintAppliedDecoration(context, localOrigin, width, -doubleOffset, 1, ov erline, textDecorationThickness, antialiasDecoration, isPrinting);
928 }
929 if (deco & TextDecorationLineThrough) {
930 const float lineThroughOffset = 2 * baseline / 3;
931 paintAppliedDecoration(context, localOrigin + FloatPoint(0, lineThroughO ffset), width, doubleOffset, 0, linethrough, textDecorationThickness, antialiasD ecoration, isPrinting);
932 }
933 }
934
935 static GraphicsContext::DocumentMarkerLineStyle lineStyleForMarkerType(DocumentM arker::MarkerType markerType)
936 {
937 switch (markerType) {
938 case DocumentMarker::Spelling:
939 return GraphicsContext::DocumentMarkerSpellingLineStyle;
940 case DocumentMarker::Grammar:
941 return GraphicsContext::DocumentMarkerGrammarLineStyle;
942 default:
943 ASSERT_NOT_REACHED();
944 return GraphicsContext::DocumentMarkerSpellingLineStyle;
945 }
946 }
947
948 void InlineTextBox::paintDocumentMarker(GraphicsContext* pt, const FloatPoint& b oxOrigin, DocumentMarker* marker, RenderStyle* style, const Font& font, bool gra mmar) 381 void InlineTextBox::paintDocumentMarker(GraphicsContext* pt, const FloatPoint& b oxOrigin, DocumentMarker* marker, RenderStyle* style, const Font& font, bool gra mmar)
949 { 382 {
950 // Never print spelling/grammar markers (5327887) 383 InlineTextBoxPainter(*this).paintDocumentMarker(pt, boxOrigin, marker, style , font, grammar);
951 if (renderer().document().printing())
952 return;
953
954 if (m_truncation == cFullTruncation)
955 return;
956
957 float start = 0; // start of line to draw, relative to tx
958 float width = m_logicalWidth; // how much line to draw
959
960 // Determine whether we need to measure text
961 bool markerSpansWholeBox = true;
962 if (m_start <= (int)marker->startOffset())
963 markerSpansWholeBox = false;
964 if ((end() + 1) != marker->endOffset()) // end points at the last char, not past it
965 markerSpansWholeBox = false;
966 if (m_truncation != cNoTruncation)
967 markerSpansWholeBox = false;
968
969 if (!markerSpansWholeBox || grammar) {
970 int startPosition = std::max<int>(marker->startOffset() - m_start, 0);
971 int endPosition = std::min<int>(marker->endOffset() - m_start, m_len);
972
973 if (m_truncation != cNoTruncation)
974 endPosition = std::min<int>(endPosition, m_truncation);
975
976 // Calculate start & width
977 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selection Bottom() - logicalBottom() : logicalTop() - selectionTop();
978 int selHeight = selectionHeight();
979 FloatPoint startPoint(boxOrigin.x(), boxOrigin.y() - deltaY);
980 TextRun run = constructTextRun(style, font);
981
982 // FIXME: Convert the document markers to float rects.
983 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, sta rtPoint, selHeight, startPosition, endPosition));
984 start = markerRect.x() - startPoint.x();
985 width = markerRect.width();
986
987 // Store rendered rects for bad grammar markers, so we can hit-test agai nst it elsewhere in order to
988 // display a toolTip. We don't do this for misspelling markers.
989 if (grammar) {
990 markerRect.move(-boxOrigin.x(), -boxOrigin.y());
991 markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).e nclosingBoundingBox();
992 toRenderedDocumentMarker(marker)->setRenderedRect(markerRect);
993 }
994 }
995
996 // IMPORTANT: The misspelling underline is not considered when calculating t he text bounds, so we have to
997 // make sure to fit within those bounds. This means the top pixel(s) of the underline will overlap the
998 // bottom pixel(s) of the glyphs in smaller font sizes. The alternatives ar e to increase the line spacing (bad!!)
999 // or decrease the underline thickness. The overlap is actually the most us eful, and matches what AppKit does.
1000 // So, we generally place the underline at the bottom of the text, but in la rger fonts that's not so good so
1001 // we pin to two pixels under the baseline.
1002 int lineThickness = misspellingLineThickness;
1003 int baseline = renderer().style(isFirstLineStyle())->fontMetrics().ascent();
1004 int descent = logicalHeight() - baseline;
1005 int underlineOffset;
1006 if (descent <= (2 + lineThickness)) {
1007 // Place the underline at the very bottom of the text in small/medium fo nts.
1008 underlineOffset = logicalHeight() - lineThickness;
1009 } else {
1010 // In larger fonts, though, place the underline up near the baseline to prevent a big gap.
1011 underlineOffset = baseline + 2;
1012 }
1013 pt->drawLineForDocumentMarker(FloatPoint(boxOrigin.x() + start, boxOrigin.y( ) + underlineOffset), width, lineStyleForMarkerType(marker->type()));
1014 } 384 }
1015 385
1016 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPoint& boxOrigin, DocumentMarker* marker, RenderStyle* style, const Font& font) 386 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPoint& boxOrigin, DocumentMarker* marker, RenderStyle* style, const Font& font)
1017 { 387 {
1018 // Use same y positioning and height as for selection, so that when the sele ction and this highlight are on 388 InlineTextBoxPainter(*this).paintTextMatchMarker(pt, boxOrigin, marker, styl e, font);
1019 // the same word there are no pieces sticking out.
1020 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop();
1021 int selHeight = selectionHeight();
1022
1023 int sPos = std::max(marker->startOffset() - m_start, (unsigned)0);
1024 int ePos = std::min(marker->endOffset() - m_start, (unsigned)m_len);
1025 TextRun run = constructTextRun(style, font);
1026
1027 // Always compute and store the rect associated with this marker. The comput ed rect is in absolute coordinates.
1028 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoin t(x(), selectionTop()), selHeight, sPos, ePos));
1029 markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).enclosing BoundingBox();
1030 toRenderedDocumentMarker(marker)->setRenderedRect(markerRect);
1031
1032 // Optionally highlight the text
1033 if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) {
1034 Color color = marker->activeMatch() ?
1035 RenderTheme::theme().platformActiveTextSearchHighlightColor() :
1036 RenderTheme::theme().platformInactiveTextSearchHighlightColor();
1037 GraphicsContextStateSaver stateSaver(*pt);
1038 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_logicalWidth , selHeight));
1039 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin. y() - deltaY), selHeight, color, sPos, ePos);
1040 }
1041 }
1042
1043 void InlineTextBox::paintCompositionBackgrounds(GraphicsContext* pt, const Float Point& boxOrigin, RenderStyle* style, const Font& font, bool useCustomUnderlines )
1044 {
1045 if (useCustomUnderlines) {
1046 // Paint custom background highlights for compositions.
1047 const Vector<CompositionUnderline>& underlines = renderer().frame()->inp utMethodController().customCompositionUnderlines();
1048 CompositionUnderlineRangeFilter filter(underlines, start(), end());
1049 for (CompositionUnderlineRangeFilter::ConstIterator it = filter.begin(); it != filter.end(); ++it) {
1050 if (it->backgroundColor == Color::transparent)
1051 continue;
1052 paintSingleCompositionBackgroundRun(pt, boxOrigin, style, font, it-> backgroundColor, underlinePaintStart(*it), underlinePaintEnd(*it));
1053 }
1054
1055 } else {
1056 paintSingleCompositionBackgroundRun(pt, boxOrigin, style, font, RenderTh eme::theme().platformDefaultCompositionBackgroundColor(),
1057 renderer().frame()->inputMethodController().compositionStart(),
1058 renderer().frame()->inputMethodController().compositionEnd());
1059 }
1060 }
1061
1062 void InlineTextBox::paintDocumentMarkers(GraphicsContext* pt, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, bool background)
1063 {
1064 if (!renderer().node())
1065 return;
1066
1067 DocumentMarkerVector markers = renderer().document().markers().markersFor(re nderer().node());
1068 DocumentMarkerVector::const_iterator markerIt = markers.begin();
1069
1070 // Give any document markers that touch this run a chance to draw before the text has been drawn.
1071 // Note end() points at the last char, not one past it like endOffset and ra nges do.
1072 for ( ; markerIt != markers.end(); ++markerIt) {
1073 DocumentMarker* marker = *markerIt;
1074
1075 // Paint either the background markers or the foreground markers, but no t both
1076 switch (marker->type()) {
1077 case DocumentMarker::Grammar:
1078 case DocumentMarker::Spelling:
1079 if (background)
1080 continue;
1081 break;
1082 case DocumentMarker::TextMatch:
1083 if (!background)
1084 continue;
1085 break;
1086 default:
1087 continue;
1088 }
1089
1090 if (marker->endOffset() <= start())
1091 // marker is completely before this run. This might be a marker tha t sits before the
1092 // first run we draw, or markers that were within runs we skipped du e to truncation.
1093 continue;
1094
1095 if (marker->startOffset() > end())
1096 // marker is completely after this run, bail. A later run will pain t it.
1097 break;
1098
1099 // marker intersects this run. Paint it.
1100 switch (marker->type()) {
1101 case DocumentMarker::Spelling:
1102 paintDocumentMarker(pt, boxOrigin, marker, style, font, false);
1103 break;
1104 case DocumentMarker::Grammar:
1105 paintDocumentMarker(pt, boxOrigin, marker, style, font, true);
1106 break;
1107 case DocumentMarker::TextMatch:
1108 paintTextMatchMarker(pt, boxOrigin, marker, style, font);
1109 break;
1110 default:
1111 ASSERT_NOT_REACHED();
1112 }
1113
1114 }
1115 }
1116
1117 void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, const FloatP oint& boxOrigin, const CompositionUnderline& underline)
1118 {
1119 if (m_truncation == cFullTruncation)
1120 return;
1121
1122 unsigned paintStart = underlinePaintStart(underline);
1123 unsigned paintEnd = underlinePaintEnd(underline);
1124
1125 // start of line to draw, relative to paintOffset.
1126 float start = paintStart == static_cast<unsigned>(m_start) ? 0 :
1127 renderer().width(m_start, paintStart - m_start, textPos(), isLeftToRight Direction() ? LTR : RTL, isFirstLineStyle());
1128 // how much line to draw
1129 float width = (paintStart == static_cast<unsigned>(m_start) && paintEnd == s tatic_cast<unsigned>(end()) + 1) ? m_logicalWidth :
1130 renderer().width(paintStart, paintEnd - paintStart, textPos() + start, i sLeftToRightDirection() ? LTR : RTL, isFirstLineStyle());
1131
1132 // Thick marked text underlines are 2px thick as long as there is room for t he 2px line under the baseline.
1133 // All other marked text underlines are 1px thick.
1134 // If there's not enough space the underline will touch or overlap character s.
1135 int lineThickness = 1;
1136 int baseline = renderer().style(isFirstLineStyle())->fontMetrics().ascent();
1137 if (underline.thick && logicalHeight() - baseline >= 2)
1138 lineThickness = 2;
1139
1140 // We need to have some space between underlines of subsequent clauses, beca use some input methods do not use different underline styles for those.
1141 // We make each line shorter, which has a harmless side effect of shortening the first and last clauses, too.
1142 start += 1;
1143 width -= 2;
1144
1145 ctx->setStrokeColor(underline.color);
1146 ctx->setStrokeThickness(lineThickness);
1147 ctx->drawLineForText(FloatPoint(boxOrigin.x() + start, boxOrigin.y() + logic alHeight() - lineThickness), width, renderer().document().printing());
1148 } 389 }
1149 390
1150 int InlineTextBox::caretMinOffset() const 391 int InlineTextBox::caretMinOffset() const
1151 { 392 {
1152 return m_start; 393 return m_start;
1153 } 394 }
1154 395
1155 int InlineTextBox::caretMaxOffset() const 396 int InlineTextBox::caretMaxOffset() const
1156 { 397 {
1157 return m_start + m_len; 398 return m_start + m_len;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); 555 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj);
1315 const int rendererCharacterOffset = 24; 556 const int rendererCharacterOffset = 24;
1316 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) 557 for (; printedCharacters < rendererCharacterOffset; printedCharacters++)
1317 fputc(' ', stderr); 558 fputc(' ', stderr);
1318 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); 559 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata());
1319 } 560 }
1320 561
1321 #endif 562 #endif
1322 563
1323 } // namespace blink 564 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/InlineTextBox.h ('k') | Source/core/rendering/svg/SVGInlineTextBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698