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           Window *w = Window::retrieveWindow(part);
01844           if (w)
01845             return Value(w);
01846         }
01847             return Undefined();
01848     }
01849     case FrameFrameBorder:     return String(frameElement.frameBorder());
01850     case FrameLongDesc:        return String(frameElement.longDesc());
01851     case FrameMarginHeight:    return String(frameElement.marginHeight());
01852     case FrameMarginWidth:     return String(frameElement.marginWidth());
01853     case FrameName:            return String(frameElement.name());
01854     case FrameNoResize:        return Boolean(frameElement.noResize());
01855     case FrameScrolling:       return String(frameElement.scrolling());
01856     case FrameSrc:
01857     case FrameLocation:        return String(frameElement.src());
01858     // IE only
01859     case FrameWidth:
01860     case FrameHeight:
01861       {
01862           frameElement.handle()->getDocument()->updateLayout();
01863           khtml::RenderObject* r = frameElement.handle()->renderer();
01864           return Number( r ? (token == FrameWidth ? r->width() : r->height()) : 0 );
01865       }
01866     }
01867   }
01868   break;
01869   case ID_IFRAME: {
01870     DOM::HTMLIFrameElement iFrame = element;
01871     switch (token) {
01872     case IFrameAlign:           return String(iFrame.align());
01873     case IFrameContentDocument: return checkNodeSecurity(exec,iFrame.contentDocument()) ?
01874                        getDOMNode(exec, iFrame.contentDocument()) : Undefined();
01875     case IFrameContentWindow:       {
01876         KHTMLPart* part = static_cast<DOM::HTMLIFrameElementImpl*>(iFrame.handle())->contentPart();
01877         if (part) {
01878           Window *w = Window::retrieveWindow(part);
01879           if (w)
01880             return Value(w);
01881         }
01882             return Undefined();
01883     }
01884     case IFrameFrameBorder:     return String(iFrame.frameBorder());
01885     case IFrameHeight:          return String(iFrame.height());
01886     case IFrameLongDesc:        return String(iFrame.longDesc());
01887     case IFrameMarginHeight:    return String(iFrame.marginHeight());
01888     case IFrameMarginWidth:     return String(iFrame.marginWidth());
01889     case IFrameName:            return String(iFrame.name());
01890     case IFrameScrolling:       return String(iFrame.scrolling());
01891     case IFrameSrc:             return String(iFrame.src());
01892     case IFrameWidth:           return String(iFrame.width());
01893     }
01894     break;
01895   }
01896   } // xemacs (or arnt) could be a bit smarter when it comes to indenting switch()es ;)
01897   // its not arnt to blame - its the original Stroustrup style we like :) (Dirk)
01898 
01899   // generic properties
01900   switch (token) {
01901   case ElementId:
01902     return String(element.id()); // String is wrong here. Other browsers return empty string if no id specified.
01903   case ElementTitle:
01904     return String(element.title());
01905   case ElementLang:
01906     return String(element.lang());
01907   case ElementDir:
01908     return String(element.dir());
01909   case ElementClassName:
01910     return String(element.className());
01911   case ElementInnerHTML:
01912     return String(element.innerHTML());
01913   case ElementInnerText:
01914     return String(element.innerText());
01915   case ElementDocument:
01916     return getDOMNode(exec,element.ownerDocument());
01917   case ElementChildren:
01918     return getHTMLCollection(exec,element.children());
01919   case ElementAll:
01920     // Disable element.all when we try to be Netscape-compatible
01921     if ( exec->interpreter()->compatMode() == Interpreter::NetscapeCompat )
01922       return Undefined();
01923     else
01924     if ( exec->interpreter()->compatMode() == Interpreter::IECompat )
01925       return getHTMLCollection(exec,element.all());
01926     else // Enabled but hidden by default
01927       return getHTMLCollection(exec,element.all(), true);
01928   // ### what about style? or is this used instead for DOM2 stylesheets?
01929   }
01930   kdError() << "HTMLElement::getValueProperty unhandled token " << token << endl;
01931   return Undefined();
01932 }
01933 
01934 bool KJS::HTMLElement::hasProperty(ExecState *exec, const Identifier &propertyName) const
01935 {
01936 #ifdef KJS_VERBOSE
01937   //kdDebug(6070) << "HTMLElement::hasProperty " << propertyName.qstring() << endl;
01938 #endif
01939   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
01940   // First look at dynamic properties - keep this in sync with tryGet
01941   switch (element.elementId()) {
01942     case ID_FORM: {
01943       DOM::HTMLFormElement form = element;
01944       // Check if we're retrieving an element (by index or by name)
01945       bool ok;
01946       uint u = propertyName.toULong(&ok);
01947       if (ok && !(form.elements().item(u).isNull()))
01948         return true;
01949       DOM::Node testnode = form.elements().namedItem(propertyName.string());
01950       if (!testnode.isNull())
01951         return true;
01952     }
01953     case ID_SELECT: {
01954       DOM::HTMLSelectElement select = element;
01955       bool ok;
01956       uint u = propertyName.toULong(&ok);
01957       if (ok && !(select.options().item(u).isNull()))
01958         return true;
01959     }
01960     default:
01961       break;
01962   }
01963 
01964   return DOMElement::hasProperty(exec, propertyName);
01965 }
01966 
01967 UString KJS::HTMLElement::toString(ExecState *exec) const
01968 {
01969   if (node.elementId() == ID_A)
01970     return UString(static_cast<const DOM::HTMLAnchorElement&>(node).href());
01971   else if (node.elementId() == ID_APPLET) {
01972     KParts::LiveConnectExtension *lc = getLiveConnectExtension(node);
01973     QStringList qargs;
01974     QString retvalue;
01975     KParts::LiveConnectExtension::Type rettype;
01976     unsigned long retobjid;
01977     if (lc && lc->call(0, "hashCode", qargs, rettype, retobjid, retvalue)) {
01978       QString str("[object APPLET ref=");
01979       return UString(str + retvalue + QString("]"));
01980     }
01981   } else if (node.elementId() == ID_IMG) {
01982     DOM::HTMLImageElement image(node);
01983     if (!image.alt().isEmpty())
01984       return UString(image.alt()) + " " + DOMElement::toString(exec);
01985   }
01986   return DOMElement::toString(exec);
01987 }
01988 
01989 static void getForm(DOM::HTMLFormElement* form, const DOM::HTMLElement& element)
01990 {
01991     switch (element.elementId()) {
01992         case ID_ISINDEX: {
01993             DOM::HTMLIsIndexElement isindex = element;
01994             *form = isindex.form();
01995             break;
01996         }
01997         case ID_SELECT: {
01998             DOM::HTMLSelectElement select = element;
01999             *form = select.form();
02000             break;
02001         }
02002         case ID_OPTION: {
02003             DOM::HTMLOptionElement option = element;
02004             *form = option.form();
02005             break;
02006         }
02007         case ID_INPUT: {
02008             DOM::HTMLInputElement input = element;
02009             *form = input.form();
02010             break;
02011         }
02012         case ID_TEXTAREA: {
02013             DOM::HTMLTextAreaElement textarea = element;
02014             *form = textarea.form();
02015             break;
02016         }
02017         case ID_LABEL: {
02018             DOM::HTMLLabelElement label = element;
02019             *form = label.form();
02020             break;
02021         }
02022         case ID_FIELDSET: {
02023             DOM::HTMLFieldSetElement fieldset = element;
02024             *form = fieldset.form();
02025             break;
02026         }
02027         case ID_LEGEND: {
02028             DOM::HTMLLegendElement legend = element;
02029             *form = legend.form();
02030             break;
02031         }
02032         case ID_OBJECT: {
02033             DOM::HTMLObjectElement object = element;
02034             *form = object.form();
02035             break;
02036         }
02037         default:
02038             break;
02039     }
02040 }
02041 
02042 void KJS::HTMLElement::pushEventHandlerScope(ExecState *exec, ScopeChain &scope) const
02043 {
02044   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02045 
02046   // The document is put on first, fall back to searching it only after the element and form.
02047   scope.push(static_cast<ObjectImp *>(getDOMNode(exec, element.ownerDocument()).imp()));
02048 
02049   // The form is next, searched before the document, but after the element itself.
02050   DOM::HTMLFormElement formElt;
02051 
02052   // First try to obtain the form from the element itself.  We do this to deal with
02053   // the malformed case where <form>s aren't in our parent chain (e.g., when they were inside
02054   // <table> or <tbody>.
02055   getForm(&formElt, element);
02056   if (!formElt.isNull())
02057     scope.push(static_cast<ObjectImp *>(getDOMNode(exec, formElt).imp()));
02058   else {
02059     DOM::Node form = element.parentNode();
02060     while (!form.isNull() && form.elementId() != ID_FORM)
02061         form = form.parentNode();
02062 
02063     if (!form.isNull())
02064         scope.push(static_cast<ObjectImp *>(getDOMNode(exec, form).imp()));
02065   }
02066 
02067   // The element is on top, searched first.
02068   scope.push(static_cast<ObjectImp *>(getDOMNode(exec, element).imp()));
02069 }
02070 
02071 HTMLElementFunction::HTMLElementFunction(ExecState *exec, int i, int len)
02072   : DOMFunction(exec), id(i)
02073 {
02074   Value protect(this);
02075   put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum);
02076 }
02077 
02078 Value KJS::HTMLElementFunction::tryCall(ExecState *exec, Object &thisObj, const List &args)
02079 {
02080   KJS_CHECK_THIS( HTMLElement, thisObj );
02081 
02082 #ifdef KJS_VERBOSE
02083   kdDebug(6070) << "KJS::HTMLElementFunction::tryCall " << endl;
02084 #endif
02085   DOM::HTMLElement element = static_cast<KJS::HTMLElement *>(thisObj.imp())->toElement();
02086 
02087   switch (element.elementId()) {
02088     case ID_FORM: {
02089       DOM::HTMLFormElement form = element;
02090       if (id == KJS::HTMLElement::FormSubmit) {
02091 
02092 
02093         DOM::HTMLDocument doc = element.ownerDocument();
02094         KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
02095         KHTMLSettings::KJSWindowOpenPolicy policy = KHTMLSettings::KJSWindowOpenAllow;
02096     if (view)
02097         policy = view->part()->settings()->windowOpenPolicy(view->part()->url().host());
02098 
02099         bool block = false;
02100 
02101         if ( policy != KHTMLSettings::KJSWindowOpenAllow ) {
02102           block = true;
02103 
02104          // if this is a form without a target, or a special target, don't block
02105           QString trg = form.target().lower().string();
02106           if( trg.isEmpty() || trg == "_top" || trg == "_self" ||
02107               trg == "_parent")
02108             block = false;
02109 
02110           QString caption;
02111 
02112           // if there is a frame with the target name, don't block
02113           if ( view && view->part() )  {
02114             if (!view->part()->url().host().isEmpty())
02115               caption = view->part()->url().host() + " - ";
02116             // search all (possibly nested) framesets
02117             KHTMLPart *currentPart = view->part()->parentPart();
02118             while( currentPart != 0L ) {
02119               if( currentPart->frameExists( form.target().string() ) )
02120                 block = false;
02121               currentPart = currentPart->parentPart();
02122             }
02123           }
02124 
02125           if ( block && policy == KHTMLSettings::KJSWindowOpenAsk && view ) {
02126             if (view && view->part())
02127             emit view->part()->browserExtension()->requestFocus(view->part());
02128             caption += i18n( "Confirmation: JavaScript Popup" );
02129             if ( KMessageBox::questionYesNo(view, form.action().isEmpty() ?
02130                    i18n( "This site is submitting a form which will open up a new browser "
02131                          "window via JavaScript.\n"
02132                          "Do you want to allow the form to be submitted?" ) :
02133                    i18n( "<qt>This site is submitting a form which will open <p>%1</p> in a new browser window via JavaScript.<br />"
02134                          "Do you want to allow the form to be submitted?</qt>").arg(KStringHandler::csqueeze(form.action().string(),  100)),
02135                    caption, i18n("Allow"), i18n("Do Not Allow") ) == KMessageBox::Yes )
02136               block = false;
02137 
02138           } else if ( block && policy == KHTMLSettings::KJSWindowOpenSmart ) {
02139             if( static_cast<KJS::ScriptInterpreter *>(exec->interpreter())->isWindowOpenAllowed() ) {
02140               // This submission has been triggered by the user
02141               block = false;
02142             }
02143           }
02144         }
02145 
02146         if( !block )
02147           form.submit();
02148 
02149         return Undefined();
02150       }
02151       else if (id == KJS::HTMLElement::FormReset) {
02152         form.reset();
02153         return Undefined();
02154       }
02155     }
02156     break;
02157     case ID_SELECT: {
02158       DOM::HTMLSelectElement select = element;
02159       if (id == KJS::HTMLElement::SelectAdd) {
02160         select.add(KJS::toNode(args[0]),KJS::toNode(args[1]));
02161         return Undefined();
02162       }
02163       else if (id == KJS::HTMLElement::SelectRemove) {
02164         select.remove(int(args[0].toNumber(exec)));
02165         return Undefined();
02166       }
02167       else if (id == KJS::HTMLElement::SelectBlur) {
02168         select.blur();
02169         return Undefined();
02170       }
02171       else if (id == KJS::HTMLElement::SelectFocus) {
02172         select.focus();
02173         return Undefined();
02174       }
02175     }
02176     break;
02177     case ID_INPUT: {
02178       DOM::HTMLInputElement input = element;
02179       if (id == KJS::HTMLElement::InputBlur) {
02180         input.blur();
02181         return Undefined();
02182       }
02183       else if (id == KJS::HTMLElement::InputFocus) {
02184         input.focus();
02185         return Undefined();
02186       }
02187       else if (id == KJS::HTMLElement::InputSelect) {
02188         input.select();
02189         return Undefined();
02190       }
02191       else if (id == KJS::HTMLElement::InputClick) {
02192         input.click();
02193         return Undefined();
02194       }
02195       else if (id == KJS::HTMLElement::InputSetSelectionRange) {
02196         input.setSelectionRange(args[0].toNumber(exec), args[1].toNumber(exec));
02197         return Undefined();
02198       }
02199     }
02200     break;
02201     case ID_BUTTON: {
02202       DOM::HTMLButtonElement button = element;
02203       if (id == KJS::HTMLElement::ButtonBlur) {
02204         button.blur();
02205         return Undefined();
02206       }
02207       else if (id == KJS::HTMLElement::ButtonFocus) {
02208         button.focus();
02209         return Undefined();
02210       }
02211     }
02212     break;
02213     case ID_TEXTAREA: {
02214       DOM::HTMLTextAreaElement textarea = element;
02215       if (id == KJS::HTMLElement::TextAreaBlur) {
02216         textarea.blur();
02217         return Undefined();
02218       }
02219       else if (id == KJS::HTMLElement::TextAreaFocus) {
02220         textarea.focus();
02221         return Undefined();
02222       }
02223       else if (id == KJS::HTMLElement::TextAreaSelect) {
02224         textarea.select();
02225         return Undefined();
02226       }
02227       else if (id == KJS::HTMLElement::TextAreaSetSelectionRange) {
02228         textarea.setSelectionRange(args[0].toNumber(exec), args[1].toNumber(exec));
02229         return Undefined();
02230       }
02231 
02232     }
02233     break;
02234     case ID_A: {
02235       DOM::HTMLAnchorElement anchor = element;
02236       if (id == KJS::HTMLElement::AnchorBlur) {
02237         anchor.blur();
02238         return Undefined();
02239       }
02240       else if (id == KJS::HTMLElement::AnchorFocus) {
02241         anchor.focus();
02242         return Undefined();
02243       }
02244       else if (id == KJS::HTMLElement::AnchorClick) {
02245         static_cast<DOM::HTMLAnchorElementImpl*>(anchor.handle())->click();
02246         return Undefined();
02247       }
02248     }
02249     break;
02250     case ID_TABLE: {
02251       DOM::HTMLTableElement table = element;
02252       if (id == KJS::HTMLElement::TableCreateTHead)
02253         return getDOMNode(exec,table.createTHead());
02254       else if (id == KJS::HTMLElement::TableDeleteTHead) {
02255         table.deleteTHead();
02256         return Undefined();
02257       }
02258       else if (id == KJS::HTMLElement::TableCreateTFoot)
02259         return getDOMNode(exec,table.createTFoot());
02260       else if (id == KJS::HTMLElement::TableDeleteTFoot) {
02261         table.deleteTFoot();
02262         return Undefined();
02263       }
02264       else if (id == KJS::HTMLElement::TableCreateCaption)
02265         return getDOMNode(exec,table.createCaption());
02266       else if (id == KJS::HTMLElement::TableDeleteCaption) {
02267         table.deleteCaption();
02268         return Undefined();
02269       }
02270       else if (id == KJS::HTMLElement::TableInsertRow)
02271         return getDOMNode(exec,table.insertRow(args[0].toInteger(exec)));
02272       else if (id == KJS::HTMLElement::TableDeleteRow) {
02273         table.deleteRow(args[0].toInteger(exec));
02274         return Undefined();
02275       }
02276     }
02277     break;
02278     case ID_THEAD:
02279     case ID_TBODY:
02280     case ID_TFOOT: {
02281       DOM::HTMLTableSectionElement tableSection = element;
02282       if (id == KJS::HTMLElement::TableSectionInsertRow)
02283         return getDOMNode(exec,tableSection.insertRow(args[0].toInteger(exec)));
02284       else if (id == KJS::HTMLElement::TableSectionDeleteRow) {
02285         tableSection.deleteRow(args[0].toInteger(exec));
02286         return Undefined();
02287       }
02288     }
02289     break;
02290     case ID_TR: {
02291       DOM::HTMLTableRowElement tableRow = element;
02292       if (id == KJS::HTMLElement::TableRowInsertCell)
02293         return getDOMNode(exec,tableRow.insertCell(args[0].toInteger(exec)));
02294       else if (id == KJS::HTMLElement::TableRowDeleteCell) {
02295         tableRow.deleteCell(args[0].toInteger(exec));
02296         return Undefined();
02297       }
02298       break;
02299     }
02300     case ID_MARQUEE: {
02301       if (id == KJS::HTMLElement::MarqueeStart && element.handle()->renderer() &&
02302         element.handle()->renderer()->layer() &&
02303         element.handle()->renderer()->layer()->marquee()) {
02304         element.handle()->renderer()->layer()->marquee()->start();
02305         return Undefined();
02306       }
02307       else if (id == KJS::HTMLElement::MarqueeStop && element.handle()->renderer() &&
02308               element.handle()->renderer()->layer() &&
02309               element.handle()->renderer()->layer()->marquee()) {
02310         element.handle()->renderer()->layer()->marquee()->stop();
02311         return Undefined();
02312       }
02313       break;
02314     }
02315   }
02316 
02317   if (id == HTMLElement::ElementScrollIntoView) {
02318     // ### implement
02319     kdWarning() << "non-standard HTMLElement::scrollIntoView() not implemented"
02320         << endl;
02321     return Undefined();
02322   }
02323 
02324   return Undefined();
02325 }
02326 
02327 void KJS::HTMLElement::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
02328 {
02329 #ifdef KJS_VERBOSE
02330   DOM::DOMString str = value.isA(NullType) ? DOM::DOMString() : value.toString(exec).string();
02331 #endif
02332   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02333 #ifdef KJS_VERBOSE
02334   kdDebug(6070) << "KJS::HTMLElement::tryPut " << propertyName.qstring()
02335                 << " thisTag=" << element.tagName().string()
02336                 << " str=" << str.string() << endl;
02337 #endif
02338   // First look at dynamic properties
02339   switch (element.elementId()) {
02340     case ID_SELECT: {
02341       DOM::HTMLSelectElement select = element;
02342       bool ok;
02343       /*uint u =*/ propertyName.toULong(&ok);
02344       if (ok) {
02345         Object coll = Object::dynamicCast( getSelectHTMLCollection(exec, select.options(), select) );
02346         if ( coll.isValid() )
02347           coll.put(exec,propertyName,value);
02348         return;
02349       }
02350       break;
02351     }
02352     case ID_APPLET:
02353     case ID_OBJECT:
02354     case ID_EMBED: {
02355       KParts::LiveConnectExtension *lc = getLiveConnectExtension(element);
02356       if (lc && lc->put(0, propertyName.qstring(), value.toString(exec).qstring()))
02357         return;
02358       break;
02359     }
02360     default:
02361       break;
02362   }
02363 
02364   const HashTable* table = classInfo()->propHashTable; // get the right hashtable
02365   const HashEntry* entry = Lookup::findEntry(table, propertyName);
02366   if (entry) {
02367     if (entry->attr & Function) // function: put as override property
02368     {
02369       ObjectImp::put(exec, propertyName, value, attr);
02370       return;
02371     }
02372     else if ((entry->attr & ReadOnly) == 0) // let DOMObjectLookupPut print the warning if not
02373     {
02374       putValueProperty(exec, entry->value, value, attr);
02375       return;
02376     }
02377   }
02378   DOMObjectLookupPut<KJS::HTMLElement, DOMElement>(exec, propertyName, value, attr, &KJS::HTMLElementTable, this);
02379 }
02380 
02381 void KJS::HTMLElement::putValueProperty(ExecState *exec, int token, const Value& value, int)
02382 {
02383   DOM::DOMString str = value.isA(NullType) ? DOM::DOMString() : value.toString(exec).string();
02384   DOMNode *kjsNode = new DOMNode(exec, KJS::toNode(value));
02385   // Need to create a Value wrapper to avoid leaking the KJS::DOMNode
02386   Value nodeValue(kjsNode);
02387   DOM::Node n = kjsNode->toNode();
02388   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02389 #ifdef KJS_VERBOSE
02390   kdDebug(6070) << "KJS::HTMLElement::putValueProperty "
02391                 << " thisTag=" << element.tagName().string()
02392                 << " token=" << token << endl;
02393 #endif
02394 
02395   switch (element.elementId()) {
02396   case ID_HTML: {
02397       DOM::HTMLHtmlElement html = element;
02398       switch (token) {
02399       case HtmlVersion:         { html.setVersion(str); return; }
02400       }
02401   }
02402   break;
02403   case ID_HEAD: {
02404     DOM::HTMLHeadElement head = element;
02405     switch (token) {
02406     case HeadProfile:         { head.setProfile(str); return; }
02407     }
02408   }
02409   break;
02410   case ID_LINK: {
02411     DOM::HTMLLinkElement link = element;
02412     switch (token) {
02413       case LinkDisabled:        { link.setDisabled(value.toBoolean(exec)); return; }
02414       case LinkCharset:         { link.setCharset(str); return; }
02415       case LinkHref:            { link.setHref(str); return; }
02416       case LinkHrefLang:        { link.setHreflang(str); return; }
02417       case LinkMedia:           { link.setMedia(str); return; }
02418       case LinkRel:             { link.setRel(str); return; }
02419       case LinkRev:             { link.setRev(str); return; }
02420       case LinkTarget:          { link.setTarget(str); return; }
02421       case LinkType:            { link.setType(str); return; }
02422       }
02423     }
02424     break;
02425     case ID_TITLE: {
02426       DOM::HTMLTitleElement title = element;
02427       switch (token) {
02428       case TitleText:                 { title.setText(str); return; }
02429       }
02430     }
02431     break;
02432     case ID_META: {
02433       DOM::HTMLMetaElement meta = element;
02434       switch (token) {
02435       case MetaContent:         { meta.setContent(str); return; }
02436       case MetaHttpEquiv:       { meta.setHttpEquiv(str); return; }
02437       case MetaName:            { meta.setName(str); return; }
02438       case MetaScheme:          { meta.setScheme(str); return; }
02439       }
02440     }
02441     break;
02442     case ID_BASE: {
02443       DOM::HTMLBaseElement base = element;
02444       switch (token) {
02445       case BaseHref:            { base.setHref(str); return; }
02446       case BaseTarget:          { base.setTarget(str); return; }
02447       }
02448     }
02449     break;
02450     case ID_ISINDEX: {
02451       DOM::HTMLIsIndexElement isindex = element;
02452       switch (token) {
02453       // read-only: form
02454       case IsIndexPrompt:               { isindex.setPrompt(str); return; }
02455       }
02456     }
02457     break;
02458     case ID_STYLE: {
02459       DOM::HTMLStyleElement style = element;
02460       switch (token) {
02461       case StyleDisabled:        { style.setDisabled(value.toBoolean(exec)); return; }
02462       case StyleMedia:           { style.setMedia(str); return; }
02463       case StyleType:            { style.setType(str); return; }
02464       }
02465     }
02466     break;
02467     case ID_BODY: {
02468       DOM::HTMLBodyElement body = element;
02469       switch (token) {
02470       case BodyALink:           { body.setALink(str); return; }
02471       case BodyBackground:      { body.setBackground(str); return; }
02472       case BodyBgColor:         { body.setBgColor(str); return; }
02473       case BodyLink:            { body.setLink(str); return; }
02474       case BodyText:            { body.setText(str); return; }
02475       case BodyVLink:           { body.setVLink(str); return; }
02476       case BodyOnLoad:
02477         DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(node.ownerDocument().handle());
02478         if (doc && checkNodeSecurity(exec, node))
02479         {
02480           DOMNode* kjsDocNode = new DOMNode(exec, doc);
02481           // Need to create a Value wrapper to avoid leaking the KJS::DOMNode
02482           Value nodeValue(kjsDocNode);
02483           kjsDocNode->setListener(exec,DOM::EventImpl::LOAD_EVENT,value);
02484         }
02485         return;
02486       }
02487     }
02488     break;
02489     case ID_FORM: {
02490       DOM::HTMLFormElement form = element;
02491       switch (token) {
02492       // read-only: elements
02493       // read-only: length
02494       case FormName:            { form.setName(str); return; }
02495       case FormAcceptCharset:   { form.setAcceptCharset(str); return; }
02496       case FormAction:          { form.setAction(str.string()); return; }
02497       case FormEncType:         { form.setEnctype(str); return; }
02498       case FormMethod:          { form.setMethod(str); return; }
02499       case FormTarget:          { form.setTarget(str); return; }
02500       }
02501     }
02502     break;
02503     case ID_SELECT: {
02504       DOM::HTMLSelectElement select = element;
02505       switch (token) {
02506       // read-only: type
02507       case SelectSelectedIndex:   { select.setSelectedIndex(value.toInteger(exec)); return; }
02508       case SelectValue:           { select.setValue(str); return; }
02509       case SelectLength:          { // read-only according to the NS spec, but webpages need it writeable
02510                                          Object coll = Object::dynamicCast( getSelectHTMLCollection(exec, select.options(), select) );
02511                                          if ( coll.isValid() )
02512                                            coll.put(exec,"length",value);
02513                                          return;
02514                                        }
02515       // read-only: form
02516       // read-only: options
02517       case SelectDisabled:        { select.setDisabled(value.toBoolean(exec)); return; }
02518       case SelectMultiple:        { select.setMultiple(value.toBoolean(exec)); return; }
02519       case SelectName:            { select.setName(str); return; }
02520       case SelectSize:            { select.setSize(value.toInteger(exec)); return; }
02521       case SelectTabIndex:        { select.setTabIndex(value.toInteger(exec)); return; }
02522       }
02523     }
02524     break;
02525     case ID_OPTGROUP: {
02526       DOM::HTMLOptGroupElement optgroup = element;
02527       switch (token) {
02528       case OptGroupDisabled:        { optgroup.setDisabled(value.toBoolean(exec)); return; }
02529       case OptGroupLabel:           { optgroup.setLabel(str); return; }
02530       }
02531     }
02532     break;
02533     case ID_OPTION: {
02534       DOM::HTMLOptionElement option = element;
02535       switch (token) {
02536       // read-only: form
02537       case OptionDefaultSelected: { option.setDefaultSelected(value.toBoolean(exec)); return; }
02538       // read-only: text  <--- According to the DOM, but JavaScript and JScript both allow changes.
02539       // So, we'll do it here and not add it to our DOM headers.
02540       case OptionText:            { DOM::NodeList nl(option.childNodes());
02541                                     for (unsigned int i = 0; i < nl.length(); i++) {
02542                                         if (nl.item(i).nodeType() == DOM::Node::TEXT_NODE) {
02543                                             static_cast<DOM::Text>(nl.item(i)).setData(str);
02544                                             return;
02545                                         }
02546                                   }
02547                                   // No child text node found, creating one
02548                                   DOM::Text t = option.ownerDocument().createTextNode(str);
02549                                   try { option.appendChild(t); }
02550                                   catch(DOM::DOMException& e) {
02551                                     // #### exec->setException ?
02552                                   }
02553 
02554                                   return;
02555       }
02556       // read-only: index
02557       case OptionDisabled:        { option.setDisabled(value.toBoolean(exec)); return; }
02558       case OptionLabel:           { option.setLabel(str); return; }
02559       case OptionSelected:        { option.setSelected(value.toBoolean(exec)); return; }
02560       case OptionValue:           { option.setValue(str); return; }
02561       }
02562     }
02563     break;
02564     case ID_INPUT: {
02565       DOM::HTMLInputElement input = element;
02566       switch (token) {
02567       case InputDefaultValue:    { input.setDefaultValue(str); return; }
02568       case InputDefaultChecked:  { input.setDefaultChecked(value.toBoolean(exec)); return; }
02569       // read-only: form
02570       case InputAccept:          { input.setAccept(str); return; }
02571       case InputAccessKey:       { input.setAccessKey(str); return; }
02572       case InputAlign:           { input.setAlign(str); return; }
02573       case InputAlt:             { input.setAlt(str); return; }
02574       case InputChecked:         { input.setChecked(value.toBoolean(exec)); return; }
02575       case InputIndeterminate:   { input.setIndeterminate(value.toBoolean(exec)); return; }
02576       case InputDisabled:        { input.setDisabled(value.toBoolean(exec)); return; }
02577       case InputMaxLength:       { input.setMaxLength(value.toInteger(exec)); return; }
02578       case InputName:            { input.setName(str); return; }
02579       case InputReadOnly:        { input.setReadOnly(value.toBoolean(exec)); return; }
02580       case InputSize:            { input.setSize(value.toInteger(exec)); return; }
02581       case InputSrc:             { input.setSrc(str); return; }
02582       case InputTabIndex:        { input.setTabIndex(value.toInteger(exec)); return; }
02583       case InputType:            { input.setType(str); return; }
02584       case InputUseMap:          { input.setUseMap(str); return; }
02585       case InputValue:           { input.setValue(str); return; }
02586       case InputSelectionStart:  { input.setSelectionStart(value.toInteger(exec)); return; }
02587       case InputSelectionEnd:    { input.setSelectionEnd  (value.toInteger(exec)); return; }
02588       }
02589     }
02590     break;
02591     case ID_TEXTAREA: {
02592       DOM::HTMLTextAreaElement textarea = element;
02593       switch (token) {
02594       case TextAreaDefaultValue:    { textarea.setDefaultValue(str); return; }
02595       // read-only: form
02596       case TextAreaAccessKey:       { textarea.setAccessKey(str); return; }
02597       case TextAreaCols:            { textarea.setCols(value.toInteger(exec)); return; }
02598       case TextAreaDisabled:        { textarea.setDisabled(value.toBoolean(exec)); return; }
02599       case TextAreaName:            { textarea.setName(str); return; }
02600       case TextAreaReadOnly:        { textarea.setReadOnly(value.toBoolean(exec)); return; }
02601       case TextAreaRows:            { textarea.setRows(value.toInteger(exec)); return; }
02602       case TextAreaTabIndex:        { textarea.setTabIndex(value.toInteger(exec)); return; }
02603       // read-only: type
02604       case TextAreaValue:           { textarea.setValue(str); return; }
02605       case TextAreaSelectionStart:  { textarea.setSelectionStart(value.toInteger(exec)); return; }
02606       case TextAreaSelectionEnd:    { textarea.setSelectionEnd  (value.toInteger(exec)); return; }
02607       }
02608     }
02609     break;
02610     case ID_BUTTON: {
02611       DOM::HTMLButtonElement button = element;
02612       switch (token) {
02613       // read-only: form
02614       case ButtonAccessKey:       { button.setAccessKey(str); return; }
02615       case ButtonDisabled:        { button.setDisabled(value.toBoolean(exec)); return; }
02616       case ButtonName:            { button.setName(str); return; }
02617       case ButtonTabIndex:        { button.setTabIndex(value.toInteger(exec)); return; }
02618       // read-only: type
02619       case ButtonValue:           { button.setValue(str); return; }
02620       }
02621     }
02622     break;
02623     case ID_LABEL: {
02624       DOM::HTMLLabelElement label = element;
02625       switch (token) {
02626       // read-only: form
02627       case LabelAccessKey:       { label.setAccessKey(str); return; }
02628       case LabelHtmlFor:         { label.setHtmlFor(str); return; }
02629       }
02630     }
02631     break;
02632 //    case ID_FIELDSET: {
02633 //      DOM::HTMLFieldSetElement fieldSet = element;
02634 //      // read-only: form
02635 //    }
02636 //    break;
02637     case ID_LEGEND: {
02638       DOM::HTMLLegendElement legend = element;
02639       switch (token) {
02640       // read-only: form
02641       case LegendAccessKey:       { legend.setAccessKey(str); return; }
02642       case LegendAlign:           { legend.setAlign(str); return; }
02643       }
02644     }
02645     break;
02646     case ID_UL: {
02647       DOM::HTMLUListElement uList = element;
02648       switch (token) {
02649       case UListCompact:         { uList.setCompact(value.toBoolean(exec)); return; }
02650       case UListType:            { uList.setType(str); return; }
02651       }
02652     }
02653     break;
02654     case ID_OL: {
02655       DOM::HTMLOListElement oList = element;
02656       switch (token) {
02657       case OListCompact:         { oList.setCompact(value.toBoolean(exec)); return; }
02658       case OListStart:           { oList.setStart(value.toInteger(exec)); return; }
02659       case OListType:            { oList.setType(str); return; }
02660       }
02661     }
02662     break;
02663     case ID_DL: {
02664       DOM::HTMLDListElement dList = element;
02665       switch (token) {
02666       case DListCompact:         { dList.setCompact(value.toBoolean(exec)); return; }
02667       }
02668     }
02669     break;
02670     case ID_DIR: {
02671       DOM::HTMLDirectoryElement directory = element;
02672       switch (token) {
02673       case DirectoryCompact:     { directory.setCompact(value.toBoolean(exec)); return; }
02674       }
02675     }
02676     break;
02677     case ID_MENU: {
02678       DOM::HTMLMenuElement menu = element;
02679       switch (token) {
02680       case MenuCompact:         { menu.setCompact(value.toBoolean(exec)); return; }
02681       }
02682     }
02683     break;
02684     case ID_LI: {
02685       DOM::HTMLLIElement li = element;
02686       switch (token) {
02687       case LIType:            { li.setType(str); return; }
02688       case LIValue:           { li.setValue(value.toInteger(exec)); return; }
02689       }
02690     }
02691     break;
02692     case ID_DIV: {
02693       DOM::HTMLDivElement div = element;
02694       switch (token) {
02695       case DivAlign:           { div.setAlign(str); return; }
02696       }
02697     }
02698     break;
02699     case ID_P: {
02700       DOM::HTMLParagraphElement paragraph = element;
02701       switch (token) {
02702       case ParagraphAlign:     { paragraph.setAlign(str); return; }
02703       }
02704     }
02705     break;
02706     case ID_H1:
02707     case ID_H2:
02708     case ID_H3:
02709     case ID_H4:
02710     case ID_H5:
02711     case ID_H6: {
02712       DOM::HTMLHeadingElement heading = element;
02713       switch (token) {
02714       case HeadingAlign:         { heading.setAlign(str); return; }
02715       }
02716     }
02717     break;
02718     case ID_BLOCKQUOTE: {
02719       DOM::HTMLBlockquoteElement blockquote = element;
02720       switch (token) {
02721       case BlockQuoteCite:       { blockquote.setCite(str); return; }
02722       }
02723     }
02724     break;
02725     case ID_Q: {
02726       DOM::HTMLQuoteElement quote = element;
02727       switch (token) {
02728       case QuoteCite:            { quote.setCite(str); return; }
02729       }
02730     }
02731     break;
02732     case ID_PRE: {
02733       DOM::HTMLPreElement pre = element;
02734       switch (token) {
02735       case PreWidth:           { pre.setWidth(value.toInteger(exec)); return; }
02736       }
02737     }
02738     break;
02739     case ID_BR: {
02740       DOM::HTMLBRElement br = element;
02741       switch (token) {
02742       case BRClear:           { br.setClear(str); return; }
02743       }
02744     }
02745     break;
02746     case ID_BASEFONT: {
02747       DOM::HTMLBaseFontElement baseFont = element;
02748       switch (token) {
02749       case BaseFontColor:           { baseFont.setColor(str); return; }
02750       case BaseFontFace:            { baseFont.setFace(str); return; }
02751       case BaseFontSize:            { baseFont.setSize(value.toInteger(exec)); return; }
02752       }
02753     }
02754     break;
02755     case ID_FONT: {
02756       DOM::HTMLFontElement font = element;
02757       switch (token) {
02758       case FontColor:           { font.setColor(str); return; }
02759       case FontFace:            { font.setFace(str); return; }
02760       case FontSize:            { font.setSize(str); return; }
02761       }
02762     }
02763     break;
02764     case ID_HR: {
02765       DOM::HTMLHRElement hr = element;
02766       switch (token) {
02767       case HRAlign:           { hr.setAlign(str); return; }
02768       case HRNoShade:         { hr.setNoShade(value.toBoolean(exec)); return; }
02769       case HRSize:            { hr.setSize(str); return; }
02770       case HRWidth:           { hr.setWidth(str); return; }
02771       }
02772     }
02773     break;
02774     case ID_INS:
02775     case ID_DEL: {
02776       DOM::HTMLModElement mod = element;
02777       switch (token) {
02778       case ModCite:            { mod.setCite(str); return; }
02779       case ModDateTime:        { mod.setDateTime(str); return; }
02780       }
02781     }
02782     break;
02783     case ID_A: {
02784       DOM::HTMLAnchorElement anchor = element;
02785       switch (token) {
02786       case AnchorAccessKey:       { anchor.setAccessKey(str); return; }
02787       case AnchorCharset:         { anchor.setCharset(str); return; }
02788       case AnchorCoords:          { anchor.setCoords(str); return; }
02789       case AnchorHref:            { anchor.setHref(str); return; }
02790       case AnchorHrefLang:        { anchor.setHreflang(str); return; }
02791       case AnchorName:            { anchor.setName(str); return; }
02792       case AnchorRel:             { anchor.setRel(str); return; }
02793       case AnchorRev:             { anchor.setRev(str); return; }
02794       case AnchorShape:           { anchor.setShape(str); return; }
02795       case AnchorTabIndex:        { anchor.setTabIndex(value.toInteger(exec)); return; }
02796       case AnchorTarget:          { anchor.setTarget(str); return; }
02797       case AnchorType:            { anchor.setType(str); return; }
02798       }
02799     }
02800     break;
02801     case ID_IMG: {
02802       DOM::HTMLImageElement image = element;
02803       switch (token) {
02804       case ImageName:            { image.setName(str); return; }
02805       case ImageAlign:           { image.setAlign(str); return; }
02806       case ImageAlt:             { image.setAlt(str); return; }
02807       case ImageBorder:          { image.setBorder(str); return; }
02808       case ImageHeight:          { image.setHeight(value.toInteger(exec)); return; }
02809       case ImageHspace:          { image.setHspace(value.toInteger(exec)); return; }
02810       case ImageIsMap:           { image.setIsMap(value.toBoolean(exec)); return; }
02811       case ImageLongDesc:        { image.setLongDesc(str); return; }
02812       case ImageSrc:             { image.setSrc(str); return; }
02813       case ImageUseMap:          { image.setUseMap(str); return; }
02814       case ImageVspace:          { image.setVspace(value.toInteger(exec)); return; }
02815       case ImageWidth:           { image.setWidth(value.toInteger(exec)); return; }
02816       }
02817     }
02818     break;
02819     case ID_OBJECT: {
02820       DOM::HTMLObjectElement object = element;
02821       switch (token) {
02822       // read-only: form
02823       case ObjectCode:                 { object.setCode(str); return; }
02824       case ObjectAlign:           { object.setAlign(str); return; }
02825       case ObjectArchive:         { object.setArchive(str); return; }
02826       case ObjectBorder:          { object.setBorder(str); return; }
02827       case ObjectCodeBase:        { object.setCodeBase(str); return; }
02828       case ObjectCodeType:        { object.setCodeType(str); return; }
02829       // read-only: ObjectContentDocument
02830       case ObjectData:            { object.setData(str); return; }
02831       case ObjectDeclare:         { object.setDeclare(value.toBoolean(exec)); return; }
02832       case ObjectHeight:          { object.setHeight(str); return; }
02833       case ObjectHspace:          { object.setHspace(value.toInteger(exec)); return; }
02834       case ObjectName:            { object.setName(str); return; }
02835       case ObjectStandby:         { object.setStandby(str); return; }
02836       case ObjectTabIndex:        { object.setTabIndex(value.toInteger(exec)); return; }
02837       case ObjectType:            { object.setType(str); return; }
02838       case ObjectUseMap:          { object.setUseMap(str); return; }
02839       case ObjectVspace:          { object.setVspace(value.toInteger(exec)); return; }
02840       case ObjectWidth:           { object.setWidth(str); return; }
02841       }
02842     }
02843     break;
02844     case ID_PARAM: {
02845       DOM::HTMLParamElement param = element;
02846       switch (token) {
02847       case ParamName:            { param.setName(str); return; }
02848       case ParamType:            { param.setType(str); return; }
02849       case ParamValue:           { param.setValue(str); return; }
02850       case ParamValueType:       { param.setValueType(str); return; }
02851       }
02852     }
02853     break;
02854     case ID_APPLET: {
02855       DOM::HTMLAppletElement applet = element;
02856       switch (token) {
02857       case AppletAlign:           { applet.setAlign(str); return; }
02858       case AppletAlt:             { applet.setAlt(str); return; }
02859       case AppletArchive:         { applet.setArchive(str); return; }
02860       case AppletCode:            { applet.setCode(str); return; }
02861       case AppletCodeBase:        { applet.setCodeBase(str); return; }
02862       case AppletHeight:          { applet.setHeight(str); return; }
02863       case AppletHspace:          { applet.setHspace(value.toInteger(exec)); return; }
02864       case AppletName:            { applet.setName(str); return; }
02865       case AppletObject:          { applet.setObject(str); return; }
02866       case AppletVspace:          { applet.setVspace(value.toInteger(exec)); return; }
02867       case AppletWidth:           { applet.setWidth(str); return; }
02868       }
02869     }
02870     break;
02871     case ID_MAP: {
02872       DOM::HTMLMapElement map = element;
02873       switch (token) {
02874       // read-only: areas
02875       case MapName:                 { map.setName(str); return; }
02876      }
02877     }
02878     break;
02879     case ID_AREA: {
02880       DOM::HTMLAreaElement area = element;
02881       switch (token) {
02882       case AreaAccessKey:       { area.setAccessKey(str); return; }
02883       case AreaAlt:             { area.setAlt(str); return; }
02884       case AreaCoords:          { area.setCoords(str); return; }
02885       case AreaHref:            { area.setHref(str); return; }
02886       case AreaNoHref:          { area.setNoHref(value.toBoolean(exec)); return; }
02887       case AreaShape:           { area.setShape(str); return; }
02888       case AreaTabIndex:        { area.setTabIndex(value.toInteger(exec)); return; }
02889       case AreaTarget:          { area.setTarget(str); return; }
02890       }
02891     }
02892     break;
02893     case ID_SCRIPT: {
02894       DOM::HTMLScriptElement script = element;
02895       switch (token) {
02896       case ScriptText:            { script.setText(str); return; }
02897       case ScriptHtmlFor:         { script.setHtmlFor(str); return; }
02898       case ScriptEvent:           { script.setEvent(str); return; }
02899       case ScriptCharset:         { script.setCharset(str); return; }
02900       case ScriptDefer:           { script.setDefer(value.toBoolean(exec)); return; }
02901       case ScriptSrc:             { script.setSrc(str); return; }
02902       case ScriptType:            { script.setType(str); return; }
02903       }
02904     }
02905     break;
02906     case ID_TABLE: {
02907       DOM::HTMLTableElement table = element;
02908       switch (token) {
02909       case TableCaption:         { table.setCaption(n); return; } // type HTMLTableCaptionElement
02910       case TableTHead:           { table.setTHead(n); return; } // type HTMLTableSectionElement
02911       case TableTFoot:           { table.setTFoot(n); return; } // type HTMLTableSectionElement
02912       // read-only: rows
02913       // read-only: tbodies
02914       case TableAlign:           { table.setAlign(str); return; }
02915       case TableBgColor:         { table.setBgColor(str); return; }
02916       case TableBorder:          { table.setBorder(str); return; }
02917       case TableCellPadding:     { table.setCellPadding(str); return; }
02918       case TableCellSpacing:     { table.setCellSpacing(str); return; }
02919       case TableFrame:           { table.setFrame(str); return; }
02920       case TableRules:           { table.setRules(str); return; }
02921       case TableSummary:         { table.setSummary(str); return; }
02922       case TableWidth:           { table.setWidth(str); return; }
02923       }
02924     }
02925     break;
02926     case ID_CAPTION: {
02927       DOM::HTMLTableCaptionElement tableCaption = element;
02928       switch (token) {
02929       case TableCaptionAlign:           { tableCaption.setAlign(str); return; }
02930       }
02931     }
02932     break;
02933     case ID_COL:
02934     case ID_COLGROUP: {
02935       DOM::HTMLTableColElement tableCol = element;
02936       switch (token) {
02937       case TableColAlign:           { tableCol.setAlign(str); return; }
02938       case TableColCh:              { tableCol.setCh(str); return; }
02939       case TableColChOff:           { tableCol.setChOff(str); return; }
02940       case TableColSpan:            { tableCol.setSpan(value.toInteger(exec)); return; }
02941       case TableColVAlign:          { tableCol.setVAlign(str); return; }
02942       case TableColWidth:           { tableCol.setWidth(str); return; }
02943       }
02944     }
02945     break;
02946     case ID_THEAD:
02947     case ID_TBODY:
02948     case ID_TFOOT: {
02949       DOM::HTMLTableSectionElement tableSection = element;
02950       switch (token) {
02951       case TableSectionAlign:           { tableSection.setAlign(str); return; }
02952       case TableSectionCh:              { tableSection.setCh(str); return; }
02953       case TableSectionChOff:           { tableSection.setChOff(str); return; }
02954       case TableSectionVAlign:          { tableSection.setVAlign(str); return; }
02955       // read-only: rows
02956       }
02957     }
02958     break;
02959     case ID_TR: {
02960       DOM::HTMLTableRowElement tableRow = element;
02961       switch (token) {
02962       // read-only: rowIndex
02963       // read-only: sectionRowIndex
02964       // read-only: cells
02965       case TableRowAlign:           { tableRow.setAlign(str); return; }
02966       case TableRowBgColor:         { tableRow.setBgColor(str); return; }
02967       case TableRowCh:              { tableRow.setCh(str); return; }
02968       case TableRowChOff:           { tableRow.setChOff(str); return; }
02969       case TableRowVAlign:          { tableRow.setVAlign(str); return; }
02970       }
02971     }
02972     break;
02973     case ID_TH:
02974     case ID_TD: {
02975       DOM::HTMLTableCellElement tableCell = element;
02976       switch (token) {
02977       // read-only: cellIndex
02978       case TableCellAbbr:            { tableCell.setAbbr(str); return; }
02979       case TableCellAlign:           { tableCell.setAlign(str); return; }
02980       case TableCellAxis:            { tableCell.setAxis(str); return; }
02981       case TableCellBgColor:         { tableCell.setBgColor(str); return; }
02982       case TableCellCh:              { tableCell.setCh(str); return; }
02983       case TableCellChOff:           { tableCell.setChOff(str); return; }
02984       case TableCellColSpan:         { tableCell.setColSpan(value.toInteger(exec)); return; }
02985       case TableCellHeaders:         { tableCell.setHeaders(str); return; }
02986       case TableCellHeight:          { tableCell.setHeight(str); return; }
02987       case TableCellNoWrap:          { tableCell.setNoWrap(value.toBoolean(exec)); return; }
02988       case TableCellRowSpan:         { tableCell.setRowSpan(value.toInteger(exec)); return; }
02989       case TableCellScope:           { tableCell.setScope(str); return; }
02990       case TableCellVAlign:          { tableCell.setVAlign(str); return; }
02991       case TableCellWidth:           { tableCell.setWidth(str); return; }
02992       }
02993     }
02994     break;
02995     case ID_FRAMESET: {
02996       DOM::HTMLFrameSetElement frameSet = element;
02997       switch (token) {
02998       case FrameSetCols:            { frameSet.setCols(str); return; }
02999       case FrameSetRows:            { frameSet.setRows(str); return; }
03000       }
03001     }
03002     break;
03003     case ID_LAYER: {
03004       DOM::HTMLLayerElement layerElement = element;
03005       switch (token) {
03006       case LayerTop:                   { layerElement.setTop(value.toInteger(exec)); return; }
03007       case LayerLeft:                  { layerElement.setLeft(value.toInteger(exec)); return; }
03008       case LayerVisibility:            { layerElement.setVisibility(str); return; }
03009       case LayerBgColor:               { layerElement.setBgColor(str); return; }
03010       // read-only: layers, clip
03011       }
03012     }
03013     break;
03014     case ID_FRAME: {
03015       DOM::HTMLFrameElement frameElement = element;
03016       switch (token) {
03017        // read-only: FrameContentDocument:
03018       case FrameFrameBorder:     { frameElement.setFrameBorder(str); return; }
03019       case FrameLongDesc:        { frameElement.setLongDesc(str); return; }
03020       case FrameMarginHeight:    { frameElement.setMarginHeight(str); return; }
03021       case FrameMarginWidth:     { frameElement.setMarginWidth(str); return; }
03022       case FrameName:            { frameElement.setName(str); return; }
03023       case FrameNoResize:        { frameElement.setNoResize(value.toBoolean(exec)); return; }
03024       case FrameScrolling:       { frameElement.setScrolling(str); return; }
03025       case FrameSrc:             { frameElement.setSrc(str); return; }
03026       case FrameLocation:        {
03027                                    static_cast<DOM::HTMLFrameElementImpl *>(frameElement.handle())->setLocation(str);
03028                                    return;
03029                                  }
03030       }
03031     }
03032     break;
03033     case ID_IFRAME: {
03034       DOM::HTMLIFrameElement iFrame = element;
03035       switch (token) {
03036       case IFrameAlign:           { iFrame.setAlign(str); return; }
03037       // read-only: IFrameContentDocument
03038       case IFrameFrameBorder:     { iFrame.setFrameBorder(str); return; }
03039       case IFrameHeight:          { iFrame.setHeight(str); return; }
03040       case IFrameLongDesc:        { iFrame.setLongDesc(str); return; }
03041       case IFrameMarginHeight:    { iFrame.setMarginHeight(str); return; }
03042       case IFrameMarginWidth:     { iFrame.setMarginWidth(str); return; }
03043       case IFrameName:            { iFrame.setName(str); return; }
03044       case IFrameScrolling:       { iFrame.setScrolling(str); return; }
03045       case IFrameSrc:             { iFrame.setSrc(str); return; }
03046       case IFrameWidth:           { iFrame.setWidth(str); return; }
03047       }
03048       break;
03049     }
03050   }
03051 
03052   // generic properties
03053   switch (token) {
03054   case ElementId:
03055     element.setId(str);
03056     return;
03057   case ElementTitle:
03058     element.setTitle(str);
03059     return;
03060   case ElementLang:
03061     element.setLang(str);
03062     return;
03063   case ElementDir:
03064     element.setDir(str);
03065     return;
03066   case ElementClassName:
03067     element.setClassName(str);
03068     return;
03069   case ElementInnerHTML:
03070     element.setInnerHTML(str);
03071     return;
03072   case ElementInnerText:
03073     element.setInnerText(str);
03074     return;
03075   default:
03076     kdDebug(6070) << "WARNING: KJS::HTMLElement::putValueProperty unhandled token " << token << " thisTag=" << element.tagName().string() << " str=" << str.string() << endl;
03077   }
03078 }
03079 
03080 // -------------------------------------------------------------------------
03081 /* Source for HTMLCollectionProtoTable.
03082 @begin HTMLCollectionProtoTable 3
03083   item      HTMLCollection::Item        DontDelete|Function 1
03084   namedItem HTMLCollection::NamedItem   DontDelete|Function 1
03085   tags      HTMLCollection::Tags        DontDelete|Function 1
03086 @end
03087 */
03088 DEFINE_PROTOTYPE("HTMLCollection", HTMLCollectionProto)
03089 IMPLEMENT_PROTOFUNC_DOM(HTMLCollectionProtoFunc)
03090 IMPLEMENT_PROTOTYPE(HTMLCollectionProto,HTMLCollectionProtoFunc)
03091 
03092 const ClassInfo KJS::HTMLCollection::info = { "HTMLCollection", 0, 0, 0 };
03093 
03094 KJS::HTMLCollection::HTMLCollection(ExecState *exec, const DOM::HTMLCollection& c)
03095   : DOMObject(HTMLCollectionProto::self(exec)), collection(c), hidden(false) {}
03096 
03097 KJS::HTMLCollection::~HTMLCollection()
03098 {
03099   ScriptInterpreter::forgetDOMObject(collection.handle());
03100 }
03101 
03102 bool KJS::HTMLCollection::toBoolean(ExecState *) const {
03103     return !hidden;
03104 }
03105 
03106 // We have to implement hasProperty since we don't use a hashtable for 'selectedIndex' and 'length',
03107 // and for indices in "for (..in..)"
03108 bool KJS::HTMLCollection::hasProperty(ExecState *exec, const Identifier &p) const
03109 {
03110   if (p == lengthPropertyName)
03111     return true;
03112   if ( collection.handle()->getType() == HTMLCollectionImpl::SELECT_OPTIONS &&
03113        ( p == "selectedIndex" || p == "value" ) )
03114     return true;
03115 
03116   bool ok;
03117   unsigned long pos = p.toULong(&ok);
03118   if (ok && pos < collection.length())
03119     return true;
03120 
03121   return DOMObject::hasProperty(exec, p);
03122 }
03123 
03124 ReferenceList KJS::HTMLCollection::propList(ExecState *exec, bool recursive)
03125 {
03126   ReferenceList properties = ObjectImp::propList(exec,recursive);
03127 
03128   for (unsigned i = 0; i < collection.length(); ++i) {
03129     if (!ObjectImp::hasProperty(exec,Identifier::from(i))) {
03130       properties.append(Reference(this, i));
03131     }
03132   }
03133 
03134   if (!ObjectImp::hasProperty(exec, lengthPropertyName))
03135     properties.append(Reference(this, lengthPropertyName));
03136 
03137   return properties;
03138 }
03139 
03140 Value KJS::HTMLCollection::tryGet(ExecState *exec, const Identifier &propertyName) const
03141 {
03142 #ifdef KJS_VERBOSE
03143   kdDebug(6070) << "KJS::HTMLCollection::tryGet " << propertyName.ascii() << endl;
03144 #endif
03145   if (propertyName == lengthPropertyName)
03146   {
03147 #ifdef KJS_VERBOSE
03148     kdDebug(6070) << "  collection length is " << collection.length() << endl;
03149 #endif
03150     return Number(collection.length());
03151   }
03152 
03153   if (collection.handle()->getType() == HTMLCollectionImpl::SELECT_OPTIONS) {
03154     DOM::HTMLSelectElement parentSelect = collection.base();
03155     if ( parentSelect.isNull() )
03156       return Undefined();
03157     if (propertyName == "selectedIndex") {
03158       // NON-STANDARD options.selectedIndex
03159       return Number(parentSelect.selectedIndex());
03160     } else if ( propertyName == "value" ) {
03161       // NON-STANDARD options.value
03162       return String(parentSelect.value());
03163     }
03164   }
03165 
03166   // Look in the prototype (for functions) before assuming it's an item's name
03167   Object proto = Object::dynamicCast(prototype());
03168   if (proto.isValid() && proto.hasProperty(exec,propertyName))
03169     return proto.get(exec,propertyName);
03170 
03171   // name or index ?
03172   bool ok;
03173   unsigned int u = propertyName.toULong(&ok);
03174   if (ok) {
03175     if ( u < collection.length() ) {
03176       DOM::Node node = collection.item(u);
03177       return getDOMNode(exec,node);
03178     } else
03179       return Undefined();
03180   }
03181   else
03182     return getNamedItems(exec,propertyName);
03183 }
03184 
03185 // HTMLCollections are strange objects, they support both get and call,
03186 // so that document.forms.item(0) and document.forms(0) both work.
03187 Value KJS::HTMLCollection::call(ExecState *exec, Object &thisObj, const List &args)
03188 {
03189   // This code duplication is necessary, HTMLCollection isn't a DOMFunction
03190   Value val;
03191   try {
03192     val = tryCall(exec, thisObj, args);
03193   }
03194   // pity there's no way to distinguish between these in JS code
03195   catch (...) {
03196     Object err = Error::create(exec, GeneralError, "Exception from HTMLCollection");
03197     exec->setException(err);
03198   }
03199   return val;
03200 }
03201 
03202 Value KJS::HTMLCollection::tryCall(ExecState *exec, Object &, const List &args)
03203 {
03204   // Do not use thisObj here. It can be the HTMLDocument, in the document.forms(i) case.
03205   /*if( thisObj.imp() != this )
03206   {
03207     kdDebug(6070) << "WARNING: thisObj.imp() != this in HTMLCollection::tryCall" << endl;
03208     KJS::printInfo(exec,"KJS::HTMLCollection::tryCall thisObj",thisObj,-1);
03209     KJS::printInfo(exec,"KJS::HTMLCollection::tryCall this",Value(this),-1);
03210   }*/
03211   // Also, do we need the TypeError test here ?
03212 
03213   if (args.size() == 1) {
03214     // support for document.all(<index>) etc.
03215     bool ok;
03216     UString s = args[0].toString(exec);
03217     unsigned int u = s.toULong(&ok);
03218     if (ok) {
03219       DOM::Element element = collection.item(u);
03220       return getDOMNode(exec,element);
03221     }
03222     // support for document.images('<name>') etc.
03223     return getNamedItems(exec,Identifier(s));
03224   }
03225   else if (args.size() >= 1) // the second arg, if set, is the index of the item we want
03226   {
03227     bool ok;
03228     UString s = args[0].toString(exec);
03229     unsigned int u = args[1].toString(exec).toULong(&ok);
03230     if (ok)
03231     {
03232       DOM::DOMString pstr = s.string();
03233       DOM::Node node = collection.namedItem(pstr);
03234       while (!node.isNull()) {
03235         if (!u)
03236           return getDOMNode(exec,node);
03237         node = collection.nextNamedItem(pstr);
03238         --u;
03239       }
03240     }
03241   }
03242   return Undefined();
03243 }
03244 
03245 Value KJS::HTMLCollection::getNamedItems(ExecState *exec, const Identifier &propertyName) const
03246 {
03247 #ifdef KJS_VERBOSE
03248   kdDebug(6070) << "KJS::HTMLCollection::getNamedItems " << propertyName.ascii() << endl;
03249 #endif
03250 
03251   DOM::DOMString pstr = propertyName.string();
03252 
03253   QValueList<DOM::NodeImpl*> matches = collection.handle()->namedItems(pstr);
03254 
03255   if (!matches.isEmpty()) {
03256     if (matches.size() == 1) {
03257       DOM::Node node(matches[0]);
03258 #ifdef KJS_VERBOSE
03259       kdDebug(6070) << "returning single node" << endl;
03260 #endif
03261       return getDOMNode(exec,node);
03262     }
03263     else  {
03264       // multiple items, return a collection
03265       QValueList<DOM::Node> nodes;
03266       for (QValueList<DOM::NodeImpl*>::const_iterator i =  matches.begin();
03267                                                       i != matches.end(); ++i)
03268            nodes.append(DOM::Node(*i));
03269 #ifdef KJS_VERBOSE
03270       kdDebug(6070) << "returning list of " << nodes.count() << " nodes" << endl;
03271 #endif
03272       return Value(new DOMNamedNodesCollection(exec, nodes));
03273     }
03274   }
03275 #ifdef KJS_VERBOSE
03276   kdDebug(6070) << "not found" << endl;
03277 #endif
03278   return Undefined();
03279 }
03280 
03281 Value KJS::HTMLCollectionProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
03282 {
03283   KJS_CHECK_THIS( KJS::HTMLCollection, thisObj );
03284   DOM::HTMLCollection coll = static_cast<KJS::HTMLCollection *>(thisObj.imp())->toCollection();
03285 
03286   switch (id) {
03287   case KJS::HTMLCollection::Item:
03288   {
03289     // support for item(<index>) (DOM)
03290     bool ok;
03291     UString s = args[0].toString(exec);
03292     unsigned int u = s.toULong(&ok);
03293     if (ok) {
03294       return getDOMNode(exec,coll.item(u));
03295     }
03296     // support for item('<name>') (IE only)
03297     kdWarning() << "non-standard HTMLCollection.item('" << s.ascii() << "') called, use namedItem instead" << endl;
03298     return getDOMNode(exec,coll.namedItem(s.string()));
03299   }
03300   case KJS::HTMLCollection::Tags:
03301   {
03302     DOM::DOMString tagName = args[0].toString(exec).string();
03303     DOM::NodeList list;
03304     // getElementsByTagName exists in Document and in Element, pick up the right one
03305     if ( coll.base().nodeType() == DOM::Node::DOCUMENT_NODE )
03306     {
03307       DOM::Document doc = coll.base();
03308       list = doc.getElementsByTagName(tagName);
03309 #ifdef KJS_VERBOSE
03310       kdDebug(6070) << "KJS::HTMLCollectionProtoFunc::tryCall document.tags(" << tagName.string() << ") -> " << list.length() << " items in node list" << endl;
03311 #endif
03312     } else
03313     {
03314       DOM::Element e = coll.base();
03315       list = e.getElementsByTagName(tagName);
03316 #ifdef KJS_VERBOSE
03317       kdDebug(6070) << "KJS::HTMLCollectionProtoFunc::tryCall element.tags(" << tagName.string() << ") -> " << list.length() << " items in node list" << endl;
03318 #endif
03319     }
03320     return getDOMNodeList(exec, list);
03321   }
03322   case KJS::HTMLCollection::NamedItem:
03323   {
03324     Value val = static_cast<HTMLCollection *>(thisObj.imp())->getNamedItems(exec, Identifier(args[0].toString(exec)));
03325     // Must return null when asking for a named item that isn't in the collection
03326     // (DOM2 testsuite, HTMLCollection12 test)
03327     if ( val.type() == KJS::UndefinedType )
03328       return Null();
03329     else
03330       return val;
03331   }
03332   default:
03333     return Undefined();
03334   }
03335 }
03336 
03337 Value KJS::HTMLSelectCollection::tryGet(ExecState *exec, const Identifier &p) const
03338 {
03339   if (p == "selectedIndex")
03340     return Number(element.selectedIndex());
03341 
03342   return  HTMLCollection::tryGet(exec, p);
03343 }
03344 
03345 void KJS::HTMLSelectCollection::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int)
03346 {
03347 #ifdef KJS_VERBOSE
03348   kdDebug(6070) << "KJS::HTMLSelectCollection::tryPut " << propertyName.qstring() << endl;
03349 #endif
03350   if ( propertyName == "selectedIndex" ) {
03351     element.setSelectedIndex( value.toInteger( exec ) );
03352     return;
03353   }
03354   // resize ?
03355   else if (propertyName == lengthPropertyName) {
03356     unsigned newLen;
03357     bool converted = value.toUInt32(newLen);
03358 
03359     if (!converted) {
03360       return;
03361     }
03362 
03363     long diff = element.length() - newLen;
03364 
03365     if (diff < 0) { // add dummy elements
03366       do {
03367         element.add(element.ownerDocument().createElement("OPTION"), DOM::HTMLElement());
03368       } while (++diff);
03369     }
03370     else // remove elements
03371       while (diff-- > 0)
03372         element.remove(newLen + diff);
03373 
03374     return;
03375   }
03376   // an index ?
03377   bool ok;
03378   unsigned int u = propertyName.toULong(&ok);
03379   if (!ok)
03380     return;
03381 
03382   if (value.isA(NullType) || value.isA(UndefinedType)) {
03383     // null and undefined delete. others, too ?
03384     element.remove(u);
03385     return;
03386   }
03387 
03388   // is v an option element ?
03389   DOM::Node node = KJS::toNode(value);
03390   if (node.isNull() || node.elementId() != ID_OPTION)
03391     return;
03392 
03393   DOM::HTMLOptionElement option = static_cast<DOM::HTMLOptionElement>(node);
03394   if ( option.ownerDocument() != element.ownerDocument() )
03395     option = static_cast<DOM::HTMLOptionElement>(element.ownerDocument().importNode(option, true));
03396   long diff = long(u) - element.length();
03397   DOM::HTMLElement before;
03398   // out of array bounds ? first insert empty dummies
03399   if (diff > 0) {
03400     while (diff--) {
03401       element.add(element.ownerDocument().createElement("OPTION"), before);
03402     }
03403     // replace an existing entry ?
03404   } else if (diff < 0) {
03405     before = element.options().item(u+1);
03406     element.remove(u);
03407   }
03408   // finally add the new element
03409   element.add(option, before);
03410 }
03411 
03413 
03414 OptionConstructorImp::OptionConstructorImp(ExecState *exec, const DOM::Document &d)
03415     : ObjectImp(), doc(d)
03416 {
03417   // ## isn't there some redundancy between ObjectImp::_proto and the "prototype" property ?
03418   //put(exec,"prototype", ...,DontEnum|DontDelete|ReadOnly);
03419 
03420   // no. of arguments for constructor
03421   // ## is 4 correct ? 0 to 4, it seems to be
03422   put(exec,lengthPropertyName, Number(4), ReadOnly|DontDelete|DontEnum);
03423 }
03424 
03425 bool OptionConstructorImp::implementsConstruct() const
03426 {
03427   return true;
03428 }
03429 
03430 Object OptionConstructorImp::construct(ExecState *exec, const List &args)
03431 {
03432   DOM::Element el = doc.createElement("OPTION");
03433   DOM::HTMLOptionElement opt = static_cast<DOM::HTMLOptionElement>(el);
03434   int sz = args.size();
03435   DOM::Text t = doc.createTextNode("");
03436   try { opt.appendChild(t); }
03437   catch(DOM::DOMException& e) {
03438     // #### exec->setException ?
03439   }
03440   if (sz > 0)
03441     t.setData(args[0].toString(exec).string()); // set the text
03442   if (sz > 1)
03443     opt.setValue(args[1].toString(exec).string());
03444   if (sz > 2)
03445     opt.setDefaultSelected(args[2].toBoolean(exec));
03446   if (sz > 3)
03447     opt.setSelected(args[3].toBoolean(exec));
03448 
03449   return Object::dynamicCast(getDOMNode(exec,opt));
03450 }
03451 
03453 
03454 //Like in other browsers, we merely make a new HTMLImageElement
03455 //not in tree for this.
03456 ImageConstructorImp::ImageConstructorImp(ExecState *, const DOM::Document &d)
03457     : ObjectImp(), doc(d)
03458 {
03459 }
03460 
03461 bool ImageConstructorImp::implementsConstruct() const
03462 {
03463   return true;
03464 }
03465 
03466 Object ImageConstructorImp::construct(ExecState *exec, const List &list)
03467 {
03468   bool widthSet = false, heightSet = false;
03469   int width = 0, height = 0;
03470   if (list.size() > 0) {
03471     widthSet = true;
03472     Value w = list.at(0);
03473     width = w.toInt32(exec);
03474   }
03475   if (list.size() > 1) {
03476     heightSet = true;
03477     Value h = list.at(1);
03478     height = h.toInt32(exec);
03479   }
03480 
03481   HTMLImageElement image(doc.createElement("image"));
03482 
03483   if (widthSet)
03484     image.setWidth(width);
03485 
03486   if (heightSet)
03487     image.setHeight(height);
03488 
03489   return Object::dynamicCast(getDOMNode(exec,image));
03490 }
03491 
03492 Value KJS::getHTMLCollection(ExecState *exec, const DOM::HTMLCollection& c, bool hide)
03493 {
03494   Value coll = cacheDOMObject<DOM::HTMLCollection, KJS::HTMLCollection>(exec, c);
03495   if (hide) {
03496     KJS::HTMLCollection *impl = static_cast<KJS::HTMLCollection*>(coll.imp());
03497     impl->hide();
03498   }
03499   return coll;
03500 }
03501 
03502 Value KJS::getSelectHTMLCollection(ExecState *exec, const DOM::HTMLCollection& c, const DOM::HTMLSelectElement& e)
03503 {
03504   DOMObject *ret;
03505   if (c.isNull())
03506     return Null();
03507   ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
03508   if ((ret = interp->getDOMObject(c.handle())))
03509     return Value(ret);
03510   else {
03511     ret = new HTMLSelectCollection(exec, c, e);
03512     interp->putDOMObject(c.handle(),ret);
03513     return Value(ret);
03514   }
03515 }
KDE Home | KDE Accessibility Home | Description of Access Keys