1 |
wakaba |
1.1 |
package Message::DOM::Window; |
2 |
|
|
use strict; |
3 |
|
|
require Scalar::Util; |
4 |
|
|
push our @ISA, 'Message::IF::AbstractView', |
5 |
|
|
'Message::IF::Window', |
6 |
|
|
'Message::IF::ViewCSS'; |
7 |
|
|
|
8 |
|
|
## NOTE: We don't support multiple views - all the views are |
9 |
|
|
## the default views. |
10 |
|
|
|
11 |
|
|
## NOTE: The current implementation does not support non-CSS views. |
12 |
|
|
|
13 |
|
|
sub ___new ($$) { |
14 |
|
|
my $self = bless \{ |
15 |
|
|
#___css |
16 |
|
|
#___css_options => {}, |
17 |
|
|
___user_style_sheets => [], ___ua_style_sheets => [], |
18 |
|
|
}, shift; |
19 |
|
|
$$self->{___implementation} = shift; |
20 |
|
|
|
21 |
|
|
my $doc = $$self->{document} = $$self->{___implementation}->create_document; |
22 |
|
|
$$doc->{default_view} = $self; |
23 |
|
|
Scalar::Util::weaken ($$doc->{default_view}); |
24 |
|
|
|
25 |
|
|
$doc->manakai_is_html (1); |
26 |
|
|
$doc->inner_html (q[<!DOCTYPE HTML><title></title><body>]); |
27 |
|
|
$self->___reset_css; |
28 |
|
|
|
29 |
|
|
return $self; |
30 |
|
|
} # ___new |
31 |
|
|
|
32 |
|
|
## |AbstractView| attribute |
33 |
|
|
|
34 |
|
|
sub document ($) { ${$_[0]}->{document} } |
35 |
|
|
|
36 |
|
|
## |ViewCSS| methods |
37 |
|
|
|
38 |
|
|
sub get_computed_style ($$;$) { |
39 |
|
|
my $css = ${$_[0]}->{___css}; |
40 |
|
|
|
41 |
|
|
## TODO: pseudo element |
42 |
|
|
## TODO: element not part of this document or not part of document tree |
43 |
|
|
## TODO: Sameness of return values of multiple invocations. |
44 |
|
|
|
45 |
|
|
require Message::DOM::CSSStyleDeclaration; |
46 |
|
|
return Message::DOM::CSSComputedStyleDeclaration->____new ($css, $_[1]); |
47 |
|
|
} # get_computed_style |
48 |
|
|
|
49 |
|
|
sub ___set_css_options ($$) { |
50 |
|
|
${$_[0]}->{___css_options} = $_[1]; |
51 |
|
|
} # ___set_css_options |
52 |
|
|
|
53 |
|
|
sub ___set_ua_style_sheets ($$) { |
54 |
|
|
${$_[0]}->{___ua_style_sheets} = $_[1]; |
55 |
|
|
} # ___set_ua_style_sheets |
56 |
|
|
|
57 |
|
|
sub ___set_user_style_sheets ($$) { |
58 |
|
|
${$_[0]}->{___user_style_sheets} = $_[1]; |
59 |
|
|
} # ___set_user_style_sheets |
60 |
|
|
|
61 |
|
|
sub ___reset_css ($) { |
62 |
|
|
my $self = shift; |
63 |
|
|
require Whatpm::CSS::Cascade; |
64 |
wakaba |
1.2 |
my $cas = Whatpm::CSS::Cascade->new ($$self->{document}); |
65 |
wakaba |
1.1 |
$cas->{has_invert} |
66 |
|
|
= $$self->{___css_options}->{prop_value}->{'outline-color'}->{invert}; |
67 |
|
|
|
68 |
|
|
## TODO: ... |
69 |
|
|
$cas->add_style_sheets ([@{$$self->{___user_style_sheets}}, |
70 |
|
|
@{$$self->{___ua_style_sheets}}]); |
71 |
|
|
|
72 |
|
|
$cas->___associate_rules; |
73 |
|
|
$$self->{___css} = $cas; |
74 |
|
|
} # ___reset_css |
75 |
|
|
|
76 |
|
|
## |Window| methods |
77 |
|
|
|
78 |
|
|
## NOTE: An Opera extension. |
79 |
|
|
sub set_document ($$) { |
80 |
|
|
## NOTE: See <http://suika.fam.cx/gate/2005/sw/setDocument>. |
81 |
|
|
|
82 |
|
|
my $self = shift; |
83 |
|
|
|
84 |
|
|
my $new_doc = shift; |
85 |
|
|
return if $new_doc->default_view; |
86 |
|
|
|
87 |
|
|
## NOTE: When $new_doc eq $self->document, only re-rendering |
88 |
|
|
## should be happen. |
89 |
|
|
|
90 |
|
|
my $old_doc = $$self->{document}; |
91 |
|
|
if ($old_doc) { |
92 |
|
|
delete $$old_doc->{default_view}; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
$$self->{document} = $new_doc; |
96 |
|
|
$$new_doc->{default_view} = $self; |
97 |
|
|
Scalar::Util::weaken ($$new_doc->{default_view}); |
98 |
|
|
|
99 |
|
|
$self->___reset_css; |
100 |
|
|
} # set_document |
101 |
|
|
|
102 |
|
|
package Message::IF::AbstractView; |
103 |
|
|
package Message::IF::ViewCSS; |
104 |
|
|
package Message::IF::Window; |
105 |
|
|
|
106 |
|
|
1; |
107 |
wakaba |
1.2 |
## $Date: 2008/01/13 06:37:47 $ |