1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:37:46 +00:00

LibWeb: Make Document::page() return a Page&

Now that Document always has a Page, and always keeps it alive, we can
make this return a Page&, exposing various unnecessary null checks.
This commit is contained in:
Andreas Kling 2023-12-15 15:41:28 +01:00
parent 70193c0009
commit 7c95ebc302
17 changed files with 43 additions and 78 deletions

View file

@ -33,7 +33,7 @@ CSSImportRule::CSSImportRule(AK::URL url, DOM::Document& document)
, m_document(document)
{
dbgln_if(CSS_LOADER_DEBUG, "CSSImportRule: Loading import URL: {}", m_url);
auto request = LoadRequest::create_for_url_on_page(m_url, document.page());
auto request = LoadRequest::create_for_url_on_page(m_url, &document.page());
// NOTE: Mark this rule as delaying the document load event *before* calling set_resource()
// as it may trigger a synchronous resource_did_load() callback.

View file

@ -2334,11 +2334,8 @@ NonnullOwnPtr<StyleComputer::RuleCache> StyleComputer::make_rule_cache_for_casca
void StyleComputer::build_rule_cache()
{
// FIXME: How are we sometimes calculating style before the Document has a Page?
if (document().page()) {
if (auto user_style_source = document().page()->user_style(); user_style_source.has_value()) {
m_user_style_sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document()), user_style_source.value()));
}
if (auto user_style_source = document().page().user_style(); user_style_source.has_value()) {
m_user_style_sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document()), user_style_source.value()));
}
m_author_rule_cache = make_rule_cache_for_cascade_origin(CascadeOrigin::Author);

View file

@ -217,10 +217,7 @@ Color IdentifierStyleValue::to_color(Optional<Layout::NodeWithStyle const&> node
if (id() == CSS::ValueID::LibwebLink || id() == ValueID::Linktext)
return document.link_color();
if (!document.page())
return {};
auto palette = document.page()->palette();
auto palette = document.page().palette();
switch (id()) {
case CSS::ValueID::LibwebPaletteDesktopBackground:
return palette.color(ColorRole::DesktopBackground);

View file

@ -32,7 +32,7 @@ void ImageStyleValue::load_any_resources(DOM::Document& document)
return;
m_document = &document;
m_image_request = HTML::SharedImageRequest::get_or_create(document.realm(), *document.page(), m_url);
m_image_request = HTML::SharedImageRequest::get_or_create(document.realm(), document.page(), m_url);
m_image_request->add_callbacks(
[this, weak_this = make_weak_ptr()] {
if (!weak_this)