OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "wtf/OwnPtr.h" | 38 #include "wtf/OwnPtr.h" |
39 #include "wtf/RefCounted.h" | 39 #include "wtf/RefCounted.h" |
40 | 40 |
41 namespace WebCore { | 41 namespace WebCore { |
42 | 42 |
43 class MutationObserverInterestGroup; | 43 class MutationObserverInterestGroup; |
44 | 44 |
45 // ChildListMutationAccumulator is not meant to be used directly; ChildListMutat
ionScope is the public interface. | 45 // ChildListMutationAccumulator is not meant to be used directly; ChildListMutat
ionScope is the public interface. |
46 class ChildListMutationAccumulator : public RefCounted<ChildListMutationAccumula
tor> { | 46 class ChildListMutationAccumulator : public RefCounted<ChildListMutationAccumula
tor> { |
47 public: | 47 public: |
48 static PassRefPtr<ChildListMutationAccumulator> getOrCreate(Node*); | 48 static PassRefPtr<ChildListMutationAccumulator> getOrCreate(Node&); |
49 ~ChildListMutationAccumulator(); | 49 ~ChildListMutationAccumulator(); |
50 | 50 |
51 void childAdded(PassRefPtr<Node>); | 51 void childAdded(PassRefPtr<Node>); |
52 void willRemoveChild(PassRefPtr<Node>); | 52 void willRemoveChild(PassRefPtr<Node>); |
53 | 53 |
54 bool hasObservers() const { return m_observers; } | 54 bool hasObservers() const { return m_observers; } |
55 | 55 |
56 private: | 56 private: |
57 ChildListMutationAccumulator(PassRefPtr<Node>, PassOwnPtr<MutationObserverIn
terestGroup>); | 57 ChildListMutationAccumulator(PassRefPtr<Node>, PassOwnPtr<MutationObserverIn
terestGroup>); |
58 | 58 |
59 void enqueueMutationRecord(); | 59 void enqueueMutationRecord(); |
60 bool isEmpty(); | 60 bool isEmpty(); |
61 bool isAddedNodeInOrder(Node*); | 61 bool isAddedNodeInOrder(Node*); |
62 bool isRemovedNodeInOrder(Node*); | 62 bool isRemovedNodeInOrder(Node*); |
63 | 63 |
64 RefPtr<Node> m_target; | 64 RefPtr<Node> m_target; |
65 | 65 |
66 Vector<RefPtr<Node> > m_removedNodes; | 66 Vector<RefPtr<Node> > m_removedNodes; |
67 Vector<RefPtr<Node> > m_addedNodes; | 67 Vector<RefPtr<Node> > m_addedNodes; |
68 RefPtr<Node> m_previousSibling; | 68 RefPtr<Node> m_previousSibling; |
69 RefPtr<Node> m_nextSibling; | 69 RefPtr<Node> m_nextSibling; |
70 Node* m_lastAdded; | 70 Node* m_lastAdded; |
71 | 71 |
72 OwnPtr<MutationObserverInterestGroup> m_observers; | 72 OwnPtr<MutationObserverInterestGroup> m_observers; |
73 }; | 73 }; |
74 | 74 |
75 class ChildListMutationScope { | 75 class ChildListMutationScope { |
76 WTF_MAKE_NONCOPYABLE(ChildListMutationScope); | 76 WTF_MAKE_NONCOPYABLE(ChildListMutationScope); |
77 public: | 77 public: |
78 explicit ChildListMutationScope(Node* target) | 78 explicit ChildListMutationScope(Node& target) |
79 { | 79 { |
80 if (target->document().hasMutationObserversOfType(MutationObserver::Chil
dList)) | 80 if (target.document().hasMutationObserversOfType(MutationObserver::Child
List)) |
81 m_accumulator = ChildListMutationAccumulator::getOrCreate(target); | 81 m_accumulator = ChildListMutationAccumulator::getOrCreate(target); |
82 } | 82 } |
83 | 83 |
84 void childAdded(Node* child) | 84 void childAdded(Node& child) |
85 { | 85 { |
86 if (m_accumulator && m_accumulator->hasObservers()) | 86 if (m_accumulator && m_accumulator->hasObservers()) |
87 m_accumulator->childAdded(child); | 87 m_accumulator->childAdded(PassRefPtr<Node>(child)); |
88 } | 88 } |
89 | 89 |
90 void willRemoveChild(Node* child) | 90 void willRemoveChild(Node& child) |
91 { | 91 { |
92 if (m_accumulator && m_accumulator->hasObservers()) | 92 if (m_accumulator && m_accumulator->hasObservers()) |
93 m_accumulator->willRemoveChild(child); | 93 m_accumulator->willRemoveChild(PassRefPtr<Node>(child)); |
94 } | 94 } |
95 | 95 |
96 private: | 96 private: |
97 RefPtr<ChildListMutationAccumulator> m_accumulator; | 97 RefPtr<ChildListMutationAccumulator> m_accumulator; |
98 }; | 98 }; |
99 | 99 |
100 } // namespace WebCore | 100 } // namespace WebCore |
101 | 101 |
102 #endif // ChildListMutationScope_h | 102 #endif // ChildListMutationScope_h |
OLD | NEW |