summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-12-27 14:31:23 +0100
committerAndreas Kling <kling@serenityos.org>2021-12-27 16:43:23 +0100
commit7d435b5adacdaa8f038669d10fba9f615265897a (patch)
treeb4602ec22b105ad8b412b3a241f1e21702334ce5 /Userland/Libraries
parent6d50ff71de74ccb3b0b8dbf7a46b53fd7c93e424 (diff)
downloadserenity-7d435b5adacdaa8f038669d10fba9f615265897a.zip
LibWeb: Implement CanvasRenderingContext2D.save()
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp7
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h3
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl2
3 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
index 1cade07f81..a7eab5c996 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
@@ -313,4 +313,11 @@ void CanvasRenderingContext2D::put_image_data(const ImageData& image_data, float
did_draw(Gfx::FloatRect(x, y, image_data.width(), image_data.height()));
}
+// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-save
+void CanvasRenderingContext2D::save()
+{
+ // The save() method steps are to push a copy of the current drawing state onto the drawing state stack.
+ m_drawing_state_stack.append(m_drawing_state);
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
index 90e7cf7c9b..7d2552a370 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
@@ -69,6 +69,8 @@ public:
RefPtr<ImageData> create_image_data(int width, int height) const;
void put_image_data(const ImageData&, float x, float y);
+ void save();
+
HTMLCanvasElement* canvas() { return m_element; }
private:
@@ -89,6 +91,7 @@ private:
};
DrawingState m_drawing_state;
+ Vector<DrawingState> m_drawing_state_stack;
Gfx::Path m_path;
};
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
index c5a5b7bf6f..05b5870207 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
@@ -31,6 +31,8 @@ interface CanvasRenderingContext2D {
ImageData createImageData(double sw, double sh);
undefined putImageData(ImageData imagedata, double dx, double dy);
+ undefined save();
+
readonly attribute HTMLCanvasElement canvas;
};