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

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

Issue 2270983002: [layoutng] Add an NGFragmentBuilder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove SwapChildren Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/ng/ng_box.h" 5 #include "core/layout/ng/ng_box.h"
6 6
7 #include "core/layout/LayoutObject.h" 7 #include "core/layout/LayoutObject.h"
8 #include "core/layout/ng/layout_ng_block_flow.h" 8 #include "core/layout/ng/layout_ng_block_flow.h"
9 #include "core/layout/ng/ng_block_layout_algorithm.h" 9 #include "core/layout/ng/ng_block_layout_algorithm.h"
10 #include "core/layout/ng/ng_box_iterator.h" 10 #include "core/layout/ng/ng_box_iterator.h"
11 #include "core/layout/ng/ng_fragment.h" 11 #include "core/layout/ng/ng_fragment.h"
12 #include "core/layout/ng/ng_fragment_builder.h"
12 #include "core/layout/LayoutBlockFlow.h" 13 #include "core/layout/LayoutBlockFlow.h"
13 #include "core/layout/LayoutBox.h" 14 #include "core/layout/LayoutBox.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 NGFragment* NGBox::layout(const NGConstraintSpace& constraintSpace) { 18 NGFragment* NGBox::layout(const NGConstraintSpace& constraintSpace) {
18 // We can either use the new layout code to do the layout and then copy the 19 // We can either use the new layout code to do the layout and then copy the
19 // resulting size to the LayoutObject, or use the old layout code and 20 // resulting size to the LayoutObject, or use the old layout code and
20 // synthesize a fragment. 21 // synthesize a fragment.
21 NGFragment* fragment = nullptr; 22 NGFragment* fragment = nullptr;
22 if (canUseNewLayout()) { 23 if (canUseNewLayout()) {
23 NGBlockLayoutAlgorithm algorithm(style(), childIterator()); 24 NGBlockLayoutAlgorithm algorithm(style(), childIterator());
24 fragment = algorithm.layout(constraintSpace); 25 fragment = algorithm.layout(constraintSpace);
25 m_layoutBox->setLogicalWidth(fragment->inlineSize()); 26 m_layoutBox->setLogicalWidth(fragment->InlineSize());
26 m_layoutBox->setLogicalHeight(fragment->blockSize()); 27 m_layoutBox->setLogicalHeight(fragment->BlockSize());
27 if (m_layoutBox->isLayoutBlock()) 28 if (m_layoutBox->isLayoutBlock())
28 toLayoutBlock(m_layoutBox)->layoutPositionedObjects(true); 29 toLayoutBlock(m_layoutBox)->layoutPositionedObjects(true);
29 m_layoutBox->clearNeedsLayout(); 30 m_layoutBox->clearNeedsLayout();
30 } else { 31 } else {
31 // TODO(layout-ng): If fixedSize is true, set the override width/height too 32 // TODO(layout-ng): If fixedSize is true, set the override width/height too
32 NGLogicalSize containerSize = constraintSpace.ContainerSize(); 33 NGLogicalSize containerSize = constraintSpace.ContainerSize();
33 m_layoutBox->setOverrideContainingBlockContentLogicalWidth( 34 m_layoutBox->setOverrideContainingBlockContentLogicalWidth(
34 containerSize.inlineSize); 35 containerSize.inlineSize);
35 m_layoutBox->setOverrideContainingBlockContentLogicalHeight( 36 m_layoutBox->setOverrideContainingBlockContentLogicalHeight(
36 containerSize.blockSize); 37 containerSize.blockSize);
37 if (m_layoutBox->isLayoutNGBlockFlow() && m_layoutBox->needsLayout()) { 38 if (m_layoutBox->isLayoutNGBlockFlow() && m_layoutBox->needsLayout()) {
38 toLayoutNGBlockFlow(m_layoutBox)->LayoutBlockFlow::layoutBlock(true); 39 toLayoutNGBlockFlow(m_layoutBox)->LayoutBlockFlow::layoutBlock(true);
39 } else { 40 } else {
40 m_layoutBox->layoutIfNeeded(); 41 m_layoutBox->layoutIfNeeded();
41 } 42 }
42 LayoutRect overflow = m_layoutBox->layoutOverflowRect(); 43 LayoutRect overflow = m_layoutBox->layoutOverflowRect();
43 // TODO(layout-ng): This does not handle writing modes correctly (for 44 // TODO(layout-ng): This does not handle writing modes correctly (for
44 // overflow & the enums) 45 // overflow & the enums)
45 fragment = new NGFragment( 46 NGFragmentBuilder builder(NGFragmentBase::FragmentBox);
46 m_layoutBox->logicalWidth(), m_layoutBox->logicalHeight(), 47 builder.SetInlineSize(m_layoutBox->logicalWidth())
47 overflow.width(), overflow.height(), HorizontalTopBottom, LeftToRight); 48 .SetBlockSize(m_layoutBox->logicalHeight())
49 .SetInlineOverflow(overflow.width())
50 .SetBlockOverflow(overflow.height());
51 fragment = builder.ToFragment();
48 } 52 }
49 return fragment; 53 return fragment;
50 } 54 }
51 55
52 const ComputedStyle* NGBox::style() const { 56 const ComputedStyle* NGBox::style() const {
53 return m_layoutBox->style(); 57 return m_layoutBox->style();
54 } 58 }
55 59
56 NGBoxIterator NGBox::childIterator() { 60 NGBoxIterator NGBox::childIterator() {
57 return NGBoxIterator(firstChild()); 61 return NGBoxIterator(firstChild());
58 } 62 }
59 63
60 NGBox NGBox::nextSibling() const { 64 NGBox NGBox::nextSibling() const {
61 return m_layoutBox ? NGBox(m_layoutBox->nextSibling()) : NGBox(); 65 return m_layoutBox ? NGBox(m_layoutBox->nextSibling()) : NGBox();
62 } 66 }
63 67
64 NGBox NGBox::firstChild() const { 68 NGBox NGBox::firstChild() const {
65 return m_layoutBox ? NGBox(m_layoutBox->slowFirstChild()) : NGBox(); 69 return m_layoutBox ? NGBox(m_layoutBox->slowFirstChild()) : NGBox();
66 } 70 }
67 71
68 void NGBox::positionUpdated(const NGFragment& fragment) { 72 void NGBox::positionUpdated(const NGFragment& fragment) {
69 m_layoutBox->setLogicalLeft(fragment.inlineOffset()); 73 m_layoutBox->setLogicalLeft(fragment.InlineOffset());
70 m_layoutBox->setLogicalTop(fragment.blockOffset()); 74 m_layoutBox->setLogicalTop(fragment.BlockOffset());
71 } 75 }
72 76
73 bool NGBox::canUseNewLayout() { 77 bool NGBox::canUseNewLayout() {
74 if (!m_layoutBox) 78 if (!m_layoutBox)
75 return true; 79 return true;
76 if (m_layoutBox->isLayoutBlockFlow() && !m_layoutBox->childrenInline()) 80 if (m_layoutBox->isLayoutBlockFlow() && !m_layoutBox->childrenInline())
77 return true; 81 return true;
78 return false; 82 return false;
79 } 83 }
80 } // namespace blink 84 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698