| 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 #include "core/layout/DepthOrderedLayoutObjectList.h" | 5 #include "core/layout/DepthOrderedLayoutObjectList.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/layout/LayoutObject.h" | 8 #include "core/layout/LayoutObject.h" |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 struct DepthOrderedLayoutObjectListData { |
| 14 // LayoutObjects sorted by depth (deepest first). This structure is only |
| 15 // populated at the beginning of enumerations. See ordered(). |
| 16 Vector<DepthOrderedLayoutObjectList::LayoutObjectWithDepth> m_orderedObjects
; |
| 17 |
| 18 // Outside of layout, LayoutObjects can be added and removed as needed such |
| 19 // as when style was changed or destroyed. They're kept in this hashset to |
| 20 // keep those operations fast. |
| 21 HashSet<LayoutObject*> m_objects; |
| 22 }; |
| 23 |
| 24 DepthOrderedLayoutObjectList::DepthOrderedLayoutObjectList() |
| 25 : m_data(new DepthOrderedLayoutObjectListData) |
| 26 { |
| 27 } |
| 28 |
| 29 DepthOrderedLayoutObjectList::~DepthOrderedLayoutObjectList() |
| 30 { |
| 31 delete m_data; |
| 32 } |
| 33 |
| 34 int DepthOrderedLayoutObjectList::size() const |
| 35 { |
| 36 return m_data->m_objects.size(); |
| 37 } |
| 38 |
| 39 bool DepthOrderedLayoutObjectList::isEmpty() const |
| 40 { |
| 41 return m_data->m_objects.isEmpty(); |
| 42 } |
| 43 |
| 13 void DepthOrderedLayoutObjectList::add(LayoutObject& object) | 44 void DepthOrderedLayoutObjectList::add(LayoutObject& object) |
| 14 { | 45 { |
| 15 ASSERT(!object.frameView()->isInPerformLayout()); | 46 ASSERT(!object.frameView()->isInPerformLayout()); |
| 16 m_objects.add(&object); | 47 m_data->m_objects.add(&object); |
| 17 m_orderedObjects.clear(); | 48 m_data->m_orderedObjects.clear(); |
| 18 } | 49 } |
| 19 | 50 |
| 20 void DepthOrderedLayoutObjectList::remove(LayoutObject& object) | 51 void DepthOrderedLayoutObjectList::remove(LayoutObject& object) |
| 21 { | 52 { |
| 22 auto it = m_objects.find(&object); | 53 auto it = m_data->m_objects.find(&object); |
| 23 if (it == m_objects.end()) | 54 if (it == m_data->m_objects.end()) |
| 24 return; | 55 return; |
| 25 ASSERT(!object.frameView()->isInPerformLayout()); | 56 ASSERT(!object.frameView()->isInPerformLayout()); |
| 26 m_objects.remove(it); | 57 m_data->m_objects.remove(it); |
| 27 m_orderedObjects.clear(); | 58 m_data->m_orderedObjects.clear(); |
| 28 } | 59 } |
| 29 | 60 |
| 30 void DepthOrderedLayoutObjectList::clear() | 61 void DepthOrderedLayoutObjectList::clear() |
| 31 { | 62 { |
| 32 m_objects.clear(); | 63 m_data->m_objects.clear(); |
| 33 m_orderedObjects.clear(); | 64 m_data->m_orderedObjects.clear(); |
| 34 } | 65 } |
| 35 | 66 |
| 36 unsigned DepthOrderedLayoutObjectList::LayoutObjectWithDepth::determineDepth(Lay
outObject* object) | 67 unsigned DepthOrderedLayoutObjectList::LayoutObjectWithDepth::determineDepth(Lay
outObject* object) |
| 37 { | 68 { |
| 38 unsigned depth = 1; | 69 unsigned depth = 1; |
| 39 for (LayoutObject* parent = object->parent(); parent; parent = parent->paren
t()) | 70 for (LayoutObject* parent = object->parent(); parent; parent = parent->paren
t()) |
| 40 ++depth; | 71 ++depth; |
| 41 return depth; | 72 return depth; |
| 42 } | 73 } |
| 43 | 74 |
| 75 const HashSet<LayoutObject*>& DepthOrderedLayoutObjectList::unordered() const |
| 76 { |
| 77 return m_data->m_objects; |
| 78 } |
| 79 |
| 44 const Vector<DepthOrderedLayoutObjectList::LayoutObjectWithDepth>& DepthOrderedL
ayoutObjectList::ordered() | 80 const Vector<DepthOrderedLayoutObjectList::LayoutObjectWithDepth>& DepthOrderedL
ayoutObjectList::ordered() |
| 45 { | 81 { |
| 46 if (m_objects.isEmpty() || !m_orderedObjects.isEmpty()) | 82 if (m_data->m_objects.isEmpty() || !m_data->m_orderedObjects.isEmpty()) |
| 47 return m_orderedObjects; | 83 return m_data->m_orderedObjects; |
| 48 | 84 |
| 49 copyToVector(m_objects, m_orderedObjects); | 85 copyToVector(m_data->m_objects, m_data->m_orderedObjects); |
| 50 std::sort(m_orderedObjects.begin(), m_orderedObjects.end()); | 86 std::sort(m_data->m_orderedObjects.begin(), m_data->m_orderedObjects.end()); |
| 51 return m_orderedObjects; | 87 return m_data->m_orderedObjects; |
| 52 } | 88 } |
| 53 | 89 |
| 54 } // namespace blink | 90 } // namespace blink |
| OLD | NEW |