?? dom2_eventsimpl.cpp
字號:
/**
* This file is part of the DOM implementation for KDE.
*
* (C) 2001 Peter Kelly (pmk@post.com)
* (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* 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; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "dom/dom2_views.h"
#include "xml/dom2_eventsimpl.h"
#include "xml/dom_stringimpl.h"
#include "xml/dom_nodeimpl.h"
#include "xml/dom_docimpl.h"
#include "rendering/render_object.h"
#include "rendering/render_layer.h"
#include <kdebug.h>
using namespace DOM;
EventImpl::EventImpl()
{
m_type = 0;
m_canBubble = false;
m_cancelable = false;
m_propagationStopped = false;
m_defaultPrevented = false;
m_cancelBubble = false;
m_id = UNKNOWN_EVENT;
m_currentTarget = 0;
m_eventPhase = 0;
m_target = 0;
m_createTime = QDateTime::currentDateTime();
m_defaultHandled = false;
}
EventImpl::EventImpl(EventId _id, bool canBubbleArg, bool cancelableArg)
{
DOMString t = EventImpl::idToType(_id);
m_type = t.implementation();
if (m_type)
m_type->ref();
m_canBubble = canBubbleArg;
m_cancelable = cancelableArg;
m_propagationStopped = false;
m_defaultPrevented = false;
m_cancelBubble = false;
m_id = _id;
m_currentTarget = 0;
m_eventPhase = 0;
m_target = 0;
m_createTime = QDateTime::currentDateTime();
m_defaultHandled = false;
}
EventImpl::~EventImpl()
{
if (m_type)
m_type->deref();
if (m_target)
m_target->deref();
}
DOMString EventImpl::type() const
{
return m_type;
}
NodeImpl *EventImpl::target() const
{
return m_target;
}
void EventImpl::setTarget(NodeImpl *_target)
{
if (m_target)
m_target->deref();
m_target = _target;
if (m_target)
m_target->ref();
}
NodeImpl *EventImpl::currentTarget() const
{
return m_currentTarget;
}
void EventImpl::setCurrentTarget(NodeImpl *_currentTarget)
{
m_currentTarget = _currentTarget;
}
unsigned short EventImpl::eventPhase() const
{
return m_eventPhase;
}
void EventImpl::setEventPhase(unsigned short _eventPhase)
{
m_eventPhase = _eventPhase;
}
bool EventImpl::bubbles() const
{
return m_canBubble;
}
bool EventImpl::cancelable() const
{
return m_cancelable;
}
DOMTimeStamp EventImpl::timeStamp()
{
QDateTime epoch(QDate(1970,1,1),QTime(0,0));
// ### kjs does not yet support long long (?) so the value wraps around
return epoch.secsTo(m_createTime)*1000+m_createTime.time().msec();
}
void EventImpl::stopPropagation()
{
m_propagationStopped = true;
}
void EventImpl::preventDefault()
{
if (m_cancelable)
m_defaultPrevented = true;
}
void EventImpl::initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg)
{
// ### ensure this is not called after we have been dispatched (also for subclasses)
if (m_type)
m_type->deref();
m_type = eventTypeArg.implementation();
if (m_type)
m_type->ref();
m_id = typeToId(eventTypeArg);
m_canBubble = canBubbleArg;
m_cancelable = cancelableArg;
}
static const char * const eventNames[EventImpl::numEventIds] = {
0,
"DOMFocusIn",
"DOMFocusOut",
"DOMActivate",
"click",
"mousedown",
"mouseup",
"mouseover",
"mousemove",
"mouseout",
"onbeforecut",
"oncut",
"onbeforecopy",
"oncopy",
"onbeforepaste",
"onpaste",
"dragenter",
"dragover",
"dragleave",
"drop",
"dragstart",
"drag",
"dragend",
"selectstart",
"DOMSubtreeModified",
"DOMNodeInserted",
"DOMNodeRemoved",
"DOMNodeRemovedFromDocument",
"DOMNodeInsertedIntoDocument",
"DOMAttrModified",
"DOMCharacterDataModified",
"load",
"unload",
"abort",
"error",
"select",
"change",
"submit",
"reset",
"focus",
"blur",
"resize",
"scroll",
"contextmenu",
#if APPLE_CHANGES
"search",
#endif
"input",
"keydown",
"keyup",
"textInput", // FIXME: is the capital I correct?
0, // KHTML_DBLCLICK_EVENT
0, // KHTML_CLICK_EVENT
0, // KHTML_DRAGDROP_EVENT
0, // KHTML_ERROR_EVENT
"keypress",
0, // KHTML_MOVE_EVENT
0, // KHTML_ORIGCLICK_MOUSEUP_EVENT
"readystatechange",
};
EventImpl::EventId EventImpl::typeToId(const DOMString &type)
{
for (int i = 0; i < numEventIds; ++i) {
const char *n = eventNames[i];
if (n && type == n)
return static_cast<EventId>(i);
}
return UNKNOWN_EVENT;
}
DOMString EventImpl::idToType(EventId id)
{
switch (id) {
case KHTML_DBLCLICK_EVENT:
return "dblclick";
case KHTML_CLICK_EVENT:
return "click";
case KHTML_DRAGDROP_EVENT:
return "khtml_dragdrop";
case KHTML_ERROR_EVENT:
return "khtml_error";
case KHTML_MOVE_EVENT:
return "khtml_move";
case KHTML_ORIGCLICK_MOUSEUP_EVENT:
return "khtml_origclick_mouseup_event";
default:
break;
}
if (id >= numEventIds)
return DOMString();
return eventNames[id];
}
bool EventImpl::isUIEvent() const
{
return false;
}
bool EventImpl::isMouseEvent() const
{
return false;
}
bool EventImpl::isMutationEvent() const
{
return false;
}
bool EventImpl::isKeyboardEvent() const
{
return false;
}
bool EventImpl::isDragEvent() const
{
return false;
}
bool EventImpl::isClipboardEvent() const
{
return false;
}
// -----------------------------------------------------------------------------
UIEventImpl::UIEventImpl()
{
m_view = 0;
m_detail = 0;
}
UIEventImpl::UIEventImpl(EventId _id, bool canBubbleArg, bool cancelableArg,
AbstractViewImpl *viewArg, long detailArg)
: EventImpl(_id,canBubbleArg,cancelableArg)
{
m_view = viewArg;
if (m_view)
m_view->ref();
m_detail = detailArg;
}
UIEventImpl::~UIEventImpl()
{
if (m_view)
m_view->deref();
}
void UIEventImpl::initUIEvent(const DOMString &typeArg,
bool canBubbleArg,
bool cancelableArg,
const AbstractView &viewArg,
long detailArg)
{
EventImpl::initEvent(typeArg,canBubbleArg,cancelableArg);
if (m_view)
m_view->deref();
m_view = viewArg.handle();
if (m_view)
m_view->ref();
m_detail = detailArg;
}
bool UIEventImpl::isUIEvent() const
{
return true;
}
// -----------------------------------------------------------------------------
MouseEventImpl::MouseEventImpl()
{
m_screenX = 0;
m_screenY = 0;
m_clientX = 0;
m_clientY = 0;
m_ctrlKey = false;
m_altKey = false;
m_shiftKey = false;
m_metaKey = false;
m_button = 0;
m_relatedTarget = 0;
m_clipboard = 0;
}
MouseEventImpl::MouseEventImpl(EventId _id,
bool canBubbleArg,
bool cancelableArg,
AbstractViewImpl *viewArg,
long detailArg,
long screenXArg,
long screenYArg,
long clientXArg,
long clientYArg,
bool ctrlKeyArg,
bool altKeyArg,
bool shiftKeyArg,
bool metaKeyArg,
unsigned short buttonArg,
NodeImpl *relatedTargetArg,
ClipboardImpl *clipboardArg)
: UIEventImpl(_id,canBubbleArg,cancelableArg,viewArg,detailArg)
{
m_screenX = screenXArg;
m_screenY = screenYArg;
m_clientX = clientXArg;
m_clientY = clientYArg;
m_ctrlKey = ctrlKeyArg;
m_altKey = altKeyArg;
m_shiftKey = shiftKeyArg;
m_metaKey = metaKeyArg;
m_button = buttonArg;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -