Changeset 71934 in webkit


Ignore:
Timestamp:
Nov 12, 2010 11:49:40 AM (13 years ago)
Author:
Dimitri Glazkov
Message:

2010-11-05 Dimitri Glazkov <Dimitri Glazkov>

Reviewed by Darin Adler.

Implement shadow DOM-aware event targeting and introduce EventContext to track the context of each event dispatch.
https://bugs.webkit.org/show_bug.cgi?id=46015

Added more test coverage around events crossing shadow DOM boundaries and tweaked existing tests.

  • fast/events/shadow-boundary-crossing-2-expected.txt: Added.
  • fast/events/shadow-boundary-crossing-2.html: Added.
  • fast/events/shadow-boundary-crossing.html: Tuned to better reflect its point:

the event should indeed fire (it used to be swallowed), but its target
should be a non-shadow node.

  • media/audio-delete-while-slider-thumb-clicked.html : Tweaked to actually click on

the scrubber thumb (it was off by 2 pixels).

2010-11-05 Dimitri Glazkov <Dimitri Glazkov>

Reviewed by Darin Adler.

Implement shadow DOM-aware event targeting and introduce EventContext to track the context of each event dispatch.
https://bugs.webkit.org/show_bug.cgi?id=46015

Test: fast/events/shadow-boundary-crossing-2.html

This patch adds the notion of EventContext (and a very similar-acting WindowEventContext, specifically
for DOMWindow), an abstraction that carries information around dispatching an event for any given Node.

This abstraction is necessary to ensure that events, fired from shadow DOM nodes are properly retargeted to
appear as if they are coming from their host, thus never exposing the shadow DOM nodes to the world outside.

  • Android.mk: Added EventContext, WindowEventContext files.
  • CMakeLists.txt: Ditto.
  • GNUmakefile.am: Ditto.
  • WebCore.gypi: Ditto.
  • WebCore.pro: Ditto.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • WebCore.vcproj/WebCore.vcproj: Ditto.
  • dom/ContainerNode.cpp: (WebCore::notifyChildInserted): Changed to be shadow DOM-aware.
  • dom/EventContext.cpp: Added.
  • dom/EventContext.h: Added.
  • dom/Node.cpp: (WebCore::Node::markAncestorsWithChildNeedsStyleRecalc): Changed to be shadow DOM-aware. (WebCore::Node::createRendererIfNeeded): Ditto. (WebCore::Node::parentOrHostNode): Added new helper method. (WebCore::Node::enclosingLinkEventParentOrSelf): Changed to be shadow DOM-aware. (WebCore::eventTargetRespectingSVGTargetRules): Collapsed two helper methods into one. (WebCore::Node::getEventAncestors): Renamed and refactored to collect a vector of EventContexts. (WebCore::Node::topEventContext): Added. (WebCore::eventHasListeners): Changed to use EventContexts. (WebCore::Node::dispatchGenericEvent): Ditto.
  • dom/Node.h: Removed eventParentNode that's no longer needed, added parentOrHostNode decl,

and changed signature of eventAncestors to use EventContexts.

  • dom/Text.cpp: (WebCore::Text::createRenderer): Changed to be shadow DOM-aware.
  • dom/WindowEventContext.cpp: Added.
  • dom/WindowEventContext.h: Added.
  • inspector/InspectorDOMAgent.cpp: (WebCore::InspectorDOMAgent::getEventListenersForNode): Changed to use EventContexts.
  • page/EventHandler.cpp: (WebCore::EventHandler::updateMouseEventTargetNode): Removed code that's no longer necessary.
  • rendering/RenderTextControlMultiLine.cpp: (WebCore::RenderTextControlMultiLine::subtreeHasChanged): Removed event invocation that's

no longer necessary.

  • rendering/ShadowElement.h: Made m_shadowParent a RefPtr to avoid stale references when parent is deleted.
  • rendering/TextControlInnerElements.cpp: (WebCore::TextControlInnerTextElement::defaultEventHandler): Flipped the condition back

from where it was prior to r60418.

  • svg/SVGElement.cpp: Removed eventParentNode that's no longer needed.
  • svg/SVGElement.h: Ditto.
