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

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

Issue 2284983002: [layoutng] Implement state machine for async layout (Closed)
Patch Set: remove outdated todo 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_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/style/ComputedStyle.h" 12 #include "core/style/ComputedStyle.h"
13 #include "platform/LengthFunctions.h" 13 #include "platform/LengthFunctions.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( 17 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(
18 PassRefPtr<const ComputedStyle> style, 18 PassRefPtr<const ComputedStyle> style,
19 NGBoxIterator box_iterator) 19 NGBox* first_child)
20 : style_(style), box_iterator_(box_iterator) {} 20 : style_(style), first_child_(first_child), state_(kStateInit) {}
21 21
22 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space, 22 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space,
23 NGFragment** out) { 23 NGFragment** out) {
24 LayoutUnit inline_size = 24 switch (state_) {
25 computeInlineSizeForFragment(*constraint_space, *style_); 25 case kStateInit: {
26 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of -1? 26 LayoutUnit inline_size =
27 LayoutUnit block_size = 27 computeInlineSizeForFragment(*constraint_space, *style_);
28 computeBlockSizeForFragment(*constraint_space, *style_, LayoutUnit(-1)); 28 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of
29 NGConstraintSpace* constraint_space_for_children = new NGConstraintSpace( 29 // -1?
30 *constraint_space, NGLogicalSize(inline_size, block_size)); 30 LayoutUnit block_size = computeBlockSizeForFragment(
31 *constraint_space, *style_, LayoutUnit(-1));
32 constraint_space_for_children_ = new NGConstraintSpace(
33 *constraint_space, NGLogicalSize(inline_size, block_size));
34 content_size_ = LayoutUnit();
31 35
32 NGFragmentBuilder builder(NGFragmentBase::FragmentBox); 36 builder_ = new NGFragmentBuilder(NGFragmentBase::FragmentBox);
33 builder.SetInlineSize(inline_size).SetBlockSize(block_size); 37 builder_->SetInlineSize(inline_size).SetBlockSize(block_size);
38 current_child_ = first_child_;
39 state_ = kStateChildLayout;
40 return false;
41 }
42 case kStateChildLayout: {
43 if (current_child_) {
44 NGFragment* fragment;
45 if (!current_child_->Layout(constraint_space_for_children_, &fragment))
46 return false;
47 NGBoxStrut child_margins = computeMargins(
48 *constraint_space_for_children_, *current_child_->Style());
49 // TODO(layout-ng): Support auto margins
50 fragment->SetOffset(child_margins.inline_start,
51 content_size_ + child_margins.block_start);
52 current_child_->PositionUpdated(*fragment);
53 content_size_ += fragment->BlockSize() + child_margins.BlockSum();
54 max_inline_size_ =
55 std::max(max_inline_size_,
56 fragment->InlineSize() + child_margins.InlineSum());
57 builder_->AddChild(fragment);
58 current_child_ = current_child_->NextSibling();
59 if (current_child_)
60 return false;
61 }
34 62
35 LayoutUnit content_size; 63 state_ = kStateFinalize;
36 for (NGBox box : box_iterator_) { 64 return false;
37 NGBoxStrut child_margins = 65 }
38 computeMargins(*constraint_space_for_children, *box.style()); 66 case kStateFinalize: {
39 NGFragment* fragment; 67 // Recompute the block-axis size now that we know our content size.
40 // TODO(layout-ng): Actually make this async 68 LayoutUnit block_size = computeBlockSizeForFragment(
41 while (!box.Layout(constraint_space_for_children, &fragment)) 69 *constraint_space, *style_, content_size_);
42 ;
43 // TODO(layout-ng): Support auto margins
44 fragment->SetOffset(child_margins.inline_start,
45 content_size + child_margins.block_start);
46 box.positionUpdated(*fragment);
47 content_size += fragment->BlockSize() + child_margins.BlockSum();
48 builder.AddChild(fragment);
49 }
50 70
51 // Recompute the block-axis size now that we know our content size. 71 builder_->SetBlockSize(block_size)
52 block_size = 72 .SetInlineOverflow(max_inline_size_)
53 computeBlockSizeForFragment(*constraint_space, *style_, content_size); 73 .SetBlockOverflow(content_size_);
54 74 *out = builder_->ToFragment();
55 // TODO(layout-ng): Compute correct inline overflow (block overflow should be 75 state_ = kStateInit;
56 // correct) 76 return true;
57 builder.SetBlockSize(block_size) 77 }
58 .SetInlineOverflow(inline_size) 78 };
eae 2016/08/26 23:47:38 ASSERT_NOT_REACHED (or whateher the DCHECK equiv i
cbiesinger 2016/08/29 15:49:20 Done.
59 .SetBlockOverflow(content_size);
60 *out = builder.ToFragment();
61 return true;
62 } 79 }
63 80
64 } // namespace blink 81 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698