Permalink
Browse files

Initial structure and functionality of FireAccess

  • Loading branch information...
0 parents commit c13a5e820aac6cc7f3429f4b5448cc660ffa5b68 @SebastianZ committed Oct 17, 2012
@@ -0,0 +1,3 @@
+# DO NOT MERGE INTO TRUNK
+RELEASE=.1
+VERSION=0
@@ -0,0 +1,148 @@
+/* See license.txt for terms of usage */
+
+// ********************************************************************************************* //
+// XPCOM
+
+var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+// ********************************************************************************************* //
+// Constants
+
+// Extension installation path. Set within startup callback.
+var installPath;
+
+// ********************************************************************************************* //
+// Firefox Bootstrap API
+
+function install(data, reason) {}
+function uninstall(data, reason) {}
+
+function startup(data, reason)
+{
+ // Remember so, we can use later within firebugStartup callback.
+ installPath = data.installPath;
+
+ // Firebug extension start-up callback. Since extension load order isn't guaranteed
+ // the code needs to be ready for two alternatives:
+ // 1) Firebug is already loaded - good, let's just execute firebugStartup() callback
+ // that will ensure proper Firebug related initialization for this extension.
+ // 2) Firebug is not loaded yet - as soon as Firebug is loaded it'll execute this
+ // method automatially.
+ firebugStartup();
+}
+
+function shutdown(data, reason)
+{
+ firebugShutdown();
+}
+
+function isFirebugLoaded()
+{
+ try
+ {
+ // Import Firebug modules into this scope. It fails if Firebug isn't loaded yet.
+ Cu.import("resource://firebug/loader.js");
+ Cu.import("resource://firebug/prefLoader.js");
+
+ return true;
+ }
+ catch (e)
+ {
+ }
+
+ return true;
+}
+
+// ********************************************************************************************* //
+// Firebug Bootstrap API
+
+/**
+ * Executed by Firebug framework when Firebug is started. Since the order of Firebug
+ * and its bootstrapped extensions is not guaranteed this function is executed twice.
+ * 1) When Firebug is loaded
+ * 2) When this extension is loaded
+ */
+function firebugStartup()
+{
+ // If Firebu isn't loade just bail out, Firebug will execute this method
+ // as soon as it loads.
+ if (!isFirebugLoaded())
+ return;
+
+ FirebugLoader.registerBootstrapScope(this);
+
+ // Load default preferences
+ PrefLoader.loadDefaultPrefs(installPath, "prefs.js");
+}
+
+/**
+ * Executed by Firefox when this extension shutdowns.
+ */
+function firebugShutdown()
+{
+ try
+ {
+ FirebugLoader.unregisterBootstrapScope(this);
+ }
+ catch (e)
+ {
+ Cu.reportError(e);
+ }
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+/**
+ * Executed by Firebug framework for every browser window. Use this function to append
+ * any new elements into the browser window (browser.xul). Don't forget to remove
+ * these elements in topWindowUnload.
+ *
+ * @param {Window} win The browser window
+ */
+function topWindowLoad(win)
+{
+ // TODO: overlay global browser window
+}
+
+/**
+ * Executed by Firebug framework when this extension
+ * @param {Object} win
+ */
+function topWindowUnload(win)
+{
+ // TODO: remove global browser window overlays
+}
+
+/**
+ * Entire Firebug UI is running inside an iframe (firebugFrame.xul). This function
+ * is executed by Firebug framework when the frame is loaded. This happens when
+ * the user requires Firebug for the first time (doesn't have to happen during the
+ * Firefox session at all)
+ *
+ * @param {Window} win The Firebug window
+ */
+function firebugFrameLoad(Firebug)
+{
+ // Register trace listener the customizes trace logs coming from this extension
+ // * fireAccess; is unique prefix of all messages that should be customized.
+ // * DBG_FIREACCESS is a class name with style defined in the specified stylesheet.
+ Firebug.registerTracePrefix("fireAccess;", "DBG_FIREACCESS", true,
+ "chrome://fireaccess/skin/fireaccess.css");
+
+ // The registration process will automatically look for 'main' module and load it.
+ // The is the same what happens in a XUL overlay applied on:
+ // chrome://firebug/content/firebugOverlay.xul
+ var config = {id: "fireaccess@janodvarko.cz"};
+ Firebug.registerExtension("fireaccess", config);
+}
+
+function firebugFrameUnload(Firebug)
+{
+ if (!Firebug.isInitialized)
+ return;
+
+ Firebug.unregisterExtension("fireaccess");
+ Firebug.unregisterTracePrefix("fireAccess;");
+}
+
+// ********************************************************************************************* //
@@ -0,0 +1,44 @@
+<?xml version="1.0" ?>
+
+<!-- Run ant in the extension's directory and look for: fireaccess-0.5.1.xpi -->
+<project name="fireaccess" basedir="." default="build">
+
+ <!-- Properties -->
+ <property file="ant.properties"/>
+ <property name="build.dir" value="./release"/>
+ <property name="file-name" value="fireaccess-${VERSION}${RELEASE}.xpi"/>
+
+ <!-- Clean -->
+ <target name="clean">
+ <delete dir="${build.dir}"/>
+ </target>
+
+ <!-- Build -->
+ <target name="build" depends="clean">
+
+ <!-- Copy files -->
+ <copy todir="${build.dir}">
+ <fileset dir=".">
+ <include name="**/*.js"/>
+ <include name="**/*.xul"/>
+ <include name="**/*.properties"/>
+ <include name="**/*.css"/>
+ <include name="**/*.manifest"/>
+ <include name="**/*.rdf"/>
+ <include name="**/*.txt"/>
+ </fileset>
+ </copy>
+
+ <!-- Copy install.rdf with updated release version info -->
+ <replace file="${build.dir}/install.rdf" propertyFile="ant.properties">
+ <replacefilter token="@VERSION@" property="VERSION"/>
+ <replacefilter token="@RELEASE@" property="RELEASE"/>
+ </replace>
+
+ <!-- Compress files (ZIP) -->
+ <zip destfile="${file-name}" basedir="${build.dir}" update="true" />
+
+ <echo message="FireAccess version: ${VERSION}${RELEASE} created!"/>
+ </target>
+
+</project>
@@ -0,0 +1,3 @@
+content fireaccess chrome/content/
+skin fireaccess classic/1.0 chrome/skin/classic/
+locale fireaccess en-US chrome/locale/en-US/
@@ -0,0 +1,68 @@
+/* See license.txt for terms of usage */
+
+define([
+ "firebug/lib/object",
+ "firebug/lib/trace",
+],
+function(Obj, FBTrace) {
+
+// ********************************************************************************************* //
+// Custom Module Implementation
+
+Firebug.HTMLAccessibilityModule = Obj.extend(Firebug.Module,
+{
+ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+ // Initialization
+
+ initialize: function(owner)
+ {
+ Firebug.Module.initialize.apply(this, arguments);
+
+ // TODO: Module initialization (there is one module instance per browser window)
+
+ if (FBTrace.DBG_FIREACCESS)
+ FBTrace.sysout("fireAccess; HTMLAccessibilityModule.initialize");
+ },
+
+ shutdown: function()
+ {
+ Firebug.Module.shutdown.apply(this, arguments);
+
+ if (FBTrace.DBG_FIREACCESS)
+ FBTrace.sysout("fireAccess; HTMLAccessibilityModule.shutdown");
+ },
+
+ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+ // Visual and audio accessibility
+ calculateContrast: function(r1, g1, b1, r2, g2, b2)
+ {
+ function relativeLuminance(r, g, b)
+ {
+ r /= 255;
+ g /= 255;
+ b /= 255;
+ var rl = r <= 0.03928 ? r / 12.92 : Math.pow((r+0.055) / 1.055, 2.4);
+ var gl = g <= 0.03928 ? g / 12.92 : Math.pow((g+0.055) / 1.055, 2.4);
+ var bl = b <= 0.03928 ? b / 12.92 : Math.pow((b+0.055) / 1.055, 2.4);
+
+ return rl * 0.2126 + gl * 0.7152 + bl * 0.0722;
+ }
+
+ var l1 = relativeLuminance(r1, g1, b1);
+ var l2 = relativeLuminance(r2, g2, b2);
+ var lighterLuminance = l1 > l2 ? l1 : l2;
+ var darkerLuminance = l1 < l2 ? l1 : l2;
+
+ return (lighterLuminance + 0.05) / (darkerLuminance + 0.05);
+ }
+});
+
+// ********************************************************************************************* //
+// Registration
+
+Firebug.registerModule(Firebug.HTMLAccessibilityModule);
+
+return Firebug.HTMLAccessibilityModule;
+
+// ********************************************************************************************* //
+});
Oops, something went wrong.

0 comments on commit c13a5e8

Please sign in to comment.