Title: [154400] trunk
Revision
154400
Author
[email protected]
Date
2013-08-21 11:04:42 -0700 (Wed, 21 Aug 2013)

Log 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (154399 => 154400)


--- trunk/LayoutTests/ChangeLog	2013-08-21 18:03:06 UTC (rev 154399)
+++ trunk/LayoutTests/ChangeLog	2013-08-21 18:04:42 UTC (rev 154400)
@@ -1,3 +1,16 @@
+2013-08-21  Simon Fraser  <[email protected]>
+
+        Allow opacity to apply to custom scrollbars
+        https://bugs.webkit.org/show_bug.cgi?id=120104
+
+        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.
+
 2013-08-21  Robert Hogan  <[email protected]>
 
         REGRESSION(r127163): Respect clearance set on ancestors when placing floats

Added: trunk/LayoutTests/scrollbars/scrollbar-parts-opacity-expected.html (0 => 154400)


--- trunk/LayoutTests/scrollbars/scrollbar-parts-opacity-expected.html	                        (rev 0)
+++ trunk/LayoutTests/scrollbars/scrollbar-parts-opacity-expected.html	2013-08-21 18:04:42 UTC (rev 154400)
@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+    <style>
+        body {
+            margin: 0;
+        }
+        .bar-background {
+            position: absolute;
+            background-color: green;
+            opacity: 0.75;
+        }
+        
+        .bar-background.vertical {
+            left: 340px;
+            width: 60px;
+            height: 340px;
+        }
+
+        .bar-background.horizontal {
+            top: 340px;
+            height: 60px;
+            width: 340px;
+        }
+
+        .thumb {
+            position: absolute;
+            background-color: navy;
+            opacity: 0.5;
+        }
+        
+        .vertical > .thumb {
+            width: 60px;
+            height: 145px;
+        }
+
+        .horizontal > .thumb {
+            width: 145px;
+            height: 60px;
+        }
+
+        .backdrop {
+            position: absolute;
+            top: 100px;
+            left: 100px;
+            height: 400px;
+            width: 400px;
+            background-color: gray;
+        }
+        
+        .backdrop.vertical {
+            width: 150px;
+        }
+
+        .backdrop.horizontal {
+            height: 150px;
+        }
+    </style>
+</head>
+<body>
+
+    <div class="backdrop vertical"></div>
+    <div class="backdrop horizontal"></div>
+
+    <div class="bar-background vertical">
+        <div class="thumb"></div>
+    </div>
+    <div class="bar-background horizontal">
+        <div class="thumb"></div>
+    </div>
+</body>
+</html>
Property changes on: trunk/LayoutTests/scrollbars/scrollbar-parts-opacity-expected.html
___________________________________________________________________

Added: svn:mime-type

Added: svn:keywords

Added: svn:eol-style

Added: trunk/LayoutTests/scrollbars/scrollbar-parts-opacity.html (0 => 154400)


--- trunk/LayoutTests/scrollbars/scrollbar-parts-opacity.html	                        (rev 0)
+++ trunk/LayoutTests/scrollbars/scrollbar-parts-opacity.html	2013-08-21 18:04:42 UTC (rev 154400)
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+    <style>
+        body {
+            margin: 0;
+        }
+        ::-webkit-scrollbar {
+            width: 60px;
+            height: 60px;
+            background-color: green;
+            opacity: 0.75;
+        }
+
+        ::-webkit-scrollbar-thumb {
+            background-color: navy;
+            opacity: 0.5;
+        }
+        
+        .overflow {
+            position: absolute;
+            height: 400px;
+            width: 400px;
+            overflow: scroll;
+        }
+        .contents {
+            height: 800px;
+            width: 800px;
+        }
+        
+        .backdrop {
+            position: absolute;
+            top: 100px;
+            left: 100px;
+            height: 400px;
+            width: 400px;
+            background-color: gray;
+        }
+        
+        .vertical {
+            width: 150px;
+        }
+
+        .horizontal {
+            height: 150px;
+        }
+    </style>
+</head>
+<body>
+
+    <div class="backdrop vertical"></div>
+    <div class="backdrop horizontal"></div>
+    <div class="composited overflow">
+        <div class="contents"></div>
+    </div>
+</body>
+</html>
Property changes on: trunk/LayoutTests/scrollbars/scrollbar-parts-opacity.html
___________________________________________________________________

Added: svn:mime-type

Added: svn:keywords

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (154399 => 154400)


--- trunk/Source/WebCore/ChangeLog	2013-08-21 18:03:06 UTC (rev 154399)
+++ trunk/Source/WebCore/ChangeLog	2013-08-21 18:04:42 UTC (rev 154400)
@@ -1,3 +1,40 @@
+2013-08-21  Simon Fraser  <[email protected]>
+
+        Allow opacity to apply to custom scrollbars
+        https://bugs.webkit.org/show_bug.cgi?id=120104
+
+        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:
+
 2013-08-21  Robert Hogan  <[email protected]>
 
         REGRESSION(r127163): Respect clearance set on ancestors when placing floats

Modified: trunk/Source/WebCore/platform/ScrollbarThemeComposite.cpp (154399 => 154400)


--- trunk/Source/WebCore/platform/ScrollbarThemeComposite.cpp	2013-08-21 18:03:06 UTC (rev 154399)
+++ trunk/Source/WebCore/platform/ScrollbarThemeComposite.cpp	2013-08-21 18:04:42 UTC (rev 154400)
@@ -75,6 +75,8 @@
             scrollMask |= ForwardTrackPart;
     }
 
+    willPaintScrollbar(graphicsContext, scrollbar);
+    
     // Paint the scrollbar background (only used by custom CSS scrollbars).
     paintScrollbarBackground(graphicsContext, scrollbar);
 
@@ -105,6 +107,7 @@
     if (scrollMask & ThumbPart)
         paintThumb(graphicsContext, scrollbar, thumbRect);
 
+    didPaintScrollbar(graphicsContext, scrollbar);
     return true;
 }
 

Modified: trunk/Source/WebCore/platform/ScrollbarThemeComposite.h (154399 => 154400)


--- trunk/Source/WebCore/platform/ScrollbarThemeComposite.h	2013-08-21 18:03:06 UTC (rev 154399)
+++ trunk/Source/WebCore/platform/ScrollbarThemeComposite.h	2013-08-21 18:04:42 UTC (rev 154400)
@@ -55,6 +55,9 @@
     
     virtual int minimumThumbLength(ScrollbarThemeClient*);
 
+    virtual void willPaintScrollbar(GraphicsContext*, ScrollbarThemeClient*) { }
+    virtual void didPaintScrollbar(GraphicsContext*, ScrollbarThemeClient*) { }
+
     virtual void paintScrollbarBackground(GraphicsContext*, ScrollbarThemeClient*) { }
     virtual void paintTrackBackground(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) { }
     virtual void paintTrackPiece(GraphicsContext*, ScrollbarThemeClient*, const IntRect&, ScrollbarPart) { }

Modified: trunk/Source/WebCore/rendering/RenderScrollbar.cpp (154399 => 154400)


--- trunk/Source/WebCore/rendering/RenderScrollbar.cpp	2013-08-21 18:03:06 UTC (rev 154399)
+++ trunk/Source/WebCore/rendering/RenderScrollbar.cpp	2013-08-21 18:04:42 UTC (rev 154400)
@@ -357,4 +357,13 @@
     return orientation() == HorizontalScrollbar ? partRenderer->width() : partRenderer->height();
 }
 
+float RenderScrollbar::opacity()
+{
+    RenderScrollbarPart* partRenderer = m_parts.get(ScrollbarBGPart);
+    if (!partRenderer)
+        return 1;
+
+    return partRenderer->style()->opacity();
 }
+
+}

Modified: trunk/Source/WebCore/rendering/RenderScrollbar.h (154399 => 154400)


--- trunk/Source/WebCore/rendering/RenderScrollbar.h	2013-08-21 18:03:06 UTC (rev 154399)
+++ trunk/Source/WebCore/rendering/RenderScrollbar.h	2013-08-21 18:04:42 UTC (rev 154400)
@@ -59,6 +59,8 @@
 
     virtual bool isOverlayScrollbar() const { return false; }
 
+    float opacity();
+
 private:
     virtual void setParent(ScrollView*);
     virtual void setEnabled(bool);

Modified: trunk/Source/WebCore/rendering/RenderScrollbarPart.cpp (154399 => 154400)


--- trunk/Source/WebCore/rendering/RenderScrollbarPart.cpp	2013-08-21 18:03:06 UTC (rev 154399)
+++ trunk/Source/WebCore/rendering/RenderScrollbarPart.cpp	2013-08-21 18:04:42 UTC (rev 154400)
@@ -181,9 +181,18 @@
     setWidth(rect.width());
     setHeight(rect.height());
 
-    if (graphicsContext->paintingDisabled())
+    if (graphicsContext->paintingDisabled() || !style()->opacity())
         return;
 
+    // We don't use RenderLayers for scrollbar parts, so we need to handle opacity here.
+    // Opacity for ScrollbarBGPart is handled by RenderScrollbarTheme::willPaintScrollbar().
+    bool needsTransparencyLayer = m_part != ScrollbarBGPart && style()->opacity() < 1;
+    if (needsTransparencyLayer) {
+        graphicsContext->save();
+        graphicsContext->clip(rect);
+        graphicsContext->beginTransparencyLayer(style()->opacity());
+    }
+    
     // Now do the paint.
     PaintInfo paintInfo(graphicsContext, pixelSnappedIntRect(rect), PaintPhaseBlockBackground, PaintBehaviorNormal);
     paint(paintInfo, paintOffset);
@@ -195,6 +204,11 @@
     paint(paintInfo, paintOffset);
     paintInfo.phase = PaintPhaseOutline;
     paint(paintInfo, paintOffset);
+
+    if (needsTransparencyLayer) {
+        graphicsContext->endTransparencyLayer();
+        graphicsContext->restore();
+    }
 }
 
 RenderObject* RenderScrollbarPart::rendererOwningScrollbar() const

Modified: trunk/Source/WebCore/rendering/RenderScrollbarTheme.cpp (154399 => 154400)


--- trunk/Source/WebCore/rendering/RenderScrollbarTheme.cpp	2013-08-21 18:03:06 UTC (rev 154399)
+++ trunk/Source/WebCore/rendering/RenderScrollbarTheme.cpp	2013-08-21 18:04:42 UTC (rev 154400)
@@ -107,6 +107,25 @@
     return result;
 }
 
+void RenderScrollbarTheme::willPaintScrollbar(GraphicsContext* context, ScrollbarThemeClient* scrollbar)
+{
+    float opacity = toRenderScrollbar(scrollbar)->opacity();
+    if (opacity != 1) {
+        context->save();
+        context->clip(scrollbar->frameRect());
+        context->beginTransparencyLayer(opacity);
+    }
+}
+
+void RenderScrollbarTheme::didPaintScrollbar(GraphicsContext* context, ScrollbarThemeClient* scrollbar)
+{
+    float opacity = toRenderScrollbar(scrollbar)->opacity();
+    if (opacity != 1) {
+        context->endTransparencyLayer();
+        context->restore();
+    }
+}
+
 void RenderScrollbarTheme::paintScrollCorner(ScrollView*, GraphicsContext* context, const IntRect& cornerRect)
 {
     // FIXME: Implement.

Modified: trunk/Source/WebCore/rendering/RenderScrollbarTheme.h (154399 => 154400)


--- trunk/Source/WebCore/rendering/RenderScrollbarTheme.h	2013-08-21 18:03:06 UTC (rev 154399)
+++ trunk/Source/WebCore/rendering/RenderScrollbarTheme.h	2013-08-21 18:04:42 UTC (rev 154400)
@@ -67,6 +67,9 @@
     virtual IntRect backButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false);
     virtual IntRect forwardButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false);
     virtual IntRect trackRect(ScrollbarThemeClient*, bool painting = false);
+
+    virtual void willPaintScrollbar(GraphicsContext*, ScrollbarThemeClient*) OVERRIDE;
+    virtual void didPaintScrollbar(GraphicsContext*, ScrollbarThemeClient*) OVERRIDE;
     
     virtual void paintScrollbarBackground(GraphicsContext*, ScrollbarThemeClient*);
     virtual void paintTrackBackground(GraphicsContext*, ScrollbarThemeClient*, const IntRect&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to