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