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

📄 kjs_html.cpp

📁 将konqueror浏览器移植到ARM9 2410中
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// -*- c-basic-offset: 2 -*-/* *  This file is part of the KDE libraries *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org) * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with this library; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <stdio.h>#include <qptrdict.h>#include <khtml_part.h>#include <misc/loader.h>#include <dom/html_base.h>#include <dom/html_block.h>#include <dom/html_document.h>#include <dom/html_element.h>#include <dom/html_form.h>#include <dom/html_head.h>#include <dom/html_image.h>#include <dom/html_inline.h>#include <dom/html_list.h>#include <dom/html_misc.h>#include <dom/html_table.h>#include <dom/html_object.h>#include <dom/dom_node.h>#include <dom_string.h>#include <dom_exception.h>// ### HACK#include <html/html_baseimpl.h>#include <xml/dom_docimpl.h>#include <xml/dom2_eventsimpl.h>#include <khtmlview.h>#include <kjs/operations.h>#include "kjs_dom.h"#include "kjs_html.h"#include "kjs_window.h"#include "kjs_events.h"#include <htmltags.h>#include <kdebug.h>using namespace KJS;QPtrDict<KJS::HTMLCollection> htmlCollections;KJSO KJS::HTMLDocFunction::tryGet(const UString &p) const{  DOM::HTMLCollection coll;  switch (id) {  case Images:    coll = doc.images();    break;  case Applets:    coll = doc.applets();    break;  case Links:    coll = doc.links();    break;  case Forms:    coll = doc.forms();    break;  case Anchors:    coll = doc.anchors();    break;  case All:  // IE specific, not part of the DOM    coll = doc.all();    break;  default:    return Undefined();  }  KJSO tmp(new KJS::HTMLCollection(coll));  return tmp.get(p);}Completion KJS::HTMLDocFunction::tryExecute(const List &args){  KJSO result;  String s;  DOM::HTMLElement element;  DOM::HTMLCollection coll;  KJSO v = args[0];  switch (id) {  case Images:    coll = doc.images();    break;  case Applets:    coll = doc.applets();    break;  case Links:    coll = doc.links();    break;  case Forms:    coll = doc.forms();    break;  case Anchors:    coll = doc.anchors();    break;  case All:    coll = doc.all();    break;  case Open:    // this is just a dummy function,  has no purpose anymore    //doc.open();    result = Undefined();    break;  case Close:    // this is just a dummy function,  has no purpose    // see khtmltests/ecma/tokenizer-script-recursion.html    // doc.close();    result = Undefined();    break;  case Write:  case WriteLn: {    // DOM only specifies single string argument, but NS & IE allow multiple    UString str = v.toString().value();    for (int i = 1; i < args.size(); i++)      str += args[i].toString().value();    if (id == WriteLn)      str += "\n";    doc.write(str.string());    result = Undefined();    break;  }  case GetElementById:    s = v.toString();    result = getDOMNode(doc.getElementById(s.value().string()));    break;  case GetElementsByName:    s = v.toString();    result = getDOMNodeList(doc.getElementsByName(s.value().string()));    break;  }  // retrieve element from collection. Either by name or indexed.  if (id == Images || id == Applets || id == Links ||      id == Forms || id == Anchors || id == All) {    bool ok;    UString s = args[0].toString().value();    unsigned int u = s.toULong(&ok);    if (ok)      element = coll.item(u);    else      element = coll.namedItem(s.string());    result = getDOMNode(element);  }  return Completion(ReturnValue, result);}const TypeInfo KJS::HTMLDocument::info = { "HTMLDocument", HostType,					   &DOMDocument::info, 0, 0 };bool KJS::HTMLDocument::hasProperty(const UString &p, bool recursive) const{  if (p == "title" || p == "referrer" || p == "domain" || p == "URL" ||      p == "body" || p == "location" || p == "images" || p == "applets" ||      p == "links" || p == "forms" || p == "anchors" || p == "all" ||      p == "cookie" || p == "open" || p == "close" || p == "write" ||      p == "writeln" || p == "getElementById" || p == "getElementsByName")    return true;  if (!static_cast<DOM::HTMLDocument>(node).all().      namedItem(p.string()).isNull())    return true;  return recursive && DOMDocument::hasProperty(p, true);}KJSO KJS::HTMLDocument::tryGet(const UString &p) const{  //kdDebug() << "KJS::HTMLDocument::get " << p.qstring() << endl;  DOM::HTMLDocument doc = static_cast<DOM::HTMLDocument>(node);  // image and form elements with the name p will be looked up first  DOM::HTMLCollection coll = doc.all();  DOM::HTMLElement element = coll.namedItem(p.string());  if (!element.isNull() &&      (element.elementId() == ID_IMG || element.elementId() == ID_FORM))    return getDOMNode(element);  if (p == "title")    return getString(doc.title());  else if (p == "referrer")    return String(doc.referrer());  else if (p == "domain")    return String(doc.domain());  else if (p == "URL")    return getString(doc.URL());  else if (p == "body")    return getDOMNode(doc.body());  else if (p == "location") {    KHTMLPart *part = static_cast<DOM::DocumentImpl*>(doc.handle())->		      view()->part();    return Window::retrieveWindow(part)->location();  } else if (p == "images")    return new HTMLDocFunction(doc, HTMLDocFunction::Images);  else if (p == "applets")    return new HTMLDocFunction(doc, HTMLDocFunction::Applets);  else if (p == "links")    return new HTMLDocFunction(doc, HTMLDocFunction::Links);  else if (p == "forms")    return new HTMLDocFunction(doc, HTMLDocFunction::Forms);  else if (p == "anchors")    return new HTMLDocFunction(doc, HTMLDocFunction::Anchors);  else if (p == "all")    return new HTMLDocFunction(doc, HTMLDocFunction::All);  else if (p == "cookie")    return String(doc.cookie());  else if (DOMDocument::hasProperty(p))	// expandos override functions    return DOMDocument::tryGet(p);  else if (p == "open")    return new HTMLDocFunction(doc, HTMLDocFunction::Open);  else if (p == "close")    return new HTMLDocFunction(doc, HTMLDocFunction::Close);  else if (p == "write")    return new HTMLDocFunction(doc, HTMLDocFunction::Write);  else if (p == "writeln")    return new HTMLDocFunction(doc, HTMLDocFunction::WriteLn);  else if (p == "getElementById")    return new HTMLDocFunction(doc, HTMLDocFunction::GetElementById);  else if (p == "getElementsByName")    return new HTMLDocFunction(doc, HTMLDocFunction::GetElementsByName);  else {    if(!element.isNull())      return getDOMNode(element);    return Undefined();  }}void KJS::HTMLDocument::tryPut(const UString &p, const KJSO& v){  DOM::HTMLDocument doc = static_cast<DOM::HTMLDocument>(node);  if (p == "title")    doc.setTitle(v.toString().value().string());  else if (p == "body")    doc.setBody((new DOMNode(KJS::toNode(v)))->toNode());  else if (p == "cookie")    doc.setCookie(v.toString().value().string());  else if (p == "location") {    KHTMLPart *part = static_cast<DOM::DocumentImpl *>( doc.handle() )->view()->part();    QString str = v.toString().value().qstring();    part->scheduleRedirection(0, str);  }  else if (p == "onclick")    doc.handle()->setHTMLEventListener(DOM::EventImpl::KHTML_CLICK_EVENT,Window::retrieveActive()->getJSEventListener(v,true));  else if (p == "ondblclick")    doc.handle()->setHTMLEventListener(DOM::EventImpl::KHTML_DBLCLICK_EVENT,Window::retrieveActive()->getJSEventListener(v,true));  else if (p == "onkeydown")    doc.handle()->setHTMLEventListener(DOM::EventImpl::KHTML_KEYDOWN_EVENT,Window::retrieveActive()->getJSEventListener(v,true));  else if (p == "onkeypress")    doc.handle()->setHTMLEventListener(DOM::EventImpl::KHTML_KEYPRESS_EVENT,Window::retrieveActive()->getJSEventListener(v,true));  else if (p == "onkeyup")    doc.handle()->setHTMLEventListener(DOM::EventImpl::KHTML_KEYUP_EVENT,Window::retrieveActive()->getJSEventListener(v,true));  else if (p == "onmousedown")    doc.handle()->setHTMLEventListener(DOM::EventImpl::MOUSEDOWN_EVENT,Window::retrieveActive()->getJSEventListener(v,true));  else if (p == "onmouseup")    doc.handle()->setHTMLEventListener(DOM::EventImpl::MOUSEUP_EVENT,Window::retrieveActive()->getJSEventListener(v,true));  else    DOMDocument::tryPut(p,v);}// -------------------------------------------------------------------------const TypeInfo KJS::HTMLElement::info = { "HTMLElement", HostType,					  &DOMElement::info, 0, 0 };KJSO KJS::HTMLElement::tryGet(const UString &p) const{  DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);  //kdDebug() << "KJS::HTMLElement::tryGet " << p.qstring() << " id=" << element.elementId() << endl;  switch (element.elementId()) {    case ID_HTML: {      DOM::HTMLHtmlElement html = element;      if      (p == "version")         return getString(html.version());

⌨️ 快捷键说明

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