Changeset 256298 in webkit


Ignore:
Timestamp:
Feb 11, 2020 1:35:23 AM (4 years ago)
Author:
Carlos Garcia Campos
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:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r256230 r256298  
     12020-01-30  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [WPE] Add initial support for rendering scrollbars
     4        https://bugs.webkit.org/show_bug.cgi?id=206999
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Show overlay scrollbars with a style similar to Adwaita.
     9
     10        * SourcesWPE.txt: Add ScrollAnimatorGeneric.cpp to the build.
     11        * platform/ScrollAnimator.cpp: Switch to use ScrollAnimatorGeneric, required to show/hide the overlay scrollbars.
     12        * platform/wpe/ScrollbarThemeWPE.cpp:
     13        (WebCore::ScrollbarThemeWPE::scrollbarThickness):
     14        (WebCore::ScrollbarThemeWPE::minimumThumbLength):
     15        (WebCore::ScrollbarThemeWPE::hasButtons):
     16        (WebCore::ScrollbarThemeWPE::hasThumb):
     17        (WebCore::ScrollbarThemeWPE::backButtonRect):
     18        (WebCore::ScrollbarThemeWPE::forwardButtonRect):
     19        (WebCore::ScrollbarThemeWPE::trackRect):
     20        (WebCore::ScrollbarThemeWPE::paint):
     21        * platform/wpe/ScrollbarThemeWPE.h:
     22
    1232020-02-10  Keith Rollin  <krollin@apple.com>
    224
  • trunk/Source/WebCore/SourcesWPE.txt

    r254064 r256298  
    6060page/scrolling/generic/ScrollingThreadGeneric.cpp
    6161
     62platform/ScrollAnimationKinetic.cpp
    6263platform/UserAgentQuirks.cpp
     64
     65platform/generic/ScrollAnimatorGeneric.cpp
    6366
    6467platform/graphics/GLContext.cpp
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r255957 r256298  
    4242namespace WebCore {
    4343
    44 #if !ENABLE(SMOOTH_SCROLLING) && !PLATFORM(IOS_FAMILY) && !PLATFORM(MAC)
     44#if !ENABLE(SMOOTH_SCROLLING) && !PLATFORM(IOS_FAMILY) && !PLATFORM(MAC) && !PLATFORM(WPE)
    4545std::unique_ptr<ScrollAnimator> ScrollAnimator::create(ScrollableArea& scrollableArea)
    4646{
  • trunk/Source/WebCore/platform/wpe/ScrollbarThemeWPE.cpp

    r216497 r256298  
    2727#include "ScrollbarThemeWPE.h"
    2828
    29 #include "NotImplemented.h"
     29#include "Color.h"
     30#include "FloatRoundedRect.h"
     31#include "GraphicsContext.h"
     32#include "PlatformMouseEvent.h"
     33#include "Scrollbar.h"
    3034
    3135namespace WebCore {
    3236
     37static const unsigned scrollbarSize = 13;
     38static const unsigned hoveredScrollbarBorderSize = 1;
     39static const unsigned thumbBorderSize = 1;
     40static const unsigned overlayThumbSize = 5;
     41static const unsigned thumbSize = 6;
     42static const double scrollbarOpacity = 0.8;
     43static const Color scrollbarBackgroundColor = makeRGB(252, 252, 252);
     44static const Color scrollbarBorderColor = makeRGB(220, 223, 227);
     45static const Color overlayThumbBorderColor = makeRGBA(255, 255, 255, 100);
     46static const Color overlayThumbColor = makeRGBA(46, 52, 54, 100);
     47static const Color thumbHoveredColor = makeRGB(86, 91, 92);
     48static const Color thumbPressedColor = makeRGB(27, 106, 203);
     49static const Color thumbColor = makeRGB(126, 129, 130);
     50
     51int ScrollbarThemeWPE::scrollbarThickness(ScrollbarControlSize, ScrollbarExpansionState)
     52{
     53    return scrollbarSize;
     54}
     55
     56int ScrollbarThemeWPE::minimumThumbLength(Scrollbar&)
     57{
     58    return 0;
     59}
     60
    3361bool ScrollbarThemeWPE::hasButtons(Scrollbar&)
    3462{
    35     notImplemented();
     63    return false;
     64}
     65
     66bool ScrollbarThemeWPE::hasThumb(Scrollbar& scrollbar)
     67{
     68    return thumbLength(scrollbar) > 0;
     69}
     70
     71IntRect ScrollbarThemeWPE::backButtonRect(Scrollbar&, ScrollbarPart, bool)
     72{
     73    return { };
     74}
     75
     76IntRect ScrollbarThemeWPE::forwardButtonRect(Scrollbar&, ScrollbarPart, bool)
     77{
     78    return { };
     79}
     80
     81IntRect ScrollbarThemeWPE::trackRect(Scrollbar& scrollbar, bool)
     82{
     83    return scrollbar.frameRect();
     84}
     85
     86bool ScrollbarThemeWPE::paint(Scrollbar& scrollbar, GraphicsContext& graphicsContext, const IntRect& damageRect)
     87{
     88    if (graphicsContext.paintingDisabled())
     89        return false;
     90
     91    if (!scrollbar.enabled())
     92        return true;
     93
     94    IntRect rect = scrollbar.frameRect();
     95    if (!rect.intersects(damageRect))
     96        return true;
     97
     98    double opacity = scrollbar.hoveredPart() == NoPart ? scrollbar.opacity() : scrollbarOpacity;
     99    if (!opacity)
     100        return true;
     101
     102    GraphicsContextStateSaver stateSaver(graphicsContext);
     103    if (opacity != 1) {
     104        graphicsContext.clip(damageRect);
     105        graphicsContext.beginTransparencyLayer(opacity);
     106    }
     107
     108    if (scrollbar.hoveredPart() != NoPart) {
     109        graphicsContext.fillRect(rect, scrollbarBackgroundColor);
     110
     111        IntRect frame = rect;
     112        if (scrollbar.orientation() == VerticalScrollbar) {
     113            if (scrollbar.scrollableArea().shouldPlaceBlockDirectionScrollbarOnLeft())
     114                frame.move(frame.width() - hoveredScrollbarBorderSize, 0);
     115            frame.setWidth(hoveredScrollbarBorderSize);
     116        } else
     117            frame.setHeight(hoveredScrollbarBorderSize);
     118        graphicsContext.fillRect(frame, scrollbarBorderColor);
     119    }
     120
     121    int thumbPos = thumbPosition(scrollbar);
     122    int thumbLen = thumbLength(scrollbar);
     123    IntRect thumb = rect;
     124    if (scrollbar.hoveredPart() == NoPart) {
     125        if (scrollbar.orientation() == VerticalScrollbar) {
     126            if (scrollbar.scrollableArea().shouldPlaceBlockDirectionScrollbarOnLeft())
     127                thumb.move(hoveredScrollbarBorderSize, thumbPos + thumbBorderSize);
     128            else
     129                thumb.move(scrollbarSize - (overlayThumbSize + thumbBorderSize) + hoveredScrollbarBorderSize, thumbPos + thumbBorderSize);
     130            thumb.setWidth(overlayThumbSize);
     131            thumb.setHeight(thumbLen - thumbBorderSize * 2);
     132        } else {
     133            thumb.move(thumbPos + thumbBorderSize, scrollbarSize - (overlayThumbSize + thumbBorderSize) + hoveredScrollbarBorderSize);
     134            thumb.setWidth(thumbLen - thumbBorderSize * 2);
     135            thumb.setHeight(overlayThumbSize);
     136        }
     137    } else {
     138        if (scrollbar.orientation() == VerticalScrollbar) {
     139            if (scrollbar.scrollableArea().shouldPlaceBlockDirectionScrollbarOnLeft())
     140                thumb.move(scrollbarSize - (scrollbarSize / 2 + thumbSize / 2) - hoveredScrollbarBorderSize, thumbPos + thumbBorderSize);
     141            else
     142                thumb.move(scrollbarSize - (scrollbarSize / 2 + thumbSize / 2), thumbPos + thumbBorderSize);
     143            thumb.setWidth(thumbSize);
     144            thumb.setHeight(thumbLen - thumbBorderSize * 2);
     145        } else {
     146            thumb.move(thumbPos + thumbBorderSize, scrollbarSize - (scrollbarSize / 2 + thumbSize / 2));
     147            thumb.setWidth(thumbLen - thumbBorderSize * 2);
     148            thumb.setHeight(thumbSize);
     149        }
     150    }
     151
     152    FloatSize corner(4, 4);
     153    Path path;
     154    if (scrollbar.hoveredPart() == NoPart) {
     155        path.addRoundedRect(thumb, corner);
     156        thumb.inflate(-1);
     157        path.addRoundedRect(thumb, corner);
     158        graphicsContext.setFillRule(WindRule::EvenOdd);
     159        graphicsContext.setFillColor(overlayThumbBorderColor);
     160        graphicsContext.fillPath(path);
     161        path.clear();
     162    }
     163
     164    path.addRoundedRect(thumb, corner);
     165    graphicsContext.setFillRule(WindRule::NonZero);
     166    if (scrollbar.hoveredPart() == NoPart)
     167        graphicsContext.setFillColor(overlayThumbColor);
     168    else if (scrollbar.pressedPart() == ThumbPart)
     169        graphicsContext.setFillColor(thumbPressedColor);
     170    else if (scrollbar.hoveredPart() == ThumbPart)
     171        graphicsContext.setFillColor(thumbHoveredColor);
     172    else
     173        graphicsContext.setFillColor(thumbColor);
     174    graphicsContext.fillPath(path);
     175
     176    if (opacity != 1)
     177        graphicsContext.endTransparencyLayer();
     178
    36179    return true;
    37180}
    38181
    39 bool ScrollbarThemeWPE::hasThumb(Scrollbar&)
    40 {
    41     notImplemented();
    42     return true;
    43 }
    44 
    45 IntRect ScrollbarThemeWPE::backButtonRect(Scrollbar&, ScrollbarPart, bool)
    46 {
    47     notImplemented();
    48     return IntRect();
    49 }
    50 
    51 IntRect ScrollbarThemeWPE::forwardButtonRect(Scrollbar&, ScrollbarPart, bool)
    52 {
    53     notImplemented();
    54     return IntRect();
    55 }
    56 
    57 IntRect ScrollbarThemeWPE::trackRect(Scrollbar&, bool)
    58 {
    59     notImplemented();
    60     return IntRect();
     182ScrollbarButtonPressAction ScrollbarThemeWPE::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
     183{
     184    switch (pressedPart) {
     185    case BackTrackPart:
     186    case ForwardTrackPart:
     187        // The shift key or middle/right button reverses the sense.
     188        if (event.shiftKey() || event.button() != LeftButton)
     189            return ScrollbarButtonPressAction::CenterOnThumb;
     190        return ScrollbarButtonPressAction::Scroll;
     191    case ThumbPart:
     192        if (event.button() != RightButton)
     193            return ScrollbarButtonPressAction::StartDrag;
     194        break;
     195    case BackButtonStartPart:
     196    case ForwardButtonStartPart:
     197    case BackButtonEndPart:
     198    case ForwardButtonEndPart:
     199        return ScrollbarButtonPressAction::Scroll;
     200    default:
     201        break;
     202    }
     203
     204    return ScrollbarButtonPressAction::None;
    61205}
    62206
  • trunk/Source/WebCore/platform/wpe/ScrollbarThemeWPE.h

    r216497 r256298  
    3535    virtual ~ScrollbarThemeWPE() = default;
    3636
     37private:
     38    bool usesOverlayScrollbars() const override { return true; }
     39
     40    bool paint(Scrollbar&, GraphicsContext&, const IntRect&) override;
     41    ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart) override;
     42
     43    int scrollbarThickness(ScrollbarControlSize, ScrollbarExpansionState) override;
     44    int minimumThumbLength(Scrollbar&) override;
     45
    3746    bool hasButtons(Scrollbar&) override;
    3847    bool hasThumb(Scrollbar&) override;
Note: See TracChangeset for help on using the changeset viewer.