Chromium Code Reviews| 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_box.h" | 5 #include "core/layout/ng/ng_box.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutBlockFlow.h" | 7 #include "core/layout/LayoutBlockFlow.h" |
| 8 #include "core/layout/ng/layout_ng_block_flow.h" | 8 #include "core/layout/ng/layout_ng_block_flow.h" |
| 9 #include "core/layout/ng/ng_block_layout_algorithm.h" | 9 #include "core/layout/ng/ng_block_layout_algorithm.h" |
| 10 #include "core/layout/ng/ng_constraint_space.h" | 10 #include "core/layout/ng/ng_constraint_space.h" |
| 11 #include "core/layout/ng/ng_direction.h" | 11 #include "core/layout/ng/ng_direction.h" |
| 12 #include "core/layout/ng/ng_fragment.h" | 12 #include "core/layout/ng/ng_fragment.h" |
| 13 #include "core/layout/ng/ng_fragment_builder.h" | 13 #include "core/layout/ng/ng_fragment_builder.h" |
| 14 #include "core/layout/ng/ng_length_utils.h" | 14 #include "core/layout/ng/ng_length_utils.h" |
| 15 #include "core/layout/ng/ng_writing_mode.h" | 15 #include "core/layout/ng/ng_writing_mode.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 NGBox::NGBox(LayoutObject* layout_object) | 18 NGBox::NGBox(LayoutObject* layout_object) |
| 19 : layout_box_(toLayoutBox(layout_object)) { | 19 : layout_box_(toLayoutBox(layout_object)) { |
| 20 DCHECK(layout_box_); | 20 DCHECK(layout_box_); |
| 21 } | 21 } |
| 22 | 22 |
| 23 NGBox::NGBox(ComputedStyle* style) : layout_box_(nullptr), style_(style) { | 23 NGBox::NGBox(ComputedStyle* style) : layout_box_(nullptr), style_(style) { |
| 24 DCHECK(style_); | 24 DCHECK(style_); |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool NGBox::Layout(const NGConstraintSpace* constraint_space, | 27 bool NGBox::Layout(const NGConstraintSpace* constraint_space) { |
| 28 NGFragment** out) { | |
| 29 if (layout_box_ && layout_box_->isOutOfFlowPositioned()) | 28 if (layout_box_ && layout_box_->isOutOfFlowPositioned()) |
| 30 layout_box_->containingBlock()->insertPositionedObject(layout_box_); | 29 layout_box_->containingBlock()->insertPositionedObject(layout_box_); |
| 30 | |
| 31 NGPhysicalFragment* physical_fragment = nullptr; | |
| 31 // We can either use the new layout code to do the layout and then copy the | 32 // We can either use the new layout code to do the layout and then copy the |
| 32 // resulting size to the LayoutObject, or use the old layout code and | 33 // resulting size to the LayoutObject, or use the old layout code and |
| 33 // synthesize a fragment. | 34 // synthesize a fragment. |
| 34 if (CanUseNewLayout()) { | 35 if (CanUseNewLayout()) { |
| 35 if (!algorithm_) | 36 if (!algorithm_) |
| 36 algorithm_ = new NGBlockLayoutAlgorithm(Style(), FirstChild()); | 37 algorithm_ = new NGBlockLayoutAlgorithm(Style(), FirstChild()); |
| 37 // Change the coordinate system of the constraint space. | 38 // Change the coordinate system of the constraint space. |
| 38 NGConstraintSpace* child_constraint_space = new NGConstraintSpace( | 39 NGConstraintSpace child_constraint_space( |
| 39 FromPlatformWritingMode(Style()->getWritingMode()), | 40 FromPlatformWritingMode(Style()->getWritingMode()), |
| 40 FromPlatformDirection(Style()->direction()), constraint_space); | 41 FromPlatformDirection(Style()->direction()), constraint_space); |
| 41 | 42 |
| 42 NGPhysicalFragment* fragment = nullptr; | 43 if (!algorithm_->Layout(child_constraint_space, &physical_fragment)) |
| 43 if (!algorithm_->Layout(child_constraint_space, &fragment)) | |
| 44 return false; | 44 return false; |
| 45 fragment_ = fragment; | |
| 46 | 45 |
| 47 if (layout_box_) { | 46 if (layout_box_) { |
| 48 layout_box_->setWidth(fragment_->Width()); | 47 layout_box_->setWidth(physical_fragment->Width()); |
| 49 layout_box_->setHeight(fragment_->Height()); | 48 layout_box_->setHeight(physical_fragment->Height()); |
| 50 NGBoxStrut border_and_padding = | 49 NGBoxStrut border_and_padding = |
| 51 computeBorders(*Style()) + | 50 computeBorders(*Style()) + |
| 52 computePadding(*constraint_space, *Style()); | 51 computePadding(*constraint_space, *Style()); |
| 53 LayoutUnit intrinsic_logical_height = | 52 LayoutUnit intrinsic_logical_height = |
| 54 layout_box_->style()->isHorizontalWritingMode() | 53 layout_box_->style()->isHorizontalWritingMode() |
| 55 ? fragment_->HeightOverflow() | 54 ? physical_fragment->HeightOverflow() |
| 56 : fragment_->WidthOverflow(); | 55 : physical_fragment->WidthOverflow(); |
| 57 intrinsic_logical_height -= border_and_padding.BlockSum(); | 56 intrinsic_logical_height -= border_and_padding.BlockSum(); |
| 58 layout_box_->setIntrinsicContentLogicalHeight(intrinsic_logical_height); | 57 layout_box_->setIntrinsicContentLogicalHeight(intrinsic_logical_height); |
| 59 | 58 |
| 60 // Ensure the position of the children are copied across to the | 59 // Ensure the position of the children are copied across to the |
| 61 // LayoutObject tree. | 60 // LayoutObject tree. |
| 62 for (NGBox* box = FirstChild(); box; box = box->NextSibling()) { | 61 for (NGBox* box = FirstChild(); box; box = box->NextSibling()) { |
| 63 if (box->fragment_) | 62 if (box->Fragment()) |
| 64 box->PositionUpdated(); | 63 box->PositionUpdated(); |
| 65 } | 64 } |
| 66 | 65 |
| 67 if (layout_box_->isLayoutBlock()) | 66 if (layout_box_->isLayoutBlock()) |
| 68 toLayoutBlock(layout_box_)->layoutPositionedObjects(true); | 67 toLayoutBlock(layout_box_)->layoutPositionedObjects(true); |
| 69 layout_box_->clearNeedsLayout(); | 68 layout_box_->clearNeedsLayout(); |
| 70 if (layout_box_->isLayoutBlockFlow()) { | 69 if (layout_box_->isLayoutBlockFlow()) { |
| 71 toLayoutBlockFlow(layout_box_)->updateIsSelfCollapsing(); | 70 toLayoutBlockFlow(layout_box_)->updateIsSelfCollapsing(); |
| 72 } | 71 } |
| 73 } | 72 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 89 // overflow) | 88 // overflow) |
| 90 NGFragmentBuilder builder(NGPhysicalFragmentBase::FragmentBox); | 89 NGFragmentBuilder builder(NGPhysicalFragmentBase::FragmentBox); |
| 91 builder.SetInlineSize(layout_box_->logicalWidth()) | 90 builder.SetInlineSize(layout_box_->logicalWidth()) |
| 92 .SetBlockSize(layout_box_->logicalHeight()) | 91 .SetBlockSize(layout_box_->logicalHeight()) |
| 93 .SetDirection( | 92 .SetDirection( |
| 94 FromPlatformDirection(layout_box_->styleRef().direction())) | 93 FromPlatformDirection(layout_box_->styleRef().direction())) |
| 95 .SetWritingMode( | 94 .SetWritingMode( |
| 96 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode())) | 95 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode())) |
| 97 .SetInlineOverflow(overflow.width()) | 96 .SetInlineOverflow(overflow.width()) |
| 98 .SetBlockOverflow(overflow.height()); | 97 .SetBlockOverflow(overflow.height()); |
| 99 fragment_ = builder.ToFragment(); | 98 physical_fragment = builder.ToFragment(); |
| 100 } | 99 } |
| 101 *out = new NGFragment(constraint_space->WritingMode(), | 100 fragment_ = new NGFragment(constraint_space->WritingMode(), |
| 102 FromPlatformDirection(Style()->direction()), | 101 FromPlatformDirection(Style()->direction()), |
| 103 fragment_.get()); | 102 physical_fragment); |
| 104 // Reset algorithm for future use | 103 // Reset algorithm for future use |
| 105 algorithm_ = nullptr; | 104 algorithm_ = nullptr; |
| 106 return true; | 105 return true; |
| 107 } | 106 } |
| 108 | 107 |
| 109 const ComputedStyle* NGBox::Style() const { | 108 const ComputedStyle* NGBox::Style() const { |
| 110 if (style_) | 109 if (style_) |
| 111 return style_.get(); | 110 return style_.get(); |
| 112 DCHECK(layout_box_); | 111 DCHECK(layout_box_); |
| 113 return layout_box_->style(); | 112 return layout_box_->style(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 134 | 133 |
| 135 void NGBox::SetNextSibling(NGBox* sibling) { | 134 void NGBox::SetNextSibling(NGBox* sibling) { |
| 136 next_sibling_ = sibling; | 135 next_sibling_ = sibling; |
| 137 } | 136 } |
| 138 | 137 |
| 139 void NGBox::SetFirstChild(NGBox* child) { | 138 void NGBox::SetFirstChild(NGBox* child) { |
| 140 first_child_ = child; | 139 first_child_ = child; |
| 141 } | 140 } |
| 142 | 141 |
| 143 void NGBox::PositionUpdated() { | 142 void NGBox::PositionUpdated() { |
| 144 if (layout_box_) { | 143 if (layout_box_ && fragment_->PhysicalFragment()) { |
|
cbiesinger
2016/09/26 17:17:55
Can PhysicalFragment() ever be null?
| |
| 145 layout_box_->setX(fragment_->LeftOffset()); | 144 layout_box_->setX(fragment_->PhysicalFragment()->LeftOffset()); |
| 146 layout_box_->setY(fragment_->TopOffset()); | 145 layout_box_->setY(fragment_->PhysicalFragment()->TopOffset()); |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 | 148 |
| 150 bool NGBox::CanUseNewLayout() { | 149 bool NGBox::CanUseNewLayout() { |
| 151 if (!layout_box_) | 150 if (!layout_box_) |
| 152 return true; | 151 return true; |
| 153 if (!layout_box_->isLayoutBlockFlow()) | 152 if (!layout_box_->isLayoutBlockFlow()) |
| 154 return false; | 153 return false; |
| 155 const LayoutBlockFlow* block_flow = toLayoutBlockFlow(layout_box_); | 154 const LayoutBlockFlow* block_flow = toLayoutBlockFlow(layout_box_); |
| 156 return !block_flow->childrenInline() || !block_flow->firstChild(); | 155 return !block_flow->childrenInline() || !block_flow->firstChild(); |
| 157 } | 156 } |
| 158 } // namespace blink | 157 } // namespace blink |
| OLD | NEW |