mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
LibWeb: Extract CanvasFillStrokeStyles class from CRC2D
This commit is contained in:
parent
aa87b9699e
commit
afabd613bd
5 changed files with 70 additions and 36 deletions
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasState.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#canvasfillstrokestyles
|
||||
template<typename IncludingClass>
|
||||
class CanvasFillStrokeStyles {
|
||||
public:
|
||||
~CanvasFillStrokeStyles() = default;
|
||||
|
||||
void set_fill_style(String style)
|
||||
{
|
||||
// FIXME: 2. If the given value is a CanvasPattern object that is marked as not origin-clean, then set this's origin-clean flag to false.
|
||||
my_drawing_state().fill_style = Gfx::Color::from_string(style).value_or(Color::Black);
|
||||
}
|
||||
|
||||
String fill_style() const
|
||||
{
|
||||
return my_drawing_state().fill_style.to_string();
|
||||
}
|
||||
|
||||
void set_stroke_style(String style)
|
||||
{
|
||||
// FIXME: 2. If the given value is a CanvasPattern object that is marked as not origin-clean, then set this's origin-clean flag to false.
|
||||
my_drawing_state().stroke_style = Gfx::Color::from_string(style).value_or(Color::Black);
|
||||
}
|
||||
|
||||
String stroke_style() const
|
||||
{
|
||||
return my_drawing_state().stroke_style.to_string();
|
||||
}
|
||||
|
||||
protected:
|
||||
CanvasFillStrokeStyles() = default;
|
||||
|
||||
private:
|
||||
CanvasState::DrawingState& my_drawing_state() { return reinterpret_cast<IncludingClass&>(*this).drawing_state(); }
|
||||
CanvasState::DrawingState const& my_drawing_state() const { return reinterpret_cast<IncludingClass const&>(*this).drawing_state(); }
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue