Commit 55353007 authored by Alison Maher's avatar Alison Maher Committed by Commit Bot

[css-layout-api] IntrinsicSizes follow up

This change is a follow-up to the intrinsicSizes implementation based
on feedback in the following CL:
https://chromium-review.googlesource.com/c/chromium/src/+/1949536

The main changes are as follows:
1. Pass in the correct information to
CalculateChildPercentageBlockSizeForMinMax().
2. Subtract out border_scrollbar_padding_ instead of border_padding_
from the intrinsic sizes if in legacy layout.

Bug: 726125
Change-Id: I430a029ef76f7326a3224593c4c9bac18c0e94d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1980895
Commit-Queue: Alison Maher <almaher@microsoft.com>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728232}
parent f1743a5a
...@@ -90,6 +90,7 @@ bool CSSLayoutDefinition::Instance::Layout( ...@@ -90,6 +90,7 @@ bool CSSLayoutDefinition::Instance::Layout(
const NGBlockNode& node, const NGBlockNode& node,
const LogicalSize& border_box_size, const LogicalSize& border_box_size,
const NGBoxStrut& border_scrollbar_padding, const NGBoxStrut& border_scrollbar_padding,
const LayoutUnit child_percentage_resolution_block_size_for_min_max,
CustomLayoutScope* custom_layout_scope, CustomLayoutScope* custom_layout_scope,
FragmentResultOptions* fragment_result_options, FragmentResultOptions* fragment_result_options,
scoped_refptr<SerializedScriptValue>* fragment_result_data) { scoped_refptr<SerializedScriptValue>* fragment_result_data) {
...@@ -144,8 +145,10 @@ bool CSSLayoutDefinition::Instance::Layout( ...@@ -144,8 +145,10 @@ bool CSSLayoutDefinition::Instance::Layout(
// Run the work queue until exhaustion. // Run the work queue until exhaustion.
while (!custom_layout_scope->Queue()->IsEmpty()) { while (!custom_layout_scope->Queue()->IsEmpty()) {
for (auto& task : *custom_layout_scope->Queue()) for (auto& task : *custom_layout_scope->Queue()) {
task.Run(node, space, node.Style(), border_scrollbar_padding); task.Run(space, node.Style(),
child_percentage_resolution_block_size_for_min_max);
}
custom_layout_scope->Queue()->clear(); custom_layout_scope->Queue()->clear();
{ {
v8::MicrotasksScope microtasks_scope(isolate, microtask_queue, v8::MicrotasksScope microtasks_scope(isolate, microtask_queue,
...@@ -218,6 +221,7 @@ bool CSSLayoutDefinition::Instance::IntrinsicSizes( ...@@ -218,6 +221,7 @@ bool CSSLayoutDefinition::Instance::IntrinsicSizes(
const NGBlockNode& node, const NGBlockNode& node,
const LogicalSize& border_box_size, const LogicalSize& border_box_size,
const NGBoxStrut& border_scrollbar_padding, const NGBoxStrut& border_scrollbar_padding,
const LayoutUnit child_percentage_resolution_block_size_for_min_max,
CustomLayoutScope* custom_layout_scope, CustomLayoutScope* custom_layout_scope,
IntrinsicSizesResultOptions* intrinsic_sizes_result_options) { IntrinsicSizesResultOptions* intrinsic_sizes_result_options) {
ScriptState* script_state = definition_->GetScriptState(); ScriptState* script_state = definition_->GetScriptState();
...@@ -266,8 +270,10 @@ bool CSSLayoutDefinition::Instance::IntrinsicSizes( ...@@ -266,8 +270,10 @@ bool CSSLayoutDefinition::Instance::IntrinsicSizes(
// Run the work queue until exhaustion. // Run the work queue until exhaustion.
while (!custom_layout_scope->Queue()->IsEmpty()) { while (!custom_layout_scope->Queue()->IsEmpty()) {
for (auto& task : *custom_layout_scope->Queue()) for (auto& task : *custom_layout_scope->Queue()) {
task.Run(node, space, node.Style(), border_scrollbar_padding); task.Run(space, node.Style(),
child_percentage_resolution_block_size_for_min_max);
}
custom_layout_scope->Queue()->clear(); custom_layout_scope->Queue()->clear();
{ {
v8::MicrotasksScope microtasks_scope(isolate, microtask_queue, v8::MicrotasksScope microtasks_scope(isolate, microtask_queue,
......
...@@ -18,6 +18,7 @@ namespace blink { ...@@ -18,6 +18,7 @@ namespace blink {
class CustomLayoutScope; class CustomLayoutScope;
class FragmentResultOptions; class FragmentResultOptions;
class IntrinsicSizesResultOptions; class IntrinsicSizesResultOptions;
class LayoutUnit;
struct LogicalSize; struct LogicalSize;
class NGBlockNode; class NGBlockNode;
struct NGBoxStrut; struct NGBoxStrut;
...@@ -54,24 +55,28 @@ class CSSLayoutDefinition final : public GarbageCollected<CSSLayoutDefinition>, ...@@ -54,24 +55,28 @@ class CSSLayoutDefinition final : public GarbageCollected<CSSLayoutDefinition>,
// Runs the web developer defined layout, returns true if everything // Runs the web developer defined layout, returns true if everything
// succeeded. It populates the FragmentResultOptions dictionary, and // succeeded. It populates the FragmentResultOptions dictionary, and
// fragment_result_data. // fragment_result_data.
bool Layout(const NGConstraintSpace&, bool Layout(
const Document&, const NGConstraintSpace&,
const NGBlockNode&, const Document&,
const LogicalSize& border_box_size, const NGBlockNode&,
const NGBoxStrut& border_scrollbar_padding, const LogicalSize& border_box_size,
CustomLayoutScope*, const NGBoxStrut& border_scrollbar_padding,
FragmentResultOptions*, const LayoutUnit child_percentage_resolution_block_size_for_min_max,
scoped_refptr<SerializedScriptValue>* fragment_result_data); CustomLayoutScope*,
FragmentResultOptions*,
scoped_refptr<SerializedScriptValue>* fragment_result_data);
// Runs the web developer defined intrinsicSizes, returns true if everything // Runs the web developer defined intrinsicSizes, returns true if everything
// succeeded. It populates the IntrinsicSizesResultOptions dictionary. // succeeded. It populates the IntrinsicSizesResultOptions dictionary.
bool IntrinsicSizes(const NGConstraintSpace&, bool IntrinsicSizes(
const Document&, const NGConstraintSpace&,
const NGBlockNode&, const Document&,
const LogicalSize& border_box_size, const NGBlockNode&,
const NGBoxStrut& border_scrollbar_padding, const LogicalSize& border_box_size,
CustomLayoutScope*, const NGBoxStrut& border_scrollbar_padding,
IntrinsicSizesResultOptions*); const LayoutUnit child_percentage_resolution_block_size_for_min_max,
CustomLayoutScope*,
IntrinsicSizesResultOptions*);
void Trace(blink::Visitor*); void Trace(blink::Visitor*);
......
...@@ -15,7 +15,7 @@ class CustomLayoutChild; ...@@ -15,7 +15,7 @@ class CustomLayoutChild;
// This represents the result of intrinsicSizes (on a LayoutChild). // This represents the result of intrinsicSizes (on a LayoutChild).
// //
// This should eventually mirror the information in a MinMaxSize, it has the // This should mirror the information in a MinMaxSize, and it has the
// additional capability that it is exposed to web developers. // additional capability that it is exposed to web developers.
class CustomIntrinsicSizes : public ScriptWrappable { class CustomIntrinsicSizes : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
......
...@@ -39,16 +39,17 @@ CustomLayoutWorkTask::CustomLayoutWorkTask( ...@@ -39,16 +39,17 @@ CustomLayoutWorkTask::CustomLayoutWorkTask(
CustomLayoutWorkTask::~CustomLayoutWorkTask() = default; CustomLayoutWorkTask::~CustomLayoutWorkTask() = default;
void CustomLayoutWorkTask::Run(const NGBlockNode& parent, void CustomLayoutWorkTask::Run(
const NGConstraintSpace& parent_space, const NGConstraintSpace& parent_space,
const ComputedStyle& parent_style, const ComputedStyle& parent_style,
const NGBoxStrut& border_scrollbar_padding) { const LayoutUnit child_percentage_resolution_block_size_for_min_max) {
DCHECK(token_->IsValid()); DCHECK(token_->IsValid());
NGLayoutInputNode child = child_->GetLayoutNode(); NGLayoutInputNode child = child_->GetLayoutNode();
if (type_ == CustomLayoutWorkTask::TaskType::kIntrinsicSizes) { if (type_ == CustomLayoutWorkTask::TaskType::kIntrinsicSizes) {
RunIntrinsicSizesTask(parent, parent_space, parent_style, RunIntrinsicSizesTask(parent_style,
border_scrollbar_padding, child); child_percentage_resolution_block_size_for_min_max,
child);
} else { } else {
DCHECK_EQ(type_, CustomLayoutWorkTask::TaskType::kLayoutFragment); DCHECK_EQ(type_, CustomLayoutWorkTask::TaskType::kLayoutFragment);
RunLayoutFragmentTask(parent_space, parent_style, child); RunLayoutFragmentTask(parent_space, parent_style, child);
...@@ -138,22 +139,13 @@ void CustomLayoutWorkTask::RunLayoutFragmentTask( ...@@ -138,22 +139,13 @@ void CustomLayoutWorkTask::RunLayoutFragmentTask(
} }
void CustomLayoutWorkTask::RunIntrinsicSizesTask( void CustomLayoutWorkTask::RunIntrinsicSizesTask(
const NGBlockNode& parent,
const NGConstraintSpace& parent_space,
const ComputedStyle& parent_style, const ComputedStyle& parent_style,
const NGBoxStrut& border_scrollbar_padding, const LayoutUnit child_percentage_resolution_block_size_for_min_max,
NGLayoutInputNode child) { NGLayoutInputNode child) {
DCHECK_EQ(type_, CustomLayoutWorkTask::TaskType::kIntrinsicSizes); DCHECK_EQ(type_, CustomLayoutWorkTask::TaskType::kIntrinsicSizes);
DCHECK(resolver_); DCHECK(resolver_);
// TODO(almaher) should use border_padding instead of MinMaxSizeInput input(child_percentage_resolution_block_size_for_min_max);
// border_scrollbar_padding.
LayoutUnit child_percentage_resolution_block_size =
CalculateChildPercentageBlockSizeForMinMax(
parent_space, parent, border_scrollbar_padding,
parent_space.PercentageResolutionBlockSize());
MinMaxSizeInput input(child_percentage_resolution_block_size);
MinMaxSize sizes = MinMaxSize sizes =
ComputeMinAndMaxContentContribution(parent_style, child, input); ComputeMinAndMaxContentContribution(parent_style, child, input);
resolver_->Resolve(MakeGarbageCollected<CustomIntrinsicSizes>( resolver_->Resolve(MakeGarbageCollected<CustomIntrinsicSizes>(
......
...@@ -14,12 +14,11 @@ namespace blink { ...@@ -14,12 +14,11 @@ namespace blink {
class ComputedStyle; class ComputedStyle;
class CustomLayoutChild; class CustomLayoutChild;
class CustomLayoutToken; class CustomLayoutToken;
class NGBlockNode; class LayoutUnit;
class NGConstraintSpace; class NGConstraintSpace;
class NGLayoutInputNode; class NGLayoutInputNode;
class SerializedScriptValue; class SerializedScriptValue;
class ScriptPromiseResolver; class ScriptPromiseResolver;
struct NGBoxStrut;
// Contains all the information needed to resolve a promise with a fragment or // Contains all the information needed to resolve a promise with a fragment or
// intrinsic-sizes. // intrinsic-sizes.
...@@ -46,10 +45,9 @@ class CustomLayoutWorkTask { ...@@ -46,10 +45,9 @@ class CustomLayoutWorkTask {
~CustomLayoutWorkTask(); ~CustomLayoutWorkTask();
// Runs this work task. // Runs this work task.
void Run(const NGBlockNode& parent, void Run(const NGConstraintSpace& parent_space,
const NGConstraintSpace& parent_space,
const ComputedStyle& parent_style, const ComputedStyle& parent_style,
const NGBoxStrut& border_scrollbar_padding); const LayoutUnit child_percentage_resolution_block_size_for_min_max);
private: private:
Persistent<CustomLayoutChild> child_; Persistent<CustomLayoutChild> child_;
...@@ -62,11 +60,10 @@ class CustomLayoutWorkTask { ...@@ -62,11 +60,10 @@ class CustomLayoutWorkTask {
void RunLayoutFragmentTask(const NGConstraintSpace& parent_space, void RunLayoutFragmentTask(const NGConstraintSpace& parent_space,
const ComputedStyle& parent_style, const ComputedStyle& parent_style,
NGLayoutInputNode child); NGLayoutInputNode child);
void RunIntrinsicSizesTask(const NGBlockNode& parent, void RunIntrinsicSizesTask(
const NGConstraintSpace& parent_space, const ComputedStyle& parent_style,
const ComputedStyle& parent_style, const LayoutUnit child_percentage_resolution_block_size_for_min_max,
const NGBoxStrut& border_scrollbar_padding, NGLayoutInputNode child);
NGLayoutInputNode child);
}; };
} // namespace blink } // namespace blink
......
...@@ -31,6 +31,11 @@ NGCustomLayoutAlgorithm::NGCustomLayoutAlgorithm( ...@@ -31,6 +31,11 @@ NGCustomLayoutAlgorithm::NGCustomLayoutAlgorithm(
container_builder_.SetIsNewFormattingContext( container_builder_.SetIsNewFormattingContext(
params.space.IsNewFormattingContext()); params.space.IsNewFormattingContext());
container_builder_.SetInitialFragmentGeometry(params.fragment_geometry); container_builder_.SetInitialFragmentGeometry(params.fragment_geometry);
const NGConstraintSpace& space = ConstraintSpace();
child_percentage_resolution_block_size_for_min_max_ =
CalculateChildPercentageBlockSizeForMinMax(
space, Node(), border_padding_,
space.PercentageResolutionBlockSize());
} }
base::Optional<MinMaxSize> NGCustomLayoutAlgorithm::ComputeMinMaxSize( base::Optional<MinMaxSize> NGCustomLayoutAlgorithm::ComputeMinMaxSize(
...@@ -56,10 +61,11 @@ base::Optional<MinMaxSize> NGCustomLayoutAlgorithm::ComputeMinMaxSize( ...@@ -56,10 +61,11 @@ base::Optional<MinMaxSize> NGCustomLayoutAlgorithm::ComputeMinMaxSize(
IntrinsicSizesResultOptions* intrinsic_sizes_result_options = IntrinsicSizesResultOptions* intrinsic_sizes_result_options =
IntrinsicSizesResultOptions::Create(); IntrinsicSizesResultOptions::Create();
if (!instance->IntrinsicSizes(ConstraintSpace(), document, Node(), if (!instance->IntrinsicSizes(
container_builder_.InitialBorderBoxSize(), ConstraintSpace(), document, Node(),
border_scrollbar_padding_, &scope, container_builder_.InitialBorderBoxSize(), border_scrollbar_padding_,
intrinsic_sizes_result_options)) { child_percentage_resolution_block_size_for_min_max_, &scope,
intrinsic_sizes_result_options)) {
// TODO(ikilpatrick): Report this error to the developer. // TODO(ikilpatrick): Report this error to the developer.
return FallbackMinMaxSize(input); return FallbackMinMaxSize(input);
} }
...@@ -72,7 +78,7 @@ base::Optional<MinMaxSize> NGCustomLayoutAlgorithm::ComputeMinMaxSize( ...@@ -72,7 +78,7 @@ base::Optional<MinMaxSize> NGCustomLayoutAlgorithm::ComputeMinMaxSize(
intrinsic_sizes_result_options->minContentSize())); intrinsic_sizes_result_options->minContentSize()));
if (input.size_type == NGMinMaxSizeType::kContentBoxSize) if (input.size_type == NGMinMaxSizeType::kContentBoxSize)
sizes -= border_padding_.InlineSum(); sizes -= border_scrollbar_padding_.InlineSum();
sizes.min_size.ClampNegativeToZero(); sizes.min_size.ClampNegativeToZero();
sizes.max_size.ClampNegativeToZero(); sizes.max_size.ClampNegativeToZero();
...@@ -105,10 +111,11 @@ scoped_refptr<const NGLayoutResult> NGCustomLayoutAlgorithm::Layout() { ...@@ -105,10 +111,11 @@ scoped_refptr<const NGLayoutResult> NGCustomLayoutAlgorithm::Layout() {
FragmentResultOptions* fragment_result_options = FragmentResultOptions* fragment_result_options =
FragmentResultOptions::Create(); FragmentResultOptions::Create();
scoped_refptr<SerializedScriptValue> fragment_result_data; scoped_refptr<SerializedScriptValue> fragment_result_data;
if (!instance->Layout(ConstraintSpace(), document, Node(), if (!instance->Layout(
container_builder_.InitialBorderBoxSize(), ConstraintSpace(), document, Node(),
border_scrollbar_padding_, &scope, container_builder_.InitialBorderBoxSize(), border_scrollbar_padding_,
fragment_result_options, &fragment_result_data)) { child_percentage_resolution_block_size_for_min_max_, &scope,
fragment_result_options, &fragment_result_data)) {
// TODO(ikilpatrick): Report this error to the developer. // TODO(ikilpatrick): Report this error to the developer.
return FallbackLayout(); return FallbackLayout();
} }
......
...@@ -32,6 +32,7 @@ class CORE_EXPORT NGCustomLayoutAlgorithm ...@@ -32,6 +32,7 @@ class CORE_EXPORT NGCustomLayoutAlgorithm
const NGLayoutAlgorithmParams& params_; const NGLayoutAlgorithmParams& params_;
const NGBoxStrut border_padding_; const NGBoxStrut border_padding_;
const NGBoxStrut border_scrollbar_padding_; const NGBoxStrut border_scrollbar_padding_;
LayoutUnit child_percentage_resolution_block_size_for_min_max_;
}; };
} // namespace blink } // namespace blink
......
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