mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibWeb: Add CanvasRenderingContext2D.canvas
This commit is contained in:
parent
abb33d425e
commit
a0f3e3c50e
Notes:
sideshowbarker
2024-07-19 06:17:54 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/a0f3e3c50e6 Pull-request: https://github.com/SerenityOS/serenity/pull/2314 Reviewed-by: https://github.com/awesomekling
3 changed files with 28 additions and 11 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <LibWeb/Bindings/HTMLImageElementWrapper.h>
|
||||
#include <LibWeb/Bindings/ImageDataWrapper.h>
|
||||
#include <LibWeb/DOM/CanvasRenderingContext2D.h>
|
||||
#include <LibWeb/DOM/HTMLCanvasElement.h>
|
||||
#include <LibWeb/DOM/HTMLImageElement.h>
|
||||
#include <LibWeb/DOM/ImageData.h>
|
||||
|
||||
|
@ -50,14 +51,11 @@ CanvasRenderingContext2DWrapper::CanvasRenderingContext2DWrapper(CanvasRendering
|
|||
: Wrapper(*interpreter().global_object().object_prototype())
|
||||
, m_impl(impl)
|
||||
{
|
||||
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);
|
||||
put_native_property("strokeStyle", stroke_style_getter, stroke_style_setter);
|
||||
put_native_function("strokeRect", stroke_rect, 4);
|
||||
put_native_function("drawImage", draw_image, 3);
|
||||
|
||||
put_native_function("beginPath", begin_path, 0);
|
||||
put_native_function("closePath", close_path, 0);
|
||||
put_native_function("stroke", stroke, 0);
|
||||
|
@ -65,11 +63,13 @@ CanvasRenderingContext2DWrapper::CanvasRenderingContext2DWrapper(CanvasRendering
|
|||
put_native_function("moveTo", move_to, 2);
|
||||
put_native_function("lineTo", line_to, 2);
|
||||
put_native_function("quadraticCurveTo", quadratic_curve_to, 4);
|
||||
|
||||
put_native_function("createImageData", create_image_data, 1);
|
||||
put_native_function("putImageData", put_image_data, 3);
|
||||
|
||||
put_native_property("fillStyle", fill_style_getter, fill_style_setter);
|
||||
put_native_property("strokeStyle", stroke_style_getter, stroke_style_setter);
|
||||
put_native_property("lineWidth", line_width_getter, line_width_setter);
|
||||
put_native_property("canvas", canvas_getter, nullptr);
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DWrapper::~CanvasRenderingContext2DWrapper()
|
||||
|
@ -397,5 +397,16 @@ JS::Value CanvasRenderingContext2DWrapper::put_image_data(JS::Interpreter& inter
|
|||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS::Value CanvasRenderingContext2DWrapper::canvas_getter(JS::Interpreter& interpreter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter);
|
||||
if (!impl)
|
||||
return {};
|
||||
auto* element = impl->element();
|
||||
if (!element)
|
||||
return JS::js_null();
|
||||
return wrap(interpreter.heap(), *element);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,12 +47,6 @@ private:
|
|||
static JS::Value draw_image(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);
|
||||
static JS::Value stroke_style_getter(JS::Interpreter&);
|
||||
static void stroke_style_setter(JS::Interpreter&, JS::Value);
|
||||
static JS::Value line_width_getter(JS::Interpreter&);
|
||||
static void line_width_setter(JS::Interpreter&, JS::Value);
|
||||
static JS::Value begin_path(JS::Interpreter&);
|
||||
static JS::Value close_path(JS::Interpreter&);
|
||||
static JS::Value stroke(JS::Interpreter&);
|
||||
|
@ -60,10 +54,20 @@ private:
|
|||
static JS::Value move_to(JS::Interpreter&);
|
||||
static JS::Value line_to(JS::Interpreter&);
|
||||
static JS::Value quadratic_curve_to(JS::Interpreter&);
|
||||
|
||||
static JS::Value create_image_data(JS::Interpreter&);
|
||||
static JS::Value put_image_data(JS::Interpreter&);
|
||||
|
||||
static JS::Value fill_style_getter(JS::Interpreter&);
|
||||
static void fill_style_setter(JS::Interpreter&, JS::Value);
|
||||
|
||||
static JS::Value stroke_style_getter(JS::Interpreter&);
|
||||
static void stroke_style_setter(JS::Interpreter&, JS::Value);
|
||||
|
||||
static void line_width_setter(JS::Interpreter&, JS::Value);
|
||||
static JS::Value line_width_getter(JS::Interpreter&);
|
||||
|
||||
static JS::Value canvas_getter(JS::Interpreter&);
|
||||
|
||||
NonnullRefPtr<CanvasRenderingContext2D> m_impl;
|
||||
};
|
||||
|
||||
|
|
|
@ -77,6 +77,8 @@ public:
|
|||
RefPtr<ImageData> create_image_data(JS::GlobalObject&, int width, int height) const;
|
||||
void put_image_data(const ImageData&, float x, float y);
|
||||
|
||||
HTMLCanvasElement* element() { return m_element; }
|
||||
|
||||
private:
|
||||
explicit CanvasRenderingContext2D(HTMLCanvasElement&);
|
||||
|
||||
|
|
Loading…
Reference in a new issue