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/CompositionUnderlineVisitor.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 583 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 CompositionUnderlineVisitor visitor(underlines, start(), end()); | |
|
yosin_UTC9
2014/06/05 01:19:00
How about using begin()/end() STL iterator protoco
huangs
2014/06/05 15:40:33
Range-for and auto aren't used in WebKit. Also, e
| |
| 642 const CompositionUnderline* underline; | |
| 643 while (visitor.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, Color(225, 221, 85), |
|
yosin_UTC9
2014/06/05 01:19:00
Could you move this hard coded color value to some
huangs
2014/06/05 15:40:33
Done.
"%02X%02X%02X" % (255, 221, 85) == "FFDD55"
| |
| 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 Loading... | |
| 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 CompositionUnderlineVisitor visitor(underlines, start(), end()); |
| 768 | 785 const CompositionUnderline* underline; |
| 769 for (size_t index = 0; index < numUnderlines; ++index) { | 786 while (visitor.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 { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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((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, (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, (int)m_len); | |
|
yosin_UTC9
2014/06/05 01:19:00
nit: static_cast<int>(m_len)
huangs
2014/06/05 15:40:33
Done, replaced globally.
| |
| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 == (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 == (unsigned)m_start && paintEnd == (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 Loading... | |
| 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 |
| OLD | NEW |