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

📄 kjs_dom.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    exec->setException(err);  }  #else    try {    val = tryCall(exec, thisObj, args);  }  // pity there's no way to distinguish between these in JS code  catch (...) {    Object err = Error::create(exec, GeneralError, "Exception from DOMNodeList");    exec->setException(err);  }#endif  return val;}Value DOMNodeList::tryCall(ExecState *exec, Object &, const List &args){  // Do not use thisObj here. See HTMLCollection.  UString s = args[0].toString(exec);  bool ok;  unsigned int u = s.toULong(&ok);  if (ok)    return getDOMNode(exec,list.item(u));  kdWarning() << "KJS::DOMNodeList::tryCall " << s.qstring() << " not implemented" << endl;  return Undefined();}DOMNodeListFunc::DOMNodeListFunc(ExecState *exec, int i, int len)  : DOMFunction(), id(i){  Value protect(this);  put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum);}// Not a prototype class currently, but should probably be converted to oneValue DOMNodeListFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){  if (!thisObj.inherits(&KJS::DOMNodeList::info)) {    Object err = Error::create(exec,TypeError);    exec->setException(err);    return err;  }  DOM::NodeList list = static_cast<DOMNodeList *>(thisObj.imp())->nodeList();  Value result;  if (id == Item)    result = getDOMNode(exec, list.item(args[0].toInt32(exec)));  return result;}// -------------------------------------------------------------------------const ClassInfo DOMAttr::info = { "Attr", &DOMNode::info, &DOMAttrTable, 0 };/* Source for DOMAttrTable. Use "make hashtables" to regenerate.@begin DOMAttrTable 5  name		DOMAttr::Name		DontDelete|ReadOnly  specified	DOMAttr::Specified	DontDelete|ReadOnly  value		DOMAttr::ValueProperty	DontDelete|ReadOnly  ownerElement	DOMAttr::OwnerElement	DontDelete|ReadOnly@end*/Value DOMAttr::tryGet(ExecState *exec, const Identifier &propertyName) const{#ifdef KJS_VERBOSE  kdDebug(6070) << "DOMAttr::tryPut " << 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 getStringOrNull(static_cast<DOM::Attr>(node).name());  case Specified:    return Boolean(static_cast<DOM::Attr>(node).specified());  case ValueProperty:    return getStringOrNull(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::putValue(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:    kdWarning() << "DOMAttr::putValue unhandled token " << token << endl;  }}// -------------------------------------------------------------------------/* Source for DOMDocumentProtoTable. Use "make hashtables" to regenerate.@begin DOMDocumentProtoTable 29  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  execCommand        DOMDocument::ExecCommand                  DontDelete|Function 3  queryCommandEnabled DOMDocument::QueryCommandEnabled         DontDelete|Function 1  queryCommandIndeterm DOMDocument::QueryCommandIndeterm       DontDelete|Function 1  queryCommandState DOMDocument::QueryCommandState             DontDelete|Function 1  queryCommandSupported DOMDocument::QueryCommandSupported     DontDelete|Function 1  queryCommandValue DOMDocument::QueryCommandValue             DontDelete|Function 1@end*/DEFINE_PROTOTYPE("DOMDocument", DOMDocumentProto)IMPLEMENT_PROTOFUNC(DOMDocumentProtoFunc)IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMDocumentProto, DOMDocumentProtoFunc, DOMNodeProto)const ClassInfo DOMDocument::info = { "Document", &DOMNode::info, &DOMDocumentTable, 0 };/* Source for DOMDocumentTable. Use "make hashtables" to regenerate.@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@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 PreferredStylesheetSet:    return getStringOrNull(doc.preferredStylesheetSet());  case SelectedStylesheetSet:    return getStringOrNull(doc.selectedStylesheetSet());  case ReadyState:    {    DOM::DocumentImpl* docimpl = node.handle()->getDocument();    if ( docimpl )    {      KHTMLPart* part = docimpl->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 DOMDocument::DefaultView: // DOM2    return getDOMAbstractView(exec,doc.defaultView());  default:    kdWarning() << "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::putValue(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;    }  }}Value DOMDocumentProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){  if (!thisObj.inherits(&KJS::DOMNode::info)) {    Object err = Error::create(exec,TypeError);    exec->setException(err);    return err;  }  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:    return getDOMNode(exec,doc.getElementById(args[0].toString(exec).string()));  case DOMDocument::CreateRange:    return getDOMRange(exec,doc.createRange());  case DOMDocument::CreateNodeIterator: {    NodeFilter filter;    if (!args[2].isA(NullType)) {        Object obj = Object::dynamicCast(args[2]);        if (!obj.isNull())            filter = NodeFilter(new JSNodeFilterCondition(obj));    }    return getDOMNodeIterator(exec, doc.createNodeIterator(toNode(args[0]), (long unsigned int)(args[1].toNumber(exec)), filter, args[3].toBoolean(exec)));  }  case DOMDocument::CreateTreeWalker: {    NodeFilter filter;    if (!args[2].isA(NullType)) {        Object obj = Object::dynamicCast(args[2]);        if (!obj.isNull())            filter = NodeFilter(new JSNodeFilterCondition(obj));    }    return getDOMTreeWalker(exec, doc.createTreeWalker(toNode(args[0]), (long unsigned int)(args[1].toNumber(exec)), filter, 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::ExecCommand: {    return Boolean(doc.execCommand(args[0].toString(exec).string(), args[1].toBoolean(exec), args[2].toString(exec).string()));  }  case DOMDocument::QueryCommandEnabled: {    return Boolean(doc.queryCommandEnabled(args[0].toString(exec).string()));  }  case DOMDocument::QueryCommandIndeterm: {    return Boolean(doc.queryCommandIndeterm(args[0].toString(exec).string()));  }  case DOMDocument::QueryCommandState: {    return Boolean(doc.queryCommandState(args[0].toString(exec).string()));  }  case DOMDocument::QueryCommandSupported: {    return Boolean(doc.queryCommandSupported(args[0].toString(exec).string()));  }  case DOMDocument::QueryCommandValue: {    DOM::DOMString commandValue(doc.queryCommandValue(args[0].toString(exec).string()));    // Method returns null DOMString to signal command is unsupported.    // Micorsoft documentation for this method says:    // "If not supported [for a command identifier], this method returns a Boolean set to false."    if (commandValue.isNull())        return Boolean(false);    else         return String(commandValue);  }  default:    break;  }  return Undefined();}

⌨️ 快捷键说明

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