Merge from Chromium at DEPS revision 251904

This commit was generated by merge_to_master.py.

Change-Id: I8ca36eee41eba7e9a56d6728a9d19e5883d7058c
diff --git a/Source/core/events/AutocompleteErrorEvent.h b/Source/core/events/AutocompleteErrorEvent.h
index 1eed01d..847f257 100644
--- a/Source/core/events/AutocompleteErrorEvent.h
+++ b/Source/core/events/AutocompleteErrorEvent.h
@@ -34,7 +34,7 @@
     String reason;
 };
 
-class AutocompleteErrorEvent : public Event {
+class AutocompleteErrorEvent FINAL : public Event {
 public:
     static PassRefPtr<AutocompleteErrorEvent> create()
     {
@@ -53,7 +53,7 @@
 
     const String& reason() const { return m_reason; }
 
-    virtual const AtomicString& interfaceName() const { return EventNames::AutocompleteErrorEvent; }
+    virtual const AtomicString& interfaceName() const OVERRIDE { return EventNames::AutocompleteErrorEvent; }
 
 private:
     AutocompleteErrorEvent()
diff --git a/Source/core/events/BeforeLoadEvent.h b/Source/core/events/BeforeLoadEvent.h
index f52c537..b7fc894 100644
--- a/Source/core/events/BeforeLoadEvent.h
+++ b/Source/core/events/BeforeLoadEvent.h
@@ -27,6 +27,7 @@
 #ifndef BeforeLoadEvent_h
 #define BeforeLoadEvent_h
 
+#include "RuntimeEnabledFeatures.h"
 #include "core/events/Event.h"
 #include "core/events/ThreadLocalEventNames.h"
 
@@ -40,7 +41,7 @@
     String url;
 };
 
-class BeforeLoadEvent : public Event {
+class BeforeLoadEvent FINAL : public Event {
 public:
     static PassRefPtr<BeforeLoadEvent> create()
     {
@@ -59,11 +60,12 @@
 
     const String& url() const { return m_url; }
 
-    virtual const AtomicString& interfaceName() const { return EventNames::BeforeLoadEvent; }
+    virtual const AtomicString& interfaceName() const OVERRIDE { return EventNames::BeforeLoadEvent; }
 
 private:
     BeforeLoadEvent()
     {
+        RELEASE_ASSERT(RuntimeEnabledFeatures::beforeLoadEnabled());
         ScriptWrappable::init(this);
     }
 
@@ -71,6 +73,7 @@
         : Event(EventTypeNames::beforeload, false, true)
         , m_url(url)
     {
+        RELEASE_ASSERT(RuntimeEnabledFeatures::beforeLoadEnabled());
         ScriptWrappable::init(this);
     }
 
@@ -78,6 +81,7 @@
         : Event(type, initializer)
         , m_url(initializer.url)
     {
+        RELEASE_ASSERT(RuntimeEnabledFeatures::beforeLoadEnabled());
         ScriptWrappable::init(this);
     }
 
diff --git a/Source/core/events/BeforeLoadEvent.idl b/Source/core/events/BeforeLoadEvent.idl
index 6f8eca6..b8758d7 100644
--- a/Source/core/events/BeforeLoadEvent.idl
+++ b/Source/core/events/BeforeLoadEvent.idl
@@ -25,6 +25,7 @@
  */
 
 [
+    RuntimeEnabled=BeforeLoad,
     EventConstructor,
 ] interface BeforeLoadEvent : Event {
     [InitializedByEventConstructor] readonly attribute DOMString url;
diff --git a/Source/core/events/BeforeTextInsertedEvent.h b/Source/core/events/BeforeTextInsertedEvent.h
index 546c4fb..44f0434 100644
--- a/Source/core/events/BeforeTextInsertedEvent.h
+++ b/Source/core/events/BeforeTextInsertedEvent.h
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-class BeforeTextInsertedEvent : public Event {
+class BeforeTextInsertedEvent FINAL : public Event {
 public:
     virtual ~BeforeTextInsertedEvent();
 
@@ -39,8 +39,8 @@
         return adoptRef(new BeforeTextInsertedEvent(text));
     }
 
-    virtual const AtomicString& interfaceName() const;
-    virtual bool isBeforeTextInsertedEvent() const { return true; }
+    virtual const AtomicString& interfaceName() const OVERRIDE;
+    virtual bool isBeforeTextInsertedEvent() const OVERRIDE { return true; }
 
     const String& text() const { return m_text; }
     void setText(const String& s) { m_text = s; }
diff --git a/Source/core/events/BeforeUnloadEvent.h b/Source/core/events/BeforeUnloadEvent.h
index 57136f9..7f7e881 100644
--- a/Source/core/events/BeforeUnloadEvent.h
+++ b/Source/core/events/BeforeUnloadEvent.h
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-class BeforeUnloadEvent : public Event {
+class BeforeUnloadEvent FINAL : public Event {
 public:
     virtual ~BeforeUnloadEvent();
 
diff --git a/Source/core/events/ClipboardEvent.cpp b/Source/core/events/ClipboardEvent.cpp
index a8fa4f9..849a64b 100644
--- a/Source/core/events/ClipboardEvent.cpp
+++ b/Source/core/events/ClipboardEvent.cpp
@@ -23,7 +23,7 @@
 #include "config.h"
 #include "core/events/ClipboardEvent.h"
 
-#include "core/dom/Clipboard.h"
+#include "core/clipboard/Clipboard.h"
 #include "core/events/ThreadLocalEventNames.h"
 
 namespace WebCore {
diff --git a/Source/core/events/ClipboardEvent.h b/Source/core/events/ClipboardEvent.h
index 671315b..d0d93c4 100644
--- a/Source/core/events/ClipboardEvent.h
+++ b/Source/core/events/ClipboardEvent.h
@@ -30,14 +30,10 @@
 
     class Clipboard;
 
-    class ClipboardEvent : public Event {
+    class ClipboardEvent FINAL : public Event {
     public:
         virtual ~ClipboardEvent();
 
-        static PassRefPtr<ClipboardEvent> create()
-        {
-            return adoptRef(new ClipboardEvent);
-        }
         static PassRefPtr<ClipboardEvent> create(const AtomicString& type, bool canBubbleArg, bool cancelableArg, PassRefPtr<Clipboard> clipboardArg)
         {
             return adoptRef(new ClipboardEvent(type, canBubbleArg, cancelableArg, clipboardArg));
diff --git a/Source/core/events/CompositionEvent.cpp b/Source/core/events/CompositionEvent.cpp
index f4ecff6..6281bdc 100644
--- a/Source/core/events/CompositionEvent.cpp
+++ b/Source/core/events/CompositionEvent.cpp
@@ -36,22 +36,31 @@
 }
 
 CompositionEvent::CompositionEvent()
+    : m_activeSegmentStart(0)
+    , m_activeSegmentEnd(0)
 {
     ScriptWrappable::init(this);
+    initializeSegments();
 }
 
-CompositionEvent::CompositionEvent(const AtomicString& type, PassRefPtr<AbstractView> view, const String& data)
+CompositionEvent::CompositionEvent(const AtomicString& type, PassRefPtr<AbstractView> view, const String& data, const Vector<CompositionUnderline>& underlines)
     : UIEvent(type, true, true, view, 0)
     , m_data(data)
+    , m_activeSegmentStart(0)
+    , m_activeSegmentEnd(0)
 {
     ScriptWrappable::init(this);
+    initializeSegments(&underlines);
 }
 
 CompositionEvent::CompositionEvent(const AtomicString& type, const CompositionEventInit& initializer)
     : UIEvent(type, initializer)
     , m_data(initializer.data)
+    , m_activeSegmentStart(0)
+    , m_activeSegmentEnd(0)
 {
     ScriptWrappable::init(this);
+    initializeSegments();
 }
 
 CompositionEvent::~CompositionEvent()
@@ -66,6 +75,29 @@
     initUIEvent(type, canBubble, cancelable, view, 0);
 
     m_data = data;
+    initializeSegments();
+}
+
+void CompositionEvent::initializeSegments(const Vector<CompositionUnderline>* underlines)
+{
+    m_activeSegmentStart = 0;
+    m_activeSegmentEnd = m_data.length();
+
+    if (!underlines || !underlines->size()) {
+        m_segments.append(0);
+        return;
+    }
+
+    for (size_t i = 0; i < underlines->size(); ++i) {
+        if (underlines->at(i).thick) {
+            m_activeSegmentStart = underlines->at(i).startOffset;
+            m_activeSegmentEnd = underlines->at(i).endOffset;
+            break;
+        }
+    }
+
+    for (size_t i = 0; i < underlines->size(); ++i)
+        m_segments.append(underlines->at(i).startOffset);
 }
 
 const AtomicString& CompositionEvent::interfaceName() const
diff --git a/Source/core/events/CompositionEvent.h b/Source/core/events/CompositionEvent.h
index c06da88..b3c1a74 100644
--- a/Source/core/events/CompositionEvent.h
+++ b/Source/core/events/CompositionEvent.h
@@ -27,6 +27,7 @@
 #ifndef CompositionEvent_h
 #define CompositionEvent_h
 
+#include "core/editing/CompositionUnderline.h"
 #include "core/events/UIEvent.h"
 
 namespace WebCore {
@@ -37,16 +38,16 @@
     String data;
 };
 
-class CompositionEvent : public UIEvent {
+class CompositionEvent FINAL : public UIEvent {
 public:
     static PassRefPtr<CompositionEvent> create()
     {
         return adoptRef(new CompositionEvent);
     }
 
-    static PassRefPtr<CompositionEvent> create(const AtomicString& type, PassRefPtr<AbstractView> view, const String& data)
+    static PassRefPtr<CompositionEvent> create(const AtomicString& type, PassRefPtr<AbstractView> view, const String& data, const Vector<CompositionUnderline>& underlines)
     {
-        return adoptRef(new CompositionEvent(type, view, data));
+        return adoptRef(new CompositionEvent(type, view, data, underlines));
     }
 
     static PassRefPtr<CompositionEvent> create(const AtomicString& type, const CompositionEventInit& initializer)
@@ -59,15 +60,22 @@
     void initCompositionEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, const String& data);
 
     String data() const { return m_data; }
+    int activeSegmentStart() const { return m_activeSegmentStart; }
+    int activeSegmentEnd() const { return m_activeSegmentEnd; }
+    const Vector<unsigned>& getSegments() const { return m_segments; }
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
 private:
     CompositionEvent();
-    CompositionEvent(const AtomicString& type, PassRefPtr<AbstractView>, const String&);
+    CompositionEvent(const AtomicString& type, PassRefPtr<AbstractView>, const String&, const Vector<CompositionUnderline>& underlines);
     CompositionEvent(const AtomicString& type, const CompositionEventInit&);
+    void initializeSegments(const Vector<CompositionUnderline>* = 0);
 
     String m_data;
+    int m_activeSegmentStart;
+    int m_activeSegmentEnd;
+    Vector<unsigned> m_segments;
 };
 
 } // namespace WebCore
diff --git a/Source/core/events/CompositionEvent.idl b/Source/core/events/CompositionEvent.idl
index 4e14a95..8b1d740 100644
--- a/Source/core/events/CompositionEvent.idl
+++ b/Source/core/events/CompositionEvent.idl
@@ -29,6 +29,10 @@
 
     [InitializedByEventConstructor] readonly attribute DOMString data;
 
+    [RuntimeEnabled=IMEAPI] readonly attribute long activeSegmentStart;
+    [RuntimeEnabled=IMEAPI] readonly attribute long activeSegmentEnd;
+    [RuntimeEnabled=IMEAPI] sequence<unsigned long> getSegments();
+
     void initCompositionEvent([Default=Undefined] optional DOMString typeArg,
                               [Default=Undefined] optional boolean canBubbleArg,
                               [Default=Undefined] optional boolean cancelableArg,
@@ -36,4 +40,3 @@
                               [Default=Undefined] optional DOMString dataArg);
 
 };
-
diff --git a/Source/core/events/CustomEvent.h b/Source/core/events/CustomEvent.h
index 9be0e11..8b855d7 100644
--- a/Source/core/events/CustomEvent.h
+++ b/Source/core/events/CustomEvent.h
@@ -34,7 +34,7 @@
 
 typedef EventInit CustomEventInit;
 
-class CustomEvent : public Event {
+class CustomEvent FINAL : public Event {
 public:
     virtual ~CustomEvent();
 
@@ -50,7 +50,7 @@
 
     void initCustomEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<SerializedScriptValue>);
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
     SerializedScriptValue* serializedDetail() { return m_serializedDetail.get(); }
 
diff --git a/Source/core/events/DOMWindowEventQueue.h b/Source/core/events/DOMWindowEventQueue.h
index f19e22b..23dbb93 100644
--- a/Source/core/events/DOMWindowEventQueue.h
+++ b/Source/core/events/DOMWindowEventQueue.h
@@ -41,7 +41,7 @@
 class Node;
 class ExecutionContext;
 
-class DOMWindowEventQueue : public RefCounted<DOMWindowEventQueue>, public EventQueue {
+class DOMWindowEventQueue FINAL : public RefCounted<DOMWindowEventQueue>, public EventQueue {
 public:
     static PassRefPtr<DOMWindowEventQueue> create(ExecutionContext*);
     virtual ~DOMWindowEventQueue();
diff --git a/Source/core/events/ErrorEvent.cpp b/Source/core/events/ErrorEvent.cpp
index 0bd32f4..5485e81 100644
--- a/Source/core/events/ErrorEvent.cpp
+++ b/Source/core/events/ErrorEvent.cpp
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "core/events/ErrorEvent.h"
 
+#include "bindings/v8/V8Binding.h"
 #include "core/events/ThreadLocalEventNames.h"
 
 namespace WebCore {
@@ -54,7 +55,7 @@
     , m_fileName(initializer.filename)
     , m_lineNumber(initializer.lineno)
     , m_columnNumber(initializer.colno)
-    , m_world(DOMWrapperWorld::current())
+    , m_world(DOMWrapperWorld::current(v8::Isolate::GetCurrent()))
 {
     ScriptWrappable::init(this);
 }
diff --git a/Source/core/events/ErrorEvent.h b/Source/core/events/ErrorEvent.h
index e0643e4..09912ec 100644
--- a/Source/core/events/ErrorEvent.h
+++ b/Source/core/events/ErrorEvent.h
@@ -47,7 +47,7 @@
     unsigned colno;
 };
 
-class ErrorEvent : public Event {
+class ErrorEvent FINAL : public Event {
 public:
     static PassRefPtr<ErrorEvent> create()
     {
@@ -76,7 +76,7 @@
     // 'messageForConsole' is not exposed to JavaScript, and prefers 'm_unsanitizedMessage'.
     const String& messageForConsole() const { return !m_unsanitizedMessage.isEmpty() ? m_unsanitizedMessage : m_sanitizedMessage; }
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
     PassRefPtr<DOMWrapperWorld> world() const { return m_world; }
 
diff --git a/Source/core/events/ErrorEvent.idl b/Source/core/events/ErrorEvent.idl
index f8e8e51..ad12285 100644
--- a/Source/core/events/ErrorEvent.idl
+++ b/Source/core/events/ErrorEvent.idl
@@ -35,6 +35,6 @@
     [InitializedByEventConstructor] readonly attribute DOMString filename;
     [InitializedByEventConstructor] readonly attribute unsigned long lineno;
     [InitializedByEventConstructor] readonly attribute unsigned long colno;
-    [Custom=Getter, InitializedByEventConstructor, Unserializable] readonly attribute any error;
+    [Custom=Getter, InitializedByEventConstructor] readonly attribute any error;
 };
 
diff --git a/Source/core/events/Event.cpp b/Source/core/events/Event.cpp
index 4ec6012..ee384a5 100644
--- a/Source/core/events/Event.cpp
+++ b/Source/core/events/Event.cpp
@@ -48,7 +48,6 @@
     , m_eventPhase(0)
     , m_currentTarget(0)
     , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
-    , m_eventPath(this)
 {
     ScriptWrappable::init(this);
 }
@@ -65,7 +64,6 @@
     , m_eventPhase(0)
     , m_currentTarget(0)
     , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
-    , m_eventPath(this)
 {
     ScriptWrappable::init(this);
 }
@@ -82,7 +80,6 @@
     , m_eventPhase(0)
     , m_currentTarget(0)
     , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
-    , m_eventPath(this)
 {
     ScriptWrappable::init(this);
 }
@@ -193,16 +190,23 @@
     m_underlyingEvent = ue;
 }
 
+EventPath& Event::ensureEventPath()
+{
+    if (!m_eventPath)
+        m_eventPath = adoptPtr(new EventPath(this));
+    return *m_eventPath;
+}
+
 PassRefPtr<NodeList> Event::path() const
 {
     if (!m_currentTarget || !m_currentTarget->toNode())
         return StaticNodeList::createEmpty();
     Node* node = m_currentTarget->toNode();
-    size_t eventPathSize = m_eventPath.size();
+    size_t eventPathSize = m_eventPath->size();
     for (size_t i = 0; i < eventPathSize; ++i) {
-        if (node == m_eventPath[i].node()) {
-            ASSERT(m_eventPath[i].eventPath());
-            return m_eventPath[i].eventPath();
+        if (node == (*m_eventPath)[i].node()) {
+            ASSERT((*m_eventPath)[i].eventPath());
+            return (*m_eventPath)[i].eventPath();
         }
     }
     return StaticNodeList::createEmpty();
diff --git a/Source/core/events/Event.h b/Source/core/events/Event.h
index b28f7f1..fab6c95 100644
--- a/Source/core/events/Event.h
+++ b/Source/core/events/Event.h
@@ -26,14 +26,12 @@
 
 #include "bindings/v8/ScriptWrappable.h"
 #include "core/dom/DOMTimeStamp.h"
-#include "core/events/EventContext.h"
 #include "core/events/EventPath.h"
 #include "wtf/RefCounted.h"
 #include "wtf/text/AtomicString.h"
 
 namespace WebCore {
 
-class Clipboard;
 class EventTarget;
 class EventDispatcher;
 class HTMLIFrameElement;
@@ -132,8 +130,6 @@
     bool legacyReturnValue() const { return !defaultPrevented(); }
     void setLegacyReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); }
 
-    Clipboard* clipboardData() const { return isClipboardEvent() ? clipboard() : 0; }
-
     virtual const AtomicString& interfaceName() const;
     bool hasInterface(const AtomicString&) const;
 
@@ -175,10 +171,10 @@
     Event* underlyingEvent() const { return m_underlyingEvent.get(); }
     void setUnderlyingEvent(PassRefPtr<Event>);
 
-    EventPath& eventPath() { return m_eventPath; }
-    PassRefPtr<NodeList> path() const;
+    EventPath& eventPath() { ASSERT(m_eventPath); return *m_eventPath; }
+    EventPath& ensureEventPath();
 
-    virtual Clipboard* clipboard() const { return 0; }
+    PassRefPtr<NodeList> path() const;
 
     bool isBeingDispatched() const { return eventPhase(); }
 
@@ -206,7 +202,7 @@
     RefPtr<EventTarget> m_target;
     DOMTimeStamp m_createTime;
     RefPtr<Event> m_underlyingEvent;
-    EventPath m_eventPath;
+    OwnPtr<EventPath> m_eventPath;
 };
 
 #define DEFINE_EVENT_TYPE_CASTS(typeName) \
diff --git a/Source/core/events/EventAliases.in b/Source/core/events/EventAliases.in
index 82b8e99..f5d9063 100644
--- a/Source/core/events/EventAliases.in
+++ b/Source/core/events/EventAliases.in
@@ -5,10 +5,10 @@
 KeyboardEvents ImplementedAs=KeyboardEvent
 MouseEvents ImplementedAs=MouseEvent
 MutationEvents ImplementedAs=MutationEvent
-OrientationEvent ImplementedAs=Event, Conditional=ORIENTATION_EVENTS
+OrientationEvent ImplementedAs=Event, RuntimeEnabled=OrientationEventEnabled
 SVGEvents ImplementedAs=Event
 SVGZoomEvents ImplementedAs=SVGZoomEvent
 UIEvents ImplementedAs=UIEvent
 WebKitTransitionEvent ImplementedAs=TransitionEvent
 
-core/dom/TouchEvent RuntimeEnabled=touchEnabled
+core/events/TouchEvent RuntimeEnabled=touchEnabled
diff --git a/Source/core/events/EventContext.cpp b/Source/core/events/EventContext.cpp
deleted file mode 100644
index 0adddcc..0000000
--- a/Source/core/events/EventContext.cpp
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2010 Google Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "config.h"
-#include "core/events/EventContext.h"
-
-#include "core/events/Event.h"
-#include "core/events/FocusEvent.h"
-#include "core/events/MouseEvent.h"
-#include "core/events/TouchEvent.h"
-#include "core/dom/TouchList.h"
-
-namespace WebCore {
-
-EventContext::EventContext(PassRefPtr<Node> node, PassRefPtr<EventTarget> currentTarget, PassRefPtr<EventTarget> target)
-    : m_node(node)
-    , m_currentTarget(currentTarget)
-    , m_target(target)
-{
-    ASSERT(m_node);
-    ASSERT(!isUnreachableNode(m_target.get()));
-}
-
-EventContext::~EventContext()
-{
-}
-
-void EventContext::adoptEventPath(Vector<RefPtr<Node> >& nodes)
-{
-    m_eventPath = StaticNodeList::adopt(nodes);
-}
-
-void EventContext::handleLocalEvents(Event* event) const
-{
-    event->setTarget(m_target.get());
-    event->setCurrentTarget(m_currentTarget.get());
-    m_node->handleLocalEvents(event);
-}
-
-bool EventContext::isMouseOrFocusEventContext() const
-{
-    return false;
-}
-
-bool EventContext::isTouchEventContext() const
-{
-    return false;
-}
-
-MouseOrFocusEventContext::MouseOrFocusEventContext(PassRefPtr<Node> node, PassRefPtr<EventTarget> currentTarget, PassRefPtr<EventTarget> target)
-    : EventContext(node, currentTarget, target)
-    , m_relatedTarget(0)
-{
-}
-
-MouseOrFocusEventContext::~MouseOrFocusEventContext()
-{
-}
-
-void MouseOrFocusEventContext::handleLocalEvents(Event* event) const
-{
-    ASSERT(event->isMouseEvent() || event->isFocusEvent());
-    if (m_relatedTarget.get() && event->isMouseEvent())
-        toMouseEvent(event)->setRelatedTarget(m_relatedTarget.get());
-    else if (m_relatedTarget.get() && event->isFocusEvent())
-        toFocusEvent(event)->setRelatedTarget(m_relatedTarget.get());
-    EventContext::handleLocalEvents(event);
-}
-
-bool MouseOrFocusEventContext::isMouseOrFocusEventContext() const
-{
-    return true;
-}
-
-TouchEventContext::TouchEventContext(PassRefPtr<Node> node, PassRefPtr<EventTarget> currentTarget, PassRefPtr<EventTarget> target)
-    : EventContext(node, currentTarget, target)
-    , m_touches(TouchList::create())
-    , m_targetTouches(TouchList::create())
-    , m_changedTouches(TouchList::create())
-{
-}
-
-TouchEventContext::~TouchEventContext()
-{
-}
-
-void TouchEventContext::handleLocalEvents(Event* event) const
-{
-#ifndef NDEBUG
-    checkReachability(m_touches.get());
-    checkReachability(m_targetTouches.get());
-    checkReachability(m_changedTouches.get());
-#endif
-    ASSERT(event->isTouchEvent());
-    TouchEvent* touchEvent = toTouchEvent(event);
-    touchEvent->setTouches(m_touches);
-    touchEvent->setTargetTouches(m_targetTouches);
-    touchEvent->setChangedTouches(m_changedTouches);
-    EventContext::handleLocalEvents(event);
-}
-
-bool TouchEventContext::isTouchEventContext() const
-{
-    return true;
-}
-
-#ifndef NDEBUG
-void TouchEventContext::checkReachability(TouchList* touchList) const
-{
-    for (size_t i = 0; i < touchList->length(); ++i)
-        ASSERT(touchList->item(i)->target()->toNode()->treeScope().isInclusiveAncestorOf(m_node->treeScope()));
-}
-#endif
-
-}
diff --git a/Source/core/events/EventContext.h b/Source/core/events/EventContext.h
deleted file mode 100644
index 09d1097..0000000
--- a/Source/core/events/EventContext.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2010 Google Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef EventContext_h
-#define EventContext_h
-
-#include "core/events/EventTarget.h"
-#include "core/dom/Node.h"
-#include "core/dom/StaticNodeList.h"
-#include "core/dom/TreeScope.h"
-#include "wtf/RefPtr.h"
-
-namespace WebCore {
-
-class Event;
-class TouchList;
-
-class EventContext {
-public:
-    // FIXME: Use ContainerNode instead of Node.
-    EventContext(PassRefPtr<Node>, PassRefPtr<EventTarget> currentTarget, PassRefPtr<EventTarget> target);
-    virtual ~EventContext();
-
-    Node* node() const { return m_node.get(); }
-    EventTarget* target() const { return m_target.get(); }
-    void setTarget(PassRefPtr<EventTarget> target) { m_target = target; }
-    PassRefPtr<NodeList> eventPath() const { return m_eventPath; }
-    void adoptEventPath(Vector<RefPtr<Node> >&);
-    void setEventPath(PassRefPtr<NodeList> nodeList) { m_eventPath = nodeList; }
-
-    bool currentTargetSameAsTarget() const { return m_currentTarget.get() == m_target.get(); }
-    virtual void handleLocalEvents(Event*) const;
-    virtual bool isMouseOrFocusEventContext() const;
-    virtual bool isTouchEventContext() const;
-
-protected:
-#ifndef NDEBUG
-    bool isUnreachableNode(EventTarget*);
-#endif
-    RefPtr<Node> m_node;
-    RefPtr<EventTarget> m_currentTarget;
-    RefPtr<EventTarget> m_target;
-    RefPtr<NodeList> m_eventPath;
-};
-
-class MouseOrFocusEventContext : public EventContext {
-public:
-    MouseOrFocusEventContext(PassRefPtr<Node>, PassRefPtr<EventTarget> currentTarget, PassRefPtr<EventTarget> target);
-    virtual ~MouseOrFocusEventContext();
-    EventTarget* relatedTarget() const { return m_relatedTarget.get(); }
-    void setRelatedTarget(PassRefPtr<EventTarget>);
-    virtual void handleLocalEvents(Event*) const OVERRIDE;
-    virtual bool isMouseOrFocusEventContext() const OVERRIDE;
-
-private:
-    RefPtr<EventTarget> m_relatedTarget;
-};
-
-
-class TouchEventContext : public EventContext {
-public:
-    TouchEventContext(PassRefPtr<Node>, PassRefPtr<EventTarget> currentTarget, PassRefPtr<EventTarget> target);
-    virtual ~TouchEventContext();
-
-    virtual void handleLocalEvents(Event*) const OVERRIDE;
-    virtual bool isTouchEventContext() const OVERRIDE;
-
-    TouchList* touches() { return m_touches.get(); }
-    TouchList* targetTouches() { return m_targetTouches.get(); }
-    TouchList* changedTouches() { return m_changedTouches.get(); }
-
-private:
-    RefPtr<TouchList> m_touches;
-    RefPtr<TouchList> m_targetTouches;
-    RefPtr<TouchList> m_changedTouches;
-#ifndef NDEBUG
-    void checkReachability(TouchList*) const;
-#endif
-};
-
-inline TouchEventContext& toTouchEventContext(EventContext& eventContext)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(eventContext.isTouchEventContext());
-    return static_cast<TouchEventContext&>(eventContext);
-}
-
-#ifndef NDEBUG
-inline bool EventContext::isUnreachableNode(EventTarget* target)
-{
-    // FIXME: Checks also for SVG elements.
-    return target && target->toNode() && !target->toNode()->isSVGElement() && !target->toNode()->treeScope().isInclusiveAncestorOf(m_node->treeScope());
-}
-#endif
-
-inline void MouseOrFocusEventContext::setRelatedTarget(PassRefPtr<EventTarget> relatedTarget)
-{
-    ASSERT(!isUnreachableNode(relatedTarget.get()));
-    m_relatedTarget = relatedTarget;
-}
-
-}
-
-#endif // EventContext_h
diff --git a/Source/core/events/EventDispatcher.cpp b/Source/core/events/EventDispatcher.cpp
index fa5698e..055273a 100644
--- a/Source/core/events/EventDispatcher.cpp
+++ b/Source/core/events/EventDispatcher.cpp
@@ -28,7 +28,6 @@
 
 #include "core/dom/ContainerNode.h"
 #include "core/events/EventDispatchMediator.h"
-#include "core/events/EventRetargeter.h"
 #include "core/events/MouseEvent.h"
 #include "core/events/ScopedEventQueue.h"
 #include "core/events/WindowEventContext.h"
@@ -60,7 +59,7 @@
     ASSERT(m_event.get());
     ASSERT(!m_event->type().isNull()); // JavaScript code can create an event with an empty name, but not null.
     m_view = node->document().view();
-    m_event->eventPath().resetWith(m_node.get());
+    m_event->ensureEventPath().resetWith(m_node.get());
 }
 
 void EventDispatcher::dispatchScopedEvent(Node* node, PassRefPtr<EventDispatchMediator> mediator)
@@ -109,7 +108,7 @@
     m_event->setTarget(EventPath::eventTargetRespectingTargetRules(m_node.get()));
     ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
     ASSERT(m_event->target());
-    WindowEventContext windowEventContext(m_event.get(), m_node.get(), topEventContext());
+    WindowEventContext windowEventContext(m_event.get(), m_node.get(), topNodeEventContext());
     InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchEvent(&m_node->document(), *m_event, windowEventContext.window(), m_node.get(), m_event->eventPath());
 
     void* preDispatchEventHandlerResult;
@@ -144,7 +143,7 @@
         return DoneDispatching;
 
     for (size_t i = m_event->eventPath().size() - 1; i > 0; --i) {
-        const EventContext& eventContext = m_event->eventPath()[i];
+        const NodeEventContext& eventContext = m_event->eventPath()[i];
         if (eventContext.currentTargetSameAsTarget())
             continue;
         eventContext.handleLocalEvents(m_event.get());
@@ -167,7 +166,7 @@
     // Trigger bubbling event handlers, starting at the bottom and working our way up.
     size_t size = m_event->eventPath().size();
     for (size_t i = 1; i < size; ++i) {
-        const EventContext& eventContext = m_event->eventPath()[i];
+        const NodeEventContext& eventContext = m_event->eventPath()[i];
         if (eventContext.currentTargetSameAsTarget())
             m_event->setEventPhase(Event::AT_TARGET);
         else if (m_event->bubbles() && !m_event->cancelBubble())
@@ -218,7 +217,7 @@
     }
 }
 
-const EventContext* EventDispatcher::topEventContext()
+const NodeEventContext* EventDispatcher::topNodeEventContext()
 {
     return m_event->eventPath().isEmpty() ? 0 : &m_event->eventPath().last();
 }
diff --git a/Source/core/events/EventDispatcher.h b/Source/core/events/EventDispatcher.h
index aae65a2..9fac66f 100644
--- a/Source/core/events/EventDispatcher.h
+++ b/Source/core/events/EventDispatcher.h
@@ -26,22 +26,17 @@
 #ifndef EventDispatcher_h
 #define EventDispatcher_h
 
-#include "core/events/EventContext.h"
 #include "core/dom/SimulatedClickOptions.h"
-#include "wtf/Forward.h"
 #include "wtf/PassRefPtr.h"
+#include "wtf/RefPtr.h"
 
 namespace WebCore {
 
 class Event;
 class EventDispatchMediator;
-class EventTarget;
 class FrameView;
 class Node;
-class PlatformKeyboardEvent;
-class PlatformMouseEvent;
-class ShadowRoot;
-class TreeScope;
+class NodeEventContext;
 class WindowEventContext;
 
 enum EventDispatchContinuation {
@@ -62,7 +57,7 @@
 
 private:
     EventDispatcher(Node*, PassRefPtr<Event>);
-    const EventContext* topEventContext();
+    const NodeEventContext* topNodeEventContext();
 
     EventDispatchContinuation dispatchEventPreProcess(void*& preDispatchEventHandlerResult);
     EventDispatchContinuation dispatchEventAtCapturing(WindowEventContext&);
diff --git a/Source/core/events/EventListener.h b/Source/core/events/EventListener.h
index 7829104..ea8bc44 100644
--- a/Source/core/events/EventListener.h
+++ b/Source/core/events/EventListener.h
@@ -43,6 +43,7 @@
         virtual bool operator==(const EventListener&) = 0;
         virtual void handleEvent(ExecutionContext*, Event*) = 0;
         virtual bool wasCreatedFromMarkup() const { return false; }
+        virtual bool belongsToTheCurrentWorld() const { return false; }
         virtual DOMWrapperWorld* world() const { return 0; }
 
         bool isAttribute() const { return virtualisAttribute(); }
diff --git a/Source/core/events/EventPath.cpp b/Source/core/events/EventPath.cpp
index 954ef21..c35c575 100644
--- a/Source/core/events/EventPath.cpp
+++ b/Source/core/events/EventPath.cpp
@@ -31,10 +31,14 @@
 #include "RuntimeEnabledFeatures.h"
 #include "SVGNames.h"
 #include "core/dom/FullscreenElementStack.h"
-#include "core/dom/shadow/ElementShadow.h"
+#include "core/dom/Touch.h"
+#include "core/dom/TouchList.h"
 #include "core/dom/shadow/InsertionPoint.h"
 #include "core/dom/shadow/ShadowRoot.h"
-#include "core/html/shadow/HTMLShadowElement.h"
+#include "core/events/FocusEvent.h"
+#include "core/events/MouseEvent.h"
+#include "core/events/TouchEvent.h"
+#include "core/events/TouchEventContext.h"
 #include "core/svg/SVGElementInstance.h"
 #include "core/svg/SVGUseElement.h"
 
@@ -58,8 +62,8 @@
 
     // Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
     // as a deeply cloned child of the 'use' element, except that events are dispatched to the SVGElementInstance objects.
-    Node* rootNode = referenceNode->treeScope().rootNode();
-    Element* shadowHostElement = rootNode->isShadowRoot() ? toShadowRoot(rootNode)->host() : 0;
+    Node& rootNode = referenceNode->treeScope().rootNode();
+    Element* shadowHostElement = rootNode.isShadowRoot() ? toShadowRoot(rootNode).host() : 0;
     // At this time, SVG nodes are not supported in non-<use> shadow trees.
     if (!shadowHostElement || !shadowHostElement->hasTagName(SVGNames::useTag))
         return referenceNode;
@@ -122,33 +126,26 @@
 {
     ASSERT(node);
     m_node = node;
-    m_eventContexts.clear();
+    m_nodeEventContexts.clear();
+    m_treeScopeEventContexts.clear();
     calculatePath();
     calculateAdjustedTargets();
-    calculateAdjustedEventPathForEachNode();
+    calculateAdjustedEventPath();
 }
 
-void EventPath::addEventContext(Node* node, bool isMouseOrFocusEvent, bool isTouchEvent)
+void EventPath::addNodeEventContext(Node* node)
 {
-    if (isMouseOrFocusEvent)
-        m_eventContexts.append(adoptPtr(new MouseOrFocusEventContext(node, eventTargetRespectingTargetRules(node), 0)));
-    else if (isTouchEvent)
-        m_eventContexts.append(adoptPtr(new TouchEventContext(node, eventTargetRespectingTargetRules(node), 0)));
-    else
-        m_eventContexts.append(adoptPtr(new EventContext(node, eventTargetRespectingTargetRules(node), 0)));
+    m_nodeEventContexts.append(NodeEventContext(node, eventTargetRespectingTargetRules(node)));
 }
 
 void EventPath::calculatePath()
 {
     ASSERT(m_node);
-    ASSERT(m_eventContexts.isEmpty());
+    ASSERT(m_nodeEventContexts.isEmpty());
     m_node->document().updateDistributionForNodeIfNeeded(const_cast<Node*>(m_node));
 
-    bool isMouseOrFocusEvent = m_event && (m_event->isMouseEvent() || m_event->isFocusEvent());
-    bool isTouchEvent = m_event && m_event->isTouchEvent();
-
     Node* current = m_node;
-    addEventContext(current, isMouseOrFocusEvent, isTouchEvent);
+    addNodeEventContext(current);
     if (!m_node->inDocument())
         return;
     while (current) {
@@ -163,102 +160,218 @@
                     ShadowRoot* containingShadowRoot = insertionPoint->containingShadowRoot();
                     ASSERT(containingShadowRoot);
                     if (!containingShadowRoot->isOldest())
-                        addEventContext(containingShadowRoot->olderShadowRoot(), isMouseOrFocusEvent, isTouchEvent);
+                        addNodeEventContext(containingShadowRoot->olderShadowRoot());
                 }
-                addEventContext(insertionPoint, isMouseOrFocusEvent, isTouchEvent);
+                addNodeEventContext(insertionPoint);
             }
             current = insertionPoints.last();
             continue;
         }
         if (current->isShadowRoot()) {
             current = current->shadowHost();
-            addEventContext(current, isMouseOrFocusEvent, isTouchEvent);
+            addNodeEventContext(current);
         } else {
             current = current->parentNode();
             if (current)
-                addEventContext(current, isMouseOrFocusEvent, isTouchEvent);
+                addNodeEventContext(current);
         }
     }
 }
 
-void EventPath::calculateAdjustedEventPathForEachNode()
+void EventPath::calculateAdjustedEventPath()
 {
     if (!RuntimeEnabledFeatures::shadowDOMEnabled())
         return;
-    TreeScope* lastScope = 0;
-    for (size_t i = 0; i < size(); ++i) {
-        TreeScope* currentScope = &at(i).node()->treeScope();
-        if (currentScope == lastScope) {
-            // Fast path.
-            at(i).setEventPath(at(i - 1).eventPath());
-            continue;
-        }
-        lastScope = currentScope;
+    for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) {
+        TreeScopeEventContext* treeScopeEventContext = m_treeScopeEventContexts[i].get();
         Vector<RefPtr<Node> > nodes;
-        for (size_t j = 0; j < size(); ++j) {
-            if (at(j).node()->treeScope().isInclusiveAncestorOf(*currentScope))
-                nodes.append(at(j).node());
+        nodes.reserveInitialCapacity(size());
+        for (size_t i = 0; i < size(); ++i) {
+            if (at(i).node()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(treeScopeEventContext->treeScope())) {
+                ASSERT(!at(i).node()->containingShadowRoot()
+                    || at(i).node()->treeScope() == treeScopeEventContext->treeScope()
+                    || toShadowRoot(treeScopeEventContext->treeScope().rootNode()).type() == ShadowRoot::UserAgentShadowRoot
+                    || at(i).node()->containingShadowRoot()->type() != ShadowRoot::UserAgentShadowRoot);
+                nodes.append(at(i).node());
+            }
         }
-        at(i).adoptEventPath(nodes);
+        treeScopeEventContext->adoptEventPath(nodes);
     }
 }
 
-#ifndef NDEBUG
-static inline bool movedFromOlderToYounger(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope)
+TreeScopeEventContext* EventPath::ensureTreeScopeEventContext(Node* currentTarget, TreeScope* treeScope, TreeScopeEventContextMap& treeScopeEventContextMap)
 {
-    Node* rootNode = lastTreeScope.rootNode();
-    return rootNode->isShadowRoot() && toShadowRoot(rootNode)->youngerShadowRoot() == currentTreeScope.rootNode();
-}
-
-static inline bool movedFromYoungerToOlder(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope)
-{
-    Node* rootNode = lastTreeScope.rootNode();
-    return rootNode->isShadowRoot() && toShadowRoot(rootNode)->olderShadowRoot() == currentTreeScope.rootNode();
-}
-#endif
-
-static inline bool movedFromChildToParent(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope)
-{
-    return lastTreeScope.parentTreeScope() == &currentTreeScope;
-}
-
-static inline bool movedFromParentToChild(const TreeScope& lastTreeScope, const TreeScope& currentTreeScope)
-{
-    return currentTreeScope.parentTreeScope() == &lastTreeScope;
+    if (!treeScope)
+        return 0;
+    TreeScopeEventContextMap::AddResult addResult = treeScopeEventContextMap.add(treeScope, TreeScopeEventContext::create(*treeScope));
+    TreeScopeEventContext* treeScopeEventContext = addResult.storedValue->value.get();
+    if (addResult.isNewEntry) {
+        TreeScopeEventContext* parentTreeScopeEventContext = ensureTreeScopeEventContext(0, treeScope->olderShadowRootOrParentTreeScope(), treeScopeEventContextMap);
+        if (parentTreeScopeEventContext && parentTreeScopeEventContext->target()) {
+            treeScopeEventContext->setTarget(parentTreeScopeEventContext->target());
+        } else if (currentTarget) {
+            treeScopeEventContext->setTarget(eventTargetRespectingTargetRules(currentTarget));
+        }
+    } else if (!treeScopeEventContext->target() && currentTarget) {
+        treeScopeEventContext->setTarget(eventTargetRespectingTargetRules(currentTarget));
+    }
+    return treeScopeEventContext;
 }
 
 void EventPath::calculateAdjustedTargets()
 {
-    Vector<Node*, 32> targetStack;
     const TreeScope* lastTreeScope = 0;
     bool isSVGElement = at(0).node()->isSVGElement();
 
+    TreeScopeEventContextMap treeScopeEventContextMap;
+    TreeScopeEventContext* lastTreeScopeEventContext = 0;
+
     for (size_t i = 0; i < size(); ++i) {
-        Node* current = at(i).node();
-        const TreeScope& currentTreeScope = current->treeScope();
-        if (targetStack.isEmpty()) {
-            targetStack.append(current);
-        } else if (*lastTreeScope != currentTreeScope && !isSVGElement) {
-            if (movedFromParentToChild(*lastTreeScope, currentTreeScope)) {
-                targetStack.append(targetStack.last());
-            } else if (movedFromChildToParent(*lastTreeScope, currentTreeScope)) {
-                ASSERT(!targetStack.isEmpty());
-                targetStack.removeLast();
-                if (targetStack.isEmpty())
-                    targetStack.append(current);
+        Node* currentNode = at(i).node();
+        TreeScope& currentTreeScope = currentNode->treeScope();
+        if (lastTreeScope != &currentTreeScope) {
+            if (!isSVGElement) {
+                lastTreeScopeEventContext = ensureTreeScopeEventContext(currentNode, &currentTreeScope, treeScopeEventContextMap);
             } else {
-                ASSERT(movedFromYoungerToOlder(*lastTreeScope, currentTreeScope) || movedFromOlderToYounger(*lastTreeScope, currentTreeScope));
-                ASSERT(!targetStack.isEmpty());
-                targetStack.removeLast();
-                if (targetStack.isEmpty())
-                    targetStack.append(current);
-                else
-                    targetStack.append(targetStack.last());
+                TreeScopeEventContextMap::AddResult addResult = treeScopeEventContextMap.add(&currentTreeScope, TreeScopeEventContext::create(currentTreeScope));
+                lastTreeScopeEventContext = addResult.storedValue->value.get();
+                if (addResult.isNewEntry) {
+                    // Don't adjust an event target for SVG.
+                    lastTreeScopeEventContext->setTarget(eventTargetRespectingTargetRules(at(0).node()));
+                }
             }
         }
-        at(i).setTarget(eventTargetRespectingTargetRules(targetStack.last()));
+        ASSERT(lastTreeScopeEventContext);
+        at(i).setTreeScopeEventContext(lastTreeScopeEventContext);
         lastTreeScope = &currentTreeScope;
     }
+    m_treeScopeEventContexts.appendRange(treeScopeEventContextMap.values().begin(), treeScopeEventContextMap.values().end());
 }
 
+void EventPath::buildRelatedNodeMap(const Node* relatedNode, RelatedTargetMap& relatedTargetMap)
+{
+    EventPath relatedTargetEventPath(const_cast<Node*>(relatedNode));
+    for (size_t i = 0; i < relatedTargetEventPath.m_treeScopeEventContexts.size(); ++i) {
+        TreeScopeEventContext* treeScopeEventContext = relatedTargetEventPath.m_treeScopeEventContexts[i].get();
+        relatedTargetMap.add(&treeScopeEventContext->treeScope(), treeScopeEventContext->target());
+    }
+}
+
+EventTarget* EventPath::findRelatedNode(TreeScope* scope, RelatedTargetMap& relatedTargetMap)
+{
+    Vector<TreeScope*, 32> parentTreeScopes;
+    EventTarget* relatedNode = 0;
+    while (scope) {
+        parentTreeScopes.append(scope);
+        RelatedTargetMap::const_iterator iter = relatedTargetMap.find(scope);
+        if (iter != relatedTargetMap.end() && iter->value) {
+            relatedNode = iter->value;
+            break;
+        }
+        scope = scope->olderShadowRootOrParentTreeScope();
+    }
+    ASSERT(relatedNode);
+    for (Vector<TreeScope*, 32>::iterator iter = parentTreeScopes.begin(); iter < parentTreeScopes.end(); ++iter)
+        relatedTargetMap.add(*iter, relatedNode);
+    return relatedNode;
+}
+
+void EventPath::adjustForRelatedTarget(Node* target, EventTarget* relatedTarget)
+{
+    if (!target)
+        return;
+    if (!relatedTarget)
+        return;
+    Node* relatedNode = relatedTarget->toNode();
+    if (!relatedNode)
+        return;
+    if (target->document() != relatedNode->document())
+        return;
+    if (!target->inDocument() || !relatedNode->inDocument())
+        return;
+
+    RelatedTargetMap relatedNodeMap;
+    buildRelatedNodeMap(relatedNode, relatedNodeMap);
+
+    for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) {
+        TreeScopeEventContext* treeScopeEventContext = m_treeScopeEventContexts[i].get();
+        EventTarget* adjustedRelatedTarget = findRelatedNode(&treeScopeEventContext->treeScope(), relatedNodeMap);
+        ASSERT(adjustedRelatedTarget);
+        treeScopeEventContext->setRelatedTarget(adjustedRelatedTarget);
+    }
+
+    shrinkIfNeeded(target, relatedTarget);
+}
+
+void EventPath::shrinkIfNeeded(const Node* target, const EventTarget* relatedTarget)
+{
+    // Synthetic mouse events can have a relatedTarget which is identical to the target.
+    bool targetIsIdenticalToToRelatedTarget = (target == relatedTarget);
+
+    for (size_t i = 0; i < size(); ++i) {
+        if (targetIsIdenticalToToRelatedTarget) {
+            if (target->treeScope().rootNode() == at(i).node()) {
+                shrink(i + 1);
+                break;
+            }
+        } else if (at(i).target() == at(i).relatedTarget()) {
+            // Event dispatching should be stopped here.
+            shrink(i);
+            break;
+        }
+    }
+}
+
+void EventPath::adjustForTouchEvent(Node* node, TouchEvent& touchEvent)
+{
+    Vector<TouchList*> adjustedTouches;
+    Vector<TouchList*> adjustedTargetTouches;
+    Vector<TouchList*> adjustedChangedTouches;
+    Vector<TreeScope*> treeScopes;
+
+    for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) {
+        TouchEventContext* touchEventContext = m_treeScopeEventContexts[i]->ensureTouchEventContext();
+        adjustedTouches.append(&touchEventContext->touches());
+        adjustedTargetTouches.append(&touchEventContext->targetTouches());
+        adjustedChangedTouches.append(&touchEventContext->changedTouches());
+        treeScopes.append(&m_treeScopeEventContexts[i]->treeScope());
+    }
+
+    adjustTouchList(node, touchEvent.touches(), adjustedTouches, treeScopes);
+    adjustTouchList(node, touchEvent.targetTouches(), adjustedTargetTouches, treeScopes);
+    adjustTouchList(node, touchEvent.changedTouches(), adjustedChangedTouches, treeScopes);
+
+#ifndef NDEBUG
+    for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) {
+        TreeScope& treeScope = m_treeScopeEventContexts[i]->treeScope();
+        TouchEventContext* touchEventContext = m_treeScopeEventContexts[i]->touchEventContext();
+        checkReachability(treeScope, touchEventContext->touches());
+        checkReachability(treeScope, touchEventContext->targetTouches());
+        checkReachability(treeScope, touchEventContext->changedTouches());
+    }
+#endif
+}
+
+void EventPath::adjustTouchList(const Node* node, const TouchList* touchList, Vector<TouchList*> adjustedTouchList, const Vector<TreeScope*>& treeScopes)
+{
+    if (!touchList)
+        return;
+    for (size_t i = 0; i < touchList->length(); ++i) {
+        const Touch& touch = *touchList->item(i);
+        RelatedTargetMap relatedNodeMap;
+        buildRelatedNodeMap(touch.target()->toNode(), relatedNodeMap);
+        for (size_t j = 0; j < treeScopes.size(); ++j) {
+            adjustedTouchList[j]->append(touch.cloneWithNewTarget(findRelatedNode(treeScopes[j], relatedNodeMap)));
+        }
+    }
+}
+
+#ifndef NDEBUG
+void EventPath::checkReachability(TreeScope& treeScope, TouchList& touchList)
+{
+    for (size_t i = 0; i < touchList.length(); ++i)
+        ASSERT(touchList.item(i)->target()->toNode()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(treeScope));
+}
+#endif
+
 } // namespace
diff --git a/Source/core/events/EventPath.h b/Source/core/events/EventPath.h
index 5df0d5d..b29f2b6 100644
--- a/Source/core/events/EventPath.h
+++ b/Source/core/events/EventPath.h
@@ -27,15 +27,20 @@
 #ifndef EventPath_h
 #define EventPath_h
 
-#include "wtf/OwnPtr.h"
+#include "core/events/NodeEventContext.h"
+#include "core/events/TreeScopeEventContext.h"
+
+#include "wtf/HashMap.h"
 #include "wtf/Vector.h"
 
 namespace WebCore {
 
 class Event;
-class EventContext;
 class EventTarget;
 class Node;
+class TouchEvent;
+class TouchList;
+class TreeScope;
 
 enum EventDispatchBehavior {
     RetargetEvent,
@@ -48,14 +53,15 @@
     explicit EventPath(Node*);
     void resetWith(Node*);
 
-    EventContext& operator[](size_t index) { return *m_eventContexts[index]; }
-    const EventContext& operator[](size_t index) const { return *m_eventContexts[index]; }
-    EventContext& last() const { return *m_eventContexts[size() - 1]; }
+    NodeEventContext& operator[](size_t index) { return m_nodeEventContexts[index]; }
+    const NodeEventContext& operator[](size_t index) const { return m_nodeEventContexts[index]; }
+    const NodeEventContext& last() const { return m_nodeEventContexts[size() - 1]; }
 
-    bool isEmpty() const { return m_eventContexts.isEmpty(); }
-    size_t size() const { return m_eventContexts.size(); }
+    bool isEmpty() const { return m_nodeEventContexts.isEmpty(); }
+    size_t size() const { return m_nodeEventContexts.size(); }
 
-    void shrink(size_t newSize) { m_eventContexts.shrink(newSize); }
+    void adjustForRelatedTarget(Node*, EventTarget* relatedTarget);
+    void adjustForTouchEvent(Node*, TouchEvent&);
 
     static Node* parent(Node*);
     static EventTarget* eventTargetRespectingTargetRules(Node*);
@@ -63,17 +69,35 @@
 private:
     EventPath();
 
-    EventContext& at(size_t index) { return *m_eventContexts[index]; }
+    NodeEventContext& at(size_t index) { return m_nodeEventContexts[index]; }
 
-    void addEventContext(Node*, bool isMouseOrFocusEvent, bool isTouchEvent);
+    void addNodeEventContext(Node*);
 
     void calculatePath();
     void calculateAdjustedTargets();
-    void calculateAdjustedEventPathForEachNode();
+    void calculateAdjustedEventPath();
 
-    Vector<OwnPtr<EventContext>, 32> m_eventContexts;
+    void shrink(size_t newSize) { m_nodeEventContexts.shrink(newSize); }
+    void shrinkIfNeeded(const Node* target, const EventTarget* relatedTarget);
+
+    void adjustTouchList(const Node*, const TouchList*, Vector<TouchList*> adjustedTouchList, const Vector<TreeScope*>& treeScopes);
+
+    typedef HashMap<TreeScope*, RefPtr<TreeScopeEventContext> > TreeScopeEventContextMap;
+    TreeScopeEventContext* ensureTreeScopeEventContext(Node* currentTarget, TreeScope*, TreeScopeEventContextMap&);
+
+    typedef HashMap<TreeScope*, EventTarget*> RelatedTargetMap;
+
+    static void buildRelatedNodeMap(const Node*, RelatedTargetMap&);
+    static EventTarget* findRelatedNode(TreeScope*, RelatedTargetMap&);
+
+#ifndef NDEBUG
+    static void checkReachability(TreeScope&, TouchList&);
+#endif
+
+    Vector<NodeEventContext, 64> m_nodeEventContexts;
     Node* m_node;
     Event* m_event;
+    Vector<RefPtr<TreeScopeEventContext> > m_treeScopeEventContexts;
 };
 
 } // namespace
diff --git a/Source/core/events/EventRetargeter.cpp b/Source/core/events/EventRetargeter.cpp
deleted file mode 100644
index 4281150..0000000
--- a/Source/core/events/EventRetargeter.cpp
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "core/events/EventRetargeter.h"
-
-#include "RuntimeEnabledFeatures.h"
-#include "core/dom/ContainerNode.h"
-#include "core/dom/FullscreenElementStack.h"
-#include "core/dom/Touch.h"
-#include "core/dom/TouchList.h"
-#include "core/dom/TreeScope.h"
-#include "core/dom/shadow/InsertionPoint.h"
-#include "core/dom/shadow/ShadowRoot.h"
-#include "core/events/EventContext.h"
-#include "core/events/EventPath.h"
-#include "core/events/FocusEvent.h"
-#include "core/events/MouseEvent.h"
-#include "core/events/TouchEvent.h"
-#include "wtf/PassRefPtr.h"
-
-namespace WebCore {
-
-void EventRetargeter::adjustForMouseEvent(Node* node, MouseEvent& mouseEvent)
-{
-    adjustForRelatedTarget(node, mouseEvent.relatedTarget(), mouseEvent.eventPath());
-}
-
-void EventRetargeter::adjustForFocusEvent(Node* node, FocusEvent& focusEvent)
-{
-    adjustForRelatedTarget(node, focusEvent.relatedTarget(), focusEvent.eventPath());
-}
-
-void EventRetargeter::adjustForTouchEvent(Node* node, TouchEvent& touchEvent)
-{
-    EventPath& eventPath = touchEvent.eventPath();
-    size_t eventPathSize = eventPath.size();
-
-    EventPathTouchLists eventPathTouches(eventPathSize);
-    EventPathTouchLists eventPathTargetTouches(eventPathSize);
-    EventPathTouchLists eventPathChangedTouches(eventPathSize);
-
-    for (size_t i = 0; i < eventPathSize; ++i) {
-        ASSERT(eventPath[i].isTouchEventContext());
-        TouchEventContext& touchEventContext = toTouchEventContext(eventPath[i]);
-        eventPathTouches[i] = touchEventContext.touches();
-        eventPathTargetTouches[i] = touchEventContext.targetTouches();
-        eventPathChangedTouches[i] = touchEventContext.changedTouches();
-    }
-
-    adjustTouchList(node, touchEvent.touches(), eventPath, eventPathTouches);
-    adjustTouchList(node, touchEvent.targetTouches(), eventPath, eventPathTargetTouches);
-    adjustTouchList(node, touchEvent.changedTouches(), eventPath, eventPathChangedTouches);
-}
-
-void EventRetargeter::adjustTouchList(const Node* node, const TouchList* touchList, const EventPath& eventPath, EventPathTouchLists& eventPathTouchLists)
-{
-    if (!touchList)
-        return;
-    size_t eventPathSize = eventPath.size();
-    ASSERT(eventPathTouchLists.size() == eventPathSize);
-    for (size_t i = 0; i < touchList->length(); ++i) {
-        const Touch& touch = *touchList->item(i);
-        AdjustedTargets adjustedNodes;
-        calculateAdjustedNodes(node, touch.target()->toNode(), DoesNotStopAtBoundary, const_cast<EventPath&>(eventPath), adjustedNodes);
-        ASSERT(adjustedNodes.size() == eventPathSize);
-        for (size_t j = 0; j < eventPathSize; ++j)
-            eventPathTouchLists[j]->append(touch.cloneWithNewTarget(adjustedNodes[j].get()));
-    }
-}
-
-void EventRetargeter::adjustForRelatedTarget(const Node* node, EventTarget* relatedTarget, EventPath& eventPath)
-{
-    if (!node)
-        return;
-    if (!relatedTarget)
-        return;
-    Node* relatedNode = relatedTarget->toNode();
-    if (!relatedNode)
-        return;
-    AdjustedTargets adjustedNodes;
-    calculateAdjustedNodes(node, relatedNode, StopAtBoundaryIfNeeded, eventPath, adjustedNodes);
-    ASSERT(adjustedNodes.size() <= eventPath.size());
-    for (size_t i = 0; i < adjustedNodes.size(); ++i) {
-        ASSERT(eventPath[i].isMouseOrFocusEventContext());
-        MouseOrFocusEventContext& mouseOrFocusEventContext = static_cast<MouseOrFocusEventContext&>(eventPath[i]);
-        mouseOrFocusEventContext.setRelatedTarget(adjustedNodes[i]);
-    }
-}
-
-void EventRetargeter::calculateAdjustedNodes(const Node* node, const Node* relatedNode, EventWithRelatedTargetDispatchBehavior eventWithRelatedTargetDispatchBehavior, EventPath& eventPath, AdjustedTargets& adjustedTargets)
-{
-    RelatedTargetMap relatedNodeMap;
-    buildRelatedNodeMap(relatedNode, relatedNodeMap);
-
-    // Synthetic mouse events can have a relatedTarget which is identical to the target.
-    bool targetIsIdenticalToToRelatedTarget = (node == relatedNode);
-
-    TreeScope* lastTreeScope = 0;
-    EventTarget* adjustedTarget = 0;
-
-    for (size_t i = 0; i < eventPath.size(); ++i) {
-        TreeScope* scope = &eventPath[i].node()->treeScope();
-        if (scope == lastTreeScope) {
-            // Re-use the previous adjustedRelatedTarget if treeScope does not change. Just for the performance optimization.
-            adjustedTargets.append(adjustedTarget);
-        } else {
-            adjustedTarget = findRelatedNode(scope, relatedNodeMap);
-            adjustedTargets.append(adjustedTarget);
-        }
-        lastTreeScope = scope;
-        if (eventWithRelatedTargetDispatchBehavior == DoesNotStopAtBoundary)
-            continue;
-        if (targetIsIdenticalToToRelatedTarget) {
-            if (node->treeScope().rootNode() == eventPath[i].node()) {
-                eventPath.shrink(i + 1);
-                break;
-            }
-        } else if (eventPath[i].target() == adjustedTarget) {
-            // Event dispatching should be stopped here.
-            eventPath.shrink(i);
-            adjustedTargets.shrink(adjustedTargets.size() - 1);
-            break;
-        }
-    }
-}
-
-void EventRetargeter::buildRelatedNodeMap(const Node* relatedNode, RelatedTargetMap& relatedTargetMap)
-{
-    TreeScope* lastTreeScope = 0;
-    EventPath eventPath(const_cast<Node*>(relatedNode));
-    for (size_t i = 0; i < eventPath.size(); ++i) {
-        TreeScope* treeScope = &eventPath[i].node()->treeScope();
-        if (treeScope != lastTreeScope)
-            relatedTargetMap.add(treeScope, eventPath[i].target());
-        lastTreeScope = treeScope;
-    }
-}
-
-EventTarget* EventRetargeter::findRelatedNode(TreeScope* scope, RelatedTargetMap& relatedTargetMap)
-{
-    Vector<TreeScope*, 32> parentTreeScopes;
-    EventTarget* relatedNode = 0;
-    while (scope) {
-        parentTreeScopes.append(scope);
-        RelatedTargetMap::const_iterator found = relatedTargetMap.find(scope);
-        if (found != relatedTargetMap.end()) {
-            relatedNode = found->value;
-            break;
-        }
-        scope = scope->parentTreeScope();
-    }
-    for (Vector<TreeScope*, 32>::iterator iter = parentTreeScopes.begin(); iter < parentTreeScopes.end(); ++iter)
-        relatedTargetMap.add(*iter, relatedNode);
-    return relatedNode;
-}
-
-}
diff --git a/Source/core/events/EventRetargeter.h b/Source/core/events/EventRetargeter.h
deleted file mode 100644
index 4edcded..0000000
--- a/Source/core/events/EventRetargeter.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef EventRetargeter_h
-#define EventRetargeter_h
-
-#include "wtf/HashMap.h"
-#include "wtf/RefPtr.h"
-#include "wtf/Vector.h"
-
-namespace WebCore {
-
-class EventPath;
-class EventTarget;
-class FocusEvent;
-class MouseEvent;
-class Node;
-class TouchEvent;
-class TouchList;
-class TreeScope;
-
-class EventRetargeter {
-public:
-    static void adjustForMouseEvent(Node*, MouseEvent&);
-    static void adjustForFocusEvent(Node*, FocusEvent&);
-    typedef Vector<RefPtr<TouchList> > EventPathTouchLists;
-    static void adjustForTouchEvent(Node*, TouchEvent&);
-
-private:
-    typedef Vector<RefPtr<EventTarget> > AdjustedTargets;
-    typedef HashMap<TreeScope*, EventTarget*> RelatedTargetMap;
-    enum EventWithRelatedTargetDispatchBehavior {
-        StopAtBoundaryIfNeeded,
-        DoesNotStopAtBoundary
-    };
-    static void adjustForRelatedTarget(const Node*, EventTarget* relatedTarget, EventPath&);
-    static void calculateAdjustedNodes(const Node*, const Node* relatedNode, EventWithRelatedTargetDispatchBehavior, EventPath&, AdjustedTargets&);
-    static void buildRelatedNodeMap(const Node*, RelatedTargetMap&);
-    static EventTarget* findRelatedNode(TreeScope*, RelatedTargetMap&);
-    static void adjustTouchList(const Node*, const TouchList*, const EventPath&, EventPathTouchLists&);
-};
-
-}
-
-#endif // EventRetargeter_h
diff --git a/Source/core/events/EventTarget.cpp b/Source/core/events/EventTarget.cpp
index 6e96b47..99ef922 100644
--- a/Source/core/events/EventTarget.cpp
+++ b/Source/core/events/EventTarget.cpp
@@ -33,7 +33,6 @@
 #include "core/events/EventTarget.h"
 
 #include "RuntimeEnabledFeatures.h"
-#include "bindings/v8/DOMWrapperWorld.h"
 #include "bindings/v8/ExceptionState.h"
 #include "core/events/Event.h"
 #include "core/dom/ExceptionCode.h"
@@ -83,7 +82,12 @@
 
 bool EventTarget::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
 {
-    return ensureEventTargetData().eventListenerMap.add(eventType, listener, useCapture);
+    EventListener* eventListener = listener.get();
+    if (ensureEventTargetData().eventListenerMap.add(eventType, listener, useCapture)) {
+        InspectorInstrumentation::didAddEventListener(this, eventType, eventListener, useCapture);
+        return true;
+    }
+    return false;
 }
 
 bool EventTarget::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
@@ -96,6 +100,7 @@
 
     if (!d->eventListenerMap.remove(eventType, listener, useCapture, indexOfRemovedListener))
         return false;
+    InspectorInstrumentation::didRemoveEventListener(this, eventType, listener, useCapture);
 
     // Notify firing events planning to invoke the listener at 'index' that
     // they have one less listener to invoke.
@@ -117,38 +122,28 @@
     return true;
 }
 
-bool EventTarget::setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld)
+bool EventTarget::setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener)
 {
-    clearAttributeEventListener(eventType, isolatedWorld);
+    clearAttributeEventListener(eventType);
     if (!listener)
         return false;
     return addEventListener(eventType, listener, false);
 }
 
-EventListener* EventTarget::getAttributeEventListener(const AtomicString& eventType, DOMWrapperWorld* isolatedWorld)
+EventListener* EventTarget::getAttributeEventListener(const AtomicString& eventType)
 {
     const EventListenerVector& entry = getEventListeners(eventType);
     for (size_t i = 0; i < entry.size(); ++i) {
         EventListener* listener = entry[i].listener.get();
-        if (listener->isAttribute()) {
-            DOMWrapperWorld* listenerWorld = listener->world();
-            // Worker listener
-            if (!listenerWorld) {
-                ASSERT(!isolatedWorld);
-                return listener;
-            }
-            if (listenerWorld->isMainWorld() && !isolatedWorld)
-                return listener;
-            if (listenerWorld == isolatedWorld)
-                return listener;
-        }
+        if (listener->isAttribute() && listener->belongsToTheCurrentWorld())
+            return listener;
     }
     return 0;
 }
 
-bool EventTarget::clearAttributeEventListener(const AtomicString& eventType, DOMWrapperWorld* isolatedWorld)
+bool EventTarget::clearAttributeEventListener(const AtomicString& eventType)
 {
-    EventListener* listener = getAttributeEventListener(eventType, isolatedWorld);
+    EventListener* listener = getAttributeEventListener(eventType);
     if (!listener)
         return false;
     return removeEventListener(eventType, listener, false);
@@ -189,7 +184,7 @@
 {
 }
 
-static AtomicString legacyType(const Event* event)
+static const AtomicString& legacyType(const Event* event)
 {
     if (event->type() == EventTypeNames::transitionend)
         return EventTypeNames::webkitTransitionEnd;
@@ -206,7 +201,7 @@
     if (event->type() == EventTypeNames::wheel)
         return EventTypeNames::mousewheel;
 
-    return emptyString();
+    return emptyAtom;
 }
 
 void EventTarget::countLegacyEvents(const AtomicString& legacyTypeName, EventListenerVector* listenersVector, EventListenerVector* legacyListenersVector)
@@ -242,11 +237,11 @@
         if (DOMWindow* executingWindow = this->executingWindow()) {
             if (legacyListenersVector) {
                 if (listenersVector)
-                    UseCounter::count(executingWindow, prefixedAndUnprefixedFeature);
+                    UseCounter::count(executingWindow->document(), prefixedAndUnprefixedFeature);
                 else
-                    UseCounter::count(executingWindow, prefixedFeature);
+                    UseCounter::count(executingWindow->document(), prefixedFeature);
             } else if (listenersVector) {
-                UseCounter::count(executingWindow, unprefixedFeature);
+                UseCounter::count(executingWindow->document(), unprefixedFeature);
             }
         }
     }
@@ -297,12 +292,12 @@
     if (event->type() == EventTypeNames::beforeunload) {
         if (DOMWindow* executingWindow = this->executingWindow()) {
             if (executingWindow->top())
-                UseCounter::count(executingWindow, UseCounter::SubFrameBeforeUnloadFired);
-            UseCounter::count(executingWindow, UseCounter::DocumentBeforeUnloadFired);
+                UseCounter::count(executingWindow->document(), UseCounter::SubFrameBeforeUnloadFired);
+            UseCounter::count(executingWindow->document(), UseCounter::DocumentBeforeUnloadFired);
         }
     } else if (event->type() == EventTypeNames::unload) {
         if (DOMWindow* executingWindow = this->executingWindow())
-            UseCounter::count(executingWindow, UseCounter::DocumentUnloadFired);
+            UseCounter::count(executingWindow->document(), UseCounter::DocumentUnloadFired);
     }
 
     bool userEventWasHandled = false;
@@ -327,7 +322,7 @@
         if (!context)
             break;
 
-        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willHandleEvent(context, event);
+        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willHandleEvent(this, event->type(), registeredListener.listener.get(), registeredListener.useCapture);
         // To match Mozilla, the AT_TARGET phase fires both capturing and bubbling
         // event listeners, even though that violates some versions of the DOM spec.
         registeredListener.listener->handleEvent(context, event);
@@ -357,12 +352,19 @@
     return *listenerVector;
 }
 
+Vector<AtomicString> EventTarget::eventTypes()
+{
+    EventTargetData* d = eventTargetData();
+    return d ? d->eventListenerMap.eventTypes() : Vector<AtomicString>();
+}
+
 void EventTarget::removeAllEventListeners()
 {
     EventTargetData* d = eventTargetData();
     if (!d)
         return;
     d->eventListenerMap.clear();
+    InspectorInstrumentation::didRemoveAllEventListeners(this);
 
     // Notify firing events planning to invoke the listener at 'index' that
     // they have one less listener to invoke.
diff --git a/Source/core/events/EventTarget.h b/Source/core/events/EventTarget.h
index fa21925..28f7545 100644
--- a/Source/core/events/EventTarget.h
+++ b/Source/core/events/EventTarget.h
@@ -57,7 +57,6 @@
 class MediaController;
 class MediaStream;
 class MessagePort;
-class NamedFlow;
 class Node;
 class Notification;
 class SVGElementInstance;
@@ -116,16 +115,16 @@
     virtual void uncaughtExceptionInEventHandler();
 
     // Used for legacy "onEvent" attribute APIs.
-    bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, DOMWrapperWorld* isolatedWorld = 0);
-    EventListener* getAttributeEventListener(const AtomicString& eventType, DOMWrapperWorld* isolatedWorld = 0);
+    bool setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
+    EventListener* getAttributeEventListener(const AtomicString& eventType);
 
     bool hasEventListeners() const;
     bool hasEventListeners(const AtomicString& eventType) const;
     bool hasCapturingEventListeners(const AtomicString& eventType);
     const EventListenerVector& getEventListeners(const AtomicString& eventType);
+    Vector<AtomicString> eventTypes();
 
     bool fireEventListeners(Event*);
-    bool isFiringEventListeners();
 
 protected:
     virtual ~EventTarget();
@@ -143,7 +142,7 @@
     void fireEventListeners(Event*, EventTargetData*, EventListenerVector&);
     void countLegacyEvents(const AtomicString& legacyTypeName, EventListenerVector*, EventListenerVector*);
 
-    bool clearAttributeEventListener(const AtomicString& eventType, DOMWrapperWorld* isolatedWorld);
+    bool clearAttributeEventListener(const AtomicString& eventType);
 
     friend class EventListenerIterator;
 };
@@ -159,57 +158,49 @@
 // FIXME: These macros should be split into separate DEFINE and DECLARE
 // macros to avoid causing so many header includes.
 #define DEFINE_ATTRIBUTE_EVENT_LISTENER(attribute) \
-    EventListener* on##attribute(DOMWrapperWorld* isolatedWorld) { return getAttributeEventListener(EventTypeNames::attribute, isolatedWorld); } \
-    void setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld = 0) { setAttributeEventListener(EventTypeNames::attribute, listener, isolatedWorld); } \
+    EventListener* on##attribute() { return getAttributeEventListener(EventTypeNames::attribute); } \
+    void setOn##attribute(PassRefPtr<EventListener> listener) { setAttributeEventListener(EventTypeNames::attribute, listener); } \
 
 #define DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(attribute) \
-    static EventListener* on##attribute(EventTarget* eventTarget, DOMWrapperWorld* isolatedWorld) { return eventTarget->getAttributeEventListener(EventTypeNames::attribute, isolatedWorld); } \
-    static void setOn##attribute(EventTarget* eventTarget, PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld = 0) { eventTarget->setAttributeEventListener(EventTypeNames::attribute, listener, isolatedWorld); } \
+    static EventListener* on##attribute(EventTarget* eventTarget) { return eventTarget->getAttributeEventListener(EventTypeNames::attribute); } \
+    static void setOn##attribute(EventTarget* eventTarget, PassRefPtr<EventListener> listener) { eventTarget->setAttributeEventListener(EventTypeNames::attribute, listener); } \
 
 #define DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \
-    EventListener* on##attribute(DOMWrapperWorld* isolatedWorld) { return document().getWindowAttributeEventListener(EventTypeNames::attribute, isolatedWorld); } \
-    void setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld) { document().setWindowAttributeEventListener(EventTypeNames::attribute, listener, isolatedWorld); } \
+    EventListener* on##attribute() { return document().getWindowAttributeEventListener(EventTypeNames::attribute); } \
+    void setOn##attribute(PassRefPtr<EventListener> listener) { document().setWindowAttributeEventListener(EventTypeNames::attribute, listener); } \
 
 #define DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(attribute) \
-    static EventListener* on##attribute(EventTarget* eventTarget, DOMWrapperWorld* isolatedWorld) { \
+    static EventListener* on##attribute(EventTarget* eventTarget) { \
         if (Node* node = eventTarget->toNode()) \
-            return node->document().getWindowAttributeEventListener(EventTypeNames::attribute, isolatedWorld); \
+            return node->document().getWindowAttributeEventListener(EventTypeNames::attribute); \
         ASSERT(eventTarget->toDOMWindow()); \
-        return eventTarget->getAttributeEventListener(EventTypeNames::attribute, isolatedWorld); \
+        return eventTarget->getAttributeEventListener(EventTypeNames::attribute); \
     } \
-    static void setOn##attribute(EventTarget* eventTarget, PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld) { \
+    static void setOn##attribute(EventTarget* eventTarget, PassRefPtr<EventListener> listener) { \
         if (Node* node = eventTarget->toNode()) \
-            node->document().setWindowAttributeEventListener(EventTypeNames::attribute, listener, isolatedWorld); \
+            node->document().setWindowAttributeEventListener(EventTypeNames::attribute, listener); \
         else { \
             ASSERT(eventTarget->toDOMWindow()); \
-            eventTarget->setAttributeEventListener(EventTypeNames::attribute, listener, isolatedWorld); \
+            eventTarget->setAttributeEventListener(EventTypeNames::attribute, listener); \
         } \
     }
 
 #define DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(attribute, eventName) \
-    EventListener* on##attribute(DOMWrapperWorld* isolatedWorld) { return getAttributeEventListener(EventTypeNames::eventName, isolatedWorld); } \
-    void setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld) { setAttributeEventListener(EventTypeNames::eventName, listener, isolatedWorld); } \
+    EventListener* on##attribute() { return getAttributeEventListener(EventTypeNames::eventName); } \
+    void setOn##attribute(PassRefPtr<EventListener> listener) { setAttributeEventListener(EventTypeNames::eventName, listener); } \
 
 #define DECLARE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(recipient, attribute) \
-    EventListener* on##attribute(DOMWrapperWorld* isolatedWorld); \
-    void setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld);
+    EventListener* on##attribute(); \
+    void setOn##attribute(PassRefPtr<EventListener> listener);
 
 #define DEFINE_FORWARDING_ATTRIBUTE_EVENT_LISTENER(type, recipient, attribute) \
-    EventListener* type::on##attribute(DOMWrapperWorld* isolatedWorld) { return recipient ? recipient->getAttributeEventListener(EventTypeNames::attribute, isolatedWorld) : 0; } \
-    void type::setOn##attribute(PassRefPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld) \
+    EventListener* type::on##attribute() { return recipient ? recipient->getAttributeEventListener(EventTypeNames::attribute) : 0; } \
+    void type::setOn##attribute(PassRefPtr<EventListener> listener) \
     { \
         if (recipient) \
-            recipient->setAttributeEventListener(EventTypeNames::attribute, listener, isolatedWorld); \
+            recipient->setAttributeEventListener(EventTypeNames::attribute, listener); \
     }
 
