2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2022-02-15 19:16:57 +01:00
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
2022-02-17 21:22:36 +00:00
|
|
|
* Copyright (c) 2022, Adam Hodgen <ant1441@gmail.com>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-11-25 21:21:55 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-10-03 23:39:53 -06:00
|
|
|
#include <LibWeb/FileAPI/FileList.h>
|
2021-04-20 11:50:29 +02:00
|
|
|
#include <LibWeb/HTML/FormAssociatedElement.h>
|
2020-07-26 15:08:16 +02:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2022-10-03 23:39:53 -06:00
|
|
|
#include <LibWeb/WebIDL/DOMException.h>
|
2019-11-25 21:21:55 +01:00
|
|
|
|
2020-07-28 18:20:36 +02:00
|
|
|
namespace Web::HTML {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2022-02-17 21:22:36 +00:00
|
|
|
// https://html.spec.whatwg.org/multipage/input.html#attr-input-type
|
2022-02-17 23:05:46 +00:00
|
|
|
#define ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTES \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(hidden, Hidden) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(text, Text) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(search, Search) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(tel, Telephone) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(url, URL) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(email, Email) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(password, Password) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(date, Date) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(month, Month) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(week, Week) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(time, Time) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE("datetime-local", LocalDateAndTime) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(number, Number) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(range, Range) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(color, Color) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(checkbox, Checkbox) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(radio, RadioButton) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(file, FileUpload) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(submit, SubmitButton) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(image, ImageButton) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(reset, ResetButton) \
|
|
|
|
__ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(button, Button)
|
2022-02-17 21:22:36 +00:00
|
|
|
|
2022-03-23 18:55:54 -04:00
|
|
|
class HTMLInputElement final
|
|
|
|
: public HTMLElement
|
|
|
|
, public FormAssociatedElement {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLInputElement, HTMLElement);
|
2022-03-23 18:55:54 -04:00
|
|
|
FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLInputElement)
|
|
|
|
|
2019-11-25 21:21:55 +01:00
|
|
|
public:
|
|
|
|
virtual ~HTMLInputElement() override;
|
|
|
|
|
2022-10-17 14:41:50 +02:00
|
|
|
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
|
2019-11-25 21:21:55 +01:00
|
|
|
|
2022-03-26 17:59:58 +00:00
|
|
|
enum class TypeAttributeState {
|
2022-02-17 23:05:46 +00:00
|
|
|
#define __ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(_, state) state,
|
|
|
|
ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTES
|
|
|
|
#undef __ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE
|
|
|
|
};
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString type() const;
|
2022-03-16 07:46:17 -04:00
|
|
|
TypeAttributeState type_state() const { return m_type; }
|
2022-12-04 18:02:33 +00:00
|
|
|
void set_type(DeprecatedString const&);
|
2022-02-17 13:12:01 +01:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString default_value() const { return attribute(HTML::AttributeNames::value); }
|
|
|
|
DeprecatedString name() const { return attribute(HTML::AttributeNames::name); }
|
2020-09-11 18:17:39 +02:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString value() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_value(DeprecatedString);
|
2021-02-10 18:26:07 +01:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
Optional<DeprecatedString> placeholder_value() const;
|
2022-11-30 22:15:12 -05:00
|
|
|
|
2020-09-11 18:17:39 +02:00
|
|
|
bool checked() const { return m_checked; }
|
2022-02-15 19:16:57 +01:00
|
|
|
enum class ChangeSource {
|
|
|
|
Programmatic,
|
|
|
|
User,
|
|
|
|
};
|
2022-03-14 23:05:55 +00:00
|
|
|
void set_checked(bool, ChangeSource = ChangeSource::Programmatic);
|
2020-09-12 17:56:11 +02:00
|
|
|
|
2022-03-15 01:13:05 +00:00
|
|
|
bool checked_binding() const { return checked(); }
|
|
|
|
void set_checked_binding(bool);
|
|
|
|
|
2022-02-17 12:59:32 +01:00
|
|
|
void did_edit_text_node(Badge<BrowsingContext>);
|
|
|
|
|
2022-10-03 23:39:53 -06:00
|
|
|
JS::GCPtr<FileAPI::FileList> files();
|
|
|
|
void set_files(JS::GCPtr<FileAPI::FileList>);
|
|
|
|
|
|
|
|
// NOTE: User interaction
|
|
|
|
// https://html.spec.whatwg.org/multipage/input.html#update-the-file-selection
|
|
|
|
void update_the_file_selection(JS::NonnullGCPtr<FileAPI::FileList>);
|
|
|
|
|
2022-12-30 23:00:11 +00:00
|
|
|
WebIDL::ExceptionOr<void> set_selection_range(u32 start, u32 end, DeprecatedString const& direction);
|
|
|
|
|
2022-10-03 23:39:53 -06:00
|
|
|
WebIDL::ExceptionOr<void> show_picker();
|
|
|
|
|
2022-03-26 18:02:41 +00:00
|
|
|
// ^EventTarget
|
|
|
|
// https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-input-element
|
|
|
|
virtual bool is_focusable() const override { return m_type != TypeAttributeState::Hidden; }
|
2022-02-06 19:27:10 +01:00
|
|
|
|
2022-03-26 18:02:41 +00:00
|
|
|
// ^HTMLElement
|
2022-12-04 18:02:33 +00:00
|
|
|
virtual void parse_attribute(FlyString const&, DeprecatedString const&) override;
|
2022-02-15 19:16:57 +01:00
|
|
|
virtual void did_remove_attribute(FlyString const&) override;
|
|
|
|
|
2022-03-01 21:03:30 +00:00
|
|
|
// ^FormAssociatedElement
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
|
|
|
virtual bool is_listed() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-submit
|
|
|
|
virtual bool is_submittable() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-reset
|
|
|
|
virtual bool is_resettable() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
|
|
|
|
virtual bool is_auto_capitalize_inheriting() const override { return true; }
|
|
|
|
|
2022-12-22 19:33:37 -05:00
|
|
|
virtual void reset_algorithm() override;
|
|
|
|
|
2022-03-23 18:55:54 -04:00
|
|
|
virtual void form_associated_element_was_inserted() override;
|
|
|
|
|
2022-03-01 21:03:30 +00:00
|
|
|
// ^HTMLElement
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-label
|
|
|
|
virtual bool is_labelable() const override { return type_state() != TypeAttributeState::Hidden; }
|
|
|
|
|
2020-09-11 18:17:39 +02:00
|
|
|
private:
|
2022-08-28 13:42:07 +02:00
|
|
|
HTMLInputElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
|
2022-02-06 19:27:10 +01:00
|
|
|
// ^DOM::EventTarget
|
|
|
|
virtual void did_receive_focus() override;
|
2022-03-14 23:05:55 +00:00
|
|
|
virtual void legacy_pre_activation_behavior() override;
|
|
|
|
virtual void legacy_cancelled_activation_behavior() override;
|
|
|
|
virtual void legacy_cancelled_activation_behavior_was_not_called() override;
|
2022-02-06 19:27:10 +01:00
|
|
|
|
2022-11-05 03:58:14 +00:00
|
|
|
// ^DOM::Element
|
|
|
|
virtual i32 default_tab_index_value() const override;
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2022-03-16 07:44:21 -04:00
|
|
|
static TypeAttributeState parse_type_attribute(StringView);
|
2021-02-10 18:26:07 +01:00
|
|
|
void create_shadow_tree_if_needed();
|
2022-02-15 19:16:57 +01:00
|
|
|
void run_input_activation_behavior();
|
2022-03-14 23:05:55 +00:00
|
|
|
void set_checked_within_group();
|
2021-02-10 18:26:07 +01:00
|
|
|
|
2022-02-17 23:05:46 +00:00
|
|
|
// https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString value_sanitization_algorithm(DeprecatedString) const;
|
2022-02-17 23:05:46 +00:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
JS::GCPtr<DOM::Text> m_text_node;
|
2020-09-11 18:17:39 +02:00
|
|
|
bool m_checked { false };
|
2022-02-15 19:16:57 +01:00
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/input.html#concept-input-checked-dirty-flag
|
|
|
|
bool m_dirty_checkedness { false };
|
2022-03-14 23:05:55 +00:00
|
|
|
|
2022-03-22 10:55:13 -04:00
|
|
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-dirty
|
|
|
|
bool m_dirty_value { false };
|
|
|
|
|
2022-03-14 23:05:55 +00:00
|
|
|
// https://html.spec.whatwg.org/multipage/input.html#the-input-element:legacy-pre-activation-behavior
|
|
|
|
bool m_before_legacy_pre_activation_behavior_checked { false };
|
2022-08-28 13:42:07 +02:00
|
|
|
JS::GCPtr<HTMLInputElement> m_legacy_pre_activation_behavior_checked_element_in_group;
|
2022-03-16 07:44:21 -04:00
|
|
|
|
2022-10-03 23:39:53 -06:00
|
|
|
// https://html.spec.whatwg.org/multipage/input.html#concept-input-type-file-selected
|
|
|
|
JS::GCPtr<FileAPI::FileList> m_selected_files;
|
|
|
|
|
2022-03-16 07:44:21 -04:00
|
|
|
TypeAttributeState m_type { TypeAttributeState::Text };
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_value;
|
2019-11-25 21:21:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|