From bfdb30c74a61b80336b6916efc3efb18b6874899 Mon Sep 17 00:00:00 2001 From: Igor Pissolati Date: Fri, 4 Nov 2022 22:56:42 -0300 Subject: LibWeb: Implement bare-bones `HTMLElement.dir` --- Userland/Libraries/LibWeb/HTML/AttributeNames.h | 1 + Userland/Libraries/LibWeb/HTML/HTMLElement.cpp | 18 ++++++++++++++++++ Userland/Libraries/LibWeb/HTML/HTMLElement.h | 9 +++++++++ Userland/Libraries/LibWeb/HTML/HTMLElement.idl | 1 + 4 files changed, 29 insertions(+) (limited to 'Userland/Libraries/LibWeb') diff --git a/Userland/Libraries/LibWeb/HTML/AttributeNames.h b/Userland/Libraries/LibWeb/HTML/AttributeNames.h index 061131938e..ab609ee5ba 100644 --- a/Userland/Libraries/LibWeb/HTML/AttributeNames.h +++ b/Userland/Libraries/LibWeb/HTML/AttributeNames.h @@ -55,6 +55,7 @@ namespace AttributeNames { __ENUMERATE_HTML_ATTRIBUTE(declare) \ __ENUMERATE_HTML_ATTRIBUTE(default_) \ __ENUMERATE_HTML_ATTRIBUTE(defer) \ + __ENUMERATE_HTML_ATTRIBUTE(dir) \ __ENUMERATE_HTML_ATTRIBUTE(direction) \ __ENUMERATE_HTML_ATTRIBUTE(dirname) \ __ENUMERATE_HTML_ATTRIBUTE(disabled) \ diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 5ad8a57195..6281f7f5d6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -53,6 +53,24 @@ void HTMLElement::visit_edges(Cell::Visitor& visitor) visitor.visit(m_dataset.ptr()); } +// https://html.spec.whatwg.org/multipage/dom.html#dom-dir +String HTMLElement::dir() const +{ + auto dir = attribute(HTML::AttributeNames::dir); +#define __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(keyword) \ + if (dir.equals_ignoring_case(#keyword##sv)) \ + return #keyword##sv; + ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTES +#undef __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE + + return {}; +} + +void HTMLElement::set_dir(String const& dir) +{ + MUST(set_attribute(HTML::AttributeNames::dir, dir)); +} + HTMLElement::ContentEditableState HTMLElement::content_editable_state() const { auto contenteditable = attribute(HTML::AttributeNames::contenteditable); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.h b/Userland/Libraries/LibWeb/HTML/HTMLElement.h index 76d7fe7350..b6b20092ae 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.h @@ -12,6 +12,12 @@ namespace Web::HTML { +// https://html.spec.whatwg.org/multipage/dom.html#attr-dir +#define ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTES \ + __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(ltr) \ + __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(rtl) \ + __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(auto) + class HTMLElement : public DOM::Element , public HTML::GlobalEventHandlers { @@ -22,6 +28,9 @@ public: String title() const { return attribute(HTML::AttributeNames::title); } + String dir() const; + void set_dir(String const&); + virtual bool is_editable() const final; String content_editable() const; WebIDL::ExceptionOr set_content_editable(String const&); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLElement.idl index 3ef611ee4c..9347592a86 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.idl @@ -7,6 +7,7 @@ interface HTMLElement : Element { [Reflect] attribute DOMString title; [Reflect] attribute DOMString lang; + attribute DOMString dir; [Reflect] attribute boolean hidden; -- cgit v1.2.3