mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-05 01:10:24 +00:00
LibWeb/CSS: Dump out media queries in more detail
Instead of just serializing them, dump out the query condition as a tree, taking advantage of the existing dump code for BooleanExpressions.
This commit is contained in:
Notes:
github-actions[bot]
2025-12-04 16:25:37 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/5343c9bd2e3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7018
@@ -80,8 +80,8 @@ void CSSMediaRule::dump(StringBuilder& builder, int indent_levels) const
|
||||
{
|
||||
Base::dump(builder, indent_levels);
|
||||
|
||||
dump_indent(builder, indent_levels + 1);
|
||||
builder.appendff("Media: {}\n", condition_text());
|
||||
m_media->dump(builder, indent_levels + 1);
|
||||
|
||||
dump_indent(builder, indent_levels + 1);
|
||||
builder.appendff("Rules ({}):\n", css_rules().length());
|
||||
for (auto& rule : css_rules())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
||||
* Copyright (c) 2022-2023, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <LibWeb/CSS/CSSStyleSheet.h>
|
||||
#include <LibWeb/CSS/MediaList.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
@@ -136,4 +137,12 @@ Optional<JS::Value> MediaList::item_value(size_t index) const
|
||||
return JS::PrimitiveString::create(vm(), m_media[index]->to_string());
|
||||
}
|
||||
|
||||
void MediaList::dump(StringBuilder& builder, int indent_levels) const
|
||||
{
|
||||
dump_indent(builder, indent_levels);
|
||||
builder.appendff("Media list ({}):\n", m_media.size());
|
||||
for (auto const& media : m_media)
|
||||
media->dump(builder, indent_levels + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
||||
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
||||
*
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
|
||||
void set_associated_style_sheet(GC::Ref<StyleSheet> style_sheet) { m_associated_style_sheet = style_sheet; }
|
||||
|
||||
void dump(StringBuilder&, int indent_levels = 0) const;
|
||||
|
||||
private:
|
||||
MediaList(JS::Realm&, Vector<NonnullRefPtr<MediaQuery>>&&);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
|
||||
@@ -261,7 +262,7 @@ MatchResult MediaFeature::compare(DOM::Document const& document, MediaFeatureVal
|
||||
void MediaFeature::dump(StringBuilder& builder, int indent_levels) const
|
||||
{
|
||||
indent(builder, indent_levels);
|
||||
builder.appendff("MediaFeature: {}", to_string());
|
||||
builder.appendff("MediaFeature: {}\n", to_string());
|
||||
}
|
||||
|
||||
String MediaQuery::to_string() const
|
||||
@@ -318,6 +319,24 @@ bool MediaQuery::evaluate(DOM::Document const& document)
|
||||
return m_matches;
|
||||
}
|
||||
|
||||
void MediaQuery::dump(StringBuilder& builder, int indent_levels) const
|
||||
{
|
||||
dump_indent(builder, indent_levels);
|
||||
builder.appendff("Media condition: (matches = {})\n", m_matches);
|
||||
|
||||
dump_indent(builder, indent_levels + 1);
|
||||
builder.appendff("Negated: {}\n", m_negated);
|
||||
|
||||
dump_indent(builder, indent_levels + 1);
|
||||
builder.appendff("Type: {}\n", m_media_type.name);
|
||||
|
||||
if (m_media_condition) {
|
||||
dump_indent(builder, indent_levels + 1);
|
||||
builder.append("Condition:\n"sv);
|
||||
m_media_condition->dump(builder, indent_levels + 2);
|
||||
}
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-1/#serialize-a-media-query-list
|
||||
String serialize_a_media_query_list(Vector<NonnullRefPtr<MediaQuery>> const& media_queries)
|
||||
{
|
||||
|
||||
@@ -221,6 +221,8 @@ public:
|
||||
bool evaluate(DOM::Document const&);
|
||||
String to_string() const;
|
||||
|
||||
void dump(StringBuilder&, int indent_levels = 0) const;
|
||||
|
||||
private:
|
||||
MediaQuery() = default;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user