mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
LibWeb: Implement quirks mode detection
This allows us to determine which mode to render the page in. Exposes "doctype" and "compatMode" on Document. Exposes "name", "publicId" and "systemId" on DocumentType.
This commit is contained in:
parent
a5ecb9bd6b
commit
19d6884529
13 changed files with 196 additions and 6 deletions
|
@ -477,4 +477,20 @@ void Document::adopt_node(Node& subtree_root)
|
|||
});
|
||||
}
|
||||
|
||||
const DocumentType* Document::doctype() const
|
||||
{
|
||||
return first_child_of_type<DocumentType>();
|
||||
}
|
||||
|
||||
const String& Document::compat_mode() const
|
||||
{
|
||||
static String back_compat = "BackCompat";
|
||||
static String css1_compat = "CSS1Compat";
|
||||
|
||||
if (m_quirks_mode == QuirksMode::Yes)
|
||||
return back_compat;
|
||||
|
||||
return css1_compat;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,6 +43,12 @@
|
|||
|
||||
namespace Web {
|
||||
|
||||
enum class QuirksMode {
|
||||
No,
|
||||
Limited,
|
||||
Yes
|
||||
};
|
||||
|
||||
class Document
|
||||
: public ParentNode
|
||||
, public NonElementParentNode<Document> {
|
||||
|
@ -142,11 +148,15 @@ public:
|
|||
void add_script_to_execute_as_soon_as_possible(Badge<HTMLScriptElement>, HTMLScriptElement&);
|
||||
NonnullRefPtrVector<HTMLScriptElement> take_scripts_to_execute_as_soon_as_possible(Badge<HTMLDocumentParser>);
|
||||
|
||||
bool in_quirks_mode() const { return m_quirks_mode; }
|
||||
void set_quirks_mode(bool mode) { m_quirks_mode = mode; }
|
||||
QuirksMode mode() const { return m_quirks_mode; }
|
||||
bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; }
|
||||
void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; }
|
||||
|
||||
void adopt_node(Node&);
|
||||
|
||||
const DocumentType* doctype() const;
|
||||
const String& compat_mode() const;
|
||||
|
||||
private:
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
|
||||
|
||||
|
@ -175,7 +185,7 @@ private:
|
|||
NonnullRefPtrVector<HTMLScriptElement> m_scripts_to_execute_when_parsing_has_finished;
|
||||
NonnullRefPtrVector<HTMLScriptElement> m_scripts_to_execute_as_soon_as_possible;
|
||||
|
||||
bool m_quirks_mode { false };
|
||||
QuirksMode m_quirks_mode { QuirksMode::No };
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
@ -6,6 +6,9 @@ interface Document : Node {
|
|||
ArrayFromVector querySelectorAll(DOMString selectors);
|
||||
Element createElement(DOMString tagName);
|
||||
|
||||
readonly attribute DOMString compatMode;
|
||||
readonly attribute DocumentType? doctype;
|
||||
|
||||
readonly attribute HTMLElement? body;
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ namespace Web {
|
|||
|
||||
class DocumentType final : public Node {
|
||||
public:
|
||||
using WrapperType = Bindings::DocumentTypeWrapper;
|
||||
|
||||
explicit DocumentType(Document&);
|
||||
virtual ~DocumentType() override;
|
||||
|
||||
|
@ -41,8 +43,16 @@ public:
|
|||
const String& name() const { return m_name; }
|
||||
void set_name(const String& name) { m_name = name; }
|
||||
|
||||
const String& public_id() const { return m_public_id; }
|
||||
void set_public_id(const String& public_id) { m_public_id = public_id; }
|
||||
|
||||
const String& system_id() const { return m_system_id; }
|
||||
void set_system_id(const String& system_id) { m_system_id = system_id; }
|
||||
|
||||
private:
|
||||
String m_name;
|
||||
String m_public_id;
|
||||
String m_system_id;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
7
Libraries/LibWeb/DOM/DocumentType.idl
Normal file
7
Libraries/LibWeb/DOM/DocumentType.idl
Normal file
|
@ -0,0 +1,7 @@
|
|||
interface DocumentType : Node {
|
||||
|
||||
readonly attribute DOMString name;
|
||||
readonly attribute DOMString publicId;
|
||||
readonly attribute DOMString systemId;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue