diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index c5c6670308d..f2c498ed4db 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -6306,9 +6306,12 @@ GC::Ptr Document::cursor_position() const return nullptr; Optional target {}; - if (is(*focused_element)) - target = static_cast(*focused_element); - else if (is(*focused_element)) + if (auto const* input_element = as_if(*focused_element)) { + // Some types of tags shouldn't have a cursor, like buttons + if (!input_element->can_have_text_editing_cursor()) + return nullptr; + target = *input_element; + } else if (is(*focused_element)) target = static_cast(*focused_element); if (target.has_value()) diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 4d37c235398..46bf0889129 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1594,6 +1594,14 @@ WebIDL::ExceptionOr HTMLInputElement::set_type(String const& type) return set_attribute(HTML::AttributeNames::type, type); } +bool HTMLInputElement::can_have_text_editing_cursor() const +{ + if (first_is_one_of(type_state(), TypeAttributeState::SubmitButton, TypeAttributeState::ResetButton, TypeAttributeState::Button)) + return false; + + return true; +} + // https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-simple-colour static bool is_valid_simple_color(StringView value) { diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.h b/Libraries/LibWeb/HTML/HTMLInputElement.h index 5cb353eaec5..1237ec81119 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -106,6 +106,8 @@ public: bool indeterminate() const { return m_indeterminate; } void set_indeterminate(bool); + bool can_have_text_editing_cursor() const; + GC::Ptr list() const; void did_pick_color(Optional picked_color, ColorPickerUpdateState state);