⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kjs_dom.cpp

📁 konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版本源码包.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  getElementsByTagName	DOMElement::GetElementsByTagName	DontDelete|Function 1  hasAttribute		DOMElement::HasAttribute	DontDelete|Function 1  getAttributeNS	DOMElement::GetAttributeNS	DontDelete|Function 2  setAttributeNS	DOMElement::SetAttributeNS	DontDelete|Function 3  removeAttributeNS	DOMElement::RemoveAttributeNS	DontDelete|Function 2  getAttributeNodeNS	DOMElement::GetAttributeNodeNS	DontDelete|Function 2  setAttributeNodeNS	DOMElement::SetAttributeNodeNS	DontDelete|Function 1  getElementsByTagNameNS DOMElement::GetElementsByTagNameNS	DontDelete|Function 2  hasAttributeNS	DOMElement::HasAttributeNS	DontDelete|Function 2@end*/DEFINE_PROTOTYPE("DOMElement",DOMElementProto)IMPLEMENT_PROTOFUNC_DOM(DOMElementProtoFunc)IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMElementProto,DOMElementProtoFunc,DOMNodeProto)const ClassInfo DOMElement::info = { "Element", &DOMNode::info, &DOMElementTable, 0 };/* Source for DOMElementTable.@begin DOMElementTable 3  tagName	DOMElement::TagName                         DontDelete|ReadOnly  style		DOMElement::Style                           DontDelete|ReadOnly@end*/DOMElement::DOMElement(ExecState *exec, const DOM::Element& e)  : DOMNode(DOMElementProto::self(exec), e) { }DOMElement::DOMElement(const Object& proto, const DOM::Element& e)  : DOMNode(proto, e) { }Value DOMElement::tryGet(ExecState *exec, const Identifier &propertyName) const{#ifdef KJS_VERBOSE  kdDebug(6070) << "DOMElement::tryGet " << propertyName.qstring() << endl;#endif  DOM::Element element = static_cast<DOM::Element>(node);  const HashEntry* entry = Lookup::findEntry(&DOMElementTable, propertyName);  if (entry)  {    switch( entry->value ) {    case TagName:      return String(element.tagName());    case Style:      return getDOMCSSStyleDeclaration(exec,element.style());    default:      kdDebug(6070) << "WARNING: Unhandled token in DOMElement::tryGet : " << entry->value << endl;      break;    }  }  // We have to check in DOMNode before giving access to attributes, otherwise  // onload="..." would make onload return the string (attribute value) instead of  // the listener object (function).  if (DOMNode::hasProperty(exec, propertyName))    return DOMNode::tryGet(exec, propertyName);  DOM::DOMString attr = element.getAttribute( propertyName.string() );  // Give access to attributes  if ( !attr.isNull() )    return String( attr );  return Undefined();}Value DOMElementProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){  KJS_CHECK_THIS( KJS::DOMNode, thisObj ); // node should be enough here, given the cast  DOM::Node node = static_cast<DOMNode *>( thisObj.imp() )->toNode();  DOM::Element element = static_cast<DOM::Element>(node);  switch(id) {    case DOMElement::GetAttribute:      /** In theory, we should not return null here, as per DOM. In practice, that        breaks websites      */      return getString(element.getAttribute(args[0].toString(exec).string()));    case DOMElement::SetAttribute:      element.setAttribute(args[0].toString(exec).string(),args[1].toString(exec).string());      return Undefined();    case DOMElement::RemoveAttribute:      element.removeAttribute(args[0].toString(exec).string());      return Undefined();    case DOMElement::GetAttributeNode:      return getDOMNode(exec,element.getAttributeNode(args[0].toString(exec).string()));    case DOMElement::SetAttributeNode:      return getDOMNode(exec,element.setAttributeNode((new DOMNode(exec,KJS::toNode(args[0])))->toNode()));    case DOMElement::RemoveAttributeNode:      return getDOMNode(exec,element.removeAttributeNode((new DOMNode(exec,KJS::toNode(args[0])))->toNode()));    case DOMElement::GetElementsByTagName:      return getDOMNodeList(exec,element.getElementsByTagName(args[0].toString(exec).string()));    case DOMElement::HasAttribute: // DOM2      return Boolean(element.hasAttribute(args[0].toString(exec).string()));    case DOMElement::GetAttributeNS: // DOM2      return String(element.getAttributeNS(args[0].toString(exec).string(),args[1].toString(exec).string()));    case DOMElement::SetAttributeNS: // DOM2      element.setAttributeNS(args[0].toString(exec).string(),args[1].toString(exec).string(),args[2].toString(exec).string());      return Undefined();    case DOMElement::RemoveAttributeNS: // DOM2      element.removeAttributeNS(args[0].toString(exec).string(),args[1].toString(exec).string());      return Undefined();    case DOMElement::GetAttributeNodeNS: // DOM2      return getDOMNode(exec,element.getAttributeNodeNS(args[0].toString(exec).string(),args[1].toString(exec).string()));    case DOMElement::SetAttributeNodeNS: // DOM2      return getDOMNode(exec,element.setAttributeNodeNS((new DOMNode(exec,KJS::toNode(args[0])))->toNode()));    case DOMElement::GetElementsByTagNameNS: // DOM2      return getDOMNodeList(exec,element.getElementsByTagNameNS(args[0].toString(exec).string(),args[1].toString(exec).string()));    case DOMElement::HasAttributeNS: // DOM2      return Boolean(element.hasAttributeNS(args[0].toString(exec).string(),args[1].toString(exec).string()));  default:    return Undefined();  }}// -------------------------------------------------------------------------/* Source for DOMDOMImplementationProtoTable.@begin DOMDOMImplementationProtoTable 5  hasFeature		DOMDOMImplementation::HasFeature		DontDelete|Function 2  createCSSStyleSheet	DOMDOMImplementation::CreateCSSStyleSheet	DontDelete|Function 2# DOM2  createDocumentType	DOMDOMImplementation::CreateDocumentType	DontDelete|Function 3  createDocument	DOMDOMImplementation::CreateDocument		DontDelete|Function 3  createHTMLDocument    DOMDOMImplementation::CreateHTMLDocument        DontDelete|Function 1@end*/DEFINE_PROTOTYPE("DOMImplementation",DOMDOMImplementationProto)IMPLEMENT_PROTOFUNC_DOM(DOMDOMImplementationProtoFunc)IMPLEMENT_PROTOTYPE(DOMDOMImplementationProto,DOMDOMImplementationProtoFunc)const ClassInfo DOMDOMImplementation::info = { "DOMImplementation", 0, 0, 0 };DOMDOMImplementation::DOMDOMImplementation(ExecState *exec, const DOM::DOMImplementation& i)  : DOMObject(DOMDOMImplementationProto::self(exec)), implementation(i) { }DOMDOMImplementation::~DOMDOMImplementation(){  ScriptInterpreter::forgetDOMObject(implementation.handle());}Value DOMDOMImplementationProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){  KJS_CHECK_THIS( KJS::DOMDOMImplementation, thisObj );  DOM::DOMImplementation implementation = static_cast<DOMDOMImplementation *>( thisObj.imp() )->toImplementation();  switch(id) {  case DOMDOMImplementation::HasFeature:    return Boolean(implementation.hasFeature(args[0].toString(exec).string(),args[1].toString(exec).string()));  case DOMDOMImplementation::CreateDocumentType: // DOM2    return getDOMNode(exec,implementation.createDocumentType(args[0].toString(exec).string(),args[1].toString(exec).string(),args[2].toString(exec).string()));  case DOMDOMImplementation::CreateDocument: { // DOM2    // Initially set the URL to document of the creator... this is so that it resides in the same    // host/domain for security checks. The URL will be updated if Document.load() is called.    KHTMLPart *part = ::qt_cast<KHTMLPart*>(static_cast<KJS::ScriptInterpreter*>(exec->interpreter())->part());    if (part) {      Document doc = implementation.createDocument(args[0].toString(exec).string(),args[1].toString(exec).string(),toNode(args[2]));      KURL url = static_cast<DocumentImpl*>(part->document().handle())->URL();      static_cast<DocumentImpl*>(doc.handle())->setURL(url.url());      return getDOMNode(exec,doc);    }    break;  }  case DOMDOMImplementation::CreateCSSStyleSheet: // DOM2    return getDOMStyleSheet(exec,implementation.createCSSStyleSheet(args[0].toString(exec).string(),args[1].toString(exec).string()));  case DOMDOMImplementation::CreateHTMLDocument: // DOM2-HTML    return getDOMNode(exec, implementation.createHTMLDocument(args[0].toString(exec).string()));  default:    break;  }  return Undefined();}// -------------------------------------------------------------------------const ClassInfo DOMDocumentType::info = { "DocumentType", &DOMNode::info, &DOMDocumentTypeTable, 0 };/* Source for DOMDocumentTypeTable.@begin DOMDocumentTypeTable 6  name			DOMDocumentType::Name		DontDelete|ReadOnly  entities		DOMDocumentType::Entities	DontDelete|ReadOnly  notations		DOMDocumentType::Notations	DontDelete|ReadOnly# DOM2  publicId		DOMDocumentType::PublicId	DontDelete|ReadOnly  systemId		DOMDocumentType::SystemId	DontDelete|ReadOnly  internalSubset	DOMDocumentType::InternalSubset	DontDelete|ReadOnly@end*/DOMDocumentType::DOMDocumentType(ExecState *exec, const DOM::DocumentType& dt)  : DOMNode( /*### no proto yet*/exec, dt ) { }Value DOMDocumentType::tryGet(ExecState *exec, const Identifier &propertyName) const{#ifdef KJS_VERBOSE  kdDebug(6070) << "DOMDocumentType::tryGet " << propertyName.qstring() << endl;#endif  return DOMObjectLookupGetValue<DOMDocumentType, DOMNode>(exec, propertyName, &DOMDocumentTypeTable, this);}Value DOMDocumentType::getValueProperty(ExecState *exec, int token) const{  DOM::DocumentType type = static_cast<DOM::DocumentType>(node);  switch (token) {  case Name:    return String(type.name());  case Entities:    return getDOMNamedNodeMap(exec,type.entities());  case Notations:    return getDOMNamedNodeMap(exec,type.notations());  case PublicId: // DOM2    return String(type.publicId());  case SystemId: // DOM2    return String(type.systemId());  case InternalSubset: // DOM2    return getString(type.internalSubset()); // can be null, see domts/level2/core/internalSubset01.html  default:    kdDebug(6070) << "WARNING: DOMDocumentType::getValueProperty unhandled token " << token << endl;    return Value();  }}// -------------------------------------------------------------------------/* Source for DOMNamedNodeMapProtoTable.@begin DOMNamedNodeMapProtoTable 7  getNamedItem		DOMNamedNodeMap::GetNamedItem		DontDelete|Function 1  setNamedItem		DOMNamedNodeMap::SetNamedItem		DontDelete|Function 1  removeNamedItem	DOMNamedNodeMap::RemoveNamedItem	DontDelete|Function 1  item			DOMNamedNodeMap::Item			DontDelete|Function 1# DOM2  getNamedItemNS	DOMNamedNodeMap::GetNamedItemNS		DontDelete|Function 2  setNamedItemNS	DOMNamedNodeMap::SetNamedItemNS		DontDelete|Function 1  removeNamedItemNS	DOMNamedNodeMap::RemoveNamedItemNS	DontDelete|Function 2@end@begin DOMNamedNodeMapTable 7  length		DOMNamedNodeMap::Length			DontDelete|Function 1@end*/DEFINE_PROTOTYPE("NamedNodeMap", DOMNamedNodeMapProto)IMPLEMENT_PROTOFUNC_DOM(DOMNamedNodeMapProtoFunc)IMPLEMENT_PROTOTYPE(DOMNamedNodeMapProto,DOMNamedNodeMapProtoFunc)const ClassInfo DOMNamedNodeMap::info = { "NamedNodeMap", 0, &DOMNamedNodeMapTable, 0 };DOMNamedNodeMap::DOMNamedNodeMap(ExecState *exec, const DOM::NamedNodeMap& m)  : DOMObject(DOMNamedNodeMapProto::self(exec)), map(m) { }DOMNamedNodeMap::~DOMNamedNodeMap(){  ScriptInterpreter::forgetDOMObject(map.handle());}bool DOMNamedNodeMap::hasProperty(ExecState *exec, const Identifier &p) const{  // ## missing? array index  return DOMObject::hasProperty(exec, p);}Value DOMNamedNodeMap::tryGet(ExecState* exec, const Identifier &p) const{  if (p == lengthPropertyName)    return Number(map.length());  // array index ?  bool ok;  long unsigned int idx = p.toULong(&ok);  if (ok)    return getDOMNode(exec,map.item(idx));  // Anything else (including functions, defined in the prototype)  return DOMObject::tryGet(exec, p);}Value DOMNamedNodeMapProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){  KJS_CHECK_THIS( KJS::DOMNamedNodeMap, thisObj );  DOM::NamedNodeMap map = static_cast<DOMNamedNodeMap *>(thisObj.imp())->toMap();  switch(id) {    case DOMNamedNodeMap::GetNamedItem:      return getDOMNode(exec, map.getNamedItem(args[0].toString(exec).string()));    case DOMNamedNodeMap::SetNamedItem:      return getDOMNode(exec, map.setNamedItem((new DOMNode(exec,KJS::toNode(args[0])))->toNode()));    case DOMNamedNodeMap::RemoveNamedItem:      return getDOMNode(exec, map.removeNamedItem(args[0].toString(exec).string()));    case DOMNamedNodeMap::Item:      return getDOMNode(exec, map.item(args[0].toInt32(exec)));    case DOMNamedNodeMap::GetNamedItemNS: // DOM2      return getDOMNode(exec, map.getNamedItemNS(args[0].toString(exec).string(),args[1].toString(exec).string()));    case DOMNamedNodeMap::SetNamedItemNS: // DOM2      return getDOMNode(exec, map.setNamedItemNS(toNode(args[0])));    case DOMNamedNodeMap::RemoveNamedItemNS: // DOM2      return getDOMNode(exec, map.removeNamedItemNS(args[0].toString(exec).string(),args[1].toString(exec).string()));    default:      break;  }  return Undefined();}// -------------------------------------------------------------------------const ClassInfo DOMProcessingInstruction::info = { "ProcessingInstruction", &DOMNode::info, &DOMProcessingInstructionTable, 0 };/* Source for DOMProcessingInstructionTable.@begin DOMProcessingInstructionTable 3  target	DOMProcessingInstruction::Target	DontDelete|ReadOnly  data		DOMProcessingInstruction::Data		DontDelete  sheet		DOMProcessingInstruction::Sheet		DontDelete|ReadOnly@end*/Value DOMProcessingInstruction::tryGet(ExecState *exec, const Identifier &propertyName) const{  return DOMObjectLookupGetValue<DOMProcessingInstruction, DOMNode>(exec, propertyName, &DOMProcessingInstructionTable, this);}Value DOMProcessingInstruction::getValueProperty(ExecState *exec, int token) const{  switch (token) {  case Target:    return String(static_cast<DOM::ProcessingInstruction>(node).target());  case Data:    return String(static_cast<DOM::ProcessingInstruction>(node).data());  case Sheet:    return getDOMStyleSheet(exec,static_cast<DOM::ProcessingInstruction>(node).sheet());  default:    kdDebug(6070) << "WARNING: DOMProcessingInstruction::getValueProperty unhandled token " << token << endl;    return Value();  }}void DOMProcessingInstruction::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr){  // Not worth using the hashtable for this one ;)  if (propertyName == "data")    static_cast<DOM::ProcessingInstruction>(node).setData(value.toString(exec).string());  else    DOMNode::tryPut(exec, propertyName,value,attr);}// -------------------------------------------------------------------------const ClassInfo DOMNotation::info = { "Notation", &DOMNode::info, &DOMNotationTable, 0 };

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -