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

Unified Diff: include.postload.js

Issue 6264613016436736: Issue #350 - iFrame block element improvements (Closed)
Patch Set: Separate unrelated changes into other code reviews Created Jan. 16, 2015, 8:29 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.postload.js
diff --git a/include.postload.js b/include.postload.js
index 30f02b011848af3a9e5cf05cdaf80d84940f5a69..2aacf80e1737d6e928b2d347f28bd431e0fcb381 100644
--- a/include.postload.js
+++ b/include.postload.js
@@ -22,6 +22,7 @@ var currentElement = null;
var highlightedElementsSelector = null;
var clickHideFiltersDialog = null;
var lastRightClickEvent = null;
+var lastRightClickEventRandom = null;
function escapeChar(chr)
{
@@ -389,6 +390,8 @@ function clickHide_deactivate(keepOverlays)
if (!keepOverlays)
{
+ lastRightClickEvent = null;
+
if (currentElement) {
currentElement.removeEventListener("contextmenu", clickHide_elementClickHandler, true);
unhighlightElements();
@@ -524,8 +527,17 @@ function clickHide_mouseClick(e)
addSelector(escapeCSS(elt.localName) + '[style=' + quote(style) + ']');
}
- // Show popup
- clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
+ // Show popup, or if inside frame tell the parent to do it
+ if (window.self == window.top)
+ clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
+ else
+ ext.backgroundPage.sendMessage(
+ {
+ type: "clickHide-showDialog",
+ screenX: e.screenX,
+ screenY: e.screenY,
+ clickHideFilters: clickHideFilters
+ });
// Highlight the elements specified by selector in yellow
if (selectorList.length > 0)
@@ -577,8 +589,18 @@ if ("ext" in window && document instanceof HTMLDocument)
// To make things easier, we actually save the DOM event.
// We have to do this because the contextMenu API only provides a URL, not the actual
// DOM element.
- document.addEventListener('contextmenu', function(e) {
+ document.addEventListener('contextmenu', function(e)
+ {
lastRightClickEvent = e;
+ // We also need to ensure any old lastRightClickEvent variables in other
+ // frames are cleared. So we store a random number, send a message to all
+ // frames that they should clear lastRightClickEvent unless the number matches
+ lastRightClickEventRandom = Math.random();
Sebastian Noack 2015/01/16 22:45:31 I don't really like the approach here to generate
kzar 2015/01/16 23:03:45 Done.
+ ext.backgroundPage.sendMessage(
+ {
+ type: "clickHide-clear-lastRightClickEvent",
+ random: lastRightClickEventRandom
+ });
}, true);
document.addEventListener("click", function(event)
@@ -681,7 +703,7 @@ if ("ext" in window && document instanceof HTMLDocument)
}
break;
case "clickhide-close":
- if (clickHideFiltersDialog && msg.remove)
+ if (currentElement && msg.remove)
{
// Explicitly get rid of currentElement
var element = currentElement.prisoner || currentElement;
@@ -690,6 +712,17 @@ if ("ext" in window && document instanceof HTMLDocument)
}
clickHide_deactivate();
break;
+ case "clickHide-showDialog":
Sebastian Noack 2015/01/16 22:45:31 For consistency with the message types implemented
kzar 2015/01/16 23:03:45 Done.
+ if (window.self == window.top)
+ clickHide_showDialog(msg.screenX + window.pageXOffset,
+ msg.screenY + window.pageYOffset,
+ msg.clickHideFilters);
+ break;
+ case "clickHide-clear-lastRightClickEvent":
+ if (msg.random != lastRightClickEventRandom)
+ lastRightClickEvent = null;
+ lastRightClickEventRandom = null;
+ break;
}
});
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld