Title: [256298] trunk/Source/WebCore
Revision
256298
Author
carlo...@webkit.org
Date
2020-02-11 01:35:23 -0800 (Tue, 11 Feb 2020)

Log Message

[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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (256297 => 256298)


--- trunk/Source/WebCore/ChangeLog	2020-02-11 08:24:47 UTC (rev 256297)
+++ trunk/Source/WebCore/ChangeLog	2020-02-11 09:35:23 UTC (rev 256298)
@@ -1,3 +1,25 @@
+2020-01-30  Carlos Garcia Campos  <cgar...@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  <krol...@apple.com>
 
         Adjust the minor version number for the desktop user agent string.

Modified: trunk/Source/WebCore/SourcesWPE.txt (256297 => 256298)


--- trunk/Source/WebCore/SourcesWPE.txt	2020-02-11 08:24:47 UTC (rev 256297)
+++ trunk/Source/WebCore/SourcesWPE.txt	2020-02-11 09:35:23 UTC (rev 256298)
@@ -59,8 +59,11 @@
 
 page/scrolling/generic/ScrollingThreadGeneric.cpp
 
+platform/ScrollAnimationKinetic.cpp
 platform/UserAgentQuirks.cpp
 
+platform/generic/ScrollAnimatorGeneric.cpp
+
 platform/graphics/GLContext.cpp
 platform/graphics/PlatformDisplay.cpp
 

Modified: trunk/Source/WebCore/platform/ScrollAnimator.cpp (256297 => 256298)


--- trunk/Source/WebCore/platform/ScrollAnimator.cpp	2020-02-11 08:24:47 UTC (rev 256297)
+++ trunk/Source/WebCore/platform/ScrollAnimator.cpp	2020-02-11 09:35:23 UTC (rev 256298)
@@ -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);

Modified: trunk/Source/WebCore/platform/wpe/ScrollbarThemeWPE.cpp (256297 => 256298)


--- trunk/Source/WebCore/platform/wpe/ScrollbarThemeWPE.cpp	2020-02-11 08:24:47 UTC (rev 256297)
+++ trunk/Source/WebCore/platform/wpe/ScrollbarThemeWPE.cpp	2020-02-11 09:35:23 UTC (rev 256298)
@@ -26,40 +26,184 @@
 #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&, bool)
+IntRect ScrollbarThemeWPE::trackRect(Scrollbar& scrollbar, bool)
 {
-    notImplemented();
-    return IntRect();
+    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;
+}
+
+ScrollbarButtonPressAction ScrollbarThemeWPE::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
+{
+    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()
 {
     static ScrollbarThemeWPE theme;

Modified: trunk/Source/WebCore/platform/wpe/ScrollbarThemeWPE.h (256297 => 256298)


--- trunk/Source/WebCore/platform/wpe/ScrollbarThemeWPE.h	2020-02-11 08:24:47 UTC (rev 256297)
+++ trunk/Source/WebCore/platform/wpe/ScrollbarThemeWPE.h	2020-02-11 09:35:23 UTC (rev 256298)
@@ -34,6 +34,15 @@
     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;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to