summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-04 23:54:58 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-04 23:54:58 +0200
commit9d099835f92bfaba503b3fe95a2dfb998c65bab4 (patch)
tree2930ab301ed9aff7e72c46246355e6d82044843e /Libraries/LibWeb
parent2db8716a6fb6106ad6bf59a628137c4e4474e1a9 (diff)
downloadserenity-9d099835f92bfaba503b3fe95a2dfb998c65bab4.zip
LibWeb: Add CanvasRenderingContext2D scale() and translate() stubs
These don't do anything for now.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r--Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp24
-rw-r--r--Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.h2
-rw-r--r--Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp16
-rw-r--r--Libraries/LibWeb/DOM/CanvasRenderingContext2D.h6
4 files changed, 48 insertions, 0 deletions
diff --git a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp
index 5af008f98a..64ae861ff1 100644
--- a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp
+++ b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.cpp
@@ -45,6 +45,8 @@ CanvasRenderingContext2DWrapper::CanvasRenderingContext2DWrapper(CanvasRendering
{
put_native_property("fillStyle", fill_style_getter, fill_style_setter);
put_native_function("fillRect", fill_rect, 4);
+ put_native_function("scale", scale, 2);
+ put_native_function("translate", translate, 2);
}
CanvasRenderingContext2DWrapper::~CanvasRenderingContext2DWrapper()
@@ -71,6 +73,28 @@ JS::Value CanvasRenderingContext2DWrapper::fill_rect(JS::Interpreter& interprete
return JS::js_undefined();
}
+JS::Value CanvasRenderingContext2DWrapper::scale(JS::Interpreter& interpreter)
+{
+ auto* impl = impl_from(interpreter);
+ if (!impl)
+ return {};
+ auto& arguments = interpreter.call_frame().arguments;
+ if (arguments.size() >= 2)
+ impl->scale(arguments[0].to_number().as_double(), arguments[1].to_number().as_double());
+ return JS::js_undefined();
+}
+
+JS::Value CanvasRenderingContext2DWrapper::translate(JS::Interpreter& interpreter)
+{
+ auto* impl = impl_from(interpreter);
+ if (!impl)
+ return {};
+ auto& arguments = interpreter.call_frame().arguments;
+ if (arguments.size() >= 2)
+ impl->translate(arguments[0].to_number().as_double(), arguments[1].to_number().as_double());
+ return JS::js_undefined();
+}
+
JS::Value CanvasRenderingContext2DWrapper::fill_style_getter(JS::Interpreter& interpreter)
{
auto* impl = impl_from(interpreter);
diff --git a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.h b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.h
index 8e8f1ad1a0..5ab2e0ce97 100644
--- a/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.h
+++ b/Libraries/LibWeb/Bindings/CanvasRenderingContext2DWrapper.h
@@ -43,6 +43,8 @@ private:
virtual const char* class_name() const override { return "CanvasRenderingContext2DWrapper"; }
static JS::Value fill_rect(JS::Interpreter&);
+ static JS::Value scale(JS::Interpreter&);
+ static JS::Value translate(JS::Interpreter&);
static JS::Value fill_style_getter(JS::Interpreter&);
static void fill_style_setter(JS::Interpreter&, JS::Value);
diff --git a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp
index 393e26d2d3..ca33cf2532 100644
--- a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp
+++ b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp
@@ -35,6 +35,22 @@ void CanvasRenderingContext2D::fill_rect(int x, int y, int width, int height)
did_draw(rect);
}
+void CanvasRenderingContext2D::scale(double sx, double sy)
+{
+ // FIXME: Actually do something with the scale factor!
+ dbg() << "CanvasRenderingContext2D::scale(): " << String::format("%f", sx) << ", " << String::format("%f", sy);
+ m_scale_x = sx;
+ m_scale_y = sy;
+}
+
+void CanvasRenderingContext2D::translate(double x, double y)
+{
+ // FIXME: Actually do something with the translation!
+ dbg() << "CanvasRenderingContext2D::translate(): " << String::format("%f", x) << ", " << String::format("%f", y);
+ m_translate_x = x;
+ m_translate_y = y;
+}
+
void CanvasRenderingContext2D::did_draw(const Gfx::Rect&)
{
// FIXME: Make use of the rect to reduce the invalidated area when possible.
diff --git a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.h b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.h
index ec84dfe815..b95c5fdf15 100644
--- a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.h
+++ b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.h
@@ -24,6 +24,8 @@ public:
String fill_style() const;
void fill_rect(int x, int y, int width, int height);
+ void scale(double sx, double sy);
+ void translate(double x, double y);
private:
explicit CanvasRenderingContext2D(HTMLCanvasElement&);
@@ -34,6 +36,10 @@ private:
WeakPtr<HTMLCanvasElement> m_element;
+ double m_scale_x { 1 };
+ double m_scale_y { 1 };
+ double m_translate_x { 0 };
+ double m_translate_y { 0 };
Gfx::Color m_fill_style;
};