Index: third_party/WebKit/Source/core/layout/ng/ng_box.cc |
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_box.cc b/third_party/WebKit/Source/core/layout/ng/ng_box.cc |
index a32d9852d34ca0e34953bb9d2bef0ebffd990c52..d5e1bafae6771664a5536c84479b44c6b06716f7 100644 |
--- a/third_party/WebKit/Source/core/layout/ng/ng_box.cc |
+++ b/third_party/WebKit/Source/core/layout/ng/ng_box.cc |
@@ -5,19 +5,40 @@ |
#include "core/layout/ng/ng_box.h" |
#include "core/layout/LayoutObject.h" |
+#include "core/layout/ng/layout_ng_block_flow.h" |
#include "core/layout/ng/ng_block_layout_algorithm.h" |
#include "core/layout/ng/ng_box_iterator.h" |
#include "core/layout/ng/ng_fragment.h" |
+#include "core/layout/LayoutBlockFlow.h" |
#include "core/layout/LayoutBox.h" |
namespace blink { |
NGFragment* NGBox::layout(const NGConstraintSpace& constraintSpace) { |
- NGBlockLayoutAlgorithm algorithm(style(), childIterator()); |
- m_layoutBox->clearNeedsLayout(); |
- NGFragment* fragment = algorithm.layout(constraintSpace); |
- m_layoutBox->setLogicalWidth(fragment->inlineSize()); |
- m_layoutBox->setLogicalHeight(fragment->blockSize()); |
+ // We can either use the new layout code to do the layout and then copy the |
+ // resulting size to the LayoutObject, or use the old layout code and |
+ // synthesize a fragment. |
+ NGFragment* fragment = nullptr; |
+ if (canUseNewLayout()) { |
+ NGBlockLayoutAlgorithm algorithm(style(), childIterator()); |
+ fragment = algorithm.layout(constraintSpace); |
+ m_layoutBox->setLogicalWidth(fragment->inlineSize()); |
+ m_layoutBox->setLogicalHeight(fragment->blockSize()); |
+ if (m_layoutBox->isLayoutBlock()) |
+ toLayoutBlock(m_layoutBox)->layoutPositionedObjects(true); |
+ m_layoutBox->clearNeedsLayout(); |
+ } else { |
+ if (m_layoutBox->isLayoutNGBlockFlow() && m_layoutBox->needsLayout()) { |
+ toLayoutNGBlockFlow(m_layoutBox)->LayoutBlockFlow::layoutBlock(true); |
+ } else { |
+ m_layoutBox->layoutIfNeeded(); |
+ } |
+ LayoutRect overflow = m_layoutBox->layoutOverflowRect(); |
+ // This does not handle writing modes correctly (for overflow & the enums) |
+ fragment = new NGFragment( |
+ m_layoutBox->logicalWidth(), m_layoutBox->logicalHeight(), |
+ overflow.width(), overflow.height(), HorizontalTopBottom, LeftToRight); |
+ } |
return fragment; |
} |
@@ -36,4 +57,17 @@ NGBox NGBox::nextSibling() const { |
NGBox NGBox::firstChild() const { |
return m_layoutBox ? NGBox(m_layoutBox->slowFirstChild()) : NGBox(); |
} |
+ |
+void NGBox::positionUpdated(const NGFragment& fragment) { |
+ m_layoutBox->setLogicalLeft(fragment.inlineOffset()); |
+ m_layoutBox->setLogicalTop(fragment.blockOffset()); |
+} |
+ |
+bool NGBox::canUseNewLayout() { |
+ if (!m_layoutBox) |
+ return true; |
+ if (m_layoutBox->isLayoutBlockFlow() && !m_layoutBox->childrenInline()) |
+ return true; |
+ return false; |
+} |
} // namespace blink |