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