OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 setFlag(HasRareDataFlag); | 323 setFlag(HasRareDataFlag); |
324 return *data; | 324 return *data; |
325 } | 325 } |
326 | 326 |
327 void Node::clearRareData() | 327 void Node::clearRareData() |
328 { | 328 { |
329 ASSERT(hasRareData()); | 329 ASSERT(hasRareData()); |
330 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi
stry()->isEmpty()); | 330 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi
stry()->isEmpty()); |
331 | 331 |
332 RenderObject* renderer = m_data.m_rareData->renderer(); | 332 RenderObject* renderer = m_data.m_rareData->renderer(); |
333 if (isElementNode()) | 333 if (isElementNode()) { |
334 delete static_cast<ElementRareData*>(m_data.m_rareData); | 334 ElementRareData* rareData = static_cast<ElementRareData*>(m_data.m_rareD
ata); |
335 else | 335 rareData->dispose(); |
336 delete static_cast<NodeRareData*>(m_data.m_rareData); | 336 delete rareData; |
| 337 } else { |
| 338 NodeRareData* rareData = static_cast<NodeRareData*>(m_data.m_rareData); |
| 339 rareData->dispose(); |
| 340 delete rareData; |
| 341 } |
337 m_data.m_renderer = renderer; | 342 m_data.m_renderer = renderer; |
338 clearFlag(HasRareDataFlag); | 343 clearFlag(HasRareDataFlag); |
339 } | 344 } |
340 | 345 |
341 Node* Node::toNode() | 346 Node* Node::toNode() |
342 { | 347 { |
343 return this; | 348 return this; |
344 } | 349 } |
345 | 350 |
346 short Node::tabIndex() const | 351 short Node::tabIndex() const |
(...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 } | 1943 } |
1939 | 1944 |
1940 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets
()) { | 1945 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets
()) { |
1941 while (touchHandlers->contains(this)) { | 1946 while (touchHandlers->contains(this)) { |
1942 oldDocument.didRemoveTouchEventHandler(this); | 1947 oldDocument.didRemoveTouchEventHandler(this); |
1943 document().didAddTouchEventHandler(this); | 1948 document().didAddTouchEventHandler(this); |
1944 } | 1949 } |
1945 } | 1950 } |
1946 EventHandlerRegistry::from(document())->didMoveFromOtherDocument(*this, oldD
ocument); | 1951 EventHandlerRegistry::from(document())->didMoveFromOtherDocument(*this, oldD
ocument); |
1947 | 1952 |
1948 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserv
erRegistry()) { | 1953 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* reg
istry = mutationObserverRegistry()) { |
1949 for (size_t i = 0; i < registry->size(); ++i) { | 1954 for (size_t i = 0; i < registry->size(); ++i) { |
1950 document().addMutationObserverTypes(registry->at(i)->mutationTypes()
); | 1955 document().addMutationObserverTypes(registry->at(i)->mutationTypes()
); |
1951 } | 1956 } |
1952 } | 1957 } |
1953 | 1958 |
1954 if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMut
ationObserverRegistry()) { | 1959 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* tr
ansientRegistry = transientMutationObserverRegistry()) { |
1955 for (HashSet<MutationObserverRegistration*>::iterator iter = transientRe
gistry->begin(); iter != transientRegistry->end(); ++iter) { | 1960 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration>
>::iterator iter = transientRegistry->begin(); iter != transientRegistry->end();
++iter) { |
1956 document().addMutationObserverTypes((*iter)->mutationTypes()); | 1961 document().addMutationObserverTypes((*iter)->mutationTypes()); |
1957 } | 1962 } |
1958 } | 1963 } |
1959 } | 1964 } |
1960 | 1965 |
1961 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve
ntType, PassRefPtr<EventListener> listener, bool useCapture) | 1966 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve
ntType, PassRefPtr<EventListener> listener, bool useCapture) |
1962 { | 1967 { |
1963 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu
re)) | 1968 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu
re)) |
1964 return false; | 1969 return false; |
1965 | 1970 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 EventTargetData* data = new EventTargetData; | 2044 EventTargetData* data = new EventTargetData; |
2040 eventTargetDataMap().set(this, adoptPtr(data)); | 2045 eventTargetDataMap().set(this, adoptPtr(data)); |
2041 return *data; | 2046 return *data; |
2042 } | 2047 } |
2043 | 2048 |
2044 void Node::clearEventTargetData() | 2049 void Node::clearEventTargetData() |
2045 { | 2050 { |
2046 eventTargetDataMap().remove(this); | 2051 eventTargetDataMap().remove(this); |
2047 } | 2052 } |
2048 | 2053 |
2049 Vector<OwnPtr<MutationObserverRegistration> >* Node::mutationObserverRegistry() | 2054 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* Node::mutat
ionObserverRegistry() |
2050 { | 2055 { |
2051 if (!hasRareData()) | 2056 if (!hasRareData()) |
2052 return 0; | 2057 return 0; |
2053 NodeMutationObserverData* data = rareData()->mutationObserverData(); | 2058 NodeMutationObserverData* data = rareData()->mutationObserverData(); |
2054 if (!data) | 2059 if (!data) |
2055 return 0; | 2060 return 0; |
2056 return &data->registry; | 2061 return &data->registry; |
2057 } | 2062 } |
2058 | 2063 |
2059 HashSet<MutationObserverRegistration*>* Node::transientMutationObserverRegistry(
) | 2064 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* Node::tran
sientMutationObserverRegistry() |
2060 { | 2065 { |
2061 if (!hasRareData()) | 2066 if (!hasRareData()) |
2062 return 0; | 2067 return 0; |
2063 NodeMutationObserverData* data = rareData()->mutationObserverData(); | 2068 NodeMutationObserverData* data = rareData()->mutationObserverData(); |
2064 if (!data) | 2069 if (!data) |
2065 return 0; | 2070 return 0; |
2066 return &data->transientRegistry; | 2071 return &data->transientRegistry; |
2067 } | 2072 } |
2068 | 2073 |
2069 template<typename Registry> | 2074 template<typename Registry> |
2070 static inline void collectMatchingObserversForMutation(HashMap<MutationObserver*
, MutationRecordDeliveryOptions>& observers, Registry* registry, Node& target, M
utationObserver::MutationType type, const QualifiedName* attributeName) | 2075 static inline void collectMatchingObserversForMutation(WillBeHeapHashMap<RawPtrW
illBeMember<MutationObserver>, MutationRecordDeliveryOptions>& observers, Regist
ry* registry, Node& target, MutationObserver::MutationType type, const Qualified
Name* attributeName) |
2071 { | 2076 { |
2072 if (!registry) | 2077 if (!registry) |
2073 return; | 2078 return; |
2074 for (typename Registry::iterator iter = registry->begin(); iter != registry-
>end(); ++iter) { | 2079 for (typename Registry::iterator iter = registry->begin(); iter != registry-
>end(); ++iter) { |
2075 const MutationObserverRegistration& registration = **iter; | 2080 const MutationObserverRegistration& registration = **iter; |
2076 if (registration.shouldReceiveMutationFrom(target, type, attributeName))
{ | 2081 if (registration.shouldReceiveMutationFrom(target, type, attributeName))
{ |
2077 MutationRecordDeliveryOptions deliveryOptions = registration.deliver
yOptions(); | 2082 MutationRecordDeliveryOptions deliveryOptions = registration.deliver
yOptions(); |
2078 HashMap<MutationObserver*, MutationRecordDeliveryOptions>::AddResult
result = observers.add(®istration.observer(), deliveryOptions); | 2083 WillBeHeapHashMap<RawPtrWillBeMember<MutationObserver>, MutationReco
rdDeliveryOptions>::AddResult result = observers.add(®istration.observer(), d
eliveryOptions); |
2079 if (!result.isNewEntry) | 2084 if (!result.isNewEntry) |
2080 result.storedValue->value |= deliveryOptions; | 2085 result.storedValue->value |= deliveryOptions; |
2081 } | 2086 } |
2082 } | 2087 } |
2083 } | 2088 } |
2084 | 2089 |
2085 void Node::getRegisteredMutationObserversOfType(HashMap<MutationObserver*, Mutat
ionRecordDeliveryOptions>& observers, MutationObserver::MutationType type, const
QualifiedName* attributeName) | 2090 void Node::getRegisteredMutationObserversOfType(WillBeHeapHashMap<RawPtrWillBeMe
mber<MutationObserver>, MutationRecordDeliveryOptions>& observers, MutationObser
ver::MutationType type, const QualifiedName* attributeName) |
2086 { | 2091 { |
2087 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute
Name); | 2092 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute
Name); |
2088 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), *
this, type, attributeName); | 2093 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), *
this, type, attributeName); |
2089 collectMatchingObserversForMutation(observers, transientMutationObserverRegi
stry(), *this, type, attributeName); | 2094 collectMatchingObserversForMutation(observers, transientMutationObserverRegi
stry(), *this, type, attributeName); |
2090 for (Node* node = parentNode(); node; node = node->parentNode()) { | 2095 for (Node* node = parentNode(); node; node = node->parentNode()) { |
2091 collectMatchingObserversForMutation(observers, node->mutationObserverReg
istry(), *this, type, attributeName); | 2096 collectMatchingObserversForMutation(observers, node->mutationObserverReg
istry(), *this, type, attributeName); |
2092 collectMatchingObserversForMutation(observers, node->transientMutationOb
serverRegistry(), *this, type, attributeName); | 2097 collectMatchingObserversForMutation(observers, node->transientMutationOb
serverRegistry(), *this, type, attributeName); |
2093 } | 2098 } |
2094 } | 2099 } |
2095 | 2100 |
2096 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver
Options options, const HashSet<AtomicString>& attributeFilter) | 2101 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver
Options options, const HashSet<AtomicString>& attributeFilter) |
2097 { | 2102 { |
2098 MutationObserverRegistration* registration = 0; | 2103 MutationObserverRegistration* registration = 0; |
2099 Vector<OwnPtr<MutationObserverRegistration> >& registry = ensureRareData().e
nsureMutationObserverData().registry; | 2104 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >& registr
y = ensureRareData().ensureMutationObserverData().registry; |
2100 for (size_t i = 0; i < registry.size(); ++i) { | 2105 for (size_t i = 0; i < registry.size(); ++i) { |
2101 if (®istry[i]->observer() == &observer) { | 2106 if (®istry[i]->observer() == &observer) { |
2102 registration = registry[i].get(); | 2107 registration = registry[i].get(); |
2103 registration->resetObservation(options, attributeFilter); | 2108 registration->resetObservation(options, attributeFilter); |
2104 } | 2109 } |
2105 } | 2110 } |
2106 | 2111 |
2107 if (!registration) { | 2112 if (!registration) { |
2108 registry.append(MutationObserverRegistration::create(observer, *this, op
tions, attributeFilter)); | 2113 registry.append(MutationObserverRegistration::create(observer, *this, op
tions, attributeFilter)); |
2109 registration = registry.last().get(); | 2114 registration = registry.last().get(); |
2110 } | 2115 } |
2111 | 2116 |
2112 document().addMutationObserverTypes(registration->mutationTypes()); | 2117 document().addMutationObserverTypes(registration->mutationTypes()); |
2113 } | 2118 } |
2114 | 2119 |
2115 void Node::unregisterMutationObserver(MutationObserverRegistration* registration
) | 2120 void Node::unregisterMutationObserver(MutationObserverRegistration* registration
) |
2116 { | 2121 { |
2117 Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserverRe
gistry(); | 2122 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* registr
y = mutationObserverRegistry(); |
2118 ASSERT(registry); | 2123 ASSERT(registry); |
2119 if (!registry) | 2124 if (!registry) |
2120 return; | 2125 return; |
2121 | 2126 |
2122 size_t index = registry->find(registration); | 2127 size_t index = registry->find(registration); |
2123 ASSERT(index != kNotFound); | 2128 ASSERT(index != kNotFound); |
2124 if (index == kNotFound) | 2129 if (index == kNotFound) |
2125 return; | 2130 return; |
2126 | 2131 |
2127 // Deleting the registration may cause this node to be derefed, so we must m
ake sure the Vector operation completes | 2132 // Deleting the registration may cause this node to be derefed, so we must m
ake sure the Vector operation completes |
2128 // before that, in case |this| is destroyed (see MutationObserverRegistratio
n::m_registrationNodeKeepAlive). | 2133 // before that, in case |this| is destroyed (see MutationObserverRegistratio
n::m_registrationNodeKeepAlive). |
2129 // FIXME: Simplify the registration/transient registration logic to make thi
s understandable by humans. | 2134 // FIXME: Simplify the registration/transient registration logic to make thi
s understandable by humans. |
2130 RefPtr<Node> protect(this); | 2135 RefPtr<Node> protect(this); |
| 2136 // The explicit dispose() is motivated by Oilpan; the registration |
| 2137 // object needs to unregister itself promptly. |
| 2138 registration->dispose(); |
2131 registry->remove(index); | 2139 registry->remove(index); |
2132 } | 2140 } |
2133 | 2141 |
2134 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis
tration) | 2142 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis
tration) |
2135 { | 2143 { |
2136 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra
tion); | 2144 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra
tion); |
2137 } | 2145 } |
2138 | 2146 |
2139 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg
istration) | 2147 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg
istration) |
2140 { | 2148 { |
2141 HashSet<MutationObserverRegistration*>* transientRegistry = transientMutatio
nObserverRegistry(); | 2149 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* transi
entRegistry = transientMutationObserverRegistry(); |
2142 ASSERT(transientRegistry); | 2150 ASSERT(transientRegistry); |
2143 if (!transientRegistry) | 2151 if (!transientRegistry) |
2144 return; | 2152 return; |
2145 | 2153 |
2146 ASSERT(transientRegistry->contains(registration)); | 2154 ASSERT(transientRegistry->contains(registration)); |
2147 transientRegistry->remove(registration); | 2155 transientRegistry->remove(registration); |
2148 } | 2156 } |
2149 | 2157 |
2150 void Node::notifyMutationObserversNodeWillDetach() | 2158 void Node::notifyMutationObserversNodeWillDetach() |
2151 { | 2159 { |
2152 if (!document().hasMutationObservers()) | 2160 if (!document().hasMutationObservers()) |
2153 return; | 2161 return; |
2154 | 2162 |
2155 for (Node* node = parentNode(); node; node = node->parentNode()) { | 2163 for (Node* node = parentNode(); node; node = node->parentNode()) { |
2156 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = node->muta
tionObserverRegistry()) { | 2164 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >*
registry = node->mutationObserverRegistry()) { |
2157 const size_t size = registry->size(); | 2165 const size_t size = registry->size(); |
2158 for (size_t i = 0; i < size; ++i) | 2166 for (size_t i = 0; i < size; ++i) |
2159 registry->at(i)->observedSubtreeNodeWillDetach(*this); | 2167 registry->at(i)->observedSubtreeNodeWillDetach(*this); |
2160 } | 2168 } |
2161 | 2169 |
2162 if (HashSet<MutationObserverRegistration*>* transientRegistry = node->tr
ansientMutationObserverRegistry()) { | 2170 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >
* transientRegistry = node->transientMutationObserverRegistry()) { |
2163 for (HashSet<MutationObserverRegistration*>::iterator iter = transie
ntRegistry->begin(); iter != transientRegistry->end(); ++iter) | 2171 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistrati
on> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->en
d(); ++iter) |
2164 (*iter)->observedSubtreeNodeWillDetach(*this); | 2172 (*iter)->observedSubtreeNodeWillDetach(*this); |
2165 } | 2173 } |
2166 } | 2174 } |
2167 } | 2175 } |
2168 | 2176 |
2169 void Node::handleLocalEvents(Event* event) | 2177 void Node::handleLocalEvents(Event* event) |
2170 { | 2178 { |
2171 if (!hasEventTargetData()) | 2179 if (!hasEventTargetData()) |
2172 return; | 2180 return; |
2173 | 2181 |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2544 node->showTreeForThis(); | 2552 node->showTreeForThis(); |
2545 } | 2553 } |
2546 | 2554 |
2547 void showNodePath(const WebCore::Node* node) | 2555 void showNodePath(const WebCore::Node* node) |
2548 { | 2556 { |
2549 if (node) | 2557 if (node) |
2550 node->showNodePathForThis(); | 2558 node->showNodePathForThis(); |
2551 } | 2559 } |
2552 | 2560 |
2553 #endif | 2561 #endif |
OLD | NEW |