OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NGConstraintSpace_h |
| 6 #define NGConstraintSpace_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "platform/LayoutUnit.h" |
| 10 #include "wtf/DoublyLinkedList.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class NGDerivedConstraintSpace; |
| 15 class NGExclusion; |
| 16 class NGFragment; |
| 17 class NGLayoutOpportunityIterator; |
| 18 |
| 19 enum NGExclusionType { |
| 20 ClearNone = 0, |
| 21 ClearFloatLeft = 1, |
| 22 ClearFloatRight = 2, |
| 23 ClearFragment = 4 |
| 24 }; |
| 25 |
| 26 enum NGFragmentationType { |
| 27 FragmentNone, |
| 28 FragmentPage, |
| 29 FragmentColumn, |
| 30 FragmentRegion |
| 31 }; |
| 32 |
| 33 enum NGExclusionFlowType { |
| 34 ExcludeNone, |
| 35 ExcludeInlineFlow, |
| 36 ExcludeInlineStart, |
| 37 ExcludeInlineEnd, |
| 38 ExcludeInlineBoth |
| 39 }; |
| 40 |
| 41 class NGExclusion { |
| 42 public: |
| 43 NGExclusion(); |
| 44 ~NGExclusion() { } |
| 45 }; |
| 46 |
| 47 class CORE_EXPORT NGConstraintSpace { |
| 48 public: |
| 49 NGConstraintSpace(LayoutUnit inlineSize, LayoutUnit blockSize); |
| 50 ~NGConstraintSpace() { } |
| 51 |
| 52 void addExclusion(const NGExclusion, unsigned options = 0); |
| 53 void setOverflowSize(LayoutUnit inlineSize, LayoutUnit blockSize); |
| 54 void setFixedSize(bool inlineFixed, bool blockFixed); |
| 55 void setFragmentationType(NGFragmentationType blockFragmentationType); |
| 56 |
| 57 // Available space in each direction, -1 indicates infinite space. |
| 58 LayoutUnit inlineSize() const { return m_inlineSize; } |
| 59 LayoutUnit blockSize() const { return m_blockSize; } |
| 60 |
| 61 // The size threashold in the inline and block directions respectively that |
| 62 // triggers the presence of a scrollbar. If exceeded the current layout |
| 63 // should be aborted and invoked again with a constraint space modified to |
| 64 // reserve space for a scrollbar. -1 indicates no limit. |
| 65 LayoutUnit inlineOverflowSize() const { return m_inlineOverflowSize; } |
| 66 LayoutUnit blockOverflowSize() const { return m_blockOverflowSize; } |
| 67 |
| 68 // Some layout modes “stretch” their children to a fixed size (e.g. flex, |
| 69 // grid). These flags represented whether a layout needs to produce a |
| 70 // fragment that satisfies a fixed constraint in the inline and block |
| 71 // direction respectively. |
| 72 bool fixedInlineSize() const { return m_fixedInlineSize; } |
| 73 bool fixedBlockSize() const { return m_fixedBlockSize; } |
| 74 |
| 75 // If specified a layout should produce a Fragment which fragments at the |
| 76 // blockSize if possible. |
| 77 NGFragmentationType blockFragmentationType() const |
| 78 { |
| 79 return static_cast<NGFragmentationType>(m_blockFragmentationType); |
| 80 } |
| 81 |
| 82 DoublyLinkedList<const NGExclusion> exclusions(unsigned options = 0) const; |
| 83 |
| 84 NGLayoutOpportunityIterator layoutOpportunities( |
| 85 unsigned clear = ClearNone, |
| 86 NGExclusionFlowType avoid = ExcludeNone) const; |
| 87 |
| 88 // Modifies constraint space to account for a placed fragment. Depending on |
| 89 // the shape of the fragment this will either modify the inline or block |
| 90 // size, or add an exclusion. |
| 91 void subtract(const NGFragment); |
| 92 |
| 93 private: |
| 94 LayoutUnit m_inlineSize; |
| 95 LayoutUnit m_blockSize; |
| 96 LayoutUnit m_inlineOverflowSize; |
| 97 LayoutUnit m_blockOverflowSize; |
| 98 |
| 99 unsigned m_fixedInlineSize : 1; |
| 100 unsigned m_fixedBlockSize : 1; |
| 101 unsigned m_blockFragmentationType : 2; |
| 102 |
| 103 DoublyLinkedList<const NGExclusion> m_exclusions; |
| 104 }; |
| 105 |
| 106 |
| 107 class CORE_EXPORT NGLayoutOpportunityIterator final { |
| 108 public: |
| 109 NGLayoutOpportunityIterator(const NGConstraintSpace* space, |
| 110 unsigned clear, NGExclusionFlowType avoid) |
| 111 : m_constraintSpace(space) |
| 112 , m_clear(clear) |
| 113 , m_avoid(avoid) { } |
| 114 ~NGLayoutOpportunityIterator() { } |
| 115 |
| 116 const NGDerivedConstraintSpace* next(); |
| 117 |
| 118 private: |
| 119 const NGConstraintSpace* m_constraintSpace; |
| 120 unsigned m_clear; |
| 121 NGExclusionFlowType m_avoid; |
| 122 }; |
| 123 |
| 124 |
| 125 class CORE_EXPORT NGDerivedConstraintSpace final : NGConstraintSpace { |
| 126 public: |
| 127 ~NGDerivedConstraintSpace(); |
| 128 |
| 129 LayoutUnit inlineOffset() const; |
| 130 LayoutUnit blockOffset() const; |
| 131 |
| 132 // When creating a derived NGConstraintSpace for the next inline level |
| 133 // layout opportunity, inlineSize and blockSize of the NGConstraintSpace |
| 134 // may be different from its parent. These properties hold the inline and |
| 135 // block size of the original NGConstraintSpaces, allowing percentage |
| 136 // resolution to work correctly. |
| 137 LayoutUnit inlineSizeForPercentageResolution() const; |
| 138 LayoutUnit blockSizeForPercentageResolution() const; |
| 139 |
| 140 private: |
| 141 NGDerivedConstraintSpace(); |
| 142 |
| 143 LayoutUnit m_inlineOffset; |
| 144 LayoutUnit m_blockOffset; |
| 145 NGConstraintSpace* m_original; |
| 146 }; |
| 147 |
| 148 } // namespace blink |
| 149 |
| 150 #endif // NGConstraintSpace_h |
OLD | NEW |