ladybird/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h
Andreas Kling 246c31ccf6 LibWeb: Make <input type=checkbox> fire click events when clicked :^)
This makes React react to checkboxes. Apparently they ignore the
"change" event in favor of "click" on checkboxes. This is a
compatibility hack for IE8.
2022-02-17 16:33:55 +01:00

74 lines
2 KiB
C++

/*
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/HTML/HTMLElement.h>
namespace Web::HTML {
class HTMLInputElement final : public FormAssociatedElement {
public:
using WrapperType = Bindings::HTMLInputElementWrapper;
HTMLInputElement(DOM::Document&, QualifiedName);
virtual ~HTMLInputElement() override;
virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
String type() const;
void set_type(String const&);
String default_value() const { return attribute(HTML::AttributeNames::value); }
String name() const { return attribute(HTML::AttributeNames::name); }
String value() const;
void set_value(String);
bool checked() const { return m_checked; }
enum class ChangeSource {
Programmatic,
User,
};
enum class ShouldRunActivationBehavior {
No,
Yes,
};
void set_checked(bool, ChangeSource = ChangeSource::Programmatic, ShouldRunActivationBehavior = ShouldRunActivationBehavior::Yes);
bool enabled() const;
void did_click_button(Badge<Layout::ButtonBox>);
void did_click_checkbox(Badge<Layout::CheckBox>);
void did_edit_text_node(Badge<BrowsingContext>);
virtual bool is_focusable() const override;
virtual void parse_attribute(FlyString const&, String const&) override;
virtual void did_remove_attribute(FlyString const&) override;
private:
// ^DOM::Node
virtual void inserted() override;
virtual void removed_from(Node*) override;
// ^DOM::EventTarget
virtual void did_receive_focus() override;
virtual void run_activation_behavior() override;
void create_shadow_tree_if_needed();
void run_input_activation_behavior();
RefPtr<DOM::Text> m_text_node;
bool m_checked { false };
// https://html.spec.whatwg.org/multipage/input.html#concept-input-checked-dirty-flag
bool m_dirty_checkedness { false };
};
}