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

Side by Side Diff: include.preload.js

Issue 29336409: Issue 3654 - Reuse splitSelector() from cssProperties.js (Closed)
Patch Set: Updated dependency Created Feb. 15, 2016, 8:23 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 | « dependencies ('k') | 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 /* 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 stylesheet.addRule(selector, "display: none !important;"); 374 stylesheet.addRule(selector, "display: none !important;");
375 } 375 }
376 } 376 }
377 ); 377 );
378 }); 378 });
379 379
380 observer.observe(style.parentNode, {childList: true}); 380 observer.observe(style.parentNode, {childList: true});
381 return observer; 381 return observer;
382 } 382 }
383 383
384 function convertSelectorsForShadowDOM(selectors)
385 {
386 var result = [];
387 var prefix = "::content ";
388
389 for (var i = 0; i < selectors.length; i++)
390 {
391 var selector = selectors[i];
392 if (selector.indexOf(",") == -1)
393 {
394 result.push(prefix + selector);
395 continue;
396 }
397
398 var start = 0;
399 var sep = "";
400 for (var j = 0; j < selector.length; j++)
401 {
402 var chr = selector[j];
403 if (chr == "\\")
404 j++;
405 else if (chr == sep)
406 sep = "";
407 else if (sep == "")
408 {
409 if (chr == '"' || chr == "'")
410 sep = chr;
411 else if (chr == ",")
412 {
413 result.push(prefix + selector.substring(start, j));
414 start = j + 1;
415 }
416 }
417 }
418
419 result.push(prefix + selector.substring(start));
420 }
421
422 return result;
423 }
424
425 function init(document) 384 function init(document)
426 { 385 {
427 var shadow = null; 386 var shadow = null;
428 var style = null; 387 var style = null;
429 var observer = null; 388 var observer = null;
430 var tracer = null; 389 var tracer = null;
431 var propertyFilters = new CSSPropertyFilters(window, addElemHideSelectors); 390 var propertyFilters = new CSSPropertyFilters(window, addElemHideSelectors);
432 391
433 // Use Shadow DOM if available to don't mess with web pages that rely on 392 // Use Shadow DOM if available to don't mess with web pages that rely on
434 // the order of their own <style> tags (#309). 393 // the order of their own <style> tags (#309).
(...skipping 30 matching lines...) Expand all
465 if (!style.sheet) 424 if (!style.sheet)
466 return; 425 return;
467 426
468 observer = reinjectRulesWhenRemoved(document, style); 427 observer = reinjectRulesWhenRemoved(document, style);
469 } 428 }
470 429
471 // If using shadow DOM, we have to add the ::content pseudo-element 430 // If using shadow DOM, we have to add the ::content pseudo-element
472 // before each selector, in order to match elements within the 431 // before each selector, in order to match elements within the
473 // insertion point. 432 // insertion point.
474 if (shadow) 433 if (shadow)
475 selectors = convertSelectorsForShadowDOM(selectors); 434 {
435 var preparedSelectors = [];
436 for (var i = 0; i < selectors.length; i++)
437 {
438 var subSelectors = splitSelector(selectors[i]);
439 for (var j = 0; j < subSelectors.length; j++)
440 preparedSelectors.push("::content " + subSelectors[j]);
441 }
442 selectors = preparedSelectors;
443 }
476 444
477 // WebKit (and Blink?) apparently chokes when the selector list in a 445 // WebKit (and Blink?) apparently chokes when the selector list in a
478 // CSS rule is huge. So we split the elemhide selectors into groups. 446 // CSS rule is huge. So we split the elemhide selectors into groups.
479 while (selectors.length > 0) 447 while (selectors.length > 0)
480 { 448 {
481 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", "); 449 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", ");
482 style.sheet.addRule(selector, "display: none !important;"); 450 style.sheet.addRule(selector, "display: none !important;");
483 } 451 }
484 }; 452 };
485 453
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 }, true); 537 }, true);
570 538
571 return updateStylesheet; 539 return updateStylesheet;
572 } 540 }
573 541
574 if (document instanceof HTMLDocument) 542 if (document instanceof HTMLDocument)
575 { 543 {
576 checkSitekey(); 544 checkSitekey();
577 window.updateStylesheet = init(document); 545 window.updateStylesheet = init(document);
578 } 546 }
OLDNEW
« no previous file with comments | « dependencies ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld