| Index: Source/core/events/EventPath.cpp | 
| diff --git a/Source/core/events/EventPath.cpp b/Source/core/events/EventPath.cpp | 
| index 086d53cf7fc5e1aae91f3f3b4e6f902e88d37c8d..954ef21816a6447785378ee0d6785422412f5c61 100644 | 
| --- a/Source/core/events/EventPath.cpp | 
| +++ b/Source/core/events/EventPath.cpp | 
| @@ -204,27 +204,27 @@ void EventPath::calculateAdjustedEventPathForEachNode() | 
| } | 
|  | 
| #ifndef NDEBUG | 
| -static inline bool movedFromChildToParent(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope) | 
| +static inline bool movedFromOlderToYounger(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope) | 
| { | 
| -    return lastTreeScope.parentTreeScope() == ¤tTreeScope; | 
| +    Node* rootNode = lastTreeScope.rootNode(); | 
| +    return rootNode->isShadowRoot() && toShadowRoot(rootNode)->youngerShadowRoot() == currentTreeScope.rootNode(); | 
| } | 
|  | 
| -static inline bool movedFromOlderToYounger(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope) | 
| +static inline bool movedFromYoungerToOlder(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope) | 
| { | 
| Node* rootNode = lastTreeScope.rootNode(); | 
| -    return rootNode->isShadowRoot() && toShadowRoot(rootNode)->youngerShadowRoot() == currentTreeScope.rootNode(); | 
| +    return rootNode->isShadowRoot() && toShadowRoot(rootNode)->olderShadowRoot() == currentTreeScope.rootNode(); | 
| } | 
| #endif | 
|  | 
| -static inline bool movedFromParentToChild(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope) | 
| +static inline bool movedFromChildToParent(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope) | 
| { | 
| -    return currentTreeScope.parentTreeScope() == &lastTreeScope; | 
| +    return lastTreeScope.parentTreeScope() == ¤tTreeScope; | 
| } | 
|  | 
| -static inline bool movedFromYoungerToOlder(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope) | 
| +static inline bool movedFromParentToChild(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope) | 
| { | 
| -    Node* rootNode = lastTreeScope.rootNode(); | 
| -    return rootNode->isShadowRoot() && toShadowRoot(rootNode)->olderShadowRoot() == currentTreeScope.rootNode(); | 
| +    return currentTreeScope.parentTreeScope() == &lastTreeScope; | 
| } | 
|  | 
| void EventPath::calculateAdjustedTargets() | 
| @@ -239,14 +239,21 @@ void EventPath::calculateAdjustedTargets() | 
| if (targetStack.isEmpty()) { | 
| targetStack.append(current); | 
| } else if (*lastTreeScope != currentTreeScope && !isSVGElement) { | 
| -            if (movedFromParentToChild(*lastTreeScope, currentTreeScope) || movedFromYoungerToOlder(*lastTreeScope, currentTreeScope)) { | 
| +            if (movedFromParentToChild(*lastTreeScope, currentTreeScope)) { | 
| targetStack.append(targetStack.last()); | 
| +            } else if (movedFromChildToParent(*lastTreeScope, currentTreeScope)) { | 
| +                ASSERT(!targetStack.isEmpty()); | 
| +                targetStack.removeLast(); | 
| +                if (targetStack.isEmpty()) | 
| +                    targetStack.append(current); | 
| } else { | 
| -                ASSERT(movedFromChildToParent(*lastTreeScope, currentTreeScope) || movedFromOlderToYounger(*lastTreeScope, currentTreeScope)); | 
| +                ASSERT(movedFromYoungerToOlder(*lastTreeScope, currentTreeScope) || movedFromOlderToYounger(*lastTreeScope, currentTreeScope)); | 
| ASSERT(!targetStack.isEmpty()); | 
| targetStack.removeLast(); | 
| if (targetStack.isEmpty()) | 
| targetStack.append(current); | 
| +                else | 
| +                    targetStack.append(targetStack.last()); | 
| } | 
| } | 
| at(i).setTarget(eventTargetRespectingTargetRules(targetStack.last())); | 
|  |