Skip to content

Truly independent web browser

LibWeb: Remove CSS helpers that the Rust style and layout replaced

Aliaksandr Kalenik8c56784754ec
diff --git a/Libraries/LibWeb/CSS/Display.cpp b/Libraries/LibWeb/CSS/Display.cpp
index 75554a72f72..866a7428010 100644
--- a/Libraries/LibWeb/CSS/Display.cpp
+++ b/Libraries/LibWeb/CSS/Display.cpp
@@ -27,61 +27,6 @@ String Display::to_string() const
return MUST(String::join(' ', parts));
}
-Display Display::from_keyword(Keyword keyword)
-{
- switch (keyword) {
- case Keyword::None:
- return Display::from_short(Short::None);
- case Keyword::Contents:
- return Display::from_short(Short::Contents);
- case Keyword::Block:
- return Display::from_short(Short::Block);
- case Keyword::Inline:
- return Display::from_short(Short::Inline);
- case Keyword::Flow:
- return Display::from_short(Short::Flow);
- case Keyword::FlowRoot:
- return Display::from_short(Short::FlowRoot);
- case Keyword::InlineBlock:
- return Display::from_short(Short::InlineBlock);
- case Keyword::RunIn:
- return Display::from_short(Short::RunIn);
- case Keyword::ListItem:
- return Display::from_short(Short::ListItem);
- case Keyword::Flex:
- return Display::from_short(Short::Flex);
- case Keyword::InlineFlex:
- return Display::from_short(Short::InlineFlex);
- case Keyword::Grid:
- return Display::from_short(Short::Grid);
- case Keyword::InlineGrid:
- return Display::from_short(Short::InlineGrid);
- case Keyword::Ruby:
- return Display::from_short(Short::Ruby);
- case Keyword::Table:
- return Display::from_short(Short::Table);
- case Keyword::InlineTable:
- return Display::from_short(Short::InlineTable);
- case Keyword::Math:
- return Display::from_short(Short::Math);
- case Keyword::WebkitBox:
- return Display { DisplayOutside::Block, DisplayInside::WebkitBox };
- case Keyword::WebkitInlineBox:
- return Display { DisplayOutside::Inline, DisplayInside::WebkitBox };
- case Keyword::WebkitFlex:
- return Display::from_short(Short::Flex);
- case Keyword::WebkitInlineFlex:
- return Display::from_short(Short::InlineFlex);
- default:
- break;
- }
-
- if (auto internal_value = keyword_to_display_internal(keyword); internal_value.has_value())
- return Display { internal_value.release_value() };
-
- VERIFY_NOT_REACHED();
-}
-
Display Display::from_short(Short short_)
{
switch (short_) {
diff --git a/Libraries/LibWeb/CSS/Display.h b/Libraries/LibWeb/CSS/Display.h
index fb82d42aabb..ba40156d84d 100644
--- a/Libraries/LibWeb/CSS/Display.h
+++ b/Libraries/LibWeb/CSS/Display.h
@@ -57,28 +57,10 @@ public:
return m_value.internal;
}
- bool is_table_column() const { return is_internal() && internal() == DisplayInternal::TableColumn; }
- bool is_table_row_group() const { return is_internal() && internal() == DisplayInternal::TableRowGroup; }
- bool is_table_header_group() const { return is_internal() && internal() == DisplayInternal::TableHeaderGroup; }
- bool is_table_footer_group() const { return is_internal() && internal() == DisplayInternal::TableFooterGroup; }
bool is_table_row() const { return is_internal() && internal() == DisplayInternal::TableRow; }
bool is_table_cell() const { return is_internal() && internal() == DisplayInternal::TableCell; }
- bool is_table_column_group() const { return is_internal() && internal() == DisplayInternal::TableColumnGroup; }
bool is_table_caption() const { return is_internal() && internal() == DisplayInternal::TableCaption; }
- // https://drafts.csswg.org/css-display-3/#internal-table-element
- bool is_internal_table() const
- {
- return is_internal()
- && (internal() == DisplayInternal::TableRowGroup
- || internal() == DisplayInternal::TableHeaderGroup
- || internal() == DisplayInternal::TableFooterGroup
- || internal() == DisplayInternal::TableRow
- || internal() == DisplayInternal::TableCell
- || internal() == DisplayInternal::TableColumnGroup
- || internal() == DisplayInternal::TableColumn);
- }
-
bool is_none() const { return m_type == Type::Box && m_value.box == DisplayBox::None; }
bool is_contents() const { return m_type == Type::Box && m_value.box == DisplayBox::Contents; }
@@ -94,7 +76,6 @@ public:
bool is_block_outside() const { return is_outside_and_inside() && outside() == DisplayOutside::Block; }
bool is_inline_outside() const { return is_outside_and_inside() && outside() == DisplayOutside::Inline; }
- bool is_inline_block() const { return is_inline_outside() && is_flow_root_inside(); }
ListItem list_item() const
{
@@ -114,10 +95,7 @@ public:
bool is_flow_root_inside() const { return is_outside_and_inside() && inside() == DisplayInside::FlowRoot; }
bool is_table_inside() const { return is_outside_and_inside() && inside() == DisplayInside::Table; }
bool is_flex_inside() const { return is_outside_and_inside() && first_is_one_of(inside(), DisplayInside::Flex, DisplayInside::WebkitBox); }
- bool is_webkit_box_inside() const { return is_outside_and_inside() && inside() == DisplayInside::WebkitBox; }
bool is_grid_inside() const { return is_outside_and_inside() && inside() == DisplayInside::Grid; }
- bool is_ruby_inside() const { return is_outside_and_inside() && inside() == DisplayInside::Ruby; }
- bool is_math_inside() const { return is_outside_and_inside() && inside() == DisplayInside::Math; }
enum class Short {
None,
@@ -140,7 +118,6 @@ public:
Math,
};
- static Display from_keyword(Keyword);
static Display from_short(Short short_);
Optional<Keyword> to_keyword() const;
diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cpp
index 6446252819b..8877c546851 100644
--- a/Libraries/LibWeb/CSS/Length.cpp
+++ b/Libraries/LibWeb/CSS/Length.cpp
@@ -111,21 +111,11 @@ Length Length::percentage_of(Percentage const& percentage) const
return Length { percentage.as_fraction() * raw_value(), m_unit };
}
-CSSPixels Length::font_relative_length_to_px(Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
-{
- return CSSPixels::nearest_value_for(font_relative_length_to_px_without_rounding(font_metrics, root_font_metrics));
-}
-
double Length::font_relative_length_to_px_without_rounding(Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
{
return ratio_between_font_relative_unit_and_px(m_unit, font_metrics, root_font_metrics) * m_value;
}
-CSSPixels Length::viewport_relative_length_to_px(CSSPixelRect const& viewport_rect) const
-{
- return CSSPixels::nearest_value_for(viewport_relative_length_to_px_without_rounding(viewport_rect));
-}
-
double Length::viewport_relative_length_to_px_without_rounding(CSSPixelRect const& viewport_rect) const
{
return ratio_between_viewport_relative_unit_and_px(m_unit, viewport_rect) * m_value;
diff --git a/Libraries/LibWeb/CSS/Length.h b/Libraries/LibWeb/CSS/Length.h
index 6ff6c9b8be6..acafe5455e8 100644
--- a/Libraries/LibWeb/CSS/Length.h
+++ b/Libraries/LibWeb/CSS/Length.h
@@ -155,26 +155,6 @@ public:
VERIFY_NOT_REACHED();
}
- ALWAYS_INLINE CSSPixels to_px(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const
- {
- if (is_absolute())
- return absolute_length_to_px();
- if (is_font_relative())
- return font_relative_length_to_px(font_metrics, root_font_metrics);
- if (is_viewport_relative())
- return viewport_relative_length_to_px(viewport_rect);
- if (is_container_relative()) {
- ResolutionContext context {
- .viewport_rect = viewport_rect,
- .font_metrics = font_metrics,
- .root_font_metrics = root_font_metrics,
- };
- return CSSPixels::nearest_value_for(container_relative_length_to_px_without_rounding(context));
- }
-
- VERIFY_NOT_REACHED();
- }
-
[[nodiscard]] ALWAYS_INLINE CSSPixels absolute_length_to_px() const
{
return CSSPixels::nearest_value_for(absolute_length_to_px_without_rounding());
@@ -193,9 +173,7 @@ public:
return m_unit == other.m_unit && m_value == other.m_value;
}
- CSSPixels font_relative_length_to_px(FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
double font_relative_length_to_px_without_rounding(FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const;
- CSSPixels viewport_relative_length_to_px(CSSPixelRect const& viewport_rect) const;
double viewport_relative_length_to_px_without_rounding(CSSPixelRect const& viewport_rect) const;
double container_relative_length_to_px_without_rounding(ResolutionContext const&) const;
@@ -206,63 +184,7 @@ private:
double m_value { 0 };
};
-// FIXME: This should be CSSPixelsOrAuto since it's only used after computation when lengths have been absolutized
-class LengthOrAuto {
-public:
- LengthOrAuto(Length length)
- : m_length(move(length))
- {
- }
-
- static LengthOrAuto make_auto() { return LengthOrAuto { OptionalNone {} }; }
-
- bool is_length() const { return m_length.has_value(); }
- bool is_auto() const { return !m_length.has_value(); }
-
- Length const& length() const { return m_length.value(); }
-
- void serialize(StringBuilder& builder, SerializationMode mode = SerializationMode::Normal) const
- {
- if (is_auto())
- builder.append("auto"sv);
- else
- m_length->serialize(builder, mode);
- }
-
- String to_string(SerializationMode mode = SerializationMode::Normal) const
- {
- StringBuilder builder;
- serialize(builder, mode);
- return builder.to_string_without_validation();
- }
-
- CSSPixels to_px_or_zero() const
- {
- if (is_auto())
- return 0;
- return m_length->absolute_length_to_px();
- }
-
- bool operator==(LengthOrAuto const&) const = default;
-
-private:
- explicit LengthOrAuto(Optional<Length> maybe_length)
- : m_length(move(maybe_length))
- {
- }
-
- Optional<Length> m_length;
-};
-
double ratio_between_font_relative_unit_and_px(LengthUnit font_relative_unit, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics);
double ratio_between_viewport_relative_unit_and_px(LengthUnit viewport_relative_unit, CSSPixelRect const& viewport_rect);
}
-
-template<>
-struct AK::Formatter<Web::CSS::LengthOrAuto> : Formatter<StringView> {
- ErrorOr<void> format(FormatBuilder& builder, Web::CSS::LengthOrAuto const& length_or_auto)
- {
- return Formatter<StringView>::format(builder, length_or_auto.to_string());
- }
-};
diff --git a/Libraries/LibWeb/CSS/Parser/SubstitutionFunctionsPresence.h b/Libraries/LibWeb/CSS/Parser/SubstitutionFunctionsPresence.h
index 5d94fd62712..2dd7d2ede9e 100644
--- a/Libraries/LibWeb/CSS/Parser/SubstitutionFunctionsPresence.h
+++ b/Libraries/LibWeb/CSS/Parser/SubstitutionFunctionsPresence.h
@@ -15,8 +15,6 @@ struct SubstitutionFunctionsPresence {
bool if_ { false };
bool inherit { false };
bool var { false };
-
- bool has_any() const { return attr || dashed_function || env || if_ || inherit || var; }
};
}
diff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
index 57a8f22a346..148d4720eed 100644
--- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
+++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
@@ -287,8 +287,6 @@ ValueComparingNonnullRefPtr<StyleValue const> StyleValue::create_guaranteed_inva
void StyleValue::set_style_sheet(StyleSheetState* style_sheet)
{
- m_has_style_sheet_context = !!style_sheet;
-
// Only the types holding nested values with document-associated state care.
switch (type()) {
case Type::Content:
@@ -560,17 +558,6 @@ StyleValueVector StyleValue::subdivide_into_iterations(PropertyNameAndID const&
return StyleValueVector { *this };
}
-i32 int_from_style_value(NonnullRefPtr<StyleValue const> const& style_value)
-{
- if (style_value->is_integer())
- return style_value->as_integer().integer();
-
- if (style_value->is_calculated())
- return style_value->as_calculated().resolve_integer({}).value();
-
- VERIFY_NOT_REACHED();
-}
-
double number_from_style_value(NonnullRefPtr<StyleValue const> const& style_value, Optional<double> percentage_basis)
{
if (style_value->is_number())
diff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.h b/Libraries/LibWeb/CSS/StyleValues/StyleValue.h
index f12317a4222..c7d5377d1e8 100644
--- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.h
+++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.h
@@ -218,7 +218,6 @@ public:
StyleValueVector subdivide_into_iterations(PropertyNameAndID const&) const;
void set_style_sheet(StyleSheetState*);
- bool has_style_sheet_context() const { return m_has_style_sheet_context; }
bool equals(StyleValue const& other) const;
@@ -242,7 +241,6 @@ protected:
private:
Type m_type;
- bool m_has_style_sheet_context { false };
};
template<typename T>
@@ -251,7 +249,6 @@ struct StyleValueWithDefaultOperators : public StyleValue {
using Base = StyleValue;
};
-i32 int_from_style_value(NonnullRefPtr<StyleValue const> const& style_value);
double number_from_style_value(NonnullRefPtr<StyleValue const> const& style_value, Optional<double> percentage_basis);
Utf16FlyString string_from_style_value(NonnullRefPtr<StyleValue const> const& style_value);
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index 3f1156c55d6..334ae517fb8 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -329,7 +329,6 @@ class IntegerStyleValue;
class KeywordStyleValue;
class Length;
class LengthBox;
-class LengthOrAuto;
class LengthPercentage;
class LengthPercentageOrAuto;
class LengthStyleValue;