LibWeb: Add HTMLElement wrapper
Expose the "title" attribute just to expose something. :^)
This commit is contained in:
parent
244b243d22
commit
1914f52371
Notes:
sideshowbarker
2024-07-19 05:29:36 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/1914f52371b
10 changed files with 36 additions and 14 deletions
|
@ -39,7 +39,7 @@ namespace Web {
|
|||
namespace Bindings {
|
||||
|
||||
HTMLCanvasElementWrapper::HTMLCanvasElementWrapper(JS::GlobalObject& global_object, HTMLCanvasElement& element)
|
||||
: ElementWrapper(global_object, element)
|
||||
: HTMLElementWrapper(global_object, element)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/ElementWrapper.h>
|
||||
#include <LibWeb/Bindings/HTMLElementWrapper.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Bindings {
|
||||
|
||||
class HTMLCanvasElementWrapper : public ElementWrapper {
|
||||
class HTMLCanvasElementWrapper : public HTMLElementWrapper {
|
||||
public:
|
||||
HTMLCanvasElementWrapper(JS::GlobalObject&, HTMLCanvasElement&);
|
||||
virtual void initialize(JS::Interpreter&, JS::GlobalObject&) override;
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Web {
|
|||
namespace Bindings {
|
||||
|
||||
HTMLImageElementWrapper::HTMLImageElementWrapper(JS::GlobalObject& global_object, HTMLImageElement& element)
|
||||
: ElementWrapper(global_object, element)
|
||||
: HTMLElementWrapper(global_object, element)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/ElementWrapper.h>
|
||||
#include <LibWeb/Bindings/HTMLElementWrapper.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Bindings {
|
||||
|
||||
class HTMLImageElementWrapper : public ElementWrapper {
|
||||
class HTMLImageElementWrapper : public HTMLElementWrapper {
|
||||
public:
|
||||
HTMLImageElementWrapper(JS::GlobalObject&, HTMLImageElement&);
|
||||
virtual ~HTMLImageElementWrapper() override;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <LibWeb/Bindings/DocumentWrapper.h>
|
||||
#include <LibWeb/Bindings/HTMLCanvasElementWrapper.h>
|
||||
#include <LibWeb/Bindings/HTMLImageElementWrapper.h>
|
||||
#include <LibWeb/Bindings/HTMLElementWrapper.h>
|
||||
#include <LibWeb/Bindings/NodeWrapper.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/HTMLCanvasElement.h>
|
||||
|
@ -45,6 +46,8 @@ NodeWrapper* wrap(JS::Heap& heap, Node& node)
|
|||
return static_cast<NodeWrapper*>(wrap_impl(heap, to<HTMLCanvasElement>(node)));
|
||||
if (is<HTMLImageElement>(node))
|
||||
return static_cast<NodeWrapper*>(wrap_impl(heap, to<HTMLImageElement>(node)));
|
||||
if (is<HTMLElement>(node))
|
||||
return static_cast<NodeWrapper*>(wrap_impl(heap, to<HTMLElement>(node)));
|
||||
if (is<Element>(node))
|
||||
return static_cast<NodeWrapper*>(wrap_impl(heap, to<Element>(node)));
|
||||
return static_cast<NodeWrapper*>(wrap_impl(heap, node));
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
virtual bool is_node_wrapper() const { return false; }
|
||||
virtual bool is_document_wrapper() const { return false; }
|
||||
virtual bool is_element_wrapper() const { return false; }
|
||||
virtual bool is_htmlelement_wrapper() const { return false; }
|
||||
|
||||
protected:
|
||||
explicit Wrapper(Object& prototype)
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
set(SOURCES
|
||||
Bindings/CanvasRenderingContext2DWrapper.cpp
|
||||
Bindings/DocumentWrapper.cpp
|
||||
Bindings/DocumentWrapper.h
|
||||
Bindings/ElementWrapper.cpp
|
||||
Bindings/ElementWrapper.h
|
||||
Bindings/EventListenerWrapper.cpp
|
||||
Bindings/EventTargetWrapper.cpp
|
||||
Bindings/EventTargetWrapper.h
|
||||
Bindings/EventWrapper.cpp
|
||||
Bindings/HTMLCanvasElementWrapper.cpp
|
||||
Bindings/HTMLImageElementWrapper.cpp
|
||||
|
@ -14,8 +8,6 @@ set(SOURCES
|
|||
Bindings/LocationObject.cpp
|
||||
Bindings/MouseEventWrapper.cpp
|
||||
Bindings/NavigatorObject.cpp
|
||||
Bindings/NodeWrapper.cpp
|
||||
Bindings/NodeWrapper.h
|
||||
Bindings/NodeWrapperFactory.cpp
|
||||
Bindings/WindowObject.cpp
|
||||
Bindings/Wrappable.cpp
|
||||
|
@ -128,7 +120,19 @@ set(GENERATED_SOURCES
|
|||
../../Services/ProtocolServer/ProtocolServerEndpoint.h
|
||||
)
|
||||
|
||||
set_property(GLOBAL PROPERTY wrapper_sources)
|
||||
function(add_wrapper_sources)
|
||||
get_property(tmp GLOBAL PROPERTY wrapper_sources)
|
||||
foreach(arg ${ARGV})
|
||||
set(tmp ${tmp}
|
||||
${arg}
|
||||
)
|
||||
endforeach()
|
||||
set_property(GLOBAL PROPERTY wrapper_sources "${tmp}")
|
||||
endfunction(add_wrapper_sources)
|
||||
|
||||
function(libweb_js_wrapper class)
|
||||
add_wrapper_sources(Bindings/${class}Wrapper.cpp Bindings/${class}Wrapper.h)
|
||||
add_custom_command(
|
||||
OUTPUT Bindings/${class}Wrapper.h
|
||||
COMMAND /bin/mkdir -p Bindings
|
||||
|
@ -146,12 +150,17 @@ function(libweb_js_wrapper class)
|
|||
MAIN_DEPENDENCY DOM/${class}.idl
|
||||
)
|
||||
add_custom_target(generate_${class}Wrapper.h DEPENDS Bindings/${class}Wrapper.h)
|
||||
add_custom_target(generate_${class}Wrapper.cpp DEPENDS Bindings/${class}Wrapper.cpp)
|
||||
endfunction()
|
||||
|
||||
libweb_js_wrapper(EventTarget)
|
||||
libweb_js_wrapper(Node)
|
||||
libweb_js_wrapper(Document)
|
||||
libweb_js_wrapper(Element)
|
||||
libweb_js_wrapper(HTMLElement)
|
||||
|
||||
get_property(WRAPPER_SOURCES GLOBAL PROPERTY wrapper_sources)
|
||||
set(SOURCES ${SOURCES} ${WRAPPER_SOURCES})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT CSS/PropertyID.h
|
||||
|
|
|
@ -32,10 +32,13 @@ namespace Web {
|
|||
|
||||
class HTMLElement : public Element {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLElementWrapper;
|
||||
|
||||
HTMLElement(Document&, const FlyString& tag_name);
|
||||
virtual ~HTMLElement() override;
|
||||
|
||||
String title() const { return attribute(HTML::AttributeNames::title); }
|
||||
void set_title(const String& value) { set_attribute(HTML::AttributeNames::title, value); }
|
||||
|
||||
private:
|
||||
virtual bool is_html_element() const final { return true; }
|
||||
|
|
5
Libraries/LibWeb/DOM/HTMLElement.idl
Normal file
5
Libraries/LibWeb/DOM/HTMLElement.idl
Normal file
|
@ -0,0 +1,5 @@
|
|||
interface HTMLElement : Element {
|
||||
|
||||
attribute DOMString title;
|
||||
|
||||
}
|
|
@ -81,6 +81,7 @@ class EventWrapper;
|
|||
class EventListenerWrapper;
|
||||
class EventTargetWrapper;
|
||||
class HTMLCanvasElementWrapper;
|
||||
class HTMLElementWrapper;
|
||||
class HTMLImageElementWrapper;
|
||||
class ImageDataWrapper;
|
||||
class LocationObject;
|
||||
|
|
Loading…
Add table
Reference in a new issue