Last active
December 30, 2015 05:09
-
-
Save tetsuharuohzeki/7781050 to your computer and use it in GitHub Desktop.
Spatial Navigation Igniter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | |
* You can obtain one at http://mozilla.org/MPL/2.0/. | |
* The Original Code is mozilla.org code (Firefox 23) | |
* The Initial Developer of the Original Code is mozilla.org. | |
*/ | |
"use strict"; | |
const { classes: Cc, interfaces: Ci, utils: Cu } = Components; | |
Cu.import("resource://gre/modules/Services.jsm"); | |
Cu.import("resource://gre/modules/SpatialNavigation.jsm"); | |
/** | |
* | |
* bootstrapped addon interfaces | |
* | |
*/ | |
function startup(aData, aReason) { | |
// Enable Spatial Navigation preference. | |
Services.prefs.setBoolPref("snav.enabled", true); | |
let windows = Services.wm.getEnumerator("navigator:browser"); | |
while (windows.hasMoreElements()) { | |
let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow); | |
DOMEventListener.init(domWindow); | |
} | |
Services.wm.addListener(WindowListener); | |
} | |
function shutdown(aData, aReason) { | |
Services.wm.removeListener(WindowListener); | |
// if the application is shutdown time, we don't have to call these step. | |
if (aReason === APP_SHUTDOWN) { | |
return; | |
} | |
let windows = Services.wm.getEnumerator("navigator:browser"); | |
while (windows.hasMoreElements()) { | |
let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow); | |
DOMEventListener.finalize(domWindow); | |
} | |
// XXX: Set default preference for to enable Spatial Navigation. | |
Services.prefs.clearUserPref("snav.enabled"); | |
} | |
function install(aData, aReason) { | |
} | |
function uninstall(aData, aReason) { | |
} | |
// nsIWindowMediatorListener | |
let WindowListener = { | |
onOpenWindow : function (aXulWindow) { | |
let domWindow = aXulWindow.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIDOMWindow); | |
// Wait finish loading | |
domWindow.addEventListener("load", function onLoad(aEvent) { | |
domWindow.removeEventListener("load", onLoad, false); | |
DOMEventListener.init(domWindow); | |
}, false); | |
}, | |
onCloseWindow : function (aXulWindow) { | |
let domWindow = aXulWindow.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIDOMWindow); | |
DOMEventListener.finalize(domWindow); | |
}, | |
onWindowTitleChange : function (aWindow, aNewTitle) {} | |
}; | |
let DOMEventListener = { | |
init: function (aDomWindow) { | |
let windowType = aDomWindow.document. | |
documentElement.getAttribute("windowtype"); | |
// If this isn't a browser window then abort setup. | |
if (windowType !== "navigator:browser") { | |
return; | |
} | |
let gBrowser = aDomWindow.gBrowser; | |
// Enable Spatial Navigation. | |
// because TabOpen event is not fired when opens browser window. | |
let tabs = gBrowser.tabContainer.childNodes; | |
for (let tab of tabs) { | |
this.enableSpatialNavigation(tab); | |
} | |
gBrowser.tabContainer.addEventListener("TabOpen", this, false); | |
}, | |
finalize: function (aDomWindow) { | |
let gBrowser = aDomWindow.gBrowser; | |
gBrowser.tabContainer.removeEventListener("TabOpen", this, false); | |
}, | |
handleEvent: function (aEvent) { | |
switch (aEvent.type) { | |
case "TabOpen": | |
this.onTabOpen(aEvent); | |
break; | |
} | |
}, | |
onTabOpen: function (aEvent) { | |
let tab = aEvent.target; | |
this.enableSpatialNavigation(tab); | |
}, | |
enableSpatialNavigation: function (aTab) { | |
let browser = aTab.linkedBrowser; | |
SpatialNavigation.init(browser); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:em="http://www.mozilla.org/2004/em-rdf#"> | |
<Description about="urn:mozilla:install-manifest"> | |
<!-- Extension Identifier --> | |
<em:id>spatial_nav_igniter@saneyuki_s</em:id> | |
<em:version>0.1</em:version> | |
<em:type>2</em:type> | |
<em:bootstrap>true</em:bootstrap> | |
<!-- Metadata --> | |
<em:name>Spatial Navigation Igniter</em:name> | |
<em:description>This add-on ignite Spatial Navigation automatically.</em:description> | |
<em:developer>saneyuki_s</em:developer> | |
<!-- Target Application --> | |
<em:targetApplication> | |
<!-- Firefox --> | |
<Description> | |
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> | |
<em:minVersion>27.0a1</em:minVersion> | |
<em:maxVersion>*</em:maxVersion> | |
</Description> | |
</em:targetApplication> | |
</Description> | |
</RDF> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment