From 3fd66836e6c5fbd25dd8f90dd50914cabeb7a9a7 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sat, 15 Oct 2011 22:55:56 +0200 Subject: [PATCH] introduce touch events (or try that), start refactoring toolbar; also KILL THE XUL APP, this is an add-on only now. --- Makefile.in | 31 ++- .../aboutMandelbrot.js => aboutMandelbrot.js | 0 {extension => content}/fxOverlay.xul | 0 .../content => content}/mandelbrot.js | 194 ++++++--------- .../content => content}/mandelbrot.xul | 65 ++--- {extension => content}/mobileOverlay.xul | 0 {extension => content}/smOverlay.xul | 0 extension/install.rdf => install.rdf | 9 +- jar.mn | 26 +- .../en-US/mandelbrot-overlay.dtd | 0 .../locales => locales}/en-US/mandelbrot.dtd | 4 - .../en-US/mandelbrot.properties | 0 mandelbrot | 79 ------ .../defaults/preferences/prefs.js => prefs.js | 0 .../skin => skin}/classic/mandelbrot.css | 0 .../classic/mandelbrotIcon16.png | Bin .../classic/mandelbrotIcon32.png | Bin .../skin => skin}/classic/mobileUI.css | 0 .../brand.properties => tests/Makefile.in | 24 +- xulapp/application.ini | 51 ---- xulapp/chrome/branding.manifest | 1 - .../chrome/branding/locales/en-US/brand.dtd | 46 ---- .../chrome/icons/default/mandelbrotWindow.ico | Bin 766 -> 0 bytes .../chrome/icons/default/mandelbrotWindow.png | Bin 648 -> 0 bytes xulapp/chrome/mandelbrot.manifest | 3 - .../mandelbrot/content/mandelbrot-tab.xul | 226 ------------------ 26 files changed, 153 insertions(+), 606 deletions(-) rename extension/aboutMandelbrot.js => aboutMandelbrot.js (100%) rename {extension => content}/fxOverlay.xul (100%) rename {xulapp/chrome/mandelbrot/content => content}/mandelbrot.js (85%) rename {xulapp/chrome/mandelbrot/content => content}/mandelbrot.xul (86%) rename {extension => content}/mobileOverlay.xul (100%) rename {extension => content}/smOverlay.xul (100%) rename extension/install.rdf => install.rdf (86%) rename {xulapp/chrome/mandelbrot/locales => locales}/en-US/mandelbrot-overlay.dtd (100%) rename {xulapp/chrome/mandelbrot/locales => locales}/en-US/mandelbrot.dtd (95%) rename {xulapp/chrome/mandelbrot/locales => locales}/en-US/mandelbrot.properties (100%) delete mode 100755 mandelbrot rename xulapp/defaults/preferences/prefs.js => prefs.js (100%) rename {xulapp/chrome/mandelbrot/skin => skin}/classic/mandelbrot.css (100%) rename {xulapp/chrome/mandelbrot/skin => skin}/classic/mandelbrotIcon16.png (100%) rename {xulapp/chrome/mandelbrot/skin => skin}/classic/mandelbrotIcon32.png (100%) rename {xulapp/chrome/mandelbrot/skin => skin}/classic/mobileUI.css (100%) rename xulapp/chrome/branding/locales/en-US/brand.properties => tests/Makefile.in (79%) delete mode 100644 xulapp/application.ini delete mode 100644 xulapp/chrome/branding.manifest delete mode 100644 xulapp/chrome/branding/locales/en-US/brand.dtd delete mode 100755 xulapp/chrome/icons/default/mandelbrotWindow.ico delete mode 100644 xulapp/chrome/icons/default/mandelbrotWindow.png delete mode 100644 xulapp/chrome/mandelbrot.manifest delete mode 100644 xulapp/chrome/mandelbrot/content/mandelbrot-tab.xul diff --git a/Makefile.in b/Makefile.in index 11f742e..d7428b5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -14,12 +14,12 @@ # The Original Code is KaiRo-Mandelbrot. # # The Initial Developer of the Original Code is -# Robert Kaiser. -# Portions created by the Initial Developer are Copyright (C) 2010 +# Robert Kaiser . +# Portions created by the Initial Developer are Copyright (C) 2010-2011 # the Initial Developer. All Rights Reserved. # # Contributor(s): -# Robert Kaiser +# Robert Kaiser (original author) # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or @@ -43,9 +43,13 @@ relativesrcdir = extensions/mandelbrot include $(DEPTH)/config/autoconf.mk -MODULE = mandelbrot +ifdef ENABLE_TESTS +PARALLEL_DIRS += tests +endif + +MODULE = mandelbrot -EXTENSION_VERSION = 4.0b2 +EXTENSION_VERSION = 4.0b3 XPI_NAME = mandelbrot USE_EXTENSION_MANIFEST = 1 @@ -54,12 +58,17 @@ NO_JS_MANIFEST = 1 INSTALL_EXTENSION_ID = mandelbrot@kairo.at XPI_PKGNAME = mandelbrot-$(EXTENSION_VERSION) -DIST_FILES = extension/install.rdf +DIST_FILES = \ + install.rdf \ + $(NULL) -EXTRA_COMPONENTS = extension/aboutMandelbrot.js +PREF_JS_EXPORTS = \ + $(srcdir)/prefs.js \ + $(NULL) -# this interferes with e.g. Firefox prefs -#PREF_JS_EXPORTS = $(srcdir)/xulapp/defaults/preferences/prefs.js +EXTRA_COMPONENTS = \ + aboutMandelbrot.js \ + $(NULL) # include config.mk before using the AB_CD var include $(topsrcdir)/config/config.mk @@ -70,10 +79,6 @@ DEFINES += -DAB_CD=en-US \ include $(topsrcdir)/config/rules.mk -export:: - $(NSINSTALL) -D $(FINAL_TARGET)/chrome/icons/default - $(INSTALL) $(srcdir)/xulapp/chrome/icons/default/mandelbrotWindow* $(FINAL_TARGET)/chrome/icons/default - ifdef MOZ_OMNIJAR ABS_DIST = $(call core_abspath,$(DIST)/bin) diff --git a/extension/aboutMandelbrot.js b/aboutMandelbrot.js similarity index 100% rename from extension/aboutMandelbrot.js rename to aboutMandelbrot.js diff --git a/extension/fxOverlay.xul b/content/fxOverlay.xul similarity index 100% rename from extension/fxOverlay.xul rename to content/fxOverlay.xul diff --git a/xulapp/chrome/mandelbrot/content/mandelbrot.js b/content/mandelbrot.js similarity index 85% rename from xulapp/chrome/mandelbrot/content/mandelbrot.js rename to content/mandelbrot.js index 1ccebbe..68cdffe 100644 --- a/xulapp/chrome/mandelbrot/content/mandelbrot.js +++ b/content/mandelbrot.js @@ -51,6 +51,16 @@ function Startup() { updatePaletteMenu(); gMbrotBundle = document.getElementById("mbrotBundle"); document.getElementById("statusLabel").value = gMbrotBundle.getString("statusEmpty"); + + let img = document.getElementById("mbrotImage"); + img.addEventListener("mouseup", imgEvHandler, false); + img.addEventListener("mousedown", imgEvHandler, false); + img.addEventListener("mousemove", imgEvHandler, false); + img.addEventListener("touchstart", imgEvHandler, false); + img.addEventListener("touchend", imgEvHandler, false); + img.addEventListener("touchcancel", imgEvHandler, false); + img.addEventListener("touchleave", imgEvHandler, false); + img.addEventListener("touchmove", imgEvHandler, false); } function getAdjustPref(prefname) { @@ -451,60 +461,65 @@ function drawPoint(context, img_x, img_y, C, iterMax, algorithm) { var zoomstart; var imgBackup; -function mouseevent(etype, event) { - let canvas = document.getElementById("mbrotImage"); - let context = canvas.getContext("2d"); - switch (etype) { - case 'down': - if (event.button == 0) { - // left button - start dragzoom - zoomstart = {x: event.clientX - canvas.offsetLeft, - y: event.clientY - canvas.offsetTop}; - imgBackup = context.getImageData(0, 0, canvas.width, canvas.height); - } - break; - case 'up': - if (event.button == 0 && zoomstart) { - context.putImageData(imgBackup, 0, 0); - let zoomend = {x: event.clientX - canvas.offsetLeft, - y: event.clientY - canvas.offsetTop}; - - // make sure zoomend is bigger than zoomstart - if ((zoomend.x == zoomstart.x) || (zoomend.y == zoomstart.y)) { - // cannot zoom what has no area, discard it - zoomstart = undefined; - return; +let imgEvHandler = { + handleEvent: function(aEvent) { + let canvas = document.getElementById("mbrotImage"); + let context = canvas.getContext("2d"); + switch (aEvent.type) { + case 'mousedown': + case 'touchstart': + if (aEvent.button == 0) { + // left button - start dragzoom + zoomstart = {x: aEvent.clientX - canvas.offsetLeft, + y: aEvent.clientY - canvas.offsetTop}; + imgBackup = context.getImageData(0, 0, canvas.width, canvas.height); + } + break; + case 'mouseup': + case 'touchend': + if (aEvent.button == 0 && zoomstart) { + context.putImageData(imgBackup, 0, 0); + let zoomend = {x: aEvent.clientX - canvas.offsetLeft, + y: aEvent.clientY - canvas.offsetTop}; + + // make sure zoomend is bigger than zoomstart + if ((zoomend.x == zoomstart.x) || (zoomend.y == zoomstart.y)) { + // cannot zoom what has no area, discard it + zoomstart = undefined; + return; + } + if (zoomend.x < zoomstart.x) + [zoomend.x, zoomstart.x] = [zoomstart.x, zoomend.x]; + if (zoomend.y < zoomstart.y) + [zoomend.y, zoomstart.y] = [zoomstart.y, zoomend.y]; + + // determine new "coordinates" + let CWidth = gCurrentImageData.C_max.r - gCurrentImageData.C_min.r; + let CHeight = gCurrentImageData.C_max.i - gCurrentImageData.C_min.i; + let newC_min = new complex( + gCurrentImageData.C_min.r + zoomstart.x / gCurrentImageData.iWidth * CWidth, + gCurrentImageData.C_min.i + zoomstart.y / gCurrentImageData.iHeight * CHeight); + let newC_max = new complex( + gCurrentImageData.C_min.r + zoomend.x / gCurrentImageData.iWidth * CWidth, + gCurrentImageData.C_min.i + zoomend.y / gCurrentImageData.iHeight * CHeight); + + adjustCoordsAndDraw(newC_min, newC_max); + } + zoomstart = undefined; + break; + case 'mousemove': + case 'touchmove': + if (aEvent.button == 0 && zoomstart) { + context.putImageData(imgBackup, 0, 0); + context.strokeStyle = "rgb(255,255,31)"; + context.strokeRect(zoomstart.x, zoomstart.y, + aEvent.clientX - canvas.offsetLeft - zoomstart.x, + aEvent.clientY - canvas.offsetTop - zoomstart.y); } - if (zoomend.x < zoomstart.x) - [zoomend.x, zoomstart.x] = [zoomstart.x, zoomend.x]; - if (zoomend.y < zoomstart.y) - [zoomend.y, zoomstart.y] = [zoomstart.y, zoomend.y]; - - // determine new "coordinates" - let CWidth = gCurrentImageData.C_max.r - gCurrentImageData.C_min.r; - let CHeight = gCurrentImageData.C_max.i - gCurrentImageData.C_min.i; - let newC_min = new complex( - gCurrentImageData.C_min.r + zoomstart.x / gCurrentImageData.iWidth * CWidth, - gCurrentImageData.C_min.i + zoomstart.y / gCurrentImageData.iHeight * CHeight); - let newC_max = new complex( - gCurrentImageData.C_min.r + zoomend.x / gCurrentImageData.iWidth * CWidth, - gCurrentImageData.C_min.i + zoomend.y / gCurrentImageData.iHeight * CHeight); - - adjustCoordsAndDraw(newC_min, newC_max); - } - zoomstart = undefined; break; - case 'move': - if (event.button == 0 && zoomstart) { - context.putImageData(imgBackup, 0, 0); - context.strokeStyle = "rgb(255,255,31)"; - context.strokeRect(zoomstart.x, zoomstart.y, - event.clientX - canvas.offsetLeft - zoomstart.x, - event.clientY - canvas.offsetTop - zoomstart.y); - } - break; + } } -} +}; function saveImage() { const nsIFilePicker = Components.interfaces.nsIFilePicker; @@ -760,29 +775,6 @@ function setAlgorithm(algoID) { gPref.setCharPref("mandelbrot.use_algorithm", algoID); } -function addonsManager(aPane) { - let theEM = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator) - .getMostRecentWindow("Extension:Manager"); - if (theEM) { - theEM.focus(); - if (aPane) - theEM.showView(aPane); - return; - } - - const EMURL = "chrome://mozapps/content/extensions/extensions.xul"; - const EMFEATURES = "all,dialog=no"; - if (aPane) - window.openDialog(EMURL, "", EMFEATURES, aPane); - else - window.openDialog(EMURL, "", EMFEATURES); -} - -function errorConsole() { - toOpenWindowByType("global:console", "chrome://global/content/console.xul"); -} - function initImgSettings() { // Get values from prefs. for each (let coord in ["Cr", "Ci"]) { @@ -884,8 +876,9 @@ function recalcCoord(coord, target) { let othercoord = (coord == "Ci") ? "Cr" : "Ci"; let owndim = (coord == "Ci") ? "height" : "width"; let otherdim = (coord == "Ci") ? "width" : "height"; + let myscale; if (target == "scale") { - var myscale = + myscale = parseFloat(document.getElementById("is_" + coord + "_max").value) - parseFloat(document.getElementById("is_" + coord + "_min").value); document.getElementById("is_" + coord + "_scale").value = roundCoord(myscale); @@ -895,7 +888,7 @@ function recalcCoord(coord, target) { parseFloat(document.getElementById("is_" + coord + "_min").value) + parseFloat(document.getElementById("is_" + coord + "_scale").value); document.getElementById("is_" + coord + "_max").value = roundCoord(mymax); - var myscale = document.getElementById("is_" + coord + "_scale").value; + myscale = document.getElementById("is_" + coord + "_scale").value; } if (document.getElementById("is_syncProp").checked) { let otherscale = myscale * @@ -943,52 +936,3 @@ function saveCanvas(aCanvas, aDestFile) { // save the canvas data to the file persist.saveURI(source, null, null, null, null, aDestFile); } - -// function below is from http://developer.mozilla.org/en/docs/How_to_Quit_a_XUL_Application -function quitApp(aForceQuit) { - var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'] - .getService(Components.interfaces.nsIAppStartup); - - // eAttemptQuit will try to close each XUL window, but the XUL window can cancel the quit - // process if there is unsaved data. eForceQuit will quit no matter what. - var quitSeverity = aForceQuit ? Components.interfaces.nsIAppStartup.eForceQuit : - Components.interfaces.nsIAppStartup.eAttemptQuit; - appStartup.quit(quitSeverity); -} - -// functions below are from comm-central/suite/common/tasksOverlay.js -function toOpenWindow(aWindow) { - try { - // Try to focus the previously focused window e.g. message compose body - aWindow.document.commandDispatcher.focusedWindow.focus(); - } catch (e) { - // e.g. full-page plugin or non-XUL document; just raise the top window - aWindow.focus(); - } -} - -function toOpenWindowByType(inType, uri, features) { - // don't do several loads in parallel - if (uri in window) - return; - - var topWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator) - .getMostRecentWindow(inType); - if ( topWindow ) - toOpenWindow( topWindow ); - else { - // open the requested window, but block it until it's fully loaded - function newWindowLoaded(event) { - // make sure that this handler is called only once - window.removeEventListener("unload", newWindowLoaded, false); - window[uri].removeEventListener("load", newWindowLoaded, false); - delete window[uri]; - } - // remember the newly loading window until it's fully loaded - // or until the current window passes away - window[uri] = window.openDialog(uri, "", features || "all,dialog=no"); - window[uri].addEventListener("load", newWindowLoaded, false); - window.addEventListener("unload", newWindowLoaded, false); - } -} diff --git a/xulapp/chrome/mandelbrot/content/mandelbrot.xul b/content/mandelbrot.xul similarity index 86% rename from xulapp/chrome/mandelbrot/content/mandelbrot.xul rename to content/mandelbrot.xul index 1663d18..47f8c59 100644 --- a/xulapp/chrome/mandelbrot/content/mandelbrot.xul +++ b/content/mandelbrot.xul @@ -17,7 +17,7 @@ - - The Initial Developer of the Original Code is - Robert Kaiser . - - Portions created by the Initial Developer are Copyright (C) 2008 + - Portions created by the Initial Developer are Copyright (C) 2008-2011 - the Initial Developer. All Rights Reserved. - - Contributor(s): @@ -40,7 +40,7 @@ - %mandelOverlayDTD; @@ -49,11 +49,14 @@ %mandelbrotDTD; ]> - + + +