| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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_layout_input_node.h" | 5 #include "core/layout/ng/ng_layout_input_node.h" |
| 6 |
| 6 #include "core/layout/ng/inline/ng_inline_node.h" | 7 #include "core/layout/ng/inline/ng_inline_node.h" |
| 8 #include "core/layout/ng/layout_ng_block_flow.h" |
| 7 #include "core/layout/ng/ng_block_node.h" | 9 #include "core/layout/ng/ng_block_node.h" |
| 10 #include "core/layout/ng/ng_layout_result.h" |
| 11 #include "core/layout/ng/ng_min_max_content_size.h" |
| 8 #include "platform/wtf/text/StringBuilder.h" | 12 #include "platform/wtf/text/StringBuilder.h" |
| 9 | 13 |
| 10 namespace blink { | 14 namespace blink { |
| 11 namespace { | 15 namespace { |
| 12 | 16 |
| 13 #ifndef NDEBUG | 17 #ifndef NDEBUG |
| 14 void AppendNodeToString(const NGLayoutInputNode* node, | 18 void AppendNodeToString(NGLayoutInputNode node, |
| 15 StringBuilder* string_builder, | 19 StringBuilder* string_builder, |
| 16 unsigned indent = 2) { | 20 unsigned indent = 2) { |
| 17 if (!node) | 21 if (!node) |
| 18 return; | 22 return; |
| 19 DCHECK(string_builder); | 23 DCHECK(string_builder); |
| 20 | 24 |
| 21 string_builder->Append(node->ToString()); | 25 string_builder->Append(node.ToString()); |
| 22 string_builder->Append("\n"); | 26 string_builder->Append("\n"); |
| 23 | 27 |
| 24 StringBuilder indent_builder; | 28 StringBuilder indent_builder; |
| 25 for (unsigned i = 0; i < indent; i++) | 29 for (unsigned i = 0; i < indent; i++) |
| 26 indent_builder.Append(" "); | 30 indent_builder.Append(" "); |
| 27 | 31 |
| 28 if (node->IsBlock()) { | 32 if (node.IsBlock()) { |
| 29 auto* first_child = | 33 NGLayoutInputNode first_child = ToNGBlockNode(node).FirstChild(); |
| 30 ToNGBlockNode(const_cast<NGLayoutInputNode*>(node))->FirstChild(); | 34 for (NGLayoutInputNode node_runner = first_child; node_runner; |
| 31 for (NGLayoutInputNode* node_runner = first_child; node_runner; | 35 node_runner = node_runner.NextSibling()) { |
| 32 node_runner = node_runner->NextSibling()) { | |
| 33 string_builder->Append(indent_builder.ToString()); | 36 string_builder->Append(indent_builder.ToString()); |
| 34 AppendNodeToString(node_runner, string_builder, indent + 2); | 37 AppendNodeToString(node_runner, string_builder, indent + 2); |
| 35 } | 38 } |
| 36 } | 39 } |
| 37 | 40 |
| 38 if (node->IsInline()) { | 41 if (node.IsInline()) { |
| 39 for (const NGInlineItem& inline_item : ToNGInlineNode(node)->Items()) { | 42 for (const NGInlineItem& inline_item : ToNGInlineNode(node).Items()) { |
| 40 string_builder->Append(indent_builder.ToString()); | 43 string_builder->Append(indent_builder.ToString()); |
| 41 string_builder->Append(inline_item.ToString()); | 44 string_builder->Append(inline_item.ToString()); |
| 42 string_builder->Append("\n"); | 45 string_builder->Append("\n"); |
| 43 } | 46 } |
| 44 auto* next_sibling = | 47 NGLayoutInputNode next_sibling = ToNGInlineNode(node).NextSibling(); |
| 45 ToNGInlineNode(const_cast<NGLayoutInputNode*>(node))->NextSibling(); | 48 for (NGLayoutInputNode node_runner = next_sibling; node_runner; |
| 46 for (NGLayoutInputNode* node_runner = next_sibling; node_runner; | 49 node_runner = node_runner.NextSibling()) { |
| 47 node_runner = node_runner->NextSibling()) { | |
| 48 string_builder->Append(indent_builder.ToString()); | 50 string_builder->Append(indent_builder.ToString()); |
| 49 AppendNodeToString(node_runner, string_builder, indent + 2); | 51 AppendNodeToString(node_runner, string_builder, indent + 2); |
| 50 } | 52 } |
| 51 } | 53 } |
| 52 } | 54 } |
| 53 #endif | 55 #endif |
| 54 | 56 |
| 55 } // namespace | 57 } // namespace |
| 56 | 58 |
| 59 bool NGLayoutInputNode::IsInline() const { |
| 60 return box_->LayoutNGInline(); |
| 61 } |
| 62 |
| 63 bool NGLayoutInputNode::IsBlock() const { |
| 64 return !IsInline(); |
| 65 } |
| 66 |
| 67 bool NGLayoutInputNode::IsFloating() const { |
| 68 return IsBlock() && Style().IsFloating(); |
| 69 } |
| 70 |
| 71 bool NGLayoutInputNode::IsOutOfFlowPositioned() const { |
| 72 return IsBlock() && Style().HasOutOfFlowPosition(); |
| 73 } |
| 74 |
| 75 RefPtr<NGLayoutResult> NGLayoutInputNode::Layout(NGConstraintSpace* space, |
| 76 NGBreakToken* break_token) { |
| 77 return IsInline() ? ToNGInlineNode(*this).Layout(space, break_token) |
| 78 : ToNGBlockNode(*this).Layout(space, break_token); |
| 79 } |
| 80 |
| 81 MinMaxContentSize NGLayoutInputNode::ComputeMinMaxContentSize() { |
| 82 return IsInline() ? ToNGInlineNode(*this).ComputeMinMaxContentSize() |
| 83 : ToNGBlockNode(*this).ComputeMinMaxContentSize(); |
| 84 } |
| 85 |
| 86 NGLayoutInputNode NGLayoutInputNode::NextSibling() { |
| 87 return IsInline() ? ToNGInlineNode(*this).NextSibling() |
| 88 : ToNGBlockNode(*this).NextSibling(); |
| 89 } |
| 90 |
| 91 LayoutObject* NGLayoutInputNode::GetLayoutObject() const { |
| 92 return box_; |
| 93 } |
| 94 |
| 95 const ComputedStyle& NGLayoutInputNode::Style() const { |
| 96 return box_->StyleRef(); |
| 97 } |
| 98 |
| 99 String NGLayoutInputNode::ToString() const { |
| 100 return IsInline() ? ToNGInlineNode(*this).ToString() |
| 101 : ToNGBlockNode(*this).ToString(); |
| 102 } |
| 103 |
| 57 #ifndef NDEBUG | 104 #ifndef NDEBUG |
| 58 void NGLayoutInputNode::ShowNodeTree() const { | 105 void NGLayoutInputNode::ShowNodeTree() const { |
| 59 StringBuilder string_builder; | 106 StringBuilder string_builder; |
| 60 string_builder.Append("\n.:: LayoutNG Node Tree ::.\n\n"); | 107 string_builder.Append("\n.:: LayoutNG Node Tree ::.\n\n"); |
| 61 AppendNodeToString(this, &string_builder); | 108 AppendNodeToString(*this, &string_builder); |
| 62 fprintf(stderr, "%s\n", string_builder.ToString().Utf8().data()); | 109 fprintf(stderr, "%s\n", string_builder.ToString().Utf8().data()); |
| 63 } | 110 } |
| 64 #endif | 111 #endif |
| 65 | 112 |
| 66 } // namespace blink | 113 } // namespace blink |
| OLD | NEW |