Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: third_party/WebKit/Source/core/layout/ng/ng_box.cc

Issue 2244463003: [layoutng] Bidirectional interoperability between layoutng and legacy layout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Positioning Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_box.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_box.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698