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

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

Issue 29493648: Issue 5436 - Allow relative selectors in :-abp-has() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created July 20, 2017, 7:18 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 | test/browser/elemHideEmulation.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 * @param {Node} subtree the subtree we work on. 184 * @param {Node} subtree the subtree we work on.
185 * @param {StringifiedStyle[]} styles the stringified style objects. 185 * @param {StringifiedStyle[]} styles the stringified style objects.
186 */ 186 */
187 *getSelectors(prefix, subtree, styles) 187 *getSelectors(prefix, subtree, styles)
188 { 188 {
189 yield [prefix + this._selector, subtree]; 189 yield [prefix + this._selector, subtree];
190 } 190 }
191 }; 191 };
192 192
193 const incompletePrefixRegexp = /[\s>+~]$/; 193 const incompletePrefixRegexp = /[\s>+~]$/;
194 const relativeSelector = /^[\s>+~]/;
194 195
195 function HasSelector(selectors) 196 function HasSelector(selectors)
196 { 197 {
197 this._innerSelectors = selectors; 198 this._innerSelectors = selectors;
198 } 199 }
199 200
200 HasSelector.prototype = { 201 HasSelector.prototype = {
201 requiresHiding: true, 202 requiresHiding: true,
202 203
203 get dependsOnStyles() 204 get dependsOnStyles()
(...skipping 15 matching lines...) Expand all
219 */ 220 */
220 *getElements(prefix, subtree, styles) 221 *getElements(prefix, subtree, styles)
221 { 222 {
222 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? 223 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ?
223 prefix + "*" : prefix; 224 prefix + "*" : prefix;
224 let elements = subtree.querySelectorAll(actualPrefix); 225 let elements = subtree.querySelectorAll(actualPrefix);
225 for (let element of elements) 226 for (let element of elements)
226 { 227 {
227 let iter = evaluate(this._innerSelectors, 0, "", element, styles); 228 let iter = evaluate(this._innerSelectors, 0, "", element, styles);
228 for (let selector of iter) 229 for (let selector of iter)
230 {
231 if (relativeSelector.test(selector))
232 selector = ":scope" + selector;
229 if (element.querySelector(selector)) 233 if (element.querySelector(selector))
230 yield element; 234 yield element;
235 }
231 } 236 }
232 } 237 }
233 }; 238 };
234 239
235 function PropsSelector(propertyExpression) 240 function PropsSelector(propertyExpression)
236 { 241 {
237 let regexpString; 242 let regexpString;
238 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && 243 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" &&
239 propertyExpression[propertyExpression.length - 1] == "/") 244 propertyExpression[propertyExpression.length - 1] == "/")
240 { 245 {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 469
465 if (this.patterns.length > 0) 470 if (this.patterns.length > 0)
466 { 471 {
467 let {document} = this.window; 472 let {document} = this.window;
468 this.addSelectors(); 473 this.addSelectors();
469 document.addEventListener("load", this.onLoad.bind(this), true); 474 document.addEventListener("load", this.onLoad.bind(this), true);
470 } 475 }
471 }); 476 });
472 } 477 }
473 }; 478 };
OLDNEW
« no previous file with comments | « no previous file | test/browser/elemHideEmulation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld