1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:47:35 +00:00

LibWeb: Extract CanvasRect class from CRC2D

This one requires drawing to the canvas, so it doesn't make so much
sense to move the implementation over.
This commit is contained in:
Sam Atkins 2022-08-12 16:06:32 +01:00 committed by Andreas Kling
parent aa3cb8b425
commit c0494988ed
4 changed files with 38 additions and 8 deletions

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/canvas.html#canvasrect
class CanvasRect {
public:
virtual ~CanvasRect() = default;
virtual void fill_rect(float x, float y, float width, float height) = 0;
virtual void stroke_rect(float x, float y, float width, float height) = 0;
virtual void clear_rect(float x, float y, float width, float height) = 0;
protected:
CanvasRect() = default;
};
}

View file

@ -0,0 +1,6 @@
// https://html.spec.whatwg.org/multipage/canvas.html#canvasrect
interface mixin CanvasRect {
undefined clearRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
undefined fillRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
undefined strokeRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
};

View file

@ -18,6 +18,7 @@
#include <LibWeb/DOM/ExceptionOr.h> #include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h> #include <LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h>
#include <LibWeb/HTML/Canvas/CanvasPath.h> #include <LibWeb/HTML/Canvas/CanvasPath.h>
#include <LibWeb/HTML/Canvas/CanvasRect.h>
#include <LibWeb/HTML/Canvas/CanvasState.h> #include <LibWeb/HTML/Canvas/CanvasState.h>
#include <LibWeb/HTML/Canvas/CanvasTransform.h> #include <LibWeb/HTML/Canvas/CanvasTransform.h>
#include <LibWeb/HTML/CanvasGradient.h> #include <LibWeb/HTML/CanvasGradient.h>
@ -36,7 +37,8 @@ class CanvasRenderingContext2D
, public CanvasPath , public CanvasPath
, public CanvasState , public CanvasState
, public CanvasTransform<CanvasRenderingContext2D> , public CanvasTransform<CanvasRenderingContext2D>
, public CanvasFillStrokeStyles<CanvasRenderingContext2D> { , public CanvasFillStrokeStyles<CanvasRenderingContext2D>
, public CanvasRect {
AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D); AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D);
AK_MAKE_NONMOVABLE(CanvasRenderingContext2D); AK_MAKE_NONMOVABLE(CanvasRenderingContext2D);
@ -47,9 +49,9 @@ public:
static NonnullRefPtr<CanvasRenderingContext2D> create(HTMLCanvasElement& element) { return adopt_ref(*new CanvasRenderingContext2D(element)); } static NonnullRefPtr<CanvasRenderingContext2D> create(HTMLCanvasElement& element) { return adopt_ref(*new CanvasRenderingContext2D(element)); }
~CanvasRenderingContext2D(); ~CanvasRenderingContext2D();
void fill_rect(float x, float y, float width, float height); virtual void fill_rect(float x, float y, float width, float height) override;
void stroke_rect(float x, float y, float width, float height); virtual void stroke_rect(float x, float y, float width, float height) override;
void clear_rect(float x, float y, float width, float height); virtual void clear_rect(float x, float y, float width, float height) override;
DOM::ExceptionOr<void> draw_image(CanvasImageSource const&, float destination_x, float destination_y); DOM::ExceptionOr<void> draw_image(CanvasImageSource const&, float destination_x, float destination_y);
DOM::ExceptionOr<void> draw_image(CanvasImageSource const&, float destination_x, float destination_y, float destination_width, float destination_height); DOM::ExceptionOr<void> draw_image(CanvasImageSource const&, float destination_x, float destination_y, float destination_width, float destination_height);

View file

@ -4,6 +4,7 @@
#import <HTML/TextMetrics.idl> #import <HTML/TextMetrics.idl>
#import <HTML/Canvas/CanvasFillStrokeStyles.idl> #import <HTML/Canvas/CanvasFillStrokeStyles.idl>
#import <HTML/Canvas/CanvasPath.idl> #import <HTML/Canvas/CanvasPath.idl>
#import <HTML/Canvas/CanvasRect.idl>
#import <HTML/Canvas/CanvasState.idl> #import <HTML/Canvas/CanvasState.idl>
#import <HTML/Canvas/CanvasTransform.idl> #import <HTML/Canvas/CanvasTransform.idl>
#import <HTML/Path2D.idl> #import <HTML/Path2D.idl>
@ -12,10 +13,6 @@
[Exposed=Window] [Exposed=Window]
interface CanvasRenderingContext2D { interface CanvasRenderingContext2D {
undefined fillRect(double x, double y, double w, double h);
undefined strokeRect(double x, double y, double w, double h);
undefined clearRect(double x, double y, double w, double h);
undefined beginPath(); undefined beginPath();
// FIXME: `DOMString` should be `CanvasFillRule` // FIXME: `DOMString` should be `CanvasFillRule`
undefined fill(optional DOMString fillRule = "nonzero"); undefined fill(optional DOMString fillRule = "nonzero");
@ -51,4 +48,5 @@ interface CanvasRenderingContext2D {
CanvasRenderingContext2D includes CanvasState; CanvasRenderingContext2D includes CanvasState;
CanvasRenderingContext2D includes CanvasTransform; CanvasRenderingContext2D includes CanvasTransform;
CanvasRenderingContext2D includes CanvasFillStrokeStyles; CanvasRenderingContext2D includes CanvasFillStrokeStyles;
CanvasRenderingContext2D includes CanvasRect;
CanvasRenderingContext2D includes CanvasPath; CanvasRenderingContext2D includes CanvasPath;