mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
LibWeb: Register FormAssociatedElement with their owner form
This will eventually allow us to implement HTMLFormControlsCollection.
This commit is contained in:
parent
e454e1a45d
commit
78733417a4
6 changed files with 32 additions and 2 deletions
|
@ -31,7 +31,11 @@ namespace Web::HTML {
|
||||||
|
|
||||||
void FormAssociatedElement::set_form(HTMLFormElement* form)
|
void FormAssociatedElement::set_form(HTMLFormElement* form)
|
||||||
{
|
{
|
||||||
|
if (m_form)
|
||||||
|
m_form->remove_associated_element({}, form_associated_element_to_html_element());
|
||||||
m_form = form;
|
m_form = form;
|
||||||
|
if (m_form)
|
||||||
|
m_form->add_associated_element({}, form_associated_element_to_html_element());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,10 @@ public:
|
||||||
void set_form(HTMLFormElement*);
|
void set_form(HTMLFormElement*);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FormAssociatedElement() { }
|
FormAssociatedElement() = default;
|
||||||
|
virtual ~FormAssociatedElement() = default;
|
||||||
|
|
||||||
|
virtual HTMLElement& form_associated_element_to_html_element() = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WeakPtr<HTMLFormElement> m_form;
|
WeakPtr<HTMLFormElement> m_form;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -148,4 +148,14 @@ void HTMLFormElement::submit()
|
||||||
submit_form(this, true);
|
submit_form(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HTMLFormElement::add_associated_element(Badge<FormAssociatedElement>, HTMLElement& element)
|
||||||
|
{
|
||||||
|
m_associated_elements.append(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTMLFormElement::remove_associated_element(Badge<FormAssociatedElement>, HTMLElement& element)
|
||||||
|
{
|
||||||
|
m_associated_elements.remove_first_matching([&](auto& entry) { return entry.ptr() == &element; });
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,13 @@ public:
|
||||||
// NOTE: This is for the JS bindings. Use submit_form instead.
|
// NOTE: This is for the JS bindings. Use submit_form instead.
|
||||||
void submit();
|
void submit();
|
||||||
|
|
||||||
|
void add_associated_element(Badge<FormAssociatedElement>, HTMLElement&);
|
||||||
|
void remove_associated_element(Badge<FormAssociatedElement>, HTMLElement&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_firing_submission_events { false };
|
bool m_firing_submission_events { false };
|
||||||
|
|
||||||
|
Vector<WeakPtr<HTMLElement>> m_associated_elements;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,9 +57,13 @@ public:
|
||||||
void did_click_button(Badge<Layout::ButtonBox>);
|
void did_click_button(Badge<Layout::ButtonBox>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// ^DOM::Node
|
||||||
virtual void inserted() override;
|
virtual void inserted() override;
|
||||||
virtual void removed_from(Node*) override;
|
virtual void removed_from(Node*) override;
|
||||||
|
|
||||||
|
// ^HTML::FormAssociatedElement
|
||||||
|
virtual HTMLElement& form_associated_element_to_html_element() override { return *this; }
|
||||||
|
|
||||||
void create_shadow_tree_if_needed();
|
void create_shadow_tree_if_needed();
|
||||||
|
|
||||||
RefPtr<DOM::Text> m_text_node;
|
RefPtr<DOM::Text> m_text_node;
|
||||||
|
|
|
@ -42,8 +42,12 @@ public:
|
||||||
virtual ~HTMLSelectElement() override;
|
virtual ~HTMLSelectElement() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// ^DOM::Node
|
||||||
virtual void inserted() override;
|
virtual void inserted() override;
|
||||||
virtual void removed_from(DOM::Node*) override;
|
virtual void removed_from(DOM::Node*) override;
|
||||||
|
|
||||||
|
// ^HTML::FormAssociatedElement
|
||||||
|
virtual HTMLElement& form_associated_element_to_html_element() override { return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue