1 |
wakaba |
1.1 |
package Message::DOM::Event; |
2 |
|
|
use strict; |
3 |
wakaba |
1.2 |
our $VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
wakaba |
1.1 |
push our @ISA, 'Message::IF::Event'; |
5 |
|
|
|
6 |
|
|
## The |Event| interface - constants |
7 |
|
|
|
8 |
|
|
## |PhaseType| |
9 |
|
|
|
10 |
|
|
sub CAPTURING_PHASE () { 1 } |
11 |
|
|
sub AT_TARGET () { 2 } |
12 |
|
|
sub BUBBLING_PHASE () { 3 } |
13 |
|
|
|
14 |
|
|
sub AUTOLOAD { |
15 |
|
|
my $method_name = our $AUTOLOAD; |
16 |
|
|
$method_name =~ s/.*:://; |
17 |
|
|
return if $method_name eq 'DESTROY'; |
18 |
|
|
|
19 |
|
|
if ({ |
20 |
|
|
## Read-only attributes (trivial accessors) |
21 |
|
|
'Message::DOM::Event::bubbles' => 1, |
22 |
|
|
'Message::DOM::Event::cancelable' => 1, |
23 |
|
|
'Message::DOM::Event::current_target' => 1, |
24 |
|
|
'Message::DOM::Event::default_prevented' => 1, |
25 |
|
|
'Message::DOM::Event::manakai_dispatched' => 1, |
26 |
|
|
'Message::DOM::Event::event_phase' => 1, |
27 |
|
|
'Message::DOM::Event::manakai_immediate_propagation_stopped' => 1, |
28 |
|
|
'Message::DOM::Event::namespace_uri' => 1, |
29 |
|
|
'Message::DOM::Event::manakai_propagation_stopped' => 1, |
30 |
|
|
'Message::DOM::Event::target' => 1, |
31 |
|
|
'Message::DOM::Event::time_stamp' => 1, |
32 |
|
|
'Message::DOM::Event::type' => 1, |
33 |
|
|
|
34 |
|
|
'Message::DOM::Event::CustomEvent::detail' => 1, |
35 |
|
|
}->{$AUTOLOAD}) { |
36 |
|
|
no strict 'refs'; |
37 |
|
|
eval qq{ |
38 |
|
|
sub $method_name (\$) { |
39 |
|
|
return \${\$_[0]}->{$method_name}; |
40 |
|
|
} |
41 |
|
|
}; |
42 |
|
|
goto &{ $AUTOLOAD }; |
43 |
|
|
} else { |
44 |
|
|
require Carp; |
45 |
|
|
Carp::croak (qq<Can't locate method "$AUTOLOAD">); |
46 |
|
|
} |
47 |
|
|
} # AUTOLOAD |
48 |
|
|
|
49 |
|
|
## The |Event| interface - attributes |
50 |
|
|
|
51 |
|
|
sub bubbles ($); |
52 |
|
|
|
53 |
|
|
sub cancelable ($); |
54 |
|
|
|
55 |
|
|
sub current_target ($); |
56 |
|
|
|
57 |
|
|
sub default_prevented ($); |
58 |
|
|
|
59 |
|
|
## TODO: documentation |
60 |
|
|
sub manakai_dispatched ($); |
61 |
|
|
|
62 |
|
|
sub event_phase ($); |
63 |
|
|
|
64 |
|
|
## TODO: documentation |
65 |
|
|
sub manakai_immediate_propagation_stopped ($); |
66 |
|
|
|
67 |
|
|
sub namespace_uri ($); |
68 |
|
|
|
69 |
|
|
## TODO: documentation |
70 |
|
|
sub manakai_propagation_stopped ($); |
71 |
|
|
|
72 |
|
|
sub target ($); |
73 |
|
|
|
74 |
|
|
sub time_stamp ($); |
75 |
|
|
|
76 |
|
|
sub type ($); |
77 |
|
|
|
78 |
|
|
## The |Event| interface - methods |
79 |
|
|
|
80 |
|
|
sub init_event ($$;$$) { |
81 |
|
|
my $self = $_[0]; |
82 |
|
|
unless ($self->{manakai_dispatched}) { |
83 |
wakaba |
1.2 |
delete $self->{namespace_uri}; |
84 |
wakaba |
1.1 |
$self->{type} = ''.$_[1]; |
85 |
|
|
$self->{bubbles} = $_[2]; |
86 |
|
|
$self->{cancelable} = $_[3]; |
87 |
|
|
} |
88 |
|
|
} # init_event |
89 |
|
|
|
90 |
|
|
sub init_event_ns ($$;$$) { |
91 |
|
|
my $self = $_[0]; |
92 |
|
|
unless ($self->{manakai_dispatched}) { |
93 |
wakaba |
1.2 |
unless (not defined $_[1] or $_[1] eq '') { |
94 |
wakaba |
1.1 |
$self->{namespace_uri} = $_[1]; |
95 |
wakaba |
1.2 |
} else { |
96 |
|
|
delete $self->{namespace_uri}; |
97 |
wakaba |
1.1 |
} |
98 |
|
|
$self->{type} = ''.$_[2]; |
99 |
|
|
$self->{bubbles} = $_[3]; |
100 |
|
|
$self->{cancelable} = $_[4]; |
101 |
|
|
} |
102 |
|
|
} # init_event_ns |
103 |
|
|
|
104 |
|
|
sub prevent_default ($) { |
105 |
|
|
if ($_[0]->{cancelable}) { |
106 |
|
|
$_[0]->{default_prevented} = 1; |
107 |
|
|
} |
108 |
|
|
} # prevent_default |
109 |
|
|
|
110 |
|
|
sub stop_immediate_propagation ($) { |
111 |
|
|
$_[0]->{manakai_immediate_propagation_stopped} = 1; |
112 |
|
|
$_[0]->{manakai_propagation_stopped} = 1; |
113 |
|
|
} # stop_immediate_propagation |
114 |
|
|
|
115 |
|
|
sub stop_propagation ($) { |
116 |
|
|
$_[0]->{manakai_propagation_stopped} = 1; |
117 |
|
|
} # stop_propagation |
118 |
|
|
|
119 |
|
|
package Message::DOM::Event::CustomEvent; |
120 |
|
|
push our @ISA, 'Message::DOM::Event', 'Message::IF::CustomEvent'; |
121 |
|
|
|
122 |
|
|
## The |CustomEvent| interface - attribute |
123 |
|
|
|
124 |
|
|
sub detail ($); |
125 |
|
|
|
126 |
|
|
## The |CustomEvent| interface - method |
127 |
|
|
|
128 |
|
|
sub init_custom_event_ns ($$$;$$$) { |
129 |
|
|
my $self = $_[0]; |
130 |
|
|
unless ($self->{manakai_dispatched}) { |
131 |
wakaba |
1.2 |
unless (not defined $_[1] or $_[1] eq '') { |
132 |
wakaba |
1.1 |
$self->{namespace_uri} = $_[1]; |
133 |
wakaba |
1.2 |
} else { |
134 |
|
|
delete $self->{namespace_uri}; |
135 |
wakaba |
1.1 |
} |
136 |
|
|
$self->{type} = ''.$_[2]; |
137 |
|
|
$self->{bubbles} = $_[3]; |
138 |
|
|
$self->{cancelable} = $_[4]; |
139 |
|
|
$self->{detail} = $_[5]; |
140 |
|
|
} |
141 |
|
|
} # init_custom_event_ns |
142 |
|
|
|
143 |
|
|
package Message::IF::Event; |
144 |
|
|
package Message::IF::CustomEvent; |
145 |
|
|
|
146 |
|
|
1; |