Changeset 154400 in webkit


Ignore:
Timestamp:
Aug 21, 2013 11:04:42 AM (11 years ago)
Author:
Simon Fraser
Message:

Allow opacity to apply to custom scrollbars
https://bugs.webkit.org/show_bug.cgi?id=120104

Source/WebCore:

Reviewed by David Hyatt.

Opacity was ignored custom scrollbar pseudoelements because custom scrollbar
renderers never create layers, and opacity is normally handled by the RenderLayer code.

Fix by having RenderScrollbarTheme and RenderScrollbarPart do the transparency
layers necessary for opacity. RenderScrollbarPart handles opacity for individual
parts.

Because ScrollbarThemeComposite::paint() renders the parts on after another (with
no nesting), opacity handling for the entire scrollbar needs special-casing.
This is done by willPaintScrollbar()/didPaintScrollbar() on the theme.
RenderScrollbarTheme consults the opacity the scrollbar (which we get from
the ScrollbarBGPart renderer) to decide whether to set up a transparency layer.

Test: scrollbars/scrollbar-parts-opacity.html

  • platform/ScrollbarThemeComposite.cpp:

(WebCore::ScrollbarThemeComposite::paint):

  • platform/ScrollbarThemeComposite.h:

(WebCore::ScrollbarThemeComposite::willPaintScrollbar):
(WebCore::ScrollbarThemeComposite::didPaintScrollbar):

  • rendering/RenderScrollbar.cpp:

(WebCore::RenderScrollbar::opacity):

  • rendering/RenderScrollbar.h:
  • rendering/RenderScrollbarPart.cpp:

(WebCore::RenderScrollbarPart::paintIntoRect):

  • rendering/RenderScrollbarTheme.cpp:

(WebCore::RenderScrollbarTheme::willPaintScrollbar):
(WebCore::RenderScrollbarTheme::didPaintScrollbar):

  • rendering/RenderScrollbarTheme.h:

LayoutTests:

Reviewed by David Hyatt.

Ref test for custom scrollbars with opacity on the bar itself,
and on the thumb.

  • scrollbars/scrollbar-parts-opacity-expected.html: Added.
  • scrollbars/scrollbar-parts-opacity.html: Added.
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r154399 r154400  
     12013-08-21  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Allow opacity to apply to custom scrollbars
     4        https://bugs.webkit.org/show_bug.cgi?id=120104
     5
     6        Reviewed by David Hyatt.
     7       
     8        Ref test for custom scrollbars with opacity on the bar itself,
     9        and on the thumb.
     10
     11        * scrollbars/scrollbar-parts-opacity-expected.html: Added.
     12        * scrollbars/scrollbar-parts-opacity.html: Added.
     13
    1142013-08-21  Robert Hogan  <robert@webkit.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r154399 r154400  
     12013-08-21  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Allow opacity to apply to custom scrollbars
     4        https://bugs.webkit.org/show_bug.cgi?id=120104
     5
     6        Reviewed by David Hyatt.
     7       
     8        Opacity was ignored custom scrollbar pseudoelements because custom scrollbar
     9        renderers never create layers, and opacity is normally handled by the RenderLayer code.
     10       
     11        Fix by having RenderScrollbarTheme and RenderScrollbarPart do the transparency
     12        layers necessary for opacity. RenderScrollbarPart handles opacity for individual
     13        parts.
     14       
     15        Because ScrollbarThemeComposite::paint() renders the parts on after another (with
     16        no nesting), opacity handling for the entire scrollbar needs special-casing.
     17        This is done by willPaintScrollbar()/didPaintScrollbar() on the theme.
     18        RenderScrollbarTheme consults the opacity the scrollbar (which we get from
     19        the ScrollbarBGPart renderer) to decide whether to set up a transparency layer.
     20
     21        Test: scrollbars/scrollbar-parts-opacity.html
     22
     23        * platform/ScrollbarThemeComposite.cpp:
     24        (WebCore::ScrollbarThemeComposite::paint):
     25        * platform/ScrollbarThemeComposite.h:
     26        (WebCore::ScrollbarThemeComposite::willPaintScrollbar):
     27        (WebCore::ScrollbarThemeComposite::didPaintScrollbar):
     28        * rendering/RenderScrollbar.cpp:
     29        (WebCore::RenderScrollbar::opacity):
     30        * rendering/RenderScrollbar.h:
     31        * rendering/RenderScrollbarPart.cpp:
     32        (WebCore::RenderScrollbarPart::paintIntoRect):
     33        * rendering/RenderScrollbarTheme.cpp:
     34        (WebCore::RenderScrollbarTheme::willPaintScrollbar):
     35        (WebCore::RenderScrollbarTheme::didPaintScrollbar):
     36        * rendering/RenderScrollbarTheme.h:
     37
    1382013-08-21  Robert Hogan  <robert@webkit.org>
    239
  • trunk/Source/WebCore/platform/ScrollbarThemeComposite.cpp

    r148967 r154400  
    7676    }
    7777
     78    willPaintScrollbar(graphicsContext, scrollbar);
     79   
    7880    // Paint the scrollbar background (only used by custom CSS scrollbars).
    7981    paintScrollbarBackground(graphicsContext, scrollbar);
     
    106108        paintThumb(graphicsContext, scrollbar, thumbRect);
    107109
     110    didPaintScrollbar(graphicsContext, scrollbar);
    108111    return true;
    109112}
  • trunk/Source/WebCore/platform/ScrollbarThemeComposite.h

    r134965 r154400  
    5656    virtual int minimumThumbLength(ScrollbarThemeClient*);
    5757
     58    virtual void willPaintScrollbar(GraphicsContext*, ScrollbarThemeClient*) { }
     59    virtual void didPaintScrollbar(GraphicsContext*, ScrollbarThemeClient*) { }
     60
    5861    virtual void paintScrollbarBackground(GraphicsContext*, ScrollbarThemeClient*) { }
    5962    virtual void paintTrackBackground(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) { }
  • trunk/Source/WebCore/rendering/RenderScrollbar.cpp

    r143848 r154400  
    358358}
    359359
    360 }
     360float RenderScrollbar::opacity()
     361{
     362    RenderScrollbarPart* partRenderer = m_parts.get(ScrollbarBGPart);
     363    if (!partRenderer)
     364        return 1;
     365
     366    return partRenderer->style()->opacity();
     367}
     368
     369}
  • trunk/Source/WebCore/rendering/RenderScrollbar.h

    r145399 r154400  
    6060    virtual bool isOverlayScrollbar() const { return false; }
    6161
     62    float opacity();
     63
    6264private:
    6365    virtual void setParent(ScrollView*);
  • trunk/Source/WebCore/rendering/RenderScrollbarPart.cpp

    r148536 r154400  
    182182    setHeight(rect.height());
    183183
    184     if (graphicsContext->paintingDisabled())
    185         return;
    186 
     184    if (graphicsContext->paintingDisabled() || !style()->opacity())
     185        return;
     186
     187    // We don't use RenderLayers for scrollbar parts, so we need to handle opacity here.
     188    // Opacity for ScrollbarBGPart is handled by RenderScrollbarTheme::willPaintScrollbar().
     189    bool needsTransparencyLayer = m_part != ScrollbarBGPart && style()->opacity() < 1;
     190    if (needsTransparencyLayer) {
     191        graphicsContext->save();
     192        graphicsContext->clip(rect);
     193        graphicsContext->beginTransparencyLayer(style()->opacity());
     194    }
     195   
    187196    // Now do the paint.
    188197    PaintInfo paintInfo(graphicsContext, pixelSnappedIntRect(rect), PaintPhaseBlockBackground, PaintBehaviorNormal);
     
    196205    paintInfo.phase = PaintPhaseOutline;
    197206    paint(paintInfo, paintOffset);
     207
     208    if (needsTransparencyLayer) {
     209        graphicsContext->endTransparencyLayer();
     210        graphicsContext->restore();
     211    }
    198212}
    199213
  • trunk/Source/WebCore/rendering/RenderScrollbarTheme.cpp

    r123418 r154400  
    108108}
    109109
     110void RenderScrollbarTheme::willPaintScrollbar(GraphicsContext* context, ScrollbarThemeClient* scrollbar)
     111{
     112    float opacity = toRenderScrollbar(scrollbar)->opacity();
     113    if (opacity != 1) {
     114        context->save();
     115        context->clip(scrollbar->frameRect());
     116        context->beginTransparencyLayer(opacity);
     117    }
     118}
     119
     120void RenderScrollbarTheme::didPaintScrollbar(GraphicsContext* context, ScrollbarThemeClient* scrollbar)
     121{
     122    float opacity = toRenderScrollbar(scrollbar)->opacity();
     123    if (opacity != 1) {
     124        context->endTransparencyLayer();
     125        context->restore();
     126    }
     127}
     128
    110129void RenderScrollbarTheme::paintScrollCorner(ScrollView*, GraphicsContext* context, const IntRect& cornerRect)
    111130{
  • trunk/Source/WebCore/rendering/RenderScrollbarTheme.h

    r123418 r154400  
    6868    virtual IntRect forwardButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false);
    6969    virtual IntRect trackRect(ScrollbarThemeClient*, bool painting = false);
     70
     71    virtual void willPaintScrollbar(GraphicsContext*, ScrollbarThemeClient*) OVERRIDE;
     72    virtual void didPaintScrollbar(GraphicsContext*, ScrollbarThemeClient*) OVERRIDE;
    7073   
    7174    virtual void paintScrollbarBackground(GraphicsContext*, ScrollbarThemeClient*);
Note: See TracChangeset for help on using the changeset viewer.