• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

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 
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     {
00321         // return 0 unless the key has an ascii value
00322         if ( static_cast<KeyEventBaseImpl*>( impl )->keyVal() )
00323             return static_cast<KeyEventBaseImpl*>( impl )->keyCode();
00324     }
00325     
00326     return 0;
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,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,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(KeyEventBaseImpl *impl) : UIEvent(impl)
00504 {
00505 }
00506 
00507 TextEvent &TextEvent::operator = (const TextEvent &other)
00508 {
00509     UIEvent::operator = (other);
00510     return *this;
00511 }
00512 
00513 TextEvent &TextEvent::operator = (const Event &other)
00514 {
00515     Event e;
00516     e = other;
00517     if (!e.isNull() && !(e.handle()->isTextInputEvent() || e.handle()->isKeyboardEvent())) {
00518     if ( impl ) impl->deref();
00519     impl = 0;
00520     } else
00521     UIEvent::operator = (other);
00522     return *this;
00523 }
00524 
00525 TextEvent::~TextEvent()
00526 {
00527 }
00528 
00529 void TextEvent::initTextEvent(const DOMString &typeArg,
00530         bool canBubbleArg,
00531         bool cancelableArg,
00532         const AbstractView &viewArg,
00533         long /*detailArg*/,
00534         const DOMString &outputStringArg,
00535         unsigned long keyValArg,
00536         unsigned long virtKeyValArg,
00537         bool /*inputGeneratedArg*/,
00538         bool numPadArg)
00539 {
00540     if (!impl)
00541     throw DOMException(DOMException::INVALID_STATE_ERR);
00542 
00543     if (impl->isTextInputEvent()) {
00544         //Initialize based on the outputStringArg or virtKeyValArg.
00545         QString text = outputStringArg.string();
00546         if (outputStringArg.length() == 0 && virtKeyValArg) {
00547             text += QChar((unsigned short)virtKeyValArg);
00548         }
00549 
00550         TextEventImpl* tImpl = static_cast<TextEventImpl*>(impl);
00551         tImpl->initTextEvent(typeArg, canBubbleArg, cancelableArg, viewArg, text);
00552     } else {
00553         KeyboardEventImpl* kbImpl = static_cast<KeyboardEventImpl*>(impl);
00554         kbImpl->initKeyboardEvent(typeArg, canBubbleArg, cancelableArg, viewArg,
00555             keyValArg, virtKeyValArg, 0, numPadArg ?
00556                 KeyboardEventImpl::DOM_KEY_LOCATION_NUMPAD : KeyboardEventImpl::DOM_KEY_LOCATION_STANDARD);
00557     }
00558 }
00559 
00560 unsigned long TextEvent::keyVal() const
00561 {
00562     if (!impl)
00563     throw DOMException(DOMException::INVALID_STATE_ERR);
00564 
00565     return static_cast<KeyEventBaseImpl*>(impl)->keyVal();
00566 }
00567 
00568 DOMString TextEvent::outputString() const
00569 {
00570     if (!impl)
00571     throw DOMException(DOMException::INVALID_STATE_ERR);
00572 
00573     KeyEventBaseImpl* ke = static_cast<KeyEventBaseImpl*>(impl);
00574     if (ke->isTextInputEvent())
00575         return static_cast<TextEventImpl*>(ke)->data();
00576     else {
00577         if (ke->keyVal())
00578             return QString(QChar((ushort)ke->keyVal()));
00579         else
00580             return DOMString();
00581     }
00582 }
00583 
00584 unsigned long TextEvent::virtKeyVal() const
00585 {
00586     if (!impl)
00587     throw DOMException(DOMException::INVALID_STATE_ERR);
00588 
00589     return static_cast<KeyEventBaseImpl*>(impl)->virtKeyVal();
00590 }
00591 
00592 void TextEvent::initModifier(unsigned long modifierArg, bool valueArg)
00593 {
00594     if (!impl)
00595     throw DOMException(DOMException::INVALID_STATE_ERR);
00596 
00597     return static_cast<KeyEventBaseImpl*>(impl)->initModifier(modifierArg,valueArg);
00598 }
00599 
00600 bool TextEvent::checkModifier(unsigned long modifierArg)
00601 {
00602     if (!impl)
00603     throw DOMException(DOMException::INVALID_STATE_ERR);
00604 
00605     return static_cast<KeyEventBaseImpl*>(impl)->checkModifier(modifierArg);
00606 }
00607 
00608 bool TextEvent::inputGenerated() const
00609 {
00610     if (!impl)
00611     throw DOMException(DOMException::INVALID_STATE_ERR);
00612 
00613     return static_cast<KeyEventBaseImpl*>(impl)->inputGenerated();
00614 }
00615 
00616 bool TextEvent::numPad() const
00617 {
00618     if (!impl)
00619     throw DOMException(DOMException::INVALID_STATE_ERR);
00620 
00621     KeyEventBaseImpl* ke = static_cast<KeyEventBaseImpl*>(impl);
00622     if (ke->isKeyboardEvent())
00623         return static_cast<KeyboardEventImpl*>(ke)->keyLocation() ==
00624                     KeyboardEventImpl::DOM_KEY_LOCATION_NUMPAD;
00625     else return false;
00626 }
00627 // -----------------------------------------------------------------------------
00628 
00629 MutationEvent::MutationEvent() : Event()
00630 {
00631 }
00632 
00633 MutationEvent::MutationEvent(const MutationEvent &other) : Event(other)
00634 {
00635 }
00636 
00637 MutationEvent::MutationEvent(const Event &other) : Event()
00638 {
00639     (*this)=other;
00640 }
00641 
00642 MutationEvent::MutationEvent(MutationEventImpl *impl) : Event(impl)
00643 {
00644 }
00645 
00646 MutationEvent &MutationEvent::operator = (const MutationEvent &other)
00647 {
00648     Event::operator = (other);
00649     return *this;
00650 }
00651 
00652 MutationEvent &MutationEvent::operator = (const Event &other)
00653 {
00654     Event e;
00655     e = other;
00656     if (!e.isNull() && !e.handle()->isMutationEvent()) {
00657     if ( impl ) impl->deref();
00658     impl = 0;
00659     } else
00660     Event::operator = (other);
00661     return *this;
00662 }
00663 
00664 MutationEvent::~MutationEvent()
00665 {
00666 }
00667 
00668 Node MutationEvent::relatedNode() const
00669 {
00670     if (!impl)
00671     throw DOMException(DOMException::INVALID_STATE_ERR);
00672 
00673     return static_cast<MutationEventImpl*>(impl)->relatedNode();
00674 }
00675 
00676 DOMString MutationEvent::prevValue() const
00677 {
00678     if (!impl)
00679     throw DOMException(DOMException::INVALID_STATE_ERR);
00680 
00681     return static_cast<MutationEventImpl*>(impl)->prevValue();
00682 }
00683 
00684 DOMString MutationEvent::newValue() const
00685 {
00686     if (!impl)
00687     throw DOMException(DOMException::INVALID_STATE_ERR);
00688 
00689     return static_cast<MutationEventImpl*>(impl)->newValue();
00690 }
00691 
00692 DOMString MutationEvent::attrName() const
00693 {
00694     if (!impl)
00695     throw DOMException(DOMException::INVALID_STATE_ERR);
00696 
00697     return static_cast<MutationEventImpl*>(impl)->attrName();
00698 }
00699 
00700 unsigned short MutationEvent::attrChange() const
00701 {
00702     if (!impl)
00703     throw DOMException(DOMException::INVALID_STATE_ERR);
00704 
00705     return static_cast<MutationEventImpl*>(impl)->attrChange();
00706 }
00707 
00708 void MutationEvent::initMutationEvent(const DOMString &typeArg,
00709                                        bool canBubbleArg,
00710                                        bool cancelableArg,
00711                                        const Node &relatedNodeArg,
00712                                        const DOMString &prevValueArg,
00713                                        const DOMString &newValueArg,
00714                                        const DOMString &attrNameArg,
00715                                        unsigned short attrChangeArg)
00716 {
00717     if (!impl)
00718     throw DOMException(DOMException::INVALID_STATE_ERR);
00719 
00720     static_cast<MutationEventImpl*>(impl)->initMutationEvent(typeArg,
00721     canBubbleArg,cancelableArg,relatedNodeArg,prevValueArg,
00722     newValueArg,attrNameArg,attrChangeArg);
00723 }
00724 
00725 

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal