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   click     KJS::HTMLElement::AnchorClick       DontDelete|Function 0
00897 @end
00898 @begin HTMLImageElementTable 15
00899   name      KJS::HTMLElement::ImageName     DontDelete
00900   align     KJS::HTMLElement::ImageAlign        DontDelete
00901   alt       KJS::HTMLElement::ImageAlt      DontDelete
00902   border    KJS::HTMLElement::ImageBorder       DontDelete
00903   complete  KJS::HTMLElement::ImageComplete     DontDelete|ReadOnly
00904   height    KJS::HTMLElement::ImageHeight       DontDelete
00905   hspace    KJS::HTMLElement::ImageHspace       DontDelete
00906   isMap     KJS::HTMLElement::ImageIsMap        DontDelete
00907   longDesc  KJS::HTMLElement::ImageLongDesc     DontDelete
00908   src       KJS::HTMLElement::ImageSrc      DontDelete
00909   useMap    KJS::HTMLElement::ImageUseMap       DontDelete
00910   vspace    KJS::HTMLElement::ImageVspace       DontDelete
00911   width     KJS::HTMLElement::ImageWidth        DontDelete
00912   x         KJS::HTMLElement::ImageX        DontDelete|ReadOnly
00913   y         KJS::HTMLElement::ImageY        DontDelete|ReadOnly
00914 @end
00915 @begin HTMLObjectElementTable 20
00916   form        KJS::HTMLElement::ObjectForm        DontDelete|ReadOnly
00917   code        KJS::HTMLElement::ObjectCode        DontDelete
00918   align       KJS::HTMLElement::ObjectAlign       DontDelete
00919   archive     KJS::HTMLElement::ObjectArchive     DontDelete
00920   border      KJS::HTMLElement::ObjectBorder      DontDelete
00921   codeBase    KJS::HTMLElement::ObjectCodeBase    DontDelete
00922   codeType    KJS::HTMLElement::ObjectCodeType    DontDelete
00923   contentDocument KJS::HTMLElement::ObjectContentDocument DontDelete|ReadOnly
00924   data        KJS::HTMLElement::ObjectData        DontDelete
00925   declare     KJS::HTMLElement::ObjectDeclare     DontDelete
00926   height      KJS::HTMLElement::ObjectHeight      DontDelete
00927   hspace      KJS::HTMLElement::ObjectHspace      DontDelete
00928   name        KJS::HTMLElement::ObjectName        DontDelete
00929   standby     KJS::HTMLElement::ObjectStandby     DontDelete
00930   tabIndex    KJS::HTMLElement::ObjectTabIndex    DontDelete
00931   type        KJS::HTMLElement::ObjectType        DontDelete
00932   useMap      KJS::HTMLElement::ObjectUseMap      DontDelete
00933   vspace      KJS::HTMLElement::ObjectVspace      DontDelete
00934   width       KJS::HTMLElement::ObjectWidth       DontDelete
00935 @end
00936 @begin HTMLParamElementTable 4
00937   name      KJS::HTMLElement::ParamName     DontDelete
00938   type      KJS::HTMLElement::ParamType     DontDelete
00939   value     KJS::HTMLElement::ParamValue        DontDelete
00940   valueType KJS::HTMLElement::ParamValueType    DontDelete
00941 @end
00942 @begin HTMLAppletElementTable 11
00943   align     KJS::HTMLElement::AppletAlign       DontDelete
00944   alt       KJS::HTMLElement::AppletAlt     DontDelete
00945   archive   KJS::HTMLElement::AppletArchive     DontDelete
00946   code      KJS::HTMLElement::AppletCode        DontDelete
00947   codeBase  KJS::HTMLElement::AppletCodeBase    DontDelete
00948   height    KJS::HTMLElement::AppletHeight      DontDelete
00949   hspace    KJS::HTMLElement::AppletHspace      DontDelete
00950   name      KJS::HTMLElement::AppletName        DontDelete
00951   object    KJS::HTMLElement::AppletObject      DontDelete
00952   vspace    KJS::HTMLElement::AppletVspace      DontDelete
00953   width     KJS::HTMLElement::AppletWidth       DontDelete
00954 @end
00955 @begin HTMLMapElementTable 2
00956   areas     KJS::HTMLElement::MapAreas      DontDelete|ReadOnly
00957   name      KJS::HTMLElement::MapName       DontDelete
00958 @end
00959 @begin HTMLAreaElementTable 15
00960   accessKey KJS::HTMLElement::AreaAccessKey     DontDelete
00961   alt       KJS::HTMLElement::AreaAlt       DontDelete
00962   coords    KJS::HTMLElement::AreaCoords        DontDelete
00963   href      KJS::HTMLElement::AreaHref      DontDelete
00964   hash      KJS::HTMLElement::AreaHash      DontDelete|ReadOnly
00965   host      KJS::HTMLElement::AreaHost      DontDelete|ReadOnly
00966   hostname  KJS::HTMLElement::AreaHostName      DontDelete|ReadOnly
00967   pathname  KJS::HTMLElement::AreaPathName      DontDelete|ReadOnly
00968   port      KJS::HTMLElement::AreaPort      DontDelete|ReadOnly
00969   protocol  KJS::HTMLElement::AreaProtocol      DontDelete|ReadOnly
00970   search    KJS::HTMLElement::AreaSearch        DontDelete|ReadOnly
00971   noHref    KJS::HTMLElement::AreaNoHref        DontDelete
00972   shape     KJS::HTMLElement::AreaShape     DontDelete
00973   tabIndex  KJS::HTMLElement::AreaTabIndex      DontDelete
00974   target    KJS::HTMLElement::AreaTarget        DontDelete
00975 @end
00976 @begin HTMLScriptElementTable 7
00977   text      KJS::HTMLElement::ScriptText        DontDelete
00978   htmlFor   KJS::HTMLElement::ScriptHtmlFor     DontDelete
00979   event     KJS::HTMLElement::ScriptEvent       DontDelete
00980   charset   KJS::HTMLElement::ScriptCharset     DontDelete
00981   defer     KJS::HTMLElement::ScriptDefer       DontDelete
00982   src       KJS::HTMLElement::ScriptSrc     DontDelete
00983   type      KJS::HTMLElement::ScriptType        DontDelete
00984 @end
00985 @begin HTMLTableElementTable 23
00986   caption   KJS::HTMLElement::TableCaption      DontDelete
00987   tHead     KJS::HTMLElement::TableTHead        DontDelete
00988   tFoot     KJS::HTMLElement::TableTFoot        DontDelete
00989   rows      KJS::HTMLElement::TableRows     DontDelete|ReadOnly
00990   tBodies   KJS::HTMLElement::TableTBodies      DontDelete|ReadOnly
00991   align     KJS::HTMLElement::TableAlign        DontDelete
00992   bgColor   KJS::HTMLElement::TableBgColor      DontDelete
00993   border    KJS::HTMLElement::TableBorder       DontDelete
00994   cellPadding   KJS::HTMLElement::TableCellPadding  DontDelete
00995   cellSpacing   KJS::HTMLElement::TableCellSpacing  DontDelete
00996   frame     KJS::HTMLElement::TableFrame        DontDelete
00997   rules     KJS::HTMLElement::TableRules        DontDelete
00998   summary   KJS::HTMLElement::TableSummary      DontDelete
00999   width     KJS::HTMLElement::TableWidth        DontDelete
01000   createTHead   KJS::HTMLElement::TableCreateTHead  DontDelete|Function 0
01001   deleteTHead   KJS::HTMLElement::TableDeleteTHead  DontDelete|Function 0
01002   createTFoot   KJS::HTMLElement::TableCreateTFoot  DontDelete|Function 0
01003   deleteTFoot   KJS::HTMLElement::TableDeleteTFoot  DontDelete|Function 0
01004   createCaption KJS::HTMLElement::TableCreateCaption    DontDelete|Function 0
01005   deleteCaption KJS::HTMLElement::TableDeleteCaption    DontDelete|Function 0
01006   insertRow KJS::HTMLElement::TableInsertRow    DontDelete|Function 1
01007   deleteRow KJS::HTMLElement::TableDeleteRow    DontDelete|Function 1
01008 @end
01009 @begin HTMLTableCaptionElementTable 1
01010   align     KJS::HTMLElement::TableCaptionAlign DontDelete
01011 @end
01012 @begin HTMLTableColElementTable 7
01013   align     KJS::HTMLElement::TableColAlign     DontDelete
01014   ch        KJS::HTMLElement::TableColCh        DontDelete
01015   chOff     KJS::HTMLElement::TableColChOff     DontDelete
01016   span      KJS::HTMLElement::TableColSpan      DontDelete
01017   vAlign    KJS::HTMLElement::TableColVAlign    DontDelete
01018   width     KJS::HTMLElement::TableColWidth     DontDelete
01019 @end
01020 @begin HTMLTableSectionElementTable 7
01021   align     KJS::HTMLElement::TableSectionAlign     DontDelete
01022   ch        KJS::HTMLElement::TableSectionCh        DontDelete
01023   chOff     KJS::HTMLElement::TableSectionChOff     DontDelete
01024   vAlign    KJS::HTMLElement::TableSectionVAlign        DontDelete
01025   rows      KJS::HTMLElement::TableSectionRows      DontDelete|ReadOnly
01026   insertRow KJS::HTMLElement::TableSectionInsertRow     DontDelete|Function 1
01027   deleteRow KJS::HTMLElement::TableSectionDeleteRow     DontDelete|Function 1
01028 @end
01029 @begin HTMLTableRowElementTable 11
01030   rowIndex  KJS::HTMLElement::TableRowRowIndex      DontDelete|ReadOnly
01031   sectionRowIndex KJS::HTMLElement::TableRowSectionRowIndex DontDelete|ReadOnly
01032   cells     KJS::HTMLElement::TableRowCells         DontDelete|ReadOnly
01033   align     KJS::HTMLElement::TableRowAlign         DontDelete
01034   bgColor   KJS::HTMLElement::TableRowBgColor       DontDelete
01035   ch        KJS::HTMLElement::TableRowCh            DontDelete
01036   chOff     KJS::HTMLElement::TableRowChOff         DontDelete
01037   vAlign    KJS::HTMLElement::TableRowVAlign        DontDelete
01038   insertCell    KJS::HTMLElement::TableRowInsertCell        DontDelete|Function 1
01039   deleteCell    KJS::HTMLElement::TableRowDeleteCell        DontDelete|Function 1
01040 @end
01041 @begin HTMLTableCellElementTable 15
01042   cellIndex KJS::HTMLElement::TableCellCellIndex        DontDelete|ReadOnly
01043   abbr      KJS::HTMLElement::TableCellAbbr         DontDelete
01044   align     KJS::HTMLElement::TableCellAlign        DontDelete
01045   axis      KJS::HTMLElement::TableCellAxis         DontDelete
01046   bgColor   KJS::HTMLElement::TableCellBgColor      DontDelete
01047   ch        KJS::HTMLElement::TableCellCh           DontDelete
01048   chOff     KJS::HTMLElement::TableCellChOff        DontDelete
01049   colSpan   KJS::HTMLElement::TableCellColSpan      DontDelete
01050   headers   KJS::HTMLElement::TableCellHeaders      DontDelete
01051   height    KJS::HTMLElement::TableCellHeight       DontDelete
01052   noWrap    KJS::HTMLElement::TableCellNoWrap       DontDelete
01053   rowSpan   KJS::HTMLElement::TableCellRowSpan      DontDelete
01054   scope     KJS::HTMLElement::TableCellScope        DontDelete
01055   vAlign    KJS::HTMLElement::TableCellVAlign       DontDelete
01056   width     KJS::HTMLElement::TableCellWidth        DontDelete
01057 @end
01058 @begin HTMLFrameSetElementTable 2
01059   cols      KJS::HTMLElement::FrameSetCols          DontDelete
01060   rows      KJS::HTMLElement::FrameSetRows          DontDelete
01061 @end
01062 @begin HTMLLayerElementTable 6
01063   top         KJS::HTMLElement::LayerTop            DontDelete
01064   left        KJS::HTMLElement::LayerLeft           DontDelete
01065   visibility      KJS::HTMLElement::LayerVisibility     DontDelete
01066   bgColor     KJS::HTMLElement::LayerBgColor        DontDelete
01067   document        KJS::HTMLElement::LayerDocument       DontDelete|ReadOnly
01068   clip        KJS::HTMLElement::LayerClip           DontDelete|ReadOnly
01069   layers      KJS::HTMLElement::LayerLayers         DontDelete|ReadOnly
01070 @end
01071 @begin HTMLFrameElementTable 9
01072   contentDocument KJS::HTMLElement::FrameContentDocument        DontDelete|ReadOnly
01073   contentWindow KJS::HTMLElement::FrameContentWindow        DontDelete|ReadOnly
01074   frameBorder     KJS::HTMLElement::FrameFrameBorder        DontDelete
01075   longDesc    KJS::HTMLElement::FrameLongDesc       DontDelete
01076   marginHeight    KJS::HTMLElement::FrameMarginHeight       DontDelete
01077   marginWidth     KJS::HTMLElement::FrameMarginWidth        DontDelete
01078   name        KJS::HTMLElement::FrameName           DontDelete
01079   noResize    KJS::HTMLElement::FrameNoResize       DontDelete
01080   scrolling   KJS::HTMLElement::FrameScrolling      DontDelete
01081   src         KJS::HTMLElement::FrameSrc            DontDelete
01082   location    KJS::HTMLElement::FrameLocation       DontDelete
01083 @end
01084 @begin HTMLIFrameElementTable 12
01085   align       KJS::HTMLElement::IFrameAlign         DontDelete
01086   contentDocument KJS::HTMLElement::IFrameContentDocument       DontDelete|ReadOnly
01087   contentWindow KJS::HTMLElement::IFrameContentWindow        DontDelete|ReadOnly
01088   frameBorder     KJS::HTMLElement::IFrameFrameBorder       DontDelete
01089   height      KJS::HTMLElement::IFrameHeight        DontDelete
01090   longDesc    KJS::HTMLElement::IFrameLongDesc      DontDelete
01091   marginHeight    KJS::HTMLElement::IFrameMarginHeight      DontDelete
01092   marginWidth     KJS::HTMLElement::IFrameMarginWidth       DontDelete
01093   name        KJS::HTMLElement::IFrameName          DontDelete
01094   scrolling   KJS::HTMLElement::IFrameScrolling     DontDelete
01095   src         KJS::HTMLElement::IFrameSrc           DontDelete
01096   width       KJS::HTMLElement::IFrameWidth         DontDelete
01097 @end
01098 
01099 @begin HTMLMarqueeElementTable 2
01100   start           KJS::HTMLElement::MarqueeStart        DontDelete|Function 0
01101   stop            KJS::HTMLElement::MarqueeStop                 DontDelete|Function 0
01102 @end
01103 
01104 */
01105 
01106 static KParts::LiveConnectExtension *getLiveConnectExtension(const DOM::HTMLElement & element)
01107 {
01108   DOM::HTMLDocument doc = element.ownerDocument();
01109   KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
01110   if (view && element.handle())
01111     return view->part()->liveConnectExtension(static_cast<khtml::RenderPart*>(element.handle()->renderer()));
01112   return 0L;
01113 }
01114 
01115 Value KJS::HTMLElement::tryGet(ExecState *exec, const Identifier &propertyName) const
01116 {
01117   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
01118 #ifdef KJS_VERBOSE
01119   kdDebug(6070) << "KJS::HTMLElement::tryGet " << propertyName.qstring() << " thisTag=" << element.tagName().string() << endl;
01120 #endif
01121   // First look at dynamic properties
01122   switch (element.elementId()) {
01123     case ID_FORM: {
01124       DOM::HTMLFormElement form = element;
01125       // Check if we're retrieving an element (by index or by name)
01126       bool ok;
01127       uint u = propertyName.toULong(&ok);
01128 
01129       if (ok)
01130         return getDOMNode(exec,form.elements().item(u));
01131       KJS::HTMLCollection coll(exec, form.elements());
01132       Value namedItems = coll.getNamedItems(exec, propertyName);
01133       if (namedItems.type() != UndefinedType)
01134         return namedItems;
01135     }
01136       break;
01137     case ID_SELECT: {
01138       DOM::HTMLSelectElement select = element;
01139       bool ok;
01140       uint u = propertyName.toULong(&ok);
01141       if (ok)
01142         return getDOMNode(exec,select.options().item(u)); // not specified by DOM(?) but supported in netscape/IE
01143     }
01144       break;
01145     case ID_APPLET:
01146     case ID_OBJECT:
01147     case ID_EMBED: {
01148       KParts::LiveConnectExtension *lc = getLiveConnectExtension(element);
01149       QString rvalue;
01150       KParts::LiveConnectExtension::Type rtype;
01151       unsigned long robjid;
01152       if (lc && lc->get(0, propertyName.qstring(), rtype, robjid, rvalue))
01153         return getLiveConnectValue(lc, propertyName.qstring(), rtype, rvalue, robjid);
01154     }
01155       break;
01156   default:
01157     break;
01158   }
01159 
01160   const HashTable* table = classInfo()->propHashTable; // get the right hashtable
01161   const HashEntry* entry = Lookup::findEntry(table, propertyName);
01162   if (entry) {
01163     if (entry->attr & Function)
01164       return lookupOrCreateFunction<KJS::HTMLElementFunction>(exec, propertyName, this, entry->value, entry->params, entry->attr);
01165     return getValueProperty(exec, entry->value);
01166   }
01167 
01168   // Base HTMLElement stuff or parent class forward, as usual
01169   return DOMObjectLookupGet<KJS::HTMLElementFunction, KJS::HTMLElement, DOMElement>(exec, propertyName, &KJS::HTMLElementTable, this);
01170 }
01171 
01172 Value KJS::HTMLElement::getValueProperty(ExecState *exec, int token) const
01173 {
01174   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
01175   switch (element.elementId()) {
01176   case ID_HTML: {
01177     DOM::HTMLHtmlElement html = element;
01178     if      (token == HtmlVersion)         return String(html.version());
01179   }
01180   break;
01181   case ID_HEAD: {
01182     DOM::HTMLHeadElement head = element;
01183     if      (token == HeadProfile)         return String(head.profile());
01184   }
01185   break;
01186   case ID_LINK: {
01187     DOM::HTMLLinkElement link = element;
01188     switch (token) {
01189     case LinkDisabled:        return Boolean(link.disabled());
01190     case LinkCharset:         return String(link.charset());
01191     case LinkHref:            return String(link.href());
01192     case LinkHrefLang:        return String(link.hreflang());
01193     case LinkMedia:           return String(link.media());
01194     case LinkRel:             return String(link.rel());
01195     case LinkRev:             return String(link.rev());
01196     case LinkTarget:          return String(link.target());
01197     case LinkType:            return String(link.type());
01198     case LinkSheet:           return getDOMStyleSheet(exec,static_cast<DOM::ProcessingInstruction>(node).sheet());
01199     }
01200   }
01201   break;
01202   case ID_TITLE: {
01203     DOM::HTMLTitleElement title = element;
01204     switch (token) {
01205     case TitleText:                 return String(title.text());
01206     }
01207   }
01208   break;
01209   case ID_META: {
01210     DOM::HTMLMetaElement meta = element;
01211     switch (token) {
01212     case MetaContent:         return String(meta.content());
01213     case MetaHttpEquiv:       return String(meta.httpEquiv());
01214     case MetaName:            return String(meta.name());
01215     case MetaScheme:          return String(meta.scheme());
01216     }
01217   }
01218   break;
01219   case ID_BASE: {
01220     DOM::HTMLBaseElement base = element;
01221     switch (token) {
01222     case BaseHref:            return String(base.href());
01223     case BaseTarget:          return String(base.target());
01224     }
01225   }
01226   break;
01227   case ID_ISINDEX: {
01228     DOM::HTMLIsIndexElement isindex = element;
01229     switch (token) {
01230     case IsIndexForm:            return getDOMNode(exec,isindex.form()); // type HTMLFormElement
01231     case IsIndexPrompt:          return String(isindex.prompt());
01232     }
01233   }
01234   break;
01235   case ID_STYLE: {
01236     DOM::HTMLStyleElement style = element;
01237     switch (token) {
01238     case StyleDisabled:        return Boolean(style.disabled());
01239     case StyleMedia:           return String(style.media());
01240     case StyleType:            return String(style.type());
01241     case StyleSheet:           return getDOMStyleSheet(exec,style.sheet());
01242     }
01243   }
01244   break;
01245   case ID_BODY: {
01246     DOM::HTMLBodyElement body = element;
01247     switch (token) {
01248     case BodyALink:           return String(body.aLink());
01249     case BodyBackground:      return String(body.background());
01250     case BodyBgColor:         return String(body.bgColor());
01251     case BodyLink:            return String(body.link());
01252     case BodyText:            return String(body.text());
01253     case BodyVLink:           return String(body.vLink());
01254     case BodyOnLoad: {
01255         DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(node.ownerDocument().handle());
01256         if (!doc || !checkNodeSecurity(exec, node))
01257           return Undefined();
01258         DOMNode* kjsDocNode = new DOMNode(exec, doc);
01259         // Need to create a Value wrapper to avoid leaking the KJS::DOMNode
01260         Value nodeValue(kjsDocNode);
01261         return kjsDocNode->getListener( DOM::EventImpl::LOAD_EVENT );
01262     }
01263     default:
01264       // Update the document's layout before we compute these attributes.
01265       DOM::DocumentImpl* docimpl = node.handle()->getDocument();
01266       if (docimpl)
01267         docimpl->updateLayout();
01268 
01269       switch( token ) {
01270       case BodyScrollLeft:
01271         return Number(body.ownerDocument().view() ? body.ownerDocument().view()->contentsX() : 0);
01272       case BodyScrollTop:
01273         return Number(body.ownerDocument().view() ? body.ownerDocument().view()->contentsY() : 0);
01274       case BodyScrollHeight:   return Number(body.ownerDocument().view() ? body.ownerDocument().view()->contentsHeight() : 0);
01275       case BodyScrollWidth:    return Number(body.ownerDocument().view() ? body.ownerDocument().view()->contentsWidth() : 0);
01276       }
01277     }
01278   }
01279   break;
01280 
01281   case ID_FORM: {
01282     DOM::HTMLFormElement form = element;
01283     switch (token) {
01284     case FormElements:        return getHTMLCollection(exec,form.elements());
01285     case FormLength:          return Number(form.length());
01286     case FormName:            return String(form.name()); // NOT getString (IE gives empty string)
01287     case FormAcceptCharset:   return String(form.acceptCharset());
01288     case FormAction:          return String(form.action());
01289     case FormEncType:         return String(form.enctype());
01290     case FormMethod:          return String(form.method());
01291     case FormTarget:          return String(form.target());
01292     }
01293   }
01294   break;
01295   case ID_SELECT: {
01296     DOM::HTMLSelectElement select = element;
01297     switch (token) {
01298     case SelectType:            return String(select.type());
01299     case SelectSelectedIndex:   return Number(select.selectedIndex());
01300     case SelectValue:           return String(select.value());
01301     case SelectLength:          return Number(select.length());
01302     case SelectForm:            return getDOMNode(exec,select.form()); // type HTMLFormElement
01303     case SelectOptions:         return getSelectHTMLCollection(exec, select.options(), select); // type HTMLCollection
01304     case SelectDisabled:        return Boolean(select.disabled());
01305     case SelectMultiple:        return Boolean(select.multiple());
01306     case SelectName:            return String(select.name());
01307     case SelectSize:            return Number(select.size());
01308     case SelectTabIndex:        return Number(select.tabIndex());
01309     }
01310   }
01311   break;
01312   case ID_OPTGROUP: {
01313     DOM::HTMLOptGroupElement optgroup = element;
01314     switch (token) {
01315     case OptGroupDisabled:        return Boolean(optgroup.disabled());
01316     case OptGroupLabel:           return String(optgroup.label());
01317     }
01318   }
01319   break;
01320   case ID_OPTION: {
01321     DOM::HTMLOptionElement option = element;
01322     switch (token) {
01323     case OptionForm:            return getDOMNode(exec,option.form()); // type HTMLFormElement
01324     case OptionDefaultSelected: return Boolean(option.defaultSelected());
01325     case OptionText:            return String(option.text());
01326     case OptionIndex:           return Number(option.index());
01327     case OptionDisabled:        return Boolean(option.disabled());
01328     case OptionLabel:           return String(option.label());
01329     case OptionSelected:        return Boolean(option.selected());
01330     case OptionValue:           return String(option.value());
01331     }
01332   }
01333   break;
01334   case ID_INPUT: {
01335     DOM::HTMLInputElement input = element;
01336     switch (token) {
01337     case InputDefaultValue:    return String(input.defaultValue());
01338     case InputDefaultChecked:  return Boolean(input.defaultChecked());
01339     case InputForm:            return getDOMNode(exec,input.form()); // type HTMLFormElement
01340     case InputAccept:          return String(input.accept());
01341     case InputAccessKey:       return String(input.accessKey());
01342     case InputAlign:           return String(input.align());
01343     case InputAlt:             return String(input.alt());
01344     case InputChecked:         return Boolean(input.checked());
01345     case InputDisabled:        return Boolean(input.disabled());
01346     case InputMaxLength:       return Number(input.maxLength());
01347     case InputName:            return String(input.name()); // NOT getString (IE gives empty string)
01348     case InputReadOnly:        return Boolean(input.readOnly());
01349     case InputSize:            return Number(input.getSize());
01350     case InputSrc:             return String(input.src());
01351     case InputTabIndex:        return Number(input.tabIndex());
01352     case InputType:            return String(input.type());
01353     case InputUseMap:          return String(input.useMap());
01354     case InputValue:           return String(input.value());
01355     }
01356   }
01357   break;
01358   case ID_TEXTAREA: {
01359     DOM::HTMLTextAreaElement textarea = element;
01360     switch (token) {
01361     case TextAreaDefaultValue:    return String(textarea.defaultValue());
01362     case TextAreaForm:            return getDOMNode(exec,textarea.form()); // type HTMLFormElement
01363     case TextAreaAccessKey:       return String(textarea.accessKey());
01364     case TextAreaCols:            return Number(textarea.cols());
01365     case TextAreaDisabled:        return Boolean(textarea.disabled());
01366     case TextAreaName:            return String(textarea.name());
01367     case TextAreaReadOnly:        return Boolean(textarea.readOnly());
01368     case TextAreaRows:            return Number(textarea.rows());
01369     case TextAreaTabIndex:        return Number(textarea.tabIndex());
01370     case TextAreaType:            return String(textarea.type());
01371     case TextAreaValue:           return String(textarea.value());
01372     }
01373   }
01374   break;
01375   case ID_BUTTON: {
01376     DOM::HTMLButtonElement button = element;
01377     switch (token) {
01378     case ButtonForm:            return getDOMNode(exec,button.form()); // type HTMLFormElement
01379     case ButtonAccessKey:       return String(button.accessKey());
01380     case ButtonDisabled:        return Boolean(button.disabled());
01381     case ButtonName:            return String(button.name());
01382     case ButtonTabIndex:        return Number(button.tabIndex());
01383     case ButtonType:            return String(button.type());
01384     case ButtonValue:           return String(button.value());
01385     }
01386   }
01387   break;
01388   case ID_LABEL: {
01389     DOM::HTMLLabelElement label = element;
01390     switch (token) {
01391     case LabelForm:            return getDOMNode(exec,label.form()); // type HTMLFormElement
01392     case LabelAccessKey:       return String(label.accessKey());
01393     case LabelHtmlFor:         return String(label.htmlFor());
01394     }
01395   }
01396   break;
01397   case ID_FIELDSET: {
01398     DOM::HTMLFieldSetElement fieldSet = element;
01399     switch (token) {
01400     case FieldSetForm:            return getDOMNode(exec,fieldSet.form()); // type HTMLFormElement
01401     }
01402   }
01403   break;
01404   case ID_LEGEND: {
01405     DOM::HTMLLegendElement legend = element;
01406     switch (token) {
01407     case LegendForm:            return getDOMNode(exec,legend.form()); // type HTMLFormElement
01408     case LegendAccessKey:       return String(legend.accessKey());
01409     case LegendAlign:           return String(legend.align());
01410     }
01411   }
01412   break;
01413   case ID_UL: {
01414     DOM::HTMLUListElement uList = element;
01415     switch (token) {
01416     case UListCompact:         return Boolean(uList.compact());
01417     case UListType:            return String(uList.type());
01418     }
01419   }
01420   break;
01421   case ID_OL: {
01422     DOM::HTMLOListElement oList = element;
01423     switch (token) {
01424     case OListCompact:         return Boolean(oList.compact());
01425     case OListStart:           return Number(oList.start());
01426     case OListType:            return String(oList.type());
01427     }
01428   }
01429   break;
01430   case ID_DL: {
01431     DOM::HTMLDListElement dList = element;
01432     switch (token) {
01433     case DListCompact:         return Boolean(dList.compact());
01434     }
01435   }
01436   break;
01437   case ID_DIR: {
01438     DOM::HTMLDirectoryElement directory = element;
01439     switch (token) {
01440     case DirectoryCompact:         return Boolean(directory.compact());
01441     }
01442   }
01443   break;
01444   case ID_MENU: {
01445     DOM::HTMLMenuElement menu = element;
01446     switch (token) {
01447     case MenuCompact:         return Boolean(menu.compact());
01448     }
01449   }
01450   break;
01451   case ID_LI: {
01452     DOM::HTMLLIElement li = element;
01453     switch (token) {
01454     case LIType:            return String(li.type());
01455     case LIValue:           return Number(li.value());
01456     }
01457   }
01458   break;
01459   case ID_DIV: {
01460     DOM::HTMLDivElement div = element;
01461     switch (token) {
01462     case DivAlign:           return String(div.align());
01463     }
01464   }
01465   break;
01466   case ID_P: {
01467     DOM::HTMLParagraphElement paragraph = element;
01468     switch (token) {
01469     case ParagraphAlign:           return String(paragraph.align());
01470     }
01471   }
01472   break;
01473   case ID_H1:
01474   case ID_H2:
01475   case ID_H3:
01476   case ID_H4:
01477   case ID_H5:
01478   case ID_H6: {
01479     DOM::HTMLHeadingElement heading = element;
01480     switch (token) {
01481     case HeadingAlign:           return String(heading.align());
01482     }
01483   }
01484   break;
01485   case ID_BLOCKQUOTE: {
01486     DOM::HTMLBlockquoteElement blockquote = element;
01487     switch (token) {
01488     case BlockQuoteCite:            return String(blockquote.cite());
01489     }
01490   }
01491   case ID_Q: {
01492     DOM::HTMLQuoteElement quote = element;
01493     switch (token) {
01494     case QuoteCite:            return String(quote.cite());
01495     }
01496   }
01497   case ID_PRE: {
01498     DOM::HTMLPreElement pre = element;
01499     switch (token) {
01500     case PreWidth:           return Number(pre.width());
01501     }
01502   }
01503   break;
01504   case ID_BR: {
01505     DOM::HTMLBRElement br = element;
01506     switch (token) {
01507     case BRClear:           return String(br.clear());
01508     }
01509   }
01510   break;
01511   case ID_BASEFONT: {
01512     DOM::HTMLBaseFontElement baseFont = element;
01513     switch (token) {
01514     case BaseFontColor:           return String(baseFont.color());
01515     case BaseFontFace:            return String(baseFont.face());
01516     case BaseFontSize:            return Number(baseFont.getSize());
01517     }
01518   }
01519   break;
01520   case ID_FONT: {
01521     DOM::HTMLFontElement font = element;
01522     switch (token) {
01523     case FontColor:           return String(font.color());
01524     case FontFace:            return String(font.face());
01525     case FontSize:            return String(font.size());
01526     }
01527   }
01528   break;
01529   case ID_HR: {
01530     DOM::HTMLHRElement hr = element;
01531     switch (token) {
01532     case HRAlign:           return String(hr.align());
01533     case HRNoShade:         return Boolean(hr.noShade());
01534     case HRSize:            return String(hr.size());
01535     case HRWidth:           return String(hr.width());
01536     }
01537   }
01538   break;
01539   case ID_INS:
01540   case ID_DEL: {
01541     DOM::HTMLModElement mod = element;
01542     switch (token) {
01543     case ModCite:            return String(mod.cite());
01544     case ModDateTime:        return String(mod.dateTime());
01545     }
01546   }
01547   break;
01548   case ID_A: {
01549     DOM::HTMLAnchorElement anchor = element;
01550     switch (token) {
01551     case AnchorAccessKey:       return String(anchor.accessKey());
01552     case AnchorCharset:         return String(anchor.charset());
01553     case AnchorCoords:          return String(anchor.coords());
01554     case AnchorHref:            return String(anchor.href());
01555     case AnchorHrefLang:        return String(anchor.hreflang());
01556     case AnchorHash:            return String('#'+KURL(anchor.href().string()).ref());
01557     case AnchorHost:            return String(KURL(anchor.href().string()).host());
01558     case AnchorHostname: {
01559       KURL url(anchor.href().string());
01560       kdDebug(6070) << "anchor::hostname uses:" <<url.url()<<endl;
01561       if (url.port()==0)
01562         return String(url.host());
01563       else
01564         return String(url.host() + ":" + QString::number(url.port()));
01565     }
01566     case AnchorPathName:        return String(KURL(anchor.href().string()).path());
01567     case AnchorPort:            return String(QString::number(KURL(anchor.href().string()).port()));
01568     case AnchorProtocol:        return String(KURL(anchor.href().string()).protocol()+":");
01569     case AnchorSearch:          return String(KURL(anchor.href().string()).query());
01570     case AnchorName:            return String(anchor.name());
01571     case AnchorRel:             return String(anchor.rel());
01572     case AnchorRev:             return String(anchor.rev());
01573     case AnchorShape:           return String(anchor.shape());
01574     case AnchorTabIndex:        return Number(anchor.tabIndex());
01575     case AnchorTarget:          return String(anchor.target());
01576     // Not specified in http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/a.asp
01577     // Mozilla returns the inner text.
01578     case AnchorText:            return String(anchor.innerText());
01579     case AnchorType:            return String(anchor.type());
01580     }
01581   }
01582   break;
01583   case ID_IMG: {
01584     DOM::HTMLImageElement image = element;
01585     switch (token) {
01586     case ImageName:            return String(image.name()); // NOT getString (IE gives empty string)
01587     case ImageAlign:           return String(image.align());
01588     case ImageAlt:             return String(image.alt());
01589     case ImageBorder:          return String(image.getBorder());
01590     case ImageComplete:        return Boolean(static_cast<DOM::HTMLImageElementImpl*>( image.handle() )->complete());
01591     case ImageHeight:          return Number(image.height());
01592     case ImageHspace:          return Number(image.hspace());
01593     case ImageIsMap:           return Boolean(image.isMap());
01594     case ImageLongDesc:        return String(image.longDesc());
01595     case ImageSrc:             return String(image.src());
01596     case ImageUseMap:          return String(image.useMap());
01597     case ImageVspace:          return Number(image.vspace());
01598     case ImageWidth:           return Number(image.width());
01599     case ImageX:               return Number(image.x());
01600     case ImageY:               return Number(image.y());
01601     }
01602   }
01603   break;
01604   case ID_OBJECT: {
01605     DOM::HTMLObjectElement object = element;
01606     switch (token) {
01607     case ObjectForm:            return getDOMNode(exec,object.form()); // type HTMLFormElement
01608     case ObjectCode:            return String(object.code());
01609     case ObjectAlign:           return String(object.align());
01610     case ObjectArchive:         return String(object.archive());
01611     case ObjectBorder:          return String(object.border());
01612     case ObjectCodeBase:        return String(object.codeBase());
01613     case ObjectCodeType:        return String(object.codeType());
01614     case ObjectContentDocument: return checkNodeSecurity(exec,object.contentDocument()) ?
01615                        getDOMNode(exec, object.contentDocument()) : Undefined();
01616     case ObjectData:            return String(object.data());
01617     case ObjectDeclare:         return Boolean(object.declare());
01618     case ObjectHeight:          return String(object.height());
01619     case ObjectHspace:          return Number(object.getHspace());
01620     case ObjectName:            return String(object.name());
01621     case ObjectStandby:         return String(object.standby());
01622     case ObjectTabIndex:        return Number(object.tabIndex());
01623     case ObjectType:            return String(object.type());
01624     case ObjectUseMap:          return String(object.useMap());
01625     case ObjectVspace:          return Number(object.getVspace());
01626     case ObjectWidth:           return String(object.width());
01627     }
01628   }
01629   break;
01630   case ID_PARAM: {
01631     DOM::HTMLParamElement param = element;
01632     switch (token) {
01633     case ParamName:            return String(param.name());
01634     case ParamType:            return String(param.type());
01635     case ParamValue:           return String(param.value());
01636     case ParamValueType:       return String(param.valueType());
01637     }
01638   }
01639   break;
01640   case ID_APPLET: {
01641     DOM::HTMLAppletElement applet = element;
01642     switch (token) {
01643     case AppletAlign:           return String(applet.align());
01644     case AppletAlt:             return String(applet.alt());
01645     case AppletArchive:         return String(applet.archive());
01646     case AppletCode:            return String(applet.code());
01647     case AppletCodeBase:        return String(applet.codeBase());
01648     case AppletHeight:          return String(applet.height());
01649     case AppletHspace:          return Number(applet.getHspace());
01650     case AppletName:            return String(applet.name());
01651     case AppletObject:          return String(applet.object());
01652     case AppletVspace:          return Number(applet.getVspace());
01653     case AppletWidth:           return String(applet.width());
01654     }
01655   }
01656   break;
01657   case ID_MAP: {
01658     DOM::HTMLMapElement map = element;
01659     switch (token) {
01660     case MapAreas:           return getHTMLCollection(exec, map.areas()); // type HTMLCollection
01661     case MapName:            return String(map.name());
01662     }
01663   }
01664   break;
01665   case ID_AREA: {
01666     DOM::HTMLAreaElement area = element;
01667     switch (token) {
01668     case AreaAccessKey:       return String(area.accessKey());
01669     case AreaAlt:             return String(area.alt());
01670     case AreaCoords:          return String(area.coords());
01671     // Group everything that needs href
01672     case AreaHref:
01673     case AreaHash:
01674     case AreaHost:
01675     case AreaHostName:
01676     case AreaPathName:
01677     case AreaPort:
01678     case AreaProtocol:
01679     case AreaSearch:
01680     {
01681       DOM::Document doc = area.ownerDocument();
01682       DOM::DOMString href = area.href();
01683       KURL url;
01684       if ( !href.isNull() ) {
01685         url = doc.completeURL( href ).string();
01686         if ( href.isEmpty() )
01687           url.setFileName( QString::null ); // href="" clears the filename (in IE)
01688       }
01689       switch(token) {
01690       case AreaHref:
01691         return String(url.url());
01692       case AreaHash:            return String(url.isEmpty() ? "" : '#'+url.ref());
01693       case AreaHost:            return String(url.host());
01694       case AreaHostName: {
01695         if (url.port()==0)
01696           return String(url.host());
01697         else
01698           return String(url.host() + ":" + QString::number(url.port()));
01699       }
01700       case AreaPathName:        {
01701         return String(url.path());
01702       }
01703       case AreaPort:            return String(QString::number(url.port()));
01704       case AreaProtocol:        return String(url.isEmpty() ? "" : url.protocol()+":");
01705       case AreaSearch:          return String(url.query());
01706       }
01707     }
01708     case AreaNoHref:          return Boolean(area.noHref());
01709     case AreaShape:           return String(area.shape());
01710     case AreaTabIndex:        return Number(area.tabIndex());
01711     case AreaTarget:          return String(area.target());
01712     }
01713   }
01714   break;
01715   case ID_SCRIPT: {
01716     DOM::HTMLScriptElement script = element;
01717     switch (token) {
01718     case ScriptText:            return String(script.text());
01719     case ScriptHtmlFor:         return String(script.htmlFor());
01720     case ScriptEvent:           return String(script.event());
01721     case ScriptCharset:         return String(script.charset());
01722     case ScriptDefer:           return Boolean(script.defer());
01723     case ScriptSrc:             return String(script.src());
01724     case ScriptType:            return String(script.type());
01725     }
01726   }
01727   break;
01728   case ID_TABLE: {
01729     DOM::HTMLTableElement table = element;
01730     switch (token) {
01731     case TableCaption:         return getDOMNode(exec,table.caption()); // type HTMLTableCaptionElement
01732     case TableTHead:           return getDOMNode(exec,table.tHead()); // type HTMLTableSectionElement
01733     case TableTFoot:           return getDOMNode(exec,table.tFoot()); // type HTMLTableSectionElement
01734     case TableRows:            return getHTMLCollection(exec,table.rows()); // type HTMLCollection
01735     case TableTBodies:         return getHTMLCollection(exec,table.tBodies()); // type HTMLCollection
01736     case TableAlign:           return String(table.align());
01737     case TableBgColor:         return String(table.bgColor());
01738     case TableBorder:          return String(table.border());
01739     case TableCellPadding:     return String(table.cellPadding());
01740     case TableCellSpacing:     return String(table.cellSpacing());
01741     case TableFrame:           return String(table.frame());
01742     case TableRules:           return String(table.rules());
01743     case TableSummary:         return String(table.summary());
01744     case TableWidth:           return String(table.width());
01745     }
01746   }
01747   break;
01748   case ID_CAPTION: {
01749     DOM::HTMLTableCaptionElement tableCaption = element;
01750     switch (token) {
01751     case TableCaptionAlign:       return String(tableCaption.align());
01752     }
01753   }
01754   break;
01755   case ID_COL:
01756   case ID_COLGROUP: {
01757     DOM::HTMLTableColElement tableCol = element;
01758     switch (token) {
01759     case TableColAlign:           return String(tableCol.align());
01760     case TableColCh:              return String(tableCol.ch());
01761     case TableColChOff:           return String(tableCol.chOff());
01762     case TableColSpan:            return Number(tableCol.span());
01763     case TableColVAlign:          return String(tableCol.vAlign());
01764     case TableColWidth:           return String(tableCol.width());
01765     }
01766   }
01767   break;
01768   case ID_THEAD:
01769   case ID_TBODY:
01770   case ID_TFOOT: {
01771     DOM::HTMLTableSectionElement tableSection = element;
01772     switch (token) {
01773     case TableSectionAlign:           return String(tableSection.align());
01774     case TableSectionCh:              return String(tableSection.ch());
01775     case TableSectionChOff:           return String(tableSection.chOff());
01776     case TableSectionVAlign:          return String(tableSection.vAlign());
01777     case TableSectionRows:            return getHTMLCollection(exec,tableSection.rows()); // type HTMLCollection
01778     }
01779   }
01780   break;
01781   case ID_TR: {
01782    DOM::HTMLTableRowElement tableRow = element;
01783    switch (token) {
01784    case TableRowRowIndex:        return Number(tableRow.rowIndex());
01785    case TableRowSectionRowIndex: return Number(tableRow.sectionRowIndex());
01786    case TableRowCells:           return getHTMLCollection(exec,tableRow.cells()); // type HTMLCollection
01787    case TableRowAlign:           return String(tableRow.align());
01788    case TableRowBgColor:         return String(tableRow.bgColor());
01789    case TableRowCh:              return String(tableRow.ch());
01790    case TableRowChOff:           return String(tableRow.chOff());
01791    case TableRowVAlign:          return String(tableRow.vAlign());
01792    }
01793   }
01794   break;
01795   case ID_TH:
01796   case ID_TD: {
01797     DOM::HTMLTableCellElement tableCell = element;
01798     switch (token) {
01799     case TableCellCellIndex:       return Number(tableCell.cellIndex());
01800     case TableCellAbbr:            return String(tableCell.abbr());
01801     case TableCellAlign:           return String(tableCell.align());
01802     case TableCellAxis:            return String(tableCell.axis());
01803     case TableCellBgColor:         return String(tableCell.bgColor());
01804     case TableCellCh:              return String(tableCell.ch());
01805     case TableCellChOff:           return String(tableCell.chOff());
01806     case TableCellColSpan:         return Number(tableCell.colSpan());
01807     case TableCellHeaders:         return String(tableCell.headers());
01808     case TableCellHeight:          return String(tableCell.height());
01809     case TableCellNoWrap:          return Boolean(tableCell.noWrap());
01810     case TableCellRowSpan:         return Number(tableCell.rowSpan());
01811     case TableCellScope:           return String(tableCell.scope());
01812     case TableCellVAlign:          return String(tableCell.vAlign());
01813     case TableCellWidth:           return String(tableCell.width());
01814     }
01815   }
01816   break;
01817   case ID_FRAMESET: {
01818     DOM::HTMLFrameSetElement frameSet = element;
01819     switch (token) {
01820     case FrameSetCols:            return String(frameSet.cols());
01821     case FrameSetRows:            return String(frameSet.rows());
01822     }
01823   }
01824   break;
01825   case ID_LAYER: {
01826     DOM::HTMLLayerElement layerElement = element;
01827     switch (token) {
01828     case LayerTop:            return Number(layerElement.top());
01829     case LayerLeft:           return Number(layerElement.left());
01830     case LayerVisibility:     return getString(layerElement.visibility());
01831     case LayerBgColor:        return getString(layerElement.bgColor());
01832     /*case LayerClip:           return getLayerClip(exec, layerElement); */
01833     case LayerDocument:       return Undefined();
01834     case LayerLayers:         return getHTMLCollection(exec,layerElement.layers());
01835     }
01836   }
01837   break;
01838   case ID_FRAME: {
01839     DOM::HTMLFrameElement frameElement = element;
01840     switch (token) {
01841     case FrameContentDocument: return checkNodeSecurity(exec,frameElement.contentDocument()) ?
01842                       getDOMNode(exec, frameElement.contentDocument()) : Undefined();
01843     case FrameContentWindow:   {
01844         KHTMLView *view = static_cast<DOM::DocumentImpl*>(frameElement.contentDocument().handle())->view();
01845         if (view && view->part())
01846             return Value(Window::retrieveWindow(view->part()));
01847         else
01848             return Undefined();
01849     }
01850     case FrameFrameBorder:     return String(frameElement.frameBorder());
01851     case FrameLongDesc:        return String(frameElement.longDesc());
01852     case FrameMarginHeight:    return String(frameElement.marginHeight());
01853     case FrameMarginWidth:     return String(frameElement.marginWidth());
01854     case FrameName:            return String(frameElement.name());
01855     case FrameNoResize:        return Boolean(frameElement.noResize());
01856     case FrameScrolling:       return String(frameElement.scrolling());
01857     case FrameSrc:
01858     case FrameLocation:        return String(frameElement.src());
01859     }
01860   }
01861   break;
01862   case ID_IFRAME: {
01863     DOM::HTMLIFrameElement iFrame = element;
01864     switch (token) {
01865     case IFrameAlign:           return String(iFrame.align());
01866     case IFrameContentDocument: return checkNodeSecurity(exec,iFrame.contentDocument()) ?
01867                        getDOMNode(exec, iFrame.contentDocument()) : Undefined();
01868     case IFrameContentWindow:       {
01869         DOM::DocumentImpl* contentDoc = static_cast<DOM::DocumentImpl*>(iFrame.contentDocument().handle());
01870         if (!contentDoc)
01871             return Undefined();
01872 
01873         KHTMLView *view = contentDoc->view();
01874         if (view && view->part())
01875             return Value(Window::retrieveWindow(view->part()));
01876         else
01877             return Undefined();
01878     }
01879     case IFrameFrameBorder:     return String(iFrame.frameBorder());
01880     case IFrameHeight:          return String(iFrame.height());
01881     case IFrameLongDesc:        return String(iFrame.longDesc());
01882     case IFrameMarginHeight:    return String(iFrame.marginHeight());
01883     case IFrameMarginWidth:     return String(iFrame.marginWidth());
01884     case IFrameName:            return String(iFrame.name());
01885     case IFrameScrolling:       return String(iFrame.scrolling());
01886     case IFrameSrc:             return String(iFrame.src());
01887     case IFrameWidth:           return String(iFrame.width());
01888     }
01889     break;
01890   }
01891   } // xemacs (or arnt) could be a bit smarter when it comes to indenting switch()es ;)
01892   // its not arnt to blame - its the original Stroustrup style we like :) (Dirk)
01893 
01894   // generic properties
01895   switch (token) {
01896   case ElementId:
01897     return String(element.id()); // String is wrong here. Other browsers return empty string if no id specified.
01898   case ElementTitle:
01899     return String(element.title());
01900   case ElementLang:
01901     return String(element.lang());
01902   case ElementDir:
01903     return String(element.dir());
01904   case ElementClassName:
01905     return String(element.className());
01906   case ElementInnerHTML:
01907     return String(element.innerHTML());
01908   case ElementInnerText:
01909     return String(element.innerText());
01910   case ElementDocument:
01911     return getDOMNode(exec,element.ownerDocument());
01912   case ElementChildren:
01913     return getHTMLCollection(exec,element.children());
01914   case ElementAll:
01915     // Disable element.all when we try to be Netscape-compatible
01916     if ( exec->interpreter()->compatMode() == Interpreter::NetscapeCompat )
01917       return Undefined();
01918     else
01919     if ( exec->interpreter()->compatMode() == Interpreter::IECompat )
01920       return getHTMLCollection(exec,element.all());
01921     else // Enabled but hidden by default
01922       return getHTMLCollection(exec,element.all(), true);
01923   // ### what about style? or is this used instead for DOM2 stylesheets?
01924   }
01925   kdError() << "HTMLElement::getValueProperty unhandled token " << token << endl;
01926   return Undefined();
01927 }
01928 
01929 bool KJS::HTMLElement::hasProperty(ExecState *exec, const Identifier &propertyName) const
01930 {
01931 #ifdef KJS_VERBOSE
01932   //kdDebug(6070) << "HTMLElement::hasProperty " << propertyName.qstring() << endl;
01933 #endif
01934   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
01935   // First look at dynamic properties - keep this in sync with tryGet
01936   switch (element.elementId()) {
01937     case ID_FORM: {
01938       DOM::HTMLFormElement form = element;
01939       // Check if we're retrieving an element (by index or by name)
01940       bool ok;
01941       uint u = propertyName.toULong(&ok);
01942       if (ok && !(form.elements().item(u).isNull()))
01943         return true;
01944       DOM::Node testnode = form.elements().namedItem(propertyName.string());
01945       if (!testnode.isNull())
01946         return true;
01947     }
01948     case ID_SELECT: {
01949       DOM::HTMLSelectElement select = element;
01950       bool ok;
01951       uint u = propertyName.toULong(&ok);
01952       if (ok && !(select.options().item(u).isNull()))
01953         return true;
01954     }
01955     default:
01956       break;
01957   }
01958 
01959   return DOMElement::hasProperty(exec, propertyName);
01960 }
01961 
01962 UString KJS::HTMLElement::toString(ExecState *exec) const
01963 {
01964   if (node.elementId() == ID_A)
01965     return UString(static_cast<const DOM::HTMLAnchorElement&>(node).href());
01966   else if (node.elementId() == ID_APPLET) {
01967     KParts::LiveConnectExtension *lc = getLiveConnectExtension(node);
01968     QStringList qargs;
01969     QString retvalue;
01970     KParts::LiveConnectExtension::Type rettype;
01971     unsigned long retobjid;
01972     if (lc && lc->call(0, "hashCode", qargs, rettype, retobjid, retvalue)) {
01973       QString str("[object APPLET ref=");
01974       return UString(str + retvalue + QString("]"));
01975     }
01976   } else if (node.elementId() == ID_IMG) {
01977     DOM::HTMLImageElement image(node);
01978     if (!image.alt().isEmpty())
01979       return UString(image.alt()) + " " + DOMElement::toString(exec);
01980   }
01981   return DOMElement::toString(exec);
01982 }
01983 
01984 static void getForm(DOM::HTMLFormElement* form, const DOM::HTMLElement& element)
01985 {
01986     switch (element.elementId()) {
01987         case ID_ISINDEX: {
01988             DOM::HTMLIsIndexElement isindex = element;
01989             *form = isindex.form();
01990             break;
01991         }
01992         case ID_SELECT: {
01993             DOM::HTMLSelectElement select = element;
01994             *form = select.form();
01995             break;
01996         }
01997         case ID_OPTION: {
01998             DOM::HTMLOptionElement option = element;
01999             *form = option.form();
02000             break;
02001         }
02002         case ID_INPUT: {
02003             DOM::HTMLInputElement input = element;
02004             *form = input.form();
02005             break;
02006         }
02007         case ID_TEXTAREA: {
02008             DOM::HTMLTextAreaElement textarea = element;
02009             *form = textarea.form();
02010             break;
02011         }
02012         case ID_LABEL: {
02013             DOM::HTMLLabelElement label = element;
02014             *form = label.form();
02015             break;
02016         }
02017         case ID_FIELDSET: {
02018             DOM::HTMLFieldSetElement fieldset = element;
02019             *form = fieldset.form();
02020             break;
02021         }
02022         case ID_LEGEND: {
02023             DOM::HTMLLegendElement legend = element;
02024             *form = legend.form();
02025             break;
02026         }
02027         case ID_OBJECT: {
02028             DOM::HTMLObjectElement object = element;
02029             *form = object.form();
02030             break;
02031         }
02032         default:
02033             break;
02034     }
02035 }
02036 
02037 void KJS::HTMLElement::pushEventHandlerScope(ExecState *exec, ScopeChain &scope) const
02038 {
02039   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02040 
02041   // The document is put on first, fall back to searching it only after the element and form.
02042   scope.push(static_cast<ObjectImp *>(getDOMNode(exec, element.ownerDocument()).imp()));
02043 
02044   // The form is next, searched before the document, but after the element itself.
02045   DOM::HTMLFormElement formElt;
02046 
02047   // First try to obtain the form from the element itself.  We do this to deal with
02048   // the malformed case where <form>s aren't in our parent chain (e.g., when they were inside
02049   // <table> or <tbody>.
02050   getForm(&formElt, element);
02051   if (!formElt.isNull())
02052     scope.push(static_cast<ObjectImp *>(getDOMNode(exec, formElt).imp()));
02053   else {
02054     DOM::Node form = element.parentNode();
02055     while (!form.isNull() && form.elementId() != ID_FORM)
02056         form = form.parentNode();
02057 
02058     if (!form.isNull())
02059         scope.push(static_cast<ObjectImp *>(getDOMNode(exec, form).imp()));
02060   }
02061 
02062   // The element is on top, searched first.
02063   scope.push(static_cast<ObjectImp *>(getDOMNode(exec, element).imp()));
02064 }
02065 
02066 HTMLElementFunction::HTMLElementFunction(ExecState *exec, int i, int len)
02067   : DOMFunction(exec), id(i)
02068 {
02069   Value protect(this);
02070   put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum);
02071 }
02072 
02073 Value KJS::HTMLElementFunction::tryCall(ExecState *exec, Object &thisObj, const List &args)
02074 {
02075   KJS_CHECK_THIS( HTMLElement, thisObj );
02076 
02077 #ifdef KJS_VERBOSE
02078   kdDebug(6070) << "KJS::HTMLElementFunction::tryCall " << endl;
02079 #endif
02080   DOM::HTMLElement element = static_cast<KJS::HTMLElement *>(thisObj.imp())->toElement();
02081 
02082   switch (element.elementId()) {
02083     case ID_FORM: {
02084       DOM::HTMLFormElement form = element;
02085       if (id == KJS::HTMLElement::FormSubmit) {
02086 
02087 
02088         DOM::HTMLDocument doc = element.ownerDocument();
02089         KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
02090         KHTMLSettings::KJSWindowOpenPolicy policy = KHTMLSettings::KJSWindowOpenAllow;
02091     if (view)
02092         policy = view->part()->settings()->windowOpenPolicy(view->part()->url().host());
02093 
02094         bool block = false;
02095 
02096         if ( policy != KHTMLSettings::KJSWindowOpenAllow ) {
02097           block = true;
02098 
02099          // if this is a form without a target, or a special target, don't block
02100           QString trg = form.target().lower().string();
02101           if( trg.isEmpty() || trg == "_top" || trg == "_self" ||
02102               trg == "_parent")
02103             block = false;
02104 
02105           QString caption;
02106 
02107           // if there is a frame with the target name, don't block
02108           if ( view && view->part() )  {
02109             if (!view->part()->url().host().isEmpty())
02110               caption = view->part()->url().host() + " - ";
02111             // search all (possibly nested) framesets
02112             KHTMLPart *currentPart = view->part()->parentPart();
02113             while( currentPart != 0L ) {
02114               if( currentPart->frameExists( form.target().string() ) )
02115                 block = false;
02116               currentPart = currentPart->parentPart();
02117             }
02118           }
02119 
02120           if ( block && policy == KHTMLSettings::KJSWindowOpenAsk && view ) {
02121             if (view && view->part())
02122             emit view->part()->browserExtension()->requestFocus(view->part());
02123             caption += i18n( "Confirmation: JavaScript Popup" );
02124             if ( KMessageBox::questionYesNo(view, form.action().isEmpty() ?
02125                    i18n( "This site is submitting a form which will open up a new browser "
02126                          "window via JavaScript.\n"
02127                          "Do you want to allow the form to be submitted?" ) :
02128                    i18n( "<qt>This site is submitting a form which will open <p>%1</p> in a new browser window via JavaScript.<br />"
02129                          "Do you want to allow the form to be submitted?</qt>").arg(KStringHandler::csqueeze(form.action().string(),  100)),
02130                    caption, i18n("Allow"), i18n("Do Not Allow") ) == KMessageBox::Yes )
02131               block = false;
02132 
02133           } else if ( block && policy == KHTMLSettings::KJSWindowOpenSmart ) {
02134             if( static_cast<KJS::ScriptInterpreter *>(exec->interpreter())->isWindowOpenAllowed() ) {
02135               // This submission has been triggered by the user
02136               block = false;
02137             }
02138           }
02139         }
02140 
02141         if( !block )
02142           form.submit();
02143 
02144         return Undefined();
02145       }
02146       else if (id == KJS::HTMLElement::FormReset) {
02147         form.reset();
02148         return Undefined();
02149       }
02150     }
02151     break;
02152     case ID_SELECT: {
02153       DOM::HTMLSelectElement select = element;
02154       if (id == KJS::HTMLElement::SelectAdd) {
02155         select.add(KJS::toNode(args[0]),KJS::toNode(args[1]));
02156         return Undefined();
02157       }
02158       else if (id == KJS::HTMLElement::SelectRemove) {
02159         select.remove(int(args[0].toNumber(exec)));
02160         return Undefined();
02161       }
02162       else if (id == KJS::HTMLElement::SelectBlur) {
02163         select.blur();
02164         return Undefined();
02165       }
02166       else if (id == KJS::HTMLElement::SelectFocus) {
02167         select.focus();
02168         return Undefined();
02169       }
02170     }
02171     break;
02172     case ID_INPUT: {
02173       DOM::HTMLInputElement input = element;
02174       if (id == KJS::HTMLElement::InputBlur) {
02175         input.blur();
02176         return Undefined();
02177       }
02178       else if (id == KJS::HTMLElement::InputFocus) {
02179         input.focus();
02180         return Undefined();
02181       }
02182       else if (id == KJS::HTMLElement::InputSelect) {
02183         input.select();
02184         return Undefined();
02185       }
02186       else if (id == KJS::HTMLElement::InputClick) {
02187         input.click();
02188         return Undefined();
02189       }
02190     }
02191     break;
02192     case ID_BUTTON: {
02193       DOM::HTMLButtonElement button = element;
02194       if (id == KJS::HTMLElement::ButtonBlur) {
02195         button.blur();
02196         return Undefined();
02197       }
02198       else if (id == KJS::HTMLElement::ButtonFocus) {
02199         button.focus();
02200         return Undefined();
02201       }
02202     }
02203     break;
02204     case ID_TEXTAREA: {
02205       DOM::HTMLTextAreaElement textarea = element;
02206       if (id == KJS::HTMLElement::TextAreaBlur) {
02207         textarea.blur();
02208         return Undefined();
02209       }
02210       else if (id == KJS::HTMLElement::TextAreaFocus) {
02211         textarea.focus();
02212         return Undefined();
02213       }
02214       else if (id == KJS::HTMLElement::TextAreaSelect) {
02215         textarea.select();
02216         return Undefined();
02217       }
02218     }
02219     break;
02220     case ID_A: {
02221       DOM::HTMLAnchorElement anchor = element;
02222       if (id == KJS::HTMLElement::AnchorBlur) {
02223         anchor.blur();
02224         return Undefined();
02225       }
02226       else if (id == KJS::HTMLElement::AnchorFocus) {
02227         anchor.focus();
02228         return Undefined();
02229       }
02230       else if (id == KJS::HTMLElement::AnchorClick) {
02231         static_cast<DOM::HTMLAnchorElementImpl*>(anchor.handle())->click();
02232         return Undefined();
02233       }
02234     }
02235     break;
02236     case ID_TABLE: {
02237       DOM::HTMLTableElement table = element;
02238       if (id == KJS::HTMLElement::TableCreateTHead)
02239         return getDOMNode(exec,table.createTHead());
02240       else if (id == KJS::HTMLElement::TableDeleteTHead) {
02241         table.deleteTHead();
02242         return Undefined();
02243       }
02244       else if (id == KJS::HTMLElement::TableCreateTFoot)
02245         return getDOMNode(exec,table.createTFoot());
02246       else if (id == KJS::HTMLElement::TableDeleteTFoot) {
02247         table.deleteTFoot();
02248         return Undefined();
02249       }
02250       else if (id == KJS::HTMLElement::TableCreateCaption)
02251         return getDOMNode(exec,table.createCaption());
02252       else if (id == KJS::HTMLElement::TableDeleteCaption) {
02253         table.deleteCaption();
02254         return Undefined();
02255       }
02256       else if (id == KJS::HTMLElement::TableInsertRow)
02257         return getDOMNode(exec,table.insertRow(args[0].toInteger(exec)));
02258       else if (id == KJS::HTMLElement::TableDeleteRow) {
02259         table.deleteRow(args[0].toInteger(exec));
02260         return Undefined();
02261       }
02262     }
02263     break;
02264     case ID_THEAD:
02265     case ID_TBODY:
02266     case ID_TFOOT: {
02267       DOM::HTMLTableSectionElement tableSection = element;
02268       if (id == KJS::HTMLElement::TableSectionInsertRow)
02269         return getDOMNode(exec,tableSection.insertRow(args[0].toInteger(exec)));
02270       else if (id == KJS::HTMLElement::TableSectionDeleteRow) {
02271         tableSection.deleteRow(args[0].toInteger(exec));
02272         return Undefined();
02273       }
02274     }
02275     break;
02276     case ID_TR: {
02277       DOM::HTMLTableRowElement tableRow = element;
02278       if (id == KJS::HTMLElement::TableRowInsertCell)
02279         return getDOMNode(exec,tableRow.insertCell(args[0].toInteger(exec)));
02280       else if (id == KJS::HTMLElement::TableRowDeleteCell) {
02281         tableRow.deleteCell(args[0].toInteger(exec));
02282         return Undefined();
02283       }
02284       break;
02285     }
02286     case ID_MARQUEE: {
02287       if (id == KJS::HTMLElement::MarqueeStart && element.handle()->renderer() &&
02288         element.handle()->renderer()->layer() &&
02289         element.handle()->renderer()->layer()->marquee()) {
02290         element.handle()->renderer()->layer()->marquee()->start();
02291         return Undefined();
02292       }
02293       else if (id == KJS::HTMLElement::MarqueeStop && element.handle()->renderer() &&
02294               element.handle()->renderer()->layer() &&
02295               element.handle()->renderer()->layer()->marquee()) {
02296         element.handle()->renderer()->layer()->marquee()->stop();
02297         return Undefined();
02298       }
02299       break;
02300     }
02301   }
02302 
02303   return Undefined();
02304 }
02305 
02306 void KJS::HTMLElement::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
02307 {
02308 #ifdef KJS_VERBOSE
02309   DOM::DOMString str = value.isA(NullType) ? DOM::DOMString() : value.toString(exec).string();
02310 #endif
02311   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02312 #ifdef KJS_VERBOSE
02313   kdDebug(6070) << "KJS::HTMLElement::tryPut " << propertyName.qstring()
02314                 << " thisTag=" << element.tagName().string()
02315                 << " str=" << str.string() << endl;
02316 #endif
02317   // First look at dynamic properties
02318   switch (element.elementId()) {
02319     case ID_SELECT: {
02320       DOM::HTMLSelectElement select = element;
02321       bool ok;
02322       /*uint u =*/ propertyName.toULong(&ok);
02323       if (ok) {
02324         Object coll = Object::dynamicCast( getSelectHTMLCollection(exec, select.options(), select) );
02325         if ( coll.isValid() )
02326           coll.put(exec,propertyName,value);
02327         return;
02328       }
02329       break;
02330     }
02331     case ID_APPLET:
02332     case ID_OBJECT:
02333     case ID_EMBED: {
02334       KParts::LiveConnectExtension *lc = getLiveConnectExtension(element);
02335       if (lc && lc->put(0, propertyName.qstring(), value.toString(exec).qstring()))
02336         return;
02337       break;
02338     }
02339     default:
02340       break;
02341   }
02342 
02343   const HashTable* table = classInfo()->propHashTable; // get the right hashtable
02344   const HashEntry* entry = Lookup::findEntry(table, propertyName);
02345   if (entry) {
02346     if (entry->attr & Function) // function: put as override property
02347     {
02348       ObjectImp::put(exec, propertyName, value, attr);
02349       return;
02350     }
02351     else if ((entry->attr & ReadOnly) == 0) // let DOMObjectLookupPut print the warning if not
02352     {
02353       putValueProperty(exec, entry->value, value, attr);
02354       return;
02355     }
02356   }
02357   DOMObjectLookupPut<KJS::HTMLElement, DOMElement>(exec, propertyName, value, attr, &KJS::HTMLElementTable, this);
02358 }
02359 
02360 void KJS::HTMLElement::putValueProperty(ExecState *exec, int token, const Value& value, int)
02361 {
02362   DOM::DOMString str = value.isA(NullType) ? DOM::DOMString() : value.toString(exec).string();
02363   DOMNode *kjsNode = new DOMNode(exec, KJS::toNode(value));
02364   // Need to create a Value wrapper to avoid leaking the KJS::DOMNode
02365   Value nodeValue(kjsNode);
02366   DOM::Node n = kjsNode->toNode();
02367   DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
02368 #ifdef KJS_VERBOSE
02369   kdDebug(6070) << "KJS::HTMLElement::putValueProperty "
02370                 << " thisTag=" << element.tagName().string()
02371                 << " token=" << token << endl;
02372 #endif
02373 
02374   switch (element.elementId()) {
02375   case ID_HTML: {
02376       DOM::HTMLHtmlElement html = element;
02377       switch (token) {
02378       case HtmlVersion:         { html.setVersion(str); return; }
02379       }
02380   }
02381   break;
02382   case ID_HEAD: {
02383     DOM::HTMLHeadElement head = element;
02384     switch (token) {
02385     case HeadProfile:         { head.setProfile(str); return; }
02386     }
02387   }
02388   break;
02389   case ID_LINK: {
02390     DOM::HTMLLinkElement link = element;
02391     switch (token) {
02392       case LinkDisabled:        { link.setDisabled(value.toBoolean(exec)); return; }
02393       case LinkCharset:         { link.setCharset(str); return; }
02394       case LinkHref:            { link.setHref(str); return; }
02395       case LinkHrefLang:        { link.setHreflang(str); return; }
02396       case LinkMedia:           { link.setMedia(str); return; }
02397       case LinkRel:             { link.setRel(str); return; }
02398       case LinkRev:             { link.setRev(str); return; }
02399       case LinkTarget:          { link.setTarget(str); return; }
02400       case LinkType:            { link.setType(str); return; }
02401       }
02402     }
02403     break;
02404     case ID_TITLE: {
02405       DOM::HTMLTitleElement title = element;
02406       switch (token) {
02407       case TitleText:                 { title.setText(str); return; }
02408       }
02409     }
02410     break;
02411     case ID_META: {
02412       DOM::HTMLMetaElement meta = element;
02413       switch (token) {
02414       case MetaContent:         { meta.setContent(str); return; }
02415       case MetaHttpEquiv:       { meta.setHttpEquiv(str); return; }
02416       case MetaName:            { meta.setName(str); return; }
02417       case MetaScheme:          { meta.setScheme(str); return; }
02418       }
02419     }
02420     break;
02421     case ID_BASE: {
02422       DOM::HTMLBaseElement base = element;
02423       switch (token) {
02424       case BaseHref:            { base.setHref(str); return; }
02425       case BaseTarget:          { base.setTarget(str); return; }
02426       }
02427     }
02428     break;
02429     case ID_ISINDEX: {
02430       DOM::HTMLIsIndexElement isindex = element;
02431       switch (token) {
02432       // read-only: form
02433       case IsIndexPrompt:               { isindex.setPrompt(str); return; }
02434       }
02435     }
02436     break;
02437     case ID_STYLE: {
02438       DOM::HTMLStyleElement style = element;
02439       switch (token) {
02440       case StyleDisabled:        { style.setDisabled(value.toBoolean(exec)); return; }
02441       case StyleMedia:           { style.setMedia(str); return; }
02442       case StyleType:            { style.setType(str); return; }
02443       }
02444     }
02445     break;
02446     case ID_BODY: {
02447       DOM::HTMLBodyElement body = element;
02448       switch (token) {
02449       case BodyALink:           { body.setALink(str); return; }
02450       case BodyBackground:      { body.setBackground(str); return; }
02451       case BodyBgColor:         { body.setBgColor(str); return; }
02452       case BodyLink:            { body.setLink(str); return; }
02453       case BodyText:            { body.setText(str); return; }
02454       case BodyVLink:           { body.setVLink(str); return; }
02455       case BodyScrollLeft:
02456       case BodyScrollTop: {
02457         QScrollView* sview = body.ownerDocument().view();
02458         if (sview) {
02459           // Update the document's layout before we compute these attributes.
02460           DOM::DocumentImpl* docimpl = body.handle()->getDocument();
02461           if (docimpl)
02462             docimpl->updateLayout();
02463           if (token == BodyScrollLeft)
02464             sview->setContentsPos(value.toInteger(exec), sview->contentsY());
02465           else
02466             sview->setContentsPos(sview->contentsX(), value.toInteger(exec));
02467           }
02468         return;
02469       }
02470       case BodyOnLoad:
02471         DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(node.ownerDocument().handle());
02472         if (doc && checkNodeSecurity(exec, node))
02473         {
02474           DOMNode* kjsDocNode = new DOMNode(exec, doc);
02475           // Need to create a Value wrapper to avoid leaking the KJS::DOMNode
02476           Value nodeValue(kjsDocNode);
02477           kjsDocNode->setListener(exec,DOM::EventImpl::LOAD_EVENT,value);
02478         }
02479         return;
02480       }
02481     }
02482     break;
02483     case ID_FORM: {
02484       DOM::HTMLFormElement form = element;
02485       switch (token) {
02486       // read-only: elements
02487       // read-only: length
02488       case FormName:            { form.setName(str); return; }
02489       case FormAcceptCharset:   { form.setAcceptCharset(str); return; }
02490       case FormAction:          { form.setAction(str.string()); return; }
02491       case FormEncType:         { form.setEnctype(str); return; }
02492       case FormMethod:          { form.setMethod(str); return; }
02493       case FormTarget:          { form.setTarget(str); return; }
02494       }
02495     }
02496     break;
02497     case ID_SELECT: {
02498       DOM::HTMLSelectElement select = element;
02499       switch (token) {
02500       // read-only: type
02501       case SelectSelectedIndex:   { select.setSelectedIndex(value.toInteger(exec)); return; }
02502       case SelectValue:           { select.setValue(str); return; }
02503       case SelectLength:          { // read-only according to the NS spec, but webpages need it writeable
02504                                          Object coll = Object::dynamicCast( getSelectHTMLCollection(exec, select.options(), select) );
02505                                          if ( coll.isValid() )
02506                                            coll.put(exec,"length",value);
02507                                          return;
02508                                        }
02509       // read-only: form
02510       // read-only: options
02511       case SelectDisabled:        { select.setDisabled(value.toBoolean(exec)); return; }
02512       case SelectMultiple:        { select.setMultiple(value.toBoolean(exec)); return; }
02513       case SelectName:            { select.setName(str); return; }
02514       case SelectSize:            { select.setSize(value.toInteger(exec)); return; }
02515       case SelectTabIndex:        { select.setTabIndex(value.toInteger(exec)); return; }
02516       }
02517     }
02518     break;
02519     case ID_OPTGROUP: {
02520       DOM::HTMLOptGroupElement optgroup = element;
02521       switch (token) {
02522       case OptGroupDisabled:        { optgroup.setDisabled(value.toBoolean(exec)); return; }
02523       case OptGroupLabel:           { optgroup.setLabel(str); return; }
02524       }
02525     }
02526     break;
02527     case ID_OPTION: {
02528       DOM::HTMLOptionElement option = element;
02529       switch (token) {
02530       // read-only: form
02531       case OptionDefaultSelected: { option.setDefaultSelected(value.toBoolean(exec)); return; }
02532       // read-only: text  <--- According to the DOM, but JavaScript and JScript both allow changes.
02533       // So, we'll do it here and not add it to our DOM headers.
02534       case OptionText:            { DOM::NodeList nl(option.childNodes());
02535                                     for (unsigned int i = 0; i < nl.length(); i++) {
02536                                         if (nl.item(i).nodeType() == DOM::Node::TEXT_NODE) {
02537                                             static_cast<DOM::Text>(nl.item(i)).setData(str);
02538                                             return;
02539                                         }
02540                                   }
02541                                   // No child text node found, creating one
02542                                   DOM::Text t = option.ownerDocument().createTextNode(str);
02543                                   try { option.appendChild(t); }
02544                                   catch(DOM::DOMException& e) {
02545                                     // #### exec->setException ?
02546                                   }
02547 
02548                                   return;
02549       }
02550       // read-only: index
02551       case OptionDisabled:        { option.setDisabled(value.toBoolean(exec)); return; }
02552       case OptionLabel:           { option.setLabel(str); return; }
02553       case OptionSelected:        { option.setSelected(value.toBoolean(exec)); return; }
02554       case OptionValue:           { option.setValue(str); return; }
02555       }
02556     }
02557     break;
02558     case ID_INPUT: {
02559       DOM::HTMLInputElement input = element;
02560       switch (token) {
02561       case InputDefaultValue:    { input.setDefaultValue(str); return; }
02562       case InputDefaultChecked:  { input.setDefaultChecked(value.toBoolean(exec)); return; }
02563       // read-only: form
02564       case InputAccept:          { input.setAccept(str); return; }
02565       case InputAccessKey:       { input.setAccessKey(str); return; }
02566       case InputAlign:           { input.setAlign(str); return; }
02567       case InputAlt:             { input.setAlt(str); return; }
02568       case InputChecked:         { input.setChecked(value.toBoolean(exec)); return; }
02569       case InputDisabled:        { input.setDisabled(value.toBoolean(exec)); return; }
02570       case InputMaxLength:       { input.setMaxLength(value.toInteger(exec)); return; }
02571       case InputName:            { input.setName(str); return; }
02572       case InputReadOnly:        { input.setReadOnly(value.toBoolean(exec)); return; }
02573       case InputSize:            { input.setSize(value.toInteger(exec)); return; }
02574       case InputSrc:             { input.setSrc(str); return; }
02575       case InputTabIndex:        { input.setTabIndex(value.toInteger(exec)); return; }
02576       case InputType:            { input.setType(str); return; }
02577       case InputUseMap:          { input.setUseMap(str); return; }
02578       case InputValue:           { input.setValue(str); return; }
02579       }
02580     }
02581     break;
02582     case ID_TEXTAREA: {
02583       DOM::HTMLTextAreaElement textarea = element;
02584       switch (token) {
02585       case TextAreaDefaultValue:    { textarea.setDefaultValue(str); return; }
02586       // read-only: form
02587       case TextAreaAccessKey:       { textarea.setAccessKey(str); return; }
02588       case TextAreaCols:            { textarea.setCols(value.toInteger(exec)); return; }
02589       case TextAreaDisabled:        { textarea.setDisabled(value.toBoolean(exec)); return; }
02590       case TextAreaName:            { textarea.setName(str); return; }
02591       case TextAreaReadOnly:        { textarea.setReadOnly(value.toBoolean(exec)); return; }
02592       case TextAreaRows:            { textarea.setRows(value.toInteger(exec)); return; }
02593       case TextAreaTabIndex:        { textarea.setTabIndex(value.toInteger(exec)); return; }
02594       // read-only: type
02595       case TextAreaValue:           { textarea.setValue(str); return; }
02596       }
02597     }
02598     break;
02599     case ID_BUTTON: {
02600       DOM::HTMLButtonElement button = element;
02601       switch (token) {
02602       // read-only: form
02603       case ButtonAccessKey:       { button.setAccessKey(str); return; }
02604       case ButtonDisabled:        { button.setDisabled(value.toBoolean(exec)); return; }
02605       case ButtonName:            { button.setName(str); return; }
02606       case ButtonTabIndex:        { button.setTabIndex(value.toInteger(exec)); return; }
02607       // read-only: type
02608       case ButtonValue:           { button.setValue(str); return; }
02609       }
02610     }
02611     break;
02612     case ID_LABEL: {
02613       DOM::HTMLLabelElement label = element;
02614       switch (token) {
02615       // read-only: form
02616       case LabelAccessKey:       { label.setAccessKey(str); return; }
02617       case LabelHtmlFor:         { label.setHtmlFor(str); return; }
02618       }
02619     }
02620     break;
02621 //    case ID_FIELDSET: {
02622 //      DOM::HTMLFieldSetElement fieldSet = element;
02623 //      // read-only: form
02624 //    }
02625 //    break;
02626     case ID_LEGEND: {
02627       DOM::HTMLLegendElement legend = element;
02628       switch (token) {
02629       // read-only: form
02630       case LegendAccessKey:       { legend.setAccessKey(str); return; }
02631       case LegendAlign:           { legend.setAlign(str); return; }
02632       }
02633     }
02634     break;
02635     case ID_UL: {
02636       DOM::HTMLUListElement uList = element;
02637       switch (token) {
02638       case UListCompact:         { uList.setCompact(value.toBoolean(exec)); return; }
02639       case UListType:            { uList.setType(str); return; }
02640       }
02641     }
02642     break;
02643     case ID_OL: {
02644       DOM::HTMLOListElement oList = element;
02645       switch (token) {
02646       case OListCompact:         { oList.setCompact(value.toBoolean(exec)); return; }
02647       case OListStart:           { oList.setStart(value.toInteger(exec)); return; }
02648       case OListType:            { oList.setType(str); return; }
02649       }
02650     }
02651     break;
02652     case ID_DL: {
02653       DOM::HTMLDListElement dList = element;
02654       switch (token) {
02655       case DListCompact:         { dList.setCompact(value.toBoolean(exec)); return; }
02656       }
02657     }
02658     break;
02659     case ID_DIR: {
02660       DOM::HTMLDirectoryElement directory = element;
02661       switch (token) {
02662       case DirectoryCompact:     { directory.setCompact(value.toBoolean(exec)); return; }
02663       }
02664     }
02665     break;
02666     case ID_MENU: {
02667       DOM::HTMLMenuElement menu = element;
02668       switch (token) {
02669       case MenuCompact:         { menu.setCompact(value.toBoolean(exec)); return; }
02670       }
02671     }
02672     break;
02673     case ID_LI: {
02674       DOM::HTMLLIElement li = element;
02675       switch (token) {
02676       case LIType:            { li.setType(str); return; }
02677       case LIValue:           { li.setValue(value.toInteger(exec)); return; }
02678       }
02679     }
02680     break;
02681     case ID_DIV: {
02682       DOM::HTMLDivElement div = element;
02683       switch (token) {
02684       case DivAlign:           { div.setAlign(str); return; }
02685       }
02686     }
02687     break;
02688     case ID_P: {
02689       DOM::HTMLParagraphElement paragraph = element;
02690       switch (token) {
02691       case ParagraphAlign:     { paragraph.setAlign(str); return; }
02692       }
02693     }
02694     break;
02695     case ID_H1:
02696     case ID_H2:
02697     case ID_H3:
02698     case ID_H4:
02699     case ID_H5:
02700     case ID_H6: {
02701       DOM::HTMLHeadingElement heading = element;
02702       switch (token) {
02703       case HeadingAlign:         { heading.setAlign(str); return; }
02704       }
02705     }
02706     break;
02707     case ID_BLOCKQUOTE: {
02708       DOM::HTMLBlockquoteElement blockquote = element;
02709       switch (token) {
02710       case BlockQuoteCite:       { blockquote.setCite(str); return; }
02711       }
02712     }
02713     break;
02714     case ID_Q: {
02715       DOM::HTMLQuoteElement quote = element;
02716       switch (token) {
02717       case QuoteCite:            { quote.setCite(str); return; }
02718       }
02719     }
02720     break;
02721     case ID_PRE: {
02722       DOM::HTMLPreElement pre = element;
02723       switch (token) {
02724       case PreWidth:           { pre.setWidth(value.toInteger(exec)); return; }
02725       }
02726     }
02727     break;
02728     case ID_BR: {
02729       DOM::HTMLBRElement br = element;
02730       switch (token) {
02731       case BRClear:           { br.setClear(str); return; }
02732       }
02733     }
02734     break;
02735     case ID_BASEFONT: {
02736       DOM::HTMLBaseFontElement baseFont = element;
02737       switch (token) {
02738       case BaseFontColor:           { baseFont.setColor(str); return; }
02739       case BaseFontFace:            { baseFont.setFace(str); return; }
02740       case BaseFontSize:            { baseFont.setSize(value.toInteger(exec)); return; }
02741       }
02742     }
02743     break;
02744     case ID_FONT: {
02745       DOM::HTMLFontElement font = element;
02746       switch (token) {
02747       case FontColor:           { font.setColor(str); return; }
02748       case FontFace:            { font.setFace(str); return; }
02749       case FontSize:            { font.setSize(str); return; }
02750       }
02751     }
02752     break;
02753     case ID_HR: {
02754       DOM::HTMLHRElement hr = element;
02755       switch (token) {
02756       case HRAlign:           { hr.setAlign(str); return; }
02757       case HRNoShade:         { hr.setNoShade(value.toBoolean(exec)); return; }
02758       case HRSize:            { hr.setSize(str); return; }
02759       case HRWidth:           { hr.setWidth(str); return; }
02760       }
02761     }
02762     break;
02763     case ID_INS:
02764     case ID_DEL: {
02765       DOM::HTMLModElement mod = element;
02766       switch (token) {
02767       case ModCite:            { mod.setCite(str); return; }
02768       case ModDateTime:        { mod.setDateTime(str); return; }
02769       }
02770     }
02771     break;
02772     case ID_A: {
02773       DOM::HTMLAnchorElement anchor = element;
02774       switch (token) {
02775       case AnchorAccessKey:       { anchor.setAccessKey(str); return; }
02776       case AnchorCharset:         { anchor.setCharset(str); return; }
02777       case AnchorCoords:          { anchor.setCoords(str); return; }
02778       case AnchorHref:            { anchor.setHref(str); return; }
02779       case AnchorHrefLang:        { anchor.setHreflang(str); return; }
02780       case AnchorName:            { anchor.setName(str); return; }
02781       case AnchorRel:             { anchor.setRel(str); return; }
02782       case AnchorRev:             { anchor.setRev(str); return; }
02783       case AnchorShape:           { anchor.setShape(str); return; }
02784       case AnchorTabIndex:        { anchor.setTabIndex(value.toInteger(exec)); return; }
02785       case AnchorTarget:          { anchor.setTarget(str); return; }
02786       case AnchorType:            { anchor.setType(str); return; }
02787       }
02788     }
02789     break;
02790     case ID_IMG: {
02791       DOM::HTMLImageElement image = element;
02792       switch (token) {
02793       case ImageName:            { image.setName(str); return; }
02794       case ImageAlign:           { image.setAlign(str); return; }
02795       case ImageAlt:             { image.setAlt(str); return; }
02796       case ImageBorder:          { image.setBorder(str); return; }
02797       case ImageHeight:          { image.setHeight(value.toInteger(exec)); return; }
02798       case ImageHspace:          { image.setHspace(value.toInteger(exec)); return; }
02799       case ImageIsMap:           { image.setIsMap(value.toBoolean(exec)); return; }
02800       case ImageLongDesc:        { image.setLongDesc(str); return; }
02801       case ImageSrc:             { image.setSrc(str); return; }
02802       case ImageUseMap:          { image.setUseMap(str); return; }
02803       case ImageVspace:          { image.setVspace(value.toInteger(exec)); return; }
02804       case ImageWidth:           { image.setWidth(value.toInteger(exec)); return; }
02805       }
02806     }
02807     break;
02808     case ID_OBJECT: {
02809       DOM::HTMLObjectElement object = element;
02810       switch (token) {
02811       // read-only: form
02812       case ObjectCode:                 { object.setCode(str); return; }
02813       case ObjectAlign:           { object.setAlign(str); return; }
02814       case ObjectArchive:         { object.setArchive(str); return; }
02815       case ObjectBorder:          { object.setBorder(str); return; }
02816       case ObjectCodeBase:        { object.setCodeBase(str); return; }
02817       case ObjectCodeType:        { object.setCodeType(str); return; }
02818       // read-only: ObjectContentDocument
02819       case ObjectData:            { object.setData(str); return; }
02820       case ObjectDeclare:         { object.setDeclare(value.toBoolean(exec)); return; }
02821       case ObjectHeight:          { object.setHeight(str); return; }
02822       case ObjectHspace:          { object.setHspace(value.toInteger(exec)); return; }
02823       case ObjectName:            { object.setName(str); return; }
02824       case ObjectStandby:         { object.setStandby(str); return; }
02825       case ObjectTabIndex:        { object.setTabIndex(value.toInteger(exec)); return; }
02826       case ObjectType:            { object.setType(str); return; }
02827       case ObjectUseMap:          { object.setUseMap(str); return; }
02828       case ObjectVspace:          { object.setVspace(value.toInteger(exec)); return; }
02829       case ObjectWidth:           { object.setWidth(str); return; }
02830       }
02831     }
02832     break;
02833     case ID_PARAM: {
02834       DOM::HTMLParamElement param = element;
02835       switch (token) {
02836       case ParamName:            { param.setName(str); return; }
02837       case ParamType:            { param.setType(str); return; }
02838       case ParamValue:           { param.setValue(str); return; }
02839       case ParamValueType:       { param.setValueType(str); return; }
02840       }
02841     }
02842     break;
02843     case ID_APPLET: {
02844       DOM::HTMLAppletElement applet = element;
02845       switch (token) {
02846       case AppletAlign:           { applet.setAlign(str); return; }
02847       case AppletAlt:             { applet.setAlt(str); return; }
02848       case AppletArchive:         { applet.setArchive(str); return; }
02849       case AppletCode:            { applet.setCode(str); return; }
02850       case AppletCodeBase:        { applet.setCodeBase(str); return; }
02851       case AppletHeight:          { applet.setHeight(str); return; }
02852       case AppletHspace:          { applet.setHspace(value.toInteger(exec)); return; }
02853       case AppletName:            { applet.setName(str); return; }
02854       case AppletObject:          { applet.setObject(str); return; }
02855       case AppletVspace:          { applet.setVspace(value.toInteger(exec)); return; }
02856       case AppletWidth:           { applet.setWidth(str); return; }
02857       }
02858     }
02859     break;
02860     case ID_MAP: {
02861       DOM::HTMLMapElement map = element;
02862       switch (token) {
02863       // read-only: areas
02864       case MapName:                 { map.setName(str); return; }
02865      }
02866     }
02867     break;
02868     case ID_AREA: {
02869       DOM::HTMLAreaElement area = element;
02870       switch (token) {
02871       case AreaAccessKey:       { area.setAccessKey(str); return; }
02872       case AreaAlt:             { area.setAlt(str); return; }
02873       case AreaCoords:          { area.setCoords(str); return; }
02874       case AreaHref:            { area.setHref(str); return; }
02875       case AreaNoHref:          { area.setNoHref(value.toBoolean(exec)); return; }
02876       case AreaShape:           { area.setShape(str); return; }
02877       case AreaTabIndex:        { area.setTabIndex(value.toInteger(exec)); return; }
02878       case AreaTarget:          { area.setTarget(str); return; }
02879       }
02880     }
02881     break;
02882     case ID_SCRIPT: {
02883       DOM::HTMLScriptElement script = element;
02884       switch (token) {
02885       case ScriptText:            { script.setText(str); return; }
02886       case ScriptHtmlFor:         { script.setHtmlFor(str); return; }
02887       case ScriptEvent:           { script.setEvent(str); return; }
02888       case ScriptCharset:         { script.setCharset(str); return; }
02889       case ScriptDefer:           { script.setDefer(value.toBoolean(exec)); return; }
02890       case ScriptSrc:             { script.setSrc(str); return; }
02891       case ScriptType:            { script.setType(str); return; }
02892       }
02893     }
02894     break;
02895     case ID_TABLE: {
02896       DOM::HTMLTableElement table = element;
02897       switch (token) {
02898       case TableCaption:         { table.setCaption(n); return; } // type HTMLTableCaptionElement
02899       case TableTHead:           { table.setTHead(n); return; } // type HTMLTableSectionElement
02900       case TableTFoot:           { table.setTFoot(n); return; } // type HTMLTableSectionElement
02901       // read-only: rows
02902       // read-only: tbodies
02903       case TableAlign:           { table.setAlign(str); return; }
02904       case TableBgColor:         { table.setBgColor(str); return; }
02905       case TableBorder:          { table.setBorder(str); return; }
02906       case TableCellPadding:     { table.setCellPadding(str); return; }
02907       case TableCellSpacing:     { table.setCellSpacing(str); return; }
02908       case TableFrame:           { table.setFrame(str); return; }
02909       case TableRules:           { table.setRules(str); return; }
02910       case TableSummary:         { table.setSummary(str); return; }
02911       case TableWidth:           { table.setWidth(str); return; }
02912       }
02913     }
02914     break;
02915     case ID_CAPTION: {
02916       DOM::HTMLTableCaptionElement tableCaption = element;
02917       switch (token) {
02918       case TableCaptionAlign:           { tableCaption.setAlign(str); return; }
02919       }
02920     }
02921     break;
02922     case ID_COL:
02923     case ID_COLGROUP: {
02924       DOM::HTMLTableColElement tableCol = element;
02925       switch (token) {
02926       case TableColAlign:           { tableCol.setAlign(str); return; }
02927       case TableColCh:              { tableCol.setCh(str); return; }
02928       case TableColChOff:           { tableCol.setChOff(str); return; }
02929       case TableColSpan:            { tableCol.setSpan(value.toInteger(exec)); return; }
02930       case TableColVAlign:          { tableCol.setVAlign(str); return; }
02931       case TableColWidth:           { tableCol.setWidth(str); return; }
02932       }
02933     }
02934     break;
02935     case ID_THEAD:
02936     case ID_TBODY:
02937     case ID_TFOOT: {
02938       DOM::HTMLTableSectionElement tableSection = element;
02939       switch (token) {
02940       case TableSectionAlign:           { tableSection.setAlign(str); return; }
02941       case TableSectionCh:              { tableSection.setCh(str); return; }
02942       case TableSectionChOff:           { tableSection.setChOff(str); return; }
02943       case TableSectionVAlign:          { tableSection.setVAlign(str); return; }
02944       // read-only: rows
02945       }
02946     }
02947     break;
02948     case ID_TR: {
02949       DOM::HTMLTableRowElement tableRow = element;
02950       switch (token) {
02951       // read-only: rowIndex
02952       // read-only: sectionRowIndex
02953       // read-only: cells
02954       case TableRowAlign:           { tableRow.setAlign(str); return; }
02955       case TableRowBgColor:         { tableRow.setBgColor(str); return; }
02956       case TableRowCh:              { tableRow.setCh(str); return; }
02957       case TableRowChOff:           { tableRow.setChOff(str); return; }
02958       case TableRowVAlign:          { tableRow.setVAlign(str); return; }
02959       }
02960     }
02961     break;
02962     case ID_TH:
02963     case ID_TD: {
02964       DOM::HTMLTableCellElement tableCell = element;
02965       switch (token) {
02966       // read-only: cellIndex
02967       case TableCellAbbr:            { tableCell.setAbbr(str); return; }
02968       case TableCellAlign:           { tableCell.setAlign(str); return; }
02969       case TableCellAxis:            { tableCell.setAxis(str); return; }
02970       case TableCellBgColor:         { tableCell.setBgColor(str); return; }
02971       case TableCellCh:              { tableCell.setCh(str); return; }
02972       case TableCellChOff:           { tableCell.setChOff(str); return; }
02973       case TableCellColSpan:         { tableCell.setColSpan(value.toInteger(exec)); return; }
02974       case TableCellHeaders:         { tableCell.setHeaders(str); return; }
02975       case TableCellHeight:          { tableCell.setHeight(str); return; }
02976       case TableCellNoWrap:          { tableCell.setNoWrap(value.toBoolean(exec)); return; }
02977       case TableCellRowSpan:         { tableCell.setRowSpan(value.toInteger(exec)); return; }
02978       case TableCellScope:           { tableCell.setScope(str); return; }
02979       case TableCellVAlign:          { tableCell.setVAlign(str); return; }
02980       case TableCellWidth:           { tableCell.setWidth(str); return; }
02981       }
02982     }
02983     break;
02984     case ID_FRAMESET: {
02985       DOM::HTMLFrameSetElement frameSet = element;
02986       switch (token) {
02987       case FrameSetCols:            { frameSet.setCols(str); return; }
02988       case FrameSetRows:            { frameSet.setRows(str); return; }
02989       }
02990     }
02991     break;
02992     case ID_LAYER: {
02993       DOM::HTMLLayerElement layerElement = element;
02994       switch (token) {
02995       case LayerTop:                   { layerElement.setTop(value.toInteger(exec)); return; }
02996       case LayerLeft:                  { layerElement.setLeft(value.toInteger(exec)); return; }
02997       case LayerVisibility:            { layerElement.setVisibility(str); return; }
02998       case LayerBgColor:               { layerElement.setBgColor(str); return; }
02999       // read-only: layers, clip
03000       }
03001     }
03002     break;
03003     case ID_FRAME: {
03004       DOM::HTMLFrameElement frameElement = element;
03005       switch (token) {
03006        // read-only: FrameContentDocument:
03007       case FrameFrameBorder:     { frameElement.setFrameBorder(str); return; }
03008       case FrameLongDesc:        { frameElement.setLongDesc(str); return; }
03009       case FrameMarginHeight:    { frameElement.setMarginHeight(str); return; }
03010       case FrameMarginWidth:     { frameElement.setMarginWidth(str); return; }
03011       case FrameName:            { frameElement.setName(str); return; }
03012       case FrameNoResize:        { frameElement.setNoResize(value.toBoolean(exec)); return; }
03013       case FrameScrolling:       { frameElement.setScrolling(str); return; }
03014       case FrameSrc:             { frameElement.setSrc(str); return; }
03015       case FrameLocation:        {
03016                                    static_cast<DOM::HTMLFrameElementImpl *>(frameElement.handle())->setLocation(str);
03017                                    return;
03018                                  }
03019       }
03020     }
03021     break;
03022     case ID_IFRAME: {
03023       DOM::HTMLIFrameElement iFrame = element;
03024       switch (token) {
03025       case IFrameAlign:           { iFrame.setAlign(str); return; }
03026       // read-only: IFrameContentDocument
03027       case IFrameFrameBorder:     { iFrame.setFrameBorder(str); return; }
03028       case IFrameHeight:          { iFrame.setHeight(str); return; }
03029       case IFrameLongDesc:        { iFrame.setLongDesc(str); return; }
03030       case IFrameMarginHeight:    { iFrame.setMarginHeight(str); return; }
03031       case IFrameMarginWidth:     { iFrame.setMarginWidth(str); return; }
03032       case IFrameName:            { iFrame.setName(str); return; }
03033       case IFrameScrolling:       { iFrame.setScrolling(str); return; }
03034       case IFrameSrc:             { iFrame.setSrc(str); return; }
03035       case IFrameWidth:           { iFrame.setWidth(str); return; }
03036       }
03037       break;
03038     }
03039   }
03040 
03041   // generic properties
03042   switch (token) {
03043   case ElementId:
03044     element.setId(str);
03045     return;
03046   case ElementTitle:
03047     element.setTitle(str);
03048     return;
03049   case ElementLang:
03050     element.setLang(str);
03051     return;
03052   case ElementDir:
03053     element.setDir(str);
03054     return;
03055   case ElementClassName:
03056     element.setClassName(str);
03057     return;
03058   case ElementInnerHTML:
03059     element.setInnerHTML(str);
03060     return;
03061   case ElementInnerText:
03062     element.setInnerText(str);
03063     return;
03064   default:
03065     kdDebug(6070) << "WARNING: KJS::HTMLElement::putValueProperty unhandled token " << token << " thisTag=" << element.tagName().string() << " str=" << str.string() << endl;
03066   }
03067 }
03068 
03069 // -------------------------------------------------------------------------
03070 /* Source for HTMLCollectionProtoTable.
03071 @begin HTMLCollectionProtoTable 3
03072   item      HTMLCollection::Item        DontDelete|Function 1
03073   namedItem HTMLCollection::NamedItem   DontDelete|Function 1
03074   tags      HTMLCollection::Tags        DontDelete|Function 1
03075 @end
03076 */
03077 DEFINE_PROTOTYPE("HTMLCollection", HTMLCollectionProto)
03078 IMPLEMENT_PROTOFUNC_DOM(HTMLCollectionProtoFunc)
03079 IMPLEMENT_PROTOTYPE(HTMLCollectionProto,HTMLCollectionProtoFunc)
03080 
03081 const ClassInfo KJS::HTMLCollection::info = { "HTMLCollection", 0, 0, 0 };
03082 
03083 KJS::HTMLCollection::HTMLCollection(ExecState *exec, const DOM::HTMLCollection& c)
03084   : DOMObject(HTMLCollectionProto::self(exec)), collection(c), hidden(false) {}
03085 
03086 KJS::HTMLCollection::~HTMLCollection()
03087 {
03088   ScriptInterpreter::forgetDOMObject(collection.handle());
03089 }
03090 
03091 bool KJS::HTMLCollection::toBoolean(ExecState *) const {
03092     return !hidden;
03093 }
03094 
03095 // We have to implement hasProperty since we don't use a hashtable for 'selectedIndex' and 'length'
03096 // ## this breaks "for (..in..)" though.
03097 bool KJS::HTMLCollection::hasProperty(ExecState *exec, const Identifier &p) const
03098 {
03099   if (p == lengthPropertyName)
03100     return true;
03101   if ( collection.handle()->getType() == HTMLCollectionImpl::SELECT_OPTIONS &&
03102        ( p == "selectedIndex" || p == "value" ) )
03103     return true;
03104   return DOMObject::hasProperty(exec, p);
03105 }
03106 
03107 Value KJS::HTMLCollection::tryGet(ExecState *exec, const Identifier &propertyName) const
03108 {
03109 #ifdef KJS_VERBOSE
03110   kdDebug(6070) << "KJS::HTMLCollection::tryGet " << propertyName.ascii() << endl;
03111 #endif
03112   if (propertyName == lengthPropertyName)
03113   {
03114 #ifdef KJS_VERBOSE
03115     kdDebug(6070) << "  collection length is " << collection.length() << endl;
03116 #endif
03117     return Number(collection.length());
03118   }
03119 
03120   if (collection.handle()->getType() == HTMLCollectionImpl::SELECT_OPTIONS) {
03121     DOM::HTMLSelectElement parentSelect = collection.base();
03122     if ( parentSelect.isNull() )
03123       return Undefined();
03124     if (propertyName == "selectedIndex") {
03125       // NON-STANDARD options.selectedIndex
03126       return Number(parentSelect.selectedIndex());
03127     } else if ( propertyName == "value" ) {
03128       // NON-STANDARD options.value
03129       return String(parentSelect.value());
03130     }
03131   }
03132 
03133   // Look in the prototype (for functions) before assuming it's an item's name
03134   Object proto = Object::dynamicCast(prototype());
03135   if (proto.isValid() && proto.hasProperty(exec,propertyName))
03136     return proto.get(exec,propertyName);
03137 
03138   // name or index ?
03139   bool ok;
03140   unsigned int u = propertyName.toULong(&ok);
03141   if (ok) {
03142     if ( u < collection.length() ) {
03143       DOM::Node node = collection.item(u);
03144       return getDOMNode(exec,node);
03145     } else
03146       return Undefined();
03147   }
03148   else
03149     return getNamedItems(exec,propertyName);
03150 }
03151 
03152 // HTMLCollections are strange objects, they support both get and call,
03153 // so that document.forms.item(0) and document.forms(0) both work.
03154 Value KJS::HTMLCollection::call(ExecState *exec, Object &thisObj, const List &args)
03155 {
03156   // This code duplication is necessary, HTMLCollection isn't a DOMFunction
03157   Value val;
03158   try {
03159     val = tryCall(exec, thisObj, args);
03160   }
03161   // pity there's no way to distinguish between these in JS code
03162   catch (...) {
03163     Object err = Error::create(exec, GeneralError, "Exception from HTMLCollection");
03164     exec->setException(err);
03165   }
03166   return val;
03167 }
03168 
03169 Value KJS::HTMLCollection::tryCall(ExecState *exec, Object &, const List &args)
03170 {
03171   // Do not use thisObj here. It can be the HTMLDocument, in the document.forms(i) case.
03172   /*if( thisObj.imp() != this )
03173   {
03174     kdDebug(6070) << "WARNING: thisObj.imp() != this in HTMLCollection::tryCall" << endl;
03175     KJS::printInfo(exec,"KJS::HTMLCollection::tryCall thisObj",thisObj,-1);
03176     KJS::printInfo(exec,"KJS::HTMLCollection::tryCall this",Value(this),-1);
03177   }*/
03178   // Also, do we need the TypeError test here ?
03179 
03180   if (args.size() == 1) {
03181     // support for document.all(<index>) etc.
03182     bool ok;
03183     UString s = args[0].toString(exec);
03184     unsigned int u = s.toULong(&ok);
03185     if (ok) {
03186       DOM::Element element = collection.item(u);
03187       return getDOMNode(exec,element);
03188     }
03189     // support for document.images('<name>') etc.
03190     return getNamedItems(exec,Identifier(s));
03191   }
03192   else if (args.size() >= 1) // the second arg, if set, is the index of the item we want
03193   {
03194     bool ok;
03195     UString s = args[0].toString(exec);
03196     unsigned int u = args[1].toString(exec).toULong(&ok);
03197     if (ok)
03198     {
03199       DOM::DOMString pstr = s.string();
03200       DOM::Node node = collection.namedItem(pstr);
03201       while (!node.isNull()) {
03202         if (!u)
03203           return getDOMNode(exec,node);
03204         node = collection.nextNamedItem(pstr);
03205         --u;
03206       }
03207     }
03208   }
03209   return Undefined();
03210 }
03211 
03212 Value KJS::HTMLCollection::getNamedItems(ExecState *exec, const Identifier &propertyName) const
03213 {
03214 #ifdef KJS_VERBOSE
03215   kdDebug(6070) << "KJS::HTMLCollection::getNamedItems " << propertyName.ascii() << endl;
03216 #endif
03217 
03218   DOM::DOMString pstr = propertyName.string();
03219 
03220   QValueList<DOM::NodeImpl*> matches = collection.handle()->namedItems(pstr);
03221 
03222   if (!matches.isEmpty()) {
03223     if (matches.size() == 1) {
03224       DOM::Node node(matches[0]);
03225 #ifdef KJS_VERBOSE
03226       kdDebug(6070) << "returning single node" << endl;
03227 #endif
03228       return getDOMNode(exec,node);
03229     }
03230     else  {
03231       // multiple items, return a collection
03232       QValueList<DOM::Node> nodes;
03233       for (QValueList<DOM::NodeImpl*>::const_iterator i =  matches.begin();
03234                                                       i != matches.end(); ++i)
03235            nodes.append(DOM::Node(*i));
03236 #ifdef KJS_VERBOSE
03237       kdDebug(6070) << "returning list of " << nodes.count() << " nodes" << endl;
03238 #endif
03239       return Value(new DOMNamedNodesCollection(exec, nodes));
03240     }
03241   }
03242 #ifdef KJS_VERBOSE
03243   kdDebug(6070) << "not found" << endl;
03244 #endif
03245   return Undefined();
03246 }
03247 
03248 Value KJS::HTMLCollectionProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
03249 {
03250   KJS_CHECK_THIS( KJS::HTMLCollection, thisObj );
03251   DOM::HTMLCollection coll = static_cast<KJS::HTMLCollection *>(thisObj.imp())->toCollection();
03252 
03253   switch (id) {
03254   case KJS::HTMLCollection::Item:
03255   {
03256     // support for item(<index>) (DOM)
03257     bool ok;
03258     UString s = args[0].toString(exec);
03259     unsigned int u = s.toULong(&ok);
03260     if (ok) {
03261       return getDOMNode(exec,coll.item(u));
03262     }
03263     // support for item('<name>') (IE only)
03264     kdWarning() << "non-standard HTMLCollection.item('" << s.ascii() << "') called, use namedItem instead" << endl;
03265     return getDOMNode(exec,coll.namedItem(s.string()));
03266   }
03267   case KJS::HTMLCollection::Tags:
03268   {
03269     DOM::DOMString tagName = args[0].toString(exec).string();
03270     DOM::NodeList list;
03271     // getElementsByTagName exists in Document and in Element, pick up the right one
03272     if ( coll.base().nodeType() == DOM::Node::DOCUMENT_NODE )
03273     {
03274       DOM::Document doc = coll.base();
03275       list = doc.getElementsByTagName(tagName);
03276 #ifdef KJS_VERBOSE
03277       kdDebug(6070) << "KJS::HTMLCollectionProtoFunc::tryCall document.tags(" << tagName.string() << ") -> " << list.length() << " items in node list" << endl;
03278 #endif
03279     } else
03280     {
03281       DOM::Element e = coll.base();
03282       list = e.getElementsByTagName(tagName);
03283 #ifdef KJS_VERBOSE
03284       kdDebug(6070) << "KJS::HTMLCollectionProtoFunc::tryCall element.tags(" << tagName.string() << ") -> " << list.length() << " items in node list" << endl;
03285 #endif
03286     }
03287     return getDOMNodeList(exec, list);
03288   }
03289   case KJS::HTMLCollection::NamedItem:
03290   {
03291     Value val = static_cast<HTMLCollection *>(thisObj.imp())->getNamedItems(exec, Identifier(args[0].toString(exec)));
03292     // Must return null when asking for a named item that isn't in the collection
03293     // (DOM2 testsuite, HTMLCollection12 test)
03294     if ( val.type() == KJS::UndefinedType )
03295       return Null();
03296     else
03297       return val;
03298   }
03299   default:
03300     return Undefined();
03301   }
03302 }
03303 
03304 Value KJS::HTMLSelectCollection::tryGet(ExecState *exec, const Identifier &p) const
03305 {
03306   if (p == "selectedIndex")
03307     return Number(element.selectedIndex());
03308 
03309   return  HTMLCollection::tryGet(exec, p);
03310 }
03311 
03312 void KJS::HTMLSelectCollection::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int)
03313 {
03314 #ifdef KJS_VERBOSE
03315   kdDebug(6070) << "KJS::HTMLSelectCollection::tryPut " << propertyName.qstring() << endl;
03316 #endif
03317   if ( propertyName == "selectedIndex" ) {
03318     element.setSelectedIndex( value.toInteger( exec ) );
03319     return;
03320   }
03321   // resize ?
03322   else if (propertyName == lengthPropertyName) {
03323     unsigned newLen;
03324     bool converted = value.toUInt32(newLen);
03325 
03326     if (!converted) {
03327       return;
03328     }
03329 
03330     long diff = element.length() - newLen;
03331 
03332     if (diff < 0) { // add dummy elements
03333       do {
03334         element.add(element.ownerDocument().createElement("OPTION"), DOM::HTMLElement());
03335       } while (++diff);
03336     }
03337     else // remove elements
03338       while (diff-- > 0)
03339         element.remove(newLen + diff);
03340 
03341     return;
03342   }
03343   // an index ?
03344   bool ok;
03345   unsigned int u = propertyName.toULong(&ok);
03346   if (!ok)
03347     return;
03348 
03349   if (value.isA(NullType) || value.isA(UndefinedType)) {
03350     // null and undefined delete. others, too ?
03351     element.remove(u);
03352     return;
03353   }
03354 
03355   // is v an option element ?
03356   DOM::Node node = KJS::toNode(value);
03357   if (node.isNull() || node.elementId() != ID_OPTION)
03358     return;
03359 
03360   DOM::HTMLOptionElement option = static_cast<DOM::HTMLOptionElement>(node);
03361   if ( option.ownerDocument() != element.ownerDocument() )
03362     option = static_cast<DOM::HTMLOptionElement>(element.ownerDocument().importNode(option, true));
03363   long diff = long(u) - element.length();
03364   DOM::HTMLElement before;
03365   // out of array bounds ? first insert empty dummies
03366   if (diff > 0) {
03367     while (diff--) {
03368       element.add(element.ownerDocument().createElement("OPTION"), before);
03369     }
03370     // replace an existing entry ?
03371   } else if (diff < 0) {
03372     before = element.options().item(u+1);
03373     element.remove(u);
03374   }
03375   // finally add the new element
03376   element.add(option, before);
03377 }
03378 
03380 
03381 OptionConstructorImp::OptionConstructorImp(ExecState *exec, const DOM::Document &d)
03382     : ObjectImp(), doc(d)
03383 {
03384   // ## isn't there some redundancy between ObjectImp::_proto and the "prototype" property ?
03385   //put(exec,"prototype", ...,DontEnum|DontDelete|ReadOnly);
03386 
03387   // no. of arguments for constructor
03388   // ## is 4 correct ? 0 to 4, it seems to be
03389   put(exec,lengthPropertyName, Number(4), ReadOnly|DontDelete|DontEnum);
03390 }
03391 
03392 bool OptionConstructorImp::implementsConstruct() const
03393 {
03394   return true;
03395 }
03396 
03397 Object OptionConstructorImp::construct(ExecState *exec, const List &args)
03398 {
03399   DOM::Element el = doc.createElement("OPTION");
03400   DOM::HTMLOptionElement opt = static_cast<DOM::HTMLOptionElement>(el);
03401   int sz = args.size();
03402   DOM::Text t = doc.createTextNode("");
03403   try { opt.appendChild(t); }
03404   catch(DOM::DOMException& e) {
03405     // #### exec->setException ?
03406   }
03407   if (sz > 0)
03408     t.setData(args[0].toString(exec).string()); // set the text
03409   if (sz > 1)
03410     opt.setValue(args[1].toString(exec).string());
03411   if (sz > 2)
03412     opt.setDefaultSelected(args[2].toBoolean(exec));
03413   if (sz > 3)
03414     opt.setSelected(args[3].toBoolean(exec));
03415 
03416   return Object::dynamicCast(getDOMNode(exec,opt));
03417 }
03418 
03420 
03421 //Like in other browsers, we merely make a new HTMLImageElement
03422 //not in tree for this.
03423 ImageConstructorImp::ImageConstructorImp(ExecState *, const DOM::Document &d)
03424     : ObjectImp(), doc(d)
03425 {
03426 }
03427 
03428 bool ImageConstructorImp::implementsConstruct() const
03429 {
03430   return true;
03431 }
03432 
03433 Object ImageConstructorImp::construct(ExecState *exec, const List &list)
03434 {
03435   bool widthSet = false, heightSet = false;
03436   int width = 0, height = 0;
03437   if (list.size() > 0) {
03438     widthSet = true;
03439     Value w = list.at(0);
03440     width = w.toInt32(exec);
03441   }
03442   if (list.size() > 1) {
03443     heightSet = true;
03444     Value h = list.at(1);
03445     height = h.toInt32(exec);
03446   }
03447 
03448   HTMLImageElement image(doc.createElement("image"));
03449 
03450   if (widthSet)
03451     image.setWidth(width);
03452 
03453   if (heightSet)
03454     image.setHeight(height);
03455 
03456   return Object::dynamicCast(getDOMNode(exec,image));
03457 }
03458 
03459 Value KJS::getHTMLCollection(ExecState *exec, const DOM::HTMLCollection& c, bool hide)
03460 {
03461   Value coll = cacheDOMObject<DOM::HTMLCollection, KJS::HTMLCollection>(exec, c);
03462   if (hide) {
03463     KJS::HTMLCollection *impl = static_cast<KJS::HTMLCollection*>(coll.imp());
03464     impl->hide();
03465   }
03466   return coll;
03467 }
03468 
03469 Value KJS::getSelectHTMLCollection(ExecState *exec, const DOM::HTMLCollection& c, const DOM::HTMLSelectElement& e)
03470 {
03471   DOMObject *ret;
03472   if (c.isNull())
03473     return Null();
03474   ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
03475   if ((ret = interp->getDOMObject(c.handle())))
03476     return Value(ret);
03477   else {
03478     ret = new HTMLSelectCollection(exec, c, e);
03479     interp->putDOMObject(c.handle(),ret);
03480     return Value(ret);
03481   }
03482 }
KDE Home | KDE Accessibility Home | Description of Access Keys