mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-24 20:12:53 +00:00
LibWeb: Evaluate style sheet media rules immediately on insertion
Before this change, we were waiting for Document to lazily evaluate sheet media and media rules. This often meant that we'd get two full-document style invalidations: one from adding a new style sheet, and one from the media queries changing state. By evaluating the rules eagerly on insertion, we coalesce the two invalidations into one. This reduces the number of full-document invalidations on Speedometer 3 from 51 to 34.
This commit is contained in:
parent
28d564197c
commit
5df3838a80
Notes:
github-actions[bot]
2025-04-18 23:15:06 +00:00
Author: https://github.com/awesomekling
Commit: 5df3838a80
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4400
1 changed files with 7 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2024, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2020-2025, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -10,6 +10,7 @@
|
|||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/CSS/StyleSheetList.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
|
@ -108,6 +109,11 @@ void StyleSheetList::add_sheet(CSSStyleSheet& sheet)
|
|||
m_sheets.prepend(sheet);
|
||||
}
|
||||
|
||||
// NOTE: We evaluate media queries immediately when adding a new sheet.
|
||||
// This coalesces the full document style invalidations.
|
||||
// If we don't do this, we invalidate now, and then again when Document updates media rules.
|
||||
sheet.evaluate_media_queries(as<HTML::Window>(HTML::relevant_global_object(*this)));
|
||||
|
||||
if (sheet.rules().length() == 0) {
|
||||
// NOTE: If the added sheet has no rules, we don't have to invalidate anything.
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue