mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 01:59:14 +03:00
LibWeb: Switch to new CSS Parser :^)
Change all the places that were including the deprecated parser, to include the new one instead, and then delete the old parser code. `ParentNode::query_selector[_all]()` now treat their input as a comma-separated list of selectors, instead of just one, and return elements that match any of the selectors in that list. This is according to these specs: - querySelector/querySelectorAll: https://dom.spec.whatwg.org/#ref-for-dom-parentnode-queryselector%E2%91%A0 - selector matching algorithm: https://www.w3.org/TR/selectors-4/#match-against-tree
This commit is contained in:
parent
4065eb169c
commit
3bd14941c7
Notes:
sideshowbarker
2024-07-18 07:34:49 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/3bd14941c74 Pull-request: https://github.com/SerenityOS/serenity/pull/9121 Reviewed-by: https://github.com/Dexesttp ✅ Reviewed-by: https://github.com/alimpfard
@ -6,7 +6,7 @@
|
||||
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
@ -48,7 +48,7 @@ bool CSSStyleDeclarationWrapper::internal_set(JS::PropertyName const& name, JS::
|
||||
if (vm().exception())
|
||||
return false;
|
||||
|
||||
auto new_value = parse_css_value(CSS::DeprecatedParsingContext {}, css_text, property_id);
|
||||
auto new_value = parse_css_value(CSS::ParsingContext {}, css_text, property_id);
|
||||
// FIXME: What are we supposed to do if we can't parse it?
|
||||
if (!new_value)
|
||||
return false;
|
||||
|
@ -19,7 +19,6 @@ set(SOURCES
|
||||
CSS/CSSStyleSheet.cpp
|
||||
CSS/DefaultStyleSheetSource.cpp
|
||||
CSS/Length.cpp
|
||||
CSS/Parser/DeprecatedCSSParser.cpp
|
||||
CSS/Parser/Parser.cpp
|
||||
CSS/Parser/StyleRules.cpp
|
||||
CSS/Parser/Token.cpp
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/CSS/CSSStyleSheet.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
class DeprecatedParsingContext {
|
||||
public:
|
||||
DeprecatedParsingContext();
|
||||
explicit DeprecatedParsingContext(const DOM::Document&);
|
||||
explicit DeprecatedParsingContext(const DOM::ParentNode&);
|
||||
|
||||
bool in_quirks_mode() const;
|
||||
|
||||
URL complete_url(const String&) const;
|
||||
|
||||
private:
|
||||
const DOM::Document* m_document { nullptr };
|
||||
};
|
||||
}
|
||||
|
||||
namespace Web {
|
||||
|
||||
RefPtr<CSS::CSSStyleSheet> parse_css(const CSS::DeprecatedParsingContext&, const StringView&);
|
||||
RefPtr<CSS::CSSStyleDeclaration> parse_css_declaration(const CSS::DeprecatedParsingContext&, const StringView&);
|
||||
RefPtr<CSS::StyleValue> parse_css_value(const CSS::DeprecatedParsingContext&, const StringView&, CSS::PropertyID property_id = CSS::PropertyID::Invalid);
|
||||
RefPtr<CSS::Selector> parse_selector(const CSS::DeprecatedParsingContext&, const StringView&);
|
||||
|
||||
RefPtr<CSS::LengthStyleValue> parse_line_width(const CSS::DeprecatedParsingContext&, const StringView&);
|
||||
RefPtr<CSS::ColorStyleValue> parse_color(const CSS::DeprecatedParsingContext&, const StringView&);
|
||||
RefPtr<CSS::IdentifierStyleValue> parse_line_style(const CSS::DeprecatedParsingContext&, const StringView&);
|
||||
|
||||
RefPtr<CSS::StyleValue> parse_html_length(const DOM::Document&, const StringView&);
|
||||
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/SelectorEngine.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include <AK/QuickSort.h>
|
||||
#include <LibWeb/CSS/CSSStyleRule.h>
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/SelectorEngine.h>
|
||||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
@ -36,7 +35,7 @@ static StyleSheet& default_stylesheet()
|
||||
if (!sheet) {
|
||||
extern char const default_stylesheet_source[];
|
||||
String css = default_stylesheet_source;
|
||||
sheet = parse_css(CSS::DeprecatedParsingContext(), css).leak_ref();
|
||||
sheet = parse_css(CSS::ParsingContext(), css).leak_ref();
|
||||
}
|
||||
return *sheet;
|
||||
}
|
||||
@ -47,7 +46,7 @@ static StyleSheet& quirks_mode_stylesheet()
|
||||
if (!sheet) {
|
||||
extern char const quirks_mode_stylesheet_source[];
|
||||
String css = quirks_mode_stylesheet_source;
|
||||
sheet = parse_css(CSS::DeprecatedParsingContext(), css).leak_ref();
|
||||
sheet = parse_css(CSS::ParsingContext(), css).leak_ref();
|
||||
}
|
||||
return *sheet;
|
||||
}
|
||||
@ -524,7 +523,6 @@ static inline bool is_text_decoration_style(StyleValue const& value)
|
||||
|
||||
static void set_property_expanding_shorthands(StyleProperties& style, CSS::PropertyID property_id, StyleValue const& value, DOM::Document& document, bool is_internally_generated_pseudo_property = false)
|
||||
{
|
||||
CSS::DeprecatedParsingContext deprecated_context(document);
|
||||
CSS::ParsingContext context(document);
|
||||
|
||||
if (is_pseudo_property(property_id) && !is_internally_generated_pseudo_property) {
|
||||
@ -617,48 +615,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
style.set_property(CSS::PropertyID::BorderBottomLeftRadius, value);
|
||||
return;
|
||||
}
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (parts.size() == 2) {
|
||||
auto diagonal1 = parse_css_value(deprecated_context, parts[0]);
|
||||
auto diagonal2 = parse_css_value(deprecated_context, parts[1]);
|
||||
if (diagonal1 && diagonal2) {
|
||||
style.set_property(CSS::PropertyID::BorderTopLeftRadius, *diagonal1);
|
||||
style.set_property(CSS::PropertyID::BorderBottomRightRadius, *diagonal1);
|
||||
style.set_property(CSS::PropertyID::BorderTopRightRadius, *diagonal2);
|
||||
style.set_property(CSS::PropertyID::BorderBottomLeftRadius, *diagonal2);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (parts.size() == 3) {
|
||||
auto top_left = parse_css_value(deprecated_context, parts[0]);
|
||||
auto diagonal = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom_right = parse_css_value(deprecated_context, parts[2]);
|
||||
if (top_left && diagonal && bottom_right) {
|
||||
style.set_property(CSS::PropertyID::BorderTopLeftRadius, *top_left);
|
||||
style.set_property(CSS::PropertyID::BorderBottomRightRadius, *bottom_right);
|
||||
style.set_property(CSS::PropertyID::BorderTopRightRadius, *diagonal);
|
||||
style.set_property(CSS::PropertyID::BorderBottomLeftRadius, *diagonal);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (parts.size() == 4) {
|
||||
auto top_left = parse_css_value(deprecated_context, parts[0]);
|
||||
auto top_right = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom_right = parse_css_value(deprecated_context, parts[2]);
|
||||
auto bottom_left = parse_css_value(deprecated_context, parts[3]);
|
||||
if (top_left && top_right && bottom_right && bottom_left) {
|
||||
style.set_property(CSS::PropertyID::BorderTopLeftRadius, *top_left);
|
||||
style.set_property(CSS::PropertyID::BorderBottomRightRadius, *bottom_right);
|
||||
style.set_property(CSS::PropertyID::BorderTopRightRadius, *top_right);
|
||||
style.set_property(CSS::PropertyID::BorderBottomLeftRadius, *bottom_left);
|
||||
}
|
||||
return;
|
||||
}
|
||||
dbgln("Unsure what to do with CSS border-radius value '{}'", value.to_string());
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 2) {
|
||||
@ -736,54 +693,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
|
||||
if (parts.size() == 1) {
|
||||
if (auto value = parse_line_style(deprecated_context, parts[0])) {
|
||||
set_property_border_style(style, value.release_nonnull(), edge);
|
||||
set_property_border_color(style, ColorStyleValue::create(Gfx::Color::Black), edge);
|
||||
set_property_border_width(style, LengthStyleValue::create(Length(3, Length::Type::Px)), edge);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<LengthStyleValue> line_width_value;
|
||||
RefPtr<ColorStyleValue> color_value;
|
||||
RefPtr<IdentifierStyleValue> line_style_value;
|
||||
|
||||
for (auto& part : parts) {
|
||||
if (auto value = parse_line_width(deprecated_context, part)) {
|
||||
if (line_width_value)
|
||||
return;
|
||||
line_width_value = move(value);
|
||||
continue;
|
||||
}
|
||||
if (auto value = parse_color(deprecated_context, part)) {
|
||||
if (color_value)
|
||||
return;
|
||||
color_value = move(value);
|
||||
continue;
|
||||
}
|
||||
if (auto value = parse_line_style(deprecated_context, part)) {
|
||||
if (line_style_value)
|
||||
return;
|
||||
line_style_value = move(value);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (line_width_value)
|
||||
set_property_border_width(style, line_width_value.release_nonnull(), edge);
|
||||
if (color_value)
|
||||
set_property_border_color(style, color_value.release_nonnull(), edge);
|
||||
if (line_style_value)
|
||||
set_property_border_style(style, line_style_value.release_nonnull(), edge);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
|
||||
@ -839,49 +748,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::BorderStyle) {
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (parts.size() == 4) {
|
||||
auto top = parse_css_value(deprecated_context, parts[0]);
|
||||
auto right = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom = parse_css_value(deprecated_context, parts[2]);
|
||||
auto left = parse_css_value(deprecated_context, parts[3]);
|
||||
if (top && right && bottom && left) {
|
||||
style.set_property(CSS::PropertyID::BorderTopStyle, *top);
|
||||
style.set_property(CSS::PropertyID::BorderRightStyle, *right);
|
||||
style.set_property(CSS::PropertyID::BorderBottomStyle, *bottom);
|
||||
style.set_property(CSS::PropertyID::BorderLeftStyle, *left);
|
||||
}
|
||||
} else if (parts.size() == 3) {
|
||||
auto top = parse_css_value(deprecated_context, parts[0]);
|
||||
auto right = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom = parse_css_value(deprecated_context, parts[2]);
|
||||
auto left = parse_css_value(deprecated_context, parts[1]);
|
||||
if (top && right && bottom && left) {
|
||||
style.set_property(CSS::PropertyID::BorderTopStyle, *top);
|
||||
style.set_property(CSS::PropertyID::BorderRightStyle, *right);
|
||||
style.set_property(CSS::PropertyID::BorderBottomStyle, *bottom);
|
||||
style.set_property(CSS::PropertyID::BorderLeftStyle, *left);
|
||||
}
|
||||
} else if (parts.size() == 2) {
|
||||
auto vertical = parse_css_value(deprecated_context, parts[0]);
|
||||
auto horizontal = parse_css_value(deprecated_context, parts[1]);
|
||||
if (vertical && horizontal) {
|
||||
style.set_property(CSS::PropertyID::BorderTopStyle, *vertical);
|
||||
style.set_property(CSS::PropertyID::BorderRightStyle, *horizontal);
|
||||
style.set_property(CSS::PropertyID::BorderBottomStyle, *vertical);
|
||||
style.set_property(CSS::PropertyID::BorderLeftStyle, *horizontal);
|
||||
}
|
||||
} else {
|
||||
style.set_property(CSS::PropertyID::BorderTopStyle, value);
|
||||
style.set_property(CSS::PropertyID::BorderRightStyle, value);
|
||||
style.set_property(CSS::PropertyID::BorderBottomStyle, value);
|
||||
style.set_property(CSS::PropertyID::BorderLeftStyle, value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 4) {
|
||||
@ -935,48 +801,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::BorderWidth) {
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (parts.size() == 4) {
|
||||
auto top_border_width = parse_css_value(deprecated_context, parts[0]);
|
||||
auto right_border_width = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom_border_width = parse_css_value(deprecated_context, parts[2]);
|
||||
auto left_border_width = parse_css_value(deprecated_context, parts[3]);
|
||||
if (top_border_width && right_border_width && bottom_border_width && left_border_width) {
|
||||
style.set_property(CSS::PropertyID::BorderTopWidth, *top_border_width);
|
||||
style.set_property(CSS::PropertyID::BorderRightWidth, *right_border_width);
|
||||
style.set_property(CSS::PropertyID::BorderBottomWidth, *bottom_border_width);
|
||||
style.set_property(CSS::PropertyID::BorderLeftWidth, *left_border_width);
|
||||
}
|
||||
} else if (parts.size() == 3) {
|
||||
auto top_border_width = parse_css_value(deprecated_context, parts[0]);
|
||||
auto horizontal_border_width = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom_border_width = parse_css_value(deprecated_context, parts[2]);
|
||||
if (top_border_width && horizontal_border_width && bottom_border_width) {
|
||||
style.set_property(CSS::PropertyID::BorderTopWidth, *top_border_width);
|
||||
style.set_property(CSS::PropertyID::BorderRightWidth, *horizontal_border_width);
|
||||
style.set_property(CSS::PropertyID::BorderBottomWidth, *bottom_border_width);
|
||||
style.set_property(CSS::PropertyID::BorderLeftWidth, *horizontal_border_width);
|
||||
}
|
||||
} else if (parts.size() == 2) {
|
||||
auto vertical_border_width = parse_css_value(deprecated_context, parts[0]);
|
||||
auto horizontal_border_width = parse_css_value(deprecated_context, parts[1]);
|
||||
if (vertical_border_width && horizontal_border_width) {
|
||||
style.set_property(CSS::PropertyID::BorderTopWidth, *vertical_border_width);
|
||||
style.set_property(CSS::PropertyID::BorderRightWidth, *horizontal_border_width);
|
||||
style.set_property(CSS::PropertyID::BorderBottomWidth, *vertical_border_width);
|
||||
style.set_property(CSS::PropertyID::BorderLeftWidth, *horizontal_border_width);
|
||||
}
|
||||
} else {
|
||||
style.set_property(CSS::PropertyID::BorderTopWidth, value);
|
||||
style.set_property(CSS::PropertyID::BorderRightWidth, value);
|
||||
style.set_property(CSS::PropertyID::BorderBottomWidth, value);
|
||||
style.set_property(CSS::PropertyID::BorderLeftWidth, value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 4) {
|
||||
@ -1029,48 +853,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::BorderColor) {
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (parts.size() == 4) {
|
||||
auto top = parse_css_value(deprecated_context, parts[0]);
|
||||
auto right = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom = parse_css_value(deprecated_context, parts[2]);
|
||||
auto left = parse_css_value(deprecated_context, parts[3]);
|
||||
if (top && right && bottom && left) {
|
||||
style.set_property(CSS::PropertyID::BorderTopColor, *top);
|
||||
style.set_property(CSS::PropertyID::BorderRightColor, *right);
|
||||
style.set_property(CSS::PropertyID::BorderBottomColor, *bottom);
|
||||
style.set_property(CSS::PropertyID::BorderLeftColor, *left);
|
||||
}
|
||||
} else if (parts.size() == 3) {
|
||||
auto top = parse_css_value(deprecated_context, parts[0]);
|
||||
auto horizontal = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom = parse_css_value(deprecated_context, parts[2]);
|
||||
if (top && horizontal && bottom) {
|
||||
style.set_property(CSS::PropertyID::BorderTopColor, *top);
|
||||
style.set_property(CSS::PropertyID::BorderRightColor, *horizontal);
|
||||
style.set_property(CSS::PropertyID::BorderBottomColor, *bottom);
|
||||
style.set_property(CSS::PropertyID::BorderLeftColor, *horizontal);
|
||||
}
|
||||
} else if (parts.size() == 2) {
|
||||
auto vertical = parse_css_value(deprecated_context, parts[0]);
|
||||
auto horizontal = parse_css_value(deprecated_context, parts[1]);
|
||||
if (vertical && horizontal) {
|
||||
style.set_property(CSS::PropertyID::BorderTopColor, *vertical);
|
||||
style.set_property(CSS::PropertyID::BorderRightColor, *horizontal);
|
||||
style.set_property(CSS::PropertyID::BorderBottomColor, *vertical);
|
||||
style.set_property(CSS::PropertyID::BorderLeftColor, *horizontal);
|
||||
}
|
||||
} else {
|
||||
style.set_property(CSS::PropertyID::BorderTopColor, value);
|
||||
style.set_property(CSS::PropertyID::BorderRightColor, value);
|
||||
style.set_property(CSS::PropertyID::BorderBottomColor, value);
|
||||
style.set_property(CSS::PropertyID::BorderLeftColor, value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto& parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 4) {
|
||||
@ -1138,46 +920,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
NonnullRefPtrVector<StyleValue> values;
|
||||
for (auto& part : parts) {
|
||||
auto value = parse_css_value(deprecated_context, part);
|
||||
if (!value)
|
||||
return;
|
||||
values.append(value.release_nonnull());
|
||||
}
|
||||
|
||||
// HACK: Disallow more than one color value in a 'background' shorthand
|
||||
size_t color_value_count = 0;
|
||||
for (auto& value : values)
|
||||
color_value_count += value.is_color();
|
||||
|
||||
if (values[0].is_color() && color_value_count == 1)
|
||||
style.set_property(CSS::PropertyID::BackgroundColor, values[0]);
|
||||
|
||||
for (auto it = values.begin(); it != values.end(); ++it) {
|
||||
auto& value = *it;
|
||||
|
||||
if (is_background_repeat(value)) {
|
||||
if ((it + 1 != values.end()) && is_background_repeat(*(it + 1))) {
|
||||
++it;
|
||||
|
||||
set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundRepeatX, value, document, true);
|
||||
set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundRepeatY, *it, document, true);
|
||||
} else {
|
||||
set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundRepeat, value, document);
|
||||
}
|
||||
}
|
||||
|
||||
if (!value.is_string())
|
||||
continue;
|
||||
set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundImage, value, document);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
|
||||
@ -1319,27 +1061,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
assign_background_repeat_from_single_value(value);
|
||||
}
|
||||
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
NonnullRefPtrVector<StyleValue> values;
|
||||
for (auto& part : parts) {
|
||||
auto value = parse_css_value(deprecated_context, part);
|
||||
if (!value || !is_background_repeat(*value))
|
||||
return;
|
||||
values.append(value.release_nonnull());
|
||||
}
|
||||
|
||||
if (values.size() == 1) {
|
||||
assign_background_repeat_from_single_value(values[0]);
|
||||
} else if (values.size() == 2) {
|
||||
set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundRepeatX, values[0], document, true);
|
||||
set_property_expanding_shorthands(style, CSS::PropertyID::BackgroundRepeatY, values[1], document, true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
NonnullRefPtrVector<StyleValue> repeat_values;
|
||||
@ -1381,47 +1102,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (parts.size() == 2) {
|
||||
auto vertical = parse_css_value(deprecated_context, parts[0]);
|
||||
auto horizontal = parse_css_value(deprecated_context, parts[1]);
|
||||
if (vertical && horizontal) {
|
||||
style.set_property(CSS::PropertyID::MarginTop, *vertical);
|
||||
style.set_property(CSS::PropertyID::MarginBottom, *vertical);
|
||||
style.set_property(CSS::PropertyID::MarginLeft, *horizontal);
|
||||
style.set_property(CSS::PropertyID::MarginRight, *horizontal);
|
||||
}
|
||||
return;
|
||||
} else if (parts.size() == 3) {
|
||||
auto top = parse_css_value(deprecated_context, parts[0]);
|
||||
auto horizontal = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom = parse_css_value(deprecated_context, parts[2]);
|
||||
if (top && horizontal && bottom) {
|
||||
style.set_property(CSS::PropertyID::MarginTop, *top);
|
||||
style.set_property(CSS::PropertyID::MarginBottom, *bottom);
|
||||
style.set_property(CSS::PropertyID::MarginLeft, *horizontal);
|
||||
style.set_property(CSS::PropertyID::MarginRight, *horizontal);
|
||||
}
|
||||
return;
|
||||
} else if (parts.size() == 4) {
|
||||
auto top = parse_css_value(deprecated_context, parts[0]);
|
||||
auto right = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom = parse_css_value(deprecated_context, parts[2]);
|
||||
auto left = parse_css_value(deprecated_context, parts[3]);
|
||||
if (top && right && bottom && left) {
|
||||
style.set_property(CSS::PropertyID::MarginTop, *top);
|
||||
style.set_property(CSS::PropertyID::MarginBottom, *bottom);
|
||||
style.set_property(CSS::PropertyID::MarginLeft, *left);
|
||||
style.set_property(CSS::PropertyID::MarginRight, *right);
|
||||
}
|
||||
return;
|
||||
}
|
||||
dbgln("Unsure what to do with CSS margin value '{}'", value.to_string());
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 2) {
|
||||
@ -1473,47 +1153,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (parts.size() == 2) {
|
||||
auto vertical = parse_css_value(deprecated_context, parts[0]);
|
||||
auto horizontal = parse_css_value(deprecated_context, parts[1]);
|
||||
if (vertical && horizontal) {
|
||||
style.set_property(CSS::PropertyID::PaddingTop, *vertical);
|
||||
style.set_property(CSS::PropertyID::PaddingBottom, *vertical);
|
||||
style.set_property(CSS::PropertyID::PaddingLeft, *horizontal);
|
||||
style.set_property(CSS::PropertyID::PaddingRight, *horizontal);
|
||||
}
|
||||
return;
|
||||
} else if (parts.size() == 3) {
|
||||
auto top = parse_css_value(deprecated_context, parts[0]);
|
||||
auto horizontal = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom = parse_css_value(deprecated_context, parts[2]);
|
||||
if (top && bottom && horizontal) {
|
||||
style.set_property(CSS::PropertyID::PaddingTop, *top);
|
||||
style.set_property(CSS::PropertyID::PaddingBottom, *bottom);
|
||||
style.set_property(CSS::PropertyID::PaddingLeft, *horizontal);
|
||||
style.set_property(CSS::PropertyID::PaddingRight, *horizontal);
|
||||
}
|
||||
return;
|
||||
} else if (parts.size() == 4) {
|
||||
auto top = parse_css_value(deprecated_context, parts[0]);
|
||||
auto right = parse_css_value(deprecated_context, parts[1]);
|
||||
auto bottom = parse_css_value(deprecated_context, parts[2]);
|
||||
auto left = parse_css_value(deprecated_context, parts[3]);
|
||||
if (top && bottom && left && right) {
|
||||
style.set_property(CSS::PropertyID::PaddingTop, *top);
|
||||
style.set_property(CSS::PropertyID::PaddingBottom, *bottom);
|
||||
style.set_property(CSS::PropertyID::PaddingLeft, *left);
|
||||
style.set_property(CSS::PropertyID::PaddingRight, *right);
|
||||
}
|
||||
return;
|
||||
}
|
||||
dbgln("Unsure what to do with CSS padding value '{}'", value.to_string());
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 2) {
|
||||
@ -1557,18 +1196,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::ListStyle) {
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (!parts.is_empty()) {
|
||||
auto value = parse_css_value(deprecated_context, parts[0]);
|
||||
if (!value)
|
||||
return;
|
||||
style.set_property(CSS::PropertyID::ListStyleType, value.release_nonnull());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
|
||||
@ -1626,30 +1253,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::Font) {
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (parts.size() < 2)
|
||||
return;
|
||||
auto size_parts = parts[0].split_view('/');
|
||||
if (size_parts.size() == 2) {
|
||||
auto size = parse_css_value(deprecated_context, size_parts[0]);
|
||||
auto line_height = parse_css_value(deprecated_context, size_parts[1]);
|
||||
if (!size || !line_height)
|
||||
return;
|
||||
style.set_property(CSS::PropertyID::FontSize, size.release_nonnull());
|
||||
style.set_property(CSS::PropertyID::LineHeight, line_height.release_nonnull());
|
||||
} else if (size_parts.size() == 1) {
|
||||
auto size = parse_css_value(deprecated_context, parts[0]);
|
||||
if (!size)
|
||||
return;
|
||||
style.set_property(CSS::PropertyID::FontSize, size.release_nonnull());
|
||||
}
|
||||
auto family = parse_css_value(deprecated_context, parts[1]);
|
||||
style.set_property(CSS::PropertyID::FontFamily, family.release_nonnull());
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
|
||||
@ -1779,44 +1382,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (parts.size() == 1) {
|
||||
auto flex_grow = parse_css_value(deprecated_context, parts[0]);
|
||||
style.set_property(CSS::PropertyID::FlexGrow, *flex_grow);
|
||||
return;
|
||||
}
|
||||
|
||||
if (parts.size() == 2) {
|
||||
auto flex_grow = parse_css_value(deprecated_context, parts[0]);
|
||||
style.set_property(CSS::PropertyID::FlexGrow, *flex_grow);
|
||||
|
||||
auto second_value = parse_css_value(deprecated_context, parts[1]);
|
||||
if (second_value->is_length() || (second_value->is_identifier() && second_value->to_identifier() == CSS::ValueID::Content)) {
|
||||
style.set_property(CSS::PropertyID::FlexBasis, *second_value);
|
||||
} else {
|
||||
auto flex_shrink = parse_css_value(deprecated_context, parts[1]);
|
||||
style.set_property(CSS::PropertyID::FlexShrink, *flex_shrink);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (parts.size() == 3) {
|
||||
auto flex_grow = parse_css_value(deprecated_context, parts[0]);
|
||||
style.set_property(CSS::PropertyID::FlexGrow, *flex_grow);
|
||||
auto flex_shrink = parse_css_value(deprecated_context, parts[1]);
|
||||
style.set_property(CSS::PropertyID::FlexShrink, *flex_shrink);
|
||||
|
||||
auto third_value = parse_css_value(deprecated_context, parts[2]);
|
||||
if (third_value->is_length() || (third_value->is_identifier() && third_value->to_identifier() == CSS::ValueID::Content))
|
||||
style.set_property(CSS::PropertyID::FlexBasis, *third_value);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.size() == 1) {
|
||||
@ -1871,22 +1436,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
||||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::FlexFlow) {
|
||||
// FIXME: Remove string parsing once DeprecatedCSSParser is gone.
|
||||
if (value.is_string()) {
|
||||
auto parts = split_on_whitespace(value.to_string());
|
||||
if (parts.is_empty())
|
||||
return;
|
||||
|
||||
auto direction = parse_css_value(deprecated_context, parts[0]);
|
||||
style.set_property(CSS::PropertyID::FlexDirection, direction.release_nonnull());
|
||||
|
||||
if (parts.size() > 1) {
|
||||
auto wrap = parse_css_value(deprecated_context, parts[1]);
|
||||
style.set_property(CSS::PropertyID::FlexWrap, wrap.release_nonnull());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.is_value_list()) {
|
||||
auto parts = static_cast<CSS::ValueListStyleValue const&>(value).values();
|
||||
if (parts.is_empty() || parts.size() > 2)
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <AK/AnyOf.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleInvalidator.h>
|
||||
#include <LibWeb/DOM/DOMException.h>
|
||||
@ -158,7 +158,7 @@ void Element::parse_attribute(const FlyString& name, const String& value)
|
||||
m_classes.unchecked_append(new_class);
|
||||
}
|
||||
} else if (name == HTML::AttributeNames::style) {
|
||||
m_inline_style = parse_css_declaration(CSS::DeprecatedParsingContext(document()), value);
|
||||
m_inline_style = parse_css_declaration(CSS::ParsingContext(document()), value);
|
||||
set_needs_style_update(true);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/SelectorEngine.h>
|
||||
#include <LibWeb/DOM/ParentNode.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
@ -13,17 +13,22 @@ namespace Web::DOM {
|
||||
|
||||
RefPtr<Element> ParentNode::query_selector(const StringView& selector_text)
|
||||
{
|
||||
auto selector = parse_selector(CSS::DeprecatedParsingContext(*this), selector_text);
|
||||
if (!selector)
|
||||
auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text);
|
||||
if (!maybe_selectors.has_value())
|
||||
return {};
|
||||
|
||||
dump_selector(*selector);
|
||||
auto selectors = maybe_selectors.value();
|
||||
|
||||
for (auto& selector : selectors)
|
||||
dump_selector(selector);
|
||||
|
||||
RefPtr<Element> result;
|
||||
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||
if (SelectorEngine::matches(*selector, element)) {
|
||||
result = element;
|
||||
return IterationDecision::Break;
|
||||
for (auto& selector : selectors) {
|
||||
if (SelectorEngine::matches(selector, element)) {
|
||||
result = element;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
@ -33,16 +38,21 @@ RefPtr<Element> ParentNode::query_selector(const StringView& selector_text)
|
||||
|
||||
NonnullRefPtrVector<Element> ParentNode::query_selector_all(const StringView& selector_text)
|
||||
{
|
||||
auto selector = parse_selector(CSS::DeprecatedParsingContext(*this), selector_text);
|
||||
if (!selector)
|
||||
auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text);
|
||||
if (!maybe_selectors.has_value())
|
||||
return {};
|
||||
|
||||
dump_selector(*selector);
|
||||
auto selectors = maybe_selectors.value();
|
||||
|
||||
for (auto& selector : selectors)
|
||||
dump_selector(selector);
|
||||
|
||||
NonnullRefPtrVector<Element> elements;
|
||||
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||
if (SelectorEngine::matches(*selector, element)) {
|
||||
elements.append(element);
|
||||
for (auto& selector : selectors) {
|
||||
if (SelectorEngine::matches(selector, element)) {
|
||||
elements.append(element);
|
||||
}
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/HTMLLinkElement.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
|
@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/HTML/HTMLTableCellElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -5,7 +5,7 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
#include <LibWeb/HTML/HTMLTableColElement.h>
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/Loader/CSSLoader.h>
|
||||
@ -21,7 +21,7 @@ CSSLoader::CSSLoader(DOM::Element& owner_element)
|
||||
|
||||
void CSSLoader::load_from_text(const String& text)
|
||||
{
|
||||
m_style_sheet = parse_css(CSS::DeprecatedParsingContext(m_owner_element.document()), text);
|
||||
m_style_sheet = parse_css(CSS::ParsingContext(m_owner_element.document()), text);
|
||||
if (!m_style_sheet) {
|
||||
m_style_sheet = CSS::CSSStyleSheet::create({});
|
||||
m_style_sheet->set_owner_node(&m_owner_element);
|
||||
@ -49,7 +49,7 @@ void CSSLoader::resource_did_load()
|
||||
dbgln_if(CSS_LOADER_DEBUG, "CSSLoader: Resource did load, has encoded data. URL: {}", resource()->url());
|
||||
}
|
||||
|
||||
auto sheet = parse_css(CSS::DeprecatedParsingContext(m_owner_element.document()), resource()->encoded_data());
|
||||
auto sheet = parse_css(CSS::ParsingContext(m_owner_element.document()), resource()->encoded_data());
|
||||
if (!sheet) {
|
||||
dbgln_if(CSS_LOADER_DEBUG, "CSSLoader: Failed to parse stylesheet: {}", resource()->url());
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user