Ignore:
Timestamp:
Aug 21, 2013, 11:04:42 AM (12 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.