OLD | NEW |
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_builder.h" |
10 #include "core/layout/ng/ng_fragment.h" | 10 #include "core/layout/ng/ng_fragment.h" |
11 #include "core/layout/ng/ng_length_utils.h" | 11 #include "core/layout/ng/ng_length_utils.h" |
12 #include "core/layout/ng/ng_margin_strut.h" | 12 #include "core/layout/ng/ng_margin_strut.h" |
13 #include "core/style/ComputedStyle.h" | 13 #include "core/style/ComputedStyle.h" |
14 #include "platform/LengthFunctions.h" | 14 #include "platform/LengthFunctions.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( | 18 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( |
19 PassRefPtr<const ComputedStyle> style, | 19 PassRefPtr<const ComputedStyle> style, |
20 NGBoxIterator boxIterator) | 20 NGBoxIterator box_iterator) |
21 : m_style(style), m_boxIterator(boxIterator) {} | 21 : m_style(style), m_boxIterator(box_iterator) {} |
22 | 22 |
23 NGFragment* NGBlockLayoutAlgorithm::layout( | 23 NGFragment* NGBlockLayoutAlgorithm::layout( |
24 const NGConstraintSpace& constraintSpace) { | 24 const NGConstraintSpace& constraint_space) { |
25 LayoutUnit inlineSize = | 25 LayoutUnit inline_size = |
26 computeInlineSizeForFragment(constraintSpace, *m_style); | 26 computeInlineSizeForFragment(constraint_space, *m_style); |
27 // 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? |
28 LayoutUnit blockSize = | 28 LayoutUnit block_size = |
29 computeBlockSizeForFragment(constraintSpace, *m_style, LayoutUnit(-1)); | 29 computeBlockSizeForFragment(constraint_space, *m_style, LayoutUnit(-1)); |
30 NGConstraintSpace constraint_space_for_children( | 30 NGConstraintSpace constraint_space_for_children( |
31 constraintSpace, NGLogicalSize(inlineSize, blockSize)); | 31 constraint_space, NGLogicalSize(inline_size, block_size)); |
32 | 32 |
33 NGFragmentBuilder builder(NGFragmentBase::FragmentBox); | 33 NGFragmentBuilder builder(NGFragmentBase::FragmentBox); |
34 builder.SetInlineSize(inlineSize).SetBlockSize(blockSize); | 34 builder.SetInlineSize(inline_size).SetBlockSize(block_size); |
35 | 35 |
36 LayoutUnit contentSize; | 36 LayoutUnit content_size; |
37 for (NGBox box : m_boxIterator) { | 37 for (NGBox box : m_boxIterator) { |
38 NGBoxMargins childMargins = | 38 NGBoxMargins child_margins = |
39 computeMargins(constraint_space_for_children, *box.style()); | 39 computeMargins(constraint_space_for_children, *box.style()); |
40 NGFragment* fragment = box.layout(constraint_space_for_children); | 40 NGFragment* fragment = box.layout(constraint_space_for_children); |
41 // TODO(layout-ng): Support auto margins | 41 // TODO(layout-ng): Support auto margins |
42 fragment->SetOffset(childMargins.inlineStart, | 42 fragment->SetOffset(child_margins.inline_start, |
43 contentSize + childMargins.blockStart); | 43 content_size + child_margins.block_start); |
44 box.positionUpdated(*fragment); | 44 box.positionUpdated(*fragment); |
45 contentSize += fragment->BlockSize() + childMargins.blockSum(); | 45 content_size += fragment->BlockSize() + child_margins.BlockSum(); |
46 builder.AddChild(fragment); | 46 builder.AddChild(fragment); |
47 } | 47 } |
48 | 48 |
49 // 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. |
50 blockSize = | 50 block_size = |
51 computeBlockSizeForFragment(constraintSpace, *m_style, contentSize); | 51 computeBlockSizeForFragment(constraint_space, *m_style, content_size); |
52 // TODO(layout-ng): Compute correct inline overflow (block overflow should be | 52 // TODO(layout-ng): Compute correct inline overflow (block overflow should be |
53 // correct) | 53 // correct) |
54 builder.SetBlockSize(blockSize) | 54 builder.SetBlockSize(block_size) |
55 .SetInlineOverflow(inlineSize) | 55 .SetInlineOverflow(inline_size) |
56 .SetBlockOverflow(contentSize); | 56 .SetBlockOverflow(content_size); |
57 return builder.ToFragment(); | 57 return builder.ToFragment(); |
58 } | 58 } |
59 | 59 |
60 } // namespace blink | 60 } // namespace blink |
OLD | NEW |