KHTML
dom2_events.cpp
Go to the documentation of this file.
00001 00023 #include "dom/dom2_views.h" 00024 #include "dom/dom_exception.h" 00025 #include "xml/dom2_eventsimpl.h" 00026 #include "xml/dom_nodeimpl.h" 00027 00028 using namespace DOM; 00029 00030 EventListener::EventListener() 00031 { 00032 } 00033 00034 EventListener::~EventListener() 00035 { 00036 } 00037 00038 void EventListener::handleEvent(Event &/*evt*/) 00039 { 00040 } 00041 00042 DOMString EventListener::eventListenerType() 00043 { 00044 return ""; 00045 } 00046 00047 // ----------------------------------------------------------------------------- 00048 00049 Event::Event() 00050 { 00051 impl = 0; 00052 } 00053 00054 00055 Event::Event(const Event &other) 00056 { 00057 impl = other.impl; 00058 if (impl) impl->ref(); 00059 } 00060 00061 Event::Event(EventImpl *i) 00062 { 00063 impl = i; 00064 if (impl) impl->ref(); 00065 } 00066 00067 Event::~Event() 00068 { 00069 if (impl) impl->deref(); 00070 } 00071 00072 Event &Event::operator = (const Event &other) 00073 { 00074 if ( impl != other.impl ) { 00075 if(impl) impl->deref(); 00076 impl = other.impl; 00077 if(impl) impl->ref(); 00078 } 00079 return *this; 00080 } 00081 00082 DOMString Event::type() const 00083 { 00084 if (!impl) 00085 throw DOMException(DOMException::INVALID_STATE_ERR); 00086 00087 return impl->type(); 00088 } 00089 00090 Node Event::target() const 00091 { 00092 if (!impl) 00093 throw DOMException(DOMException::INVALID_STATE_ERR); 00094 00095 if (impl->target()->eventTargetType() == EventTargetImpl::DOM_NODE) 00096 return static_cast<DOM::NodeImpl*>(impl->target()); 00097 return 0; 00098 } 00099 00100 Node Event::currentTarget() const 00101 { 00102 if (!impl) 00103 throw DOMException(DOMException::INVALID_STATE_ERR); 00104 00105 if (impl->currentTarget()->eventTargetType() == EventTargetImpl::DOM_NODE) 00106 return static_cast<DOM::NodeImpl*>(impl->currentTarget()); 00107 return 0; 00108 } 00109 00110 unsigned short Event::eventPhase() const 00111 { 00112 if (!impl) 00113 throw DOMException(DOMException::INVALID_STATE_ERR); 00114 00115 return impl->eventPhase(); 00116 } 00117 00118 bool Event::bubbles() const 00119 { 00120 if (!impl) 00121 throw DOMException(DOMException::INVALID_STATE_ERR); 00122 00123 return impl->bubbles(); 00124 } 00125 00126 bool Event::cancelable() const 00127 { 00128 if (!impl) 00129 throw DOMException(DOMException::INVALID_STATE_ERR); 00130 00131 return impl->cancelable(); 00132 } 00133 00134 DOMTimeStamp Event::timeStamp() const 00135 { 00136 if (!impl) 00137 throw DOMException(DOMException::INVALID_STATE_ERR); 00138 00139 return impl->timeStamp(); 00140 } 00141 00142 void Event::stopPropagation() 00143 { 00144 if (!impl) 00145 throw DOMException(DOMException::INVALID_STATE_ERR); 00146 00147 impl->stopPropagation(true); 00148 } 00149 00150 void Event::preventDefault() 00151 { 00152 if (!impl) 00153 throw DOMException(DOMException::INVALID_STATE_ERR); 00154 00155 impl->preventDefault(true); 00156 } 00157 00158 void Event::initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg) 00159 { 00160 if (!impl) 00161 throw DOMException(DOMException::INVALID_STATE_ERR); 00162 00163 impl->initEvent(eventTypeArg,canBubbleArg,cancelableArg); 00164 } 00165 00166 EventImpl *Event::handle() const 00167 { 00168 return impl; 00169 } 00170 00171 bool Event::isNull() const 00172 { 00173 return (impl == 0); 00174 } 00175 00176 // ----------------------------------------------------------------------------- 00177 00178 #ifndef SAVE_SPACE 00179 00180 EventException::EventException(unsigned short _code) 00181 { 00182 code = _code; 00183 } 00184 00185 EventException::EventException(const EventException &other) 00186 { 00187 code = other.code; 00188 } 00189 00190 EventException & EventException::operator = (const EventException &other) 00191 { 00192 code = other.code; 00193 return *this; 00194 } 00195 00196 #endif 00197 00198 DOMString EventException::codeAsString() const 00199 { 00200 return codeAsString(code); 00201 } 00202 00203 bool EventException::isEventExceptionCode(int exceptioncode) 00204 { 00205 return exceptioncode >= _EXCEPTION_OFFSET && exceptioncode < _EXCEPTION_MAX; 00206 } 00207 00208 DOMString EventException::codeAsString(int code) 00209 { 00210 switch ( code ) { 00211 case UNSPECIFIED_EVENT_TYPE_ERR: 00212 return DOMString( "UNSPECIFIED_EVENT_TYPE_ERR" ); 00213 default: 00214 return DOMString( "(unknown exception code)" ); 00215 } 00216 } 00217 00218 00219 // ----------------------------------------------------------------------------- 00220 00221 UIEvent::UIEvent() : Event() 00222 { 00223 } 00224 00225 UIEvent::UIEvent(const UIEvent &other) : Event(other) 00226 { 00227 } 00228 00229 UIEvent::UIEvent(const Event &other) : Event() 00230 { 00231 (*this)=other; 00232 } 00233 00234 UIEvent::UIEvent(UIEventImpl *impl) : Event(impl) 00235 { 00236 } 00237 00238 UIEvent &UIEvent::operator = (const UIEvent &other) 00239 { 00240 Event::operator = (other); 00241 return *this; 00242 } 00243 00244 UIEvent &UIEvent::operator = (const Event &other) 00245 { 00246 Event e; 00247 e = other; 00248 if (!e.isNull() && !e.handle()->isUIEvent()) { 00249 if ( impl ) impl->deref(); 00250 impl = 0; 00251 } else 00252 Event::operator = (other); 00253 return *this; 00254 } 00255 00256 UIEvent::~UIEvent() 00257 { 00258 } 00259 00260 AbstractView UIEvent::view() const 00261 { 00262 if (!impl) 00263 throw DOMException(DOMException::INVALID_STATE_ERR); 00264 00265 return static_cast<UIEventImpl*>(impl)->view(); 00266 } 00267 00268 long UIEvent::detail() const 00269 { 00270 if (!impl) 00271 throw DOMException(DOMException::INVALID_STATE_ERR); 00272 00273 return static_cast<UIEventImpl*>(impl)->detail(); 00274 } 00275 00276 int UIEvent::keyCode() const 00277 { 00278 if ( !impl ) throw DOMException( DOMException::INVALID_STATE_ERR ); 00279 00280 return static_cast<UIEventImpl*>(impl)->keyCode(); 00281 } 00282 00283 int UIEvent::charCode() const 00284 { 00285 if (!impl) 00286 throw DOMException(DOMException::INVALID_STATE_ERR); 00287 00288 return static_cast<UIEventImpl*>(impl)->charCode(); 00289 } 00290 00291 int UIEvent::pageX() const 00292 { 00293 if (!impl) 00294 throw DOMException(DOMException::INVALID_STATE_ERR); 00295 00296 return static_cast<UIEventImpl*>(impl)->pageX(); 00297 } 00298 00299 int UIEvent::pageY() const 00300 { 00301 if (!impl) 00302 throw DOMException(DOMException::INVALID_STATE_ERR); 00303 00304 return static_cast<UIEventImpl*>(impl)->pageY(); 00305 } 00306 00307 int UIEvent::layerX() const 00308 { 00309 if( !impl ) 00310 throw DOMException( DOMException::INVALID_STATE_ERR ); 00311 00312 return static_cast<UIEventImpl*>(impl)->layerX(); 00313 } 00314 00315 int UIEvent::layerY() const 00316 { 00317 if( !impl ) 00318 throw DOMException( DOMException::INVALID_STATE_ERR ); 00319 00320 return static_cast<UIEventImpl*>(impl)->layerY(); 00321 } 00322 00323 int UIEvent::which() const 00324 { 00325 if( !impl ) throw DOMException( DOMException::INVALID_STATE_ERR ); 00326 return static_cast<UIEventImpl*>(impl)->which(); 00327 } 00328 00329 void UIEvent::initUIEvent(const DOMString &typeArg, 00330 bool canBubbleArg, 00331 bool cancelableArg, 00332 const AbstractView &viewArg, 00333 long detailArg) 00334 { 00335 if (!impl) 00336 throw DOMException(DOMException::INVALID_STATE_ERR); 00337 00338 static_cast<UIEventImpl*>(impl)->initUIEvent(typeArg,canBubbleArg,cancelableArg, 00339 viewArg.handle(),detailArg); 00340 } 00341 00342 // ----------------------------------------------------------------------------- 00343 00344 MouseEvent::MouseEvent() : UIEvent() 00345 { 00346 } 00347 00348 MouseEvent::MouseEvent(const MouseEvent &other) : UIEvent(other) 00349 { 00350 } 00351 00352 MouseEvent::MouseEvent(const Event &other) : UIEvent() 00353 { 00354 (*this)=other; 00355 } 00356 00357 MouseEvent::MouseEvent(MouseEventImpl *impl) : UIEvent(impl) 00358 { 00359 } 00360 00361 MouseEvent &MouseEvent::operator = (const MouseEvent &other) 00362 { 00363 UIEvent::operator = (other); 00364 return *this; 00365 } 00366 00367 MouseEvent &MouseEvent::operator = (const Event &other) 00368 { 00369 Event e; 00370 e = other; 00371 if (!e.isNull() && !e.handle()->isMouseEvent()) { 00372 if ( impl ) impl->deref(); 00373 impl = 0; 00374 } else 00375 UIEvent::operator = (other); 00376 return *this; 00377 } 00378 00379 MouseEvent::~MouseEvent() 00380 { 00381 } 00382 00383 long MouseEvent::screenX() const 00384 { 00385 if (!impl) 00386 throw DOMException(DOMException::INVALID_STATE_ERR); 00387 00388 return static_cast<MouseEventImpl*>(impl)->screenX(); 00389 } 00390 00391 long MouseEvent::screenY() const 00392 { 00393 if (!impl) 00394 throw DOMException(DOMException::INVALID_STATE_ERR); 00395 00396 return static_cast<MouseEventImpl*>(impl)->screenY(); 00397 } 00398 00399 long MouseEvent::clientX() const 00400 { 00401 if (!impl) 00402 throw DOMException(DOMException::INVALID_STATE_ERR); 00403 00404 return static_cast<MouseEventImpl*>(impl)->clientX(); 00405 } 00406 00407 long MouseEvent::clientY() const 00408 { 00409 if (!impl) 00410 throw DOMException(DOMException::INVALID_STATE_ERR); 00411 00412 return static_cast<MouseEventImpl*>(impl)->clientY(); 00413 } 00414 00415 bool MouseEvent::ctrlKey() const 00416 { 00417 if (!impl) 00418 throw DOMException(DOMException::INVALID_STATE_ERR); 00419 00420 return static_cast<MouseEventImpl*>(impl)->ctrlKey(); 00421 } 00422 00423 bool MouseEvent::shiftKey() const 00424 { 00425 if (!impl) 00426 throw DOMException(DOMException::INVALID_STATE_ERR); 00427 00428 return static_cast<MouseEventImpl*>(impl)->shiftKey(); 00429 } 00430 00431 bool MouseEvent::altKey() const 00432 { 00433 if (!impl) 00434 throw DOMException(DOMException::INVALID_STATE_ERR); 00435 00436 return static_cast<MouseEventImpl*>(impl)->altKey(); 00437 } 00438 00439 bool MouseEvent::metaKey() const 00440 { 00441 if (!impl) 00442 throw DOMException(DOMException::INVALID_STATE_ERR); 00443 00444 return static_cast<MouseEventImpl*>(impl)->metaKey(); 00445 } 00446 00447 unsigned short MouseEvent::button() const 00448 { 00449 if (!impl) 00450 throw DOMException(DOMException::INVALID_STATE_ERR); 00451 00452 return static_cast<MouseEventImpl*>(impl)->button(); 00453 } 00454 00455 Node MouseEvent::relatedTarget() const 00456 { 00457 if (!impl) 00458 throw DOMException(DOMException::INVALID_STATE_ERR); 00459 00460 return static_cast<MouseEventImpl*>(impl)->relatedTarget(); 00461 } 00462 00463 void MouseEvent::initMouseEvent(const DOMString &typeArg, 00464 bool canBubbleArg, 00465 bool cancelableArg, 00466 const AbstractView &viewArg, 00467 long detailArg, 00468 long screenXArg, 00469 long screenYArg, 00470 long clientXArg, 00471 long clientYArg, 00472 bool ctrlKeyArg, 00473 bool altKeyArg, 00474 bool shiftKeyArg, 00475 bool metaKeyArg, 00476 unsigned short buttonArg, 00477 const Node &relatedTargetArg) 00478 { 00479 if (!impl) 00480 throw DOMException(DOMException::INVALID_STATE_ERR); 00481 00482 static_cast<MouseEventImpl*>(impl)->initMouseEvent(typeArg,canBubbleArg, 00483 cancelableArg,viewArg.handle(),detailArg,screenXArg,screenYArg,clientXArg, 00484 clientYArg,ctrlKeyArg,altKeyArg,shiftKeyArg,metaKeyArg,buttonArg, 00485 relatedTargetArg); 00486 } 00487 00488 // ----------------------------------------------------------------------------- 00489 00490 TextEvent::TextEvent() : UIEvent() 00491 { 00492 } 00493 00494 TextEvent::TextEvent(const TextEvent &other) : UIEvent(other) 00495 { 00496 } 00497 00498 TextEvent::TextEvent(const Event &other) : UIEvent() 00499 { 00500 (*this)=other; 00501 } 00502 00503 TextEvent &TextEvent::operator = (const TextEvent &other) 00504 { 00505 UIEvent::operator = (other); 00506 return *this; 00507 } 00508 00509 TextEvent &TextEvent::operator = (const Event &other) 00510 { 00511 Event e; 00512 e = other; 00513 if (!e.isNull() && !e.handle()->isTextInputEvent()) { 00514 if ( impl ) impl->deref(); 00515 impl = 0; 00516 } else 00517 UIEvent::operator = (other); 00518 return *this; 00519 } 00520 00521 TextEvent::~TextEvent() 00522 { 00523 } 00524 00525 void TextEvent::initTextEvent(const DOMString &typeArg, 00526 bool canBubbleArg, 00527 bool cancelableArg, 00528 const AbstractView &viewArg, 00529 const DOMString &dataArg) 00530 { 00531 static_cast<TextEventImpl*>(impl)->initTextEvent( 00532 typeArg, canBubbleArg, cancelableArg, viewArg.handle(), dataArg); 00533 } 00534 // ----------------------------------------------------------------------------- 00535 00536 KeyboardEvent::KeyboardEvent() : UIEvent() 00537 { 00538 } 00539 00540 KeyboardEvent::KeyboardEvent(const KeyboardEvent &other) : UIEvent(other) 00541 { 00542 } 00543 00544 KeyboardEvent::KeyboardEvent(const Event &other) : UIEvent() 00545 { 00546 (*this)=other; 00547 } 00548 00549 KeyboardEvent &KeyboardEvent::operator = (const KeyboardEvent &other) 00550 { 00551 UIEvent::operator = (other); 00552 return *this; 00553 } 00554 00555 KeyboardEvent &KeyboardEvent::operator = (const Event &other) 00556 { 00557 Event e; 00558 e = other; 00559 if (!e.isNull() && !e.handle()->isKeyboardEvent()) { 00560 if ( impl ) impl->deref(); 00561 impl = 0; 00562 } else 00563 UIEvent::operator = (other); 00564 return *this; 00565 } 00566 00567 KeyboardEvent::~KeyboardEvent() 00568 { 00569 } 00570 00571 DOMString KeyboardEvent::keyIdentifier() const 00572 { 00573 return static_cast<const KeyboardEventImpl*>(impl)->keyIdentifier(); 00574 } 00575 00576 unsigned long KeyboardEvent::keyLocation() const 00577 { 00578 return static_cast<const KeyboardEventImpl*>(impl)->keyLocation(); 00579 } 00580 00581 bool KeyboardEvent::ctrlKey() const 00582 { 00583 return static_cast<const KeyboardEventImpl*>(impl)->ctrlKey(); 00584 } 00585 00586 bool KeyboardEvent::shiftKey() const 00587 { 00588 return static_cast<const KeyboardEventImpl*>(impl)->shiftKey(); 00589 } 00590 00591 bool KeyboardEvent::altKey() const 00592 { 00593 return static_cast<const KeyboardEventImpl*>(impl)->altKey(); 00594 } 00595 00596 bool KeyboardEvent::metaKey() const 00597 { 00598 return static_cast<const KeyboardEventImpl*>(impl)->metaKey(); 00599 } 00600 00601 bool KeyboardEvent::getModifierState(DOMString keyIdentifierArg) const 00602 { 00603 return static_cast<const KeyboardEventImpl*>(impl)->getModifierState(keyIdentifierArg); 00604 } 00605 00606 void KeyboardEvent::initKeyboardEvent(DOMString typeArg, 00607 bool canBubbleArg, 00608 bool cancelableArg, 00609 AbstractView viewArg, 00610 DOMString keyIdentifierArg, 00611 unsigned long keyLocationArg, 00612 DOMString modifiersList) 00613 { 00614 static_cast<KeyboardEventImpl*>(impl)->initKeyboardEvent(typeArg, 00615 canBubbleArg, cancelableArg, viewArg.handle(), keyIdentifierArg, keyLocationArg, modifiersList); 00616 } 00617 00618 00619 // ----------------------------------------------------------------------------- 00620 00621 MutationEvent::MutationEvent() : Event() 00622 { 00623 } 00624 00625 MutationEvent::MutationEvent(const MutationEvent &other) : Event(other) 00626 { 00627 } 00628 00629 MutationEvent::MutationEvent(const Event &other) : Event() 00630 { 00631 (*this)=other; 00632 } 00633 00634 MutationEvent::MutationEvent(MutationEventImpl *impl) : Event(impl) 00635 { 00636 } 00637 00638 MutationEvent &MutationEvent::operator = (const MutationEvent &other) 00639 { 00640 Event::operator = (other); 00641 return *this; 00642 } 00643 00644 MutationEvent &MutationEvent::operator = (const Event &other) 00645 { 00646 Event e; 00647 e = other; 00648 if (!e.isNull() && !e.handle()->isMutationEvent()) { 00649 if ( impl ) impl->deref(); 00650 impl = 0; 00651 } else 00652 Event::operator = (other); 00653 return *this; 00654 } 00655 00656 MutationEvent::~MutationEvent() 00657 { 00658 } 00659 00660 Node MutationEvent::relatedNode() const 00661 { 00662 if (!impl) 00663 throw DOMException(DOMException::INVALID_STATE_ERR); 00664 00665 return static_cast<MutationEventImpl*>(impl)->relatedNode(); 00666 } 00667 00668 DOMString MutationEvent::prevValue() const 00669 { 00670 if (!impl) 00671 throw DOMException(DOMException::INVALID_STATE_ERR); 00672 00673 return static_cast<MutationEventImpl*>(impl)->prevValue(); 00674 } 00675 00676 DOMString MutationEvent::newValue() const 00677 { 00678 if (!impl) 00679 throw DOMException(DOMException::INVALID_STATE_ERR); 00680 00681 return static_cast<MutationEventImpl*>(impl)->newValue(); 00682 } 00683 00684 DOMString MutationEvent::attrName() const 00685 { 00686 if (!impl) 00687 throw DOMException(DOMException::INVALID_STATE_ERR); 00688 00689 return static_cast<MutationEventImpl*>(impl)->attrName(); 00690 } 00691 00692 unsigned short MutationEvent::attrChange() const 00693 { 00694 if (!impl) 00695 throw DOMException(DOMException::INVALID_STATE_ERR); 00696 00697 return static_cast<MutationEventImpl*>(impl)->attrChange(); 00698 } 00699 00700 void MutationEvent::initMutationEvent(const DOMString &typeArg, 00701 bool canBubbleArg, 00702 bool cancelableArg, 00703 const Node &relatedNodeArg, 00704 const DOMString &prevValueArg, 00705 const DOMString &newValueArg, 00706 const DOMString &attrNameArg, 00707 unsigned short attrChangeArg) 00708 { 00709 if (!impl) 00710 throw DOMException(DOMException::INVALID_STATE_ERR); 00711 00712 static_cast<MutationEventImpl*>(impl)->initMutationEvent(typeArg, 00713 canBubbleArg,cancelableArg,relatedNodeArg,prevValueArg, 00714 newValueArg,attrNameArg,attrChangeArg); 00715 } 00716 00717
KDE 4.6 API Reference