-inline bool EventTarget::isFiringEventListeners()
-{
-    EventTargetData* d = eventTargetData();
-    if (!d)
-        return false;
-    return d->firingEventIterators && !d->firingEventIterators->isEmpty();
-}
-
 inline bool EventTarget::hasEventListeners() const
 {
     // FIXME: We should have a const version of eventTargetData.
diff --git a/Source/core/events/EventTargetFactory.in b/Source/core/events/EventTargetFactory.in
index a3eb30b..69317cb 100644
--- a/Source/core/events/EventTargetFactory.in
+++ b/Source/core/events/EventTargetFactory.in
@@ -3,7 +3,6 @@
 core/css/FontFaceSet
 core/dom/MessagePort
 core/dom/Node
-core/dom/WebKitNamedFlow ImplementedAs=NamedFlow
 core/fileapi/FileReader
 core/html/MediaController
 core/html/ime/InputMethodContext
@@ -13,6 +12,7 @@
 core/loader/appcache/ApplicationCache
 core/page/EventSource
 core/timing/Performance
+core/frame/Screen
 core/frame/Window ImplementedAs=DOMWindow
 core/svg/SVGElementInstance
 core/workers/DedicatedWorkerGlobalScope
@@ -21,7 +21,7 @@
 core/workers/Worker
 core/xml/XMLHttpRequest
 core/xml/XMLHttpRequestUpload
-modules/encryptedmedia/MediaKeySession Conditional=ENCRYPTED_MEDIA_V2
+modules/encryptedmedia/MediaKeySession
 modules/filesystem/FileWriter
 modules/indexeddb/IDBDatabase
 modules/indexeddb/IDBOpenDBRequest
diff --git a/Source/core/events/EventTypeNames.in b/Source/core/events/EventTypeNames.in
index b814801..96d8286 100644
--- a/Source/core/events/EventTypeNames.in
+++ b/Source/core/events/EventTypeNames.in
@@ -119,6 +119,7 @@
 mouseup
 mousewheel
 mute
+needkey
 negotiationneeded
 nomatch
 noupdate
@@ -137,6 +138,7 @@
 popstate
 progress
 ratechange
+ready
 readystatechange
 removesourcebuffer
 removestream
@@ -214,8 +216,6 @@
 webkitprerenderload
 webkitprerenderstart
 webkitprerenderstop
-webkitregionlayoutupdate
-webkitregionoversetchange
 webkitremovesourcebuffer
 webkitresourcetimingbufferfull
 webkitsourceclose
diff --git a/Source/core/events/FocusEvent.cpp b/Source/core/events/FocusEvent.cpp
index e201de0..b69c74a 100644
--- a/Source/core/events/FocusEvent.cpp
+++ b/Source/core/events/FocusEvent.cpp
@@ -28,7 +28,6 @@
 
 #include "core/events/Event.h"
 #include "core/events/EventDispatcher.h"
-#include "core/events/EventRetargeter.h"
 #include "core/events/ThreadLocalEventNames.h"
 
 namespace WebCore {
@@ -79,7 +78,7 @@
 
 bool FocusEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
 {
-    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event());
+    event()->eventPath().adjustForRelatedTarget(dispatcher->node(), event()->relatedTarget());
     return EventDispatchMediator::dispatchEvent(dispatcher);
 }
 
@@ -95,7 +94,7 @@
 
 bool BlurEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
 {
-    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event());
+    event()->eventPath().adjustForRelatedTarget(dispatcher->node(), event()->relatedTarget());
     return EventDispatchMediator::dispatchEvent(dispatcher);
 }
 
@@ -111,7 +110,7 @@
 
 bool FocusInEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
 {
-    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event());
+    event()->eventPath().adjustForRelatedTarget(dispatcher->node(), event()->relatedTarget());
     return EventDispatchMediator::dispatchEvent(dispatcher);
 }
 
@@ -127,7 +126,7 @@
 
 bool FocusOutEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
 {
-    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event());
+    event()->eventPath().adjustForRelatedTarget(dispatcher->node(), event()->relatedTarget());
     return EventDispatchMediator::dispatchEvent(dispatcher);
 }
 
diff --git a/Source/core/events/FocusEvent.h b/Source/core/events/FocusEvent.h
index 20a9a28..517f71f 100644
--- a/Source/core/events/FocusEvent.h
+++ b/Source/core/events/FocusEvent.h
@@ -39,7 +39,7 @@
     RefPtr<EventTarget> relatedTarget;
 };
 
-class FocusEvent : public UIEvent {
+class FocusEvent FINAL : public UIEvent {
 public:
     static PassRefPtr<FocusEvent> create()
     {
@@ -60,8 +60,8 @@
     EventTarget* relatedTarget(bool& isNull) const { isNull = !m_relatedTarget; return m_relatedTarget.get(); }
     void setRelatedTarget(EventTarget* relatedTarget) { m_relatedTarget = relatedTarget; }
 
-    virtual const AtomicString& interfaceName() const;
-    virtual bool isFocusEvent() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
+    virtual bool isFocusEvent() const OVERRIDE;
 
 private:
     FocusEvent();
@@ -73,7 +73,7 @@
 
 DEFINE_EVENT_TYPE_CASTS(FocusEvent);
 
-class FocusEventDispatchMediator : public EventDispatchMediator {
+class FocusEventDispatchMediator FINAL : public EventDispatchMediator {
 public:
     static PassRefPtr<FocusEventDispatchMediator> create(PassRefPtr<FocusEvent>);
 private:
@@ -82,7 +82,7 @@
     virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE;
 };
 
-class BlurEventDispatchMediator : public EventDispatchMediator {
+class BlurEventDispatchMediator FINAL : public EventDispatchMediator {
 public:
     static PassRefPtr<BlurEventDispatchMediator> create(PassRefPtr<FocusEvent>);
 private:
@@ -91,7 +91,7 @@
     virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE;
 };
 
-class FocusInEventDispatchMediator : public EventDispatchMediator {
+class FocusInEventDispatchMediator FINAL : public EventDispatchMediator {
 public:
     static PassRefPtr<FocusInEventDispatchMediator> create(PassRefPtr<FocusEvent>);
 private:
@@ -100,7 +100,7 @@
     virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE;
 };
 
-class FocusOutEventDispatchMediator : public EventDispatchMediator {
+class FocusOutEventDispatchMediator FINAL : public EventDispatchMediator {
 public:
     static PassRefPtr<FocusOutEventDispatchMediator> create(PassRefPtr<FocusEvent>);
 private:
diff --git a/Source/core/events/GenericEventQueue.cpp b/Source/core/events/GenericEventQueue.cpp
index b35f85c..453eeba 100644
--- a/Source/core/events/GenericEventQueue.cpp
+++ b/Source/core/events/GenericEventQueue.cpp
@@ -56,7 +56,7 @@
     if (event->target() == m_owner)
         event->setTarget(0);
 
-    TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event.get(), "type", event->type().string().ascii());
+    TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event.get(), "type", event->type().ascii());
     m_pendingEvents.append(event);
 
     if (!m_timer.isActive())
@@ -71,7 +71,7 @@
 
     if (found) {
         m_pendingEvents.remove(m_pendingEvents.find(event));
-        TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().string().ascii(), "status", "cancelled");
+        TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled");
     }
 
     if (m_pendingEvents.isEmpty())
@@ -92,7 +92,7 @@
     for (size_t i = 0; i < pendingEvents.size(); ++i) {
         Event* event = pendingEvents[i].get();
         EventTarget* target = event->target() ? event->target() : m_owner;
-        CString type(event->type().string().ascii());
+        CString type(event->type().ascii());
         TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", event, "dispatch", "type", type);
         target->dispatchEvent(pendingEvents[i].release());
         TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, "type", type);
@@ -111,7 +111,7 @@
 
     for (size_t i = 0; i < m_pendingEvents.size(); ++i) {
         Event* event = m_pendingEvents[i].get();
-        TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().string().ascii(), "status", "cancelled");
+        TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled");
     }
     m_pendingEvents.clear();
 }
diff --git a/Source/core/events/GenericEventQueue.h b/Source/core/events/GenericEventQueue.h
index ab80f89..cf8e8a6 100644
--- a/Source/core/events/GenericEventQueue.h
+++ b/Source/core/events/GenericEventQueue.h
@@ -35,7 +35,7 @@
 
 namespace WebCore {
 
-class GenericEventQueue : public EventQueue {
+class GenericEventQueue FINAL : public EventQueue {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     explicit GenericEventQueue(EventTarget*);
diff --git a/Source/core/events/GestureEvent.cpp b/Source/core/events/GestureEvent.cpp
index 13d5f6f..5c7e937 100644
--- a/Source/core/events/GestureEvent.cpp
+++ b/Source/core/events/GestureEvent.cpp
@@ -30,11 +30,6 @@
 
 namespace WebCore {
 
-PassRefPtr<GestureEvent> GestureEvent::create()
-{
-    return adoptRef(new GestureEvent);
-}
-
 PassRefPtr<GestureEvent> GestureEvent::create(PassRefPtr<AbstractView> view, const PlatformGestureEvent& event)
 {
     AtomicString eventType;
@@ -73,24 +68,6 @@
     return adoptRef(new GestureEvent(eventType, view, event.globalPosition().x(), event.globalPosition().y(), event.position().x(), event.position().y(), event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), deltaX, deltaY));
 }
 
-void GestureEvent::initGestureEvent(const AtomicString& type, PassRefPtr<AbstractView> view, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, float deltaX, float deltaY)
-{
-    if (dispatched())
-        return;
-
-    initUIEvent(type, true, true, view, 0);
-    m_screenLocation = IntPoint(screenX, screenY);
-    m_ctrlKey = ctrlKey;
-    m_altKey = altKey;
-    m_shiftKey = shiftKey;
-    m_metaKey = metaKey;
-
-    m_deltaX = deltaX;
-    m_deltaY = deltaY;
-
-    initCoordinates(IntPoint(clientX, clientY));
-}
-
 const AtomicString& GestureEvent::interfaceName() const
 {
     // FIXME: when a GestureEvent.idl interface is defined, return the string "GestureEvent".
diff --git a/Source/core/events/GestureEvent.h b/Source/core/events/GestureEvent.h
index fe98200..a9696d2 100644
--- a/Source/core/events/GestureEvent.h
+++ b/Source/core/events/GestureEvent.h
@@ -32,18 +32,15 @@
 
 namespace WebCore {
 
-class GestureEvent : public MouseRelatedEvent {
+class GestureEvent FINAL : public MouseRelatedEvent {
 public:
     virtual ~GestureEvent() { }
 
-    static PassRefPtr<GestureEvent> create();
     static PassRefPtr<GestureEvent> create(PassRefPtr<AbstractView>, const PlatformGestureEvent&);
 
-    void initGestureEvent(const AtomicString& type, PassRefPtr<AbstractView>, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, float deltaX, float deltaY);
-
     virtual bool isGestureEvent() const OVERRIDE;
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
     float deltaX() const { return m_deltaX; }
     float deltaY() const { return m_deltaY; }
@@ -56,7 +53,7 @@
     float m_deltaY;
 };
 
-class GestureEventDispatchMediator : public EventDispatchMediator {
+class GestureEventDispatchMediator FINAL : public EventDispatchMediator {
 public:
     static PassRefPtr<GestureEventDispatchMediator> create(PassRefPtr<GestureEvent> gestureEvent)
     {
diff --git a/Source/core/events/HashChangeEvent.h b/Source/core/events/HashChangeEvent.h
index e652df8..16d4f73 100644
--- a/Source/core/events/HashChangeEvent.h
+++ b/Source/core/events/HashChangeEvent.h
@@ -35,7 +35,7 @@
     String newURL;
 };
 
-class HashChangeEvent : public Event {
+class HashChangeEvent FINAL : public Event {
 public:
     static PassRefPtr<HashChangeEvent> create()
     {
@@ -66,7 +66,7 @@
     const String& oldURL() const { return m_oldURL; }
     const String& newURL() const { return m_newURL; }
 
-    virtual const AtomicString& interfaceName() const { return EventNames::HashChangeEvent; }
+    virtual const AtomicString& interfaceName() const OVERRIDE { return EventNames::HashChangeEvent; }
 
 private:
     HashChangeEvent()
diff --git a/Source/core/events/KeyboardEvent.cpp b/Source/core/events/KeyboardEvent.cpp
index c03712e..93034ad 100644
--- a/Source/core/events/KeyboardEvent.cpp
+++ b/Source/core/events/KeyboardEvent.cpp
@@ -217,15 +217,6 @@
     return keyCode();
 }
 
-KeyboardEvent* findKeyboardEvent(Event* event)
-{
-    for (Event* e = event; e; e = e->underlyingEvent()) {
-        if (e->isKeyboardEvent())
-            return toKeyboardEvent(e);
-    }
-    return 0;
-}
-
 PassRefPtr<KeyboardEventDispatchMediator> KeyboardEventDispatchMediator::create(PassRefPtr<KeyboardEvent> event)
 {
     return adoptRef(new KeyboardEventDispatchMediator(event));
diff --git a/Source/core/events/KeyboardEvent.h b/Source/core/events/KeyboardEvent.h
index e4d1e9e..671b1bf 100644
--- a/Source/core/events/KeyboardEvent.h
+++ b/Source/core/events/KeyboardEvent.h
@@ -45,7 +45,7 @@
     bool repeat;
 };
 
-class KeyboardEvent : public UIEventWithKeyState {
+class KeyboardEvent FINAL : public UIEventWithKeyState {
 public:
     enum KeyLocationCode {
         DOM_KEY_LOCATION_STANDARD   = 0x00,
@@ -92,13 +92,13 @@
 
     const PlatformKeyboardEvent* keyEvent() const { return m_keyEvent.get(); }
 
-    int keyCode() const; // key code for keydown and keyup, character for keypress
-    int charCode() const; // character code for keypress, 0 for keydown and keyup
+    virtual int keyCode() const OVERRIDE; // key code for keydown and keyup, character for keypress
+    virtual int charCode() const OVERRIDE; // character code for keypress, 0 for keydown and keyup
     bool repeat() const { return m_isAutoRepeat; }
 
-    virtual const AtomicString& interfaceName() const;
-    virtual bool isKeyboardEvent() const;
-    virtual int which() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
+    virtual bool isKeyboardEvent() const OVERRIDE;
+    virtual int which() const OVERRIDE;
 
 private:
     KeyboardEvent();
@@ -115,8 +115,6 @@
     bool m_isAutoRepeat : 1;
 };
 
-KeyboardEvent* findKeyboardEvent(Event*);
-
 class KeyboardEventDispatchMediator : public EventDispatchMediator {
 public:
     static PassRefPtr<KeyboardEventDispatchMediator> create(PassRefPtr<KeyboardEvent>);
diff --git a/Source/core/events/MessageEvent.h b/Source/core/events/MessageEvent.h
index 64df40f..1442bf4 100644
--- a/Source/core/events/MessageEvent.h
+++ b/Source/core/events/MessageEvent.h
@@ -47,7 +47,7 @@
     MessagePortArray ports;
 };
 
-class MessageEvent : public Event {
+class MessageEvent FINAL : public Event {
 public:
     static PassRefPtr<MessageEvent> create()
     {
@@ -90,7 +90,7 @@
     MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArray(); }
     MessagePortChannelArray* channels() const { return m_channels ? m_channels.get() : 0; }
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
     enum DataType {
         DataTypeScriptValue,
diff --git a/Source/core/events/MessageEvent.idl b/Source/core/events/MessageEvent.idl
index c482b08..b830e16 100644
--- a/Source/core/events/MessageEvent.idl
+++ b/Source/core/events/MessageEvent.idl
@@ -29,28 +29,28 @@
     EventConstructor,
     GlobalContext=Window&WorkerGlobalScope,
     RaisesException=Constructor,
+    Custom=Wrap,
 ] interface MessageEvent : Event {
     [InitializedByEventConstructor] readonly attribute DOMString origin;
     [InitializedByEventConstructor] readonly attribute DOMString lastEventId;
     [InitializedByEventConstructor] readonly attribute EventTarget? source; // May be a Window or a MessagePort
     [InitializedByEventConstructor, Custom=Getter] readonly attribute any data;
     [InitializedByEventConstructor] readonly attribute MessagePort[] ports;
-    [Custom] void initMessageEvent([Default=Undefined] optional DOMString typeArg,
+    [Custom, MeasureAs=InitMessageEvent] void initMessageEvent([Default=Undefined] optional DOMString typeArg,
                                    [Default=Undefined] optional boolean canBubbleArg,
                                    [Default=Undefined] optional boolean cancelableArg,
                                    [Default=Undefined] optional any dataArg,
                                    [Default=Undefined] optional DOMString originArg,
                                    [Default=Undefined] optional DOMString lastEventIdArg,
                                    [Default=Undefined] optional Window sourceArg,
-                                   [Default=Undefined] optional Array messagePorts);
+                                   [Default=Undefined] optional MessagePort[] messagePorts);
 
-    [Custom] void webkitInitMessageEvent([Default=Undefined] optional DOMString typeArg,
+    [Custom, MeasureAs=PrefixedInitMessageEvent] void webkitInitMessageEvent([Default=Undefined] optional DOMString typeArg,
                                          [Default=Undefined] optional boolean canBubbleArg,
                                          [Default=Undefined] optional boolean cancelableArg,
                                          [Default=Undefined] optional any dataArg,
                                          [Default=Undefined] optional DOMString originArg,
                                          [Default=Undefined] optional DOMString lastEventIdArg,
                                          [Default=Undefined] optional Window sourceArg,
-                                         [Default=Undefined] optional Array transferables);
+                                         [Default=Undefined] optional MessagePort[] transferables);
 };
-
diff --git a/Source/core/events/MouseEvent.cpp b/Source/core/events/MouseEvent.cpp
index 1e6a697..8c3d2fa 100644
--- a/Source/core/events/MouseEvent.cpp
+++ b/Source/core/events/MouseEvent.cpp
@@ -23,10 +23,9 @@
 #include "config.h"
 #include "core/events/MouseEvent.h"
 
-#include "core/dom/Clipboard.h"
+#include "core/clipboard/Clipboard.h"
 #include "core/dom/Element.h"
 #include "core/events/EventDispatcher.h"
-#include "core/events/EventRetargeter.h"
 #include "core/events/ThreadLocalEventNames.h"
 #include "platform/PlatformMouseEvent.h"
 
@@ -70,19 +69,6 @@
     int detail, int screenX, int screenY, int pageX, int pageY,
     int movementX, int movementY,
     bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
-    PassRefPtr<EventTarget> relatedTarget)
-
-{
-    return MouseEvent::create(type, canBubble, cancelable, view,
-        detail, screenX, screenY, pageX, pageY,
-        movementX, movementY,
-        ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, 0, false);
-}
-
-PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view,
-    int detail, int screenX, int screenY, int pageX, int pageY,
-    int movementX, int movementY,
-    bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
     PassRefPtr<EventTarget> relatedTarget, PassRefPtr<Clipboard> clipboard, bool isSimulated)
 {
     return adoptRef(new MouseEvent(type, canBubble, cancelable, view,
@@ -251,7 +237,7 @@
 bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
 {
     if (isSyntheticMouseEvent()) {
-        EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event());
+        event()->eventPath().adjustForRelatedTarget(dispatcher->node(), event()->relatedTarget());
         return dispatcher->dispatch();
     }
 
@@ -264,7 +250,7 @@
     ASSERT(!event()->target() || event()->target() != event()->relatedTarget());
 
     EventTarget* relatedTarget = event()->relatedTarget();
-    EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event());
+    event()->eventPath().adjustForRelatedTarget(dispatcher->node(), relatedTarget);
 
     dispatcher->dispatch();
     bool swallowEvent = event()->defaultHandled() || event()->defaultPrevented();
diff --git a/Source/core/events/MouseEvent.h b/Source/core/events/MouseEvent.h
index 41ab261..a61c73e 100644
--- a/Source/core/events/MouseEvent.h
+++ b/Source/core/events/MouseEvent.h
@@ -59,12 +59,6 @@
         int detail, int screenX, int screenY, int pageX, int pageY,
         int movementX, int movementY,
         bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
-        PassRefPtr<EventTarget> relatedTarget);
-
-    static PassRefPtr<MouseEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>,
-        int detail, int screenX, int screenY, int pageX, int pageY,
-        int movementX, int movementY,
-        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
         PassRefPtr<EventTarget> relatedTarget, PassRefPtr<Clipboard>, bool isSimulated = false);
 
     static PassRefPtr<MouseEvent> create(const AtomicString& eventType, PassRefPtr<AbstractView>, const PlatformMouseEvent&, int detail, PassRefPtr<Node> relatedTarget);
@@ -86,18 +80,16 @@
     EventTarget* relatedTarget(bool& isNull) const { isNull = !m_relatedTarget; return m_relatedTarget.get(); }
     void setRelatedTarget(PassRefPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; }
 
-    Clipboard* clipboard() const { return m_clipboard.get(); }
-
     Node* toElement() const;
     Node* fromElement() const;
 
     Clipboard* dataTransfer() const { return isDragEvent() ? m_clipboard.get() : 0; }
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
-    virtual bool isMouseEvent() const;
-    virtual bool isDragEvent() const;
-    virtual int which() const;
+    virtual bool isMouseEvent() const OVERRIDE;
+    virtual bool isDragEvent() const OVERRIDE FINAL;
+    virtual int which() const OVERRIDE FINAL;
 
 protected:
     MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>,
@@ -117,7 +109,7 @@
     RefPtr<Clipboard> m_clipboard;
 };
 
-class SimulatedMouseEvent : public MouseEvent {
+class SimulatedMouseEvent FINAL : public MouseEvent {
 public:
     static PassRefPtr<SimulatedMouseEvent> create(const AtomicString& eventType, PassRefPtr<AbstractView>, PassRefPtr<Event> underlyingEvent);
     virtual ~SimulatedMouseEvent();
@@ -126,7 +118,7 @@
     SimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<AbstractView>, PassRefPtr<Event> underlyingEvent);
 };
 
-class MouseEventDispatchMediator : public EventDispatchMediator {
+class MouseEventDispatchMediator FINAL : public EventDispatchMediator {
 public:
     enum MouseEventType { SyntheticMouseEvent, NonSyntheticMouseEvent};
     static PassRefPtr<MouseEventDispatchMediator> create(PassRefPtr<MouseEvent>, MouseEventType = NonSyntheticMouseEvent);
diff --git a/Source/core/events/MouseRelatedEvent.cpp b/Source/core/events/MouseRelatedEvent.cpp
index 4953243..f9df0d8 100644
--- a/Source/core/events/MouseRelatedEvent.cpp
+++ b/Source/core/events/MouseRelatedEvent.cpp
@@ -208,11 +208,6 @@
     return m_pageLocation.y();
 }
 
-const LayoutPoint& MouseRelatedEvent::pageLocation() const
-{
-    return m_pageLocation;
-}
-
 int MouseRelatedEvent::x() const
 {
     // FIXME: This is not correct.
diff --git a/Source/core/events/MouseRelatedEvent.h b/Source/core/events/MouseRelatedEvent.h
index fbaeb9c..ee70b84 100644
--- a/Source/core/events/MouseRelatedEvent.h
+++ b/Source/core/events/MouseRelatedEvent.h
@@ -42,14 +42,13 @@
         int webkitMovementX() const { return m_movementDelta.x(); }
         int webkitMovementY() const { return m_movementDelta.y(); }
         const LayoutPoint& clientLocation() const { return m_clientLocation; }
-        int layerX();
-        int layerY();
+        virtual int layerX() OVERRIDE FINAL;
+        virtual int layerY() OVERRIDE FINAL;
         int offsetX();
         int offsetY();
         bool isSimulated() const { return m_isSimulated; }
-        virtual int pageX() const;
-        virtual int pageY() const;
-        virtual const LayoutPoint& pageLocation() const;
+        virtual int pageX() const OVERRIDE FINAL;
+        virtual int pageY() const OVERRIDE FINAL;
         int x() const;
         int y() const;
 
@@ -67,7 +66,7 @@
 
         void initCoordinates();
         void initCoordinates(const LayoutPoint& clientLocation);
-        virtual void receivedTarget();
+        virtual void receivedTarget() OVERRIDE FINAL;
 
         void computePageLocation();
         void computeRelativePosition();
diff --git a/Source/core/events/MutationEvent.h b/Source/core/events/MutationEvent.h
index f0ef13e..e2e9f56 100644
--- a/Source/core/events/MutationEvent.h
+++ b/Source/core/events/MutationEvent.h
@@ -29,7 +29,7 @@
 
 namespace WebCore {
 
-    class MutationEvent : public Event {
+    class MutationEvent FINAL : public Event {
     public:
         virtual ~MutationEvent();
 
@@ -60,7 +60,7 @@
         String attrName() const { return m_attrName; }
         unsigned short attrChange() const { return m_attrChange; }
 
-        virtual const AtomicString& interfaceName() const;
+        virtual const AtomicString& interfaceName() const OVERRIDE;
 
     private:
         MutationEvent();
diff --git a/Source/core/events/NavigatorEvents.cpp b/Source/core/events/NavigatorEvents.cpp
index a9f9a26..a4285c2 100644
--- a/Source/core/events/NavigatorEvents.cpp
+++ b/Source/core/events/NavigatorEvents.cpp
@@ -33,24 +33,18 @@
 
 #include "core/frame/Frame.h"
 #include "core/frame/Navigator.h"
-#include "core/page/Page.h"
-#include "core/page/Settings.h"
+#include "core/frame/Settings.h"
 
 namespace WebCore {
 
 long NavigatorEvents::maxTouchPoints(Navigator* navigator)
 {
     Frame* frame = navigator->frame();
-
     if (!frame)
         return 0;
-
-    Page* page = frame->page();
-
-    if (!page)
-        return 0;
-
-    return page->settings().maxTouchPoints();
+    if (Settings* settings = frame->settings())
+        return settings->maxTouchPoints();
+    return 0;
 }
 
 } // namespace WebCore
diff --git a/Source/core/events/NavigatorEvents.idl b/Source/core/events/NavigatorEvents.idl
index fe899fc..2b83961 100644
--- a/Source/core/events/NavigatorEvents.idl
+++ b/Source/core/events/NavigatorEvents.idl
@@ -29,6 +29,5 @@
  */
 
 partial interface Navigator {
-    [RuntimeEnabled=PointerEventsMaxTouchPoints]
-    readonly    attribute long    maxTouchPoints;
-};
\ No newline at end of file
+    [RuntimeEnabled=PointerEventsMaxTouchPoints] readonly attribute long maxTouchPoints;
+};
diff --git a/Source/core/events/NodeEventContext.cpp b/Source/core/events/NodeEventContext.cpp
new file mode 100644
index 0000000..e422cce
--- /dev/null
+++ b/Source/core/events/NodeEventContext.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "config.h"
+#include "core/events/NodeEventContext.h"
+
+#include "core/dom/TouchList.h"
+#include "core/events/Event.h"
+#include "core/events/FocusEvent.h"
+#include "core/events/MouseEvent.h"
+#include "core/events/TouchEventContext.h"
+
+namespace WebCore {
+
+NodeEventContext::NodeEventContext(PassRefPtr<Node> node, PassRefPtr<EventTarget> currentTarget)
+    : m_node(node)
+    , m_currentTarget(currentTarget)
+{
+    ASSERT(m_node);
+}
+
+NodeEventContext::~NodeEventContext()
+{
+}
+
+void NodeEventContext::handleLocalEvents(Event* event) const
+{
+    if (touchEventContext()) {
+        touchEventContext()->handleLocalEvents(event);
+    } else if (relatedTarget()) {
+        if (event->isMouseEvent()) {
+            toMouseEvent(event)->setRelatedTarget(relatedTarget());
+        } else if (event->isFocusEvent()) {
+            toFocusEvent(event)->setRelatedTarget(relatedTarget());
+        }
+    }
+    event->setTarget(target());
+    event->setCurrentTarget(m_currentTarget.get());
+    m_node->handleLocalEvents(event);
+}
+
+}
diff --git a/Source/core/events/NodeEventContext.h b/Source/core/events/NodeEventContext.h
new file mode 100644
index 0000000..4a8cf0c
--- /dev/null
+++ b/Source/core/events/NodeEventContext.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef NodeEventContext_h
+#define NodeEventContext_h
+
+#include "core/events/TreeScopeEventContext.h"
+#include "wtf/PassRefPtr.h"
+#include "wtf/RefPtr.h"
+
+namespace WebCore {
+
+class EventTarget;
+class Node;
+class NodeList;
+class TouchEventContext;
+
+class NodeEventContext {
+public:
+    // FIXME: Use ContainerNode instead of Node.
+    NodeEventContext(PassRefPtr<Node>, PassRefPtr<EventTarget> currentTarget);
+    ~NodeEventContext();
+
+    Node* node() const { return m_node.get(); }
+
+    void setTreeScopeEventContext(PassRefPtr<TreeScopeEventContext> prpTreeScopeEventContext) { m_treeScopeEventContext = prpTreeScopeEventContext; }
+
+    EventTarget* target() const { return m_treeScopeEventContext->target(); }
+    EventTarget* relatedTarget() const { return m_treeScopeEventContext->relatedTarget(); }
+    TouchEventContext* touchEventContext() const { return m_treeScopeEventContext->touchEventContext(); }
+    PassRefPtr<NodeList> eventPath() const { return m_treeScopeEventContext->eventPath(); }
+
+    bool currentTargetSameAsTarget() const { return m_currentTarget.get() == target(); }
+    void handleLocalEvents(Event*) const;
+
+private:
+    RefPtr<Node> m_node;
+    RefPtr<EventTarget> m_currentTarget;
+    RefPtr<TreeScopeEventContext> m_treeScopeEventContext;
+};
+
+}
+
+#endif // NodeEventContext_h
diff --git a/Source/core/events/OverflowEvent.cpp b/Source/core/events/OverflowEvent.cpp
index c958ce6..376404d 100644
--- a/Source/core/events/OverflowEvent.cpp
+++ b/Source/core/events/OverflowEvent.cpp
@@ -76,14 +76,4 @@
     return EventNames::OverflowEvent;
 }
 
-void OverflowEvent::initOverflowEvent(unsigned short orient, bool horizontalOverflow, bool verticalOverflow)
-{
-    if (dispatched())
-        return;
-
-    m_orient = orient;
-    m_horizontalOverflow = horizontalOverflow;
-    m_verticalOverflow = verticalOverflow;
-}
-
 }
diff --git a/Source/core/events/OverflowEvent.h b/Source/core/events/OverflowEvent.h
index 96c220b..1f8e1a1 100644
--- a/Source/core/events/OverflowEvent.h
+++ b/Source/core/events/OverflowEvent.h
@@ -38,7 +38,7 @@
     bool verticalOverflow;
 };
 
-class OverflowEvent : public Event {
+class OverflowEvent FINAL : public Event {
 public:
     enum orientType {
         HORIZONTAL = 0,
@@ -59,13 +59,11 @@
         return adoptRef(new OverflowEvent(type, initializer));
     }
 
-    void initOverflowEvent(unsigned short orient, bool horizontalOverflow, bool verticalOverflow);
-
     unsigned short orient() const { return m_orient; }
     bool horizontalOverflow() const { return m_horizontalOverflow; }
     bool verticalOverflow() const { return m_verticalOverflow; }
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
 private:
     OverflowEvent();
diff --git a/Source/core/events/PageTransitionEvent.h b/Source/core/events/PageTransitionEvent.h
index 1002f55..cc79580 100644
--- a/Source/core/events/PageTransitionEvent.h
+++ b/Source/core/events/PageTransitionEvent.h
@@ -36,7 +36,7 @@
     bool persisted;
 };
 
-class PageTransitionEvent : public Event {
+class PageTransitionEvent FINAL : public Event {
 public:
     static PassRefPtr<PageTransitionEvent> create()
     {
@@ -53,7 +53,7 @@
 
     virtual ~PageTransitionEvent();
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
     bool persisted() const { return m_persisted; }
 
diff --git a/Source/core/events/PopStateEvent.h b/Source/core/events/PopStateEvent.h
index 5f874ea..889e5aaf 100644
--- a/Source/core/events/PopStateEvent.h
+++ b/Source/core/events/PopStateEvent.h
@@ -36,7 +36,7 @@
 
 typedef EventInit PopStateEventInit;
 
-class PopStateEvent : public Event {
+class PopStateEvent FINAL : public Event {
 public:
     virtual ~PopStateEvent();
     static PassRefPtr<PopStateEvent> create();
@@ -51,7 +51,7 @@
     }
     History* history() const { return m_history.get(); }
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
 private:
     PopStateEvent();
diff --git a/Source/core/events/ProgressEvent.h b/Source/core/events/ProgressEvent.h
index eb5edb7..76bc750 100644
--- a/Source/core/events/ProgressEvent.h
+++ b/Source/core/events/ProgressEvent.h
@@ -57,7 +57,7 @@
     unsigned long long loaded() const { return m_loaded; }
     unsigned long long total() const { return m_total; }
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
 protected:
     ProgressEvent();
diff --git a/Source/core/events/ResourceProgressEvent.h b/Source/core/events/ResourceProgressEvent.h
index 9c88b19..bb8ae58 100644
--- a/Source/core/events/ResourceProgressEvent.h
+++ b/Source/core/events/ResourceProgressEvent.h
@@ -42,7 +42,7 @@
 // (and translate in the case of PNaCl) multiple binary files. It is not
 // constructable by web content at all, and so does not provide the usual
 // EventInit pattern for Event construction.
-class ResourceProgressEvent : public ProgressEvent {
+class ResourceProgressEvent FINAL : public ProgressEvent {
 public:
     static PassRefPtr<ResourceProgressEvent> create()
     {
@@ -55,7 +55,7 @@
 
     const String& url() const;
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
 protected:
     ResourceProgressEvent();
diff --git a/Source/core/events/SecurityPolicyViolationEvent.h b/Source/core/events/SecurityPolicyViolationEvent.h
index cc88d03..5c52cab 100644
--- a/Source/core/events/SecurityPolicyViolationEvent.h
+++ b/Source/core/events/SecurityPolicyViolationEvent.h
@@ -47,7 +47,7 @@
     int statusCode;
 };
 
-class SecurityPolicyViolationEvent : public Event {
+class SecurityPolicyViolationEvent FINAL : public Event {
 public:
     static PassRefPtr<SecurityPolicyViolationEvent> create()
     {
@@ -70,7 +70,7 @@
     int columnNumber() const { return m_columnNumber; }
     int statusCode() const { return m_statusCode; }
 
-    virtual const AtomicString& interfaceName() const { return EventNames::SecurityPolicyViolationEvent; }
+    virtual const AtomicString& interfaceName() const OVERRIDE { return EventNames::SecurityPolicyViolationEvent; }
 
 private:
     SecurityPolicyViolationEvent()
diff --git a/Source/core/events/TextEvent.h b/Source/core/events/TextEvent.h
index 6c2f256..782ed0d 100644
--- a/Source/core/events/TextEvent.h
+++ b/Source/core/events/TextEvent.h
@@ -35,7 +35,7 @@
 
     class DocumentFragment;
 
-    class TextEvent : public UIEvent {
+    class TextEvent FINAL : public UIEvent {
     public:
 
         static PassRefPtr<TextEvent> create();
@@ -50,11 +50,10 @@
 
         String data() const { return m_data; }
 
-        virtual const AtomicString& interfaceName() const;
+        virtual const AtomicString& interfaceName() const OVERRIDE;
 
         bool isLineBreak() const { return m_inputType == TextEventInputLineBreak; }
         bool isComposition() const { return m_inputType == TextEventInputComposition; }
-        bool isBackTab() const { return m_inputType == TextEventInputBackTab; }
         bool isPaste() const { return m_inputType == TextEventInputPaste; }
         bool isDrop() const { return m_inputType == TextEventInputDrop; }
 
diff --git a/Source/core/events/TouchEvent.cpp b/Source/core/events/TouchEvent.cpp
index f0527ed..68d8095 100644
--- a/Source/core/events/TouchEvent.cpp
+++ b/Source/core/events/TouchEvent.cpp
@@ -29,7 +29,6 @@
 #include "core/events/TouchEvent.h"
 
 #include "core/events/EventDispatcher.h"
-#include "core/events/EventRetargeter.h"
 #include "core/events/ThreadLocalEventNames.h"
 
 namespace WebCore {
@@ -106,7 +105,7 @@
 
 bool TouchEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
 {
-    EventRetargeter::adjustForTouchEvent(dispatcher->node(), *event());
+    event()->eventPath().adjustForTouchEvent(dispatcher->node(), *event());
     return dispatcher->dispatch();
 }
 
diff --git a/Source/core/events/TouchEvent.h b/Source/core/events/TouchEvent.h
index 25c6f61..0961817 100644
--- a/Source/core/events/TouchEvent.h
+++ b/Source/core/events/TouchEvent.h
@@ -33,7 +33,7 @@
 
 namespace WebCore {
 
-class TouchEvent : public MouseRelatedEvent {
+class TouchEvent FINAL : public MouseRelatedEvent {
 public:
     virtual ~TouchEvent();
 
@@ -68,7 +68,7 @@
 
     virtual bool isTouchEvent() const OVERRIDE;
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
 private:
     TouchEvent();
@@ -83,7 +83,7 @@
     RefPtr<TouchList> m_changedTouches;
 };
 
-class TouchEventDispatchMediator : public EventDispatchMediator {
+class TouchEventDispatchMediator FINAL : public EventDispatchMediator {
 public:
     static PassRefPtr<TouchEventDispatchMediator> create(PassRefPtr<TouchEvent>);
 
diff --git a/Source/core/events/TouchEventContext.cpp b/Source/core/events/TouchEventContext.cpp
new file mode 100644
index 0000000..5bdd411
--- /dev/null
+++ b/Source/core/events/TouchEventContext.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "config.h"
+#include "core/events/TouchEventContext.h"
+
+#include "core/dom/TouchList.h"
+#include "core/events/Event.h"
+#include "core/events/TouchEvent.h"
+
+namespace WebCore {
+
+PassRefPtr<TouchEventContext> TouchEventContext::create()
+{
+    return adoptRef(new TouchEventContext);
+}
+
+TouchEventContext::TouchEventContext()
+    : m_touches(TouchList::create())
+    , m_targetTouches(TouchList::create())
+    , m_changedTouches(TouchList::create())
+{
+}
+
+TouchEventContext::~TouchEventContext()
+{
+}
+
+void TouchEventContext::handleLocalEvents(Event* event) const
+{
+    ASSERT(event->isTouchEvent());
+    TouchEvent* touchEvent = toTouchEvent(event);
+    touchEvent->setTouches(m_touches);
+    touchEvent->setTargetTouches(m_targetTouches);
+    touchEvent->setChangedTouches(m_changedTouches);
+}
+
+}
diff --git a/Source/core/events/TouchEventContext.h b/Source/core/events/TouchEventContext.h
new file mode 100644
index 0000000..b6c0f1a
--- /dev/null
+++ b/Source/core/events/TouchEventContext.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef TouchEventContext_h
+#define TouchEventContext_h
+
+#include "wtf/PassRefPtr.h"
+#include "wtf/RefCounted.h"
+#include "wtf/RefPtr.h"
+
+namespace WebCore {
+
+class Event;
+class TouchList;
+
+class TouchEventContext : public RefCounted<TouchEventContext> {
+public:
+    static PassRefPtr<TouchEventContext> create();
+    ~TouchEventContext();
+    void handleLocalEvents(Event*) const;
+    TouchList& touches() { return *m_touches; }
+    TouchList& targetTouches() { return *m_targetTouches; }
+    TouchList& changedTouches() { return *m_changedTouches; }
+
+private:
+    TouchEventContext();
+
+    RefPtr<TouchList> m_touches;
+    RefPtr<TouchList> m_targetTouches;
+    RefPtr<TouchList> m_changedTouches;
+};
+
+}
+
+#endif // TouchEventContext_h
diff --git a/Source/core/events/TransitionEvent.h b/Source/core/events/TransitionEvent.h
index e1d5fa2..91bab0e 100644
--- a/Source/core/events/TransitionEvent.h
+++ b/Source/core/events/TransitionEvent.h
@@ -39,7 +39,7 @@
     String pseudoElement;
 };
 
-class TransitionEvent : public Event {
+class TransitionEvent FINAL : public Event {
 public:
     static PassRefPtr<TransitionEvent> create()
     {
@@ -60,7 +60,7 @@
     double elapsedTime() const;
     const String& pseudoElement() const;
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
 private:
     TransitionEvent();
diff --git a/Source/core/events/TreeScopeEventContext.cpp b/Source/core/events/TreeScopeEventContext.cpp
new file mode 100644
index 0000000..98df539
--- /dev/null
+++ b/Source/core/events/TreeScopeEventContext.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "config.h"
+#include "core/events/TreeScopeEventContext.h"
+
+#include "core/dom/StaticNodeList.h"
+#include "core/events/TouchEventContext.h"
+
+namespace WebCore {
+
+void TreeScopeEventContext::adoptEventPath(Vector<RefPtr<Node> >& nodes)
+{
+    m_eventPath = StaticNodeList::adopt(nodes);
+}
+
+TouchEventContext* TreeScopeEventContext::ensureTouchEventContext()
+{
+    if (!m_touchEventContext)
+        m_touchEventContext = TouchEventContext::create();
+    return m_touchEventContext.get();
+}
+
+PassRefPtr<TreeScopeEventContext> TreeScopeEventContext::create(TreeScope& treeScope)
+{
+    return adoptRef(new TreeScopeEventContext(treeScope));
+}
+
+TreeScopeEventContext::TreeScopeEventContext(TreeScope& treeScope)
+    : m_treeScope(treeScope)
+{
+}
+
+TreeScopeEventContext::~TreeScopeEventContext()
+{
+}
+
+}
diff --git a/Source/core/events/TreeScopeEventContext.h b/Source/core/events/TreeScopeEventContext.h
new file mode 100644
index 0000000..c697566
--- /dev/null
+++ b/Source/core/events/TreeScopeEventContext.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef TreeScopeEventContext_h
+#define TreeScopeEventContext_h
+
+#include "core/dom/Node.h"
+#include "core/dom/NodeList.h"
+#include "core/dom/TreeScope.h"
+#include "core/events/EventTarget.h"
+#include "wtf/PassRefPtr.h"
+#include "wtf/RefPtr.h"
+#include "wtf/Vector.h"
+
+namespace WebCore {
+
+class EventTarget;
+class Node;
+class TouchEventContext;
+class TreeScope;
+
+class TreeScopeEventContext : public RefCounted<TreeScopeEventContext> {
+public:
+    static PassRefPtr<TreeScopeEventContext> create(TreeScope&);
+    ~TreeScopeEventContext();
+
+    TreeScope& treeScope() const { return m_treeScope; }
+
+    EventTarget* target() const { return m_target.get(); }
+    void setTarget(PassRefPtr<EventTarget>);
+
+    EventTarget* relatedTarget() const { return m_relatedTarget.get(); }
+    void setRelatedTarget(PassRefPtr<EventTarget>);
+
+    TouchEventContext* touchEventContext() const { return m_touchEventContext.get(); }
+    TouchEventContext* ensureTouchEventContext();
+
+    PassRefPtr<NodeList> eventPath() const { return m_eventPath; }
+    void adoptEventPath(Vector<RefPtr<Node> >&);
+
+private:
+    TreeScopeEventContext(TreeScope&);
+
+#ifndef NDEBUG
+    bool isUnreachableNode(EventTarget&);
+#endif
+
+    TreeScope& m_treeScope;
+    RefPtr<EventTarget> m_target;
+    RefPtr<EventTarget> m_relatedTarget;
+    RefPtr<NodeList> m_eventPath;
+    RefPtr<TouchEventContext> m_touchEventContext;
+};
+
+#ifndef NDEBUG
+inline bool TreeScopeEventContext::isUnreachableNode(EventTarget& target)
+{
+    // FIXME: Checks also for SVG elements.
+    return target.toNode() && !target.toNode()->isSVGElement() && !target.toNode()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(m_treeScope);
+}
+#endif
+
+inline void TreeScopeEventContext::setTarget(PassRefPtr<EventTarget> target)
+{
+    ASSERT(target);
+    ASSERT(!isUnreachableNode(*target));
+    m_target = target;
+}
+
+inline void TreeScopeEventContext::setRelatedTarget(PassRefPtr<EventTarget> relatedTarget)
+{
+    ASSERT(relatedTarget);
+    ASSERT(!isUnreachableNode(*relatedTarget));
+    m_relatedTarget = relatedTarget;
+}
+
+}
+
+#endif // TreeScopeEventContext_h
diff --git a/Source/core/events/UIEvent.h b/Source/core/events/UIEvent.h
index 2750331..b0d3844 100644
--- a/Source/core/events/UIEvent.h
+++ b/Source/core/events/UIEvent.h
@@ -61,8 +61,8 @@
     AbstractView* view(bool& isNull) const { isNull = !m_view; return m_view.get(); }
     int detail() const { return m_detail; }
 
-    virtual const AtomicString& interfaceName() const;
-    virtual bool isUIEvent() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
+    virtual bool isUIEvent() const OVERRIDE FINAL;
 
     virtual int keyCode() const;
     virtual int charCode() const;
diff --git a/Source/core/events/WebKitAnimationEvent.h b/Source/core/events/WebKitAnimationEvent.h
index b91c980..731f45d 100644
--- a/Source/core/events/WebKitAnimationEvent.h
+++ b/Source/core/events/WebKitAnimationEvent.h
@@ -40,7 +40,7 @@
     double elapsedTime;
 };
 
-class WebKitAnimationEvent : public Event {
+class WebKitAnimationEvent FINAL : public Event {
 public:
     static PassRefPtr<WebKitAnimationEvent> create()
     {
@@ -60,7 +60,7 @@
     const String& animationName() const;
     double elapsedTime() const;
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
 
 private:
     WebKitAnimationEvent();
diff --git a/Source/core/events/WheelEvent.cpp b/Source/core/events/WheelEvent.cpp
index 0c23299..37bf05b 100644
--- a/Source/core/events/WheelEvent.cpp
+++ b/Source/core/events/WheelEvent.cpp
@@ -24,7 +24,7 @@
 #include "config.h"
 #include "core/events/WheelEvent.h"
 
-#include "core/dom/Clipboard.h"
+#include "core/clipboard/Clipboard.h"
 #include "core/events/ThreadLocalEventNames.h"
 #include "platform/PlatformWheelEvent.h"
 
diff --git a/Source/core/events/WheelEvent.h b/Source/core/events/WheelEvent.h
index 6c8ea02..b527130 100644
--- a/Source/core/events/WheelEvent.h
+++ b/Source/core/events/WheelEvent.h
@@ -44,7 +44,7 @@
     unsigned deltaMode;
 };
 
-class WheelEvent : public MouseEvent {
+class WheelEvent FINAL : public MouseEvent {
 public:
     enum { TickMultiplier = 120 };
 
@@ -93,7 +93,7 @@
 
     bool webkitDirectionInvertedFromDevice() const { return m_directionInvertedFromDevice; }
 
-    virtual const AtomicString& interfaceName() const;
+    virtual const AtomicString& interfaceName() const OVERRIDE;
     virtual bool isMouseEvent() const OVERRIDE;
     virtual bool isWheelEvent() const OVERRIDE;
 
@@ -114,7 +114,7 @@
 
 DEFINE_EVENT_TYPE_CASTS(WheelEvent);
 
-class WheelEventDispatchMediator : public EventDispatchMediator {
+class WheelEventDispatchMediator FINAL : public EventDispatchMediator {
 public:
     static PassRefPtr<WheelEventDispatchMediator> create(const PlatformWheelEvent&, PassRefPtr<AbstractView>);
 private:
diff --git a/Source/core/events/WindowEventContext.cpp b/Source/core/events/WindowEventContext.cpp
index 673ef36..b788f04 100644
--- a/Source/core/events/WindowEventContext.cpp
+++ b/Source/core/events/WindowEventContext.cpp
@@ -28,26 +28,26 @@
 #include "core/events/WindowEventContext.h"
 
 #include "core/dom/Document.h"
-#include "core/events/Event.h"
-#include "core/events/EventContext.h"
 #include "core/dom/Node.h"
+#include "core/events/Event.h"
+#include "core/events/NodeEventContext.h"
 #include "core/frame/DOMWindow.h"
 
 namespace WebCore {
 
-WindowEventContext::WindowEventContext(Event* event, PassRefPtr<Node> node, const EventContext* topEventContext)
+WindowEventContext::WindowEventContext(Event* event, PassRefPtr<Node> node, const NodeEventContext* topNodeEventContext)
 {
     // We don't dispatch load events to the window. This quirk was originally
     // added because Mozilla doesn't propagate load events to the window object.
     if (event->type() == EventTypeNames::load)
         return;
 
-    Node* topLevelContainer = topEventContext ? topEventContext->node() : node.get();
+    Node* topLevelContainer = topNodeEventContext ? topNodeEventContext->node() : node.get();
     if (!topLevelContainer->isDocumentNode())
         return;
 
     m_window = toDocument(topLevelContainer)->domWindow();
-    m_target = topEventContext ? topEventContext->target() : node.get();
+    m_target = topNodeEventContext ? topNodeEventContext->target() : node.get();
 }
 
 bool WindowEventContext::handleLocalEvents(Event* event)
diff --git a/Source/core/events/WindowEventContext.h b/Source/core/events/WindowEventContext.h
index 25c5079..f7c2acd 100644
--- a/Source/core/events/WindowEventContext.h
+++ b/Source/core/events/WindowEventContext.h
@@ -33,13 +33,13 @@
 
 class DOMWindow;
 class EventTarget;
-class EventContext;
 class Event;
 class Node;
+class NodeEventContext;
 
 class WindowEventContext {
 public:
-    WindowEventContext(Event*, PassRefPtr<Node>, const EventContext*);
+    WindowEventContext(Event*, PassRefPtr<Node>, const NodeEventContext*);
 
     DOMWindow* window() const;
     EventTarget* target() const;