summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h')
-rw-r--r--Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h
new file mode 100644
index 0000000000..0f0e773256
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h
@@ -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(); }
+};
+
+}