• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdehtml
 

tdehtml

  • tdehtml
  • dom
dom2_events.cpp
1 
23 #include "dom/dom2_views.h"
24 #include "dom/dom_exception.h"
25 #include "xml/dom2_eventsimpl.h"
26 
27 using namespace DOM;
28 
29 EventListener::EventListener()
30 {
31 }
32 
33 EventListener::~EventListener()
34 {
35 }
36 
37 void EventListener::handleEvent(Event &/*evt*/)
38 {
39 }
40 
41 DOMString EventListener::eventListenerType()
42 {
43  return "";
44 }
45 
46 // -----------------------------------------------------------------------------
47 
48 Event::Event()
49 {
50  impl = 0;
51 }
52 
53 
54 Event::Event(const Event &other)
55 {
56  impl = other.impl;
57  if (impl) impl->ref();
58 }
59 
60 Event::Event(EventImpl *i)
61 {
62  impl = i;
63  if (impl) impl->ref();
64 }
65 
66 Event::~Event()
67 {
68  if (impl) impl->deref();
69 }
70 
71 Event &Event::operator = (const Event &other)
72 {
73  if ( impl != other.impl ) {
74  if(impl) impl->deref();
75  impl = other.impl;
76  if(impl) impl->ref();
77  }
78  return *this;
79 }
80 
81 DOMString Event::type() const
82 {
83  if (!impl)
84  throw DOMException(DOMException::INVALID_STATE_ERR);
85 
86  return impl->type();
87 }
88 
89 Node Event::target() const
90 {
91  if (!impl)
92  throw DOMException(DOMException::INVALID_STATE_ERR);
93 
94  return impl->target();
95 }
96 
97 Node Event::currentTarget() const
98 {
99  if (!impl)
100  throw DOMException(DOMException::INVALID_STATE_ERR);
101 
102  return impl->currentTarget();
103 }
104 
105 unsigned short Event::eventPhase() const
106 {
107  if (!impl)
108  throw DOMException(DOMException::INVALID_STATE_ERR);
109 
110  return impl->eventPhase();
111 }
112 
113 bool Event::bubbles() const
114 {
115  if (!impl)
116  throw DOMException(DOMException::INVALID_STATE_ERR);
117 
118  return impl->bubbles();
119 }
120 
121 bool Event::cancelable() const
122 {
123  if (!impl)
124  throw DOMException(DOMException::INVALID_STATE_ERR);
125 
126  return impl->cancelable();
127 }
128 
129 DOMTimeStamp Event::timeStamp() const
130 {
131  if (!impl)
132  throw DOMException(DOMException::INVALID_STATE_ERR);
133 
134  return impl->timeStamp();
135 }
136 
137 void Event::stopPropagation()
138 {
139  if (!impl)
140  throw DOMException(DOMException::INVALID_STATE_ERR);
141 
142  impl->stopPropagation(true);
143 }
144 
145 void Event::preventDefault()
146 {
147  if (!impl)
148  throw DOMException(DOMException::INVALID_STATE_ERR);
149 
150  impl->preventDefault(true);
151 }
152 
153 void Event::initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg)
154 {
155  if (!impl)
156  throw DOMException(DOMException::INVALID_STATE_ERR);
157 
158  impl->initEvent(eventTypeArg,canBubbleArg,cancelableArg);
159 }
160 
161 EventImpl *Event::handle() const
162 {
163  return impl;
164 }
165 
166 bool Event::isNull() const
167 {
168  return (impl == 0);
169 }
170 
171 // -----------------------------------------------------------------------------
172 
173 #ifndef SAVE_SPACE
174 
175 EventException::EventException(unsigned short _code)
176 {
177  code = _code;
178 }
179 
180 EventException::EventException(const EventException &other)
181 {
182  code = other.code;
183 }
184 
185 EventException & EventException::operator = (const EventException &other)
186 {
187  code = other.code;
188  return *this;
189 }
190 
191 #endif
192 
193 // -----------------------------------------------------------------------------
194 
195 UIEvent::UIEvent() : Event()
196 {
197 }
198 
199 UIEvent::UIEvent(const UIEvent &other) : Event(other)
200 {
201 }
202 
203 UIEvent::UIEvent(const Event &other) : Event()
204 {
205  (*this)=other;
206 }
207 
208 UIEvent::UIEvent(UIEventImpl *impl) : Event(impl)
209 {
210 }
211 
212 UIEvent &UIEvent::operator = (const UIEvent &other)
213 {
214  Event::operator = (other);
215  return *this;
216 }
217 
218 UIEvent &UIEvent::operator = (const Event &other)
219 {
220  Event e;
221  e = other;
222  if (!e.isNull() && !e.handle()->isUIEvent()) {
223  if ( impl ) impl->deref();
224  impl = 0;
225  } else
226  Event::operator = (other);
227  return *this;
228 }
229 
230 UIEvent::~UIEvent()
231 {
232 }
233 
234 AbstractView UIEvent::view() const
235 {
236  if (!impl)
237  throw DOMException(DOMException::INVALID_STATE_ERR);
238 
239  return static_cast<UIEventImpl*>(impl)->view();
240 }
241 
242 long UIEvent::detail() const
243 {
244  if (!impl)
245  throw DOMException(DOMException::INVALID_STATE_ERR);
246 
247  return static_cast<UIEventImpl*>(impl)->detail();
248 }
249 
250 int UIEvent::keyCode() const
251 {
252  if ( !impl ) throw DOMException( DOMException::INVALID_STATE_ERR );
253 
254  if( impl->isTextInputEvent() || impl->isKeyboardEvent() )
255  return static_cast<KeyEventBaseImpl*>( impl )->keyCode();
256 
257  return 0;
258 }
259 
260 int UIEvent::charCode() const
261 {
262  if (!impl)
263  throw DOMException(DOMException::INVALID_STATE_ERR);
264 
265  if( impl->isTextInputEvent() || impl->isKeyboardEvent() )
266  return static_cast<KeyEventBaseImpl*>( impl )->charCode();
267 
268  return 0;
269 }
270 
271 int UIEvent::pageX() const
272 {
273  if (!impl)
274  throw DOMException(DOMException::INVALID_STATE_ERR);
275 
276  if (impl->isMouseEvent() )
277  return static_cast<MouseEventImpl*>( impl )->pageX();
278  else
279  return 0;
280 }
281 
282 int UIEvent::pageY() const
283 {
284  if (!impl)
285  throw DOMException(DOMException::INVALID_STATE_ERR);
286 
287  if ( impl->isMouseEvent() )
288  return static_cast<MouseEventImpl*>( impl )->pageY();
289  else
290  return 0;
291 }
292 
293 int UIEvent::layerX() const
294 {
295  if( !impl )
296  throw DOMException( DOMException::INVALID_STATE_ERR );
297 
298  if( impl->isMouseEvent() )
299  return static_cast<MouseEventImpl*>( impl )->layerX();
300  return 0;
301 }
302 
303 int UIEvent::layerY() const
304 {
305  if( !impl )
306  throw DOMException( DOMException::INVALID_STATE_ERR );
307 
308  if( impl->isMouseEvent() )
309  return static_cast<MouseEventImpl*>( impl )->layerY();
310  return 0;
311 }
312 
313 int UIEvent::which() const
314 {
315  if( !impl ) throw DOMException( DOMException::INVALID_STATE_ERR );
316 
317  if( impl->isMouseEvent() )
318  return static_cast<MouseEventImpl*>( impl )->button() + 1;
319  else if( impl->isTextInputEvent() || impl->isKeyboardEvent() )
320  {
321  // return 0 unless the key has an ascii value
322  if ( static_cast<KeyEventBaseImpl*>( impl )->keyVal() )
323  return static_cast<KeyEventBaseImpl*>( impl )->keyCode();
324  }
325 
326  return 0;
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,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,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(KeyEventBaseImpl *impl) : UIEvent(impl)
504 {
505 }
506 
507 TextEvent &TextEvent::operator = (const TextEvent &other)
508 {
509  UIEvent::operator = (other);
510  return *this;
511 }
512 
513 TextEvent &TextEvent::operator = (const Event &other)
514 {
515  Event e;
516  e = other;
517  if (!e.isNull() && !(e.handle()->isTextInputEvent() || e.handle()->isKeyboardEvent())) {
518  if ( impl ) impl->deref();
519  impl = 0;
520  } else
521  UIEvent::operator = (other);
522  return *this;
523 }
524 
525 TextEvent::~TextEvent()
526 {
527 }
528 
529 void TextEvent::initTextEvent(const DOMString &typeArg,
530  bool canBubbleArg,
531  bool cancelableArg,
532  const AbstractView &viewArg,
533  long /*detailArg*/,
534  const DOMString &outputStringArg,
535  unsigned long keyValArg,
536  unsigned long virtKeyValArg,
537  bool /*inputGeneratedArg*/,
538  bool numPadArg)
539 {
540  if (!impl)
541  throw DOMException(DOMException::INVALID_STATE_ERR);
542 
543  if (impl->isTextInputEvent()) {
544  //Initialize based on the outputStringArg or virtKeyValArg.
545  TQString text = outputStringArg.string();
546  if (outputStringArg.length() == 0 && virtKeyValArg) {
547  text += TQChar((unsigned short)virtKeyValArg);
548  }
549 
550  TextEventImpl* tImpl = static_cast<TextEventImpl*>(impl);
551  tImpl->initTextEvent(typeArg, canBubbleArg, cancelableArg, viewArg, text);
552  } else {
553  KeyboardEventImpl* kbImpl = static_cast<KeyboardEventImpl*>(impl);
554  kbImpl->initKeyboardEvent(typeArg, canBubbleArg, cancelableArg, viewArg,
555  keyValArg, virtKeyValArg, 0, numPadArg ?
556  KeyboardEventImpl::DOM_KEY_LOCATION_NUMPAD : KeyboardEventImpl::DOM_KEY_LOCATION_STANDARD);
557  }
558 }
559 
560 unsigned long TextEvent::keyVal() const
561 {
562  if (!impl)
563  throw DOMException(DOMException::INVALID_STATE_ERR);
564 
565  return static_cast<KeyEventBaseImpl*>(impl)->keyVal();
566 }
567 
568 DOMString TextEvent::outputString() const
569 {
570  if (!impl)
571  throw DOMException(DOMException::INVALID_STATE_ERR);
572 
573  KeyEventBaseImpl* ke = static_cast<KeyEventBaseImpl*>(impl);
574  if (ke->isTextInputEvent())
575  return static_cast<TextEventImpl*>(ke)->data();
576  else {
577  if (ke->keyVal())
578  return TQString(TQChar((ushort)ke->keyVal()));
579  else
580  return DOMString();
581  }
582 }
583 
584 unsigned long TextEvent::virtKeyVal() const
585 {
586  if (!impl)
587  throw DOMException(DOMException::INVALID_STATE_ERR);
588 
589  return static_cast<KeyEventBaseImpl*>(impl)->virtKeyVal();
590 }
591 
592 void TextEvent::initModifier(unsigned long modifierArg, bool valueArg)
593 {
594  if (!impl)
595  throw DOMException(DOMException::INVALID_STATE_ERR);
596 
597  return static_cast<KeyEventBaseImpl*>(impl)->initModifier(modifierArg,valueArg);
598 }
599 
600 bool TextEvent::checkModifier(unsigned long modifierArg)
601 {
602  if (!impl)
603  throw DOMException(DOMException::INVALID_STATE_ERR);
604 
605  return static_cast<KeyEventBaseImpl*>(impl)->checkModifier(modifierArg);
606 }
607 
608 bool TextEvent::inputGenerated() const
609 {
610  if (!impl)
611  throw DOMException(DOMException::INVALID_STATE_ERR);
612 
613  return static_cast<KeyEventBaseImpl*>(impl)->inputGenerated();
614 }
615 
616 bool TextEvent::numPad() const
617 {
618  if (!impl)
619  throw DOMException(DOMException::INVALID_STATE_ERR);
620 
621  KeyEventBaseImpl* ke = static_cast<KeyEventBaseImpl*>(impl);
622  if (ke->isKeyboardEvent())
623  return static_cast<KeyboardEventImpl*>(ke)->keyLocation() ==
624  KeyboardEventImpl::DOM_KEY_LOCATION_NUMPAD;
625  else return false;
626 }
627 // -----------------------------------------------------------------------------
628 
629 MutationEvent::MutationEvent() : Event()
630 {
631 }
632 
633 MutationEvent::MutationEvent(const MutationEvent &other) : Event(other)
634 {
635 }
636 
637 MutationEvent::MutationEvent(const Event &other) : Event()
638 {
639  (*this)=other;
640 }
641 
642 MutationEvent::MutationEvent(MutationEventImpl *impl) : Event(impl)
643 {
644 }
645 
646 MutationEvent &MutationEvent::operator = (const MutationEvent &other)
647 {
648  Event::operator = (other);
649  return *this;
650 }
651 
652 MutationEvent &MutationEvent::operator = (const Event &other)
653 {
654  Event e;
655  e = other;
656  if (!e.isNull() && !e.handle()->isMutationEvent()) {
657  if ( impl ) impl->deref();
658  impl = 0;
659  } else
660  Event::operator = (other);
661  return *this;
662 }
663 
664 MutationEvent::~MutationEvent()
665 {
666 }
667 
668 Node MutationEvent::relatedNode() const
669 {
670  if (!impl)
671  throw DOMException(DOMException::INVALID_STATE_ERR);
672 
673  return static_cast<MutationEventImpl*>(impl)->relatedNode();
674 }
675 
676 DOMString MutationEvent::prevValue() const
677 {
678  if (!impl)
679  throw DOMException(DOMException::INVALID_STATE_ERR);
680 
681  return static_cast<MutationEventImpl*>(impl)->prevValue();
682 }
683 
684 DOMString MutationEvent::newValue() const
685 {
686  if (!impl)
687  throw DOMException(DOMException::INVALID_STATE_ERR);
688 
689  return static_cast<MutationEventImpl*>(impl)->newValue();
690 }
691 
692 DOMString MutationEvent::attrName() const
693 {
694  if (!impl)
695  throw DOMException(DOMException::INVALID_STATE_ERR);
696 
697  return static_cast<MutationEventImpl*>(impl)->attrName();
698 }
699 
700 unsigned short MutationEvent::attrChange() const
701 {
702  if (!impl)
703  throw DOMException(DOMException::INVALID_STATE_ERR);
704 
705  return static_cast<MutationEventImpl*>(impl)->attrChange();
706 }
707 
708 void MutationEvent::initMutationEvent(const DOMString &typeArg,
709  bool canBubbleArg,
710  bool cancelableArg,
711  const Node &relatedNodeArg,
712  const DOMString &prevValueArg,
713  const DOMString &newValueArg,
714  const DOMString &attrNameArg,
715  unsigned short attrChangeArg)
716 {
717  if (!impl)
718  throw DOMException(DOMException::INVALID_STATE_ERR);
719 
720  static_cast<MutationEventImpl*>(impl)->initMutationEvent(typeArg,
721  canBubbleArg,cancelableArg,relatedNodeArg,prevValueArg,
722  newValueArg,attrNameArg,attrChangeArg);
723 }
724 
725 

tdehtml

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

tdehtml

Skip menu "tdehtml"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdehtml by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.