|
## NOTE: This module will be renamed as Document.pm. |
|
|
|
|
1 |
package Message::DOM::Document; |
package Message::DOM::Document; |
2 |
use strict; |
use strict; |
3 |
our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
push our @ISA, 'Message::DOM::Node', 'Message::IF::Document', |
push our @ISA, 'Message::DOM::Node', 'Message::IF::Document', |
5 |
'Message::IF::DocumentTraversal', 'Message::IF::DocumentXDoctype', |
'Message::IF::DocumentTraversal', 'Message::IF::DocumentXDoctype', |
6 |
|
'Message::IF::DocumentSelector', # MUST in Selectors API spec |
7 |
'Message::IF::HTMLDocument'; |
'Message::IF::HTMLDocument'; |
8 |
require Message::DOM::Node; |
require Message::DOM::Node; |
9 |
use Char::Class::XML |
use Char::Class::XML |
37 |
|
|
38 |
if ({ |
if ({ |
39 |
## Read-only attributes (trivial accessors) |
## Read-only attributes (trivial accessors) |
40 |
|
default_view => 1, |
41 |
implementation => 1, |
implementation => 1, |
42 |
}->{$method_name}) { |
}->{$method_name}) { |
43 |
no strict 'refs'; |
no strict 'refs'; |
49 |
goto &{ $AUTOLOAD }; |
goto &{ $AUTOLOAD }; |
50 |
} elsif ({ |
} elsif ({ |
51 |
## Read-write attributes (DOMString, trivial accessors) |
## Read-write attributes (DOMString, trivial accessors) |
52 |
|
manakai_charset => 1, |
53 |
document_uri => 1, |
document_uri => 1, |
54 |
input_encoding => 1, |
input_encoding => 1, |
55 |
}->{$method_name}) { |
}->{$method_name}) { |
77 |
} elsif ({ |
} elsif ({ |
78 |
## Read-write attributes (boolean, trivial accessors) |
## Read-write attributes (boolean, trivial accessors) |
79 |
all_declarations_processed => 1, |
all_declarations_processed => 1, |
80 |
|
manakai_has_bom => 1, |
81 |
}->{$method_name}) { |
}->{$method_name}) { |
82 |
no strict 'refs'; |
no strict 'refs'; |
83 |
eval qq{ |
eval qq{ |
101 |
}; |
}; |
102 |
goto &{ $AUTOLOAD }; |
goto &{ $AUTOLOAD }; |
103 |
} elsif (my $module_name = { |
} elsif (my $module_name = { |
104 |
|
can_dispatch => 'Message::DOM::EventTargetNode', |
105 |
create_attribute => 'Message::DOM::Attr', |
create_attribute => 'Message::DOM::Attr', |
106 |
create_attribute_ns => 'Message::DOM::Attr', |
create_attribute_ns => 'Message::DOM::Attr', |
107 |
create_attribute_definition => 'Message::DOM::AttributeDefinition', |
create_attribute_definition => 'Message::DOM::AttributeDefinition', |
113 |
create_element_ns => 'Message::DOM::Element', |
create_element_ns => 'Message::DOM::Element', |
114 |
create_element_type_definition => 'Message::DOM::ElementTypeDefinition', |
create_element_type_definition => 'Message::DOM::ElementTypeDefinition', |
115 |
create_entity_reference => 'Message::DOM::EntityReference', |
create_entity_reference => 'Message::DOM::EntityReference', |
116 |
|
create_event => 'Message::DOM::EventTargetNode', |
117 |
create_general_entity => 'Message::DOM::Entity', |
create_general_entity => 'Message::DOM::Entity', |
118 |
create_notation => 'Message::DOM::Notation', |
create_notation => 'Message::DOM::Notation', |
119 |
create_processing_instruction => 'Message::DOM::ProcessingInstruction', |
create_processing_instruction => 'Message::DOM::ProcessingInstruction', |
120 |
manakai_create_serial_walker => 'Message::DOM::SerialWalker', |
manakai_create_serial_walker => 'Message::DOM::SerialWalker', |
121 |
create_text_node => 'Message::DOM::Text', |
create_text_node => 'Message::DOM::Text', |
122 |
create_tree_walker => 'Message::DOM::TreeWalker', |
create_tree_walker => 'Message::DOM::TreeWalker', |
123 |
|
query_selector => 'Message::DOM::SelectorsAPI', |
124 |
|
query_selector_all => 'Message::DOM::SelectorsAPI', |
125 |
|
___query_selector_all => 'Message::DOM::SelectorsAPI', |
126 |
}->{$method_name}) { |
}->{$method_name}) { |
127 |
eval qq{ require $module_name } or die $@; |
eval qq{ require $module_name } or die $@; |
128 |
goto &{ $AUTOLOAD }; |
goto &{ $AUTOLOAD }; |
216 |
-object => $self, |
-object => $self, |
217 |
-type => 'NOT_SUPPORTED_ERR', |
-type => 'NOT_SUPPORTED_ERR', |
218 |
-subtype => 'ADOPT_NODE_TYPE_NOT_SUPPORTED_ERR'; |
-subtype => 'ADOPT_NODE_TYPE_NOT_SUPPORTED_ERR'; |
|
## ISSUE: Define ELEMENT_TYPE_DEFINITION_NODE and ATTRIBUTE_DEFINITION_NODE |
|
219 |
} |
} |
220 |
|
|
221 |
my @change_od; |
my @change_od; |
815 |
## NOTE: A manakai extension. |
## NOTE: A manakai extension. |
816 |
sub all_declarations_processed ($;$); |
sub all_declarations_processed ($;$); |
817 |
|
|
818 |
|
## TODO: documentation |
819 |
|
sub manakai_charset ($;$); |
820 |
|
|
821 |
sub doctype ($) { |
sub doctype ($) { |
822 |
my $self = $_[0]; |
my $self = $_[0]; |
823 |
for (@{$self->child_nodes}) { |
for (@{$self->child_nodes}) { |
870 |
} |
} |
871 |
} # manakai_entity_base_uri |
} # manakai_entity_base_uri |
872 |
|
|
873 |
|
## TODO: documentation |
874 |
|
sub manakai_has_bom ($;$); |
875 |
|
|
876 |
sub input_encoding ($;$); |
sub input_encoding ($;$); |
877 |
|
|
878 |
sub strict_error_checking ($;$) { |
sub strict_error_checking ($;$) { |
1083 |
|
|
1084 |
sub create_tree_walker ($$;$$$); |
sub create_tree_walker ($$;$$$); |
1085 |
|
|
1086 |
|
## |DocumentView| attribute |
1087 |
|
|
1088 |
|
sub default_view ($); |
1089 |
|
|
1090 |
## |HTMLDocument| attributes |
## |HTMLDocument| attributes |
1091 |
|
|
1092 |
sub compat_mode ($) { |
sub compat_mode ($) { |
1111 |
} |
} |
1112 |
} # manakai_compat_mode |
} # manakai_compat_mode |
1113 |
|
|
1114 |
|
## TODO: documentation |
1115 |
|
sub manakai_head ($) { |
1116 |
|
local $Error::Depth = $Error::Depth + 1; |
1117 |
|
my $html = $_[0]->manakai_html; |
1118 |
|
return undef unless defined $html; |
1119 |
|
for my $el (@{$html->child_nodes}) { |
1120 |
|
next unless $el->node_type == 1; # ELEMENT_NODE |
1121 |
|
my $nsuri = $el->namespace_uri; |
1122 |
|
next unless defined $nsuri; |
1123 |
|
next unless $nsuri eq q<http://www.w3.org/1999/xhtml>; |
1124 |
|
next unless $el->manakai_local_name eq 'head'; |
1125 |
|
return $el; |
1126 |
|
} |
1127 |
|
return undef; |
1128 |
|
} # manakai_head |
1129 |
|
|
1130 |
|
## TODO: documentation |
1131 |
|
sub manakai_html ($) { |
1132 |
|
local $Error::Depth = $Error::Depth + 1; |
1133 |
|
my $de = $_[0]->document_element; |
1134 |
|
my $nsuri = $de->namespace_uri; |
1135 |
|
if (defined $nsuri and $nsuri eq q<http://www.w3.org/1999/xhtml> and |
1136 |
|
$de->manakai_local_name eq 'html') { |
1137 |
|
return $de; |
1138 |
|
} else { |
1139 |
|
return undef; |
1140 |
|
} |
1141 |
|
} # manakai_html |
1142 |
|
|
1143 |
sub inner_html ($;$) { |
sub inner_html ($;$) { |
1144 |
my $self = $_[0]; |
my $self = $_[0]; |
1145 |
local $Error::Depth = $Error::Depth + 1; |
local $Error::Depth = $Error::Depth + 1; |
1166 |
return unless defined wantarray; |
return unless defined wantarray; |
1167 |
} |
} |
1168 |
|
|
1169 |
return ${ Whatpm::HTML->get_inner_html ($self) }; |
require Whatpm::HTML::Serializer; |
1170 |
|
return ${ Whatpm::HTML::Serializer->get_inner_html ($self) }; |
1171 |
} else { |
} else { |
1172 |
if (@_ > 1) { |
if (@_ > 1) { |
1173 |
## Step 1 |
## Step 1 |
1174 |
require Whatpm::XMLParser; # MUST |
require Whatpm::XML::Parser; # MUST |
1175 |
my $doc = $self->implementation->create_document; |
my $doc = $self->implementation->create_document; |
1176 |
|
|
1177 |
## Step 2 |
## Step 2 |
1178 |
# |
# |
1179 |
|
|
1180 |
## Step 3 |
## Step 3 |
1181 |
$doc = Whatpm::XMLParser->parse_string ($_[1] => $doc); # MUST |
$doc = Whatpm::XML::Parser->parse_char_string ($_[1] => $doc); # MUST |
1182 |
|
|
1183 |
## Step 4 |
## Step 4 |
1184 |
# |
# |
1191 |
for (@cn) { |
for (@cn) { |
1192 |
$self->remove_child ($_); |
$self->remove_child ($_); |
1193 |
} |
} |
1194 |
|
## TODO: strict-document-children option? |
1195 |
|
|
1196 |
## Step 7, 8, 9, 10 |
## Step 7, 8, 9, 10 |
1197 |
for my $node (@{$doc->child_nodes}) { |
for my $node (@{$doc->child_nodes}) { |
1204 |
## TODO: This serializer is currently not conformant to HTML5 spec. |
## TODO: This serializer is currently not conformant to HTML5 spec. |
1205 |
require Whatpm::XMLSerializer; |
require Whatpm::XMLSerializer; |
1206 |
my $r = ''; |
my $r = ''; |
1207 |
for (@{$self->child_nodes}) { |
for my $node (@{$self->child_nodes}) { |
1208 |
$r .= ${ Whatpm::XMLSerializer->get_outer_xml ($_, sub { |
$r .= ${ Whatpm::XMLSerializer->get_outer_xml ($node, sub { |
1209 |
## TODO: INVALID_STATE_ERR |
## TODO: INVALID_STATE_ERR |
1210 |
}) }; |
}) }; |
1211 |
} |
} |
1228 |
package Message::IF::Document; |
package Message::IF::Document; |
1229 |
package Message::IF::DocumentTraversal; |
package Message::IF::DocumentTraversal; |
1230 |
package Message::IF::DocumentXDoctype; |
package Message::IF::DocumentXDoctype; |
1231 |
|
package Message::IF::DocumentSelector; |
1232 |
package Message::IF::HTMLDocument; |
package Message::IF::HTMLDocument; |
1233 |
|
|
1234 |
package Message::DOM::DOMImplementation; |
package Message::DOM::DOMImplementation; |