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

Side by Side Diff: include.postload.js

Issue 6175313801248768: Issue 1665 - Catch all mouse events when clickHide is active (Closed)
Patch Set: Created Feb. 11, 2015, 6:22 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 /* 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // so that they can still be selected. 338 // so that they can still be selected.
339 var elts = document.querySelectorAll('object,embed,iframe,frame'); 339 var elts = document.querySelectorAll('object,embed,iframe,frame');
340 for(var i=0; i<elts.length; i++) 340 for(var i=0; i<elts.length; i++)
341 { 341 {
342 var element = elts[i]; 342 var element = elts[i];
343 if (isBlockable(element)) 343 if (isBlockable(element))
344 addElementOverlay(element); 344 addElementOverlay(element);
345 } 345 }
346 346
347 clickHide_activated = true; 347 clickHide_activated = true;
348 document.addEventListener("mousedown", clickHide_stopPropagation, true);
349 document.addEventListener("mouseup", clickHide_stopPropagation, true);
350 document.addEventListener("mouseenter", clickHide_stopPropagation, true);
351 document.addEventListener("mouseleave", clickHide_stopPropagation, true);
348 document.addEventListener("mouseover", clickHide_mouseOver, true); 352 document.addEventListener("mouseover", clickHide_mouseOver, true);
349 document.addEventListener("mouseout", clickHide_mouseOut, true); 353 document.addEventListener("mouseout", clickHide_mouseOut, true);
350 document.addEventListener("click", clickHide_mouseClick, true); 354 document.addEventListener("click", clickHide_mouseClick, true);
351 document.addEventListener("keydown", clickHide_keyDown, true); 355 document.addEventListener("keydown", clickHide_keyDown, true);
352 356
353 ext.onExtensionUnloaded.addListener(clickHide_deactivate); 357 ext.onExtensionUnloaded.addListener(clickHide_deactivate);
354 } 358 }
355 359
356 // Called when user has clicked on something and we are waiting for confirmation 360 // Called when user has clicked on something and we are waiting for confirmation
357 // on whether the user actually wants these filters 361 // on whether the user actually wants these filters
358 function clickHide_rulesPending() { 362 function clickHide_rulesPending() {
359 clickHide_activated = false; 363 clickHide_activated = false;
364 document.removeEventListener("mousedown", clickHide_stopPropagation, true);
365 document.removeEventListener("mouseup", clickHide_stopPropagation, true);
366 document.removeEventListener("mouseenter", clickHide_stopPropagation, true);
367 document.removeEventListener("mouseleave", clickHide_stopPropagation, true);
360 document.removeEventListener("mouseover", clickHide_mouseOver, true); 368 document.removeEventListener("mouseover", clickHide_mouseOver, true);
361 document.removeEventListener("mouseout", clickHide_mouseOut, true); 369 document.removeEventListener("mouseout", clickHide_mouseOut, true);
362 document.removeEventListener("click", clickHide_mouseClick, true); 370 document.removeEventListener("click", clickHide_mouseClick, true);
363 document.removeEventListener("keydown", clickHide_keyDown, true); 371 document.removeEventListener("keydown", clickHide_keyDown, true);
364 } 372 }
365 373
366 // Turn off click-to-hide 374 // Turn off click-to-hide
367 function clickHide_deactivate(keepOverlays) 375 function clickHide_deactivate(keepOverlays)
368 { 376 {
369 if (clickHideFiltersDialog) 377 if (clickHideFiltersDialog)
370 { 378 {
371 document.documentElement.removeChild(clickHideFiltersDialog); 379 document.documentElement.removeChild(clickHideFiltersDialog);
372 clickHideFiltersDialog = null; 380 clickHideFiltersDialog = null;
373 } 381 }
374 382
375 clickHide_activated = false; 383 clickHide_activated = false;
376 clickHide_filters = null; 384 clickHide_filters = null;
377 if(!document) 385 if(!document)
378 return; // This can happen inside a nuked iframe...I think 386 return; // This can happen inside a nuked iframe...I think
387
388 document.removeEventListener("mousedown", clickHide_stopPropagation, true);
389 document.removeEventListener("mouseup", clickHide_stopPropagation, true);
390 document.removeEventListener("mouseenter", clickHide_stopPropagation, true);
391 document.removeEventListener("mouseleave", clickHide_stopPropagation, true);
379 document.removeEventListener("mouseover", clickHide_mouseOver, true); 392 document.removeEventListener("mouseover", clickHide_mouseOver, true);
380 document.removeEventListener("mouseout", clickHide_mouseOut, true); 393 document.removeEventListener("mouseout", clickHide_mouseOut, true);
381 document.removeEventListener("click", clickHide_mouseClick, true); 394 document.removeEventListener("click", clickHide_mouseClick, true);
382 document.removeEventListener("keydown", clickHide_keyDown, true); 395 document.removeEventListener("keydown", clickHide_keyDown, true);
383 396
384 if (keepOverlays !== true) 397 if (keepOverlays !== true)
385 { 398 {
386 lastRightClickEvent = null; 399 lastRightClickEvent = null;
387 400
388 if (currentElement) { 401 if (currentElement) {
389 currentElement.removeEventListener("contextmenu", clickHide_elementClickH andler, true); 402 currentElement.removeEventListener("contextmenu", clickHide_elementClickH andler, true);
390 unhighlightElements(); 403 unhighlightElements();
391 unhighlightElement(currentElement); 404 unhighlightElement(currentElement);
392 currentElement = null; 405 currentElement = null;
393 } 406 }
394 unhighlightElements(); 407 unhighlightElements();
395 408
396 var overlays = document.getElementsByClassName("__adblockplus__overlay"); 409 var overlays = document.getElementsByClassName("__adblockplus__overlay");
397 while (overlays.length > 0) 410 while (overlays.length > 0)
398 overlays[0].parentNode.removeChild(overlays[0]); 411 overlays[0].parentNode.removeChild(overlays[0]);
399 412
400 ext.onExtensionUnloaded.removeListener(clickHide_deactivate); 413 ext.onExtensionUnloaded.removeListener(clickHide_deactivate);
401 } 414 }
402 } 415 }
403 416
404 function clickHide_elementClickHandler(ev) { 417 function clickHide_stopPropagation(e)
405 ev.preventDefault(); 418 {
406 ev.stopPropagation(); 419 e.stopPropagation();
407 clickHide_mouseClick(ev); 420 }
421
422 function clickHide_elementClickHandler(e) {
423 e.preventDefault();
424 e.stopPropagation();
425 clickHide_mouseClick(e);
408 } 426 }
409 427
410 function getBlockableElementOrAncestor(element) 428 function getBlockableElementOrAncestor(element)
411 { 429 {
412 while (element && element != document.documentElement 430 while (element && element != document.documentElement
413 && element != document.body) 431 && element != document.body)
414 { 432 {
415 if (element instanceof HTMLElement && element.localName != "area") 433 if (element instanceof HTMLElement && element.localName != "area")
416 { 434 {
417 // Handle <area> and their <map> elements specially, 435 // Handle <area> and their <map> elements specially,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 468
451 var target = getBlockableElementOrAncestor(e.target); 469 var target = getBlockableElementOrAncestor(e.target);
452 470
453 if (target) 471 if (target)
454 { 472 {
455 currentElement = target; 473 currentElement = target;
456 474
457 highlightElement(target, "#d6d84b", "#f8fa47"); 475 highlightElement(target, "#d6d84b", "#f8fa47");
458 target.addEventListener("contextmenu", clickHide_elementClickHandler, true); 476 target.addEventListener("contextmenu", clickHide_elementClickHandler, true);
459 } 477 }
478 e.stopPropagation();
460 } 479 }
461 480
462 // No longer hovering over this element so unhighlight it 481 // No longer hovering over this element so unhighlight it
463 function clickHide_mouseOut(e) 482 function clickHide_mouseOut(e)
464 { 483 {
465 if (!clickHide_activated || !currentElement) 484 if (!clickHide_activated || !currentElement)
466 return; 485 return;
467 486
468 unhighlightElement(currentElement); 487 unhighlightElement(currentElement);
469 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, true); 488 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, true);
489 e.stopPropagation();
470 } 490 }
471 491
472 // Selects the currently hovered-over filter or cancels selection 492 // Selects the currently hovered-over filter or cancels selection
473 function clickHide_keyDown(e) 493 function clickHide_keyDown(e)
474 { 494 {
475 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN* /) 495 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN* /)
476 clickHide_mouseClick(e); 496 clickHide_mouseClick(e);
477 else if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 27 /*DOM_VK_ES CAPE*/) 497 else if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 27 /*DOM_VK_ES CAPE*/)
478 { 498 {
479 ext.backgroundPage.sendMessage( 499 ext.backgroundPage.sendMessage(
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 lastRightClickEventValid = false; 775 lastRightClickEventValid = false;
756 else 776 else
757 lastRightClickEvent = null; 777 lastRightClickEvent = null;
758 break; 778 break;
759 } 779 }
760 }); 780 });
761 781
762 if (window == window.top) 782 if (window == window.top)
763 ext.backgroundPage.sendMessage({type: "report-html-page"}); 783 ext.backgroundPage.sendMessage({type: "report-html-page"});
764 } 784 }
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