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

Unified 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: a rebase for myself. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_multi_column_layout_algorithm.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/layout/ng/ng_multi_column_layout_algorithm.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_multi_column_layout_algorithm.cc b/third_party/WebKit/Source/core/layout/ng/ng_multi_column_layout_algorithm.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2359dc872030f1fe45d47410d5e08694474b8a8e
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/ng/ng_multi_column_layout_algorithm.cc
@@ -0,0 +1,125 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/layout/ng/ng_multi_column_layout_algorithm.h"
+
+#include "core/layout/ng/ng_absolute_utils.h"
+#include "core/layout/ng/ng_block_break_token.h"
+#include "core/layout/ng/ng_block_layout_algorithm.h"
+#include "core/layout/ng/ng_box_fragment.h"
+#include "core/layout/ng/ng_constraint_space.h"
+#include "core/layout/ng/ng_constraint_space_builder.h"
+#include "core/layout/ng/ng_fragment.h"
+#include "core/layout/ng/ng_fragment_builder.h"
+#include "core/layout/ng/ng_inline_node.h"
+#include "core/layout/ng/ng_layout_opportunity_iterator.h"
+#include "core/layout/ng/ng_length_utils.h"
+#include "core/layout/ng/ng_line_builder.h"
+#include "core/layout/ng/ng_out_of_flow_layout_part.h"
+#include "core/style/ComputedStyle.h"
+#include "platform/LengthFunctions.h"
+#include "wtf/Optional.h"
+
+namespace blink {
+
+NGMultiColumnLayoutAlgorithm::NGMultiColumnLayoutAlgorithm(
+ NGBlockNode* node,
+ NGConstraintSpace* constraint_space,
+ NGBreakToken* break_token)
+ : node_(node),
+ constraint_space_(constraint_space),
+ break_token_(break_token),
+ builder_(NGPhysicalFragment::kFragmentBox, node),
+ space_builder_(constraint_space) {}
+
+Optional<MinMaxContentSize>
+NGMultiColumnLayoutAlgorithm::ComputeMinMaxContentSize() const {
+ return NGBlockLayoutAlgorithm(node_, constraint_space_,
+ toNGBlockBreakToken(break_token_))
+ .ComputeMinMaxContentSize();
+}
+
+RefPtr<NGLayoutResult> NGMultiColumnLayoutAlgorithm::Layout() {
+ WTF::Optional<MinMaxContentSize> sizes;
+ if (NeedMinMaxContentSize(ConstraintSpace(), Style()))
+ sizes = ComputeMinMaxContentSize();
+
+ border_and_padding_ = ComputeBorders(ConstraintSpace(), Style()) +
+ ComputePadding(ConstraintSpace(), Style());
+
+ LayoutUnit inline_size =
+ ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes);
+
+ DCHECK(Style().specifiesColumns());
+ LayoutUnit adjusted_inline_size = ResolveUsedColumnInlineSize(
+ inline_size - border_and_padding_.InlineSum(), Style());
+
+ /*LayoutUnit inline_progression =
+ adjusted_inline_size + ResolveUsedColumnGap(Style());*/
+
+ LayoutUnit block_size =
+ ComputeBlockSizeForFragment(ConstraintSpace(), Style(), NGSizeIndefinite);
+
+ // Our calculated block-axis size may be indefinite at this point.
+ // If so, just leave the size as NGSizeIndefinite instead of subtracting
+ // borders and padding.
+ LayoutUnit adjusted_block_size(block_size);
+ if (adjusted_block_size != NGSizeIndefinite)
+ adjusted_block_size -= border_and_padding_.BlockSum();
+
+ space_builder_.SetFragmentationType(kFragmentColumn)
+ .SetAvailableSize(
+ NGLogicalSize(adjusted_inline_size, adjusted_block_size))
+ .SetPercentageResolutionSize(
+ NGLogicalSize(adjusted_inline_size, adjusted_block_size));
+
+ // TODO(ikilpatrick): if we don't have a fragmentation line we should peform a
+ // full layout, determine the break opportunities, and then perform a relayout
+ // into the individual columns.
+ // If __our__ constraint space has a column fragmentation line, we trust that
+ // a multi column algorithm above us has determined the correct layout
+ // opportunites so we just layout with that fragmentation line.
+
+ // TODO(ikilpatrick): We only support multicols with definite block sizes.
+ DCHECK(adjusted_block_size != NGSizeIndefinite);
+ space_builder_.SetFragmentainerSpaceAvailable(
+ constraint_space_->HasBlockFragmentation()
+ ? constraint_space_->FragmentainerSpaceAvailable()
+ : // TODO need to account for borders and padding.
+ adjusted_block_size);
+
+ builder_.SetDirection(constraint_space_->Direction());
+ builder_.SetWritingMode(constraint_space_->WritingMode());
+ builder_.SetInlineSize(inline_size).SetBlockSize(block_size);
+
+ /*LayoutUnit block_offset = border_and_padding_.block_start;
+ LayoutUnit inline_offset = border_and_padding_.inline_start;*/
+
+ NGBreakToken* break_token =
+ break_token_; // TODO we should have a special multi-col break token.
+ do {
+ RefPtr<NGConstraintSpace> space = space_builder_.ToConstraintSpace(
+ FromPlatformWritingMode(Style().getWritingMode()));
+
+ RefPtr<NGLayoutResult> layout_result =
Gleb Lanbin 2017/04/03 16:54:55 this should be declared out of the loop's scope. O
+ NGBlockLayoutAlgorithm(node_, space.get(),
+ toNGBlockBreakToken(break_token))
+ .Layout();
+
+ // TODO(ikilpatrick): we need to check if a spanner was bubbled up to us, if
+ // so, layout that next across all the columns. :)
+
+ break_token = layout_result->PhysicalFragment()->BreakToken();
+ } while (!break_token->IsFinished()); // TODO OR WE SHOULD FRAGMENT.
+
+ // Recompute the block-axis size now that we know our content size.
+ block_size =
+ ComputeBlockSizeForFragment(ConstraintSpace(), Style(), content_size_);
+ builder_.SetBlockSize(block_size);
+ builder_.SetInlineOverflow(max_inline_size_).SetBlockOverflow(content_size_);
+
+ return builder_.ToBoxFragment();
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_multi_column_layout_algorithm.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698