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

Side by Side Diff: include.postload.js

Issue 5852223410012160: Issue 1755 - Create overlays with correct positioning and z-index, considering all ancestors (Closed)
Patch Set: Rebased and addressed comments Created Jan. 13, 2015, 1:16 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 var t = 0; 245 var t = 0;
246 for(; elt; elt = elt.offsetParent) { 246 for(; elt; elt = elt.offsetParent) {
247 l += elt.offsetLeft; 247 l += elt.offsetLeft;
248 t += elt.offsetTop; 248 t += elt.offsetTop;
249 } 249 }
250 return [l, t]; 250 return [l, t];
251 } 251 }
252 252
253 // Adds an overlay to an element, which is probably a Flash object 253 // Adds an overlay to an element, which is probably a Flash object
254 function addElementOverlay(elt) { 254 function addElementOverlay(elt) {
255 // If the element isn't rendered (since its or one of its ancestor's 255 var zIndex = "auto";
256 // "display" property is "none"), the overlay wouldn't match the element. 256 var position = "absolute";
257 if (!elt.offsetParent)
258 return;
259 257
260 var thisStyle = getComputedStyle(elt, null); 258 for (var e = elt; e; e = e.parentElement)
259 {
260 var style = getComputedStyle(e);
261
262 // If the element isn't rendered (since its or one of its ancestor's
263 // "display" property is "none"), the overlay wouldn't match the element.
264 if (style.display == "none")
265 return null;
266
267 // If the element or one of its ancestors uses fixed postioning, the overlay
268 // has to use fixed postioning too. Otherwise it might not match the element .
269 if (style.position == "fixed")
270 position = "fixed";
271
272 // Determine the effective z-index, which is the highest z-index used
273 // by the element and its offset ancestors. When using a lower z-index
274 // the element would cover the overlay. When using a higher z-index the
275 // overlay might also cover other elements.
276 if (style.position != "static" && style.zIndex != "auto")
277 {
278 if (zIndex == "auto")
279 zIndex = style.zIndex;
280 else
281 zIndex = Math.max(zIndex, style.zIndex);
282 }
283 }
284
261 var overlay = document.createElement('div'); 285 var overlay = document.createElement('div');
262 overlay.prisoner = elt; 286 overlay.prisoner = elt;
263 overlay.className = "__adblockplus__overlay"; 287 overlay.className = "__adblockplus__overlay";
264 overlay.setAttribute('style', 'opacity:0.4; display:inline-box; position:absol ute; overflow:hidden; box-sizing:border-box;'); 288 overlay.setAttribute('style', 'opacity:0.4; display:inline-box; overflow:hidde n; box-sizing:border-box;');
265 var pos = getAbsolutePosition(elt); 289 var pos = getAbsolutePosition(elt);
266 overlay.style.width = elt.offsetWidth + "px"; 290 overlay.style.width = elt.offsetWidth + "px";
267 overlay.style.height = elt.offsetHeight + "px"; 291 overlay.style.height = elt.offsetHeight + "px";
268 overlay.style.left = pos[0] + "px"; 292 overlay.style.left = pos[0] + "px";
269 overlay.style.top = pos[1] + "px"; 293 overlay.style.top = pos[1] + "px";
270 294 overlay.style.position = position;
271 if (thisStyle.position != "static") 295 overlay.style.zIndex = zIndex;
272 overlay.style.zIndex = thisStyle.zIndex;
273 else
274 overlay.style.zIndex = getComputedStyle(elt.offsetParent).zIndex;
275 296
276 // elt.parentNode.appendChild(overlay, elt); 297 // elt.parentNode.appendChild(overlay, elt);
277 document.body.appendChild(overlay); 298 document.body.appendChild(overlay);
278 return overlay; 299 return overlay;
279 } 300 }
280 301
281 // Show dialog asking user whether she wants to add the proposed filters derived 302 // Show dialog asking user whether she wants to add the proposed filters derived
282 // from selected page element 303 // from selected page element
283 function clickHide_showDialog(left, top, filters) 304 function clickHide_showDialog(left, top, filters)
284 { 305 {
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 element.parentNode.removeChild(element); 691 element.parentNode.removeChild(element);
671 } 692 }
672 clickHide_deactivate(); 693 clickHide_deactivate();
673 break; 694 break;
674 } 695 }
675 }); 696 });
676 697
677 if (window == window.top) 698 if (window == window.top)
678 ext.backgroundPage.sendMessage({type: "report-html-page"}); 699 ext.backgroundPage.sendMessage({type: "report-html-page"});
679 } 700 }
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