📄 kjs_dom.cpp
字号:
return getDOMNode(exec, list.item(args[0].toInt32(exec))); case KJS::DOMNodeList::NamedItem: { // Not a real namedItem implementation like the one HTMLCollection has. // This is only an IE extension... DOM::HTMLElement e; unsigned long len = list.length(); DOM::DOMString s = args[0].toString(exec).string(); for ( unsigned long i = 0; i < len; i++ ) { e = list.item( i ); if ( !e.isNull() && ( e.id() == s || static_cast<ElementImpl *>(e.handle())->getAttribute(ATTR_NAME) == s ) ) { return getDOMNode(exec, e ); } } return Null(); // see HTMLCollection::NamedItem implementation } default: return Undefined(); }}// -------------------------------------------------------------------------const ClassInfo DOMAttr::info = { "Attr", &DOMNode::info, &DOMAttrTable, 0 };/* Source for DOMAttrTable.@begin DOMAttrTable 5 name DOMAttr::Name DontDelete|ReadOnly specified DOMAttr::Specified DontDelete|ReadOnly value DOMAttr::ValueProperty DontDelete ownerElement DOMAttr::OwnerElement DontDelete|ReadOnly@end*/Value DOMAttr::tryGet(ExecState *exec, const Identifier &propertyName) const{#ifdef KJS_VERBOSE kdDebug(6070) << "DOMAttr::tryGet " << propertyName.qstring() << endl;#endif return DOMObjectLookupGetValue<DOMAttr,DOMNode>(exec, propertyName, &DOMAttrTable, this );}Value DOMAttr::getValueProperty(ExecState *exec, int token) const{ switch (token) { case Name: return String(static_cast<DOM::Attr>(node).name()); case Specified: return Boolean(static_cast<DOM::Attr>(node).specified()); case ValueProperty: return String(static_cast<DOM::Attr>(node).value()); case OwnerElement: // DOM2 return getDOMNode(exec,static_cast<DOM::Attr>(node).ownerElement()); } return Value(); // not reached}void DOMAttr::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr){#ifdef KJS_VERBOSE kdDebug(6070) << "DOMAttr::tryPut " << propertyName.qstring() << endl;#endif DOMObjectLookupPut<DOMAttr,DOMNode>(exec, propertyName, value, attr, &DOMAttrTable, this );}void DOMAttr::putValueProperty(ExecState *exec, int token, const Value& value, int /*attr*/){ switch (token) { case ValueProperty: static_cast<DOM::Attr>(node).setValue(value.toString(exec).string()); return; default: kdDebug(6070) << "WARNING: DOMAttr::putValueProperty unhandled token " << token << endl; }}// -------------------------------------------------------------------------/* Source for DOMDocumentProtoTable.@begin DOMDocumentProtoTable 23 createElement DOMDocument::CreateElement DontDelete|Function 1 createDocumentFragment DOMDocument::CreateDocumentFragment DontDelete|Function 1 createTextNode DOMDocument::CreateTextNode DontDelete|Function 1 createComment DOMDocument::CreateComment DontDelete|Function 1 createCDATASection DOMDocument::CreateCDATASection DontDelete|Function 1 createProcessingInstruction DOMDocument::CreateProcessingInstruction DontDelete|Function 1 createAttribute DOMDocument::CreateAttribute DontDelete|Function 1 createEntityReference DOMDocument::CreateEntityReference DontDelete|Function 1 getElementsByTagName DOMDocument::GetElementsByTagName DontDelete|Function 1 importNode DOMDocument::ImportNode DontDelete|Function 2 createElementNS DOMDocument::CreateElementNS DontDelete|Function 2 createAttributeNS DOMDocument::CreateAttributeNS DontDelete|Function 2 getElementsByTagNameNS DOMDocument::GetElementsByTagNameNS DontDelete|Function 2 getElementById DOMDocument::GetElementById DontDelete|Function 1 createRange DOMDocument::CreateRange DontDelete|Function 0 createNodeIterator DOMDocument::CreateNodeIterator DontDelete|Function 3 createTreeWalker DOMDocument::CreateTreeWalker DontDelete|Function 4 createEvent DOMDocument::CreateEvent DontDelete|Function 1 getOverrideStyle DOMDocument::GetOverrideStyle DontDelete|Function 2 abort DOMDocument::Abort DontDelete|Function 0 load DOMDocument::Load DontDelete|Function 1 loadXML DOMDocument::LoadXML DontDelete|Function 2@end*/DEFINE_PROTOTYPE("DOMDocument", DOMDocumentProto)IMPLEMENT_PROTOFUNC_DOM(DOMDocumentProtoFunc)IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMDocumentProto, DOMDocumentProtoFunc, DOMNodeProto)const ClassInfo DOMDocument::info = { "Document", &DOMNode::info, &DOMDocumentTable, 0 };/* Source for DOMDocumentTable.@begin DOMDocumentTable 4 doctype DOMDocument::DocType DontDelete|ReadOnly implementation DOMDocument::Implementation DontDelete|ReadOnly documentElement DOMDocument::DocumentElement DontDelete|ReadOnly styleSheets DOMDocument::StyleSheets DontDelete|ReadOnly preferredStylesheetSet DOMDocument::PreferredStylesheetSet DontDelete|ReadOnly selectedStylesheetSet DOMDocument::SelectedStylesheetSet DontDelete readyState DOMDocument::ReadyState DontDelete|ReadOnly defaultView DOMDocument::DefaultView DontDelete|ReadOnly async DOMDocument::Async DontDelete@end*/DOMDocument::DOMDocument(ExecState *exec, const DOM::Document& d) : DOMNode(DOMDocumentProto::self(exec), d) { }DOMDocument::DOMDocument(const Object& proto, const DOM::Document& d) : DOMNode(proto, d) { }DOMDocument::~DOMDocument(){ ScriptInterpreter::forgetDOMObject(node.handle());}Value DOMDocument::tryGet(ExecState *exec, const Identifier &propertyName) const{#ifdef KJS_VERBOSE kdDebug(6070) << "DOMDocument::tryGet " << propertyName.qstring() << endl;#endif return DOMObjectLookupGetValue<DOMDocument, DOMNode>( exec, propertyName, &DOMDocumentTable, this);}Value DOMDocument::getValueProperty(ExecState *exec, int token) const{ DOM::Document doc = static_cast<DOM::Document>(node); switch(token) { case DocType: return getDOMNode(exec,doc.doctype()); case Implementation: return getDOMDOMImplementation(exec,doc.implementation()); case DocumentElement: return getDOMNode(exec,doc.documentElement()); case StyleSheets: //kdDebug() << "DOMDocument::StyleSheets, returning " << doc.styleSheets().length() << " stylesheets" << endl; return getDOMStyleSheetList(exec, doc.styleSheets(), doc); case DOMDocument::DefaultView: // DOM2 { KHTMLView *view = node.handle()->getDocument()->view(); if (view) return Window::retrieve(view->part()); return getDOMAbstractView(exec, doc.defaultView()); } case PreferredStylesheetSet: return String(doc.preferredStylesheetSet()); case SelectedStylesheetSet: return String(doc.selectedStylesheetSet()); case ReadyState: { DOM::DocumentImpl* docimpl = node.handle()->getDocument(); if ( docimpl && docimpl->view() ) { KHTMLPart* part = docimpl->view()->part(); if ( part ) { if (part->d->m_bComplete) return String("complete"); if (docimpl->parsing()) return String("loading"); return String("loaded"); // What does the interactive value mean ? // Missing support for "uninitialized" } } return Undefined(); } case Async: return Boolean(doc.async()); default: kdDebug(6070) << "WARNING: DOMDocument::getValueProperty unhandled token " << token << endl; return Value(); }}void DOMDocument::tryPut(ExecState *exec, const Identifier& propertyName, const Value& value, int attr){#ifdef KJS_VERBOSE kdDebug(6070) << "DOMDocument::tryPut " << propertyName.qstring() << endl;#endif DOMObjectLookupPut<DOMDocument,DOMNode>(exec, propertyName, value, attr, &DOMDocumentTable, this );}void DOMDocument::putValueProperty(ExecState *exec, int token, const Value& value, int /*attr*/){ DOM::Document doc = static_cast<DOM::Document>(node); switch (token) { case SelectedStylesheetSet: { doc.setSelectedStylesheetSet(value.toString(exec).string()); break; } case Async: { doc.setAsync(value.toBoolean(exec)); break; } }}Value DOMDocumentProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){ KJS_CHECK_THIS( KJS::DOMDocument, thisObj ); DOM::Node node = static_cast<DOMNode *>( thisObj.imp() )->toNode(); DOM::Document doc = static_cast<DOM::Document>(node); String str = args[0].toString(exec); DOM::DOMString s = str.value().string(); switch(id) { case DOMDocument::CreateElement: return getDOMNode(exec,doc.createElement(s)); case DOMDocument::CreateDocumentFragment: return getDOMNode(exec,doc.createDocumentFragment()); case DOMDocument::CreateTextNode: return getDOMNode(exec,doc.createTextNode(s)); case DOMDocument::CreateComment: return getDOMNode(exec,doc.createComment(s)); case DOMDocument::CreateCDATASection: return getDOMNode(exec,doc.createCDATASection(s)); /* TODO: okay ? */ case DOMDocument::CreateProcessingInstruction: return getDOMNode(exec,doc.createProcessingInstruction(args[0].toString(exec).string(), args[1].toString(exec).string())); case DOMDocument::CreateAttribute: return getDOMNode(exec,doc.createAttribute(s)); case DOMDocument::CreateEntityReference: return getDOMNode(exec,doc.createEntityReference(args[0].toString(exec).string())); case DOMDocument::GetElementsByTagName: return getDOMNodeList(exec,doc.getElementsByTagName(s)); case DOMDocument::ImportNode: // DOM2 return getDOMNode(exec,doc.importNode(toNode(args[0]), args[1].toBoolean(exec))); case DOMDocument::CreateElementNS: // DOM2 return getDOMNode(exec,doc.createElementNS(args[0].toString(exec).string(), args[1].toString(exec).string())); case DOMDocument::CreateAttributeNS: // DOM2 return getDOMNode(exec,doc.createAttributeNS(args[0].toString(exec).string(),args[1].toString(exec).string())); case DOMDocument::GetElementsByTagNameNS: // DOM2 return getDOMNodeList(exec,doc.getElementsByTagNameNS(args[0].toString(exec).string(), args[1].toString(exec).string())); case DOMDocument::GetElementById:#ifdef KJS_VERBOSE kdDebug(6070) << "DOMDocument::GetElementById looking for " << args[0].toString(exec).string() << endl;#endif return getDOMNode(exec,doc.getElementById(args[0].toString(exec).string())); case DOMDocument::CreateRange: return getDOMRange(exec,doc.createRange()); case DOMDocument::CreateNodeIterator: if (args[2].isA(NullType)) { DOM::NodeFilter filter; return getDOMNodeIterator(exec, doc.createNodeIterator(toNode(args[0]), (long unsigned int)(args[1].toNumber(exec)), filter,args[3].toBoolean(exec))); } else { Object obj = Object::dynamicCast(args[2]); if (obj.isValid()) { DOM::CustomNodeFilter *customFilter = new JSNodeFilter(obj); DOM::NodeFilter filter = DOM::NodeFilter::createCustom(customFilter); return getDOMNodeIterator(exec, doc.createNodeIterator( toNode(args[0]),(long unsigned int)(args[1].toNumber(exec)), filter,args[3].toBoolean(exec))); }// else? } case DOMDocument::CreateTreeWalker: return getDOMTreeWalker(exec,doc.createTreeWalker(toNode(args[0]),(long unsigned int)(args[1].toNumber(exec)), toNodeFilter(args[2]),args[3].toBoolean(exec))); case DOMDocument::CreateEvent: return getDOMEvent(exec,doc.createEvent(s)); case DOMDocument::GetOverrideStyle: { DOM::Node arg0 = toNode(args[0]); if (arg0.nodeType() != DOM::Node::ELEMENT_NODE) return Undefined(); // throw exception? else return getDOMCSSStyleDeclaration(exec,doc.getOverrideStyle(static_cast<DOM::Element>(arg0),args[1].toString(exec).string())); } case DOMDocument::Abort: doc.abort(); break; case DOMDocument::Load: { Window* active = Window::retrieveActive(exec); // Complete the URL using the "active part" (running interpreter). We do this for the security // check and to make sure we load exactly the same url as we have verified to be safe KHTMLPart *khtmlpart = ::qt_cast<KHTMLPart *>(active->part()); if (khtmlpart) { // Security: only allow documents to be loaded from the same host QString dstUrl = khtmlpart->htmlDocument().completeURL(s).string(); KParts::ReadOnlyPart *part = static_cast<KJS::ScriptInterpreter*>(exec->interpreter())->part(); if (part->url().host() == KURL(dstUrl).host()) { kdDebug(6070) << "JavaScript: access granted for document.load() of " << dstUrl << endl; doc.load(dstUrl); } else { kdDebug(6070) << "JavaScript: access denied for document.load() of " << dstUrl << endl; } } break; } case DOMDocument::LoadXML: doc.loadXML(s); break; default: break; } return Undefined();}// -------------------------------------------------------------------------/* Source for DOMElementProtoTable.@begin DOMElementProtoTable 17 getAttribute DOMElement::GetAttribute DontDelete|Function 1 setAttribute DOMElement::SetAttribute DontDelete|Function 2 removeAttribute DOMElement::RemoveAttribute DontDelete|Function 1 getAttributeNode DOMElement::GetAttributeNode DontDelete|Function 1 setAttributeNode DOMElement::SetAttributeNode DontDelete|Function 2 removeAttributeNode DOMElement::RemoveAttributeNode DontDelete|Function 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -