| 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 NGUnpositionedFloat_h | 5 #ifndef NGUnpositionedFloat_h |
| 6 #define NGUnpositionedFloat_h | 6 #define NGUnpositionedFloat_h |
| 7 | 7 |
| 8 #include "core/layout/ng/geometry/ng_box_strut.h" | 8 #include "core/layout/ng/geometry/ng_box_strut.h" |
| 9 #include "core/layout/ng/geometry/ng_logical_size.h" | 9 #include "core/layout/ng/geometry/ng_logical_size.h" |
| 10 #include "core/layout/ng/ng_block_break_token.h" | 10 #include "core/layout/ng/ng_block_break_token.h" |
| 11 #include "core/layout/ng/ng_block_node.h" | 11 #include "core/layout/ng/ng_block_node.h" |
| 12 #include "core/layout/ng/ng_exclusion.h" | 12 #include "core/layout/ng/ng_exclusion.h" |
| 13 #include "core/style/ComputedStyleConstants.h" | 13 #include "core/style/ComputedStyleConstants.h" |
| 14 #include "platform/wtf/Optional.h" | 14 #include "platform/wtf/Optional.h" |
| 15 #include "platform/wtf/RefPtr.h" | 15 #include "platform/wtf/RefPtr.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 class NGPhysicalBoxFragment; | 19 class NGPhysicalBoxFragment; |
| 20 | 20 |
| 21 // Struct that keeps all information needed to position floats in LayoutNG. | 21 // Struct that keeps all information needed to position floats in LayoutNG. |
| 22 struct CORE_EXPORT NGUnpositionedFloat | 22 struct CORE_EXPORT NGUnpositionedFloat |
| 23 : public RefCounted<NGUnpositionedFloat> { | 23 : public RefCounted<NGUnpositionedFloat> { |
| 24 public: | 24 public: |
| 25 static RefPtr<NGUnpositionedFloat> Create(NGLogicalSize available_size, | 25 static RefPtr<NGUnpositionedFloat> Create(NGLogicalSize available_size, |
| 26 NGLogicalSize percentage_size, | 26 NGLogicalSize percentage_size, |
| 27 NGLogicalOffset origin_offset, | 27 LayoutUnit origin_bfc_inline_offset, |
| 28 NGLogicalOffset from_offset, | 28 LayoutUnit bfc_inline_offset, |
| 29 NGBoxStrut margins, | 29 NGBoxStrut margins, |
| 30 NGBlockNode node, | 30 NGBlockNode node, |
| 31 NGBlockBreakToken* token) { | 31 NGBlockBreakToken* token) { |
| 32 return AdoptRef(new NGUnpositionedFloat(margins, available_size, | 32 return AdoptRef(new NGUnpositionedFloat( |
| 33 percentage_size, origin_offset, | 33 margins, available_size, percentage_size, origin_bfc_inline_offset, |
| 34 from_offset, node, token)); | 34 bfc_inline_offset, node, token)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 NGBlockNode node; | 37 NGBlockNode node; |
| 38 RefPtr<NGBlockBreakToken> token; | 38 RefPtr<NGBlockBreakToken> token; |
| 39 | 39 |
| 40 // Available size of the constraint space that will be used by | 40 // Available size of the constraint space that will be used by |
| 41 // NGLayoutOpportunityIterator to position this floating object. | 41 // NGLayoutOpportunityIterator to position this floating object. |
| 42 NGLogicalSize available_size; | 42 NGLogicalSize available_size; |
| 43 NGLogicalSize percentage_size; | 43 NGLogicalSize percentage_size; |
| 44 | 44 |
| 45 // To correctly position a float we need 2 offsets: | 45 // This is the BFC inline-offset for where we begin searching for layout |
| 46 // - origin_offset which represents the layout point for this float. | 46 // opportunities for this float. |
| 47 // - from_offset which represents the point from where we need to calculate | 47 LayoutUnit origin_bfc_inline_offset; |
| 48 // the relative logical offset for this float. | |
| 49 // Layout details: | |
| 50 // At the time when this float is created only *inline* offsets are known. | |
| 51 // Block offset will be set when we are about to place this float, i.e. when | |
| 52 // we resolved MarginStrut, adjusted the offset to clearance line etc. | |
| 53 NGLogicalOffset origin_offset; | |
| 54 NGLogicalOffset from_offset; | |
| 55 | 48 |
| 56 // To correctly **paint** a float we need to know the BFC offset of the | 49 // This is the BFC inline-offset for the float's parent. This is used for |
| 57 // container to which we are attaching this float. It's used to calculate | 50 // calculating the offset between the float and its parent. |
| 58 // {@code paint_offset}. | 51 LayoutUnit bfc_inline_offset; |
| 59 // In most situations {@code paint_offset} equals to float's logical | |
| 60 // offset except the cases where a float needs to be re-attached to a non-zero | |
| 61 // height parent. | |
| 62 // | |
| 63 // Example: | |
| 64 // <body> | |
| 65 // <p style="height: 60px">Example</p> | |
| 66 // <div id="zero-height-div"><float></div> | |
| 67 // | |
| 68 // Here the float's logical offset is 0 relative to its #zero-height-div | |
| 69 // parent. Because of the "zero height" div this float is re-attached to the | |
| 70 // 1st non-empty parent => body. To paint this float correctly we provide the | |
| 71 // modified {@code paint_offset} which is relative to the float's new | |
| 72 // parent. | |
| 73 // I.e. for our example {@code paint_offset.top} == | |
| 74 // #zero-height-div's BFC offset | |
| 75 // - body's BFC offset + float's logical offset | |
| 76 // | |
| 77 // For code safety reasons {@code parent_bfc_block_offset} is Optional here | |
| 78 // because the block's offset can be only determined before the actual float's | |
| 79 // placement event. | |
| 80 WTF::Optional<LayoutUnit> parent_bfc_block_offset; | |
| 81 | 52 |
| 82 // The margins are relative to the writing mode of the block formatting | 53 // The margins are relative to the writing mode of the block formatting |
| 83 // context. They are stored for convinence and could be recomputed with other | 54 // context. They are stored for convinence and could be recomputed with other |
| 84 // data on this object. | 55 // data on this object. |
| 85 NGBoxStrut margins; | 56 NGBoxStrut margins; |
| 86 | 57 |
| 87 // The fragment for this unpositioned float. This is only present if it's in | 58 // The fragment for this unpositioned float. This is only present if it's in |
| 88 // a different writing mode than the BFC. | 59 // a different writing mode than the BFC. |
| 89 WTF::Optional<RefPtr<NGPhysicalBoxFragment>> fragment; | 60 WTF::Optional<RefPtr<NGPhysicalBoxFragment>> fragment; |
| 90 | 61 |
| 91 bool IsLeft() const; | 62 bool IsLeft() const; |
| 92 bool IsRight() const; | 63 bool IsRight() const; |
| 93 EClear ClearType() const; | 64 EClear ClearType() const; |
| 94 | 65 |
| 95 private: | 66 private: |
| 96 NGUnpositionedFloat(const NGBoxStrut& margins, | 67 NGUnpositionedFloat(const NGBoxStrut& margins, |
| 97 const NGLogicalSize& available_size, | 68 const NGLogicalSize& available_size, |
| 98 const NGLogicalSize& percentage_size, | 69 const NGLogicalSize& percentage_size, |
| 99 const NGLogicalOffset& origin_offset, | 70 LayoutUnit origin_bfc_inline_offset, |
| 100 const NGLogicalOffset& from_offset, | 71 LayoutUnit bfc_inline_offset, |
| 101 NGBlockNode node, | 72 NGBlockNode node, |
| 102 NGBlockBreakToken* token) | 73 NGBlockBreakToken* token) |
| 103 : node(node), | 74 : node(node), |
| 104 token(token), | 75 token(token), |
| 105 available_size(available_size), | 76 available_size(available_size), |
| 106 percentage_size(percentage_size), | 77 percentage_size(percentage_size), |
| 107 origin_offset(origin_offset), | 78 origin_bfc_inline_offset(origin_bfc_inline_offset), |
| 108 from_offset(from_offset), | 79 bfc_inline_offset(bfc_inline_offset), |
| 109 margins(margins) {} | 80 margins(margins) {} |
| 110 }; | 81 }; |
| 111 | 82 |
| 112 } // namespace blink | 83 } // namespace blink |
| 113 | 84 |
| 114 #endif // NGUnpositionedFloat_h | 85 #endif // NGUnpositionedFloat_h |
| OLD | NEW |