Commit 711a3a27 authored by eae's avatar eae Committed by Commit bot

[LayoutNG] Initial NGLayoutOpportunityIterator implementation

Add initial simple NGLayoutOpportunityIterator implementation. Does not
yet handle exclusions, inlines or bfcs.

R=ikilpatrick@chromium.org,cbiesinger@chromium.org
BUG=635619

Review-Url: https://codereview.chromium.org/2286403004
Cr-Commit-Position: refs/heads/master@{#415417}
parent 38182d4a
...@@ -81,7 +81,6 @@ void NGConstraintSpace::Subtract(const NGFragment*) { ...@@ -81,7 +81,6 @@ void NGConstraintSpace::Subtract(const NGFragment*) {
NGLayoutOpportunityIterator NGConstraintSpace::LayoutOpportunities( NGLayoutOpportunityIterator NGConstraintSpace::LayoutOpportunities(
unsigned clear, unsigned clear,
bool for_inline_or_bfc) { bool for_inline_or_bfc) {
// TODO(layout-ng): Implement.
NGLayoutOpportunityIterator iterator(this, clear, for_inline_or_bfc); NGLayoutOpportunityIterator iterator(this, clear, for_inline_or_bfc);
return iterator; return iterator;
} }
...@@ -131,4 +130,12 @@ void NGConstraintSpace::SetFragmentationType(NGFragmentationType type) { ...@@ -131,4 +130,12 @@ void NGConstraintSpace::SetFragmentationType(NGFragmentationType type) {
} }
} }
NGConstraintSpace* NGLayoutOpportunityIterator::Next() {
auto* exclusions = constraint_space_->PhysicalSpace()->Exclusions();
if (!exclusions->head())
return new NGConstraintSpace(constraint_space_->WritingMode(),
constraint_space_->PhysicalSpace());
return nullptr;
}
} // namespace blink } // namespace blink
...@@ -112,7 +112,7 @@ class CORE_EXPORT NGLayoutOpportunityIterator final { ...@@ -112,7 +112,7 @@ class CORE_EXPORT NGLayoutOpportunityIterator final {
for_inline_or_bfc_(for_inline_or_bfc) {} for_inline_or_bfc_(for_inline_or_bfc) {}
~NGLayoutOpportunityIterator() {} ~NGLayoutOpportunityIterator() {}
const NGDerivedConstraintSpace* Next(); NGConstraintSpace* Next();
private: private:
Persistent<NGConstraintSpace> constraint_space_; Persistent<NGConstraintSpace> constraint_space_;
......
...@@ -40,6 +40,21 @@ TEST(NGConstraintSpaceTest, WritingMode) { ...@@ -40,6 +40,21 @@ TEST(NGConstraintSpaceTest, WritingMode) {
EXPECT_EQ(FragmentNone, vert_space->BlockFragmentationType()); EXPECT_EQ(FragmentNone, vert_space->BlockFragmentationType());
} }
TEST(NGConstraintSpaceTest, LayoutOpportunities) {
NGPhysicalSize physical_size;
physical_size.width = LayoutUnit(600);
physical_size.height = LayoutUnit(400);
auto* physical_space = new NGPhysicalConstraintSpace(physical_size);
auto* space = new NGConstraintSpace(HorizontalTopBottom, physical_space);
bool for_inline_or_bfc = false;
auto iterator = space->LayoutOpportunities(NGClearNone, for_inline_or_bfc);
auto firstOpportunity = iterator.Next();
EXPECT_EQ(LayoutUnit(600), firstOpportunity->Size().inline_size);
EXPECT_EQ(LayoutUnit(400), firstOpportunity->Size().block_size);
}
} // namespace } // namespace
} // namespace blink } // namespace blink
...@@ -45,11 +45,11 @@ void NGPhysicalConstraintSpace::AddExclusion(const NGExclusion, ...@@ -45,11 +45,11 @@ void NGPhysicalConstraintSpace::AddExclusion(const NGExclusion,
// TODO(layout-ng): Implement. // TODO(layout-ng): Implement.
} }
DoublyLinkedList<const NGExclusion> NGPhysicalConstraintSpace::Exclusions( const DoublyLinkedList<const NGExclusion>*
unsigned options) const { NGPhysicalConstraintSpace::Exclusions(unsigned options) const {
DoublyLinkedList<const NGExclusion> exclusions; // TODO(layout-ng): Filter based on options? Perhaps layout Opportunities
// TODO(layout-ng): Implement. // should filter instead?
return exclusions; return &exclusions_;
} }
} // namespace blink } // namespace blink
...@@ -47,7 +47,8 @@ class CORE_EXPORT NGPhysicalConstraintSpace final ...@@ -47,7 +47,8 @@ class CORE_EXPORT NGPhysicalConstraintSpace final
NGPhysicalSize ContainerSize() const { return container_size_; } NGPhysicalSize ContainerSize() const { return container_size_; }
void AddExclusion(const NGExclusion, unsigned options = 0); void AddExclusion(const NGExclusion, unsigned options = 0);
DoublyLinkedList<const NGExclusion> Exclusions(unsigned options = 0) const; const DoublyLinkedList<const NGExclusion>* Exclusions(
unsigned options = 0) const;
DEFINE_INLINE_TRACE() {} DEFINE_INLINE_TRACE() {}
......
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