Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | // The including script sets this for us |
michael@0 | 2 | //var NUM_STEPS; |
michael@0 | 3 | |
michael@0 | 4 | var plugin; |
michael@0 | 5 | var left = 1, top = 1, width = 199, height = 199; |
michael@0 | 6 | function movePluginTo(x, y, w, h) { |
michael@0 | 7 | left = x; top = y; width = w; height = h; |
michael@0 | 8 | plugin.width = w; |
michael@0 | 9 | plugin.height = h; |
michael@0 | 10 | plugin.style.left = left + "px"; |
michael@0 | 11 | plugin.style.top = top + "px"; |
michael@0 | 12 | } |
michael@0 | 13 | function deltaInBounds(dx,dy, dw,dh) { |
michael@0 | 14 | var l = dx + left; |
michael@0 | 15 | var r = l + width + dw; |
michael@0 | 16 | var t = dy + top; |
michael@0 | 17 | var b = t + height + dh; |
michael@0 | 18 | return (0 <= l && l <= 20 && |
michael@0 | 19 | 0 <= t && t <= 20 && |
michael@0 | 20 | 200 <= r && r <= 220 && |
michael@0 | 21 | 200 <= b && b <= 220); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | var initialFrame; |
michael@0 | 25 | function start() { |
michael@0 | 26 | window.removeEventListener("MozReftestInvalidate", start, false); |
michael@0 | 27 | |
michael@0 | 28 | window.addEventListener("MozAfterPaint", step, false); |
michael@0 | 29 | window.addEventListener("MozPaintWaitFinished", step, false); |
michael@0 | 30 | |
michael@0 | 31 | initialFrame = window.mozPaintCount; |
michael@0 | 32 | plugin = document.getElementById("plugin"); |
michael@0 | 33 | |
michael@0 | 34 | movePluginTo(0,0, 200,200); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | var steps = 0; |
michael@0 | 38 | var which = "move"; // or "grow" |
michael@0 | 39 | var dx = 1, dy = 1, dw = 1, dh = 1; |
michael@0 | 40 | function step() { |
michael@0 | 41 | if (++steps >= NUM_STEPS) { |
michael@0 | 42 | window.removeEventListener("MozAfterPaint", step, false); |
michael@0 | 43 | window.removeEventListener("MozPaintWaitFinished", step, false); |
michael@0 | 44 | return finish(); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | var didSomething = false; |
michael@0 | 48 | if (which == "grow") { |
michael@0 | 49 | if (deltaInBounds(0,0, dw,dh)) { |
michael@0 | 50 | movePluginTo(left,top, width+dw, height+dh); |
michael@0 | 51 | didSomething = true; |
michael@0 | 52 | } else { |
michael@0 | 53 | dw = -dw; dh = -dh; |
michael@0 | 54 | } |
michael@0 | 55 | } else { |
michael@0 | 56 | // "move" |
michael@0 | 57 | if (deltaInBounds(dx,dy, 0,0)) { |
michael@0 | 58 | movePluginTo(left+dx,top+dy, width, height); |
michael@0 | 59 | didSomething = true; |
michael@0 | 60 | } else { |
michael@0 | 61 | dx = -dx; dy = -dy; |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 | which = (which == "grow") ? "move" : "grow"; |
michael@0 | 65 | |
michael@0 | 66 | if (!didSomething) { |
michael@0 | 67 | step(); |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function finish() { |
michael@0 | 72 | document.documentElement.removeAttribute("class"); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | window.addEventListener("MozReftestInvalidate", start, false); |