Commit 5f8a6dad authored by ap's avatar ap

Reviewed by Darin.

        http://bugs.webkit.org/show_bug.cgi?id=11610
        XMLHttpRequest.onreadystatechange doesn't provide access to the request object

        Created a separate EventTarget class, now that EventTargetNode isn't the only kind.

WebCore:
        * WebCore.xcodeproj/project.pbxproj: Added EventTarget.{h,cpp}

        * bindings/js/kjs_dom.cpp:
        (KJS::toJS): Added an EventTarget variant.
        * bindings/js/kjs_dom.h: Added toJS() for EventTarget; some minor style fixes.

        * bindings/objc/DOM.mm:
        (+[DOMNode _eventTargetWith:WebCore::]):
        * bindings/scripts/CodeGeneratorObjC.pm:
        Added an EventTarget->DOMEventTarget converter in DOMNode (WebCoreInternal). 
        It only works for nodes, since we don't have an ObjC binding for XMLHttpRequest.
        Corrected spelling of internalHeaderContent.

        * dom/Event.cpp:
        (WebCore::Event::setTarget):
        * dom/Event.h:
        (WebCore::Event::target):
        (WebCore::Event::currentTarget):
        (WebCore::Event::setCurrentTarget):
        These methods now work with EventTargets instead of Nodes.

        * dom/EventTarget.cpp: Added.
        (WebCore::EventTarget::~EventTarget):
        (WebCore::EventTarget::toNode):
        (WebCore::EventTarget::toXMLHttpRequest):
        * dom/EventTarget.h: Added.
        (WebCore::EventTarget::ref):
        (WebCore::EventTarget::deref):
        Originally, my intention was to share much of the implementation between 
        EventTargetNode and XHR, but now I don't see anything substantial worth sharing.

        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::dispatchGenericEvent): Cast Node to EventTargetNode.

        * dom/EventTargetNode.h: Made EventTarget methods virtual.
        (WebCore::EventTargetNode::toNode): Added poor man's RTTI to upcast from EventTarget.
        (WebCore::EventTargetNode::refEventTarget):
        (WebCore::EventTargetNode::derefEventTarget):

        * dom/MouseEvent.cpp:
        (WebCore::MouseEvent::toElement):
        (WebCore::MouseEvent::fromElement):
        * dom/MouseRelatedEvent.cpp:
        (WebCore::MouseRelatedEvent::receivedTarget):
        * html/HTMLAnchorElement.cpp:
        (WebCore::HTMLAnchorElement::defaultEventHandler):
        * html/HTMLLabelElement.cpp:
        (WebCore::HTMLLabelElement::defaultEventHandler):
        * page/ContextMenuController.cpp:
        (WebCore::ContextMenuController::handleContextMenuEvent):
        * rendering/RenderSlider.cpp:
        (WebCore::RenderSlider::mouseEventIsInThumb):
        Cast from EventTarget to Node as appropriate.

        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::dispatchEvent):
        (WebCore::XMLHttpRequest::callReadyStateChangeListener):
        Set target and currentTarget before dispatching.

        * xml/xmlhttprequest.h: Made EventTarget methods virtual, added a bool tempEvent parameter
        to match EventTargetNode.
        (WebCore::XMLHttpRequest::toXMLHttpRequest): Added poor man's RTTI to upcast from EventTarget.
        (WebCore::XMLHttpRequest::refEventTarget):
        (WebCore::XMLHttpRequest::derefEventTarget):

LayoutTests:
        * fast/dom/xmlhttprequest-get-expected.txt:
        * http/tests/xmlhttprequest/event-target-expected.txt:
        * http/tests/xmlhttprequest/event-target.html:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@18238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2632b6a0
2006-12-15 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Darin.
http://bugs.webkit.org/show_bug.cgi?id=11610
XMLHttpRequest.onreadystatechange doesn't provide access to the request object
* fast/dom/xmlhttprequest-get-expected.txt:
* http/tests/xmlhttprequest/event-target-expected.txt:
* http/tests/xmlhttprequest/event-target.html:
2006-12-15 Rob Buis <buis@kde.org>
Reviewed by Darin.
......@@ -46,7 +46,7 @@ bubbles : 'true'
cancelBubble : 'false'
cancelable : 'true'
clipboardData : 'undefined'
currentTarget : 'null'
currentTarget : '[object JSXMLHttpRequest]'
dataTransfer : 'undefined'
eventPhase : '0'
initEvent : '
......@@ -60,12 +60,12 @@ function preventDefault() {
}
'
returnValue : 'true'
srcElement : 'null'
srcElement : '[object JSXMLHttpRequest]'
stopPropagation : '
function stopPropagation() {
[native code]
}
'
target : 'null'
target : '[object JSXMLHttpRequest]'
type : 'load'
Tests for bug 11053 - XMLHttpRequest should be an EventTarget.
fooListener
onload
eventListener
eventListener2
eventListener3
onload
eventListener
eventListener2
fooListener: this = [object JSXMLHttpRequest]
onload: this = [object JSXMLHttpRequest]
eventListener: this = [object JSXMLHttpRequest]
eventListener2: this = [object JSXMLHttpRequest]
eventListener3: this = [object JSXMLHttpRequest]
onload: this = [object JSXMLHttpRequest]
eventListener: this = [object JSXMLHttpRequest]
eventListener2: this = [object JSXMLHttpRequest]
......@@ -18,24 +18,24 @@ XMLHttpRequest should be an EventTarget.</p>
function onLoad() {
log("onload");
log("onload: this = " + this);
req.removeEventListener("load", eventListener4, false);
}
function eventListener() { log("eventListener"); }
function eventListener() { log("eventListener: this = " + this); }
function eventListener2() {
log("eventListener2");
log("eventListener2: this = " + this);
// It is too late to remove this listener, so it will still fire.
req.removeEventListener("load", eventListener3, false);
}
function eventListener3() { log("eventListener3"); }
function eventListener3() { log("eventListener3: this = " + this); }
// This one is removed just in time to be really removed.
function eventListener4() { log("eventListener4"); }
function eventListener4() { log("eventListener4: this = " + this); }
function fooListener() { log("fooListener"); }
function fooListener() { log("fooListener: this = " + this); }
req = new XMLHttpRequest;
......
2006-12-15 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Darin.
http://bugs.webkit.org/show_bug.cgi?id=11610
XMLHttpRequest.onreadystatechange doesn't provide access to the request object
Created a separate EventTarget class, now that EventTargetNode isn't the only kind.
Test: http/tests/xmlhttprequest/event-target.html
* WebCore.xcodeproj/project.pbxproj: Added EventTarget.{h,cpp}
* bindings/js/kjs_dom.cpp:
(KJS::toJS): Added an EventTarget variant.
* bindings/js/kjs_dom.h: Added toJS() for EventTarget; some minor style fixes.
* bindings/objc/DOM.mm:
(+[DOMNode _eventTargetWith:WebCore::]):
* bindings/scripts/CodeGeneratorObjC.pm:
Added an EventTarget->DOMEventTarget converter in DOMNode (WebCoreInternal).
It only works for nodes, since we don't have an ObjC binding for XMLHttpRequest.
Corrected spelling of internalHeaderContent.
* dom/Event.cpp:
(WebCore::Event::setTarget):
* dom/Event.h:
(WebCore::Event::target):
(WebCore::Event::currentTarget):
(WebCore::Event::setCurrentTarget):
These methods now work with EventTargets instead of Nodes.
* dom/EventTarget.cpp: Added.
(WebCore::EventTarget::~EventTarget):
(WebCore::EventTarget::toNode):
(WebCore::EventTarget::toXMLHttpRequest):
* dom/EventTarget.h: Added.
(WebCore::EventTarget::ref):
(WebCore::EventTarget::deref):
Originally, my intention was to share much of the implementation between
EventTargetNode and XHR, but now I don't see anything substantial worth sharing.
* dom/EventTargetNode.cpp:
(WebCore::EventTargetNode::dispatchGenericEvent): Cast Node to EventTargetNode.
* dom/EventTargetNode.h: Made EventTarget methods virtual.
(WebCore::EventTargetNode::toNode): Added poor man's RTTI to upcast from EventTarget.
(WebCore::EventTargetNode::refEventTarget):
(WebCore::EventTargetNode::derefEventTarget):
* dom/MouseEvent.cpp:
(WebCore::MouseEvent::toElement):
(WebCore::MouseEvent::fromElement):
* dom/MouseRelatedEvent.cpp:
(WebCore::MouseRelatedEvent::receivedTarget):
* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::defaultEventHandler):
* html/HTMLLabelElement.cpp:
(WebCore::HTMLLabelElement::defaultEventHandler):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::handleContextMenuEvent):
* rendering/RenderSlider.cpp:
(WebCore::RenderSlider::mouseEventIsInThumb):
Cast from EventTarget to Node as appropriate.
* xml/xmlhttprequest.cpp:
(WebCore::XMLHttpRequest::dispatchEvent):
(WebCore::XMLHttpRequest::callReadyStateChangeListener):
Set target and currentTarget before dispatching.
* xml/xmlhttprequest.h: Made EventTarget methods virtual, added a bool tempEvent parameter
to match EventTargetNode.
(WebCore::XMLHttpRequest::toXMLHttpRequest): Added poor man's RTTI to upcast from EventTarget.
(WebCore::XMLHttpRequest::refEventTarget):
(WebCore::XMLHttpRequest::derefEventTarget):
2006-12-15 Anders Carlsson <acarlsson@apple.com>
Reviewed by Darin.
......@@ -2796,6 +2796,8 @@
DD7CDF250A23CF9800069928 /* CSSUnknownRule.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E6CCE0A1989CA007FB8C5 /* CSSUnknownRule.h */; };
E11D51930B2E7A5F0056C188 /* Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = E11D51910B2E7A5F0056C188 /* Base64.h */; };
E11D51940B2E7A5F0056C188 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E11D51920B2E7A5F0056C188 /* Base64.cpp */; };
E12EDB7B0B308A78002704B6 /* EventTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = E12EDB7A0B308A78002704B6 /* EventTarget.h */; settings = {ATTRIBUTES = (Private, ); }; };
E12EDBEA0B308E0B002704B6 /* EventTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E12EDBE90B308E0B002704B6 /* EventTarget.cpp */; };
E14842DE0A674934007E4D39 /* TextCodecICU.h in Headers */ = {isa = PBXBuildFile; fileRef = E14842DD0A674934007E4D39 /* TextCodecICU.h */; };
E14842FF0A674A31007E4D39 /* TextCodecICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E14842FE0A674A31007E4D39 /* TextCodecICU.cpp */; };
E148432F0A674FC2007E4D39 /* TextCodecMac.h in Headers */ = {isa = PBXBuildFile; fileRef = E148432E0A674FC2007E4D39 /* TextCodecMac.h */; };
......@@ -5897,6 +5899,8 @@
DD763BB10992C2C900740B8E /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = /usr/lib/libxml2.dylib; sourceTree = "<absolute>"; };
E11D51910B2E7A5F0056C188 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; };
E11D51920B2E7A5F0056C188 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; };
E12EDB7A0B308A78002704B6 /* EventTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventTarget.h; sourceTree = "<group>"; };
E12EDBE90B308E0B002704B6 /* EventTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventTarget.cpp; sourceTree = "<group>"; };
E14842DD0A674934007E4D39 /* TextCodecICU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCodecICU.h; sourceTree = "<group>"; };
E14842FE0A674A31007E4D39 /* TextCodecICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextCodecICU.cpp; sourceTree = "<group>"; };
E148432E0A674FC2007E4D39 /* TextCodecMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = TextCodecMac.h; path = mac/TextCodecMac.h; sourceTree = "<group>"; };
......@@ -9324,6 +9328,8 @@
939885C108B7E3D100E707C4 /* EventNames.cpp */,
939885C208B7E3D100E707C4 /* EventNames.h */,
85AFA7420AAF298400E84305 /* EventTarget.idl */,
E12EDB7A0B308A78002704B6 /* EventTarget.h */,
E12EDBE90B308E0B002704B6 /* EventTarget.cpp */,
14EC267E09CA07E000E1EEEC /* EventTargetNode.cpp */,
14EC267D09CA07E000E1EEEC /* EventTargetNode.h */,
935FBCF109BA143B00E230B1 /* ExceptionCode.h */,
......@@ -10851,6 +10857,7 @@
E11D51930B2E7A5F0056C188 /* Base64.h in Headers */,
B21127A60B3186770009BE53 /* JSSVGPODTypeWrapper.h in Headers */,
14993BE60B2F2B1C0050497F /* FocusController.h in Headers */,
E12EDB7B0B308A78002704B6 /* EventTarget.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -12172,6 +12179,7 @@
B25DFAAF0B2E2929000E6510 /* JSSVGMatrixCustom.cpp in Sources */,
E11D51940B2E7A5F0056C188 /* Base64.cpp in Sources */,
14993BE50B2F2B1C0050497F /* FocusController.cpp in Sources */,
E12EDBEA0B308E0B002704B6 /* EventTarget.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -30,7 +30,7 @@
#include "Element.h"
#include "Entity.h"
#include "Event.h"
#include "EventListener.h"
#include "EventTarget.h"
#include "EventNames.h"
#include "ExceptionCode.h"
#include "Frame.h"
......@@ -57,6 +57,7 @@
#include "ProcessingInstruction.h"
#include "Range.h"
#include "RenderView.h"
#include "xmlhttprequest.h"
#include "kjs_css.h"
#include "kjs_events.h"
#include "kjs_traversal.h"
......@@ -1031,6 +1032,27 @@ JSValue* toJS(ExecState* exec, NamedNodeMap* m)
return cacheDOMObject<NamedNodeMap, DOMNamedNodeMap>(exec, m);
}
JSValue* toJS(ExecState* exec, EventTarget* target)
{
if (!target)
return jsNull();
Node* node = target->toNode();
if (node)
return toJS(exec, node);
XMLHttpRequest* xhr = target->toXMLHttpRequest();
if (xhr) {
// XMLHttpRequest is always created via JS, so we don't need to use cacheDOMObject() here.
ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
return interp->getDOMObject(xhr);
}
// There are two kinds of EventTargets: EventTargetNode and XMLHttpRequest.
ASSERT(0);
return jsNull();
}
JSValue* getRuntimeObject(ExecState* exec, Node* n)
{
if (!n)
......
......@@ -33,6 +33,7 @@ namespace WebCore {
class DOMImplementation;
class Element;
class Entity;
class EventTarget;
class EventTargetNode;
class NamedNodeMap;
class Notation;
......@@ -133,13 +134,14 @@ namespace KJS {
};
JSValue* toJS(ExecState*, WebCore::Document*);
bool checkNodeSecurity(ExecState *exec, WebCore::Node *n);
JSValue *getRuntimeObject(ExecState *exec, WebCore::Node *n);
bool checkNodeSecurity(ExecState*, WebCore::Node*);
JSValue* getRuntimeObject(ExecState*, WebCore::Node*);
JSValue* toJS(ExecState*, PassRefPtr<WebCore::Node>);
JSValue* toJS(ExecState*, WebCore::NamedNodeMap *);
JSValue* toJS(ExecState*, WebCore::NamedNodeMap*);
JSValue* toJS(ExecState*, PassRefPtr<WebCore::NodeList>);
JSObject *getNodeConstructor(ExecState *exec);
JSObject *getDOMExceptionConstructor(ExecState *exec);
JSValue* toJS(ExecState*, WebCore::EventTarget*);
JSObject* getNodeConstructor(ExecState*);
JSObject* getDOMExceptionConstructor(ExecState*);
// Internal class, used for the collection return by e.g. document.forms.myinput
// when multiple nodes have the same name.
......
......@@ -40,6 +40,7 @@
#import "EntityReference.h"
#import "Event.h"
#import "EventListener.h"
#import "EventTarget.h"
#import "ExceptionHandlers.h"
#import "FontData.h"
#import "FoundationExtras.h"
......@@ -357,6 +358,15 @@ static NSArray *kit(const Vector<IntRect>& rects)
return [[[wrapperClass alloc] _initWithNode:impl] autorelease];
}
+ (id <DOMEventTarget>)_eventTargetWith:(WebCore::EventTarget *)eventTarget
{
if (!eventTarget)
return nil;
// We don't have an ObjC binding for XMLHttpRequest
return [DOMNode _nodeWith:eventTarget->toNode()];
}
- (WebCore::Node *)_node
{
return reinterpret_cast<WebCore::Node*>(_internal);
......
......@@ -44,7 +44,7 @@ my @privateHeaderContent = ();
my %privateHeaderForwardDeclarations = ();
my %privateHeaderForwardDeclarationsForProtocols = ();
my @intenalHeaderContent = ();
my @internalHeaderContent = ();
my @implContentHeader = ();
my @implContent = ();
......@@ -400,8 +400,6 @@ sub GetObjCTypeMaker
$typeMaker = "xpath" . $1;
} elsif ($type eq "DOMWindow") {
$typeMaker = "abstractView";
} elsif ($type eq "EventTarget") {
$typeMaker = "node";
} else {
$typeMaker = lcfirst($type);
}
......@@ -1307,22 +1305,30 @@ sub GenerateImplementation
$typeMakerSig = "+ ($className *)$typeMakerName:($podTypeWithNamespace)impl" . $typeMakerSigAddition if $podType;
# Generate interface definitions.
@intenalHeaderContent = split("\r", $implementationLicenceTemplate);
push(@intenalHeaderContent, "\n#import <WebCore/$className.h>\n");
@internalHeaderContent = split("\r", $implementationLicenceTemplate);
push(@internalHeaderContent, "\n#import <WebCore/$className.h>\n");
if ($interfaceName eq "Node") {
push(@internalHeaderContent, "\n\@protocol DOMEventTarget;\n");
}
if ($codeGenerator->IsSVGAnimatedType($interfaceName)) {
push(@intenalHeaderContent, "#import <WebCore/SVGAnimatedTemplate.h>\n\n");
push(@internalHeaderContent, "#import <WebCore/SVGAnimatedTemplate.h>\n\n");
} else {
if ($podType and $podType ne "double") {
push(@intenalHeaderContent, "\nnamespace WebCore { class $podType; }\n\n");
push(@internalHeaderContent, "\nnamespace WebCore { class $podType; }\n\n");
} elsif ($interfaceName eq "Node") {
push(@internalHeaderContent, "\nnamespace WebCore { class Node; class EventTarget; }\n\n");
} else {
push(@intenalHeaderContent, "\nnamespace WebCore { class $implClassName; }\n\n");
push(@internalHeaderContent, "\nnamespace WebCore { class $implClassName; }\n\n");
}
}
push(@intenalHeaderContent, "\@interface $className (WebCoreInternal)\n");
push(@intenalHeaderContent, $typeGetterSig . ";\n");
push(@intenalHeaderContent, $typeMakerSig . ";\n");
push(@intenalHeaderContent, "\@end\n");
push(@internalHeaderContent, "\@interface $className (WebCoreInternal)\n");
push(@internalHeaderContent, $typeGetterSig . ";\n");
push(@internalHeaderContent, $typeMakerSig . ";\n");
if ($interfaceName eq "Node") {
push(@internalHeaderContent, "+ (id <DOMEventTarget>)_eventTargetWith:(WebCore::EventTarget *)eventTarget;\n");
}
push(@internalHeaderContent, "\@end\n");
unless ($dataNode->extendedAttributes->{ObjCCustomInternalImpl}) {
# - BEGIN WebCoreInternal category @implementation
......@@ -1475,14 +1481,14 @@ sub WriteData
%implIncludes = ();
}
if (@intenalHeaderContent > 0) {
if (@internalHeaderContent > 0) {
open(INTERNAL_HEADER, ">$internalHeaderFileName") or die "Couldn't open file $internalHeaderFileName";
print INTERNAL_HEADER @intenalHeaderContent;
print INTERNAL_HEADER @internalHeaderContent;
close(INTERNAL_HEADER);
@intenalHeaderContent = ();
@internalHeaderContent = ();
}
}
......
......@@ -25,7 +25,6 @@
#include "Event.h"
#include "AtomicString.h"
#include "Node.h"
#include "SystemTime.h"
namespace WebCore {
......@@ -133,7 +132,7 @@ void Event::storeResult(const String&)
{
}
void Event::setTarget(PassRefPtr<Node> target)
void Event::setTarget(PassRefPtr<EventTarget> target)
{
m_target = target;
if (m_target)
......
......@@ -27,7 +27,7 @@
#define Event_h
#include "AtomicString.h"
#include "Node.h"
#include "EventTarget.h"
#include "Shared.h"
namespace WebCore {
......@@ -75,11 +75,11 @@ namespace WebCore {
const AtomicString& type() const { return m_type; }
Node* target() const { return m_target.get(); }
void setTarget(PassRefPtr<Node>);
EventTarget* target() const { return m_target.get(); }
void setTarget(PassRefPtr<EventTarget>);
Node* currentTarget() const { return m_currentTarget; }
void setCurrentTarget(Node* currentTarget) { m_currentTarget = currentTarget; }
EventTarget* currentTarget() const { return m_currentTarget; }
void setCurrentTarget(EventTarget* currentTarget) { m_currentTarget = currentTarget; }
unsigned short eventPhase() const { return m_eventPhase; }
void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; }
......@@ -134,9 +134,9 @@ namespace WebCore {
bool m_defaultHandled;
bool m_cancelBubble;
Node* m_currentTarget;
EventTarget* m_currentTarget;
unsigned short m_eventPhase;
RefPtr<Node> m_target;
RefPtr<EventTarget> m_target;
DOMTimeStamp m_createTime;
RefPtr<Event> m_underlyingEvent;
......
/*
* This file is part of the DOM implementation for KDE.
*
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
*
* 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 "EventTarget.h"
#include "EventTargetNode.h"
#include "xmlhttprequest.h"
namespace WebCore {
EventTarget::~EventTarget()
{
}
Node* EventTarget::toNode()
{
return 0;
}
XMLHttpRequest* EventTarget::toXMLHttpRequest()
{
return 0;
}
} // end namespace
/*
* This file is part of the DOM implementation for KDE.
*
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
*
* 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 EventTarget_h
#define EventTarget_h
#include <wtf/PassRefPtr.h>
namespace WebCore {
class AtomicString;
class Event;
class EventListener;
class Node;
class XMLHttpRequest;
typedef int ExceptionCode;
class EventTarget {
public:
virtual ~EventTarget();
virtual Node* toNode();
virtual XMLHttpRequest* toXMLHttpRequest();
virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture) = 0;
virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture) = 0;
virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&, bool tempEvent = false) = 0;
void ref() { refEventTarget(); }
void deref() { derefEventTarget(); }
private:
virtual void refEventTarget() = 0;
virtual void derefEventTarget() = 0;
};
}
#endif
......@@ -199,7 +199,7 @@ bool EventTargetNode::dispatchGenericEvent(PassRefPtr<Event> e, ExceptionCode&,
static_cast<Document*>(it.current())->handleWindowEvent(evt.get(), true);
for (; it.current() && it.current() != this && !evt->propagationStopped(); ++it) {
evt->setCurrentTarget(it.current());
evt->setCurrentTarget(EventTargetNodeCast(it.current()));
EventTargetNodeCast(it.current())->handleLocalEvents(evt.get(), true);
}
......@@ -207,7 +207,7 @@ bool EventTargetNode::dispatchGenericEvent(PassRefPtr<Event> e, ExceptionCode&,
it.toLast();
if (!evt->propagationStopped()) {
evt->setEventPhase(Event::AT_TARGET);
evt->setCurrentTarget(it.current());
evt->setCurrentTarget(EventTargetNodeCast(it.current()));
// We do want capturing event listeners to be invoked here, even though
// that violates the specification since Mozilla does it.
......@@ -232,7 +232,7 @@ bool EventTargetNode::dispatchGenericEvent(PassRefPtr<Event> e, ExceptionCode&,
if (evt->bubbles()) {
evt->setEventPhase(Event::BUBBLING_PHASE);
for (; it.current() && !evt->propagationStopped() && !evt->cancelBubble(); --it) {
evt->setCurrentTarget(it.current());
evt->setCurrentTarget(EventTargetNodeCast(it.current()));
EventTargetNodeCast(it.current())->handleLocalEvents(evt.get(), false);
}
// Handle window events for bubbling phase, except load events, this quirk is needed
......@@ -240,7 +240,7 @@ bool EventTargetNode::dispatchGenericEvent(PassRefPtr<Event> e, ExceptionCode&,
it.toFirst();
if (evt->type() != loadEvent && it.current()->isDocumentNode() && !evt->propagationStopped() && !evt->cancelBubble()) {
evt->setCurrentTarget(it.current());
evt->setCurrentTarget(EventTargetNodeCast(it.current()));
static_cast<Document*>(it.current())->handleWindowEvent(evt.get(), false);
}
}
......
......@@ -26,21 +26,24 @@
#ifndef DOM_EventTargetNodeImpl_h
#define DOM_EventTargetNodeImpl_h
#include "EventTarget.h"
#include "Node.h"
namespace WebCore {
template <typename T> class DeprecatedValueList;
class EventTargetNode : public Node {
class EventTargetNode : public Node, public EventTarget {
public:
EventTargetNode(Document*);
virtual ~EventTargetNode();
virtual bool isEventTargetNode() const { return true; }
virtual Node* toNode() { return this; }
void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&, bool tempEvent = false);
void removeAllEventListeners();
void setHTMLEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
......@@ -49,7 +52,6 @@ public:
EventListener *getHTMLEventListener(const AtomicString& eventType);
bool dispatchGenericEvent(PassRefPtr<Event>, ExceptionCode&, bool tempEvent = false);
bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&, bool tempEvent = false);
bool dispatchSubtreeModifiedEvent(bool childrenChanged = true);
void dispatchWindowEvent(const AtomicString& eventType, bool canBubble, bool cancelable);
bool dispatchUIEvent(const AtomicString& eventType, int detail = 0, PassRefPtr<Event> underlyingEvent = 0);
......@@ -92,9 +94,16 @@ public:
virtual void dump(TextStream*, DeprecatedString indent = "") const;
#endif
using Node::ref;
using Node::deref;
protected: