diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-08-12 17:43:37 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-14 11:30:40 +0200 |
commit | 9f71d6500569d76afd11e2a77a4670e80cfecbb0 (patch) | |
tree | af3fa96bf4464f94cdd96091bb499062dec2bd50 /Userland | |
parent | 53b9f364131192517d355e46d4d81b37f4868454 (diff) | |
download | serenity-9f71d6500569d76afd11e2a77a4670e80cfecbb0.zip |
LibWeb: Extract CanvasPathDrawingStyles class from CRC2D
Diffstat (limited to 'Userland')
4 files changed, 57 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPathDrawingStyles.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPathDrawingStyles.h new file mode 100644 index 0000000000..e6b1265158 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPathDrawingStyles.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibWeb/HTML/Canvas/CanvasState.h> + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/canvas.html#canvaspathdrawingstyles +template<typename IncludingClass> +class CanvasPathDrawingStyles { +public: + ~CanvasPathDrawingStyles() = default; + + void set_line_width(float line_width) { my_drawing_state().line_width = line_width; } + float line_width() const { return my_drawing_state().line_width; } + +protected: + CanvasPathDrawingStyles() = 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(); } +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPathDrawingStyles.idl b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPathDrawingStyles.idl new file mode 100644 index 0000000000..305f7b67a8 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPathDrawingStyles.idl @@ -0,0 +1,22 @@ +// https://html.spec.whatwg.org/multipage/canvas.html#canvaslinecap +enum CanvasLineCap { "butt", "round", "square" }; +enum CanvasLineJoin { "round", "bevel", "miter" }; +enum CanvasTextAlign { "start", "end", "left", "right", "center" }; +enum CanvasTextBaseline { "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" }; +enum CanvasDirection { "ltr", "rtl", "inherit" }; +enum CanvasFontKerning { "auto", "normal", "none" }; +enum CanvasFontStretch { "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "normal", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" }; +enum CanvasFontVariantCaps { "normal", "small-caps", "all-small-caps", "petite-caps", "all-petite-caps", "unicase", "titling-caps" }; +enum CanvasTextRendering { "auto", "optimizeSpeed", "optimizeLegibility", "geometricPrecision" }; + +// https://html.spec.whatwg.org/multipage/canvas.html#canvaspathdrawingstyles +interface mixin CanvasPathDrawingStyles { + attribute unrestricted double lineWidth; + // FIXME: attribute CanvasLineCap lineCap; + // FIXME: attribute CanvasLineJoin lineJoin; + // FIXME: attribute unrestricted double miterLimit; + + // FIXME: undefined setLineDash(sequence<unrestricted double> segments); + // FIXME: sequence<unrestricted double> getLineDash(); + // FIXME: attribute unrestricted double lineDashOffset; +}; diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h index 936a3182ba..3fecfb3fad 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h @@ -21,6 +21,7 @@ #include <LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h> #include <LibWeb/HTML/Canvas/CanvasImageData.h> #include <LibWeb/HTML/Canvas/CanvasPath.h> +#include <LibWeb/HTML/Canvas/CanvasPathDrawingStyles.h> #include <LibWeb/HTML/Canvas/CanvasRect.h> #include <LibWeb/HTML/Canvas/CanvasState.h> #include <LibWeb/HTML/Canvas/CanvasText.h> @@ -46,7 +47,8 @@ class CanvasRenderingContext2D , public CanvasDrawPath , public CanvasText , public CanvasDrawImage - , public CanvasImageData { + , public CanvasImageData + , public CanvasPathDrawingStyles<CanvasRenderingContext2D> { AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D); AK_MAKE_NONMOVABLE(CanvasRenderingContext2D); @@ -63,9 +65,6 @@ public: virtual DOM::ExceptionOr<void> draw_image_internal(CanvasImageSource const&, float source_x, float source_y, float source_width, float source_height, float destination_x, float destination_y, float destination_width, float destination_height) override; - void set_line_width(float line_width) { drawing_state().line_width = line_width; } - float line_width() const { return drawing_state().line_width; } - virtual void begin_path() override; virtual void stroke() override; virtual void stroke(Path2D const& path) override; diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl index efcf607892..41a9cd75ff 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl @@ -4,6 +4,7 @@ #import <HTML/Canvas/CanvasFillStrokeStyles.idl> #import <HTML/Canvas/CanvasImageData.idl> #import <HTML/Canvas/CanvasPath.idl> +#import <HTML/Canvas/CanvasPathDrawingStyles.idl> #import <HTML/Canvas/CanvasRect.idl> #import <HTML/Canvas/CanvasState.idl> #import <HTML/Canvas/CanvasText.idl> @@ -12,11 +13,7 @@ // https://html.spec.whatwg.org/multipage/canvas.html#canvasrenderingcontext2d [Exposed=Window] interface CanvasRenderingContext2D { - - attribute double lineWidth; - [ImplementedAs=canvas_for_binding] readonly attribute HTMLCanvasElement canvas; - }; CanvasRenderingContext2D includes CanvasState; @@ -27,4 +24,5 @@ CanvasRenderingContext2D includes CanvasDrawPath; CanvasRenderingContext2D includes CanvasText; CanvasRenderingContext2D includes CanvasDrawImage; CanvasRenderingContext2D includes CanvasImageData; +CanvasRenderingContext2D includes CanvasPathDrawingStyles; CanvasRenderingContext2D includes CanvasPath; |