khtml Library API Documentation

kjs_html.cpp

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 1999-2002 Harri Porten (porten@kde.org)
00005  *  Copyright (C) 2001-2003 David Faure (faure@kde.org)
00006  *  Copyright (C) 2003 Apple Computer, Inc.
00007  *
00008  *  This library is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU Library General Public
00010  *  License as published by the Free Software Foundation; either
00011  *  version 2 of the License, or (at your option) any later version.
00012  *
00013  *  This library is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *  Library General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Library General Public
00019  *  License along with this library; if not, write to the Free Software
00020  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  */
00022 
00023 #include "misc/loader.h"
00024 #include "dom/html_block.h"
00025 #include "dom/html_head.h"
00026 #include "dom/html_image.h"
00027 #include "dom/html_inline.h"
00028 #include "dom/html_list.h"
00029 #include "dom/html_table.h"
00030 #include "dom/html_object.h"
00031 #include "dom/dom_exception.h"
00032 
00033 // ### HACK
00034 #include "html/html_baseimpl.h"
00035 #include "html/html_documentimpl.h"
00036 #include "html/html_imageimpl.h"
00037 #include "html/html_objectimpl.h"
00038 #include "html/html_miscimpl.h"
00039 #include "xml/dom2_eventsimpl.h"
00040 
00041 #include <kparts/browserextension.h>
00042 
00043 #include "khtml_part.h"
00044 #include "khtmlview.h"
00045 
00046 #include "ecma/kjs_css.h"
00047 #include "ecma/kjs_events.h"
00048 #include "ecma/kjs_html.h"
00049 #include "ecma/kjs_window.h"
00050 #include "kjs_html.lut.h"
00051 
00052 #include "misc/htmltags.h"
00053 #include "misc/htmlattrs.h"
00054 #include "rendering/render_object.h"
00055 #include "rendering/render_canvas.h"
00056 
00057 #include "kmessagebox.h"
00058 #include <kstringhandler.h>
00059 #include <klocale.h>
00060 
00061 #include <kdebug.h>
00062 
00063 using namespace KJS;
00064 
00065 IMPLEMENT_PROTOFUNC_DOM(HTMLDocFunction)
00066 
00067 Value KJS::HTMLDocFunction::tryCall(ExecState *exec, Object &thisObj, const List &args)
00068 {
00069   KJS_CHECK_THIS( HTMLDocument, thisObj );
00070 
00071   DOM::HTMLDocument doc = static_cast<KJS::HTMLDocument *>(thisObj.imp())->toDocument();
00072 
00073   switch (id) {
00074   case HTMLDocument::Clear: // even IE doesn't support that one...
00075     //doc.clear(); // TODO
00076     return Undefined();
00077   case HTMLDocument::Open:
00078     if (args.size() >= 3) // IE extension for document.open: it means window.open if it has 3 args or more
00079     {
00080       KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
00081       if ( view && view->part() ) {
00082         Window* win = Window::retrieveWindow(view->part());
00083         if( win ) {
00084           win->openWindow(exec, args);
00085         }
00086       }
00087     }
00088 
00089     doc.open();
00090     return Undefined();
00091   case HTMLDocument::Close:
00092     // see khtmltests/ecma/tokenizer-script-recursion.html
00093     doc.close();
00094     return Undefined();
00095   case HTMLDocument::Write:
00096   case HTMLDocument::WriteLn: {
00097     // DOM only specifies single string argument, but NS & IE allow multiple
00098     // or no arguments
00099     UString str = "";
00100     for (int i = 0; i < args.size(); i++)
00101       str += args[i].toString(exec);
00102     if (id == HTMLDocument::WriteLn)
00103       str += "\n";
00104 #ifdef KJS_VERBOSE
00105     kdDebug(6070) << "document.write: " << str.string().string() << endl;
00106 #endif
00107     doc.write(str.string());
00108     return Undefined();
00109   }
00110   case HTMLDocument::GetElementsByName:
00111     return getDOMNodeList(exec,doc.getElementsByName(args[0].toString(exec).string()));
00112   case HTMLDocument::GetSelection: {
00113     // NS4 and Mozilla specific. IE uses document.selection.createRange()
00114     // http://docs.sun.com/source/816-6408-10/document.htm#1195981
00115     KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
00116     if ( view && view->part() )
00117        return String(view->part()->selectedText());
00118     else
00119        return Undefined();
00120   }
00121   case HTMLDocument::CaptureEvents:
00122   case HTMLDocument::ReleaseEvents:
00123     // Do nothing for now. These are NS-specific legacy calls.
00124     break;
00125   }
00126 
00127   return Undefined();
00128 }
00129 
00130 const ClassInfo KJS::HTMLDocument::info =
00131   { "HTMLDocument", &DOMDocument::info, &HTMLDocumentTable, 0 };
00132 /* Source for HTMLDocumentTable.
00133 @begin HTMLDocumentTable 31
00134   title         HTMLDocument::Title     DontDelete
00135   referrer      HTMLDocument::Referrer      DontDelete|ReadOnly
00136   domain        HTMLDocument::Domain        DontDelete
00137   URL           HTMLDocument::URL       DontDelete|ReadOnly
00138   body          HTMLDocument::Body      DontDelete
00139   location      HTMLDocument::Location      DontDelete
00140   cookie        HTMLDocument::Cookie        DontDelete
00141   images        HTMLDocument::Images        DontDelete|ReadOnly
00142   applets       HTMLDocument::Applets       DontDelete|ReadOnly
00143   links         HTMLDocument::Links     DontDelete|ReadOnly
00144   forms         HTMLDocument::Forms     DontDelete|ReadOnly
00145   anchors       HTMLDocument::Anchors       DontDelete|ReadOnly
00146   scripts       HTMLDocument::Scripts       DontDelete|ReadOnly
00147   all           HTMLDocument::All       DontDelete|ReadOnly
00148   clear         HTMLDocument::Clear     DontDelete|Function 0
00149   open          HTMLDocument::Open      DontDelete|Function 0
00150   close         HTMLDocument::Close     DontDelete|Function 0
00151   write         HTMLDocument::Write     DontDelete|Function 1
00152   writeln       HTMLDocument::WriteLn       DontDelete|Function 1
00153   getElementsByName HTMLDocument::GetElementsByName DontDelete|Function 1
00154   getSelection  HTMLDocument::GetSelection  DontDelete|Function 1
00155   captureEvents     HTMLDocument::CaptureEvents DontDelete|Function 0
00156   releaseEvents     HTMLDocument::ReleaseEvents DontDelete|Function 0
00157   bgColor       HTMLDocument::BgColor       DontDelete
00158   fgColor       HTMLDocument::FgColor       DontDelete
00159   alinkColor        HTMLDocument::AlinkColor    DontDelete
00160   linkColor     HTMLDocument::LinkColor     DontDelete
00161   vlinkColor        HTMLDocument::VlinkColor    DontDelete
00162   lastModified      HTMLDocument::LastModified  DontDelete|ReadOnly
00163   height        HTMLDocument::Height        DontDelete|ReadOnly
00164   width         HTMLDocument::Width     DontDelete|ReadOnly
00165   dir           HTMLDocument::Dir       DontDelete
00166 #IE extension
00167   frames        HTMLDocument::Frames        DontDelete|ReadOnly
00168 #potentially obsolete array properties
00169 # layers
00170 # plugins
00171 # tags
00172 #potentially obsolete properties
00173 # embeds
00174 # ids
00175 @end
00176 */
00177 
00178 /* Helper function object for determining the number
00179  * of occurrences of xxxx as in document.xxxx.
00180  * The order of the TagLength array is the order of preference.
00181  */
00182 class NamedTagLengthDeterminer {
00183 public:
00184   struct TagLength {
00185     NodeImpl::Id id; unsigned long length; NodeImpl *last;
00186   };
00187   NamedTagLengthDeterminer(const DOMString& n, TagLength *t, int l)
00188     : name(n), tags(t), nrTags(l) {}
00189   void operator () (NodeImpl *start);
00190 private:
00191   const DOMString& name;
00192   TagLength *tags;
00193   int nrTags;
00194 };
00195 
00196 void NamedTagLengthDeterminer::operator () (NodeImpl *start) {
00197   for(NodeImpl *n = start->firstChild(); n != 0; n = n->nextSibling())
00198     if ( n->nodeType() == Node::ELEMENT_NODE ) {
00199       for (int i = 0; i < nrTags; i++)
00200         if (n->id() == tags[i].id &&
00201             static_cast<ElementImpl *>(n)->getAttribute(ATTR_NAME) == name) {
00202           tags[i].length++;
00203           tags[i].last = n;   // cache this NodeImpl*
00204           nrTags = i+1;       // forget about Tags with lower preference
00205           break;
00206         }
00207       (*this)(n);
00208     }
00209 }
00210 
00211 KJS::HTMLDocument::HTMLDocument(ExecState *exec, const DOM::HTMLDocument& d)
00212   /*TODO pass HTMLDocumentProto::self(exec), but it needs to access DOMDocumentProto...*/
00213   : DOMDocument(exec, d) { }
00214 
00215 bool KJS::HTMLDocument::hasProperty(ExecState *exec, const Identifier &p) const
00216 {
00217 #ifdef KJS_VERBOSE
00218   //kdDebug(6070) << "KJS::HTMLDocument::hasProperty " << p.qstring() << endl;
00219 #endif
00220   DOM::HTMLDocument doc = static_cast<DOM::HTMLDocument>(node);
00221   KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
00222   Window* win = view && view->part() ? Window::retrieveWindow(view->part()) : 0L;
00223   if ( !win || !win->isSafeScript(exec) )
00224     return false;
00225 
00226   // Keep in sync with tryGet
00227   NamedTagLengthDeterminer::TagLength tags[3] = {
00228     {ID_IMG, 0, 0L}, {ID_FORM, 0, 0L}, {ID_APPLET, 0, 0L}
00229   };
00230   NamedTagLengthDeterminer(p.string(), tags, 3)(doc.handle());
00231   for (int i = 0; i < 3; i++)
00232     if (tags[i].length > 0)
00233         return true;
00234 
00235   if ( view && view->part() )
00236   {
00237     KHTMLPart *kp = view->part()->findFrame( p.qstring() );
00238     if (kp)
00239       return true;
00240   }
00241 
00242   return DOMDocument::hasProperty(exec, p);
00243 }
00244 
00245 Value KJS::HTMLDocument::tryGet(ExecState *exec, const Identifier &propertyName) const
00246 {
00247 #ifdef KJS_VERBOSE
00248   kdDebug(6070) << "KJS::HTMLDocument::tryGet " << propertyName.qstring() << endl;
00249 #endif
00250 
00251   DOM::HTMLDocument doc = static_cast<DOM::HTMLDocument>(node);
00252   KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
00253 
00254   Window* win = view && view->part() ? Window::retrieveWindow(view->part()) : 0L;
00255   if ( !win || !win->isSafeScript(exec) )
00256     return Undefined();
00257 
00258   // Check for images with name==propertyName, return item or list if found
00259   // We don't use the images collection because it looks for id=p and name=p, we only want name=p
00260   // Check for forms with name==propertyName, return item or list if found
00261   // Note that document.myform should only look at forms
00262   // Check for applets with name==propertyName, return item or list if found
00263 
00264   NamedTagLengthDeterminer::TagLength tags[3] = {
00265     {ID_IMG, 0, 0L}, {ID_FORM, 0, 0L}, {ID_APPLET, 0, 0L}
00266   };
00267   NamedTagLengthDeterminer(propertyName.string(), tags, 3)(doc.handle());
00268   for (int i = 0; i < 3; i++)
00269     if (tags[i].length > 0) {
00270       if (tags[i].length == 1)
00271         return getDOMNode(exec, tags[i].last);
00272       // Get all the items with the same name
00273       return getDOMNodeList(exec, DOM::NodeList(new DOM::NamedTagNodeListImpl(doc.handle(), tags[i].id, propertyName.string())));
00274     }
00275 
00276   // Check for frames/iframes with name==propertyName
00277   if ( view && view->part() )
00278   {
00279     // ###### TODO return a collection in case several frames have the same name
00280     // (IE does that). Hard to do with findFrame :}
00281     KHTMLPart *kp = view->part()->findFrame( propertyName.qstring() );
00282     if (kp)
00283       return Window::retrieve(kp);
00284   }
00285 
00286   const HashEntry* entry = Lookup::findEntry(&HTMLDocumentTable, propertyName);
00287   if (entry) {
00288     switch (entry->value) {
00289     case Title:
00290       return String(doc.title());
00291     case Referrer:
00292       return String(doc.referrer()); // not getString - DOMTS HTMLDocument02.html
00293     case Domain:
00294       return String(doc.domain());
00295     case URL:
00296       return getString(doc.URL());
00297     case Body:
00298       return getDOMNode(exec,doc.body());
00299     case Location:
00300       if (win)
00301         return Value(win->location());
00302       else
00303         return Undefined();
00304     case Cookie:
00305       return String(doc.cookie());
00306     case Images:
00307       return getHTMLCollection(exec,doc.images());
00308     case Applets:
00309       return getHTMLCollection(exec,doc.applets());
00310     case Links:
00311       return getHTMLCollection(exec,doc.links());
00312     case Forms:
00313       return getHTMLCollection(exec,doc.forms());
00314     case Anchors:
00315       return getHTMLCollection(exec,doc.anchors());
00316     case Scripts: // TODO (IE-specific)
00317     {
00318       // Disable document.scripts unless we try to be IE-compatible
00319       // Especially since it's not implemented, so
00320       // if (document.scripts) shouldn't return true.
00321       if ( exec->interpreter()->compatMode() != Interpreter::IECompat )
00322         return Undefined();
00323       // To be implemented. Meanwhile, return an object with a length property set to 0
00324       // This gets some code going on IE-specific pages.
00325       // The script object isn't really simple to implement though
00326       // (http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/script.asp)
00327       kdDebug(6070) << "WARNING: KJS::HTMLDocument document.scripts called - not implemented" << endl;
00328       Object obj( new ObjectImp() );
00329       obj.put( exec, lengthPropertyName, Number(0) );
00330       return obj;
00331     }
00332     case All:
00333       // Disable document.all when we try to be Netscape-compatible
00334       if ( exec->interpreter()->compatMode() == Interpreter::NetscapeCompat )
00335         return Undefined();
00336       return getHTMLCollection(exec,doc.all());
00337     case Clear:
00338     case Open:
00339     case Close:
00340     case Write:
00341     case WriteLn:
00342     case GetElementsByName:
00343     case GetSelection:
00344     case CaptureEvents:
00345     case ReleaseEvents:
00346       return lookupOrCreateFunction<HTMLDocFunction>( exec, propertyName, this, entry->value, entry->params, entry->attr );
00347     }
00348   }
00349   // Look for overrides
00350   ValueImp * val = ObjectImp::getDirect(propertyName);
00351   if (val)
00352     return Value(val);
00353 
00354   DOM::HTMLBodyElement body = doc.body();
00355   if (entry) {
00356     switch (entry->value) {
00357     case BgColor:
00358       return String(body.bgColor());
00359     case FgColor:
00360       return String(body.text());
00361     case AlinkColor:
00362       return String(body.aLink());
00363     case LinkColor:
00364       return String(body.link());
00365     case VlinkColor:
00366       return String(body.vLink());
00367     case LastModified:
00368       return String(doc.lastModified());
00369     case Height: // NS-only, not available in IE
00370       return Number(view ? view->contentsHeight() : 0);
00371     case Width: // NS-only, not available in IE
00372       return Number(view ? view->contentsWidth() : 0);
00373     case Dir:
00374       return String(body.dir());
00375     case Frames:
00376       if ( win )
00377         return Value(win->frames(exec));
00378       else
00379         return Undefined();
00380     }
00381   }
00382   if (DOMDocument::hasProperty(exec, propertyName))
00383     return DOMDocument::tryGet(exec, propertyName);
00384 
00385   // allow shortcuts like 'document.Applet1' instead of document.applets.Applet1
00386   if (doc.isHTMLDocument()) { // might be XML
00387     DOM::HTMLCollection coll = doc.applets();
00388     DOM::HTMLElement element = coll.namedItem(propertyName.string());
00389     if (!element.isNull()) {
00390       return getDOMNode(exec,element);
00391     }
00392   }
00393 #ifdef KJS_VERBOSE
00394   kdDebug(6070) << "KJS::HTMLDocument::tryGet " << propertyName.qstring() << " not found" << endl;
00395 #endif
00396   return Undefined();
00397 }
00398 
00399 void KJS::HTMLDocument::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
00400 {
00401 #ifdef KJS_VERBOSE
00402   kdDebug(6070) << "KJS::HTMLDocument::tryPut " << propertyName.qstring() << endl;
00403 #endif
00404   KHTMLView *view = static_cast<DOM::DocumentImpl*>(node.handle())->view();
00405 
00406   Window* win = view && view->part() ? Window::retrieveWindow(view->part()) : 0L;
00407   if ( !win || !win->isSafeScript(exec) )
00408     return;
00409 
00410   DOMObjectLookupPut<HTMLDocument, DOMDocument>( exec, propertyName, value, attr, &HTMLDocumentTable, this );
00411 }
00412 
00413 void KJS::HTMLDocument::putValueProperty(ExecState *exec, int token, const Value& value, int /*attr*/)
00414 {
00415   DOM::HTMLDocument doc = static_cast<DOM::HTMLDocument>(node);
00416 
00417   DOM::HTMLBodyElement body = doc.body();
00418   DOM::DOMString val = value.toString(exec).string();
00419 
00420   switch (token) {
00421   case Title:
00422     if (doc.title() != val) doc.setTitle(val);
00423     break;
00424   case Body: {
00425     DOMNode *node = new DOMNode(exec, KJS::toNode(value));
00426     // This is required to avoid leaking the node.
00427     Value nodeValue(node);
00428     doc.setBody(node->toNode());
00429     break;
00430   }
00431   case Domain: { // not part of the DOM
00432     DOM::HTMLDocumentImpl* docimpl = static_cast<DOM::HTMLDocumentImpl*>(doc.handle());
00433     if (docimpl)
00434       docimpl->setDomain(val);
00435     break;
00436   }
00437   case Cookie:
00438     doc.setCookie(val);
00439     break;
00440   case Location:
00441   {
00442     KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
00443     if ( view )
00444       Window::retrieveWindow(view->part())->goURL(exec, value.toString(exec).qstring(), false /*don't lock history*/);
00445     break;
00446   }
00447   case BgColor:
00448     if (body.bgColor() != val) body.setBgColor(val);
00449     break;
00450   case FgColor:
00451     if (body.text() != val) body.setText(val);
00452     break;
00453   case AlinkColor:
00454     if (body.aLink() != val) body.setALink(val);
00455     break;
00456   case LinkColor:
00457     if (body.link() != val) body.setLink(val);
00458     break;
00459   case VlinkColor:
00460     if (body.vLink() != val) body.setVLink(val);
00461     break;
00462   case Dir:
00463     body.setDir(val);
00464     break;
00465   default:
00466     kdDebug(6070) << "WARNING: HTMLDocument::putValueProperty unhandled token " << token << endl;
00467   }
00468 }
00469 
00470 // -------------------------------------------------------------------------
00471 
00472 const ClassInfo KJS::HTMLElement::info = { "HTMLElement", &DOMElement::info, &HTMLElementTable, 0 };
00473 const ClassInfo KJS::HTMLElement::html_info = { "HTMLHtmlElement", &KJS::HTMLElement::info, &HTMLHtmlElementTable, 0 };
00474 const ClassInfo KJS::HTMLElement::head_info = { "HTMLHeadElement", &KJS::HTMLElement::info, &HTMLHeadElementTable, 0 };
00475 const ClassInfo KJS::HTMLElement::link_info = { "HTMLLinkElement", &KJS::HTMLElement::info, &HTMLLinkElementTable, 0 };
00476 const ClassInfo KJS::HTMLElement::title_info = { "HTMLTitleElement", &KJS::HTMLElement::info, &HTMLTitleElementTable, 0 };
00477 const ClassInfo KJS::HTMLElement::meta_info = { "HTMLMetaElement", &KJS::HTMLElement::info, &HTMLMetaElementTable, 0 };
00478 const ClassInfo KJS::HTMLElement::base_info = { "HTMLBaseElement", &KJS::HTMLElement::info, &HTMLBaseElementTable, 0 };
00479 const ClassInfo KJS::HTMLElement::isIndex_info = { "HTMLIsIndexElement", &KJS::HTMLElement::info, &HTMLIsIndexElementTable, 0 };
00480 const ClassInfo KJS::HTMLElement::style_info = { "HTMLStyleElement", &KJS::HTMLElement::info, &HTMLStyleElementTable, 0 };
00481 const ClassInfo KJS::HTMLElement::body_info = { "HTMLBodyElement", &KJS::HTMLElement::info, &HTMLBodyElementTable, 0 };
00482 const ClassInfo KJS::HTMLElement::form_info = { "HTMLFormElement", &KJS::HTMLElement::info, &HTMLFormElementTable, 0 };
00483 const ClassInfo KJS::HTMLElement::select_info = { "HTMLSelectElement", &KJS::HTMLElement::info, &HTMLSelectElementTable, 0 };
00484 const ClassInfo KJS::HTMLElement::optGroup_info = { "HTMLOptGroupElement", &KJS::HTMLElement::info, &HTMLOptGroupElementTable, 0 };
00485 const ClassInfo KJS::HTMLElement::option_info = { "HTMLOptionElement", &KJS::HTMLElement::info, &HTMLOptionElementTable, 0 };
00486 const ClassInfo KJS::HTMLElement::input_info = { "HTMLInputElement", &KJS::HTMLElement::info, &HTMLInputElementTable, 0 };
00487 const ClassInfo KJS::HTMLElement::textArea_info = { "HTMLTextAreaElement", &KJS::HTMLElement::info, &HTMLTextAreaElementTable, 0 };
00488 const ClassInfo KJS::HTMLElement::button_info = { "HTMLButtonElement", &KJS::HTMLElement::info, &HTMLButtonElementTable, 0 };
00489 const ClassInfo KJS::HTMLElement::label_info = { "HTMLLabelElement", &KJS::HTMLElement::info, &HTMLLabelElementTable, 0 };
00490 const ClassInfo KJS::HTMLElement::fieldSet_info = { "HTMLFieldSetElement", &KJS::HTMLElement::info, &HTMLFieldSetElementTable, 0 };
00491 const ClassInfo KJS::HTMLElement::legend_info = { "HTMLLegendElement", &KJS::HTMLElement::info, &HTMLLegendElementTable, 0 };
00492 const ClassInfo KJS::HTMLElement::ul_info = { "HTMLUListElement", &KJS::HTMLElement::info, &HTMLUListElementTable, 0 };
00493 const ClassInfo KJS::HTMLElement::ol_info = { "HTMLOListElement", &KJS::HTMLElement::info, &HTMLOListElementTable, 0 };
00494 const ClassInfo KJS::HTMLElement::dl_info = { "HTMLDListElement", &KJS::HTMLElement::info, &HTMLDListElementTable, 0 };
00495 const ClassInfo KJS::HTMLElement::dir_info = { "HTMLDirectoryElement", &KJS::HTMLElement::info, &HTMLDirectoryElementTable, 0 };
00496 const ClassInfo KJS::HTMLElement::menu_info = { "HTMLMenuElement", &KJS::HTMLElement::info, &HTMLMenuElementTable, 0 };
00497 const ClassInfo KJS::HTMLElement::li_info = { "HTMLLIElement", &KJS::HTMLElement::info, &HTMLLIElementTable, 0 };
00498 const ClassInfo KJS::HTMLElement::div_info = { "HTMLDivElement", &KJS::HTMLElement::info, &HTMLDivElementTable, 0 };
00499 const ClassInfo KJS::HTMLElement::p_info = { "HTMLParagraphElement", &KJS::HTMLElement::info, &HTMLParagraphElementTable, 0 };
00500 const ClassInfo KJS::HTMLElement::heading_info = { "HTMLHeadingElement", &KJS::HTMLElement::info, &HTMLHeadingElementTable, 0 };
00501 const ClassInfo KJS::HTMLElement::blockQuote_info = { "HTMLBlockQuoteElement", &KJS::HTMLElement::info, &HTMLBlockQuoteElementTable, 0 };
00502 const ClassInfo KJS::HTMLElement::q_info = { "HTMLQuoteElement", &KJS::HTMLElement::info, &HTMLQuoteElementTable, 0 };
00503 const ClassInfo KJS::HTMLElement::pre_info = { "HTMLPreElement", &KJS::HTMLElement::info, &HTMLPreElementTable, 0 };
00504 const ClassInfo KJS::HTMLElement::br_info = { "HTMLBRElement", &KJS::HTMLElement::info, &HTMLBRElementTable, 0 };
00505 const ClassInfo KJS::HTMLElement::baseFont_info = { "HTMLBaseFontElement", &KJS::HTMLElement::info, &HTMLBaseFontElementTable, 0 };
00506 const ClassInfo KJS::HTMLElement::font_info = { "HTMLFontElement", &KJS::HTMLElement::info, &HTMLFontElementTable, 0 };
00507 const ClassInfo KJS::HTMLElement::hr_info = { "HTMLHRElement", &KJS::HTMLElement::info, &HTMLHRElementTable, 0 };
00508 const ClassInfo KJS::HTMLElement::mod_info = { "HTMLModElement", &KJS::HTMLElement::info, &HTMLModElementTable, 0 };
00509 const ClassInfo KJS::HTMLElement::a_info = { "HTMLAnchorElement", &KJS::HTMLElement::info, &HTMLAnchorElementTable, 0 };
00510 const ClassInfo KJS::HTMLElement::img_info = { "HTMLImageElement", &KJS::HTMLElement::info, &HTMLImageElementTable, 0 };
00511 const ClassInfo KJS::HTMLElement::object_info = { "HTMLObjectElement", &KJS::HTMLElement::info, &HTMLObjectElementTable, 0 };
00512 const ClassInfo KJS::HTMLElement::param_info = { "HTMLParamElement", &KJS::HTMLElement::info, &HTMLParamElementTable, 0 };
00513 const ClassInfo KJS::HTMLElement::applet_info = { "HTMLAppletElement", &KJS::HTMLElement::info, &HTMLAppletElementTable, 0 };
00514 const ClassInfo KJS::HTMLElement::map_info = { "HTMLMapElement", &KJS::HTMLElement::info, &HTMLMapElementTable, 0 };
00515 const ClassInfo KJS::HTMLElement::area_info = { "HTMLAreaElement", &KJS::HTMLElement::info, &HTMLAreaElementTable, 0 };
00516 const ClassInfo KJS::HTMLElement::script_info = { "HTMLScriptElement", &KJS::HTMLElement::info, &HTMLScriptElementTable, 0 };
00517 const ClassInfo KJS::HTMLElement::table_info = { "HTMLTableElement", &KJS::HTMLElement::info, &HTMLTableElementTable, 0 };
00518 const ClassInfo KJS::HTMLElement::caption_info = { "HTMLTableCaptionElement", &KJS::HTMLElement::info, &HTMLTableCaptionElementTable, 0 };
00519 const ClassInfo KJS::HTMLElement::col_info = { "HTMLTableColElement", &KJS::HTMLElement::info, &HTMLTableColElementTable, 0 };
00520 const ClassInfo KJS::HTMLElement::tablesection_info = { "HTMLTableSectionElement", &KJS::HTMLElement::info, &HTMLTableSectionElementTable, 0 };
00521 const ClassInfo KJS::HTMLElement::tr_info = { "HTMLTableRowElement", &KJS::HTMLElement::info, &HTMLTableRowElementTable, 0 };
00522 const ClassInfo KJS::HTMLElement::tablecell_info = { "HTMLTableCellElement", &KJS::HTMLElement::info, &HTMLTableCellElementTable, 0 };
00523 const ClassInfo KJS::HTMLElement::frameSet_info = { "HTMLFrameSetElement", &KJS::HTMLElement::info, &HTMLFrameSetElementTable, 0 };
00524 const ClassInfo KJS::HTMLElement::frame_info = { "HTMLFrameElement", &KJS::HTMLElement::info, &HTMLFrameElementTable, 0 };
00525 const ClassInfo KJS::HTMLElement::iFrame_info = { "HTMLIFrameElement", &KJS::HTMLElement::info, &HTMLIFrameElementTable, 0 };
00526 
00527 const ClassInfo* KJS::HTMLElement::classInfo() const
00528 {
00529   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
00530   switch (element.elementId()) {
00531   case ID_HTML:
00532     return &html_info;
00533   case ID_HEAD:
00534     return &head_info;
00535   case ID_LINK:
00536     return &link_info;
00537   case ID_TITLE:
00538     return &title_info;
00539   case ID_META:
00540     return &meta_info;
00541   case ID_BASE:
00542     return &base_info;
00543   case ID_ISINDEX:
00544     return &isIndex_info;
00545   case ID_STYLE:
00546     return &style_info;
00547   case ID_BODY:
00548     return &body_info;
00549   case ID_FORM:
00550     return &form_info;
00551   case ID_SELECT:
00552     return &select_info;
00553   case ID_OPTGROUP:
00554     return &optGroup_info;
00555   case ID_OPTION:
00556     return &option_info;
00557   case ID_INPUT:
00558     return &input_info;
00559   case ID_TEXTAREA:
00560     return &textArea_info;
00561   case ID_BUTTON:
00562     return &button_info;
00563   case ID_LABEL:
00564     return &label_info;
00565   case ID_FIELDSET:
00566     return &fieldSet_info;
00567   case ID_LEGEND:
00568     return &legend_info;
00569   case ID_UL:
00570     return &ul_info;
00571   case ID_OL:
00572     return &ol_info;
00573   case ID_DL:
00574     return &dl_info;
00575   case ID_DIR:
00576     return &dir_info;
00577   case ID_MENU:
00578     return &menu_info;
00579   case ID_LI:
00580     return &li_info;
00581   case ID_DIV:
00582     return &div_info;
00583   case ID_P:
00584     return &p_info;
00585   case ID_H1:
00586   case ID_H2:
00587   case ID_H3:
00588   case ID_H4:
00589   case ID_H5:
00590   case ID_H6:
00591     return &heading_info;
00592   case ID_BLOCKQUOTE:
00593     return &blockQuote_info;
00594   case ID_Q:
00595     return &q_info;
00596   case ID_PRE:
00597     return &pre_info;
00598   case ID_BR:
00599     return &br_info;
00600   case ID_BASEFONT:
00601     return &baseFont_info;
00602   case ID_FONT:
00603     return &font_info;
00604   case ID_HR:
00605     return &hr_info;
00606   case ID_INS:
00607   case ID_DEL:
00608     return &mod_info;
00609   case ID_A:
00610     return &a_info;
00611   case ID_IMG:
00612     return &img_info;
00613   case ID_OBJECT:
00614     return &object_info;
00615   case ID_PARAM:
00616     return &param_info;
00617   case ID_APPLET:
00618     return &applet_info;
00619   case ID_MAP:
00620     return &map_info;
00621   case ID_AREA:
00622     return &area_info;
00623   case ID_SCRIPT:
00624     return &script_info;
00625   case ID_TABLE:
00626     return &table_info;
00627   case ID_CAPTION:
00628     return &caption_info;
00629   case ID_COL:
00630   case ID_COLGROUP:
00631     return &col_info;
00632   case ID_THEAD:
00633     return &tablesection_info;
00634   case ID_TBODY:
00635     return &tablesection_info;
00636   case ID_TFOOT:
00637     return &tablesection_info;
00638   case ID_TR:
00639     return &tr_info;
00640   case ID_TH:
00641     return &tablecell_info;
00642   case ID_TD:
00643     return &tablecell_info;
00644   case ID_FRAMESET:
00645     return &frameSet_info;
00646   case ID_FRAME:
00647     return &frame_info;
00648   case ID_IFRAME:
00649     return &iFrame_info;
00650   default:
00651     return &info;
00652   }
00653 }
00654 /*
00655 @begin HTMLElementTable 8
00656   id        KJS::HTMLElement::ElementId DontDelete
00657   title     KJS::HTMLElement::ElementTitle  DontDelete
00658   lang      KJS::HTMLElement::ElementLang   DontDelete
00659   dir       KJS::HTMLElement::ElementDir    DontDelete
00660 ### isn't this "class" in the HTML spec?
00661   className KJS::HTMLElement::ElementClassName DontDelete
00662   innerHTML KJS::HTMLElement::ElementInnerHTML DontDelete
00663   innerText KJS::HTMLElement::ElementInnerText DontDelete
00664   document  KJS::HTMLElement::ElementDocument  DontDelete|ReadOnly
00665   scrollHeight  KJS::HTMLElement::ElementScrollHeight   DontDelete|ReadOnly
00666   scrollWidth   KJS::HTMLElement::ElementScrollWidth    DontDelete|ReadOnly
00667 # IE extension
00668   children  KJS::HTMLElement::ElementChildren  DontDelete|ReadOnly
00669   all           KJS::HTMLElement::ElementAll       DontDelete|ReadOnly
00670 @end
00671 @begin HTMLHtmlElementTable 1
00672   version   KJS::HTMLElement::HtmlVersion   DontDelete
00673 @end
00674 @begin HTMLHeadElementTable 1
00675   profile   KJS::HTMLElement::HeadProfile   DontDelete
00676 @end
00677 @begin HTMLLinkElementTable 11
00678   disabled  KJS::HTMLElement::LinkDisabled  DontDelete
00679   charset   KJS::HTMLElement::LinkCharset   DontDelete
00680   href      KJS::HTMLElement::LinkHref  DontDelete
00681   hreflang  KJS::HTMLElement::LinkHrefLang  DontDelete
00682   media     KJS::HTMLElement::LinkMedia DontDelete
00683   rel       KJS::HTMLElement::LinkRel       DontDelete
00684   rev       KJS::HTMLElement::LinkRev   DontDelete
00685   target    KJS::HTMLElement::LinkTarget    DontDelete
00686   type      KJS::HTMLElement::LinkType  DontDelete
00687   sheet     KJS::HTMLElement::LinkSheet DontDelete|ReadOnly
00688 @end
00689 @begin HTMLTitleElementTable 1
00690   text      KJS::HTMLElement::TitleText DontDelete
00691 @end
00692 @begin HTMLMetaElementTable 4
00693   content   KJS::HTMLElement::MetaContent   DontDelete
00694   httpEquiv KJS::HTMLElement::MetaHttpEquiv DontDelete
00695   name      KJS::HTMLElement::MetaName  DontDelete
00696   scheme    KJS::HTMLElement::MetaScheme    DontDelete
00697 @end
00698 @begin HTMLBaseElementTable 2
00699   href      KJS::HTMLElement::BaseHref  DontDelete
00700   target    KJS::HTMLElement::BaseTarget    DontDelete
00701 @end
00702 @begin HTMLIsIndexElementTable 2
00703   form      KJS::HTMLElement::IsIndexForm   DontDelete|ReadOnly
00704   prompt    KJS::HTMLElement::IsIndexPrompt DontDelete
00705 @end
00706 @begin HTMLStyleElementTable 4
00707   disabled  KJS::HTMLElement::StyleDisabled DontDelete
00708   media     KJS::HTMLElement::StyleMedia    DontDelete
00709   type      KJS::HTMLElement::StyleType DontDelete
00710   sheet     KJS::HTMLElement::StyleSheet    DontDelete|ReadOnly
00711 @end
00712 @begin HTMLBodyElementTable 8
00713   aLink     KJS::HTMLElement::BodyALink DontDelete
00714   background    KJS::HTMLElement::BodyBackground    DontDelete
00715   bgColor   KJS::HTMLElement::BodyBgColor   DontDelete
00716   link      KJS::HTMLElement::BodyLink  DontDelete
00717   text      KJS::HTMLElement::BodyText  DontDelete
00718   vLink     KJS::HTMLElement::BodyVLink DontDelete
00719 @end
00720 @begin HTMLFormElementTable 11
00721 # Also supported, by name/index
00722   elements  KJS::HTMLElement::FormElements  DontDelete|ReadOnly
00723   length    KJS::HTMLElement::FormLength    DontDelete|ReadOnly
00724   name      KJS::HTMLElement::FormName  DontDelete
00725   acceptCharset KJS::HTMLElement::FormAcceptCharset DontDelete
00726   action    KJS::HTMLElement::FormAction    DontDelete
00727   encoding  KJS::HTMLElement::FormEncType   DontDelete
00728   enctype   KJS::HTMLElement::FormEncType   DontDelete
00729   method    KJS::HTMLElement::FormMethod    DontDelete
00730   target    KJS::HTMLElement::FormTarget    DontDelete
00731   submit    KJS::HTMLElement::FormSubmit    DontDelete|Function 0
00732   reset     KJS::HTMLElement::FormReset DontDelete|Function 0
00733 @end
00734 @begin HTMLSelectElementTable 11
00735 # Also supported, by index
00736   type      KJS::HTMLElement::SelectType    DontDelete|ReadOnly
00737   selectedIndex KJS::HTMLElement::SelectSelectedIndex   DontDelete
00738   value     KJS::HTMLElement::SelectValue   DontDelete
00739   length    KJS::HTMLElement::SelectLength  DontDelete
00740   form      KJS::HTMLElement::SelectForm    DontDelete|ReadOnly
00741   options   KJS::HTMLElement::SelectOptions DontDelete|ReadOnly
00742   disabled  KJS::HTMLElement::SelectDisabled    DontDelete
00743   multiple  KJS::HTMLElement::SelectMultiple    DontDelete
00744   name      KJS::HTMLElement::SelectName    DontDelete
00745   size      KJS::HTMLElement::SelectSize    DontDelete
00746   tabIndex  KJS::HTMLElement::SelectTabIndex    DontDelete
00747   add       KJS::HTMLElement::SelectAdd DontDelete|Function 2
00748   remove    KJS::HTMLElement::SelectRemove  DontDelete|Function 1
00749   blur      KJS::HTMLElement::SelectBlur    DontDelete|Function 0
00750   focus     KJS::HTMLElement::SelectFocus   DontDelete|Function 0
00751 @end
00752 @begin HTMLOptGroupElementTable 2
00753   disabled  KJS::HTMLElement::OptGroupDisabled  DontDelete
00754   label     KJS::HTMLElement::OptGroupLabel     DontDelete
00755 @end
00756 @begin HTMLOptionElementTable 8
00757   form      KJS::HTMLElement::OptionForm        DontDelete|ReadOnly
00758   defaultSelected KJS::HTMLElement::OptionDefaultSelected   DontDelete
00759   text      KJS::HTMLElement::OptionText        DontDelete
00760   index     KJS::HTMLElement::OptionIndex       DontDelete|ReadOnly
00761   disabled  KJS::HTMLElement::OptionDisabled    DontDelete
00762   label     KJS::HTMLElement::OptionLabel       DontDelete
00763   selected  KJS::HTMLElement::OptionSelected    DontDelete
00764   value     KJS::HTMLElement::OptionValue       DontDelete
00765 @end
00766 @begin HTMLInputElementTable 24
00767   defaultValue  KJS::HTMLElement::InputDefaultValue DontDelete
00768   defaultChecked KJS::HTMLElement::InputDefaultChecked  DontDelete
00769   form      KJS::HTMLElement::InputForm     DontDelete|ReadOnly
00770   accept    KJS::HTMLElement::InputAccept       DontDelete
00771   accessKey KJS::HTMLElement::InputAccessKey    DontDelete
00772   align     KJS::HTMLElement::InputAlign        DontDelete
00773   alt       KJS::HTMLElement::InputAlt      DontDelete
00774   checked   KJS::HTMLElement::InputChecked      DontDelete
00775   status    KJS::HTMLElement::InputChecked      DontDelete
00776   disabled  KJS::HTMLElement::InputDisabled     DontDelete
00777   maxLength KJS::HTMLElement::InputMaxLength    DontDelete
00778   name      KJS::HTMLElement::InputName     DontDelete
00779   readOnly  KJS::HTMLElement::InputReadOnly     DontDelete
00780   size      KJS::HTMLElement::InputSize     DontDelete
00781   src       KJS::HTMLElement::InputSrc      DontDelete
00782   tabIndex  KJS::HTMLElement::InputTabIndex     DontDelete
00783   type      KJS::HTMLElement::InputType     DontDelete
00784   useMap    KJS::HTMLElement::InputUseMap       DontDelete
00785   value     KJS::HTMLElement::InputValue        DontDelete
00786   blur      KJS::HTMLElement::InputBlur     DontDelete|Function 0
00787   focus     KJS::HTMLElement::InputFocus        DontDelete|Function 0
00788   select    KJS::HTMLElement::InputSelect       DontDelete|Function 0
00789   click     KJS::HTMLElement::InputClick        DontDelete|Function 0
00790 @end
00791 @begin HTMLTextAreaElementTable 13
00792   defaultValue  KJS::HTMLElement::TextAreaDefaultValue  DontDelete
00793   form      KJS::HTMLElement::TextAreaForm      DontDelete|ReadOnly
00794   accessKey KJS::HTMLElement::TextAreaAccessKey DontDelete
00795   cols      KJS::HTMLElement::TextAreaCols      DontDelete
00796   disabled  KJS::HTMLElement::TextAreaDisabled  DontDelete
00797   name      KJS::HTMLElement::TextAreaName      DontDelete
00798   readOnly  KJS::HTMLElement::TextAreaReadOnly  DontDelete
00799   rows      KJS::HTMLElement::TextAreaRows      DontDelete
00800   tabIndex  KJS::HTMLElement::TextAreaTabIndex  DontDelete
00801   type      KJS::HTMLElement::TextAreaType      DontDelete|ReadOnly
00802   value     KJS::HTMLElement::TextAreaValue     DontDelete
00803   blur      KJS::HTMLElement::TextAreaBlur      DontDelete|Function 0
00804   focus     KJS::HTMLElement::TextAreaFocus     DontDelete|Function 0
00805   select    KJS::HTMLElement::TextAreaSelect    DontDelete|Function 0
00806 @end
00807 @begin HTMLButtonElementTable 7
00808   form      KJS::HTMLElement::ButtonForm        DontDelete|ReadOnly
00809   accessKey KJS::HTMLElement::ButtonAccessKey   DontDelete
00810   disabled  KJS::HTMLElement::ButtonDisabled    DontDelete
00811   name      KJS::HTMLElement::ButtonName        DontDelete
00812   tabIndex  KJS::HTMLElement::ButtonTabIndex    DontDelete
00813   type      KJS::HTMLElement::ButtonType        DontDelete|ReadOnly
00814   value     KJS::HTMLElement::ButtonValue       DontDelete
00815 @end
00816 @begin HTMLLabelElementTable 3
00817   form      KJS::HTMLElement::LabelForm     DontDelete|ReadOnly
00818   accessKey KJS::HTMLElement::LabelAccessKey    DontDelete
00819   htmlFor   KJS::HTMLElement::LabelHtmlFor      DontDelete
00820 @end
00821 @begin HTMLFieldSetElementTable 1
00822   form      KJS::HTMLElement::FieldSetForm      DontDelete|ReadOnly
00823 @end
00824 @begin HTMLLegendElementTable 3
00825   form      KJS::HTMLElement::LegendForm        DontDelete|ReadOnly
00826   accessKey KJS::HTMLElement::LegendAccessKey   DontDelete
00827   align     KJS::HTMLElement::LegendAlign       DontDelete
00828 @end
00829 @begin HTMLUListElementTable 2
00830   compact   KJS::HTMLElement::UListCompact      DontDelete
00831   type      KJS::HTMLElement::UListType     DontDelete
00832 @end
00833 @begin HTMLOListElementTable 3
00834   compact   KJS::HTMLElement::OListCompact      DontDelete
00835   start     KJS::HTMLElement::OListStart        DontDelete
00836   type      KJS::HTMLElement::OListType     DontDelete
00837 @end
00838 @begin HTMLDListElementTable 1
00839   compact   KJS::HTMLElement::DListCompact      DontDelete
00840 @end
00841 @begin HTMLDirectoryElementTable 1
00842   compact   KJS::HTMLElement::DirectoryCompact  DontDelete
00843 @end
00844 @begin HTMLMenuElementTable 1
00845   compact   KJS::HTMLElement::MenuCompact       DontDelete
00846 @end
00847 @begin HTMLLIElementTable 2
00848   type      KJS::HTMLElement::LIType        DontDelete
00849   value     KJS::HTMLElement::LIValue       DontDelete
00850 @end
00851 @begin HTMLDivElementTable 1
00852   align     KJS::HTMLElement::DivAlign      DontDelete
00853 @end
00854 @begin HTMLParagraphElementTable 1
00855   align     KJS::HTMLElement::ParagraphAlign    DontDelete
00856 @end
00857 @begin HTMLHeadingElementTable 1
00858   align     KJS::HTMLElement::HeadingAlign      DontDelete
00859 @end
00860 @begin HTMLBlockQuoteElementTable 1
00861   cite      KJS::HTMLElement::BlockQuoteCite    DontDelete
00862 @end
00863 @begin HTMLQuoteElementTable 1
00864   cite      KJS::HTMLElement::QuoteCite     DontDelete
00865 @end
00866 @begin HTMLPreElementTable 1
00867   width     KJS::HTMLElement::PreWidth      DontDelete
00868 @end
00869 @begin HTMLBRElementTable 1
00870   clear     KJS::HTMLElement::BRClear       DontDelete
00871 @end
00872 @begin HTMLBaseFontElementTable 3
00873   color     KJS::HTMLElement::BaseFontColor     DontDelete
00874   face      KJS::HTMLElement::BaseFontFace      DontDelete
00875   size      KJS::HTMLElement::BaseFontSize      DontDelete
00876 @end
00877 @begin HTMLFontElementTable 3
00878   color     KJS::HTMLElement::FontColor     DontDelete
00879   face      KJS::HTMLElement::FontFace      DontDelete
00880   size      KJS::HTMLElement::FontSize      DontDelete
00881 @end
00882 @begin HTMLHRElementTable 4
00883   align     KJS::HTMLElement::HRAlign       DontDelete
00884   noShade   KJS::HTMLElement::HRNoShade     DontDelete
00885   size      KJS::HTMLElement::HRSize        DontDelete
00886   width     KJS::HTMLElement::HRWidth       DontDelete
00887 @end
00888 @begin HTMLModElementTable 2
00889   cite      KJS::HTMLElement::ModCite       DontDelete
00890   dateTime  KJS::HTMLElement::ModDateTime       DontDelete
00891 @end
00892 @begin HTMLAnchorElementTable 23
00893   accessKey KJS::HTMLElement::AnchorAccessKey   DontDelete
00894   charset   KJS::HTMLElement::AnchorCharset     DontDelete
00895   coords    KJS::HTMLElement::AnchorCoords      DontDelete
00896   href      KJS::HTMLElement::AnchorHref        DontDelete
00897   hreflang  KJS::HTMLElement::AnchorHrefLang    DontDelete
00898   hash      KJS::HTMLElement::AnchorHash        DontDelete|ReadOnly
00899   host      KJS::HTMLElement::AnchorHost        DontDelete|ReadOnly
00900   hostname  KJS::HTMLElement::AnchorHostname    DontDelete|ReadOnly
00901   name      KJS::HTMLElement::AnchorName        DontDelete
00902   pathname  KJS::HTMLElement::AnchorPathName    DontDelete|ReadOnly
00903   port      KJS::HTMLElement::AnchorPort        DontDelete|ReadOnly
00904   protocol  KJS::HTMLElement::AnchorProtocol    DontDelete|ReadOnly
00905   rel       KJS::HTMLElement::AnchorRel     DontDelete
00906   rev       KJS::HTMLElement::AnchorRev     DontDelete
00907   search    KJS::HTMLElement::AnchorSearch      DontDelete|ReadOnly
00908   shape     KJS::HTMLElement::AnchorShape       DontDelete
00909   tabIndex  KJS::HTMLElement::AnchorTabIndex    DontDelete
00910   target    KJS::HTMLElement::AnchorTarget      DontDelete
00911   text      KJS::HTMLElement::AnchorText        DontDelete|ReadOnly
00912   type      KJS::HTMLElement::AnchorType        DontDelete
00913   blur      KJS::HTMLElement::AnchorBlur        DontDelete|Function 0
00914   focus     KJS::HTMLElement::AnchorFocus       DontDelete|Function 0
00915 @end
00916 @begin HTMLImageElementTable 14
00917   name      KJS::HTMLElement::ImageName     DontDelete
00918   align     KJS::HTMLElement::ImageAlign        DontDelete
00919   alt       KJS::HTMLElement::ImageAlt      DontDelete
00920   border    KJS::HTMLElement::ImageBorder       DontDelete
00921   complete  KJS::HTMLElement::ImageComplete     DontDelete|ReadOnly
00922   height    KJS::HTMLElement::ImageHeight       DontDelete
00923   hspace    KJS::HTMLElement::ImageHspace       DontDelete
00924   isMap     KJS::HTMLElement::ImageIsMap        DontDelete
00925   longDesc  KJS::HTMLElement::ImageLongDesc     DontDelete
00926   src       KJS::HTMLElement::ImageSrc      DontDelete
00927   useMap    KJS::HTMLElement::ImageUseMap       DontDelete
00928   vspace    KJS::HTMLElement::ImageVspace       DontDelete
00929   width     KJS::HTMLElement::ImageWidth        DontDelete
00930   x         KJS::HTMLElement::ImageX        DontDelete|ReadOnly
00931   y         KJS::HTMLElement::ImageY        DontDelete|ReadOnly
00932 @end
00933 @begin HTMLObjectElementTable 20
00934   form        KJS::HTMLElement::ObjectForm        DontDelete|ReadOnly
00935   code        KJS::HTMLElement::ObjectCode        DontDelete
00936   align       KJS::HTMLElement::ObjectAlign       DontDelete
00937   archive     KJS::HTMLElement::ObjectArchive     DontDelete
00938   border      KJS::HTMLElement::ObjectBorder      DontDelete
00939   codeBase    KJS::HTMLElement::ObjectCodeBase    DontDelete
00940   codeType    KJS::HTMLElement::ObjectCodeType    DontDelete
00941   contentDocument KJS::HTMLElement::ObjectContentDocument DontDelete|ReadOnly
00942   data        KJS::HTMLElement::ObjectData        DontDelete
00943   declare     KJS::HTMLElement::ObjectDeclare     DontDelete
00944   height      KJS::HTMLElement::ObjectHeight      DontDelete
00945   hspace      KJS::HTMLElement::ObjectHspace      DontDelete
00946   name        KJS::HTMLElement::ObjectName        DontDelete
00947   standby     KJS::HTMLElement::ObjectStandby     DontDelete
00948   tabIndex    KJS::HTMLElement::ObjectTabIndex    DontDelete
00949   type        KJS::HTMLElement::ObjectType        DontDelete
00950   useMap      KJS::HTMLElement::ObjectUseMap      DontDelete
00951   vspace      KJS::HTMLElement::ObjectVspace      DontDelete
00952   width       KJS::HTMLElement::ObjectWidth       DontDelete
00953 @end
00954 @begin HTMLParamElementTable 4
00955   name      KJS::HTMLElement::ParamName     DontDelete
00956   type      KJS::HTMLElement::ParamType     DontDelete
00957   value     KJS::HTMLElement::ParamValue        DontDelete
00958   valueType KJS::HTMLElement::ParamValueType    DontDelete
00959 @end
00960 @begin HTMLAppletElementTable 11
00961   align     KJS::HTMLElement::AppletAlign       DontDelete
00962   alt       KJS::HTMLElement::AppletAlt     DontDelete
00963   archive   KJS::HTMLElement::AppletArchive     DontDelete
00964   code      KJS::HTMLElement::AppletCode        DontDelete
00965   codeBase  KJS::HTMLElement::AppletCodeBase    DontDelete
00966   height    KJS::HTMLElement::AppletHeight      DontDelete
00967   hspace    KJS::HTMLElement::AppletHspace      DontDelete
00968   name      KJS::HTMLElement::AppletName        DontDelete
00969   object    KJS::HTMLElement::AppletObject      DontDelete
00970   vspace    KJS::HTMLElement::AppletVspace      DontDelete
00971   width     KJS::HTMLElement::AppletWidth       DontDelete
00972 @end
00973 @begin HTMLMapElementTable 2
00974   areas     KJS::HTMLElement::MapAreas      DontDelete|ReadOnly
00975   name      KJS::HTMLElement::MapName       DontDelete
00976 @end
00977 @begin HTMLAreaElementTable 15
00978   accessKey KJS::HTMLElement::AreaAccessKey     DontDelete
00979   alt       KJS::HTMLElement::AreaAlt       DontDelete
00980   coords    KJS::HTMLElement::AreaCoords        DontDelete
00981   href      KJS::HTMLElement::AreaHref      DontDelete
00982   hash      KJS::HTMLElement::AreaHash      DontDelete|ReadOnly
00983   host      KJS::HTMLElement::AreaHost      DontDelete|ReadOnly
00984   hostname  KJS::HTMLElement::AreaHostName      DontDelete|ReadOnly
00985   pathname  KJS::HTMLElement::AreaPathName      DontDelete|ReadOnly
00986   port      KJS::HTMLElement::AreaPort      DontDelete|ReadOnly
00987   protocol  KJS::HTMLElement::AreaProtocol      DontDelete|ReadOnly
00988   search    KJS::HTMLElement::AreaSearch        DontDelete|ReadOnly
00989   noHref    KJS::HTMLElement::AreaNoHref        DontDelete
00990   shape     KJS::HTMLElement::AreaShape     DontDelete
00991   tabIndex  KJS::HTMLElement::AreaTabIndex      DontDelete
00992   target    KJS::HTMLElement::AreaTarget        DontDelete
00993 @end
00994 @begin HTMLScriptElementTable 7
00995   text      KJS::HTMLElement::ScriptText        DontDelete
00996   htmlFor   KJS::HTMLElement::ScriptHtmlFor     DontDelete
00997   event     KJS::HTMLElement::ScriptEvent       DontDelete
00998   charset   KJS::HTMLElement::ScriptCharset     DontDelete
00999   defer     KJS::HTMLElement::ScriptDefer       DontDelete
01000   src       KJS::HTMLElement::ScriptSrc     DontDelete
01001   type      KJS::HTMLElement::ScriptType        DontDelete
01002 @end
01003 @begin HTMLTableElementTable 23
01004   caption   KJS::HTMLElement::TableCaption      DontDelete
01005   tHead     KJS::HTMLElement::TableTHead        DontDelete
01006   tFoot     KJS::HTMLElement::TableTFoot        DontDelete
01007   rows      KJS::HTMLElement::TableRows     DontDelete|ReadOnly
01008   tBodies   KJS::HTMLElement::TableTBodies      DontDelete|ReadOnly
01009   align     KJS::HTMLElement::TableAlign        DontDelete
01010   bgColor   KJS::HTMLElement::TableBgColor      DontDelete
01011   border    KJS::HTMLElement::TableBorder       DontDelete
01012   cellPadding   KJS::HTMLElement::TableCellPadding  DontDelete
01013   cellSpacing   KJS::HTMLElement::TableCellSpacing  DontDelete
01014   frame     KJS::HTMLElement::TableFrame        DontDelete
01015   rules     KJS::HTMLElement::TableRules        DontDelete
01016   summary   KJS::HTMLElement::TableSummary      DontDelete
01017   width     KJS::HTMLElement::TableWidth        DontDelete
01018   createTHead   KJS::HTMLElement::TableCreateTHead  DontDelete|Function 0
01019   deleteTHead   KJS::HTMLElement::TableDeleteTHead  DontDelete|Function 0
01020   createTFoot   KJS::HTMLElement::TableCreateTFoot  DontDelete|Function 0
01021   deleteTFoot   KJS::HTMLElement::TableDeleteTFoot  DontDelete|Function 0
01022   createCaption KJS::HTMLElement::TableCreateCaption    DontDelete|Function 0
01023   deleteCaption KJS::HTMLElement::TableDeleteCaption    DontDelete|Function 0
01024   insertRow KJS::HTMLElement::TableInsertRow    DontDelete|Function 1
01025   deleteRow KJS::HTMLElement::TableDeleteRow    DontDelete|Function 1
01026 @end
01027 @begin HTMLTableCaptionElementTable 1
01028   align     KJS::HTMLElement::TableCaptionAlign DontDelete
01029 @end
01030 @begin HTMLTableColElementTable 7
01031   align     KJS::HTMLElement::TableColAlign     DontDelete
01032   ch        KJS::HTMLElement::TableColCh        DontDelete
01033   chOff     KJS::HTMLElement::TableColChOff     DontDelete
01034   span      KJS::HTMLElement::TableColSpan      DontDelete
01035   vAlign    KJS::HTMLElement::TableColVAlign    DontDelete
01036   width     KJS::HTMLElement::TableColWidth     DontDelete
01037 @end
01038 @begin HTMLTableSectionElementTable 7
01039   align     KJS::HTMLElement::TableSectionAlign     DontDelete
01040   ch        KJS::HTMLElement::TableSectionCh        DontDelete
01041   chOff     KJS::HTMLElement::TableSectionChOff     DontDelete
01042   vAlign    KJS::HTMLElement::TableSectionVAlign        DontDelete
01043   rows      KJS::HTMLElement::TableSectionRows      DontDelete|ReadOnly
01044   insertRow KJS::HTMLElement::TableSectionInsertRow     DontDelete|Function 1
01045   deleteRow KJS::HTMLElement::TableSectionDeleteRow     DontDelete|Function 1
01046 @end
01047 @begin HTMLTableRowElementTable 11
01048   rowIndex  KJS::HTMLElement::TableRowRowIndex      DontDelete|ReadOnly
01049   sectionRowIndex KJS::HTMLElement::TableRowSectionRowIndex DontDelete|ReadOnly
01050   cells     KJS::HTMLElement::TableRowCells         DontDelete|ReadOnly
01051   align     KJS::HTMLElement::TableRowAlign         DontDelete
01052   bgColor   KJS::HTMLElement::TableRowBgColor       DontDelete
01053   ch        KJS::HTMLElement::TableRowCh            DontDelete
01054   chOff     KJS::HTMLElement::TableRowChOff         DontDelete
01055   vAlign    KJS::HTMLElement::TableRowVAlign        DontDelete
01056   insertCell    KJS::HTMLElement::TableRowInsertCell        DontDelete|Function 1
01057   deleteCell    KJS::HTMLElement::TableRowDeleteCell        DontDelete|Function 1
01058 @end
01059 @begin HTMLTableCellElementTable 15
01060   cellIndex KJS::HTMLElement::TableCellCellIndex        DontDelete|ReadOnly
01061   abbr      KJS::HTMLElement::TableCellAbbr         DontDelete
01062   align     KJS::HTMLElement::TableCellAlign        DontDelete
01063   axis      KJS::HTMLElement::TableCellAxis         DontDelete
01064   bgColor   KJS::HTMLElement::TableCellBgColor      DontDelete
01065   ch        KJS::HTMLElement::TableCellCh           DontDelete
01066   chOff     KJS::HTMLElement::TableCellChOff        DontDelete
01067   colSpan   KJS::HTMLElement::TableCellColSpan      DontDelete
01068   headers   KJS::HTMLElement::TableCellHeaders      DontDelete
01069   height    KJS::HTMLElement::TableCellHeight       DontDelete
01070   noWrap    KJS::HTMLElement::TableCellNoWrap       DontDelete
01071   rowSpan   KJS::HTMLElement::TableCellRowSpan      DontDelete
01072   scope     KJS::HTMLElement::TableCellScope        DontDelete
01073   vAlign    KJS::HTMLElement::TableCellVAlign       DontDelete
01074   width     KJS::HTMLElement::TableCellWidth        DontDelete
01075 @end
01076 @begin HTMLFrameSetElementTable 2
01077   cols      KJS::HTMLElement::FrameSetCols          DontDelete
01078   rows      KJS::HTMLElement::FrameSetRows          DontDelete
01079 @end
01080 @begin HTMLFrameElementTable 9
01081   contentDocument KJS::HTMLElement::FrameContentDocument        DontDelete|ReadOnly
01082   frameBorder     KJS::HTMLElement::FrameFrameBorder        DontDelete
01083   longDesc    KJS::HTMLElement::FrameLongDesc       DontDelete
01084   marginHeight    KJS::HTMLElement::FrameMarginHeight       DontDelete
01085   marginWidth     KJS::HTMLElement::FrameMarginWidth        DontDelete
01086   name        KJS::HTMLElement::FrameName           DontDelete
01087   noResize    KJS::HTMLElement::FrameNoResize       DontDelete
01088   scrolling   KJS::HTMLElement::FrameScrolling      DontDelete
01089   src         KJS::HTMLElement::FrameSrc            DontDelete
01090   location    KJS::HTMLElement::FrameLocation       DontDelete
01091 @end
01092 @begin HTMLIFrameElementTable 12
01093   align       KJS::HTMLElement::IFrameAlign         DontDelete
01094   contentDocument KJS::HTMLElement::IFrameContentDocument       DontDelete|ReadOnly
01095   frameBorder     KJS::HTMLElement::IFrameFrameBorder       DontDelete
01096   height      KJS::HTMLElement::IFrameHeight        DontDelete
01097   longDesc    KJS::HTMLElement::IFrameLongDesc      DontDelete
01098   marginHeight    KJS::HTMLElement::IFrameMarginHeight      DontDelete
01099   marginWidth     KJS::HTMLElement::IFrameMarginWidth       DontDelete
01100   name        KJS::HTMLElement::IFrameName          DontDelete
01101   scrolling   KJS::HTMLElement::IFrameScrolling     DontDelete
01102   src         KJS::HTMLElement::IFrameSrc           DontDelete
01103   width       KJS::HTMLElement::IFrameWidth         DontDelete
01104 @end
01105 */
01106 
01107 class EmbedLiveConnect : public ObjectImp {
01108 public:
01109     EmbedLiveConnect(const DOM::HTMLElement& elm, UString n, KParts::LiveConnectExtension::Type t, int id)
01110         : element (elm), name(n), objtype(t), objid(id) {}
01111     ~EmbedLiveConnect() {
01112         DOM::HTMLObjectBaseElementImpl * elm = static_cast<DOM::HTMLObjectBaseElementImpl*>(element.handle());
01113         if (elm)
01114             elm->unregister(objid);
01115     }
01116     static Value getValue(const DOM::HTMLElement& elm, const QString & name,
01117                           const KParts::LiveConnectExtension::Type t,
01118                           const QString & value, int id)
01119     {
01120         switch(t) {
01121             case KParts::LiveConnectExtension::TypeBool: {
01122                 bool ok;
01123                 int i = value.toInt(&ok);
01124                 if (ok)
01125                     return Boolean(i);
01126                 return Boolean(!strcasecmp(value.latin1(), "true"));
01127             }
01128             case KParts::LiveConnectExtension::TypeFunction:
01129                 return Value(new EmbedLiveConnect(elm, name, t, id));
01130             case KParts::LiveConnectExtension::TypeNumber: {
01131                 bool ok;
01132                 int i = value.toInt(&ok);
01133                 if (ok)
01134                     return Number(i);
01135                 else
01136                     return Number(value.toDouble(&ok));
01137             }
01138             case KParts::LiveConnectExtension::TypeObject:
01139                 return Value(new EmbedLiveConnect(elm, name, t, id));
01140             case KParts::LiveConnectExtension::TypeString:
01141                 return String(value);
01142             case KParts::LiveConnectExtension::TypeVoid:
01143             default:
01144                 return Undefined();
01145         }
01146     }
01147     virtual Value get(ExecState *, const Identifier & prop) const {
01148         DOM::HTMLObjectBaseElementImpl * elm = static_cast<DOM::HTMLObjectBaseElementImpl*>(element.handle());
01149         KParts::LiveConnectExtension::Type rettype;
01150         QString retvalue;
01151         unsigned long retobjid;
01152         if (elm && elm->get(objid, prop.qstring(), rettype, retobjid, retvalue))
01153             return getValue(element, prop.qstring(), rettype, retvalue, retobjid);
01154         return Undefined();
01155     }
01156     virtual void put(ExecState * exec, const Identifier &prop, const Value & value, int=None) {
01157         DOM::HTMLObjectBaseElementImpl * elm = static_cast<DOM::HTMLObjectBaseElementImpl*>(element.handle());
01158         if (elm)
01159             elm->put(objid, prop.qstring(), value.toString(exec).qstring());
01160     }
01161     virtual bool implementsCall() const {
01162         return objtype == KParts::LiveConnectExtension::TypeFunction;
01163     }
01164     virtual Value call(ExecState * exec, Object &, const List &args) {
01165         DOM::HTMLObjectBaseElementImpl * elm = static_cast<DOM::HTMLObjectBaseElementImpl*>(element.handle());
01166         QStringList qargs;
01167         for (ListIterator i = args.begin(); i != args.end(); i++)
01168             qargs.append((*i).toString(exec).qstring());
01169         KParts::LiveConnectExtension::Type rettype;
01170         QString retvalue;
01171         unsigned long retobjid;
01172         if (elm && elm->call(objid, name.qstring(), qargs, rettype, retobjid, retvalue))
01173             return getValue(element, name.qstring(), rettype, retvalue, retobjid);
01174         return Undefined();
01175     }
01176     virtual bool toBoolean(ExecState *) const { return true; }
01177     virtual Value toPrimitive(ExecState *exec, Type) const {
01178         return String(toString(exec));
01179     }
01180     virtual UString toString(ExecState *) const {
01181         QString str;
01182         const char *type = objtype == KParts::LiveConnectExtension::TypeFunction ? "Function" : "Object";
01183         str.sprintf("[object %s ref=%d]", type, (int) objid);
01184         return UString(str);
01185     }
01186 private:
01187     EmbedLiveConnect(const EmbedLiveConnect &);
01188     DOM::HTMLElement element;
01189     UString name;
01190     KParts::LiveConnectExtension::Type objtype;
01191     unsigned long objid;
01192 };
01193 
01194 Value KJS::HTMLElement::tryGet(ExecState *exec, const Identifier &propertyName) const
01195 {
01196   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
01197 #ifdef KJS_VERBOSE
01198   kdDebug(6070) << "KJS::HTMLElement::tryGet " << propertyName.qstring() << " thisTag=" << element.tagName().string() << endl;
01199 #endif
01200   // First look at dynamic properties
01201   switch (element.elementId()) {
01202     case ID_FORM: {
01203       DOM::HTMLFormElement form = element;
01204       // Check if we're retrieving an element (by index or by name)
01205       bool ok;
01206       uint u = propertyName.toULong(&ok);
01207 
01208       if (ok)
01209         return getDOMNode(exec,form.elements().item(u));
01210       KJS::HTMLCollection coll(exec, form.elements());
01211       Value namedItems = coll.getNamedItems(exec, propertyName);
01212       if (namedItems.type() != UndefinedType)
01213         return namedItems;
01214     }
01215       break;
01216     case ID_SELECT: {
01217       DOM::HTMLSelectElement select = element;
01218       bool ok;
01219       uint u = propertyName.toULong(&ok);
01220       if (ok)
01221         return getDOMNode(exec,select.options().item(u)); // not specified by DOM(?) but supported in netscape/IE
01222     }
01223       break;
01224   case ID_APPLET:
01225   case ID_OBJECT:
01226   case ID_EMBED: {
01227       DOM::HTMLObjectBaseElementImpl * elm = static_cast<DOM::HTMLObjectBaseElementImpl*>(element.handle());
01228       QString retvalue;
01229       KParts::LiveConnectExtension::Type rettype;
01230       unsigned long retobjid;
01231       if (elm && elm->get(0, propertyName.qstring(), rettype, retobjid, retvalue))
01232           return EmbedLiveConnect::getValue(element, propertyName.qstring(), rettype, retvalue, retobjid);
01233       break;
01234   }
01235   default:
01236     break;
01237   }
01238 
01239   const HashTable* table = classInfo()->propHashTable; // get the right hashtable
01240   const HashEntry* entry = Lookup::findEntry(table, propertyName);
01241   if (entry) {
01242     if (entry->attr & Function)
01243       return lookupOrCreateFunction<KJS::HTMLElementFunction>(exec, propertyName, this, entry->value, entry->params, entry->attr);
01244     return getValueProperty(exec, entry->value);
01245   }
01246 
01247   // Base HTMLElement stuff or parent class forward, as usual
01248   return DOMObjectLookupGet<KJS::HTMLElementFunction, KJS::HTMLElement, DOMElement>(exec, propertyName, &KJS::HTMLElementTable, this);
01249 }
01250 
01251 Value KJS::HTMLElement::getValueProperty(ExecState *exec, int token) const
01252 {
01253   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
01254   switch (element.elementId()) {
01255   case ID_HTML: {
01256     DOM::HTMLHtmlElement html = element;
01257     if      (token == HtmlVersion)         return getString(html.version());
01258   }
01259   break;
01260   case ID_HEAD: {
01261     DOM::HTMLHeadElement head = element;
01262     if      (token == HeadProfile)         return getString(head.profile());
01263   }
01264   break;
01265   case ID_LINK: {
01266     DOM::HTMLLinkElement link = element;
01267     switch (token) {
01268     case LinkDisabled:        return Boolean(link.disabled());
01269     case LinkCharset:         return getString(link.charset());
01270     case LinkHref:            return getString(link.href());
01271     case LinkHrefLang:        return getString(link.hreflang());
01272     case LinkMedia:           return getString(link.media());
01273     case LinkRel:             return getString(link.rel());
01274     case LinkRev:             return getString(link.rev());
01275     case LinkTarget:          return getString(link.target());
01276     case LinkType:            return getString(link.type());
01277     case LinkSheet:           return getDOMStyleSheet(exec,static_cast<DOM::ProcessingInstruction>(node).sheet());
01278     }
01279   }
01280   break;
01281   case ID_TITLE: {
01282     DOM::HTMLTitleElement title = element;
01283     switch (token) {
01284     case TitleText:                 return getString(title.text());
01285     }
01286   }
01287   break;
01288   case ID_META: {
01289     DOM::HTMLMetaElement meta = element;
01290     switch (token) {
01291     case MetaContent:         return getString(meta.content());
01292     case MetaHttpEquiv:       return getString(meta.httpEquiv());
01293     case MetaName:            return getString(meta.name());
01294     case MetaScheme:          return getString(meta.scheme());
01295     }
01296   }
01297   break;
01298   case ID_BASE: {
01299     DOM::HTMLBaseElement base = element;
01300     switch (token) {
01301     case BaseHref:            return getString(base.href());
01302     case BaseTarget:          return getString(base.target());
01303     }
01304   }
01305   break;
01306   case ID_ISINDEX: {
01307     DOM::HTMLIsIndexElement isindex = element;
01308     switch (token) {
01309     case IsIndexForm:            return getDOMNode(exec,isindex.form()); // type HTMLFormElement
01310     case IsIndexPrompt:          return getString(isindex.prompt());
01311     }
01312   }
01313   break;
01314   case ID_STYLE: {
01315     DOM::HTMLStyleElement style = element;
01316     switch (token) {
01317     case StyleDisabled:        return Boolean(style.disabled());
01318     case StyleMedia:           return getString(style.media());
01319     case StyleType:            return getString(style.type());
01320     case StyleSheet:           return getDOMStyleSheet(exec,style.sheet());
01321     }
01322   }
01323   break;
01324   case ID_BODY: {
01325     DOM::HTMLBodyElement body = element;
01326     switch (token) {
01327     case BodyALink:           return getString(body.aLink());
01328     case BodyBackground:      return getString(body.background());
01329     case BodyBgColor:         return getString(body.bgColor());
01330     case BodyLink:            return getString(body.link());
01331     case BodyText:            return getString(body.text());
01332     case BodyVLink:           return getString(body.vLink());
01333     // Those exist for all elements, but have a different implementation for body
01334     // e.g. lowestPosition doesn't include margins.
01335     case ElementScrollHeight:
01336     case ElementScrollWidth:
01337       {
01338         khtml::RenderObject *rend = body.ownerDocument().handle() ? body.ownerDocument().handle()->renderer() : 0L;
01339         if (rend) {
01340           Q_ASSERT( rend->isCanvas() );
01341           khtml::RenderCanvas* root = static_cast<khtml::RenderCanvas*>(rend);
01342           return Number( token == ElementScrollWidth ? root->docWidth() : root->docHeight() );
01343         }
01344         return Number(0);
01345       }
01346     }
01347   }
01348   break;
01349 
01350   case ID_FORM: {
01351     DOM::HTMLFormElement form = element;
01352     switch (token) {
01353     case FormElements:        return getHTMLCollection(exec,form.elements());
01354     case FormLength:          return Number(form.length());
01355     case FormName:            return String(form.name()); // NOT getString (IE gives empty string)
01356     case FormAcceptCharset:   return getString(form.acceptCharset());
01357     case FormAction:          return getString(form.action());
01358     case FormEncType:         return getString(form.enctype());
01359     case FormMethod:          return getString(form.method());
01360     case FormTarget:          return String(form.target());
01361     }
01362   }
01363   break;
01364   case ID_SELECT: {
01365     DOM::HTMLSelectElement select = element;
01366     switch (token) {
01367     case SelectType:            return getString(select.type());
01368     case SelectSelectedIndex:   return Number(select.selectedIndex());
01369     case SelectValue:           return getString(select.value());
01370     case SelectLength:          return Number(select.length());
01371     case SelectForm:            return getDOMNode(exec,select.form()); // type HTMLFormElement
01372     case SelectOptions:         return getSelectHTMLCollection(exec, select.options(), select); // type HTMLCollection
01373     case SelectDisabled:        return Boolean(select.disabled());
01374     case SelectMultiple:        return Boolean(select.multiple());
01375     case SelectName:            return String(select.name());
01376     case SelectSize:            return Number(select.size());
01377     case SelectTabIndex:        return Number(select.tabIndex());
01378     }
01379   }
01380   break;
01381   case ID_OPTGROUP: {
01382     DOM::HTMLOptGroupElement optgroup = element;
01383     switch (token) {
01384     case OptGroupDisabled:        return Boolean(optgroup.disabled());
01385     case OptGroupLabel:           return getString(optgroup.label());
01386     }
01387   }
01388   break;
01389   case ID_OPTION: {
01390     DOM::HTMLOptionElement option = element;
01391     switch (token) {
01392     case OptionForm:            return getDOMNode(exec,option.form()); // type HTMLFormElement
01393     case OptionDefaultSelected: return Boolean(option.defaultSelected());
01394     case OptionText:            return getString(option.text());
01395     case OptionIndex:           return Number(option.index());
01396     case OptionDisabled:        return Boolean(option.disabled());
01397     case OptionLabel:           return getString(option.label());
01398     case OptionSelected:        return Boolean(option.selected());
01399     case OptionValue:           return getString(option.value());
01400     }
01401   }
01402   break;
01403   case ID_INPUT: {
01404     DOM::HTMLInputElement input = element;
01405     switch (token) {
01406     case InputDefaultValue:    return getString(input.defaultValue());
01407     case InputDefaultChecked:  return Boolean(input.defaultChecked());
01408     case InputForm:            return getDOMNode(exec,input.form()); // type HTMLFormElement
01409     case InputAccept:          return getString(input.accept());
01410     case InputAccessKey:       return getString(input.accessKey());
01411     case InputAlign:           return getString(input.align());
01412     case InputAlt:             return String(input.alt());
01413     case InputChecked:         return Boolean(input.checked());
01414     case InputDisabled:        return Boolean(input.disabled());
01415     case InputMaxLength:       return Number(input.maxLength());
01416     case InputName:            return String(input.name()); // NOT getString (IE gives empty string)
01417     case InputReadOnly:        return Boolean(input.readOnly());
01418     case InputSize:            return Number(input.getSize());
01419     case InputSrc:             return getString(input.src());
01420     case InputTabIndex:        return Number(input.tabIndex());
01421     case InputType:            return getString(input.type());
01422     case InputUseMap:          return getString(input.useMap());
01423     case InputValue:           return getString(input.value());
01424     }
01425   }
01426   break;
01427   case ID_TEXTAREA: {
01428     DOM::HTMLTextAreaElement textarea = element;
01429     switch (token) {
01430     case TextAreaDefaultValue:    return getString(textarea.defaultValue());
01431     case TextAreaForm:            return getDOMNode(exec,textarea.form()); // type HTMLFormElement
01432     case TextAreaAccessKey:       return getString(textarea.accessKey());
01433     case TextAreaCols:            return Number(textarea.cols());
01434     case TextAreaDisabled:        return Boolean(textarea.disabled());
01435     case TextAreaName:            return String(textarea.name());
01436     case TextAreaReadOnly:        return Boolean(textarea.readOnly());
01437     case TextAreaRows:            return Number(textarea.rows());
01438     case TextAreaTabIndex:        return Number(textarea.tabIndex());
01439     case TextAreaType:            return getString(textarea.type());
01440     case TextAreaValue:           return getString(textarea.value());
01441     }
01442   }
01443   break;
01444   case ID_BUTTON: {
01445     DOM::HTMLButtonElement button = element;
01446     switch (token) {
01447     case ButtonForm:            return getDOMNode(exec,button.form()); // type HTMLFormElement
01448     case ButtonAccessKey:       return getString(button.accessKey());
01449     case ButtonDisabled:        return Boolean(button.disabled());
01450     case ButtonName:            return String(button.name());
01451     case ButtonTabIndex:        return Number(button.tabIndex());
01452     case ButtonType:            return getString(button.type());
01453     case ButtonValue:           return getString(button.value());
01454     }
01455   }
01456   break;
01457   case ID_LABEL: {
01458     DOM::HTMLLabelElement label = element;
01459     switch (token) {
01460     case LabelForm:            return getDOMNode(exec,label.form()); // type HTMLFormElement
01461     case LabelAccessKey:       return getString(label.accessKey());
01462     case LabelHtmlFor:         return getString(label.htmlFor());
01463     }
01464   }
01465   break;
01466   case ID_FIELDSET: {
01467     DOM::HTMLFieldSetElement fieldSet = element;
01468     switch (token) {
01469     case FieldSetForm:            return getDOMNode(exec,fieldSet.form()); // type HTMLFormElement
01470     }
01471   }
01472   break;
01473   case ID_LEGEND: {
01474     DOM::HTMLLegendElement legend = element;
01475     switch (token) {
01476     case LegendForm:            return getDOMNode(exec,legend.form()); // type HTMLFormElement
01477     case LegendAccessKey:       return getString(legend.accessKey());
01478     case LegendAlign:           return getString(legend.align());
01479     }
01480   }
01481   break;
01482   case ID_UL: {
01483     DOM::HTMLUListElement uList = element;
01484     switch (token) {
01485     case UListCompact:         return Boolean(uList.compact());
01486     case UListType:            return getString(uList.type());
01487     }
01488   }
01489   break;
01490   case ID_OL: {
01491     DOM::HTMLOListElement oList = element;
01492     switch (token) {
01493     case OListCompact:         return Boolean(oList.compact());
01494     case OListStart:           return Number(oList.start());
01495     case OListType:            return getString(oList.type());
01496     }
01497   }
01498   break;
01499   case ID_DL: {
01500     DOM::HTMLDListElement dList = element;
01501     switch (token) {
01502     case DListCompact:         return Boolean(dList.compact());
01503     }
01504   }
01505   break;
01506   case ID_DIR: {
01507     DOM::HTMLDirectoryElement directory = element;
01508     switch (token) {
01509     case DirectoryCompact:         return Boolean(directory.compact());
01510     }
01511   }
01512   break;
01513   case ID_MENU: {
01514     DOM::HTMLMenuElement menu = element;
01515     switch (token) {
01516     case MenuCompact:         return Boolean(menu.compact());
01517     }
01518   }
01519   break;
01520   case ID_LI: {
01521     DOM::HTMLLIElement li = element;
01522     switch (token) {
01523     case LIType:            return getString(li.type());
01524     case LIValue:           return Number(li.value());
01525     }
01526   }
01527   break;
01528   case ID_DIV: {
01529     DOM::HTMLDivElement div = element;
01530     switch (token) {
01531     case DivAlign:           return getString(div.align());
01532     }
01533   }
01534   break;
01535   case ID_P: {
01536     DOM::HTMLParagraphElement paragraph = element;
01537     switch (token) {
01538     case ParagraphAlign:           return getString(paragraph.align());
01539     }
01540   }
01541   break;
01542   case ID_H1:
01543   case ID_H2:
01544   case ID_H3:
01545   case ID_H4:
01546   case ID_H5:
01547   case ID_H6: {
01548     DOM::HTMLHeadingElement heading = element;
01549     switch (token) {
01550     case HeadingAlign:           return getString(heading.align());
01551     }
01552   }
01553   break;
01554   case ID_BLOCKQUOTE: {
01555     DOM::HTMLBlockquoteElement blockquote = element;
01556     switch (token) {
01557     case BlockQuoteCite:            return getString(blockquote.cite());
01558     }
01559   }
01560   case ID_Q: {
01561     DOM::HTMLQuoteElement quote = element;
01562     switch (token) {
01563     case QuoteCite:            return getString(quote.cite());
01564     }
01565   }
01566   case ID_PRE: {
01567     DOM::HTMLPreElement pre = element;
01568     switch (token) {
01569     case PreWidth:           return Number(pre.width());
01570     }
01571   }
01572   break;
01573   case ID_BR: {
01574     DOM::HTMLBRElement br = element;
01575     switch (token) {
01576     case BRClear:           return getString(br.clear());
01577     }
01578   }
01579   break;
01580   case ID_BASEFONT: {
01581     DOM::HTMLBaseFontElement baseFont = element;
01582     switch (token) {
01583     case BaseFontColor:           return getString(baseFont.color());
01584     case BaseFontFace:            return getString(baseFont.face());
01585     case BaseFontSize:            return Number(baseFont.getSize());
01586     }
01587   }
01588   break;
01589   case ID_FONT: {
01590     DOM::HTMLFontElement font = element;
01591     switch (token) {
01592     case FontColor:           return getString(font.color());
01593     case FontFace:            return getString(font.face());
01594     case FontSize:            return getString(font.size());
01595     }
01596   }
01597   break;
01598   case ID_HR: {
01599     DOM::HTMLHRElement hr = element;
01600     switch (token) {
01601     case HRAlign:           return getString(hr.align());
01602     case HRNoShade:         return Boolean(hr.noShade());
01603     case HRSize:            return getString(hr.size());
01604     case HRWidth:           return getString(hr.width());
01605     }
01606   }
01607   break;
01608   case ID_INS:
01609   case ID_DEL: {
01610     DOM::HTMLModElement mod = element;
01611     switch (token) {
01612     case ModCite:            return getString(mod.cite());
01613     case ModDateTime:        return getString(mod.dateTime());
01614     }
01615   }
01616   break;
01617   case ID_A: {
01618     DOM::HTMLAnchorElement anchor = element;
01619     switch (token) {
01620     case AnchorAccessKey:       return String(anchor.accessKey());
01621     case AnchorCharset:         return String(anchor.charset());
01622     case AnchorCoords:          return String(anchor.coords());
01623     case AnchorHref:            return String(anchor.href());
01624     case AnchorHrefLang:        return String(anchor.hreflang());
01625     case AnchorHash:            return String('#'+KURL(anchor.href().string()).ref());
01626     case AnchorHost:            return String(KURL(anchor.href().string()).host());
01627     case AnchorHostname: {
01628       KURL url(anchor.href().string());
01629       kdDebug(6070) << "anchor::hostname uses:" <<url.url()<<endl;
01630       if (url.port()==0)
01631         return String(url.host());
01632       else
01633         return String(url.host() + ":" + QString::number(url.port()));
01634     }
01635     case AnchorPathName:        return String(KURL(anchor.href().string()).path());
01636     case AnchorPort:            return String(QString::number(KURL(anchor.href().string()).port()));
01637     case AnchorProtocol:        return String(KURL(anchor.href().string()).protocol()+":");
01638     case AnchorSearch:          return String(KURL(anchor.href().string()).query());
01639     case AnchorName:            return String(anchor.name());
01640     case AnchorRel:             return String(anchor.rel());
01641     case AnchorRev:             return String(anchor.rev());
01642     case AnchorShape:           return String(anchor.shape());
01643     case AnchorTabIndex:        return Number(anchor.tabIndex());
01644     case AnchorTarget:          return String(anchor.target());
01645     // Not specified in http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/a.asp
01646     // Mozilla returns the inner text.
01647     case AnchorText:            return String(anchor.innerText());
01648     case AnchorType:            return String(anchor.type());
01649     }
01650   }
01651   break;
01652   case ID_IMG: {
01653     DOM::HTMLImageElement image = element;
01654     switch (token) {
01655     case ImageName:            return String(image.name()); // NOT getString (IE gives empty string)
01656     case ImageAlign:           return getString(image.align());
01657     case ImageAlt:             return String(image.alt());
01658     case ImageBorder:          return String(image.getBorder());
01659     case ImageComplete:        return Boolean(static_cast<DOM::HTMLImageElementImpl*>( image.handle() )->complete());
01660     case ImageHeight:          return Number(image.height());
01661     case ImageHspace:          return Number(image.hspace());
01662     case ImageIsMap:           return Boolean(image.isMap());
01663     case ImageLongDesc:        return getString(image.longDesc());
01664     case ImageSrc:             return String(image.src());
01665     case ImageUseMap:          return getString(image.useMap());
01666     case ImageVspace:          return Number(image.vspace());
01667     case ImageWidth:           return Number(image.width());
01668     case ImageX:               return Number(image.x());
01669     case ImageY:               return Number(image.y());
01670     }
01671   }
01672   break;
01673   case ID_OBJECT: {
01674     DOM::HTMLObjectElement object = element;
01675     switch (token) {
01676     case ObjectForm:            return getDOMNode(exec,object.form()); // type HTMLFormElement
01677     case ObjectCode:            return String(object.code()); // not getString, cf DOM2TS-HTMLObjectElement02.html
01678     case ObjectAlign:           return getString(object.align());
01679     case ObjectArchive:         return getString(object.archive());
01680     case ObjectBorder:          return getString(object.border());
01681     case ObjectCodeBase:        return getString(object.codeBase());
01682     case ObjectCodeType:        return getString(object.codeType());
01683     case ObjectContentDocument: return checkNodeSecurity(exec,object.contentDocument()) ?
01684                        getDOMNode(exec, object.contentDocument()) : Undefined();
01685     case ObjectData:            return getString(object.data());
01686     case ObjectDeclare:         return Boolean(object.declare());
01687     case ObjectHeight:          return getString(object.height());
01688     case ObjectHspace:          return Number(object.getHspace());
01689     case ObjectName:            return getString(object.name());
01690     case ObjectStandby:         return getString(object.standby());
01691     case ObjectTabIndex:        return Number(object.tabIndex());
01692     case ObjectType:            return getString(object.type());
01693     case ObjectUseMap:          return getString(object.useMap());
01694     case ObjectVspace:          return Number(object.getVspace());
01695     case ObjectWidth:           return getString(object.width());
01696     }
01697   }
01698   break;
01699   case ID_PARAM: {
01700     DOM::HTMLParamElement param = element;
01701     switch (token) {
01702     case ParamName:            return getString(param.name());
01703     case ParamType:            return getString(param.type());
01704     case ParamValue:           return getString(param.value());
01705     case ParamValueType:       return getString(param.valueType());
01706     }
01707   }
01708   break;
01709   case ID_APPLET: {
01710     DOM::HTMLAppletElement applet = element;
01711     switch (token) {
01712     case AppletAlign:           return getString(applet.align());
01713     case AppletAlt:             return String(applet.alt());
01714     case AppletArchive:         return getString(applet.archive());
01715     case AppletCode:            return getString(applet.code());
01716     case AppletCodeBase:        return getString(applet.codeBase());
01717     case AppletHeight:          return getString(applet.height());
01718     case AppletHspace:          return Number(applet.getHspace());
01719     case AppletName:            return getString(applet.name());
01720     case AppletObject:          return getString(applet.object());
01721     case AppletVspace:          return Number(applet.getVspace());
01722     case AppletWidth:           return getString(applet.width());
01723     }
01724   }
01725   break;
01726   case ID_MAP: {
01727     DOM::HTMLMapElement map = element;
01728     switch (token) {
01729     case MapAreas:           return getHTMLCollection(exec, map.areas()); // type HTMLCollection
01730     case MapName:            return getString(map.name());
01731     }
01732   }
01733   break;
01734   case ID_AREA: {
01735     DOM::HTMLAreaElement area = element;
01736     switch (token) {
01737     case AreaAccessKey:       return getString(area.accessKey());
01738     case AreaAlt:             return String(area.alt());
01739     case AreaCoords:          return getString(area.coords());
01740     // Group everything that needs href
01741     case AreaHref:
01742     case AreaHash:
01743     case AreaHost:
01744     case AreaHostName:
01745     case AreaPathName:
01746     case AreaPort:
01747     case AreaProtocol:
01748     case AreaSearch:
01749     {
01750       DOM::Document doc = area.ownerDocument();
01751       DOM::DOMString href = area.href();
01752       KURL url;
01753       if ( !href.isNull() ) {
01754         url = doc.completeURL( href ).string();
01755         if ( href.isEmpty() )
01756           url.setFileName( QString::null ); // href="" clears the filename (in IE)
01757       }
01758       switch(token) {
01759       case AreaHref:
01760         return String(url.url());
01761       case AreaHash:            return String(url.isEmpty() ? "" : '#'+url.ref());
01762       case AreaHost:            return String(url.host());
01763       case AreaHostName: {
01764         if (url.port()==0)
01765           return String(url.host());
01766         else
01767           return String(url.host() + ":" + QString::number(url.port()));
01768       }
01769       case AreaPathName:        {
01770         return String(url.path());
01771       }
01772       case AreaPort:            return String(QString::number(url.port()));
01773       case AreaProtocol:        return String(url.isEmpty() ? "" : url.protocol()+":");
01774       case AreaSearch:          return String(url.query());
01775       }
01776     }
01777     case AreaNoHref:          return Boolean(area.noHref());
01778     case AreaShape:           return getString(area.shape());
01779     case AreaTabIndex:        return Number(area.tabIndex());
01780     case AreaTarget:          return getString(area.target());
01781     }
01782   }
01783   break;
01784   case ID_SCRIPT: {
01785     DOM::HTMLScriptElement script = element;
01786     switch (token) {
01787     case ScriptText:            return getString(script.text());
01788     case ScriptHtmlFor:         return getString(script.htmlFor());
01789     case ScriptEvent:           return getString(script.event());
01790     case ScriptCharset:         return getString(script.charset());
01791     case ScriptDefer:           return Boolean(script.defer());
01792     case ScriptSrc:             return getString(script.src());
01793     case ScriptType:            return getString(script.type());
01794     }
01795   }
01796   break;
01797   case ID_TABLE: {
01798     DOM::HTMLTableElement table = element;
01799     switch (token) {
01800     case TableCaption:         return getDOMNode(exec,table.caption()); // type HTMLTableCaptionElement
01801     case TableTHead:           return getDOMNode(exec,table.tHead()); // type HTMLTableSectionElement
01802     case TableTFoot:           return getDOMNode(exec,table.tFoot()); // type HTMLTableSectionElement
01803     case TableRows:            return getHTMLCollection(exec,table.rows()); // type HTMLCollection
01804     case TableTBodies:         return getHTMLCollection(exec,table.tBodies()); // type HTMLCollection
01805     case TableAlign:           return getString(table.align());
01806     case TableBgColor:         return getString(table.bgColor());
01807     case TableBorder:          return getString(table.border());
01808     case TableCellPadding:     return getString(table.cellPadding());
01809     case TableCellSpacing:     return getString(table.cellSpacing());
01810     case TableFrame:           return getString(table.frame());
01811     case TableRules:           return getString(table.rules());
01812     case TableSummary:         return getString(table.summary());
01813     case TableWidth:           return getString(table.width());
01814     }
01815   }
01816   break;
01817   case ID_CAPTION: {
01818     DOM::HTMLTableCaptionElement tableCaption = element;
01819     switch (token) {
01820     case TableCaptionAlign:       return getString(tableCaption.align());
01821     }
01822   }
01823   break;
01824   case ID_COL:
01825   case ID_COLGROUP: {
01826     DOM::HTMLTableColElement tableCol = element;
01827     switch (token) {
01828     case TableColAlign:           return getString(tableCol.align());
01829     case TableColCh:              return getString(tableCol.ch());
01830     case TableColChOff:           return getString(tableCol.chOff());
01831     case TableColSpan:            return Number(tableCol.span());
01832     case TableColVAlign:          return getString(tableCol.vAlign());
01833     case TableColWidth:           return getString(tableCol.width());
01834     }
01835   }
01836   break;
01837   case ID_THEAD:
01838   case ID_TBODY:
01839   case ID_TFOOT: {
01840     DOM::HTMLTableSectionElement tableSection = element;
01841     switch (token) {
01842     case TableSectionAlign:           return getString(tableSection.align());
01843     case TableSectionCh:              return getString(tableSection.ch());
01844     case TableSectionChOff:           return getString(tableSection.chOff());
01845     case TableSectionVAlign:          return getString(tableSection.vAlign());
01846     case TableSectionRows:            return getHTMLCollection(exec,tableSection.rows()); // type HTMLCollection
01847     }
01848   }
01849   break;
01850   case ID_TR: {
01851    DOM::HTMLTableRowElement tableRow = element;
01852    switch (token) {
01853    case TableRowRowIndex:        return Number(tableRow.rowIndex());
01854    case TableRowSectionRowIndex: return Number(tableRow.sectionRowIndex());
01855    case TableRowCells:           return getHTMLCollection(exec,tableRow.cells()); // type HTMLCollection
01856    case TableRowAlign:           return getString(tableRow.align());
01857    case TableRowBgColor:         return getString(tableRow.bgColor());
01858    case TableRowCh:              return getString(tableRow.ch());
01859    case TableRowChOff:           return getString(tableRow.chOff());
01860    case TableRowVAlign:          return getString(tableRow.vAlign());
01861    }
01862   }
01863   break;
01864   case ID_TH:
01865   case ID_TD: {
01866     DOM::HTMLTableCellElement tableCell = element;
01867     switch (token) {
01868     case TableCellCellIndex:       return Number(tableCell.cellIndex());
01869     case TableCellAbbr:            return getString(tableCell.abbr());
01870     case TableCellAlign:           return getString(tableCell.align());
01871     case TableCellAxis:            return getString(tableCell.axis());
01872     case TableCellBgColor:         return getString(tableCell.bgColor());
01873     case TableCellCh:              return getString(tableCell.ch());
01874     case TableCellChOff:           return getString(tableCell.chOff());
01875     case TableCellColSpan:         return Number(tableCell.colSpan());
01876     case TableCellHeaders:         return getString(tableCell.headers());
01877     case TableCellHeight:          return getString(tableCell.height());
01878     case TableCellNoWrap:          return Boolean(tableCell.noWrap());
01879     case TableCellRowSpan:         return Number(tableCell.rowSpan());
01880     case TableCellScope:           return getString(tableCell.scope());
01881     case TableCellVAlign:          return getString(tableCell.vAlign());
01882     case TableCellWidth:           return getString(tableCell.width());
01883     }
01884   }
01885   break;
01886   case ID_FRAMESET: {
01887     DOM::HTMLFrameSetElement frameSet = element;
01888     switch (token) {
01889     case FrameSetCols:            return getString(frameSet.cols());
01890     case FrameSetRows:            return getString(frameSet.rows());
01891     }
01892   }
01893   break;
01894   case ID_FRAME: {
01895     DOM::HTMLFrameElement frameElement = element;
01896     switch (token) {
01897     case FrameContentDocument: return checkNodeSecurity(exec,frameElement.contentDocument()) ?
01898                       getDOMNode(exec, frameElement.contentDocument()) : Undefined();
01899     case FrameFrameBorder:     return getString(frameElement.frameBorder());
01900     case FrameLongDesc:        return getString(frameElement.longDesc());
01901     case FrameMarginHeight:    return getString(frameElement.marginHeight());
01902     case FrameMarginWidth:     return getString(frameElement.marginWidth());
01903     case FrameName:            return getString(frameElement.name());
01904     case FrameNoResize:        return Boolean(frameElement.noResize());
01905     case FrameScrolling:       return getString(frameElement.scrolling());
01906     case FrameSrc:
01907     case FrameLocation:        return getString(frameElement.src());
01908     }
01909   }
01910   break;
01911   case ID_IFRAME: {
01912     DOM::HTMLIFrameElement iFrame = element;
01913     switch (token) {
01914     case IFrameAlign:           return getString(iFrame.align());
01915     case IFrameContentDocument: return checkNodeSecurity(exec,iFrame.contentDocument()) ?
01916                        getDOMNode(exec, iFrame.contentDocument()) : Undefined();
01917     case IFrameFrameBorder:     return getString(iFrame.frameBorder());
01918     case IFrameHeight:          return getString(iFrame.height());
01919     case IFrameLongDesc:        return getString(iFrame.longDesc());
01920     case IFrameMarginHeight:    return getString(iFrame.marginHeight());
01921     case IFrameMarginWidth:     return getString(iFrame.marginWidth());
01922     case IFrameName:            return getString(iFrame.name());
01923     case IFrameScrolling:       return getString(iFrame.scrolling());
01924     case IFrameSrc:             return getString(iFrame.src());
01925     case IFrameWidth:           return getString(iFrame.width());
01926     }
01927     break;
01928   }
01929   } // xemacs (or arnt) could be a bit smarter when it comes to indenting switch()es ;)
01930   // its not arnt to blame - its the original Stroustrup style we like :) (Dirk)
01931 
01932   // generic properties
01933   switch (token) {
01934   case ElementId:
01935     return String(element.id()); // getString is wrong here. Other browsers return empty string if no id specified.
01936   case ElementTitle:
01937     return String(element.title());
01938   case ElementLang:
01939     return getString(element.lang());
01940   case ElementDir:
01941     return getString(element.dir());
01942   case ElementClassName:
01943     return getString(element.className());
01944   case ElementInnerHTML:
01945     return getString(element.innerHTML());
01946   case ElementInnerText:
01947     return getString(element.innerText());
01948   case ElementDocument:
01949     return getDOMNode(exec,element.ownerDocument());
01950   case ElementChildren:
01951     return getHTMLCollection(exec,element.children());
01952   case ElementAll:
01953     // Disable element.all when we try to be Netscape-compatible
01954     if ( exec->interpreter()->compatMode() == Interpreter::NetscapeCompat )
01955       return Undefined();
01956     return getHTMLCollection(exec,element.all());
01957   case ElementScrollHeight: {
01958     khtml::RenderObject *rend = element.handle() ? element.handle()->renderer() : 0L;
01959     // Note: lowestPosition only works on blocklevel, special or replaced elements
01960     return Number(rend ? rend->lowestPosition() : 0);
01961   }
01962   case ElementScrollWidth: {
01963     khtml::RenderObject *rend = element.handle() ? element.handle()->renderer() : 0L;
01964     return Number(rend ? rend->rightmostPosition() : 0);
01965   }
01966   // ### what about style? or is this used instead for DOM2 stylesheets?
01967   }
01968   kdError() << "HTMLElement::getValueProperty unhandled token " << token << endl;
01969   return Undefined();
01970 }
01971 
01972 bool KJS::HTMLElement::hasProperty(ExecState *exec, const Identifier &propertyName) const
01973 {
01974 #ifdef KJS_VERBOSE
01975   //kdDebug(6070) << "HTMLElement::hasProperty " << propertyName.qstring() << endl;
01976 #endif
01977   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
01978   // First look at dynamic properties - keep this in sync with tryGet
01979   switch (element.elementId()) {
01980     case ID_FORM: {
01981       DOM::HTMLFormElement form = element;
01982       // Check if we're retrieving an element (by index or by name)
01983       bool ok;
01984       uint u = propertyName.toULong(&ok);
01985       if (ok && !(form.elements().item(u).isNull()))
01986         return true;
01987       DOM::Node testnode = form.elements().namedItem(propertyName.string());
01988       if (!testnode.isNull())
01989         return true;
01990     }
01991     case ID_SELECT: {
01992       DOM::HTMLSelectElement select = element;
01993       bool ok;
01994       uint u = propertyName.toULong(&ok);
01995       if (ok && !(select.options().item(u).isNull()))
01996         return true;
01997     }
01998     default:
01999       break;
02000   }
02001 
02002   return DOMElement::hasProperty(exec, propertyName);
02003 }
02004 
02005 UString KJS::HTMLElement::toString(ExecState *exec) const
02006 {
02007   if (node.elementId() == ID_A)
02008     return UString(static_cast<const DOM::HTMLAnchorElement&>(node).href());
02009   else if (node.elementId() == ID_APPLET) {
02010     DOM::HTMLObjectBaseElementImpl * elm = static_cast<DOM::HTMLObjectBaseElementImpl*>(node.handle());
02011     QStringList qargs;
02012     QString retvalue;
02013     KParts::LiveConnectExtension::Type rettype;
02014     unsigned long retobjid;
02015     if (elm && elm->call(0, "hashCode", qargs, rettype, retobjid, retvalue)) {
02016         QString str("[object APPLET ref=");
02017         return UString(str + retvalue + QString("]"));
02018     }
02019   } else if (node.elementId() == ID_IMG) {
02020     DOM::HTMLImageElement image(node);
02021     if (!image.alt().isEmpty())
02022       return UString(image.alt()) + " " + DOMElement::toString(exec);
02023   }
02024   return DOMElement::toString(exec);
02025 }
02026 
02027 static void getForm(DOM::HTMLFormElement* form, const DOM::HTMLElement& element)
02028 {
02029     switch (element.elementId()) {
02030         case ID_ISINDEX: {
02031             DOM::HTMLIsIndexElement isindex = element;
02032             *form = isindex.form();
02033             break;
02034         }
02035         case ID_SELECT: {
02036             DOM::HTMLSelectElement select = element;
02037             *form = select.form();
02038             break;
02039         }
02040         case ID_OPTION: {
02041             DOM::HTMLOptionElement option = element;
02042             *form = option.form();
02043             break;
02044         }
02045         case ID_INPUT: {
02046             DOM::HTMLInputElement input = element;
02047             *form = input.form();
02048             break;
02049         }
02050         case ID_TEXTAREA: {
02051             DOM::HTMLTextAreaElement textarea = element;
02052             *form = textarea.form();
02053             break;
02054         }
02055         case ID_LABEL: {
02056             DOM::HTMLLabelElement label = element;
02057             *form = label.form();
02058             break;
02059         }
02060         case ID_FIELDSET: {
02061             DOM::HTMLFieldSetElement fieldset = element;
02062             *form = fieldset.form();
02063             break;
02064         }
02065         case ID_LEGEND: {
02066             DOM::HTMLLegendElement legend = element;
02067             *form = legend.form();
02068             break;
02069         }
02070         case ID_OBJECT: {
02071             DOM::HTMLObjectElement object = element;
02072             *form = object.form();
02073             break;
02074         }
02075         default:
02076             break;
02077     }
02078 }
02079 
02080 void KJS::HTMLElement::pushEventHandlerScope(ExecState *exec, ScopeChain &scope) const
02081 {
02082   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02083 
02084   // The document is put on first, fall back to searching it only after the element and form.
02085   scope.push(static_cast<ObjectImp *>(getDOMNode(exec, element.ownerDocument()).imp()));
02086 
02087   // The form is next, searched before the document, but after the element itself.
02088   DOM::HTMLFormElement formElt;
02089 
02090   // First try to obtain the form from the element itself.  We do this to deal with
02091   // the malformed case where <form>s aren't in our parent chain (e.g., when they were inside
02092   // <table> or <tbody>.
02093   getForm(&formElt, element);
02094   if (!formElt.isNull())
02095     scope.push(static_cast<ObjectImp *>(getDOMNode(exec, formElt).imp()));
02096   else {
02097     DOM::Node form = element.parentNode();
02098     while (!form.isNull() && form.elementId() != ID_FORM)
02099         form = form.parentNode();
02100 
02101     if (!form.isNull())
02102         scope.push(static_cast<ObjectImp *>(getDOMNode(exec, form).imp()));
02103   }
02104 
02105   // The element is on top, searched first.
02106   scope.push(static_cast<ObjectImp *>(getDOMNode(exec, element).imp()));
02107 }
02108 
02109 HTMLElementFunction::HTMLElementFunction(ExecState *exec, int i, int len)
02110   : DOMFunction(exec), id(i)
02111 {
02112   Value protect(this);
02113   put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum);
02114 }
02115 
02116 Value KJS::HTMLElementFunction::tryCall(ExecState *exec, Object &thisObj, const List &args)
02117 {
02118   KJS_CHECK_THIS( HTMLElement, thisObj );
02119 
02120 #ifdef KJS_VERBOSE
02121   kdDebug(6070) << "KJS::HTMLElementFunction::tryCall " << endl;
02122 #endif
02123   DOM::HTMLElement element = static_cast<KJS::HTMLElement *>(thisObj.imp())->toElement();
02124 
02125   switch (element.elementId()) {
02126     case ID_FORM: {
02127       DOM::HTMLFormElement form = element;
02128       if (id == KJS::HTMLElement::FormSubmit) {
02129 
02130 
02131         DOM::HTMLDocument doc = element.ownerDocument();
02132         KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
02133         KHTMLSettings::KJSWindowOpenPolicy policy = KHTMLSettings::KJSWindowOpenAllow;
02134     if (view)
02135         policy = view->part()->settings()->windowOpenPolicy(view->part()->url().host());
02136 
02137         bool block = false;
02138 
02139         if ( policy != KHTMLSettings::KJSWindowOpenAllow ) {
02140           block = true;
02141 
02142          // if this is a form without a target, or a special target, don't block
02143           QString trg = form.target().lower().string();
02144           if( trg.isEmpty() || trg == "_top" || trg == "_self" ||
02145               trg == "_parent")
02146             block = false;
02147 
02148           // if there is a frame with the target name, don't block
02149           if ( view && view->part() )  {
02150             // search all (possibly nested) framesets
02151             KHTMLPart *currentPart = view->part()->parentPart();
02152             while( currentPart != 0L ) {
02153               if( currentPart->frameExists( form.target().string() ) )
02154                 block = false;
02155               currentPart = currentPart->parentPart();
02156             }
02157           }
02158 
02159           if ( block && policy == KHTMLSettings::KJSWindowOpenAsk && view ) {
02160 
02161             if ( KMessageBox::questionYesNo(view, form.action().isEmpty() ?
02162                    i18n( "This site is submitting a form which will open up a new browser "
02163                          "window via JavaScript.\n"
02164                          "Do you want to allow the form to be submitted?" ) :
02165                    i18n( "<qt>This site is submitting a form which will open <p>%1</p> in a new browser window via JavaScript.<br />"
02166                          "Do you want to allow the form to be submitted?</qt>").arg(KStringHandler::csqueeze(form.action().string(),  100)),
02167                    i18n( "Confirmation: JavaScript Popup" ) ) == KMessageBox::Yes )
02168               block = false;
02169 
02170           } else if ( block && policy == KHTMLSettings::KJSWindowOpenSmart ) {
02171             if( static_cast<KJS::ScriptInterpreter *>(exec->interpreter())->isWindowOpenAllowed() ) {
02172               // This submission has been triggered by the user
02173               block = false;
02174             }
02175           }
02176         }
02177 
02178         if( !block )
02179           form.submit();
02180 
02181         return Undefined();
02182       }
02183       else if (id == KJS::HTMLElement::FormReset) {
02184         form.reset();
02185         return Undefined();
02186       }
02187     }
02188     break;
02189     case ID_SELECT: {
02190       DOM::HTMLSelectElement select = element;
02191       if (id == KJS::HTMLElement::SelectAdd) {
02192         select.add(KJS::toNode(args[0]),KJS::toNode(args[1]));
02193         return Undefined();
02194       }
02195       else if (id == KJS::HTMLElement::SelectRemove) {
02196         select.remove(int(args[0].toNumber(exec)));
02197         return Undefined();
02198       }
02199       else if (id == KJS::HTMLElement::SelectBlur) {
02200         select.blur();
02201         return Undefined();
02202       }
02203       else if (id == KJS::HTMLElement::SelectFocus) {
02204         select.focus();
02205         return Undefined();
02206       }
02207     }
02208     break;
02209     case ID_INPUT: {
02210       DOM::HTMLInputElement input = element;
02211       if (id == KJS::HTMLElement::InputBlur) {
02212         input.blur();
02213         return Undefined();
02214       }
02215       else if (id == KJS::HTMLElement::InputFocus) {
02216         input.focus();
02217         return Undefined();
02218       }
02219       else if (id == KJS::HTMLElement::InputSelect) {
02220         input.select();
02221         return Undefined();
02222       }
02223       else if (id == KJS::HTMLElement::InputClick) {
02224         input.click();
02225         return Undefined();
02226       }
02227     }
02228     break;
02229     case ID_TEXTAREA: {
02230       DOM::HTMLTextAreaElement textarea = element;
02231       if (id == KJS::HTMLElement::TextAreaBlur) {
02232         textarea.blur();
02233         return Undefined();
02234       }
02235       else if (id == KJS::HTMLElement::TextAreaFocus) {
02236         textarea.focus();
02237         return Undefined();
02238       }
02239       else if (id == KJS::HTMLElement::TextAreaSelect) {
02240         textarea.select();
02241         return Undefined();
02242       }
02243     }
02244     break;
02245     case ID_A: {
02246       DOM::HTMLAnchorElement anchor = element;
02247       if (id == KJS::HTMLElement::AnchorBlur) {
02248         anchor.blur();
02249         return Undefined();
02250       }
02251       else if (id == KJS::HTMLElement::AnchorFocus) {
02252         anchor.focus();
02253         return Undefined();
02254       }
02255     }
02256     break;
02257     case ID_TABLE: {
02258       DOM::HTMLTableElement table = element;
02259       if (id == KJS::HTMLElement::TableCreateTHead)
02260         return getDOMNode(exec,table.createTHead());
02261       else if (id == KJS::HTMLElement::TableDeleteTHead) {
02262         table.deleteTHead();
02263         return Undefined();
02264       }
02265       else if (id == KJS::HTMLElement::TableCreateTFoot)
02266         return getDOMNode(exec,table.createTFoot());
02267       else if (id == KJS::HTMLElement::TableDeleteTFoot) {
02268         table.deleteTFoot();
02269         return Undefined();
02270       }
02271       else if (id == KJS::HTMLElement::TableCreateCaption)
02272         return getDOMNode(exec,table.createCaption());
02273       else if (id == KJS::HTMLElement::TableDeleteCaption) {
02274         table.deleteCaption();
02275         return Undefined();
02276       }
02277       else if (id == KJS::HTMLElement::TableInsertRow)
02278         return getDOMNode(exec,table.insertRow(args[0].toInteger(exec)));
02279       else if (id == KJS::HTMLElement::TableDeleteRow) {
02280         table.deleteRow(args[0].toInteger(exec));
02281         return Undefined();
02282       }
02283     }
02284     break;
02285     case ID_THEAD:
02286     case ID_TBODY:
02287     case ID_TFOOT: {
02288       DOM::HTMLTableSectionElement tableSection = element;
02289       if (id == KJS::HTMLElement::TableSectionInsertRow)
02290         return getDOMNode(exec,tableSection.insertRow(args[0].toInteger(exec)));
02291       else if (id == KJS::HTMLElement::TableSectionDeleteRow) {
02292         tableSection.deleteRow(args[0].toInteger(exec));
02293         return Undefined();
02294       }
02295     }
02296     break;
02297     case ID_TR: {
02298       DOM::HTMLTableRowElement tableRow = element;
02299       if (id == KJS::HTMLElement::TableRowInsertCell)
02300         return getDOMNode(exec,tableRow.insertCell(args[0].toInteger(exec)));
02301       else if (id == KJS::HTMLElement::TableRowDeleteCell) {
02302         tableRow.deleteCell(args[0].toInteger(exec));
02303         return Undefined();
02304       }
02305       break;
02306     }
02307   }
02308 
02309   return Undefined();
02310 }
02311 
02312 void KJS::HTMLElement::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
02313 {
02314 #ifdef KJS_VERBOSE
02315   DOM::DOMString str = value.isA(NullType) ? DOM::DOMString() : value.toString(exec).string();
02316 #endif
02317   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02318 #ifdef KJS_VERBOSE
02319   kdDebug(6070) << "KJS::HTMLElement::tryPut " << propertyName.qstring()
02320                 << " thisTag=" << element.tagName().string()
02321                 << " str=" << str.string() << endl;
02322 #endif
02323   // First look at dynamic properties
02324   switch (element.elementId()) {
02325     case ID_SELECT: {
02326       DOM::HTMLSelectElement select = element;
02327       bool ok;
02328       /*uint u =*/ propertyName.toULong(&ok);
02329       if (ok) {
02330         Object coll = Object::dynamicCast( getSelectHTMLCollection(exec, select.options(), select) );
02331         if ( !coll.isNull() )
02332           coll.put(exec,propertyName,value);
02333         return;
02334       }
02335       break;
02336     }
02337     case ID_APPLET:
02338     case ID_OBJECT:
02339     case ID_EMBED: {
02340       DOM::HTMLObjectBaseElementImpl * elm = static_cast<DOM::HTMLObjectBaseElementImpl*>(element.handle());
02341       if (elm && elm->put(0, propertyName.qstring(),
02342                           value.toString(exec).qstring()))
02343           return;
02344       break;
02345     }
02346     default:
02347       break;
02348   }
02349 
02350   const HashTable* table = classInfo()->propHashTable; // get the right hashtable
02351   const HashEntry* entry = Lookup::findEntry(table, propertyName);
02352   if (entry) {
02353     if (entry->attr & Function) // function: put as override property
02354     {
02355       ObjectImp::put(exec, propertyName, value, attr);
02356       return;
02357     }
02358     else if ((entry->attr & ReadOnly) == 0) // let DOMObjectLookupPut print the warning if not
02359     {
02360       putValueProperty(exec, entry->value, value, attr);
02361       return;
02362     }
02363   }
02364   DOMObjectLookupPut<KJS::HTMLElement, DOMElement>(exec, propertyName, value, attr, &KJS::HTMLElementTable, this);
02365 }
02366 
02367 void KJS::HTMLElement::putValueProperty(ExecState *exec, int token, const Value& value, int)
02368 {
02369   DOM::DOMString str = value.isA(NullType) ? DOM::DOMString() : value.toString(exec).string();
02370   DOMNode *kjsNode = new DOMNode(exec, KJS::toNode(value));
02371   // Need to create a Value wrapper to avoid leaking the KJS::DOMNode
02372   Value nodeValue(kjsNode);
02373   DOM::Node n = kjsNode->toNode();
02374   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02375 #ifdef KJS_VERBOSE
02376   kdDebug(6070) << "KJS::HTMLElement::putValueProperty "
02377                 << " thisTag=" << element.tagName().string()
02378                 << " token=" << token << endl;
02379 #endif
02380 
02381   switch (element.elementId()) {
02382   case ID_HTML: {
02383       DOM::HTMLHtmlElement html = element;
02384       switch (token) {
02385       case HtmlVersion:         { html.setVersion(str); return; }
02386       }
02387   }
02388   break;
02389   case ID_HEAD: {
02390     DOM::HTMLHeadElement head = element;
02391     switch (token) {
02392     case HeadProfile:         { head.setProfile(str); return; }
02393     }
02394   }
02395   break;
02396   case ID_LINK: {
02397     DOM::HTMLLinkElement link = element;
02398     switch (token) {
02399       case LinkDisabled:        { link.setDisabled(value.toBoolean(exec)); return; }
02400       case LinkCharset:         { link.setCharset(str); return; }
02401       case LinkHref:            { link.setHref(str); return; }
02402       case LinkHrefLang:        { link.setHreflang(str); return; }
02403       case LinkMedia:           { link.setMedia(str); return; }
02404       case LinkRel:             { link.setRel(str); return; }
02405       case LinkRev:             { link.setRev(str); return; }
02406       case LinkTarget:          { link.setTarget(str); return; }
02407       case LinkType:            { link.setType(str); return; }
02408       }
02409     }
02410     break;
02411     case ID_TITLE: {
02412       DOM::HTMLTitleElement title = element;
02413       switch (token) {
02414       case TitleText:                 { title.setText(str); return; }
02415       }
02416     }
02417     break;
02418     case ID_META: {
02419       DOM::HTMLMetaElement meta = element;
02420       switch (token) {
02421       case MetaContent:         { meta.setContent(str); return; }
02422       case MetaHttpEquiv:       { meta.setHttpEquiv(str); return; }
02423       case MetaName:            { meta.setName(str); return; }
02424       case MetaScheme:          { meta.setScheme(str); return; }
02425       }
02426     }
02427     break;
02428     case ID_BASE: {
02429       DOM::HTMLBaseElement base = element;
02430       switch (token) {
02431       case BaseHref:            { base.setHref(str); return; }
02432       case BaseTarget:          { base.setTarget(str); return; }
02433       }
02434     }
02435     break;
02436     case ID_ISINDEX: {
02437       DOM::HTMLIsIndexElement isindex = element;
02438       switch (token) {
02439       // read-only: form
02440       case IsIndexPrompt:               { isindex.setPrompt(str); return; }
02441       }
02442     }
02443     break;
02444     case ID_STYLE: {
02445       DOM::HTMLStyleElement style = element;
02446       switch (token) {
02447       case StyleDisabled:        { style.setDisabled(value.toBoolean(exec)); return; }
02448       case StyleMedia:           { style.setMedia(str); return; }
02449       case StyleType:            { style.setType(str); return; }
02450       }
02451     }
02452     break;
02453     case ID_BODY: {
02454       DOM::HTMLBodyElement body = element;
02455       switch (token) {
02456       case BodyALink:           { body.setALink(str); return; }
02457       case BodyBackground:      { body.setBackground(str); return; }
02458       case BodyBgColor:         { body.setBgColor(str); return; }
02459       case BodyLink:            { body.setLink(str); return; }
02460       case BodyText:            { body.setText(str); return; }
02461       case BodyVLink:           { body.setVLink(str); return; }
02462       }
02463     }
02464     break;
02465     case ID_FORM: {
02466       DOM::HTMLFormElement form = element;
02467       switch (token) {
02468       // read-only: elements
02469       // read-only: length
02470       case FormName:            { form.setName(str); return; }
02471       case FormAcceptCharset:   { form.setAcceptCharset(str); return; }
02472       case FormAction:          { form.setAction(str.string()); return; }
02473       case FormEncType:         { form.setEnctype(str); return; }
02474       case FormMethod:          { form.setMethod(str); return; }
02475       case FormTarget:          { form.setTarget(str); return; }
02476       }
02477     }
02478     break;
02479     case ID_SELECT: {
02480       DOM::HTMLSelectElement select = element;
02481       switch (token) {
02482       // read-only: type
02483       case SelectSelectedIndex:   { select.setSelectedIndex(value.toInteger(exec)); return; }
02484       case SelectValue:           { select.setValue(str); return; }
02485       case SelectLength:          { // read-only according to the NS spec, but webpages need it writeable
02486                                          Object coll = Object::dynamicCast( getSelectHTMLCollection(exec, select.options(), select) );
02487                                          if ( !coll.isNull() )
02488                                            coll.put(exec,"length",value);
02489                                          return;
02490                                        }
02491       // read-only: form
02492       // read-only: options
02493       case SelectDisabled:        { select.setDisabled(value.toBoolean(exec)); return; }
02494       case SelectMultiple:        { select.setMultiple(value.toBoolean(exec)); return; }
02495       case SelectName:            { select.setName(str); return; }
02496       case SelectSize:            { select.setSize(value.toInteger(exec)); return; }
02497       case SelectTabIndex:        { select.setTabIndex(value.toInteger(exec)); return; }
02498       }
02499     }
02500     break;
02501     case ID_OPTGROUP: {
02502       DOM::HTMLOptGroupElement optgroup = element;
02503       switch (token) {
02504       case OptGroupDisabled:        { optgroup.setDisabled(value.toBoolean(exec)); return; }
02505       case OptGroupLabel:           { optgroup.setLabel(str); return; }
02506       }
02507     }
02508     break;
02509     case ID_OPTION: {
02510       DOM::HTMLOptionElement option = element;
02511       switch (token) {
02512       // read-only: form
02513       case OptionDefaultSelected: { option.setDefaultSelected(value.toBoolean(exec)); return; }
02514       // read-only: text  <--- According to the DOM, but JavaScript and JScript both allow changes.
02515       // So, we'll do it here and not add it to our DOM headers.
02516       case OptionText:            { DOM::NodeList nl(option.childNodes());
02517                                     for (unsigned int i = 0; i < nl.length(); i++) {
02518                                         if (nl.item(i).nodeType() == DOM::Node::TEXT_NODE) {
02519                                             static_cast<DOM::Text>(nl.item(i)).setData(str);
02520                                             return;
02521                                         }
02522                                   }
02523                                   // No child text node found, creating one
02524                                   DOM::Text t = option.ownerDocument().createTextNode(str);
02525                                   try { option.appendChild(t); }
02526                                   catch(DOM::DOMException& e) {
02527                                     // #### exec->setException ?
02528                                   }
02529 
02530                                   return;
02531       }
02532       // read-only: index
02533       case OptionDisabled:        { option.setDisabled(value.toBoolean(exec)); return; }
02534       case OptionLabel:           { option.setLabel(str); return; }
02535       case OptionSelected:        { option.setSelected(value.toBoolean(exec)); return; }
02536       case OptionValue:           { option.setValue(str); return; }
02537       }
02538     }
02539     break;
02540     case ID_INPUT: {
02541       DOM::HTMLInputElement input = element;
02542       switch (token) {
02543       case InputDefaultValue:    { input.setDefaultValue(str); return; }
02544       case InputDefaultChecked:  { input.setDefaultChecked(value.toBoolean(exec)); return; }
02545       // read-only: form
02546       case InputAccept:          { input.setAccept(str); return; }
02547       case InputAccessKey:       { input.setAccessKey(str); return; }
02548       case InputAlign:           { input.setAlign(str); return; }
02549       case InputAlt:             { input.setAlt(str); return; }
02550       case InputChecked:         { input.setChecked(value.toBoolean(exec)); return; }
02551       case InputDisabled:        { input.setDisabled(value.toBoolean(exec)); return; }
02552       case InputMaxLength:       { input.setMaxLength(value.toInteger(exec)); return; }
02553       case InputName:            { input.setName(str); return; }
02554       case InputReadOnly:        { input.setReadOnly(value.toBoolean(exec)); return; }
02555       case InputSize:            { input.setSize(value.toInteger(exec)); return; }
02556       case InputSrc:             { input.setSrc(str); return; }
02557       case InputTabIndex:        { input.setTabIndex(value.toInteger(exec)); return; }
02558       case InputType:            { input.setType(str); return; }
02559       case InputUseMap:          { input.setUseMap(str); return; }
02560       case InputValue:           { input.setValue(str); return; }
02561       }
02562     }
02563     break;
02564     case ID_TEXTAREA: {
02565       DOM::HTMLTextAreaElement textarea = element;
02566       switch (token) {
02567       case TextAreaDefaultValue:    { textarea.setDefaultValue(str); return; }
02568       // read-only: form
02569       case TextAreaAccessKey:       { textarea.setAccessKey(str); return; }
02570       case TextAreaCols:            { textarea.setCols(value.toInteger(exec)); return; }
02571       case TextAreaDisabled:        { textarea.setDisabled(value.toBoolean(exec)); return; }
02572       case TextAreaName:            { textarea.setName(str); return; }
02573       case TextAreaReadOnly:        { textarea.setReadOnly(value.toBoolean(exec)); return; }
02574       case TextAreaRows:            { textarea.setRows(value.toInteger(exec)); return; }
02575       case TextAreaTabIndex:        { textarea.setTabIndex(value.toInteger(exec)); return; }
02576       // read-only: type
02577       case TextAreaValue:           { textarea.setValue(str); return; }
02578       }
02579     }
02580     break;
02581     case ID_BUTTON: {
02582       DOM::HTMLButtonElement button = element;
02583       switch (token) {
02584       // read-only: form
02585       case ButtonAccessKey:       { button.setAccessKey(str); return; }
02586       case ButtonDisabled:        { button.setDisabled(value.toBoolean(exec)); return; }
02587       case ButtonName:            { button.setName(str); return; }
02588       case ButtonTabIndex:        { button.setTabIndex(value.toInteger(exec)); return; }
02589       // read-only: type
02590       case ButtonValue:           { button.setValue(str); return; }
02591       }
02592     }
02593     break;
02594     case ID_LABEL: {
02595       DOM::HTMLLabelElement label = element;
02596       switch (token) {
02597       // read-only: form
02598       case LabelAccessKey:       { label.setAccessKey(str); return; }
02599       case LabelHtmlFor:         { label.setHtmlFor(str); return; }
02600       }
02601     }
02602     break;
02603 //    case ID_FIELDSET: {
02604 //      DOM::HTMLFieldSetElement fieldSet = element;
02605 //      // read-only: form
02606 //    }
02607 //    break;
02608     case ID_LEGEND: {
02609       DOM::HTMLLegendElement legend = element;
02610       switch (token) {
02611       // read-only: form
02612       case LegendAccessKey:       { legend.setAccessKey(str); return; }
02613       case LegendAlign:           { legend.setAlign(str); return; }
02614       }
02615     }
02616     break;
02617     case ID_UL: {
02618       DOM::HTMLUListElement uList = element;
02619       switch (token) {
02620       case UListCompact:         { uList.setCompact(value.toBoolean(exec)); return; }
02621       case UListType:            { uList.setType(str); return; }
02622       }
02623     }
02624     break;
02625     case ID_OL: {
02626       DOM::HTMLOListElement oList = element;
02627       switch (token) {
02628       case OListCompact:         { oList.setCompact(value.toBoolean(exec)); return; }
02629       case OListStart:           { oList.setStart(value.toInteger(exec)); return; }
02630       case OListType:            { oList.setType(str); return; }
02631       }
02632     }
02633     break;
02634     case ID_DL: {
02635       DOM::HTMLDListElement dList = element;
02636       switch (token) {
02637       case DListCompact:         { dList.setCompact(value.toBoolean(exec)); return; }
02638       }
02639     }
02640     break;
02641     case ID_DIR: {
02642       DOM::HTMLDirectoryElement directory = element;
02643       switch (token) {
02644       case DirectoryCompact:     { directory.setCompact(value.toBoolean(exec)); return; }
02645       }
02646     }
02647     break;
02648     case ID_MENU: {
02649       DOM::HTMLMenuElement menu = element;
02650       switch (token) {
02651       case MenuCompact:         { menu.setCompact(value.toBoolean(exec)); return; }
02652       }
02653     }
02654     break;
02655     case ID_LI: {
02656       DOM::HTMLLIElement li = element;
02657       switch (token) {
02658       case LIType:            { li.setType(str); return; }
02659       case LIValue:           { li.setValue(value.toInteger(exec)); return; }
02660       }
02661     }
02662     break;
02663     case ID_DIV: {
02664       DOM::HTMLDivElement div = element;
02665       switch (token) {
02666       case DivAlign:           { div.setAlign(str); return; }
02667       }
02668     }
02669     break;
02670     case ID_P: {
02671       DOM::HTMLParagraphElement paragraph = element;
02672       switch (token) {
02673       case ParagraphAlign:     { paragraph.setAlign(str); return; }
02674       }
02675     }
02676     break;
02677     case ID_H1:
02678     case ID_H2:
02679     case ID_H3:
02680     case ID_H4:
02681     case ID_H5:
02682     case ID_H6: {
02683       DOM::HTMLHeadingElement heading = element;
02684       switch (token) {
02685       case HeadingAlign:         { heading.setAlign(str); return; }
02686       }
02687     }
02688     break;
02689     case ID_BLOCKQUOTE: {
02690       DOM::HTMLBlockquoteElement blockquote = element;
02691       switch (token) {
02692       case BlockQuoteCite:       { blockquote.setCite(str); return; }
02693       }
02694     }
02695     break;
02696     case ID_Q: {
02697       DOM::HTMLQuoteElement quote = element;
02698       switch (token) {
02699       case QuoteCite:            { quote.setCite(str); return; }
02700       }
02701     }
02702     break;
02703     case ID_PRE: {
02704       DOM::HTMLPreElement pre = element;
02705       switch (token) {
02706       case PreWidth:           { pre.setWidth(value.toInteger(exec)); return; }
02707       }
02708     }
02709     break;
02710     case ID_BR: {
02711       DOM::HTMLBRElement br = element;
02712       switch (token) {
02713       case BRClear:           { br.setClear(str); return; }
02714       }
02715     }
02716     break;
02717     case ID_BASEFONT: {
02718       DOM::HTMLBaseFontElement baseFont = element;
02719       switch (token) {
02720       case BaseFontColor:           { baseFont.setColor(str); return; }
02721       case BaseFontFace:            { baseFont.setFace(str); return; }
02722       case BaseFontSize:            { baseFont.setSize(value.toInteger(exec)); return; }
02723       }
02724     }
02725     break;
02726     case ID_FONT: {
02727       DOM::HTMLFontElement font = element;
02728       switch (token) {
02729       case FontColor:           { font.setColor(str); return; }
02730       case FontFace:            { font.setFace(str); return; }
02731       case FontSize:            { font.setSize(str); return; }
02732       }
02733     }
02734     break;
02735     case ID_HR: {
02736       DOM::HTMLHRElement hr = element;
02737       switch (token) {
02738       case HRAlign:           { hr.setAlign(str); return; }
02739       case HRNoShade:         { hr.setNoShade(value.toBoolean(exec)); return; }
02740       case HRSize:            { hr.setSize(str); return; }
02741       case HRWidth:           { hr.setWidth(str); return; }
02742       }
02743     }
02744     break;
02745     case ID_INS:
02746     case ID_DEL: {
02747       DOM::HTMLModElement mod = element;
02748       switch (token) {
02749       case ModCite:            { mod.setCite(str); return; }
02750       case ModDateTime:        { mod.setDateTime(str); return; }
02751       }
02752     }
02753     break;
02754     case ID_A: {
02755       DOM::HTMLAnchorElement anchor = element;
02756       switch (token) {
02757       case AnchorAccessKey:       { anchor.setAccessKey(str); return; }
02758       case AnchorCharset:         { anchor.setCharset(str); return; }
02759       case AnchorCoords:          { anchor.setCoords(str); return; }
02760       case AnchorHref:            { anchor.setHref(str); return; }
02761       case AnchorHrefLang:        { anchor.setHreflang(str); return; }
02762       case AnchorName:            { anchor.setName(str); return; }
02763       case AnchorRel:             { anchor.setRel(str); return; }
02764       case AnchorRev:             { anchor.setRev(str); return; }
02765       case AnchorShape:           { anchor.setShape(str); return; }
02766       case AnchorTabIndex:        { anchor.setTabIndex(value.toInteger(exec)); return; }
02767       case AnchorTarget:          { anchor.setTarget(str); return; }
02768       case AnchorType:            { anchor.setType(str); return; }
02769       }
02770     }
02771     break;
02772     case ID_IMG: {
02773       DOM::HTMLImageElement image = element;
02774       switch (token) {
02775       case ImageName:            { image.setName(str); return; }
02776       case ImageAlign:           { image.setAlign(str); return; }
02777       case ImageAlt:             { image.setAlt(str); return; }
02778       case ImageBorder:          { image.setBorder(str); return; }
02779       case ImageHeight:          { image.setHeight(value.toInteger(exec)); return; }
02780       case ImageHspace:          { image.setHspace(value.toInteger(exec)); return; }
02781       case ImageIsMap:           { image.setIsMap(value.toBoolean(exec)); return; }
02782       case ImageLongDesc:        { image.setLongDesc(str); return; }
02783       case ImageSrc:             { image.setSrc(str); return; }
02784       case ImageUseMap:          { image.setUseMap(str); return; }
02785       case ImageVspace:          { image.setVspace(value.toInteger(exec)); return; }
02786       case ImageWidth:           { image.setWidth(value.toInteger(exec)); return; }
02787       }
02788     }
02789     break;
02790     case ID_OBJECT: {
02791       DOM::HTMLObjectElement object = element;
02792       switch (token) {
02793       // read-only: form
02794       case ObjectCode:                 { object.setCode(str); return; }
02795       case ObjectAlign:           { object.setAlign(str); return; }
02796       case ObjectArchive:         { object.setArchive(str); return; }
02797       case ObjectBorder:          { object.setBorder(str); return; }
02798       case ObjectCodeBase:        { object.setCodeBase(str); return; }
02799       case ObjectCodeType:        { object.setCodeType(str); return; }
02800       // read-only: ObjectContentDocument
02801       case ObjectData:            { object.setData(str); return; }
02802       case ObjectDeclare:         { object.setDeclare(value.toBoolean(exec)); return; }
02803       case ObjectHeight:          { object.setHeight(str); return; }
02804       case ObjectHspace:          { object.setHspace(value.toInteger(exec)); return; }
02805       case ObjectName:            { object.setName(str); return; }
02806       case ObjectStandby:         { object.setStandby(str); return; }
02807       case ObjectTabIndex:        { object.setTabIndex(value.toInteger(exec)); return; }
02808       case ObjectType:            { object.setType(str); return; }
02809       case ObjectUseMap:          { object.setUseMap(str); return; }
02810       case ObjectVspace:          { object.setVspace(value.toInteger(exec)); return; }
02811       case ObjectWidth:           { object.setWidth(str); return; }
02812       }
02813     }
02814     break;
02815     case ID_PARAM: {
02816       DOM::HTMLParamElement param = element;
02817       switch (token) {
02818       case ParamName:            { param.setName(str); return; }
02819       case ParamType:            { param.setType(str); return; }
02820       case ParamValue:           { param.setValue(str); return; }
02821       case ParamValueType:       { param.setValueType(str); return; }
02822       }
02823     }
02824     break;
02825     case ID_APPLET: {
02826       DOM::HTMLAppletElement applet = element;
02827       switch (token) {
02828       case AppletAlign:           { applet.setAlign(str); return; }
02829       case AppletAlt:             { applet.setAlt(str); return; }
02830       case AppletArchive:         { applet.setArchive(str); return; }
02831       case AppletCode:            { applet.setCode(str); return; }
02832       case AppletCodeBase:        { applet.setCodeBase(str); return; }
02833       case AppletHeight:          { applet.setHeight(str); return; }
02834       case AppletHspace:          { applet.setHspace(value.toInteger(exec)); return; }
02835       case AppletName:            { applet.setName(str); return; }
02836       case AppletObject:          { applet.setObject(str); return; }
02837       case AppletVspace:          { applet.setVspace(value.toInteger(exec)); return; }
02838       case AppletWidth:           { applet.setWidth(str); return; }
02839       }
02840     }
02841     break;
02842     case ID_MAP: {
02843       DOM::HTMLMapElement map = element;
02844       switch (token) {
02845       // read-only: areas
02846       case MapName:                 { map.setName(str); return; }
02847      }
02848     }
02849     break;
02850     case ID_AREA: {
02851       DOM::HTMLAreaElement area = element;
02852       switch (token) {
02853       case AreaAccessKey:       { area.setAccessKey(str); return; }
02854       case AreaAlt:             { area.setAlt(str); return; }
02855       case AreaCoords:          { area.setCoords(str); return; }
02856       case AreaHref:            { area.setHref(str); return; }
02857       case AreaNoHref:          { area.setNoHref(value.toBoolean(exec)); return; }
02858       case AreaShape:           { area.setShape(str); return; }
02859       case AreaTabIndex:        { area.setTabIndex(value.toInteger(exec)); return; }
02860       case AreaTarget:          { area.setTarget(str); return; }
02861       }
02862     }
02863     break;
02864     case ID_SCRIPT: {
02865       DOM::HTMLScriptElement script = element;
02866       switch (token) {
02867       case ScriptText:            { script.setText(str); return; }
02868       case ScriptHtmlFor:         { script.setHtmlFor(str); return; }
02869       case ScriptEvent:           { script.setEvent(str); return; }
02870       case ScriptCharset:         { script.setCharset(str); return; }
02871       case ScriptDefer:           { script.setDefer(value.toBoolean(exec)); return; }
02872       case ScriptSrc:             { script.setSrc(str); return; }
02873       case ScriptType:            { script.setType(str); return; }
02874       }
02875     }
02876     break;
02877     case ID_TABLE: {
02878       DOM::HTMLTableElement table = element;
02879       switch (token) {
02880       case TableCaption:         { table.setCaption(n); return; } // type HTMLTableCaptionElement
02881       case TableTHead:           { table.setTHead(n); return; } // type HTMLTableSectionElement
02882       case TableTFoot:           { table.setTFoot(n); return; } // type HTMLTableSectionElement
02883       // read-only: rows
02884       // read-only: tbodies
02885       case TableAlign:           { table.setAlign(str); return; }
02886       case TableBgColor:         { table.setBgColor(str); return; }
02887       case TableBorder:          { table.setBorder(str); return; }
02888       case TableCellPadding:     { table.setCellPadding(str); return; }
02889       case TableCellSpacing:     { table.setCellSpacing(str); return; }
02890       case TableFrame:           { table.setFrame(str); return; }
02891       case TableRules:           { table.setRules(str); return; }
02892       case TableSummary:         { table.setSummary(str); return; }
02893       case TableWidth:           { table.setWidth(str); return; }
02894       }
02895     }
02896     break;
02897     case ID_CAPTION: {
02898       DOM::HTMLTableCaptionElement tableCaption = element;
02899       switch (token) {
02900       case TableAlign:           { tableCaption.setAlign(str); return; }
02901       }
02902     }
02903     break;
02904     case ID_COL:
02905     case ID_COLGROUP: {
02906       DOM::HTMLTableColElement tableCol = element;
02907       switch (token) {
02908       case TableColAlign:           { tableCol.setAlign(str); return; }
02909       case TableColCh:              { tableCol.setCh(str); return; }
02910       case TableColChOff:           { tableCol.setChOff(str); return; }
02911       case TableColSpan:            { tableCol.setSpan(value.toInteger(exec)); return; }
02912       case TableColVAlign:          { tableCol.setVAlign(str); return; }
02913       case TableColWidth:           { tableCol.setWidth(str); return; }
02914       }
02915     }
02916     break;
02917     case ID_THEAD:
02918     case ID_TBODY:
02919     case ID_TFOOT: {
02920       DOM::HTMLTableSectionElement tableSection = element;
02921       switch (token) {
02922       case TableSectionAlign:           { tableSection.setAlign(str); return; }
02923       case TableSectionCh:              { tableSection.setCh(str); return; }
02924       case TableSectionChOff:           { tableSection.setChOff(str); return; }
02925       case TableSectionVAlign:          { tableSection.setVAlign(str); return; }
02926       // read-only: rows
02927       }
02928     }
02929     break;
02930     case ID_TR: {
02931       DOM::HTMLTableRowElement tableRow = element;
02932       switch (token) {
02933       // read-only: rowIndex
02934       // read-only: sectionRowIndex
02935       // read-only: cells
02936       case TableRowAlign:           { tableRow.setAlign(str); return; }
02937       case TableRowBgColor:         { tableRow.setBgColor(str); return; }
02938       case TableRowCh:              { tableRow.setCh(str); return; }
02939       case TableRowChOff:           { tableRow.setChOff(str); return; }
02940       case TableRowVAlign:          { tableRow.setVAlign(str); return; }
02941       }
02942     }
02943     break;
02944     case ID_TH:
02945     case ID_TD: {
02946       DOM::HTMLTableCellElement tableCell = element;
02947       switch (token) {
02948       // read-only: cellIndex
02949       case TableCellAbbr:            { tableCell.setAbbr(str); return; }
02950       case TableCellAlign:           { tableCell.setAlign(str); return; }
02951       case TableCellAxis:            { tableCell.setAxis(str); return; }
02952       case TableCellBgColor:         { tableCell.setBgColor(str); return; }
02953       case TableCellCh:              { tableCell.setCh(str); return; }
02954       case TableCellChOff:           { tableCell.setChOff(str); return; }
02955       case TableCellColSpan:         { tableCell.setColSpan(value.toInteger(exec)); return; }
02956       case TableCellHeaders:         { tableCell.setHeaders(str); return; }
02957       case TableCellHeight:          { tableCell.setHeight(str); return; }
02958       case TableCellNoWrap:          { tableCell.setNoWrap(value.toBoolean(exec)); return; }
02959       case TableCellRowSpan:         { tableCell.setRowSpan(value.toInteger(exec)); return; }
02960       case TableCellScope:           { tableCell.setScope(str); return; }
02961       case TableCellVAlign:          { tableCell.setVAlign(str); return; }
02962       case TableCellWidth:           { tableCell.setWidth(str); return; }
02963       }
02964     }
02965     break;
02966     case ID_FRAMESET: {
02967       DOM::HTMLFrameSetElement frameSet = element;
02968       switch (token) {
02969       case FrameSetCols:            { frameSet.setCols(str); return; }
02970       case FrameSetRows:            { frameSet.setRows(str); return; }
02971       }
02972     }
02973     break;
02974     case ID_FRAME: {
02975       DOM::HTMLFrameElement frameElement = element;
02976       switch (token) {
02977        // read-only: FrameContentDocument:
02978       case FrameFrameBorder:     { frameElement.setFrameBorder(str); return; }
02979       case FrameLongDesc:        { frameElement.setLongDesc(str); return; }
02980       case FrameMarginHeight:    { frameElement.setMarginHeight(str); return; }
02981       case FrameMarginWidth:     { frameElement.setMarginWidth(str); return; }
02982       case FrameName:            { frameElement.setName(str); return; }
02983       case FrameNoResize:        { frameElement.setNoResize(value.toBoolean(exec)); return; }
02984       case FrameScrolling:       { frameElement.setScrolling(str); return; }
02985       case FrameSrc:             { frameElement.setSrc(str); return; }
02986       case FrameLocation:        {
02987                                    static_cast<DOM::HTMLFrameElementImpl *>(frameElement.handle())->setLocation(str);
02988                                    return;
02989                                  }
02990       }
02991     }
02992     break;
02993     case ID_IFRAME: {
02994       DOM::HTMLIFrameElement iFrame = element;
02995       switch (token) {
02996       case IFrameAlign:           { iFrame.setAlign(str); return; }
02997       // read-only: IFrameContentDocument
02998       case IFrameFrameBorder:     { iFrame.setFrameBorder(str); return; }
02999       case IFrameHeight:          { iFrame.setHeight(str); return; }
03000       case IFrameLongDesc:        { iFrame.setLongDesc(str); return; }
03001       case IFrameMarginHeight:    { iFrame.setMarginHeight(str); return; }
03002       case IFrameMarginWidth:     { iFrame.setMarginWidth(str); return; }
03003       case IFrameName:            { iFrame.setName(str); return; }
03004       case IFrameScrolling:       { iFrame.setScrolling(str); return; }
03005       case IFrameSrc:             { iFrame.setSrc(str); return; }
03006       case IFrameWidth:           { iFrame.setWidth(str); return; }
03007       }
03008       break;
03009     }
03010   }
03011 
03012   // generic properties
03013   switch (token) {
03014   case ElementId:
03015     element.setId(str);
03016     return;
03017   case ElementTitle:
03018     element.setTitle(str);
03019     return;
03020   case ElementLang:
03021     element.setLang(str);
03022     return;
03023   case ElementDir:
03024     element.setDir(str);
03025     return;
03026   case ElementClassName:
03027     element.setClassName(str);
03028     return;
03029   case ElementInnerHTML:
03030     element.setInnerHTML(str);
03031     return;
03032   case ElementInnerText:
03033     element.setInnerText(str);
03034     return;
03035   default:
03036     kdDebug(6070) << "WARNING: KJS::HTMLElement::putValueProperty unhandled token " << token << " thisTag=" << element.tagName().string() << " str=" << str.string() << endl;
03037   }
03038 }
03039 
03040 // -------------------------------------------------------------------------
03041 /* Source for HTMLCollectionProtoTable.
03042 @begin HTMLCollectionProtoTable 3
03043   item      HTMLCollection::Item        DontDelete|Function 1
03044   namedItem HTMLCollection::NamedItem   DontDelete|Function 1
03045   tags      HTMLCollection::Tags        DontDelete|Function 1
03046 @end
03047 */
03048 DEFINE_PROTOTYPE("HTMLCollection", HTMLCollectionProto)
03049 IMPLEMENT_PROTOFUNC_DOM(HTMLCollectionProtoFunc)
03050 IMPLEMENT_PROTOTYPE(HTMLCollectionProto,HTMLCollectionProtoFunc)
03051 
03052 const ClassInfo KJS::HTMLCollection::info = { "HTMLCollection", 0, 0, 0 };
03053 
03054 KJS::HTMLCollection::HTMLCollection(ExecState *exec, const DOM::HTMLCollection& c)
03055   : DOMObject(HTMLCollectionProto::self(exec)), collection(c) {}
03056 
03057 KJS::HTMLCollection::~HTMLCollection()
03058 {
03059   ScriptInterpreter::forgetDOMObject(collection.handle());
03060 }
03061 
03062 // We have to implement hasProperty since we don't use a hashtable for 'selectedIndex' and 'length'
03063 // ## this breaks "for (..in..)" though.
03064 bool KJS::HTMLCollection::hasProperty(ExecState *exec, const Identifier &p) const
03065 {
03066   if (p == lengthPropertyName)
03067     return true;
03068   if ( collection.item(0).elementId() == ID_OPTION &&
03069        ( p == "selectedIndex" || p == "value" ) )
03070     return true;
03071   return DOMObject::hasProperty(exec, p);
03072 }
03073 
03074 Value KJS::HTMLCollection::tryGet(ExecState *exec, const Identifier &propertyName) const
03075 {
03076 #ifdef KJS_VERBOSE
03077   kdDebug(6070) << "KJS::HTMLCollection::tryGet " << propertyName.ascii() << endl;
03078 #endif
03079   if (propertyName == lengthPropertyName)
03080   {
03081 #ifdef KJS_VERBOSE
03082     kdDebug(6070) << "  collection length is " << collection.length() << endl;
03083 #endif
03084     return Number(collection.length());
03085   }
03086 
03087   if (collection.item(0).elementId() == ID_OPTION) {
03088     DOM::HTMLSelectElement parentSelect;
03089     DOM::Node node = collection.item(0).parentNode();
03090     while(!node.isNull() && parentSelect.isNull()) {
03091       if(node.elementId() == ID_SELECT)
03092         parentSelect = static_cast<DOM::HTMLSelectElement>(node);
03093       node = node.parentNode();
03094     }
03095     if ( parentSelect.isNull() )
03096       return Undefined();
03097     if (propertyName == "selectedIndex") {
03098       // NON-STANDARD options.selectedIndex
03099       return Number(parentSelect.selectedIndex());
03100     } else if ( propertyName == "value" ) {
03101       // NON-STANDARD options.value
03102       return String(parentSelect.value());
03103     }
03104   }
03105 
03106   // Look in the prototype (for functions) before assuming it's an item's name
03107   Object proto = Object::dynamicCast(prototype());
03108   if (!proto.isNull() && proto.hasProperty(exec,propertyName))
03109     return proto.get(exec,propertyName);
03110 
03111   // name or index ?
03112   bool ok;
03113   unsigned int u = propertyName.toULong(&ok);
03114   if (ok) {
03115     DOM::Node node = collection.item(u);
03116     return getDOMNode(exec,node);
03117   }
03118   else
03119     return getNamedItems(exec,propertyName);
03120 }
03121 
03122 // HTMLCollections are strange objects, they support both get and call,
03123 // so that document.forms.item(0) and document.forms(0) both work.
03124 Value KJS::HTMLCollection::call(ExecState *exec, Object &thisObj, const List &args)
03125 {
03126   // This code duplication is necessary, HTMLCollection isn't a DOMFunction
03127   Value val;
03128   try {
03129     val = tryCall(exec, thisObj, args);
03130   }
03131   // pity there's no way to distinguish between these in JS code
03132   catch (...) {
03133     Object err = Error::create(exec, GeneralError, "Exception from HTMLCollection");
03134     exec->setException(err);
03135   }
03136   return val;
03137 }
03138 
03139 Value KJS::HTMLCollection::tryCall(ExecState *exec, Object &, const List &args)
03140 {
03141   // Do not use thisObj here. It can be the HTMLDocument, in the document.forms(i) case.
03142   /*if( thisObj.imp() != this )
03143   {
03144     kdDebug(6070) << "WARNING: thisObj.imp() != this in HTMLCollection::tryCall" << endl;
03145     KJS::printInfo(exec,"KJS::HTMLCollection::tryCall thisObj",thisObj,-1);
03146     KJS::printInfo(exec,"KJS::HTMLCollection::tryCall this",Value(this),-1);
03147   }*/
03148   // Also, do we need the TypeError test here ?
03149 
03150   if (args.size() == 1) {
03151     // support for document.all(<index>) etc.
03152     bool ok;
03153     UString s = args[0].toString(exec);
03154     unsigned int u = s.toULong(&ok);
03155     if (ok) {
03156       DOM::Element element = collection.item(u);
03157       return getDOMNode(exec,element);
03158     }
03159     // support for document.images('<name>') etc.
03160     return getNamedItems(exec,Identifier(s));
03161   }
03162   else if (args.size() >= 1) // the second arg, if set, is the index of the item we want
03163   {
03164     bool ok;
03165     UString s = args[0].toString(exec);
03166     unsigned int u = args[1].toString(exec).toULong(&ok);
03167     if (ok)
03168     {
03169       DOM::DOMString pstr = s.string();
03170       DOM::Node node = collection.namedItem(pstr);
03171       while (!node.isNull()) {
03172         if (!u)
03173           return getDOMNode(exec,node);
03174         node = collection.nextNamedItem(pstr);
03175         --u;
03176       }
03177     }
03178   }
03179   return Undefined();
03180 }
03181 
03182 Value KJS::HTMLCollection::getNamedItems(ExecState *exec, const Identifier &propertyName) const
03183 {
03184 #ifdef KJS_VERBOSE
03185   kdDebug(6070) << "KJS::HTMLCollection::getNamedItems " << propertyName.ascii() << endl;
03186 #endif
03187   DOM::DOMString pstr = propertyName.string();
03188   DOM::Node node = collection.namedItem(pstr);
03189   if(!node.isNull())
03190   {
03191     DOM::Node next = collection.nextNamedItem(pstr);
03192     if (next.isNull()) // single item
03193     {
03194 #ifdef KJS_VERBOSE
03195       kdDebug(6070) << "returning single node" << endl;
03196 #endif
03197       return getDOMNode(exec,node);
03198     }
03199     else // multiple items, return a collection
03200     {
03201       QValueList<DOM::Node> nodes;
03202       nodes.append(node);
03203       do {
03204         nodes.append(next);
03205         next = collection.nextNamedItem(pstr);
03206       } while (!next.isNull());
03207 #ifdef KJS_VERBOSE
03208       kdDebug(6070) << "returning list of " << nodes.count() << " nodes" << endl;
03209 #endif
03210       return Value(new DOMNamedNodesCollection(exec, nodes));
03211     }
03212   }
03213 #ifdef KJS_VERBOSE
03214   kdDebug(6070) << "not found" << endl;
03215 #endif
03216   return Undefined();
03217 }
03218 
03219 Value KJS::HTMLCollectionProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
03220 {
03221   KJS_CHECK_THIS( KJS::HTMLCollection, thisObj );
03222   DOM::HTMLCollection coll = static_cast<KJS::HTMLCollection *>(thisObj.imp())->toCollection();
03223 
03224   switch (id) {
03225   case KJS::HTMLCollection::Item:
03226     return getDOMNode(exec,coll.item(args[0].toUInt32(exec)));
03227   case KJS::HTMLCollection::Tags:
03228   {
03229     DOM::DOMString tagName = args[0].toString(exec).string();
03230     DOM::NodeList list;
03231     // getElementsByTagName exists in Document and in Element, pick up the right one
03232     if ( coll.base().nodeType() == DOM::Node::DOCUMENT_NODE )
03233     {
03234       DOM::Document doc = coll.base();
03235       list = doc.getElementsByTagName(tagName);
03236 #ifdef KJS_VERBOSE
03237       kdDebug(6070) << "KJS::HTMLCollectionProtoFunc::tryCall document.tags(" << tagName.string() << ") -> " << list.length() << " items in node list" << endl;
03238 #endif
03239     } else
03240     {
03241       DOM::Element e = coll.base();
03242       list = e.getElementsByTagName(tagName);
03243 #ifdef KJS_VERBOSE
03244       kdDebug(6070) << "KJS::HTMLCollectionProtoFunc::tryCall element.tags(" << tagName.string() << ") -> " << list.length() << " items in node list" << endl;
03245 #endif
03246     }
03247     return getDOMNodeList(exec, list);
03248   }
03249   case KJS::HTMLCollection::NamedItem:
03250   {
03251     Value val = static_cast<HTMLCollection *>(thisObj.imp())->getNamedItems(exec, Identifier(args[0].toString(exec)));
03252     // Must return null when asking for a named item that isn't in the collection
03253     // (DOM2 testsuite, HTMLCollection12 test)
03254     if ( val.type() == KJS::UndefinedType )
03255       return Null();
03256     else
03257       return val;
03258   }
03259   default:
03260     return Undefined();
03261   }
03262 }
03263 
03264 Value KJS::HTMLSelectCollection::tryGet(ExecState *exec, const Identifier &p) const
03265 {
03266   if (p == "selectedIndex")
03267     return Number(element.selectedIndex());
03268 
03269   return  HTMLCollection::tryGet(exec, p);
03270 }
03271 
03272 void KJS::HTMLSelectCollection::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int)
03273 {
03274 #ifdef KJS_VERBOSE
03275   kdDebug(6070) << "KJS::HTMLSelectCollection::tryPut " << propertyName.qstring() << endl;
03276 #endif
03277   if ( propertyName == "selectedIndex" ) {
03278     element.setSelectedIndex( value.toInteger( exec ) );
03279     return;
03280   }
03281   // resize ?
03282   else if (propertyName == lengthPropertyName) {
03283     unsigned newLen;
03284     bool converted = value.toUInt32(newLen);
03285 
03286     if (!converted) {
03287       return;
03288     }
03289 
03290     long diff = element.length() - newLen;
03291 
03292     if (diff < 0) { // add dummy elements
03293       do {
03294         element.add(element.ownerDocument().createElement("OPTION"), DOM::HTMLElement());
03295       } while (++diff);
03296     }
03297     else // remove elements
03298       while (diff-- > 0)
03299         element.remove(newLen);
03300 
03301     return;
03302   }
03303   // an index ?
03304   bool ok;
03305   unsigned int u = propertyName.toULong(&ok);
03306   if (!ok)
03307     return;
03308 
03309   if (value.isA(NullType) || value.isA(UndefinedType)) {
03310     // null and undefined delete. others, too ?
03311     element.remove(u);
03312     return;
03313   }
03314 
03315   // is v an option element ?
03316   DOM::Node node = KJS::toNode(value);
03317   if (node.isNull() || node.elementId() != ID_OPTION)
03318     return;
03319 
03320   DOM::HTMLOptionElement option = static_cast<DOM::HTMLOptionElement>(node);
03321   if ( option.ownerDocument() != element.ownerDocument() )
03322     option = static_cast<DOM::HTMLOptionElement>(element.ownerDocument().importNode(option, true));
03323   long diff = long(u) - element.length();
03324   DOM::HTMLElement before;
03325   // out of array bounds ? first insert empty dummies
03326   if (diff > 0) {
03327     while (diff--) {
03328       element.add(element.ownerDocument().createElement("OPTION"), before);
03329     }
03330     // replace an existing entry ?
03331   } else if (diff < 0) {
03332     before = element.options().item(u+1);
03333     element.remove(u);
03334   }
03335   // finally add the new element
03336   element.add(option, before);
03337 }
03338 
03340 
03341 OptionConstructorImp::OptionConstructorImp(ExecState *exec, const DOM::Document &d)
03342     : ObjectImp(), doc(d)
03343 {
03344   // ## isn't there some redundancy between ObjectImp::_proto and the "prototype" property ?
03345   //put(exec,"prototype", ...,DontEnum|DontDelete|ReadOnly);
03346 
03347   // no. of arguments for constructor
03348   // ## is 4 correct ? 0 to 4, it seems to be
03349   put(exec,lengthPropertyName, Number(4), ReadOnly|DontDelete|DontEnum);
03350 }
03351 
03352 bool OptionConstructorImp::implementsConstruct() const
03353 {
03354   return true;
03355 }
03356 
03357 Object OptionConstructorImp::construct(ExecState *exec, const List &args)
03358 {
03359   DOM::Element el = doc.createElement("OPTION");
03360   DOM::HTMLOptionElement opt = static_cast<DOM::HTMLOptionElement>(el);
03361   int sz = args.size();
03362   DOM::Text t = doc.createTextNode("");
03363   try { opt.appendChild(t); }
03364   catch(DOM::DOMException& e) {
03365     // #### exec->setException ?
03366   }
03367   if (sz > 0)
03368     t.setData(args[0].toString(exec).string()); // set the text
03369   if (sz > 1)
03370     opt.setValue(args[1].toString(exec).string());
03371   if (sz > 2)
03372     opt.setDefaultSelected(args[2].toBoolean(exec));
03373   if (sz > 3)
03374     opt.setSelected(args[3].toBoolean(exec));
03375 
03376   return Object::dynamicCast(getDOMNode(exec,opt));
03377 }
03378 
03380 
03381 ImageConstructorImp::ImageConstructorImp(ExecState *, const DOM::Document &d)
03382     : ObjectImp(), doc(d)
03383 {
03384 }
03385 
03386 bool ImageConstructorImp::implementsConstruct() const
03387 {
03388   return true;
03389 }
03390 
03391 Object ImageConstructorImp::construct(ExecState *exec, const List &)
03392 {
03393   /* TODO: fetch optional height & width from arguments */
03394 
03395   Object result(new Image(exec, doc));
03396   /* TODO: do we need a prototype ? */
03397 
03398   return result;
03399 }
03400 
03401 const ClassInfo KJS::Image::info = { "Image", 0, &ImageTable, 0 };
03402 
03403 /* Source for ImageTable.
03404 @begin ImageTable 5
03405   src       Image::Src      DontDelete
03406   width     Image::Width        DontDelete|ReadOnly
03407   height    Image::Height       DontDelete|ReadOnly
03408   complete  Image::Complete     DontDelete|ReadOnly
03409   onload    Image::OnLoad       DontDelete
03410 @end
03411 */
03412 Image::Image(ExecState* exec, const DOM::Document &d)
03413   : DOMObject(exec->interpreter()->builtinObjectPrototype()), doc(d), img(0),
03414   m_onLoadListener(0L)
03415 {
03416 }
03417 
03418 Value Image::tryGet(ExecState *exec, const Identifier &propertyName) const
03419 {
03420   return DOMObjectLookupGetValue<Image,DOMObject>(exec, propertyName, &ImageTable, this);
03421 }
03422 
03423 Value Image::getValueProperty(ExecState *, int token) const
03424 {
03425   switch (token) {
03426   case Src:
03427     return String(src);
03428   case Complete:
03429     return Boolean(!img || img->status() >= khtml::CachedObject::Persistent);
03430   case Width:
03431     if ( !img )
03432       return Undefined();
03433     return Number(img->pixmap_size().width());
03434   case Height:
03435     if ( !img )
03436       return Undefined();
03437     return Number(img->pixmap_size().height());
03438   case OnLoad:
03439     if ( m_onLoadListener )
03440       return m_onLoadListener->listenerObj();
03441     return Undefined();
03442   default:
03443     kdDebug(6070) << "WARNING: Image::getValueProperty unhandled token " << token << endl;
03444     return Value();
03445   }
03446 }
03447 
03448 void Image::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
03449 {
03450   DOMObjectLookupPut<Image, DOMObject>( exec, propertyName, value, attr, &ImageTable, this );
03451 }
03452 
03453 void Image::putValueProperty(ExecState *exec, int token, const Value& value, int)
03454 {
03455   switch (token) {
03456   case Src: {
03457     String str = value.toString(exec);
03458     src = str.value();
03459     if ( img ) img->deref(this);
03460     img = static_cast<DOM::DocumentImpl*>( doc.handle() )->docLoader()->requestImage( src.string() );
03461 // ### img = doc ? doc->docLoader()->requestImage( src.string() ) : 0;
03462     if ( img ) img->ref(this);
03463     break;
03464   }
03465   case OnLoad:
03466     if ( m_onLoadListener )
03467         m_onLoadListener->deref();
03468     m_onLoadListener = Window::retrieveActive(exec)->getJSEventListener(value,true);
03469     if ( m_onLoadListener )
03470         m_onLoadListener->ref();
03471     break;
03472   default:
03473     kdDebug(6070) << "WARNING: Image::putValueProperty unhandled token " << token << endl;
03474   }
03475 }
03476 
03477 void Image::notifyFinished(khtml::CachedObject * finishedObj)
03478 {
03479   if (img == finishedObj /*&& !loadEventSent*/ && m_onLoadListener ) {
03480     //loadEventSent = true;
03481     DOM::EventImpl *evt = new DOM::EventImpl( (DOM::EventImpl::EventId)ATTR_ONLOAD, false, false );
03482     evt->setTarget( 0 );
03483     evt->ref();
03484     DOM::Event e(evt);
03485     Object thisObj( this );
03486     m_onLoadListener->hackSetThisObj( thisObj );
03487     m_onLoadListener->handleEvent( e );
03488     if ( m_onLoadListener ) // #57195
03489         m_onLoadListener->hackUnsetThisObj();
03490     evt->deref();
03491   }
03492 }
03493 
03494 Image::~Image()
03495 {
03496   if ( img ) img->deref(this);
03497   if ( m_onLoadListener )
03498       m_onLoadListener->deref();
03499 }
03500 
03501 Value KJS::getHTMLCollection(ExecState *exec, const DOM::HTMLCollection& c)
03502 {
03503   return cacheDOMObject<DOM::HTMLCollection, KJS::HTMLCollection>(exec, c);
03504 }
03505 
03506 Value KJS::getSelectHTMLCollection(ExecState *exec, const DOM::HTMLCollection& c, const DOM::HTMLSelectElement& e)
03507 {
03508   DOMObject *ret;
03509   if (c.isNull())
03510     return Null();
03511   ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
03512   if ((ret = interp->getDOMObject(c.handle())))
03513     return Value(ret);
03514   else {
03515     ret = new HTMLSelectCollection(exec, c, e);
03516     interp->putDOMObject(c.handle(),ret);
03517     return Value(ret);
03518   }
03519 }
KDE Logo
This file is part of the documentation for khtml Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:37:22 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003