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 NGLayoutOpportunityIterator_h | 5 #ifndef NGLayoutOpportunityIterator_h |
6 #define NGLayoutOpportunityIterator_h | 6 #define NGLayoutOpportunityIterator_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/ng/ng_exclusion.h" |
9 #include "core/layout/ng/ng_layout_opportunity_tree_node.h" | 10 #include "core/layout/ng/ng_layout_opportunity_tree_node.h" |
10 #include "platform/wtf/Optional.h" | |
11 #include "platform/wtf/Vector.h" | 11 #include "platform/wtf/Vector.h" |
12 #include "platform/wtf/text/StringBuilder.h" | 12 #include "platform/wtf/text/StringBuilder.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class NGConstraintSpace; | |
17 typedef NGLogicalRect NGLayoutOpportunity; | 16 typedef NGLogicalRect NGLayoutOpportunity; |
18 typedef Vector<NGLayoutOpportunity> NGLayoutOpportunities; | 17 typedef Vector<NGLayoutOpportunity> NGLayoutOpportunities; |
19 | 18 |
20 class CORE_EXPORT NGLayoutOpportunityIterator final { | 19 class CORE_EXPORT NGLayoutOpportunityIterator final { |
21 public: | 20 public: |
22 // Default constructor. | 21 // Default constructor. |
23 // | 22 // |
24 // @param space Constraint space with exclusions for which this iterator needs | 23 // @param exclusions List of exclusions that should be avoided by this |
25 // to generate layout opportunities. | 24 // iterator while generating layout opportunities. |
26 // @param opt_offset Optional offset parameter that is used as a | 25 // @param available_size Available size that represents a rectangle where this |
27 // default start point for layout opportunities. | 26 // iterator searches layout opportunities. |
28 // @param opt_leader_point Optional 'leader' parameter that is used to specify | 27 // @param offset Offset used as a default starting point for layout |
29 // the ending point of temporary excluded rectangle | 28 // opportunities. |
30 // which starts from 'origin'. This rectangle may | 29 NGLayoutOpportunityIterator(const NGExclusions* exclusions, |
31 // represent a text fragment for example. | 30 const NGLogicalSize& available_size, |
32 NGLayoutOpportunityIterator( | 31 const NGLogicalOffset& offset); |
33 const NGConstraintSpace* space, | |
34 const NGLogicalSize& available_size, | |
35 const WTF::Optional<NGLogicalOffset>& opt_offset = WTF::kNullopt, | |
36 const WTF::Optional<NGLogicalOffset>& opt_leader_point = WTF::kNullopt); | |
37 | 32 |
38 // Gets the next Layout Opportunity or empty one if the search is exhausted. | 33 // Gets the next Layout Opportunity or empty one if the search is exhausted. |
39 // TODO(chrome-layout-team): Refactor with using C++ <iterator> library. | 34 // TODO(chrome-layout-team): Refactor with using C++ <iterator> library. |
40 // TODO(glebl): Refactor the iterator to return unique_ptr here. | 35 // TODO(glebl): Refactor the iterator to return unique_ptr here. |
41 const NGLayoutOpportunity Next(); | 36 const NGLayoutOpportunity Next(); |
42 | 37 |
43 // Offset that specifies the starting point to search layout opportunities. | 38 // Offset that specifies the starting point to search layout opportunities. |
44 // It's either {@code opt_offset} or space->BfcOffset(). | 39 // It's either {@code opt_offset} or space->BfcOffset(). |
45 NGLogicalOffset Offset() const { return offset_; } | 40 NGLogicalOffset Offset() const { return offset_; } |
46 | 41 |
47 #ifndef NDEBUG | 42 #ifndef NDEBUG |
48 // Prints Layout Opportunity tree for debug purposes. | 43 // Prints Layout Opportunity tree for debug purposes. |
49 void ShowLayoutOpportunityTree() const; | 44 void ShowLayoutOpportunityTree() const; |
50 #endif | 45 #endif |
51 | 46 |
52 private: | 47 private: |
53 // Mutable Getters. | 48 // Mutable Getters. |
54 NGLayoutOpportunityTreeNode* MutableOpportunityTreeRoot() { | 49 NGLayoutOpportunityTreeNode* MutableOpportunityTreeRoot() { |
55 return opportunity_tree_root_.get(); | 50 return opportunity_tree_root_.get(); |
56 } | 51 } |
57 | 52 |
58 // Read-only Getters. | 53 // Read-only Getters. |
59 const NGLayoutOpportunityTreeNode* OpportunityTreeRoot() const { | 54 const NGLayoutOpportunityTreeNode* OpportunityTreeRoot() const { |
60 return opportunity_tree_root_.get(); | 55 return opportunity_tree_root_.get(); |
61 } | 56 } |
62 | 57 |
63 const NGConstraintSpace* constraint_space_; | |
64 | |
65 NGLayoutOpportunities opportunities_; | 58 NGLayoutOpportunities opportunities_; |
66 NGLayoutOpportunities::const_iterator opportunity_iter_; | 59 NGLayoutOpportunities::const_iterator opportunity_iter_; |
67 std::unique_ptr<NGLayoutOpportunityTreeNode> opportunity_tree_root_; | 60 std::unique_ptr<NGLayoutOpportunityTreeNode> opportunity_tree_root_; |
68 NGLogicalOffset offset_; | 61 NGLogicalOffset offset_; |
69 }; | 62 }; |
70 | 63 |
71 } // namespace blink | 64 } // namespace blink |
72 | 65 |
73 #endif // NGLayoutOpportunityIterator_h | 66 #endif // NGLayoutOpportunityIterator_h |
OLD | NEW |