mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
LibWeb: Move DOM classes into the Web::DOM namespace
LibWeb keeps growing and the Web namespace is filling up fast. Let's put DOM stuff into Web::DOM, just like we already started doing with SVG stuff in Web::SVG.
This commit is contained in:
parent
96d13f75cf
commit
11ff9d0f17
178 changed files with 516 additions and 523 deletions
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include <LibWeb/DOM/CharacterData.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
CharacterData::CharacterData(Document& document, NodeType type, const String& data)
|
||||
: Node(document, type)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <AK/String.h>
|
||||
#include <LibWeb/DOM/Node.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class CharacterData : public Node {
|
||||
public:
|
||||
|
@ -49,6 +49,6 @@ private:
|
|||
|
||||
}
|
||||
|
||||
AK_BEGIN_TYPE_TRAITS(Web::CharacterData)
|
||||
static bool is_type(const Web::Node& node) { return node.is_character_data(); }
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DOM::CharacterData)
|
||||
static bool is_type(const Web::DOM::Node& node) { return node.is_character_data(); }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <LibWeb/DOM/Comment.h>
|
||||
#include <LibWeb/Layout/LayoutText.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
Comment::Comment(Document& document, const String& data)
|
||||
: CharacterData(document, NodeType::COMMENT_NODE, data)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <AK/FlyString.h>
|
||||
#include <LibWeb/DOM/CharacterData.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class Comment final : public CharacterData {
|
||||
public:
|
||||
|
@ -41,6 +41,6 @@ public:
|
|||
|
||||
}
|
||||
|
||||
AK_BEGIN_TYPE_TRAITS(Web::Comment)
|
||||
static bool is_type(const Web::Node& node) { return node.is_comment(); }
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DOM::Comment)
|
||||
static bool is_type(const Web::DOM::Node& node) { return node.is_comment(); }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
#include <LibWeb/SVG/TagNames.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
Document::Document(const URL& url)
|
||||
: ParentNode(*this, NodeType::DOCUMENT_NODE)
|
||||
|
@ -433,7 +433,7 @@ JS::Value Document::run_javascript(const StringView& source)
|
|||
|
||||
NonnullRefPtr<Element> Document::create_element(const String& tag_name)
|
||||
{
|
||||
return Web::create_element(*this, tag_name);
|
||||
return DOM::create_element(*this, tag_name);
|
||||
}
|
||||
|
||||
NonnullRefPtr<Text> Document::create_text_node(const String& data)
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include <LibWeb/DOM/NonElementParentNode.h>
|
||||
#include <LibWeb/DOM/ParentNode.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
enum class QuirksMode {
|
||||
No,
|
||||
|
@ -190,7 +190,6 @@ private:
|
|||
|
||||
}
|
||||
|
||||
AK_BEGIN_TYPE_TRAITS(Web::Document)
|
||||
static bool is_type(const Web::Node& node) { return node.is_document(); }
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DOM::Document)
|
||||
static bool is_type(const Web::DOM::Node& node) { return node.is_document(); }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <LibWeb/DOM/NonElementParentNode.h>
|
||||
#include <LibWeb/DOM/ParentNode.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class DocumentFragment
|
||||
: public ParentNode
|
||||
|
@ -46,6 +46,6 @@ public:
|
|||
|
||||
}
|
||||
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DocumentFragment)
|
||||
static bool is_type(const Web::Node& node) { return node.is_document_fragment(); }
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DOM::DocumentFragment)
|
||||
static bool is_type(const Web::DOM::Node& node) { return node.is_document_fragment(); }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include <LibWeb/DOM/DocumentType.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
DocumentType::DocumentType(Document& document)
|
||||
: Node(document, NodeType::DOCUMENT_TYPE_NODE)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <AK/FlyString.h>
|
||||
#include <LibWeb/DOM/Node.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class DocumentType final : public Node {
|
||||
public:
|
||||
|
@ -57,6 +57,6 @@ private:
|
|||
|
||||
}
|
||||
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DocumentType)
|
||||
static bool is_type(const Web::Node& node) { return node.type() == Web::NodeType::DOCUMENT_TYPE_NODE; }
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DOM::DocumentType)
|
||||
static bool is_type(const Web::DOM::Node& node) { return node.type() == Web::DOM::NodeType::DOCUMENT_TYPE_NODE; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include <LibWeb/Layout/LayoutTreeBuilder.h>
|
||||
#include <LibWeb/Parser/HTMLDocumentParser.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
Element::Element(Document& document, const FlyString& tag_name)
|
||||
: ParentNode(document, NodeType::ELEMENT_NODE)
|
||||
|
|
|
@ -34,9 +34,7 @@
|
|||
#include <LibWeb/DOM/TagNames.h>
|
||||
#include <LibWeb/Layout/LayoutNode.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
class LayoutNodeWithStyle;
|
||||
namespace Web::DOM {
|
||||
|
||||
class Element : public ParentNode {
|
||||
public:
|
||||
|
@ -101,6 +99,6 @@ private:
|
|||
|
||||
}
|
||||
|
||||
AK_BEGIN_TYPE_TRAITS(Web::Element)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element(); }
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DOM::Element)
|
||||
static bool is_type(const Web::DOM::Node& node) { return node.is_element(); }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||
#include <LibWeb/SVG/TagNames.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
NonnullRefPtr<Element> create_element(Document& document, const FlyString& tag_name)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
NonnullRefPtr<Element> create_element(Document&, const FlyString& tag_name);
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <AK/FlyString.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class Event
|
||||
: public RefCounted<Event>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <LibJS/Runtime/Function.h>
|
||||
#include <LibWeb/DOM/EventListener.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
JS::Function& EventListener::function()
|
||||
{
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class EventListener
|
||||
: public RefCounted<EventListener>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <LibWeb/DOM/EventListener.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
EventTarget::EventTarget()
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class EventTarget {
|
||||
AK_MAKE_NONCOPYABLE(EventTarget);
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class MouseEvent final : public Event {
|
||||
class MouseEvent final : public DOM::Event {
|
||||
public:
|
||||
using WrapperType = Bindings::MouseEventWrapper;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
|
||||
//#define EVENT_DEBUG
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
Node::Node(Document& document, NodeType type)
|
||||
: m_document(&document)
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/TreeNode.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
enum class NodeType : unsigned {
|
||||
INVALID = 0,
|
||||
|
@ -47,15 +47,6 @@ enum class NodeType : unsigned {
|
|||
DOCUMENT_FRAGMENT_NODE = 11,
|
||||
};
|
||||
|
||||
class Document;
|
||||
class Element;
|
||||
class HTMLElement;
|
||||
class HTMLAnchorElement;
|
||||
class ParentNode;
|
||||
class LayoutNode;
|
||||
class StyleResolver;
|
||||
class StyleProperties;
|
||||
|
||||
class Node
|
||||
: public TreeNode<Node>
|
||||
, public EventTarget
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/TreeNode.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
template<typename NodeType>
|
||||
class NonElementParentNode {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include <LibWeb/DOM/ParentNode.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
void ParentNode::remove_all_children()
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include <LibWeb/DOM/Node.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class ParentNode : public Node {
|
||||
public:
|
||||
|
@ -60,6 +60,6 @@ inline void ParentNode::for_each_child(Callback callback)
|
|||
|
||||
}
|
||||
|
||||
AK_BEGIN_TYPE_TRAITS(Web::ParentNode)
|
||||
static bool is_type(const Web::Node& node) { return node.is_parent_node(); }
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DOM::ParentNode)
|
||||
static bool is_type(const Web::DOM::Node& node) { return node.is_parent_node(); }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/Layout/LayoutText.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
Text::Text(Document& document, const String& data)
|
||||
: CharacterData(document, NodeType::TEXT_NODE, data)
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <AK/String.h>
|
||||
#include <LibWeb/DOM/CharacterData.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class Text final : public CharacterData {
|
||||
public:
|
||||
|
@ -45,6 +45,6 @@ private:
|
|||
|
||||
}
|
||||
|
||||
AK_BEGIN_TYPE_TRAITS(Web::Text)
|
||||
static bool is_type(const Web::Node& node) { return node.is_text(); }
|
||||
AK_BEGIN_TYPE_TRAITS(Web::DOM::Text)
|
||||
static bool is_type(const Web::DOM::Node& node) { return node.is_text(); }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <LibWeb/DOM/Timer.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
NonnullRefPtr<Timer> Timer::create_interval(Window& window, int milliseconds, JS::Function& callback)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class Timer final : public RefCounted<Timer> {
|
||||
public:
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include <LibWeb/Frame/Frame.h>
|
||||
#include <LibWeb/PageView.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
NonnullRefPtr<Window> Window::create_with_document(Document& document)
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::DOM {
|
||||
|
||||
class Window : public RefCounted<Window> {
|
||||
public:
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
namespace Web {
|
||||
|
||||
XMLHttpRequest::XMLHttpRequest(Window& window)
|
||||
XMLHttpRequest::XMLHttpRequest(DOM::Window& window)
|
||||
: m_window(window)
|
||||
{
|
||||
}
|
||||
|
@ -78,22 +78,22 @@ void XMLHttpRequest::send()
|
|||
return;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).m_response = data;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).set_ready_state(ReadyState::Done);
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(Event::create("load"));
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(DOM::Event::create("load"));
|
||||
},
|
||||
[weak_this = make_weak_ptr()](auto& error) {
|
||||
if (!weak_this)
|
||||
return;
|
||||
dbg() << "XHR failed to load: " << error;
|
||||
const_cast<XMLHttpRequest&>(*weak_this).set_ready_state(ReadyState::Done);
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(Event::create("error"));
|
||||
const_cast<XMLHttpRequest&>(*weak_this).dispatch_event(DOM::Event::create("error"));
|
||||
});
|
||||
}
|
||||
|
||||
void XMLHttpRequest::dispatch_event(NonnullRefPtr<Event> event)
|
||||
void XMLHttpRequest::dispatch_event(NonnullRefPtr<DOM::Event> event)
|
||||
{
|
||||
for (auto& listener : listeners()) {
|
||||
if (listener.event_name == event->type()) {
|
||||
auto& function = const_cast<EventListener&>(*listener.listener).function();
|
||||
auto& function = const_cast<DOM::EventListener&>(*listener.listener).function();
|
||||
auto& global_object = function.global_object();
|
||||
auto* this_value = wrap(global_object, *this);
|
||||
JS::MarkedValueList arguments(global_object.heap());
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace Web {
|
|||
class XMLHttpRequest final
|
||||
: public RefCounted<XMLHttpRequest>
|
||||
, public Weakable<XMLHttpRequest>
|
||||
, public EventTarget
|
||||
, public DOM::EventTarget
|
||||
, public Bindings::Wrappable {
|
||||
public:
|
||||
enum class ReadyState {
|
||||
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
using WrapperType = Bindings::XMLHttpRequestWrapper;
|
||||
|
||||
static NonnullRefPtr<XMLHttpRequest> create(Window& window) { return adopt(*new XMLHttpRequest(window)); }
|
||||
static NonnullRefPtr<XMLHttpRequest> create(DOM::Window& window) { return adopt(*new XMLHttpRequest(window)); }
|
||||
|
||||
virtual ~XMLHttpRequest() override;
|
||||
|
||||
|
@ -65,13 +65,13 @@ public:
|
|||
private:
|
||||
virtual void ref_event_target() override { ref(); }
|
||||
virtual void unref_event_target() override { unref(); }
|
||||
virtual void dispatch_event(NonnullRefPtr<Event>) override;
|
||||
virtual void dispatch_event(NonnullRefPtr<DOM::Event>) override;
|
||||
|
||||
void set_ready_state(ReadyState);
|
||||
|
||||
explicit XMLHttpRequest(Window&);
|
||||
explicit XMLHttpRequest(DOM::Window&);
|
||||
|
||||
NonnullRefPtr<Window> m_window;
|
||||
NonnullRefPtr<DOM::Window> m_window;
|
||||
|
||||
ReadyState m_ready_state { ReadyState::Unsent };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue