Changeset 157015 in webkit
- Timestamp:
- Oct 6, 2013 7:17:02 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r156991 r157015 2157 2157 rendering/ScrollBehavior.cpp 2158 2158 rendering/TextAutosizer.cpp 2159 rendering/TextPaintStyle.cpp 2159 2160 rendering/break_lines.cpp 2160 2161 -
trunk/Source/WebCore/ChangeLog
r157013 r157015 1 2013-10-06 Antti Koivisto <antti@apple.com> 2 3 Factor text paint style computation out from InlineTextBox 4 https://bugs.webkit.org/show_bug.cgi?id=122433 5 6 Reviewed by Andreas Kling. 7 8 Move it to TextPaintStyle.h/cpp. Other parts of the code may use it in the future. 9 1 10 2013-10-06 Darin Adler <darin@apple.com> 2 11 -
trunk/Source/WebCore/GNUmakefile.list.am
r156991 r157015 4437 4437 Source/WebCore/rendering/TextAutosizer.cpp \ 4438 4438 Source/WebCore/rendering/TextAutosizer.h \ 4439 Source/WebCore/rendering/TextPaintStyle.cpp \ 4440 Source/WebCore/rendering/TextPaintStyle.h \ 4439 4441 Source/WebCore/rendering/VerticalPositionCache.h \ 4440 4442 Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp \ -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
r156991 r157015 10802 10802 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild> 10803 10803 </ClCompile> 10804 <ClCompile Include="..\rendering\TextPaintStyle.cpp" /> 10804 10805 <ClCompile Include="..\rendering\shapes\PolygonShape.cpp" /> 10805 10806 <ClCompile Include="..\rendering\shapes\RasterShape.cpp" /> … … 19576 19577 <ClInclude Include="..\rendering\svg\SVGResourcesCycleSolver.h" /> 19577 19578 <ClInclude Include="..\rendering\TableLayout.h" /> 19579 <ClInclude Include="..\rendering\TextPaintStyle.h" /> 19578 19580 <ClInclude Include="..\rendering\TrailingFloatsRootInlineBox.h" /> 19579 19581 <ClInclude Include="..\rendering\mathml\RenderMathMLBlock.h" /> -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r157002 r157015 5645 5645 E4C279580CF9741900E97B98 /* RenderMedia.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C279560CF9741900E97B98 /* RenderMedia.cpp */; }; 5646 5646 E4C279590CF9741900E97B98 /* RenderMedia.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C279570CF9741900E97B98 /* RenderMedia.h */; }; 5647 E4C91A0E1802343100A17F6D /* TextPaintStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C91A0D1802343100A17F6D /* TextPaintStyle.h */; }; 5648 E4C91A101802343900A17F6D /* TextPaintStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C91A0F1802343900A17F6D /* TextPaintStyle.cpp */; }; 5647 5649 E4D58EB417B4DBDC00CBDCA8 /* StyleResolveForDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4D58EB217B4DBDC00CBDCA8 /* StyleResolveForDocument.cpp */; }; 5648 5650 E4D58EB517B4DBDC00CBDCA8 /* StyleResolveForDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = E4D58EB317B4DBDC00CBDCA8 /* StyleResolveForDocument.h */; }; … … 12582 12584 E4C279560CF9741900E97B98 /* RenderMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderMedia.cpp; sourceTree = "<group>"; }; 12583 12585 E4C279570CF9741900E97B98 /* RenderMedia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMedia.h; sourceTree = "<group>"; }; 12586 E4C91A0D1802343100A17F6D /* TextPaintStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextPaintStyle.h; sourceTree = "<group>"; }; 12587 E4C91A0F1802343900A17F6D /* TextPaintStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextPaintStyle.cpp; sourceTree = "<group>"; }; 12584 12588 E4D58EB217B4DBDC00CBDCA8 /* StyleResolveForDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleResolveForDocument.cpp; sourceTree = "<group>"; }; 12585 12589 E4D58EB317B4DBDC00CBDCA8 /* StyleResolveForDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleResolveForDocument.h; sourceTree = "<group>"; }; … … 20554 20558 5D925B660F64D4DD00B847F0 /* ScrollBehavior.h */, 20555 20559 A8CFF04C0A154F09000A4234 /* TableLayout.h */, 20560 E4C91A0F1802343900A17F6D /* TextPaintStyle.cpp */, 20561 E4C91A0D1802343100A17F6D /* TextPaintStyle.h */, 20556 20562 37FC96DA1104ED71003E1FAD /* TrailingFloatsRootInlineBox.h */, 20557 20563 BCA257141293C010007A263D /* VerticalPositionCache.h */, … … 24278 24284 BE88E0DF1715D2A200658D98 /* VideoTrack.h in Headers */, 24279 24285 BE88E0E21715D2A200658D98 /* VideoTrackList.h in Headers */, 24286 E4C91A0E1802343100A17F6D /* TextPaintStyle.h in Headers */, 24280 24287 BEF29EEC1715DD0900C4B4C9 /* VideoTrackPrivate.h in Headers */, 24281 24288 CEF418CF1179678C009D112C /* ViewportArguments.h in Headers */, … … 25562 25569 07969DAD17D14151007FF842 /* JSRTCDataChannelEvent.cpp in Sources */, 25563 25570 65A21484097A3F5300B9050A /* FrameTree.cpp in Sources */, 25571 E4C91A101802343900A17F6D /* TextPaintStyle.cpp in Sources */, 25564 25572 65CBFEF90974F607001DAC25 /* FrameView.cpp in Sources */, 25565 25573 97205AAF123928CA00B17380 /* FTPDirectoryDocument.cpp in Sources */, -
trunk/Source/WebCore/rendering/InlineTextBox.cpp
r157011 r157015 48 48 #include "SVGTextRunRenderingContext.h" 49 49 #include "Text.h" 50 #include "TextPaintStyle.h" 50 51 #include "break_lines.h" 51 52 #include <wtf/text/CString.h> … … 331 332 } 332 333 333 Color correctedTextColor(Color textColor, Color backgroundColor) 334 { 335 // Adjust the text color if it is too close to the background color, 336 // by darkening or lightening it to move it further away. 337 338 int d = differenceSquared(textColor, backgroundColor); 339 // semi-arbitrarily chose 65025 (255^2) value here after a few tests; 340 if (d > 65025) { 341 return textColor; 342 } 343 344 int distanceFromWhite = differenceSquared(textColor, Color::white); 345 int distanceFromBlack = differenceSquared(textColor, Color::black); 346 347 if (distanceFromWhite < distanceFromBlack) { 348 return textColor.dark(); 349 } 350 351 return textColor.light(); 352 } 353 354 void updateGraphicsContext(GraphicsContext* context, const Color& fillColor, const Color& strokeColor, float strokeThickness, ColorSpace colorSpace) 355 { 356 TextDrawingModeFlags mode = context->textDrawingMode(); 357 if (strokeThickness > 0) { 358 TextDrawingModeFlags newMode = mode | TextModeStroke; 359 if (mode != newMode) { 360 context->setTextDrawingMode(newMode); 361 mode = newMode; 362 } 363 } 364 365 if (mode & TextModeFill && (fillColor != context->fillColor() || colorSpace != context->fillColorSpace())) 366 context->setFillColor(fillColor, colorSpace); 367 368 if (mode & TextModeStroke) { 369 if (strokeColor != context->strokeColor()) 370 context->setStrokeColor(strokeColor, colorSpace); 371 if (strokeThickness != context->strokeThickness()) 372 context->setStrokeThickness(strokeThickness); 373 } 374 } 334 375 335 376 336 bool InlineTextBox::isLineBreak() const … … 584 544 585 545 // Determine the text colors and selection colors. 586 Color textFillColor; 587 Color textStrokeColor; 588 Color emphasisMarkColor; 589 float textStrokeWidth = lineStyle.textStrokeWidth(); 590 const ShadowData* textShadow = paintInfo.forceBlackText() ? 0 : lineStyle.textShadow(); 591 592 if (paintInfo.forceBlackText()) { 593 textFillColor = Color::black; 594 textStrokeColor = Color::black; 595 emphasisMarkColor = Color::black; 596 } else { 597 textFillColor = lineStyle.visitedDependentColor(CSSPropertyWebkitTextFillColor); 598 599 bool forceBackgroundToWhite = false; 600 if (isPrinting) { 601 if (lineStyle.printColorAdjust() == PrintColorAdjustEconomy) 602 forceBackgroundToWhite = true; 603 if (renderer().frame().settings().shouldPrintBackgrounds()) 604 forceBackgroundToWhite = false; 605 } 606 607 // Make the text fill color legible against a white background 608 if (forceBackgroundToWhite) 609 textFillColor = correctedTextColor(textFillColor, Color::white); 610 611 textStrokeColor = lineStyle.visitedDependentColor(CSSPropertyWebkitTextStrokeColor); 612 613 // Make the text stroke color legible against a white background 614 if (forceBackgroundToWhite) 615 textStrokeColor = correctedTextColor(textStrokeColor, Color::white); 616 617 emphasisMarkColor = lineStyle.visitedDependentColor(CSSPropertyWebkitTextEmphasisColor); 618 619 // Make the text stroke color legible against a white background 620 if (forceBackgroundToWhite) 621 emphasisMarkColor = correctedTextColor(emphasisMarkColor, Color::white); 622 } 623 624 bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection); 625 bool paintSelectedTextSeparately = false; 626 627 Color selectionFillColor = textFillColor; 628 Color selectionStrokeColor = textStrokeColor; 629 Color selectionEmphasisMarkColor = emphasisMarkColor; 630 float selectionStrokeWidth = textStrokeWidth; 631 const ShadowData* selectionShadow = textShadow; 632 if (haveSelection) { 633 // Check foreground color first. 634 Color foreground = paintInfo.forceBlackText() ? Color::black : renderer().selectionForegroundColor(); 635 if (foreground.isValid() && foreground != selectionFillColor) { 636 if (!paintSelectedTextOnly) 637 paintSelectedTextSeparately = true; 638 selectionFillColor = foreground; 639 } 640 641 Color emphasisMarkForeground = paintInfo.forceBlackText() ? Color::black : renderer().selectionEmphasisMarkColor(); 642 if (emphasisMarkForeground.isValid() && emphasisMarkForeground != selectionEmphasisMarkColor) { 643 if (!paintSelectedTextOnly) 644 paintSelectedTextSeparately = true; 645 selectionEmphasisMarkColor = emphasisMarkForeground; 646 } 647 648 if (RenderStyle* pseudoStyle = renderer().getCachedPseudoStyle(SELECTION)) { 649 const ShadowData* shadow = paintInfo.forceBlackText() ? 0 : pseudoStyle->textShadow(); 650 if (shadow != selectionShadow) { 651 if (!paintSelectedTextOnly) 652 paintSelectedTextSeparately = true; 653 selectionShadow = shadow; 654 } 655 656 float strokeWidth = pseudoStyle->textStrokeWidth(); 657 if (strokeWidth != selectionStrokeWidth) { 658 if (!paintSelectedTextOnly) 659 paintSelectedTextSeparately = true; 660 selectionStrokeWidth = strokeWidth; 661 } 662 663 Color stroke = paintInfo.forceBlackText() ? Color::black : pseudoStyle->visitedDependentColor(CSSPropertyWebkitTextStrokeColor); 664 if (stroke != selectionStrokeColor) { 665 if (!paintSelectedTextOnly) 666 paintSelectedTextSeparately = true; 667 selectionStrokeColor = stroke; 668 } 669 } 670 } 546 TextPaintStyle textPaintStyle = computeTextPaintStyle(renderer(), lineStyle, paintInfo); 547 548 bool paintSelectedTextOnly; 549 bool paintSelectedTextSeparately; 550 const ShadowData* selectionShadow; 551 TextPaintStyle selectionPaintStyle = computeTextSelectionPaintStyle(textPaintStyle, renderer(), lineStyle, paintInfo, paintSelectedTextOnly, paintSelectedTextSeparately, selectionShadow); 671 552 672 553 // Set our font. … … 695 576 696 577 if (haveSelection && !useCustomUnderlines) 697 paintSelection(context, boxOrigin, lineStyle, font, selection FillColor);578 paintSelection(context, boxOrigin, lineStyle, font, selectionPaintStyle.fillColor); 698 579 } 699 580 … … 746 627 emphasisMarkOffset = emphasisMarkPosition == TextEmphasisPositionOver ? -font.fontMetrics().ascent() - font.emphasisMarkDescent(emphasisMark) : font.fontMetrics().descent() + font.emphasisMarkAscent(emphasisMark); 747 628 629 const ShadowData* textShadow = paintInfo.forceBlackText() ? 0 : lineStyle.textShadow(); 630 748 631 if (!paintSelectedTextOnly) { 749 632 // For stroked painting, we have to change the text drawing mode. It's probably dangerous to leave that mutated as a side 750 633 // effect, so only when we know we're stroking, do a save/restore. 751 GraphicsContextStateSaver stateSaver(*context, text StrokeWidth > 0);752 753 updateGraphicsContext( context, textFillColor, textStrokeColor, textStrokeWidth, lineStyle.colorSpace());634 GraphicsContextStateSaver stateSaver(*context, textPaintStyle.strokeWidth > 0); 635 636 updateGraphicsContext(*context, textPaintStyle); 754 637 if (!paintSelectedTextSeparately || ePos <= sPos) { 755 638 // FIXME: Truncate right-to-left text correctly. 756 paintTextWithShadows(context, font, textRun, nullAtom, 0, 0, length, length, textOrigin, boxRect, textShadow, text StrokeWidth > 0, isHorizontal());639 paintTextWithShadows(context, font, textRun, nullAtom, 0, 0, length, length, textOrigin, boxRect, textShadow, textPaintStyle.strokeWidth > 0, isHorizontal()); 757 640 } else 758 paintTextWithShadows(context, font, textRun, nullAtom, 0, ePos, sPos, length, textOrigin, boxRect, textShadow, text StrokeWidth > 0, isHorizontal());641 paintTextWithShadows(context, font, textRun, nullAtom, 0, ePos, sPos, length, textOrigin, boxRect, textShadow, textPaintStyle.strokeWidth > 0, isHorizontal()); 759 642 760 643 if (!emphasisMark.isEmpty()) { 761 updateGraphicsContext( context, emphasisMarkColor, textStrokeColor, textStrokeWidth, lineStyle.colorSpace());644 updateGraphicsContext(*context, textPaintStyle, UseEmphasisMarkColor); 762 645 763 646 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1)); … … 769 652 if (!paintSelectedTextSeparately || ePos <= sPos) { 770 653 // FIXME: Truncate right-to-left text correctly. 771 paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, 0, length, length, emphasisMarkTextOrigin, boxRect, textShadow, text StrokeWidth > 0, isHorizontal());654 paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, 0, length, length, emphasisMarkTextOrigin, boxRect, textShadow, textPaintStyle.strokeWidth > 0, isHorizontal()); 772 655 } else 773 paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, ePos, sPos, length, emphasisMarkTextOrigin, boxRect, textShadow, text StrokeWidth > 0, isHorizontal());656 paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, ePos, sPos, length, emphasisMarkTextOrigin, boxRect, textShadow, textPaintStyle.strokeWidth > 0, isHorizontal()); 774 657 775 658 if (combinedText) … … 780 663 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && sPos < ePos) { 781 664 // paint only the text that is selected 782 GraphicsContextStateSaver stateSaver(*context, selection StrokeWidth > 0);783 784 updateGraphicsContext( context, selectionFillColor, selectionStrokeColor, selectionStrokeWidth, lineStyle.colorSpace());785 paintTextWithShadows(context, font, textRun, nullAtom, 0, sPos, ePos, length, textOrigin, boxRect, selectionShadow, selection StrokeWidth > 0, isHorizontal());665 GraphicsContextStateSaver stateSaver(*context, selectionPaintStyle.strokeWidth > 0); 666 667 updateGraphicsContext(*context, selectionPaintStyle); 668 paintTextWithShadows(context, font, textRun, nullAtom, 0, sPos, ePos, length, textOrigin, boxRect, selectionShadow, selectionPaintStyle.strokeWidth > 0, isHorizontal()); 786 669 if (!emphasisMark.isEmpty()) { 787 updateGraphicsContext( context, selectionEmphasisMarkColor, textStrokeColor, textStrokeWidth, lineStyle.colorSpace());670 updateGraphicsContext(*context, selectionPaintStyle, UseEmphasisMarkColor); 788 671 789 672 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1)); … … 793 676 context->concatCTM(rotation(boxRect, Clockwise)); 794 677 795 paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, sPos, ePos, length, emphasisMarkTextOrigin, boxRect, selectionShadow, selection StrokeWidth > 0, isHorizontal());678 paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, sPos, ePos, length, emphasisMarkTextOrigin, boxRect, selectionShadow, selectionPaintStyle.strokeWidth > 0, isHorizontal()); 796 679 797 680 if (combinedText) … … 803 686 TextDecoration textDecorations = lineStyle.textDecorationsInEffect(); 804 687 if (textDecorations != TextDecorationNone && paintInfo.phase != PaintPhaseSelection) { 805 updateGraphicsContext( context, textFillColor, textStrokeColor, textStrokeWidth, lineStyle.colorSpace());688 updateGraphicsContext(*context, textPaintStyle); 806 689 if (combinedText) 807 690 context->concatCTM(rotation(boxRect, Clockwise)); … … 890 773 891 774 GraphicsContextStateSaver stateSaver(*context); 892 updateGraphicsContext( context, c, c, 0, style.colorSpace()); // Don't draw text at all!775 updateGraphicsContext(*context, TextPaintStyle(c, style.colorSpace())); // Don't draw text at all! 893 776 894 777 // If the text is truncated, let the thing being painted in the truncation … … 937 820 Color c = Color(225, 221, 85); 938 821 939 updateGraphicsContext( context, c, c, 0, style.colorSpace()); // Don't draw text at all!822 updateGraphicsContext(*context, TextPaintStyle(c, style.colorSpace())); // Don't draw text at all! 940 823 941 824 int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop(); … … 1392 1275 renderer().theme()->platformInactiveTextSearchHighlightColor(); 1393 1276 GraphicsContextStateSaver stateSaver(*pt); 1394 updateGraphicsContext( pt, color, color, 0, style.colorSpace()); // Don't draw text at all!1277 updateGraphicsContext(*pt, TextPaintStyle(color, style.colorSpace())); // Don't draw text at all! 1395 1278 pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_logicalWidth, selHeight)); 1396 1279 pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.y() - deltaY), selHeight, color, style.colorSpace(), sPos, ePos); -
trunk/Source/WebCore/rendering/InlineTextBox.h
r156613 r157015 41 41 BufferForAppendingHyphen() { reserveCapacity(256); } 42 42 }; 43 44 // Helper functions shared by InlineTextBox / SVGRootInlineBox45 void updateGraphicsContext(GraphicsContext*, const Color& fillColor, const Color& strokeColor, float strokeThickness, ColorSpace);46 Color correctedTextColor(Color textColor, Color backgroundColor);47 43 48 44 class InlineTextBox : public InlineBox {
Note: See TracChangeset
for help on using the changeset viewer.