📄 kjs_dom.cpp
字号:
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 2000 Harri Porten (porten@kde.org)
* Copyright (C) 2004 Apple Computer, Inc.
*
* 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 <khtmlview.h>
#include "xml/dom2_eventsimpl.h"
#include "rendering/render_canvas.h"
#include "xml/dom_nodeimpl.h"
#include "xml/dom_docimpl.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"
#include "html_objectimpl.h"
#include "misc/htmltags.h"
#if APPLE_CHANGES && !NOKIA_CHANGES
#include <JavaScriptCore/runtime_object.h>
#endif
using namespace KJS;
using DOM::DOMException;
using DOM::DOMString;
using DOM::NodeFilter;
// -------------------------------------------------------------------------
/* Source for DOMNodeProtoTable. Use "make hashtables" to regenerate.
@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
contains DOMNode::Contains DontDelete|Function 1
# "DOM level 0" (from Gecko DOM reference; also in WinIE)
item DOMNode::Item DontDelete|Function 1
@end
*/
DEFINE_PROTOTYPE("DOMNode",DOMNodeProto)
IMPLEMENT_PROTOFUNC(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)
{
}
bool DOMNode::toBoolean(ExecState *) const
{
return !node.isNull();
}
/* Source for DOMNodeTable. Use "make hashtables" to regenerate.
@begin DOMNodeTable 67
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
#
onabort DOMNode::OnAbort DontDelete
onblur DOMNode::OnBlur DontDelete
onchange DOMNode::OnChange DontDelete
onclick DOMNode::OnClick DontDelete
oncontextmenu DOMNode::OnContextMenu DontDelete
ondblclick DOMNode::OnDblClick DontDelete
onbeforecut DOMNode::OnBeforeCut DontDelete
oncut DOMNode::OnCut DontDelete
onbeforecopy DOMNode::OnBeforeCopy DontDelete
oncopy DOMNode::OnCopy DontDelete
onbeforepaste DOMNode::OnBeforePaste DontDelete
onpaste DOMNode::OnPaste DontDelete
ondrag DOMNode::OnDrag DontDelete
ondragdrop DOMNode::OnDragDrop DontDelete
ondragend DOMNode::OnDragEnd DontDelete
ondragenter DOMNode::OnDragEnter DontDelete
ondragleave DOMNode::OnDragLeave DontDelete
ondragover DOMNode::OnDragOver DontDelete
ondragstart DOMNode::OnDragStart DontDelete
ondrop DOMNode::OnDrop DontDelete
onerror DOMNode::OnError DontDelete
onfocus DOMNode::OnFocus DontDelete
oninput DOMNode::OnInput 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
onscroll DOMNode::OnScroll DontDelete
onsearch DOMNode::OnSearch DontDelete
onselect DOMNode::OnSelect DontDelete
onselectstart DOMNode::OnSelectStart 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
@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 getStringOrNull(node.nodeName());
case NodeValue:
return getStringOrNull(node.nodeValue());
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 getStringOrNull(node.namespaceURI());
case Prefix:
return getStringOrNull(node.prefix());
case LocalName:
return getStringOrNull(node.localName());
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_CLICK_EVENT);
case OnContextMenu:
return getListener(DOM::EventImpl::CONTEXTMENU_EVENT);
case OnDblClick:
return getListener(DOM::EventImpl::KHTML_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 OnInput:
return getListener(DOM::EventImpl::INPUT_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 OnBeforeCut:
return getListener(DOM::EventImpl::BEFORECUT_EVENT);
case OnCut:
return getListener(DOM::EventImpl::CUT_EVENT);
case OnBeforeCopy:
return getListener(DOM::EventImpl::BEFORECOPY_EVENT);
case OnCopy:
return getListener(DOM::EventImpl::COPY_EVENT);
case OnBeforePaste:
return getListener(DOM::EventImpl::BEFOREPASTE_EVENT);
case OnPaste:
return getListener(DOM::EventImpl::PASTE_EVENT);
case OnDragEnter:
return getListener(DOM::EventImpl::DRAGENTER_EVENT);
case OnDragOver:
return getListener(DOM::EventImpl::DRAGOVER_EVENT);
case OnDragLeave:
return getListener(DOM::EventImpl::DRAGLEAVE_EVENT);
case OnDrop:
return getListener(DOM::EventImpl::DROP_EVENT);
case OnDragStart:
return getListener(DOM::EventImpl::DRAGSTART_EVENT);
case OnDrag:
return getListener(DOM::EventImpl::DRAG_EVENT);
case OnDragEnd:
return getListener(DOM::EventImpl::DRAGEND_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 OnScroll:
return getListener(DOM::EventImpl::SCROLL_EVENT);
#if APPLE_CHANGES
case OnSearch:
return getListener(DOM::EventImpl::SEARCH_EVENT);
#endif
case OnSelect:
return getListener(DOM::EventImpl::SELECT_EVENT);
case OnSelectStart:
return getListener(DOM::EventImpl::SELECTSTART_EVENT);
case OnSubmit:
return getListener(DOM::EventImpl::SUBMIT_EVENT);
case OnUnload:
return getListener(DOM::EventImpl::UNLOAD_EVENT);
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->updateLayoutIgnorePendingStylesheets();
}
khtml::RenderObject *rend = node.handle()->renderer();
switch (token) {
case OffsetLeft:
return rend ? static_cast<Value>(Number(rend->offsetLeft())) : Value(Undefined());
case OffsetTop:
return rend ? static_cast<Value>(Number(rend->offsetTop())) : Value(Undefined());
case OffsetWidth:
return rend ? static_cast<Value>(Number(rend->offsetWidth()) ) : Value(Undefined());
case OffsetHeight:
return rend ? static_cast<Value>(Number(rend->offsetHeight() ) ) : Value(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()) ) : Value(Undefined());
case ClientHeight:
return rend ? static_cast<Value>(Number(rend->clientHeight()) ) : Value(Undefined());
case ScrollWidth:
return rend ? static_cast<Value>(Number(rend->scrollWidth()) ) : Value(Undefined());
case ScrollHeight:
return rend ? static_cast<Value>(Number(rend->scrollHeight()) ) : Value(Undefined());
case ScrollLeft:
return Number(rend && rend->layer() ? rend->layer()->scrollXOffset() : 0);
case ScrollTop:
return Number(rend && rend->layer() ? rend->layer()->scrollYOffset() : 0);
default:
kdWarning() << "Unhandled token in DOMNode::getValueProperty : " << token << endl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -