| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Header: /cvsroot/html2ps/css.rules.inc.php,v 1.10 2007/03/23 18:33:34 Konstantin Exp $
|
|
|
3 |
|
|
|
4 |
class CSSRule {
|
|
|
5 |
var $selector;
|
|
|
6 |
var $body;
|
|
|
7 |
var $baseurl;
|
|
|
8 |
var $order;
|
|
|
9 |
|
|
|
10 |
var $specificity;
|
|
|
11 |
var $pseudoelement;
|
|
|
12 |
|
|
|
13 |
function apply(&$root, &$state, &$pipeline) {
|
|
|
14 |
$pipeline->push_base_url($this->baseurl);
|
|
|
15 |
$this->body->apply($state);
|
|
|
16 |
$pipeline->pop_base_url();
|
|
|
17 |
}
|
|
|
18 |
|
|
|
19 |
function add_property($property) {
|
|
|
20 |
$this->body->add_property($property);
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
function CSSRule($rule, &$pipeline) {
|
|
|
24 |
$this->selector = $rule[0];
|
|
|
25 |
$this->body = $rule[1]->copy();
|
|
|
26 |
$this->baseurl = $rule[2];
|
|
|
27 |
$this->order = $rule[3];
|
|
|
28 |
|
|
|
29 |
$this->specificity = css_selector_specificity($this->selector);
|
|
|
30 |
$this->pseudoelement = css_find_pseudoelement($this->selector);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
function set_property($key, $value, &$pipeline) {
|
|
|
34 |
$this->body->set_property_value($key, $value);
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
function &get_property($key) {
|
|
|
38 |
return $this->body->get_property_value($key);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
function get_order() { return $this->order; }
|
|
|
42 |
function get_pseudoelement() { return $this->pseudoelement; }
|
|
|
43 |
function get_selector() { return $this->selector; }
|
|
|
44 |
function get_specificity() { return $this->specificity; }
|
|
|
45 |
|
|
|
46 |
function match($root) {
|
|
|
47 |
return match_selector($this->selector, $root);
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
function rule_get_selector(&$rule) { return $rule[0]; };
|
|
|
52 |
|
|
|
53 |
function cmp_rules($r1, $r2) {
|
|
|
54 |
$a = css_selector_specificity($r1[0]);
|
|
|
55 |
$b = css_selector_specificity($r2[0]);
|
|
|
56 |
|
|
|
57 |
for ($i=0; $i<=2; $i++) {
|
|
|
58 |
if ($a[$i] != $b[$i]) { return ($a[$i] < $b[$i]) ? -1 : 1; };
|
|
|
59 |
};
|
|
|
60 |
|
|
|
61 |
// If specificity of selectors is equal, use rules natural order in stylesheet
|
|
|
62 |
|
|
|
63 |
return $r1[3] < $r2[3] ? -1 : 1;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
function cmp_rule_objs($r1, $r2) {
|
|
|
67 |
$a = $r1->get_specificity();
|
|
|
68 |
$b = $r2->get_specificity();
|
|
|
69 |
|
|
|
70 |
for ($i=0; $i<=2; $i++) {
|
|
|
71 |
if ($a[$i] != $b[$i]) { return ($a[$i] < $b[$i]) ? -1 : 1; };
|
|
|
72 |
};
|
|
|
73 |
|
|
|
74 |
// If specificity of selectors is equal, use rules natural order in stylesheet
|
|
|
75 |
|
|
|
76 |
return $r1->get_order() < $r2->get_order() ? -1 : 1;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
?>
|