| 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 DepthOrderedLayoutObjectList_h | 5 #ifndef DepthOrderedLayoutObjectList_h |
| 6 #define DepthOrderedLayoutObjectList_h | 6 #define DepthOrderedLayoutObjectList_h |
| 7 | 7 |
| 8 #include "wtf/Allocator.h" | 8 #include "wtf/Allocator.h" |
| 9 #include "wtf/HashSet.h" | 9 #include "wtf/HashSet.h" |
| 10 #include "wtf/Vector.h" | 10 #include "wtf/Vector.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class LayoutObject; | 14 class LayoutObject; |
| 15 | 15 |
| 16 // Put data inside a forward-declared struct, to avoid including LayoutObject.h
here. |
| 17 struct DepthOrderedLayoutObjectListData; |
| 18 |
| 16 class DepthOrderedLayoutObjectList { | 19 class DepthOrderedLayoutObjectList { |
| 17 public: | 20 public: |
| 18 DepthOrderedLayoutObjectList() | 21 DepthOrderedLayoutObjectList(); |
| 19 { | 22 ~DepthOrderedLayoutObjectList(); |
| 20 } | |
| 21 | 23 |
| 22 void add(LayoutObject&); | 24 void add(LayoutObject&); |
| 23 void remove(LayoutObject&); | 25 void remove(LayoutObject&); |
| 24 void clear(); | 26 void clear(); |
| 25 | 27 |
| 26 int size() const { return m_objects.size(); } | 28 int size() const; |
| 27 bool isEmpty() const { return m_objects.isEmpty(); } | 29 bool isEmpty() const; |
| 28 | 30 |
| 29 struct LayoutObjectWithDepth { | 31 struct LayoutObjectWithDepth { |
| 30 LayoutObjectWithDepth(LayoutObject* inObject) | 32 LayoutObjectWithDepth(LayoutObject* inObject) |
| 31 : object(inObject) | 33 : object(inObject) |
| 32 , depth(determineDepth(inObject)) | 34 , depth(determineDepth(inObject)) |
| 33 { | 35 { |
| 34 } | 36 } |
| 35 | 37 |
| 36 LayoutObjectWithDepth() | 38 LayoutObjectWithDepth() |
| 37 : object(nullptr) | 39 : object(nullptr) |
| 38 , depth(0) | 40 , depth(0) |
| 39 { | 41 { |
| 40 } | 42 } |
| 41 | 43 |
| 42 LayoutObject* object; | 44 LayoutObject* object; |
| 43 unsigned depth; | 45 unsigned depth; |
| 44 | 46 |
| 45 LayoutObject& operator*() const { return *object; } | 47 LayoutObject& operator*() const { return *object; } |
| 46 LayoutObject* operator->() const { return object; } | 48 LayoutObject* operator->() const { return object; } |
| 47 | 49 |
| 48 bool operator<(const DepthOrderedLayoutObjectList::LayoutObjectWithDepth
& other) const | 50 bool operator<(const DepthOrderedLayoutObjectList::LayoutObjectWithDepth
& other) const |
| 49 { | 51 { |
| 50 return depth > other.depth; | 52 return depth > other.depth; |
| 51 } | 53 } |
| 52 | 54 |
| 53 private: | 55 private: |
| 54 static unsigned determineDepth(LayoutObject*); | 56 static unsigned determineDepth(LayoutObject*); |
| 55 }; | 57 }; |
| 56 | 58 |
| 57 const HashSet<LayoutObject*>& unordered() const { return m_objects; } | 59 const HashSet<LayoutObject*>& unordered() const; |
| 58 const Vector<LayoutObjectWithDepth>& ordered(); | 60 const Vector<LayoutObjectWithDepth>& ordered(); |
| 59 | 61 |
| 60 private: | 62 private: |
| 61 // LayoutObjects sorted by depth (deepest first). This structure is only | 63 DepthOrderedLayoutObjectListData* m_data; |
| 62 // populated at the beginning of enumerations. See ordered(). | |
| 63 Vector<LayoutObjectWithDepth> m_orderedObjects; | |
| 64 | |
| 65 // Outside of layout, LayoutObjects can be added and removed as needed such | |
| 66 // as when style was changed or destroyed. They're kept in this hashset to | |
| 67 // keep those operations fast. | |
| 68 HashSet<LayoutObject*> m_objects; | |
| 69 }; | 64 }; |
| 70 | 65 |
| 71 } // namespace blink | 66 } // namespace blink |
| 72 | 67 |
| 73 #endif // DepthOrderedLayoutObjectList_h | 68 #endif // DepthOrderedLayoutObjectList_h |
| OLD | NEW |