From 82fe8b26eb41c3d18e1cc19cd23bc8d4fc0c70cb Mon Sep 17 00:00:00 2001 From: Benjamin Stover Date: Fri, 4 Dec 2009 12:03:56 -0800 Subject: [PATCH] Bug 530835 - Flash: Chrome UI shows up on background of flash videos [r=gavin.sharp] --- toolkit/content/Geometry.jsm | 37 +++++++++++++++++-- .../content/tests/browser/browser_Geometry.js | 31 +++++++++++++++- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/toolkit/content/Geometry.jsm b/toolkit/content/Geometry.jsm index 25e93a056b0f..400bac0295f5 100644 --- a/toolkit/content/Geometry.jsm +++ b/toolkit/content/Geometry.jsm @@ -176,11 +176,15 @@ let Util = { } }; +/** + * Cache of commonly used elements. + */ let Elements = {}; [ ["browserBundle", "bundle_browser"], ["contentShowing", "bcast_contentShowing"], + ["stack", "stack"], ].forEach(function (elementGlobal) { let [name, id] = elementGlobal; Elements.__defineGetter__(name, function () { @@ -314,7 +318,7 @@ Rect.prototype = { return this; }, - setBounds: function(t, l, b, r) { + setBounds: function(l, t, r, b) { this.top = t; this.left = l; this.bottom = b; @@ -452,8 +456,35 @@ Rect.prototype = { translateInside: function translateInside(other) { let offsetX = (this.left < other.left ? other.left - this.left : (this.right > other.right ? this.right - other.right : 0)); - let offsetY = (this.top < other.top ? other.top - this.top : + let offsetY = (this.top < other.top ? other.top - this.top : (this.bottom > other.bottom ? this.bottom - other.bottom : 0)); return this.translate(offsetX, offsetY); - } + }, + + /** Subtract other area from this. Returns array of rects whose union is this-other. */ + subtract: function subtract(other) { + let r = new Rect(0, 0, 0, 0); + let result = []; + other = other.intersect(this); + if (other.isEmpty()) + return [this.clone()]; + + // left strip + r.setBounds(this.left, this.top, other.left, this.bottom); + if (!r.isEmpty()) + result.push(r.clone()); + // inside strip + r.setBounds(other.left, this.top, other.right, other.top); + if (!r.isEmpty()) + result.push(r.clone()); + r.setBounds(other.left, other.bottom, other.right, this.bottom); + if (!r.isEmpty()) + result.push(r.clone()); + // right strip + r.setBounds(other.right, this.top, this.right, this.bottom); + if (!r.isEmpty()) + result.push(r.clone()); + + return result; + }, }; diff --git a/toolkit/content/tests/browser/browser_Geometry.js b/toolkit/content/tests/browser/browser_Geometry.js index 1c7afc37d589..c422e6998c7a 100644 --- a/toolkit/content/tests/browser/browser_Geometry.js +++ b/toolkit/content/tests/browser/browser_Geometry.js @@ -69,5 +69,34 @@ let tests = { let r2 = new Rect(0, 0, 0, 0); r1.expandToContain(r2); ok(r1.isEmpty(), "expandToContain of empty and empty is empty"); - } + }, + + testSubtract: function testSubtract() { + function equals(rects1, rects2) { + return rects1.length == rects2.length && rects1.every(function(r, i) { + return r.equals(rects2[i]); + }); + } + + let r1 = new Rect(0, 0, 100, 100); + let r2 = new Rect(500, 500, 100, 100); + ok(equals(r1.subtract(r2), [r1]), "subtract area outside of region yields same region"); + + let r1 = new Rect(0, 0, 100, 100); + let r2 = new Rect(-10, -10, 50, 120); + ok(equals(r1.subtract(r2), [new Rect(40, 0, 60, 100)]), "subtracting vertical bar from edge leaves one rect"); + + let r1 = new Rect(0, 0, 100, 100); + let r2 = new Rect(-10, -10, 120, 50); + ok(equals(r1.subtract(r2), [new Rect(0, 40, 100, 60)]), "subtracting horizontal bar from edge leaves one rect"); + + let r1 = new Rect(0, 0, 100, 100); + let r2 = new Rect(40, 40, 20, 20); + ok(equals(r1.subtract(r2), [ + new Rect(0, 0, 40, 100), + new Rect(40, 0, 20, 40), + new Rect(40, 60, 20, 40), + new Rect(60, 0, 40, 100)]), + "subtracting rect in middle leaves union of rects"); + }, };