[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

oliver at apple.com oliver at apple.com
Thu Apr 8 01:57:56 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit d4c01312375fcb02ac67e2e8df28ee4dc5070bf4
Author: oliver at apple.com <oliver at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Feb 24 07:14:05 2010 +0000

    2010-02-23  Geoff Garen  <ggaren at apple.com>
    
            Reviewed by Oliver Hunt.
    
            Simplify animation lifetime handling.  Previously we manually
            determined whether our base element was safe when we unregistered
            our listener, now we simply ensure that the base element itself
            registers and unregisters the animation listener.
    
            * svg/animation/SVGSMILElement.cpp:
            (WebCore::ConditionEventListener::create):
            (WebCore::ConditionEventListener::disconnectAnimation):
            (WebCore::ConditionEventListener::ConditionEventListener):
            (WebCore::ConditionEventListener::operator==):
            (WebCore::ConditionEventListener::handleEvent):
            (WebCore::SVGSMILElement::eventBaseFor):
            (WebCore::SVGSMILElement::connectConditions):
            (WebCore::SVGSMILElement::disconnectConditions):
            * svg/animation/SVGSMILElement.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55182 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index f606761..2c3979a 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,23 @@
+2010-02-23  Geoff Garen  <ggaren at apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        Simplify animation lifetime handling.  Previously we manually
+        determined whether our base element was safe when we unregistered
+        our listener, now we simply ensure that the base element itself
+        registers and unregisters the animation listener.
+
+        * svg/animation/SVGSMILElement.cpp:
+        (WebCore::ConditionEventListener::create):
+        (WebCore::ConditionEventListener::disconnectAnimation):
+        (WebCore::ConditionEventListener::ConditionEventListener):
+        (WebCore::ConditionEventListener::operator==):
+        (WebCore::ConditionEventListener::handleEvent):
+        (WebCore::SVGSMILElement::eventBaseFor):
+        (WebCore::SVGSMILElement::connectConditions):
+        (WebCore::SVGSMILElement::disconnectConditions):
+        * svg/animation/SVGSMILElement.h:
+
 2010-02-23  Dmitry Titov  <dimich at chromium.org>
 
         Reviewed by David Levin.
diff --git a/WebCore/svg/animation/SVGSMILElement.cpp b/WebCore/svg/animation/SVGSMILElement.cpp
index 3957b81..2bd33dd 100644
--- a/WebCore/svg/animation/SVGSMILElement.cpp
+++ b/WebCore/svg/animation/SVGSMILElement.cpp
@@ -56,9 +56,9 @@ static const double invalidCachedTime = -1.;
     
 class ConditionEventListener : public EventListener {
 public:
-    static PassRefPtr<ConditionEventListener> create(SVGSMILElement* animation, Element* eventBase, SVGSMILElement::Condition* condition)
+    static PassRefPtr<ConditionEventListener> create(SVGSMILElement* animation, SVGSMILElement::Condition* condition)
     {
-        return adoptRef(new ConditionEventListener(animation, eventBase, condition));
+        return adoptRef(new ConditionEventListener(animation, condition));
     }
 
     static const ConditionEventListener* cast(const EventListener* listener)
@@ -69,42 +69,38 @@ public:
     }
 
     virtual bool operator==(const EventListener& other);
-
-    void unregister()
+    
+    void disconnectAnimation()
     {
-        // If this has only one ref then the event base is dead already and we don't need to remove ourself.
-        if (!hasOneRef())
-            m_eventBase->removeEventListener(m_condition->m_name, this, false);
+        m_animation = 0;
     }
 
 private:
-    ConditionEventListener(SVGSMILElement* animation, Element* eventBase, SVGSMILElement::Condition* condition) 
+    ConditionEventListener(SVGSMILElement* animation, SVGSMILElement::Condition* condition) 
         : EventListener(ConditionEventListenerType)
         , m_animation(animation)
         , m_condition(condition) 
-        , m_eventBase(eventBase)
     {
-        m_eventBase->addEventListener(m_condition->m_name, this, false);
     }
 
     virtual void handleEvent(ScriptExecutionContext*, Event*);
 
     SVGSMILElement* m_animation;
     SVGSMILElement::Condition* m_condition;
-    Element* m_eventBase;
 };
 
 bool ConditionEventListener::operator==(const EventListener& listener)
 {
     if (const ConditionEventListener* conditionEventListener = ConditionEventListener::cast(&listener))
-        return m_animation == conditionEventListener->m_animation
-               && m_condition == conditionEventListener->m_condition
-               && m_eventBase == conditionEventListener->m_eventBase;
+        return m_animation == conditionEventListener->m_animation &&
+               m_condition == conditionEventListener->m_condition;
     return false;
 }
 
 void ConditionEventListener::handleEvent(ScriptExecutionContext*, Event* event) 
 {
+    if (!m_animation)
+        return;
     m_animation->handleConditionEvent(event, m_condition);
 }
 
@@ -394,6 +390,11 @@ void SVGSMILElement::attributeChanged(Attribute* attr, bool preserveDecls)
     }
 }
 
+inline Element* SVGSMILElement::eventBaseFor(const Condition& condition) const
+{
+    return condition.m_baseID.isEmpty() ? targetElement() : document()->getElementById(condition.m_baseID);
+}
+
 void SVGSMILElement::connectConditions()
 {
     if (m_conditionsConnected)
@@ -403,11 +404,12 @@ void SVGSMILElement::connectConditions()
         Condition& condition = m_conditions[n];
         if (condition.m_type == Condition::EventBase) {
             ASSERT(!condition.m_syncbase);
-            Element* eventBase = condition.m_baseID.isEmpty() ? targetElement() : document()->getElementById(condition.m_baseID);
+            Element* eventBase = eventBaseFor(condition);
             if (!eventBase)
                 continue;
             ASSERT(!condition.m_eventListener);
-            condition.m_eventListener = ConditionEventListener::create(this, eventBase, &condition);
+            condition.m_eventListener = ConditionEventListener::create(this, &condition);
+            eventBase->addEventListener(condition.m_name, condition.m_eventListener, false);
         } else if (condition.m_type == Condition::Syncbase) {
             ASSERT(!condition.m_baseID.isEmpty());
             condition.m_syncbase = document()->getElementById(condition.m_baseID);
@@ -430,10 +432,18 @@ void SVGSMILElement::disconnectConditions()
         Condition& condition = m_conditions[n];
         if (condition.m_type == Condition::EventBase) {
             ASSERT(!condition.m_syncbase);
-            if (condition.m_eventListener) {
-                condition.m_eventListener->unregister();
-                condition.m_eventListener = 0;
-            }
+            if (!condition.m_eventListener)
+                continue;
+            // Note: It's a memory optimization to try to remove our condition
+            // event listener, but it's not guaranteed to work, since we have
+            // no guarantee that eventBaseFor() will be able to find our condition's
+            // original eventBase. So, we also have to disconnect ourselves from
+            // our condition event listener, in case it later fires.
+            Element* eventBase = eventBaseFor(condition);
+            if (eventBase)
+                eventBase->removeEventListener(condition.m_name, condition.m_eventListener.get(), false);
+            condition.m_eventListener->disconnectAnimation();
+            condition.m_eventListener = 0;
         } else if (condition.m_type == Condition::Syncbase) {
             if (condition.m_syncbase) {
                 ASSERT(isSMILElement(condition.m_syncbase.get()));
diff --git a/WebCore/svg/animation/SVGSMILElement.h b/WebCore/svg/animation/SVGSMILElement.h
index b61f20d..8fcc2fc 100644
--- a/WebCore/svg/animation/SVGSMILElement.h
+++ b/WebCore/svg/animation/SVGSMILElement.h
@@ -133,7 +133,8 @@ private:
         };
         bool parseCondition(const String&, BeginOrEnd beginOrEnd);
         void parseBeginOrEnd(const String&, BeginOrEnd beginOrEnd);
-        
+        Element* eventBaseFor(const Condition&) const;
+
         void connectConditions();
         void disconnectConditions();
         

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list