[go: up one dir, main page]

Move break_token_ to NGPhysicalContainerFragment from NGPhysicalFragment

This patch moves |NGPhysicalFragment::break_token_| member to
|NGPhysicalContainerFragment| to reduce size of |NGPhysicalTextFragment| since
|NGPhysicalTextFragment| never has break token.

TBR=yosin@chromium.org

Bug: 962108
Change-Id: I9f86c413c01932dfaed5d55933b490deaddbde1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1662095
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/branch-heads/3809@{#336}
Cr-Branched-From: d82dec1a818f378c464ba307ddd9c92133eac355-refs/heads/master@{#665002}
diff --git a/third_party/blink/renderer/core/layout/ng/inline/ng_abstract_inline_text_box.cc b/third_party/blink/renderer/core/layout/ng/inline/ng_abstract_inline_text_box.cc
index f0cb6b1..7fe1900 100644
--- a/third_party/blink/renderer/core/layout/ng/inline/ng_abstract_inline_text_box.cc
+++ b/third_party/blink/renderer/core/layout/ng/inline/ng_abstract_inline_text_box.cc
@@ -91,8 +91,8 @@
     return false;
   if (text_fragment.TextContent()[text_fragment.EndOffset()] != ' ')
     return false;
-  const NGInlineBreakToken& break_token =
-      *To<NGInlineBreakToken>(line_box.PhysicalFragment().BreakToken());
+  const NGInlineBreakToken& break_token = *To<NGInlineBreakToken>(
+      To<NGPhysicalLineBoxFragment>(line_box.PhysicalFragment()).BreakToken());
   // TODO(yosin): We should support OOF fragments between |fragment_| and
   // break token.
   if (break_token.TextOffset() != text_fragment.EndOffset() + 1)
diff --git a/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm.cc b/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm.cc
index 9b9feab..3a7bc24c 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm.cc
+++ b/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm.cc
@@ -1940,7 +1940,7 @@
   if (!container_builder_.BfcBlockOffset().has_value())
     return NoBreak;
 
-  const NGPhysicalFragment& physical_fragment =
+  const NGPhysicalContainerFragment& physical_fragment =
       layout_result.PhysicalFragment();
 
   // If we haven't used any space at all in the fragmentainer yet, we cannot
diff --git a/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc b/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc
index 63131ad1..4743312 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc
+++ b/third_party/blink/renderer/core/layout/ng/ng_block_layout_algorithm_test.cc
@@ -90,7 +90,7 @@
 
   NGBlockNode box(ToLayoutBox(GetLayoutObjectByElementId("box")));
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(box, space);
 
   EXPECT_EQ(PhysicalSize(30, 40), fragment->Size());
@@ -1772,7 +1772,7 @@
   NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace(
       WritingMode::kHorizontalTb, TextDirection::kLtr,
       LogicalSize(LayoutUnit(100), kIndefiniteSize), true);
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(container, space);
 
   EXPECT_EQ(LayoutUnit(kWidthChild2), fragment->Size().width);
@@ -1924,7 +1924,7 @@
       node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable);
 
   // We should only have one 150x200 fragment with no fragmentation.
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(150, 200), fragment->Size());
   ASSERT_TRUE(fragment->BreakToken()->IsFinished());
@@ -1951,7 +1951,7 @@
       LogicalSize(LayoutUnit(1000), kIndefiniteSize), false,
       node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable);
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(150, 200), fragment->Size());
   ASSERT_FALSE(fragment->BreakToken()->IsFinished());
@@ -1994,7 +1994,7 @@
       LogicalSize(LayoutUnit(1000), kIndefiniteSize), false,
       node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable);
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(150, 200), fragment->Size());
   ASSERT_FALSE(fragment->BreakToken()->IsFinished());
@@ -2059,7 +2059,7 @@
       LogicalSize(LayoutUnit(1000), kIndefiniteSize), false,
       node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable);
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(150, 200), fragment->Size());
   ASSERT_FALSE(fragment->BreakToken()->IsFinished());
@@ -2122,7 +2122,7 @@
       LogicalSize(LayoutUnit(1000), kIndefiniteSize), false,
       node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable);
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(150, 70), fragment->Size());
   ASSERT_FALSE(fragment->BreakToken()->IsFinished());
