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