Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_floating_object.h

Issue 2790283003: Reset constraint space's BFC offset if block creates a new FC (Closed)
Patch Set: git rebase-update Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "core/layout/ng/ng_constraint_space.h" 11 #include "core/layout/ng/ng_constraint_space.h"
12 #include "core/layout/ng/ng_exclusion.h" 12 #include "core/layout/ng/ng_exclusion.h"
13 #include "core/layout/ng/ng_physical_fragment.h" 13 #include "core/layout/ng/ng_physical_fragment.h"
14 #include "core/style/ComputedStyle.h" 14 #include "core/style/ComputedStyle.h"
15 #include "core/style/ComputedStyleConstants.h" 15 #include "core/style/ComputedStyleConstants.h"
16 #include "wtf/RefPtr.h" 16 #include "wtf/RefPtr.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 // Struct that keeps all information needed to position floats in LayoutNG. 20 // Struct that keeps all information needed to position floats in LayoutNG.
21 struct CORE_EXPORT NGFloatingObject : public RefCounted<NGFloatingObject> { 21 struct CORE_EXPORT NGFloatingObject : public RefCounted<NGFloatingObject> {
22 public: 22 public:
23 static RefPtr<NGFloatingObject> Create(const NGConstraintSpace* space, 23 static RefPtr<NGFloatingObject> Create(const ComputedStyle& style,
24 const NGConstraintSpace* parent_space, 24 NGWritingMode writing_mode,
25 const ComputedStyle& style, 25 NGLogicalSize available_size,
26 const NGBoxStrut& margins, 26 NGLogicalOffset origin_offset,
27 const NGLogicalSize& available_size, 27 NGLogicalOffset from_offset,
28 NGBoxStrut margins,
28 NGPhysicalFragment* fragment) { 29 NGPhysicalFragment* fragment) {
29 return adoptRef(new NGFloatingObject(space, parent_space, style, margins, 30 return adoptRef(new NGFloatingObject(style, margins, available_size,
30 available_size, fragment)); 31 origin_offset, from_offset,
32 writing_mode, fragment));
31 } 33 }
32 34
33 // Original constraint space of the float.
34 RefPtr<const NGConstraintSpace> space;
35
36 // Parent space is used so we can calculate the inline offset relative to
37 // the original parent of this float.
38 RefPtr<const NGConstraintSpace> original_parent_space;
39
40 NGExclusion::Type exclusion_type; 35 NGExclusion::Type exclusion_type;
41 EClear clear_type; 36 EClear clear_type;
42 NGBoxStrut margins; 37 NGBoxStrut margins;
43 // Available size of the constraint space that will be used by 38 // Available size of the constraint space that will be used by
44 // NGLayoutOpportunityIterator to position this floaing object. 39 // NGLayoutOpportunityIterator to position this floating object.
45 NGLogicalSize available_size; 40 NGLogicalSize available_size;
46 41
42 // To correctly position a float we need 2 offsets:
43 // - origin_offset which represents the layout point for this float.
44 // - from_offset which represents the point from where we need to calculate
45 // the relative logical offset for this float.
46 // Layout details:
47 // At the time when this float is created only *inline* offsets are known.
48 // Block offset will be set when we are about to place this float, i.e. when
49 // we resolved MarginStrut, adjusted the offset to clearance line etc.
50 NGLogicalOffset origin_offset;
51 NGLogicalOffset from_offset;
52
53 // Writing mode of the float's constraint space.
54 NGWritingMode writing_mode;
55
47 RefPtr<NGPhysicalFragment> fragment; 56 RefPtr<NGPhysicalFragment> fragment;
48 57
49 // In the case where a legacy FloatingObject is attached to not its own 58 // In the case where a legacy FloatingObject is attached to not its own
50 // parent, e.g. a float surrounded by a bunch of nested empty divs, 59 // parent, e.g. a float surrounded by a bunch of nested empty divs,
51 // NG float fragment's LeftOffset() cannot be used as legacy FloatingObject's 60 // NG float fragment's LeftOffset() cannot be used as legacy FloatingObject's
52 // left offset because that offset should be relative to the original float 61 // left offset because that offset should be relative to the original float
53 // parent. 62 // parent.
54 // {@code left_offset} is calculated when we know to which parent this float 63 // {@code left_offset} is calculated when we know to which parent this float
55 // would be attached. 64 // would be attached.
56 LayoutUnit left_offset; 65 LayoutUnit left_offset;
57 66
58 bool IsLeft() const { return exclusion_type == NGExclusion::kFloatLeft; } 67 bool IsLeft() const { return exclusion_type == NGExclusion::kFloatLeft; }
59 68
60 bool IsRight() const { return exclusion_type == NGExclusion::kFloatRight; } 69 bool IsRight() const { return exclusion_type == NGExclusion::kFloatRight; }
61 70
62 String ToString() const { 71 String ToString() const {
63 return String::format("Type: '%d' Fragment: '%s'", exclusion_type, 72 return String::format("Type: '%d' Fragment: '%s'", exclusion_type,
64 fragment->ToString().ascii().data()); 73 fragment->ToString().ascii().data());
65 } 74 }
66 75
67 private: 76 private:
68 NGFloatingObject(const NGConstraintSpace* space, 77 NGFloatingObject(const ComputedStyle& style,
69 const NGConstraintSpace* parent_space,
70 const ComputedStyle& style,
71 const NGBoxStrut& margins, 78 const NGBoxStrut& margins,
72 const NGLogicalSize& available_size, 79 const NGLogicalSize& available_size,
80 const NGLogicalOffset& origin_offset,
81 const NGLogicalOffset& from_offset,
82 NGWritingMode writing_mode,
73 NGPhysicalFragment* fragment) 83 NGPhysicalFragment* fragment)
74 : space(space), 84 : margins(margins),
75 original_parent_space(parent_space),
76 margins(margins),
77 available_size(available_size), 85 available_size(available_size),
86 origin_offset(origin_offset),
87 from_offset(from_offset),
88 writing_mode(writing_mode),
78 fragment(fragment) { 89 fragment(fragment) {
79 exclusion_type = NGExclusion::kFloatLeft; 90 exclusion_type = NGExclusion::kFloatLeft;
80 if (style.floating() == EFloat::kRight) 91 if (style.floating() == EFloat::kRight)
81 exclusion_type = NGExclusion::kFloatRight; 92 exclusion_type = NGExclusion::kFloatRight;
82 clear_type = style.clear(); 93 clear_type = style.clear();
83 } 94 }
84 }; 95 };
85 96
86 } // namespace blink 97 } // namespace blink
87 98
88 #endif // NGFloatingObject_h 99 #endif // NGFloatingObject_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698