LibWeb/CSS: Implement the scrollbar-color property

This allows the user to set the scrollbar thumb and track colors.
This commit is contained in:
Tim Ledbetter 2025-05-26 22:36:12 +01:00 committed by Alexander Kalenik
commit e2d0d8e2b9
Notes: github-actions[bot] 2025-06-01 22:18:57 +00:00
24 changed files with 212 additions and 10 deletions

View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ScrollbarColorStyleValue.h"
namespace Web::CSS {
ValueComparingNonnullRefPtr<ScrollbarColorStyleValue const> ScrollbarColorStyleValue::create(NonnullRefPtr<CSSStyleValue const> thumb_color, NonnullRefPtr<CSSStyleValue const> track_color)
{
return adopt_ref(*new ScrollbarColorStyleValue(move(thumb_color), move(track_color)));
}
String ScrollbarColorStyleValue::to_string(SerializationMode mode) const
{
return MUST(String::formatted("{} {}", m_thumb_color->to_string(mode), m_track_color->to_string(mode)));
}
}

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/OwnPtr.h>
#include <LibWeb/CSS/CSSStyleValue.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
namespace Web::CSS {
class ScrollbarColorStyleValue final : public StyleValueWithDefaultOperators<ScrollbarColorStyleValue> {
public:
static ValueComparingNonnullRefPtr<ScrollbarColorStyleValue const> create(NonnullRefPtr<CSSStyleValue const> thumb_color, NonnullRefPtr<CSSStyleValue const> track_color);
virtual ~ScrollbarColorStyleValue() override = default;
virtual String to_string(SerializationMode) const override;
bool properties_equal(ScrollbarColorStyleValue const& other) const { return m_thumb_color == other.m_thumb_color && m_track_color == other.m_track_color; }
NonnullRefPtr<CSSStyleValue const> thumb_color() const { return m_thumb_color; }
NonnullRefPtr<CSSStyleValue const> track_color() const { return m_track_color; }
private:
explicit ScrollbarColorStyleValue(NonnullRefPtr<CSSStyleValue const> thumb_color, NonnullRefPtr<CSSStyleValue const> track_color)
: StyleValueWithDefaultOperators(Type::ScrollbarColor)
, m_thumb_color(move(thumb_color))
, m_track_color(move(track_color))
{
}
NonnullRefPtr<CSSStyleValue const> m_thumb_color;
NonnullRefPtr<CSSStyleValue const> m_track_color;
};
}