patch to add KeyboardEvent for JavaScript
Darin Adler
darin at apple.com
Thu Nov 6 17:53:05 CET 2003
Normally, I avoid doing "cleanup" as much as possible, to try to
prevent WebCore KHTML from diverging in arbitrary ways from the one in
the KDE tree. But since we are talking about this now, I did a little
cleanup and eliminated the eventModuleName() function.
-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/ChangeLog,v
retrieving revision 1.2210
diff -p -u -u -p -r1.2210 ChangeLog
--- ChangeLog 2003/11/06 06:26:16 1.2210
+++ ChangeLog 2003/11/06 16:50:58
@@ -1,3 +1,51 @@
+2003-11-06 Darin Adler <darin at apple.com>
+
+ Reviewed by NOBODY (OOPS!).
+
+ - event cleanup motivated by questions on khtml-devel
+
+ * khtml/dom/dom2_events.h: Removed eventModuleName.
+ * khtml/dom/dom2_events.cpp: Removed eventModuleName.
+
+ * khtml/xml/dom2_eventsimpl.h: Removed eventModuleName, made many trivially simple
+ functions inline, made virtual functions no longer inline. Also made some functions const.
+ (DOM::EventImpl::propagationStopped): Made this non-virtual; there was no reason for
+ it to be virtual I could see.
+ (DOM::EventImpl::defaultPrevented): Ditto.
+ (DOM::EventImpl::setDefaultHandled): Ditto.
+ (DOM::UIEventImpl::view): Made this inline.
+ (DOM::UIEventImpl::detail): Ditto.
+ (DOM::MouseEventImpl::screenX): Ditto.
+ (DOM::MouseEventImpl::screenY): Ditto.
+ (DOM::MouseEventImpl::clientX): Ditto.
+ (DOM::MouseEventImpl::clientY): Ditto.
+ (DOM::MouseEventImpl::layerX): Ditto.
+ (DOM::MouseEventImpl::layerY): Ditto.
+ (DOM::MouseEventImpl::ctrlKey): Ditto.
+ (DOM::MouseEventImpl::shiftKey): Ditto.
+ (DOM::MouseEventImpl::altKey): Ditto.
+ (DOM::MouseEventImpl::metaKey): Ditto.
+ (DOM::MouseEventImpl::button): Ditto.
+ (DOM::MouseEventImpl::relatedTarget): Ditto.
+ (DOM::MutationEventImpl::relatedNode): Ditto.
+ (DOM::MutationEventImpl::prevValue): Ditto.
+ (DOM::MutationEventImpl::newValue): Ditto.
+ (DOM::MutationEventImpl::attrName): Ditto.
+ (DOM::MutationEventImpl::attrChange): Ditto.
+
+ * khtml/ecma/kjs_events.cpp: (KJS::getDOMEvent): Changed implementation to no longer
+ require eventModuleName(), and removed some unneeded casts.
+
+ * khtml/xml/dom2_eventsimpl.cpp: Made lots of functions inline.
+ (EventImpl::isUIEvent): Since this is virtual, make it no longer inline.
+ (EventImpl::isMouseEvent): Ditto.
+ (EventImpl::isMutationEvent): Ditto.
+ (EventImpl::isKeyboardEvent): Ditto.
+ (UIEventImpl::isUIEvent): Ditto.
+ (MouseEventImpl::isMouseEvent): Ditto.
+ (KeyboardEventImpl::isKeyboardEvent): Ditto.
+ (MutationEventImpl::isMutationEvent): Ditto.
+
2003-11-05 Darin Adler <darin at apple.com>
Reviewed by Maciej.
Index: khtml/dom/dom2_events.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/dom/dom2_events.cpp,v
retrieving revision 1.14
diff -p -u -u -p -r1.14 khtml/dom/dom2_events.cpp
--- khtml/dom/dom2_events.cpp 2003/11/06 06:26:16 1.14
+++ khtml/dom/dom2_events.cpp 2003/11/06 16:50:58
@@ -169,14 +169,6 @@ bool Event::isNull() const
return (impl == 0);
}
-DOMString Event::eventModuleName()
-{
- if (!impl)
- throw DOMException(DOMException::INVALID_STATE_ERR);
-
- return impl->eventModuleName();
-}
-
void Event::setCancelBubble(bool cancel)
{
if (!impl)
Index: khtml/dom/dom2_events.h
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/dom/dom2_events.h,v
retrieving revision 1.12
diff -p -u -u -p -r1.12 khtml/dom/dom2_events.h
--- khtml/dom/dom2_events.h 2003/10/29 01:23:15 1.12
+++ khtml/dom/dom2_events.h 2003/11/06 16:50:59
@@ -249,15 +249,6 @@ public:
EventImpl *handle() const;
bool isNull() const;
- /**
- * @internal
- * not part of the DOM
- *
- * Returns the module name of the event - this is the same as passed to
- * Document::createEvent() (e.g. UIEvents)
- */
- DOMString eventModuleName();
-
/* Nonstandard extensions needed to support widely used JS event properties */
void setCancelBubble(bool cancel);
void setDefaultPrevented(bool returnValue);
Index: khtml/ecma/kjs_events.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/ecma/kjs_events.cpp,v
retrieving revision 1.20
diff -p -u -u -p -r1.20 khtml/ecma/kjs_events.cpp
--- khtml/ecma/kjs_events.cpp 2003/11/06 06:26:16 1.20
+++ khtml/ecma/kjs_events.cpp 2003/11/06 16:50:59
@@ -298,26 +298,25 @@ Value DOMEventProtoFunc::tryCall(ExecSta
Value KJS::getDOMEvent(ExecState *exec, DOM::Event e)
{
- DOMObject *ret;
- if (e.isNull())
+ DOM::EventImpl *ei = e.handle();
+ if (!ei)
return Null();
ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
- if ((ret = interp->getDOMObject(e.handle())))
- return Value(ret);
+ DOMObject *ret = interp->getDOMObject(ei);
+ if (!ret) {
+ if (ei->isKeyboardEvent())
+ ret = new DOMKeyboardEvent(exec, e);
+ else if (ei->isMouseEvent())
+ ret = new DOMMouseEvent(exec, e);
+ else if (ei->isUIEvent())
+ ret = new DOMUIEvent(exec, e);
+ else if (ei->isMutationEvent())
+ ret = new DOMMutationEvent(exec, e);
+ else
+ ret = new DOMEvent(exec, e);
- DOM::DOMString module = e.eventModuleName();
- if (e.handle()->isKeyboardEvent())
- ret = new DOMKeyboardEvent(exec, static_cast<DOM::KeyboardEvent>(e));
- else if (module == "UIEvents")
- ret = new DOMUIEvent(exec, static_cast<DOM::UIEvent>(e));
- else if (module == "MouseEvents")
- ret = new DOMMouseEvent(exec, static_cast<DOM::MouseEvent>(e));
- else if (module == "MutationEvents")
- ret = new DOMMutationEvent(exec, static_cast<DOM::MutationEvent>(e));
- else
- ret = new DOMEvent(exec, e);
-
- interp->putDOMObject(e.handle(),ret);
+ interp->putDOMObject(ei, ret);
+ }
return Value(ret);
}
Index: khtml/xml/dom2_eventsimpl.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/xml/dom2_eventsimpl.cpp,v
retrieving revision 1.13
diff -p -u -u -p -r1.13 khtml/xml/dom2_eventsimpl.cpp
--- khtml/xml/dom2_eventsimpl.cpp 2003/10/30 06:55:56 1.13
+++ khtml/xml/dom2_eventsimpl.cpp 2003/11/06 16:51:00
@@ -322,11 +322,26 @@ DOMString EventImpl::idToType(EventImpl:
}
}
-void EventImpl::setDefaultHandled()
+bool EventImpl::isUIEvent() const
{
- m_defaultHandled = true;
+ return false;
}
+bool EventImpl::isMouseEvent() const
+{
+ return false;
+}
+
+bool EventImpl::isMutationEvent() const
+{
+ return false;
+}
+
+bool EventImpl::isKeyboardEvent() const
+{
+ return false;
+}
+
// -----------------------------------------------------------------------------
UIEventImpl::UIEventImpl()
@@ -351,16 +366,6 @@ UIEventImpl::~UIEventImpl()
m_view->deref();
}
-AbstractViewImpl *UIEventImpl::view() const
-{
- return m_view;
-}
-
-long UIEventImpl::detail() const
-{
- return m_detail;
-}
-
void UIEventImpl::initUIEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
@@ -378,6 +383,11 @@ void UIEventImpl::initUIEvent(const DOMS
m_detail = detailArg;
}
+bool UIEventImpl::isUIEvent() const
+{
+ return true;
+}
+
// -----------------------------------------------------------------------------
MouseEventImpl::MouseEventImpl()
@@ -463,66 +473,6 @@ MouseEventImpl::~MouseEventImpl()
m_relatedTarget->deref();
}
-long MouseEventImpl::screenX() const
-{
- return m_screenX;
-}
-
-long MouseEventImpl::screenY() const
-{
- return m_screenY;
-}
-
-long MouseEventImpl::clientX() const
-{
- return m_clientX;
-}
-
-long MouseEventImpl::clientY() const
-{
- return m_clientY;
-}
-
-long MouseEventImpl::layerX() const
-{
- return m_layerX;
-}
-
-long MouseEventImpl::layerY() const
-{
- return m_layerY;
-}
-
-bool MouseEventImpl::ctrlKey() const
-{
- return m_ctrlKey;
-}
-
-bool MouseEventImpl::shiftKey() const
-{
- return m_shiftKey;
-}
-
-bool MouseEventImpl::altKey() const
-{
- return m_altKey;
-}
-
-bool MouseEventImpl::metaKey() const
-{
- return m_metaKey;
-}
-
-unsigned short MouseEventImpl::button() const
-{
- return m_button;
-}
-
-NodeImpl *MouseEventImpl::relatedTarget() const
-{
- return m_relatedTarget;
-}
-
void MouseEventImpl::initMouseEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
@@ -559,6 +509,11 @@ void MouseEventImpl::initMouseEvent(cons
computeLayerPos();
}
+bool MouseEventImpl::isMouseEvent() const
+{
+ return true;
+}
+
//---------------------------------------------------------------------------------------------
KeyboardEventImpl::KeyboardEventImpl()
@@ -663,6 +618,11 @@ void KeyboardEventImpl::initKeyboardEven
m_altGraphKey = altGraphKeyArg;
}
+bool KeyboardEventImpl::isKeyboardEvent() const
+{
+ return true;
+}
+
// -----------------------------------------------------------------------------
MutationEventImpl::MutationEventImpl()
@@ -711,31 +671,6 @@ MutationEventImpl::~MutationEventImpl()
m_attrName->deref();
}
-Node MutationEventImpl::relatedNode() const
-{
- return m_relatedNode;
-}
-
-DOMString MutationEventImpl::prevValue() const
-{
- return m_prevValue;
-}
-
-DOMString MutationEventImpl::newValue() const
-{
- return m_newValue;
-}
-
-DOMString MutationEventImpl::attrName() const
-{
- return m_attrName;
-}
-
-unsigned short MutationEventImpl::attrChange() const
-{
- return m_attrChange;
-}
-
void MutationEventImpl::initMutationEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
@@ -769,6 +704,11 @@ void MutationEventImpl::initMutationEven
if (m_newValue)
m_newValue->ref();
m_attrChange = attrChangeArg;
+}
+
+bool MutationEventImpl::isMutationEvent() const
+{
+ return true;
}
// -----------------------------------------------------------------------------
Index: khtml/xml/dom2_eventsimpl.h
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/xml/dom2_eventsimpl.h,v
retrieving revision 1.10
diff -p -u -u -p -r1.10 khtml/xml/dom2_eventsimpl.h
--- khtml/xml/dom2_eventsimpl.h 2003/10/29 01:23:15 1.10
+++ khtml/xml/dom2_eventsimpl.h 2003/11/06 16:51:00
@@ -1,8 +1,9 @@
/*
* This file is part of the DOM implementation for KDE.
*
- * (C) 2001 Peter Kelly (pmk at post.com)
- * (C) 2001 Tobias Anton (anton at stud.fbi.fh-darmstadt.de)
+ * Copyright (C) 2001 Peter Kelly (pmk at post.com)
+ * Copyright (C) 2001 Tobias Anton (anton at stud.fbi.fh-darmstadt.de)
+ * Copyright (C) 2003 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -113,19 +114,18 @@ public:
void preventDefault();
void initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg);
- virtual bool isUIEvent() { return false; }
- virtual bool isMouseEvent() { return false; }
- virtual bool isMutationEvent() { return false; }
- virtual bool isKeyboardEvent() { return false; }
- virtual DOMString eventModuleName() { return ""; }
+ virtual bool isUIEvent() const;
+ virtual bool isMouseEvent() const;
+ virtual bool isMutationEvent() const;
+ virtual bool isKeyboardEvent() const;
- virtual bool propagationStopped() const { return m_propagationStopped; }
- virtual bool defaultPrevented() const { return m_defaultPrevented; }
+ bool propagationStopped() const { return m_propagationStopped; }
+ bool defaultPrevented() const { return m_defaultPrevented; }
static EventId typeToId(DOMString type);
static DOMString idToType(EventId id);
- virtual void setDefaultHandled();
+ void setDefaultHandled() { m_defaultHandled = true; }
bool defaultHandled() const { return m_defaultHandled; }
void setCancelBubble(bool cancel) { m_cancelBubble = cancel; }
@@ -161,15 +161,14 @@ public:
AbstractViewImpl *viewArg,
long detailArg);
virtual ~UIEventImpl();
- AbstractViewImpl *view() const;
- long detail() const;
+ AbstractViewImpl *view() const { return m_view; }
+ long detail() const { return m_detail; }
void initUIEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
const AbstractView &viewArg,
long detailArg);
- virtual bool isUIEvent() { return true; }
- virtual DOMString eventModuleName() { return "UIEvents"; }
+ virtual bool isUIEvent() const;
protected:
AbstractViewImpl *m_view;
@@ -200,18 +199,18 @@ public:
unsigned short buttonArg,
NodeImpl *relatedTargetArg);
virtual ~MouseEventImpl();
- long screenX() const;
- long screenY() const;
- long clientX() const;
- long clientY() const;
- long layerX() const;
- long layerY() const;
- bool ctrlKey() const;
- bool shiftKey() const;
- bool altKey() const;
- bool metaKey() const;
- unsigned short button() const;
- NodeImpl *relatedTarget() const;
+ long screenX() const { return m_screenX; }
+ long screenY() const { return m_screenY; }
+ long clientX() const { return m_clientX; }
+ long clientY() const { return m_clientY; }
+ long layerX() const { return m_layerX; }
+ long layerY() const { return m_layerY; }
+ bool ctrlKey() const { return m_ctrlKey; }
+ bool shiftKey() const { return m_shiftKey; }
+ bool altKey() const { return m_altKey; }
+ bool metaKey() const { return m_metaKey; }
+ unsigned short button() const { return m_button; }
+ NodeImpl *relatedTarget() const { return m_relatedTarget; }
void initMouseEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
@@ -227,8 +226,7 @@ public:
bool metaKeyArg,
unsigned short buttonArg,
const Node &relatedTargetArg);
- virtual bool isMouseEvent() { return true; }
- virtual DOMString eventModuleName() { return "MouseEvents"; }
+ virtual bool isMouseEvent() const;
protected:
long m_screenX;
long m_screenY;
@@ -288,7 +286,7 @@ public:
QKeyEvent *qKeyEvent() const { return m_keyEvent; }
- virtual bool isKeyboardEvent() { return true; }
+ virtual bool isKeyboardEvent() const;
private:
QKeyEvent *m_keyEvent;
@@ -315,11 +313,11 @@ public:
unsigned short attrChangeArg);
~MutationEventImpl();
- Node relatedNode() const;
- DOMString prevValue() const;
- DOMString newValue() const;
- DOMString attrName() const;
- unsigned short attrChange() const;
+ Node relatedNode() const { return m_relatedNode; }
+ DOMString prevValue() const { return m_prevValue; }
+ DOMString newValue() const { return m_newValue; }
+ DOMString attrName() const { return m_attrName; }
+ unsigned short attrChange() const { return m_attrChange; }
void initMutationEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
@@ -328,8 +326,7 @@ public:
const DOMString &newValueArg,
const DOMString &attrNameArg,
unsigned short attrChangeArg);
- virtual bool isMutationEvent() { return true; }
- virtual DOMString eventModuleName() { return "MutationEvents"; }
+ virtual bool isMutationEvent() const;
protected:
NodeImpl *m_relatedNode;
DOMStringImpl *m_prevValue;
-------------- next part --------------
-- Darin
More information about the Khtml-devel
mailing list