mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Implement the form associated element clear algorithm
This is a method defined in the WebDriver spec, but requires access to a bunch of private fields in these classes, so this is implemented in the same manner as the reset algorithm.
This commit is contained in:
parent
fadb14d31d
commit
516f5f7008
Notes:
github-actions[bot]
2024-10-12 13:02:37 +00:00
Author: https://github.com/trflynn89
Commit: 516f5f7008
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1727
Reviewed-by: https://github.com/gmta
8 changed files with 75 additions and 1 deletions
|
@ -166,6 +166,14 @@ void FormAssociatedElement::reset_form_owner()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/webdriver/#dfn-clear-algorithm
|
||||||
|
void FormAssociatedElement::clear_algorithm()
|
||||||
|
{
|
||||||
|
// When the clear algorithm is invoked for an element that does not define its own clear algorithm, its reset
|
||||||
|
// algorithm must be invoked instead.
|
||||||
|
reset_algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-formaction
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-formaction
|
||||||
String FormAssociatedElement::form_action() const
|
String FormAssociatedElement::form_action() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,6 +98,8 @@ public:
|
||||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-reset-control
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-reset-control
|
||||||
virtual void reset_algorithm() {};
|
virtual void reset_algorithm() {};
|
||||||
|
|
||||||
|
virtual void clear_algorithm();
|
||||||
|
|
||||||
String form_action() const;
|
String form_action() const;
|
||||||
WebIDL::ExceptionOr<void> set_form_action(String const&);
|
WebIDL::ExceptionOr<void> set_form_action(String const&);
|
||||||
|
|
||||||
|
|
|
@ -1528,7 +1528,8 @@ void HTMLInputElement::reset_algorithm()
|
||||||
m_checked = has_attribute(AttributeNames::checked);
|
m_checked = has_attribute(AttributeNames::checked);
|
||||||
|
|
||||||
// empty the list of selected files,
|
// empty the list of selected files,
|
||||||
m_selected_files = FileAPI::FileList::create(realm());
|
if (m_selected_files)
|
||||||
|
m_selected_files = FileAPI::FileList::create(realm());
|
||||||
|
|
||||||
// and then invoke the value sanitization algorithm, if the type attribute's current state defines one.
|
// and then invoke the value sanitization algorithm, if the type attribute's current state defines one.
|
||||||
m_value = value_sanitization_algorithm(m_value);
|
m_value = value_sanitization_algorithm(m_value);
|
||||||
|
@ -1544,6 +1545,42 @@ void HTMLInputElement::reset_algorithm()
|
||||||
update_shadow_tree();
|
update_shadow_tree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/webdriver/#dfn-clear-algorithm
|
||||||
|
void HTMLInputElement::clear_algorithm()
|
||||||
|
{
|
||||||
|
// The clear algorithm for input elements is to set the dirty value flag and dirty checkedness flag back to false,
|
||||||
|
m_dirty_value = false;
|
||||||
|
m_dirty_checkedness = false;
|
||||||
|
|
||||||
|
// set the value of the element to an empty string,
|
||||||
|
auto old_value = move(m_value);
|
||||||
|
m_value = String {};
|
||||||
|
|
||||||
|
// set the checkedness of the element to true if the element has a checked content attribute and false if it does not,
|
||||||
|
m_checked = has_attribute(AttributeNames::checked);
|
||||||
|
|
||||||
|
// empty the list of selected files,
|
||||||
|
if (m_selected_files)
|
||||||
|
m_selected_files = FileAPI::FileList::create(realm());
|
||||||
|
|
||||||
|
// and then invoke the value sanitization algorithm iff the type attribute's current state defines one.
|
||||||
|
m_value = value_sanitization_algorithm(m_value);
|
||||||
|
|
||||||
|
// Unlike their associated reset algorithms, changes made to form controls as part of these algorithms do count as
|
||||||
|
// changes caused by the user (and thus, e.g. do cause input events to fire).
|
||||||
|
user_interaction_did_change_input_value();
|
||||||
|
|
||||||
|
if (m_value != old_value)
|
||||||
|
relevant_value_was_changed(m_text_node);
|
||||||
|
|
||||||
|
if (m_text_node) {
|
||||||
|
m_text_node->set_data(m_value);
|
||||||
|
update_placeholder_visibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
update_shadow_tree();
|
||||||
|
}
|
||||||
|
|
||||||
void HTMLInputElement::form_associated_element_was_inserted()
|
void HTMLInputElement::form_associated_element_was_inserted()
|
||||||
{
|
{
|
||||||
create_shadow_tree_if_needed();
|
create_shadow_tree_if_needed();
|
||||||
|
|
|
@ -179,6 +179,7 @@ public:
|
||||||
bool is_single_line() const;
|
bool is_single_line() const;
|
||||||
|
|
||||||
virtual void reset_algorithm() override;
|
virtual void reset_algorithm() override;
|
||||||
|
virtual void clear_algorithm() override;
|
||||||
|
|
||||||
virtual void form_associated_element_was_inserted() override;
|
virtual void form_associated_element_was_inserted() override;
|
||||||
virtual void form_associated_element_was_removed(DOM::Node*) override;
|
virtual void form_associated_element_was_removed(DOM::Node*) override;
|
||||||
|
|
|
@ -100,4 +100,14 @@ void HTMLOutputElement::reset_algorithm()
|
||||||
m_default_value_override = {};
|
m_default_value_override = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/webdriver/#dfn-clear-algorithm
|
||||||
|
void HTMLOutputElement::clear_algorithm()
|
||||||
|
{
|
||||||
|
// The clear algorithm for output elements is set the element's value mode flag to default
|
||||||
|
m_default_value_override = default_value();
|
||||||
|
|
||||||
|
// and then to set the element's textContent IDL attribute to an empty string (thus clearing the element's child nodes).
|
||||||
|
string_replace_all({});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
virtual bool is_labelable() const override { return true; }
|
virtual bool is_labelable() const override { return true; }
|
||||||
|
|
||||||
virtual void reset_algorithm() override;
|
virtual void reset_algorithm() override;
|
||||||
|
virtual void clear_algorithm() override;
|
||||||
|
|
||||||
// https://www.w3.org/TR/html-aria/#el-output
|
// https://www.w3.org/TR/html-aria/#el-output
|
||||||
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::status; }
|
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::status; }
|
||||||
|
|
|
@ -119,6 +119,20 @@ void HTMLTextAreaElement::reset_algorithm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/webdriver/#dfn-clear-algorithm
|
||||||
|
void HTMLTextAreaElement::clear_algorithm()
|
||||||
|
{
|
||||||
|
// The clear algorithm for textarea elements is to set the dirty value flag back to false,
|
||||||
|
m_dirty_value = false;
|
||||||
|
|
||||||
|
// and set the raw value of element to an empty string.
|
||||||
|
set_raw_value(child_text_content());
|
||||||
|
|
||||||
|
// Unlike their associated reset algorithms, changes made to form controls as part of these algorithms do count as
|
||||||
|
// changes caused by the user (and thus, e.g. do cause input events to fire).
|
||||||
|
queue_firing_input_event();
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-node-clone-ext
|
// https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-node-clone-ext
|
||||||
WebIDL::ExceptionOr<void> HTMLTextAreaElement::cloned(DOM::Node& copy, bool)
|
WebIDL::ExceptionOr<void> HTMLTextAreaElement::cloned(DOM::Node& copy, bool)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,6 +63,7 @@ public:
|
||||||
virtual bool is_labelable() const override { return true; }
|
virtual bool is_labelable() const override { return true; }
|
||||||
|
|
||||||
virtual void reset_algorithm() override;
|
virtual void reset_algorithm() override;
|
||||||
|
virtual void clear_algorithm() override;
|
||||||
|
|
||||||
virtual WebIDL::ExceptionOr<void> cloned(Node&, bool) override;
|
virtual WebIDL::ExceptionOr<void> cloned(Node&, bool) override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue