diff --git a/engine/engine.cpp b/engine/engine.cpp index 327d4c79..f4fb5c94 100644 --- a/engine/engine.cpp +++ b/engine/engine.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2021-2024 Robin Lindén +// SPDX-FileCopyrightText: 2021-2025 Robin Lindén // // SPDX-License-Identifier: BSD-2-Clause @@ -86,6 +86,7 @@ css::MediaQuery::Context to_media_context(Options opts) { // NOLINTNEXTLINE(performance-unnecessary-value-param): Clang is wrong, the uri is moved below. tl::expected, NavigationError> Engine::navigate(uri::Uri uri, Options opts) { + spdlog::info("Navigating to {}", uri.uri); auto result = load(std::move(uri)); if (!result.response.has_value()) { @@ -108,9 +109,11 @@ tl::expected, NavigationError> Engine::navigate(uri:: auto state = std::make_unique(); state->uri = std::move(result.uri_after_redirects); state->response = std::move(result.response.value()); + spdlog::info("Parsing HTML"); state->dom = html::parse(state->response.body); - state->stylesheet = css::default_style(); + spdlog::info("Parsing inline styles"); + state->stylesheet = css::default_style(); for (auto const &style : dom::nodes_by_xpath(state->dom.html(), "/html/head/style"sv)) { if (style->children.empty()) { continue; @@ -121,7 +124,9 @@ tl::expected, NavigationError> Engine::navigate(uri:: state->stylesheet.splice(css::parse(style_content.text)); } - auto head_links = dom::nodes_by_xpath(state->dom.html(), "/html/head/link"); + // Stylesheets can appear a bit everywhere: + // https://html.spec.whatwg.org/multipage/semantics.html#allowed-in-the-body + auto head_links = dom::nodes_by_xpath(state->dom.html(), "//link"); std::erase_if(head_links, [](auto const *link) { return !link->attributes.contains("rel") || (link->attributes.contains("rel") && link->attributes.at("rel") != "stylesheet") @@ -177,11 +182,13 @@ tl::expected, NavigationError> Engine::navigate(uri:: state->layout_width = opts.layout_width; state->viewport_height = opts.viewport_height; state->styled = style::style_tree(state->dom.html_node, state->stylesheet, to_media_context(opts)); + spdlog::info("Building layout"); state->layout = layout::create_layout(*state->styled, {state->layout_width, state->viewport_height}, *type_, get_intrensic_size_for_resource_at_url_); + spdlog::info("Done navigating to {}", state->uri.uri); return state; } diff --git a/engine/engine_test.cpp b/engine/engine_test.cpp index bdfaf584..b84307c7 100644 --- a/engine/engine_test.cpp +++ b/engine/engine_test.cpp @@ -163,7 +163,9 @@ int main() { .body{"" "" "" - ""}, + "" + "" + ""}, }; responses["hax://example.com/one.css"s] = Response{ .status_line = {.status_code = 200}, @@ -173,11 +175,16 @@ int main() { .status_line = {.status_code = 200}, .body{"p { color: green; }"}, }; + responses["hax://example.com/sad.css"s] = Response{ + .status_line = {.status_code = 200}, + .body{"a { color: red; }"}, + }; engine::Engine e{std::make_unique(std::move(responses))}; auto page = e.navigate(uri::Uri::parse("hax://example.com").value()).value(); a.expect(contains( page->stylesheet.rules, {.selectors{"p"}, .declarations{{css::PropertyId::FontSize, "123em"}}})); a.expect(contains(page->stylesheet.rules, {.selectors{"p"}, .declarations{{css::PropertyId::Color, "green"}}})); + a.expect(contains(page->stylesheet.rules, {.selectors{"a"}, .declarations{{css::PropertyId::Color, "red"}}})); }); s.add_test("stylesheet link, unsupported Content-Encoding", [](etest::IActions &a) {