Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/cssProperties.js

Issue 29336406: Issue 3654 - Properly split up selectors when applying CSS property filters (Closed)
Patch Set: Undid unrelated whitespace change Created Feb. 15, 2016, 6:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 function splitSelector(selector)
2 {
3 if (selector.indexOf(",") == -1)
4 return [selector];
5
6 var selectors = [];
7 var start = 0;
8 var level = 0;
9 var sep = "";
10
11 for (var i = 0; i < selector.length; i++)
12 {
13 var chr = selector[i];
14
15 if (chr == "\\") // ignore escaped characters
16 i++;
17 else if (chr == sep) // don't split within quoted text
18 sep = ""; // e.g. [attr=","]
19 else if (sep == "")
20 {
21 if (chr == '"' || chr == "'")
22 sep = chr;
23 else if (chr == "(") // don't split between parentheses
24 level++; // e.g. :matches(div,span)
25 else if (chr == ")")
26 level = Math.max(0, level - 1);
27 else if (chr == "," && level == 0)
28 {
29 selectors.push(selector.substring(start, i));
30 start = i + 1;
31 }
32 }
33 }
34
35 selectors.push(selector.substring(start));
36 return selectors;
37 }
38
1 function CSSPropertyFilters(window, addSelectorsFunc) { 39 function CSSPropertyFilters(window, addSelectorsFunc) {
2 this.window = window; 40 this.window = window;
3 this.addSelectorsFunc = addSelectorsFunc; 41 this.addSelectorsFunc = addSelectorsFunc;
4 } 42 }
5 43
6 CSSPropertyFilters.prototype = { 44 CSSPropertyFilters.prototype = {
7 stringifyStyle: function(style) 45 stringifyStyle: function(style)
8 { 46 {
9 var styles = []; 47 var styles = [];
10 for (var i = 0; i < style.length; i++) 48 for (var i = 0; i < style.length; i++)
(...skipping 22 matching lines...) Expand all
33 var style = this.stringifyStyle(rule.style); 71 var style = this.stringifyStyle(rule.style);
34 for (var j = 0; j < this.patterns.length; j++) 72 for (var j = 0; j < this.patterns.length; j++)
35 { 73 {
36 var pattern = this.patterns[j]; 74 var pattern = this.patterns[j];
37 var regexp = pattern.regexp; 75 var regexp = pattern.regexp;
38 76
39 if (typeof regexp == "string") 77 if (typeof regexp == "string")
40 regexp = pattern.regexp = new RegExp(regexp); 78 regexp = pattern.regexp = new RegExp(regexp);
41 79
42 if (regexp.test(style)) 80 if (regexp.test(style))
43 selectors.push(pattern.prefix + rule.selectorText + pattern.suffix); 81 {
82 var subSelectors = splitSelector(rule.selectorText);
83 for (var k = 0; k < subSelectors.length; k++)
84 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix);
85 }
44 } 86 }
45 } 87 }
46 }, 88 },
47 89
48 addSelectors: function(stylesheets) 90 addSelectors: function(stylesheets)
49 { 91 {
50 var selectors = []; 92 var selectors = [];
51 for (var i = 0; i < stylesheets.length; i++) 93 for (var i = 0; i < stylesheets.length; i++)
52 this.findSelectors(stylesheets[i], selectors); 94 this.findSelectors(stylesheets[i], selectors);
53 this.addSelectorsFunc(selectors); 95 this.addSelectorsFunc(selectors);
(...skipping 24 matching lines...) Expand all
78 apply: function() 120 apply: function()
79 { 121 {
80 if (this.patterns.length > 0) 122 if (this.patterns.length > 0)
81 { 123 {
82 var document = this.window.document; 124 var document = this.window.document;
83 this.addSelectors(document.styleSheets); 125 this.addSelectors(document.styleSheets);
84 document.addEventListener("load", this.onLoad.bind(this), true); 126 document.addEventListener("load", this.onLoad.bind(this), true);
85 } 127 }
86 } 128 }
87 }; 129 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld