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 String(element.innerHTML());
01946   case ElementInnerText:
01947     return String(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           QString caption;
02140 
02141           // if there is a frame with the target name, don't block
02142           if ( view && view->part() )  {
02143             if (!view->part()->url().host().isEmpty())
02144               caption = view->part()->url().host() + " - ";
02145             // search all (possibly nested) framesets
02146             KHTMLPart *currentPart = view->part()->parentPart();
02147             while( currentPart != 0L ) {
02148               if( currentPart->frameExists( form.target().string() ) )
02149                 block = false;
02150               currentPart = currentPart->parentPart();
02151             }
02152           }
02153 
02154           if ( block && policy == KHTMLSettings::KJSWindowOpenAsk && view ) {
02155             if (view && view->part())
02156             emit view->part()->browserExtension()->requestFocus(view->part());
02157             caption += i18n( "Confirmation: JavaScript Popup" );
02158             if ( KMessageBox::questionYesNo(view, form.action().isEmpty() ?
02159                    i18n( "This site is submitting a form which will open up a new browser "
02160                          "window via JavaScript.\n"
02161                          "Do you want to allow the form to be submitted?" ) :
02162                    i18n( "<qt>This site is submitting a form which will open <p>%1</p> in a new browser window via JavaScript.<br />"
02163                          "Do you want to allow the form to be submitted?</qt>").arg(KStringHandler::csqueeze(form.action().string(),  100)),
02164                    caption ) == KMessageBox::Yes )
02165               block = false;
02166 
02167           } else if ( block && policy == KHTMLSettings::KJSWindowOpenSmart ) {
02168             if( static_cast<KJS::ScriptInterpreter *>(exec->interpreter())->isWindowOpenAllowed() ) {
02169               // This submission has been triggered by the user
02170               block = false;
02171             }
02172           }
02173         }
02174 
02175         if( !block )
02176           form.submit();
02177 
02178         return Undefined();
02179       }
02180       else if (id == KJS::HTMLElement::FormReset) {
02181         form.reset();
02182         return Undefined();
02183       }
02184     }
02185     break;
02186     case ID_SELECT: {
02187       DOM::HTMLSelectElement select = element;
02188       if (id == KJS::HTMLElement::SelectAdd) {
02189         select.add(KJS::toNode(args[0]),KJS::toNode(args[1]));
02190         return Undefined();
02191       }
02192       else if (id == KJS::HTMLElement::SelectRemove) {
02193         select.remove(int(args[0].toNumber(exec)));
02194         return Undefined();
02195       }
02196       else if (id == KJS::HTMLElement::SelectBlur) {
02197         select.blur();
02198         return Undefined();
02199       }
02200       else if (id == KJS::HTMLElement::SelectFocus) {
02201         select.focus();
02202         return Undefined();
02203       }
02204     }
02205     break;
02206     case ID_INPUT: {
02207       DOM::HTMLInputElement input = element;
02208       if (id == KJS::HTMLElement::InputBlur) {
02209         input.blur();
02210         return Undefined();
02211       }
02212       else if (id == KJS::HTMLElement::InputFocus) {
02213         input.focus();
02214         return Undefined();
02215       }
02216       else if (id == KJS::HTMLElement::InputSelect) {
02217         input.select();
02218         return Undefined();
02219       }
02220       else if (id == KJS::HTMLElement::InputClick) {
02221         input.click();
02222         return Undefined();
02223       }
02224     }
02225     break;
02226     case ID_TEXTAREA: {
02227       DOM::HTMLTextAreaElement textarea = element;
02228       if (id == KJS::HTMLElement::TextAreaBlur) {
02229         textarea.blur();
02230         return Undefined();
02231       }
02232       else if (id == KJS::HTMLElement::TextAreaFocus) {
02233         textarea.focus();
02234         return Undefined();
02235       }
02236       else if (id == KJS::HTMLElement::TextAreaSelect) {
02237         textarea.select();
02238         return Undefined();
02239       }
02240     }
02241     break;
02242     case ID_A: {
02243       DOM::HTMLAnchorElement anchor = element;
02244       if (id == KJS::HTMLElement::AnchorBlur) {
02245         anchor.blur();
02246         return Undefined();
02247       }
02248       else if (id == KJS::HTMLElement::AnchorFocus) {
02249         anchor.focus();
02250         return Undefined();
02251       }
02252     }
02253     break;
02254     case ID_TABLE: {
02255       DOM::HTMLTableElement table = element;
02256       if (id == KJS::HTMLElement::TableCreateTHead)
02257         return getDOMNode(exec,table.createTHead());
02258       else if (id == KJS::HTMLElement::TableDeleteTHead) {
02259         table.deleteTHead();
02260         return Undefined();
02261       }
02262       else if (id == KJS::HTMLElement::TableCreateTFoot)
02263         return getDOMNode(exec,table.createTFoot());
02264       else if (id == KJS::HTMLElement::TableDeleteTFoot) {
02265         table.deleteTFoot();
02266         return Undefined();
02267       }
02268       else if (id == KJS::HTMLElement::TableCreateCaption)
02269         return getDOMNode(exec,table.createCaption());
02270       else if (id == KJS::HTMLElement::TableDeleteCaption) {
02271         table.deleteCaption();
02272         return Undefined();
02273       }
02274       else if (id == KJS::HTMLElement::TableInsertRow)
02275         return getDOMNode(exec,table.insertRow(args[0].toInteger(exec)));
02276       else if (id == KJS::HTMLElement::TableDeleteRow) {
02277         table.deleteRow(args[0].toInteger(exec));
02278         return Undefined();
02279       }
02280     }
02281     break;
02282     case ID_THEAD:
02283     case ID_TBODY:
02284     case ID_TFOOT: {
02285       DOM::HTMLTableSectionElement tableSection = element;
02286       if (id == KJS::HTMLElement::TableSectionInsertRow)
02287         return getDOMNode(exec,tableSection.insertRow(args[0].toInteger(exec)));
02288       else if (id == KJS::HTMLElement::TableSectionDeleteRow) {
02289         tableSection.deleteRow(args[0].toInteger(exec));
02290         return Undefined();
02291       }
02292     }
02293     break;
02294     case ID_TR: {
02295       DOM::HTMLTableRowElement tableRow = element;
02296       if (id == KJS::HTMLElement::TableRowInsertCell)
02297         return getDOMNode(exec,tableRow.insertCell(args[0].toInteger(exec)));
02298       else if (id == KJS::HTMLElement::TableRowDeleteCell) {
02299         tableRow.deleteCell(args[0].toInteger(exec));
02300         return Undefined();
02301       }
02302       break;
02303     }
02304     case ID_MARQUEE: {
02305       if (id == KJS::HTMLElement::MarqueeStart && element.handle()->renderer() &&
02306         element.handle()->renderer()->layer() &&
02307         element.handle()->renderer()->layer()->marquee()) {
02308         element.handle()->renderer()->layer()->marquee()->start();
02309         return Undefined();
02310       }
02311       else if (id == KJS::HTMLElement::MarqueeStop && element.handle()->renderer() &&
02312               element.handle()->renderer()->layer() &&
02313               element.handle()->renderer()->layer()->marquee()) {
02314         element.handle()->renderer()->layer()->marquee()->stop();
02315         return Undefined();
02316       }
02317       break;
02318     }
02319   }
02320 
02321   return Undefined();
02322 }
02323 
02324 void KJS::HTMLElement::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
02325 {
02326 #ifdef KJS_VERBOSE
02327   DOM::DOMString str = value.isA(NullType) ? DOM::DOMString() : value.toString(exec).string();
02328 #endif
02329   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02330 #ifdef KJS_VERBOSE
02331   kdDebug(6070) << "KJS::HTMLElement::tryPut " << propertyName.qstring()
02332                 << " thisTag=" << element.tagName().string()
02333                 << " str=" << str.string() << endl;
02334 #endif
02335   // First look at dynamic properties
02336   switch (element.elementId()) {
02337     case ID_SELECT: {
02338       DOM::HTMLSelectElement select = element;
02339       bool ok;
02340       /*uint u =*/ propertyName.toULong(&ok);
02341       if (ok) {
02342         Object coll = Object::dynamicCast( getSelectHTMLCollection(exec, select.options(), select) );
02343         if ( !coll.isNull() )
02344           coll.put(exec,propertyName,value);
02345         return;
02346       }
02347       break;
02348     }
02349     case ID_APPLET:
02350     case ID_OBJECT:
02351     case ID_EMBED: {
02352       DOM::HTMLObjectBaseElementImpl * elm = static_cast<DOM::HTMLObjectBaseElementImpl*>(element.handle());
02353       if (elm && elm->put(0, propertyName.qstring(),
02354                           value.toString(exec).qstring()))
02355           return;
02356       break;
02357     }
02358     default:
02359       break;
02360   }
02361 
02362   const HashTable* table = classInfo()->propHashTable; // get the right hashtable
02363   const HashEntry* entry = Lookup::findEntry(table, propertyName);
02364   if (entry) {
02365     if (entry->attr & Function) // function: put as override property
02366     {
02367       ObjectImp::put(exec, propertyName, value, attr);
02368       return;
02369     }
02370     else if ((entry->attr & ReadOnly) == 0) // let DOMObjectLookupPut print the warning if not
02371     {
02372       putValueProperty(exec, entry->value, value, attr);
02373       return;
02374     }
02375   }
02376   DOMObjectLookupPut<KJS::HTMLElement, DOMElement>(exec, propertyName, value, attr, &KJS::HTMLElementTable, this);
02377 }
02378 
02379 void KJS::HTMLElement::putValueProperty(ExecState *exec, int token, const Value& value, int)
02380 {
02381   DOM::DOMString str = value.isA(NullType) ? DOM::DOMString() : value.toString(exec).string();
02382   DOMNode *kjsNode = new DOMNode(exec, KJS::toNode(value));
02383   // Need to create a Value wrapper to avoid leaking the KJS::DOMNode
02384   Value nodeValue(kjsNode);
02385   DOM::Node n = kjsNode->toNode();
02386   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02387 #ifdef KJS_VERBOSE
02388   kdDebug(6070) << "KJS::HTMLElement::putValueProperty "
02389                 << " thisTag=" << element.tagName().string()
02390                 << " token=" << token << endl;
02391 #endif
02392 
02393   switch (element.elementId()) {
02394   case ID_HTML: {
02395       DOM::HTMLHtmlElement html = element;
02396       switch (token) {
02397       case HtmlVersion:         { html.setVersion(str); return; }
02398       }
02399   }
02400   break;
02401   case ID_HEAD: {
02402     DOM::HTMLHeadElement head = element;
02403     switch (token) {
02404     case HeadProfile:         { head.setProfile(str); return; }
02405     }
02406   }
02407   break;
02408   case ID_LINK: {
02409     DOM::HTMLLinkElement link = element;
02410     switch (token) {
02411       case LinkDisabled:        { link.setDisabled(value.toBoolean(exec)); return; }
02412       case LinkCharset:         { link.setCharset(str); return; }
02413       case LinkHref:            { link.setHref(str); return; }
02414       case LinkHrefLang:        { link.setHreflang(str); return; }
02415       case LinkMedia:           { link.setMedia(str); return; }
02416       case LinkRel:             { link.setRel(str); return; }
02417       case LinkRev:             { link.setRev(str); return; }
02418       case LinkTarget:          { link.setTarget(str); return; }
02419       case LinkType:            { link.setType(str); return; }
02420       }
02421     }
02422     break;
02423     case ID_TITLE: {
02424       DOM::HTMLTitleElement title = element;
02425       switch (token) {
02426       case TitleText:                 { title.setText(str); return; }
02427       }
02428     }
02429     break;
02430     case ID_META: {
02431       DOM::HTMLMetaElement meta = element;
02432       switch (token) {
02433       case MetaContent:         { meta.setContent(str); return; }
02434       case MetaHttpEquiv:       { meta.setHttpEquiv(str); return; }
02435       case MetaName:            { meta.setName(str); return; }
02436       case MetaScheme:          { meta.setScheme(str); return; }
02437       }
02438     }
02439     break;
02440     case ID_BASE: {
02441       DOM::HTMLBaseElement base = element;
02442       switch (token) {
02443       case BaseHref:            { base.setHref(str); return; }
02444       case BaseTarget:          { base.setTarget(str); return; }
02445       }
02446     }
02447     break;
02448     case ID_ISINDEX: {
02449       DOM::HTMLIsIndexElement isindex = element;
02450       switch (token) {
02451       // read-only: form
02452       case IsIndexPrompt:               { isindex.setPrompt(str); return; }
02453       }
02454     }
02455     break;
02456     case ID_STYLE: {
02457       DOM::HTMLStyleElement style = element;
02458       switch (token) {
02459       case StyleDisabled:        { style.setDisabled(value.toBoolean(exec)); return; }
02460       case StyleMedia:           { style.setMedia(str); return; }
02461       case StyleType:            { style.setType(str); return; }
02462       }
02463     }
02464     break;
02465     case ID_BODY: {
02466       DOM::HTMLBodyElement body = element;
02467       switch (token) {
02468       case BodyALink:           { body.setALink(str); return; }
02469       case BodyBackground:      { body.setBackground(str); return; }
02470       case BodyBgColor:         { body.setBgColor(str); return; }
02471       case BodyLink:            { body.setLink(str); return; }
02472       case BodyText:            { body.setText(str); return; }
02473       case BodyVLink:           { body.setVLink(str); return; }
02474       case BodyScrollLeft:
02475       case BodyScrollTop: {
02476         QScrollView* sview = body.ownerDocument().view();
02477         if (sview) {
02478           // Update the document's layout before we compute these attributes.
02479           DOM::DocumentImpl* docimpl = body.handle()->getDocument();
02480           if (docimpl)
02481             docimpl->updateLayout();
02482           if (token == BodyScrollLeft)
02483             sview->setContentsPos(value.toInteger(exec), sview->contentsY());
02484           else
02485             sview->setContentsPos(sview->contentsX(), value.toInteger(exec));
02486           }
02487         return;
02488         }
02489       }
02490     }
02491     break;
02492     case ID_FORM: {
02493       DOM::HTMLFormElement form = element;
02494       switch (token) {
02495       // read-only: elements
02496       // read-only: length
02497       case FormName:            { form.setName(str); return; }
02498       case FormAcceptCharset:   { form.setAcceptCharset(str); return; }
02499       case FormAction:          { form.setAction(str.string()); return; }
02500       case FormEncType:         { form.setEnctype(str); return; }
02501       case FormMethod:          { form.setMethod(str); return; }
02502       case FormTarget:          { form.setTarget(str); return; }
02503       }
02504     }
02505     break;
02506     case ID_SELECT: {
02507       DOM::HTMLSelectElement select = element;
02508       switch (token) {
02509       // read-only: type
02510       case SelectSelectedIndex:   { select.setSelectedIndex(value.toInteger(exec)); return; }
02511       case SelectValue:           { select.setValue(str); return; }
02512       case SelectLength:          { // read-only according to the NS spec, but webpages need it writeable
02513                                          Object coll = Object::dynamicCast( getSelectHTMLCollection(exec, select.options(), select) );
02514                                          if ( !coll.isNull() )
02515                                            coll.put(exec,"length",value);
02516                                          return;
02517                                        }
02518       // read-only: form
02519       // read-only: options
02520       case SelectDisabled:        { select.setDisabled(value.toBoolean(exec)); return; }
02521       case SelectMultiple:        { select.setMultiple(value.toBoolean(exec)); return; }
02522       case SelectName:            { select.setName(str); return; }
02523       case SelectSize:            { select.setSize(value.toInteger(exec)); return; }
02524       case SelectTabIndex:        { select.setTabIndex(value.toInteger(exec)); return; }
02525       }
02526     }
02527     break;
02528     case ID_OPTGROUP: {
02529       DOM::HTMLOptGroupElement optgroup = element;
02530       switch (token) {
02531       case OptGroupDisabled:        { optgroup.setDisabled(value.toBoolean(exec)); return; }
02532       case OptGroupLabel:           { optgroup.setLabel(str); return; }
02533       }
02534     }
02535     break;
02536     case ID_OPTION: {
02537       DOM::HTMLOptionElement option = element;
02538       switch (token) {
02539       // read-only: form
02540       case OptionDefaultSelected: { option.setDefaultSelected(value.toBoolean(exec)); return; }
02541       // read-only: text  <--- According to the DOM, but JavaScript and JScript both allow changes.
02542       // So, we'll do it here and not add it to our DOM headers.
02543       case OptionText:            { DOM::NodeList nl(option.childNodes());
02544                                     for (unsigned int i = 0; i < nl.length(); i++) {
02545                                         if (nl.item(i).nodeType() == DOM::Node::TEXT_NODE) {
02546                                             static_cast<DOM::Text>(nl.item(i)).setData(str);
02547                                             return;
02548                                         }
02549                                   }
02550                                   // No child text node found, creating one
02551                                   DOM::Text t = option.ownerDocument().createTextNode(str);
02552                                   try { option.appendChild(t); }
02553                                   catch(DOM::DOMException& e) {
02554                                     // #### exec->setException ?
02555                                   }
02556 
02557                                   return;
02558       }
02559       // read-only: index
02560       case OptionDisabled:        { option.setDisabled(value.toBoolean(exec)); return; }
02561       case OptionLabel:           { option.setLabel(str); return; }
02562       case OptionSelected:        { option.setSelected(value.toBoolean(exec)); return; }
02563       case OptionValue:           { option.setValue(str); return; }
02564       }
02565     }
02566     break;
02567     case ID_INPUT: {
02568       DOM::HTMLInputElement input = element;
02569       switch (token) {
02570       case InputDefaultValue:    { input.setDefaultValue(str); return; }
02571       case InputDefaultChecked:  { input.setDefaultChecked(value.toBoolean(exec)); return; }
02572       // read-only: form
02573       case InputAccept:          { input.setAccept(str); return; }
02574       case InputAccessKey:       { input.setAccessKey(str); return; }
02575       case InputAlign:           { input.setAlign(str); return; }
02576       case InputAlt:             { input.setAlt(str); return; }
02577       case InputChecked:         { input.setChecked(value.toBoolean(exec)); return; }
02578       case InputDisabled:        { input.setDisabled(value.toBoolean(exec)); return; }
02579       case InputMaxLength:       { input.setMaxLength(value.toInteger(exec)); return; }
02580       case InputName:            { input.setName(str); return; }
02581       case InputReadOnly:        { input.setReadOnly(value.toBoolean(exec)); return; }
02582       case InputSize:            { input.setSize(value.toInteger(exec)); return; }
02583       case InputSrc:             { input.setSrc(str); return; }
02584       case InputTabIndex:        { input.setTabIndex(value.toInteger(exec)); return; }
02585       case InputType:            { input.setType(str); return; }
02586       case InputUseMap:          { input.setUseMap(str); return; }
02587       case InputValue:           { input.setValue(str); return; }
02588       }
02589     }
02590     break;
02591     case ID_TEXTAREA: {
02592       DOM::HTMLTextAreaElement textarea = element;
02593       switch (token) {
02594       case TextAreaDefaultValue:    { textarea.setDefaultValue(str); return; }
02595       // read-only: form
02596       case TextAreaAccessKey:       { textarea.setAccessKey(str); return; }
02597       case TextAreaCols:            { textarea.setCols(value.toInteger(exec)); return; }
02598       case TextAreaDisabled:        { textarea.setDisabled(value.toBoolean(exec)); return; }
02599       case TextAreaName:            { textarea.setName(str); return; }
02600       case TextAreaReadOnly:        { textarea.setReadOnly(value.toBoolean(exec)); return; }
02601       case TextAreaRows:            { textarea.setRows(value.toInteger(exec)); return; }
02602       case TextAreaTabIndex:        { textarea.setTabIndex(value.toInteger(exec)); return; }
02603       // read-only: type
02604       case TextAreaValue:           { textarea.setValue(str); return; }
02605       }
02606     }
02607     break;
02608     case ID_BUTTON: {
02609       DOM::HTMLButtonElement button = element;
02610       switch (token) {
02611       // read-only: form
02612       case ButtonAccessKey:       { button.setAccessKey(str); return; }
02613       case ButtonDisabled:        { button.setDisabled(value.toBoolean(exec)); return; }
02614       case ButtonName:            { button.setName(str); return; }
02615       case ButtonTabIndex:        { button.setTabIndex(value.toInteger(exec)); return; }
02616       // read-only: type
02617       case ButtonValue:           { button.setValue(str); return; }
02618       }
02619     }
02620     break;
02621     case ID_LABEL: {
02622       DOM::HTMLLabelElement label = element;
02623       switch (token) {
02624       // read-only: form
02625       case LabelAccessKey:       { label.setAccessKey(str); return; }
02626       case LabelHtmlFor:         { label.setHtmlFor(str); return; }
02627       }
02628     }
02629     break;
02630 //    case ID_FIELDSET: {
02631 //      DOM::HTMLFieldSetElement fieldSet = element;
02632 //      // read-only: form
02633 //    }
02634 //    break;
02635     case ID_LEGEND: {
02636       DOM::HTMLLegendElement legend = element;
02637       switch (token) {
02638       // read-only: form
02639       case LegendAccessKey:       { legend.setAccessKey(str); return; }
02640       case LegendAlign:           { legend.setAlign(str); return; }
02641       }
02642     }
02643     break;
02644     case ID_UL: {
02645       DOM::HTMLUListElement uList = element;
02646       switch (token) {
02647       case UListCompact:         { uList.setCompact(value.toBoolean(exec)); return; }
02648       case UListType:            { uList.setType(str); return; }
02649       }
02650     }
02651     break;
02652     case ID_OL: {
02653       DOM::HTMLOListElement oList = element;
02654       switch (token) {
02655       case OListCompact:         { oList.setCompact(value.toBoolean(exec)); return; }
02656       case OListStart:           { oList.setStart(value.toInteger(exec)); return; }
02657       case OListType:            { oList.setType(str); return; }
02658       }
02659     }
02660     break;
02661     case ID_DL: {
02662       DOM::HTMLDListElement dList = element;
02663       switch (token) {
02664       case DListCompact:         { dList.setCompact(value.toBoolean(exec)); return; }
02665       }
02666     }
02667     break;
02668     case ID_DIR: {
02669       DOM::HTMLDirectoryElement directory = element;
02670       switch (token) {
02671       case DirectoryCompact:     { directory.setCompact(value.toBoolean(exec)); return; }
02672       }
02673     }
02674     break;
02675     case ID_MENU: {
02676       DOM::HTMLMenuElement menu = element;
02677       switch (token) {
02678       case MenuCompact:         { menu.setCompact(value.toBoolean(exec)); return; }
02679       }
02680     }
02681     break;
02682     case ID_LI: {
02683       DOM::HTMLLIElement li = element;
02684       switch (token) {
02685       case LIType:            { li.setType(str); return; }
02686       case LIValue:           { li.setValue(value.toInteger(exec)); return; }
02687       }
02688     }
02689     break;
02690     case ID_DIV: {
02691       DOM::HTMLDivElement div = element;
02692       switch (token) {
02693       case DivAlign:           { div.setAlign(str); return; }
02694       }
02695     }
02696     break;
02697     case ID_P: {
02698       DOM::HTMLParagraphElement paragraph = element;
02699       switch (token) {
02700       case ParagraphAlign:     { paragraph.setAlign(str); return; }
02701       }
02702     }
02703     break;
02704     case ID_H1:
02705     case ID_H2:
02706     case ID_H3:
02707     case ID_H4:
02708     case ID_H5:
02709     case ID_H6: {
02710       DOM::HTMLHeadingElement heading = element;
02711       switch (token) {
02712       case HeadingAlign:         { heading.setAlign(str); return; }
02713       }
02714     }
02715     break;
02716     case ID_BLOCKQUOTE: {
02717       DOM::HTMLBlockquoteElement blockquote = element;
02718       switch (token) {
02719       case BlockQuoteCite:       { blockquote.setCite(str); return; }
02720       }
02721     }
02722     break;
02723     case ID_Q: {
02724       DOM::HTMLQuoteElement quote = element;
02725       switch (token) {
02726       case QuoteCite:            { quote.setCite(str); return; }
02727       }
02728     }
02729     break;
02730     case ID_PRE: {
02731       DOM::HTMLPreElement pre = element;
02732       switch (token) {
02733       case PreWidth:           { pre.setWidth(value.toInteger(exec)); return; }
02734       }
02735     }
02736     break;
02737     case ID_BR: {
02738       DOM::HTMLBRElement br = element;
02739       switch (token) {
02740       case BRClear:           { br.setClear(str); return; }
02741       }
02742     }
02743     break;
02744     case ID_BASEFONT: {
02745       DOM::HTMLBaseFontElement baseFont = element;
02746       switch (token) {
02747       case BaseFontColor:           { baseFont.setColor(str); return; }
02748       case BaseFontFace:            { baseFont.setFace(str); return; }
02749       case BaseFontSize:            { baseFont.setSize(value.toInteger(exec)); return; }
02750       }
02751     }
02752     break;
02753     case ID_FONT: {
02754       DOM::HTMLFontElement font = element;
02755       switch (token) {
02756       case FontColor:           { font.setColor(str); return; }
02757       case FontFace:            { font.setFace(str); return; }
02758       case FontSize:            { font.setSize(str); return; }
02759       }
02760     }
02761     break;
02762     case ID_HR: {
02763       DOM::HTMLHRElement hr = element;
02764       switch (token) {
02765       case HRAlign:           { hr.setAlign(str); return; }
02766       case HRNoShade:         { hr.setNoShade(value.toBoolean(exec)); return; }
02767       case HRSize:            { hr.setSize(str); return; }
02768       case HRWidth:           { hr.setWidth(str); return; }
02769       }
02770     }
02771     break;
02772     case ID_INS:
02773     case ID_DEL: {
02774       DOM::HTMLModElement mod = element;
02775       switch (token) {
02776       case ModCite:            { mod.setCite(str); return; }
02777       case ModDateTime:        { mod.setDateTime(str); return; }
02778       }
02779     }
02780     break;
02781     case ID_A: {
02782       DOM::HTMLAnchorElement anchor = element;
02783       switch (token) {
02784       case AnchorAccessKey:       { anchor.setAccessKey(str); return; }
02785       case AnchorCharset:         { anchor.setCharset(str); return; }
02786       case AnchorCoords:          { anchor.setCoords(str); return; }
02787       case AnchorHref:            { anchor.setHref(str); return; }
02788       case AnchorHrefLang:        { anchor.setHreflang(str); return; }
02789       case AnchorName:            { anchor.setName(str); return; }
02790       case AnchorRel:             { anchor.setRel(str); return; }
02791       case AnchorRev:             { anchor.setRev(str); return; }
02792       case AnchorShape:           { anchor.setShape(str); return; }
02793       case AnchorTabIndex:        { anchor.setTabIndex(value.toInteger(exec)); return; }
02794       case AnchorTarget:          { anchor.setTarget(str); return; }
02795       case AnchorType:            { anchor.setType(str); return; }
02796       }
02797     }
02798     break;
02799     case ID_IMG: {
02800       DOM::HTMLImageElement image = element;
02801       switch (token) {
02802       case ImageName:            { image.setName(str); return; }
02803       case ImageAlign:           { image.setAlign(str); return; }
02804       case ImageAlt:             { image.setAlt(str); return; }
02805       case ImageBorder:          { image.setBorder(str); return; }
02806       case ImageHeight:          { image.setHeight(value.toInteger(exec)); return; }
02807       case ImageHspace:          { image.setHspace(value.toInteger(exec)); return; }
02808       case ImageIsMap:           { image.setIsMap(value.toBoolean(exec)); return; }
02809       case ImageLongDesc:        { image.setLongDesc(str); return; }
02810       case ImageSrc:             { image.setSrc(str); return; }
02811       case ImageUseMap:          { image.setUseMap(str); return; }
02812       case ImageVspace:          { image.setVspace(value.toInteger(exec)); return; }
02813       case ImageWidth:           { image.setWidth(value.toInteger(exec)); return; }
02814       }
02815     }
02816     break;
02817     case ID_OBJECT: {
02818       DOM::HTMLObjectElement object = element;
02819       switch (token) {
02820       // read-only: form
02821       case ObjectCode:                 { object.setCode(str); return; }
02822       case ObjectAlign:           { object.setAlign(str); return; }
02823       case ObjectArchive:         { object.setArchive(str); return; }
02824       case ObjectBorder:          { object.setBorder(str); return; }
02825       case ObjectCodeBase:        { object.setCodeBase(str); return; }
02826       case ObjectCodeType:        { object.setCodeType(str); return; }
02827       // read-only: ObjectContentDocument
02828       case ObjectData:            { object.setData(str); return; }
02829       case ObjectDeclare:         { object.setDeclare(value.toBoolean(exec)); return; }
02830       case ObjectHeight:          { object.setHeight(str); return; }
02831       case ObjectHspace:          { object.setHspace(value.toInteger(exec)); return; }
02832       case ObjectName:            { object.setName(str); return; }
02833       case ObjectStandby:         { object.setStandby(str); return; }
02834       case ObjectTabIndex:        { object.setTabIndex(value.toInteger(exec)); return; }
02835       case ObjectType:            { object.setType(str); return; }
02836       case ObjectUseMap:          { object.setUseMap(str); return; }
02837       case ObjectVspace:          { object.setVspace(value.toInteger(exec)); return; }
02838       case ObjectWidth:           { object.setWidth(str); return; }
02839       }
02840     }
02841     break;
02842     case ID_PARAM: {
02843       DOM::HTMLParamElement param = element;
02844       switch (token) {
02845       case ParamName:            { param.setName(str); return; }
02846       case ParamType:            { param.setType(str); return; }
02847       case ParamValue:           { param.setValue(str); return; }
02848       case ParamValueType:       { param.setValueType(str); return; }
02849       }
02850     }
02851     break;
02852     case ID_APPLET: {
02853       DOM::HTMLAppletElement applet = element;
02854       switch (token) {
02855       case AppletAlign:           { applet.setAlign(str); return; }
02856       case AppletAlt:             { applet.setAlt(str); return; }
02857       case AppletArchive:         { applet.setArchive(str); return; }
02858       case AppletCode:            { applet.setCode(str); return; }
02859       case AppletCodeBase:        { applet.setCodeBase(str); return; }
02860       case AppletHeight:          { applet.setHeight(str); return; }
02861       case AppletHspace:          { applet.setHspace(value.toInteger(exec)); return; }
02862       case AppletName:            { applet.setName(str); return; }
02863       case AppletObject:          { applet.setObject(str); return; }
02864       case AppletVspace:          { applet.setVspace(value.toInteger(exec)); return; }
02865       case AppletWidth:           { applet.setWidth(str); return; }
02866       }
02867     }
02868     break;
02869     case ID_MAP: {
02870       DOM::HTMLMapElement map = element;
02871       switch (token) {
02872       // read-only: areas
02873       case MapName:                 { map.setName(str); return; }
02874      }
02875     }
02876     break;
02877     case ID_AREA: {
02878       DOM::HTMLAreaElement area = element;
02879       switch (token) {
02880       case AreaAccessKey:       { area.setAccessKey(str); return; }
02881       case AreaAlt:             { area.setAlt(str); return; }
02882       case AreaCoords:          { area.setCoords(str); return; }
02883       case AreaHref:            { area.setHref(str); return; }
02884       case AreaNoHref:          { area.setNoHref(value.toBoolean(exec)); return; }
02885       case AreaShape:           { area.setShape(str); return; }
02886       case AreaTabIndex:        { area.setTabIndex(value.toInteger(exec)); return; }
02887       case AreaTarget:          { area.setTarget(str); return; }
02888       }
02889     }
02890     break;
02891     case ID_SCRIPT: {
02892       DOM::HTMLScriptElement script = element;
02893       switch (token) {
02894       case ScriptText:            { script.setText(str); return; }
02895       case ScriptHtmlFor:         { script.setHtmlFor(str); return; }
02896       case ScriptEvent:           { script.setEvent(str); return; }
02897       case ScriptCharset:         { script.setCharset(str); return; }
02898       case ScriptDefer:           { script.setDefer(value.toBoolean(exec)); return; }
02899       case ScriptSrc:             { script.setSrc(str); return; }
02900       case ScriptType:            { script.setType(str); return; }
02901       }
02902     }
02903     break;
02904     case ID_TABLE: {
02905       DOM::HTMLTableElement table = element;
02906       switch (token) {
02907       case TableCaption:         { table.setCaption(n); return; } // type HTMLTableCaptionElement
02908       case TableTHead:           { table.setTHead(n); return; } // type HTMLTableSectionElement
02909       case TableTFoot:           { table.setTFoot(n); return; } // type HTMLTableSectionElement
02910       // read-only: rows
02911       // read-only: tbodies
02912       case TableAlign:           { table.setAlign(str); return; }
02913       case TableBgColor:         { table.setBgColor(str); return; }
02914       case TableBorder:          { table.setBorder(str); return; }
02915       case TableCellPadding:     { table.setCellPadding(str); return; }
02916       case TableCellSpacing:     { table.setCellSpacing(str); return; }
02917       case TableFrame:           { table.setFrame(str); return; }
02918       case TableRules:           { table.setRules(str); return; }
02919       case TableSummary:         { table.setSummary(str); return; }
02920       case TableWidth:           { table.setWidth(str); return; }
02921       }
02922     }
02923     break;
02924     case ID_CAPTION: {
02925       DOM::HTMLTableCaptionElement tableCaption = element;
02926       switch (token) {
02927       case TableAlign:           { tableCaption.setAlign(str); return; }
02928       }
02929     }
02930     break;
02931     case ID_COL:
02932     case ID_COLGROUP: {
02933       DOM::HTMLTableColElement tableCol = element;
02934       switch (token) {
02935       case TableColAlign:           { tableCol.setAlign(str); return; }
02936       case TableColCh:              { tableCol.setCh(str); return; }
02937       case TableColChOff:           { tableCol.setChOff(str); return; }
02938       case TableColSpan:            { tableCol.setSpan(value.toInteger(exec)); return; }
02939       case TableColVAlign:          { tableCol.setVAlign(str); return; }
02940       case TableColWidth:           { tableCol.setWidth(str); return; }
02941       }
02942     }
02943     break;
02944     case ID_THEAD:
02945     case ID_TBODY:
02946     case ID_TFOOT: {
02947       DOM::HTMLTableSectionElement tableSection = element;
02948       switch (token) {
02949       case TableSectionAlign:           { tableSection.setAlign(str); return; }
02950       case TableSectionCh:              { tableSection.setCh(str); return; }
02951       case TableSectionChOff:           { tableSection.setChOff(str); return; }
02952       case TableSectionVAlign:          { tableSection.setVAlign(str); return; }
02953       // read-only: rows
02954       }
02955     }
02956     break;
02957     case ID_TR: {
02958       DOM::HTMLTableRowElement tableRow = element;
02959       switch (token) {
02960       // read-only: rowIndex
02961       // read-only: sectionRowIndex
02962       // read-only: cells
02963       case TableRowAlign:           { tableRow.setAlign(str); return; }
02964       case TableRowBgColor:         { tableRow.setBgColor(str); return; }
02965       case TableRowCh:              { tableRow.setCh(str); return; }
02966       case TableRowChOff:           { tableRow.setChOff(str); return; }
02967       case TableRowVAlign:          { tableRow.setVAlign(str); return; }
02968       }
02969     }
02970     break;
02971     case ID_TH:
02972     case ID_TD: {
02973       DOM::HTMLTableCellElement tableCell = element;
02974       switch (token) {
02975       // read-only: cellIndex
02976       case TableCellAbbr:            { tableCell.setAbbr(str); return; }
02977       case TableCellAlign:           { tableCell.setAlign(str); return; }
02978       case TableCellAxis:            { tableCell.setAxis(str); return; }
02979       case TableCellBgColor:         { tableCell.setBgColor(str); return; }
02980       case TableCellCh:              { tableCell.setCh(str); return; }
02981       case TableCellChOff:           { tableCell.setChOff(str); return; }
02982       case TableCellColSpan:         { tableCell.setColSpan(value.toInteger(exec)); return; }
02983       case TableCellHeaders:         { tableCell.setHeaders(str); return; }
02984       case TableCellHeight:          { tableCell.setHeight(str); return; }
02985       case TableCellNoWrap:          { tableCell.setNoWrap(value.toBoolean(exec)); return; }
02986       case TableCellRowSpan:         { tableCell.setRowSpan(value.toInteger(exec)); return; }
02987       case TableCellScope:           { tableCell.setScope(str); return; }
02988       case TableCellVAlign:          { tableCell.setVAlign(str); return; }
02989       case TableCellWidth:           { tableCell.setWidth(str); return; }
02990       }
02991     }
02992     break;
02993     case ID_FRAMESET: {
02994       DOM::HTMLFrameSetElement frameSet = element;
02995       switch (token) {
02996       case FrameSetCols:            { frameSet.setCols(str); return; }
02997       case FrameSetRows:            { frameSet.setRows(str); return; }
02998       }
02999     }
03000     break;
03001     case ID_FRAME: {
03002       DOM::HTMLFrameElement frameElement = element;
03003       switch (token) {
03004        // read-only: FrameContentDocument:
03005       case FrameFrameBorder:     { frameElement.setFrameBorder(str); return; }
03006       case FrameLongDesc:        { frameElement.setLongDesc(str); return; }
03007       case FrameMarginHeight:    { frameElement.setMarginHeight(str); return; }
03008       case FrameMarginWidth:     { frameElement.setMarginWidth(str); return; }
03009       case FrameName:            { frameElement.setName(str); return; }
03010       case FrameNoResize:        { frameElement.setNoResize(value.toBoolean(exec)); return; }
03011       case FrameScrolling:       { frameElement.setScrolling(str); return; }
03012       case FrameSrc:             { frameElement.setSrc(str); return; }
03013       case FrameLocation:        {
03014                                    static_cast<DOM::HTMLFrameElementImpl *>(frameElement.handle())->setLocation(str);
03015                                    return;
03016                                  }
03017       }
03018     }
03019     break;
03020     case ID_IFRAME: {
03021       DOM::HTMLIFrameElement iFrame = element;
03022       switch (token) {
03023       case IFrameAlign:           { iFrame.setAlign(str); return; }
03024       // read-only: IFrameContentDocument
03025       case IFrameFrameBorder:     { iFrame.setFrameBorder(str); return; }
03026       case IFrameHeight:          { iFrame.setHeight(str); return; }
03027       case IFrameLongDesc:        { iFrame.setLongDesc(str); return; }
03028       case IFrameMarginHeight:    { iFrame.setMarginHeight(str); return; }
03029       case IFrameMarginWidth:     { iFrame.setMarginWidth(str); return; }
03030       case IFrameName:            { iFrame.setName(str); return; }
03031       case IFrameScrolling:       { iFrame.setScrolling(str); return; }
03032       case IFrameSrc:             { iFrame.setSrc(str); return; }
03033       case IFrameWidth:           { iFrame.setWidth(str); return; }
03034       }
03035       break;
03036     }
03037   }
03038 
03039   // generic properties
03040   switch (token) {
03041   case ElementId:
03042     element.setId(str);
03043     return;
03044   case ElementTitle:
03045     element.setTitle(str);
03046     return;
03047   case ElementLang:
03048     element.setLang(str);
03049     return;
03050   case ElementDir:
03051     element.setDir(str);
03052     return;
03053   case ElementClassName:
03054     element.setClassName(str);
03055     return;
03056   case ElementInnerHTML:
03057     element.setInnerHTML(str);
03058     return;
03059   case ElementInnerText:
03060     element.setInnerText(str);
03061     return;
03062   default:
03063     kdDebug(6070) << "WARNING: KJS::HTMLElement::putValueProperty unhandled token " << token << " thisTag=" << element.tagName().string() << " str=" << str.string() << endl;
03064   }
03065 }
03066 
03067 // -------------------------------------------------------------------------
03068 /* Source for HTMLCollectionProtoTable.
03069 @begin HTMLCollectionProtoTable 3
03070   item      HTMLCollection::Item        DontDelete|Function 1
03071   namedItem HTMLCollection::NamedItem   DontDelete|Function 1
03072   tags      HTMLCollection::Tags        DontDelete|Function 1
03073 @end
03074 */
03075 DEFINE_PROTOTYPE("HTMLCollection", HTMLCollectionProto)
03076 IMPLEMENT_PROTOFUNC_DOM(HTMLCollectionProtoFunc)
03077 IMPLEMENT_PROTOTYPE(HTMLCollectionProto,HTMLCollectionProtoFunc)
03078 
03079 const ClassInfo KJS::HTMLCollection::info = { "HTMLCollection", 0, 0, 0 };
03080 
03081 KJS::HTMLCollection::HTMLCollection(ExecState *exec, const DOM::HTMLCollection& c)
03082   : DOMObject(HTMLCollectionProto::self(exec)), collection(c) {}
03083 
03084 KJS::HTMLCollection::~HTMLCollection()
03085 {
03086   ScriptInterpreter::forgetDOMObject(collection.handle());
03087 }
03088 
03089 // We have to implement hasProperty since we don't use a hashtable for 'selectedIndex' and 'length'
03090 // ## this breaks "for (..in..)" though.
03091 bool KJS::HTMLCollection::hasProperty(ExecState *exec, const Identifier &p) const
03092 {
03093   if (p == lengthPropertyName)
03094     return true;
03095   if ( collection.item(0).elementId() == ID_OPTION &&
03096        ( p == "selectedIndex" || p == "value" ) )
03097     return true;
03098   return DOMObject::hasProperty(exec, p);
03099 }
03100 
03101 Value KJS::HTMLCollection::tryGet(ExecState *exec, const Identifier &propertyName) const
03102 {
03103 #ifdef KJS_VERBOSE
03104   kdDebug(6070) << "KJS::HTMLCollection::tryGet " << propertyName.ascii() << endl;
03105 #endif
03106   if (propertyName == lengthPropertyName)
03107   {
03108 #ifdef KJS_VERBOSE
03109     kdDebug(6070) << "  collection length is " << collection.length() << endl;
03110 #endif
03111     return Number(collection.length());
03112   }
03113 
03114   if (collection.item(0).elementId() == ID_OPTION) {
03115     DOM::HTMLSelectElement parentSelect;
03116     DOM::Node node = collection.item(0).parentNode();
03117     while(!node.isNull() && parentSelect.isNull()) {
03118       if(node.elementId() == ID_SELECT)
03119         parentSelect = static_cast<DOM::HTMLSelectElement>(node);
03120       node = node.parentNode();
03121     }
03122     if ( parentSelect.isNull() )
03123       return Undefined();
03124     if (propertyName == "selectedIndex") {
03125       // NON-STANDARD options.selectedIndex
03126       return Number(parentSelect.selectedIndex());
03127     } else if ( propertyName == "value" ) {
03128       // NON-STANDARD options.value
03129       return String(parentSelect.value());
03130     }
03131   }
03132 
03133   // Look in the prototype (for functions) before assuming it's an item's name
03134   Object proto = Object::dynamicCast(prototype());
03135   if (!proto.isNull() && proto.hasProperty(exec,propertyName))
03136     return proto.get(exec,propertyName);
03137 
03138   // name or index ?
03139   bool ok;
03140   unsigned int u = propertyName.toULong(&ok);
03141   if (ok) {
03142     if ( u < collection.length() ) {
03143        DOM::Node node = collection.item(u);
03144        return getDOMNode(exec,node);
03145     } else
03146        return Undefined();
03147   }
03148   else
03149     return getNamedItems(exec,propertyName);
03150 }
03151 
03152 // HTMLCollections are strange objects, they support both get and call,
03153 // so that document.forms.item(0) and document.forms(0) both work.
03154 Value KJS::HTMLCollection::call(ExecState *exec, Object &thisObj, const List &args)
03155 {
03156   // This code duplication is necessary, HTMLCollection isn't a DOMFunction
03157   Value val;
03158   try {
03159     val = tryCall(exec, thisObj, args);
03160   }
03161   // pity there's no way to distinguish between these in JS code
03162   catch (...) {
03163     Object err = Error::create(exec, GeneralError, "Exception from HTMLCollection");
03164     exec->setException(err);
03165   }
03166   return val;
03167 }
03168 
03169 Value KJS::HTMLCollection::tryCall(ExecState *exec, Object &, const List &args)
03170 {
03171   // Do not use thisObj here. It can be the HTMLDocument, in the document.forms(i) case.
03172   /*if( thisObj.imp() != this )
03173   {
03174     kdDebug(6070) << "WARNING: thisObj.imp() != this in HTMLCollection::tryCall" << endl;
03175     KJS::printInfo(exec,"KJS::HTMLCollection::tryCall thisObj",thisObj,-1);
03176     KJS::printInfo(exec,"KJS::HTMLCollection::tryCall this",Value(this),-1);
03177   }*/
03178   // Also, do we need the TypeError test here ?
03179 
03180   if (args.size() == 1) {
03181     // support for document.all(<index>) etc.
03182     bool ok;
03183     UString s = args[0].toString(exec);
03184     unsigned int u = s.toULong(&ok);
03185     if (ok) {
03186       DOM::Element element = collection.item(u);
03187       return getDOMNode(exec,element);
03188     }
03189     // support for document.images('<name>') etc.
03190     return getNamedItems(exec,Identifier(s));
03191   }
03192   else if (args.size() >= 1) // the second arg, if set, is the index of the item we want
03193   {
03194     bool ok;
03195     UString s = args[0].toString(exec);
03196     unsigned int u = args[1].toString(exec).toULong(&ok);
03197     if (ok)
03198     {
03199       DOM::DOMString pstr = s.string();
03200       DOM::Node node = collection.namedItem(pstr);
03201       while (!node.isNull()) {
03202         if (!u)
03203           return getDOMNode(exec,node);
03204         node = collection.nextNamedItem(pstr);
03205         --u;
03206       }
03207     }
03208   }
03209   return Undefined();
03210 }
03211 
03212 Value KJS::HTMLCollection::getNamedItems(ExecState *exec, const Identifier &propertyName) const
03213 {
03214 #ifdef KJS_VERBOSE
03215   kdDebug(6070) << "KJS::HTMLCollection::getNamedItems " << propertyName.ascii() << endl;
03216 #endif
03217   DOM::DOMString pstr = propertyName.string();
03218   DOM::Node node = collection.namedItem(pstr);
03219   if(!node.isNull())
03220   {
03221     DOM::Node next = collection.nextNamedItem(pstr);
03222     if (next.isNull()) // single item
03223     {
03224 #ifdef KJS_VERBOSE
03225       kdDebug(6070) << "returning single node" << endl;
03226 #endif
03227       return getDOMNode(exec,node);
03228     }
03229     else // multiple items, return a collection
03230     {
03231       QValueList<DOM::Node> nodes;
03232       nodes.append(node);
03233       do {
03234         nodes.append(next);
03235         next = collection.nextNamedItem(pstr);
03236       } while (!next.isNull());
03237 #ifdef KJS_VERBOSE
03238       kdDebug(6070) << "returning list of " << nodes.count() << " nodes" << endl;
03239 #endif
03240       return Value(new DOMNamedNodesCollection(exec, nodes));
03241     }
03242   }
03243 #ifdef KJS_VERBOSE
03244   kdDebug(6070) << "not found" << endl;
03245 #endif
03246   return Undefined();
03247 }
03248 
03249 Value KJS::HTMLCollectionProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
03250 {
03251   KJS_CHECK_THIS( KJS::HTMLCollection, thisObj );
03252   DOM::HTMLCollection coll = static_cast<KJS::HTMLCollection *>(thisObj.imp())->toCollection();
03253 
03254   switch (id) {
03255   case KJS::HTMLCollection::Item:
03256     return getDOMNode(exec,coll.item(args[0].toUInt32(exec)));
03257   case KJS::HTMLCollection::Tags:
03258   {
03259     DOM::DOMString tagName = args[0].toString(exec).string();
03260     DOM::NodeList list;
03261     // getElementsByTagName exists in Document and in Element, pick up the right one
03262     if ( coll.base().nodeType() == DOM::Node::DOCUMENT_NODE )
03263     {
03264       DOM::Document doc = coll.base();
03265       list = doc.getElementsByTagName(tagName);
03266 #ifdef KJS_VERBOSE
03267       kdDebug(6070) << "KJS::HTMLCollectionProtoFunc::tryCall document.tags(" << tagName.string() << ") -> " << list.length() << " items in node list" << endl;
03268 #endif
03269     } else
03270     {
03271       DOM::Element e = coll.base();
03272       list = e.getElementsByTagName(tagName);
03273 #ifdef KJS_VERBOSE
03274       kdDebug(6070) << "KJS::HTMLCollectionProtoFunc::tryCall element.tags(" << tagName.string() << ") -> " << list.length() << " items in node list" << endl;
03275 #endif
03276     }
03277     return getDOMNodeList(exec, list);
03278   }
03279   case KJS::HTMLCollection::NamedItem:
03280   {
03281     Value val = static_cast<HTMLCollection *>(thisObj.imp())->getNamedItems(exec, Identifier(args[0].toString(exec)));
03282     // Must return null when asking for a named item that isn't in the collection
03283     // (DOM2 testsuite, HTMLCollection12 test)
03284     if ( val.type() == KJS::UndefinedType )
03285       return Null();
03286     else
03287       return val;
03288   }
03289   default:
03290     return Undefined();
03291   }
03292 }
03293 
03294 Value KJS::HTMLSelectCollection::tryGet(ExecState *exec, const Identifier &p) const
03295 {
03296   if (p == "selectedIndex")
03297     return Number(element.selectedIndex());
03298 
03299   return  HTMLCollection::tryGet(exec, p);
03300 }
03301 
03302 void KJS::HTMLSelectCollection::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int)
03303 {
03304 #ifdef KJS_VERBOSE
03305   kdDebug(6070) << "KJS::HTMLSelectCollection::tryPut " << propertyName.qstring() << endl;
03306 #endif
03307   if ( propertyName == "selectedIndex" ) {
03308     element.setSelectedIndex( value.toInteger( exec ) );
03309     return;
03310   }
03311   // resize ?
03312   else if (propertyName == lengthPropertyName) {
03313     unsigned newLen;
03314     bool converted = value.toUInt32(newLen);
03315 
03316     if (!converted) {
03317       return;
03318     }
03319 
03320     long diff = element.length() - newLen;
03321 
03322     if (diff < 0) { // add dummy elements
03323       do {
03324         element.add(element.ownerDocument().createElement("OPTION"), DOM::HTMLElement());
03325       } while (++diff);
03326     }
03327     else // remove elements
03328       while (diff-- > 0)
03329         element.remove(newLen);
03330 
03331     return;
03332   }
03333   // an index ?
03334   bool ok;
03335   unsigned int u = propertyName.toULong(&ok);
03336   if (!ok)
03337     return;
03338 
03339   if (value.isA(NullType) || value.isA(UndefinedType)) {
03340     // null and undefined delete. others, too ?
03341     element.remove(u);
03342     return;
03343   }
03344 
03345   // is v an option element ?
03346   DOM::Node node = KJS::toNode(value);
03347   if (node.isNull() || node.elementId() != ID_OPTION)
03348     return;
03349 
03350   DOM::HTMLOptionElement option = static_cast<DOM::HTMLOptionElement>(node);
03351   if ( option.ownerDocument() != element.ownerDocument() )
03352     option = static_cast<DOM::HTMLOptionElement>(element.ownerDocument().importNode(option, true));
03353   long diff = long(u) - element.length();
03354   DOM::HTMLElement before;
03355   // out of array bounds ? first insert empty dummies
03356   if (diff > 0) {
03357     while (diff--) {
03358       element.add(element.ownerDocument().createElement("OPTION"), before);
03359     }
03360     // replace an existing entry ?
03361   } else if (diff < 0) {
03362     before = element.options().item(u+1);
03363     element.remove(u);
03364   }
03365   // finally add the new element
03366   element.add(option, before);
03367 }
03368 
03370 
03371 OptionConstructorImp::OptionConstructorImp(ExecState *exec, const DOM::Document &d)
03372     : ObjectImp(), doc(d)
03373 {
03374   // ## isn't there some redundancy between ObjectImp::_proto and the "prototype" property ?
03375   //put(exec,"prototype", ...,DontEnum|DontDelete|ReadOnly);
03376 
03377   // no. of arguments for constructor
03378   // ## is 4 correct ? 0 to 4, it seems to be
03379   put(exec,lengthPropertyName, Number(4), ReadOnly|DontDelete|DontEnum);
03380 }
03381 
03382 bool OptionConstructorImp::implementsConstruct() const
03383 {
03384   return true;
03385 }
03386 
03387 Object OptionConstructorImp::construct(ExecState *exec, const List &args)
03388 {
03389   DOM::Element el = doc.createElement("OPTION");
03390   DOM::HTMLOptionElement opt = static_cast<DOM::HTMLOptionElement>(el);
03391   int sz = args.size();
03392   DOM::Text t = doc.createTextNode("");
03393   try { opt.appendChild(t); }
03394   catch(DOM::DOMException& e) {
03395     // #### exec->setException ?
03396   }
03397   if (sz > 0)
03398     t.setData(args[0].toString(exec).string()); // set the text
03399   if (sz > 1)
03400     opt.setValue(args[1].toString(exec).string());
03401   if (sz > 2)
03402     opt.setDefaultSelected(args[2].toBoolean(exec));
03403   if (sz > 3)
03404     opt.setSelected(args[3].toBoolean(exec));
03405 
03406   return Object::dynamicCast(getDOMNode(exec,opt));
03407 }
03408 
03410 
03411 ImageConstructorImp::ImageConstructorImp(ExecState *, const DOM::Document &d)
03412     : ObjectImp(), doc(d)
03413 {
03414 }
03415 
03416 bool ImageConstructorImp::implementsConstruct() const
03417 {
03418   return true;
03419 }
03420 
03421 Object ImageConstructorImp::construct(ExecState *exec, const List &)
03422 {
03423   /* TODO: fetch optional height & width from arguments */
03424 
03425   Object result(new Image(exec, doc));
03426   /* TODO: do we need a prototype ? */
03427 
03428   return result;
03429 }
03430 
03431 const ClassInfo KJS::Image::info = { "Image", 0, &ImageTable, 0 };
03432 
03433 /* Source for ImageTable.
03434 @begin ImageTable 5
03435   src       Image::Src      DontDelete
03436   width     Image::Width        DontDelete|ReadOnly
03437   height    Image::Height       DontDelete|ReadOnly
03438   complete  Image::Complete     DontDelete|ReadOnly
03439   onload    Image::OnLoad       DontDelete
03440 @end
03441 */
03442 Image::Image(ExecState* exec, const DOM::Document &d)
03443   : DOMObject(exec->interpreter()->builtinObjectPrototype()), doc(d), img(0),
03444   m_onLoadListener(0L)
03445 {
03446 }
03447 
03448 Value Image::tryGet(ExecState *exec, const Identifier &propertyName) const
03449 {
03450   return DOMObjectLookupGetValue<Image,DOMObject>(exec, propertyName, &ImageTable, this);
03451 }
03452 
03453 Value Image::getValueProperty(ExecState *, int token) const
03454 {
03455   switch (token) {
03456   case Src:
03457     return String(src);
03458   case Complete:
03459     return Boolean(!img || img->status() >= khtml::CachedObject::Persistent);
03460   case Width:
03461     if ( !img )
03462       return Undefined();
03463     return Number(img->pixmap_size().width());
03464   case Height:
03465     if ( !img )
03466       return Undefined();
03467     return Number(img->pixmap_size().height());
03468   case OnLoad:
03469     if ( m_onLoadListener && m_onLoadListener->listenerObjImp())
03470       return m_onLoadListener->listenerObj();
03471     return Undefined();
03472   default:
03473     kdDebug(6070) << "WARNING: Image::getValueProperty unhandled token " << token << endl;
03474     return Value();
03475   }
03476 }
03477 
03478 void Image::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
03479 {
03480   DOMObjectLookupPut<Image, DOMObject>( exec, propertyName, value, attr, &ImageTable, this );
03481 }
03482 
03483 void Image::putValueProperty(ExecState *exec, int token, const Value& value, int)
03484 {
03485   switch (token) {
03486   case Src: {
03487     String str = value.toString(exec);
03488     src = str.value();
03489     if ( img ) img->deref(this);
03490     img = static_cast<DOM::DocumentImpl*>( doc.handle() )->docLoader()->requestImage( src.string() );
03491 // ### img = doc ? doc->docLoader()->requestImage( src.string() ) : 0;
03492     if ( img ) img->ref(this);
03493     break;
03494   }
03495   case OnLoad:
03496     if ( m_onLoadListener )
03497         m_onLoadListener->deref();
03498     m_onLoadListener = Window::retrieveActive(exec)->getJSEventListener(value,true);
03499     if ( m_onLoadListener )
03500         m_onLoadListener->ref();
03501     break;
03502   default:
03503     kdDebug(6070) << "WARNING: Image::putValueProperty unhandled token " << token << endl;
03504   }
03505 }
03506 
03507 void Image::notifyFinished(khtml::CachedObject * finishedObj)
03508 {
03509   if (img == finishedObj /*&& !loadEventSent*/ && m_onLoadListener ) {
03510     //loadEventSent = true;
03511     DOM::EventImpl *evt = new DOM::EventImpl( (DOM::EventImpl::EventId)ATTR_ONLOAD, false, false );
03512     evt->setTarget( 0 );
03513     evt->ref();
03514     DOM::Event e(evt);
03515     Object thisObj( this );
03516     m_onLoadListener->hackSetThisObj( thisObj );
03517     m_onLoadListener->handleEvent( e );
03518     if ( m_onLoadListener ) // #57195
03519         m_onLoadListener->hackUnsetThisObj();
03520     evt->deref();
03521   }
03522 }
03523 
03524 Image::~Image()
03525 {
03526   if ( img ) img->deref(this);
03527   if ( m_onLoadListener )
03528       m_onLoadListener->deref();
03529 }
03530 
03531 Value KJS::getHTMLCollection(ExecState *exec, const DOM::HTMLCollection& c)
03532 {
03533   return cacheDOMObject<DOM::HTMLCollection, KJS::HTMLCollection>(exec, c);
03534 }
03535 
03536 Value KJS::getSelectHTMLCollection(ExecState *exec, const DOM::HTMLCollection& c, const DOM::HTMLSelectElement& e)
03537 {
03538   DOMObject *ret;
03539   if (c.isNull())
03540     return Null();
03541   ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
03542   if ((ret = interp->getDOMObject(c.handle())))
03543     return Value(ret);
03544   else {
03545     ret = new HTMLSelectCollection(exec, c, e);
03546     interp->putDOMObject(c.handle(),ret);
03547     return Value(ret);
03548   }
03549 }
KDE Logo
This file is part of the documentation for khtml Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Feb 18 15:11:44 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003