Module: dom-internals Synopsis: Document Object Model Author: Scott McKay Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND /// HTML Elements define constant $html-element-names :: = make(); define macro html-element-definer { define html-element ?tag:expression ?attributes:* end } => { $html-element-names[?tag] := ?tag; define html-attributes ?attributes end } end macro html-element-definer; define macro html-attributes-definer { define html-attributes end } => { } { define html-attributes readonly attribute ?tag:expression => ?attribute:name :: ?type:expression; ?attributes:* end } => { define html-attribute readonly ?tag => ?attribute :: ?type end; define html-attributes ?attributes end } { define html-attributes attribute ?tag:expression => ?attribute:name :: ?type:expression; ?attributes:* end } => { define html-attribute ?tag => ?attribute :: ?type end; define html-attributes ?attributes end } end macro html-attributes-definer; define macro html-attribute-definer { define html-attribute readonly ?tag:expression => ?attribute:name :: ?type:expression end } => { define sealed method ?attribute (_elt :: ) => (_val :: ?type) get-html-attribute(_elt, ?tag, ?type) end method } { define html-attribute ?tag:expression => ?attribute:name :: ?type:expression end } => { define sealed method ?attribute (_elt :: ) => (_val :: ?type) get-html-attribute(_elt, ?tag, ?type) end method; define sealed method ?attribute ## "-setter" (_val :: ?type, _elt :: ) => () set-html-attribute(_elt, ?tag, ?type, _val) end method } end macro html-attribute-definer; define sealed method get-html-attribute (elt :: , name :: , type == ) => (_value :: ) get-attribute(elt, name) end method get-html-attribute; define sealed method set-html-attribute (elt :: , name :: , type == , _value :: ) => () set-attribute(elt, name, _value) end method set-html-attribute; define sealed method get-html-attribute (elt :: , name :: , type == ) => (_value :: ) string-to-integer(get-attribute(elt, name)) end method get-html-attribute; define sealed method set-html-attribute (elt :: , name :: , type == , _value :: ) => () set-attribute(elt, name, integer-to-string(_value)) end method set-html-attribute; define sealed method get-html-attribute (elt :: , name :: , type == ) => (_value :: ) select (get-attribute(elt, name) by string-equal?) "YES" => #t; "NO" => #f end end method get-html-attribute; define sealed method set-html-attribute (elt :: , name :: , type == , _value :: ) => () let _value = if (_value) "YES" else "NO" end; set-attribute(elt, name, _value) end method set-html-attribute; /// Define the shared attribute methods define html-attribute "ACCESSKEY" => html/access-key :: end; define html-attribute "ALIGN" => html/align :: end; define html-attribute "ALT" => html/alt :: end; define html-attribute "ARCHIVE" => html/archive :: end; define html-attribute "BGCOLOR" => html/bg-color :: end; define html-attribute "BORDER" => html/border :: end; define html-attribute "CH" => html/ch :: end; define html-attribute "CHOFF" => html/ch-off :: end; define html-attribute "CHARSET" => html/charset :: end; define html-attribute "CITE" => html/cite :: end; define html-attribute "CLASS" => html/class :: end; define html-attribute "CODE" => html/code :: end; define html-attribute "CODEBASE" => html/code-base :: end; define html-attribute "COLOR" => html/color :: end; define html-attribute "COMPACT" => html/compact? :: end; define html-attribute "COORDS" => html/coords :: end; define html-attribute "DEFAULTVALUE" => html/default-value :: end; define html-attribute "DIR" => html/dir :: end; define html-attribute "DISABLED" => html/disabled? :: end; define html-attribute "FACE" => html/face :: end; define html-attribute "FRAMEBORDER" => html/frame-border :: end; define html-attribute "HEIGHT" => html/height :: end; define html-attribute "HREF" => html/href :: end; define html-attribute "HREFLANG" => html/href-lang :: end; define html-attribute "HSPACE" => html/hspace :: end; define html-attribute "HTMLFOR" => html/html-for :: end; define html-attribute "LABEL" => html/label :: end; define html-attribute "LANG" => html/lang :: end; define html-attribute "LONGDESC" => html/long-desc :: end; define html-attribute "MARGINHEIGHT" => html/margin-height :: end; define html-attribute "MARGINWIDTH" => html/margin-width :: end; define html-attribute "MEDIA" => html/media :: end; define html-attribute "NAME" => html/name :: end; define html-attribute "READONLY" => html/read-only? :: end; define html-attribute "REL" => html/rel :: end; define html-attribute "REV" => html/rev :: end; define html-attribute "SCROLLING" => html/scrolling :: end; define html-attribute "SHAPE" => html/shape :: end; define html-attribute "SIZE" => html/size :: end; define html-attribute "SRC" => html/src :: end; define html-attribute "TABINDEX" => html/tab-index :: end; define html-attribute "TARGET" => html/target :: end; define html-attribute "TEXT" => html/text :: end; define html-attribute "TITLE" => html/title :: end; define html-attribute "TYPE" => html/type :: end; define html-attribute "USEMAP" => html/use-map :: end; define html-attribute "VALIGN" => html/valign :: end; define html-attribute "VALUE" => html/value :: end; define html-attribute "VSPACE" => html/vspace :: end; define html-attribute "WIDTH" => html/width :: end; define sealed method html/form (elt :: ) => (form :: false-or()) block (return) for (parent = node-parent(elt) then node-parent(parent), until: ~parent) when (tag-name(parent) = "FORM") return(parent) end end; #f end end method html/form; // // interface HTMLHtmlElement : HTMLElement { // attribute DOMString version; // }; // define html-element "HTML" attribute "VERSION" => html/version :: ; end; // // interface HTMLHeadElement : HTMLElement { // attribute DOMString profile; // }; // define html-element "HEAD" attribute "PROFILE" => html/profile :: ; end; define html-element "H1" end; define html-element "H2" end; define html-element "H3" end; define html-element "H4" end; define html-element "H5" end; define html-element "H6" end; // // interface HTMLLinkElement : HTMLElement { // attribute boolean disabled; // attribute DOMString charset; // attribute DOMString href; // attribute DOMString hreflang; // attribute DOMString media; // attribute DOMString rel; // attribute DOMString rev; // attribute DOMString target; // attribute DOMString type; // }; // define html-element "LINK" /* attribute "DISABLED" => html/disabled? :: ; */ /* attribute "CHARSET" => html/charset :: ; */ /* attribute "HREF" => html/href :: ; */ /* attribute "HREFLANG" => html/href-lang :: ; */ /* attribute "MEDIA" => html/media :: ; */ /* attribute "REL" => html/rel :: ; */ /* attribute "REV" => html/rev :: ; */ /* attribute "TARGET" => html/target :: ; */ /* attribute "TYPE" => html/type :: ; */ end; // // interface HTMLTitleElement : HTMLElement { // attribute DOMString text; // }; // define html-element "TITLE" /* attribute "TEXT" => html/text :: ; */ //---*** compute this end; // // interface HTMLMetaElement : HTMLElement { // attribute DOMString content; // attribute DOMString httpEquiv; // attribute DOMString name; // attribute DOMString scheme; // }; // define html-element "META" attribute "CONTENT" => html/content :: ; attribute "HTTPEQUIV" => html/http-equiv :: ; /* attribute "NAME" => html/name :: ; */ attribute "SCHEME" => html/scheme :: ; end; // // interface HTMLAddressElement : HTMLElement { // }; // define html-element "ADDRESS" end; // // interface HTMLBaseElement : HTMLElement { // attribute DOMString href; // attribute DOMString target; // }; // define html-element "BASE" /* attribute "HREF" => html/href :: ; */ /* attribute "TARGET" => html/target :: ; */ end; // // interface HTMLIsIndexElement : HTMLElement { // readonly attribute HTMLFormElement form; // attribute DOMString prompt; // }; // define html-element "ISINDEX" /* readonly attribute "FORM" => html/form :: ; */ attribute "PROMPT" => html/prompt :: ; end; // // interface HTMLStyleElement : HTMLElement { // attribute boolean disabled; // attribute DOMString media; // attribute DOMString type; // }; // define html-element "STYLE" /* attribute "DISABLED" => html/disabled? :: ; */ /* attribute "MEDIA" => html/media :: ; */ /* attribute "TYPE" => html/type :: ; */ end; // // interface HTMLBodyElement : HTMLElement { // attribute DOMString aLink; // attribute DOMString background; // attribute DOMString bgColor; // attribute DOMString link; // attribute DOMString text; // attribute DOMString vLink; // }; // define html-element "BODY" attribute "ALINK" => html/alink :: ; attribute "BACKGROUND" => html/background :: ; /* attribute "BGCOLOR" => html/bg-color :: ; */ attribute "LINK" => html/link :: ; /* attribute "TEXT" => html/text :: ; */ //---*** compute this attribute "VLINK" => html/vlink :: ; end; // // interface HTMLFormElement : HTMLElement { // readonly attribute HTMLCollection elements; // readonly attribute long length; // attribute DOMString name; // attribute DOMString acceptCharset; // attribute DOMString action; // attribute DOMString enctype; // attribute DOMString method; // attribute DOMString target; // void submit(); // void reset(); // }; // //---*** Do 'html/elements' and 'html/length' define html-element "FORM" /* readonly attribute "ELEMENTS" => html/elements :: ; */ /* readonly attribute "LENGTH" => html/length :: ; */ /* attribute "NAME" => html/name :: ; */ attribute "ACCEPTCHARSET" => html/accept-charset :: ; attribute "ACTION" => html/action :: ; attribute "ENCTYPE" => html/enctype :: ; attribute "METHOD" => html/method :: ; /* attribute "TARGET" => html/target :: ; */ end; define sealed method html/submit (form :: ) => () assert(string-equal?(tag-name(form), "FORM"), "You can only call 'submit' on a
"); //---*** Implement this end method html/submit; define sealed method html/reset (form :: ) => () assert(string-equal?(tag-name(form), "FORM"), "You can only call 'reset' on a "); //---*** Implement this end method html/reset; // // interface HTMLSelectElement : HTMLElement { // readonly attribute DOMString type; // attribute long selectedIndex; // attribute DOMString value; // readonly attribute long length; // readonly attribute HTMLFormElement form; // readonly attribute HTMLCollection options; // attribute boolean disabled; // attribute boolean multiple; // attribute DOMString name; // attribute long size; // attribute long tabIndex; // void add(in HTMLElement element, // in HTMLElement before); // void remove(in long index); // void blur(); // void focus(); // }; // //---*** Do 'html/options' and 'html/length' //---*** Do 'add' and 'remove', but call them 'add-option' and 'remove-option' define html-element "SELECT" /* readonly attribute "TYPE" => html/type :: ; */ //---*** compute this attribute "SELECTEDINDEX" => html/selected-index :: ; /* attribute "VALUE" => html/value :: ; */ /* readonly attribute "LENGTH" => html/length :: ; */ /* readonly attribute "FORM" => html/form :: ; */ /* readonly attribute "OPTIONS" => html/options :: ; */ /* attribute "DISABLED" => html/disabled? :: ; */ attribute "MULTIPLE" => html/multiple? :: ; /* attribute "NAME" => html/name :: ; */ /* attribute "SIZE" => html/size :: ; */ /* attribute "TABINDEX" => html/tab-index :: ; */ end; // // interface HTMLOptGroupElement : HTMLElement { // attribute boolean disabled; // attribute DOMString label; // }; // define html-element "OPTGROUP" /* attribute "DISABLED" => html/disabled? :: ; */ /* attribute "LABEL" => html/label :: ; */ end; // // interface HTMLOptionElement : HTMLElement { // readonly attribute HTMLFormElement form; // attribute boolean defaultSelected; // readonly attribute DOMString text; // attribute long index; // attribute boolean disabled; // attribute DOMString label; // readonly attribute boolean selected; // attribute DOMString value; // }; // define html-element "OPTION" /* readonly attribute "FORM" => html/form :: ; */ attribute "DEFAULTSELECTED" => html/default-selected? :: ; /* readonly attribute "TEXT" => html/text :: ; */ //---*** compute this? attribute "INDEX" => html/index :: ; /* attribute "DISABLED" => html/disabled? :: ; */ /* attribute "LABEL" => html/label :: ; */ readonly attribute "SELECTED" => html/selected? :: ; /* attribute "VALUE" => html/value :: ; */ end; // // interface HTMLInputElement : HTMLElement { // attribute DOMString defaultValue; // attribute boolean defaultChecked; // readonly attribute HTMLFormElement form; // attribute DOMString accept; // attribute DOMString accessKey; // attribute DOMString align; // attribute DOMString alt; // attribute boolean checked; // attribute boolean disabled; // attribute long maxLength; // attribute DOMString name; // attribute boolean readOnly; // attribute DOMString size; // attribute DOMString src; // attribute long tabIndex; // readonly attribute DOMString type; // attribute DOMString useMap; // attribute DOMString value; // void blur(); // void focus(); // void select(); // void click(); // }; // define html-element "INPUT" /* attribute "DEFAULTVALUE" => html/default-value :: ; */ attribute "DEFAULTCHECKED" => html/default-checked? :: ; /* readonly attribute "FORM" => html/form :: ; */ attribute "ACCEPT" => html/accept :: ; /* attribute "ACCESSKEY" => html/access-key :: ; */ /* attribute "ALIGN" => html/align :: ; */ /* attribute "ALT" => html/alt :: ; */ attribute "CHECKED" => html/checked? :: ; /* attribute "DISABLED" => html/disabled? :: ; */ attribute "MAXLENGTH" => html/max-length :: ; /* attribute "NAME" => html/name :: ; */ /* attribute "READONLY" => html/read-only? :: ; */ /* attribute "SIZE" => html/size :: ; */ /* attribute "SRC" => html/src :: ; */ /* attribute "TABINDEX" => html/tab-index :: ; */ /* readonly attribute "TYPE" => html/type :: ; */ //---*** compute this /* attribute "USEMAP" => html/use-map :: ; */ /* attribute "VALUE" => html/value :: ; */ end; define sealed method html/blur (input :: ) => () assert(string-equal?(tag-name(input), "SELECT") | string-equal?(tag-name(input), "INPUT") | string-equal?(tag-name(input), "TEXTAREA") | string-equal?(tag-name(input), "A"), "You can only call 'blur' on a ,