patch to add KeyboardEvent for JavaScript
Darin Adler
darin at apple.com
Thu Nov 6 07:26:06 CET 2003
Index: ChangeLog
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/ChangeLog,v
retrieving revision 1.2209
diff -p -u -u -p -r1.2209 ChangeLog
--- ChangeLog 2003/11/06 01:48:37 1.2209
+++ ChangeLog 2003/11/06 06:25:33
@@ -1,3 +1,26 @@
+2003-11-05 Darin Adler <darin at apple.com>
+
+ Reviewed by Maciej.
+
+ - fixed 3475109 -- support keyboard event object properties of altkey, ctrlKey, shiftKey
+
+ We had the DOM Level 3 KeyboardEvent class already; I just had to add JavaScript bindings.
+
+ * khtml/ecma/kjs_events.h: Added DOMKeyboardEvent class.
+ * khtml/ecma/kjs_events.cpp:
+ (KJS::getDOMEvent): Added code to make a DOMKeyboardEvent if the event is a DOM::KeyboardEvent.
+ (DOMKeyboardEvent::~DOMKeyboardEvent): Added.
+ (DOMKeyboardEvent::classInfo): Added.
+ (DOMKeyboardEvent::tryGet): Added.
+ (DOMKeyboardEvent::getValueProperty): Added.
+ (DOMKeyboardEventProtoFunc::tryCall): Added.
+
+ * khtml/dom/dom2_events.cpp:
+ (KeyboardEvent::keyIdentifier): Added.
+ (KeyboardEvent::keyLocation): Added.
+
+ * khtml/ecma/kjs_events.lut.h: Regenerated.
+
2003-11-05 Maciej Stachowiak <mjs at apple.com>
Reviewed by John.
Index: khtml/dom/dom2_events.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/dom/dom2_events.cpp,v
retrieving revision 1.13
diff -p -u -u -p -r1.13 khtml/dom/dom2_events.cpp
--- khtml/dom/dom2_events.cpp 2003/10/29 01:23:15 1.13
+++ khtml/dom/dom2_events.cpp 2003/11/06 06:25:33
@@ -633,7 +633,7 @@ void MutationEvent::initMutationEvent(co
// -----------------------------------------------------------------------------
-KeyboardEvent::KeyboardEvent() : UIEvent()
+KeyboardEvent::KeyboardEvent()
{
}
@@ -641,9 +641,9 @@ KeyboardEvent::KeyboardEvent(const Keybo
{
}
-KeyboardEvent::KeyboardEvent(const Event &other) : UIEvent()
+KeyboardEvent::KeyboardEvent(const Event &other)
{
- (*this)=other;
+ *this = other;
}
KeyboardEvent::KeyboardEvent(KeyboardEventImpl *impl) : UIEvent(impl)
@@ -670,6 +670,22 @@ KeyboardEvent &KeyboardEvent::operator =
KeyboardEvent::~KeyboardEvent()
{
+}
+
+DOMString KeyboardEvent::keyIdentifier() const
+{
+ if (!impl)
+ throw DOMException(DOMException::INVALID_STATE_ERR);
+
+ return static_cast<KeyboardEventImpl*>(impl)->keyIdentifier();
+}
+
+unsigned long KeyboardEvent::keyLocation() const
+{
+ if (!impl)
+ throw DOMException(DOMException::INVALID_STATE_ERR);
+
+ return static_cast<KeyboardEventImpl*>(impl)->keyLocation();
}
bool KeyboardEvent::ctrlKey() const
Index: khtml/ecma/kjs_events.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/ecma/kjs_events.cpp,v
retrieving revision 1.19
diff -p -u -u -p -r1.19 khtml/ecma/kjs_events.cpp
--- khtml/ecma/kjs_events.cpp 2003/11/05 22:24:25 1.19
+++ khtml/ecma/kjs_events.cpp 2003/11/06 06:25:34
@@ -33,6 +33,8 @@
using namespace KJS;
+using DOM::KeyboardEvent;
+
// -------------------------------------------------------------------------
JSEventListener::JSEventListener(Object _listener, const Object &_win, bool _html)
@@ -304,7 +306,9 @@ Value KJS::getDOMEvent(ExecState *exec,
return Value(ret);
DOM::DOMString module = e.eventModuleName();
- if (module == "UIEvents")
+ 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));
@@ -564,6 +568,94 @@ Value DOMMouseEventProtoFunc::tryCall(Ex
args[12].toBoolean(exec), // metaKeyArg
args[13].toInteger(exec), // buttonArg
toNode(args[14])); // relatedTargetArg
+ return Undefined();
+ }
+ return Undefined();
+}
+
+// -------------------------------------------------------------------------
+
+const ClassInfo DOMKeyboardEvent::info = { "KeyboardEvent", &DOMUIEvent::info, &DOMKeyboardEventTable, 0 };
+
+/*
+ at begin DOMKeyboardEventTable 5
+ keyIdentifier DOMKeyboardEvent::KeyIdentifier DontDelete|ReadOnly
+ keyLocation DOMKeyboardEvent::KeyLocation DontDelete|ReadOnly
+ ctrlKey DOMKeyboardEvent::CtrlKey DontDelete|ReadOnly
+ shiftKey DOMKeyboardEvent::ShiftKey DontDelete|ReadOnly
+ altKey DOMKeyboardEvent::AltKey DontDelete|ReadOnly
+ metaKey DOMKeyboardEvent::MetaKey DontDelete|ReadOnly
+ altGraphKey DOMKeyboardEvent::AltGraphKey DontDelete|ReadOnly
+ at end
+ at begin DOMKeyboardEventProtoTable 1
+ initKeyboardEvent DOMKeyboardEvent::InitKeyboardEvent DontDelete|Function 11
+ at end
+*/
+DEFINE_PROTOTYPE("DOMKeyboardEvent", DOMKeyboardEventProto)
+IMPLEMENT_PROTOFUNC(DOMKeyboardEventProtoFunc)
+IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMKeyboardEventProto, DOMKeyboardEventProtoFunc, DOMUIEventProto)
+
+DOMKeyboardEvent::~DOMKeyboardEvent()
+{
+}
+
+const ClassInfo* DOMKeyboardEvent::classInfo() const
+{
+ return &info;
+}
+
+Value DOMKeyboardEvent::tryGet(ExecState *exec, const Identifier &p) const
+{
+#ifdef KJS_VERBOSE
+ kdDebug(6070) << "DOMKeyboardEvent::tryGet " << p.qstring() << endl;
+#endif
+ return DOMObjectLookupGetValue<DOMKeyboardEvent, DOMUIEvent>(exec, p, &DOMKeyboardEventTable, this);
+}
+
+Value DOMKeyboardEvent::getValueProperty(ExecState *exec, int token) const
+{
+ switch (token) {
+ case KeyIdentifier:
+ return String(static_cast<KeyboardEvent>(event).keyIdentifier());
+ case KeyLocation:
+ return Number(static_cast<KeyboardEvent>(event).keyLocation());
+ case CtrlKey:
+ return Boolean(static_cast<KeyboardEvent>(event).ctrlKey());
+ case ShiftKey:
+ return Boolean(static_cast<KeyboardEvent>(event).shiftKey());
+ case AltKey:
+ return Boolean(static_cast<KeyboardEvent>(event).altKey());
+ case MetaKey:
+ return Boolean(static_cast<KeyboardEvent>(event).metaKey());
+ case AltGraphKey:
+ return Boolean(static_cast<KeyboardEvent>(event).altGraphKey());
+ default:
+ kdWarning() << "Unhandled token in DOMKeyboardEvent::getValueProperty : " << token << endl;
+ return Value();
+ }
+}
+
+Value DOMKeyboardEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
+{
+ if (!thisObj.inherits(&DOMKeyboardEvent::info)) {
+ Object err = Error::create(exec,TypeError);
+ exec->setException(err);
+ return err;
+ }
+ KeyboardEvent event = static_cast<DOMKeyboardEvent *>(thisObj.imp())->toKeyboardEvent();
+ switch (id) {
+ case DOMKeyboardEvent::InitKeyboardEvent:
+ event.initKeyboardEvent(args[0].toString(exec).string(), // typeArg
+ args[1].toBoolean(exec), // canBubbleArg
+ args[2].toBoolean(exec), // cancelableArg
+ toAbstractView(args[3]), // viewArg
+ args[4].toString(exec).string(), // keyIdentifier
+ args[5].toInteger(exec), // keyLocationArg
+ args[6].toBoolean(exec), // ctrlKeyArg
+ args[7].toBoolean(exec), // altKeyArg
+ args[8].toBoolean(exec), // shiftKeyArg
+ args[9].toBoolean(exec), // metaKeyArg
+ args[10].toBoolean(exec)); // altGraphKeyArg
return Undefined();
}
return Undefined();
Index: khtml/ecma/kjs_events.h
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/ecma/kjs_events.h,v
retrieving revision 1.12
diff -p -u -u -p -r1.12 khtml/ecma/kjs_events.h
--- khtml/ecma/kjs_events.h 2003/04/02 00:46:02 1.12
+++ khtml/ecma/kjs_events.h 2003/11/06 06:25:34
@@ -128,6 +128,19 @@ namespace KJS {
DOM::MouseEvent toMouseEvent() const { return static_cast<DOM::MouseEvent>(event); }
};
+ class DOMKeyboardEvent : public DOMUIEvent {
+ public:
+ DOMKeyboardEvent(ExecState *exec, DOM::KeyboardEvent ke) : DOMUIEvent(exec, ke) {}
+ ~DOMKeyboardEvent();
+ virtual Value tryGet(ExecState *exec, const Identifier &p) const;
+ Value getValueProperty(ExecState *, int token) const;
+ // no put - all read-only
+ virtual const ClassInfo* classInfo() const;
+ static const ClassInfo info;
+ enum { KeyIdentifier, KeyLocation, CtrlKey, ShiftKey, AltKey, MetaKey, AltGraphKey, InitKeyboardEvent};
+ DOM::KeyboardEvent toKeyboardEvent() const { return event; }
+ };
+
// Constructor object MutationEvent
class MutationEventConstructor : public DOMObject {
public:
Index: khtml/ecma/kjs_events.lut.h
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/ecma/kjs_events.lut.h,v
retrieving revision 1.6
diff -p -u -u -p -r1.6 khtml/ecma/kjs_events.lut.h
--- khtml/ecma/kjs_events.lut.h 2003/10/06 15:50:12 1.6
+++ khtml/ecma/kjs_events.lut.h 2003/11/06 06:25:34
@@ -141,6 +141,33 @@ const struct HashTable DOMMouseEventProt
namespace KJS {
+const struct HashEntry DOMKeyboardEventTableEntries[] = {
+ { "metaKey", DOMKeyboardEvent::MetaKey, DontDelete|ReadOnly, 0, 0 },
+ { "keyIdentifier", DOMKeyboardEvent::KeyIdentifier, DontDelete|ReadOnly, 0, &DOMKeyboardEventTableEntries[7] },
+ { 0, 0, 0, 0, 0 },
+ { "altKey", DOMKeyboardEvent::AltKey, DontDelete|ReadOnly, 0, 0 },
+ { "keyLocation", DOMKeyboardEvent::KeyLocation, DontDelete|ReadOnly, 0, &DOMKeyboardEventTableEntries[5] },
+ { "ctrlKey", DOMKeyboardEvent::CtrlKey, DontDelete|ReadOnly, 0, &DOMKeyboardEventTableEntries[6] },
+ { "shiftKey", DOMKeyboardEvent::ShiftKey, DontDelete|ReadOnly, 0, 0 },
+ { "altGraphKey", DOMKeyboardEvent::AltGraphKey, DontDelete|ReadOnly, 0, 0 }
+};
+
+const struct HashTable DOMKeyboardEventTable = { 2, 8, DOMKeyboardEventTableEntries, 5 };
+
+} // namespace
+
+namespace KJS {
+
+const struct HashEntry DOMKeyboardEventProtoTableEntries[] = {
+ { "initKeyboardEvent", DOMKeyboardEvent::InitKeyboardEvent, DontDelete|Function, 11, 0 }
+};
+
+const struct HashTable DOMKeyboardEventProtoTable = { 2, 1, DOMKeyboardEventProtoTableEntries, 1 };
+
+} // namespace
+
+namespace KJS {
+
const struct HashEntry MutationEventConstructorTableEntries[] = {
{ "ADDITION", DOM::MutationEvent::ADDITION, DontDelete|ReadOnly, 0, &MutationEventConstructorTableEntries[3] },
{ "MODIFICATION", DOM::MutationEvent::MODIFICATION, DontDelete|ReadOnly, 0, 0 },
-------------- next part --------------
-- Darin
More information about the Khtml-devel
mailing list