Skip to content

Commit

Permalink
LibWeb: Expose HTMLElement's content editable state
Browse files Browse the repository at this point in the history
  • Loading branch information
gmta committed Dec 2, 2024
1 parent 1681cf5 commit ef7fb78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Libraries/LibWeb/Editing/ExecCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion Libraries/LibWeb/Editing/Internal/Algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions Libraries/LibWeb/HTML/HTMLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,6 +47,7 @@ class HTMLElement
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();
Expand Down Expand Up @@ -106,12 +115,6 @@ class HTMLElement
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
Expand Down

0 comments on commit ef7fb78

Please sign in to comment.