mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-30 00:09:01 +00:00
LibWeb: Implement some viewport proximity features
This commit is contained in:
parent
8632ce5cdd
commit
331b1b22f5
Notes:
github-actions[bot]
2025-01-04 11:54:35 +00:00
Author: https://github.com/Psychpsyo
Commit: 331b1b22f5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2603
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 119 additions and 3 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <LibWeb/CSS/FontFaceSet.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
|
@ -20,6 +21,7 @@
|
|||
#include <LibWeb/HighResolutionTime/Performance.h>
|
||||
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/Painting/PaintableBox.h>
|
||||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||
#include <LibWeb/Platform/Timer.h>
|
||||
|
||||
|
@ -249,6 +251,7 @@ void EventLoop::queue_task_to_update_the_rendering()
|
|||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#update-the-rendering
|
||||
void EventLoop::update_the_rendering()
|
||||
{
|
||||
VERIFY(!m_is_running_rendering_task);
|
||||
|
@ -335,9 +338,36 @@ void EventLoop::update_the_rendering()
|
|||
// NOTE: Recalculation of styles is handled by update_layout()
|
||||
document->update_layout();
|
||||
|
||||
// FIXME: 2. Let hadInitialVisibleContentVisibilityDetermination be false.
|
||||
// FIXME: 3. For each element element with 'auto' used value of 'content-visibility':
|
||||
// FIXME: 4. If hadInitialVisibleContentVisibilityDetermination is true, then continue.
|
||||
// 2. Let hadInitialVisibleContentVisibilityDetermination be false.
|
||||
bool had_initial_visible_content_visibility_determination = false;
|
||||
|
||||
// 3. For each element element with 'auto' used value of 'content-visibility':
|
||||
auto* document_element = document->document_element();
|
||||
if (document_element) {
|
||||
document_element->for_each_in_inclusive_subtree_of_type<Web::DOM::Element>([&](auto& element) {
|
||||
auto const& paintable_box = element.paintable_box();
|
||||
if (!paintable_box || paintable_box->computed_values().content_visibility() != CSS::ContentVisibility::Auto) {
|
||||
return TraversalDecision::Continue;
|
||||
}
|
||||
|
||||
// 1. Let checkForInitialDetermination be true if element's proximity to the viewport is not determined and it is not relevant to the user. Otherwise, let checkForInitialDetermination be false.
|
||||
bool check_for_initial_determination = element.proximity_to_the_viewport() == Web::DOM::ProximityToTheViewport::NotDetermined && !element.is_relevant_to_the_user();
|
||||
|
||||
// 2. Determine proximity to the viewport for element.
|
||||
element.determine_proximity_to_the_viewport();
|
||||
|
||||
// 3. If checkForInitialDetermination is true and element is now relevant to the user, then set hadInitialVisibleContentVisibilityDetermination to true.
|
||||
if (check_for_initial_determination && element.is_relevant_to_the_user()) {
|
||||
had_initial_visible_content_visibility_determination = true;
|
||||
}
|
||||
|
||||
return TraversalDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
// 4. If hadInitialVisibleContentVisibilityDetermination is true, then continue.
|
||||
if (had_initial_visible_content_visibility_determination)
|
||||
continue;
|
||||
|
||||
// 5. Gather active resize observations at depth resizeObserverDepth for doc.
|
||||
document->gather_active_observations_at_depth(resize_observer_depth);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue