/[suikacvs]/messaging/manakai/lib/Message/DOM/EventTarget.pm
Suika

Contents of /messaging/manakai/lib/Message/DOM/EventTarget.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Mon Oct 8 07:17:18 2007 UTC (17 years, 1 month ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
++ manakai/lib/Message/DOM/ChangeLog	8 Oct 2007 07:16:56 -0000
2007-10-08  Wakaba  <wakaba@suika.fam.cx>

	* Event.pm, EventTarget.pm, EventTargetNode.pm,
	EventException.pm: Implemented (but not tested!).

	* DOMException.pm (MALFORMED_EVENT_TYPE_ERR,
	EVENT_INTERFACE_NOT_SUPPORTED_ERR, EXTERNAL_EVENT_ERR): New
	error subtypes.

	* DOMImplementation.pm ($HasFeature): The |Event| feature,
	version |3.0|, is added.

	* Document.pm, Node.pm: Event attributes and
	methods are implemented.

1 package Message::DOM::EventTarget;
2 use strict;
3 push our @ISA, 'Message::IF::EventTarget';
4
5 sub add_event_listener ($$$;$) {
6 push @{$_[0]->{event_listener}->{''}->{''.$_[1]}->[$_[3] ? 1 : 0] or []},
7 $_[2];
8 } # add_event_listener
9
10 sub add_event_listener_ns ($$$$;$) {
11 push @{$_[0]->{event_listener}->{
12 defined $_[1] ? $_[1] : ''
13 }->{''.$_[2]}->[$_[4] ? 1 : 0] or []}, $_[3];
14 } # add_event_listener_ns
15
16 require Message::DOM::EventException;
17 use Char::Class::XML qw/InXMLNCNameStartChar11 InXMLNCNameChar11/;
18
19 sub dispatch_event ($$) {
20 unless (UNIVERSAL::isa ($_[1], 'Message::DOM::Event')) {
21 report Message::DOM::DOMException
22 -object => $_[0],
23 -type => 'NOT_SUPPORTED_ERR',
24 -subtype => 'EXTERNAL_EVENT_ERR';
25 }
26
27 if ($_[1]->{manakai_dispatched}) {
28 report Message::DOM::EventException
29 -object => $_[0],
30 -type => 'DISPATCH_REQUEST_ERR';
31 }
32
33 my $type = $_[1]->{type};
34 if (not defined $type or $type eq '') {
35 report Message::DOM::EventException
36 -object => $_[0],
37 -type => 'UNSPECIFIED_EVENT_TYPE_ERR';
38 } elsif ($type =~ /\A\p{InXMLNCNameStartChar11}\p{InXMLNCNameChar11}*\z/) {
39 report Message::DOM::DOMException
40 -object => $_[0],
41 -type => 'INVALID_CHARACTER_ERR',
42 -subtype => 'MALFORMED_EVENT_TYPE_ERR';
43 }
44
45 local $Error::Depth = $Error::Depth + 1;
46 return $_[0]->__dispatch_event ($_[1]);
47 } # dispatch_event
48
49 sub __dispatch_event {
50 ## NOTE: MUST be implemented by subclass.
51 die "Not implemented";
52 } # __dispatch_event
53
54 ## TODO: multiple registration... then, remove them
55 ## TODO: <http://www.w3.org/2006/webapi/track/issues/77>
56
57 sub remove_event_listener ($$$;$) {
58 my $list = $_[0]->{event_listener}->{''}->{''.$_[1]}->[$_[3] ? 1 : 0] || [];
59 for my $i (0..$#$list) {
60 if ($list->[$i] eq $_[2]) {
61 splice @$list, $i, 1, ();
62 last;
63 }
64 }
65 } # remove_event_listener
66
67 sub remove_event_listener_ns ($$$$;$) {
68 my $list = $_[0]->{event_listener}->{
69 defined $_[1] ? $_[1] : ''
70 }->{''.$_[2]}->[$_[4] ? 1 : 0] || [];
71 for my $i (0..$#$list) {
72 if ($list->[$i] eq $_[3]) {
73 splice @$list, $i, 1, ();
74 last;
75 }
76 }
77 } # remove_event_listener_ns
78
79 package Message::IF::EventTarget;
80
81 1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24