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/ng_block_node.h" | 10 #include "core/layout/ng/ng_block_node.h" |
10 #include "core/layout/ng/ng_constraint_space.h" | 11 #include "core/layout/ng/ng_constraint_space.h" |
11 #include "core/layout/ng/ng_exclusion.h" | 12 #include "core/layout/ng/ng_exclusion.h" |
12 #include "core/layout/ng/ng_physical_fragment.h" | 13 #include "core/layout/ng/ng_physical_fragment.h" |
13 #include "core/style/ComputedStyle.h" | 14 #include "core/style/ComputedStyle.h" |
14 #include "core/style/ComputedStyleConstants.h" | 15 #include "core/style/ComputedStyleConstants.h" |
15 #include "wtf/RefPtr.h" | 16 #include "wtf/RefPtr.h" |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 // Struct that keeps all information needed to position floats in LayoutNG. | 20 // Struct that keeps all information needed to position floats in LayoutNG. |
20 struct CORE_EXPORT NGFloatingObject : public RefCounted<NGFloatingObject> { | 21 struct CORE_EXPORT NGFloatingObject : public RefCounted<NGFloatingObject> { |
21 public: | 22 public: |
22 static RefPtr<NGFloatingObject> Create(const NGConstraintSpace* space, | 23 static RefPtr<NGFloatingObject> Create(const NGConstraintSpace* space, |
23 const NGConstraintSpace* parent_space, | 24 const NGConstraintSpace* parent_space, |
24 const ComputedStyle& style, | 25 const ComputedStyle& style, |
25 const NGBoxStrut& margins, | 26 const NGBoxStrut& margins, |
| 27 const NGLogicalSize& available_size, |
26 NGPhysicalFragment* fragment) { | 28 NGPhysicalFragment* fragment) { |
27 return adoptRef( | 29 return adoptRef(new NGFloatingObject(space, parent_space, style, margins, |
28 new NGFloatingObject(space, parent_space, style, margins, fragment)); | 30 available_size, fragment)); |
29 } | 31 } |
30 | 32 |
31 // Original constraint space of the float. | 33 // Original constraint space of the float. |
32 RefPtr<const NGConstraintSpace> space; | 34 RefPtr<const NGConstraintSpace> space; |
33 | 35 |
34 // Parent space is used so we can calculate the inline offset relative to | 36 // Parent space is used so we can calculate the inline offset relative to |
35 // the original parent of this float. | 37 // the original parent of this float. |
36 RefPtr<const NGConstraintSpace> original_parent_space; | 38 RefPtr<const NGConstraintSpace> original_parent_space; |
37 | 39 |
38 NGExclusion::Type exclusion_type; | 40 NGExclusion::Type exclusion_type; |
39 EClear clear_type; | 41 EClear clear_type; |
40 NGBoxStrut margins; | 42 NGBoxStrut margins; |
| 43 // Available size of the constraint space that will be used by |
| 44 // NGLayoutOpportunityIterator to position this floaing object. |
| 45 NGLogicalSize available_size; |
41 | 46 |
42 RefPtr<NGPhysicalFragment> fragment; | 47 RefPtr<NGPhysicalFragment> fragment; |
43 | 48 |
44 // In the case where a legacy FloatingObject is attached to not its own | 49 // In the case where a legacy FloatingObject is attached to not its own |
45 // parent, e.g. a float surrounded by a bunch of nested empty divs, | 50 // parent, e.g. a float surrounded by a bunch of nested empty divs, |
46 // NG float fragment's LeftOffset() cannot be used as legacy FloatingObject's | 51 // NG float fragment's LeftOffset() cannot be used as legacy FloatingObject's |
47 // left offset because that offset should be relative to the original float | 52 // left offset because that offset should be relative to the original float |
48 // parent. | 53 // parent. |
49 // {@code left_offset} is calculated when we know to which parent this float | 54 // {@code left_offset} is calculated when we know to which parent this float |
50 // would be attached. | 55 // would be attached. |
51 LayoutUnit left_offset; | 56 LayoutUnit left_offset; |
52 | 57 |
53 String ToString() const { | 58 String ToString() const { |
54 return String::format("Type: '%d' Fragment: '%s'", exclusion_type, | 59 return String::format("Type: '%d' Fragment: '%s'", exclusion_type, |
55 fragment->ToString().ascii().data()); | 60 fragment->ToString().ascii().data()); |
56 } | 61 } |
57 | 62 |
58 private: | 63 private: |
59 NGFloatingObject(const NGConstraintSpace* space, | 64 NGFloatingObject(const NGConstraintSpace* space, |
60 const NGConstraintSpace* parent_space, | 65 const NGConstraintSpace* parent_space, |
61 const ComputedStyle& style, | 66 const ComputedStyle& style, |
62 const NGBoxStrut& margins, | 67 const NGBoxStrut& margins, |
| 68 const NGLogicalSize& available_size, |
63 NGPhysicalFragment* fragment) | 69 NGPhysicalFragment* fragment) |
64 : space(space), | 70 : space(space), |
65 original_parent_space(parent_space), | 71 original_parent_space(parent_space), |
66 margins(margins), | 72 margins(margins), |
| 73 available_size(available_size), |
67 fragment(fragment) { | 74 fragment(fragment) { |
68 exclusion_type = NGExclusion::kFloatLeft; | 75 exclusion_type = NGExclusion::kFloatLeft; |
69 if (style.floating() == EFloat::kRight) | 76 if (style.floating() == EFloat::kRight) |
70 exclusion_type = NGExclusion::kFloatRight; | 77 exclusion_type = NGExclusion::kFloatRight; |
71 clear_type = style.clear(); | 78 clear_type = style.clear(); |
72 } | 79 } |
73 }; | 80 }; |
74 | 81 |
75 } // namespace blink | 82 } // namespace blink |
76 | 83 |
77 #endif // NGFloatingObject_h | 84 #endif // NGFloatingObject_h |
OLD | NEW |