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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.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_block_layout_algorithm.h" 5 #include "core/layout/ng/ng_block_layout_algorithm.h"
6 6
7 #include "core/layout/LayoutBox.h" 7 #include "core/layout/LayoutBox.h"
8 #include "core/layout/ng/ng_constraint_space.h" 8 #include "core/layout/ng/ng_constraint_space.h"
9 #include "core/layout/ng/ng_fragment_builder.h"
9 #include "core/layout/ng/ng_fragment.h" 10 #include "core/layout/ng/ng_fragment.h"
10 #include "core/layout/ng/ng_length_utils.h" 11 #include "core/layout/ng/ng_length_utils.h"
11 #include "core/layout/ng/ng_margin_strut.h" 12 #include "core/layout/ng/ng_margin_strut.h"
12 #include "core/style/ComputedStyle.h" 13 #include "core/style/ComputedStyle.h"
13 #include "platform/LengthFunctions.h" 14 #include "platform/LengthFunctions.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( 18 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(
18 PassRefPtr<const ComputedStyle> style, 19 PassRefPtr<const ComputedStyle> style,
19 NGBoxIterator boxIterator) 20 NGBoxIterator boxIterator)
20 : m_style(style), m_boxIterator(boxIterator) {} 21 : m_style(style), m_boxIterator(boxIterator) {}
21 22
22 NGFragment* NGBlockLayoutAlgorithm::layout( 23 NGFragment* NGBlockLayoutAlgorithm::layout(
23 const NGConstraintSpace& constraintSpace) { 24 const NGConstraintSpace& constraintSpace) {
24 LayoutUnit inlineSize = 25 LayoutUnit inlineSize =
25 computeInlineSizeForFragment(constraintSpace, *m_style); 26 computeInlineSizeForFragment(constraintSpace, *m_style);
26 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of -1? 27 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of -1?
27 LayoutUnit blockSize = 28 LayoutUnit blockSize =
28 computeBlockSizeForFragment(constraintSpace, *m_style, LayoutUnit(-1)); 29 computeBlockSizeForFragment(constraintSpace, *m_style, LayoutUnit(-1));
29 NGConstraintSpace constraint_space_for_children( 30 NGConstraintSpace constraint_space_for_children(
30 constraintSpace, NGLogicalSize(inlineSize, blockSize)); 31 constraintSpace, NGLogicalSize(inlineSize, blockSize));
31 32
32 HeapVector<Member<const NGFragmentBase>> childFragments; 33 NGFragmentBuilder builder(NGFragmentBase::FragmentBox);
34 builder.SetInlineSize(inlineSize).SetBlockSize(blockSize);
35
33 LayoutUnit contentSize; 36 LayoutUnit contentSize;
34 for (NGBox box : m_boxIterator) { 37 for (NGBox box : m_boxIterator) {
35 NGBoxMargins childMargins = 38 NGBoxMargins childMargins =
36 computeMargins(constraint_space_for_children, *box.style()); 39 computeMargins(constraint_space_for_children, *box.style());
37 NGFragment* fragment = box.layout(constraint_space_for_children); 40 NGFragment* fragment = box.layout(constraint_space_for_children);
38 // TODO(layout-ng): Support auto margins 41 // TODO(layout-ng): Support auto margins
39 fragment->setOffset(childMargins.inlineStart, 42 fragment->SetOffset(childMargins.inlineStart,
40 contentSize + childMargins.blockStart); 43 contentSize + childMargins.blockStart);
41 box.positionUpdated(*fragment); 44 box.positionUpdated(*fragment);
42 contentSize += fragment->blockSize() + childMargins.blockSum(); 45 contentSize += fragment->BlockSize() + childMargins.blockSum();
43 childFragments.append(fragment); 46 builder.AddChild(fragment);
44 } 47 }
45 48
46 // Recompute the block-axis size now that we know our content size. 49 // Recompute the block-axis size now that we know our content size.
47 blockSize = 50 blockSize =
48 computeBlockSizeForFragment(constraintSpace, *m_style, contentSize); 51 computeBlockSizeForFragment(constraintSpace, *m_style, contentSize);
49 NGFragment* returnFragment = 52 // TODO(layout-ng): Compute correct inline overflow (block overflow should be
50 new NGFragment(inlineSize, blockSize, inlineSize, blockSize, 53 // correct)
51 HorizontalTopBottom, LeftToRight); 54 builder.SetBlockSize(blockSize)
52 returnFragment->swapChildren(childFragments); 55 .SetInlineOverflow(inlineSize)
53 return returnFragment; 56 .SetBlockOverflow(contentSize);
57 return builder.ToFragment();
54 } 58 }
55 59
56 } // namespace blink 60 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698