mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
LibWeb: Convert width/height and min-/max- versions to LengthPercentage
A lot of this is quite ugly, but it should only be so until I remove Length::Type::Percentage entirely. (Which should happen later in this PR, otherwise, yell at me!) For now, a lot of things have to be resolved twice, first from a LengthPercentage to a Length, and then from a Length to a pixel one.
This commit is contained in:
parent
cb0cce5cdc
commit
dc681913e8
Notes:
sideshowbarker
2024-07-17 20:36:20 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/dc681913e85 Pull-request: https://github.com/SerenityOS/serenity/pull/12007
12 changed files with 276 additions and 194 deletions
|
@ -104,12 +104,12 @@ public:
|
|||
CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
|
||||
Optional<BoxShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
|
||||
CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; }
|
||||
const CSS::Length& width() const { return m_noninherited.width; }
|
||||
const CSS::Length& min_width() const { return m_noninherited.min_width; }
|
||||
const CSS::Length& max_width() const { return m_noninherited.max_width; }
|
||||
const CSS::Length& height() const { return m_noninherited.height; }
|
||||
const CSS::Length& min_height() const { return m_noninherited.min_height; }
|
||||
const CSS::Length& max_height() const { return m_noninherited.max_height; }
|
||||
CSS::LengthPercentage const& width() const { return m_noninherited.width; }
|
||||
CSS::LengthPercentage const& min_width() const { return m_noninherited.min_width; }
|
||||
CSS::LengthPercentage const& max_width() const { return m_noninherited.max_width; }
|
||||
CSS::LengthPercentage const& height() const { return m_noninherited.height; }
|
||||
CSS::LengthPercentage const& min_height() const { return m_noninherited.min_height; }
|
||||
CSS::LengthPercentage const& max_height() const { return m_noninherited.max_height; }
|
||||
|
||||
const CSS::LengthBox& offset() const { return m_noninherited.offset; }
|
||||
const CSS::LengthBox& margin() const { return m_noninherited.margin; }
|
||||
|
@ -169,12 +169,12 @@ protected:
|
|||
Optional<int> z_index;
|
||||
CSS::TextDecorationLine text_decoration_line { InitialValues::text_decoration_line() };
|
||||
CSS::Position position { InitialValues::position() };
|
||||
CSS::Length width;
|
||||
CSS::Length min_width;
|
||||
CSS::Length max_width;
|
||||
CSS::Length height;
|
||||
CSS::Length min_height;
|
||||
CSS::Length max_height;
|
||||
CSS::LengthPercentage width { Length::make_auto() };
|
||||
CSS::LengthPercentage min_width { Length::make_auto() };
|
||||
CSS::LengthPercentage max_width { Length::make_auto() };
|
||||
CSS::LengthPercentage height { Length::make_auto() };
|
||||
CSS::LengthPercentage min_height { Length::make_auto() };
|
||||
CSS::LengthPercentage max_height { Length::make_auto() };
|
||||
CSS::LengthBox offset;
|
||||
CSS::LengthBox margin;
|
||||
CSS::LengthBox padding;
|
||||
|
@ -222,12 +222,12 @@ public:
|
|||
void set_text_transform(CSS::TextTransform value) { m_inherited.text_transform = value; }
|
||||
void set_position(CSS::Position position) { m_noninherited.position = position; }
|
||||
void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; }
|
||||
void set_width(const CSS::Length& width) { m_noninherited.width = width; }
|
||||
void set_min_width(const CSS::Length& width) { m_noninherited.min_width = width; }
|
||||
void set_max_width(const CSS::Length& width) { m_noninherited.max_width = width; }
|
||||
void set_height(const CSS::Length& height) { m_noninherited.height = height; }
|
||||
void set_min_height(const CSS::Length& height) { m_noninherited.min_height = height; }
|
||||
void set_max_height(const CSS::Length& height) { m_noninherited.max_height = height; }
|
||||
void set_width(CSS::LengthPercentage const& width) { m_noninherited.width = width; }
|
||||
void set_min_width(CSS::LengthPercentage const& width) { m_noninherited.min_width = width; }
|
||||
void set_max_width(CSS::LengthPercentage const& width) { m_noninherited.max_width = width; }
|
||||
void set_height(CSS::LengthPercentage const& height) { m_noninherited.height = height; }
|
||||
void set_min_height(CSS::LengthPercentage const& height) { m_noninherited.min_height = height; }
|
||||
void set_max_height(CSS::LengthPercentage const& height) { m_noninherited.max_height = height; }
|
||||
void set_offset(const CSS::LengthBox& offset) { m_noninherited.offset = offset; }
|
||||
void set_margin(const CSS::LengthBox& margin) { m_noninherited.margin = margin; }
|
||||
void set_padding(const CSS::LengthBox& padding) { m_noninherited.padding = padding; }
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
namespace Web::CSS {
|
||||
|
||||
struct LengthBox {
|
||||
Length top { Length::make_auto() };
|
||||
Length right { Length::make_auto() };
|
||||
Length bottom { Length::make_auto() };
|
||||
Length left { Length::make_auto() };
|
||||
LengthPercentage top { Length::make_auto() };
|
||||
LengthPercentage right { Length::make_auto() };
|
||||
LengthPercentage bottom { Length::make_auto() };
|
||||
LengthPercentage left { Length::make_auto() };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -505,59 +505,59 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
|
|||
return BoxShadowStyleValue::create(box_shadow_data.offset_x, box_shadow_data.offset_y, box_shadow_data.blur_radius, box_shadow_data.color);
|
||||
}
|
||||
case CSS::PropertyID::Width:
|
||||
return LengthStyleValue::create(layout_node.computed_values().width());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().width());
|
||||
case CSS::PropertyID::MinWidth:
|
||||
if (layout_node.computed_values().min_width().is_undefined_or_auto())
|
||||
if (layout_node.computed_values().min_width().is_length() && layout_node.computed_values().min_width().length().is_undefined_or_auto())
|
||||
return IdentifierStyleValue::create(CSS::ValueID::Auto);
|
||||
return LengthStyleValue::create(layout_node.computed_values().min_width());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().min_width());
|
||||
case CSS::PropertyID::MaxWidth:
|
||||
if (layout_node.computed_values().max_width().is_undefined())
|
||||
if (layout_node.computed_values().max_width().is_length() && layout_node.computed_values().max_width().length().is_undefined())
|
||||
return IdentifierStyleValue::create(CSS::ValueID::None);
|
||||
return LengthStyleValue::create(layout_node.computed_values().max_width());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().max_width());
|
||||
case CSS::PropertyID::Height:
|
||||
return LengthStyleValue::create(layout_node.computed_values().height());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().height());
|
||||
case CSS::PropertyID::MinHeight:
|
||||
if (layout_node.computed_values().min_height().is_undefined_or_auto())
|
||||
if (layout_node.computed_values().min_height().is_length() && layout_node.computed_values().min_height().length().is_undefined_or_auto())
|
||||
return IdentifierStyleValue::create(CSS::ValueID::Auto);
|
||||
return LengthStyleValue::create(layout_node.computed_values().min_height());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().min_height());
|
||||
case CSS::PropertyID::MaxHeight:
|
||||
if (layout_node.computed_values().max_height().is_undefined())
|
||||
if (layout_node.computed_values().max_height().is_length() && layout_node.computed_values().max_height().length().is_undefined())
|
||||
return IdentifierStyleValue::create(CSS::ValueID::None);
|
||||
return LengthStyleValue::create(layout_node.computed_values().max_height());
|
||||
return style_value_for_length_percentage(layout_node.computed_values().max_height());
|
||||
case CSS::PropertyID::Margin: {
|
||||
auto margin = layout_node.computed_values().margin();
|
||||
auto values = NonnullRefPtrVector<StyleValue> {};
|
||||
values.append(LengthStyleValue::create(margin.top));
|
||||
values.append(LengthStyleValue::create(margin.right));
|
||||
values.append(LengthStyleValue::create(margin.bottom));
|
||||
values.append(LengthStyleValue::create(margin.left));
|
||||
values.append(style_value_for_length_percentage(margin.top));
|
||||
values.append(style_value_for_length_percentage(margin.right));
|
||||
values.append(style_value_for_length_percentage(margin.bottom));
|
||||
values.append(style_value_for_length_percentage(margin.left));
|
||||
return StyleValueList::create(move(values));
|
||||
}
|
||||
case CSS::PropertyID::MarginTop:
|
||||
return LengthStyleValue::create(layout_node.computed_values().margin().top);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().margin().top);
|
||||
case CSS::PropertyID::MarginRight:
|
||||
return LengthStyleValue::create(layout_node.computed_values().margin().right);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().margin().right);
|
||||
case CSS::PropertyID::MarginBottom:
|
||||
return LengthStyleValue::create(layout_node.computed_values().margin().bottom);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().margin().bottom);
|
||||
case CSS::PropertyID::MarginLeft:
|
||||
return LengthStyleValue::create(layout_node.computed_values().margin().left);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().margin().left);
|
||||
case CSS::PropertyID::Padding: {
|
||||
auto padding = layout_node.computed_values().padding();
|
||||
auto values = NonnullRefPtrVector<StyleValue> {};
|
||||
values.append(LengthStyleValue::create(padding.top));
|
||||
values.append(LengthStyleValue::create(padding.right));
|
||||
values.append(LengthStyleValue::create(padding.bottom));
|
||||
values.append(LengthStyleValue::create(padding.left));
|
||||
values.append(style_value_for_length_percentage(padding.top));
|
||||
values.append(style_value_for_length_percentage(padding.right));
|
||||
values.append(style_value_for_length_percentage(padding.bottom));
|
||||
values.append(style_value_for_length_percentage(padding.left));
|
||||
return StyleValueList::create(move(values));
|
||||
}
|
||||
case CSS::PropertyID::PaddingTop:
|
||||
return LengthStyleValue::create(layout_node.computed_values().padding().top);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().padding().top);
|
||||
case CSS::PropertyID::PaddingRight:
|
||||
return LengthStyleValue::create(layout_node.computed_values().padding().right);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().padding().right);
|
||||
case CSS::PropertyID::PaddingBottom:
|
||||
return LengthStyleValue::create(layout_node.computed_values().padding().bottom);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().padding().bottom);
|
||||
case CSS::PropertyID::PaddingLeft:
|
||||
return LengthStyleValue::create(layout_node.computed_values().padding().left);
|
||||
return style_value_for_length_percentage(layout_node.computed_values().padding().left);
|
||||
case CSS::PropertyID::BorderRadius: {
|
||||
auto maybe_top_left_radius = property(CSS::PropertyID::BorderTopLeftRadius);
|
||||
auto maybe_top_right_radius = property(CSS::PropertyID::BorderTopRightRadius);
|
||||
|
|
|
@ -47,28 +47,55 @@ Optional<NonnullRefPtr<StyleValue>> StyleProperties::property(CSS::PropertyID pr
|
|||
return it->value;
|
||||
}
|
||||
|
||||
Length StyleProperties::length_or_fallback(CSS::PropertyID id, const Length& fallback) const
|
||||
Length StyleProperties::length_or_fallback(CSS::PropertyID id, Length const& fallback) const
|
||||
{
|
||||
auto value = property(id);
|
||||
if (!value.has_value())
|
||||
auto maybe_value = property(id);
|
||||
if (!maybe_value.has_value())
|
||||
return fallback;
|
||||
auto& value = maybe_value.value();
|
||||
|
||||
if (value.value()->is_calculated()) {
|
||||
if (value->is_calculated()) {
|
||||
Length length = Length(0, Length::Type::Calculated);
|
||||
length.set_calculated_style(&value.value()->as_calculated());
|
||||
length.set_calculated_style(&value->as_calculated());
|
||||
return length;
|
||||
}
|
||||
|
||||
return value.value()->to_length();
|
||||
if (value->has_length())
|
||||
return value->to_length();
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
LengthPercentage StyleProperties::length_percentage_or_fallback(CSS::PropertyID id, LengthPercentage const& fallback) const
|
||||
{
|
||||
auto maybe_value = property(id);
|
||||
if (!maybe_value.has_value())
|
||||
return fallback;
|
||||
auto& value = maybe_value.value();
|
||||
|
||||
if (value->is_calculated()) {
|
||||
// FIXME: Handle percentages here
|
||||
Length length = Length(0, Length::Type::Calculated);
|
||||
length.set_calculated_style(&value->as_calculated());
|
||||
return length;
|
||||
}
|
||||
|
||||
if (value->is_percentage())
|
||||
return value->as_percentage().percentage();
|
||||
|
||||
if (value->has_length())
|
||||
return value->to_length();
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
LengthBox StyleProperties::length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const
|
||||
{
|
||||
LengthBox box;
|
||||
box.left = length_or_fallback(left_id, default_value);
|
||||
box.top = length_or_fallback(top_id, default_value);
|
||||
box.right = length_or_fallback(right_id, default_value);
|
||||
box.bottom = length_or_fallback(bottom_id, default_value);
|
||||
box.left = length_percentage_or_fallback(left_id, default_value);
|
||||
box.top = length_percentage_or_fallback(top_id, default_value);
|
||||
box.right = length_percentage_or_fallback(right_id, default_value);
|
||||
box.bottom = length_percentage_or_fallback(bottom_id, default_value);
|
||||
return box;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,8 @@ public:
|
|||
void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue> value);
|
||||
Optional<NonnullRefPtr<StyleValue>> property(CSS::PropertyID) const;
|
||||
|
||||
Length length_or_fallback(CSS::PropertyID, const Length& fallback) const;
|
||||
Length length_or_fallback(CSS::PropertyID, Length const& fallback) const;
|
||||
LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const;
|
||||
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const;
|
||||
Color color_or_fallback(CSS::PropertyID, Layout::NodeWithStyle const&, Color fallback) const;
|
||||
Optional<CSS::TextAlign> text_align() const;
|
||||
|
|
|
@ -122,18 +122,19 @@ void BlockFormattingContext::compute_width(Box& box)
|
|||
|
||||
auto& computed_values = box.computed_values();
|
||||
float width_of_containing_block = box.containing_block()->width();
|
||||
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
|
||||
|
||||
auto zero_value = CSS::Length::make_px(0);
|
||||
|
||||
auto margin_left = CSS::Length::make_auto();
|
||||
auto margin_right = CSS::Length::make_auto();
|
||||
const auto padding_left = computed_values.padding().left.resolved_or_zero(box, width_of_containing_block);
|
||||
const auto padding_right = computed_values.padding().right.resolved_or_zero(box, width_of_containing_block);
|
||||
const auto padding_left = computed_values.padding().left.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
const auto padding_right = computed_values.padding().right.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
|
||||
auto try_compute_width = [&](const auto& a_width) {
|
||||
CSS::Length width = a_width;
|
||||
margin_left = computed_values.margin().left.resolved_or_zero(box, width_of_containing_block);
|
||||
margin_right = computed_values.margin().right.resolved_or_zero(box, width_of_containing_block);
|
||||
margin_left = computed_values.margin().left.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
margin_right = computed_values.margin().right.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
|
||||
float total_px = computed_values.border_left().width + computed_values.border_right().width;
|
||||
for (auto& value : { margin_left, padding_left, width, padding_right, margin_right }) {
|
||||
|
@ -207,14 +208,14 @@ void BlockFormattingContext::compute_width(Box& box)
|
|||
return width;
|
||||
};
|
||||
|
||||
auto specified_width = computed_values.width().resolved_or_auto(box, width_of_containing_block);
|
||||
auto specified_width = computed_values.width().resolved(width_of_containing_block_as_length).resolved_or_auto(box, width_of_containing_block);
|
||||
|
||||
// 1. The tentative used width is calculated (without 'min-width' and 'max-width')
|
||||
auto used_width = try_compute_width(specified_width);
|
||||
|
||||
// 2. The tentative used width is greater than 'max-width', the rules above are applied again,
|
||||
// but this time using the computed value of 'max-width' as the computed value for 'width'.
|
||||
auto specified_max_width = computed_values.max_width().resolved_or_auto(box, width_of_containing_block);
|
||||
auto specified_max_width = computed_values.max_width().resolved(width_of_containing_block_as_length).resolved_or_auto(box, width_of_containing_block);
|
||||
if (!specified_max_width.is_auto()) {
|
||||
if (used_width.to_px(box) > specified_max_width.to_px(box)) {
|
||||
used_width = try_compute_width(specified_max_width);
|
||||
|
@ -223,7 +224,7 @@ void BlockFormattingContext::compute_width(Box& box)
|
|||
|
||||
// 3. If the resulting width is smaller than 'min-width', the rules above are applied again,
|
||||
// but this time using the value of 'min-width' as the computed value for 'width'.
|
||||
auto specified_min_width = computed_values.min_width().resolved_or_auto(box, width_of_containing_block);
|
||||
auto specified_min_width = computed_values.min_width().resolved(width_of_containing_block_as_length).resolved_or_auto(box, width_of_containing_block);
|
||||
if (!specified_min_width.is_auto()) {
|
||||
if (used_width.to_px(box) < specified_min_width.to_px(box)) {
|
||||
used_width = try_compute_width(specified_min_width);
|
||||
|
@ -244,12 +245,13 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box)
|
|||
// 10.3.5 Floating, non-replaced elements
|
||||
auto& computed_values = box.computed_values();
|
||||
float width_of_containing_block = box.containing_block()->width();
|
||||
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
|
||||
auto zero_value = CSS::Length::make_px(0);
|
||||
|
||||
auto margin_left = computed_values.margin().left.resolved_or_zero(box, width_of_containing_block);
|
||||
auto margin_right = computed_values.margin().right.resolved_or_zero(box, width_of_containing_block);
|
||||
const auto padding_left = computed_values.padding().left.resolved_or_zero(box, width_of_containing_block);
|
||||
const auto padding_right = computed_values.padding().right.resolved_or_zero(box, width_of_containing_block);
|
||||
auto margin_left = computed_values.margin().left.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
auto margin_right = computed_values.margin().right.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
const auto padding_left = computed_values.padding().left.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
const auto padding_right = computed_values.padding().right.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
|
||||
// If 'margin-left', or 'margin-right' are computed as 'auto', their used value is '0'.
|
||||
if (margin_left.is_auto())
|
||||
|
@ -257,7 +259,7 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box)
|
|||
if (margin_right.is_auto())
|
||||
margin_right = zero_value;
|
||||
|
||||
auto width = computed_values.width().resolved_or_auto(box, width_of_containing_block);
|
||||
auto width = computed_values.width().resolved(width_of_containing_block_as_length).resolved_or_auto(box, width_of_containing_block);
|
||||
|
||||
// If 'width' is computed as 'auto', the used value is the "shrink-to-fit" width.
|
||||
if (width.is_auto()) {
|
||||
|
@ -290,31 +292,36 @@ void BlockFormattingContext::compute_width_for_block_level_replaced_element_in_n
|
|||
box.set_width(compute_width_for_replaced_element(box));
|
||||
}
|
||||
|
||||
float BlockFormattingContext::compute_theoretical_height(const Box& box)
|
||||
float BlockFormattingContext::compute_theoretical_height(Box const& box)
|
||||
{
|
||||
auto& computed_values = box.computed_values();
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto containing_block_height = CSS::Length::make_px(containing_block.height());
|
||||
|
||||
auto is_absolute = [](CSS::LengthPercentage const& length_percentage) {
|
||||
return length_percentage.is_length() && length_percentage.length().is_absolute();
|
||||
};
|
||||
|
||||
// Then work out what the height is, based on box type and CSS properties.
|
||||
float height = 0;
|
||||
if (is<ReplacedBox>(box)) {
|
||||
height = compute_height_for_replaced_element(verify_cast<ReplacedBox>(box));
|
||||
} else {
|
||||
if (box.computed_values().height().is_undefined_or_auto()
|
||||
|| (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute())) {
|
||||
if ((box.computed_values().height().is_length() && box.computed_values().height().length().is_undefined_or_auto())
|
||||
|| (computed_values.height().is_percentage() && !is_absolute(containing_block.computed_values().height()))) {
|
||||
height = compute_auto_height_for_block_level_element(box, ConsiderFloats::No);
|
||||
} else {
|
||||
height = computed_values.height().resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
height = computed_values.height().resolved(containing_block_height).resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
}
|
||||
}
|
||||
|
||||
auto specified_max_height = computed_values.max_height().resolved_or_auto(box, containing_block.height());
|
||||
auto specified_max_height = computed_values.max_height().resolved(containing_block_height).resolved_or_auto(box, containing_block.height());
|
||||
if (!specified_max_height.is_auto()
|
||||
&& !(computed_values.max_height().is_percentage() && !containing_block.computed_values().height().is_absolute()))
|
||||
&& !(computed_values.max_height().is_percentage() && !is_absolute(containing_block.computed_values().height())))
|
||||
height = min(height, specified_max_height.to_px(box));
|
||||
auto specified_min_height = computed_values.min_height().resolved_or_auto(box, containing_block.height());
|
||||
auto specified_min_height = computed_values.min_height().resolved(containing_block_height).resolved_or_auto(box, containing_block.height());
|
||||
if (!specified_min_height.is_auto()
|
||||
&& !(computed_values.min_height().is_percentage() && !containing_block.computed_values().height().is_absolute()))
|
||||
&& !(computed_values.min_height().is_percentage() && !is_absolute(containing_block.computed_values().height())))
|
||||
height = max(height, specified_min_height.to_px(box));
|
||||
return height;
|
||||
}
|
||||
|
@ -323,17 +330,18 @@ void BlockFormattingContext::compute_height(Box& box)
|
|||
{
|
||||
auto& computed_values = box.computed_values();
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto width_of_containing_block_as_length = CSS::Length::make_px(containing_block.width());
|
||||
|
||||
// First, resolve the top/bottom parts of the surrounding box model.
|
||||
|
||||
// FIXME: While negative values are generally allowed for margins, for now just ignore those for height calculation
|
||||
box.box_model().margin.top = max(computed_values.margin().top.resolved_or_zero(box, containing_block.width()).to_px(box), 0);
|
||||
box.box_model().margin.bottom = max(computed_values.margin().bottom.resolved_or_zero(box, containing_block.width()).to_px(box), 0);
|
||||
box.box_model().margin.top = max(computed_values.margin().top.resolved(width_of_containing_block_as_length).resolved_or_zero(box, containing_block.width()).to_px(box), 0);
|
||||
box.box_model().margin.bottom = max(computed_values.margin().bottom.resolved(width_of_containing_block_as_length).resolved_or_zero(box, containing_block.width()).to_px(box), 0);
|
||||
|
||||
box.box_model().border.top = computed_values.border_top().width;
|
||||
box.box_model().border.bottom = computed_values.border_bottom().width;
|
||||
box.box_model().padding.top = computed_values.padding().top.resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().padding.bottom = computed_values.padding().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().padding.top = computed_values.padding().top.resolved(width_of_containing_block_as_length).resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().padding.bottom = computed_values.padding().bottom.resolved(width_of_containing_block_as_length).resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
|
||||
auto height = compute_theoretical_height(box);
|
||||
box.set_height(height);
|
||||
|
@ -347,9 +355,10 @@ void BlockFormattingContext::compute_position(Box& box)
|
|||
auto& box_model = box.box_model();
|
||||
auto& computed_values = box.computed_values();
|
||||
float width_of_containing_block = box.containing_block()->width();
|
||||
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
|
||||
|
||||
auto specified_left = computed_values.offset().left.resolved_or_zero(box, width_of_containing_block);
|
||||
auto specified_right = computed_values.offset().right.resolved_or_zero(box, width_of_containing_block);
|
||||
auto specified_left = computed_values.offset().left.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
auto specified_right = computed_values.offset().right.resolved(width_of_containing_block_as_length).resolved_or_zero(box, width_of_containing_block);
|
||||
|
||||
if (specified_left.is_auto() && specified_right.is_auto()) {
|
||||
// If both 'left' and 'right' are 'auto' (their initial values), the used values are '0' (i.e., the boxes stay in their original position).
|
||||
|
@ -420,7 +429,7 @@ void BlockFormattingContext::layout_block_level_children(BlockContainer& block_c
|
|||
});
|
||||
|
||||
if (layout_mode != LayoutMode::Default) {
|
||||
if (block_container.computed_values().width().is_undefined() || block_container.computed_values().width().is_auto())
|
||||
if (block_container.computed_values().width().is_length() && block_container.computed_values().width().length().is_undefined_or_auto())
|
||||
block_container.set_width(content_width);
|
||||
}
|
||||
}
|
||||
|
@ -429,13 +438,14 @@ void BlockFormattingContext::place_block_level_replaced_element_in_normal_flow(B
|
|||
{
|
||||
VERIFY(!containing_block.is_absolutely_positioned());
|
||||
auto& replaced_element_box_model = child_box.box_model();
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
|
||||
|
||||
replaced_element_box_model.margin.top = child_box.computed_values().margin().top.resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
replaced_element_box_model.margin.bottom = child_box.computed_values().margin().bottom.resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
replaced_element_box_model.margin.top = child_box.computed_values().margin().top.resolved(width_of_containing_block).resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
replaced_element_box_model.margin.bottom = child_box.computed_values().margin().bottom.resolved(width_of_containing_block).resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
replaced_element_box_model.border.top = child_box.computed_values().border_top().width;
|
||||
replaced_element_box_model.border.bottom = child_box.computed_values().border_bottom().width;
|
||||
replaced_element_box_model.padding.top = child_box.computed_values().padding().top.resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
replaced_element_box_model.padding.bottom = child_box.computed_values().padding().bottom.resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
replaced_element_box_model.padding.top = child_box.computed_values().padding().top.resolved(width_of_containing_block).resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
replaced_element_box_model.padding.bottom = child_box.computed_values().padding().bottom.resolved(width_of_containing_block).resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
|
||||
float x = replaced_element_box_model.margin.left
|
||||
+ replaced_element_box_model.border.left
|
||||
|
@ -451,13 +461,14 @@ void BlockFormattingContext::place_block_level_non_replaced_element_in_normal_fl
|
|||
{
|
||||
auto& box_model = child_box.box_model();
|
||||
auto& computed_values = child_box.computed_values();
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
|
||||
|
||||
box_model.margin.top = computed_values.margin().top.resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
box_model.margin.bottom = computed_values.margin().bottom.resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
box_model.margin.top = computed_values.margin().top.resolved(width_of_containing_block).resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
box_model.margin.bottom = computed_values.margin().bottom.resolved(width_of_containing_block).resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
box_model.border.top = computed_values.border_top().width;
|
||||
box_model.border.bottom = computed_values.border_bottom().width;
|
||||
box_model.padding.top = computed_values.padding().top.resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
box_model.padding.bottom = computed_values.padding().bottom.resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
box_model.padding.top = computed_values.padding().top.resolved(width_of_containing_block).resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
box_model.padding.bottom = computed_values.padding().bottom.resolved(width_of_containing_block).resolved_or_zero(containing_block, containing_block.width()).to_px(child_box);
|
||||
|
||||
float x = box_model.margin.left
|
||||
+ box_model.border.left
|
||||
|
|
|
@ -25,6 +25,11 @@ static float get_pixel_size(Box const& box, CSS::LengthPercentage const& length_
|
|||
.to_px(box);
|
||||
}
|
||||
|
||||
static bool is_undefined_or_auto(CSS::LengthPercentage const& length_percentage)
|
||||
{
|
||||
return length_percentage.is_length() && length_percentage.length().is_undefined_or_auto();
|
||||
}
|
||||
|
||||
FlexFormattingContext::FlexFormattingContext(Box& flex_container, FormattingContext* parent)
|
||||
: FormattingContext(Type::Flex, flex_container, parent)
|
||||
, m_flex_direction(flex_container.computed_values().flex_direction())
|
||||
|
@ -110,17 +115,18 @@ void FlexFormattingContext::run(Box& run_box, LayoutMode)
|
|||
void FlexFormattingContext::populate_specified_margins(FlexItem& item, CSS::FlexDirection flex_direction) const
|
||||
{
|
||||
auto width_of_containing_block = item.box.containing_block()->width();
|
||||
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
|
||||
// FIXME: This should also take reverse-ness into account
|
||||
if (flex_direction == CSS::FlexDirection::Row || flex_direction == CSS::FlexDirection::RowReverse) {
|
||||
item.margins.main_before = item.box.computed_values().margin().left.resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.main_after = item.box.computed_values().margin().right.resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.cross_before = item.box.computed_values().margin().top.resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.cross_after = item.box.computed_values().margin().bottom.resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.main_before = item.box.computed_values().margin().left.resolved(width_of_containing_block_as_length).resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.main_after = item.box.computed_values().margin().right.resolved(width_of_containing_block_as_length).resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.cross_before = item.box.computed_values().margin().top.resolved(width_of_containing_block_as_length).resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.cross_after = item.box.computed_values().margin().bottom.resolved(width_of_containing_block_as_length).resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
} else {
|
||||
item.margins.main_before = item.box.computed_values().margin().top.resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.main_after = item.box.computed_values().margin().bottom.resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.cross_before = item.box.computed_values().margin().left.resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.cross_after = item.box.computed_values().margin().right.resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.main_before = item.box.computed_values().margin().top.resolved(width_of_containing_block_as_length).resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.main_after = item.box.computed_values().margin().bottom.resolved(width_of_containing_block_as_length).resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.cross_before = item.box.computed_values().margin().left.resolved(width_of_containing_block_as_length).resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
item.margins.cross_after = item.box.computed_values().margin().right.resolved(width_of_containing_block_as_length).resolved_or_zero(item.box, width_of_containing_block).to_px(item.box);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -136,13 +142,17 @@ void FlexFormattingContext::generate_anonymous_flex_items()
|
|||
if (!flex_container().has_definite_width()) {
|
||||
flex_container().set_width(flex_container().containing_block()->width());
|
||||
} else {
|
||||
flex_container().set_width(flex_container().computed_values().width().resolved_or_zero(flex_container(), flex_container().containing_block()->width()).to_px(flex_container()));
|
||||
auto container_width = flex_container().containing_block()->width();
|
||||
auto width = flex_container().computed_values().width().resolved(CSS::Length::make_px(container_width)).resolved_or_zero(flex_container(), container_width).to_px(flex_container());
|
||||
flex_container().set_width(width);
|
||||
}
|
||||
|
||||
if (!flex_container().has_definite_height()) {
|
||||
flex_container().set_height(flex_container().containing_block()->height());
|
||||
} else {
|
||||
flex_container().set_height(flex_container().computed_values().height().resolved_or_zero(flex_container(), flex_container().containing_block()->height()).to_px(flex_container()));
|
||||
auto container_height = flex_container().containing_block()->height();
|
||||
auto height = flex_container().computed_values().height().resolved(CSS::Length::make_px(container_height)).resolved_or_zero(flex_container(), flex_container().containing_block()->height()).to_px(flex_container());
|
||||
flex_container().set_height(height);
|
||||
}
|
||||
|
||||
flex_container().for_each_child_of_type<Box>([&](Box& child_box) {
|
||||
|
@ -191,13 +201,13 @@ float FlexFormattingContext::specified_cross_size(Box const& box) const
|
|||
bool FlexFormattingContext::has_main_min_size(Box const& box) const
|
||||
{
|
||||
auto value = is_row_layout() ? box.computed_values().min_width() : box.computed_values().min_height();
|
||||
return !value.is_undefined_or_auto();
|
||||
return !is_undefined_or_auto(value);
|
||||
}
|
||||
|
||||
bool FlexFormattingContext::has_cross_min_size(Box const& box) const
|
||||
{
|
||||
auto value = is_row_layout() ? box.computed_values().min_height() : box.computed_values().min_width();
|
||||
return !value.is_undefined_or_auto();
|
||||
return !is_undefined_or_auto(value);
|
||||
}
|
||||
|
||||
bool FlexFormattingContext::has_definite_cross_size(Box const& box) const
|
||||
|
@ -207,16 +217,19 @@ bool FlexFormattingContext::has_definite_cross_size(Box const& box) const
|
|||
|
||||
bool FlexFormattingContext::cross_size_is_absolute_or_resolved_nicely(NodeWithStyle const& box) const
|
||||
{
|
||||
auto length = is_row_layout() ? box.computed_values().height() : box.computed_values().width();
|
||||
auto length_percentage = is_row_layout() ? box.computed_values().height() : box.computed_values().width();
|
||||
|
||||
if (length.is_absolute() || length.is_relative())
|
||||
return true;
|
||||
if (length.is_undefined_or_auto())
|
||||
return false;
|
||||
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())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!box.parent())
|
||||
return false;
|
||||
if (length.is_percentage() && cross_size_is_absolute_or_resolved_nicely(*box.parent()))
|
||||
if (length_percentage.is_percentage() && cross_size_is_absolute_or_resolved_nicely(*box.parent()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -225,7 +238,7 @@ float FlexFormattingContext::specified_main_size_of_child_box(Box const& child_b
|
|||
{
|
||||
auto main_size_of_parent = specified_main_size(flex_container());
|
||||
auto value = is_row_layout() ? child_box.computed_values().width() : child_box.computed_values().height();
|
||||
return value.resolved_or_zero(child_box, main_size_of_parent).to_px(child_box);
|
||||
return value.resolved(CSS::Length::make_px(main_size_of_parent)).resolved_or_zero(child_box, main_size_of_parent).to_px(child_box);
|
||||
}
|
||||
|
||||
float FlexFormattingContext::specified_main_min_size(Box const& box) const
|
||||
|
@ -245,15 +258,15 @@ float FlexFormattingContext::specified_cross_min_size(Box const& box) const
|
|||
bool FlexFormattingContext::has_main_max_size(Box const& box) const
|
||||
{
|
||||
return is_row_layout()
|
||||
? !box.computed_values().max_width().is_undefined_or_auto()
|
||||
: !box.computed_values().max_height().is_undefined_or_auto();
|
||||
? !is_undefined_or_auto(box.computed_values().max_width())
|
||||
: !is_undefined_or_auto(box.computed_values().max_height());
|
||||
}
|
||||
|
||||
bool FlexFormattingContext::has_cross_max_size(Box const& box) const
|
||||
{
|
||||
return is_row_layout()
|
||||
? !box.computed_values().max_height().is_undefined_or_auto()
|
||||
: !box.computed_values().max_width().is_undefined_or_auto();
|
||||
? !is_undefined_or_auto(box.computed_values().max_height())
|
||||
: !is_undefined_or_auto(box.computed_values().max_width());
|
||||
}
|
||||
|
||||
float FlexFormattingContext::specified_main_max_size(Box const& box) const
|
||||
|
@ -277,17 +290,23 @@ float FlexFormattingContext::calculated_main_size(Box const& box) const
|
|||
|
||||
bool FlexFormattingContext::is_cross_auto(Box const& box) const
|
||||
{
|
||||
return is_row_layout() ? box.computed_values().height().is_auto() : box.computed_values().width().is_auto();
|
||||
if (is_row_layout())
|
||||
return box.computed_values().height().is_length() && box.computed_values().height().length().is_auto();
|
||||
return box.computed_values().width().is_length() && box.computed_values().width().length().is_auto();
|
||||
}
|
||||
|
||||
bool FlexFormattingContext::is_main_axis_margin_first_auto(Box const& box) const
|
||||
{
|
||||
return is_row_layout() ? box.computed_values().margin().left.is_auto() : box.computed_values().margin().top.is_auto();
|
||||
if (is_row_layout())
|
||||
return box.computed_values().margin().left.is_length() && box.computed_values().margin().left.length().is_auto();
|
||||
return box.computed_values().margin().top.is_length() && box.computed_values().margin().top.length().is_auto();
|
||||
}
|
||||
|
||||
bool FlexFormattingContext::is_main_axis_margin_second_auto(Box const& box) const
|
||||
{
|
||||
return is_row_layout() ? box.computed_values().margin().right.is_auto() : box.computed_values().margin().bottom.is_auto();
|
||||
if (is_row_layout())
|
||||
return box.computed_values().margin().right.is_length() && box.computed_values().margin().right.length().is_auto();
|
||||
return box.computed_values().margin().bottom.is_length() && box.computed_values().margin().bottom.length().is_auto();
|
||||
}
|
||||
|
||||
void FlexFormattingContext::set_main_size(Box& box, float size)
|
||||
|
@ -423,11 +442,11 @@ float FlexFormattingContext::layout_for_maximum_main_size(Box& box)
|
|||
{
|
||||
bool main_constrained = false;
|
||||
if (is_row_layout()) {
|
||||
if (!box.computed_values().width().is_undefined_or_auto() || !box.computed_values().min_width().is_undefined_or_auto()) {
|
||||
if (!is_undefined_or_auto(box.computed_values().width()) || !is_undefined_or_auto(box.computed_values().min_width())) {
|
||||
main_constrained = true;
|
||||
}
|
||||
} else {
|
||||
if (!box.computed_values().height().is_undefined_or_auto() || !box.computed_values().min_height().is_undefined_or_auto()) {
|
||||
if (!is_undefined_or_auto(box.computed_values().height()) || !is_undefined_or_auto(box.computed_values().min_height())) {
|
||||
main_constrained = true;
|
||||
}
|
||||
}
|
||||
|
@ -773,11 +792,11 @@ float FlexFormattingContext::determine_hypothetical_cross_size_of_item(Box& box)
|
|||
{
|
||||
bool cross_constrained = false;
|
||||
if (is_row_layout()) {
|
||||
if (!box.computed_values().height().is_undefined_or_auto() || !box.computed_values().min_height().is_undefined_or_auto()) {
|
||||
if (!is_undefined_or_auto(box.computed_values().height()) || !is_undefined_or_auto(box.computed_values().min_height())) {
|
||||
cross_constrained = true;
|
||||
}
|
||||
} else {
|
||||
if (!box.computed_values().width().is_undefined_or_auto() || !box.computed_values().min_width().is_undefined_or_auto()) {
|
||||
if (!is_undefined_or_auto(box.computed_values().width()) || !is_undefined_or_auto(box.computed_values().min_width())) {
|
||||
cross_constrained = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,10 +154,13 @@ static Gfx::FloatSize solve_replaced_size_constraint(float w, float h, const Rep
|
|||
// 10.4 Minimum and maximum widths: 'min-width' and 'max-width'
|
||||
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto specified_min_width = box.computed_values().min_width().resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
auto specified_max_width = box.computed_values().max_width().resolved(CSS::Length::make_px(w), box, containing_block.width()).to_px(box);
|
||||
auto specified_min_height = box.computed_values().min_height().resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
auto specified_max_height = box.computed_values().max_height().resolved(CSS::Length::make_px(h), box, containing_block.height()).to_px(box);
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
|
||||
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
|
||||
|
||||
auto specified_min_width = box.computed_values().min_width().resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
auto specified_max_width = box.computed_values().max_width().resolved(width_of_containing_block).resolved(CSS::Length::make_px(w), box, containing_block.width()).to_px(box);
|
||||
auto specified_min_height = box.computed_values().min_height().resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
auto specified_max_height = box.computed_values().max_height().resolved(height_of_containing_block).resolved(CSS::Length::make_px(h), box, containing_block.height()).to_px(box);
|
||||
|
||||
auto min_width = min(specified_min_width, specified_max_width);
|
||||
auto max_width = max(specified_min_width, specified_max_width);
|
||||
|
@ -248,7 +251,8 @@ float FormattingContext::compute_auto_height_for_block_level_element(Box const&
|
|||
float FormattingContext::tentative_width_for_replaced_element(ReplacedBox const& box, CSS::Length const& computed_width)
|
||||
{
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto computed_height = box.computed_values().height().resolved_or_auto(box, containing_block.height());
|
||||
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
|
||||
auto computed_height = box.computed_values().height().resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height());
|
||||
|
||||
float used_width = computed_width.to_px(box);
|
||||
|
||||
|
@ -308,9 +312,10 @@ float FormattingContext::compute_width_for_replaced_element(const ReplacedBox& b
|
|||
|
||||
auto zero_value = CSS::Length::make_px(0);
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
|
||||
|
||||
auto margin_left = box.computed_values().margin().left.resolved_or_zero(box, containing_block.width());
|
||||
auto margin_right = box.computed_values().margin().right.resolved_or_zero(box, containing_block.width());
|
||||
auto margin_left = box.computed_values().margin().left.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width());
|
||||
auto margin_right = box.computed_values().margin().right.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width());
|
||||
|
||||
// A computed value of 'auto' for 'margin-left' or 'margin-right' becomes a used value of '0'.
|
||||
if (margin_left.is_auto())
|
||||
|
@ -318,14 +323,14 @@ float FormattingContext::compute_width_for_replaced_element(const ReplacedBox& b
|
|||
if (margin_right.is_auto())
|
||||
margin_right = zero_value;
|
||||
|
||||
auto specified_width = box.computed_values().width().resolved_or_auto(box, containing_block.width());
|
||||
auto specified_width = box.computed_values().width().resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
|
||||
// 1. The tentative used width is calculated (without 'min-width' and 'max-width')
|
||||
auto used_width = tentative_width_for_replaced_element(box, specified_width);
|
||||
|
||||
// 2. The tentative used width is greater than 'max-width', the rules above are applied again,
|
||||
// but this time using the computed value of 'max-width' as the computed value for 'width'.
|
||||
auto specified_max_width = box.computed_values().max_width().resolved_or_auto(box, containing_block.width());
|
||||
auto specified_max_width = box.computed_values().max_width().resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
if (!specified_max_width.is_auto()) {
|
||||
if (used_width > specified_max_width.to_px(box)) {
|
||||
used_width = tentative_width_for_replaced_element(box, specified_max_width);
|
||||
|
@ -334,7 +339,7 @@ float FormattingContext::compute_width_for_replaced_element(const ReplacedBox& b
|
|||
|
||||
// 3. If the resulting width is smaller than 'min-width', the rules above are applied again,
|
||||
// but this time using the value of 'min-width' as the computed value for 'width'.
|
||||
auto specified_min_width = box.computed_values().min_width().resolved_or_auto(box, containing_block.width());
|
||||
auto specified_min_width = box.computed_values().min_width().resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
if (!specified_min_width.is_auto()) {
|
||||
if (used_width < specified_min_width.to_px(box)) {
|
||||
used_width = tentative_width_for_replaced_element(box, specified_min_width);
|
||||
|
@ -349,7 +354,8 @@ float FormattingContext::compute_width_for_replaced_element(const ReplacedBox& b
|
|||
float FormattingContext::tentative_height_for_replaced_element(ReplacedBox const& box, CSS::Length const& computed_height)
|
||||
{
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto computed_width = box.computed_values().width().resolved_or_auto(box, containing_block.width());
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
|
||||
auto computed_width = box.computed_values().width().resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
|
||||
// If 'height' and 'width' both have computed values of 'auto' and the element also has
|
||||
// an intrinsic height, then that intrinsic height is the used value of 'height'.
|
||||
|
@ -381,8 +387,10 @@ float FormattingContext::compute_height_for_replaced_element(const ReplacedBox&
|
|||
// 'inline-block' replaced elements in normal flow and floating replaced elements
|
||||
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto specified_width = box.computed_values().width().resolved_or_auto(box, containing_block.width());
|
||||
auto specified_height = box.computed_values().height().resolved_or_auto(box, containing_block.height());
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
|
||||
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
|
||||
auto specified_width = box.computed_values().width().resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
auto specified_height = box.computed_values().height().resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height());
|
||||
|
||||
float used_height = tentative_height_for_replaced_element(box, specified_height);
|
||||
|
||||
|
@ -398,6 +406,7 @@ float FormattingContext::compute_height_for_replaced_element(const ReplacedBox&
|
|||
void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_element(Box& box)
|
||||
{
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
|
||||
auto& computed_values = box.computed_values();
|
||||
auto zero_value = CSS::Length::make_px(0);
|
||||
|
||||
|
@ -405,15 +414,15 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele
|
|||
auto margin_right = CSS::Length::make_auto();
|
||||
const auto border_left = computed_values.border_left().width;
|
||||
const auto border_right = computed_values.border_right().width;
|
||||
const auto padding_left = computed_values.padding().left.resolved_or_zero(box, containing_block.width());
|
||||
const auto padding_right = computed_values.padding().right.resolved_or_zero(box, containing_block.width());
|
||||
const auto padding_left = computed_values.padding().left.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width());
|
||||
const auto padding_right = computed_values.padding().right.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width());
|
||||
|
||||
auto try_compute_width = [&](const auto& a_width) {
|
||||
margin_left = computed_values.margin().left.resolved_or_zero(box, containing_block.width());
|
||||
margin_right = computed_values.margin().right.resolved_or_zero(box, containing_block.width());
|
||||
margin_left = computed_values.margin().left.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width());
|
||||
margin_right = computed_values.margin().right.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width());
|
||||
|
||||
auto left = computed_values.offset().left.resolved_or_auto(box, containing_block.width());
|
||||
auto right = computed_values.offset().right.resolved_or_auto(box, containing_block.width());
|
||||
auto left = computed_values.offset().left.resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
auto right = computed_values.offset().right.resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
auto width = a_width;
|
||||
|
||||
auto solve_for_left = [&] {
|
||||
|
@ -502,14 +511,14 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele
|
|||
return width;
|
||||
};
|
||||
|
||||
auto specified_width = computed_values.width().resolved_or_auto(box, containing_block.width());
|
||||
auto specified_width = computed_values.width().resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
|
||||
// 1. The tentative used width is calculated (without 'min-width' and 'max-width')
|
||||
auto used_width = try_compute_width(specified_width);
|
||||
|
||||
// 2. The tentative used width is greater than 'max-width', the rules above are applied again,
|
||||
// but this time using the computed value of 'max-width' as the computed value for 'width'.
|
||||
auto specified_max_width = computed_values.max_width().resolved_or_auto(box, containing_block.width());
|
||||
auto specified_max_width = computed_values.max_width().resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
if (!specified_max_width.is_auto()) {
|
||||
if (used_width.to_px(box) > specified_max_width.to_px(box)) {
|
||||
used_width = try_compute_width(specified_max_width);
|
||||
|
@ -518,7 +527,7 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele
|
|||
|
||||
// 3. If the resulting width is smaller than 'min-width', the rules above are applied again,
|
||||
// but this time using the value of 'min-width' as the computed value for 'width'.
|
||||
auto specified_min_width = computed_values.min_width().resolved_or_auto(box, containing_block.width());
|
||||
auto specified_min_width = computed_values.min_width().resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
if (!specified_min_width.is_auto()) {
|
||||
if (used_width.to_px(box) < specified_min_width.to_px(box)) {
|
||||
used_width = try_compute_width(specified_min_width);
|
||||
|
@ -547,26 +556,28 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
|
|||
{
|
||||
auto& computed_values = box.computed_values();
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
|
||||
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
|
||||
|
||||
CSS::Length specified_top = computed_values.offset().top.resolved_or_auto(box, containing_block.height());
|
||||
CSS::Length specified_bottom = computed_values.offset().bottom.resolved_or_auto(box, containing_block.height());
|
||||
CSS::Length specified_top = computed_values.offset().top.resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height());
|
||||
CSS::Length specified_bottom = computed_values.offset().bottom.resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height());
|
||||
CSS::Length specified_height;
|
||||
|
||||
if (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute()) {
|
||||
if (computed_values.height().is_percentage() && !(containing_block.computed_values().height().is_length() && containing_block.computed_values().height().length().is_absolute())) {
|
||||
specified_height = CSS::Length::make_auto();
|
||||
} else {
|
||||
specified_height = computed_values.height().resolved_or_auto(box, containing_block.height());
|
||||
specified_height = computed_values.height().resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height());
|
||||
}
|
||||
|
||||
auto specified_max_height = computed_values.max_height().resolved_or_auto(box, containing_block.height());
|
||||
auto specified_min_height = computed_values.min_height().resolved_or_auto(box, containing_block.height());
|
||||
auto specified_max_height = computed_values.max_height().resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height());
|
||||
auto specified_min_height = computed_values.min_height().resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height());
|
||||
|
||||
box.box_model().margin.top = computed_values.margin().top.resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().margin.bottom = computed_values.margin().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().margin.top = computed_values.margin().top.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().margin.bottom = computed_values.margin().bottom.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().border.top = computed_values.border_top().width;
|
||||
box.box_model().border.bottom = computed_values.border_bottom().width;
|
||||
box.box_model().padding.top = computed_values.padding().top.resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().padding.bottom = computed_values.padding().bottom.resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().padding.top = computed_values.padding().top.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
box.box_model().padding.bottom = computed_values.padding().bottom.resolved(width_of_containing_block).resolved_or_zero(box, containing_block.width()).to_px(box);
|
||||
|
||||
if (specified_height.is_auto() && !specified_top.is_auto() && specified_bottom.is_auto()) {
|
||||
const auto& margin = box.box_model().margin;
|
||||
|
@ -598,43 +609,49 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
|
|||
void FormattingContext::layout_absolutely_positioned_element(Box& box)
|
||||
{
|
||||
auto& containing_block = *box.containing_block();
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
|
||||
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
|
||||
auto& box_model = box.box_model();
|
||||
|
||||
auto specified_width = box.computed_values().width().resolved_or_auto(box, containing_block.width());
|
||||
auto specified_width = box.computed_values().width().resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width());
|
||||
|
||||
compute_width_for_absolutely_positioned_element(box);
|
||||
(void)layout_inside(box, LayoutMode::Default);
|
||||
compute_height_for_absolutely_positioned_element(box);
|
||||
|
||||
box_model.margin.left = box.computed_values().margin().left.resolved_or_auto(box, containing_block.width()).to_px(box);
|
||||
box_model.margin.top = box.computed_values().margin().top.resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
box_model.margin.right = box.computed_values().margin().right.resolved_or_auto(box, containing_block.width()).to_px(box);
|
||||
box_model.margin.bottom = box.computed_values().margin().bottom.resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
box_model.margin.left = box.computed_values().margin().left.resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width()).to_px(box);
|
||||
box_model.margin.top = box.computed_values().margin().top.resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
box_model.margin.right = box.computed_values().margin().right.resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width()).to_px(box);
|
||||
box_model.margin.bottom = box.computed_values().margin().bottom.resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
|
||||
box_model.border.left = box.computed_values().border_left().width;
|
||||
box_model.border.right = box.computed_values().border_right().width;
|
||||
box_model.border.top = box.computed_values().border_top().width;
|
||||
box_model.border.bottom = box.computed_values().border_bottom().width;
|
||||
|
||||
box_model.offset.left = box.computed_values().offset().left.resolved_or_auto(box, containing_block.width()).to_px(box);
|
||||
box_model.offset.top = box.computed_values().offset().top.resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
box_model.offset.right = box.computed_values().offset().right.resolved_or_auto(box, containing_block.width()).to_px(box);
|
||||
box_model.offset.bottom = box.computed_values().offset().bottom.resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
box_model.offset.left = box.computed_values().offset().left.resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width()).to_px(box);
|
||||
box_model.offset.top = box.computed_values().offset().top.resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
box_model.offset.right = box.computed_values().offset().right.resolved(width_of_containing_block).resolved_or_auto(box, containing_block.width()).to_px(box);
|
||||
box_model.offset.bottom = box.computed_values().offset().bottom.resolved(height_of_containing_block).resolved_or_auto(box, containing_block.height()).to_px(box);
|
||||
|
||||
if (box.computed_values().offset().left.is_auto() && specified_width.is_auto() && box.computed_values().offset().right.is_auto()) {
|
||||
if (box.computed_values().margin().left.is_auto())
|
||||
auto is_auto = [](auto const& length_percentage) {
|
||||
return length_percentage.is_length() && length_percentage.length().is_auto();
|
||||
};
|
||||
|
||||
if (is_auto(box.computed_values().offset().left) && specified_width.is_auto() && is_auto(box.computed_values().offset().right)) {
|
||||
if (is_auto(box.computed_values().margin().left))
|
||||
box_model.margin.left = 0;
|
||||
if (box.computed_values().margin().right.is_auto())
|
||||
if (is_auto(box.computed_values().margin().right))
|
||||
box_model.margin.right = 0;
|
||||
}
|
||||
|
||||
Gfx::FloatPoint used_offset;
|
||||
|
||||
if (!box.computed_values().offset().left.is_auto()) {
|
||||
if (!is_auto(box.computed_values().offset().left)) {
|
||||
float x_offset = box_model.offset.left
|
||||
+ box_model.border_box().left;
|
||||
used_offset.set_x(x_offset + box_model.margin.left);
|
||||
} else if (!box.computed_values().offset().right.is_auto()) {
|
||||
} else if (!is_auto(box.computed_values().offset().right)) {
|
||||
float x_offset = 0
|
||||
- box_model.offset.right
|
||||
- box_model.border_box().right;
|
||||
|
@ -644,11 +661,11 @@ void FormattingContext::layout_absolutely_positioned_element(Box& box)
|
|||
used_offset.set_x(x_offset);
|
||||
}
|
||||
|
||||
if (!box.computed_values().offset().top.is_auto()) {
|
||||
if (!is_auto(box.computed_values().offset().top)) {
|
||||
float y_offset = box_model.offset.top
|
||||
+ box_model.border_box().top;
|
||||
used_offset.set_y(y_offset + box_model.margin.top);
|
||||
} else if (!box.computed_values().offset().bottom.is_auto()) {
|
||||
} else if (!is_auto(box.computed_values().offset().bottom)) {
|
||||
float y_offset = 0
|
||||
- box_model.offset.bottom
|
||||
- box_model.border_box().bottom;
|
||||
|
|
|
@ -191,16 +191,17 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_
|
|||
if (box.is_inline_block()) {
|
||||
auto& inline_block = const_cast<BlockContainer&>(verify_cast<BlockContainer>(box));
|
||||
|
||||
if (inline_block.computed_values().width().is_undefined_or_auto()) {
|
||||
if (inline_block.computed_values().width().is_length() && inline_block.computed_values().width().length().is_undefined_or_auto()) {
|
||||
auto result = calculate_shrink_to_fit_widths(inline_block);
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block().width());
|
||||
|
||||
auto margin_left = inline_block.computed_values().margin().left.resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block);
|
||||
auto margin_left = inline_block.computed_values().margin().left.resolved(width_of_containing_block).resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block);
|
||||
auto border_left_width = inline_block.computed_values().border_left().width;
|
||||
auto padding_left = inline_block.computed_values().padding().left.resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block);
|
||||
auto padding_left = inline_block.computed_values().padding().left.resolved(width_of_containing_block).resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block);
|
||||
|
||||
auto margin_right = inline_block.computed_values().margin().right.resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block);
|
||||
auto margin_right = inline_block.computed_values().margin().right.resolved(width_of_containing_block).resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block);
|
||||
auto border_right_width = inline_block.computed_values().border_right().width;
|
||||
auto padding_right = inline_block.computed_values().padding().right.resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block);
|
||||
auto padding_right = inline_block.computed_values().padding().right.resolved(width_of_containing_block).resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block);
|
||||
|
||||
auto available_width = containing_block().width()
|
||||
- margin_left
|
||||
|
@ -213,14 +214,16 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_
|
|||
auto width = min(max(result.preferred_minimum_width, available_width), result.preferred_width);
|
||||
inline_block.set_width(width);
|
||||
} else {
|
||||
inline_block.set_width(inline_block.computed_values().width().resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block));
|
||||
auto container_width = CSS::Length::make_px(containing_block().width());
|
||||
inline_block.set_width(inline_block.computed_values().width().resolved(container_width).resolved_or_zero(inline_block, containing_block().width()).to_px(inline_block));
|
||||
}
|
||||
(void)layout_inside(inline_block, layout_mode);
|
||||
|
||||
if (inline_block.computed_values().height().is_undefined_or_auto()) {
|
||||
if (inline_block.computed_values().height().is_length() && inline_block.computed_values().height().length().is_undefined_or_auto()) {
|
||||
// FIXME: (10.6.6) If 'height' is 'auto', the height depends on the element's descendants per 10.6.7.
|
||||
} else {
|
||||
inline_block.set_height(inline_block.computed_values().height().resolved_or_zero(inline_block, containing_block().height()).to_px(inline_block));
|
||||
auto container_height = CSS::Length::make_px(containing_block().height());
|
||||
inline_block.set_height(inline_block.computed_values().height().resolved(container_height).resolved_or_zero(inline_block, containing_block().height()).to_px(inline_block));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -31,15 +31,19 @@ void InlineNode::split_into_lines(InlineFormattingContext& context, LayoutMode l
|
|||
{
|
||||
auto& containing_block = context.containing_block();
|
||||
|
||||
if (!computed_values().padding().left.is_undefined_or_auto()) {
|
||||
float padding_left = computed_values().padding().left.resolved(CSS::Length::make_px(0), *this, containing_block.width()).to_px(*this);
|
||||
auto is_not_undefined_or_auto = [](auto const& length_percentage) {
|
||||
return !(length_percentage.is_length() && length_percentage.length().is_undefined_or_auto());
|
||||
};
|
||||
|
||||
if (is_not_undefined_or_auto(computed_values().padding().left)) {
|
||||
float padding_left = computed_values().padding().left.resolved(CSS::Length::make_px(containing_block.width())).resolved(CSS::Length::make_px(0), *this, containing_block.width()).to_px(*this);
|
||||
containing_block.ensure_last_line_box().add_fragment(*this, 0, 0, padding_left, 0, LineBoxFragment::Type::Leading);
|
||||
}
|
||||
|
||||
NodeWithStyleAndBoxModelMetrics::split_into_lines(context, layout_mode);
|
||||
|
||||
if (!computed_values().padding().right.is_undefined_or_auto()) {
|
||||
float padding_right = computed_values().padding().right.resolved(CSS::Length::make_px(0), *this, containing_block.width()).to_px(*this);
|
||||
if (is_not_undefined_or_auto(computed_values().padding().right)) {
|
||||
float padding_right = computed_values().padding().right.resolved(CSS::Length::make_px(containing_block.width())).resolved(CSS::Length::make_px(0), *this, containing_block.width()).to_px(*this);
|
||||
containing_block.ensure_last_line_box().add_fragment(*this, 0, 0, padding_right, 0, LineBoxFragment::Type::Trailing);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -433,15 +433,15 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
|
|||
|
||||
if (auto width = specified_style.property(CSS::PropertyID::Width); width.has_value() && !width.value()->has_auto())
|
||||
m_has_definite_width = true;
|
||||
computed_values.set_width(specified_style.length_or_fallback(CSS::PropertyID::Width, {}));
|
||||
computed_values.set_min_width(specified_style.length_or_fallback(CSS::PropertyID::MinWidth, {}));
|
||||
computed_values.set_max_width(specified_style.length_or_fallback(CSS::PropertyID::MaxWidth, {}));
|
||||
computed_values.set_width(specified_style.length_percentage_or_fallback(CSS::PropertyID::Width, CSS::Length {}));
|
||||
computed_values.set_min_width(specified_style.length_percentage_or_fallback(CSS::PropertyID::MinWidth, CSS::Length {}));
|
||||
computed_values.set_max_width(specified_style.length_percentage_or_fallback(CSS::PropertyID::MaxWidth, CSS::Length {}));
|
||||
|
||||
if (auto height = specified_style.property(CSS::PropertyID::Height); height.has_value() && !height.value()->has_auto())
|
||||
m_has_definite_height = true;
|
||||
computed_values.set_height(specified_style.length_or_fallback(CSS::PropertyID::Height, {}));
|
||||
computed_values.set_min_height(specified_style.length_or_fallback(CSS::PropertyID::MinHeight, {}));
|
||||
computed_values.set_max_height(specified_style.length_or_fallback(CSS::PropertyID::MaxHeight, {}));
|
||||
computed_values.set_height(specified_style.length_percentage_or_fallback(CSS::PropertyID::Height, CSS::Length {}));
|
||||
computed_values.set_min_height(specified_style.length_percentage_or_fallback(CSS::PropertyID::MinHeight, CSS::Length {}));
|
||||
computed_values.set_max_height(specified_style.length_percentage_or_fallback(CSS::PropertyID::MaxHeight, CSS::Length {}));
|
||||
|
||||
computed_values.set_offset(specified_style.length_box(CSS::PropertyID::Left, CSS::PropertyID::Top, CSS::PropertyID::Right, CSS::PropertyID::Bottom, CSS::Length::make_auto()));
|
||||
computed_values.set_margin(specified_style.length_box(CSS::PropertyID::MarginLeft, CSS::PropertyID::MarginTop, CSS::PropertyID::MarginRight, CSS::PropertyID::MarginBottom, CSS::Length::make_px(0)));
|
||||
|
|
|
@ -52,7 +52,7 @@ void TableFormattingContext::run(Box& box, LayoutMode)
|
|||
content_height += row.height();
|
||||
});
|
||||
|
||||
if (row_group_box.computed_values().width().is_auto())
|
||||
if (row_group_box.computed_values().width().is_length() && row_group_box.computed_values().width().length().is_auto())
|
||||
row_group_box.set_width(content_width);
|
||||
row_group_box.set_height(content_height);
|
||||
|
||||
|
@ -61,7 +61,7 @@ void TableFormattingContext::run(Box& box, LayoutMode)
|
|||
total_content_width = max(total_content_width, row_group_box.width());
|
||||
});
|
||||
|
||||
if (box.computed_values().width().is_auto())
|
||||
if (box.computed_values().width().is_length() && box.computed_values().width().length().is_auto())
|
||||
box.set_width(total_content_width);
|
||||
|
||||
// FIXME: This is a total hack, we should respect the 'height' property.
|
||||
|
@ -72,7 +72,7 @@ void TableFormattingContext::calculate_column_widths(Box& row, Vector<float>& co
|
|||
{
|
||||
size_t column_index = 0;
|
||||
auto* table = row.first_ancestor_of_type<TableBox>();
|
||||
bool use_auto_layout = !table || table->computed_values().width().is_undefined_or_auto();
|
||||
bool use_auto_layout = !table || (table->computed_values().width().is_length() && table->computed_values().width().length().is_undefined_or_auto());
|
||||
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
|
||||
compute_width(cell);
|
||||
if (use_auto_layout) {
|
||||
|
@ -91,7 +91,7 @@ void TableFormattingContext::layout_row(Box& row, Vector<float>& column_widths)
|
|||
float tallest_cell_height = 0;
|
||||
float content_width = 0;
|
||||
auto* table = row.first_ancestor_of_type<TableBox>();
|
||||
bool use_auto_layout = !table || table->computed_values().width().is_undefined_or_auto();
|
||||
bool use_auto_layout = !table || (table->computed_values().width().is_length() && table->computed_values().width().length().is_undefined_or_auto());
|
||||
|
||||
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
|
||||
cell.set_offset(row.effective_offset().translated(content_width, 0));
|
||||
|
|
Loading…
Add table
Reference in a new issue