1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

LibWeb: Add support for "User" CascadeOrigin

User styles are applied after the UserAgent's built-in styles, and
before the Author styles that are part of the web page.

Because they're neither part of the page, but can still be modified
while the page is open, caching is a little tricky. The approach here
is to piggy-back on the StyleComputer's rule caches, which already get
rebuilt whenever the styles change. This is not the smartest approach,
since it means re-parsing the style sheet more often than is necessary,
but it's simple and works. :^)
This commit is contained in:
Sam Atkins 2023-08-21 15:50:01 +01:00 committed by Andreas Kling
parent 7bc5949e35
commit 6dcd8d4a2c
4 changed files with 46 additions and 5 deletions

View file

@ -9,6 +9,7 @@
#include <AK/SourceLocation.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/EventLoop/EventLoop.h>
@ -372,6 +373,14 @@ JS::GCPtr<HTML::HTMLMediaElement> Page::media_context_menu_element()
return static_cast<HTML::HTMLMediaElement*>(dom_node);
}
void Page::set_user_style(String source)
{
m_user_style_sheet_source = source;
if (top_level_browsing_context_is_initialized() && top_level_browsing_context().active_document()) {
top_level_browsing_context().active_document()->style_computer().invalidate_rule_cache();
}
}
}
template<>