Event handling

Hi there,

I have three questions concerning the handling of events:

A. Specification of Event types
B. Adding event listeners
C. Specification of Event targets

ad A.

The term "eventType" is used in at least three different places in the DOM-2
specification:

A.a.  interface EventTarget {
         void addEventListener(in DOMString type, ...);
         ...
     }
with no additional comment that would specify the enumeration of valid
strings with which the 
actual parameter 'type' can be assigned.

A.b. interface DocumentEvent {
        Event createEvent(in DOMString eventType) ...
    }

with an an additional illustrative text concerning the 'eventType'
parameter, namely:

'As an example, a user wishing to synthesize some kind of  UIEvent would
call createEvent 
with the parameter "UIEvent"'.

A.c. interface MouseEvent : UIEvent {
        ....
        void initMouseEvent(in DOMString typeArg, ...);
   }

with an an additional illustrative text concerning the 'typeArg' parameter,
namely:
 
'The different types of Mouse events that can occur are: 
click ... mousedown ... mouseup'


FIRST: In the context of A.a at least an illustrative example should be
given.

SECOND: In the JAVA language binding the language construct listening for an

event is an object implementing a certain kind of interface. According to
what I 
know from AWT/Swing the event type given in 'addEventListener'  would be
something 
like "MouseEvent". In this case the event source would sort out which kind
of method to 
call for "subtypes" like "mousedown", "mouseup" etc.. 

On the other hand, as far as I understand the ECMA-script language binding ,
the language 
construct listening for an event is a "callback-function" (the
binding-specification 
says: "Object EventListener: This is an ECMAScript function reference."; in 
ECMA script functions can be refered to as data and passed accordingly).
Accordingly if I had to register 
a course grain event type like "MouseEvent" I would have to sort out what
fine-grained event 
type ("mousedown", "mouseup" etc.) actually happend in my callback-function.
This forces 
a switch-case construct in the call-back function - something viewed as bad
style in OO.

ad B.

Should 'addEventListener' not throw an exception if the 'type' parameter
specifies an invalid type.

ad C.
interface Event {
    ...
    readonly attribute EventTarget      target;
    ...
}

The standard says "The EventTarget interface is implemented by all Nodes in
an implementation 
which supports the DOM Event"

In an OO-language-binding of the DOM2 standard, both interfaces, the
'Node'-interface and the 
'EventTarget'-interface will be implemented by objects. Technically this is
achieved 
by implmenting the 'Node'-object with a construct (for example a privat
field), that referes to
the 'EventTarget'-implementation-object. The method
'addEventListener'-method contained in the 
interface of the 'Node'-implementation-object will pass on all method-calls
to the respective 
method in the interface of the 'EventTarget'-implementation-object.

To which reference should the 'target' field of the Event-object be set: To
a reference to the 
Node-implementation-object or to a reference to the
EventTarget-implementation-object? 
Personally I would set the 'target'-field of the reference to the
Node-implementation-object - but the 
the standard is not explicit with respect to this issue.


- Stefan

Received on Thursday, 16 March 2000 04:32:26 UTC