mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibWeb/CSS: Implement the light-dark color function
This commit is contained in:
parent
4a0ac312cc
commit
8e56109515
Notes:
github-actions[bot]
2025-01-08 11:19:19 +00:00
Author: https://github.com/Gingeh
Commit: 8e56109515
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3146
Reviewed-by: https://github.com/AtkinsSJ ✅
14 changed files with 275 additions and 0 deletions
37
Libraries/LibWeb/CSS/StyleValues/CSSLightDark.cpp
Normal file
37
Libraries/LibWeb/CSS/StyleValues/CSSLightDark.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Ladybird contributors
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "CSSLightDark.h"
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
Color CSSLightDark::to_color(Optional<Layout::NodeWithStyle const&> node) const
|
||||
{
|
||||
if (node.has_value() && node.value().computed_values().color_scheme() == PreferredColorScheme::Dark)
|
||||
return m_properties.dark->to_color(node);
|
||||
|
||||
return m_properties.light->to_color(node);
|
||||
}
|
||||
|
||||
bool CSSLightDark::equals(CSSStyleValue const& other) const
|
||||
{
|
||||
if (type() != other.type())
|
||||
return false;
|
||||
auto const& other_color = other.as_color();
|
||||
if (color_type() != other_color.color_type())
|
||||
return false;
|
||||
auto const& other_light_dark = verify_cast<CSSLightDark>(other_color);
|
||||
return m_properties == other_light_dark.m_properties;
|
||||
}
|
||||
|
||||
String CSSLightDark::to_string(SerializationMode mode) const
|
||||
{
|
||||
// FIXME: We don't have enough information to determine the computed value here.
|
||||
return MUST(String::formatted("light-dark({}, {})", m_properties.light->to_string(mode), m_properties.dark->to_string(mode)));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue