mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +00:00
LibWeb: Split ColorStyleValue out of StyleValue.{h,cpp}
This commit is contained in:
parent
66bc816284
commit
77b2826402
13 changed files with 89 additions and 47 deletions
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ColorStyleValue.h"
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
ValueComparingNonnullRefPtr<ColorStyleValue> ColorStyleValue::create(Color color)
|
||||
{
|
||||
if (color.value() == 0) {
|
||||
static auto transparent = adopt_ref(*new ColorStyleValue(color));
|
||||
return transparent;
|
||||
}
|
||||
|
||||
if (color == Color::from_rgb(0x000000)) {
|
||||
static auto black = adopt_ref(*new ColorStyleValue(color));
|
||||
return black;
|
||||
}
|
||||
|
||||
if (color == Color::from_rgb(0xffffff)) {
|
||||
static auto white = adopt_ref(*new ColorStyleValue(color));
|
||||
return white;
|
||||
}
|
||||
|
||||
return adopt_ref(*new ColorStyleValue(color));
|
||||
}
|
||||
|
||||
ErrorOr<String> ColorStyleValue::to_string() const
|
||||
{
|
||||
return serialize_a_srgb_value(m_color);
|
||||
}
|
||||
|
||||
}
|
39
Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
Normal file
39
Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibGfx/Color.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class ColorStyleValue : public StyleValueWithDefaultOperators<ColorStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<ColorStyleValue> create(Color color);
|
||||
virtual ~ColorStyleValue() override = default;
|
||||
|
||||
Color color() const { return m_color; }
|
||||
virtual ErrorOr<String> to_string() const override;
|
||||
virtual bool has_color() const override { return true; }
|
||||
virtual Color to_color(Layout::NodeWithStyle const&) const override { return m_color; }
|
||||
|
||||
bool properties_equal(ColorStyleValue const& other) const { return m_color == other.m_color; };
|
||||
|
||||
private:
|
||||
explicit ColorStyleValue(Color color)
|
||||
: StyleValueWithDefaultOperators(Type::Color)
|
||||
, m_color(color)
|
||||
{
|
||||
}
|
||||
|
||||
Color m_color;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue