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