@@ -2188,7 +2188,7 @@
       LogicalSize(LayoutUnit(1000), kIndefiniteSize), false,
       node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable);
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(150, 50), fragment->Size());
   ASSERT_FALSE(fragment->BreakToken()->IsFinished());
@@ -2268,7 +2268,7 @@
 
   AdvanceToLayoutPhase();
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(150, 60), fragment->Size());
   ASSERT_TRUE(!fragment->BreakToken() || fragment->BreakToken()->IsFinished());
@@ -2280,7 +2280,9 @@
 
   // float2 should only have one fragment.
   EXPECT_EQ(PhysicalSize(60, 200), float2->Size());
-  ASSERT_TRUE(!float2->BreakToken() || float2->BreakToken()->IsFinished());
+  ASSERT_TRUE(float2->IsBox());
+  NGBreakToken* break_token = To<NGPhysicalBoxFragment>(float2)->BreakToken();
+  EXPECT_TRUE(!break_token || break_token->IsFinished());
 }
 
 // Tests that a float child inside a zero height block fragments correctly.
@@ -2316,7 +2318,7 @@
       LogicalSize(LayoutUnit(1000), kIndefiniteSize), false,
       node.CreatesNewFormattingContext(), kFragmentainerSpaceAvailable);
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(150, 50), fragment->Size());
   ASSERT_FALSE(fragment->BreakToken()->IsFinished());
@@ -2439,7 +2441,7 @@
       WritingMode::kHorizontalTb, TextDirection::kLtr,
       LogicalSize(LayoutUnit(1000), kIndefiniteSize));
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(200, 150), fragment->Size());
 
@@ -2475,7 +2477,7 @@
       WritingMode::kHorizontalTb, TextDirection::kLtr,
       LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, true);
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(200, 10), fragment->Size());
 
@@ -2513,7 +2515,7 @@
       WritingMode::kHorizontalTb, TextDirection::kLtr,
       LogicalSize(LayoutUnit(1000), kIndefiniteSize), false, true);
 
-  scoped_refptr<const NGPhysicalFragment> fragment =
+  scoped_refptr<const NGPhysicalBoxFragment> fragment =
       RunBlockLayoutAlgorithm(node, space);
   EXPECT_EQ(PhysicalSize(200, 10), fragment->Size());
 
