Changeset 157015 in webkit


Ignore:
Timestamp:
Oct 6, 2013 7:17:02 PM (11 years ago)
Author:
Antti Koivisto
Message:

Factor text paint style computation out from InlineTextBox
https://bugs.webkit.org/show_bug.cgi?id=122433

Reviewed by Andreas Kling.

Move it to TextPaintStyle.h/cpp. Other parts of the code may use it in the future.

Location:
trunk/Source/WebCore
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r156991 r157015  
    21572157    rendering/ScrollBehavior.cpp
    21582158    rendering/TextAutosizer.cpp
     2159    rendering/TextPaintStyle.cpp
    21592160    rendering/break_lines.cpp
    21602161
  • trunk/Source/WebCore/ChangeLog

    r157013 r157015  
     12013-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
    1102013-10-06  Darin Adler  <darin@apple.com>
    211
  • trunk/Source/WebCore/GNUmakefile.list.am

    r156991 r157015  
    44374437        Source/WebCore/rendering/TextAutosizer.cpp \
    44384438        Source/WebCore/rendering/TextAutosizer.h \
     4439        Source/WebCore/rendering/TextPaintStyle.cpp \
     4440        Source/WebCore/rendering/TextPaintStyle.h \
    44394441        Source/WebCore/rendering/VerticalPositionCache.h \
    44404442        Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp \
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r156991 r157015  
    1080210802      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
    1080310803    </ClCompile>
     10804    <ClCompile Include="..\rendering\TextPaintStyle.cpp" />
    1080410805    <ClCompile Include="..\rendering\shapes\PolygonShape.cpp" />
    1080510806    <ClCompile Include="..\rendering\shapes\RasterShape.cpp" />
     
    1957619577    <ClInclude Include="..\rendering\svg\SVGResourcesCycleSolver.h" />
    1957719578    <ClInclude Include="..\rendering\TableLayout.h" />
     19579    <ClInclude Include="..\rendering\TextPaintStyle.h" />
    1957819580    <ClInclude Include="..\rendering\TrailingFloatsRootInlineBox.h" />
    1957919581    <ClInclude Include="..\rendering\mathml\RenderMathMLBlock.h" />
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r157002 r157015  
    56455645                E4C279580CF9741900E97B98 /* RenderMedia.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C279560CF9741900E97B98 /* RenderMedia.cpp */; };
    56465646                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 */; };
    56475649                E4D58EB417B4DBDC00CBDCA8 /* StyleResolveForDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4D58EB217B4DBDC00CBDCA8 /* StyleResolveForDocument.cpp */; };
    56485650                E4D58EB517B4DBDC00CBDCA8 /* StyleResolveForDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = E4D58EB317B4DBDC00CBDCA8 /* StyleResolveForDocument.h */; };
     
    1258212584                E4C279560CF9741900E97B98 /* RenderMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderMedia.cpp; sourceTree = "<group>"; };
    1258312585                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>"; };
    1258412588                E4D58EB217B4DBDC00CBDCA8 /* StyleResolveForDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleResolveForDocument.cpp; sourceTree = "<group>"; };
    1258512589                E4D58EB317B4DBDC00CBDCA8 /* StyleResolveForDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleResolveForDocument.h; sourceTree = "<group>"; };
     
    2055420558                                5D925B660F64D4DD00B847F0 /* ScrollBehavior.h */,
    2055520559                                A8CFF04C0A154F09000A4234 /* TableLayout.h */,
     20560                                E4C91A0F1802343900A17F6D /* TextPaintStyle.cpp */,
     20561                                E4C91A0D1802343100A17F6D /* TextPaintStyle.h */,
    2055620562                                37FC96DA1104ED71003E1FAD /* TrailingFloatsRootInlineBox.h */,
    2055720563                                BCA257141293C010007A263D /* VerticalPositionCache.h */,
     
    2427824284                                BE88E0DF1715D2A200658D98 /* VideoTrack.h in Headers */,
    2427924285                                BE88E0E21715D2A200658D98 /* VideoTrackList.h in Headers */,
     24286                                E4C91A0E1802343100A17F6D /* TextPaintStyle.h in Headers */,
    2428024287                                BEF29EEC1715DD0900C4B4C9 /* VideoTrackPrivate.h in Headers */,
    2428124288                                CEF418CF1179678C009D112C /* ViewportArguments.h in Headers */,
     
    2556225569                                07969DAD17D14151007FF842 /* JSRTCDataChannelEvent.cpp in Sources */,
    2556325570                                65A21484097A3F5300B9050A /* FrameTree.cpp in Sources */,
     25571                                E4C91A101802343900A17F6D /* TextPaintStyle.cpp in Sources */,
    2556425572                                65CBFEF90974F607001DAC25 /* FrameView.cpp in Sources */,
    2556525573                                97205AAF123928CA00B17380 /* FTPDirectoryDocument.cpp in Sources */,
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r157011 r157015  
    4848#include "SVGTextRunRenderingContext.h"
    4949#include "Text.h"
     50#include "TextPaintStyle.h"
    5051#include "break_lines.h"
    5152#include <wtf/text/CString.h>
     
    331332}
    332333
    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
    375335
    376336bool InlineTextBox::isLineBreak() const
     
    584544
    585545    // 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);
    671552
    672553    // Set our font.
     
    695576
    696577        if (haveSelection && !useCustomUnderlines)
    697             paintSelection(context, boxOrigin, lineStyle, font, selectionFillColor);
     578            paintSelection(context, boxOrigin, lineStyle, font, selectionPaintStyle.fillColor);
    698579    }
    699580
     
    746627        emphasisMarkOffset = emphasisMarkPosition == TextEmphasisPositionOver ? -font.fontMetrics().ascent() - font.emphasisMarkDescent(emphasisMark) : font.fontMetrics().descent() + font.emphasisMarkAscent(emphasisMark);
    747628
     629    const ShadowData* textShadow = paintInfo.forceBlackText() ? 0 : lineStyle.textShadow();
     630
    748631    if (!paintSelectedTextOnly) {
    749632        // For stroked painting, we have to change the text drawing mode.  It's probably dangerous to leave that mutated as a side
    750633        // effect, so only when we know we're stroking, do a save/restore.
    751         GraphicsContextStateSaver stateSaver(*context, textStrokeWidth > 0);
    752 
    753         updateGraphicsContext(context, textFillColor, textStrokeColor, textStrokeWidth, lineStyle.colorSpace());
     634        GraphicsContextStateSaver stateSaver(*context, textPaintStyle.strokeWidth > 0);
     635
     636        updateGraphicsContext(*context, textPaintStyle);
    754637        if (!paintSelectedTextSeparately || ePos <= sPos) {
    755638            // FIXME: Truncate right-to-left text correctly.
    756             paintTextWithShadows(context, font, textRun, nullAtom, 0, 0, length, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
     639            paintTextWithShadows(context, font, textRun, nullAtom, 0, 0, length, length, textOrigin, boxRect, textShadow, textPaintStyle.strokeWidth > 0, isHorizontal());
    757640        } else
    758             paintTextWithShadows(context, font, textRun, nullAtom, 0, ePos, sPos, length, textOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
     641            paintTextWithShadows(context, font, textRun, nullAtom, 0, ePos, sPos, length, textOrigin, boxRect, textShadow, textPaintStyle.strokeWidth > 0, isHorizontal());
    759642
    760643        if (!emphasisMark.isEmpty()) {
    761             updateGraphicsContext(context, emphasisMarkColor, textStrokeColor, textStrokeWidth, lineStyle.colorSpace());
     644            updateGraphicsContext(*context, textPaintStyle, UseEmphasisMarkColor);
    762645
    763646            DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1));
     
    769652            if (!paintSelectedTextSeparately || ePos <= sPos) {
    770653                // FIXME: Truncate right-to-left text correctly.
    771                 paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, 0, length, length, emphasisMarkTextOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
     654                paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, 0, length, length, emphasisMarkTextOrigin, boxRect, textShadow, textPaintStyle.strokeWidth > 0, isHorizontal());
    772655            } else
    773                 paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, ePos, sPos, length, emphasisMarkTextOrigin, boxRect, textShadow, textStrokeWidth > 0, isHorizontal());
     656                paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, ePos, sPos, length, emphasisMarkTextOrigin, boxRect, textShadow, textPaintStyle.strokeWidth > 0, isHorizontal());
    774657
    775658            if (combinedText)
     
    780663    if ((paintSelectedTextOnly || paintSelectedTextSeparately) && sPos < ePos) {
    781664        // paint only the text that is selected
    782         GraphicsContextStateSaver stateSaver(*context, selectionStrokeWidth > 0);
    783 
    784         updateGraphicsContext(context, selectionFillColor, selectionStrokeColor, selectionStrokeWidth, lineStyle.colorSpace());
    785         paintTextWithShadows(context, font, textRun, nullAtom, 0, sPos, ePos, length, textOrigin, boxRect, selectionShadow, selectionStrokeWidth > 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());
    786669        if (!emphasisMark.isEmpty()) {
    787             updateGraphicsContext(context, selectionEmphasisMarkColor, textStrokeColor, textStrokeWidth, lineStyle.colorSpace());
     670            updateGraphicsContext(*context, selectionPaintStyle, UseEmphasisMarkColor);
    788671
    789672            DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectReplacementCharacter, 1));
     
    793676                context->concatCTM(rotation(boxRect, Clockwise));
    794677
    795             paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, sPos, ePos, length, emphasisMarkTextOrigin, boxRect, selectionShadow, selectionStrokeWidth > 0, isHorizontal());
     678            paintTextWithShadows(context, combinedText ? combinedText->originalFont() : font, emphasisMarkTextRun, emphasisMark, emphasisMarkOffset, sPos, ePos, length, emphasisMarkTextOrigin, boxRect, selectionShadow, selectionPaintStyle.strokeWidth > 0, isHorizontal());
    796679
    797680            if (combinedText)
     
    803686    TextDecoration textDecorations = lineStyle.textDecorationsInEffect();
    804687    if (textDecorations != TextDecorationNone && paintInfo.phase != PaintPhaseSelection) {
    805         updateGraphicsContext(context, textFillColor, textStrokeColor, textStrokeWidth, lineStyle.colorSpace());
     688        updateGraphicsContext(*context, textPaintStyle);
    806689        if (combinedText)
    807690            context->concatCTM(rotation(boxRect, Clockwise));
     
    890773
    891774    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!
    893776   
    894777    // If the text is truncated, let the thing being painted in the truncation
     
    937820    Color c = Color(225, 221, 85);
    938821   
    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!
    940823
    941824    int deltaY = renderer().style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop();
     
    13921275            renderer().theme()->platformInactiveTextSearchHighlightColor();
    13931276        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!
    13951278        pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_logicalWidth, selHeight));
    13961279        pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.y() - deltaY), selHeight, color, style.colorSpace(), sPos, ePos);
  • trunk/Source/WebCore/rendering/InlineTextBox.h

    r156613 r157015  
    4141    BufferForAppendingHyphen() { reserveCapacity(256); }
    4242};
    43 
    44 // Helper functions shared by InlineTextBox / SVGRootInlineBox
    45 void updateGraphicsContext(GraphicsContext*, const Color& fillColor, const Color& strokeColor, float strokeThickness, ColorSpace);
    46 Color correctedTextColor(Color textColor, Color backgroundColor);
    4743
    4844class InlineTextBox : public InlineBox {
Note: See TracChangeset for help on using the changeset viewer.