Bug 710750 - ESC key should exit Tilt (page inspector 3D); r=rcampbell
authorVictor Porof <vporof@mozilla.com>
Thu, 15 Dec 2011 14:42:25 +0200
changeset 83136 c2cb5d6b8cb91e3516728fe8dd53f98edf66f925
parent 83032 d79c91d63dd8b131434729fa30dc5ae83390a77f
child 83137 de1cf77a8d6b30cd16540a106b03a572db7728d0
push id21737
push usertim.taubert@gmx.de
push dateWed, 21 Dec 2011 09:40:56 +0000
treeherdermozilla-central@cd921d073b22 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrcampbell
bugs710750
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 710750 - ESC key should exit Tilt (page inspector 3D); r=rcampbell
browser/devtools/tilt/TiltVisualizer.jsm
browser/devtools/tilt/test/Makefile.in
browser/devtools/tilt/test/browser_tilt_05_destruction-esc.js
browser/devtools/tilt/test/browser_tilt_visualizer.js
browser/devtools/tilt/test/head.js
--- a/browser/devtools/tilt/TiltVisualizer.jsm
+++ b/browser/devtools/tilt/TiltVisualizer.jsm
@@ -101,17 +101,17 @@ function TiltVisualizer(aProperties)
   /**
    * The canvas element used for rendering the visualization.
    */
   this.canvas = TiltUtils.DOM.initCanvas(aProperties.parentNode, {
     focusable: true,
     append: true
   });
 
-  /*
+  /**
    * Visualization logic and drawing loop.
    */
   this.presenter = new TiltVisualizer.Presenter(this.canvas,
     aProperties.contentWindow,
     aProperties.requestAnimationFrame,
     aProperties.inspectorUI,
     aProperties.onError || null,
     aProperties.onLoad || null);
