Changeset 116353 in webkit


Ignore:
Timestamp:
May 7, 2012 2:30:57 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Selection Background Color Error
https://bugs.webkit.org/show_bug.cgi?id=80382

Patch by Shezan Baig <shezbaig.wk@gmail.com> on 2012-05-07
Reviewed by David Hyatt.

Source/WebCore:

Determine the text colors and selection colors before painting the
background behind the text. This is because when determining whether
to invert the selection background, the selection text color should be
used instead of the regular text color. With this patch, the selection
text color is passed to 'paintSelection' so that the selection
background can be compared against it, instead of comparing against the
CSSPropertyColor value.

Test: fast/backgrounds/selection-background-color.html

  • rendering/InlineTextBox.cpp:

(WebCore::InlineTextBox::paint):

Pass selection text color to paintSelection

(WebCore::InlineTextBox::paintSelection):

Use the selection text color instead of CSSPropertyColor

  • rendering/InlineTextBox.h:

(InlineTextBox):

Adjust signature of paintSelection to accept text color

LayoutTests:

Added new test case for selection background color.

  • fast/backgrounds/selection-background-color.html: Added.
  • fast/backgrounds/selection-background-color-expected.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r116349 r116353  
     12012-05-07  Shezan Baig  <shezbaig.wk@gmail.com>
     2
     3        Selection Background Color Error
     4        https://bugs.webkit.org/show_bug.cgi?id=80382
     5
     6        Reviewed by David Hyatt.
     7
     8        Added new test case for selection background color.
     9
     10        * fast/backgrounds/selection-background-color.html: Added.
     11        * fast/backgrounds/selection-background-color-expected.html: Added.
     12
    1132012-05-07  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r116351 r116353  
     12012-05-07  Shezan Baig  <shezbaig.wk@gmail.com>
     2
     3        Selection Background Color Error
     4        https://bugs.webkit.org/show_bug.cgi?id=80382
     5
     6        Reviewed by David Hyatt.
     7
     8        Determine the text colors and selection colors before painting the
     9        background behind the text.  This is because when determining whether
     10        to invert the selection background, the selection text color should be
     11        used instead of the regular text color.  With this patch, the selection
     12        text color is passed to 'paintSelection' so that the selection
     13        background can be compared against it, instead of comparing against the
     14        CSSPropertyColor value.
     15
     16        Test: fast/backgrounds/selection-background-color.html
     17
     18        * rendering/InlineTextBox.cpp:
     19        (WebCore::InlineTextBox::paint):
     20            Pass selection text color to paintSelection
     21
     22        (WebCore::InlineTextBox::paintSelection):
     23            Use the selection text color instead of CSSPropertyColor
     24
     25        * rendering/InlineTextBox.h:
     26        (InlineTextBox):
     27            Adjust signature of paintSelection to accept text color
     28
    1292012-05-07  David Reveman  <reveman@chromium.org>
    230
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r114784 r116353  
    535535    bool useCustomUnderlines = containsComposition && renderer()->frame()->editor()->compositionUsesCustomUnderlines();
    536536
    537     // Set our font.
    538     const Font& font = styleToUse->font();
    539 
    540     FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().ascent());
    541 
    542     if (combinedText)
    543         combinedText->adjustTextOrigin(textOrigin, boxRect);
    544 
    545     // 1. Paint backgrounds behind text if needed. Examples of such backgrounds include selection
    546     // and composition underlines.
    547     if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseTextClip && !isPrinting) {
    548 #if PLATFORM(MAC)
    549         // Custom highlighters go behind everything else.
    550         if (styleToUse->highlight() != nullAtom && !context->paintingDisabled())
    551             paintCustomHighlight(adjustedPaintOffset, styleToUse->highlight());
    552 #endif
    553 
    554         if (containsComposition && !useCustomUnderlines)
    555             paintCompositionBackground(context, boxOrigin, styleToUse, font,
    556                 renderer()->frame()->editor()->compositionStart(),
    557                 renderer()->frame()->editor()->compositionEnd());
    558 
    559         paintDocumentMarkers(context, boxOrigin, styleToUse, font, true);
    560 
    561         if (haveSelection && !useCustomUnderlines)
    562             paintSelection(context, boxOrigin, styleToUse, font);
    563     }
    564 
    565     if (Frame* frame = renderer()->frame()) {
    566         if (Page* page = frame->page()) {
    567             // FIXME: Right now, InlineTextBoxes never call addRelevantUnpaintedObject() even though they might
    568             // legitimately be unpainted if they are waiting on a slow-loading web font. We should fix that, and
    569             // when we do, we will have to account for the fact the InlineTextBoxes do not always have unique
    570             // renderers and Page currently relies on each unpainted object having a unique renderer.
    571             if (paintInfo.phase == PaintPhaseForeground)
    572                 page->addRelevantRepaintedObject(renderer(), IntRect(boxOrigin.x(), boxOrigin.y(), logicalWidth(), logicalHeight()));
    573         }
    574     }
    575 
    576     // 2. Now paint the foreground, including text and decorations like underline/overline (in quirks mode only).
     537    // Determine the text colors and selection colors.
    577538    Color textFillColor;
    578539    Color textStrokeColor;
     
    661622    }
    662623
     624    // Set our font.
     625    const Font& font = styleToUse->font();
     626
     627    FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().ascent());
     628
     629    if (combinedText)
     630        combinedText->adjustTextOrigin(textOrigin, boxRect);
     631
     632    // 1. Paint backgrounds behind text if needed. Examples of such backgrounds include selection
     633    // and composition underlines.
     634    if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseTextClip && !isPrinting) {
     635#if PLATFORM(MAC)
     636        // Custom highlighters go behind everything else.
     637        if (styleToUse->highlight() != nullAtom && !context->paintingDisabled())
     638            paintCustomHighlight(adjustedPaintOffset, styleToUse->highlight());
     639#endif
     640
     641        if (containsComposition && !useCustomUnderlines)
     642            paintCompositionBackground(context, boxOrigin, styleToUse, font,
     643                renderer()->frame()->editor()->compositionStart(),
     644                renderer()->frame()->editor()->compositionEnd());
     645
     646        paintDocumentMarkers(context, boxOrigin, styleToUse, font, true);
     647
     648        if (haveSelection && !useCustomUnderlines)
     649            paintSelection(context, boxOrigin, styleToUse, font, selectionFillColor);
     650    }
     651
     652    if (Frame* frame = renderer()->frame()) {
     653        if (Page* page = frame->page()) {
     654            // FIXME: Right now, InlineTextBoxes never call addRelevantUnpaintedObject() even though they might
     655            // legitimately be unpainted if they are waiting on a slow-loading web font. We should fix that, and
     656            // when we do, we will have to account for the fact the InlineTextBoxes do not always have unique
     657            // renderers and Page currently relies on each unpainted object having a unique renderer.
     658            if (paintInfo.phase == PaintPhaseForeground)
     659                page->addRelevantRepaintedObject(renderer(), IntRect(boxOrigin.x(), boxOrigin.y(), logicalWidth(), logicalHeight()));
     660        }
     661    }
     662
     663    // 2. Now paint the foreground, including text and decorations like underline/overline (in quirks mode only).
    663664    int length = m_len;
    664665    int maximumLength;
     
    807808}
    808809
    809 void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font)
     810void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, Color textColor)
    810811{
    811812    if (context->paintingDisabled())
     
    818819        return;
    819820
    820     Color textColor = style->visitedDependentColor(CSSPropertyColor);
    821821    Color c = renderer()->selectionBackgroundColor();
    822822    if (!c.isValid() || c.alpha() == 0)
     
    824824
    825825    // If the text color ends up being the same as the selection background, invert the selection
    826     // background.  This should basically never happen, since the selection has transparency.
     826    // background.
    827827    if (textColor == c)
    828828        c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
  • trunk/Source/WebCore/rendering/InlineTextBox.h

    r114220 r116353  
    182182private:
    183183    void paintDecoration(GraphicsContext*, const FloatPoint& boxOrigin, int decoration, const ShadowData*);
    184     void paintSelection(GraphicsContext*, const FloatPoint& boxOrigin, RenderStyle*, const Font&);
     184    void paintSelection(GraphicsContext*, const FloatPoint& boxOrigin, RenderStyle*, const Font&, Color textColor);
    185185    void paintDocumentMarker(GraphicsContext*, const FloatPoint& boxOrigin, DocumentMarker*, RenderStyle*, const Font&, bool grammar);
    186186    void paintTextMatchMarker(GraphicsContext*, const FloatPoint& boxOrigin, DocumentMarker*, RenderStyle*, const Font&);
Note: See TracChangeset for help on using the changeset viewer.