mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibWeb: Add the type field to DOM::Document
This patch adds the document type concept to documents and sets it in various places.
This commit is contained in:
parent
baac3ba60c
commit
6805baeedd
5 changed files with 19 additions and 5 deletions
|
@ -53,7 +53,6 @@ ExceptionOr<NonnullRefPtr<Document>> DOMImplementation::create_document(String c
|
||||||
// https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
|
// https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
|
||||||
NonnullRefPtr<Document> DOMImplementation::create_html_document(String const& title) const
|
NonnullRefPtr<Document> DOMImplementation::create_html_document(String const& title) const
|
||||||
{
|
{
|
||||||
// FIXME: This should specifically be a HTML document.
|
|
||||||
auto html_document = Document::create();
|
auto html_document = Document::create();
|
||||||
|
|
||||||
html_document->set_content_type("text/html");
|
html_document->set_content_type("text/html");
|
||||||
|
|
|
@ -45,6 +45,11 @@ class Document
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::DocumentWrapper;
|
using WrapperType = Bindings::DocumentWrapper;
|
||||||
|
|
||||||
|
enum class Type {
|
||||||
|
XML,
|
||||||
|
HTML
|
||||||
|
};
|
||||||
|
|
||||||
static NonnullRefPtr<Document> create(const AK::URL& url = "about:blank")
|
static NonnullRefPtr<Document> create(const AK::URL& url = "about:blank")
|
||||||
{
|
{
|
||||||
return adopt_ref(*new Document(url));
|
return adopt_ref(*new Document(url));
|
||||||
|
@ -208,6 +213,12 @@ public:
|
||||||
bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; }
|
bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; }
|
||||||
void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; }
|
void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; }
|
||||||
|
|
||||||
|
Type document_type() const { return m_type; }
|
||||||
|
void set_document_type(Type type) { m_type = type; }
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#xml-document
|
||||||
|
bool is_xml_document() const { return m_type == Type::XML; }
|
||||||
|
|
||||||
ExceptionOr<NonnullRefPtr<Node>> import_node(NonnullRefPtr<Node> node, bool deep);
|
ExceptionOr<NonnullRefPtr<Node>> import_node(NonnullRefPtr<Node> node, bool deep);
|
||||||
void adopt_node(Node&);
|
void adopt_node(Node&);
|
||||||
ExceptionOr<NonnullRefPtr<Node>> adopt_node_binding(NonnullRefPtr<Node>);
|
ExceptionOr<NonnullRefPtr<Node>> adopt_node_binding(NonnullRefPtr<Node>);
|
||||||
|
@ -411,6 +422,10 @@ private:
|
||||||
NonnullRefPtrVector<HTML::HTMLScriptElement> m_scripts_to_execute_as_soon_as_possible;
|
NonnullRefPtrVector<HTML::HTMLScriptElement> m_scripts_to_execute_as_soon_as_possible;
|
||||||
|
|
||||||
QuirksMode m_quirks_mode { QuirksMode::No };
|
QuirksMode m_quirks_mode { QuirksMode::No };
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#concept-document-type
|
||||||
|
Type m_type { Type::HTML };
|
||||||
|
|
||||||
bool m_editable { false };
|
bool m_editable { false };
|
||||||
|
|
||||||
WeakPtr<Element> m_focused_element;
|
WeakPtr<Element> m_focused_element;
|
||||||
|
|
|
@ -680,7 +680,7 @@ NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children)
|
||||||
document_copy->set_content_type(document_->content_type());
|
document_copy->set_content_type(document_->content_type());
|
||||||
document_copy->set_url(document_->url());
|
document_copy->set_url(document_->url());
|
||||||
document_copy->set_origin(document_->origin());
|
document_copy->set_origin(document_->origin());
|
||||||
// FIXME: Set type ("xml" or "html")
|
document_copy->set_document_type(document_->document_type());
|
||||||
document_copy->set_quirks_mode(document_->mode());
|
document_copy->set_quirks_mode(document_->mode());
|
||||||
copy = move(document_copy);
|
copy = move(document_copy);
|
||||||
} else if (is<DocumentType>(this)) {
|
} else if (is<DocumentType>(this)) {
|
||||||
|
|
|
@ -25,7 +25,8 @@ NonnullRefPtr<DOM::Document> DOMParser::parse_from_string(String const& string,
|
||||||
// 2. Switch on type:
|
// 2. Switch on type:
|
||||||
if (type == Bindings::DOMParserSupportedType::Text_Html) {
|
if (type == Bindings::DOMParserSupportedType::Text_Html) {
|
||||||
// -> "text/html"
|
// -> "text/html"
|
||||||
// FIXME: 1. Set document's type to "html".
|
// 1. Set document's type to "html".
|
||||||
|
document->set_document_type(DOM::Document::Type::HTML);
|
||||||
|
|
||||||
// 2. Create an HTML parser parser, associated with document.
|
// 2. Create an HTML parser parser, associated with document.
|
||||||
// 3. Place string into the input stream for parser. The encoding confidence is irrelevant.
|
// 3. Place string into the input stream for parser. The encoding confidence is irrelevant.
|
||||||
|
|
|
@ -24,8 +24,7 @@ DOM::Document& HTMLTemplateElement::appropriate_template_contents_owner_document
|
||||||
if (!document.associated_inert_template_document()) {
|
if (!document.associated_inert_template_document()) {
|
||||||
auto new_document = DOM::Document::create();
|
auto new_document = DOM::Document::create();
|
||||||
new_document->set_created_for_appropriate_template_contents(true);
|
new_document->set_created_for_appropriate_template_contents(true);
|
||||||
|
new_document->set_document_type(document.document_type());
|
||||||
// FIXME: If doc is an HTML document, mark new doc as an HTML document also.
|
|
||||||
|
|
||||||
document.set_associated_inert_template_document(new_document);
|
document.set_associated_inert_template_document(new_document);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue