📄 kjs_events.cpp
字号:
}Value DOMMouseEvent::getValueProperty(ExecState *exec, int token) const{ switch (token) { case ScreenX: return Number(static_cast<DOM::MouseEvent>(event).screenX()); case ScreenY: return Number(static_cast<DOM::MouseEvent>(event).screenY()); case ClientX: case X: return Number(static_cast<DOM::MouseEvent>(event).clientX()); case ClientY: case Y: return Number(static_cast<DOM::MouseEvent>(event).clientY()); case OffsetX: case OffsetY: // MSIE extension { DOM::Node node = event.target(); node.handle()->getDocument()->updateRendering(); khtml::RenderObject *rend = node.handle() ? node.handle()->renderer() : 0L; int x = static_cast<DOM::MouseEvent>(event).clientX(); int y = static_cast<DOM::MouseEvent>(event).clientY(); if ( rend ) { int xPos, yPos; if ( rend->absolutePosition( xPos, yPos ) ) { kdDebug() << "DOMMouseEvent::getValueProperty rend=" << rend << " xPos=" << xPos << " yPos=" << yPos << endl; x -= xPos; y -= yPos; } if ( rend->canvas() ) { int cYPos, cXPos; rend->canvas()->absolutePosition( cXPos, cYPos, true ); x += cXPos; y += cYPos; } } return Number( token == OffsetX ? x : y ); } case CtrlKey: return Boolean(static_cast<DOM::MouseEvent>(event).ctrlKey()); case ShiftKey: return Boolean(static_cast<DOM::MouseEvent>(event).shiftKey()); case AltKey: return Boolean(static_cast<DOM::MouseEvent>(event).altKey()); case MetaKey: return Boolean(static_cast<DOM::MouseEvent>(event).metaKey()); case Button: { if ( exec->interpreter()->compatMode() == Interpreter::NetscapeCompat ) { return Number(static_cast<DOM::MouseEvent>(event).button()); } // Tricky. The DOM (and khtml) use 0 for LMB, 1 for MMB and 2 for RMB // but MSIE uses 1=LMB, 2=RMB, 4=MMB, as a bitfield int domButton = static_cast<DOM::MouseEvent>(event).button(); int button = domButton==0 ? 1 : domButton==1 ? 4 : domButton==2 ? 2 : 0; return Number( (unsigned int)button ); } case ToElement: // MSIE extension - "the object toward which the user is moving the mouse pointer" if (event.handle()->id() == DOM::EventImpl::MOUSEOUT_EVENT) return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).relatedTarget()); return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).target()); case FromElement: // MSIE extension - "object from which activation // or the mouse pointer is exiting during the event" (huh?) if (event.handle()->id() == DOM::EventImpl::MOUSEOUT_EVENT) return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).target()); /* fall through */ case RelatedTarget: return getDOMNode(exec,static_cast<DOM::MouseEvent>(event).relatedTarget()); default: kdDebug(6070) << "WARNING: Unhandled token in DOMMouseEvent::getValueProperty : " << token << endl; return Value(); }}Value DOMMouseEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){ KJS_CHECK_THIS( KJS::DOMMouseEvent, thisObj ); DOM::MouseEvent mouseEvent = static_cast<DOMMouseEvent *>(thisObj.imp())->toMouseEvent(); switch (id) { case DOMMouseEvent::InitMouseEvent: mouseEvent.initMouseEvent(args[0].toString(exec).string(), // typeArg args[1].toBoolean(exec), // canBubbleArg args[2].toBoolean(exec), // cancelableArg toAbstractView(args[3]), // viewArg args[4].toInteger(exec), // detailArg args[5].toInteger(exec), // screenXArg args[6].toInteger(exec), // screenYArg args[7].toInteger(exec), // clientXArg args[8].toInteger(exec), // clientYArg args[9].toBoolean(exec), // ctrlKeyArg args[10].toBoolean(exec), // altKeyArg args[11].toBoolean(exec), // shiftKeyArg args[12].toBoolean(exec), // metaKeyArg args[13].toInteger(exec), // buttonArg toNode(args[14])); // relatedTargetArg return Undefined(); } return Undefined();}// -------------------------------------------------------------------------const ClassInfo DOMTextEvent::info = { "TextEvent", &DOMUIEvent::info, &DOMTextEventTable, 0 };/*@begin DOMTextEventTable 5 keyVal DOMTextEvent::Key DontDelete|ReadOnly virtKeyVal DOMTextEvent::VirtKey DontDelete|ReadOnly outputString DOMTextEvent::OutputString DontDelete|ReadOnly inputGenerated DOMTextEvent::InputGenerated DontDelete|ReadOnly numPad DOMTextEvent::NumPad DontDelete|ReadOnly # actually belonging to KeyboardEvent ctrlKey DOMTextEvent::CtrlKey DontDelete|ReadOnly altKey DOMTextEvent::AltKey DontDelete|ReadOnly shiftKey DOMTextEvent::ShiftKey DontDelete|ReadOnly altKey DOMTextEvent::AltKey DontDelete|ReadOnly@end@begin DOMTextEventProtoTable 1 initTextEvent DOMTextEvent::InitTextEvent DontDelete|Function 10 # Missing: initTextEventNS, initModifier@end*/DEFINE_PROTOTYPE("DOMTextEvent",DOMTextEventProto)IMPLEMENT_PROTOFUNC_DOM(DOMTextEventProtoFunc)IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMTextEventProto,DOMTextEventProtoFunc,DOMUIEventProto)DOMTextEvent::DOMTextEvent(ExecState *exec, DOM::TextEvent ke) : DOMUIEvent(DOMTextEventProto::self(exec), ke) {}DOMTextEvent::~DOMTextEvent(){}Value DOMTextEvent::tryGet(ExecState *exec, const Identifier &p) const{#ifdef KJS_VERBOSE kdDebug(6070) << "DOMTextEvent::tryGet " << p.qstring() << endl;#endif return DOMObjectLookupGetValue<DOMTextEvent,DOMUIEvent>(exec,p,&DOMTextEventTable,this);}Value DOMTextEvent::getValueProperty(ExecState *, int token) const{ // ### KDE 4: use const reference DOM::TextEvent tevent = static_cast<DOM::TextEvent>(event); switch (token) { case Key: return Number(tevent.keyVal()); case VirtKey: return Number(tevent.virtKeyVal()); case OutputString: return String(tevent.outputString()); case InputGenerated: return Boolean(tevent.inputGenerated()); case NumPad: return Boolean(tevent.numPad()); // these modifier attributes actually belong into a KeyboardEvent interface case CtrlKey: return Boolean(tevent.checkModifier(Qt::ControlButton)); case ShiftKey: return Boolean(tevent.checkModifier(Qt::ShiftButton)); case AltKey: return Boolean(tevent.checkModifier(Qt::AltButton)); case MetaKey: return Boolean(tevent.checkModifier(Qt::MetaButton)); default: kdDebug(6070) << "WARNING: Unhandled token in DOMTextEvent::getValueProperty : " << token << endl; return KJS::Undefined(); }}Value DOMTextEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){ KJS_CHECK_THIS( KJS::DOMTextEvent, thisObj ); DOM::TextEvent keyEvent = static_cast<DOMTextEvent *>(thisObj.imp())->toTextEvent(); switch (id) { case DOMTextEvent::InitTextEvent: keyEvent.initTextEvent(args[0].toString(exec).string(), // typeArg args[1].toBoolean(exec), // canBubbleArg args[2].toBoolean(exec), // cancelableArg toAbstractView(args[3]), // viewArg args[4].toInteger(exec), // detailArg args[5].toString(exec).string(), // outputStringArg args[6].toInteger(exec), // keyValArg args[7].toInteger(exec), // virtKeyValArg args[8].toBoolean(exec), // inputGeneratedArg args[9].toBoolean(exec));// numPadArg 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*/MutationEventConstructor::MutationEventConstructor(ExecState* exec) : DOMObject(exec->interpreter()->builtinObjectPrototype()){}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_DOM(DOMMutationEventProtoFunc)IMPLEMENT_PROTOTYPE_WITH_PARENT(DOMMutationEventProto,DOMMutationEventProtoFunc,DOMEventProto)DOMMutationEvent::DOMMutationEvent(ExecState *exec, DOM::MutationEvent me) : DOMEvent(DOMMutationEventProto::self(exec), me) {}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: kdDebug(6070) << "WARNING: Unhandled token in DOMMutationEvent::getValueProperty : " << token << endl; return Value(); }}Value DOMMutationEventProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){ KJS_CHECK_THIS( KJS::DOMMutationEvent, thisObj ); 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].toInteger(exec)); // attrChangeArg return Undefined(); } return Undefined();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -