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

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

Issue 2693193002: [LayoutNG] A different approach to multi-col. (Closed)
Patch Set: Created 3 years, 10 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/layout/ng/ng_multi_column_layout_algorithm.h"
6
7 #include "core/layout/ng/ng_absolute_utils.h"
8 #include "core/layout/ng/ng_block_break_token.h"
9 #include "core/layout/ng/ng_block_layout_algorithm.h"
10 #include "core/layout/ng/ng_box_fragment.h"
11 #include "core/layout/ng/ng_column_mapper.h"
12 #include "core/layout/ng/ng_constraint_space.h"
13 #include "core/layout/ng/ng_constraint_space_builder.h"
14 #include "core/layout/ng/ng_fragment.h"
15 #include "core/layout/ng/ng_fragment_builder.h"
16 #include "core/layout/ng/ng_inline_node.h"
17 #include "core/layout/ng/ng_layout_opportunity_iterator.h"
18 #include "core/layout/ng/ng_length_utils.h"
19 #include "core/layout/ng/ng_line_builder.h"
20 #include "core/layout/ng/ng_out_of_flow_layout_part.h"
21 #include "core/layout/ng/ng_units.h"
22 #include "core/style/ComputedStyle.h"
23 #include "platform/LengthFunctions.h"
24 #include "wtf/Optional.h"
25
26 namespace blink {
27
28 NGMultiColumnLayoutAlgorithm::NGMultiColumnLayoutAlgorithm(
29 NGBlockNode* node,
30 NGConstraintSpace* constraint_space,
31 NGBreakToken* break_token)
32 : node_(node),
33 constraint_space_(constraint_space),
34 break_token_(break_token),
35 builder_(WTF::wrapUnique(
36 new NGFragmentBuilder(NGPhysicalFragment::kFragmentBox, node))) {}
37
38 Optional<MinAndMaxContentSizes>
39 NGMultiColumnLayoutAlgorithm::ComputeMinAndMaxContentSizes() const {
40 return NGBlockLayoutAlgorithm(node_, constraint_space_,
41 toNGBlockBreakToken(break_token_))
42 .ComputeMinAndMaxContentSizes();
43 }
44
45 RefPtr<NGPhysicalFragment> NGMultiColumnLayoutAlgorithm::Layout() {
46 WTF::Optional<MinAndMaxContentSizes> sizes;
47 if (NeedMinAndMaxContentSizes(ConstraintSpace(), Style()))
48 sizes = ComputeMinAndMaxContentSizes();
49
50 border_and_padding_ =
51 ComputeBorders(Style()) + ComputePadding(ConstraintSpace(), Style());
52
53 LayoutUnit inline_size =
54 ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes);
55
56 DCHECK(Style().specifiesColumns());
57 LayoutUnit adjusted_inline_size = ResolveUsedColumnInlineSize(
58 inline_size - border_and_padding_.InlineSum(), Style());
59
60 /*LayoutUnit inline_progression =
61 adjusted_inline_size + ResolveUsedColumnGap(Style());*/
mstensho (USE GERRIT) 2017/02/15 21:12:23 So this is currently missing, right? We need to be
62
63 LayoutUnit block_size =
64 ComputeBlockSizeForFragment(ConstraintSpace(), Style(), NGSizeIndefinite);
65
66 // Our calculated block-axis size may be indefinite at this point.
67 // If so, just leave the size as NGSizeIndefinite instead of subtracting
68 // borders and padding.
69 LayoutUnit adjusted_block_size(block_size);
70 if (adjusted_block_size != NGSizeIndefinite)
71 adjusted_block_size -= border_and_padding_.BlockSum();
72
73 space_builder_ = new NGConstraintSpaceBuilder(constraint_space_);
74 space_builder_->SetFragmentationType(kFragmentColumn)
75 .SetAvailableSize(
mstensho (USE GERRIT) 2017/02/15 21:12:23 I've been meaning to ask this for some time: What
ikilpatrick 2017/02/16 16:48:31 I think just that's what all the other builders lo
mstensho (USE GERRIT) 2017/02/16 21:14:47 Yes, this is a common pattern in this code. I'm ju
76 NGLogicalSize(adjusted_inline_size, adjusted_block_size))
77 .SetPercentageResolutionSize(
78 NGLogicalSize(adjusted_inline_size, adjusted_block_size));
79
80 // TODO(ikilpatrick): if we don't have a fragmentation line we should peform a
81 // full layout, determine the break opportunities, and then perform a relayout
82 // into the individual columns.
83 // If __our__ constraint space has a column fragmentation line, we trust that
84 // a multi column algorithm above us has determined the correct layout
85 // opportunites so we just layout with that fragmentation line.
86
87 // TODO(ikilpatrick): We only support multicols with definite block sizes.
88 DCHECK(adjusted_block_size != NGSizeIndefinite);
89 space_builder_->SetFragmentainerSpaceAvailable(
90 constraint_space_->HasBlockFragmentation()
91 ? constraint_space_->FragmentainerSpaceAvailable()
92 : // TODO need to account for borders and padding.
93 adjusted_block_size);
94
95 builder_->SetDirection(constraint_space_->Direction());
96 builder_->SetWritingMode(constraint_space_->WritingMode());
97 builder_->SetInlineSize(inline_size).SetBlockSize(block_size);
98
99 /*LayoutUnit block_offset = border_and_padding_.block_start;
100 LayoutUnit inline_offset = border_and_padding_.inline_start;*/
101
102 NGBreakToken* break_token =
103 break_token_; // TODO we should have a special multi-col break token.
104 do {
105 RefPtr<NGPhysicalFragment> physical_fragment =
106 NGBlockLayoutAlgorithm(node_, space_builder_->ToConstraintSpace(),
107 toNGBlockBreakToken(break_token))
108 .Layout();
109
110 // TODO(ikilpatrick): we need to check if a spanner was bubbled up to us, if
111 // so, layout that next across all the columns. :)
mstensho (USE GERRIT) 2017/02/15 21:12:23 I'm against using spanners and smileys in the same
ikilpatrick 2017/02/16 16:48:32 :)
112
113 break_token = physical_fragment->BreakToken();
114 } while (!break_token->IsFinished()); // TODO OR WE SHOULD FRAGMENT.
115
116 // Recompute the block-axis size now that we know our content size.
117 block_size =
118 ComputeBlockSizeForFragment(ConstraintSpace(), Style(), content_size_);
119 builder_->SetBlockSize(block_size);
120 builder_->SetInlineOverflow(max_inline_size_).SetBlockOverflow(content_size_);
121
122 return builder_->ToBoxFragment();
123 }
124
125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698