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 NGFloatingObject_h | 5 #ifndef NGFloatingObject_h |
6 #define NGFloatingObject_h | 6 #define NGFloatingObject_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_node.h" | 10 #include "core/layout/ng/ng_block_node.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 writing_mode, fragment)); | 33 writing_mode, fragment)); |
34 } | 34 } |
35 | 35 |
36 NGExclusion::Type exclusion_type; | 36 NGExclusion::Type exclusion_type; |
37 EClear clear_type; | 37 EClear clear_type; |
38 NGBoxStrut margins; | 38 NGBoxStrut margins; |
39 // Available size of the constraint space that will be used by | 39 // Available size of the constraint space that will be used by |
40 // NGLayoutOpportunityIterator to position this floating object. | 40 // NGLayoutOpportunityIterator to position this floating object. |
41 NGLogicalSize available_size; | 41 NGLogicalSize available_size; |
42 | 42 |
43 // To correctly position a float we need 2 offsets: | 43 // To correctly **position** a float we need 2 offsets: |
44 // - origin_offset which represents the layout point for this float. | 44 // - origin_offset which represents the layout point for this float. |
45 // - from_offset which represents the point from where we need to calculate | 45 // - from_offset which represents the point from where we need to calculate |
46 // the relative logical offset for this float. | 46 // the relative logical offset for this float. |
47 // Layout details: | 47 // Layout details: |
48 // At the time when this float is created only *inline* offsets are known. | 48 // At the time when this float is created only *inline* offsets are known. |
49 // Block offset will be set when we are about to place this float, i.e. when | 49 // Block offset will be set when we are about to place this float, i.e. when |
50 // we resolved MarginStrut, adjusted the offset to clearance line etc. | 50 // we resolved MarginStrut, adjusted the offset to clearance line etc. |
51 NGLogicalOffset origin_offset; | 51 NGLogicalOffset origin_offset; |
52 NGLogicalOffset from_offset; | 52 NGLogicalOffset from_offset; |
53 | 53 |
54 // To correctly **paint** a float we need to know the BFC offset of the | |
55 // container to which we are attaching this float. It's used to calculate | |
56 // {@code left_offset}, {@code top_offset}. | |
57 // In most situations {@code (left|top)_offset} equals to float's logical | |
58 // offset except the cases where a float needs to be re-attached to a non-zero | |
59 // height parent. | |
60 // | |
61 // Example: | |
62 // <body> | |
63 // <p style="height: 60px">Example</p> | |
64 // <div id="zero-height-div"><float></div> | |
65 // | |
66 // Here the float's logical offset is 0 relative to its #zero-height-div | |
67 // parent. Because of the "zero height" div this float is re-attached to the | |
68 // 1st non-empty parent => body. To paint this float correctly we provide the | |
69 // modified {@code (top|left)_offset} which is relative to the float's new | |
70 // parent. | |
71 // I.e. for our example {@code top_offset} == #zero-height-div's BFC offset | |
72 // - body's BFC offset + float's logical offset | |
73 // | |
74 // For code safety reasons {@code container_block_offset} is Optional here | |
75 // because the block's offset can be only determined before the actual float's | |
76 // placement event. | |
77 WTF::Optional<LayoutUnit> container_block_offset; | |
78 | |
54 // Calculated logical offset. It's never {@code nullopt} for a positioned | 79 // Calculated logical offset. It's never {@code nullopt} for a positioned |
55 // float. | 80 // float. |
56 WTF::Optional<NGLogicalOffset> logical_offset; | 81 WTF::Optional<NGLogicalOffset> logical_offset; |
57 | 82 |
58 // Writing mode of the float's constraint space. | 83 // Writing mode of the float's constraint space. |
59 NGWritingMode writing_mode; | 84 NGWritingMode writing_mode; |
60 | 85 |
61 RefPtr<NGPhysicalFragment> fragment; | 86 RefPtr<NGPhysicalFragment> fragment; |
62 | 87 |
63 // In the case where a legacy FloatingObject is attached to not its own | 88 // In the case where a legacy FloatingObject is attached to not its own |
64 // parent, e.g. a float surrounded by a bunch of nested empty divs, | 89 // parent, e.g. a float surrounded by a bunch of nested empty divs, |
65 // NG float fragment's LeftOffset() cannot be used as legacy FloatingObject's | 90 // NG float fragment's LeftOffset() cannot be used as legacy FloatingObject's |
66 // left offset because that offset should be relative to the original float | 91 // left offset because that offset should be relative to the original float |
67 // parent. | 92 // parent. |
68 // {@code left_offset} is calculated when we know to which parent this float | 93 // {@code left_offset} is calculated when we know to which parent this float |
69 // would be attached. | 94 // would be attached. |
ikilpatrick
2017/05/01 17:48:32
does this comment block need to be updated?
| |
70 LayoutUnit left_offset; | 95 LayoutUnit left_offset; |
96 LayoutUnit top_offset; | |
71 | 97 |
72 bool IsLeft() const { return exclusion_type == NGExclusion::kFloatLeft; } | 98 bool IsLeft() const { return exclusion_type == NGExclusion::kFloatLeft; } |
73 | 99 |
74 bool IsRight() const { return exclusion_type == NGExclusion::kFloatRight; } | 100 bool IsRight() const { return exclusion_type == NGExclusion::kFloatRight; } |
75 | 101 |
76 String ToString() const { | 102 String ToString() const { |
77 return String::Format("Type: '%d' Fragment: '%s'", exclusion_type, | 103 return String::Format("Type: '%d' Fragment: '%s'", exclusion_type, |
78 fragment->ToString().Ascii().data()); | 104 fragment->ToString().Ascii().data()); |
79 } | 105 } |
80 | 106 |
(...skipping 14 matching lines...) Expand all Loading... | |
95 exclusion_type = NGExclusion::kFloatLeft; | 121 exclusion_type = NGExclusion::kFloatLeft; |
96 if (style.Floating() == EFloat::kRight) | 122 if (style.Floating() == EFloat::kRight) |
97 exclusion_type = NGExclusion::kFloatRight; | 123 exclusion_type = NGExclusion::kFloatRight; |
98 clear_type = style.Clear(); | 124 clear_type = style.Clear(); |
99 } | 125 } |
100 }; | 126 }; |
101 | 127 |
102 } // namespace blink | 128 } // namespace blink |
103 | 129 |
104 #endif // NGFloatingObject_h | 130 #endif // NGFloatingObject_h |
OLD | NEW |