| 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 #ifndef NGBox_h | 5 #ifndef NGBox_h |
| 6 #define NGBox_h | 6 #define NGBox_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class ComputedStyle; | 13 class ComputedStyle; |
| 14 class LayoutBox; | 14 class LayoutBox; |
| 15 class LayoutObject; | 15 class LayoutObject; |
| 16 class NGBlockLayoutAlgorithm; | |
| 17 class NGConstraintSpace; | 16 class NGConstraintSpace; |
| 18 class NGFragment; | 17 class NGFragment; |
| 18 class NGLayoutAlgorithm; |
| 19 class NGPhysicalFragment; | 19 class NGPhysicalFragment; |
| 20 struct MinAndMaxContentSizes; |
| 20 | 21 |
| 21 // Represents a node to be laid out. | 22 // Represents a node to be laid out. |
| 22 class CORE_EXPORT NGBox final : public GarbageCollectedFinalized<NGBox> { | 23 class CORE_EXPORT NGBox final : public GarbageCollectedFinalized<NGBox> { |
| 23 public: | 24 public: |
| 24 explicit NGBox(LayoutObject*); | 25 explicit NGBox(LayoutObject*); |
| 25 | 26 |
| 26 // TODO(layout-ng): make it private and declare a friend class to use in tests | 27 // TODO(layout-ng): make it private and declare a friend class to use in tests |
| 27 explicit NGBox(ComputedStyle*); | 28 explicit NGBox(ComputedStyle*); |
| 28 | 29 |
| 29 // Returns true when done; when this function returns false, it has to be | 30 // Returns true when done; when this function returns false, it has to be |
| 30 // called again. The out parameter will only be set when this function | 31 // called again. The out parameter will only be set when this function |
| 31 // returns true. The same constraint space has to be passed each time. | 32 // returns true. The same constraint space has to be passed each time. |
| 32 // TODO(layout-ng): Should we have a StartLayout function to avoid passing | 33 // TODO(layout-ng): Should we have a StartLayout function to avoid passing |
| 33 // the same space for each Layout iteration? | 34 // the same space for each Layout iteration? |
| 34 bool Layout(const NGConstraintSpace*, NGFragment**); | 35 bool Layout(const NGConstraintSpace*, NGFragment**); |
| 36 |
| 37 // Computes the value of min-content and max-content for this box. |
| 38 // The return value has the same meaning as for Layout. |
| 39 // If the underlying layout algorithm returns NotImplemented from |
| 40 // ComputeMinAndMaxContentSizes, this function will synthesize these sizes |
| 41 // using Layout with special constraint spaces. |
| 42 // It is not legal to interleave a pending Layout() with a pending |
| 43 // ComputeOrSynthesizeMinAndMaxContentSizes (i.e. you have to call Layout |
| 44 // often enough that it returns true before calling |
| 45 // ComputeOrSynthesizeMinAndMaxContentSizes) |
| 46 bool ComputeMinAndMaxContentSizes(MinAndMaxContentSizes*); |
| 47 |
| 35 const ComputedStyle* Style() const; | 48 const ComputedStyle* Style() const; |
| 36 | 49 |
| 37 NGBox* NextSibling(); | 50 NGBox* NextSibling(); |
| 38 | 51 |
| 39 NGBox* FirstChild(); | 52 NGBox* FirstChild(); |
| 40 | 53 |
| 41 void SetNextSibling(NGBox*); | 54 void SetNextSibling(NGBox*); |
| 42 void SetFirstChild(NGBox*); | 55 void SetFirstChild(NGBox*); |
| 43 | 56 |
| 44 DEFINE_INLINE_VIRTUAL_TRACE() { | 57 DECLARE_VIRTUAL_TRACE(); |
| 45 visitor->trace(algorithm_); | |
| 46 visitor->trace(fragment_); | |
| 47 visitor->trace(next_sibling_); | |
| 48 visitor->trace(first_child_); | |
| 49 } | |
| 50 | 58 |
| 51 private: | 59 private: |
| 52 // This is necessary for interop between old and new trees -- after our parent | 60 // This is necessary for interop between old and new trees -- after our parent |
| 53 // positions us, it calls this function so we can store the position on the | 61 // positions us, it calls this function so we can store the position on the |
| 54 // underlying LayoutBox. | 62 // underlying LayoutBox. |
| 55 void PositionUpdated(); | 63 void PositionUpdated(); |
| 56 | 64 |
| 57 bool CanUseNewLayout(); | 65 bool CanUseNewLayout(); |
| 58 | 66 |
| 59 // After we run the layout algorithm, this function copies back the geometry | 67 // After we run the layout algorithm, this function copies back the geometry |
| 60 // data to the layout box. | 68 // data to the layout box. |
| 61 void CopyFragmentDataToLayoutBox(const NGConstraintSpace&); | 69 void CopyFragmentDataToLayoutBox(const NGConstraintSpace&); |
| 62 | 70 |
| 63 // Runs layout on layout_box_ and creates a fragment for the resulting | 71 // Runs layout on layout_box_ and creates a fragment for the resulting |
| 64 // geometry. | 72 // geometry. |
| 65 NGPhysicalFragment* RunOldLayout(const NGConstraintSpace&); | 73 NGPhysicalFragment* RunOldLayout(const NGConstraintSpace&); |
| 66 | 74 |
| 67 // We can either wrap a layout_box_ or a style_/next_sibling_/first_child_ | 75 // We can either wrap a layout_box_ or a style_/next_sibling_/first_child_ |
| 68 // combination. | 76 // combination. |
| 69 LayoutBox* layout_box_; | 77 LayoutBox* layout_box_; |
| 70 RefPtr<ComputedStyle> style_; | 78 RefPtr<ComputedStyle> style_; |
| 71 Member<NGBox> next_sibling_; | 79 Member<NGBox> next_sibling_; |
| 72 Member<NGBox> first_child_; | 80 Member<NGBox> first_child_; |
| 73 Member<NGBlockLayoutAlgorithm> algorithm_; | 81 Member<NGLayoutAlgorithm> layout_algorithm_; |
| 82 Member<NGLayoutAlgorithm> minmax_algorithm_; |
| 74 Member<NGPhysicalFragment> fragment_; | 83 Member<NGPhysicalFragment> fragment_; |
| 75 }; | 84 }; |
| 76 | 85 |
| 77 } // namespace blink | 86 } // namespace blink |
| 78 | 87 |
| 79 #endif // NGBox_h | 88 #endif // NGBox_h |
| OLD | NEW |