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

📄 kjs_dom.cpp

📁 konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版本源码包.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// -*- c-basic-offset: 2 -*-/* *  This file is part of the KDE libraries *  Copyright (C) 2000 Harri Porten (porten@kde.org) *  Copyright (C) 2003 Apple Computer, Inc. * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Library 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 *  Library General Public License for more details. * *  You should have received a copy of the GNU Library General Public *  License along with this library; if not, write to the Free Software *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA */#include <khtmlview.h>#include "xml/dom2_eventsimpl.h"#include "rendering/render_canvas.h"#include "rendering/render_layer.h"#include "xml/dom_nodeimpl.h"#include "xml/dom_docimpl.h"#include "misc/htmltags.h" // ID_*#include "misc/htmlattrs.h" // ATTR_*#include "html/html_baseimpl.h"#include <kdebug.h>#include <khtml_part.h>#include "kjs_dom.h"#include "kjs_html.h"#include "kjs_css.h"#include "kjs_range.h"#include "kjs_traversal.h"#include "kjs_events.h"#include "kjs_views.h"#include "kjs_window.h"#include "dom/dom_exception.h"#include "kjs_dom.lut.h"#include "khtmlpart_p.h"using namespace KJS;// -------------------------------------------------------------------------/* Source for DOMNodeProtoTable.@begin DOMNodeProtoTable 13  insertBefore	DOMNode::InsertBefore	DontDelete|Function 2  replaceChild	DOMNode::ReplaceChild	DontDelete|Function 2  removeChild	DOMNode::RemoveChild	DontDelete|Function 1  appendChild	DOMNode::AppendChild	DontDelete|Function 1  hasAttributes	DOMNode::HasAttributes	DontDelete|Function 0  hasChildNodes	DOMNode::HasChildNodes	DontDelete|Function 0  cloneNode	DOMNode::CloneNode	DontDelete|Function 1# DOM2  normalize	DOMNode::Normalize	DontDelete|Function 0  isSupported   DOMNode::IsSupported	DontDelete|Function 2# from the EventTarget interface  addEventListener	DOMNode::AddEventListener	DontDelete|Function 3  removeEventListener	DOMNode::RemoveEventListener	DontDelete|Function 3  dispatchEvent		DOMNode::DispatchEvent	DontDelete|Function 1# IE extensions  contains	DOMNode::Contains		DontDelete|Function 1  insertAdjacentHTML	DOMNode::InsertAdjacentHTML	DontDelete|Function 2# "DOM level 0" (from Gecko DOM reference; also in WinIE)  item          DOMNode::Item           DontDelete|Function 1@end*/DEFINE_PROTOTYPE("DOMNode",DOMNodeProto)IMPLEMENT_PROTOFUNC_DOM(DOMNodeProtoFunc)IMPLEMENT_PROTOTYPE(DOMNodeProto,DOMNodeProtoFunc)const ClassInfo DOMNode::info = { "Node", 0, &DOMNodeTable, 0 };DOMNode::DOMNode(ExecState *exec, const DOM::Node& n)  : DOMObject(DOMNodeProto::self(exec)), node(n){}DOMNode::DOMNode(const Object& proto, const DOM::Node& n)  : DOMObject(proto), node(n){}DOMNode::~DOMNode(){  ScriptInterpreter::forgetDOMObject(node.handle());}bool DOMNode::toBoolean(ExecState *) const{    return !node.isNull();}/* Source for DOMNodeTable.@begin DOMNodeTable 53  nodeName	DOMNode::NodeName	DontDelete|ReadOnly  nodeValue	DOMNode::NodeValue	DontDelete  nodeType	DOMNode::NodeType	DontDelete|ReadOnly  parentNode	DOMNode::ParentNode	DontDelete|ReadOnly  parentElement	DOMNode::ParentElement	DontDelete|ReadOnly  childNodes	DOMNode::ChildNodes	DontDelete|ReadOnly  firstChild	DOMNode::FirstChild	DontDelete|ReadOnly  lastChild	DOMNode::LastChild	DontDelete|ReadOnly  previousSibling  DOMNode::PreviousSibling DontDelete|ReadOnly  nextSibling	DOMNode::NextSibling	DontDelete|ReadOnly  attributes	DOMNode::Attributes	DontDelete|ReadOnly  namespaceURI	DOMNode::NamespaceURI	DontDelete|ReadOnly# DOM2  prefix	DOMNode::Prefix		DontDelete  localName	DOMNode::LocalName	DontDelete|ReadOnly  ownerDocument	DOMNode::OwnerDocument	DontDelete|ReadOnly# Event handlers# IE also has: onactivate, onbefore*, oncontextmenu, oncontrolselect, oncut,# ondeactivate, ondrag*, ondrop, onfocusin, onfocusout, onhelp, onmousewheel,# onmove*, onpaste, onpropertychange, onreadystatechange, onresizeend/start,# onselectionchange, onstop  onabort	DOMNode::OnAbort		DontDelete  onblur	DOMNode::OnBlur			DontDelete  onchange	DOMNode::OnChange		DontDelete  onclick	DOMNode::OnClick		DontDelete  ondblclick	DOMNode::OnDblClick		DontDelete  ondragdrop	DOMNode::OnDragDrop		DontDelete  onerror	DOMNode::OnError		DontDelete  onfocus	DOMNode::OnFocus       		DontDelete  onkeydown	DOMNode::OnKeyDown		DontDelete  onkeypress	DOMNode::OnKeyPress		DontDelete  onkeyup	DOMNode::OnKeyUp		DontDelete  onload	DOMNode::OnLoad			DontDelete  onmousedown	DOMNode::OnMouseDown		DontDelete  onmousemove	DOMNode::OnMouseMove		DontDelete  onmouseout	DOMNode::OnMouseOut		DontDelete  onmouseover	DOMNode::OnMouseOver		DontDelete  onmouseup	DOMNode::OnMouseUp		DontDelete  onmove	DOMNode::OnMove			DontDelete  onreset	DOMNode::OnReset		DontDelete  onresize	DOMNode::OnResize		DontDelete  onselect	DOMNode::OnSelect		DontDelete  onsubmit	DOMNode::OnSubmit		DontDelete  onunload	DOMNode::OnUnload		DontDelete# IE extensions  offsetLeft	DOMNode::OffsetLeft		DontDelete|ReadOnly  offsetTop	DOMNode::OffsetTop		DontDelete|ReadOnly  offsetWidth	DOMNode::OffsetWidth		DontDelete|ReadOnly  offsetHeight	DOMNode::OffsetHeight		DontDelete|ReadOnly  offsetParent	DOMNode::OffsetParent		DontDelete|ReadOnly  clientWidth	DOMNode::ClientWidth		DontDelete|ReadOnly  clientHeight	DOMNode::ClientHeight		DontDelete|ReadOnly  scrollLeft	DOMNode::ScrollLeft		DontDelete  scrollTop	DOMNode::ScrollTop		DontDelete  scrollWidth   DOMNode::ScrollWidth            DontDelete|ReadOnly  scrollHeight  DOMNode::ScrollHeight           DontDelete|ReadOnly  sourceIndex	DOMNode::SourceIndex		DontDelete|ReadOnly@end*/Value DOMNode::tryGet(ExecState *exec, const Identifier &propertyName) const{#ifdef KJS_VERBOSE  kdDebug(6070) << "DOMNode::tryGet " << propertyName.qstring() << endl;#endif  return DOMObjectLookupGetValue<DOMNode, DOMObject>(exec, propertyName, &DOMNodeTable, this);}Value DOMNode::getValueProperty(ExecState *exec, int token) const{  switch (token) {  case NodeName:    return String(node.nodeName());  case NodeValue:    return getString(node.nodeValue()); // initially null, per domts/level1/core/hc_documentcreateelement.html  case NodeType:    return Number((unsigned int)node.nodeType());  case ParentNode:    return getDOMNode(exec,node.parentNode());  case ParentElement: // IE only apparently    return getDOMNode(exec,node.parentNode());  case ChildNodes:    return getDOMNodeList(exec,node.childNodes());  case FirstChild:    return getDOMNode(exec,node.firstChild());  case LastChild:    return getDOMNode(exec,node.lastChild());  case PreviousSibling:    return getDOMNode(exec,node.previousSibling());  case NextSibling:    return getDOMNode(exec,node.nextSibling());  case Attributes:    return getDOMNamedNodeMap(exec,node.attributes());  case NamespaceURI:    return getString(node.namespaceURI()); // Moz returns null if not set (dom/namespaces.html)  case Prefix:    return getString(node.prefix());  // Moz returns null if not set (dom/namespaces.html)  case LocalName:    return getString(node.localName());  // Moz returns null if not set (dom/namespaces.html)  case OwnerDocument:    return getDOMNode(exec,node.ownerDocument());  case OnAbort:    return getListener(DOM::EventImpl::ABORT_EVENT);  case OnBlur:    return getListener(DOM::EventImpl::BLUR_EVENT);  case OnChange:    return getListener(DOM::EventImpl::CHANGE_EVENT);  case OnClick:    return getListener(DOM::EventImpl::KHTML_ECMA_CLICK_EVENT);  case OnDblClick:    return getListener(DOM::EventImpl::KHTML_ECMA_DBLCLICK_EVENT);  case OnDragDrop:    return getListener(DOM::EventImpl::KHTML_DRAGDROP_EVENT);  case OnError:    return getListener(DOM::EventImpl::KHTML_ERROR_EVENT);  case OnFocus:    return getListener(DOM::EventImpl::FOCUS_EVENT);  case OnKeyDown:    return getListener(DOM::EventImpl::KEYDOWN_EVENT);  case OnKeyPress:    return getListener(DOM::EventImpl::KEYPRESS_EVENT);  case OnKeyUp:    return getListener(DOM::EventImpl::KEYUP_EVENT);  case OnLoad:    return getListener(DOM::EventImpl::LOAD_EVENT);  case OnMouseDown:    return getListener(DOM::EventImpl::MOUSEDOWN_EVENT);  case OnMouseMove:    return getListener(DOM::EventImpl::MOUSEMOVE_EVENT);  case OnMouseOut:    return getListener(DOM::EventImpl::MOUSEOUT_EVENT);  case OnMouseOver:    return getListener(DOM::EventImpl::MOUSEOVER_EVENT);  case OnMouseUp:    return getListener(DOM::EventImpl::MOUSEUP_EVENT);  case OnMove:    return getListener(DOM::EventImpl::KHTML_MOVE_EVENT);  case OnReset:    return getListener(DOM::EventImpl::RESET_EVENT);  case OnResize:    return getListener(DOM::EventImpl::RESIZE_EVENT);  case OnSelect:    return getListener(DOM::EventImpl::SELECT_EVENT);  case OnSubmit:    return getListener(DOM::EventImpl::SUBMIT_EVENT);  case OnUnload:    return getListener(DOM::EventImpl::UNLOAD_EVENT);  case SourceIndex: {    // Retrieves the ordinal position of the object, in source order, as the object    // appears in the document's all collection    // i.e. document.all[n.sourceIndex] == n    DOM::Document doc = node.ownerDocument();    if (doc.isHTMLDocument()) {      DOM::HTMLCollection all = static_cast<DOM::HTMLDocument>(doc).all();      unsigned long i = 0;      DOM::Node n = all.firstItem();      for ( ; !n.isNull() && n != node; n = all.nextItem() )        ++i;      Q_ASSERT( !n.isNull() ); // node not in document.all !?      return Number(i);    }  }  default:    // no DOM standard, found in IE only    // Make sure our layout is up to date before we allow a query on these attributes.    DOM::DocumentImpl* docimpl = node.handle()->getDocument();    if (docimpl) {      docimpl->updateLayout();    }    khtml::RenderObject *rend = node.handle()->renderer();    switch (token) {    case OffsetLeft:      return rend ? static_cast<Value>( Number( rend->offsetLeft() ) ) : Undefined();    case OffsetTop:      return rend ? static_cast<Value>(  Number( rend->offsetTop() ) ) : Undefined();    case OffsetWidth:      return rend ? static_cast<Value>(  Number( rend->offsetWidth() ) ) : Undefined();    case OffsetHeight:      return rend ? static_cast<Value>(  Number( rend->offsetHeight() ) ) : Undefined();    case OffsetParent:    {      khtml::RenderObject* par = rend ? rend->offsetParent() : 0;      return getDOMNode( exec, par ? par->element() : 0 );    }    case ClientWidth:      return rend ? static_cast<Value>( Number( rend->clientWidth() ) ) : Undefined();    case ClientHeight:      return rend ? static_cast<Value>( Number( rend->clientHeight() ) ) : Undefined();    case ScrollWidth:      return rend ? static_cast<Value>( Number(rend->scrollWidth()) ) : Undefined();    case ScrollHeight:      return rend ? static_cast<Value>( Number(rend->scrollHeight()) ) : Undefined();    case ScrollLeft:      if (rend && rend->layer()) {          if (rend->isRoot() && !rend->style()->hidesOverflow())              return Number( node.ownerDocument().view() ? node.ownerDocument().view()->contentsX() : 0);          return Number( rend->layer()->scrollXOffset() );      }      return Number( 0 );    case ScrollTop:      if (rend && rend->layer()) {          if (rend->isRoot() && !rend->style()->hidesOverflow())              return Number( node.ownerDocument().view() ? node.ownerDocument().view()->contentsY() : 0);          return Number( rend->layer()->scrollYOffset() );      }      return Number( 0 );    default:      kdDebug(6070) << "WARNING: Unhandled token in DOMNode::getValueProperty : " << token << endl;      break;    }  }  return Undefined();}void DOMNode::tryPut(ExecState *exec, const Identifier& propertyName, const Value& value, int attr){#ifdef KJS_VERBOSE  kdDebug(6070) << "DOMNode::tryPut " << propertyName.qstring() << endl;#endif  DOMObjectLookupPut<DOMNode,DOMObject>(exec, propertyName, value, attr,                                        &DOMNodeTable, this );}void DOMNode::putValueProperty(ExecState *exec, int token, const Value& value, int /*attr*/){  switch (token) {  case NodeValue:    node.setNodeValue(value.toString(exec).string());    break;  case Prefix:    node.setPrefix(value.toString(exec).string());    break;  case OnAbort:    setListener(exec,DOM::EventImpl::ABORT_EVENT,value);    break;  case OnBlur:    setListener(exec,DOM::EventImpl::BLUR_EVENT,value);    break;

⌨️ 快捷键说明

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