/[suikacvs]/webroot/www/css/jsie/Selectors.js
Suika

Contents of /webroot/www/css/jsie/Selectors.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download) (as text)
Sun Dec 30 03:09:38 2007 UTC (17 years, 3 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
File MIME type: application/javascript
Error occurred while calculating annotation data.
Copied from http://suika.fam.cx/gate/cvs/www/cx/fam/suika/y2005/CSS/

1 if (typeof (cx) == "undefined") {
2 cx = {};
3 }
4 if (typeof (cx.fam) == "undefined") {
5 cx.fam = {};
6 }
7 if (typeof (cx.fam.suika) == "undefined") {
8 cx.fam.suika = {};
9 }
10 if (typeof (cx.fam.suika.y2005) == "undefined") {
11 cx.fam.suika.y2005 = {};
12 }
13 if (typeof (cx.fam.suika.y2005.CSS) == "undefined") {
14 cx.fam.suika.y2005.CSS = {};
15 }
16 if (typeof (cx.fam.suika.y2005.CSS.Selectors) == "undefined") {
17 cx.fam.suika.y2005.CSS.Selectors = {};
18 }
19
20 JSAN.require ("cx.fam.suika.y2005.Class.Inherit");
21 JSAN.require ("cx.fam.suika.y2005.DOM.Implementation");
22 JSAN.require ("cx.fam.suika.y2005.DOM.Node");
23 cx.fam.suika.y2005.DOM.Node.requireDOMNodeFeature
24 ("http://suika.fam.cx/www/cx/fam/suika/y2005/ElementClass#", "1.0");
25
26 /**
27 Escapes a string as an |IDENT|.
28 */
29 cx.fam.suika.y2005.CSS.Selectors._EscapeIdent = function (s) {
30 return s.replace
31 (/([\u0000-\u002C\u002E\u002F\u003A-\u0040\u005B-\u005E\u0080\u007B-\u007F]|^[0-9]|^-$)/g,
32 function (c) {
33 if (!c.match (/^[\u0000-\u0020\u007F]/)) {
34 return "\\" + c;
35 } else {
36 var e = "000000"
37 + c.charCodeAt (0).toString (16).toUpperCase ();
38 return "\\" + e.substring (e.length - 6);
39 }
40 });
41 };
42
43 /**
44 Interface |SelectorsImplementation|
45 */
46 cx.fam.suika.y2005.DOM.Implementation.DOMImplementation._AddFeature
47 ("http://suika.fam.cx/www/cx/fam/suika/y2005/CSS/Selectors#", "1.0", {
48 /**
49 Creates an empty |SSelectorsGroup| object.
50 */
51 createSSelectorsGroup: function () {
52 return new cx.fam.suika.y2005.CSS.Selectors.SelectorsGroup ();
53 },
54
55 /**
56 Creates an empty |SSelector| object.
57 */
58 createSSelector: function () {
59 return new cx.fam.suika.y2005.CSS.Selectors.Selector ();
60 },
61
62 /**
63 Creates an |SSimpleSelectorSequence| object.
64
65 @param typesel A type or universal selector.
66 */
67 createSSimpleSelectorSequence: function (typesel) {
68 return new cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence (typesel);
69 },
70
71 /**
72 Creates an |STypeSelector| object.
73
74 @param namespaceURI The namespace URI, or |null|.
75 @param prefix The namespace prefix, |*|, an empty string, or |null|.
76 @param localName The local name, |*|, or |null| (implied universal selector).
77 If |null|, |prefix| is ignored.
78 */
79 createSTypeSelectorNS: function (namespaceURI, prefix, localName) {
80 if (localName == null) prefix = null;
81 return new cx.fam.suika.y2005.CSS.Selectors.TypeSelector
82 (namespaceURI, prefix, localName);
83 },
84
85 /**
86 Creates an |SAttributeSelector| object.
87
88 @param namespaceURI The namespace URI, or |null|.
89 @param prefix The namespace prefix, |*|, an empty string, or |null|.
90 @param localName The local name.
91 @param operator The operator constant.
92 @param value The attribute value, or |null|.
93 */
94 createSAttributeSelectorNS:
95 function (namespaceURI, prefix, localName, operator, value) {
96 return new cx.fam.suika.y2005.CSS.Selectors.AttributeSelector
97 (namespaceURI, prefix, localName, operator, value);
98 },
99
100 /**
101 Creates an |SClassSelector| object.
102
103 @param className The class name.
104 */
105 createSClassSelector: function (className) {
106 return new cx.fam.suika.y2005.CSS.Selectors.ClassSelector (className);
107 },
108
109 /**
110 Creates an |SIDSelector| object.
111
112 @param id The identifier.
113 */
114 createSIDSelector: function (id) {
115 return new cx.fam.suika.y2005.CSS.Selectors.IDSelector (id);
116 },
117
118 /**
119 Creates an |SPseudoClass| object.
120
121 @param namespaceURI The namespace URI of the pseudo class.
122 @param prefix The namespace prefix of the pseudo class.
123 @param localName The local name of the pseudo class.
124 @throws DOMException |NOT_SUPPORTED_ERR|: If the implementation does
125 not support the creation of the pseudo class by
126 this method, because it does not support the pseudo
127 class entirely or it does support it but the pseudo
128 class requires one or more functional parameter.
129 In the later case, separate method to create the pseudo
130 class should be provided.
131 */
132 createSPseudoClassNS: function (namespaceURI, prefix, localName) {
133 return new cx.fam.suika.y2005.CSS.Selectors.PseudoClass
134 (namespaceURI, prefix, localName);
135 },
136
137 /**
138 Creates an |SPseudoElement| object.
139
140 @param namespaceURI The namespace URI of the pseudo element.
141 @param prefix The namespace prefix of the pseudo element.
142 @param localName The local name of the pseudo element.
143 @throws DOMException |NOT_SUPPORTED_ERR|: If the implementation does
144 not support the creation of the pseudo element by
145 this method, because it does not support the pseudo
146 element entirely or it does support it but the pseudo
147 element requires one or more functional parameter.
148 In the later case, separate method to create the pseudo
149 element should be provided.
150 */
151 createSPseudoElementNS: function (namespaceURI, prefix, localName) {
152 return new cx.fam.suika.y2005.CSS.Selectors.PseudoElement
153 (namespaceURI, prefix, localName);
154 },
155
156 /**
157 Creates a specificity object.
158
159 @param a |a| value.
160 @param b |b| value.
161 @param c |c| value.
162 @param d |d| value.
163 */
164 createSSpecificity: function (a, b, c, d) {
165 return new cx.fam.suika.y2005.CSS.Selectors.Specificity (a, b, c, d);
166 }
167 });
168
169 /**
170 Interface |SSelectorsGroup|
171
172 An |SSelectorsGroup| object represents a group of selectors,
173 or a |COMMA| separated list of selectors.
174 Unlike groups of selectors in Selectors, this object might be empty,
175 i.e. |length| might be zero. Serializing such object (i.e. |selectorText|)
176 will result in an invalid selector.
177 */
178 cx.fam.suika.y2005.CSS.Selectors.SelectorsGroup = function () {
179 this.v = [];
180 };
181
182 /**
183 Adds a selector to the group.
184
185 @param sel The selector object to add.
186 */
187 cx.fam.suika.y2005.CSS.Selectors.SelectorsGroup.prototype.appendSelector =
188 function (sel) {
189 this.v.push (sel);
190 };
191
192 /**
193 Returns the |index|th selector in the group, if any, or |null|.
194
195 @param index The ordinal index of the selector, starting from zero.
196 @return The |index|th selector or |null|.
197 */
198 cx.fam.suika.y2005.CSS.Selectors.SelectorsGroup.prototype.item = function (index) {
199 return this.v[index];
200 };
201
202 /**
203 The number of selectors in the group.
204
205 @return The number of selectors.
206 */
207 cx.fam.suika.y2005.CSS.Selectors.SelectorsGroup.prototype.getLength = function () {
208 return this.v.length;
209 };
210
211 /**
212 Tests whether the selector matched to an element node or not.
213
214 @param elementNode An element node to test.
215 @param pseudoElements A |SSimpleSelectorSequence| object, or |null|.
216 The selector and the |elementNode| match if
217 |pseudoElements| is non-|null| and the list of pseudo
218 elements in the selector is equal to the list of pseudo
219 elements in the element node, or if |pseudoElements|
220 is |null|.
221
222 Note. Any simple selector other than pseudo element
223 in |pseudoElements| is ignored.
224 @return If match, |true|, or |false| otherwise.
225 */
226 cx.fam.suika.y2005.CSS.Selectors.SelectorsGroup.prototype.matchElement =
227 function (elementNode, pseudoElements) {
228 for (var i = 0; i < this.v.length; i++) {
229 if (this.v[i].matchElement (elementNode, pseudoElements)) {
230 return true;
231 }
232 }
233 return false;
234 };
235
236 /**
237 A textual representation of the object.
238
239 Note. The returned string might be an invalid selector, in cases, for example:
240 - if a type selector has undeclared namespace prefix,
241 - if the group has no selector,
242 - or so on.
243
244 @return A textual representation.
245 */
246 cx.fam.suika.y2005.CSS.Selectors.SelectorsGroup.prototype.getSelectorText =
247 function () {
248 var r = this.v[0] != null ? this.v[0].getSelectorText () : "";
249 for (var i = 1; i < this.v.length; i++) {
250 r += ",\n" + this.v[i].getSelectorText ();
251 }
252 return r;
253 };
254
255 cx.fam.suika.y2005.CSS.Selectors.SelectorsGroup.prototype.toString = function () {
256 return "[object SSelectorsGroup]";
257 };
258
259
260 /**
261 Interface |SSelector|
262
263 An |SSelector| object represents a selector,
264 or a list of simple selector sequences separeted by combinators.
265 Unlike selectors in Selectors, this object might be empty,
266 i.e. |length| might be zero. Serializing such object (i.e. |selectorText|)
267 will result in an invalid selector.
268 */
269 cx.fam.suika.y2005.CSS.Selectors.Selector = function () {
270 this.v = [];
271 this.cmbs = [null];
272 };
273
274 /**
275 Adds a simple selector sequence to the selector.
276
277 @param combinator The combinator that separates the previous simple selector
278 sequence and the new one.
279 @param sel The simple selector sequence object to add.
280 */
281 cx.fam.suika.y2005.CSS.Selectors.Selector.prototype.appendSimpleSelectorSequence =
282 function (combinator, sel) {
283 if (this.v.length != 0) this.cmbs.push (combinator);
284 this.v.push (sel);
285 };
286
287 /**
288 Returns the |index + 1|'th combinator, i.e. the combinator between
289 |index - 1|'th and |index|th simple selector sequences in the selector,
290 if any, or |null|.
291
292 @param index The ordinal index of the combinator, starting from one.
293 @return The |index|th combinator or |null|.
294 */
295 cx.fam.suika.y2005.CSS.Selectors.Selector.prototype.getCombinator = function (index) {
296 return this.cmbs[index];
297 };
298 cx.fam.suika.y2005.CSS.Selectors.Selector
299 .prototype.SELECTORS_COMBINATOR_DESCENDANT = 1;
300 cx.fam.suika.y2005.CSS.Selectors.Selector
301 .prototype.SELECTORS_COMBINATOR_CHILD = 2;
302 cx.fam.suika.y2005.CSS.Selectors.Selector
303 .prototype.SELECTORS_COMBINATOR_DIRECT_ADJACENT_SIBLING = 3;
304 cx.fam.suika.y2005.CSS.Selectors.Selector
305 .prototype.SELECTORS_COMBINATOR_INDIRECT_ADJACENT_SIBLING = 4;
306
307 /**
308 Returns a |SSimpleSelectorSequence| object that contains pseudo
309 elements.
310
311 @return A pseudo element selector list (possibly empty) or |null| if
312 the selector is empty.
313 */
314 cx.fam.suika.y2005.CSS.Selectors.Selector.prototype.getPseudoElements = function () {
315 return this.v[this.v.length - 1];
316 };
317
318 /**
319 Returns the |index|th simple selector sequence in the selector, if any, or |null|.
320
321 @param index The ordinal index of the sequence, starting from zero.
322 @return The |index|th sequence or |null|.
323 */
324 cx.fam.suika.y2005.CSS.Selectors.Selector.prototype.item = function (index) {
325 return this.v[index];
326 };
327
328 /**
329 The number of simple selector sequences in the selector.
330
331 @return The number of sequences.
332 */
333 cx.fam.suika.y2005.CSS.Selectors.Selector.prototype.getLength = function () {
334 return this.v.length;
335 };
336
337 /**
338 Tests whether the selector matched to an element node or not.
339
340 @param elementNode An element node to test.
341 @param pseudoElements A |SSimpleSelectorSequence| object, or |null|.
342 The selector and the |elementNode| match if
343 |pseudoElements| is non-|null| and the list of pseudo
344 elements in the selector is equal to the list of pseudo
345 elements in the element node, or if |pseudoElements|
346 is |null|.
347
348 Note. Any simple selector other than pseudo element
349 in |pseudoElements| is ignored.
350 @return If match, |true|, or |false| otherwise.
351 */
352 cx.fam.suika.y2005.CSS.Selectors.Selector.prototype.matchElement =
353 function (elementNode, pseudoElements) {
354 var i = this.v.length - 1;
355 if (i == -1) return false /* ISSUE: Should be |true|? Or |false|? */;
356 if (!this.v[i].matchElement (elementNode, pseudoElements)) {
357 return false;
358 }
359
360 var epe = new cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence (null);
361 SSS: for (; i > 0; i--) {
362 switch (this.cmbs[i + 1]) {
363 case this.SELECTORS_COMBINATOR_CHILD:
364 elementNode = elementNode.getParentElement ();
365 if (elementNode == null) return false;
366 if (!this.v[i].matchElement (elementNode, epe)) {
367 return false;
368 }
369 continue SSS;
370 case this.SELECTORS_COMBINATOR_DESCENDANT:
371 elementNode = elementNode.getParentElement ();
372 while (elementNode != null) {
373 if (this.v[i].matchElement (elementNode, epe)) {
374 continue SSS;
375 }
376 elementNode = elementNode.getParentElement ();
377 }
378 return false;
379 case this.SELECTORS_COMBINATOR_DIRECT_ADJACENT_SIBLING:
380 elementNode = elementNode.getPreviousSiblingElement ();
381 if (elementNode == null) return false;
382 if (!this.v[i].matchElement (elementNode, epe)) {
383 return false;
384 }
385 continue SSS;
386 case this.SELECTORS_COMBINATOR_INDIRECT_ADJACENT_SIBLING:
387 elementNode = elementNode.getPreviousSiblingElement ();
388 while (elementNode != null) {
389 if (this.v[i].matchElement (elementNode, epe)) {
390 continue SSS;
391 }
392 elementNode = elementNode.getPreviousSiblingElement ();
393 }
394 return false;
395 default:
396 return false;
397 }
398 } /* SSS */
399 return true;
400 };
401
402 /**
403 A textual representation of the object.
404
405 Note. The returned string might be an invalid selector, in cases, for example:
406 - if a type selector has undeclared namespace prefix,
407 - if the selector has no simple selector sequence,
408 - if the simple selector sequence other than the last one
409 contains one or more pseudo elements,
410 - or so on.
411
412 @return A textual representation.
413 */
414 cx.fam.suika.y2005.CSS.Selectors.Selector.prototype.getSelectorText =
415 function () {
416 var r = this.v[0] != null ? this.v[0].getSelectorText () : "";
417 for (var i = 1; i < this.v.length; i++) {
418 if (this.cmbs[i] == this.SELECTORS_COMBINATOR_CHILD) {
419 r += " +";
420 } else if (this.cmbs[i] == this.SELECTORS_COMBINATOR_DIRECT_ADJACENT_SIBLING) {
421 r += " >";
422 } else if (this.cmbs[i] == this.SELECTORS_COMBINATOR_INDIRECT_ADJACENT_SIBLING) {
423 r += " ~";
424 }
425 r += " " + this.v[i].getSelectorText ();
426 }
427 return r;
428 };
429
430 /**
431 The specificity of the selector.
432 */
433 cx.fam.suika.y2005.CSS.Selectors.Selector.prototype.getSpecificity =
434 function () {
435 var a = 0;
436 var b = 0;
437 var c = 0;
438 var d = 0;
439 for (var i = 0; i < this.v.length; i++) {
440 var s = this.v[i].getSpecificity ();
441 a += s.getA ();
442 b += s.getB ();
443 c += s.getC ();
444 d += s.getD ();
445 }
446 return new cx.fam.suika.y2005.CSS.Selectors.Specificity (a, b, c, d);
447 };
448
449 cx.fam.suika.y2005.CSS.Selectors.Selector.prototype.toString = function () {
450 return "[object SSelector]";
451 };
452
453
454 /**
455 Interface |SSimpleSelectorSequence|
456
457 An |SSimpleSelectorSequence| object represents a simple selector sequence,
458 or a list of simple selector. It was known as simple selectors in CSS
459 Level 2.1.
460
461 Note. Although the universal selector is not explicitly appears in
462 a textual representation of the simple selector sequence,
463 |SSimpleSelectorSequence| objects always hold a type or universal
464 selector object in their |typeSelector| attribute.
465
466 Note. Pseudo elements are part of simple selector sequences in this
467 object model while it is semantically part of selectors in Selectors.
468 */
469 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence = function (typeSelector) {
470 this.typesel = typeSelector != null
471 ? typeSelector
472 : new cx.fam.suika.y2005.CSS.Selectors.TypeSelector
473 (null, null, null);
474 this.sels = [];
475 this.pels = [];
476 };
477
478 /**
479 Adds a pseudo element to the simple selector sequence.
480
481 @param sel The pseudo element object to add.
482 */
483 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype.appendPseudoElement =
484 function (sel) {
485 this.pels.push (sel);
486 };
487
488 /**
489 Adds a simple selector to the simple selector sequence.
490
491 @param sel The simple selector object to add.
492 @throw DOMException HIERARCHY_REQUEST_ERR: If the |sel| object is a
493 type, universal, or pseudo element selector.
494 */
495 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype.appendSimpleSelector
496 = function (sel) {
497 this.sels.push (sel);
498 };
499
500 /**
501 Returns a hash key created from pseudo elements in the simple selector sequence.
502 The hash key...
503 - is an empty string if and only if there is no pseudo element.
504 - matches as string to the hash key from another simple selector sequence
505 if and only if the numbers of their pseudo elements are equal and
506 pseudo elements with same index are equal in |isEqualSimpleSelector|
507 equality.
508 - does not necessarily match to the textual representation of the selector.
509 */
510 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype
511 ._GetPseudoElementHashKey
512 = function () {
513 var r = "";
514 for (var i = 0; i < this.pels.length; i++) {
515 r += this.pels[i]._GetPseudoElementHashKey ();
516 }
517 return r;
518 };
519
520 /**
521 Tests whether the selector matched to an element node or not.
522
523 @param elementNode An element node to test.
524 @param pseudoElements A |SSimpleSelectorSequence| object, or |null|.
525 The selector and the |elementNode| match if
526 |pseudoElements| is non-|null| and the list of pseudo
527 elements in the selector is equal to the list of pseudo
528 elements in the element node, or if |pseudoElements|
529 is |null|.
530
531 Note. Any simple selector other than pseudo element
532 in |pseudoElements| is ignored.
533 @return If match, |true|, or |false| otherwise.
534 */
535 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype.matchElement =
536 function (elementNode, pseudoElements) {
537 /* Pseudo element specifications */
538 if (pseudoElements != null) {
539 if (this.pels.length != pseudoElements.getPseudoElementLength ()) {
540 return false;
541 }
542 for (var i = 0; i < this.pels.length; i++) {
543 if (!this.pels[i].isEqualSimpleSelector (pseudoElements.getPseudoElement (i))) {
544 return false;
545 }
546 }
547 }
548
549 /* Type or universal selector vs element type */
550 if (!this.typesel.matchElement (elementNode, null)) {
551 return false;
552 }
553
554 /* Other simple selectors */
555 for (var i = 0; i < this.sels.length; i++) {
556 if (!this.sels[i].matchElement (elementNode, null)) {
557 return false;
558 }
559 }
560 return true;
561 };
562
563 /**
564 Returns the |index|th pseudo element in the simple selector sequence,
565 if any, or |null|.
566
567 @param index The ordinal index of the pseudo element, starting from zero.
568 @return The |index|th pseudo element, or |null|.
569 */
570 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype.getPseudoElement =
571 function (index) {
572 return this.pels[index];
573 };
574
575 /**
576 Returns the |index|th simple selector in the simple selector sequence,
577 if any, or |null|.
578
579 @param index The ordinal index of the simple selector, starting from zero.
580 @return The |index|th simple selector or |null|.
581 */
582 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype.getSimpleSelector =
583 function (index) {
584 return index == 0 ? this.typesel : this.sels[index];
585 };
586
587 /**
588 The number of pseudo elements in the simple selector sequence.
589
590 @return The number of pseudo elements.
591 */
592 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype
593 .getPseudoElementLength = function () {
594 return this.pels.length;
595 };
596
597 /**
598 A textual representation of the object.
599
600 Note. The returned string might be an invalid selector, in cases, for example:
601 - if a type selector has undeclared namespace prefix,
602 - if the selector has no simple selector sequence,
603 - or so on.
604
605 @return A textual representation.
606 */
607 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype.getSelectorText =
608 function () {
609 var r = this.typesel.getSelectorText ();
610 if (r.length + this.sels.length + this.pels.length == 0) {
611 r = "*";
612 }
613 for (var i = 0; i < this.sels.length; i++) {
614 r += this.sels[i].getSelectorText ();
615 }
616 for (var i = 0; i < this.pels.length; i++) {
617 r += this.pels[i].getSelectorText ();
618 }
619 return r;
620 };
621
622 /**
623 The number of simple selectors in the simple selector sequence.
624
625 @return The number of simple selectors.
626 */
627 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype
628 .getSimpleSelectorLength = function () {
629 return this.sels.length + 1;
630 };
631
632 /**
633 The specificity of the simple selector.
634 */
635 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype.getSpecificity =
636 function () {
637 var a = 0;
638 var b = 0;
639 var c = 0;
640 var d = this.typesel.getSimpleSelectorType () == this.typesel.SELECTORS_TYPE_SELECTOR
641 ? 1 : 0;
642 for (var i = 0; i < this.sels.length; i++) {
643 var s = this.sels[i].getSpecificity ();
644 a += s.getA ();
645 b += s.getB ();
646 c += s.getC ();
647 d += s.getD ();
648 }
649 return new cx.fam.suika.y2005.CSS.Selectors.Specificity (a, b, c, d);
650 };
651
652 /**
653 The type or universal selector in the simple selector sequence.
654
655 @return The type or universal selectors.
656 */
657 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype
658 .getTypeSelector = function () {
659 return this.typesel;
660 };
661
662 cx.fam.suika.y2005.CSS.Selectors.SimpleSelectorSequence.prototype.toString =
663 function () {
664 return "[object SSimpleSelectorSequence]";
665 };
666
667
668 /**
669 Interface |SSimpleSelector|
670
671 An |SSimpleSelector| object represents a simple selector or
672 a pseudo element.
673
674 Note. Unlike in Selectors pseudo elements are treated as simple selectors
675 in this object model.
676 */
677 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector = function () {
678 };
679
680 /**
681 Tests whether a simple selector represents the same thing or not.
682
683 Note. Two simple selectors with different |simpleSelectorType|
684 will never be equal. Two simple selectors with different
685 textual representation might be equal if, e.g., their
686 namespace prefixes are different but the namespace URIs bound
687 to them are the same. Keywords and namespace prefixes are
688 case-insensitive while local names and attribute values are
689 always case-sensitive.
690
691 @param ssel A simple selector to compare.
692 @return If equals, |true|, or |false| otherwise.
693 */
694 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype.isEqualSimpleSelector =
695 function (ssel) {
696 return false;
697 };
698
699 /**
700 Tests whether the selector matched to an element node or not.
701
702 @param elementNode An element node to test.
703 @param pseudoElements If non-|null|, |false| is returned. Otherwise, ignored.
704 @return If match, |true|, or |false| otherwise.
705 */
706 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype.matchElement =
707 function (elementNode, pseudoElements) {
708 return false;
709 };
710
711 /**
712 The kind of simple selector.
713
714 @return The type.
715 */
716 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype.getSimpleSelectorType =
717 function () {
718 return this.SELECTORS_UNKNOWN_SIMPLE_SELECTOR;
719 };
720 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype
721 .SELECTORS_UNKNOWN_SIMPLE_SELECTOR = 0;
722 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype
723 .SELECTORS_TYPE_SELECTOR = 1;
724 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype
725 .SELECTORS_UNIVERSAL_SELECTOR = 2;
726 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype
727 .SELECTORS_ATTRIBUTE_SELECTOR = 3;
728 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype
729 .SELECTORS_CLASS_SELECTOR = 4;
730 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype
731 .SELECTORS_ID_SELECTOR = 5;
732 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype
733 .SELECTORS_PSEUDO_CLASS = 6;
734 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype
735 .SELECTORS_PSEUDO_ELEMENT = 7;
736
737 /**
738 A textual representation of the object.
739
740 Note. The returned string might be an invalid selector, for example,
741 if a type selector has undeclared namespace prefix.
742
743 @return A textual representation.
744 */
745 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype.getSelectorText =
746 function () {
747 return "";
748 };
749
750 /**
751 The specificity of the simple selector.
752 */
753 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype.getSpecificity =
754 function () {
755 return new cx.fam.suika.y2005.CSS.Selectors.Specificity (0, 0, 0, 0);
756 };
757
758 cx.fam.suika.y2005.CSS.Selectors.SimpleSelector.prototype.toString = function () {
759 return "[object SSimpleSelector]";
760 };
761
762
763 /**
764 Interface |STypeSelector|
765
766 An |STypeSelector| object represents a type selector or
767 a universal selector.
768
769 | Meaning | prefix | namespaceURI | Note
770 ----+---------------+---------------+---------------+---------------
771 E | E in any | null | null | No default namespace
772 | E in default | null | uri (default) | Default namespace is defined
773 |E | E in null | "" | null |
774 P|E | E in uri (P) | P | uri (P) |
775 *|E | E in any | * | null |
776 */
777 cx.fam.suika.y2005.CSS.Selectors.TypeSelector = function (ns, pfx, ln) {
778 cx.fam.suika.y2005.CSS.Selectors.TypeSelector._superclass.apply (this, []);
779 this.namespaceURI = ns;
780 this.prefix = pfx;
781 this.localName = ln;
782 };
783 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.inherits
784 (cx.fam.suika.y2005.CSS.Selectors.SimpleSelector);
785 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.prototype.getSimpleSelectorType =
786 function () {
787 if (this.localName == "*" || this.localName == null) {
788 return this.SELECTORS_UNIVERESAL_SELECTOR;
789 } else {
790 return this.SELECTORS_TYPE_SELECTOR;
791 }
792 };
793
794 /**
795 The local name of the simple selector.
796
797 @return The local name if the object is a type selector, or "*"
798 for a universal selector.
799 */
800 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.prototype.getLocalName =
801 function () {
802 return this.localName;
803 };
804
805 /**
806 The namespace URI of the simple selector.
807
808 Note. If the value is |null|, then its semantics depends on
809 the |prefix| value.
810
811 @return The namespace URI, if it is specified, or |null| otherwise.
812 */
813 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.prototype.getNamespaceURI =
814 function () {
815 return this.namespaceURI;
816 };
817
818 /**
819 The namespace prefix of the simple selector.
820
821 @return The namespace prefix, or an empty string if the simple selector
822 does contain a "|" but its namespace prefix is omitted, or
823 |null| if the simple selector does not contain any "|",
824 or |*| that matched to any namespace.
825 */
826 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.prototype.getPrefix =
827 function () {
828 return this.prefix;
829 };
830
831 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.prototype.isEqualSimpleSelector =
832 function (ssel) {
833 if (ssel.getSimpleSelectorType () != this.getSimpleSelectorType ()) return false;
834 if (this.localName == ssel.getLocalName ()) {
835 if (this.namespaceURI == ssel.getNamespaceURI ()) {
836 if (this.namespaceURI == null) {
837 if (this.prefix == ssel.getPrefix ()) {
838 return true;
839 }
840 } else {
841 return true;
842 }
843 }
844 }
845 return false;
846 };
847
848 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.prototype.matchElement =
849 function (elementNode, pseudoElements) {
850 if (pseudoElements != null) return false;
851 if (this.localName == "*" ||
852 this.localName == elementNode.getLocalName ()) {
853 if (this.prefix == "*") {
854 return true;
855 } else if (this.namespaceURI == null) {
856 if (this.prefix == "") {
857 if (elementNode.getNamespaceURI () == null) {
858 return true;
859 }
860 } else {
861 return true;
862 }
863 } else if (this.namespaceURI == elementNode.getNamespaceURI ()) {
864 return true;
865 }
866 } else if (this.localName == null) { /* Implied universal selector */
867 return true;
868 }
869 return false;
870 };
871
872 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.prototype.getSelectorText =
873 function () {
874 var r;
875 if (this.prefix != null) {
876 r = (this.prefix == "*"
877 ? "*"
878 : cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.prefix)) + "|"
879 + (this.localName == "*"
880 ? "*"
881 : cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.localName));
882 } else if (this.localName != null) {
883 r = (this.localName == "*"
884 ? "*"
885 : cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.localName));
886 } else {
887 r = "";
888 }
889 return r;
890 };
891
892 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.prototype.getSpecificity =
893 function () {
894 return new cx.fam.suika.y2005.CSS.Selectors.Specificity
895 (0, 0, 0, this.localName == "*" || this.localName == null ? 0 : 1);
896 };
897
898 cx.fam.suika.y2005.CSS.Selectors.TypeSelector.prototype.toString = function () {
899 return "[object STypeSelector]";
900 };
901
902
903 /**
904 Interface |SAttributeSelector|
905
906 An |SAttributeSelector| object represents an attribute selector.
907 */
908 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector = function (ns, pfx, ln, op, val) {
909 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector._superclass.apply (this, []);
910 this.namespaceURI = ns;
911 this.prefix = pfx;
912 this.localName = ln;
913 this.operator = op;
914 this.value = val;
915 };
916 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.inherits
917 (cx.fam.suika.y2005.CSS.Selectors.SimpleSelector);
918 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.getSimpleSelectorType =
919 function () {
920 return this.SELECTORS_ATTRIBUTE_SELECTOR;
921 };
922
923 /**
924 The local name of the attribute.
925
926 @return The local name.
927 */
928 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.getLocalName =
929 function () {
930 return this.localName;
931 };
932
933 /**
934 The namespace URI of the attribute.
935
936 Note. If the value is |null|, then its semantics depends on
937 the |prefix| value.
938
939 @return The namespace URI, if it is specified, or |null| otherwise.
940 */
941 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.getNamespaceURI =
942 function () {
943 return this.namespaceURI;
944 };
945
946 /**
947 The tyoe of the attribute selector.
948
949 @return The type of the attribute selector.
950 */
951 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.getOperator =
952 function () {
953 return this.operator;
954 };
955 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector
956 .prototype.SELECTORS_ATTRIBUTE_HAS = 1;
957 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector
958 .prototype.SELECTORS_ATTRIBUTE_EQUALS = 2;
959 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector
960 .prototype.SELECTORS_ATTRIBUTE_INCLUDES = 3;
961 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector
962 .prototype.SELECTORS_ATTRIBUTE_DASHMATCH = 4;
963 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector
964 .prototype.SELECTORS_ATTRIBUTE_PREFIXMATCH = 5;
965 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector
966 .prototype.SELECTORS_ATTRIBUTE_SUFFIXMATCH = 6;
967 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector
968 .prototype.SELECTORS_ATTRIBUTE_SUBSTRINGMATCH = 7;
969
970 /**
971 The namespace prefix of the attribute.
972
973 @return The namespace prefix, or an empty string if the attribute name
974 does contain a "|" but its namespace prefix is omitted, or
975 |null| if the attribute name does not contain any "|",
976 or |*| that matched to any namespace.
977 */
978 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.getPrefix =
979 function () {
980 return this.prefix;
981 };
982
983 /**
984 The attribute value, if specified, or |null|.
985
986 @return The attribute value, or |null|.
987 */
988 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.getValue =
989 function () {
990 return this.value;
991 };
992
993 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.isEqualSimpleSelector =
994 function (ssel) {
995 if (ssel.getSimpleSelectorType () != this.SELECTORS_ATTRIBUTE_SELECTOR) return false;
996 if (this.operator != ssel.getOperator ()) {
997 return false;
998 } else if (this.operator != this.SELECTORS_ATTRIBUTE_HAS &&
999 this.value != ssel.getValue ()) {
1000 return false;
1001 }
1002 if (this.localName == ssel.getLocalName ()) {
1003 if (this.namespaceURI == ssel.getNamespaceURI ()) {
1004 if (this.namespaceURI == null) {
1005 if (this.prefix == ssel.getPrefix ()) {
1006 return true;
1007 }
1008 } else {
1009 return true;
1010 }
1011 }
1012 }
1013 return false;
1014 };
1015
1016 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.matchElement =
1017 function (elementNode, pseudoElements) {
1018 if (pseudoElements != null) return false;
1019 var attrs = [];
1020 if (this.namespaceURI == null && this.prefix == "*") {
1021 var eattrs = elementNode.getAttributes ();
1022 var eattrsl = eattrs.getLength ();
1023 for (var i = 0; i < eattrsl; i++) {
1024 var eattr = eattrs.item (i);
1025 if (!eattr.getSpecified () ||
1026 eattr.getLocalName () != this.localName) continue;
1027 attrs.push (eattr.getValue ());
1028 }
1029 } else if (elementNode.hasAttributeNS (this.namespaceURI, this.localName)) {
1030 //var attr = elementNode.getAttributeNS (this.namespaceURI, this.localName);
1031 //if (attr == null || !attr.getSpecified ()) return false;
1032 var attr = elementNode.getAttributeNS (this.namespaceURI, this.localName);
1033 attrs.push (attr);
1034 // TODO: |specified| check
1035 }
1036
1037 switch (this.operator) {
1038 case this.SELECTORS_ATTRIBUTE_HAS:
1039 return attrs.length > 0 ? true : false;
1040 case this.SELECTORS_ATTRIBUTE_EQUALS:
1041 for (var i = 0; i < attrs.length; i++) {
1042 if (attrs[i] == this.value) {
1043 return true;
1044 }
1045 }
1046 return false;
1047 case this.SELECTORS_ATTRIBUTE_INCLUDES:
1048 for (var i = 0; i < attrs.length; i++) {
1049 var vals = attrs[i].split (/\s+/);
1050 for (var j = 0; j < vals.length; j++) {
1051 if (vals[j] == this.value) {
1052 return true;
1053 }
1054 }
1055 }
1056 return false;
1057 case this.SELECTORS_ATTRIBUTE_DASHMATCH:
1058 for (var i = 0; i < attrs.length; i++) {
1059 var val = attrs[i];
1060 if (val == this.value ||
1061 val.substring (0, this.value.length + 1) == this.value + "-") {
1062 return true;
1063 }
1064 }
1065 return false;
1066 case this.SELECTORS_ATTRIBUTE_PREFIXMATCH:
1067 for (var i = 0; i < attrs.length; i++) {
1068 var val = attrs[i];
1069 if (val.substring (0, this.value.length) == this.value) {
1070 return true;
1071 }
1072 }
1073 return false;
1074 case this.SELECTORS_ATTRIBUTE_SUFFIXMATCH:
1075 for (var i = 0; i < attrs.length; i++) {
1076 var val = attrs[i];
1077 if (val.substring (val.length - this.value.length) == this.value) {
1078 return true;
1079 }
1080 }
1081 return false;
1082 case this.SELECTORS_ATTRIBUTE_SUBSTRINGMATCH:
1083 for (var i = 0; i < attrs.length; i++) {
1084 if (attrs[i].indexOf (this.value) > -1) {
1085 return true;
1086 }
1087 }
1088 return false;
1089 default:
1090 return false;
1091 }
1092 /* TODO: Case-insensitive match if necessary */
1093 };
1094
1095 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.getSelectorText =
1096 function () {
1097 var r = "[";
1098 if (this.prefix != null) {
1099 r += (this.prefix == "*"
1100 ? "*"
1101 : cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.prefix)) + "|"
1102 + (this.localName == "*"
1103 ? "*"
1104 : cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.localName));
1105 } else {
1106 r += (this.localName == "*"
1107 ? "*"
1108 : cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.localName));
1109 }
1110 if (this.operator != this.SELECTORS_ATTRIBUTE_HAS) {
1111 r += this.operator == this.SELECTORS_ATTRIBUTE_EQUALS ? "=" :
1112 this.operator == this.SELECTORS_ATTRIBUTE_INCLUDES ? "~=" :
1113 this.operator == this.SELECTORS_ATTRIBUTE_DASHMATCH ? "|=" :
1114 this.operator == this.SELECTORS_ATTRIBUTE_PREFIXMATCH ? "^=" :
1115 this.operator == this.SELECTORS_ATTRIBUTE_SUFFIXMATCH ? "$=" :
1116 "*=" ;
1117 r += '"'
1118 + this.value.replace (/([\u000A\u000C"\\]|\u000D\u000A)/g,
1119 function (c) { return "\\" + c })
1120 + '"';
1121 }
1122 r += "]";
1123 return r;
1124 };
1125
1126 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.getSpecificity =
1127 function () {
1128 return new cx.fam.suika.y2005.CSS.Selectors.Specificity (0, 0, 1, 0);
1129 };
1130
1131 cx.fam.suika.y2005.CSS.Selectors.AttributeSelector.prototype.toString = function () {
1132 return "[object SAttributeSelector]";
1133 };
1134
1135
1136 /**
1137 Interface |SClassSelector|
1138
1139 An |SClassSelector| object represents a class selector.
1140 */
1141 cx.fam.suika.y2005.CSS.Selectors.ClassSelector = function (cls) {
1142 cx.fam.suika.y2005.CSS.Selectors.ClassSelector._superclass.apply (this, []);
1143 this.className = cls;
1144 };
1145 cx.fam.suika.y2005.CSS.Selectors.ClassSelector.inherits
1146 (cx.fam.suika.y2005.CSS.Selectors.SimpleSelector);
1147
1148 /**
1149 The class name.
1150
1151 @return The class name.
1152 */
1153 cx.fam.suika.y2005.CSS.Selectors.ClassSelector.prototype.getClassName =
1154 function () {
1155 return this.className;
1156 };
1157
1158 cx.fam.suika.y2005.CSS.Selectors.ClassSelector.prototype.isEqualSimpleSelector =
1159 function (ssel) {
1160 if (ssel.getSimpleSelectorType () != this.SELECTORS_CLASS_SELECTOR) return false;
1161 if (this.className == ssel.getClassName ()) {
1162 return true;
1163 }
1164 return false;
1165 };
1166
1167 cx.fam.suika.y2005.CSS.Selectors.ClassSelector.prototype.matchElement =
1168 function (elementNode, pseudoElements) {
1169 if (pseudoElements != null) return false;
1170 var classes = elementNode.getClassNames ();
1171 for (var i = 0; i < classes.length; i++) {
1172 if (classes[i] == this.className) {
1173 return true;
1174 }
1175 }
1176 return false;
1177 };
1178
1179 cx.fam.suika.y2005.CSS.Selectors.ClassSelector.prototype.getSelectorText =
1180 function () {
1181 return "." + cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.className);
1182 };
1183
1184 cx.fam.suika.y2005.CSS.Selectors.ClassSelector.prototype.getSpecificity =
1185 function () {
1186 return new cx.fam.suika.y2005.CSS.Selectors.Specificity (0, 0, 1, 0);
1187 };
1188
1189 cx.fam.suika.y2005.CSS.Selectors.ClassSelector.prototype.toString = function () {
1190 return "[object SClassSelector]";
1191 };
1192
1193 /**
1194 Interface |SIDSelector|
1195
1196 An |SIDSelector| object represents an ID selector.
1197 */
1198 cx.fam.suika.y2005.CSS.Selectors.IDSelector = function (id) {
1199 cx.fam.suika.y2005.CSS.Selectors.IDSelector._superclass.apply (this, []);
1200 this.id = id;
1201 };
1202 cx.fam.suika.y2005.CSS.Selectors.IDSelector.inherits
1203 (cx.fam.suika.y2005.CSS.Selectors.SimpleSelector);
1204
1205 /**
1206 The identifier.
1207
1208 @return The identifier.
1209 */
1210 cx.fam.suika.y2005.CSS.Selectors.IDSelector.prototype.getId =
1211 function () {
1212 return this.id;
1213 };
1214 cx.fam.suika.y2005.CSS.Selectors.IDSelector.prototype.isEqualSimpleSelector =
1215 function (ssel) {
1216 if (ssel.getSimpleSelectorType () != this.SELECTORS_ID_SELECTOR) return false;
1217 if (this.id == ssel.getId ()) {
1218 return true;
1219 }
1220 return false;
1221 };
1222
1223 cx.fam.suika.y2005.CSS.Selectors.IDSelector.prototype.matchElement =
1224 function (elementNode, pseudoElements) {
1225 if (pseudoElements != null) return false;
1226 var ids = elementNode.getIds ();
1227 for (var i = 0; i < ids.length; i++) {
1228 if (ids[i] == this.id) {
1229 return true;
1230 }
1231 }
1232 return false;
1233 };
1234
1235 cx.fam.suika.y2005.CSS.Selectors.IDSelector.prototype.getSelectorText =
1236 function () {
1237 return "#" + cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.id);
1238 };
1239
1240 cx.fam.suika.y2005.CSS.Selectors.IDSelector.prototype.getSpecificity =
1241 function () {
1242 return new cx.fam.suika.y2005.CSS.Selectors.Specificity (0, 1, 0, 0);
1243 };
1244
1245 cx.fam.suika.y2005.CSS.Selectors.IDSelector.prototype.toString = function () {
1246 return "[object SIDSelector]";
1247 };
1248
1249
1250 /**
1251 Interface |SPseudoClass|
1252
1253 An |SPseudoClass| object represents a pseudo class.
1254 */
1255 cx.fam.suika.y2005.CSS.Selectors.PseudoClass = function (nsuri, pfx, ln) {
1256 cx.fam.suika.y2005.CSS.Selectors.PseudoClass._superclass.apply (this, []);
1257 this.namespaceURI = nsuri;
1258 this.prefix = pfx;
1259 this.localName = ln;
1260 };
1261 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.inherits
1262 (cx.fam.suika.y2005.CSS.Selectors.SimpleSelector);
1263
1264 /**
1265 The pseudo class local name.
1266
1267 @return The local name.
1268 */
1269 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.prototype.getClassLocalName =
1270 function () {
1271 return this.localName;
1272 };
1273
1274 /**
1275 The pseudo class name.
1276
1277 @return The pseudo class name.
1278 */
1279 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.prototype.getClassName =
1280 function () {
1281 if (this.namespaceURI == "urn:x-suika-fam-cx:selectors:") {
1282 return this.localName;
1283 } else {
1284 return "-" + this.prefix + "-" + this.localName;
1285 }
1286 };
1287
1288 /**
1289 The pseudo class namespace URI.
1290
1291 @return The namespace URI.
1292 */
1293 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.prototype.getClassNamespaceURI =
1294 function () {
1295 return this.namespaceURI;
1296 };
1297
1298 /**
1299 The pseudo class namespace prefix.
1300
1301 @return The namespace prefix, if any, or |null|.
1302 */
1303 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.prototype.getClassPrefix =
1304 function () {
1305 return this.prefix;
1306 };
1307
1308 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.prototype.isEqualSimpleSelector =
1309 function (ssel) {
1310 if (ssel.getSimpleSelectorType () != this.SELECTORS_PSEUDO_CLASS) return false;
1311 if (this.localName == ssel.getClassLocalName () &&
1312 this.namespaceURI == ssel.getClassNamespaceURI ()) {
1313 return true;
1314 }
1315 return false;
1316 };
1317
1318 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.prototype.matchElement =
1319 function (elementNode, pseudoElements) {
1320 if (pseudoElements != null) return false;
1321 if (cx.fam.suika.y2005.CSS.Selectors.PseudoClass._Impl
1322 [this.namespaceURI][this.localName].matchElement (elementNode)) {
1323 return true;
1324 }
1325 return false;
1326 };
1327
1328 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.prototype.getSelectorText =
1329 function () {
1330 return ":" + cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.getClassName ());
1331 };
1332
1333 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.prototype.getSpecificity =
1334 function () {
1335 return new cx.fam.suika.y2005.CSS.Selectors.Specificity (0, 0, 1, 0);
1336 };
1337
1338 cx.fam.suika.y2005.CSS.Selectors.PseudoClass.prototype.toString = function () {
1339 return "[object SPseudoClass]";
1340 };
1341
1342 cx.fam.suika.y2005.CSS.Selectors.PseudoClass._Impl = {};
1343 cx.fam.suika.y2005.CSS.Selectors.PseudoClass._Impl
1344 ["urn:x-suika-fam-cx:selectors:"] = {
1345 active: {
1346 matchElement: function (el) {
1347 return false;
1348 }
1349 },
1350 checked: {
1351 matchElement: function (el) {
1352 if (el.getChecked && el.getChecked ()) {
1353 return true;
1354 }
1355 return false;
1356 }
1357 },
1358 disabled: {
1359 matchElement: function (el) {
1360 if (el.getDisabled && el.getDisabled ()) {
1361 return true;
1362 }
1363 return false;
1364 }
1365 },
1366 empty: {
1367 matchElement: function (el) {
1368 return !el.hasChildNodes ();
1369 }
1370 },
1371 enabled: {
1372 matchElement: function (el) {
1373 if (el.getDisabled && el.getDisabled ()) {
1374 return false;
1375 }
1376 return true;
1377 }
1378 },
1379 root: {
1380 matchElement: function (el) {
1381 if (el.getParentNode () != null) {
1382 return true;
1383 }
1384 return false;
1385 }
1386 }
1387 };
1388 cx.fam.suika.y2005.CSS.Selectors.PseudoClass._Impl
1389 ["urn:x-suika-fam-cx:selectors:"]["first-child"] = {
1390 matchElement: function (el) {
1391 if (el.getPreviousSiblingElement () == null) {
1392 return true;
1393 }
1394 return false;
1395 }
1396 };
1397
1398 /**
1399 Interface |SPseudoElement|
1400
1401 An |SPseudoElement| object represents a pseudo element.
1402 */
1403 cx.fam.suika.y2005.CSS.Selectors.PseudoElement = function (nsuri, pfx, ln) {
1404 cx.fam.suika.y2005.CSS.Selectors.PseudoElement._superclass.apply (this, []);
1405 this.namespaceURI = nsuri;
1406 this.prefix = pfx;
1407 this.localName = ln;
1408 };
1409 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.inherits
1410 (cx.fam.suika.y2005.CSS.Selectors.SimpleSelector);
1411
1412 /**
1413 The pseudo element local name.
1414
1415 @return The local name.
1416 */
1417 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype.getElementLocalName =
1418 function () {
1419 return this.localName;
1420 };
1421
1422 /**
1423 The pseudo element name.
1424
1425 @return The pseudo element name.
1426 */
1427 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype.getElementName =
1428 function () {
1429 if (this.namespaceURI == "urn:x-suika-fam-cx:selectors:") {
1430 return this.localName;
1431 } else {
1432 return "-" + this.prefix + "-" + this.localName;
1433 }
1434 };
1435
1436 /**
1437 The pseudo element namespace URI.
1438
1439 @return The namespace URI.
1440 */
1441 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype.getElementNamespaceURI =
1442 function () {
1443 return this.namespaceURI;
1444 };
1445
1446 /**
1447 The pseudo element namespace prefix.
1448
1449 @return The namespace prefix, if any, or |null|.
1450 */
1451 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype.getElementPrefix =
1452 function () {
1453 return this.prefix;
1454 };
1455
1456 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype._GetPseudoElementHashKey
1457 = function () {
1458 return "<" + this.namespaceURI + ">" + this.localName;
1459 };
1460
1461 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype.isEqualSimpleSelector =
1462 function (ssel) {
1463 if (ssel.getSimpleSelectorType () != this.SELECTORS_PSEUDO_ELEMENT) return false;
1464 if (this.localName == ssel.getElementLocalName () &&
1465 this.namespaceURI == ssel.getElementNamespaceURI ()) {
1466 return true;
1467 }
1468 return false;
1469 };
1470
1471 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype.matchElement =
1472 function (elementNode, pseudoElements) {
1473 return false;
1474 };
1475
1476 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype.getSelectorText =
1477 function () {
1478 return "::" + cx.fam.suika.y2005.CSS.Selectors._EscapeIdent (this.getElementName ());
1479 };
1480
1481 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype.getSpecificity =
1482 function () {
1483 return new cx.fam.suika.y2005.CSS.Selectors.Specificity (0, 0, 0, 1);
1484 };
1485
1486 cx.fam.suika.y2005.CSS.Selectors.PseudoElement.prototype.toString = function () {
1487 return this.getA () + "-" + this.getB () + "-" + this.getC () + "-" + this.getD ();
1488 };
1489
1490
1491 /**
1492 Interface |SSpecificity|
1493
1494 A |SSpecificity| object represents a specificity value.
1495
1496 Note. The meaning of |a|, |b|, and |c| in CSS levels 1 and 2.0 and
1497 Selectors Candidate Recommendation on November 2001 is different
1498 from one in CSS Level 2.1, as well as in this interface,
1499 where they are called as |b|, |c|, and |d|.
1500 */
1501 cx.fam.suika.y2005.CSS.Selectors.Specificity = function (a, b, c, d) {
1502 this.a = a;
1503 this.b = b;
1504 this.c = c;
1505 this.d = d;
1506 };
1507
1508 /**
1509 The |a| value, which is most significant.
1510 */
1511 cx.fam.suika.y2005.CSS.Selectors.Specificity.prototype.getA = function () {
1512 return this.a;
1513 };
1514
1515 /**
1516 The |b| value.
1517 */
1518 cx.fam.suika.y2005.CSS.Selectors.Specificity.prototype.getB = function () {
1519 return this.b;
1520 };
1521
1522 /**
1523 The |c| value.
1524 */
1525 cx.fam.suika.y2005.CSS.Selectors.Specificity.prototype.getC = function () {
1526 return this.c;
1527 };
1528
1529 /**
1530 Compares the specificity value with another value.
1531
1532 @param another A specificity value.
1533 @return If the specificity value is less than, equal to, or greater
1534 than |another|, the method, then the method returns a
1535 negative, zero, or positive value respectively.
1536 */
1537 cx.fam.suika.y2005.CSS.Selectors.Specificity.prototype.compareSpecificity =
1538 function (another) {
1539 var v = this.a - another.getA ();
1540 if (v == 0) {
1541 v = this.b - another.getB ();
1542 if (v == 0) {
1543 v = this.c - another.getC ();
1544 if (v == 0) {
1545 v = this.d - another.getD ();
1546 }
1547 }
1548 }
1549 return v;
1550 };
1551
1552 /**
1553 The |d| value, which is less significant.
1554 */
1555 cx.fam.suika.y2005.CSS.Selectors.Specificity.prototype.getD = function () {
1556 return this.d;
1557 };
1558
1559 cx.fam.suika.y2005.CSS.Selectors.Specificity.prototype.toString = function () {
1560 return this.a + "-" + this.b + "-" + this.c + "-" + this.d;
1561 };
1562
1563 /* Revision: $Date: 2005/11/06 14:24:23 $ */
1564
1565 /* ***** BEGIN LICENSE BLOCK *****
1566 * Copyright 2005 Wakaba <w@suika.fam.cx>. All rights reserved.
1567 *
1568 * This program is free software; you can redistribute it and/or
1569 * modify it under the same terms as Perl itself.
1570 *
1571 * Alternatively, the contents of this file may be used
1572 * under the following terms (the "MPL/GPL/LGPL"),
1573 * in which case the provisions of the MPL/GPL/LGPL are applicable instead
1574 * of those above. If you wish to allow use of your version of this file only
1575 * under the terms of the MPL/GPL/LGPL, and not to allow others to
1576 * use your version of this file under the terms of the Perl, indicate your
1577 * decision by deleting the provisions above and replace them with the notice
1578 * and other provisions required by the MPL/GPL/LGPL. If you do not delete
1579 * the provisions above, a recipient may use your version of this file under
1580 * the terms of any one of the Perl or the MPL/GPL/LGPL.
1581 *
1582 * "MPL/GPL/LGPL":
1583 *
1584 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
1585 *
1586 * The contents of this file are subject to the Mozilla Public License Version
1587 * 1.1 (the "License"); you may not use this file except in compliance with
1588 * the License. You may obtain a copy of the License at
1589 * <http://www.mozilla.org/MPL/>
1590 *
1591 * Software distributed under the License is distributed on an "AS IS" basis,
1592 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1593 * for the specific language governing rights and limitations under the
1594 * License.
1595 *
1596 * The Original Code is BIDOM code.
1597 *
1598 * The Initial Developer of the Original Code is Wakaba.
1599 * Portions created by the Initial Developer are Copyright (C) 2005
1600 * the Initial Developer. All Rights Reserved.
1601 *
1602 * Contributor(s):
1603 * Wakaba <w@suika.fam.cx>
1604 *
1605 * Alternatively, the contents of this file may be used under the terms of
1606 * either the GNU General Public License Version 2 or later (the "GPL"), or
1607 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
1608 * in which case the provisions of the GPL or the LGPL are applicable instead
1609 * of those above. If you wish to allow use of your version of this file only
1610 * under the terms of either the GPL or the LGPL, and not to allow others to
1611 * use your version of this file under the terms of the MPL, indicate your
1612 * decision by deleting the provisions above and replace them with the notice
1613 * and other provisions required by the LGPL or the GPL. If you do not delete
1614 * the provisions above, a recipient may use your version of this file under
1615 * the terms of any one of the MPL, the GPL or the LGPL.
1616 *
1617 * ***** END LICENSE BLOCK ***** */

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24