Chromium Code Reviews| 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 * |
| 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/CompositionUnderlineRangeFilter.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 Loading... | |
| 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 Loading... | |
| 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 CompositionUnderlineRangeFilter filter(underlines, start(), end( )); | |
| 642 for (CompositionUnderlineRangeFilter::ConstIterator it = filter. begin(); it != filter.end(); ++it) { | |
| 643 if ((*it).backgroundColor != Color::transparent) { | |
| 644 unsigned paintStart = getUnderlinePaintStart(*it); | |
| 645 unsigned paintEnd = getUnderlinePaintEnd(*it); | |
| 646 paintCompositionBackground(context, boxOrigin, styleToUs e, font, (*it).backgroundColor, paintStart, paintEnd); | |
| 647 } | |
| 648 } | |
| 635 | 649 |
| 636 if (containsComposition && !useCustomUnderlines) { | 650 } else { |
| 637 paintCompositionBackground(context, boxOrigin, styleToUse, font, | 651 paintCompositionBackground(context, boxOrigin, styleToUse, font, RenderTheme::theme().platformDefaultCompositionBackgroundColor(), |
| 638 renderer().frame()->inputMethodController().compositionStart(), | 652 renderer().frame()->inputMethodController().compositionStart (), |
| 639 renderer().frame()->inputMethodController().compositionEnd()); | 653 renderer().frame()->inputMethodController().compositionEnd() ); |
| 654 } | |
| 640 } | 655 } |
| 641 | 656 |
| 642 paintDocumentMarkers(context, boxOrigin, styleToUse, font, true); | 657 paintDocumentMarkers(context, boxOrigin, styleToUse, font, true); |
| 643 | 658 |
| 644 if (haveSelection && !useCustomUnderlines) | 659 if (haveSelection && !useCustomUnderlines) |
| 645 paintSelection(context, boxOrigin, styleToUse, font, selectionFillCo lor); | 660 paintSelection(context, boxOrigin, styleToUse, font, selectionFillCo lor); |
| 646 } | 661 } |
| 647 | 662 |
| 648 // 2. Now paint the foreground, including text and decorations like underlin e/overline (in quirks mode only). | 663 // 2. Now paint the foreground, including text and decorations like underlin e/overline (in quirks mode only). |
| 649 int length = m_len; | 664 int length = m_len; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 if (combinedText) | 770 if (combinedText) |
| 756 context->concatCTM(rotation(boxRect, Clockwise)); | 771 context->concatCTM(rotation(boxRect, Clockwise)); |
| 757 paintDecoration(context, boxOrigin, textDecorations, textShadow); | 772 paintDecoration(context, boxOrigin, textDecorations, textShadow); |
| 758 if (combinedText) | 773 if (combinedText) |
| 759 context->concatCTM(rotation(boxRect, Counterclockwise)); | 774 context->concatCTM(rotation(boxRect, Counterclockwise)); |
| 760 } | 775 } |
| 761 | 776 |
| 762 if (paintInfo.phase == PaintPhaseForeground) { | 777 if (paintInfo.phase == PaintPhaseForeground) { |
| 763 paintDocumentMarkers(context, boxOrigin, styleToUse, font, false); | 778 paintDocumentMarkers(context, boxOrigin, styleToUse, font, false); |
| 764 | 779 |
| 780 // Paint custom underlines for compositions. | |
| 765 if (useCustomUnderlines) { | 781 if (useCustomUnderlines) { |
| 766 const Vector<CompositionUnderline>& underlines = renderer().frame()- >inputMethodController().customCompositionUnderlines(); | 782 const Vector<CompositionUnderline>& underlines = renderer().frame()- >inputMethodController().customCompositionUnderlines(); |
| 767 size_t numUnderlines = underlines.size(); | 783 CompositionUnderlineRangeFilter filter(underlines, start(), end()); |
| 768 | 784 for (CompositionUnderlineRangeFilter::ConstIterator it = filter.begi n(); it != filter.end(); ++it) { |
| 769 for (size_t index = 0; index < numUnderlines; ++index) { | 785 paintCompositionUnderline(context, boxOrigin, *it); |
| 770 const CompositionUnderline& underline = underlines[index]; | |
| 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 } | 786 } |
| 788 } | 787 } |
| 789 } | 788 } |
| 790 | 789 |
| 791 if (shouldRotate) | 790 if (shouldRotate) |
| 792 context->concatCTM(rotation(boxRect, Counterclockwise)); | 791 context->concatCTM(rotation(boxRect, Counterclockwise)); |
| 793 } | 792 } |
| 794 | 793 |
| 795 void InlineTextBox::selectionStartEnd(int& sPos, int& ePos) | 794 void InlineTextBox::selectionStartEnd(int& sPos, int& ePos) |
| 796 { | 795 { |
| 797 int startPos, endPos; | 796 int startPos, endPos; |
| 798 if (renderer().selectionState() == RenderObject::SelectionInside) { | 797 if (renderer().selectionState() == RenderObject::SelectionInside) { |
| 799 startPos = 0; | 798 startPos = 0; |
| 800 endPos = textRenderer().textLength(); | 799 endPos = textRenderer().textLength(); |
| 801 } else { | 800 } else { |
| 802 textRenderer().selectionStartEnd(startPos, endPos); | 801 textRenderer().selectionStartEnd(startPos, endPos); |
| 803 if (renderer().selectionState() == RenderObject::SelectionStart) | 802 if (renderer().selectionState() == RenderObject::SelectionStart) |
| 804 endPos = textRenderer().textLength(); | 803 endPos = textRenderer().textLength(); |
| 805 else if (renderer().selectionState() == RenderObject::SelectionEnd) | 804 else if (renderer().selectionState() == RenderObject::SelectionEnd) |
| 806 startPos = 0; | 805 startPos = 0; |
| 807 } | 806 } |
| 808 | 807 |
| 809 sPos = max(startPos - m_start, 0); | 808 sPos = max(startPos - m_start, 0); |
| 810 ePos = min(endPos - m_start, (int)m_len); | 809 ePos = min(endPos - m_start, static_cast<int>(m_len)); |
| 811 } | 810 } |
| 812 | 811 |
| 813 void alignSelectionRectToDevicePixels(FloatRect& rect) | 812 void alignSelectionRectToDevicePixels(FloatRect& rect) |
| 814 { | 813 { |
| 815 float maxX = floorf(rect.maxX()); | 814 float maxX = floorf(rect.maxX()); |
| 816 rect.setX(floorf(rect.x())); | 815 rect.setX(floorf(rect.x())); |
| 817 rect.setWidth(roundf(maxX - rect.x())); | 816 rect.setWidth(roundf(maxX - rect.x())); |
| 818 } | 817 } |
| 819 | 818 |
| 820 void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& b oxOrigin, RenderStyle* style, const Font& font, Color textColor) | 819 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 Loading... | |
| 862 | 861 |
| 863 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); | 862 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); |
| 864 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight)); | 863 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight)); |
| 865 alignSelectionRectToDevicePixels(clipRect); | 864 alignSelectionRectToDevicePixels(clipRect); |
| 866 | 865 |
| 867 context->clip(clipRect); | 866 context->clip(clipRect); |
| 868 | 867 |
| 869 context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, sPos , ePos); | 868 context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, sPos , ePos); |
| 870 } | 869 } |
| 871 | 870 |
| 872 void InlineTextBox::paintCompositionBackground(GraphicsContext* context, const F loatPoint& boxOrigin, RenderStyle* style, const Font& font, int startPos, int en dPos) | 871 unsigned InlineTextBox::getUnderlinePaintStart(const CompositionUnderline& under line) |
|
yosin_UTC9
2014/06/09 01:49:56
nit: size_t
huangs
2014/06/09 06:07:13
Done. Note that I only changed return types, but
| |
| 873 { | 872 { |
| 874 int offset = m_start; | 873 return max(static_cast<unsigned>(m_start), underline.startOffset); |
|
yosin_UTC9
2014/06/09 01:49:56
nit: It is better to write |std::max|.
huangs
2014/06/09 06:07:13
Done, replaced globally in file, and included <alg
| |
| 875 int sPos = max(startPos - offset, 0); | 874 } |
| 876 int ePos = min(endPos - offset, (int)m_len); | |
| 877 | 875 |
| 876 unsigned InlineTextBox::getUnderlinePaintEnd(const CompositionUnderline& underli ne) | |
| 877 { | |
| 878 unsigned paintEnd = min(end() + 1, underline.endOffset); // end() points at the last char, not past it. | |
| 879 if (m_truncation != cNoTruncation) | |
| 880 paintEnd = min(paintEnd, static_cast<unsigned>(m_start + m_truncation)); | |
| 881 return paintEnd; | |
| 882 } | |
| 883 | |
| 884 void InlineTextBox::paintCompositionBackground(GraphicsContext* context, const F loatPoint& boxOrigin, RenderStyle* style, const Font& font, Color backgroundColo r, int startPos, int endPos) | |
| 885 { | |
| 886 int sPos = max(startPos - m_start, 0); | |
| 887 int ePos = min(endPos - m_start, static_cast<int>(m_len)); | |
| 878 if (sPos >= ePos) | 888 if (sPos >= ePos) |
| 879 return; | 889 return; |
| 880 | 890 |
| 881 GraphicsContextStateSaver stateSaver(*context); | 891 GraphicsContextStateSaver stateSaver(*context); |
| 882 | 892 |
| 883 Color c = Color(225, 221, 85); | 893 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 | 894 |
| 887 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop(); | 895 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop(); |
| 888 int selHeight = selectionHeight(); | 896 int selHeight = selectionHeight(); |
| 889 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); | 897 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); |
| 890 context->drawHighlightForText(font, constructTextRun(style, font), localOrig in, selHeight, c, sPos, ePos); | 898 context->drawHighlightForText(font, constructTextRun(style, font), localOrig in, selHeight, backgroundColor, sPos, ePos); |
| 891 } | 899 } |
| 892 | 900 |
| 893 static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorati onStyle) | 901 static StrokeStyle textDecorationStyleToStrokeStyle(TextDecorationStyle decorati onStyle) |
| 894 { | 902 { |
| 895 StrokeStyle strokeStyle = SolidStroke; | 903 StrokeStyle strokeStyle = SolidStroke; |
| 896 switch (decorationStyle) { | 904 switch (decorationStyle) { |
| 897 case TextDecorationStyleSolid: | 905 case TextDecorationStyleSolid: |
| 898 strokeStyle = SolidStroke; | 906 strokeStyle = SolidStroke; |
| 899 break; | 907 break; |
| 900 case TextDecorationStyleDouble: | 908 case TextDecorationStyleDouble: |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1132 | 1140 |
| 1133 RenderStyle* styleToUse = renderer().style(isFirstLineStyle()); | 1141 RenderStyle* styleToUse = renderer().style(isFirstLineStyle()); |
| 1134 int baseline = styleToUse->fontMetrics().ascent(); | 1142 int baseline = styleToUse->fontMetrics().ascent(); |
| 1135 | 1143 |
| 1136 size_t shadowCount = shadowList ? shadowList->shadows().size() : 0; | 1144 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. | 1145 // 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. | 1146 // Using computedFontSize should take care of zoom as well. |
| 1139 | 1147 |
| 1140 // Update Underline thickness, in case we have Faulty Font Metrics calculati ng underline thickness by old method. | 1148 // Update Underline thickness, in case we have Faulty Font Metrics calculati ng underline thickness by old method. |
| 1141 float textDecorationThickness = styleToUse->fontMetrics().underlineThickness (); | 1149 float textDecorationThickness = styleToUse->fontMetrics().underlineThickness (); |
| 1142 int fontHeightInt = (int)(styleToUse->fontMetrics().floatHeight() + 0.5); | 1150 int fontHeightInt = static_cast<int>(styleToUse->fontMetrics().floatHeight() + 0.5); |
| 1143 if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHei ghtInt >> 1))) | 1151 if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHei ghtInt >> 1))) |
| 1144 textDecorationThickness = std::max(1.f, styleToUse->computedFontSize() / 10.f); | 1152 textDecorationThickness = std::max(1.f, styleToUse->computedFontSize() / 10.f); |
| 1145 | 1153 |
| 1146 context->setStrokeThickness(textDecorationThickness); | 1154 context->setStrokeThickness(textDecorationThickness); |
| 1147 | 1155 |
| 1148 bool antialiasDecoration = shouldSetDecorationAntialias(overline.style, unde rline.style, linethrough.style) | 1156 bool antialiasDecoration = shouldSetDecorationAntialias(overline.style, unde rline.style, linethrough.style) |
| 1149 && RenderBoxModelObject::shouldAntialiasLines(context); | 1157 && RenderBoxModelObject::shouldAntialiasLines(context); |
| 1150 | 1158 |
| 1151 float extraOffset = 0; | 1159 float extraOffset = 0; |
| 1152 if (!linesAreOpaque && shadowCount > 1) { | 1160 if (!linesAreOpaque && shadowCount > 1) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1217 return; | 1225 return; |
| 1218 | 1226 |
| 1219 if (m_truncation == cFullTruncation) | 1227 if (m_truncation == cFullTruncation) |
| 1220 return; | 1228 return; |
| 1221 | 1229 |
| 1222 float start = 0; // start of line to draw, relative to tx | 1230 float start = 0; // start of line to draw, relative to tx |
| 1223 float width = m_logicalWidth; // how much line to draw | 1231 float width = m_logicalWidth; // how much line to draw |
| 1224 | 1232 |
| 1225 // Determine whether we need to measure text | 1233 // Determine whether we need to measure text |
| 1226 bool markerSpansWholeBox = true; | 1234 bool markerSpansWholeBox = true; |
| 1227 if (m_start <= (int)marker->startOffset()) | 1235 if (m_start <= static_cast<int>(marker->startOffset())) |
| 1228 markerSpansWholeBox = false; | 1236 markerSpansWholeBox = false; |
| 1229 if ((end() + 1) != marker->endOffset()) // end points at the last char, not past it | 1237 if ((end() + 1) != marker->endOffset()) // end points at the last char, not past it |
| 1230 markerSpansWholeBox = false; | 1238 markerSpansWholeBox = false; |
| 1231 if (m_truncation != cNoTruncation) | 1239 if (m_truncation != cNoTruncation) |
| 1232 markerSpansWholeBox = false; | 1240 markerSpansWholeBox = false; |
| 1233 | 1241 |
| 1234 if (!markerSpansWholeBox || grammar) { | 1242 if (!markerSpansWholeBox || grammar) { |
| 1235 int startPosition = max<int>(marker->startOffset() - m_start, 0); | 1243 int startPosition = max<int>(marker->startOffset() - m_start, 0); |
| 1236 int endPosition = min<int>(marker->endOffset() - m_start, m_len); | 1244 int endPosition = min<int>(marker->endOffset() - m_start, m_len); |
| 1237 | 1245 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1278 pt->drawLineForDocumentMarker(FloatPoint(boxOrigin.x() + start, boxOrigin.y( ) + underlineOffset), width, lineStyleForMarkerType(marker->type())); | 1286 pt->drawLineForDocumentMarker(FloatPoint(boxOrigin.x() + start, boxOrigin.y( ) + underlineOffset), width, lineStyleForMarkerType(marker->type())); |
| 1279 } | 1287 } |
| 1280 | 1288 |
| 1281 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPoint& boxOrigin, DocumentMarker* marker, RenderStyle* style, const Font& font) | 1289 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPoint& boxOrigin, DocumentMarker* marker, RenderStyle* style, const Font& font) |
| 1282 { | 1290 { |
| 1283 // Use same y positioning and height as for selection, so that when the sele ction and this highlight are on | 1291 // 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. | 1292 // the same word there are no pieces sticking out. |
| 1285 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop(); | 1293 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBott om() - logicalBottom() : logicalTop() - selectionTop(); |
| 1286 int selHeight = selectionHeight(); | 1294 int selHeight = selectionHeight(); |
| 1287 | 1295 |
| 1288 int sPos = max(marker->startOffset() - m_start, (unsigned)0); | 1296 int sPos = max(marker->startOffset() - m_start, 0U); |
| 1289 int ePos = min(marker->endOffset() - m_start, (unsigned)m_len); | 1297 int ePos = min(marker->endOffset() - m_start, static_cast<unsigned>(m_len)); |
| 1290 TextRun run = constructTextRun(style, font); | 1298 TextRun run = constructTextRun(style, font); |
| 1291 | 1299 |
| 1292 // Always compute and store the rect associated with this marker. The comput ed rect is in absolute coordinates. | 1300 // 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)); | 1301 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoin t(x(), selectionTop()), selHeight, sPos, ePos)); |
| 1294 markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).enclosing BoundingBox(); | 1302 markerRect = renderer().localToAbsoluteQuad(FloatRect(markerRect)).enclosing BoundingBox(); |
| 1295 toRenderedDocumentMarker(marker)->setRenderedRect(markerRect); | 1303 toRenderedDocumentMarker(marker)->setRenderedRect(markerRect); |
| 1296 | 1304 |
| 1297 // Optionally highlight the text | 1305 // Optionally highlight the text |
| 1298 if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) { | 1306 if (renderer().frame()->editor().markedTextMatchesAreHighlighted()) { |
| 1299 Color color = marker->activeMatch() ? | 1307 Color color = marker->activeMatch() ? |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1359 } | 1367 } |
| 1360 | 1368 |
| 1361 } | 1369 } |
| 1362 } | 1370 } |
| 1363 | 1371 |
| 1364 void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, const FloatP oint& boxOrigin, const CompositionUnderline& underline) | 1372 void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, const FloatP oint& boxOrigin, const CompositionUnderline& underline) |
| 1365 { | 1373 { |
| 1366 if (m_truncation == cFullTruncation) | 1374 if (m_truncation == cFullTruncation) |
| 1367 return; | 1375 return; |
| 1368 | 1376 |
| 1369 float start = 0; // start of line to draw, relative to tx | 1377 unsigned paintStart = getUnderlinePaintStart(underline); |
| 1370 float width = m_logicalWidth; // how much line to draw | 1378 unsigned paintEnd = getUnderlinePaintEnd(underline); |
| 1371 bool useWholeWidth = true; | 1379 |
| 1372 unsigned paintStart = m_start; | 1380 // start of line to draw, relative to tx |
| 1373 unsigned paintEnd = end() + 1; // end points at the last char, not past it | 1381 float start = paintStart == static_cast<unsigned>(m_start) ? 0 : |
| 1374 if (paintStart <= underline.startOffset) { | 1382 toRenderText(renderer()).width(m_start, paintStart - m_start, textPos(), isLeftToRightDirection() ? LTR : RTL, isFirstLineStyle()); |
| 1375 paintStart = underline.startOffset; | 1383 // how much line to draw |
| 1376 useWholeWidth = false; | 1384 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()); | 1385 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 | 1386 |
| 1391 // Thick marked text underlines are 2px thick as long as there is room for t he 2px line under the baseline. | 1387 // 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. | 1388 // All other marked text underlines are 1px thick. |
| 1393 // If there's not enough space the underline will touch or overlap character s. | 1389 // If there's not enough space the underline will touch or overlap character s. |
| 1394 int lineThickness = 1; | 1390 int lineThickness = 1; |
| 1395 int baseline = renderer().style(isFirstLineStyle())->fontMetrics().ascent(); | 1391 int baseline = renderer().style(isFirstLineStyle())->fontMetrics().ascent(); |
| 1396 if (underline.thick && logicalHeight() - baseline >= 2) | 1392 if (underline.thick && logicalHeight() - baseline >= 2) |
| 1397 lineThickness = 2; | 1393 lineThickness = 2; |
| 1398 | 1394 |
| 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. | 1395 // 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 Loading... | |
| 1574 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); | 1570 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); |
| 1575 const int rendererCharacterOffset = 24; | 1571 const int rendererCharacterOffset = 24; |
| 1576 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) | 1572 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) |
| 1577 fputc(' ', stderr); | 1573 fputc(' ', stderr); |
| 1578 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); | 1574 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); |
| 1579 } | 1575 } |
| 1580 | 1576 |
| 1581 #endif | 1577 #endif |
| 1582 | 1578 |
| 1583 } // namespace WebCore | 1579 } // namespace WebCore |
| OLD | NEW |