| OLD | NEW |
| 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_node.h" | 5 #include "core/layout/ng/ng_block_node.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutBlockFlow.h" | 7 #include "core/layout/LayoutBlockFlow.h" |
| 8 #include "core/layout/LayoutMultiColumnFlowThread.h" | 8 #include "core/layout/LayoutMultiColumnFlowThread.h" |
| 9 #include "core/layout/LayoutMultiColumnSet.h" | 9 #include "core/layout/LayoutMultiColumnSet.h" |
| 10 #include "core/layout/api/LineLayoutAPIShim.h" | 10 #include "core/layout/api/LineLayoutAPIShim.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 196 |
| 197 const ComputedStyle& NGBlockNode::Style() const { | 197 const ComputedStyle& NGBlockNode::Style() const { |
| 198 return layout_box_->StyleRef(); | 198 return layout_box_->StyleRef(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 NGLayoutInputNode* NGBlockNode::NextSibling() { | 201 NGLayoutInputNode* NGBlockNode::NextSibling() { |
| 202 if (!next_sibling_) { | 202 if (!next_sibling_) { |
| 203 LayoutObject* next_sibling = layout_box_->NextSibling(); | 203 LayoutObject* next_sibling = layout_box_->NextSibling(); |
| 204 if (next_sibling) { | 204 if (next_sibling) { |
| 205 if (next_sibling->IsInline()) { | 205 if (next_sibling->IsInline()) { |
| 206 // As long as we traverse LayoutObject tree, this should not happen. |
| 207 // See ShouldHandleByInlineContext() for more context. |
| 208 // Also this leads to incorrect layout because we create two |
| 209 // NGLayoutInputNode for one LayoutBlockFlow. |
| 210 NOTREACHED(); |
| 206 next_sibling_ = new NGInlineNode( | 211 next_sibling_ = new NGInlineNode( |
| 207 next_sibling, ToLayoutBlockFlow(layout_box_->Parent())); | 212 next_sibling, ToLayoutBlockFlow(layout_box_->Parent())); |
| 208 } else { | 213 } else { |
| 209 next_sibling_ = new NGBlockNode(next_sibling); | 214 next_sibling_ = new NGBlockNode(next_sibling); |
| 210 } | 215 } |
| 211 } | 216 } |
| 212 } | 217 } |
| 213 return next_sibling_; | 218 return next_sibling_; |
| 214 } | 219 } |
| 215 | 220 |
| 216 LayoutObject* NGBlockNode::GetLayoutObject() { | 221 LayoutObject* NGBlockNode::GetLayoutObject() { |
| 217 return layout_box_; | 222 return layout_box_; |
| 218 } | 223 } |
| 219 | 224 |
| 225 static bool ShouldHandleByInlineContext(LayoutObject* child) { |
| 226 DCHECK(child); |
| 227 // The spec isn't clear about whether floats/OOF should be in inline |
| 228 // formatting context or in block formatting context. |
| 229 // Prefer inline formatting context because 1) floats/OOF at the beginning |
| 230 // and in the middle of inline should be handled in the same code, and 2) |
| 231 // it matches to the LayoutObject tree. |
| 232 for (; child; child = child->NextSibling()) { |
| 233 if (child->IsInline()) |
| 234 return true; |
| 235 if (child->IsFloating() || child->IsOutOfFlowPositioned()) |
| 236 continue; |
| 237 return false; |
| 238 } |
| 239 // All children are either float or OOF. |
| 240 // TODO(kojii): Should this be handled in block context or inline context? |
| 241 // If we handle in inline, we can remove all code for floats/OOF from block |
| 242 // layout, but it may change semantics and causes incorrectness? |
| 243 return false; |
| 244 } |
| 245 |
| 220 NGLayoutInputNode* NGBlockNode::FirstChild() { | 246 NGLayoutInputNode* NGBlockNode::FirstChild() { |
| 221 if (!first_child_) { | 247 if (!first_child_) { |
| 222 LayoutObject* child = layout_box_->SlowFirstChild(); | 248 LayoutObject* child = layout_box_->SlowFirstChild(); |
| 223 if (child) { | 249 if (child) { |
| 224 if (child->IsInline()) { | 250 if (ShouldHandleByInlineContext(child)) { |
| 225 first_child_ = new NGInlineNode(child, ToLayoutBlockFlow(layout_box_)); | 251 first_child_ = new NGInlineNode(child, ToLayoutBlockFlow(layout_box_)); |
| 226 } else { | 252 } else { |
| 227 first_child_ = new NGBlockNode(child); | 253 first_child_ = new NGBlockNode(child); |
| 228 } | 254 } |
| 229 } | 255 } |
| 230 } | 256 } |
| 231 return first_child_; | 257 return first_child_; |
| 232 } | 258 } |
| 233 | 259 |
| 234 DEFINE_TRACE(NGBlockNode) { | 260 DEFINE_TRACE(NGBlockNode) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 387 |
| 362 // Save static position for legacy AbsPos layout. | 388 // Save static position for legacy AbsPos layout. |
| 363 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { | 389 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { |
| 364 DCHECK(layout_box_->IsOutOfFlowPositioned()); | 390 DCHECK(layout_box_->IsOutOfFlowPositioned()); |
| 365 DCHECK(layout_box_->Layer()); | 391 DCHECK(layout_box_->Layer()); |
| 366 layout_box_->Layer()->SetStaticBlockPosition(offset.block_offset); | 392 layout_box_->Layer()->SetStaticBlockPosition(offset.block_offset); |
| 367 layout_box_->Layer()->SetStaticInlinePosition(offset.inline_offset); | 393 layout_box_->Layer()->SetStaticInlinePosition(offset.inline_offset); |
| 368 } | 394 } |
| 369 | 395 |
| 370 } // namespace blink | 396 } // namespace blink |
| OLD | NEW |