mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
LibWeb/CSS: Support media queries in import at-rules
This commit is contained in:
parent
c1fe912bf9
commit
ac19b0cda8
Notes:
github-actions[bot]
2025-04-02 13:56:49 +00:00
Author: https://github.com/tcl3
Commit: ac19b0cda8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4183
Reviewed-by: https://github.com/AtkinsSJ ✅
7 changed files with 51 additions and 15 deletions
|
@ -42,7 +42,7 @@ GC::Ref<JS::Realm> internal_css_realm()
|
|||
return *realm;
|
||||
}
|
||||
|
||||
CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const& context, StringView css, Optional<URL::URL> location)
|
||||
CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const& context, StringView css, Optional<URL::URL> location, Vector<NonnullRefPtr<CSS::MediaQuery>> media_query_list)
|
||||
{
|
||||
if (css.is_empty()) {
|
||||
auto rule_list = CSS::CSSRuleList::create_empty(*context.realm);
|
||||
|
@ -51,7 +51,7 @@ CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const& conte
|
|||
style_sheet->set_source_text({});
|
||||
return style_sheet;
|
||||
}
|
||||
auto* style_sheet = CSS::Parser::Parser::create(context, css).parse_as_css_stylesheet(location);
|
||||
auto* style_sheet = CSS::Parser::Parser::create(context, css).parse_as_css_stylesheet(location, move(media_query_list));
|
||||
// FIXME: Avoid this copy
|
||||
style_sheet->set_source_text(MUST(String::from_utf8(css)));
|
||||
return style_sheet;
|
||||
|
|
|
@ -119,7 +119,7 @@ Vector<Rule> Parser::parse_a_stylesheets_contents(TokenStream<T>& input)
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/css-syntax/#parse-a-css-stylesheet
|
||||
CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<URL::URL> location)
|
||||
CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<URL::URL> location, Vector<NonnullRefPtr<MediaQuery>> media_query_list)
|
||||
{
|
||||
// To parse a CSS stylesheet, first parse a stylesheet.
|
||||
auto const& style_sheet = parse_a_stylesheet(m_token_stream, {});
|
||||
|
@ -138,7 +138,7 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<URL::URL> location)
|
|||
}
|
||||
|
||||
auto rule_list = CSSRuleList::create(realm(), rules);
|
||||
auto media_list = MediaList::create(realm(), {});
|
||||
auto media_list = MediaList::create(realm(), move(media_query_list));
|
||||
return CSSStyleSheet::create(realm(), rule_list, media_list, move(location));
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ class Parser {
|
|||
public:
|
||||
static Parser create(ParsingParams const&, StringView input, StringView encoding = "utf-8"sv);
|
||||
|
||||
CSSStyleSheet* parse_as_css_stylesheet(Optional<URL::URL> location);
|
||||
CSSStyleSheet* parse_as_css_stylesheet(Optional<URL::URL> location, Vector<NonnullRefPtr<MediaQuery>> media_query_list = {});
|
||||
|
||||
struct PropertiesAndCustomProperties {
|
||||
Vector<StyleProperty> properties;
|
||||
|
@ -512,7 +512,7 @@ private:
|
|||
|
||||
namespace Web {
|
||||
|
||||
CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const&, StringView, Optional<URL::URL> location = {});
|
||||
CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const&, StringView, Optional<URL::URL> location = {}, Vector<NonnullRefPtr<CSS::MediaQuery>> = {});
|
||||
CSS::Parser::Parser::PropertiesAndCustomProperties parse_css_style_attribute(CSS::Parser::ParsingParams const&, StringView);
|
||||
RefPtr<CSS::CSSStyleValue> parse_css_value(CSS::Parser::ParsingParams const&, StringView, CSS::PropertyID property_id = CSS::PropertyID::Invalid);
|
||||
Optional<CSS::SelectorList> parse_selector(CSS::Parser::ParsingParams const&, StringView);
|
||||
|
|
|
@ -180,7 +180,7 @@ GC::Ptr<CSSImportRule> Parser::convert_to_import_rule(AtRule const& rule)
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: Implement media query support.
|
||||
auto media_query_list = parse_a_media_query_list(tokens);
|
||||
|
||||
if (tokens.has_next_token()) {
|
||||
if constexpr (CSS_PARSER_DEBUG) {
|
||||
|
@ -190,7 +190,7 @@ GC::Ptr<CSSImportRule> Parser::convert_to_import_rule(AtRule const& rule)
|
|||
return {};
|
||||
}
|
||||
|
||||
return CSSImportRule::create(url.value(), const_cast<DOM::Document&>(*document()), supports);
|
||||
return CSSImportRule::create(url.value(), const_cast<DOM::Document&>(*document()), supports, move(media_query_list));
|
||||
}
|
||||
|
||||
Optional<FlyString> Parser::parse_layer_name(TokenStream<ComponentValue>& tokens, AllowBlankLayerName allow_blank_layer_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue