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

Unified Diff: third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator.cc

Issue 2706353004: [LayoutNG] Introduce block child iterator. (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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator.cc b/third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..63fb7007d8fb245668b4b20ddff1ff41c1e091bf
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/ng/ng_block_child_iterator.cc
@@ -0,0 +1,60 @@
+// 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_block_child_iterator.h"
+
+#include "core/layout/ng/ng_block_break_token.h"
+#include "core/layout/ng/ng_layout_input_node.h"
+
+namespace blink {
+
+NGBlockChildIterator::NGBlockChildIterator(NGLayoutInputNode* first_child,
+ NGBlockBreakToken* break_token)
+ : child_(first_child), break_token_(break_token), child_token_idx_(0) {}
+
+std::pair<NGLayoutInputNode*, NGBreakToken*> NGBlockChildIterator::NextChild() {
+ NGLayoutInputNode* child = nullptr;
+ NGBreakToken* child_break_token = nullptr;
+
+ if (break_token_) {
+ // If we're resuming layout after a fragmentainer break, we need to skip
+ // siblings that we're done with. We may have been able to fully lay out
+ // some node(s) preceding a node that we had to break inside (and therefore
+ // were not able to fully lay out). This happens when we have parallel
+ // flows [1], which are caused by floats, overflow, etc.
+ //
+ // [1] https://drafts.csswg.org/css-break/#parallel-flows
+ do {
+ const auto& child_break_tokens = break_token_->ChildBreakTokens();
mstensho (USE GERRIT) 2017/02/22 13:11:30 Can be moved out of the do-while loop.
ikilpatrick 2017/02/22 18:47:19 Done.
+ NGBreakToken* child_break_token_candidate = nullptr;
+
+ if (child_token_idx_ < child_break_tokens.size()) {
mstensho (USE GERRIT) 2017/02/22 13:11:31 Looks like you could get out early here if you do:
ikilpatrick 2017/02/22 18:47:19 Done.
+ child_break_token_candidate = child_break_tokens[child_token_idx_];
+ }
+
+ if (child_break_token_candidate &&
+ child_break_token_candidate->InputNode() == child_) {
mstensho (USE GERRIT) 2017/02/22 13:11:31 And how about breaking early here if child_break_t
ikilpatrick 2017/02/22 18:47:19 Done.
+ ++child_token_idx_;
+
+ // We have only found a node if it's break token is unfinished.
mstensho (USE GERRIT) 2017/02/22 13:11:30 it's -> its
ikilpatrick 2017/02/22 18:47:19 Done.
+ if (!child_break_token_candidate->IsFinished()) {
+ child_break_token = child_break_token_candidate;
+ break;
mstensho (USE GERRIT) 2017/02/22 13:11:30 Let me see if I've got this right: Each child tha
ikilpatrick 2017/02/22 18:47:19 Yes thats exactly correct. I can try an encapsulat
mstensho (USE GERRIT) 2017/02/22 20:09:23 If it's a requirement that all finished nodes have
ikilpatrick 2017/02/22 22:25:21 Clarified comment on NGBlockBreakToken.
mstensho (USE GERRIT) 2017/02/23 08:31:40 Excellent! Thanks.
+ }
+ } else {
+ // This child break token candidate doesn't match the current node,
+ // this node must be unfinished.
+ break;
+ }
+ } while ((child_ = child_->NextSibling()));
+ }
+
+ child = child_;
+ if (child_)
+ child_ = child_->NextSibling();
+
+ return std::make_pair(child, child_break_token);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698