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