[WPE] Add initial support for rendering scrollbars
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Feb 2020 09:35:23 +0000 (09:35 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Feb 2020 09:35:23 +0000 (09:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=206999

Reviewed by Michael Catanzaro.

Show overlay scrollbars with a style similar to Adwaita.

* SourcesWPE.txt: Add ScrollAnimatorGeneric.cpp to the build.
* platform/ScrollAnimator.cpp: Switch to use ScrollAnimatorGeneric, required to show/hide the overlay scrollbars.
* platform/wpe/ScrollbarThemeWPE.cpp:
(WebCore::ScrollbarThemeWPE::scrollbarThickness):
(WebCore::ScrollbarThemeWPE::minimumThumbLength):
(WebCore::ScrollbarThemeWPE::hasButtons):
(WebCore::ScrollbarThemeWPE::hasThumb):
(WebCore::ScrollbarThemeWPE::backButtonRect):
(WebCore::ScrollbarThemeWPE::forwardButtonRect):
(WebCore::ScrollbarThemeWPE::trackRect):
(WebCore::ScrollbarThemeWPE::paint):
* platform/wpe/ScrollbarThemeWPE.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256298 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/SourcesWPE.txt
Source/WebCore/platform/ScrollAnimator.cpp
Source/WebCore/platform/wpe/ScrollbarThemeWPE.cpp
Source/WebCore/platform/wpe/ScrollbarThemeWPE.h

index 94dcd7a..c9163d4 100644 (file)
@@ -1,3 +1,25 @@
+2020-01-30  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [WPE] Add initial support for rendering scrollbars
+        https://bugs.webkit.org/show_bug.cgi?id=206999
+
+        Reviewed by Michael Catanzaro.
+
+        Show overlay scrollbars with a style similar to Adwaita.
+
+        * SourcesWPE.txt: Add ScrollAnimatorGeneric.cpp to the build.
+        * platform/ScrollAnimator.cpp: Switch to use ScrollAnimatorGeneric, required to show/hide the overlay scrollbars.
+        * platform/wpe/ScrollbarThemeWPE.cpp:
+        (WebCore::ScrollbarThemeWPE::scrollbarThickness):
+        (WebCore::ScrollbarThemeWPE::minimumThumbLength):
+        (WebCore::ScrollbarThemeWPE::hasButtons):
+        (WebCore::ScrollbarThemeWPE::hasThumb):
+        (WebCore::ScrollbarThemeWPE::backButtonRect):
+        (WebCore::ScrollbarThemeWPE::forwardButtonRect):
+        (WebCore::ScrollbarThemeWPE::trackRect):
+        (WebCore::ScrollbarThemeWPE::paint):
+        * platform/wpe/ScrollbarThemeWPE.h:
+
 2020-02-10  Keith Rollin  <krollin@apple.com>
 
         Adjust the minor version number for the desktop user agent string.
index b5c8915..97ecdac 100644 (file)
@@ -59,8 +59,11 @@ page/scrolling/nicosia/ScrollingTreeStickyNode.cpp
 
 page/scrolling/generic/ScrollingThreadGeneric.cpp
 
+platform/ScrollAnimationKinetic.cpp
 platform/UserAgentQuirks.cpp
 
+platform/generic/ScrollAnimatorGeneric.cpp
+
 platform/graphics/GLContext.cpp
 platform/graphics/PlatformDisplay.cpp
 
index ff57d02..0fc729e 100644 (file)
@@ -41,7 +41,7 @@
 
 namespace WebCore {
 
-#if !ENABLE(SMOOTH_SCROLLING) && !PLATFORM(IOS_FAMILY) && !PLATFORM(MAC)
+#if !ENABLE(SMOOTH_SCROLLING) && !PLATFORM(IOS_FAMILY) && !PLATFORM(MAC) && !PLATFORM(WPE)
 std::unique_ptr<ScrollAnimator> ScrollAnimator::create(ScrollableArea& scrollableArea)
 {
     return makeUnique<ScrollAnimator>(scrollableArea);
index 0f9fe5d..5163e14 100644 (file)
 #include "config.h"
 #include "ScrollbarThemeWPE.h"
 
-#include "NotImplemented.h"
+#include "Color.h"
+#include "FloatRoundedRect.h"
+#include "GraphicsContext.h"
+#include "PlatformMouseEvent.h"
+#include "Scrollbar.h"
 
 namespace WebCore {
 
+static const unsigned scrollbarSize = 13;
+static const unsigned hoveredScrollbarBorderSize = 1;
+static const unsigned thumbBorderSize = 1;
+static const unsigned overlayThumbSize = 5;
+static const unsigned thumbSize = 6;
+static const double scrollbarOpacity = 0.8;
+static const Color scrollbarBackgroundColor = makeRGB(252, 252, 252);
+static const Color scrollbarBorderColor = makeRGB(220, 223, 227);
+static const Color overlayThumbBorderColor = makeRGBA(255, 255, 255, 100);
+static const Color overlayThumbColor = makeRGBA(46, 52, 54, 100);
+static const Color thumbHoveredColor = makeRGB(86, 91, 92);
+static const Color thumbPressedColor = makeRGB(27, 106, 203);
+static const Color thumbColor = makeRGB(126, 129, 130);
+
+int ScrollbarThemeWPE::scrollbarThickness(ScrollbarControlSize, ScrollbarExpansionState)
+{
+    return scrollbarSize;
+}
+
+int ScrollbarThemeWPE::minimumThumbLength(Scrollbar&)
+{
+    return 0;
+}
+
 bool ScrollbarThemeWPE::hasButtons(Scrollbar&)
 {
-    notImplemented();
-    return true;
+    return false;
 }
 
-bool ScrollbarThemeWPE::hasThumb(Scrollbar&)
+bool ScrollbarThemeWPE::hasThumb(Scrollbar& scrollbar)
 {
-    notImplemented();
-    return true;
+    return thumbLength(scrollbar) > 0;
 }
 
 IntRect ScrollbarThemeWPE::backButtonRect(Scrollbar&, ScrollbarPart, bool)
 {
-    notImplemented();
-    return IntRect();
+    return { };
 }
 
 IntRect ScrollbarThemeWPE::forwardButtonRect(Scrollbar&, ScrollbarPart, bool)
 {
-    notImplemented();
-    return IntRect();
+    return { };
+}
+
+IntRect ScrollbarThemeWPE::trackRect(Scrollbar& scrollbar, bool)
+{
+    return scrollbar.frameRect();
+}
+
+bool ScrollbarThemeWPE::paint(Scrollbar& scrollbar, GraphicsContext& graphicsContext, const IntRect& damageRect)
+{
+    if (graphicsContext.paintingDisabled())
+        return false;
+
+    if (!scrollbar.enabled())
+        return true;
+
+    IntRect rect = scrollbar.frameRect();
+    if (!rect.intersects(damageRect))
+        return true;
+
+    double opacity = scrollbar.hoveredPart() == NoPart ? scrollbar.opacity() : scrollbarOpacity;
+    if (!opacity)
+        return true;
+
+    GraphicsContextStateSaver stateSaver(graphicsContext);
+    if (opacity != 1) {
+        graphicsContext.clip(damageRect);
+        graphicsContext.beginTransparencyLayer(opacity);
+    }
+
+    if (scrollbar.hoveredPart() != NoPart) {
+        graphicsContext.fillRect(rect, scrollbarBackgroundColor);
+
+        IntRect frame = rect;
+        if (scrollbar.orientation() == VerticalScrollbar) {
+            if (scrollbar.scrollableArea().shouldPlaceBlockDirectionScrollbarOnLeft())
+                frame.move(frame.width() - hoveredScrollbarBorderSize, 0);
+            frame.setWidth(hoveredScrollbarBorderSize);
+        } else
+            frame.setHeight(hoveredScrollbarBorderSize);
+        graphicsContext.fillRect(frame, scrollbarBorderColor);
+    }
+
+    int thumbPos = thumbPosition(scrollbar);
+    int thumbLen = thumbLength(scrollbar);
+    IntRect thumb = rect;
+    if (scrollbar.hoveredPart() == NoPart) {
+        if (scrollbar.orientation() == VerticalScrollbar) {
+            if (scrollbar.scrollableArea().shouldPlaceBlockDirectionScrollbarOnLeft())
+                thumb.move(hoveredScrollbarBorderSize, thumbPos + thumbBorderSize);
+            else
+                thumb.move(scrollbarSize - (overlayThumbSize + thumbBorderSize) + hoveredScrollbarBorderSize, thumbPos + thumbBorderSize);
+            thumb.setWidth(overlayThumbSize);
+            thumb.setHeight(thumbLen - thumbBorderSize * 2);
+        } else {
+            thumb.move(thumbPos + thumbBorderSize, scrollbarSize - (overlayThumbSize + thumbBorderSize) + hoveredScrollbarBorderSize);
+            thumb.setWidth(thumbLen - thumbBorderSize * 2);
+            thumb.setHeight(overlayThumbSize);
+        }
+    } else {
+        if (scrollbar.orientation() == VerticalScrollbar) {
+            if (scrollbar.scrollableArea().shouldPlaceBlockDirectionScrollbarOnLeft())
+                thumb.move(scrollbarSize - (scrollbarSize / 2 + thumbSize / 2) - hoveredScrollbarBorderSize, thumbPos + thumbBorderSize);
+            else
+                thumb.move(scrollbarSize - (scrollbarSize / 2 + thumbSize / 2), thumbPos + thumbBorderSize);
+            thumb.setWidth(thumbSize);
+            thumb.setHeight(thumbLen - thumbBorderSize * 2);
+        } else {
+            thumb.move(thumbPos + thumbBorderSize, scrollbarSize - (scrollbarSize / 2 + thumbSize / 2));
+            thumb.setWidth(thumbLen - thumbBorderSize * 2);
+            thumb.setHeight(thumbSize);
+        }
+    }
+
+    FloatSize corner(4, 4);
+    Path path;
+    if (scrollbar.hoveredPart() == NoPart) {
+        path.addRoundedRect(thumb, corner);
+        thumb.inflate(-1);
+        path.addRoundedRect(thumb, corner);
+        graphicsContext.setFillRule(WindRule::EvenOdd);
+        graphicsContext.setFillColor(overlayThumbBorderColor);
+        graphicsContext.fillPath(path);
+        path.clear();
+    }
+
+    path.addRoundedRect(thumb, corner);
+    graphicsContext.setFillRule(WindRule::NonZero);
+    if (scrollbar.hoveredPart() == NoPart)
+        graphicsContext.setFillColor(overlayThumbColor);
+    else if (scrollbar.pressedPart() == ThumbPart)
+        graphicsContext.setFillColor(thumbPressedColor);
+    else if (scrollbar.hoveredPart() == ThumbPart)
+        graphicsContext.setFillColor(thumbHoveredColor);
+    else
+        graphicsContext.setFillColor(thumbColor);
+    graphicsContext.fillPath(path);
+
+    if (opacity != 1)
+        graphicsContext.endTransparencyLayer();
+
+    return true;
 }
 
-IntRect ScrollbarThemeWPE::trackRect(Scrollbar&, bool)
+ScrollbarButtonPressAction ScrollbarThemeWPE::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
 {
-    notImplemented();
-    return IntRect();
+    switch (pressedPart) {
+    case BackTrackPart:
+    case ForwardTrackPart:
+        // The shift key or middle/right button reverses the sense.
+        if (event.shiftKey() || event.button() != LeftButton)
+            return ScrollbarButtonPressAction::CenterOnThumb;
+        return ScrollbarButtonPressAction::Scroll;
+    case ThumbPart:
+        if (event.button() != RightButton)
+            return ScrollbarButtonPressAction::StartDrag;
+        break;
+    case BackButtonStartPart:
+    case ForwardButtonStartPart:
+    case BackButtonEndPart:
+    case ForwardButtonEndPart:
+        return ScrollbarButtonPressAction::Scroll;
+    default:
+        break;
+    }
+
+    return ScrollbarButtonPressAction::None;
 }
 
 ScrollbarTheme& ScrollbarTheme::nativeTheme()
index 67185ad..ae9d659 100644 (file)
@@ -34,6 +34,15 @@ public:
     ScrollbarThemeWPE() = default;
     virtual ~ScrollbarThemeWPE() = default;
 
+private:
+    bool usesOverlayScrollbars() const override { return true; }
+
+    bool paint(Scrollbar&, GraphicsContext&, const IntRect&) override;
+    ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart) override;
+
+    int scrollbarThickness(ScrollbarControlSize, ScrollbarExpansionState) override;
+    int minimumThumbLength(Scrollbar&) override;
+
     bool hasButtons(Scrollbar&) override;
     bool hasThumb(Scrollbar&) override;