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

Unified Diff: third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.h

Issue 1549153002: Fix preferred logical widths of orthogonal writing modes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow call to remove() while iterating as long as it doesn't actually remove Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.h
diff --git a/third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.h b/third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.h
new file mode 100644
index 0000000000000000000000000000000000000000..409cefbdf0ed922ed1b108a63db2c166dbdef79c
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/DepthOrderedLayoutObjectList.h
@@ -0,0 +1,104 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DepthOrderedLayoutObjectList_h
+#define DepthOrderedLayoutObjectList_h
+
+#include "wtf/Allocator.h"
+#include "wtf/HashSet.h"
+#include "wtf/Vector.h"
+
+namespace blink {
+
+class LayoutObject;
+
+class DepthOrderedLayoutObjectList {
+public:
+ DepthOrderedLayoutObjectList()
+#if ENABLE(ASSERT)
+ : m_assertOnModify(false)
+#endif
+ {
+ }
+
+ void add(LayoutObject& object)
+ {
+ ASSERT(!m_assertOnModify);
leviw_travelin_and_unemployed 2016/02/02 05:03:40 Instead of needing this bit, since you always get
kojii 2016/02/02 23:32:49 Done.
+ m_objects.add(&object);
+ m_orderedObjects.clear();
+ }
+ void remove(LayoutObject& object)
+ {
+ auto it = m_objects.find(&object);
+ if (it == m_objects.end())
+ return;
+ ASSERT(!m_assertOnModify);
+ m_objects.remove(it);
+ m_orderedObjects.clear();
+ }
+ void clear()
+ {
+ ASSERT(!m_assertOnModify);
leviw_travelin_and_unemployed 2016/02/02 05:03:40 As Kojii mentioned, you'd have to allow clearing s
kojii 2016/02/02 23:32:50 Done.
+ m_objects.clear();
+ m_orderedObjects.clear();
+ }
+
+ int size() const { return m_objects.size(); }
+ bool isEmpty() const { return m_objects.isEmpty(); }
+
+ struct LayoutObjectWithDepth {
+ LayoutObjectWithDepth(LayoutObject* inObject)
+ : object(inObject)
+ , depth(determineDepth(inObject))
+ {
+ }
+
+ LayoutObjectWithDepth()
+ : object(0)
leviw_travelin_and_unemployed 2016/02/02 05:03:40 nullptr
kojii 2016/02/02 23:32:49 Done.
+ , depth(0)
+ {
+ }
+
+ LayoutObject* object;
+ unsigned depth;
+
+ LayoutObject& operator*() const { return *object; }
+ LayoutObject* operator->() const { return object; }
+
+ bool operator<(const DepthOrderedLayoutObjectList::LayoutObjectWithDepth& other) const
+ {
+ return depth > other.depth;
+ }
+
+ private:
+ static unsigned determineDepth(LayoutObject*);
+ };
+
+ const HashSet<LayoutObject*>& unordered() const { return m_objects; }
+ const Vector<LayoutObjectWithDepth>& ordered();
+
+#if ENABLE(ASSERT)
+ void assertOnModify(bool value) { m_assertOnModify = value; }
+#else
+ void assertOnModify(bool) { }
+#endif
+
+private:
+ // LayoutObjects sorted by depth (deepest first). This structure is only
+ // populated at the beginning of enumerations. See ordered().
+ Vector<LayoutObjectWithDepth> m_orderedObjects;
+
+ // Outside of layout, LayoutObjects can be added and removed as needed such
+ // as when style was changed or destroyed. They're kept in this hashset to
+ // keep those operations fast.
+ HashSet<LayoutObject*> m_objects;
+
+#if ENABLE(ASSERT)
+ bool m_assertOnModify;
+#endif
+};
+
+} // namespace blink
+
+#endif // DepthOrderedLayoutObjectList_h

Powered by Google App Engine
This is Rietveld 408576698