dom2_events.cpp

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