diff --git a/third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.cc b/third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.cc
index cf3108c..21b54f6c 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.cc
+++ b/third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.cc
@@ -153,7 +153,7 @@
 }
 
 NGBoxFragmentBuilder& NGBoxFragmentBuilder::PropagateBreak(
-    const NGPhysicalFragment& child_fragment) {
+    const NGPhysicalContainerFragment& child_fragment) {
   DCHECK(has_block_fragmentation_);
   if (!did_break_) {
     const auto* token = child_fragment.BreakToken();
diff --git a/third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h b/third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h
index d491b25..29ffa670 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h
+++ b/third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h
@@ -97,7 +97,7 @@
 
   // Update if we have fragmented in this flow.
   NGBoxFragmentBuilder& PropagateBreak(const NGLayoutResult&);
-  NGBoxFragmentBuilder& PropagateBreak(const NGPhysicalFragment&);
+  NGBoxFragmentBuilder& PropagateBreak(const NGPhysicalContainerFragment&);
 
   void AddOutOfFlowLegacyCandidate(NGBlockNode,
                                    const NGStaticPosition&,
diff --git a/third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.cc b/third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.cc
index e61ae6a5..9c556e3 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.cc
+++ b/third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.cc
@@ -17,12 +17,13 @@
                                     const NGPhysicalFragment& fragment) {
   if (!fragment.IsBox())
     return LayoutUnit();
-  const auto* break_token = To<NGBlockBreakToken>(fragment.BreakToken());
+  const NGPhysicalBoxFragment& box_fragment =
+      To<NGPhysicalBoxFragment>(fragment);
+  const auto* break_token = To<NGBlockBreakToken>(box_fragment.BreakToken());
   if (!break_token)
     return LayoutUnit();
   NGBoxFragment logical_fragment(constraint_space.GetWritingMode(),
-                                 constraint_space.Direction(),
-                                 To<NGPhysicalBoxFragment>(fragment));
+                                 constraint_space.Direction(), box_fragment);
   return break_token->UsedBlockSize() - logical_fragment.BlockSize();
 }
 
diff --git a/third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.h b/third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.h
index bc14ebb..31ead90 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.h
+++ b/third_party/blink/renderer/core/layout/ng/ng_fragmentation_utils.h
@@ -7,7 +7,7 @@
 
 #include "third_party/blink/renderer/core/layout/ng/ng_block_break_token.h"
 #include "third_party/blink/renderer/core/layout/ng/ng_layout_input_node.h"
-#include "third_party/blink/renderer/core/layout/ng/ng_physical_fragment.h"
+#include "third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h"
 #include "third_party/blink/renderer/core/style/computed_style_constants.h"
 #include "third_party/blink/renderer/platform/geometry/layout_unit.h"
 
@@ -34,7 +34,10 @@
 
 // Return true if the specified fragment is the final fragment of some node.
 inline bool IsLastFragment(const NGPhysicalFragment& fragment) {
-  const auto* break_token = fragment.BreakToken();
+  if (!fragment.IsContainer())
+    return false;
+  const auto* break_token =
+      To<NGPhysicalContainerFragment>(fragment).BreakToken();
   return !break_token || break_token->IsFinished();
 }
 
diff --git a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.cc b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.cc
index 6ce7d4c..f46de53 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.cc
+++ b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.cc
@@ -17,7 +17,13 @@
 namespace {
 
 struct SameSizeAsNGPhysicalContainerFragment : NGPhysicalFragment {
+<<<<<<< HEAD   (d91d4f Allocate memory for borders and padding members of NGPhysica)
   Vector<NGOutOfFlowPositionedDescendant> oof_positioned_descendants_;
+=======
+  void* break_token;
+  std::unique_ptr<Vector<NGOutOfFlowPositionedDescendant>>
+      oof_positioned_descendants_;
+>>>>>>> CHANGE (3ad1c0 Move break_token_ to NGPhysicalContainerFragment from NGPhys)
   void* pointer;
   wtf_size_t size;
 };
@@ -35,6 +41,7 @@
     NGFragmentType type,
     unsigned sub_type)
     : NGPhysicalFragment(builder, type, sub_type),
+      break_token_(std::move(builder->break_token_)),
       oof_positioned_descendants_(
           std::move(builder->oof_positioned_descendants_)),
       buffer_(buffer),
diff --git a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
index d79c9f5..3d24e51 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
+++ b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
@@ -7,6 +7,7 @@
 
 #include "third_party/blink/renderer/core/core_export.h"
 #include "third_party/blink/renderer/core/layout/geometry/physical_rect.h"
+#include "third_party/blink/renderer/core/layout/ng/ng_break_token.h"
 #include "third_party/blink/renderer/core/layout/ng/ng_link.h"
 #include "third_party/blink/renderer/core/layout/ng/ng_physical_fragment.h"
 #include "third_party/blink/renderer/platform/wtf/casting.h"
@@ -99,6 +100,8 @@
 
   ~NGPhysicalContainerFragment();
 
+  NGBreakToken* BreakToken() const { return break_token_.get(); }
+
   // Returns the children of |this|.
   //
   // Note, children in this collection maybe old generations. Items in this
@@ -157,7 +160,13 @@
 
   static bool DependsOnPercentageBlockSize(const NGContainerFragmentBuilder&);
 
+<<<<<<< HEAD   (d91d4f Allocate memory for borders and padding members of NGPhysica)
   Vector<NGOutOfFlowPositionedDescendant> oof_positioned_descendants_;
+=======
+  scoped_refptr<NGBreakToken> break_token_;
+  const std::unique_ptr<Vector<NGOutOfFlowPositionedDescendant>>
+      oof_positioned_descendants_;
+>>>>>>> CHANGE (3ad1c0 Move break_token_ to NGPhysicalContainerFragment from NGPhys)
 
   // Because flexible arrays need to be the last member in a class, the actual
   // storage is in the subclass and we just keep a pointer to it here.
diff --git a/third_party/blink/renderer/core/layout/ng/ng_physical_fragment.cc b/third_party/blink/renderer/core/layout/ng/ng_physical_fragment.cc
index 38ae5af7..b81af6f 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_physical_fragment.cc
+++ b/third_party/blink/renderer/core/layout/ng/ng_physical_fragment.cc
@@ -12,7 +12,6 @@
 #include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h"
 #include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
 #include "third_party/blink/renderer/core/layout/ng/ng_block_node.h"
-#include "third_party/blink/renderer/core/layout/ng/ng_break_token.h"
 #include "third_party/blink/renderer/core/layout/ng/ng_fragment_builder.h"
 #include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
 #include "third_party/blink/renderer/core/style/computed_style.h"
@@ -24,7 +23,7 @@
 
 struct SameSizeAsNGPhysicalFragment
     : RefCounted<const NGPhysicalFragment, NGPhysicalFragmentTraits> {
-  void* pointers[2];
+  void* layout_object;
   PhysicalSize size;
   unsigned flags;
 };
@@ -221,7 +220,6 @@
                                        unsigned sub_type)
     : layout_object_(*builder->layout_object_),
       size_(ToPhysicalSize(builder->size_, builder->GetWritingMode())),
-      break_token_(std::move(builder->break_token_)),
       type_(type),
       sub_type_(sub_type),
       style_variant_((unsigned)builder->style_variant_),
@@ -235,11 +233,9 @@
                                        NGStyleVariant style_variant,
                                        PhysicalSize size,
                                        NGFragmentType type,
-                                       unsigned sub_type,
-                                       scoped_refptr<NGBreakToken> break_token)
+                                       unsigned sub_type)
     : layout_object_(*layout_object),
       size_(size),
-      break_token_(std::move(break_token)),
       type_(type),
       sub_type_(sub_type),
       style_variant_((unsigned)style_variant),
diff --git a/third_party/blink/renderer/core/layout/ng/ng_physical_fragment.h b/third_party/blink/renderer/core/layout/ng/ng_physical_fragment.h
index caa75ac..8ed0c068 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_physical_fragment.h
+++ b/third_party/blink/renderer/core/layout/ng/ng_physical_fragment.h
@@ -11,7 +11,7 @@
 #include "third_party/blink/renderer/core/layout/geometry/physical_offset.h"
 #include "third_party/blink/renderer/core/layout/geometry/physical_rect.h"
 #include "third_party/blink/renderer/core/layout/geometry/physical_size.h"
-#include "third_party/blink/renderer/core/layout/ng/ng_break_token.h"
+#include "third_party/blink/renderer/core/layout/layout_object.h"
 #include "third_party/blink/renderer/core/layout/ng/ng_style_variant.h"
 #include "third_party/blink/renderer/platform/graphics/touch_action.h"
 #include "third_party/blink/renderer/platform/wtf/ref_counted.h"
@@ -21,10 +21,8 @@
 namespace blink {
 
 class ComputedStyle;
-class LayoutObject;
 class Node;
 class NGFragmentBuilder;
-class NGBreakToken;
 class NGInlineItem;
 class PaintLayer;
 
@@ -156,7 +154,6 @@
   // (0, 0).
   PhysicalRect LocalRect() const { return {{}, size_}; }
 
-  NGBreakToken* BreakToken() const { return break_token_.get(); }
   NGStyleVariant StyleVariant() const {
     return static_cast<NGStyleVariant>(style_variant_);
   }
@@ -275,8 +272,7 @@
                      NGStyleVariant,
                      PhysicalSize size,
                      NGFragmentType type,
-                     unsigned sub_type,
-                     scoped_refptr<NGBreakToken> break_token = nullptr);
+                     unsigned sub_type);
 
   const ComputedStyle& SlowEffectiveStyle() const;
 
@@ -284,7 +280,6 @@
 
   LayoutObject& layout_object_;
   const PhysicalSize size_;
-  scoped_refptr<NGBreakToken> break_token_;
 
   const unsigned type_ : 2;      // NGFragmentType
   const unsigned sub_type_ : 3;  // NGBoxType, NGTextType, or NGLineBoxType
diff --git a/third_party/blink/renderer/core/paint/ng/ng_paint_fragment.cc b/third_party/blink/renderer/core/paint/ng/ng_paint_fragment.cc
index c40df1b..3a1c78f 100644
--- a/third_party/blink/renderer/core/paint/ng/ng_paint_fragment.cc
+++ b/third_party/blink/renderer/core/paint/ng/ng_paint_fragment.cc
@@ -358,7 +358,9 @@
       return fragment;
 
     scoped_refptr<NGPaintFragment>* next = &(*fragment)->next_fragmented_;
-    if ((*fragment)->PhysicalFragment().BreakToken() == break_token)
+    auto* container =
+        DynamicTo<NGPhysicalContainerFragment>((*fragment)->PhysicalFragment());
+    if (container && container->BreakToken() == break_token)
       return next;
     fragment = next;
   }