Browse Source

LibWeb: Add HTMLElement::is_content_editable()

Aliaksandr Kalenik 1 year ago
parent
commit
e3c75d7b6f

+ 1 - 0
Tests/LibWeb/Text/expected/HTML/HTMLElement-isContentEditable.txt

@@ -0,0 +1 @@
+  true

+ 7 - 0
Tests/LibWeb/Text/input/HTML/HTMLElement-isContentEditable.html

@@ -0,0 +1,7 @@
+<script src="../include.js"></script>
+<div contenteditable="true" id="contenteditable"></div>
+<script>
+    test(() => {
+        println(document.getElementById("contenteditable").isContentEditable);
+    });
+</script>

+ 8 - 0
Userland/Libraries/LibWeb/HTML/HTMLElement.cpp

@@ -98,6 +98,14 @@ bool HTMLElement::is_focusable() const
     return m_content_editable_state == ContentEditableState::True;
     return m_content_editable_state == ContentEditableState::True;
 }
 }
 
 
+// https://html.spec.whatwg.org/multipage/interaction.html#dom-iscontenteditable
+bool HTMLElement::is_content_editable() const
+{
+    // The isContentEditable IDL attribute, on getting, must return true if the element is either an editing host or
+    // editable, and false otherwise.
+    return is_editable();
+}
+
 StringView HTMLElement::content_editable() const
 StringView HTMLElement::content_editable() const
 {
 {
     switch (m_content_editable_state) {
     switch (m_content_editable_state) {

+ 1 - 0
Userland/Libraries/LibWeb/HTML/HTMLElement.h

@@ -35,6 +35,7 @@ public:
 
 
     virtual bool is_editable() const final;
     virtual bool is_editable() const final;
     virtual bool is_focusable() const override;
     virtual bool is_focusable() const override;
+    bool is_content_editable() const;
     StringView content_editable() const;
     StringView content_editable() const;
     WebIDL::ExceptionOr<void> set_content_editable(StringView);
     WebIDL::ExceptionOr<void> set_content_editable(StringView);
 
 

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLElement.idl

@@ -53,7 +53,7 @@ HTMLElement includes HTMLOrSVGElement;
 interface mixin ElementContentEditable {
 interface mixin ElementContentEditable {
     [CEReactions] attribute DOMString contentEditable;
     [CEReactions] attribute DOMString contentEditable;
     // FIXME: [CEReactions] attribute DOMString enterKeyHint;
     // FIXME: [CEReactions] attribute DOMString enterKeyHint;
-    // FIXME: readonly attribute boolean isContentEditable;
+    readonly attribute boolean isContentEditable;
     // FIXME: [CEReactions] attribute DOMString inputMode;
     // FIXME: [CEReactions] attribute DOMString inputMode;
 };
 };