mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb/HTML: Rename popover "invoker"
Lots of renames, no behaviour differences. (Apart from the rename of the
IDL type, which does of course affect JS.)
Corresponds to:
16cb7808da
This commit is contained in:
parent
82dfa69e4e
commit
85478c9215
Notes:
github-actions[bot]
2025-11-27 16:45:55 +00:00
Author: https://github.com/AtkinsSJ
Commit: 85478c9215
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6957
16 changed files with 107 additions and 103 deletions
|
|
@ -35,7 +35,7 @@
|
|||
#include <LibWeb/HTML/HTMLLabelElement.h>
|
||||
#include <LibWeb/HTML/HTMLObjectElement.h>
|
||||
#include <LibWeb/HTML/HTMLParagraphElement.h>
|
||||
#include <LibWeb/HTML/PopoverInvokerElement.h>
|
||||
#include <LibWeb/HTML/PopoverTargetAttributes.h>
|
||||
#include <LibWeb/HTML/ToggleEvent.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Infra/CharacterTypes.h>
|
||||
|
|
@ -73,7 +73,7 @@ void HTMLElement::visit_edges(Cell::Visitor& visitor)
|
|||
HTMLOrSVGElement::visit_edges(visitor);
|
||||
visitor.visit(m_labels);
|
||||
visitor.visit(m_attached_internals);
|
||||
visitor.visit(m_popover_invoker);
|
||||
visitor.visit(m_popover_trigger);
|
||||
visitor.visit(m_popover_close_watcher);
|
||||
}
|
||||
|
||||
|
|
@ -1255,15 +1255,15 @@ WebIDL::ExceptionOr<bool> HTMLElement::check_popover_validity(ExpectedToBeShowin
|
|||
// https://html.spec.whatwg.org/multipage/popover.html#dom-showpopover
|
||||
WebIDL::ExceptionOr<void> HTMLElement::show_popover_for_bindings(ShowPopoverOptions const& options)
|
||||
{
|
||||
// 1. Let invoker be options["source"] if it exists; otherwise, null.
|
||||
auto invoker = options.source;
|
||||
// 2. Run show popover given this, true, and invoker.
|
||||
return show_popover(ThrowExceptions::Yes, invoker);
|
||||
// 1. Let source be options["source"] if it exists; otherwise, null.
|
||||
auto source = options.source;
|
||||
// 2. Run show popover given this, true, and source.
|
||||
return show_popover(ThrowExceptions::Yes, source);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/popover.html#show-popover
|
||||
// https://whatpr.org/html/9457/popover.html#show-popover
|
||||
WebIDL::ExceptionOr<void> HTMLElement::show_popover(ThrowExceptions throw_exceptions, GC::Ptr<HTMLElement> invoker)
|
||||
WebIDL::ExceptionOr<void> HTMLElement::show_popover(ThrowExceptions throw_exceptions, GC::Ptr<HTMLElement> source)
|
||||
{
|
||||
// 1. If the result of running check popover validity given element, false, throwExceptions, null and false is false, then return.
|
||||
if (!TRY(check_popover_validity(ExpectedToBeShowing::No, throw_exceptions, nullptr, IgnoreDomState::No)))
|
||||
|
|
@ -1272,8 +1272,8 @@ WebIDL::ExceptionOr<void> HTMLElement::show_popover(ThrowExceptions throw_except
|
|||
// 2. Let document be element's node document.
|
||||
auto& document = this->document();
|
||||
|
||||
// 3. Assert: element's popover invoker is null.
|
||||
VERIFY(!m_popover_invoker);
|
||||
// 3. Assert: element's popover trigger is null.
|
||||
VERIFY(!m_popover_trigger);
|
||||
|
||||
// 4. Assert: element is not in document's top layer.
|
||||
VERIFY(!in_top_layer());
|
||||
|
|
@ -1294,12 +1294,12 @@ WebIDL::ExceptionOr<void> HTMLElement::show_popover(ThrowExceptions throw_except
|
|||
m_popover_showing_or_hiding = false;
|
||||
};
|
||||
|
||||
// 9. If the result of firing an event named beforetoggle, using ToggleEvent, with the cancelable attribute initialized to true, the oldState attribute initialized to "closed", the newState attribute initialized to "open" at element, and the source attribute initialized to invoker at element is false, then run cleanupShowingFlag and return.
|
||||
// 9. If the result of firing an event named beforetoggle, using ToggleEvent, with the cancelable attribute initialized to true, the oldState attribute initialized to "closed", the newState attribute initialized to "open" at element, and the source attribute initialized to source at element is false, then run cleanupShowingFlag and return.
|
||||
ToggleEventInit event_init {};
|
||||
event_init.old_state = "closed"_string;
|
||||
event_init.new_state = "open"_string;
|
||||
event_init.cancelable = true;
|
||||
if (!dispatch_event(ToggleEvent::create(realm(), HTML::EventNames::beforetoggle, move(event_init), invoker))) {
|
||||
if (!dispatch_event(ToggleEvent::create(realm(), HTML::EventNames::beforetoggle, move(event_init), source))) {
|
||||
cleanup_showing_flag();
|
||||
return {};
|
||||
}
|
||||
|
|
@ -1324,13 +1324,15 @@ WebIDL::ExceptionOr<void> HTMLElement::show_popover(ThrowExceptions throw_except
|
|||
};
|
||||
StackToAppendTo stack_to_append_to = StackToAppendTo::Null;
|
||||
|
||||
// 16. If originalType is the auto state, then:
|
||||
// NB: Steps 14 and 15 are implemented inside step 17 instead, see note below.
|
||||
|
||||
// 16. If originalType is the Auto state, then:
|
||||
if (original_type == "auto"sv) {
|
||||
// 1. Run close entire popover list given document's showing hint popover list, shouldRestoreFocus, and fireEvents.
|
||||
close_entire_popover_list(document.showing_hint_popover_list(), should_restore_focus, fire_events);
|
||||
|
||||
// 2. Let ancestor be the result of running the topmost popover ancestor algorithm given element, document's showing auto popover list, invoker, and true.
|
||||
Variant<GC::Ptr<HTMLElement>, GC::Ptr<DOM::Document>> ancestor = topmost_popover_ancestor(this, document.showing_auto_popover_list(), invoker, IsPopover::Yes);
|
||||
// 2. Let ancestor be the result of running the topmost popover ancestor algorithm given element, document's showing auto popover list, source, and true.
|
||||
Variant<GC::Ptr<HTMLElement>, GC::Ptr<DOM::Document>> ancestor = topmost_popover_ancestor(this, document.showing_auto_popover_list(), source, IsPopover::Yes);
|
||||
|
||||
// 3. If ancestor is null, then set ancestor to document.
|
||||
if (!ancestor.get<GC::Ptr<HTMLElement>>())
|
||||
|
|
@ -1349,10 +1351,10 @@ WebIDL::ExceptionOr<void> HTMLElement::show_popover(ThrowExceptions throw_except
|
|||
// AD-HOC: Steps 14 and 15 have been moved here to avoid hitting the `popover != manual` assertion in the topmost popover ancestor algorithm.
|
||||
// Spec issue: https://github.com/whatwg/html/issues/10988.
|
||||
// 14. Let autoAncestor be the result of running the topmost popover ancestor algorithm given element, document's showing auto popover list, invoker, and true.
|
||||
auto auto_ancestor = topmost_popover_ancestor(this, document.showing_auto_popover_list(), invoker, IsPopover::Yes);
|
||||
auto auto_ancestor = topmost_popover_ancestor(this, document.showing_auto_popover_list(), source, IsPopover::Yes);
|
||||
|
||||
// 15. Let hintAncestor be the result of running the topmost popover ancestor algorithm given element, document's showing hint popover list, invoker, and true.
|
||||
auto hint_ancestor = topmost_popover_ancestor(this, document.showing_hint_popover_list(), invoker, IsPopover::Yes);
|
||||
auto hint_ancestor = topmost_popover_ancestor(this, document.showing_hint_popover_list(), source, IsPopover::Yes);
|
||||
|
||||
// 1. If hintAncestor is not null, then:
|
||||
if (hint_ancestor) {
|
||||
|
|
@ -1456,13 +1458,13 @@ WebIDL::ExceptionOr<void> HTMLElement::show_popover(ThrowExceptions throw_except
|
|||
document.add_an_element_to_the_top_layer(*this);
|
||||
// 22. Set element's popover visibility state to showing.
|
||||
m_popover_visibility_state = PopoverVisibilityState::Showing;
|
||||
// 23. Set element's popover invoker to invoker.
|
||||
m_popover_invoker = invoker;
|
||||
// FIXME: 24. Set element's implicit anchor element to invoker.
|
||||
// 23. Set element's popover trigger to source.
|
||||
m_popover_trigger = source;
|
||||
// FIXME: 24. Set element's implicit anchor element to source.
|
||||
// FIXME: 25. Run the popover focusing steps given element.
|
||||
// FIXME: 26. If shouldRestoreFocus is true and element's popover attribute is not in the No Popover state, then set element's previously focused element to originallyFocusedElement.
|
||||
// 27. Queue a popover toggle event task given element, "closed", "open", and invoker.
|
||||
queue_a_popover_toggle_event_task("closed"_string, "open"_string, invoker);
|
||||
// 27. Queue a popover toggle event task given element, "closed", "open", and source.
|
||||
queue_a_popover_toggle_event_task("closed"_string, "open"_string, source);
|
||||
// 28. Run cleanupShowingFlag.
|
||||
cleanup_showing_flag();
|
||||
|
||||
|
|
@ -1576,8 +1578,8 @@ WebIDL::ExceptionOr<void> HTMLElement::hide_popover(FocusPreviousElement focus_p
|
|||
}
|
||||
}
|
||||
|
||||
// 11. Set element's popover invoker to null.
|
||||
m_popover_invoker = nullptr;
|
||||
// 11. Set element's popover trigger to null.
|
||||
m_popover_trigger = nullptr;
|
||||
|
||||
// 12. Set element's opened in popover mode to null.
|
||||
m_opened_in_popover_mode = {};
|
||||
|
|
@ -1607,26 +1609,26 @@ WebIDL::ExceptionOr<bool> HTMLElement::toggle_popover(TogglePopoverOptionsOrForc
|
|||
{
|
||||
// 1. Let force be null.
|
||||
Optional<bool> force;
|
||||
GC::Ptr<HTMLElement> invoker;
|
||||
GC::Ptr<HTMLElement> source;
|
||||
|
||||
// 2. If options is a boolean, set force to options.
|
||||
options.visit(
|
||||
[&force](bool forceBool) {
|
||||
force = forceBool;
|
||||
},
|
||||
[&force, &invoker](TogglePopoverOptions options) {
|
||||
[&force, &source](TogglePopoverOptions options) {
|
||||
// 3. Otherwise, if options["force"] exists, set force to options["force"].
|
||||
force = options.force;
|
||||
// 4. Let invoker be options["source"] if it exists; otherwise, null.
|
||||
invoker = options.source;
|
||||
// 4. Let source be options["source"] if it exists; otherwise, null.
|
||||
source = options.source;
|
||||
});
|
||||
|
||||
// 5. If this's popover visibility state is showing, and force is null or false, then run the hide popover algorithm given this, true, true, true, false, and null.
|
||||
if (popover_visibility_state() == PopoverVisibilityState::Showing && (!force.has_value() || !force.value()))
|
||||
TRY(hide_popover(FocusPreviousElement::Yes, FireEvents::Yes, ThrowExceptions::Yes, IgnoreDomState::No, nullptr));
|
||||
// 6. Otherwise, if force is not present or true, then run show popover given this true, and invoker.
|
||||
// 6. Otherwise, if force is not present or true, then run show popover given this true, and source.
|
||||
else if (!force.has_value() || force.value())
|
||||
TRY(show_popover(ThrowExceptions::Yes, invoker));
|
||||
TRY(show_popover(ThrowExceptions::Yes, source));
|
||||
// 7. Otherwise:
|
||||
else {
|
||||
// 7.1 Let expectedToBeShowing be true if this's popover visibility state is showing; otherwise false.
|
||||
|
|
@ -1759,9 +1761,10 @@ void HTMLElement::close_entire_popover_list(Vector<GC::Ref<HTMLElement>> const&
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/popover.html#topmost-popover-ancestor
|
||||
GC::Ptr<HTMLElement> HTMLElement::topmost_popover_ancestor(GC::Ptr<DOM::Node> new_popover_or_top_layer_element, Vector<GC::Ref<HTMLElement>> const& popover_list, GC::Ptr<HTMLElement> invoker, IsPopover is_popover)
|
||||
GC::Ptr<HTMLElement> HTMLElement::topmost_popover_ancestor(GC::Ptr<DOM::Node> new_popover_or_top_layer_element, Vector<GC::Ref<HTMLElement>> const& popover_list, GC::Ptr<HTMLElement> source, IsPopover is_popover)
|
||||
{
|
||||
// To find the topmost popover ancestor, given a Node newPopoverOrTopLayerElement, a list popoverList, an HTML element or null invoker, and a boolean isPopover, perform the following steps. They return an HTML element or null.
|
||||
// To find the topmost popover ancestor, given a Node newPopoverOrTopLayerElement, a list popoverList, an HTML
|
||||
// element or null source, and a boolean isPopover, perform the following steps. They return an HTML element or null.
|
||||
|
||||
// 1. If isPopover is true:
|
||||
auto* new_popover = as_if<HTML::HTMLElement>(*new_popover_or_top_layer_element);
|
||||
|
|
@ -1777,8 +1780,8 @@ GC::Ptr<HTMLElement> HTMLElement::topmost_popover_ancestor(GC::Ptr<DOM::Node> ne
|
|||
}
|
||||
// 2. Otherwise:
|
||||
else {
|
||||
// 1. Assert: invoker is null.
|
||||
VERIFY(!invoker);
|
||||
// 1. Assert: source is null.
|
||||
VERIFY(!source);
|
||||
}
|
||||
|
||||
// 3. Let popoverPositions be an empty ordered map.
|
||||
|
|
@ -1850,8 +1853,8 @@ GC::Ptr<HTMLElement> HTMLElement::topmost_popover_ancestor(GC::Ptr<DOM::Node> ne
|
|||
// 10. Run checkAncestor given newPopoverOrTopLayerElement's parent node within the flat tree.
|
||||
check_ancestor(new_popover_or_top_layer_element->shadow_including_first_ancestor_of_type<HTMLElement>());
|
||||
|
||||
// 11. Run checkAncestor given invoker.
|
||||
check_ancestor(invoker.ptr());
|
||||
// 11. Run checkAncestor given source.
|
||||
check_ancestor(source.ptr());
|
||||
|
||||
// 12. Return topmostPopoverAncestor.
|
||||
return topmost_popover_ancestor;
|
||||
|
|
@ -1879,10 +1882,10 @@ GC::Ptr<HTMLElement> HTMLElement::nearest_inclusive_open_popover()
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/popover.html#nearest-inclusive-target-popover-for-invoker
|
||||
GC::Ptr<HTMLElement> HTMLElement::nearest_inclusive_target_popover_for_invoker()
|
||||
// https://html.spec.whatwg.org/multipage/popover.html#nearest-inclusive-target-popover
|
||||
GC::Ptr<HTMLElement> HTMLElement::nearest_inclusive_target_popover()
|
||||
{
|
||||
// To find the nearest inclusive target popover for invoker given a Node node:
|
||||
// To find the nearest inclusive target popover given a Node node:
|
||||
|
||||
// 1. Let currentNode be node.
|
||||
auto* current_node = this;
|
||||
|
|
@ -1890,7 +1893,7 @@ GC::Ptr<HTMLElement> HTMLElement::nearest_inclusive_target_popover_for_invoker()
|
|||
// 2. While currentNode is not null:
|
||||
while (current_node) {
|
||||
// 1. Let targetPopover be currentNode's popover target element.
|
||||
auto target_popover = PopoverInvokerElement::get_the_popover_target_element(*current_node);
|
||||
auto target_popover = PopoverTargetAttributes::get_the_popover_target_element(*current_node);
|
||||
|
||||
// 2. If targetPopover is not null and targetPopover's popover attribute is in the Auto state or the Hint state, and targetPopover's popover visibility state is showing, then return targetPopover.
|
||||
if (target_popover) {
|
||||
|
|
@ -2028,21 +2031,22 @@ GC::Ptr<HTMLElement> HTMLElement::topmost_clicked_popover(GC::Ptr<DOM::Node> nod
|
|||
// 1. Let clickedPopover be the result of running nearest inclusive open popover given node.
|
||||
auto clicked_popover = nearest_element->nearest_inclusive_open_popover();
|
||||
|
||||
// 2. Let invokerPopover be the result of running nearest inclusive target popover for invoker given node.
|
||||
auto invoker_popover = nearest_element->nearest_inclusive_target_popover_for_invoker();
|
||||
// 2. Let targetPopover be the result of running nearest inclusive target popover given node.
|
||||
auto target_popover = nearest_element->nearest_inclusive_target_popover();
|
||||
|
||||
if (!clicked_popover)
|
||||
return invoker_popover;
|
||||
return target_popover;
|
||||
|
||||
if (!invoker_popover)
|
||||
if (!target_popover)
|
||||
return clicked_popover;
|
||||
|
||||
// 3. If the result of getting the popover stack position given clickedPopover is greater than the result of getting the popover stack position given invokerPopover, then return clickedPopover.
|
||||
if (clicked_popover->popover_stack_position() > invoker_popover->popover_stack_position())
|
||||
// 3. If the result of getting the popover stack position given clickedPopover is greater than the result of
|
||||
// getting the popover stack position given targetPopover, then return clickedPopover.
|
||||
if (clicked_popover->popover_stack_position() > target_popover->popover_stack_position())
|
||||
return clicked_popover;
|
||||
|
||||
// 4. Return invokerPopover.
|
||||
return invoker_popover;
|
||||
// 4. Return targetPopover.
|
||||
return target_popover;
|
||||
}
|
||||
|
||||
void HTMLElement::did_receive_focus()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue