mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
LibWeb: Don't place cursor on certain <input> elements
For example, button inputs shouldn't have a cursor displayed in their text since they're not editable, and are not meant to be editable. Fixes #4140 Co-authored-by: Sam Atkins <sam@ladybird.org>
This commit is contained in:
parent
17f14a277b
commit
c52c05555b
Notes:
github-actions[bot]
2025-06-02 10:39:46 +00:00
Author: https://github.com/gotlougit
Commit: c52c05555b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4764
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 16 additions and 3 deletions
|
@ -6306,9 +6306,12 @@ GC::Ptr<DOM::Position> Document::cursor_position() const
|
|||
return nullptr;
|
||||
|
||||
Optional<HTML::FormAssociatedTextControlElement const&> target {};
|
||||
if (is<HTML::HTMLInputElement>(*focused_element))
|
||||
target = static_cast<HTML::HTMLInputElement const&>(*focused_element);
|
||||
else if (is<HTML::HTMLTextAreaElement>(*focused_element))
|
||||
if (auto const* input_element = as_if<HTML::HTMLInputElement>(*focused_element)) {
|
||||
// Some types of <input> tags shouldn't have a cursor, like buttons
|
||||
if (!input_element->can_have_text_editing_cursor())
|
||||
return nullptr;
|
||||
target = *input_element;
|
||||
} else if (is<HTML::HTMLTextAreaElement>(*focused_element))
|
||||
target = static_cast<HTML::HTMLTextAreaElement const&>(*focused_element);
|
||||
|
||||
if (target.has_value())
|
||||
|
|
|
@ -1594,6 +1594,14 @@ WebIDL::ExceptionOr<void> 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)
|
||||
{
|
||||
|
|
|
@ -106,6 +106,8 @@ public:
|
|||
bool indeterminate() const { return m_indeterminate; }
|
||||
void set_indeterminate(bool);
|
||||
|
||||
bool can_have_text_editing_cursor() const;
|
||||
|
||||
GC::Ptr<HTMLDataListElement const> list() const;
|
||||
|
||||
void did_pick_color(Optional<Color> picked_color, ColorPickerUpdateState state);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue