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

Side by Side Diff: include.postload.js

Issue 5173617369284608: Issue 1868 - Handle <area> element properly when selected with "Block element" (Closed)
Patch Set: Created Jan. 28, 2015, 11:34 a.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 /* 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 327
328 // Turn on the choose element to create filter thing 328 // Turn on the choose element to create filter thing
329 function clickHide_activate() { 329 function clickHide_activate() {
330 if(document == null) 330 if(document == null)
331 return; 331 return;
332 332
333 // If we are already selecting, abort now 333 // If we are already selecting, abort now
334 if (clickHide_activated || clickHideFiltersDialog) 334 if (clickHide_activated || clickHideFiltersDialog)
335 clickHide_deactivate(); 335 clickHide_deactivate();
336 336
337 // Add overlays for blockable elements that don't emit mouse events that they 337 // Add overlays for blockable elements that don't emit mouse events that they can still be selected
kzar 2015/02/09 17:24:41 Nitpick: Should read "...so that they can still be
Sebastian Noack 2015/02/10 10:19:27 Done.
338 // can still be selected. While images generally emit mouse events we have 338 var elts = document.querySelectorAll('object,embed,iframe,frame');
339 // also to add overlays for them, in case <area> elments are used (#1868).
340 var elts = document.querySelectorAll('object,embed,iframe,frame,img');
341 for(var i=0; i<elts.length; i++) 339 for(var i=0; i<elts.length; i++)
342 { 340 {
343 var element = elts[i]; 341 var element = elts[i];
344 if (isBlockable(element)) 342 if (isBlockable(element))
345 addElementOverlay(element); 343 addElementOverlay(element);
346 } 344 }
347 345
348 clickHide_activated = true; 346 clickHide_activated = true;
349 document.addEventListener("mouseover", clickHide_mouseOver, true); 347 document.addEventListener("mouseover", clickHide_mouseOver, true);
350 document.addEventListener("mouseout", clickHide_mouseOut, true); 348 document.addEventListener("mouseout", clickHide_mouseOut, true);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 ext.onExtensionUnloaded.removeListener(clickHide_deactivate); 399 ext.onExtensionUnloaded.removeListener(clickHide_deactivate);
402 } 400 }
403 } 401 }
404 402
405 function clickHide_elementClickHandler(ev) { 403 function clickHide_elementClickHandler(ev) {
406 ev.preventDefault(); 404 ev.preventDefault();
407 ev.stopPropagation(); 405 ev.stopPropagation();
408 clickHide_mouseClick(ev); 406 clickHide_mouseClick(ev);
409 } 407 }
410 408
409 function getBlockableElementOrAncestor(element)
410 {
411 while (element && element != document.documentElement
412 && element != document.body)
413 {
414 if (element instanceof HTMLElement && element.localName != "area")
415 {
416 // Handle <area> and their <map> elements specially,
417 // blocking the image they are associated with
418 if (element.localName == "map")
419 {
420 var images = document.querySelectorAll("img[usemap]");
421 for (var i = 0; i < images.length; i++)
422 {
423 var image = images[i];
424 var usemap = image.getAttribute("usemap");
kzar 2015/02/09 17:24:41 Don't we need to check that usemap isn't null befo
Sebastian Noack 2015/02/10 10:19:27 Mind the CSS selector above, excluding elements wi
kzar 2015/02/10 11:03:01 Ah OK
425 var index = usemap.indexOf("#");
426
427 if (index != -1 && usemap.substr(index + 1) == element.name)
428 return getBlockableElementOrAncestor(image);
429 }
430
431 return null;
432 }
433
434 if (isBlockable(element))
435 return element;
436 }
437
438 element = element.parentElement;
439 }
440
441 return null;
442 }
443
444
411 // Hovering over an element so highlight it 445 // Hovering over an element so highlight it
412 function clickHide_mouseOver(e) 446 function clickHide_mouseOver(e)
413 { 447 {
414 if (clickHide_activated == false) 448 if (clickHide_activated == false)
415 return; 449 return;
416 450
417 var target = e.target; 451 var target = getBlockableElementOrAncestor(e.target);
418 while (target.parentNode && !(target instanceof HTMLElement && isBlockable(tar get)))
419 target = target.parentNode;
420 if (target == document.documentElement || target == document.body)
421 target = null;
422 452
423 if (target) 453 if (target)
424 { 454 {
425 currentElement = target; 455 currentElement = target;
426 456
427 highlightElement(target, "#d6d84b", "#f8fa47"); 457 highlightElement(target, "#d6d84b", "#f8fa47");
428 target.addEventListener("contextmenu", clickHide_elementClickHandler, true); 458 target.addEventListener("contextmenu", clickHide_elementClickHandler, true);
429 } 459 }
430 } 460 }
431 461
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 case "clickhide-activate": 706 case "clickhide-activate":
677 clickHide_activate(); 707 clickHide_activate();
678 break; 708 break;
679 case "clickhide-deactivate": 709 case "clickhide-deactivate":
680 clickHide_deactivate(); 710 clickHide_deactivate();
681 break; 711 break;
682 case "clickhide-new-filter": 712 case "clickhide-new-filter":
683 if(lastRightClickEvent) 713 if(lastRightClickEvent)
684 { 714 {
685 clickHide_activated = true; 715 clickHide_activated = true;
686 currentElement = lastRightClickEvent.target; 716 currentElement = getBlockableElementOrAncestor(lastRightClickEvent.tar get);
687 clickHide_mouseClick(lastRightClickEvent); 717 clickHide_mouseClick(lastRightClickEvent);
688 } 718 }
689 break; 719 break;
690 case "clickhide-init": 720 case "clickhide-init":
691 if (clickHideFiltersDialog) 721 if (clickHideFiltersDialog)
692 { 722 {
693 sendResponse({filters: clickHide_filters}); 723 sendResponse({filters: clickHide_filters});
694 724
695 clickHideFiltersDialog.style.width = msg.width + "px"; 725 clickHideFiltersDialog.style.width = msg.width + "px";
696 clickHideFiltersDialog.style.height = msg.height + "px"; 726 clickHideFiltersDialog.style.height = msg.height + "px";
(...skipping 28 matching lines...) Expand all
725 lastRightClickEventValid = false; 755 lastRightClickEventValid = false;
726 else 756 else
727 lastRightClickEvent = null; 757 lastRightClickEvent = null;
728 break; 758 break;
729 } 759 }
730 }); 760 });
731 761
732 if (window == window.top) 762 if (window == window.top)
733 ext.backgroundPage.sendMessage({type: "report-html-page"}); 763 ext.backgroundPage.sendMessage({type: "report-html-page"});
734 } 764 }
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