Bug 723937 - Make sure all the obviously private properties in Tilt start with an underscore; r=rcampbell

This commit is contained in:
Victor Porof 2012-02-07 11:44:55 +02:00
parent 7f816d0c7c
commit 402b76686c
18 changed files with 332 additions and 324 deletions

View File

@ -140,7 +140,7 @@ Tilt.prototype = {
},
/**
* Destroys a specific instance of the visualizer.
* Starts destroying a specific instance of the visualizer.
*
* @param {String} aId
* the identifier of the instance in the visualizers array
@ -149,43 +149,49 @@ Tilt.prototype = {
*/
destroy: function T_destroy(aId, aAnimateFlag)
{
// if the visualizer is already destroyed, don't do anything
if (!this.visualizers[aId]) {
// if the visualizer is destroyed or destroying, don't do anything
if (!this.visualizers[aId] || this._isDestroying) {
return;
}
this._isDestroying = true;
let controller = this.visualizers[aId].controller;
let presenter = this.visualizers[aId].presenter;
let content = presenter.contentWindow;
let pageXOffset = content.pageXOffset * presenter.transforms.zoom;
let pageYOffset = content.pageYOffset * presenter.transforms.zoom;
TiltUtils.setDocumentZoom(this.chromeWindow, presenter.transforms.zoom);
// if we're not doing any outro animation, just finish destruction directly
if (!aAnimateFlag) {
this._finish(aId);
return;
}
if (!this.isDestroying) {
this.isDestroying = true;
// otherwise, trigger the outro animation and notify necessary observers
Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.DESTROYING, null);
let finalize = function T_finalize(aId) {
this.visualizers[aId].removeOverlay();
this.visualizers[aId].cleanup();
this.visualizers[aId] = null;
controller.removeEventListeners();
controller.arcball.reset([-pageXOffset, -pageYOffset]);
presenter.executeDestruction(this._finish.bind(this, aId));
},
this.isDestroying = false;
this.chromeWindow.gBrowser.selectedBrowser.focus();
Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.DESTROYED, null);
};
/**
* Finishes detroying a specific instance of the visualizer.
*
* @param {String} aId
* the identifier of the instance in the visualizers array
*/
_finish: function T__finish(aId)
{
this.visualizers[aId].removeOverlay();
this.visualizers[aId].cleanup();
this.visualizers[aId] = null;
if (!aAnimateFlag) {
finalize.call(this, aId);
return;
}
let controller = this.visualizers[aId].controller;
let presenter = this.visualizers[aId].presenter;
let content = presenter.contentWindow;
let pageXOffset = content.pageXOffset * presenter.transforms.zoom;
let pageYOffset = content.pageYOffset * presenter.transforms.zoom;
Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.DESTROYING, null);
TiltUtils.setDocumentZoom(this.chromeWindow, presenter.transforms.zoom);
controller.removeEventListeners();
controller.arcball.reset([-pageXOffset, -pageYOffset]);
presenter.executeDestruction(finalize.bind(this, aId));
}
this._isDestroying = false;
this.chromeWindow.gBrowser.selectedBrowser.focus();
Services.obs.notifyObservers(null, TILT_NOTIFICATIONS.DESTROYED, null);
},
/**
@ -359,7 +365,6 @@ Tilt.prototype = {
*/
get tiltButton()
{
return this.chromeWindow.document.getElementById(
"inspector-3D-button");
return this.chromeWindow.document.getElementById("inspector-3D-button");
}
};

View File

@ -518,8 +518,8 @@ TiltUtils.destroyObject = function TU_destroyObject(aScope)
}
// objects in Tilt usually use a function to handle internal destruction
if ("function" === typeof aScope.finalize) {
aScope.finalize();
if ("function" === typeof aScope._finalize) {
aScope._finalize();
}
for (let i in aScope) {
if (aScope.hasOwnProperty(i)) {

File diff suppressed because it is too large Load Diff

View File

@ -62,11 +62,11 @@ function performTest(canvas, arcball, callback) {
window.setTimeout(function() {
info("Synthesizing arcball reset key press.");
arcball.onResetStart = function() {
arcball._onResetStart = function() {
info("Starting arcball reset animation.");
};
arcball.onResetStep = function() {
arcball._onResetStep = function() {
info("\nlastRot: " + quat4.str(arcball._lastRot) +
"\ndeltaRot: " + quat4.str(arcball._deltaRot) +
"\ncurrentRot: " + quat4.str(arcball._currentRot) +
@ -78,7 +78,7 @@ function performTest(canvas, arcball, callback) {
"\nzoomAmount: " + arcball._zoomAmount);
};
arcball.onResetFinish = function() {
arcball._onResetFinish = function() {
ok(isApproxVec(arcball._lastRot, [0, 0, 0, 1]),
"The arcball _lastRot field wasn't reset correctly.");
ok(isApproxVec(arcball._deltaRot, [0, 0, 0, 1]),
@ -101,8 +101,10 @@ function performTest(canvas, arcball, callback) {
ok(isApproxVec([arcball._zoomAmount], [0]),
"The arcball _zoomAmount field wasn't reset correctly.");
info("Finishing arcball reset test.");
callback();
executeSoon(function() {
info("Finishing arcball reset test.");
callback();
});
};
EventUtils.synthesizeKey("VK_R", { type: "keydown" });

View File

@ -60,11 +60,11 @@ function performTest(canvas, arcball, callback) {
window.setTimeout(function() {
info("Synthesizing arcball reset key press.");
arcball.onResetStart = function() {
arcball._onResetStart = function() {
info("Starting arcball reset animation.");
};
arcball.onResetStep = function() {
arcball._onResetStep = function() {
info("\nlastRot: " + quat4.str(arcball._lastRot) +
"\ndeltaRot: " + quat4.str(arcball._deltaRot) +
"\ncurrentRot: " + quat4.str(arcball._currentRot) +
@ -76,7 +76,7 @@ function performTest(canvas, arcball, callback) {
"\nzoomAmount: " + arcball._zoomAmount);
};
arcball.onResetFinish = function() {
arcball._onResetFinish = function() {
ok(isApproxVec(arcball._lastRot, [0, 0, 0, 1]),
"The arcball _lastRot field wasn't reset correctly.");
ok(isApproxVec(arcball._deltaRot, [0, 0, 0, 1]),
@ -99,8 +99,10 @@ function performTest(canvas, arcball, callback) {
ok(isApproxVec([arcball._zoomAmount], [0]),
"The arcball _zoomAmount field wasn't reset correctly.");
info("Finishing arcball reset test.");
callback();
executeSoon(function() {
info("Finishing arcball reset test.");
callback();
});
};
EventUtils.synthesizeKey("VK_R", { type: "keydown" });

View File

@ -48,10 +48,10 @@ function test() {
let arcball3 = new TiltVisualizer.Arcball(window, 512, 512);
let sphereVec = vec3.create();
arcball3.pointToSphere(123, 456, 256, 512, 512, sphereVec);
arcball3._pointToSphere(123, 456, 256, 512, 512, sphereVec);
ok(isApproxVec(sphereVec, [-0.009765625, 0.390625, 0.9204980731010437]),
"The pointToSphere() function didn't map the coordinates correctly.");
"The _pointToSphere() function didn't map the coordinates correctly.");
let stack1 = [];
let expect1 = [

View File

@ -47,7 +47,7 @@ function test() {
EventUtils.synthesizeKey("VK_A", { type: "keydown" });
EventUtils.synthesizeKey("VK_LEFT", { type: "keydown" });
instance.controller.update();
instance.controller._update();
ok(!isEqualVec(tran(), prev_tran),
"After a translation key is pressed, the vector should change.");
@ -58,7 +58,7 @@ function test() {
cancellingEvent();
instance.controller.update();
instance.controller._update();
ok(!isEqualVec(tran(), prev_tran),
"Even if the canvas lost focus, the vector has some inertia.");
@ -70,7 +70,7 @@ function test() {
while (!isEqualVec(tran(), prev_tran) ||
!isEqualVec(rot(), prev_rot)) {
instance.controller.update();
instance.controller._update();
save();
}

View File

@ -21,14 +21,14 @@ function test() {
let presenter = instance.presenter;
let canvas = presenter.canvas;
presenter.onSetupMesh = function() {
presenter._onSetupMesh = function() {
presenter.pickNode(canvas.width / 2, 10, {
onpick: function(data)
{
ok(data.index > 0,
"Simply picking a node didn't work properly.");
ok(!presenter.highlight.disabled,
ok(!presenter._highlight.disabled,
"After only picking a node, it shouldn't be highlighted.");
Services.obs.addObserver(cleanup, DESTROYED, false);

View File

@ -23,13 +23,13 @@ function test() {
presenter = instance.presenter;
Services.obs.addObserver(whenNodeRemoved, NODE_REMOVED, false);
presenter.onSetupMesh = function() {
presenter._onSetupMesh = function() {
presenter.highlightNodeAt(presenter.canvas.width / 2, 10, {
onpick: function()
{
ok(presenter._currentSelection > 0,
"Highlighting a node didn't work properly.");
ok(!presenter.highlight.disabled,
ok(!presenter._highlight.disabled,
"After highlighting a node, it should be highlighted. D'oh.");
presenter.deleteNode();
@ -44,14 +44,14 @@ function test() {
function whenNodeRemoved() {
ok(presenter._currentSelection > 0,
"Deleting a node shouldn't change the current selection.");
ok(presenter.highlight.disabled,
ok(presenter._highlight.disabled,
"After deleting a node, it shouldn't be highlighted.");
let nodeIndex = presenter._currentSelection;
let meshData = presenter.meshData;
let vertices = presenter._meshData.vertices;
for (let i = 0, k = 36 * nodeIndex; i < 36; i++) {
is(meshData.vertices[i + k], 0,
is(vertices[i + k], 0,
"The stack vertices weren't degenerated properly.");
}

View File

@ -24,7 +24,7 @@ function test() {
presenter = instance.presenter;
Services.obs.addObserver(whenHighlighting, HIGHLIGHTING, false);
presenter.onInitializationFinished = function() {
presenter._onInitializationFinished = function() {
let contentDocument = presenter.contentWindow.document;
let div = contentDocument.getElementById("far-far-away");
@ -38,7 +38,7 @@ function test() {
function whenHighlighting() {
ok(presenter._currentSelection > 0,
"Highlighting a node didn't work properly.");
ok(!presenter.highlight.disabled,
ok(!presenter._highlight.disabled,
"After highlighting a node, it should be highlighted. D'oh.");
ok(presenter.controller.arcball._resetInProgress,
"Highlighting a node that's not already visible should trigger a reset!");
@ -52,7 +52,7 @@ function whenHighlighting() {
function whenUnhighlighting() {
ok(presenter._currentSelection < 0,
"Unhighlighting a should remove the current selection.");
ok(presenter.highlight.disabled,
ok(presenter._highlight.disabled,
"After unhighlighting a node, it shouldn't be highlighted anymore. D'oh.");
executeSoon(function() {

View File

@ -23,7 +23,7 @@ function test() {
presenter = instance.presenter;
Services.obs.addObserver(whenHighlighting, HIGHLIGHTING, false);
presenter.onSetupMesh = function() {
presenter._onSetupMesh = function() {
let contentDocument = presenter.contentWindow.document;
let div = contentDocument.getElementById("first-law");
@ -37,7 +37,7 @@ function test() {
function whenHighlighting() {
ok(presenter._currentSelection > 0,
"Highlighting a node didn't work properly.");
ok(!presenter.highlight.disabled,
ok(!presenter._highlight.disabled,
"After highlighting a node, it should be highlighted. D'oh.");
ok(!presenter.controller.arcball._resetInProgress,
"Highlighting a node that's already visible shouldn't trigger a reset.");
@ -51,7 +51,7 @@ function whenHighlighting() {
function whenUnhighlighting() {
ok(presenter._currentSelection < 0,
"Unhighlighting a should remove the current selection.");
ok(presenter.highlight.disabled,
ok(presenter._highlight.disabled,
"After unhighlighting a node, it shouldn't be highlighted anymore. D'oh.");
executeSoon(function() {

View File

@ -23,7 +23,7 @@ function test() {
presenter = instance.presenter;
Services.obs.addObserver(whenHighlighting, HIGHLIGHTING, false);
presenter.onSetupMesh = function() {
presenter._onSetupMesh = function() {
presenter.highlightNodeAt(presenter.canvas.width / 2, 10);
};
}
@ -34,7 +34,7 @@ function test() {
function whenHighlighting() {
ok(presenter._currentSelection > 0,
"Highlighting a node didn't work properly.");
ok(!presenter.highlight.disabled,
ok(!presenter._highlight.disabled,
"After highlighting a node, it should be highlighted. D'oh.");
executeSoon(function() {
@ -46,7 +46,7 @@ function whenHighlighting() {
function whenUnhighlighting() {
ok(presenter._currentSelection < 0,
"Unhighlighting a should remove the current selection.");
ok(presenter.highlight.disabled,
ok(presenter._highlight.disabled,
"After unhighlighting a node, it shouldn't be highlighted anymore. D'oh.");
executeSoon(function() {

View File

@ -23,7 +23,7 @@ function test() {
presenter = instance.presenter;
Services.obs.addObserver(whenHighlighting, HIGHLIGHTING, false);
presenter.onSetupMesh = function() {
presenter._onSetupMesh = function() {
presenter.highlightNodeFor(5); // 1 = html, 2 = body, 3 = first div
};
}
@ -34,7 +34,7 @@ function test() {
function whenHighlighting() {
ok(presenter._currentSelection > 0,
"Highlighting a node didn't work properly.");
ok(!presenter.highlight.disabled,
ok(!presenter._highlight.disabled,
"After highlighting a node, it should be highlighted. D'oh.");
executeSoon(function() {
@ -46,7 +46,7 @@ function whenHighlighting() {
function whenUnhighlighting() {
ok(presenter._currentSelection < 0,
"Unhighlighting a should remove the current selection.");
ok(presenter.highlight.disabled,
ok(presenter._highlight.disabled,
"After unhighlighting a node, it shouldn't be highlighted anymore. D'oh.");
executeSoon(function() {

View File

@ -2,10 +2,6 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
let tmp = {};
Cu.import("resource:///modules/devtools/LayoutHelpers.jsm", tmp);
let LayoutHelpers = tmp.LayoutHelpers;
function init(callback) {
let iframe = gBrowser.ownerDocument.createElement("iframe");

View File

@ -11,7 +11,7 @@ let someObject = {
};
let anotherObject = {
finalize: function()
_finalize: function()
{
someObject.c = 3;
}

View File

@ -70,33 +70,33 @@ function test() {
}
function testPresenter(presenter) {
ok(presenter.renderer,
ok(presenter._renderer,
"The presenter renderer wasn't initialized properly.");
ok(presenter.visualizationProgram,
ok(presenter._visualizationProgram,
"The presenter visualizationProgram wasn't initialized properly.");
ok(presenter.texture,
ok(presenter._texture,
"The presenter texture wasn't initialized properly.");
ok(!presenter.meshStacks,
ok(!presenter._meshStacks,
"The presenter meshStacks shouldn't be initialized yet.");
ok(!presenter.meshWireframe,
ok(!presenter._meshWireframe,
"The presenter meshWireframe shouldn't be initialized yet.");
ok(presenter.traverseData,
ok(presenter._traverseData,
"The presenter nodesInformation wasn't initialized properly.");
ok(presenter.highlight,
ok(presenter._highlight,
"The presenter highlight wasn't initialized properly.");
ok(presenter.highlight.disabled,
"The presenter highlight should be initially disabled");
ok(isApproxVec(presenter.highlight.v0, [0, 0, 0]),
ok(presenter._highlight.disabled,
"The presenter highlight should be initially disabled.");
ok(isApproxVec(presenter._highlight.v0, [0, 0, 0]),
"The presenter highlight first vertex should be initially zeroed.");
ok(isApproxVec(presenter.highlight.v1, [0, 0, 0]),
ok(isApproxVec(presenter._highlight.v1, [0, 0, 0]),
"The presenter highlight second vertex should be initially zeroed.");
ok(isApproxVec(presenter.highlight.v2, [0, 0, 0]),
ok(isApproxVec(presenter._highlight.v2, [0, 0, 0]),
"The presenter highlight third vertex should be initially zeroed.");
ok(isApproxVec(presenter.highlight.v3, [0, 0, 0]),
ok(isApproxVec(presenter._highlight.v3, [0, 0, 0]),
"The presenter highlight fourth vertex should be initially zeroed.");
ok(presenter.transforms,
"The presenter transforms wasn't initialized properly.");
ok(isApproxVec(presenter.transforms.zoom, 1),
is(presenter.transforms.zoom, 1,
"The presenter transforms zoom should be initially 1.");
ok(isApproxVec(presenter.transforms.offset, [0, 0, 0]),
"The presenter transforms offset should be initially zeroed.");
@ -112,7 +112,7 @@ function testPresenter(presenter) {
"The presenter transforms translation wasn't modified as it should");
ok(isApproxVec(presenter.transforms.rotation, [5, 6, 7, 8]),
"The presenter transforms rotation wasn't modified as it should");
ok(presenter.redraw,
ok(presenter._redraw,
"The new transforms should have issued a redraw request.");
}

View File

@ -35,7 +35,7 @@ function test() {
let initialWidth = contentWindow.innerWidth;
let initialHeight = contentWindow.innerHeight;
let renderer = instance.presenter.renderer;
let renderer = instance.presenter._renderer;
let arcball = instance.controller.arcball;
ok(isApprox(contentWindow.innerWidth * ZOOM, renderer.width, 1),

View File

@ -7,6 +7,7 @@ Components.utils.import("resource:///modules/devtools/TiltGL.jsm", tempScope);
Components.utils.import("resource:///modules/devtools/TiltMath.jsm", tempScope);
Components.utils.import("resource:///modules/devtools/TiltUtils.jsm", tempScope);
Components.utils.import("resource:///modules/devtools/TiltVisualizer.jsm", tempScope);
Components.utils.import("resource:///modules/devtools/LayoutHelpers.jsm", tempScope);
let TiltGL = tempScope.TiltGL;
let EPSILON = tempScope.EPSILON;
let TiltMath = tempScope.TiltMath;
@ -16,6 +17,7 @@ let mat4 = tempScope.mat4;
let quat4 = tempScope.quat4;
let TiltUtils = tempScope.TiltUtils;
let TiltVisualizer = tempScope.TiltVisualizer;
let LayoutHelpers = tempScope.LayoutHelpers;
const DEFAULT_HTML = "data:text/html," +