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

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

Issue 2304993002: Fix NGBox's iterator logic (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/ng/ng_box.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_box.cc b/third_party/WebKit/Source/core/layout/ng/ng_box.cc
index a0eee39b2e28e8177b85dcd067eded44da8080ba..026d7bde3f958322c119b0cb8ed96425fa6dd9bc 100644
--- a/third_party/WebKit/Source/core/layout/ng/ng_box.cc
+++ b/third_party/WebKit/Source/core/layout/ng/ng_box.cc
@@ -21,7 +21,7 @@ NGBox::NGBox(LayoutObject* layout_object)
DCHECK(layout_box_);
}
-NGBox::NGBox(ComputedStyle* style) : style_(style) {
+NGBox::NGBox(ComputedStyle* style) : layout_box_(nullptr), style_(style) {
DCHECK(style_);
}
@@ -95,31 +95,30 @@ const ComputedStyle* NGBox::Style() const {
return layout_box_->style();
}
-NGBox* NGBox::NextSibling() const {
- if (style_)
- return next_sibling_;
- DCHECK(layout_box_);
- LayoutObject* next_sibling = layout_box_->nextSibling();
- return next_sibling ? new NGBox(next_sibling) : nullptr;
+NGBox* NGBox::NextSibling() {
+ if (!next_sibling_) {
+ LayoutObject* next_sibling =
+ layout_box_ ? layout_box_->nextSibling() : nullptr;
+ NGBox* box = next_sibling ? new NGBox(next_sibling) : nullptr;
+ SetNextSibling(box);
+ }
+ return next_sibling_;
}
-NGBox* NGBox::FirstChild() const {
- if (style_)
- return first_child_;
- DCHECK(layout_box_);
- LayoutObject* child = layout_box_->slowFirstChild();
- return child ? new NGBox(child) : nullptr;
+NGBox* NGBox::FirstChild() {
+ if (!first_child_) {
+ LayoutObject* child = layout_box_ ? layout_box_->slowFirstChild() : nullptr;
+ NGBox* box = child ? new NGBox(child) : nullptr;
+ SetFirstChild(box);
+ }
+ return first_child_;
}
void NGBox::SetNextSibling(NGBox* sibling) {
- DCHECK(!layout_box_);
- DCHECK(style_);
next_sibling_ = sibling;
}
void NGBox::SetFirstChild(NGBox* child) {
- DCHECK(!layout_box_);
- DCHECK(style_);
first_child_ = child;
}

Powered by Google App Engine
This is Rietveld 408576698