mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
LibWeb: Generate HTMLImageElement bindings from IDL :^)
This commit is contained in:
parent
af51dc105a
commit
119dd2c541
6 changed files with 18 additions and 118 deletions
|
@ -156,7 +156,7 @@ JS_DEFINE_NATIVE_FUNCTION(CanvasRenderingContext2DWrapper::draw_image)
|
||||||
auto y = interpreter.argument(2).to_double(interpreter);
|
auto y = interpreter.argument(2).to_double(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
impl->draw_image(static_cast<const HTMLImageElementWrapper&>(*image_argument).node(), x, y);
|
impl->draw_image(static_cast<const HTMLImageElementWrapper&>(*image_argument).impl(), x, y);
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <AK/FlyString.h>
|
|
||||||
#include <AK/Function.h>
|
|
||||||
#include <LibJS/Interpreter.h>
|
|
||||||
#include <LibJS/Runtime/PrimitiveString.h>
|
|
||||||
#include <LibJS/Runtime/Value.h>
|
|
||||||
#include <LibWeb/Bindings/HTMLImageElementWrapper.h>
|
|
||||||
#include <LibWeb/DOM/HTMLImageElement.h>
|
|
||||||
|
|
||||||
namespace Web {
|
|
||||||
namespace Bindings {
|
|
||||||
|
|
||||||
HTMLImageElementWrapper::HTMLImageElementWrapper(JS::GlobalObject& global_object, HTMLImageElement& element)
|
|
||||||
: HTMLElementWrapper(global_object, element)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
HTMLImageElementWrapper::~HTMLImageElementWrapper()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
HTMLImageElement& HTMLImageElementWrapper::node()
|
|
||||||
{
|
|
||||||
return static_cast<HTMLImageElement&>(NodeWrapper::impl());
|
|
||||||
}
|
|
||||||
|
|
||||||
const HTMLImageElement& HTMLImageElementWrapper::node() const
|
|
||||||
{
|
|
||||||
return static_cast<const HTMLImageElement&>(NodeWrapper::impl());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <LibWeb/Bindings/HTMLElementWrapper.h>
|
|
||||||
|
|
||||||
namespace Web {
|
|
||||||
namespace Bindings {
|
|
||||||
|
|
||||||
class HTMLImageElementWrapper : public HTMLElementWrapper {
|
|
||||||
public:
|
|
||||||
HTMLImageElementWrapper(JS::GlobalObject&, HTMLImageElement&);
|
|
||||||
virtual ~HTMLImageElementWrapper() override;
|
|
||||||
|
|
||||||
HTMLImageElement& node();
|
|
||||||
const HTMLImageElement& node() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual const char* class_name() const override { return "HTMLImageElementWrapper"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@ set(SOURCES
|
||||||
Bindings/EventListenerWrapper.cpp
|
Bindings/EventListenerWrapper.cpp
|
||||||
Bindings/EventWrapper.cpp
|
Bindings/EventWrapper.cpp
|
||||||
Bindings/HTMLCanvasElementWrapper.cpp
|
Bindings/HTMLCanvasElementWrapper.cpp
|
||||||
Bindings/HTMLImageElementWrapper.cpp
|
|
||||||
Bindings/ImageDataWrapper.cpp
|
Bindings/ImageDataWrapper.cpp
|
||||||
Bindings/LocationObject.cpp
|
Bindings/LocationObject.cpp
|
||||||
Bindings/MouseEventWrapper.cpp
|
Bindings/MouseEventWrapper.cpp
|
||||||
|
@ -158,6 +157,7 @@ libweb_js_wrapper(Node)
|
||||||
libweb_js_wrapper(Document)
|
libweb_js_wrapper(Document)
|
||||||
libweb_js_wrapper(Element)
|
libweb_js_wrapper(Element)
|
||||||
libweb_js_wrapper(HTMLElement)
|
libweb_js_wrapper(HTMLElement)
|
||||||
|
libweb_js_wrapper(HTMLImageElement)
|
||||||
|
|
||||||
get_property(WRAPPER_SOURCES GLOBAL PROPERTY wrapper_sources)
|
get_property(WRAPPER_SOURCES GLOBAL PROPERTY wrapper_sources)
|
||||||
set(SOURCES ${SOURCES} ${WRAPPER_SOURCES})
|
set(SOURCES ${SOURCES} ${WRAPPER_SOURCES})
|
||||||
|
|
|
@ -407,17 +407,19 @@ void generate_implementation(const IDL::Interface& interface)
|
||||||
out() << "}";
|
out() << "}";
|
||||||
|
|
||||||
// Implementation: impl_from()
|
// Implementation: impl_from()
|
||||||
out() << "static " << interface.name << "* impl_from(JS::Interpreter& interpreter, JS::GlobalObject& global_object)";
|
if (!interface.attributes.is_empty() || !interface.functions.is_empty()) {
|
||||||
out() << "{";
|
out() << "static " << interface.name << "* impl_from(JS::Interpreter& interpreter, JS::GlobalObject& global_object)";
|
||||||
out() << " auto* this_object = interpreter.this_value(global_object).to_object(interpreter, global_object);";
|
out() << "{";
|
||||||
out() << " if (!this_object)";
|
out() << " auto* this_object = interpreter.this_value(global_object).to_object(interpreter, global_object);";
|
||||||
out() << " return {};";
|
out() << " if (!this_object)";
|
||||||
out() << " if (!this_object->inherits(\"" << wrapper_class << "\")) {";
|
out() << " return {};";
|
||||||
out() << " interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotA, \"" << interface.name << "\");";
|
out() << " if (!this_object->inherits(\"" << wrapper_class << "\")) {";
|
||||||
out() << " return nullptr;";
|
out() << " interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotA, \"" << interface.name << "\");";
|
||||||
out() << " }";
|
out() << " return nullptr;";
|
||||||
out() << " return &static_cast<" << wrapper_class << "*>(this_object)->impl();";
|
out() << " }";
|
||||||
out() << "}";
|
out() << " return &static_cast<" << wrapper_class << "*>(this_object)->impl();";
|
||||||
|
out() << "}";
|
||||||
|
}
|
||||||
|
|
||||||
auto generate_to_cpp = [&](auto& parameter, auto& js_name, auto& js_suffix, auto cpp_name, bool return_void = false) {
|
auto generate_to_cpp = [&](auto& parameter, auto& js_name, auto& js_suffix, auto cpp_name, bool return_void = false) {
|
||||||
auto generate_return = [&] {
|
auto generate_return = [&] {
|
||||||
|
|
3
Libraries/LibWeb/DOM/HTMLImageElement.idl
Normal file
3
Libraries/LibWeb/DOM/HTMLImageElement.idl
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
interface HTMLImageElement : HTMLElement {
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue