• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.2 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • dom
dom2_events.cpp
Go to the documentation of this file.
1 
23 #include "dom/dom2_views.h"
24 #include "dom/dom_exception.h"
25 #include "xml/dom2_eventsimpl.h"
26 #include "xml/dom_nodeimpl.h"
27 
28 using namespace DOM;
29 
30 EventListener::EventListener()
31 {
32 }
33 
34 EventListener::~EventListener()
35 {
36 }
37 
38 void EventListener::handleEvent(Event &/*evt*/)
39 {
40 }
41 
42 DOMString EventListener::eventListenerType()
43 {
44  return "";
45 }
46 
47 // -----------------------------------------------------------------------------
48 
49 Event::Event()
50 {
51  impl = 0;
52 }
53 
54 
55 Event::Event(const Event &other)
56 {
57  impl = other.impl;
58  if (impl) impl->ref();
59 }
60 
61 Event::Event(EventImpl *i)
62 {
63  impl = i;
64  if (impl) impl->ref();
65 }
66 
67 Event::~Event()
68 {
69  if (impl) impl->deref();
70 }
71 
72 Event &Event::operator = (const Event &other)
73 {
74  if ( impl != other.impl ) {
75  if(impl) impl->deref();
76  impl = other.impl;
77  if(impl) impl->ref();
78  }
79  return *this;
80 }
81 
82 DOMString Event::type() const
83 {
84  if (!impl)
85  throw DOMException(DOMException::INVALID_STATE_ERR);
86 
87  return impl->type();
88 }
89 
90 Node Event::target() const
91 {
92  if (!impl)
93  throw DOMException(DOMException::INVALID_STATE_ERR);
94 
95  if (impl->target()->eventTargetType() == EventTargetImpl::DOM_NODE)
96  return static_cast<DOM::NodeImpl*>(impl->target());
97  return 0;
98 }
99 
100 Node Event::currentTarget() const
101 {
102  if (!impl)
103  throw DOMException(DOMException::INVALID_STATE_ERR);
104 
105  if (impl->currentTarget()->eventTargetType() == EventTargetImpl::DOM_NODE)
106  return static_cast<DOM::NodeImpl*>(impl->currentTarget());
107  return 0;
108 }
109 
110 unsigned short Event::eventPhase() const
111 {
112  if (!impl)
113  throw DOMException(DOMException::INVALID_STATE_ERR);
114 
115  return impl->eventPhase();
116 }
117 
118 bool Event::bubbles() const
119 {
120  if (!impl)
121  throw DOMException(DOMException::INVALID_STATE_ERR);
122 
123  return impl->bubbles();
124 }
125 
126 bool Event::cancelable() const
127 {
128  if (!impl)
129  throw DOMException(DOMException::INVALID_STATE_ERR);
130 
131  return impl->cancelable();
132 }
133 
134 DOMTimeStamp Event::timeStamp() const
135 {
136  if (!impl)
137  throw DOMException(DOMException::INVALID_STATE_ERR);
138 
139  return impl->timeStamp();
140 }
141 
142 void Event::stopPropagation()
143 {
144  if (!impl)
145  throw DOMException(DOMException::INVALID_STATE_ERR);
146 
147  impl->stopPropagation(true);
148 }
149 
150 void Event::preventDefault()
151 {
152  if (!impl)
153  throw DOMException(DOMException::INVALID_STATE_ERR);
154 
155  impl->preventDefault(true);
156 }
157 
158 void Event::initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg)
159 {
160  if (!impl)
161  throw DOMException(DOMException::INVALID_STATE_ERR);
162 
163  impl->initEvent(eventTypeArg,canBubbleArg,cancelableArg);
164 }
165 
166 EventImpl *Event::handle() const
167 {
168  return impl;
169 }
170 
171 bool Event::isNull() const
172 {
173  return (impl == 0);
174 }
175 
176 // -----------------------------------------------------------------------------
177 
178 #ifndef SAVE_SPACE
179 
180 EventException::EventException(unsigned short _code)
181 {
182  code = _code;
183 }
184 
185 EventException::EventException(const EventException &other)
186 {
187  code = other.code;
188 }
189 
190 EventException & EventException::operator = (const EventException &other)
191 {
192  code = other.code;
193  return *this;
194 }
195 
196 #endif
197 
198 DOMString EventException::codeAsString() const
199 {
200  return codeAsString(code);
201 }
202 
203 bool EventException::isEventExceptionCode(int exceptioncode)
204 {
205  return exceptioncode >= _EXCEPTION_OFFSET && exceptioncode < _EXCEPTION_MAX;
206 }
207 
208 DOMString EventException::codeAsString(int code)
209 {
210  switch ( code ) {
211  case UNSPECIFIED_EVENT_TYPE_ERR:
212  return DOMString( "UNSPECIFIED_EVENT_TYPE_ERR" );
213  default:
214  return DOMString( "(unknown exception code)" );
215  }
216 }
217 
218 
219 // -----------------------------------------------------------------------------
220 
221 UIEvent::UIEvent() : Event()
222 {
223 }
224 
225 UIEvent::UIEvent(const UIEvent &other) : Event(other)
226 {
227 }
228 
229 UIEvent::UIEvent(const Event &other) : Event()
230 {
231  (*this)=other;
232 }
233 
234 UIEvent::UIEvent(UIEventImpl *impl) : Event(impl)
235 {
236 }
237 
238 UIEvent &UIEvent::operator = (const UIEvent &other)
239 {
240  Event::operator = (other);
241  return *this;
242 }
243 
244 UIEvent &UIEvent::operator = (const Event &other)
245 {
246  Event e;
247  e = other;
248  if (!e.isNull() && !e.handle()->isUIEvent()) {
249  if ( impl ) impl->deref();
250  impl = 0;
251  } else
252  Event::operator = (other);
253  return *this;
254 }
255 
256 UIEvent::~UIEvent()
257 {
258 }
259 
260 AbstractView UIEvent::view() const
261 {
262  if (!impl)
263  throw DOMException(DOMException::INVALID_STATE_ERR);
264 
265  return static_cast<UIEventImpl*>(impl)->view();
266 }
267 
268 long UIEvent::detail() const
269 {
270  if (!impl)
271  throw DOMException(DOMException::INVALID_STATE_ERR);
272 
273  return static_cast<UIEventImpl*>(impl)->detail();
274 }
275 
276 int UIEvent::keyCode() const
277 {
278  if ( !impl ) throw DOMException( DOMException::INVALID_STATE_ERR );
279 
280  return static_cast<UIEventImpl*>(impl)->keyCode();
281 }
282 
283 int UIEvent::charCode() const
284 {
285  if (!impl)
286  throw DOMException(DOMException::INVALID_STATE_ERR);
287 
288  return static_cast<UIEventImpl*>(impl)->charCode();
289 }
290 
291 int UIEvent::pageX() const
292 {
293  if (!impl)
294  throw DOMException(DOMException::INVALID_STATE_ERR);
295 
296  return static_cast<UIEventImpl*>(impl)->pageX();
297 }
298 
299 int UIEvent::pageY() const
300 {
301  if (!impl)
302  throw DOMException(DOMException::INVALID_STATE_ERR);
303 
304  return static_cast<UIEventImpl*>(impl)->pageY();
305 }
306 
307 int UIEvent::layerX() const
308 {
309  if( !impl )
310  throw DOMException( DOMException::INVALID_STATE_ERR );
311 
312  return static_cast<UIEventImpl*>(impl)->layerX();
313 }
314 
315 int UIEvent::layerY() const
316 {
317  if( !impl )
318  throw DOMException( DOMException::INVALID_STATE_ERR );
319 
320  return static_cast<UIEventImpl*>(impl)->layerY();
321 }
322 
323 int UIEvent::which() const
324 {
325  if( !impl ) throw DOMException( DOMException::INVALID_STATE_ERR );
326  return static_cast<UIEventImpl*>(impl)->which();
327 }
328 
329 void UIEvent::initUIEvent(const DOMString &typeArg,
330  bool canBubbleArg,
331  bool cancelableArg,
332  const AbstractView &viewArg,
333  long detailArg)
334 {
335  if (!impl)
336  throw DOMException(DOMException::INVALID_STATE_ERR);
337 
338  static_cast<UIEventImpl*>(impl)->initUIEvent(typeArg,canBubbleArg,cancelableArg,
339  viewArg.handle(),detailArg);
340 }
341 
342 // -----------------------------------------------------------------------------
343 
344 MouseEvent::MouseEvent() : UIEvent()
345 {
346 }
347 
348 MouseEvent::MouseEvent(const MouseEvent &other) : UIEvent(other)
349 {
350 }
351 
352 MouseEvent::MouseEvent(const Event &other) : UIEvent()
353 {
354  (*this)=other;
355 }
356 
357 MouseEvent::MouseEvent(MouseEventImpl *impl) : UIEvent(impl)
358 {
359 }
360 
361 MouseEvent &MouseEvent::operator = (const MouseEvent &other)
362 {
363  UIEvent::operator = (other);
364  return *this;
365 }
366 
367 MouseEvent &MouseEvent::operator = (const Event &other)
368 {
369  Event e;
370  e = other;
371  if (!e.isNull() && !e.handle()->isMouseEvent()) {
372  if ( impl ) impl->deref();
373  impl = 0;
374  } else
375  UIEvent::operator = (other);
376  return *this;
377 }
378 
379 MouseEvent::~MouseEvent()
380 {
381 }
382 
383 long MouseEvent::screenX() const
384 {
385  if (!impl)
386  throw DOMException(DOMException::INVALID_STATE_ERR);
387 
388  return static_cast<MouseEventImpl*>(impl)->screenX();
389 }
390 
391 long MouseEvent::screenY() const
392 {
393  if (!impl)
394  throw DOMException(DOMException::INVALID_STATE_ERR);
395 
396  return static_cast<MouseEventImpl*>(impl)->screenY();
397 }
398 
399 long MouseEvent::clientX() const
400 {
401  if (!impl)
402  throw DOMException(DOMException::INVALID_STATE_ERR);
403 
404  return static_cast<MouseEventImpl*>(impl)->clientX();
405 }
406 
407 long MouseEvent::clientY() const
408 {
409  if (!impl)
410  throw DOMException(DOMException::INVALID_STATE_ERR);
411 
412  return static_cast<MouseEventImpl*>(impl)->clientY();
413 }
414 
415 bool MouseEvent::ctrlKey() const
416 {
417  if (!impl)
418  throw DOMException(DOMException::INVALID_STATE_ERR);
419 
420  return static_cast<MouseEventImpl*>(impl)->ctrlKey();
421 }
422 
423 bool MouseEvent::shiftKey() const
424 {
425  if (!impl)
426  throw DOMException(DOMException::INVALID_STATE_ERR);
427 
428  return static_cast<MouseEventImpl*>(impl)->shiftKey();
429 }
430 
431 bool MouseEvent::altKey() const
432 {
433  if (!impl)
434  throw DOMException(DOMException::INVALID_STATE_ERR);
435 
436  return static_cast<MouseEventImpl*>(impl)->altKey();
437 }
438 
439 bool MouseEvent::metaKey() const
440 {
441  if (!impl)
442  throw DOMException(DOMException::INVALID_STATE_ERR);
443 
444  return static_cast<MouseEventImpl*>(impl)->metaKey();
445 }
446 
447 unsigned short MouseEvent::button() const
448 {
449  if (!impl)
450  throw DOMException(DOMException::INVALID_STATE_ERR);
451 
452  return static_cast<MouseEventImpl*>(impl)->button();
453 }
454 
455 Node MouseEvent::relatedTarget() const
456 {
457  if (!impl)
458  throw DOMException(DOMException::INVALID_STATE_ERR);
459 
460  return static_cast<MouseEventImpl*>(impl)->relatedTarget();
461 }
462 
463 void MouseEvent::initMouseEvent(const DOMString &typeArg,
464  bool canBubbleArg,
465  bool cancelableArg,
466  const AbstractView &viewArg,
467  long detailArg,
468  long screenXArg,
469  long screenYArg,
470  long clientXArg,
471  long clientYArg,
472  bool ctrlKeyArg,
473  bool altKeyArg,
474  bool shiftKeyArg,
475  bool metaKeyArg,
476  unsigned short buttonArg,
477  const Node &relatedTargetArg)
478 {
479  if (!impl)
480  throw DOMException(DOMException::INVALID_STATE_ERR);
481 
482  static_cast<MouseEventImpl*>(impl)->initMouseEvent(typeArg,canBubbleArg,
483  cancelableArg,viewArg.handle(),detailArg,screenXArg,screenYArg,clientXArg,
484  clientYArg,ctrlKeyArg,altKeyArg,shiftKeyArg,metaKeyArg,buttonArg,
485  relatedTargetArg);
486 }
487 
488 // -----------------------------------------------------------------------------
489 
490 TextEvent::TextEvent() : UIEvent()
491 {
492 }
493 
494 TextEvent::TextEvent(const TextEvent &other) : UIEvent(other)
495 {
496 }
497 
498 TextEvent::TextEvent(const Event &other) : UIEvent()
499 {
500  (*this)=other;
501 }
502 
503 TextEvent &TextEvent::operator = (const TextEvent &other)
504 {
505  UIEvent::operator = (other);
506  return *this;
507 }
508 
509 TextEvent &TextEvent::operator = (const Event &other)
510 {
511  Event e;
512  e = other;
513  if (!e.isNull() && !e.handle()->isTextInputEvent()) {
514  if ( impl ) impl->deref();
515  impl = 0;
516  } else
517  UIEvent::operator = (other);
518  return *this;
519 }
520 
521 TextEvent::~TextEvent()
522 {
523 }
524 
525 void TextEvent::initTextEvent(const DOMString &typeArg,
526  bool canBubbleArg,
527  bool cancelableArg,
528  const AbstractView &viewArg,
529  const DOMString &dataArg)
530 {
531  static_cast<TextEventImpl*>(impl)->initTextEvent(
532  typeArg, canBubbleArg, cancelableArg, viewArg.handle(), dataArg);
533 }
534 // -----------------------------------------------------------------------------
535 
536 KeyboardEvent::KeyboardEvent() : UIEvent()
537 {
538 }
539 
540 KeyboardEvent::KeyboardEvent(const KeyboardEvent &other) : UIEvent(other)
541 {
542 }
543 
544 KeyboardEvent::KeyboardEvent(const Event &other) : UIEvent()
545 {
546  (*this)=other;
547 }
548 
549 KeyboardEvent &KeyboardEvent::operator = (const KeyboardEvent &other)
550 {
551  UIEvent::operator = (other);
552  return *this;
553 }
554 
555 KeyboardEvent &KeyboardEvent::operator = (const Event &other)
556 {
557  Event e;
558  e = other;
559  if (!e.isNull() && !e.handle()->isKeyboardEvent()) {
560  if ( impl ) impl->deref();
561  impl = 0;
562  } else
563  UIEvent::operator = (other);
564  return *this;
565 }
566 
567 KeyboardEvent::~KeyboardEvent()
568 {
569 }
570 
571 DOMString KeyboardEvent::keyIdentifier() const
572 {
573  return static_cast<const KeyboardEventImpl*>(impl)->keyIdentifier();
574 }
575 
576 unsigned long KeyboardEvent::keyLocation() const
577 {
578  return static_cast<const KeyboardEventImpl*>(impl)->keyLocation();
579 }
580 
581 bool KeyboardEvent::ctrlKey() const
582 {
583  return static_cast<const KeyboardEventImpl*>(impl)->ctrlKey();
584 }
585 
586 bool KeyboardEvent::shiftKey() const
587 {
588  return static_cast<const KeyboardEventImpl*>(impl)->shiftKey();
589 }
590 
591 bool KeyboardEvent::altKey() const
592 {
593  return static_cast<const KeyboardEventImpl*>(impl)->altKey();
594 }
595 
596 bool KeyboardEvent::metaKey() const
597 {
598  return static_cast<const KeyboardEventImpl*>(impl)->metaKey();
599 }
600 
601 bool KeyboardEvent::getModifierState(DOMString keyIdentifierArg) const
602 {
603  return static_cast<const KeyboardEventImpl*>(impl)->getModifierState(keyIdentifierArg);
604 }
605 
606 void KeyboardEvent::initKeyboardEvent(DOMString typeArg,
607  bool canBubbleArg,
608  bool cancelableArg,
609  AbstractView viewArg,
610  DOMString keyIdentifierArg,
611  unsigned long keyLocationArg,
612  DOMString modifiersList)
613 {
614  static_cast<KeyboardEventImpl*>(impl)->initKeyboardEvent(typeArg,
615  canBubbleArg, cancelableArg, viewArg.handle(), keyIdentifierArg, keyLocationArg, modifiersList);
616 }
617 
618 
619 // -----------------------------------------------------------------------------
620 
621 MutationEvent::MutationEvent() : Event()
622 {
623 }
624 
625 MutationEvent::MutationEvent(const MutationEvent &other) : Event(other)
626 {
627 }
628 
629 MutationEvent::MutationEvent(const Event &other) : Event()
630 {
631  (*this)=other;
632 }
633 
634 MutationEvent::MutationEvent(MutationEventImpl *impl) : Event(impl)
635 {
636 }
637 
638 MutationEvent &MutationEvent::operator = (const MutationEvent &other)
639 {
640  Event::operator = (other);
641  return *this;
642 }
643 
644 MutationEvent &MutationEvent::operator = (const Event &other)
645 {
646  Event e;
647  e = other;
648  if (!e.isNull() && !e.handle()->isMutationEvent()) {
649  if ( impl ) impl->deref();
650  impl = 0;
651  } else
652  Event::operator = (other);
653  return *this;
654 }
655 
656 MutationEvent::~MutationEvent()
657 {
658 }
659 
660 Node MutationEvent::relatedNode() const
661 {
662  if (!impl)
663  throw DOMException(DOMException::INVALID_STATE_ERR);
664 
665  return static_cast<MutationEventImpl*>(impl)->relatedNode();
666 }
667 
668 DOMString MutationEvent::prevValue() const
669 {
670  if (!impl)
671  throw DOMException(DOMException::INVALID_STATE_ERR);
672 
673  return static_cast<MutationEventImpl*>(impl)->prevValue();
674 }
675 
676 DOMString MutationEvent::newValue() const
677 {
678  if (!impl)
679  throw DOMException(DOMException::INVALID_STATE_ERR);
680 
681  return static_cast<MutationEventImpl*>(impl)->newValue();
682 }
683 
684 DOMString MutationEvent::attrName() const
685 {
686  if (!impl)
687  throw DOMException(DOMException::INVALID_STATE_ERR);
688 
689  return static_cast<MutationEventImpl*>(impl)->attrName();
690 }
691 
692 unsigned short MutationEvent::attrChange() const
693 {
694  if (!impl)
695  throw DOMException(DOMException::INVALID_STATE_ERR);
696 
697  return static_cast<MutationEventImpl*>(impl)->attrChange();
698 }
699 
700 void MutationEvent::initMutationEvent(const DOMString &typeArg,
701  bool canBubbleArg,
702  bool cancelableArg,
703  const Node &relatedNodeArg,
704  const DOMString &prevValueArg,
705  const DOMString &newValueArg,
706  const DOMString &attrNameArg,
707  unsigned short attrChangeArg)
708 {
709  if (!impl)
710  throw DOMException(DOMException::INVALID_STATE_ERR);
711 
712  static_cast<MutationEventImpl*>(impl)->initMutationEvent(typeArg,
713  canBubbleArg,cancelableArg,relatedNodeArg,prevValueArg,
714  newValueArg,attrNameArg,attrChangeArg);
715 }
716 
717 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Apr 16 2013 21:10:34 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

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

kdelibs-4.10.2 API Reference

Skip menu "kdelibs-4.10.2 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal