Skip to content

Truly independent web browser

LibWeb: Report hovered links from the render clock

Andreas Kling7663061d4faa
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 0a3384552ea..f8ec6f08ba6 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -2264,6 +2264,21 @@ String const& Document::serialized_base_url() const
return *m_serialized_base_url;
}
+HoverLinkReporter& Document::hover_link_reporter()
+{
+ if (!m_hover_link_reporter)
+ m_hover_link_reporter = HoverLinkReporter::create(page().hover_link(), unique_id());
+ return *m_hover_link_reporter;
+}
+
+void Document::update_hover_link_base()
+{
+ auto& reporter = hover_link_reporter();
+ auto encoding = encoding_or_default();
+ if (!reporter.resolves_as(serialized_base_url(), encoding))
+ reporter.set_base(base_url(), move(encoding));
+}
+
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-a-url
Optional<URL::URL> Document::encoding_parse_url(Utf16View url) const
{
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index e4017c20591..57dd0bb1656 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -85,6 +85,7 @@
namespace Web {
+class HoverLinkReporter;
struct RenderingStats;
}
@@ -413,6 +414,9 @@ public:
Optional<URL::URL> get_the_base_url() const;
String const& serialized_url() const;
String const& serialized_base_url() const;
+ // What a hover of the render clock tells the page the link it is over with.
+ HoverLinkReporter& hover_link_reporter();
+ void update_hover_link_base();
void update_base_element(Badge<HTML::HTMLBaseElement>);
void did_set_frozen_base_url(Badge<HTML::HTMLBaseElement>);
@@ -2215,6 +2219,8 @@ private:
// https://html.spec.whatwg.org/multipage/dom.html#concept-document-about-base-url
Optional<URL::URL> m_about_base_url;
+ RefPtr<HoverLinkReporter> m_hover_link_reporter;
+
// https://dom.spec.whatwg.org/#document-base-url-override
Optional<URL::URL> m_base_url_override;
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index 3a724296f41..b061c41ab29 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -153,6 +153,7 @@
#include <LibWeb/MathML/TagNames.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/PageHoverLink.h>
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/PictureInPicture/PictureInPictureController.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
@@ -3196,6 +3197,16 @@ void Element::record_style_environment_change()
document().style_computer().style_engine().record_derived_element_style_input_change(style_node_id(), CSS::StyleEngine::PublishedStyle | CSS::StyleEngine::RecomputeStyle);
}
+void Element::update_hover_link()
+{
+ if (m_style_node_id == 0)
+ return;
+ Optional<Utf16String> href;
+ if (created_hyperlink())
+ href = attribute(HTML::AttributeNames::href);
+ document().hover_link_reporter().set_link(m_style_node_id.value(), move(href));
+}
+
void Element::set_style_node_id(CSS::StyleNodeID style_node_id)
{
if (m_style_node_id == style_node_id)
@@ -3204,6 +3215,11 @@ void Element::set_style_node_id(CSS::StyleNodeID style_node_id)
auto old_style_node_id = m_style_node_id;
m_style_node_id = style_node_id;
Layout::Node::dom_node_style_node_changed(*this, old_style_node_id);
+ if (created_hyperlink()) {
+ if (old_style_node_id != 0)
+ document().hover_link_reporter().set_link(old_style_node_id.value(), {});
+ update_hover_link();
+ }
// An element keeps the random base values of its own keys for its whole life: it holds them while it has no style
// node, and its next one takes them back.
auto& style_engine = document().style_computer().style_engine();
diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h
index 55b7e733ed1..608c253a998 100644
--- a/Libraries/LibWeb/DOM/Element.h
+++ b/Libraries/LibWeb/DOM/Element.h
@@ -362,6 +362,8 @@ public:
// elements keep 0, which is what makes them free.
[[nodiscard]] CSS::StyleNodeID style_node_id() const { return m_style_node_id; }
void set_style_node_id(CSS::StyleNodeID);
+ // Tells the hover of the render clock what link this element is, as its href or style node changed.
+ void update_hover_link();
void record_style_environment_change();
// https://html.spec.whatwg.org/multipage/embedded-content-other.html#dimension-attributes
diff --git a/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp b/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp
index fc2174ed4ee..6283aaec07b 100644
--- a/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp
@@ -191,6 +191,20 @@ static Layout::RustFFI::FfiPageCursor ffi_page_cursor(PageCursor& cursor)
};
}
+// What tells the document's page the link a hover of the render clock is over, on the Render thread.
+static Layout::RustFFI::FfiHoverLinkReporter ffi_hover_link_reporter(DOM::Document& document)
+{
+ document.update_hover_link_base();
+ return {
+ .reporter = &document.hover_link_reporter(),
+ .retain = [](void const* reporter) { static_cast<HoverLinkReporter const*>(reporter)->ref(); },
+ .release = [](void const* reporter) { static_cast<HoverLinkReporter const*>(reporter)->unref(); },
+ .is_link = [](void const* reporter, u32 element) { return static_cast<HoverLinkReporter const*>(reporter)->is_link(element); },
+ .report = [](void const* reporter, u32 element) { const_cast<HoverLinkReporter&>(*static_cast<HoverLinkReporter const*>(reporter)).report(element); },
+ .withdraw = [](void const* reporter) { const_cast<HoverLinkReporter&>(*static_cast<HoverLinkReporter const*>(reporter)).withdraw(); },
+ };
+}
+
bool seal_clock_plan(DOM::Document& document, bool may_plan, u64 update_serial)
{
auto* arena = document.layout_node_arena_if_created();
@@ -322,6 +336,7 @@ bool seal_clock_plan(DOM::Document& document, bool may_plan, u64 update_serial)
.scroll_offset_count = scroll_offsets.size(),
.chrome_metrics = document.page().chrome_metrics(),
.page_cursor = ffi_page_cursor(document.page().cursor()),
+ .link_reporter = ffi_hover_link_reporter(document),
.effect_timing_nodes = effect_timing_nodes.data(),
.effect_timing_identities = effect_timing_identities.data(),
.effect_timings = effect_timings.data(),
diff --git a/Libraries/LibWeb/HTML/HyperlinkElementUtils.cpp b/Libraries/LibWeb/HTML/HyperlinkElementUtils.cpp
index 6e606f7edf4..c31490a401d 100644
--- a/Libraries/LibWeb/HTML/HyperlinkElementUtils.cpp
+++ b/Libraries/LibWeb/HTML/HyperlinkElementUtils.cpp
@@ -400,6 +400,7 @@ void HyperlinkElementUtils::href_content_attribute_changed()
{
m_url = {};
m_should_invalidate_style_after_url_change = false;
+ hyperlink_element_utils_element().update_hover_link();
CSS::Invalidation::invalidate_style_after_hyperlink_state_change(hyperlink_element_utils_element());
}
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 12e00b0938d..4918dd456c2 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -2682,6 +2682,13 @@ void Internals::inject_hover_pointer(double x, double y, Optional<double> frame_
Layout::RustFFI::document_host_inject_pointer(document.layout_node_arena().host(), static_cast<float>(x * device_pixels_per_css_pixel), static_cast<float>(y * device_pixels_per_css_pixel), buttons, static_cast<i64>(frame_time * 1'000'000.0), input_event_id.value_or(0));
}
+void Internals::inject_hover_pointer_left(double frame_time_ms)
+{
+ auto& document = window().associated_document();
+ auto frame_time = document.relevant_settings_object().time_origin() + frame_time_ms;
+ Layout::RustFFI::document_host_inject_pointer_left(document.layout_node_arena().host(), static_cast<i64>(frame_time * 1'000'000));
+}
+
void Internals::note_animated_content_moved_under_pointer(double frame_time_ms)
{
auto& document = window().associated_document();
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index b3fdc246aa2..affb1f5b816 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -303,6 +303,7 @@ public:
void inject_clock_tick(double frame_time_ms, Optional<double> viewport_scroll_y);
void inject_clock_tick_scrolling_element(double frame_time_ms, DOM::Element& scroller, double x, double y);
void inject_hover_pointer(double x, double y, Optional<double> frame_time_ms, Optional<u64> input_event_id, u32 buttons);
+ void inject_hover_pointer_left(double frame_time_ms);
void note_animated_content_moved_under_pointer(double frame_time_ms);
void inject_pointer_rests_on_moving_content(double frame_time_ms);
u64 queue_mouse_move(double x, double y, u32 buttons);
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 3469cd0245a..c8eb78ec829 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -332,6 +332,8 @@ interface Internals {
// would, beside the mouse event with the given input event id, if any, and waits until the tick that hovers what is
// under it has run, at the given frame time, or now.
undefined injectHoverPointer(double x, double y, optional double frameTimeMs, optional unsigned long long inputEventId, optional unsigned long buttons = 0);
+ // Hands the clock lanes of the current document the pointer leaving it, and waits as injectHoverPointer() does.
+ undefined injectHoverPointerLeft(double frameTimeMs);
// Reports to the current document's navigable, as the compositor would, that a frame of a transform animation it
// runs moved content under the pointer at rest, or away from it, as of the given frame time.
undefined noteAnimatedContentMovedUnderPointer(double frameTimeMs);
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 7a7c10880fd..4386a7ae6e4 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -5651,8 +5651,13 @@ void EventHandler::track_the_effective_position_of_the_legacy_mouse_pointer(GC::
// NB: A primary touch or pen pointer can move the effective legacy mouse pointer position away from the native
// mouse pointer's boundary target, so the native pointer's boundary events also need to reach T.
auto previous_pointer_target = m_native_mouse_hover_target;
- if (m_effective_legacy_mouse_pointer_position == target && previous_pointer_target == target)
+ if (m_effective_legacy_mouse_pointer_position == target && previous_pointer_target == target) {
+ // AD-HOC: A hover of the render clock may have told the client of the link in the frame on screen, which may
+ // not be what is under the pointer here. Nothing else would tell the client so, as the target did not
+ // change.
+ report_hovered_link_to_client(target);
return;
+ }
// 3. Dispatch mouseover, mouseout, mouseenter and mouseleave events as per [UIEVENTS] for a mouse moving from the
// current effective legacy mouse pointer position to T. Consider an unset value of either current effective
@@ -5709,13 +5714,15 @@ void EventHandler::report_hovered_link_to_client(GC::Ptr<DOM::Node> target)
auto& page = m_navigable->page();
Optional<URL::URL> hovered_link_url;
+ Optional<UniqueNodeID> hovered_document;
if (target) {
+ hovered_document = target->document().unique_id();
// NB: A link in editable content is text to edit, which clicking does not follow.
auto const* hovered_link_element = target->enclosing_link_element();
if (hovered_link_element && !hovered_link_element->hyperlink_element_utils_element().is_editable_or_editing_host())
hovered_link_url = target->document().encoding_parse_url(hovered_link_element->href());
}
- page.hover_link().request(move(hovered_link_url));
+ page.hover_link().request(move(hovered_link_url), hovered_document);
// Whatever the client shows now, this handler reported — so the hover is this handler's to end.
GC::Ptr<HTML::LocalNavigable> hover_reporting_navigable;
@@ -5742,6 +5749,9 @@ void EventHandler::reset_hover_for_document_replacement(Badge<HTML::LocalNavigab
m_additional_pointers.clear();
if (m_navigable->page().hover_reporting_navigable() == m_navigable)
report_hovered_node_to_client(nullptr);
+ // A hover of the render clock may have told of a link there, of which no handler has heard yet.
+ if (auto document = m_navigable->active_document())
+ m_navigable->page().hover_link().withdraw(document->unique_id());
}
void EventHandler::record_last_known_mouse_position(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned buttons, unsigned modifiers)
diff --git a/Libraries/LibWeb/Page/PageHoverLink.cpp b/Libraries/LibWeb/Page/PageHoverLink.cpp
index 464c5adfa49..c19a4b91052 100644
--- a/Libraries/LibWeb/Page/PageHoverLink.cpp
+++ b/Libraries/LibWeb/Page/PageHoverLink.cpp
@@ -4,10 +4,18 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibURL/Parser.h>
#include <LibWeb/Page/PageHoverLink.h>
namespace Web {
+// NB: A blob URL's entry is counted without atomics, and a client only shows the URL, so none crosses threads here.
+static void forget_blob_url_entry(Optional<URL::URL>& url)
+{
+ if (url.has_value())
+ url->set_blob_url_entry({});
+}
+
Optional<URL::URL> PageHoverLink::current() const
{
MutexLocker locker(m_mutex);
@@ -20,13 +28,8 @@ bool PageHoverLink::has_link() const
return m_current.has_value();
}
-void PageHoverLink::request(Optional<URL::URL> url)
+void PageHoverLink::update(Optional<URL::URL> url)
{
- // NB: A blob URL's entry is counted without atomics, and a client only shows the URL, so none crosses threads here.
- if (url.has_value())
- url->set_blob_url_entry({});
-
- MutexLocker locker(m_mutex);
if (m_current == url)
return;
m_current = move(url);
@@ -34,10 +37,86 @@ void PageHoverLink::request(Optional<URL::URL> url)
m_send(m_current);
}
+void PageHoverLink::request(Optional<URL::URL> url, Optional<UniqueNodeID> document)
+{
+ forget_blob_url_entry(url);
+ MutexLocker locker(m_mutex);
+ m_document = document;
+ update(move(url));
+}
+
+void PageHoverLink::withdraw(UniqueNodeID document)
+{
+ MutexLocker locker(m_mutex);
+ if (m_document != document)
+ return;
+ m_document = {};
+ update({});
+}
+
void PageHoverLink::set_send(Send send)
{
MutexLocker locker(m_mutex);
m_send = move(send);
}
+NonnullRefPtr<HoverLinkReporter> HoverLinkReporter::create(NonnullRefPtr<PageHoverLink> hover_link, UniqueNodeID document)
+{
+ return adopt_ref(*new HoverLinkReporter(move(hover_link), document));
+}
+
+HoverLinkReporter::HoverLinkReporter(NonnullRefPtr<PageHoverLink> hover_link, UniqueNodeID document)
+ : m_hover_link(move(hover_link))
+ , m_document(document)
+{
+}
+
+bool HoverLinkReporter::resolves_as(String const& serialized_base_url, Utf16String const& encoding) const
+{
+ MutexLocker locker(m_mutex);
+ return m_base_url.serialize() == serialized_base_url && m_encoding == encoding;
+}
+
+void HoverLinkReporter::set_base(URL::URL base_url, Utf16String encoding)
+{
+ base_url.set_blob_url_entry({});
+ auto encoding_name = encoding.to_utf8();
+ MutexLocker locker(m_mutex);
+ m_base_url = move(base_url);
+ m_encoding = move(encoding);
+ m_encoding_name = move(encoding_name);
+}
+
+void HoverLinkReporter::set_link(u32 element, Optional<Utf16String> href)
+{
+ MutexLocker locker(m_mutex);
+ if (href.has_value())
+ m_links.set(element, href.release_value());
+ else
+ m_links.remove(element);
+}
+
+bool HoverLinkReporter::is_link(u32 element) const
+{
+ MutexLocker locker(m_mutex);
+ return m_links.contains(element);
+}
+
+void HoverLinkReporter::report(u32 element)
+{
+ Optional<URL::URL> url;
+ {
+ // NB: The lock keeps the string live here, so this thread takes no reference to it.
+ MutexLocker locker(m_mutex);
+ if (auto link = m_links.find(element); link != m_links.end())
+ url = URL::Parser::basic_parse(link->value.utf16_view(), m_base_url, m_encoding_name.bytes_as_string_view());
+ }
+ m_hover_link->request(move(url), m_document);
+}
+
+void HoverLinkReporter::withdraw()
+{
+ m_hover_link->withdraw(m_document);
+}
+
}
diff --git a/Libraries/LibWeb/Page/PageHoverLink.h b/Libraries/LibWeb/Page/PageHoverLink.h
index 17bbdec3303..c89d7267d0e 100644
--- a/Libraries/LibWeb/Page/PageHoverLink.h
+++ b/Libraries/LibWeb/Page/PageHoverLink.h
@@ -8,17 +8,23 @@
#include <AK/AtomicRefCounted.h>
#include <AK/Function.h>
+#include <AK/HashMap.h>
#include <AK/Mutex.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
+#include <AK/String.h>
+#include <AK/Utf16String.h>
+#include <AK/Utf16View.h>
#include <LibURL/URL.h>
#include <LibWeb/Export.h>
+#include <LibWebCommon/Forward.h>
namespace Web {
// The link a page asks its client to show the URL of, as the pointer hovers it. No script takes part in this, so what
-// is hovered may be told from any thread. Each asks under one lock, so the client is left showing the link asked for
-// last.
+// is hovered may be told from any thread: the main thread tells as it handles the pointer, and a hover of the render
+// clock tells while a task runs, on the Render thread. Each asks under one lock, so the client is left showing the link
+// asked for last.
class WEB_API PageHoverLink final : public AtomicRefCounted<PageHoverLink> {
public:
// Asks the client to show the URL of a link, or none, from any thread.
@@ -29,8 +35,12 @@ public:
Optional<URL::URL> current() const;
bool has_link() const;
- // Asks the client to show `url`, or no link, where the link asked for last is another.
- void request(Optional<URL::URL> url);
+ // Asks the client to show `url`, or no link, where the link asked for last is another. `document` is the document
+ // the pointer is over, if any.
+ void request(Optional<URL::URL> url, Optional<UniqueNodeID> document);
+
+ // Asks the client to show no link, where what it shows was asked for over the document `document`.
+ void withdraw(UniqueNodeID document);
// What asks the client from now on. None asks nothing.
void set_send(Send);
@@ -38,9 +48,47 @@ public:
private:
PageHoverLink() = default;
+ void update(Optional<URL::URL> url);
+
mutable Mutex m_mutex;
Optional<URL::URL> m_current;
+ Optional<UniqueNodeID> m_document;
Send m_send;
};
+// What tells a page the link a hover of the render clock is over, in one document. A hover cannot read the document,
+// so the hrefs of its links are kept here by the style node of each link, with the base URL and encoding that resolve
+// them.
+class WEB_API HoverLinkReporter final : public AtomicRefCounted<HoverLinkReporter> {
+public:
+ static NonnullRefPtr<HoverLinkReporter> create(NonnullRefPtr<PageHoverLink>, UniqueNodeID document);
+
+ bool resolves_as(String const& serialized_base_url, Utf16String const& encoding) const;
+ void set_base(URL::URL base_url, Utf16String encoding);
+
+ // Notes the href of the link `element` is, or that it is no link.
+ void set_link(u32 element, Optional<Utf16String> href);
+
+ // Whether `element` is a link. From any thread.
+ bool is_link(u32 element) const;
+
+ // Tells the page of the link `element` is, or of no link where it is none. From any thread.
+ void report(u32 element);
+
+ // Tells the page that the pointer left the document. From any thread.
+ void withdraw();
+
+private:
+ HoverLinkReporter(NonnullRefPtr<PageHoverLink>, UniqueNodeID document);
+
+ NonnullRefPtr<PageHoverLink> m_hover_link;
+ UniqueNodeID m_document;
+
+ mutable Mutex m_mutex;
+ HashMap<u32, Utf16String> m_links;
+ URL::URL m_base_url;
+ Utf16String m_encoding;
+ String m_encoding_name;
+};
+
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs b/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs
index 3c6b065f224..54183fe975b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs
@@ -48,6 +48,16 @@ pub(crate) struct HoverCursorFacts {
}
impl HoverCursorFacts {
+ /// See [`super::pipeline::projection::ProjectionGeneration::enclosing_link`].
+ pub(crate) fn enclosing_link(
+ &self,
+ element: StyleNodeID,
+ is_link: impl Fn(StyleNodeID) -> bool,
+ ) -> Option<Option<StyleNodeID>> {
+ self.projection
+ .enclosing_link(element, is_link, |element| self.is_editable(element))
+ }
+
pub(super) fn editable(&self) -> std::sync::Arc<super::fast_hash::FastSet<StyleNodeID>> {
self.editable.clone()
}
@@ -125,6 +135,19 @@ impl StyleEngine {
(!disabled).then_some(node)
}
+ /// The link around `element` in the engine of this hover's fork. See
+ /// [`super::pipeline::projection::ProjectionGeneration::enclosing_link`].
+ pub(crate) fn hover_enclosing_link(
+ &self,
+ element: StyleNodeID,
+ is_link: impl Fn(StyleNodeID) -> bool,
+ ) -> Option<Option<StyleNodeID>> {
+ self.retained
+ .projection
+ .generation()
+ .enclosing_link(element, is_link, |element| self.hover_target_is_editable(element))
+ }
+
/// Whether `element` is editable or an editing host.
pub(crate) fn hover_target_is_editable(&self, element: StyleNodeID) -> bool {
use crate::layout::node_data::DomPaintFact;
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs
index 1f5cfa7a4f4..e87e5e6164c 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs
@@ -693,6 +693,26 @@ impl ProjectionGeneration {
.and_then(|shadow| shadow.host);
Some(host.unwrap_or(parent))
}
+
+ /// The link around `element`, walking up as `DOM::Node::enclosing_link_element()` does: no link where none is
+ /// around it, or where the link is `is_editable`, and none at all where only the host knows.
+ pub(in crate::css::style) fn enclosing_link(
+ &self,
+ mut element: StyleNodeID,
+ is_link: impl Fn(StyleNodeID) -> bool,
+ is_editable: impl Fn(StyleNodeID) -> bool,
+ ) -> Option<Option<StyleNodeID>> {
+ loop {
+ self.committed.get(element.element_slot())?;
+ if is_link(element) {
+ return Some((!is_editable(element)).then_some(element));
+ }
+ match self.element_inheritance_parent(element) {
+ Some(parent) if parent.element_index().is_some() => element = parent,
+ _ => return Some(None),
+ }
+ }
+ }
}
/// What the selectors matched against an element read of its children's places among their siblings, and of itself
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
index 7434eb2ac29..e73fa62c119 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
@@ -40,6 +40,8 @@ pub struct FfiHoverPlanInputs {
pub chrome_metrics: FfiChromeMetrics,
/// The cursor of the document's page, which the hover asks to show the cursor of what it hovers.
pub page_cursor: FfiPageCursor,
+ /// What tells the document's page the link the hover is over.
+ pub link_reporter: FfiHoverLinkReporter,
/// The timings the host runs the effects of elements on without sampling them, as the compositor runs them: the
/// element's style node, the effect's identity, and the timing, an `FfiEffectTiming`, by effect.
pub effect_timing_nodes: *const u32,
@@ -127,6 +129,87 @@ impl Drop for PageCursor {
}
}
+/// What tells a document's page the link a hover is over, which the host hands a hover with its plan: the calls that
+/// reach it from any thread. It is retained for as long as a plan holds it.
+#[repr(C)]
+#[derive(Clone, Copy)]
+pub struct FfiHoverLinkReporter {
+ pub reporter: *const std::ffi::c_void,
+ pub retain: Option<unsafe extern "C" fn(*const std::ffi::c_void)>,
+ pub release: Option<unsafe extern "C" fn(*const std::ffi::c_void)>,
+ /// Whether the given style node is a link.
+ pub is_link: Option<unsafe extern "C" fn(*const std::ffi::c_void, u32) -> bool>,
+ /// Tells the page of the link the given style node is, or of no link where it is none.
+ pub report: Option<unsafe extern "C" fn(*const std::ffi::c_void, u32)>,
+ /// Tells the page that the pointer left the document, which ends the link it showed over the document.
+ pub withdraw: Option<unsafe extern "C" fn(*const std::ffi::c_void)>,
+}
+
+/// What tells a document's page the link a hover is over, which a plan holds a reference to.
+struct HoverLinkReporter(FfiHoverLinkReporter);
+
+// SAFETY: The reporter takes calls from any thread, and is retained and released atomically.
+unsafe impl Send for HoverLinkReporter {}
+// SAFETY: As above.
+unsafe impl Sync for HoverLinkReporter {}
+
+impl HoverLinkReporter {
+ /// A reference to the reporter `ffi` names, or none where it names none.
+ ///
+ /// # Safety
+ ///
+ /// `ffi.reporter` must point at a live reporter, which `ffi.retain` and `ffi.release` reference, or be null.
+ unsafe fn retained(ffi: FfiHoverLinkReporter) -> Option<Self> {
+ if ffi.reporter.is_null()
+ || ffi.release.is_none()
+ || ffi.is_link.is_none()
+ || ffi.report.is_none()
+ || ffi.withdraw.is_none()
+ {
+ return None;
+ }
+ let retain = ffi.retain?;
+ // SAFETY: Guaranteed by the caller.
+ unsafe { retain(ffi.reporter) };
+ Some(Self(ffi))
+ }
+
+ /// Whether `element` is a link.
+ fn is_link(&self, element: StyleNodeID) -> bool {
+ // SAFETY: The reference keeps the reporter live.
+ self.0
+ .is_link
+ .is_some_and(|is_link| unsafe { is_link(self.0.reporter, element.raw()) })
+ }
+
+ /// Tells the page of the link `link` describes, as an element's lookup answers: the link, none for no link, and
+ /// nothing at all where only the host knows, which tells as it handles the move.
+ fn report(&self, link: Option<Option<StyleNodeID>>) {
+ let (Some(link), Some(report)) = (link, self.0.report) else {
+ return;
+ };
+ // SAFETY: The reference keeps the reporter live.
+ unsafe { report(self.0.reporter, link.map_or(0, StyleNodeID::raw)) };
+ }
+
+ /// Tells the page that the pointer left the document.
+ fn withdraw(&self) {
+ if let Some(withdraw) = self.0.withdraw {
+ // SAFETY: The reference keeps the reporter live.
+ unsafe { withdraw(self.0.reporter) };
+ }
+ }
+}
+
+impl Drop for HoverLinkReporter {
+ fn drop(&mut self) {
+ if let Some(release) = self.0.release {
+ // SAFETY: The reference was retained in `retained`, and is released once.
+ unsafe { release(self.0.reporter) };
+ }
+ }
+}
+
/// The immutable inputs needed to hit test the presented frame and resolve its predefined cursors.
struct ReadOnlyHoverFrame {
rows: crate::painting::published_frame::PublishedRows,
@@ -148,6 +231,8 @@ pub(crate) struct HoverPlan {
style: Option<(StyleNodeID, Arc<SealedStyleInputs>)>,
/// The cursor of the document's page.
page_cursor: Option<PageCursor>,
+ /// What tells the document's page the link the hover is over.
+ link_reporter: Option<HoverLinkReporter>,
/// The timings the host runs effects on without sampling them, which the descriptions of their elements' effects
/// hold from before: the step a hover decides over the transitions they run reads them.
effect_timings: Vec<(StyleNodeID, u64, FfiEffectTiming)>,
@@ -161,8 +246,8 @@ impl HoverPlan {
/// # Safety
///
/// `inputs.scroll_offsets` must point at `inputs.scroll_offset_count` offsets, or be null, the effect timing
- /// arrays at `inputs.effect_timing_count` entries each, or be null, and `inputs.page_cursor` must name a live page
- /// cursor, or none.
+ /// arrays at `inputs.effect_timing_count` entries each, or be null, `inputs.page_cursor` must name a live page
+ /// cursor, or none, and `inputs.link_reporter` a live link reporter, or none.
pub(crate) unsafe fn from_ffi(inputs: &FfiHoverPlanInputs) -> Self {
let scroll_offsets = if inputs.scroll_offsets.is_null() {
Vec::new()
@@ -199,6 +284,8 @@ impl HoverPlan {
style: None,
// SAFETY: Guaranteed by the caller.
page_cursor: unsafe { PageCursor::retained(inputs.page_cursor) },
+ // SAFETY: Guaranteed by the caller.
+ link_reporter: unsafe { HoverLinkReporter::retained(inputs.link_reporter) },
effect_timings,
selection_drag: super::selection::SelectionDrag::new(
inputs.selection_drag_anchor,
@@ -209,6 +296,24 @@ impl HoverPlan {
}
}
+ /// Tells the page of the link around what `hit` landed on.
+ fn report_link_of_hit(&self, state: &RenderState, hit: CursorHit) {
+ if let Some(reporter) = &self.link_reporter {
+ reporter.report(
+ state
+ .engine_ref()
+ .hover_enclosing_link(hit.element, |element| reporter.is_link(element)),
+ );
+ }
+ }
+
+ /// Tells the page that the pointer left the document.
+ fn pointer_left(&self) {
+ if let Some(reporter) = &self.link_reporter {
+ reporter.withdraw();
+ }
+ }
+
pub(crate) fn seal_read_only_frame(&mut self, state: &mut RenderState) {
let Some((root, _)) = self.style.as_ref() else {
return;
@@ -641,13 +746,18 @@ impl Lane {
return left_to_host;
};
let placed = pointer.buttons == 0 && !(pointer.scrolled_since_frame && self.scroll_offsets.is_empty());
- if placed
+ if pointer.position.is_none() {
+ plan.pointer_left();
+ } else if placed
&& let Some(position) = pointer.position
&& let Ok(HoverTarget::Element(hit)) = self.hit_test(state, &plan, position, frame_time_nanoseconds)
- && let Some(page_cursor) = &plan.page_cursor
- && let Some(cursor) = cursor_for_hit(state, hit)
{
- page_cursor.request(cursor);
+ plan.report_link_of_hit(state, hit);
+ if let Some(page_cursor) = &plan.page_cursor
+ && let Some(cursor) = cursor_for_hit(state, hit)
+ {
+ page_cursor.request(cursor);
+ }
}
self.plan.hover = Some(plan);
left_to_host
@@ -694,12 +804,17 @@ impl Lane {
// The cursor shows what the pointer is over in the frame on screen, whether the hover moves or the host hovers
// the move: the host shows the cursor of what it finds there as it handles the move. A move handed to an iframe
// shows the cursor its lane finds.
- if !matches!(hovered, Err(HoverDeclined::Handed(_)))
- && let Some(page_cursor) = &plan.page_cursor
+ if pointer.position.is_none() {
+ plan.pointer_left();
+ } else if !matches!(hovered, Err(HoverDeclined::Handed(_)))
&& let Some(hit) = cursor_hit
- && let Some(cursor) = cursor_for_hit(state, hit)
{
- page_cursor.request(cursor);
+ plan.report_link_of_hit(state, hit);
+ if let Some(page_cursor) = &plan.page_cursor
+ && let Some(cursor) = cursor_for_hit(state, hit)
+ {
+ page_cursor.request(cursor);
+ }
}
self.plan.hover = Some(plan);
if logs_hover() {
@@ -1196,6 +1311,7 @@ impl Lane {
let mut nested = None;
let target = (|| {
let Some(position) = pointer.position else {
+ plan.pointer_left();
return Some(None);
};
if pointer.scrolled_since_frame && self.scroll_offsets.is_empty() {
@@ -1273,6 +1389,13 @@ impl Lane {
}
Self::element_for_dispatch_in(&source, item.hit_node, StyleNodeID::from_raw(identity.style_node)?)
}?;
+ if let Some(reporter) = &plan.link_reporter {
+ reporter.report(
+ frame
+ .cursors
+ .enclosing_link(target, |element| reporter.is_link(element)),
+ );
+ }
use crate::css::css_enums::cursor_predefined;
let style = source.node(item.hit_node)?.style()?;
let cursor = style.inherited_ui().cursor.as_slice().first()?;
@@ -1655,3 +1778,23 @@ pub extern "C" fn document_host_inject_pointer(
);
super::settle_lanes_for_testing();
}
+
+/// Hands the clock lanes of `host`'s document the pointer leaving it, ticks them at `frame_time_nanoseconds`, and waits
+/// as [`document_host_inject_pointer`] does. For a test.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_inject_pointer_left(
+ host: &crate::render_state::DocumentHost,
+ frame_time_nanoseconds: i64,
+) {
+ super::settle_lanes_for_testing();
+ host.clock_ticks().inject_pointer(
+ PendingPointer {
+ position: None,
+ buttons: 0,
+ scrolled_since_frame: false,
+ input_event_id: 0,
+ },
+ frame_time_nanoseconds,
+ );
+ super::settle_lanes_for_testing();
+}
diff --git a/Services/WebContent/PageHost.cpp b/Services/WebContent/PageHost.cpp
index 1e44a8fc0a9..4a76b39d5b7 100644
--- a/Services/WebContent/PageHost.cpp
+++ b/Services/WebContent/PageHost.cpp
@@ -62,9 +62,12 @@ Web::HTML::CrossProcessId PageHost::allocate_navigable_id()
void PageHost::remove_page(Badge<PageClient>, Web::PageId page_id)
{
- // The page's cursor asks nothing more of the connection, which a hover of the render clock may still ask it of.
- if (auto page = m_pages.get(page_id); page.has_value())
+ // The cursor and hovered link of the page ask nothing more of the connection, which a hover of the render clock may
+ // still ask it of.
+ if (auto page = m_pages.get(page_id); page.has_value()) {
page.value()->page().cursor().set_send({});
+ page.value()->page().hover_link().set_send({});
+ }
m_pages.remove(page_id);
}
@@ -83,9 +86,11 @@ Optional<PageClient&> PageHost::page(Web::PageId page_id)
PageHost::~PageHost()
{
- // The pages' cursors ask nothing more of the connection, which goes away with this.
- for (auto& page : m_pages)
+ // The pages' cursors and hovered links ask nothing more of the connection, which goes away with this.
+ for (auto& page : m_pages) {
page.value->page().cursor().set_send({});
+ page.value->page().hover_link().set_send({});
+ }
}
void PageHost::ensure_compositor_host()
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-around-an-element.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-around-an-element.txt
new file mode 100644
index 00000000000..0336d075a4e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-around-an-element.txt
@@ -0,0 +1 @@
+an element in a link: https://example.com/link
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-follows-its-href.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-follows-its-href.txt
new file mode 100644
index 00000000000..4b0c8991691
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-follows-its-href.txt
@@ -0,0 +1,5 @@
+the first href: https://example.com/first
+the href changed: https://example.com/second
+the href went: null
+the href came back: https://example.com/third
+the link moved below the other element: https://example.com/third
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-goes-with-its-document.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-goes-with-its-document.txt
new file mode 100644
index 00000000000..a75e9e3fefc
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-goes-with-its-document.txt
@@ -0,0 +1,2 @@
+the lane finds: https://example.com/link
+after the document went: null
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-in-a-same-process-iframe.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-in-a-same-process-iframe.txt
new file mode 100644
index 00000000000..dd653dc066f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-in-a-same-process-iframe.txt
@@ -0,0 +1,6 @@
+a link beside the iframe: https://example.com/outer/link
+a link in the iframe: https://example.com/inner/link
+no link in the iframe: null
+back on the link beside it: https://example.com/outer/link
+back on the link in the iframe: https://example.com/inner/link
+after the iframe's document went: null
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-main-thread-finds-no-link.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-main-thread-finds-no-link.txt
new file mode 100644
index 00000000000..7c9eace7fcb
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-link-main-thread-finds-no-link.txt
@@ -0,0 +1,3 @@
+the main thread hovers: null
+the lane finds: https://example.com/link
+the main thread finds: null
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-no-link-in-no-namespace.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-no-link-in-no-namespace.txt
new file mode 100644
index 00000000000..705dacb249a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-no-link-in-no-namespace.txt
@@ -0,0 +1 @@
+the lane finds: null
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-reports-the-hovered-link-it-restyles.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-reports-the-hovered-link-it-restyles.txt
new file mode 100644
index 00000000000..1d913c2e316
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-reports-the-hovered-link-it-restyles.txt
@@ -0,0 +1,8 @@
+text in a link: https://example.com/absolute
+a relative link: https://example.com/base/relative?query=1
+an anchor without href: null
+back on a link: https://example.com/absolute
+no link: null
+a link around a slot: https://example.com/base/slot
+a link in editable content: null
+a link that is an editing host: null
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-reports-the-hovered-link.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-reports-the-hovered-link.txt
new file mode 100644
index 00000000000..1d913c2e316
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-reports-the-hovered-link.txt
@@ -0,0 +1,8 @@
+text in a link: https://example.com/absolute
+a relative link: https://example.com/base/relative?query=1
+an anchor without href: null
+back on a link: https://example.com/absolute
+no link: null
+a link around a slot: https://example.com/base/slot
+a link in editable content: null
+a link that is an editing host: null
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-reports-the-link-while-an-update-holds-it.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-reports-the-link-while-an-update-holds-it.txt
new file mode 100644
index 00000000000..5680ae94004
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-reports-the-link-while-an-update-holds-it.txt
@@ -0,0 +1,4 @@
+frame scheduler while held: in-flight
+link beside the held frame: https://example.com/link
+link matches :hover beside the held frame: false
+link once the frame landed: https://example.com/link
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-withdraws-a-link-the-main-thread-told-of.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-withdraws-a-link-the-main-thread-told-of.txt
new file mode 100644
index 00000000000..8987cc3281a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-withdraws-a-link-the-main-thread-told-of.txt
@@ -0,0 +1,2 @@
+the main thread hovers: https://example.com/link
+after the pointer left: null
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-withdraws-the-link-as-the-pointer-leaves.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-withdraws-the-link-as-the-pointer-leaves.txt
new file mode 100644
index 00000000000..83b31d6fedc
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-withdraws-the-link-as-the-pointer-leaves.txt
@@ -0,0 +1,2 @@
+on the link: https://example.com/link
+after the pointer left: null
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-around-an-element.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-around-an-element.html
new file mode 100644
index 00000000000..1663a31c553
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-around-an-element.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ a, span { display: block; width: 100px; height: 20px; }
+</style>
+<a href="https://example.com/link"><span></span></a>
+<script>
+ // The lane walks up from the element to the link around it, in a document with no shadow root anywhere.
+ asyncTest(async done => {
+ await twoFramesLanded();
+ await whileLaneHovers(frameTime => {
+ internals.injectHoverPointer(50, 10, frameTime + 16);
+ println(`an element in a link: ${internals.hoveredLink()}`);
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-follows-its-href.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-follows-its-href.html
new file mode 100644
index 00000000000..7c76c593604
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-follows-its-href.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ a, div { display: block; width: 100px; height: 20px; }
+</style>
+<a id="link" href="https://example.com/first"></a>
+<div id="other"></div>
+<script>
+ // A hover tells of the href a link has now, however a task changed it, and of the link wherever it moved to.
+ asyncTest(async done => {
+ await twoFramesLanded();
+ const hoverAt = frameTime => {
+ let time = frameTime;
+ return (name, y) => {
+ time += 16;
+ internals.injectHoverPointer(50, 30, time);
+ time += 16;
+ internals.injectHoverPointer(50, y, time);
+ println(`${name}: ${internals.hoveredLink()}`);
+ };
+ };
+
+ await whileLaneHovers(frameTime => {
+ const hover = hoverAt(frameTime);
+ hover("the first href", 10);
+ link.href = "https://example.com/second";
+ hover("the href changed", 10);
+ link.removeAttribute("href");
+ hover("the href went", 10);
+ link.href = "https://example.com/third";
+ hover("the href came back", 10);
+ });
+
+ other.after(link);
+ await twoFramesLanded();
+ await whileLaneHovers(frameTime => hoverAt(frameTime)("the link moved below the other element", 30));
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-goes-with-its-document.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-goes-with-its-document.html
new file mode 100644
index 00000000000..16a1dc94496
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-goes-with-its-document.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ iframe { display: block; width: 100px; height: 40px; border: 0; }
+</style>
+<iframe srcdoc="<style>body { margin: 0 } a { display: block; height: 20px }</style><a href='https://example.com/link'></a>"></iframe>
+<script>
+ // The iframe's document goes before the main thread hears of the move its lane told of the link for.
+ asyncTest(async done => {
+ const iframe = document.querySelector("iframe");
+ await srcdocLoaded(iframe);
+ await twoFramesLanded();
+
+ await whileLaneHovers(async frameTime => {
+ internals.injectHoverPointer(50, 10, frameTime + 16, 1);
+ iframe.contentWindow.internals.injectClockTick(frameTime + 24);
+ println(`the lane finds: ${internals.hoveredLink()}`);
+
+ const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
+ iframe.srcdoc = "<p>Another document</p>";
+ await loaded;
+ println(`after the document went: ${internals.hoveredLink()}`);
+ }, [document, iframe.contentDocument]);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-in-a-same-process-iframe.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-in-a-same-process-iframe.html
new file mode 100644
index 00000000000..5dd6b53e3e5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-in-a-same-process-iframe.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<base href="https://example.com/outer/">
+<style>
+ body { margin: 0; }
+ a, div { display: block; width: 100px; height: 20px; }
+ iframe { display: block; width: 100px; height: 40px; border: 0; }
+</style>
+<a href="link"></a>
+<div></div>
+<iframe srcdoc="<base href='https://example.com/inner/'><style>body { margin: 0 } a, div { display: block; height: 20px }</style><a href='link'></a><div></div>"></iframe>
+<script>
+ // The lanes of a document and of a same-process iframe in it tell of one link between them, each resolving what it
+ // finds against the base URL of its own document. Replacing the iframe's document ends the link its lane told of.
+ asyncTest(async done => {
+ const iframe = document.querySelector("iframe");
+ await srcdocLoaded(iframe);
+ await twoFramesLanded();
+
+ await whileLaneHovers(frameTime => {
+ let time = frameTime;
+ const hover = (name, y) => {
+ time += 16;
+ internals.injectHoverPointer(50, y, time, 1);
+ iframe.contentWindow.internals.injectClockTick(time + 8);
+ println(`${name}: ${internals.hoveredLink()}`);
+ };
+
+ hover("a link beside the iframe", 10);
+ hover("a link in the iframe", 50);
+ hover("no link in the iframe", 70);
+ hover("back on the link beside it", 10);
+ hover("back on the link in the iframe", 50);
+ }, [document, iframe.contentDocument]);
+
+ const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
+ iframe.srcdoc = "<p>Another document</p>";
+ await loaded;
+ println(`after the iframe's document went: ${internals.hoveredLink()}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-main-thread-finds-no-link.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-main-thread-finds-no-link.html
new file mode 100644
index 00000000000..6973a00703d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-link-main-thread-finds-no-link.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ a, div { display: block; width: 100px; height: 20px; }
+</style>
+<a href="https://example.com/link"></a>
+<div id="plain"></div>
+<script>
+ // The lane tells of the link in the frame on screen, while the task has moved another element under the pointer,
+ // one the main thread had hovered already. Its move hovers nothing new, and still ends the link.
+ asyncTest(async done => {
+ await twoFramesLanded();
+ internals.mouseMove(50, 30);
+ println(`the main thread hovers: ${internals.hoveredLink()}`);
+ await twoFramesLanded();
+
+ await whileLaneHovers(frameTime => {
+ internals.injectHoverPointer(50, 10, frameTime + 16);
+ println(`the lane finds: ${internals.hoveredLink()}`);
+
+ document.body.prepend(plain);
+ internals.mouseMove(50, 10);
+ println(`the main thread finds: ${internals.hoveredLink()}`);
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-no-link-in-no-namespace.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-no-link-in-no-namespace.html
new file mode 100644
index 00000000000..0be6ac52fc1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-no-link-in-no-namespace.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ iframe { display: block; width: 100px; height: 40px; border: 0; }
+</style>
+<iframe></iframe>
+<script>
+ // An element called a with an href in no namespace is no link, in a document where nothing is in the HTML namespace.
+ asyncTest(async done => {
+ const iframe = document.querySelector("iframe");
+ const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
+ const xml = `<root><a href="https://example.com/link" style="display: block; width: 100px; height: 20px"/></root>`;
+ iframe.src = URL.createObjectURL(new Blob([xml], { type: "application/xml" }));
+ await loaded;
+ await twoFramesLanded();
+
+ await whileLaneHovers(frameTime => {
+ internals.injectHoverPointer(50, 10, frameTime + 16, 1);
+ iframe.contentWindow.internals.injectClockTick(frameTime + 24);
+ println(`the lane finds: ${internals.hoveredLink()}`);
+ }, [document, iframe.contentDocument]);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-reports-the-hovered-link-it-restyles.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-reports-the-hovered-link-it-restyles.html
new file mode 100644
index 00000000000..ab8d6ea9734
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-reports-the-hovered-link-it-restyles.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<base href="https://example.com/base/">
+<style>
+ body { margin: 0; }
+ a, div { display: block; width: 100px; height: 20px; }
+ a:hover, div:hover { background: rgb(0, 128, 0); }
+</style>
+<a href="https://example.com/absolute"><span>Text in a link</span></a>
+<a href="relative?query=1"></a>
+<a></a>
+<div></div>
+<div id="host"><span>Slotted text</span></div>
+<div contenteditable><a href="in-editable-content"></a></div>
+<a href="editing-host" contenteditable></a>
+<script>
+ // The main thread stays in one task for every move, so what shows is what the lane asked for.
+ asyncTest(async done => {
+ host.attachShadow({ mode: "open" }).innerHTML = `<a href="slot"><slot></slot></a>`;
+ await twoFramesLanded();
+
+ await whileLaneHovers(frameTime => {
+ let time = frameTime;
+ const hover = (name, y) => {
+ time += 16;
+ internals.injectHoverPointer(50, y, time);
+ println(`${name}: ${internals.hoveredLink()}`);
+ };
+
+ hover("text in a link", 10);
+ hover("a relative link", 30);
+ hover("an anchor without href", 50);
+ hover("back on a link", 10);
+ hover("no link", 70);
+ hover("a link around a slot", 90);
+ hover("a link in editable content", 110);
+ hover("a link that is an editing host", 130);
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-reports-the-hovered-link.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-reports-the-hovered-link.html
new file mode 100644
index 00000000000..f4f19a1803a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-reports-the-hovered-link.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<base href="https://example.com/base/">
+<style>
+ body { margin: 0; }
+ a, div { display: block; width: 100px; height: 20px; }
+</style>
+<a href="https://example.com/absolute"><span>Text in a link</span></a>
+<a href="relative?query=1"></a>
+<a></a>
+<div></div>
+<div id="host"><span>Slotted text</span></div>
+<div contenteditable><a href="in-editable-content"></a></div>
+<a href="editing-host" contenteditable></a>
+<script>
+ // The main thread stays in one task for every move, so what shows is what the lane asked for.
+ asyncTest(async done => {
+ host.attachShadow({ mode: "open" }).innerHTML = `<a href="slot"><slot></slot></a>`;
+ await twoFramesLanded();
+
+ await whileLaneHovers(frameTime => {
+ let time = frameTime;
+ const hover = (name, y) => {
+ time += 16;
+ internals.injectHoverPointer(50, y, time);
+ println(`${name}: ${internals.hoveredLink()}`);
+ };
+
+ hover("text in a link", 10);
+ hover("a relative link", 30);
+ hover("an anchor without href", 50);
+ hover("back on a link", 10);
+ hover("no link", 70);
+ hover("a link around a slot", 90);
+ hover("a link in editable content", 110);
+ hover("a link that is an editing host", 130);
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-reports-the-link-while-an-update-holds-it.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-reports-the-link-while-an-update-holds-it.html
new file mode 100644
index 00000000000..62b3585ee06
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-reports-the-link-while-an-update-holds-it.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ #link { display: block; width: 100px; height: 100px; }
+ #link:hover { width: 150px; }
+ #filler { height: 100px; }
+</style>
+<div id="filler"></div>
+<a id="link" href="https://example.com/link"></a>
+<script>
+ // A rendering update that took the lanes in, whose frame is still in flight, holds the lane from presenting. The
+ // link is not in a frame, so a move beside the held frame tells of the link it is over all the same.
+ asyncTest(async done => {
+ await whileLaneHovers(frameTime => {
+ internals.injectHoverPointer(50, 50, frameTime + 16);
+ });
+ const result = await whileRecordingInFlight(() => {
+ filler.style.height = "120px";
+ }, async schedulerState => {
+ internals.injectHoverPointer(50, 150, performance.now());
+ return { schedulerState, link: internals.hoveredLink(), hovered: link.matches(":hover") };
+ });
+ println(`frame scheduler while held: ${result.schedulerState}`);
+ println(`link beside the held frame: ${result.link}`);
+ println(`link matches :hover beside the held frame: ${result.hovered}`);
+ await twoFramesLanded();
+ await nextTask();
+ println(`link once the frame landed: ${internals.hoveredLink()}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-withdraws-a-link-the-main-thread-told-of.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-withdraws-a-link-the-main-thread-told-of.html
new file mode 100644
index 00000000000..65e8ef805fb
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-withdraws-a-link-the-main-thread-told-of.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ a { display: block; width: 100px; height: 20px; }
+</style>
+<a href="https://example.com/link"></a>
+<script>
+ // The main thread told of the link before a task began, and the pointer leaves the page beside that task.
+ asyncTest(async done => {
+ await twoFramesLanded();
+ internals.mouseMove(50, 10);
+ println(`the main thread hovers: ${internals.hoveredLink()}`);
+ await twoFramesLanded();
+
+ await whileLaneHovers(frameTime => {
+ internals.injectHoverPointerLeft(frameTime + 16);
+ println(`after the pointer left: ${internals.hoveredLink()}`);
+ });
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-withdraws-the-link-as-the-pointer-leaves.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-withdraws-the-link-as-the-pointer-leaves.html
new file mode 100644
index 00000000000..9d6771e5dfd
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-withdraws-the-link-as-the-pointer-leaves.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ body { margin: 0; }
+ a { display: block; width: 100px; height: 20px; }
+</style>
+<a href="https://example.com/link"></a>
+<script>
+ // The pointer leaves the page beside a task: the link it was over goes without the main thread.
+ asyncTest(async done => {
+ await twoFramesLanded();
+ await whileLaneHovers(frameTime => {
+ internals.injectHoverPointer(50, 10, frameTime + 16);
+ println(`on the link: ${internals.hoveredLink()}`);
+ internals.injectHoverPointerLeft(frameTime + 32);
+ println(`after the pointer left: ${internals.hoveredLink()}`);
+ });
+ done();
+ });
+</script>