📄 kjs_events.cpp
字号:
args[9].toBoolean(exec), // ctrlKeyArg
args[10].toBoolean(exec), // altKeyArg
args[11].toBoolean(exec), // shiftKeyArg
args[12].toBoolean(exec), // metaKeyArg
args[13].toInt32(exec), // buttonArg
toNode(args[14])); // relatedTargetArg
return Undefined();
}
return Undefined();
}
// -------------------------------------------------------------------------
const ClassInfo DOMKeyboardEvent::info = { "KeyboardEvent", &DOMUIEvent::info, &DOMKeyboardEventTable, 0 };
/*
@begin DOMKeyboardEventTable 5
keyIdentifier DOMKeyboardEvent::KeyIdentifier DontDelete|ReadOnly
keyLocation DOMKeyboardEvent::KeyLocation DontDelete|ReadOnly
ctrlKey DOMKeyboardEvent::CtrlKey DontDelete|ReadOnly
shiftKey DOMKeyboardEvent::ShiftKey DontDelete|ReadOnly
altKey DOMKeyboardEvent::AltKey DontDelete|ReadOnly
metaKey DOMKeyboardEvent::MetaKey DontDelete|ReadOnly
altGraphKey DOMKeyboardEvent::AltGraphKey DontDelete|ReadOnly
@end
@begin DOMKeyboardEventProtoTable 1
initKeyboardEvent DOMKeyboardEvent::InitKeyboardEvent DontDelete|Function 11
@end
*/
DEFINE_PROTOTYPE("DOMKeyboardEvent", DOMKeyboardEventProto)
IMPLEMENT_PROTOFUNC(DOMKeyboardEventProtoFunc)
IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMKeyboardEventProto, DOMKeyboardEventProtoFunc, DOMUIEventProto)
DOMKeyboardEvent::~DOMKeyboardEvent()
{
}
const ClassInfo* DOMKeyboardEvent::classInfo() const
{
return &info;
}
Value DOMKeyboardEvent::tryGet(ExecState *exec, const Identifier &p) const
{
#ifdef KJS_VERBOSE
kdDebug(6070) << "DOMKeyboardEvent::tryGet " << p.qstring() << endl;
#endif
return DOMObjectLookupGetValue<DOMKeyboardEvent, DOMUIEvent>(exec, p, &DOMKeyboardEventTable, this);
}
Value DOMKeyboardEvent::getValueProperty(ExecState *exec, int token) const
{
switch (token) {
case KeyIdentifier:
return String(static_cast<KeyboardEvent>(event).keyIdentifier());
case KeyLocation:
return Number(static_cast<KeyboardEvent>(event).keyLocation());
case CtrlKey:
return Boolean(static_cast<KeyboardEvent>(event).ctrlKey());
case ShiftKey:
return Boolean(static_cast<KeyboardEvent>(event).shiftKey());
case AltKey:
return Boolean(static_cast<KeyboardEvent>(event).altKey());
case MetaKey:
return Boolean(static_cast<KeyboardEvent>(event).metaKey());
case AltGraphKey:
return Boolean(static_cast<KeyboardEvent>(event).altGraphKey());
default:
kdWarning() << "Unhandled token in DOMKeyboardEvent::getValueProperty : " << token << endl;
return Value();
}
}
Value DOMKeyboardEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
if (!thisObj.inherits(&DOMKeyboardEvent::info)) {
Object err = Error::create(exec,TypeError);
exec->setException(err);
return err;
}
KeyboardEvent event = static_cast<DOMKeyboardEvent *>(thisObj.imp())->toKeyboardEvent();
switch (id) {
case DOMKeyboardEvent::InitKeyboardEvent:
event.initKeyboardEvent(args[0].toString(exec).string(), // typeArg
args[1].toBoolean(exec), // canBubbleArg
args[2].toBoolean(exec), // cancelableArg
toAbstractView(args[3]), // viewArg
args[4].toString(exec).string(), // keyIdentifier
args[5].toInt32(exec), // keyLocationArg
args[6].toBoolean(exec), // ctrlKeyArg
args[7].toBoolean(exec), // altKeyArg
args[8].toBoolean(exec), // shiftKeyArg
args[9].toBoolean(exec), // metaKeyArg
args[10].toBoolean(exec)); // altGraphKeyArg
return Undefined();
}
return Undefined();
}
// -------------------------------------------------------------------------
const ClassInfo MutationEventConstructor::info = { "MutationEventConstructor", 0, &MutationEventConstructorTable, 0 };
/*
@begin MutationEventConstructorTable 3
MODIFICATION DOM::MutationEvent::MODIFICATION DontDelete|ReadOnly
ADDITION DOM::MutationEvent::ADDITION DontDelete|ReadOnly
REMOVAL DOM::MutationEvent::REMOVAL DontDelete|ReadOnly
@end
*/
Value MutationEventConstructor::tryGet(ExecState *exec, const Identifier &p) const
{
return DOMObjectLookupGetValue<MutationEventConstructor,DOMObject>(exec,p,&MutationEventConstructorTable,this);
}
Value MutationEventConstructor::getValueProperty(ExecState *, int token) const
{
// We use the token as the value to return directly
return Number(token);
}
Value KJS::getMutationEventConstructor(ExecState *exec)
{
return cacheGlobalObject<MutationEventConstructor>(exec, "[[mutationEvent.constructor]]");
}
// -------------------------------------------------------------------------
const ClassInfo DOMMutationEvent::info = { "MutationEvent", &DOMEvent::info, &DOMMutationEventTable, 0 };
/*
@begin DOMMutationEventTable 5
relatedNode DOMMutationEvent::RelatedNode DontDelete|ReadOnly
prevValue DOMMutationEvent::PrevValue DontDelete|ReadOnly
newValue DOMMutationEvent::NewValue DontDelete|ReadOnly
attrName DOMMutationEvent::AttrName DontDelete|ReadOnly
attrChange DOMMutationEvent::AttrChange DontDelete|ReadOnly
@end
@begin DOMMutationEventProtoTable 1
initMutationEvent DOMMutationEvent::InitMutationEvent DontDelete|Function 8
@end
*/
DEFINE_PROTOTYPE("DOMMutationEvent",DOMMutationEventProto)
IMPLEMENT_PROTOFUNC(DOMMutationEventProtoFunc)
IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMMutationEventProto,DOMMutationEventProtoFunc,DOMEventProto)
DOMMutationEvent::~DOMMutationEvent()
{
}
Value DOMMutationEvent::tryGet(ExecState *exec, const Identifier &p) const
{
return DOMObjectLookupGetValue<DOMMutationEvent,DOMEvent>(exec,p,&DOMMutationEventTable,this);
}
Value DOMMutationEvent::getValueProperty(ExecState *exec, int token) const
{
switch (token) {
case RelatedNode:
return getDOMNode(exec,static_cast<DOM::MutationEvent>(event).relatedNode());
case PrevValue:
return String(static_cast<DOM::MutationEvent>(event).prevValue());
case NewValue:
return String(static_cast<DOM::MutationEvent>(event).newValue());
case AttrName:
return String(static_cast<DOM::MutationEvent>(event).attrName());
case AttrChange:
return Number((unsigned int)static_cast<DOM::MutationEvent>(event).attrChange());
default:
kdWarning() << "Unhandled token in DOMMutationEvent::getValueProperty : " << token << endl;
return Value();
}
}
Value DOMMutationEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
if (!thisObj.inherits(&KJS::DOMMutationEvent::info)) {
Object err = Error::create(exec,TypeError);
exec->setException(err);
return err;
}
DOM::MutationEvent mutationEvent = static_cast<DOMMutationEvent *>(thisObj.imp())->toMutationEvent();
switch (id) {
case DOMMutationEvent::InitMutationEvent:
mutationEvent.initMutationEvent(args[0].toString(exec).string(), // typeArg,
args[1].toBoolean(exec), // canBubbleArg
args[2].toBoolean(exec), // cancelableArg
toNode(args[3]), // relatedNodeArg
args[4].toString(exec).string(), // prevValueArg
args[5].toString(exec).string(), // newValueArg
args[6].toString(exec).string(), // attrNameArg
args[7].toInt32(exec)); // attrChangeArg
return Undefined();
}
return Undefined();
}
// -------------------------------------------------------------------------
const ClassInfo Clipboard::info = { "Clipboard", 0, &ClipboardTable, 0 };
/* Source for ClipboardTable. Use "make hashtables" to regenerate.
@begin ClipboardTable 3
dropEffect Clipboard::DropEffect DontDelete
effectAllowed Clipboard::EffectAllowed DontDelete
types Clipboard::Types DontDelete|ReadOnly
@end
@begin ClipboardProtoTable 4
clearData Clipboard::ClearData DontDelete|Function 0
getData Clipboard::GetData DontDelete|Function 1
setData Clipboard::SetData DontDelete|Function 2
setDragImage Clipboard::SetDragImage DontDelete|Function 3
@end
*/
DEFINE_PROTOTYPE("Clipboard", ClipboardProto)
IMPLEMENT_PROTOFUNC(ClipboardProtoFunc)
IMPLEMENT_PROTOTYPE(ClipboardProto, ClipboardProtoFunc)
Clipboard::Clipboard(ExecState *exec, DOM::ClipboardImpl *cb)
: DOMObject(ClipboardProto::self(exec)), clipboard(cb)
{
if (clipboard)
clipboard->ref();
}
Clipboard::~Clipboard()
{
if (clipboard)
clipboard->deref();
}
static Value stringOrUndefined(const DOM::DOMString &str)
{
if (str.isNull()) {
return Undefined();
} else {
return String(str);
}
}
Value Clipboard::tryGet(ExecState *exec, const Identifier &propertyName) const
{
return DOMObjectLookupGetValue<Clipboard,DOMObject>(exec, propertyName, &ClipboardTable, this);
}
Value Clipboard::getValueProperty(ExecState *exec, int token) const
{
switch (token) {
case DropEffect:
assert(clipboard->isForDragging() || clipboard->dropEffect().isNull());
return stringOrUndefined(clipboard->dropEffect());
case EffectAllowed:
assert(clipboard->isForDragging() || clipboard->effectAllowed().isNull());
return stringOrUndefined(clipboard->effectAllowed());
case Types:
{
QStringList qTypes = clipboard->types();
if (qTypes.isEmpty()) {
return Null();
} else {
List list;
for (QStringList::Iterator it = qTypes.begin(); it != qTypes.end(); ++it) {
list.append(String(UString(*it)));
}
return exec->lexicalInterpreter()->builtinArray().construct(exec, list);
}
}
default:
kdWarning() << "Clipboard::getValueProperty unhandled token " << token << endl;
return Value();
}
}
void Clipboard::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
{
DOMObjectLookupPut<Clipboard,DOMObject>(exec, propertyName, value, attr, &ClipboardTable, this );
}
void Clipboard::putValue(ExecState *exec, int token, const Value& value, int /*attr*/)
{
switch (token) {
case DropEffect:
// can never set this when not for dragging, thus getting always returns NULL string
if (clipboard->isForDragging())
clipboard->setDropEffect(value.toString(exec).string());
break;
case EffectAllowed:
// can never set this when not for dragging, thus getting always returns NULL string
if (clipboard->isForDragging())
clipboard->setEffectAllowed(value.toString(exec).string());
break;
default:
kdWarning() << "Clipboard::putValue unhandled token " << token << endl;
}
}
Value ClipboardProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
if (!thisObj.inherits(&KJS::Clipboard::info)) {
Object err = Error::create(exec,TypeError);
exec->setException(err);
return err;
}
Clipboard *cb = static_cast<Clipboard *>(thisObj.imp());
switch (id) {
case Clipboard::ClearData:
if (args.size() == 0) {
cb->clipboard->clearAllData();
return Undefined();
} else if (args.size() == 1) {
cb->clipboard->clearData(args[0].toString(exec).string());
return Undefined();
} else {
Object err = Error::create(exec,SyntaxError,"clearData: Invalid number of arguments");
exec->setException(err);
return err;
}
case Clipboard::GetData:
{
if (args.size() == 1) {
bool success;
DOM::DOMString result = cb->clipboard->getData(args[0].toString(exec).string(), success);
if (success) {
return String(result);
} else {
return Undefined();
}
} else {
Object err = Error::create(exec,SyntaxError,"getData: Invalid number of arguments");
exec->setException(err);
return err;
}
}
case Clipboard::SetData:
if (args.size() == 2) {
return Boolean(cb->clipboard->setData(args[0].toString(exec).string(), args[1].toString(exec).string()));
} else {
Object err = Error::create(exec,SyntaxError,"setData: Invalid number of arguments");
exec->setException(err);
return err;
}
case Clipboard::SetDragImage:
{
if (!cb->clipboard->isForDragging()) {
return Undefined();
}
if (args.size() != 3) {
Object err = Error::create(exec, SyntaxError,"setDragImage: Invalid number of arguments");
exec->setException(err);
return err;
}
int x = (int)args[1].toNumber(exec);
int y = (int)args[2].toNumber(exec);
// See if they passed us a node
DOM::Node node = toNode(args[0]);
if (!node.isNull()) {
if (node.nodeType() == DOM::Node::ELEMENT_NODE) {
cb->clipboard->setDragImageElement(node, QPoint(x,y));
return Undefined();
} else {
Object err = Error::create(exec, SyntaxError,"setDragImageFromElement: Invalid first argument");
exec->setException(err);
return err;
}
}
// See if they passed us an Image object
ObjectImp *o = static_cast<ObjectImp*>(args[0].imp());
if (o->inherits(&Image::info)) {
Image *JSImage = static_cast<Image*>(o);
cb->clipboard->setDragImage(JSImage->image()->pixmap(), QPoint(x,y));
return Undefined();
} else {
Object err = Error::create(exec,TypeError);
exec->setException(err);
return err;
}
}
}
return Undefined();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -