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

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

Issue 2282213002: [LayoutNG] Introduce NGPhysicalFragment and make NGFragment a 'view' (Closed)
Patch Set: address comments. 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 unified diff | Download patch
OLDNEW
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/LayoutObject.h" 7 #include "core/layout/LayoutObject.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_fragment.h" 12 #include "core/layout/ng/ng_fragment.h"
12 #include "core/layout/ng/ng_fragment_builder.h" 13 #include "core/layout/ng/ng_fragment_builder.h"
13 #include "core/layout/ng/ng_writing_mode.h" 14 #include "core/layout/ng/ng_writing_mode.h"
14 #include "core/layout/LayoutBlockFlow.h" 15 #include "core/layout/LayoutBlockFlow.h"
15 #include "core/layout/LayoutBox.h" 16 #include "core/layout/LayoutBox.h"
16 17
17 namespace blink { 18 namespace blink {
18 NGBox::NGBox(LayoutObject* layout_object) 19 NGBox::NGBox(LayoutObject* layout_object)
19 : layout_box_(toLayoutBox(layout_object)) { 20 : layout_box_(toLayoutBox(layout_object)) {
20 DCHECK(layout_box_); 21 DCHECK(layout_box_);
21 } 22 }
22 23
23 bool NGBox::Layout(const NGConstraintSpace* constraint_space, 24 bool NGBox::Layout(const NGConstraintSpace* constraint_space,
24 NGFragment** out) { 25 NGFragment** out) {
25 // We can either use the new layout code to do the layout and then copy the 26 // We can either use the new layout code to do the layout and then copy the
26 // resulting size to the LayoutObject, or use the old layout code and 27 // resulting size to the LayoutObject, or use the old layout code and
27 // synthesize a fragment. 28 // synthesize a fragment.
28 NGFragment* fragment = nullptr;
29 if (CanUseNewLayout()) { 29 if (CanUseNewLayout()) {
30 if (!algorithm_) 30 if (!algorithm_)
31 algorithm_ = new NGBlockLayoutAlgorithm(Style(), FirstChild()); 31 algorithm_ = new NGBlockLayoutAlgorithm(Style(), FirstChild());
32 // Change the coordinate system of the constraint space. 32 // Change the coordinate system of the constraint space.
33 NGConstraintSpace* child_constraint_space = new NGConstraintSpace( 33 NGConstraintSpace* child_constraint_space = new NGConstraintSpace(
34 FromPlatformWritingMode(Style()->getWritingMode()), constraint_space); 34 FromPlatformWritingMode(Style()->getWritingMode()), constraint_space);
35 35
36 NGPhysicalFragment* fragment = nullptr;
36 if (!algorithm_->Layout(child_constraint_space, &fragment)) 37 if (!algorithm_->Layout(child_constraint_space, &fragment))
37 return false; 38 return false;
38 layout_box_->setLogicalWidth(fragment->InlineSize()); 39 fragment_ = fragment;
39 layout_box_->setLogicalHeight(fragment->BlockSize()); 40
41 layout_box_->setWidth(fragment_->Width());
42 layout_box_->setHeight(fragment_->Height());
43
44 // Ensure the position of the children are copied across to the
45 // LayoutObject tree.
46 for (NGBox* box = FirstChild(); box; box = box->NextSibling()) {
47 if (box->fragment_)
48 box->PositionUpdated();
49 }
50
40 if (layout_box_->isLayoutBlock()) 51 if (layout_box_->isLayoutBlock())
41 toLayoutBlock(layout_box_)->layoutPositionedObjects(true); 52 toLayoutBlock(layout_box_)->layoutPositionedObjects(true);
42 layout_box_->clearNeedsLayout(); 53 layout_box_->clearNeedsLayout();
43 } else { 54 } else {
44 // TODO(layout-ng): If fixedSize is true, set the override width/height too 55 // TODO(layout-ng): If fixedSize is true, set the override width/height too
45 NGLogicalSize container_size = constraint_space->ContainerSize(); 56 NGLogicalSize container_size = constraint_space->ContainerSize();
46 layout_box_->setOverrideContainingBlockContentLogicalWidth( 57 layout_box_->setOverrideContainingBlockContentLogicalWidth(
47 container_size.inline_size); 58 container_size.inline_size);
48 layout_box_->setOverrideContainingBlockContentLogicalHeight( 59 layout_box_->setOverrideContainingBlockContentLogicalHeight(
49 container_size.block_size); 60 container_size.block_size);
50 if (layout_box_->isLayoutNGBlockFlow() && layout_box_->needsLayout()) { 61 if (layout_box_->isLayoutNGBlockFlow() && layout_box_->needsLayout()) {
51 toLayoutNGBlockFlow(layout_box_)->LayoutBlockFlow::layoutBlock(true); 62 toLayoutNGBlockFlow(layout_box_)->LayoutBlockFlow::layoutBlock(true);
52 } else { 63 } else {
53 layout_box_->layoutIfNeeded(); 64 layout_box_->layoutIfNeeded();
54 } 65 }
55 LayoutRect overflow = layout_box_->layoutOverflowRect(); 66 LayoutRect overflow = layout_box_->layoutOverflowRect();
56 // TODO(layout-ng): This does not handle writing modes correctly (for 67 // TODO(layout-ng): This does not handle writing modes correctly (for
57 // overflow & the enums) 68 // overflow & the enums)
58 NGFragmentBuilder builder(NGFragmentBase::FragmentBox); 69 NGFragmentBuilder builder(NGPhysicalFragmentBase::FragmentBox);
59 builder.SetInlineSize(layout_box_->logicalWidth()) 70 builder.SetInlineSize(layout_box_->logicalWidth())
60 .SetBlockSize(layout_box_->logicalHeight()) 71 .SetBlockSize(layout_box_->logicalHeight())
61 .SetInlineOverflow(overflow.width()) 72 .SetInlineOverflow(overflow.width())
62 .SetBlockOverflow(overflow.height()); 73 .SetBlockOverflow(overflow.height());
63 fragment = builder.ToFragment(); 74 fragment_ = builder.ToFragment();
64 } 75 }
65 *out = fragment; 76 *out = new NGFragment(constraint_space->WritingMode(),
77 FromPlatformDirection(Style()->direction()),
78 fragment_.get());
66 // Reset algorithm for future use 79 // Reset algorithm for future use
67 algorithm_ = nullptr; 80 algorithm_ = nullptr;
68 return true; 81 return true;
69 } 82 }
70 83
71 const ComputedStyle* NGBox::Style() const { 84 const ComputedStyle* NGBox::Style() const {
72 return layout_box_->style(); 85 return layout_box_->style();
73 } 86 }
74 87
75 NGBox* NGBox::NextSibling() const { 88 NGBox* NGBox::NextSibling() const {
76 LayoutObject* next_sibling = layout_box_->nextSibling(); 89 LayoutObject* next_sibling = layout_box_->nextSibling();
77 return next_sibling ? new NGBox(next_sibling) : nullptr; 90 return next_sibling ? new NGBox(next_sibling) : nullptr;
78 } 91 }
79 92
80 NGBox* NGBox::FirstChild() const { 93 NGBox* NGBox::FirstChild() const {
81 LayoutObject* child = layout_box_->slowFirstChild(); 94 LayoutObject* child = layout_box_->slowFirstChild();
82 return child ? new NGBox(child) : nullptr; 95 return child ? new NGBox(child) : nullptr;
83 } 96 }
84 97
85 void NGBox::PositionUpdated(const NGFragment& fragment) { 98 void NGBox::PositionUpdated() {
86 layout_box_->setLogicalLeft(fragment.InlineOffset()); 99 DCHECK(fragment_);
87 layout_box_->setLogicalTop(fragment.BlockOffset()); 100 layout_box_->setX(fragment_->LeftOffset());
101 layout_box_->setY(fragment_->TopOffset());
88 } 102 }
89 103
90 bool NGBox::CanUseNewLayout() { 104 bool NGBox::CanUseNewLayout() {
91 if (!layout_box_) 105 if (!layout_box_)
92 return true; 106 return true;
93 if (layout_box_->isLayoutBlockFlow() && !layout_box_->childrenInline()) 107 if (layout_box_->isLayoutBlockFlow() && !layout_box_->childrenInline())
94 return true; 108 return true;
95 return false; 109 return false;
96 } 110 }
97 } // namespace blink 111 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_box.h ('k') | third_party/WebKit/Source/core/layout/ng/ng_constraint_space.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698