mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 09:18:52 +00:00
LibWeb: Use JS::HeapFunction for resumption steps in HTMLImageElement
This commit is contained in:
parent
67aa86b5b6
commit
0c46d79e78
Notes:
sideshowbarker
2024-07-17 10:05:47 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 0c46d79e78
Pull-request: https://github.com/SerenityOS/serenity/pull/21228
3 changed files with 18 additions and 8 deletions
|
@ -69,6 +69,7 @@ void HTMLImageElement::visit_edges(Cell::Visitor& visitor)
|
|||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_current_request);
|
||||
visitor.visit(m_pending_request);
|
||||
visitor.visit(m_lazy_load_resumption_steps);
|
||||
}
|
||||
|
||||
void HTMLImageElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
|
@ -159,6 +160,11 @@ void HTMLImageElement::set_visible_in_viewport(bool)
|
|||
// FIXME: Loosen grip on image data when it's not visible, e.g via volatile memory.
|
||||
}
|
||||
|
||||
void HTMLImageElement::set_lazy_load_resumption_steps(Function<void()> steps)
|
||||
{
|
||||
m_lazy_load_resumption_steps = JS::create_heap_function(vm().heap(), move(steps));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-width
|
||||
unsigned HTMLImageElement::width() const
|
||||
{
|
||||
|
@ -549,9 +555,9 @@ after_step_7:
|
|||
// 24. If the will lazy load element steps given the img return true, then:
|
||||
if (will_lazy_load()) {
|
||||
// 1. Set the img's lazy load resumption steps to the rest of this algorithm starting with the step labeled fetch the image.
|
||||
m_lazy_load_resumption_steps = [this, request, image_request]() {
|
||||
set_lazy_load_resumption_steps([this, request, image_request]() {
|
||||
image_request->fetch_image(realm(), request);
|
||||
};
|
||||
});
|
||||
|
||||
// 2. Start intersection-observing a lazy loading element for the img element.
|
||||
document().start_intersection_observing_a_lazy_loading_element(*this);
|
||||
|
@ -1022,9 +1028,11 @@ bool HTMLImageElement::will_lazy_load() const
|
|||
return lazy_loading() == LazyLoading::Lazy;
|
||||
}
|
||||
|
||||
JS::SafeFunction<void()> HTMLImageElement::take_lazy_load_resumption_steps(Badge<DOM::Document>)
|
||||
JS::GCPtr<JS::HeapFunction<void()>> HTMLImageElement::take_lazy_load_resumption_steps(Badge<DOM::Document>)
|
||||
{
|
||||
return move(m_lazy_load_resumption_steps);
|
||||
auto lazy_load_resumption_steps = m_lazy_load_resumption_steps;
|
||||
m_lazy_load_resumption_steps = nullptr;
|
||||
return lazy_load_resumption_steps;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue