OLD | NEW |
---|---|
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * (C) 2000 Dirk Mueller (mueller@kde.org) |
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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" |
47 #include "core/rendering/style/ShadowList.h" | 47 #include "core/rendering/style/ShadowList.h" |
48 #include "core/rendering/svg/SVGTextRunRenderingContext.h" | 48 #include "core/rendering/svg/SVGTextRunRenderingContext.h" |
49 #include "platform/RuntimeEnabledFeatures.h" | 49 #include "platform/RuntimeEnabledFeatures.h" |
50 #include "platform/fonts/FontCache.h" | 50 #include "platform/fonts/FontCache.h" |
51 #include "platform/fonts/GlyphBuffer.h" | 51 #include "platform/fonts/GlyphBuffer.h" |
52 #include "platform/fonts/WidthIterator.h" | 52 #include "platform/fonts/WidthIterator.h" |
53 #include "platform/graphics/DrawLooperBuilder.h" | |
54 #include "platform/graphics/GraphicsContextStateSaver.h" | 53 #include "platform/graphics/GraphicsContextStateSaver.h" |
55 #include "wtf/Vector.h" | 54 #include "wtf/Vector.h" |
56 #include "wtf/text/CString.h" | 55 #include "wtf/text/CString.h" |
57 #include "wtf/text/StringBuilder.h" | 56 #include "wtf/text/StringBuilder.h" |
58 | 57 |
59 #include <algorithm> | 58 #include <algorithm> |
60 | 59 |
61 namespace WebCore { | 60 namespace WebCore { |
62 | 61 |
63 struct SameSizeAsInlineTextBox : public InlineBox { | 62 struct SameSizeAsInlineTextBox : public InlineBox { |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 FloatRect rect(boxOrigin, size()); | 380 FloatRect rect(boxOrigin, size()); |
382 if (m_truncation != cFullTruncation && visibleToHitTestRequest(request) && l ocationInContainer.intersects(rect)) { | 381 if (m_truncation != cFullTruncation && visibleToHitTestRequest(request) && l ocationInContainer.intersects(rect)) { |
383 renderer().updateHitTestResult(result, flipForWritingMode(locationInCont ainer.point() - toLayoutSize(accumulatedOffset))); | 382 renderer().updateHitTestResult(result, flipForWritingMode(locationInCont ainer.point() - toLayoutSize(accumulatedOffset))); |
384 if (!result.addNodeToRectBasedTestResult(renderer().node(), request, loc ationInContainer, rect)) | 383 if (!result.addNodeToRectBasedTestResult(renderer().node(), request, loc ationInContainer, rect)) |
385 return true; | 384 return true; |
386 } | 385 } |
387 return false; | 386 return false; |
388 } | 387 } |
389 | 388 |
390 static void paintTextWithShadows(GraphicsContext* context, | 389 static void paintTextWithShadows(GraphicsContext* context, |
391 const RenderObject& renderer, const Font& font, const TextRun& textRun, | 390 const Font& font, const TextRun& textRun, |
392 const AtomicString& emphasisMark, int emphasisMarkOffset, | 391 const AtomicString& emphasisMark, int emphasisMarkOffset, |
393 int startOffset, int endOffset, int truncationPoint, | 392 int startOffset, int endOffset, int truncationPoint, |
394 const FloatPoint& textOrigin, const FloatRect& boxRect, | 393 const FloatPoint& textOrigin, const FloatRect& boxRect, |
395 const ShadowList* shadowList, bool stroked, bool horizontal) | 394 const ShadowList* shadowList, bool horizontal) |
396 { | 395 { |
397 // Text shadows are disabled when printing. http://crbug.com/258321 | 396 // Text shadows are disabled when printing. http://crbug.com/258321 |
398 bool hasShadow = shadowList && !context->printing(); | 397 bool hasShadow = shadowList && !context->printing(); |
399 | 398 if (hasShadow) |
400 if (hasShadow) { | 399 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S hadowIgnoresAlpha, horizontal)); |
401 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create( ); | |
402 for (size_t i = shadowList->shadows().size(); i--; ) { | |
403 const ShadowData& shadow = shadowList->shadows()[i]; | |
404 float shadowX = horizontal ? shadow.x() : shadow.y(); | |
405 float shadowY = horizontal ? shadow.y() : -shadow.x(); | |
406 FloatSize offset(shadowX, shadowY); | |
407 drawLooperBuilder->addShadow(offset, shadow.blur(), shadow.color(), | |
408 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder:: ShadowIgnoresAlpha); | |
409 } | |
410 drawLooperBuilder->addUnmodifiedContent(); | |
411 context->setDrawLooper(drawLooperBuilder.release()); | |
412 } | |
413 | 400 |
414 TextRunPaintInfo textRunPaintInfo(textRun); | 401 TextRunPaintInfo textRunPaintInfo(textRun); |
415 textRunPaintInfo.bounds = boxRect; | 402 textRunPaintInfo.bounds = boxRect; |
416 if (startOffset <= endOffset) { | 403 if (startOffset <= endOffset) { |
417 textRunPaintInfo.from = startOffset; | 404 textRunPaintInfo.from = startOffset; |
418 textRunPaintInfo.to = endOffset; | 405 textRunPaintInfo.to = endOffset; |
419 if (emphasisMark.isEmpty()) | 406 if (emphasisMark.isEmpty()) |
420 context->drawText(font, textRunPaintInfo, textOrigin); | 407 context->drawText(font, textRunPaintInfo, textOrigin); |
421 else | 408 else |
422 context->drawEmphasisMarks(font, textRunPaintInfo, emphasisMark, tex tOrigin + IntSize(0, emphasisMarkOffset)); | 409 context->drawEmphasisMarks(font, textRunPaintInfo, emphasisMark, tex tOrigin + IntSize(0, emphasisMarkOffset)); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 emphasisMarkOffset = emphasisMarkPosition == TextEmphasisPositionOver ? -font.fontMetrics().ascent() - font.emphasisMarkDescent(emphasisMark) : font.fon tMetrics().descent() + font.emphasisMarkAscent(emphasisMark); | 675 emphasisMarkOffset = emphasisMarkPosition == TextEmphasisPositionOver ? -font.fontMetrics().ascent() - font.emphasisMarkDescent(emphasisMark) : font.fon tMetrics().descent() + font.emphasisMarkAscent(emphasisMark); |
689 | 676 |
690 if (!paintSelectedTextOnly) { | 677 if (!paintSelectedTextOnly) { |
691 // For stroked painting, we have to change the text drawing mode. It's probably dangerous to leave that mutated as a side | 678 // For stroked painting, we have to change the text drawing mode. It's probably dangerous to leave that mutated as a side |
692 // effect, so only when we know we're stroking, do a save/restore. | 679 // effect, so only when we know we're stroking, do a save/restore. |
693 GraphicsContextStateSaver stateSaver(*context, textStrokeWidth > 0); | 680 GraphicsContextStateSaver stateSaver(*context, textStrokeWidth > 0); |
694 | 681 |
695 updateGraphicsContext(context, textFillColor, textStrokeColor, textStrok eWidth); | 682 updateGraphicsContext(context, textFillColor, textStrokeColor, textStrok eWidth); |
696 if (!paintSelectedTextSeparately || ePos <= sPos) { | 683 if (!paintSelectedTextSeparately || ePos <= sPos) { |
697 // FIXME: Truncate right-to-left text correctly. | 684 // FIXME: Truncate right-to-left text correctly. |
698 paintTextWithShadows(context, rendererToUse, font, textRun, nullAtom , 0, 0, length, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, is Horizontal()); | 685 paintTextWithShadows(context, font, textRun, nullAtom, 0, 0, length, length, textOrigin, boxRect, textShadow, isHorizontal()); |
f(malita)
2014/06/27 14:29:47
Since we're at it, I find "rendererToUse" somewhat
jbroman
2014/06/27 15:07:00
Fair enough (for history, this variable dates back
| |
699 } else { | 686 } else { |
700 paintTextWithShadows(context, rendererToUse, font, textRun, nullAtom , 0, ePos, sPos, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, i sHorizontal()); | 687 paintTextWithShadows(context, font, textRun, nullAtom, 0, ePos, sPos , length, textOrigin, boxRect, textShadow, isHorizontal()); |
701 } | 688 } |
702 | 689 |
703 if (!emphasisMark.isEmpty()) { | 690 if (!emphasisMark.isEmpty()) { |
704 updateGraphicsContext(context, emphasisMarkColor, textStrokeColor, t extStrokeWidth); | 691 updateGraphicsContext(context, emphasisMarkColor, textStrokeColor, t extStrokeWidth); |
705 | 692 |
706 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&ob jectReplacementCharacter, 1)); | 693 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&ob jectReplacementCharacter, 1)); |
707 TextRun& emphasisMarkTextRun = combinedText ? objectReplacementChara cterTextRun : textRun; | 694 TextRun& emphasisMarkTextRun = combinedText ? objectReplacementChara cterTextRun : textRun; |
708 FloatPoint emphasisMarkTextOrigin = combinedText ? FloatPoint(boxOri gin.x() + boxRect.width() / 2, boxOrigin.y() + font.fontMetrics().ascent()) : te xtOrigin; | 695 FloatPoint emphasisMarkTextOrigin = combinedText ? FloatPoint(boxOri gin.x() + boxRect.width() / 2, boxOrigin.y() + font.fontMetrics().ascent()) : te xtOrigin; |
709 if (combinedText) | 696 if (combinedText) |
710 context->concatCTM(rotation(boxRect, Clockwise)); | 697 context->concatCTM(rotation(boxRect, Clockwise)); |
711 | 698 |
712 int startOffset = 0; | 699 int startOffset = 0; |
713 int endOffset = length; | 700 int endOffset = length; |
714 int paintRunLength = length; | 701 int paintRunLength = length; |
715 if (combinedText) { | 702 if (combinedText) { |
716 startOffset = 0; | 703 startOffset = 0; |
717 endOffset = objectReplacementCharacterTextRun.length(); | 704 endOffset = objectReplacementCharacterTextRun.length(); |
718 paintRunLength = endOffset; | 705 paintRunLength = endOffset; |
719 } else if (paintSelectedTextSeparately && ePos > sPos) { | 706 } else if (paintSelectedTextSeparately && ePos > sPos) { |
720 startOffset = ePos; | 707 startOffset = ePos; |
721 endOffset = sPos; | 708 endOffset = sPos; |
722 } | 709 } |
723 // FIXME: Truncate right-to-left text correctly. | 710 // FIXME: Truncate right-to-left text correctly. |
724 paintTextWithShadows(context, rendererToUse, combinedText ? combined Text->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffs et, startOffset, endOffset, paintRunLength, emphasisMarkTextOrigin, boxRect, tex tShadow, textStrokeWidth > 0, isHorizontal()); | 711 paintTextWithShadows(context, combinedText ? combinedText->originalF ont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, startOffset , endOffset, paintRunLength, emphasisMarkTextOrigin, boxRect, textShadow, isHori zontal()); |
725 | 712 |
726 if (combinedText) | 713 if (combinedText) |
727 context->concatCTM(rotation(boxRect, Counterclockwise)); | 714 context->concatCTM(rotation(boxRect, Counterclockwise)); |
728 } | 715 } |
729 } | 716 } |
730 | 717 |
731 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && sPos < ePos) { | 718 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && sPos < ePos) { |
732 // paint only the text that is selected | 719 // paint only the text that is selected |
733 GraphicsContextStateSaver stateSaver(*context, selectionStrokeWidth > 0) ; | 720 GraphicsContextStateSaver stateSaver(*context, selectionStrokeWidth > 0) ; |
734 | 721 |
735 updateGraphicsContext(context, selectionFillColor, selectionStrokeColor, selectionStrokeWidth); | 722 updateGraphicsContext(context, selectionFillColor, selectionStrokeColor, selectionStrokeWidth); |
736 paintTextWithShadows(context, rendererToUse, font, textRun, nullAtom, 0, sPos, ePos, length, textOrigin, boxRect, selectionShadow, selectionStrokeWidth > 0, isHorizontal()); | 723 paintTextWithShadows(context, font, textRun, nullAtom, 0, sPos, ePos, le ngth, textOrigin, boxRect, selectionShadow, isHorizontal()); |
737 if (!emphasisMark.isEmpty()) { | 724 if (!emphasisMark.isEmpty()) { |
738 updateGraphicsContext(context, selectionEmphasisMarkColor, textStrok eColor, textStrokeWidth); | 725 updateGraphicsContext(context, selectionEmphasisMarkColor, textStrok eColor, textStrokeWidth); |
739 | 726 |
740 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&ob jectReplacementCharacter, 1)); | 727 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&ob jectReplacementCharacter, 1)); |
741 TextRun& emphasisMarkTextRun = combinedText ? objectReplacementChara cterTextRun : textRun; | 728 TextRun& emphasisMarkTextRun = combinedText ? objectReplacementChara cterTextRun : textRun; |
742 FloatPoint emphasisMarkTextOrigin = combinedText ? FloatPoint(boxOri gin.x() + boxRect.width() / 2, boxOrigin.y() + font.fontMetrics().ascent()) : te xtOrigin; | 729 FloatPoint emphasisMarkTextOrigin = combinedText ? FloatPoint(boxOri gin.x() + boxRect.width() / 2, boxOrigin.y() + font.fontMetrics().ascent()) : te xtOrigin; |
743 if (combinedText) | 730 if (combinedText) |
744 context->concatCTM(rotation(boxRect, Clockwise)); | 731 context->concatCTM(rotation(boxRect, Clockwise)); |
745 | 732 |
746 int startOffset = combinedText ? 0 : sPos; | 733 int startOffset = combinedText ? 0 : sPos; |
747 int endOffset = combinedText ? objectReplacementCharacterTextRun.len gth() : ePos; | 734 int endOffset = combinedText ? objectReplacementCharacterTextRun.len gth() : ePos; |
748 int paintRunLength = combinedText ? endOffset : length; | 735 int paintRunLength = combinedText ? endOffset : length; |
749 paintTextWithShadows(context, rendererToUse, combinedText ? combined Text->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffs et, startOffset, endOffset, paintRunLength, emphasisMarkTextOrigin, boxRect, sel ectionShadow, selectionStrokeWidth > 0, isHorizontal()); | 736 paintTextWithShadows(context, combinedText ? combinedText->originalF ont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, startOffset , endOffset, paintRunLength, emphasisMarkTextOrigin, boxRect, selectionShadow, i sHorizontal()); |
750 | 737 |
751 if (combinedText) | 738 if (combinedText) |
752 context->concatCTM(rotation(boxRect, Counterclockwise)); | 739 context->concatCTM(rotation(boxRect, Counterclockwise)); |
753 } | 740 } |
754 } | 741 } |
755 | 742 |
756 // Paint decorations | 743 // Paint decorations |
757 TextDecoration textDecorations = styleToUse->textDecorationsInEffect(); | 744 TextDecoration textDecorations = styleToUse->textDecorationsInEffect(); |
758 if (textDecorations != TextDecorationNone && paintInfo.phase != PaintPhaseSe lection) { | 745 if (textDecorations != TextDecorationNone && paintInfo.phase != PaintPhaseSe lection) { |
759 updateGraphicsContext(context, textFillColor, textStrokeColor, textStrok eWidth); | 746 updateGraphicsContext(context, textFillColor, textStrokeColor, textStrok eWidth); |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1581 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); | 1568 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); |
1582 const int rendererCharacterOffset = 24; | 1569 const int rendererCharacterOffset = 24; |
1583 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) | 1570 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) |
1584 fputc(' ', stderr); | 1571 fputc(' ', stderr); |
1585 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); | 1572 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); |
1586 } | 1573 } |
1587 | 1574 |
1588 #endif | 1575 #endif |
1589 | 1576 |
1590 } // namespace WebCore | 1577 } // namespace WebCore |
OLD | NEW |