2011-11-10 02:09:18 -08:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2011-12-21 04:39:29 -08:00
|
|
|
/*global Services, Components, gBrowser, executeSoon, info */
|
2011-11-10 02:09:18 -08:00
|
|
|
/*global InspectorUI, Tilt, TiltGL, EPSILON */
|
|
|
|
"use strict";
|
|
|
|
|
2012-01-23 07:50:11 -08:00
|
|
|
let tempScope = {};
|
|
|
|
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);
|
|
|
|
let TiltGL = tempScope.TiltGL;
|
|
|
|
let EPSILON = tempScope.EPSILON;
|
|
|
|
let TiltMath = tempScope.TiltMath;
|
|
|
|
let vec3 = tempScope.vec3;
|
|
|
|
let mat3 = tempScope.mat3;
|
|
|
|
let mat4 = tempScope.mat4;
|
|
|
|
let quat4 = tempScope.quat4;
|
|
|
|
let TiltUtils = tempScope.TiltUtils;
|
|
|
|
let TiltVisualizer = tempScope.TiltVisualizer;
|
2011-11-10 02:09:18 -08:00
|
|
|
|
|
|
|
|
|
|
|
const DEFAULT_HTML = "data:text/html," +
|
|
|
|
"<DOCTYPE html>" +
|
|
|
|
"<html>" +
|
|
|
|
"<head>" +
|
|
|
|
"<title>Three Laws</title>" +
|
|
|
|
"</head>" +
|
|
|
|
"<body>" +
|
2012-01-19 07:48:22 -08:00
|
|
|
"<div id='first-law'>" +
|
2011-11-10 02:09:18 -08:00
|
|
|
"A robot may not injure a human being or, through inaction, allow a" +
|
|
|
|
"human being to come to harm." +
|
|
|
|
"</div>" +
|
|
|
|
"<div>" +
|
|
|
|
"A robot must obey the orders given to it by human beings, except" +
|
|
|
|
"where such orders would conflict with the First Law." +
|
|
|
|
"</div>" +
|
|
|
|
"<div>" +
|
|
|
|
"A robot must protect its own existence as long as such protection" +
|
|
|
|
"does not conflict with the First or Second Laws." +
|
|
|
|
"</div>" +
|
|
|
|
"<body>" +
|
|
|
|
"</html>";
|
|
|
|
|
|
|
|
const INSPECTOR_OPENED = InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED;
|
|
|
|
const INSPECTOR_CLOSED = InspectorUI.INSPECTOR_NOTIFICATIONS.CLOSED;
|
|
|
|
|
2012-01-19 07:48:22 -08:00
|
|
|
const INITIALIZING = Tilt.NOTIFICATIONS.INITIALIZING;
|
|
|
|
const INITIALIZED = Tilt.NOTIFICATIONS.INITIALIZED;
|
|
|
|
const DESTROYING = Tilt.NOTIFICATIONS.DESTROYING;
|
|
|
|
const BEFORE_DESTROYED = Tilt.NOTIFICATIONS.BEFORE_DESTROYED;
|
|
|
|
const DESTROYED = Tilt.NOTIFICATIONS.DESTROYED;
|
|
|
|
const SHOWN = Tilt.NOTIFICATIONS.SHOWN;
|
|
|
|
const HIDDEN = Tilt.NOTIFICATIONS.HIDDEN;
|
|
|
|
const HIGHLIGHTING = Tilt.NOTIFICATIONS.HIGHLIGHTING;
|
|
|
|
const UNHIGHLIGHTING = Tilt.NOTIFICATIONS.UNHIGHLIGHTING;
|
|
|
|
const NODE_REMOVED = Tilt.NOTIFICATIONS.NODE_REMOVED;
|
2011-11-10 02:09:18 -08:00
|
|
|
|
|
|
|
const TILT_ENABLED = Services.prefs.getBoolPref("devtools.tilt.enabled");
|
|
|
|
const INSP_ENABLED = Services.prefs.getBoolPref("devtools.inspector.enabled");
|
|
|
|
|
|
|
|
|
|
|
|
function isTiltEnabled() {
|
|
|
|
return TILT_ENABLED && INSP_ENABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isWebGLSupported() {
|
2011-12-15 04:42:25 -08:00
|
|
|
return TiltGL.isWebGLSupported() && TiltGL.create3DContext(createCanvas());
|
2011-11-10 02:09:18 -08:00
|
|
|
}
|
|
|
|
|
2011-12-21 04:39:29 -08:00
|
|
|
function isApprox(num1, num2, delta) {
|
|
|
|
if (Math.abs(num1 - num2) > (delta || EPSILON)) {
|
|
|
|
info("isApprox expected " + num1 + ", got " + num2 + " instead.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-10 02:09:18 -08:00
|
|
|
}
|
|
|
|
|
2011-12-21 04:39:29 -08:00
|
|
|
function isApproxVec(vec1, vec2, delta) {
|
|
|
|
vec1 = Array.prototype.slice.call(vec1);
|
|
|
|
vec2 = Array.prototype.slice.call(vec2);
|
|
|
|
|
2011-11-10 02:09:18 -08:00
|
|
|
if (vec1.length !== vec2.length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (let i = 0, len = vec1.length; i < len; i++) {
|
2011-12-21 04:39:29 -08:00
|
|
|
if (!isApprox(vec1[i], vec2[i], delta)) {
|
|
|
|
info("isApproxVec expected [" + vec1 + "], got [" + vec2 + "] instead.");
|
2011-11-10 02:09:18 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-12-22 02:51:57 -08:00
|
|
|
function isEqualVec(vec1, vec2) {
|
2011-12-21 04:39:29 -08:00
|
|
|
vec1 = Array.prototype.slice.call(vec1);
|
|
|
|
vec2 = Array.prototype.slice.call(vec2);
|
|
|
|
|
2011-12-22 02:51:57 -08:00
|
|
|
if (vec1.length !== vec2.length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (let i = 0, len = vec1.length; i < len; i++) {
|
|
|
|
if (vec1[i] !== vec2[i]) {
|
2011-12-21 04:39:29 -08:00
|
|
|
info("isEqualVec expected [" + vec1 + "], got [" + vec2 + "] instead.");
|
2011-12-22 02:51:57 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-10 02:09:18 -08:00
|
|
|
|
|
|
|
function createCanvas() {
|
2011-12-15 04:42:25 -08:00
|
|
|
return document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
2011-11-10 02:09:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function createTab(callback, location) {
|
|
|
|
let tab = gBrowser.selectedTab = gBrowser.addTab();
|
|
|
|
|
|
|
|
gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
|
|
|
|
gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
|
|
|
|
callback(tab);
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
gBrowser.selectedBrowser.contentWindow.location = location || DEFAULT_HTML;
|
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function createTilt(callbacks, close) {
|
2012-01-19 07:48:22 -08:00
|
|
|
Services.prefs.setBoolPref("webgl.verbose", true);
|
|
|
|
|
2011-11-10 02:09:18 -08:00
|
|
|
Services.obs.addObserver(onInspectorOpen, INSPECTOR_OPENED, false);
|
|
|
|
InspectorUI.toggleInspectorUI();
|
|
|
|
|
|
|
|
function onInspectorOpen() {
|
|
|
|
Services.obs.removeObserver(onInspectorOpen, INSPECTOR_OPENED);
|
|
|
|
|
|
|
|
executeSoon(function() {
|
|
|
|
if ("function" === typeof callbacks.onInspectorOpen) {
|
|
|
|
callbacks.onInspectorOpen();
|
|
|
|
}
|
2012-01-19 07:48:22 -08:00
|
|
|
Services.obs.addObserver(onTiltOpen, INITIALIZING, false);
|
2011-11-10 02:09:18 -08:00
|
|
|
Tilt.initialize();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTiltOpen() {
|
2012-01-19 07:48:22 -08:00
|
|
|
Services.obs.removeObserver(onTiltOpen, INITIALIZING);
|
2011-11-10 02:09:18 -08:00
|
|
|
|
|
|
|
executeSoon(function() {
|
|
|
|
if ("function" === typeof callbacks.onTiltOpen) {
|
2011-12-15 04:42:25 -08:00
|
|
|
callbacks.onTiltOpen(Tilt.visualizers[Tilt.currentWindowId]);
|
2011-11-10 02:09:18 -08:00
|
|
|
}
|
|
|
|
if (close) {
|
2012-01-19 07:48:22 -08:00
|
|
|
Services.obs.addObserver(onTiltClose, DESTROYED, false);
|
2011-11-10 02:09:18 -08:00
|
|
|
Tilt.destroy(Tilt.currentWindowId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTiltClose() {
|
2012-01-19 07:48:22 -08:00
|
|
|
Services.obs.removeObserver(onTiltClose, DESTROYED);
|
2011-11-10 02:09:18 -08:00
|
|
|
|
|
|
|
executeSoon(function() {
|
|
|
|
if ("function" === typeof callbacks.onTiltClose) {
|
|
|
|
callbacks.onTiltClose();
|
|
|
|
}
|
|
|
|
if (close) {
|
|
|
|
Services.obs.addObserver(onInspectorClose, INSPECTOR_CLOSED, false);
|
|
|
|
InspectorUI.closeInspectorUI();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function onInspectorClose() {
|
|
|
|
Services.obs.removeObserver(onInspectorClose, INSPECTOR_CLOSED);
|
|
|
|
|
|
|
|
executeSoon(function() {
|
|
|
|
if ("function" === typeof callbacks.onInspectorClose) {
|
|
|
|
callbacks.onInspectorClose();
|
|
|
|
}
|
|
|
|
if ("function" === typeof callbacks.onEnd) {
|
|
|
|
callbacks.onEnd();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|