kjs_html.cpp

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