mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
HTML: Partially implement HTMLInputElement's selection{Start,End}
Now that the implementation is in FormAssociatedElement, the implementation in HTMLInputElement is effectively just a passthrough, with some minor differences to handle small behavioural quirks between the two (such as the difference in nullability of types).
This commit is contained in:
parent
62bf428a7f
commit
9f24176cac
Notes:
github-actions[bot]
2024-08-01 10:17:51 +00:00
Author: https://github.com/shannonbooth
Commit: 9f24176cac
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/876
7 changed files with 114 additions and 11 deletions
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Adam Hodgen <ant1441@gmail.com>
|
||||
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
|
||||
* Copyright (c) 2023, Shannon Booth <shannon@serenityos.org>
|
||||
* Copyright (c) 2023-2024, Shannon Booth <shannon@serenityos.org>
|
||||
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -2070,6 +2070,52 @@ WebIDL::ExceptionOr<void> HTMLInputElement::set_selection_range(u32 start, u32 e
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#textFieldSelection:dom-textarea/input-selectionstart-2
|
||||
WebIDL::ExceptionOr<void> HTMLInputElement::set_selection_start_for_bindings(Optional<WebIDL::UnsignedLong> const& value)
|
||||
{
|
||||
// 1. If this element is an input element, and selectionStart does not apply to this element, throw an
|
||||
// "InvalidStateError" DOMException.
|
||||
if (!selection_or_range_applies())
|
||||
return WebIDL::InvalidStateError::create(realm(), "setSelectionStart does not apply to this input type"_fly_string);
|
||||
|
||||
// NOTE: Steps continued below:
|
||||
return set_selection_start(value);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionstart
|
||||
Optional<WebIDL::UnsignedLong> HTMLInputElement::selection_start_for_bindings() const
|
||||
{
|
||||
// 1. If this element is an input element, and selectionStart does not apply to this element, return null.
|
||||
if (!selection_or_range_applies())
|
||||
return {};
|
||||
|
||||
// NOTE: Steps continued below:
|
||||
return selection_start();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#textFieldSelection:dom-textarea/input-selectionend-3
|
||||
WebIDL::ExceptionOr<void> HTMLInputElement::set_selection_end_for_bindings(Optional<WebIDL::UnsignedLong> const& value)
|
||||
{
|
||||
// 1. If this element is an input element, and selectionEnd does not apply to this element, throw an
|
||||
// "InvalidStateError" DOMException.
|
||||
if (!selection_or_range_applies())
|
||||
return WebIDL::InvalidStateError::create(realm(), "setSelectionEnd does not apply to this input type"_fly_string);
|
||||
|
||||
// NOTE: Steps continued below:
|
||||
return set_selection_end(value);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionend
|
||||
Optional<WebIDL::UnsignedLong> HTMLInputElement::selection_end_for_bindings() const
|
||||
{
|
||||
// 1. If this element is an input element, and selectionEnd does not apply to this element, return null.
|
||||
if (!selection_or_range_applies())
|
||||
return {};
|
||||
|
||||
// NOTE: Steps continued below:
|
||||
return selection_end();
|
||||
}
|
||||
|
||||
Optional<ARIA::Role> HTMLInputElement::default_role() const
|
||||
{
|
||||
// https://www.w3.org/TR/html-aria/#el-input-button
|
||||
|
@ -2198,6 +2244,21 @@ bool HTMLInputElement::has_input_activation_behavior() const
|
|||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#do-not-apply
|
||||
bool HTMLInputElement::selection_or_range_applies() const
|
||||
{
|
||||
switch (type_state()) {
|
||||
case TypeAttributeState::Text:
|
||||
case TypeAttributeState::Search:
|
||||
case TypeAttributeState::Telephone:
|
||||
case TypeAttributeState::URL:
|
||||
case TypeAttributeState::Password:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#the-input-element:event-change-2
|
||||
bool HTMLInputElement::change_event_applies() const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue