From 356d8bcfe8a90f5dff6c661d37e1cf3ccf2a184a Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 18 Feb 2022 16:50:17 +0000 Subject: [PATCH] LibWeb: Remove Length::Type::Undefined! :^) --- Userland/Libraries/LibWeb/CSS/Length.cpp | 7 ++----- Userland/Libraries/LibWeb/CSS/Length.h | 6 +----- Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 2 +- Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 1 - .../Libraries/LibWeb/Layout/BlockFormattingContext.cpp | 4 ++-- Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp | 5 +++-- .../Libraries/LibWeb/Layout/InlineFormattingContext.cpp | 4 ++-- .../Libraries/LibWeb/Layout/TableFormattingContext.cpp | 4 ++-- 8 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp index 8c1694f1cc..c19a6505a2 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.cpp +++ b/Userland/Libraries/LibWeb/CSS/Length.cpp @@ -18,7 +18,6 @@ namespace Web::CSS { -Length::Length() = default; Length::Length(int value, Type type) : m_type(type) , m_value(value) @@ -49,8 +48,8 @@ Length Length::make_calculated(NonnullRefPtr calculated_st Length Length::percentage_of(Percentage const& percentage) const { - if (is_undefined_or_auto()) { - dbgln("Attempting to get percentage of an undefined or auto length, this seems wrong? But for now we just return the original length."); + if (is_auto()) { + dbgln("Attempting to get percentage of an auto length, this seems wrong? But for now we just return the original length."); return *this; } @@ -132,8 +131,6 @@ const char* Length::unit_name() const return "rem"; case Type::Auto: return "auto"; - case Type::Undefined: - return "undefined"; case Type::Vh: return "vh"; case Type::Vw: diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h index 60494aca0b..16abee4201 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.h +++ b/Userland/Libraries/LibWeb/CSS/Length.h @@ -15,7 +15,6 @@ namespace Web::CSS { class Length { public: enum class Type { - Undefined, Calculated, Auto, Cm, @@ -37,7 +36,6 @@ public: // We have a RefPtr member, but can't include the header StyleValue.h as it includes // this file already. To break the cyclic dependency, we must move all method definitions out. - Length(); Length(int value, Type type); Length(float value, Type type); @@ -48,8 +46,6 @@ public: Length resolved(Layout::Node const& layout_node) const; - bool is_undefined_or_auto() const { return m_type == Type::Undefined || m_type == Type::Auto; } - bool is_undefined() const { return m_type == Type::Undefined; } bool is_auto() const { return m_type == Type::Auto; } bool is_calculated() const { return m_type == Type::Calculated; } @@ -137,7 +133,7 @@ public: private: const char* unit_name() const; - Type m_type { Type::Undefined }; + Type m_type; float m_value { 0 }; RefPtr m_calculated_style; diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 086db9e3e0..e86721850d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -131,7 +131,7 @@ float StyleProperties::line_height(Layout::Node const& layout_node) const if (line_height->is_length()) { auto line_height_length = line_height->to_length(); - if (!line_height_length.is_undefined_or_auto()) + if (!line_height_length.is_auto()) return line_height_length.to_px(layout_node); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 6001bb5696..6a5451934a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -500,7 +500,6 @@ Optional CalculatedStyleValue::resolve_length(Layout::Node const& layout Optional CalculatedStyleValue::resolve_length_percentage(Layout::Node const& layout_node, Length const& percentage_basis) const { - VERIFY(!percentage_basis.is_undefined()); auto result = m_expression->resolve(&layout_node, percentage_basis); return result.value().visit( diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index eefe68c32d..ad964baba3 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -295,7 +295,7 @@ float BlockFormattingContext::compute_theoretical_height(Box const& box) height = compute_height_for_replaced_element(verify_cast(box)); } else { if (!box.computed_values().height().has_value() - || (box.computed_values().height()->is_length() && box.computed_values().height()->length().is_undefined_or_auto()) + || (box.computed_values().height()->is_length() && box.computed_values().height()->length().is_auto()) || (computed_values.height().has_value() && computed_values.height()->is_percentage() && !is_absolute(containing_block.computed_values().height()))) { height = compute_auto_height_for_block_level_element(box, ConsiderFloats::No); } else { @@ -441,7 +441,7 @@ void BlockFormattingContext::layout_block_level_children(BlockContainer& block_c if (layout_mode != LayoutMode::Default) { auto& width = block_container.computed_values().width(); - if (!width.has_value() || (width->is_length() && width->length().is_undefined_or_auto())) + if (!width.has_value() || (width->is_length() && width->length().is_auto())) block_container.set_content_width(content_width); } } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index 6161d2e5e7..a2e39d122c 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -29,7 +29,7 @@ static bool is_undefined_or_auto(Optional const& length_p { if (!length_percentage.has_value()) return true; - return length_percentage->is_length() && length_percentage->length().is_undefined_or_auto(); + return length_percentage->is_length() && length_percentage->length().is_auto(); } FlexFormattingContext::FlexFormattingContext(Box& flex_container, FormattingContext* parent) @@ -235,11 +235,12 @@ bool FlexFormattingContext::cross_size_is_absolute_or_resolved_nicely(NodeWithSt if (!length_percentage.has_value()) return false; + // FIXME: Handle calc here. if (length_percentage->is_length()) { auto& length = length_percentage->length(); if (length.is_absolute() || length.is_relative()) return true; - if (length.is_undefined_or_auto()) + if (length.is_auto()) return false; } diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 59f1abbb02..4e803f7434 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -126,7 +126,7 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_ auto& inline_block = const_cast(verify_cast(box)); auto& width_value = inline_block.computed_values().width(); - if (!width_value.has_value() || (width_value->is_length() && width_value->length().is_undefined_or_auto())) { + if (!width_value.has_value() || (width_value->is_length() && width_value->length().is_auto())) { auto result = calculate_shrink_to_fit_widths(inline_block); auto available_width = containing_block().content_width() @@ -146,7 +146,7 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_ auto independent_formatting_context = layout_inside(inline_block, layout_mode); auto& height_value = inline_block.computed_values().height(); - if (!height_value.has_value() || (height_value->is_length() && height_value->length().is_undefined_or_auto())) { + if (!height_value.has_value() || (height_value->is_length() && height_value->length().is_auto())) { // FIXME: (10.6.6) If 'height' is 'auto', the height depends on the element's descendants per 10.6.7. BlockFormattingContext::compute_height(inline_block); } else { diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index 9683e798b8..508ba34434 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -72,7 +72,7 @@ void TableFormattingContext::calculate_column_widths(Box& row, Vector& co { size_t column_index = 0; auto* table = row.first_ancestor_of_type(); - bool use_auto_layout = !table || (!table->computed_values().width().has_value() || (table->computed_values().width()->is_length() && table->computed_values().width()->length().is_undefined_or_auto())); + bool use_auto_layout = !table || (!table->computed_values().width().has_value() || (table->computed_values().width()->is_length() && table->computed_values().width()->length().is_auto())); row.for_each_child_of_type([&](auto& cell) { compute_width(cell); if (use_auto_layout) { @@ -91,7 +91,7 @@ void TableFormattingContext::layout_row(Box& row, Vector& column_widths) float tallest_cell_height = 0; float content_width = 0; auto* table = row.first_ancestor_of_type(); - bool use_auto_layout = !table || (!table->computed_values().width().has_value() || (table->computed_values().width()->is_length() && table->computed_values().width()->length().is_undefined_or_auto())); + bool use_auto_layout = !table || (!table->computed_values().width().has_value() || (table->computed_values().width()->is_length() && table->computed_values().width()->length().is_auto())); row.for_each_child_of_type([&](auto& cell) { cell.set_offset(row.effective_offset().translated(content_width, 0));