Location:
trunk
Files:
6 added
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r71929 r71934  
     12010-11-05  Dimitri Glazkov  <dglazkov@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Implement shadow DOM-aware event targeting and introduce EventContext to track the context of each event dispatch.
     6        https://bugs.webkit.org/show_bug.cgi?id=46015
     7
     8        Added more test coverage around events crossing shadow DOM boundaries and tweaked existing tests.
     9
     10        * fast/events/shadow-boundary-crossing-2-expected.txt: Added.
     11        * fast/events/shadow-boundary-crossing-2.html: Added.
     12        * fast/events/shadow-boundary-crossing.html: Tuned to better reflect its point:
     13            the event should indeed fire (it used to be swallowed), but its target
     14            should be a non-shadow node.
     15        * media/audio-delete-while-slider-thumb-clicked.html :  Tweaked to actually click on
     16            the scrubber thumb (it was off by 2 pixels).
     17
    1182010-11-12  Mihai Parparita  <mihaip@chromium.org>
    219
  • trunk/LayoutTests/fast/events/shadow-boundary-crossing.html

    r71278 r71934  
    33    <title></title>
    44    <script type="text/javascript">
    5         var fired = false;
     5        var success;
     6        var target;
    67
    78        function selectStart(event)
    89        {
    9             fired = true;
     10            success = event.target == target;
    1011        }
    1112
     
    1617            layoutTestController.dumpAsText();
    1718
    18             var target = document.getElementById("target");
     19            target = document.getElementById("target");
    1920            var x = target.offsetLeft + target.offsetWidth / 2;
    2021            var y = target.offsetTop + target.offsetHeight / 2;
     
    2425            eventSender.mouseUp();
    2526
    26             document.getElementById("result").innerText = fired ? "FAIL" : "PASS";
     27            document.getElementById("result").innerText = !success ? "FAIL" : "PASS";
    2728        }
    2829
  • trunk/LayoutTests/media/audio-delete-while-slider-thumb-clicked.html

    r71278 r71934  
    5151                var audio = document.getElementById('audio');
    5252
    53                 var middle = audio.offsetLeft + (audio.offsetWidth / 2);
    54                 var bottom = audio.offsetTop + audio.offsetHeight;
     53                var center = audio.offsetLeft + (audio.offsetWidth / 2);
     54                var middle = audio.offsetTop + (audio.offsetHeight / 2);
    5555               
    56                 var x = middle + 16 + 16 + 8;
    57                 var y = bottom - 8;
     56                var x = center + 16 + 16 + 8;
     57                var y = middle;
    5858
    5959                // drag slider, leave the mouse down
  • trunk/WebCore/Android.mk

    r71512 r71934  
    133133        dom/ErrorEvent.cpp \
    134134        dom/Event.cpp \
     135        dom/EventContext.cpp \
    135136        dom/EventNames.cpp \
    136137        dom/EventTarget.cpp \
     
    193194        dom/WebKitTransitionEvent.cpp \
    194195        dom/WheelEvent.cpp \
     196        dom/WindowEventContext.cpp \
    195197        dom/XMLDocumentParser.cpp \
    196198        dom/XMLDocumentParserLibxml2.cpp \
  • trunk/WebCore/CMakeLists.txt

    r71802 r71934  
    826826    dom/ErrorEvent.cpp
    827827    dom/Event.cpp
     828    dom/EventContext.cpp
    828829    dom/EventNames.cpp
    829830    dom/EventTarget.cpp
     
    883884    dom/WebKitTransitionEvent.cpp
    884885    dom/WheelEvent.cpp
     886    dom/WindowEventContext.cpp
    885887    dom/XMLDocumentParser.cpp
    886888    dom/XMLDocumentParserLibxml2.cpp
  • trunk/WebCore/ChangeLog

    r71933 r71934  
     12010-11-05  Dimitri Glazkov  <dglazkov@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Implement shadow DOM-aware event targeting and introduce EventContext to track the context of each event dispatch.
     6        https://bugs.webkit.org/show_bug.cgi?id=46015
     7
     8        Test: fast/events/shadow-boundary-crossing-2.html
     9
     10        This patch adds the notion of EventContext (and a very similar-acting WindowEventContext, specifically
     11        for DOMWindow), an abstraction that carries information around dispatching an event for any given Node.
     12
     13        This abstraction is necessary to ensure that events, fired from shadow DOM nodes are properly retargeted to
     14        appear as if they are coming from their host, thus never exposing the shadow DOM nodes to the world outside.
     15
     16        * Android.mk: Added EventContext, WindowEventContext files.
     17        * CMakeLists.txt: Ditto.
     18        * GNUmakefile.am: Ditto.
     19        * WebCore.gypi: Ditto.
     20        * WebCore.pro: Ditto.
     21        * WebCore.xcodeproj/project.pbxproj: Ditto.
     22        * WebCore.vcproj/WebCore.vcproj: Ditto.
     23        * dom/ContainerNode.cpp:
     24        (WebCore::notifyChildInserted): Changed to be shadow DOM-aware.
     25        * dom/EventContext.cpp: Added.
     26        * dom/EventContext.h: Added.
     27        * dom/Node.cpp:
     28        (WebCore::Node::markAncestorsWithChildNeedsStyleRecalc): Changed to be shadow DOM-aware.
     29        (WebCore::Node::createRendererIfNeeded): Ditto.
     30        (WebCore::Node::parentOrHostNode): Added new helper method.
     31        (WebCore::Node::enclosingLinkEventParentOrSelf): Changed to be shadow DOM-aware.
     32        (WebCore::eventTargetRespectingSVGTargetRules): Collapsed two helper methods into one.
     33        (WebCore::Node::getEventAncestors): Renamed and refactored to collect a vector of EventContexts.
     34        (WebCore::Node::topEventContext): Added.
     35        (WebCore::eventHasListeners): Changed to use EventContexts.
     36        (WebCore::Node::dispatchGenericEvent): Ditto.
     37        * dom/Node.h: Removed eventParentNode that's no longer needed, added parentOrHostNode decl,
     38            and changed signature of eventAncestors to use EventContexts.
     39        * dom/Text.cpp:
     40        (WebCore::Text::createRenderer): Changed to be shadow DOM-aware.
     41        * dom/WindowEventContext.cpp: Added.
     42        * dom/WindowEventContext.h: Added.
     43        * inspector/InspectorDOMAgent.cpp:
     44        (WebCore::InspectorDOMAgent::getEventListenersForNode): Changed to use EventContexts.
     45        * page/EventHandler.cpp:
     46        (WebCore::EventHandler::updateMouseEventTargetNode): Removed code that's no longer necessary.
     47        * rendering/RenderTextControlMultiLine.cpp:
     48        (WebCore::RenderTextControlMultiLine::subtreeHasChanged): Removed event invocation that's
     49            no longer necessary.
     50        * rendering/ShadowElement.h: Made m_shadowParent a RefPtr to avoid stale references when parent
     51        is deleted.
     52        * rendering/TextControlInnerElements.cpp:
     53        (WebCore::TextControlInnerTextElement::defaultEventHandler): Flipped the condition back
     54            from where it was prior to r60418.
     55        * svg/SVGElement.cpp: Removed eventParentNode that's no longer needed.
     56        * svg/SVGElement.h: Ditto.
     57
    1582010-11-12  Ryuan Choi  <ryuan.choi@samsung.com>
    259
  • trunk/WebCore/GNUmakefile.am

    r71903 r71934  
    11361136        WebCore/dom/ErrorEvent.h \
    11371137        WebCore/dom/Event.cpp \
     1138        WebCore/dom/Event.h \
     1139        WebCore/dom/EventContext.cpp \
     1140        WebCore/dom/EventContext.h \
    11381141        WebCore/dom/EventException.h \
    1139         WebCore/dom/Event.h \
    11401142        WebCore/dom/EventListener.h \
    11411143        WebCore/dom/EventNames.cpp \
     
    12651267        WebCore/dom/WheelEvent.cpp \
    12661268        WebCore/dom/WheelEvent.h \
     1269        WebCore/dom/WindowEventContext.cpp \
     1270        WebCore/dom/WindowEventContext.h \
    12671271        WebCore/dom/XMLDocumentParser.cpp \
    12681272        WebCore/dom/XMLDocumentParser.h \
  • trunk/WebCore/WebCore.gypi

    r71903 r71934  
    12031203            'dom/Event.cpp',
    12041204            'dom/Event.h',
     1205            'dom/EventContext.cpp',
     1206            'dom/EventContext.h',
    12051207            'dom/EventException.h',
    12061208            'dom/EventListener.h',
     
    13381340            'dom/WheelEvent.cpp',
    13391341            'dom/WheelEvent.h',
     1342            'dom/WindowEventContext.cpp',
     1343            'dom/WindowEventContext.h',
    13401344            'dom/XMLDocumentParser.cpp',
    13411345            'dom/XMLDocumentParser.h',
  • trunk/WebCore/WebCore.pro

    r71802 r71934  
    714714    dom/ErrorEvent.cpp \
    715715    dom/Event.cpp \
     716    dom/EventContext.cpp \
    716717    dom/EventNames.cpp \
    717718    dom/EventTarget.cpp \
     
    774775    dom/WebKitTransitionEvent.cpp \
    775776    dom/WheelEvent.cpp \
     777    dom/WindowEventContext.cpp \
    776778    dom/XMLDocumentParser.cpp \
    777779    dom/XMLDocumentParserQt.cpp \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r71903 r71934  
    4238942389                        </File>
    4239042390                        <File
     42391                                RelativePath="..\dom\EventContext.cpp"
     42392                                >
     42393                                <FileConfiguration
     42394                                        Name="Debug|Win32"
     42395                                        ExcludedFromBuild="true"
     42396                                        >
     42397                                        <Tool
     42398                                                Name="VCCLCompilerTool"
     42399                                        />
     42400                                </FileConfiguration>
     42401                                <FileConfiguration
     42402                                        Name="Release|Win32"
     42403                                        ExcludedFromBuild="true"
     42404                                        >
     42405                                        <Tool
     42406                                                Name="VCCLCompilerTool"
     42407                                        />
     42408                                </FileConfiguration>
     42409                                <FileConfiguration
     42410                                        Name="Debug_Internal|Win32"
     42411                                        ExcludedFromBuild="true"
     42412                                        >
     42413                                        <Tool
     42414                                                Name="VCCLCompilerTool"
     42415                                        />
     42416                                </FileConfiguration>
     42417                                <FileConfiguration
     42418                                        Name="Debug_Cairo|Win32"
     42419                                        ExcludedFromBuild="true"
     42420                                        >
     42421                                        <Tool
     42422                                                Name="VCCLCompilerTool"
     42423                                        />
     42424                                </FileConfiguration>
     42425                                <FileConfiguration
     42426                                        Name="Release_Cairo|Win32"
     42427                                        ExcludedFromBuild="true"
     42428                                        >
     42429                                        <Tool
     42430                                                Name="VCCLCompilerTool"
     42431                                        />
     42432                                </FileConfiguration>
     42433                                <FileConfiguration
     42434                                        Name="Debug_All|Win32"
     42435                                        ExcludedFromBuild="true"
     42436                                        >
     42437                                        <Tool
     42438                                                Name="VCCLCompilerTool"
     42439                                        />
     42440                                </FileConfiguration>
     42441                        </File>
     42442                        <File
     42443                                RelativePath="..\dom\EventContext.h"
     42444                                >
     42445                        </File>
     42446                        <File
    4239142447                                RelativePath="..\dom\EventException.h"
    4239242448                                >
     
    4547445530                        <File
    4547545531                                RelativePath="..\dom\WheelEvent.h"
     45532                                >
     45533                        </File>
     45534                        <File
     45535                                RelativePath="..\dom\WindowEventContext.cpp"
     45536                                >
     45537                                <FileConfiguration
     45538                                        Name="Debug|Win32"
     45539                                        ExcludedFromBuild="true"
     45540                                        >
     45541                                        <Tool
     45542                                                Name="VCCLCompilerTool"
     45543                                        />
     45544                                </FileConfiguration>
     45545                                <FileConfiguration
     45546                                        Name="Release|Win32"
     45547                                        ExcludedFromBuild="true"
     45548                                        >
     45549                                        <Tool
     45550                                                Name="VCCLCompilerTool"
     45551                                        />
     45552                                </FileConfiguration>
     45553                                <FileConfiguration
     45554                                        Name="Debug_Internal|Win32"
     45555                                        ExcludedFromBuild="true"
     45556                                        >
     45557                                        <Tool
     45558                                                Name="VCCLCompilerTool"
     45559                                        />
     45560                                </FileConfiguration>
     45561                                <FileConfiguration
     45562                                        Name="Debug_Cairo|Win32"
     45563                                        ExcludedFromBuild="true"
     45564                                        >
     45565                                        <Tool
     45566                                                Name="VCCLCompilerTool"
     45567                                        />
     45568                                </FileConfiguration>
     45569                                <FileConfiguration
     45570                                        Name="Release_Cairo|Win32"
     45571                                        ExcludedFromBuild="true"
     45572                                        >
     45573                                        <Tool
     45574                                                Name="VCCLCompilerTool"
     45575                                        />
     45576                                </FileConfiguration>
     45577                                <FileConfiguration
     45578                                        Name="Debug_All|Win32"
     45579                                        ExcludedFromBuild="true"
     45580                                        >
     45581                                        <Tool
     45582                                                Name="VCCLCompilerTool"
     45583                                        />
     45584                                </FileConfiguration>
     45585                        </File>
     45586                        <File
     45587                                RelativePath="..\dom\WindowEventContext.h"
    4547645588                                >
    4547745589                        </File>
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r71903 r71934  
    903903                411046410FA222A600BA436A /* ScriptEventListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 4110463F0FA222A600BA436A /* ScriptEventListener.h */; };
    904904                411046420FA222A600BA436A /* ScriptEventListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 411046400FA222A600BA436A /* ScriptEventListener.cpp */; };
     905                4123E569127B3041000FEEA7 /* WindowEventContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 4123E567127B3041000FEEA7 /* WindowEventContext.h */; };
     906                4123E56A127B3041000FEEA7 /* WindowEventContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4123E568127B3041000FEEA7 /* WindowEventContext.cpp */; };
    905907                4127D5370F8AAB1D00E424F5 /* ScriptState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4127D5360F8AAB1D00E424F5 /* ScriptState.cpp */; };
     908                4138D3351244054800323D33 /* EventContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 4138D3331244054800323D33 /* EventContext.h */; };
     909                4138D3361244054800323D33 /* EventContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4138D3341244054800323D33 /* EventContext.cpp */; };
    906910                4162A450101145AE00DFF3ED /* DedicatedWorkerContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4162A44D101145AE00DFF3ED /* DedicatedWorkerContext.cpp */; };
    907911                4162A451101145AE00DFF3ED /* DedicatedWorkerContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 4162A44E101145AE00DFF3ED /* DedicatedWorkerContext.h */; };
     
    69987002                4110463F0FA222A600BA436A /* ScriptEventListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptEventListener.h; sourceTree = "<group>"; };
    69997003                411046400FA222A600BA436A /* ScriptEventListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptEventListener.cpp; sourceTree = "<group>"; };
     7004                4123E567127B3041000FEEA7 /* WindowEventContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowEventContext.h; sourceTree = "<group>"; };
     7005                4123E568127B3041000FEEA7 /* WindowEventContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WindowEventContext.cpp; sourceTree = "<group>"; };
    70007006                4127D5360F8AAB1D00E424F5 /* ScriptState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptState.cpp; sourceTree = "<group>"; };
     7007                4138D3331244054800323D33 /* EventContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventContext.h; sourceTree = "<group>"; };
     7008                4138D3341244054800323D33 /* EventContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventContext.cpp; sourceTree = "<group>"; };
    70017009                4162A44D101145AE00DFF3ED /* DedicatedWorkerContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DedicatedWorkerContext.cpp; path = workers/DedicatedWorkerContext.cpp; sourceTree = "<group>"; };
    70027010                4162A44E101145AE00DFF3ED /* DedicatedWorkerContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DedicatedWorkerContext.h; path = workers/DedicatedWorkerContext.h; sourceTree = "<group>"; };
     
    1826918277                                85031B2C0A44EFC700F992E0 /* Event.h */,
    1827018278                                14E836D209F8512000B85AE4 /* Event.idl */,
     18279                                4138D3341244054800323D33 /* EventContext.cpp */,
     18280                                4138D3331244054800323D33 /* EventContext.h */,
    1827118281                                BC60D9090D2A17CE00B9918F /* EventException.h */,
    1827218282                                BC60D90A0D2A17CE00B9918F /* EventException.idl */,
     
    1842918439                                85031B3B0A44EFC700F992E0 /* WheelEvent.h */,
    1843018440                                93EEC1F709C2877700C515D1 /* WheelEvent.idl */,
     18441                                4123E568127B3041000FEEA7 /* WindowEventContext.cpp */,
     18442                                4123E567127B3041000FEEA7 /* WindowEventContext.h */,
    1843118443                                F523D30902DE4476018635CA /* XMLDocumentParser.cpp */,
    1843218444                                F523D30A02DE4476018635CA /* XMLDocumentParser.h */,
     
    1959519607                                2ECF7AE210162B5800427DE7 /* ErrorEvent.h in Headers */,
    1959619608                                85031B420A44EFC700F992E0 /* Event.h in Headers */,
     19609                                4138D3351244054800323D33 /* EventContext.h in Headers */,
    1959719610                                BC60D90C0D2A17CE00B9918F /* EventException.h in Headers */,
    1959819611                                93C09A530B064DB3005ABD4D /* EventHandler.h in Headers */,
     
    2127521288                                9380F47409A11AB4001FDB34 /* Widget.h in Headers */,
    2127621289                                939B02EF0EA2DBC400C54570 /* WidthIterator.h in Headers */,
     21290                                4123E569127B3041000FEEA7 /* WindowEventContext.h in Headers */,
    2127721291                                BC8243E90D0CFD7500460C8F /* WindowFeatures.h in Headers */,
    2127821292                                E1E1BF00115FF6FB006F52CA /* WindowsKeyboardCodes.h in Headers */,
     
    2224722261                                2ECF7AE110162B5800427DE7 /* ErrorEvent.cpp in Sources */,
    2224822262                                85031B410A44EFC700F992E0 /* Event.cpp in Sources */,
     22263                                4138D3361244054800323D33 /* EventContext.cpp in Sources */,
    2224922264                                93C09A810B064F00005ABD4D /* EventHandler.cpp in Sources */,
    2225022265                                93C09A7F0B064EEF005ABD4D /* EventHandlerMac.mm in Sources */,
     
    2385423869                                9380F47809A11ACC001FDB34 /* WidgetMac.mm in Sources */,
    2385523870                                939B02EE0EA2DBC400C54570 /* WidthIterator.cpp in Sources */,
     23871                                4123E56A127B3041000FEEA7 /* WindowEventContext.cpp in Sources */,
    2385623872                                BC8243E80D0CFD7500460C8F /* WindowFeatures.cpp in Sources */,
    2385723873                                08203A9F0ED8C35300B8B61A /* WMLAccessElement.cpp in Sources */,
  • trunk/WebCore/dom/ContainerNode.cpp

    r71918 r71934  
    10091009    RefPtr<Document> document = child->document();
    10101010
    1011     if (c->parentNode() && c->parentNode()->inDocument())
     1011    Node* parentOrHostNode = c->parentOrHostNode();
     1012    if (parentOrHostNode && parentOrHostNode->inDocument())
    10121013        c->insertedIntoDocument();
    10131014    else
  • trunk/WebCore/dom/DOMAllInOne.cpp

    r71278 r71934  
    7070#include "ErrorEvent.cpp"
    7171#include "Event.cpp"
     72#include "EventContext.cpp"
    7273#include "EventNames.cpp"
    7374#include "EventTarget.cpp"
     
    127128#include "WebKitTransitionEvent.cpp"
    128129#include "WheelEvent.cpp"
     130#include "WindowEventContext.cpp"
    129131#include "XMLDocumentParser.cpp"
    130132#include "XMLDocumentParserScope.cpp"
  • trunk/WebCore/dom/Node.cpp

    r71278 r71934  
    4646#include "Element.h"
    4747#include "Event.h"
     48#include "EventContext.h"
    4849#include "EventException.h"
    4950#include "EventHandler.h"
     
    8182#include "WebKitTransitionEvent.h"
    8283#include "WheelEvent.h"
     84#include "WindowEventContext.h"
    8385#include "XMLNames.h"
    8486#include "htmlediting.h"
     
    735737inline void Node::markAncestorsWithChildNeedsStyleRecalc()
    736738{
    737     for (ContainerNode* p = parentNode(); p && !p->childNeedsStyleRecalc(); p = p->parentNode())
     739    for (ContainerNode* p = parentOrHostNode(); p && !p->childNeedsStyleRecalc(); p = p->parentOrHostNode())
    738740        p->setChildNeedsStyleRecalc();
    739    
     741
    740742    if (document()->childNeedsStyleRecalc())
    741743        document()->scheduleStyleRecalc();
     
    13221324    ASSERT(!renderer());
    13231325   
    1324     ContainerNode* parent = parentNode();   
     1326    ContainerNode* parent = parentOrHostNode();
    13251327    ASSERT(parent);
    13261328   
     
    22402242}
    22412243
    2242 ContainerNode* Node::eventParentNode()
    2243 {
    2244     return parentNode();
    2245 }
    2246 
    22472244Node* Node::enclosingLinkEventParentOrSelf()
    22482245{
    2249     for (Node* node = this; node; node = node->eventParentNode()) {
     2246    for (Node* node = this; node; node = node->parentOrHostNode()) {
    22502247        // For imagemaps, the enclosing link node is the associated area element not the image itself.
    22512248        // So we don't let images be the enclosingLinkNode, even though isLink sometimes returns true
     
    24852482}
    24862483
     2484static inline EventTarget* eventTargetRespectingSVGTargetRules(Node* referenceNode)
     2485{
     2486    ASSERT(referenceNode);
     2487
    24872488#if ENABLE(SVG)
    2488 static inline SVGElementInstance* eventTargetAsSVGElementInstance(Node* referenceNode)
    2489 {
    2490     ASSERT(referenceNode);
    24912489    if (!referenceNode->isSVGElement())
    2492         return 0;
     2490        return referenceNode;
    24932491
    24942492    // Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
     
    25042502            return instance;
    25052503    }
    2506 
    2507     return 0;
    2508 }
    25092504#endif
    25102505
    2511 static inline EventTarget* eventTargetRespectingSVGTargetRules(Node* referenceNode)
    2512 {
    2513     ASSERT(referenceNode);
     2506    return referenceNode;
     2507}
     2508
     2509void Node::getEventAncestors(Vector<EventContext>& ancestors, EventTarget* originalTarget, EventDispatchBehavior behavior)
     2510{
     2511    if (!inDocument())
     2512        return;
     2513
     2514    EventTarget* target = originalTarget;
     2515    Node* ancestor = this;
     2516    bool shouldSkipNextAncestor = false;
     2517    while (true) {
     2518        if (ancestor->isShadowNode()) {
     2519            if (behavior == StayInsideShadowDOM)
     2520                return;
     2521            ancestor = ancestor->shadowParentNode();
     2522            if (!shouldSkipNextAncestor)
     2523                target = ancestor;
     2524        } else
     2525            ancestor = ancestor->parentNode();
     2526
     2527        if (!ancestor)
     2528            return;
    25142529
    25152530#if ENABLE(SVG)
    2516     if (SVGElementInstance* instance = eventTargetAsSVGElementInstance(referenceNode)) {
    2517         ASSERT(instance->shadowTreeElement() == referenceNode);
    2518         return instance;
    2519     }
     2531        // Skip SVGShadowTreeRootElement.
     2532        shouldSkipNextAncestor = ancestor->isSVGElement() && ancestor->isShadowNode();
     2533        if (shouldSkipNextAncestor)
     2534            continue;
    25202535#endif
    2521 
    2522     return referenceNode;
    2523 }
    2524 
    2525 void Node::eventAncestors(Vector<RefPtr<ContainerNode> > &ancestors)
    2526 {
    2527     if (inDocument()) {
    2528         for (ContainerNode* ancestor = eventParentNode(); ancestor; ancestor = ancestor->eventParentNode()) {
    2529 #if ENABLE(SVG)
    2530             // Skip <use> shadow tree elements.
    2531             if (ancestor->isSVGElement() && ancestor->isShadowNode())
    2532                 continue;
    2533 #endif
    2534             ancestors.append(ancestor);
    2535         }
     2536        // FIXME: Unroll the extra loop inside eventTargetRespectingSVGTargetRules into this loop.
     2537        ancestors.append(EventContext(ancestor, eventTargetRespectingSVGTargetRules(ancestor), target));
     2538
    25362539    }
    25372540}
     
    25462549    RefPtr<FrameView> view = document()->view();
    25472550    return dispatchGenericEvent(event.release());
     2551}
     2552
     2553static const EventContext* topEventContext(const Vector<EventContext>& ancestors)
     2554{
     2555    return ancestors.isEmpty() ? 0 : &ancestors.last();
    25482556}
    25492557
     
    25602568    // Be sure to ref all of nodes since event handlers could result in the last reference going away.
    25612569    RefPtr<Node> thisNode(this);
    2562     Vector<RefPtr<ContainerNode> > ancestors;
    2563     eventAncestors(ancestors);
    2564 
    2565     // Set up a pointer to indicate whether / where to dispatch window events.
    2566     // We don't dispatch load events to the window. That quirk was originally
    2567     // added because Mozilla doesn't propagate load events to the window object.
    2568     DOMWindow* targetForWindowEvents = 0;
    2569     if (event->type() != eventNames().loadEvent) {
    2570         Node* topLevelContainer = ancestors.isEmpty() ? this : ancestors.last().get();
    2571         if (topLevelContainer->isDocumentNode())
    2572             targetForWindowEvents = static_cast<Document*>(topLevelContainer)->domWindow();
    2573     }
    2574 
    2575     InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchEvent(document(), *event, targetForWindowEvents, this, ancestors);
     2570    RefPtr<EventTarget> originalTarget = event->target();
     2571    Vector<EventContext> ancestors;
     2572    getEventAncestors(ancestors, originalTarget.get(), event->isMutationEvent() ? StayInsideShadowDOM : RetargetEvent);
     2573
     2574    WindowEventContext windowContext(event.get(), this, topEventContext(ancestors));
     2575
     2576    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchEvent(document(), *event, windowContext.window(), this, ancestors);
    25762577
    25772578    // Give the target node a chance to do some work before DOM event handlers get a crack.
     
    25832584    event->setEventPhase(Event::CAPTURING_PHASE);
    25842585
    2585     if (targetForWindowEvents) {
    2586         event->setCurrentTarget(targetForWindowEvents);
    2587         targetForWindowEvents->fireEventListeners(event.get());
     2586    if (windowContext.handleLocalEvents(event.get()) && event->propagationStopped())
     2587        goto doneDispatching;
     2588
     2589    for (size_t i = ancestors.size(); i; --i) {
     2590        ancestors[i - 1].handleLocalEvents(event.get());
    25882591        if (event->propagationStopped())
    25892592            goto doneDispatching;
    25902593    }
    2591     for (size_t i = ancestors.size(); i; --i) {
    2592         ContainerNode* ancestor = ancestors[i - 1].get();
    2593         event->setCurrentTarget(eventTargetRespectingSVGTargetRules(ancestor));
    2594         ancestor->handleLocalEvents(event.get());
    2595         if (event->propagationStopped())
    2596             goto doneDispatching;
    2597     }
    25982594
    25992595    event->setEventPhase(Event::AT_TARGET);
    2600 
     2596    event->setTarget(originalTarget.get());
    26012597    event->setCurrentTarget(eventTargetRespectingSVGTargetRules(this));
    26022598    handleLocalEvents(event.get());
     
    26102606        size_t size = ancestors.size();
    26112607        for (size_t i = 0; i < size; ++i) {
    2612             ContainerNode* ancestor = ancestors[i].get();
    2613             event->setCurrentTarget(eventTargetRespectingSVGTargetRules(ancestor));
    2614             ancestor->handleLocalEvents(event.get());
     2608            ancestors[i].handleLocalEvents(event.get());
    26152609            if (event->propagationStopped() || event->cancelBubble())
    26162610                goto doneDispatching;
    26172611        }
    2618         if (targetForWindowEvents) {
    2619             event->setCurrentTarget(targetForWindowEvents);
    2620             targetForWindowEvents->fireEventListeners(event.get());
    2621             if (event->propagationStopped() || event->cancelBubble())
    2622                 goto doneDispatching;
    2623         }
     2612        windowContext.handleLocalEvents(event.get());
    26242613    }
    26252614
    26262615doneDispatching:
     2616    event->setTarget(originalTarget.get());
    26272617    event->setCurrentTarget(0);
    26282618    event->setEventPhase(0);
     
    26452635            size_t size = ancestors.size();
    26462636            for (size_t i = 0; i < size; ++i) {
    2647                 ContainerNode* ancestor = ancestors[i].get();
    2648                 ancestor->defaultEventHandler(event.get());
     2637                ancestors[i].node()->defaultEventHandler(event.get());
    26492638                ASSERT(!event->defaultPrevented());
    26502639                if (event->defaultHandled())
     
    26562645doneWithDefault:
    26572646
     2647    // Ensure that after event dispatch, the event's target object is the
     2648    // outermost shadow DOM boundary.
     2649    event->setTarget(windowContext.target());
     2650    event->setCurrentTarget(0);
    26582651    InspectorInstrumentation::didDispatchEvent(cookie);
    26592652
  • trunk/WebCore/dom/Node.h

    r71278 r71934  
    5050class Element;
    5151class Event;
     52class EventContext;
    5253class EventListener;
    5354class FloatPoint;
     
    8485    FullStyleChange = 2 << nodeStyleChangeShift,
    8586    SyntheticStyleChange = 3 << nodeStyleChangeShift
     87};
     88
     89enum EventDispatchBehavior {
     90    RetargetEvent,
     91    StayInsideShadowDOM
    8692};
    8793
     
    205211    Node* shadowTreeRootNode();
    206212    bool isInShadowTree();
    207 
    208     // The node's parent for the purpose of event capture and bubbling.
    209     virtual ContainerNode* eventParentNode();
     213    // Node's parent or shadow tree host.
     214    ContainerNode* parentOrHostNode();
    210215
    211216    // Returns the enclosing event parent node (or self) that, when clicked, would trigger a navigation.
     
    213218
    214219    // Node ancestors when concerned about event flow.
    215     // FIXME: Should be named getEventAncestors.
    216     void eventAncestors(Vector<RefPtr<ContainerNode> > &ancestors);
     220    void getEventAncestors(Vector<EventContext>& ancestors, EventTarget*, EventDispatchBehavior = RetargetEvent);
    217221
    218222    bool isBlockFlow() const;
     
    694698}
    695699
     700inline ContainerNode* Node::parentOrHostNode()
     701{
     702    if (ContainerNode* parent = parentNode())
     703        return parent;
     704    return shadowParentNode();
     705}
     706
    696707} //namespace
    697708
  • trunk/WebCore/dom/Text.cpp

    r71278 r71934  
    241241{
    242242#if ENABLE(SVG)
    243     if (parentNode()->isSVGElement()
     243    Node* parentOrHost = parentOrHostNode();
     244    if (parentOrHost->isSVGElement()
    244245#if ENABLE(SVG_FOREIGN_OBJECT)
    245         && !parentNode()->hasTagName(SVGNames::foreignObjectTag)
     246        && !parentOrHost->hasTagName(SVGNames::foreignObjectTag)
    246247#endif
    247248    )
  • trunk/WebCore/inspector/InspectorDOMAgent.cpp

    r71745 r71934  
    5252#include "DocumentType.h"
    5353#include "Event.h"
     54#include "EventContext.h"
    5455#include "EventListener.h"
    5556#include "EventNames.h"
     
    614615
    615616    // The Node's Event Ancestors (not including self)
    616     Vector<RefPtr<ContainerNode> > ancestors;
    617     node->eventAncestors(ancestors);
     617    Vector<EventContext> ancestors;
     618    node->getEventAncestors(ancestors, node);
    618619
    619620    // Nodes and their Listeners for the concerned event types (order is top to bottom)
    620621    Vector<EventListenerInfo> eventInformation;
    621622    for (size_t i = ancestors.size(); i; --i) {
    622         ContainerNode* ancestor = ancestors[i - 1].get();
     623        Node* ancestor = ancestors[i - 1].node();
    623624        for (size_t j = 0; j < eventTypesLength; ++j) {
    624625            AtomicString& type = eventTypes[j];
  • trunk/WebCore/inspector/InspectorInstrumentation.cpp

    r71278 r71934  
    3636#include "DOMWindow.h"
    3737#include "Event.h"
     38#include "EventContext.h"
    3839#include "InspectorController.h"
    3940#include "InspectorDOMAgent.h"
     
    5455int InspectorInstrumentation::s_frontendCounter = 0;
    5556
    56 static bool eventHasListeners(const AtomicString& eventType, DOMWindow* window, Node* node, const Vector<RefPtr<ContainerNode> >& ancestors)
     57static bool eventHasListeners(const AtomicString& eventType, DOMWindow* window, Node* node, const Vector<EventContext>& ancestors)
    5758{
    5859    if (window && window->hasEventListeners(eventType))
     
    6364
    6465    for (size_t i = 0; i < ancestors.size(); i++) {
    65         ContainerNode* ancestor = ancestors[i].get();
     66        Node* ancestor = ancestors[i].node();
    6667        if (ancestor->hasEventListeners(eventType))
    6768            return true;
     
    139140        domAgent->characterDataModified(characterData);
    140141}
    141 
    142142
    143143void InspectorInstrumentation::willSendXMLHttpRequestImpl(InspectorController* inspectorController, const String& url)
     
    214214}
    215215
    216 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(InspectorController* inspectorController, const Event& event, DOMWindow* window, Node* node, const Vector<RefPtr<ContainerNode> >& ancestors)
     216InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(InspectorController* inspectorController, const Event& event, DOMWindow* window, Node* node, const Vector<EventContext>& ancestors)
    217217{
    218218    pauseOnNativeEventIfNeeded(inspectorController, listenerEventCategoryType, event.type(), false);
  • trunk/WebCore/inspector/InspectorInstrumentation.h

    r71278 r71934  
    4141class CharacterData;
    4242class Element;
     43class EventContext;
    4344class InspectorController;
    4445class InspectorTimelineAgent;
     
    7475    static InspectorInstrumentationCookie willChangeXHRReadyState(ScriptExecutionContext*, XMLHttpRequest* request);
    7576    static void didChangeXHRReadyState(const InspectorInstrumentationCookie&);
    76     static InspectorInstrumentationCookie willDispatchEvent(Document*, const Event& event, DOMWindow* window, Node* node, const Vector<RefPtr<ContainerNode> >& ancestors);
     77    static InspectorInstrumentationCookie willDispatchEvent(Document*, const Event& event, DOMWindow* window, Node* node, const Vector<EventContext>& ancestors);
    7778    static void didDispatchEvent(const InspectorInstrumentationCookie&);
    7879    static InspectorInstrumentationCookie willDispatchEventOnWindow(Frame*, const Event& event, DOMWindow* window);
     
    131132    static InspectorInstrumentationCookie willChangeXHRReadyStateImpl(InspectorController*, XMLHttpRequest* request);
    132133    static void didChangeXHRReadyStateImpl(const InspectorInstrumentationCookie&);
    133     static InspectorInstrumentationCookie willDispatchEventImpl(InspectorController*, const Event& event, DOMWindow* window, Node* node, const Vector<RefPtr<ContainerNode> >& ancestors);
     134    static InspectorInstrumentationCookie willDispatchEventImpl(InspectorController*, const Event& event, DOMWindow* window, Node* node, const Vector<EventContext>& ancestors);
    134135    static void didDispatchEventImpl(const InspectorInstrumentationCookie&);
    135136    static InspectorInstrumentationCookie willDispatchEventOnWindowImpl(InspectorController*, const Event& event, DOMWindow* window);
     
    226227}
    227228
    228 
    229229inline void InspectorInstrumentation::willSendXMLHttpRequest(ScriptExecutionContext* context, const String& url)
    230230{
     
    294294}
    295295
    296 inline InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEvent(Document* document, const Event& event, DOMWindow* window, Node* node, const Vector<RefPtr<ContainerNode> >& ancestors)
     296inline InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEvent(Document* document, const Event& event, DOMWindow* window, Node* node, const Vector<EventContext>& ancestors)
    297297{
    298298#if ENABLE(INSPECTOR)
  • trunk/WebCore/page/EventHandler.cpp

    r71479 r71934  
    17671767        if (result && result->isTextNode())
    17681768            result = result->parentNode();
    1769         if (result)
    1770             result = result->shadowAncestorNode();
    17711769    }
    17721770    m_nodeUnderMouse = result;
  • trunk/WebCore/rendering/RenderTextControlMultiLine.cpp

    r70072 r71934  
    5252    if (!node()->focused())
    5353        return;
    54 
    55     node()->dispatchEvent(Event::create(eventNames().inputEvent, true, false));
    5654
    5755    if (Frame* frame = this->frame())
  • trunk/WebCore/rendering/ShadowElement.h

    r71278 r71934  
    4444    }
    4545
    46     HTMLElement* shadowParent() const { return m_shadowParent; }
     46    HTMLElement* shadowParent() const { return m_shadowParent.get(); }
    4747
    4848private:
    4949    virtual bool isShadowNode() const { return true; }
    50     virtual ContainerNode* shadowParentNode() { return m_shadowParent; }
     50    virtual ContainerNode* shadowParentNode() { return m_shadowParent.get(); }
    5151
    52     HTMLElement* m_shadowParent;
     52    RefPtr<HTMLElement> m_shadowParent;
    5353};
    5454
  • trunk/WebCore/rendering/TextControlInnerElements.cpp

    r71131 r71934  
    155155            shadowAncestor->defaultEventHandler(event);
    156156    }
    157     if (event->defaultHandled())
     157    if (!event->defaultHandled())
    158158        HTMLDivElement::defaultEventHandler(event);
    159159}
  • trunk/WebCore/svg/SVGElement.cpp

    r71278 r71934  
    348348}
    349349
    350 ContainerNode* SVGElement::eventParentNode()
    351 {
    352     if (ContainerNode* shadowParent = shadowParentNode())
    353         return shadowParent;
    354     return StyledElement::eventParentNode();
    355 }
    356 
    357350}
    358351
  • trunk/WebCore/svg/SVGElement.h

    r71278 r71934  
    100100        virtual bool isSupported(StringImpl* feature, StringImpl* version) const;
    101101
    102         virtual ContainerNode* eventParentNode();
    103 
    104102        virtual bool needsPendingResourceHandling() const { return true; }
    105103        virtual void buildPendingResource() { }
Note: See TracChangeset for help on using the changeset viewer.