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

Delta Between Two Patch Sets: chrome/content/elemHideEmulation.js

Issue 29490698: Issue 5422 - Properly build props selector (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created July 17, 2017, 5:07 p.m.
Right Patch Set: Another nit Created Aug. 19, 2017, 1:13 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 else if (sep == "") 43 else if (sep == "")
44 { 44 {
45 if (chr == '"' || chr == "'") 45 if (chr == '"' || chr == "'")
46 sep = chr; 46 sep = chr;
47 else if (chr == "(") // don't split between parentheses 47 else if (chr == "(") // don't split between parentheses
48 level++; // e.g. :matches(div,span) 48 level++; // e.g. :matches(div,span)
49 else if (chr == ")") 49 else if (chr == ")")
50 level = Math.max(0, level - 1); 50 level = Math.max(0, level - 1);
51 else if (chr == "," && level == 0) 51 else if (chr == "," && level == 0)
52 { 52 {
53 selectors.push(selector.substring(start, i).trim()); 53 selectors.push(selector.substring(start, i));
54 start = i + 1; 54 start = i + 1;
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 selectors.push(selector.substring(start).trim()); 59 selectors.push(selector.substring(start));
60 return selectors; 60 return selectors;
61 } 61 }
62 62
63 /** Return position of node from parent. 63 /** Return position of node from parent.
64 * @param {Node} node the node to find the position of. 64 * @param {Node} node the node to find the position of.
65 * @return {number} One-based index like for :nth-child(), or 0 on error. 65 * @return {number} One-based index like for :nth-child(), or 0 on error.
66 */ 66 */
67 function positionInParent(node) 67 function positionInParent(node)
68 { 68 {
69 let {children} = node.parentNode; 69 let {children} = node.parentNode;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 * @param {Node} subtree the subtree we work on. 182 * @param {Node} subtree the subtree we work on.
183 * @param {StringifiedStyle[]} styles the stringified style objects. 183 * @param {StringifiedStyle[]} styles the stringified style objects.
184 */ 184 */
185 *getSelectors(prefix, subtree, styles) 185 *getSelectors(prefix, subtree, styles)
186 { 186 {
187 yield [prefix + this._selector, subtree]; 187 yield [prefix + this._selector, subtree];
188 } 188 }
189 }; 189 };
190 190
191 const incompletePrefixRegexp = /[\s>+~]$/; 191 const incompletePrefixRegexp = /[\s>+~]$/;
192 const relativeSelector = /^[\s>+~]/;
193 192
194 function HasSelector(selectors) 193 function HasSelector(selectors)
195 { 194 {
196 this._innerSelectors = selectors; 195 this._innerSelectors = selectors;
197 } 196 }
198 197
199 HasSelector.prototype = { 198 HasSelector.prototype = {
200 requiresHiding: true, 199 requiresHiding: true,
201 200
202 get dependsOnStyles() 201 get dependsOnStyles()
(...skipping 15 matching lines...) Expand all
218 */ 217 */
219 *getElements(prefix, subtree, styles) 218 *getElements(prefix, subtree, styles)
220 { 219 {
221 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? 220 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ?
222 prefix + "*" : prefix; 221 prefix + "*" : prefix;
223 let elements = subtree.querySelectorAll(actualPrefix); 222 let elements = subtree.querySelectorAll(actualPrefix);
224 for (let element of elements) 223 for (let element of elements)
225 { 224 {
226 let iter = evaluate(this._innerSelectors, 0, "", element, styles); 225 let iter = evaluate(this._innerSelectors, 0, "", element, styles);
227 for (let selector of iter) 226 for (let selector of iter)
228 {
229 if (relativeSelector.test(selector))
230 selector = ":scope" + selector;
231 if (element.querySelector(selector)) 227 if (element.querySelector(selector))
232 yield element; 228 yield element;
233 }
234 } 229 }
235 } 230 }
236 }; 231 };
237 232
238 function ContainsSelector(textContent) 233 function ContainsSelector(textContent)
239 { 234 {
240 this._text = textContent; 235 this._text = textContent;
241 } 236 }
242 237
243 ContainsSelector.prototype = { 238 ContainsSelector.prototype = {
(...skipping 30 matching lines...) Expand all
274 269
275 this._regexp = new RegExp(regexpString, "i"); 270 this._regexp = new RegExp(regexpString, "i");
276 } 271 }
277 272
278 PropsSelector.prototype = { 273 PropsSelector.prototype = {
279 preferHideWithSelector: true, 274 preferHideWithSelector: true,
280 dependsOnStyles: true, 275 dependsOnStyles: true,
281 276
282 *findPropsSelectors(styles, prefix, regexp) 277 *findPropsSelectors(styles, prefix, regexp)
283 { 278 {
284 let actualPrefix = (prefix && !incompletePrefixRegexp.test(prefix)) ?
285 prefix + " " : prefix;
286 for (let style of styles) 279 for (let style of styles)
287 if (regexp.test(style.style)) 280 if (regexp.test(style.style))
288 for (let subSelector of style.subSelectors) 281 for (let subSelector of style.subSelectors)
289 { 282 {
290 if (subSelector == "*") 283 if (subSelector.startsWith("*") &&
291 subSelector = ""; 284 !incompletePrefixRegexp.test(prefix))
292 yield actualPrefix + subSelector; 285 {
286 subSelector = subSelector.substr(1);
287 }
288 let idx = subSelector.lastIndexOf("::");
289 if (idx != -1)
290 subSelector = subSelector.substr(0, idx);
291 yield prefix + subSelector;
293 } 292 }
294 }, 293 },
295 294
296 *getSelectors(prefix, subtree, styles) 295 *getSelectors(prefix, subtree, styles)
297 { 296 {
298 for (let selector of this.findPropsSelectors(styles, prefix, this._regexp)) 297 for (let selector of this.findPropsSelectors(styles, prefix, this._regexp))
299 yield [selector, subtree]; 298 yield [selector, subtree];
300 } 299 }
301 }; 300 };
302 301
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 510
512 if (this.patterns.length > 0) 511 if (this.patterns.length > 0)
513 { 512 {
514 let {document} = this.window; 513 let {document} = this.window;
515 this.addSelectors(); 514 this.addSelectors();
516 document.addEventListener("load", this.onLoad.bind(this), true); 515 document.addEventListener("load", this.onLoad.bind(this), true);
517 } 516 }
518 }); 517 });
519 } 518 }
520 }; 519 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld