Skip to content

Commit

Permalink
[css-scrollbars-1] Implement resolving of scrollbar track and thumb c…
Browse files Browse the repository at this point in the history
…olor

https://bugs.webkit.org/show_bug.cgi?id=260141

Reviewed by Simon Fraser.

This patch has no behavior changes.

Adds code to get the resolved scrollbar thumb and track color.

* Source/WebCore/page/LocalFrameView.cpp:
(WebCore::LocalFrameView::scrollbarThumbColorStyle const):
(WebCore::LocalFrameView::scrollbarTrackColorStyle const):
* Source/WebCore/page/LocalFrameView.h:
* Source/WebCore/platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::scrollbarThumbColorStyle const):
(WebCore::ScrollableArea::scrollbarTrackColorStyle const):
* Source/WebCore/platform/ScrollableArea.h:
* Source/WebCore/rendering/RenderLayerScrollableArea.cpp:
(WebCore::RenderLayerScrollableArea::scrollbarThumbColorStyle const):
(WebCore::RenderLayerScrollableArea::scrollbarTrackColorStyle const):
* Source/WebCore/rendering/RenderLayerScrollableArea.h:
* Source/WebCore/rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::effectiveScrollbarThumbColor const):
(WebCore::RenderStyle::effectiveScrollbarTrackColor const):
* Source/WebCore/rendering/style/RenderStyle.h:

Canonical link: https://commits.webkit.org/267260@main
  • Loading branch information
lukewarlow authored and nt1m committed Aug 25, 2023
1 parent 34880c2 commit 4045ef1
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Source/WebCore/page/LocalFrameView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6309,6 +6309,24 @@ OverscrollBehavior LocalFrameView::verticalOverscrollBehavior() const
return OverscrollBehavior::Auto;
}

Color LocalFrameView::scrollbarThumbColorStyle() const
{
auto* document = m_frame->document();
auto scrollingObject = document && document->documentElement() ? document->documentElement()->renderer() : nullptr;
if (scrollingObject)
return scrollingObject->style().effectiveScrollbarThumbColor();
return { };
}

Color LocalFrameView::scrollbarTrackColorStyle() const
{
auto* document = m_frame->document();
auto scrollingObject = document && document->documentElement() ? document->documentElement()->renderer() : nullptr;
if (scrollingObject)
return scrollingObject->style().effectiveScrollbarTrackColor();
return { };
}

ScrollbarGutter LocalFrameView::scrollbarGutterStyle() const
{
auto* document = m_frame->document();
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/page/LocalFrameView.h
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@ class LocalFrameView final : public FrameView {
OverscrollBehavior horizontalOverscrollBehavior() const final;
OverscrollBehavior verticalOverscrollBehavior() const final;

Color scrollbarThumbColorStyle() const final;
Color scrollbarTrackColorStyle() const final;
ScrollbarGutter scrollbarGutterStyle() const final;
ScrollbarWidth scrollbarWidthStyle() const final;

Expand Down
11 changes: 11 additions & 0 deletions Source/WebCore/platform/ScrollableArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "Logging.h"
#include "PlatformWheelEvent.h"
#include "ScrollAnimator.h"
#include "ScrollbarColor.h"
#include "ScrollbarGutter.h"
#include "ScrollbarTheme.h"
#include "ScrollbarsControllerMock.h"
Expand Down Expand Up @@ -511,6 +512,16 @@ String ScrollableArea::verticalScrollbarStateForTesting() const
return scrollbarsController().verticalScrollbarStateForTesting();
}

Color ScrollableArea::scrollbarThumbColorStyle() const
{
return { };
}

Color ScrollableArea::scrollbarTrackColorStyle() const
{
return { };
}

ScrollbarGutter ScrollableArea::scrollbarGutterStyle() const
{
return { };
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/platform/ScrollableArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "ScrollSnapOffsetsInfo.h"
#include "ScrollTypes.h"
#include "Scrollbar.h"
#include "ScrollbarColor.h"
#include <wtf/CheckedPtr.h>
#include <wtf/Forward.h>
#include <wtf/WeakPtr.h>
Expand All @@ -54,6 +55,7 @@ class TiledBacking;

enum class WheelScrollGestureState : uint8_t;

struct ScrollbarColor;
struct ScrollbarGutter;

inline int offsetForOrientation(ScrollOffset offset, ScrollbarOrientation orientation)
Expand Down Expand Up @@ -143,6 +145,8 @@ class ScrollableArea : public CanMakeWeakPtr<ScrollableArea>, public CanMakeChec
virtual OverscrollBehavior horizontalOverscrollBehavior() const { return OverscrollBehavior::Auto; }
virtual OverscrollBehavior verticalOverscrollBehavior() const { return OverscrollBehavior::Auto; }

WEBCORE_EXPORT virtual Color scrollbarThumbColorStyle() const;
WEBCORE_EXPORT virtual Color scrollbarTrackColorStyle() const;
WEBCORE_EXPORT virtual ScrollbarGutter scrollbarGutterStyle() const;
virtual ScrollbarWidth scrollbarWidthStyle() const { return ScrollbarWidth::Auto; }

Expand Down
14 changes: 14 additions & 0 deletions Source/WebCore/rendering/RenderLayerScrollableArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,20 @@ OverscrollBehavior RenderLayerScrollableArea::verticalOverscrollBehavior() const
return OverscrollBehavior::Auto;
}

Color RenderLayerScrollableArea::scrollbarThumbColorStyle() const
{
if (auto* renderer = m_layer.renderBox())
return renderer->style().effectiveScrollbarThumbColor();
return { };
}

Color RenderLayerScrollableArea::scrollbarTrackColorStyle() const
{
if (auto* renderer = m_layer.renderBox())
return renderer->style().effectiveScrollbarTrackColor();
return { };
}

ScrollbarGutter RenderLayerScrollableArea::scrollbarGutterStyle() const
{
if (auto* renderer = m_layer.renderBox())
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/rendering/RenderLayerScrollableArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class RenderLayerScrollableArea final : public ScrollableArea {
OverscrollBehavior horizontalOverscrollBehavior() const final;
OverscrollBehavior verticalOverscrollBehavior() const final;

Color scrollbarThumbColorStyle() const final;
Color scrollbarTrackColorStyle() const final;
ScrollbarGutter scrollbarGutterStyle() const final;
ScrollbarWidth scrollbarWidthStyle() const final;

Expand Down
22 changes: 22 additions & 0 deletions Source/WebCore/rendering/style/RenderStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,28 @@ Color RenderStyle::effectiveAccentColor() const
return colorResolvingCurrentColor(accentColor());
}

Color RenderStyle::effectiveScrollbarThumbColor() const
{
if (!scrollbarColor().has_value())
return { };

if (hasAppleColorFilter())
return colorByApplyingColorFilter(colorResolvingCurrentColor(scrollbarColor().value().thumbColor));

return colorResolvingCurrentColor(scrollbarColor().value().thumbColor);
}

Color RenderStyle::effectiveScrollbarTrackColor() const
{
if (!scrollbarColor().has_value())
return { };

if (hasAppleColorFilter())
return colorByApplyingColorFilter(colorResolvingCurrentColor(scrollbarColor().value().trackColor));

return colorResolvingCurrentColor(scrollbarColor().value().trackColor);
}

const BorderValue& RenderStyle::borderBefore() const
{
switch (blockFlowDirection()) {
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/rendering/style/RenderStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ class RenderStyle {
const ScrollSnapAlign& scrollSnapAlign() const;
ScrollSnapStop scrollSnapStop() const;

Color effectiveScrollbarThumbColor() const;
Color effectiveScrollbarTrackColor() const;
inline std::optional<ScrollbarColor> scrollbarColor() const;
inline const StyleColor& scrollbarThumbColor() const;
inline const StyleColor& scrollbarTrackColor() const;
Expand Down

0 comments on commit 4045ef1

Please sign in to comment.