LibWeb: Expose HTMLElement's content editable state

This commit is contained in:
Jelle Raaijmakers 2024-12-02 11:51:55 +01:00 committed by Andreas Kling
commit 6a85677f70
Notes: github-actions[bot] 2024-12-02 23:20:55 +00:00
3 changed files with 13 additions and 8 deletions

View file

@ -137,7 +137,7 @@ bool Document::query_command_enabled(FlyString const& command)
// NOTE: Commands can define additional conditions for being enabled, and currently the only condition mentioned in
// the spec is that certain commands must not be enabled if the editing host is in the plaintext-only state.
if (is<HTML::HTMLElement>(start_node_editing_host.ptr())
&& static_cast<HTML::HTMLElement&>(*start_node_editing_host).content_editable() == "plaintext-only"sv
&& static_cast<HTML::HTMLElement&>(*start_node_editing_host).content_editable_state() == HTML::ContentEditableState::PlaintextOnly
&& command.is_one_of(
Editing::CommandNames::backColor,
Editing::CommandNames::bold,

View file

@ -819,7 +819,9 @@ bool is_editing_host(GC::Ref<DOM::Node> node)
if (!is<HTML::HTMLElement>(*node))
return false;
auto const& html_element = static_cast<HTML::HTMLElement&>(*node);
return html_element.content_editable().is_one_of("true"sv, "plaintext-only"sv) || node->document().design_mode_enabled_state();
return html_element.content_editable_state() == HTML::ContentEditableState::True
|| html_element.content_editable_state() == HTML::ContentEditableState::PlaintextOnly
|| node->document().design_mode_enabled_state();
}
// https://w3c.github.io/editing/docs/execCommand/#element-with-inline-contents

View file

@ -20,6 +20,14 @@ namespace Web::HTML {
__ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(rtl) \
__ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(auto)
// https://html.spec.whatwg.org/#attr-contenteditable
enum class ContentEditableState {
True,
False,
PlaintextOnly,
Inherit,
};
class HTMLElement
: public DOM::Element
, public HTML::GlobalEventHandlers
@ -39,6 +47,7 @@ public:
virtual bool is_focusable() const override;
bool is_content_editable() const;
StringView content_editable() const;
ContentEditableState content_editable_state() const { return m_content_editable_state; }
WebIDL::ExceptionOr<void> set_content_editable(StringView);
String inner_text();
@ -106,12 +115,6 @@ private:
GC::Ptr<ElementInternals> m_attached_internals;
// https://html.spec.whatwg.org/#attr-contenteditable
enum class ContentEditableState {
True,
False,
PlaintextOnly,
Inherit,
};
ContentEditableState m_content_editable_state { ContentEditableState::Inherit };
// https://html.spec.whatwg.org/multipage/interaction.html#click-in-progress-flag