khtml Library API Documentation

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