Chromium Code Reviews| 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 setFlag(HasRareDataFlag); | 321 setFlag(HasRareDataFlag); |
| 322 return *data; | 322 return *data; |
| 323 } | 323 } |
| 324 | 324 |
| 325 void Node::clearRareData() | 325 void Node::clearRareData() |
| 326 { | 326 { |
| 327 ASSERT(hasRareData()); | 327 ASSERT(hasRareData()); |
| 328 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi stry()->isEmpty()); | 328 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi stry()->isEmpty()); |
| 329 | 329 |
| 330 RenderObject* renderer = m_data.m_rareData->renderer(); | 330 RenderObject* renderer = m_data.m_rareData->renderer(); |
| 331 if (isElementNode()) | 331 if (isElementNode()) { |
| 332 delete static_cast<ElementRareData*>(m_data.m_rareData); | 332 ElementRareData* rareData = static_cast<ElementRareData*>(m_data.m_rareD ata); |
| 333 else | 333 rareData->dispose(); |
| 334 delete static_cast<NodeRareData*>(m_data.m_rareData); | 334 delete rareData; |
| 335 } else { | |
| 336 NodeRareData* rareData = static_cast<NodeRareData*>(m_data.m_rareData); | |
| 337 rareData->dispose(); | |
| 338 delete rareData; | |
| 339 } | |
| 335 m_data.m_renderer = renderer; | 340 m_data.m_renderer = renderer; |
| 336 clearFlag(HasRareDataFlag); | 341 clearFlag(HasRareDataFlag); |
| 337 } | 342 } |
| 338 | 343 |
| 339 Node* Node::toNode() | 344 Node* Node::toNode() |
| 340 { | 345 { |
| 341 return this; | 346 return this; |
| 342 } | 347 } |
| 343 | 348 |
| 344 short Node::tabIndex() const | 349 short Node::tabIndex() const |
| (...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1935 newController->didAddWheelEventHandler(document()); | 1940 newController->didAddWheelEventHandler(document()); |
| 1936 } | 1941 } |
| 1937 | 1942 |
| 1938 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) { | 1943 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) { |
| 1939 while (touchHandlers->contains(this)) { | 1944 while (touchHandlers->contains(this)) { |
| 1940 oldDocument.didRemoveTouchEventHandler(this); | 1945 oldDocument.didRemoveTouchEventHandler(this); |
| 1941 document().didAddTouchEventHandler(this); | 1946 document().didAddTouchEventHandler(this); |
| 1942 } | 1947 } |
| 1943 } | 1948 } |
| 1944 | 1949 |
| 1945 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserv erRegistry()) { | 1950 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* reg istry = mutationObserverRegistry()) { |
| 1946 for (size_t i = 0; i < registry->size(); ++i) { | 1951 for (size_t i = 0; i < registry->size(); ++i) { |
| 1947 document().addMutationObserverTypes(registry->at(i)->mutationTypes() ); | 1952 document().addMutationObserverTypes(registry->at(i)->mutationTypes() ); |
| 1948 } | 1953 } |
| 1949 } | 1954 } |
| 1950 | 1955 |
| 1951 if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMut ationObserverRegistry()) { | 1956 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* tr ansientRegistry = transientMutationObserverRegistry()) { |
| 1952 for (HashSet<MutationObserverRegistration*>::iterator iter = transientRe gistry->begin(); iter != transientRegistry->end(); ++iter) { | 1957 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->end(); ++iter) { |
| 1953 document().addMutationObserverTypes((*iter)->mutationTypes()); | 1958 document().addMutationObserverTypes((*iter)->mutationTypes()); |
| 1954 } | 1959 } |
| 1955 } | 1960 } |
| 1956 } | 1961 } |
| 1957 | 1962 |
| 1958 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture) | 1963 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture) |
| 1959 { | 1964 { |
| 1960 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re)) | 1965 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re)) |
| 1961 return false; | 1966 return false; |
| 1962 | 1967 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2032 EventTargetData* data = new EventTargetData; | 2037 EventTargetData* data = new EventTargetData; |
| 2033 eventTargetDataMap().set(this, adoptPtr(data)); | 2038 eventTargetDataMap().set(this, adoptPtr(data)); |
| 2034 return *data; | 2039 return *data; |
| 2035 } | 2040 } |
| 2036 | 2041 |
| 2037 void Node::clearEventTargetData() | 2042 void Node::clearEventTargetData() |
| 2038 { | 2043 { |
| 2039 eventTargetDataMap().remove(this); | 2044 eventTargetDataMap().remove(this); |
| 2040 } | 2045 } |
| 2041 | 2046 |
| 2042 Vector<OwnPtr<MutationObserverRegistration> >* Node::mutationObserverRegistry() | 2047 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* Node::mutat ionObserverRegistry() |
| 2043 { | 2048 { |
| 2044 if (!hasRareData()) | 2049 if (!hasRareData()) |
| 2045 return 0; | 2050 return 0; |
| 2046 NodeMutationObserverData* data = rareData()->mutationObserverData(); | 2051 NodeMutationObserverData* data = rareData()->mutationObserverData(); |
| 2047 if (!data) | 2052 if (!data) |
| 2048 return 0; | 2053 return 0; |
| 2049 return &data->registry; | 2054 return &data->registry; |
| 2050 } | 2055 } |
| 2051 | 2056 |
| 2052 HashSet<MutationObserverRegistration*>* Node::transientMutationObserverRegistry( ) | 2057 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* Node::tran sientMutationObserverRegistry() |
| 2053 { | 2058 { |
| 2054 if (!hasRareData()) | 2059 if (!hasRareData()) |
| 2055 return 0; | 2060 return 0; |
| 2056 NodeMutationObserverData* data = rareData()->mutationObserverData(); | 2061 NodeMutationObserverData* data = rareData()->mutationObserverData(); |
| 2057 if (!data) | 2062 if (!data) |
| 2058 return 0; | 2063 return 0; |
| 2059 return &data->transientRegistry; | 2064 return &data->transientRegistry; |
| 2060 } | 2065 } |
| 2061 | 2066 |
| 2062 template<typename Registry> | 2067 template<typename Registry> |
| 2063 static inline void collectMatchingObserversForMutation(HashMap<MutationObserver* , MutationRecordDeliveryOptions>& observers, Registry* registry, Node& target, M utationObserver::MutationType type, const QualifiedName* attributeName) | 2068 static inline void collectMatchingObserversForMutation(WillBeHeapHashMap<RawPtrW illBeMember<MutationObserver>, MutationRecordDeliveryOptions>& observers, Regist ry* registry, Node& target, MutationObserver::MutationType type, const Qualified Name* attributeName) |
| 2064 { | 2069 { |
| 2065 if (!registry) | 2070 if (!registry) |
| 2066 return; | 2071 return; |
| 2067 for (typename Registry::iterator iter = registry->begin(); iter != registry- >end(); ++iter) { | 2072 for (typename Registry::iterator iter = registry->begin(); iter != registry- >end(); ++iter) { |
| 2068 const MutationObserverRegistration& registration = **iter; | 2073 const MutationObserverRegistration& registration = **iter; |
| 2069 if (registration.shouldReceiveMutationFrom(target, type, attributeName)) { | 2074 if (registration.shouldReceiveMutationFrom(target, type, attributeName)) { |
| 2070 MutationRecordDeliveryOptions deliveryOptions = registration.deliver yOptions(); | 2075 MutationRecordDeliveryOptions deliveryOptions = registration.deliver yOptions(); |
| 2071 HashMap<MutationObserver*, MutationRecordDeliveryOptions>::AddResult result = observers.add(®istration.observer(), deliveryOptions); | 2076 WillBeHeapHashMap<RawPtrWillBeMember<MutationObserver>, MutationReco rdDeliveryOptions>::AddResult result = observers.add(®istration.observer(), d eliveryOptions); |
| 2072 if (!result.isNewEntry) | 2077 if (!result.isNewEntry) |
| 2073 result.storedValue->value |= deliveryOptions; | 2078 result.storedValue->value |= deliveryOptions; |
| 2074 } | 2079 } |
| 2075 } | 2080 } |
| 2076 } | 2081 } |
| 2077 | 2082 |
| 2078 void Node::getRegisteredMutationObserversOfType(HashMap<MutationObserver*, Mutat ionRecordDeliveryOptions>& observers, MutationObserver::MutationType type, const QualifiedName* attributeName) | 2083 void Node::getRegisteredMutationObserversOfType(WillBeHeapHashMap<RawPtrWillBeMe mber<MutationObserver>, MutationRecordDeliveryOptions>& observers, MutationObser ver::MutationType type, const QualifiedName* attributeName) |
| 2079 { | 2084 { |
| 2080 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); | 2085 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); |
| 2081 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), * this, type, attributeName); | 2086 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), * this, type, attributeName); |
| 2082 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), *this, type, attributeName); | 2087 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), *this, type, attributeName); |
| 2083 for (Node* node = parentNode(); node; node = node->parentNode()) { | 2088 for (Node* node = parentNode(); node; node = node->parentNode()) { |
| 2084 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), *this, type, attributeName); | 2089 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), *this, type, attributeName); |
| 2085 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), *this, type, attributeName); | 2090 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), *this, type, attributeName); |
| 2086 } | 2091 } |
| 2087 } | 2092 } |
| 2088 | 2093 |
| 2089 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter) | 2094 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter) |
| 2090 { | 2095 { |
| 2091 MutationObserverRegistration* registration = 0; | 2096 MutationObserverRegistration* registration = 0; |
| 2092 Vector<OwnPtr<MutationObserverRegistration> >& registry = ensureRareData().e nsureMutationObserverData().registry; | 2097 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >& registr y = ensureRareData().ensureMutationObserverData().registry; |
| 2093 for (size_t i = 0; i < registry.size(); ++i) { | 2098 for (size_t i = 0; i < registry.size(); ++i) { |
| 2094 if (®istry[i]->observer() == &observer) { | 2099 if (®istry[i]->observer() == &observer) { |
| 2095 registration = registry[i].get(); | 2100 registration = registry[i].get(); |
| 2096 registration->resetObservation(options, attributeFilter); | 2101 registration->resetObservation(options, attributeFilter); |
| 2097 } | 2102 } |
| 2098 } | 2103 } |
| 2099 | 2104 |
| 2100 if (!registration) { | 2105 if (!registration) { |
| 2101 registry.append(MutationObserverRegistration::create(observer, *this, op tions, attributeFilter)); | 2106 registry.append(MutationObserverRegistration::create(observer, *this, op tions, attributeFilter)); |
| 2102 registration = registry.last().get(); | 2107 registration = registry.last().get(); |
| 2103 } | 2108 } |
| 2104 | 2109 |
| 2105 document().addMutationObserverTypes(registration->mutationTypes()); | 2110 document().addMutationObserverTypes(registration->mutationTypes()); |
| 2106 } | 2111 } |
| 2107 | 2112 |
| 2108 void Node::unregisterMutationObserver(MutationObserverRegistration* registration ) | 2113 void Node::unregisterMutationObserver(MutationObserverRegistration* registration ) |
| 2109 { | 2114 { |
| 2110 Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserverRe gistry(); | 2115 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* registr y = mutationObserverRegistry(); |
| 2111 ASSERT(registry); | 2116 ASSERT(registry); |
| 2112 if (!registry) | 2117 if (!registry) |
| 2113 return; | 2118 return; |
| 2114 | 2119 |
| 2115 size_t index = registry->find(registration); | 2120 size_t index = registry->find(registration); |
| 2116 ASSERT(index != kNotFound); | 2121 ASSERT(index != kNotFound); |
| 2117 if (index == kNotFound) | 2122 if (index == kNotFound) |
| 2118 return; | 2123 return; |
| 2119 | 2124 |
| 2120 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes | 2125 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes |
| 2121 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive). | 2126 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive). |
| 2122 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans. | 2127 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans. |
| 2123 RefPtr<Node> protect(this); | 2128 RefPtr<Node> protect(this); |
| 2129 #if ENABLE(OILPAN) | |
|
haraken
2014/04/21 06:00:34
So I think it would be nice if we could drop the #
sof
2014/04/21 12:45:16
Done + adjusted the comment.
| |
| 2130 // Promptly dispose of the MutationObserverRegistration object. | |
| 2131 registration->dispose(); | |
| 2132 #endif | |
| 2124 registry->remove(index); | 2133 registry->remove(index); |
| 2125 } | 2134 } |
| 2126 | 2135 |
| 2127 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration) | 2136 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration) |
| 2128 { | 2137 { |
| 2129 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion); | 2138 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion); |
| 2130 } | 2139 } |
| 2131 | 2140 |
| 2132 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration) | 2141 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration) |
| 2133 { | 2142 { |
| 2134 HashSet<MutationObserverRegistration*>* transientRegistry = transientMutatio nObserverRegistry(); | 2143 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* transi entRegistry = transientMutationObserverRegistry(); |
| 2135 ASSERT(transientRegistry); | 2144 ASSERT(transientRegistry); |
| 2136 if (!transientRegistry) | 2145 if (!transientRegistry) |
| 2137 return; | 2146 return; |
| 2138 | 2147 |
| 2139 ASSERT(transientRegistry->contains(registration)); | 2148 ASSERT(transientRegistry->contains(registration)); |
| 2140 transientRegistry->remove(registration); | 2149 transientRegistry->remove(registration); |
| 2141 } | 2150 } |
| 2142 | 2151 |
| 2143 void Node::notifyMutationObserversNodeWillDetach() | 2152 void Node::notifyMutationObserversNodeWillDetach() |
| 2144 { | 2153 { |
| 2145 if (!document().hasMutationObservers()) | 2154 if (!document().hasMutationObservers()) |
| 2146 return; | 2155 return; |
| 2147 | 2156 |
| 2148 for (Node* node = parentNode(); node; node = node->parentNode()) { | 2157 for (Node* node = parentNode(); node; node = node->parentNode()) { |
| 2149 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = node->muta tionObserverRegistry()) { | 2158 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* registry = node->mutationObserverRegistry()) { |
| 2150 const size_t size = registry->size(); | 2159 const size_t size = registry->size(); |
| 2151 for (size_t i = 0; i < size; ++i) | 2160 for (size_t i = 0; i < size; ++i) |
| 2152 registry->at(i)->observedSubtreeNodeWillDetach(*this); | 2161 registry->at(i)->observedSubtreeNodeWillDetach(*this); |
| 2153 } | 2162 } |
| 2154 | 2163 |
| 2155 if (HashSet<MutationObserverRegistration*>* transientRegistry = node->tr ansientMutationObserverRegistry()) { | 2164 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> > * transientRegistry = node->transientMutationObserverRegistry()) { |
| 2156 for (HashSet<MutationObserverRegistration*>::iterator iter = transie ntRegistry->begin(); iter != transientRegistry->end(); ++iter) | 2165 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistrati on> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->en d(); ++iter) |
| 2157 (*iter)->observedSubtreeNodeWillDetach(*this); | 2166 (*iter)->observedSubtreeNodeWillDetach(*this); |
| 2158 } | 2167 } |
| 2159 } | 2168 } |
| 2160 } | 2169 } |
| 2161 | 2170 |
| 2162 void Node::handleLocalEvents(Event* event) | 2171 void Node::handleLocalEvents(Event* event) |
| 2163 { | 2172 { |
| 2164 if (!hasEventTargetData()) | 2173 if (!hasEventTargetData()) |
| 2165 return; | 2174 return; |
| 2166 | 2175 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2537 node->showTreeForThis(); | 2546 node->showTreeForThis(); |
| 2538 } | 2547 } |
| 2539 | 2548 |
| 2540 void showNodePath(const WebCore::Node* node) | 2549 void showNodePath(const WebCore::Node* node) |
| 2541 { | 2550 { |
| 2542 if (node) | 2551 if (node) |
| 2543 node->showNodePathForThis(); | 2552 node->showNodePathForThis(); |
| 2544 } | 2553 } |
| 2545 | 2554 |
| 2546 #endif | 2555 #endif |
| OLD | NEW |