@@ -180,16 +180,17 @@ TiltVisualizer.prototype = {
  */
 TiltVisualizer.Presenter = function TV_Presenter(
   aCanvas, aContentWindow, aRequestAnimationFrame, aInspectorUI,
   onError, onLoad)
 {
   this.canvas = aCanvas;
   this.contentWindow = aContentWindow;
   this.inspectorUI = aInspectorUI;
+  this.tiltUI = aInspectorUI.chromeWin.Tilt;
 
   /**
    * Create the renderer, containing useful functions for easy drawing.
    */
   this.renderer = new TiltGL.Renderer(aCanvas, onError, onLoad);
 
   /**
    * A custom shader used for drawing the visualization mesh.
@@ -995,16 +996,20 @@ TiltVisualizer.Controller.prototype = {
   onKeyUp: function TVC_onKeyUp(e)
   {
     let code = e.keyCode || e.which;
 
     if (code >= e.DOM_VK_LEFT && code <= e.DOM_VK_DOWN) {
       e.preventDefault();
       e.stopPropagation();
     }
+    if (code === e.DOM_VK_ESCAPE) {
+      this.presenter.tiltUI.destroy(this.presenter.tiltUI.currentWindowId);
+    }
+
     this.arcball.keyUp(code);
   },
 
   /**
    * Called when the content window of the current browser is resized.
    */
   onResize: function TVC_onResize(e)
   {
--- a/browser/devtools/tilt/test/Makefile.in
+++ b/browser/devtools/tilt/test/Makefile.in
@@ -45,16 +45,17 @@ include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _BROWSER_TEST_FILES = \
 	head.js \
 	browser_tilt_01_lazy_getter.js \
 	browser_tilt_02_notifications.js \
 	browser_tilt_03_tab_switch.js \
 	browser_tilt_04_initialization.js \
+	browser_tilt_05_destruction-esc.js \
 	browser_tilt_05_destruction.js \
 	browser_tilt_arcball.js \
 	browser_tilt_gl01.js \
 	browser_tilt_gl02.js \
 	browser_tilt_gl03.js \
 	browser_tilt_gl04.js \
 	browser_tilt_gl05.js \
 	browser_tilt_gl06.js \
new file mode 100644
--- /dev/null
+++ b/browser/devtools/tilt/test/browser_tilt_05_destruction-esc.js
@@ -0,0 +1,41 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*global ok, is, info, waitForExplicitFinish, finish, gBrowser */
+/*global isTiltEnabled, isWebGLSupported, createTab, createTilt */
+/*global Services, EventUtils, Tilt, TiltUtils, InspectorUI, TILT_DESTROYED */
+"use strict";
+
+function test() {
+  if (!isTiltEnabled()) {
+    info("Skipping destruction test because Tilt isn't enabled.");
+    return;
+  }
+  if (!isWebGLSupported()) {
+    info("Skipping destruction test because WebGL isn't supported.");
+    return;
+  }
+
+  waitForExplicitFinish();
+
+  createTab(function() {
+    createTilt({
+      onTiltOpen: function()
+      {
+        Services.obs.addObserver(cleanup, TILT_DESTROYED, false);
+        EventUtils.sendKey("ESCAPE");
+      }
+    });
+  });
+}
+
+function cleanup() {
+  let id = TiltUtils.getWindowId(gBrowser.selectedBrowser.contentWindow);
+
+  is(Tilt.visualizers[id], null,
+    "The current instance of the visualizer wasn't destroyed properly.");
+
+  Services.obs.removeObserver(cleanup, TILT_DESTROYED);
+  gBrowser.removeCurrentTab();
+  finish();
+}
--- a/browser/devtools/tilt/test/browser_tilt_visualizer.js
+++ b/browser/devtools/tilt/test/browser_tilt_visualizer.js
@@ -17,16 +17,17 @@ function test() {
 
   let webGLError = false;
   let webGLLoad = false;
 
   let visualizer = new TiltVisualizer({
     parentNode: gBrowser.selectedBrowser.parentNode,
     contentWindow: gBrowser.selectedBrowser.contentWindow,
     requestAnimationFrame: window.mozRequestAnimationFrame,
+    inspectorUI: window.InspectorUI,
 
     onError: function onWebGLError()
     {
       webGLError = true;
     },
 
     onLoad: function onWebGLLoad()
     {
--- a/browser/devtools/tilt/test/head.js
+++ b/browser/devtools/tilt/test/head.js
@@ -45,19 +45,17 @@ const TILT_ENABLED = Services.prefs.getB
 const INSP_ENABLED = Services.prefs.getBoolPref("devtools.inspector.enabled");
 
 
 function isTiltEnabled() {
   return TILT_ENABLED && INSP_ENABLED;
 }
 
 function isWebGLSupported() {
-  return TiltGL.isWebGLSupported() &&
-         TiltGL.create3DContext(
-           document.createElementNS("http://www.w3.org/1999/xhtml", "canvas"));
+  return TiltGL.isWebGLSupported() && TiltGL.create3DContext(createCanvas());
 }
 
 function isApprox(num1, num2) {
   return Math.abs(num1 - num2) < EPSILON;
 }
 
 function isApproxVec(vec1, vec2) {
   if (vec1.length !== vec2.length) {
@@ -68,19 +66,17 @@ function isApproxVec(vec1, vec2) {
       return false;
     }
   }
   return true;
 }
 
 
 function createCanvas() {
-  return gBrowser.parentNode
-                 .ownerDocument
-                 .createElementNS("http://www.w3.org/1999/xhtml", "canvas");
+  return document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
 }
 
 
 function createTab(callback, location) {
   let tab = gBrowser.selectedTab = gBrowser.addTab();
 
   gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
     gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
@@ -108,17 +104,17 @@ function createTilt(callbacks, close) {
     });
   }
 
   function onTiltOpen() {
     Services.obs.removeObserver(onTiltOpen, TILT_INITIALIZED);
 
     executeSoon(function() {
       if ("function" === typeof callbacks.onTiltOpen) {
-        callbacks.onTiltOpen();
+        callbacks.onTiltOpen(Tilt.visualizers[Tilt.currentWindowId]);
       }
       if (close) {
         Services.obs.addObserver(onTiltClose, TILT_DESTROYED, false);
         Tilt.destroy(Tilt.currentWindowId);
       }
     });
   }