ladybird/Libraries/LibWeb/CSS/StyleValues/CursorStyleValue.h
Callum Law 2404f95e03
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
LibWeb: Invalidate style for tree counting functions when required
We mark any element that relies on tree counting functions as needing a
style update when a sibling is inserted/removed.
2025-10-20 16:12:08 +01:00

63 lines
2.2 KiB
C++

/*
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <LibGfx/Color.h>
#include <LibGfx/Cursor.h>
#include <LibWeb/CSS/CalculatedOr.h>
#include <LibWeb/CSS/Length.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
#include <LibWeb/Forward.h>
namespace Web::CSS {
class CursorStyleValue final : public StyleValueWithDefaultOperators<CursorStyleValue> {
public:
static ValueComparingNonnullRefPtr<CursorStyleValue const> create(ValueComparingNonnullRefPtr<AbstractImageStyleValue const> image, RefPtr<StyleValue const> x, RefPtr<StyleValue const> y)
{
// We require either both or neither the X and Y parameters
VERIFY((!x && !y) || (x && y));
return adopt_ref(*new (nothrow) CursorStyleValue(move(image), move(x), move(y)));
}
virtual ~CursorStyleValue() override = default;
Optional<Gfx::ImageCursor> make_image_cursor(Layout::NodeWithStyle const&) const;
virtual String to_string(SerializationMode) const override;
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&, PropertyComputationDependencies&) const override;
bool properties_equal(CursorStyleValue const& other) const { return m_properties == other.m_properties; }
private:
CursorStyleValue(ValueComparingNonnullRefPtr<AbstractImageStyleValue const> image,
RefPtr<StyleValue const> x,
RefPtr<StyleValue const> y)
: StyleValueWithDefaultOperators(Type::Cursor)
, m_properties { .image = move(image), .x = move(x), .y = move(y) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<AbstractImageStyleValue const> image;
RefPtr<StyleValue const> x;
RefPtr<StyleValue const> y;
bool operator==(Properties const&) const = default;
} m_properties;
// Data that can affect the bitmap rendering.
struct CacheKey {
Length::ResolutionContext length_resolution_context;
Gfx::Color current_color;
bool operator==(CacheKey const&) const = default;
};
mutable Optional<CacheKey> m_cache_key;
mutable Optional<Gfx::ShareableBitmap> m_cached_bitmap;
};
}