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

Delta Between Two Patch Sets: include.postload.js

Issue 5852223410012160: Issue 1755 - Create overlays with correct positioning and z-index, considering all ancestors (Closed)
Left Patch Set: Created Jan. 7, 2015, 2:33 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 { 47 {
48 return s.replace(/^[\d\-]|[^\w\-\u0080-\uFFFF]/g, escapeChar); 48 return s.replace(/^[\d\-]|[^\w\-\u0080-\uFFFF]/g, escapeChar);
49 } 49 }
50 50
51 function highlightElement(element, shadowColor, backgroundColor) 51 function highlightElement(element, shadowColor, backgroundColor)
52 { 52 {
53 unhighlightElement(element); 53 unhighlightElement(element);
54 54
55 var highlightWithOverlay = function() 55 var highlightWithOverlay = function()
56 { 56 {
57 var overlay = addElementOverlay(element);
58
57 highlightElement(overlay, shadowColor, backgroundColor); 59 highlightElement(overlay, shadowColor, backgroundColor);
58 overlay.style.pointerEvents = "none"; 60 overlay.style.pointerEvents = "none";
59 61
60 element._unhighlight = function() 62 element._unhighlight = function()
61 { 63 {
62 overlay.parentNode.removeChild(overlay); 64 overlay.parentNode.removeChild(overlay);
63 }; 65 };
64 }; 66 };
65 67
66 var highlightWithStyleAttribute = function() 68 var highlightWithStyleAttribute = function()
67 { 69 {
68 var originalBoxShadow = element.style.getPropertyValue ("box -shadow"); 70 var originalBoxShadow = element.style.getPropertyValue("box-shadow");
69 var originalBoxShadowPriority = element.style.getPropertyPriority("box -shadow"); 71 var originalBoxShadowPriority = element.style.getPropertyPriority("box-shado w");
70 var originalBackgroundColor = element.style.getPropertyValue ("bac kground-color"); 72 var originalBackgroundColor = element.style.getPropertyValue("background-col or");
71 var originalBackgroundColorPriority = element.style.getPropertyPriority("bac kground-color"); 73 var originalBackgroundColorPriority = element.style.getPropertyPriority("bac kground-color");
72 74
73 element.style.setProperty("box-shadow", "inset 0px 0px 5px " + shadowColor, "important"); 75 element.style.setProperty("box-shadow", "inset 0px 0px 5px " + shadowColor, "important");
74 element.style.setProperty("background-color", backgroundColor, "important"); 76 element.style.setProperty("background-color", backgroundColor, "important");
75 77
76 element._unhighlight = function() 78 element._unhighlight = function()
77 { 79 {
78 this.style.removeProperty("box-shadow"); 80 this.style.removeProperty("box-shadow");
79 this.style.setProperty( 81 this.style.setProperty(
80 "box-shadow", 82 "box-shadow",
81 originalBoxShadow, 83 originalBoxShadow,
82 originalBoxShadowPriority 84 originalBoxShadowPriority
83 ); 85 );
84 86
85 this.style.removeProperty("background-color"); 87 this.style.removeProperty("background-color");
86 this.style.setProperty( 88 this.style.setProperty(
87 "background-color", 89 "background-color",
88 originalBackgroundColor, 90 originalBackgroundColor,
89 originalBackgroundColorPriority 91 originalBackgroundColorPriority
90 ); 92 );
91 }; 93 };
92 }; 94 };
93 95
94 var overlay; 96 if ("prisoner" in element)
95 if (!("prisoner" in element) && (overlay = addElementOverlay(element))) 97 highlightWithStyleAttribute();
98 else
96 highlightWithOverlay(); 99 highlightWithOverlay();
97 else
98 highlightWithStyleAttribute();
99 } 100 }
100 101
101 102
102 function unhighlightElement(element) 103 function unhighlightElement(element)
103 { 104 {
104 if ("_unhighlight" in element) 105 if ("_unhighlight" in element)
105 { 106 {
106 element._unhighlight(); 107 element._unhighlight();
107 delete element._unhighlight; 108 delete element._unhighlight;
108 } 109 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 var t = 0; 245 var t = 0;
245 for(; elt; elt = elt.offsetParent) { 246 for(; elt; elt = elt.offsetParent) {
246 l += elt.offsetLeft; 247 l += elt.offsetLeft;
247 t += elt.offsetTop; 248 t += elt.offsetTop;
248 } 249 }
249 return [l, t]; 250 return [l, t];
250 } 251 }
251 252
252 // 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
253 function addElementOverlay(elt) { 254 function addElementOverlay(elt) {
254 var zIndex = null; 255 var zIndex = "auto";
255 var position = "absolute"; 256 var position = "absolute";
256 257
257 for (var e = elt; e; e = e.parentElement) 258 for (var e = elt; e; e = e.parentElement)
258 { 259 {
259 var style = getComputedStyle(e); 260 var style = getComputedStyle(e);
260 261
261 // If the element isn't rendered (since its or one of its ancestor's 262 // If the element isn't rendered (since its or one of its ancestor's
262 // "display" property is "none"), the overlay wouldn't match the element. 263 // "display" property is "none"), the overlay wouldn't match the element.
263 if (style.display == "none") 264 if (style.display == "none")
264 return null; 265 return null;
265 266
266 // If the element or one of its ancestors uses fixed postioning, the overlay 267 // If the element or one of its ancestors uses fixed postioning, the overlay
267 // has to use fixed postioning too. Otherwise it might not match the element . 268 // has to use fixed postioning too. Otherwise it might not match the element .
268 if (style.position == "fixed") 269 if (style.position == "fixed")
269 position = "fixed"; 270 position = "fixed";
270 271
271 // Determine the effective z-index, which is the highest z-index used 272 // Determine the effective z-index, which is the highest z-index used
272 // by the element and its offset ancestors. When using a lower z-index 273 // by the element and its offset ancestors. When using a lower z-index
273 // the element would cover the overlay. When using a higher z-index the 274 // the element would cover the overlay. When using a higher z-index the
274 // overlay might also cover other elements. 275 // overlay might also cover other elements.
275 if (style.position != "static" && style.zIndex != "auto") 276 if (style.position != "static" && style.zIndex != "auto")
276 zIndex = Math.max(zIndex, parseInt(style.zIndex, 10)); 277 {
kzar 2015/01/13 11:13:13 zIndex is initially null which when passed to Math
Sebastian Noack 2015/01/13 13:20:09 I didn't realize that null is converted to 0, but
278 if (zIndex == "auto")
279 zIndex = style.zIndex;
280 else
281 zIndex = Math.max(zIndex, style.zIndex);
282 }
277 } 283 }
278 284
279 var overlay = document.createElement('div'); 285 var overlay = document.createElement('div');
280 overlay.prisoner = elt; 286 overlay.prisoner = elt;
281 overlay.className = "__adblockplus__overlay"; 287 overlay.className = "__adblockplus__overlay";
282 overlay.setAttribute('style', 'opacity:0.4; display:inline-box; overflow:hidde n; box-sizing:border-box;'); 288 overlay.setAttribute('style', 'opacity:0.4; display:inline-box; overflow:hidde n; box-sizing:border-box;');
283 var pos = getAbsolutePosition(elt); 289 var pos = getAbsolutePosition(elt);
284 overlay.style.width = elt.offsetWidth + "px"; 290 overlay.style.width = elt.offsetWidth + "px";
285 overlay.style.height = elt.offsetHeight + "px"; 291 overlay.style.height = elt.offsetHeight + "px";
286 overlay.style.left = pos[0] + "px"; 292 overlay.style.left = pos[0] + "px";
287 overlay.style.top = pos[1] + "px"; 293 overlay.style.top = pos[1] + "px";
288 overlay.style.position = position; 294 overlay.style.position = position;
289 overlay.style.zIndex = zIndex || "auto"; 295 overlay.style.zIndex = zIndex;
kzar 2015/01/13 11:13:13 Should possibly check that zIndex is null here ins
Sebastian Noack 2015/01/13 13:20:09 I use "auto" as default value above now.
290 296
291 // elt.parentNode.appendChild(overlay, elt); 297 // elt.parentNode.appendChild(overlay, elt);
292 document.body.appendChild(overlay); 298 document.body.appendChild(overlay);
293 return overlay; 299 return overlay;
294 } 300 }
295 301
296 // 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
297 // from selected page element 303 // from selected page element
298 function clickHide_showDialog(left, top, filters) 304 function clickHide_showDialog(left, top, filters)
299 { 305 {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 case "clickhide-close": 685 case "clickhide-close":
680 if (clickHideFiltersDialog && msg.remove) 686 if (clickHideFiltersDialog && msg.remove)
681 { 687 {
682 // Explicitly get rid of currentElement 688 // Explicitly get rid of currentElement
683 var element = currentElement.prisoner || currentElement; 689 var element = currentElement.prisoner || currentElement;
684 if (element && element.parentNode) 690 if (element && element.parentNode)
685 element.parentNode.removeChild(element); 691 element.parentNode.removeChild(element);
686 } 692 }
687 clickHide_deactivate(); 693 clickHide_deactivate();
688 break; 694 break;
689 default:
kzar 2015/01/13 13:24:50 Did you remove these lines on purpose?
Sebastian Noack 2015/01/13 13:28:20 I had to rebase. And those lines don't exist anymo
690 sendResponse({});
691 break;
692 } 695 }
693 }); 696 });
694 697
695 if (window == window.top) 698 if (window == window.top)
696 ext.backgroundPage.sendMessage({type: "report-html-page"}); 699 ext.backgroundPage.sendMessage({type: "report-html-page"});
697 } 700 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld