Commit af53c613 authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[layoutng] Refactor min/max content contribution a bit

Provide a helper function in ng_length_utils that calls
node.ComputeMinMaxContentSizes for you.

R=eae@chromium.org,mstensho@chromium.org

Bug: 635619
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: Id5e559aa1d9991f1e39d74fd84578ca2b7641883
Reviewed-on: https://chromium-review.googlesource.com/1069628
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560840}
parent b5e470c2
......@@ -633,15 +633,9 @@ static LayoutUnit ComputeContentSize(NGInlineNode node,
NGBlockNode float_node = unpositioned_float->node;
const ComputedStyle& float_style = float_node.Style();
base::Optional<MinMaxSize> child_minmax;
if (NeedMinMaxSizeForContentContribution(writing_mode, float_style)) {
MinMaxSizeInput zero_input; // Floats don't intrude into floats.
// TODO(layoutng): This is wrong for orthogonal writing modes.
child_minmax = float_node.ComputeMinMaxSize(zero_input);
}
MinMaxSizeInput zero_input; // Floats don't intrude into floats.
MinMaxSize child_sizes = ComputeMinAndMaxContentContribution(
writing_mode, float_style, child_minmax);
writing_mode, float_node, zero_input);
LayoutUnit child_inline_margins =
ComputeMinMaxMargins(style, float_node).InlineSum();
......
......@@ -622,16 +622,10 @@ void NGLineBreaker::HandleAtomicInline(const NGInlineItem& item,
.InlineSize();
} else {
NGBlockNode block_node(ToLayoutBox(item.GetLayoutObject()));
base::Optional<MinMaxSize> child_minmax;
if (NeedMinMaxSizeForContentContribution(constraint_space_.GetWritingMode(),
block_node.Style())) {
MinMaxSizeInput input;
// TODO(layoutng): This is wrong for orthogonal writing modes.
child_minmax = block_node.ComputeMinMaxSize(input, &constraint_space_);
}
MinMaxSizeInput input;
MinMaxSize sizes = ComputeMinAndMaxContentContribution(
constraint_space_.GetWritingMode(), block_node.Style(), child_minmax);
constraint_space_.GetWritingMode(), block_node, input,
&constraint_space_);
item_result->inline_size = mode_ == NGLineBreakerMode::kMinContent
? sizes.min_size
: sizes.max_size;
......
......@@ -179,15 +179,8 @@ base::Optional<MinMaxSize> NGBlockLayoutAlgorithm::ComputeMinMaxSize(
// following inline siblings and descendants.
child_sizes = child.ComputeMinMaxSize(child_input);
} else {
base::Optional<MinMaxSize> child_minmax;
if (NeedMinMaxSizeForContentContribution(Style().GetWritingMode(),
child_style)) {
// TODO(layoutng): This is wrong for orthogonal writing modes.
child_minmax = child.ComputeMinMaxSize(child_input);
}
child_sizes = ComputeMinAndMaxContentContribution(
Style().GetWritingMode(), child_style, child_minmax);
Style().GetWritingMode(), child, child_input);
}
// Determine the max inline contribution of the child.
......
......@@ -15,9 +15,6 @@
#include "third_party/blink/renderer/platform/length.h"
namespace blink {
// TODO(layout-ng):
// - replaced calculations
// - Take scrollbars into account
bool NeedMinMaxSize(const NGConstraintSpace& constraint_space,
const ComputedStyle& style) {
......@@ -334,6 +331,21 @@ MinMaxSize ComputeMinAndMaxContentContribution(
return computed_sizes;
}
MinMaxSize ComputeMinAndMaxContentContribution(
WritingMode writing_mode,
NGLayoutInputNode node,
const MinMaxSizeInput& input,
const NGConstraintSpace* constraint_space) {
base::Optional<MinMaxSize> minmax;
if (NeedMinMaxSizeForContentContribution(writing_mode, node.Style())) {
// TODO(layoutng): This is wrong for orthogonal writing modes.
minmax = node.ComputeMinMaxSize(input, constraint_space);
}
return ComputeMinAndMaxContentContribution(writing_mode, node.Style(),
minmax);
}
LayoutUnit ComputeInlineSizeForFragment(
const NGConstraintSpace& space,
const ComputedStyle& style,
......
......@@ -17,6 +17,7 @@
namespace blink {
class ComputedStyle;
class Length;
struct MinMaxSizeInput;
class NGConstraintSpace;
class NGBlockNode;
class NGLayoutInputNode;
......@@ -87,6 +88,18 @@ ComputeMinAndMaxContentContribution(WritingMode writing_mode,
const ComputedStyle&,
const base::Optional<MinMaxSize>&);
// A version of ComputeMinAndMaxContentContribution that does not require you
// to compute the min/max content size of the node. Instead, this function
// will compute it if necessary.
// writing_mode is the desired output writing mode (ie. often the writing mode
// of the parent); node is the node of which to compute the min/max content
// contribution.
MinMaxSize ComputeMinAndMaxContentContribution(
WritingMode writing_mode,
NGLayoutInputNode node,
const MinMaxSizeInput& input,
const NGConstraintSpace* space = nullptr);
// Resolves the given length to a layout unit, constraining it by the min
// logical width and max logical width properties from the ComputedStyle
// object.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment