DYNAMIC EVENT HANDLERS FOR STRUCTURED TEXT
BACKGROUND OF THE INVENTION
This invention relates generally to computer programming languages for creating and delivering content on the World Wide Web, and more specifically to a mechanism for handling events associated with stractured text content.
The World Wide Web ("WWW") or "Web" is the total set of interlinked hypertext documents residing on HyperText Transfer Protocol ("HTTP") servers all around the world. These servers form the Internet, a worldwide collection of computers, networks and gateways that use the TCP/IP suite of protocols to communicate with one another. Documents on the World Wide Web, called pages or Web pages, can be written in Hypertext Markup Language ("HTML"). These documents are identified by Uniform Resource Locators ("URLs") that specify the particular machine and pathname by which a document can be accessed. Codes, called tags, embedded in an HTML document associate particular words and images in the document with other URLs such that a user can link to another document, stored on any server on the network, by the press of a key or the click of a mouse. These files may contain text (in a variety of fonts and styles), graphics images, movie files, and sounds, as well as Java4"1 applets, ActiveX® controls, or other small embedded software programs that execute when the user activates them by activating a link. These tags, used in association with text, create stractured text. The World Wide Web was developed by Timothy Berners-Lee in 1989 for the European Laboratory for Particle Physics (CERN).
Content on the World Wide Web is created and controlled using various computer programming languages. Computer programming languages are used to define a sequence of data and instructions that can ultimately be processed and executed by a computer. The instructions can be translated, from the source code expressed using the programming language to the machine code that the computer works more directly with, by means of another program, such as a compiler or interpreter. Examples of languages for Web content creation and delivery are:
HTML; the Javata computer programming language; and the Curr™ computer programming language. The Curl computer programming language is developed by Curl Corporation, Cambridge, Massachusetts.
HTML is an application of the Standard Generalized Markup Language ("SGML") and uses tags to mark content elements, such as text and graphics, in a document to indicate how Web browsers should display this content to the user and how the content should respond to user actions, such as activation of a link by means of a key press or mouse click. HTML is defined, in various versions, by the Internet Engineering Task Force ("IETF") and by the World Wide Web Consortium ("W3C").
Java is an object-oriented programming language, developed by Sun Microsystems, Inc. Similar to C++, Java is smaller, more portable, and easier to use than C++ because it is more robust and it manages memory on its own. Java was also designed to be secure and platform-neutral. Java programs are compiled into bytecodes, which are similar to machine code and are not specific to any platform, making it a useful language for programming Web applications, since users access the Web from many types of computers. Currently, the most widespread use of Java is in programming small applications, or applets, for the World Wide Web.
The Curl computer programming language is designed to present a single, coherent linguistic basis for the expression of Web content at levels ranging from simple formatted (structured) text to complex object-oriented programs. The Curl computer programming language is intended to be a gentle slope system, accessible to content creators at all skill levels ranging from novice content developers to experienced computer programmers. More information on the Curl computer programming language can be found in the paper entitled "Curl: A Gentle Slope Language For The Web" by M. Hostetter, D. Kranz, C. Seed, C. Terman and S. Ward of the Massachusetts Institute of Technology Laboratory for Computer Science.
The Curl computer programming language presents an object-oriented system that comprises both a static (compile-time) mode and a dynamic (run-time) mode. At compile-time, an object's structure, or class definition (i.e., data and
methods) is described. At run-time an instance of an object, based upon its class definition, can be created. The run-time object can then act upon, and be acted upon, by other objects created in the run-time system.
Most Web programming languages, such as the Curl computer programming language, provide a mechanism for processing events. An event is an action or occurrence, generated by a user or by the system itself, to which a computer program might wish to respond. For example, key presses, button clicks, mouse movements and timers are all types of events. Web programming languages with event processing capabilities can be used to created event-driven programs. In contrast to event-driven programs, polling-driven programs are required to interrogate, and effectively anticipate, every interaction with the program. Event processing operates through the creation and maintenance of an event queue. Events that occur are appended to the event queue for the program to process. Event based Web programming languages have proven to be an efficient way in which to process interactions with Web content.
SUMMARY OF THE INVENTION
Structured text is standard text that has been marked up with semantic or presentation information. Existing computer programming languages for Web content development provide event mechanisms that can associate existing events with structured text. But, most require that the association be done statically at compile-time, not dynamically at run-time. Additionally, other existing computer programming languages provide for dynamic association of events, but lack the ability to associate those events with stractured text. Even within systems that do allow event handlers to be added dynamically at run-time, their static set of event types means that users are not able to create new event scenarios. Without an ability to dynamically define new event types and dynamically attach event handlers to structured text objects content developers are restricted in their ability to created flexible and effective content using stractured text.
Accordingly, the present invention provides an event mechanism for dynamically defining the actions to be performed on structured text when various events occur within computer systems.
In an embodiment of the present invention a method of dynamically defimng event handlers for stractured text comprises: defining an event type; creating, at runtime, an event handler responsive to the event type; and associating the event handler with the stractured text. Once the event handler associated with the stractured text is created, it can be invoked to perform actions on the stractured text. The creation and association of the event handler can occur at run-time, thereby providing dynamic event handlers for stractured text. The defined event type can be used to invoke multiple event handlers. The event handler invoked can also consume the event type, possibly preventing other event handlers from processing it. The definition of the event type can occur at run-time, as well as at compile-time, thereby providing for dynamic event type creation. Creating an event handler comprises providing executable code for processing the event type and associating that executable code with an event target (e.g., a structured text object). The executable code, or a pointer to the executable code can be supplied to the event handler. To facilitate the creation of event handlers the Curl computer programming language provides an ON macro. A macro, in a programming language, is a named set of instructions used to assist in the construction of more complex code. The Curl ON macro provides input parameters that assist in the creation of event handlers.
Input parameters to the ON macro must include an event type and can optionally include: a variable name for the event type, a type of event target and a variable name for the event target. The first optional parameter is the name of a variable is to be bound to the event type being handled during the execution of the handler body. This variable will be of the type indicated as a parameter. The parameter is not the variable itself; the variable is created inside the macro. The second optional parameter is the type of event target to which the handler should be attached. This parameter is only useful when used in conjunction with the third optional parameter. The third optional parameter is the name of a variable to be
bound to the event target during the execution of the handler body. This variable will be of the type indicated in the optional second parameter. The parameter is not the variable itself; the variable is created inside the macro.
The following example code illustrates the parameter concepts of the ON macro:
{let et:EventTarget = {SomeEventTarget} {paragraph
{on e:PointerPressEvent at et:EventTarget do {et.phone-home} }
"hello!"
} When a user clicks on the paragraph, the value of the variable "et" on which the method "phone-home" is called, is the paragraph, not the SomeEventTarget object. The latter is a second variable, whose scope is bound outside the ON macro, but not inside it.
An embodiment of the present invention provides a method of defining and invoking dynamic event handlers for stractured text comprises using class definitions to create objects to process events on structured text. An object of an object class capable of firing events is created, along with an event object of an event class capable of specifying an event type. In environments that support procedures separate from objects, there is no need to create a specific object to fire an event. A stractured text object of a structured text class capable of representing content is also created, the structured text object being enabled to interact with the event type. At run-time an event handler object is created from an event handler class capable of processing the event type for the structured text object. The object then fires the event object at the structured text object, the stractured text object invokes the event handler object associated with the event type specified in the event object and the desired actions are performed on the stractured text object. Alternate ways to create an EventHander include: doing run-time type analysis on the handler procedure's arguments, storing the event type separate from
the handler procedure, or not storing the type at all and having the implementor of the handler procedure check the type.
The dynamic nature of the definition of the event handlers on stractured text provided by the present invention overcomes the inherent inflexibility associated with systems that require static (i.e., compile-time) definition of event handlers and event types. Additionally, dynamic event handlers for stractured text allow for scalability in systems that must react quickly to demands for enhanced features in the area of Web content presentation.
BRIEF DESCRIPTION OF THE DRAWINGS The foregoing and other objects, features and advantages of the invention will be apparent from the following more particular description of preferred embodiments of the invention, as illustrated in the accompanying drawings in which like reference characters refer to the same parts throughout the different views. The drawings are not necessarily to scale, emphasis instead being placed upon illustrating the principles of the invention.
Figure 1 illustrates a computer system on which an embodiment of the present invention is implemented.
Figure 2 shows the internal structure of the computer of Figure 1.
Figure 3 illustrates the class hierarchies defined in an embodiment of the present invention.
Figure 4 illustrates the objects and object interactions of an embodiment of the present invention.
Figure 5 is a flowchart of the process of providing executable code for processing an event type.
DETAILED DESCRIPTION OF THE INVENTION
Stractured text is an important aspect of defining effective Web content. It provides for text characters to be marked up with presentation information when displayed. Event mechanisms within computer systems provide an ability to communicate the occurrence of various actions among objects within the system.
The ability to dynamically define event types and event handlers enhances the effectiveness of event mechanisms. Applying dynamic event type and event handlers to stractured text provides a convergence of processing and content that allows for effective and powerful text presentation. There are two ways of representing text using the Curl computer programming language: as traditional programming language strings, or as text that has been marked up with presentation information. The presentation information allows the Curl computer programming language to present the text in a stylized way, similar to the behavior obtained when using Rich Text Format ("RTF"), HTML, or TeX. The Curl computer programming language's representation of text content is object-oriented and hierarchically structured. A hierarchical representation of a document as stractured text could include a node representing each section of the document. A root node could be associated with all the nodes representing the sections. Each section node could be associated with nodes representing individual paragraphs of the document. Each paragraph node could contain the paragraph's text directly, or it might be further decomposed into sub-nodes based on sentences, or words, for example. The Curl computer programming language's Element class is the base class for its structured text class, TextElement. The Element class is a subclass of EventTarget, enabling events to be fired at any stractured text node in the document tree. TextElement's initialization method is well-behaved with respect to the EventTarget protocol, so that EventHandler parameters passed to the initialization method of TextElement will be added as dynamic event handlers on the Element. In addition to creating Elements directly, the Curl computer programming language supports a markup language, similar to HTML. These markups are generally simple syntax wrappers around the initialization method of the appropriate Element classes, well-behaved markups within the Curl computer programming language will also accept EventHandlers as parameters. The EventHandler will be passed a parameter to the Element initialization method, which will eventually result in the handler being added to the object's dynamic event handler list. These syntax wrappers provide another way to dynamically add an event handler to an object.
When an event mechanism is combined with stractured text, a system is created for communicating, from objects within the system, a desire to perform various actions on stractured text. Accordingly, the present invention provides an event mechanism for defining, at run-time, the actions to be performed on structured text when various events occur within computer systems.
Figure 1 illustrates a computer system on which an embodiment of the present invention is implemented. A computer 100 provides processing and input/output devices for developing and viewing content. Computer 100 is connected to a keyboard 102 and mouse 104 for receiving input and a display 106 for presentation of content. Computer 100 is also linked to a network 110 having access to servers (112, 114). The network can be part of the Internet, the worldwide collection of computers, networks and gateways that use the TCP/TP suite of protocols to communicate with one another. The Internet provides a backbone of high-speed data communication lines between major nodes or host computers, consisting of thousands of commercial, government, educational, and other computer systems, that route data and messages. Servers (112,114) connected to the network 110 can host content for display on computer 100. The content can include specially formatted Web pages hosted on a Web server 114 connected to the network 110. Figure 2 shows the internal structure of the computer of Figure 1. The computer 100 contains a system bus 204, a bus is a set of hardware lines used for data transfer among the components of a computer system. A bus is essentially a shared highway that connects different parts of the system (e.g., processor, disk-drive controller, memory, and input/output ports) which enables the different parts to transfer information. Attached to system bus 204 is display interface 206, display interface 206 allows display 106 to communicate with other components on system bus 204. Keyboard interface 208 and mouse interface 210 are also attached to system bus 204 and allows the input devices to communicate with other components on system bus 204. Network interface 212 provides the link to an external network (e.g., network 110) allowing processes running on computer 100 to communicate with servers (112,114) connected to a network 110. A memory 200
can store computer software instructions and data structures used to implement an embodiment of the present invention. A processor 202 executes instructions stored in memory 200, allowing the computer 100 to process and display Web content, including stractured text. In a system displaying content it is often desirable to represent that content using an object-oriented paradigm, in which a system is viewed as a collection of discrete objects that are self-contained collections of data structures and routines having the ability to interact with other objects in the system. Object-oriented systems provide for the definition of classes that can be used to create (instantiate) objects of that class. The objects allow for the encapsulation of data and provide well defined interfaces for other objects to use when sending data to, or receiving data from, an object. One class definition can inherit (subclass) the capabilities of another, allowing more complex classes to be build from simpler, underlying classes. Classes, as used in this description, are allowed to be subclasses of themselves. The classes can also specify certain behaviors that are only fully defined at run-time. The combination of features provided in object-oriented systems create a platform for delivering flexible and scalable content development and display systems.
Programs written using the Curl computer programming language can be notified of the occurrence of various events of interest by means of an event mechanism. Events often occur as a result of user interaction, such as pressing a key on the keyboard, moving the pointer across the display screen, or clicking a mouse button on a graphical object. Not all events are a result of outside interaction; the Curl run-time itself can also explicitly instantiate events. When a particular type of event occurs, an event object of that type is instantiated.
In one preferred embodiment of the present invention classes are defined for an Event, an EventTarget and an EventHandler. The following description contains examples of programming concepts of the present invention in pseudocode. This code resembles the Curl computer programing language, but is not intended to conform to the syntax of any existing language. The pseudocode is presented to
illustrate concepts, not define implementation details. Example implementations of
Event, EventTarget and EventHandler classes follow.
The Event class represents an interaction that occurs within the computer system that is meant to be communicated to objects within the computer system. Events can be created and fired as a result of external interaction (e.g., a key press) or created explicitly (e.g., because a timer expired). Events can represent actions taken in the past, actions currently being taken, or actions to taken in the future.
{define-class Event Fields: boolean consumed?;
EventTarget target;
Methods: fireO {
// This method assumes that this.target is already set. set this.consumed? = false; this.target.fire-event-handlers(this); this .fire-methods() ; } fire-methods() {
// subclasses will override this to call the appropriate // static methods, if any; e.g., the KeyPress event will // call this.target.on-key-press(this). } consume() { set this.consumed? = true } }
The EventTarget class provides an object with the ability to receive and process events that may be targeted (fired) at it.
{define-class EventTarget Fields:
EventHandler[] handlers;
Methods: init(EventHandler[] handlers) { for (each handler in handlers) { this.add-event-handler(handler);
} add-event-handler(EventHandler handler) { assert(this is subclass of handler.handler-procedure's first argument); this . event-handlers . app end(handler) ;
} remove-event-handler(EventHandler handler) { this .handlers .remo ve(handler) ;
} fire-event-handlers(Event event) { for (each handler in this.handlers) { handler.handler-procedure(event, this) ; }
}
// Common static handlers on-key-press(KeyPress event) { // default implementation does nothing
} }
The EventHandler class provides dynamic handlers (attached at runtime) and static handlers (i.e., methods of EventTarget class) for processing Events. {define-class EventHandler
Fields:
ClassType type-of-event-to-handle; Procedure handler-procedure;
Methods: init(ClassType type-of-event, Procedure procedure) { assert(type-of-event is a subclass of Event); assert(procedure takes two arguments); assert(event-class is a subclass of procedure's first argument); assert(procedure's second argument is a subclass of
EventTarget); assert(procedure has zero return values); set this.type-of-event-to-handle = type-of-event; set this. handler-procedure = procedure; }
typecheck-potential-target(EventTarget target) { assert(target is a subclass of type-of-event's target type);
} fire(Event e) { handler-procedure(e); } cloneO { return new EventHandler(this.type-of-event-to-handle, this.handler-procedure); } }
Although Event represents the existence of an event, its mere existence does not mean that the event is occurring. Because events can be occurring now, may have occurred in the past, or may occur in the future, a Curl Event can represent an event occurring in various time frames. The actual occurrence of the event is represented by calling the fire method on an Event; this is known as firing the event. Generally, Events are created, fired, then released, but this sequence is not required. Curl objects are allowed to store Event objects (previously fired or not), fire an Event more than once, or create and release an Event without ever firing it.
The firing of an Event does not occur blindly; instead, the event is fired at a specific target. The target must be a subclass of the EventTarget class. The Event can be fired at more than one object by changing the target and refiring it. Some Event types are processed by an algorithm that searches for targets and fires the Event at each of the found targets.
Each EventTarget has a (possibly empty) set of EventHandlers that may process the event. Each handler will only process events of a specific Event class, or subclasses of that class. A handler for events of type Event will process all events fired at the EventTarget, since all events must be subclasses of Event.
There are two types of EventHandlers: static and dynamic. Static EvenHandlers are simply methods of EventTarget. It is the responsibility of each Event subclass to call the appropriate static EventHandler methods on the target.
For some types of Events, there maybe no static handlers that are appropriate; for others, there may be several. The predefined Event types are associated with particular static EventHandlers; for example, the KeyPress event will call the on-key-press() method on the EventTarget. The default static event handlers on EventTarget perform no action; they are merely placeholders for subclasses to provide their own handlers by overriding the methods.
Dynamic EventHandlers are not intrinsic to the EventTarget, but can added to, or removed from, the EventTarget at runtime. Conceptually, dynamic EventHandlers are procedures stored on the dynamic event handler list of the
EventTarget and are only called for events of a specific class (or subclasses of that class). There can be more than one dynamic EventHandler for the same Event on a target, and there can be a dynamic EventHandler for an Event that also has a static handler on the same EventTarget. The order in which the dynamic EventHandlers are called on an EventTarget may be undefined, although all dynamic EventHandlers for an Event will be called before the static EventHandler (if any) is called.
An EventHandler can perform its specified task and also request that other handlers not act on that specific event by consuming the event it handles. One way to indicate that an EventHandler has consumed an Event is to set a flag on the Event. A mechanism for enforcing this convention is not required within Event,
EventTarget, or EventHandler, although there are specific algorithms within the Curl run-time that use this mechanism to stop searching for new targets at which to fire an Event if the Event has been consumed.
Each EventTarget keeps a list of its EventHandlers. EventHandlers are added to an EventTarget through the add-event-handler method(). In addition to this, EventTarget provides a mechanism for adding dynamic event handlers when creating the EventTarget. The intialization method of EventTarget takes a variable number of parameters: for each parameter that is of type EventHandler, the EventTarget will call add-event-handler() on itself, passing the initialization parameter as the argument to add-event-handler(). Since any class' initialization method can pass its parameters to the initialization method of its superclass, it is
very simple for any subclass of EventTarget to accept EventHandlers when it is created. This initialization scheme, combined with the use of the ON macro, makes it easy to add a dynamic EventHandler to well-behaved subclasses of EventTarget. When an Event is fired at an EventTarget, the EventTarget considers each EventHandler on its list. If the EventHandler is defined to handle that type of event, its procedure is called with the Event as its first argument, and the EventTarget as its second argument. The event mechanism allows for all of the EventHandlers on the list to be considered, even if the Event is consumed.
Figure 3 illustrates the class hierarchies defined in an embodiment of the present invention. The Object class 350 is a base class for all other classes and is implicit in their definition. Event class 352 is a subclass of Object Class 350, Event class 352 is a parent class to WindowEvent (e.g., PointerPress, KeyPress) and SelectionEvent. BasicEventTarget class 354 contains methods used internally by an event queuing mechanism and is a parent of EventTarget class 356. EventTarget class 356 allows EventHandlers to be attached to objects and allows Events to be fired at those objects. Visual Class 358 inherits from the EventForwarder class and is part of the internal mechanism for dispatching pointer events. The Element class 360 is the parent of StructualElement and TextElement class 362. The EventHandler class 364 supports the processing of Event types using executable code to act upon the EventTarget.
Figure 4 illustrates the objects and object interactions of an embodiment of the present invention. In a generic example, an Object 300 fires an Event 302 at an EventTarget 306. In this example, StracturedText 304 object has subclassed EventTarget 306. EventTarget 306 invokes EventHandler 308 to process the Event 302. EventHandler 308 calls static methods 310 (i.e., those defined in the class definition) and dynamic procedures 312 (i.e., those added dynamically) on EventHandler 308. These static methods 310 and dynamic procedures 312 act on StracturedText 304 to effect the actions associated with Event 302 on StracturedText 304. In a more specific example, dynamic event handlers for structured text can be used to process a command to capitalize a portion of text in a content display
system. The base Event classes described above can be extended to more closely capture the semantics of a particular event (e.g., capitalization). An Event and EventHandler are defined, the EventHandler is then attached to a stractured text object and invoked to perfoπn the capitalization. Using an object-oriented approach, the class, CapitalizeEvent, is defined as a subclass of Event. The underlying Event class provides the basics of event processing. A CapitalizeEvent object can define a more specific target type, TextElement, for the CapitalizeEvent to be fired at. A CapitalizeHandler instance can also be created to perform the actual capitalization on the text. For example:
// create an event handler for the event type
EventHandler CapitalizeHandler set CapitalizeHandler =
{on CapitalizeEvent do // // actual code to capitalize the first letter of
// the first word in every sentence goes here... // • }
Once the Event and EventHandler are defined, the EventHandler is attached to an EventTarget (e.g. the structured text object defined by TextElement) to enable the Event to be fired.
The EventHandler can be added to the stractured text object after the structured text object has been created, using a method provided for associating
EventHandlers with EventTargets. For example: let Para = {paragraph "this application will be filed in the united states patent and trademark office."} Para.add-event-handler(CapitalizeHandler);
The EventHandler can be added to the structured text object when it is created. For example: {paragraph "this application will be filed in the united states patent and trademark office." {value CapitalizeHandler}}
The EventHandler can be also added to the stractured text object when it is created, providing the actual code at the same time. For example:
{paragraph "this application will be filed in the united states patent and trademark office." {on CapitalizeEvent do
//
// actual code to capitalize the first letter of // the first word in every sentence goes here...
} }
Once an EventHandler is attached to the structured text object, the
EventHandler can be invoked by firing an Event at the EventTarget. In this example the capitalization action is initiated by pressing the Ctrl-C key on the keyboard. For example: if (KeyPress = <confrol-c>) { // if Ctrl-C
CapitalizeEvent c; // declare a Capitalize event set c = new CapitalizeEvent(); // instantiate a Capitalize event for (each paragraph in a document) { // select a paragraph set c.consumed? = false // set to not consumed set c.target = paragraph // point the event at the paragraph c.fire(); // fire the event at the paragraph
} }
Attaching the EventHandler and firing the Event that causes the
EventHandler to be invoked can be combined by providing executable code during the attachment process. One preferred embodiment uses the ON macro to process a
PointerPress event. For example:
{paragraph "click on me to capitalize each sentence." {on e:PointerPress do
CapitalizeEvent c; set c = {new CapitalizeEvent} set c.target = e.target c.fireO;
} }
The creation of a dynamic EventHandler has two steps: 1) writing the code for the handler, and 2) attaching the handler to a target.
An EventHandler can be defined directly using the "define-proc" mechanism. For example, using the CapitalizeEvent discussed above, an EventHandler can be defined follows:
{define-proc capitalize-handler (CapitalizeEvent event, EventTarget target) { //
// actual code to capitalize the first letter of // the first word in every sentence goes here...
} let handler:EventHandler set handler = new EventHandler(CapitalizeEvent, capitalize-handler);
The Curl computer programming language also provides an ON macro to assist in writing the EventHandler code. Although use of the ON macro is not required it can simplify the creation of dynamic event handlers. There are several ways in which one can use the ON macro. An example of the simplest form of the ON macro is:
{on <event-type> do <body>
} where <event-type> specifies the class of event to handle, and <body> specifies the actual event handler code.
Other variations allow you to use variables to set the event target, for example:
{on <event-var>:<event-type> do
<body> }
{on <event-var>:<event-type> at <target-var>:<target-type> do
<body> }
{on <event-type> at <target-var>:<target-type> do <body>
} where <event-type> specifies the class of event to handle, <event-var> is the name of a variable that will contain the instance of the event that was fired, <target-type> specifies the class of event target onto which the handler will be attached,
<target-var> is the name of a variable that will contain the instance of the target at which the event was fired, and <body> is the actual event handler code. The handler will also be called for events that are subclasses of <event-type>, and that the handler can be attached to objects that are subclasses of <target-type>.
When the code has been predefined in a procedure, the ON macro can be used to directly invoke the procedure upon the occurrence of the event, for example:
{on <event-type> invoke <proc>
} where <proc> is a procedure of no parameters that contains the event handler code.
The ON macro creates and returns an object of type EventHandler. An object of this type can also be created directly. The initializer function for the
EventHandler class takes two parameters: the type of event to handle, and a procedure to call when the handler is invoked. The procedure takes two parameters: an Event and an EventTarget.
Figure 5 is a flowchart of the process of providing executable code for processing an event type in the implementation of the ON macro. The process starts at step 402. The variables used in the process: <event-var>, <event-type>, <target-var>, <target-type>, <body>, and <proc> are initialized to null at step 402. Step 404 parses the next expression. Step 406 determines if the expression is an identifier. If it is, Step 408 sets the variable <event-type> to that identifier; otherwise, Step 410 determines if the expression is a pair of a name and an identifier. If it is, Step 412 sets the variable <event-var> to the name and the variable <event-type> to the identifier; otherwise Step 414 throws an error and execution exits. Step 412 and Step 408 both proceed to Step 416.
Step 416 parses the next expression. Step 418 determines if the expression is the word "at". If it is, execution proceeds to Step 420; otherwise, execution jumps to
Step 432. Step 420 parses the next expression. Step 422 determines if the expression is an bidentifier. If it is, Step 424 sets the variable <target-type> to that identifier; otherwise, Step 426 determines if the expression is a pair of a name and an identifier. If it is, Step 428 sets the variable <target-var> to the name and the variable <target-type> to the identifier; otherwise Step 430 throws an error and execution exits. Step 424 and Step 428 both proceed to Step 432.
Step 432 parses the next expression. Step 434 determines if the expression is the word "do". If it is, execution proceeds to Step 434; otherwise, Step 436 throws an error and execution exits. Step 434 stores the remaining expressions in <body>. Step 438 determines if <event-var> is null. If it is, Step 440 generates a unique name and sets <event-var> to it; in either case, execution proceeds to Step 442. Step 442 determines if <target-var> is null. If it is, Step 444 generates a unique name and sets <target-var> to it; in either case, execution proceeds to Step 446. Step 446 determines if <target-type> is null. If it is, Step 448 sets <target-type> to EventTarget; in either case, execution proceeds to Step 450.
Step 450 creates a new procedure and sets <proc> to it. This procedure has an argument named <event-var> of type <event-type>, and an argument named <target-var> of type <target-type>. The body of the procedure is <body>. Step 452 creates and returns an EventHandler with arguments <event-type> and <proc>. Step 454 is the end.
Other example uses for dynamic event handlers on structured text include: a TranslateEventHandler that looks up the text in a language translation dictionary and pops up a window displaying the results. An ExecuteEventHandler can invoke the Curl just-in-time compiler on the text; if the text was valid Curl code, the compiled program would be executed. An AnimateEventHandler might adjust the appearance of the rendered text, not the content, with each firing, by updating a marquee that marches around each glyph. A FindDocumentationEventHandler might pop up a documentation system and perform a query using the selected text.
While this invention has been particularly shown and described with references to preferred embodiments thereof, it will be understood by those skilled
in the art that various changes in form and details may be made therein without departing from the scope of the invention encompassed by the appended claims.