зеркало из https://github.com/mozilla/gecko-dev.git
Bug 736628 - Move mozKeyboard to a distinct xpcom component [r=cjones]
This commit is contained in:
Родитель
089f0ec075
Коммит
36e2d15f53
|
@ -4,75 +4,20 @@
|
|||
* 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/. */
|
||||
|
||||
dump('======================= webapi+apps.js ======================= \n');
|
||||
|
||||
'use strict';
|
||||
|
||||
dump('======================= webapi+apps.js ======================= \n');
|
||||
|
||||
let { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
Cu.import('resource://gre/modules/Geometry.jsm');
|
||||
|
||||
XPCOMUtils.defineLazyGetter(Services, 'fm', function() {
|
||||
return Cc['@mozilla.org/focus-manager;1']
|
||||
.getService(Ci.nsIFocusManager);
|
||||
});
|
||||
|
||||
(function() {
|
||||
function generateAPI(window) {
|
||||
let navigator = window.navigator;
|
||||
|
||||
XPCOMUtils.defineLazyGetter(navigator, 'mozKeyboard', function() {
|
||||
return new MozKeyboard();
|
||||
});
|
||||
};
|
||||
|
||||
let progressListener = {
|
||||
onStateChange: function onStateChange(progress, request,
|
||||
flags, status) {
|
||||
},
|
||||
|
||||
onProgressChange: function onProgressChange(progress, request,
|
||||
curSelf, maxSelf,
|
||||
curTotal, maxTotal) {
|
||||
},
|
||||
|
||||
onLocationChange: function onLocationChange(progress, request,
|
||||
locationURI, flags) {
|
||||
content.addEventListener('appwillopen', function(evt) {
|
||||
let appManager = content.wrappedJSObject.Gaia.AppManager;
|
||||
let topWindow = appManager.foregroundWindow.contentWindow;
|
||||
generateAPI(topWindow);
|
||||
});
|
||||
|
||||
generateAPI(content.wrappedJSObject);
|
||||
},
|
||||
|
||||
onStatusChange: function onStatusChange(progress, request,
|
||||
status, message) {
|
||||
},
|
||||
|
||||
onSecurityChange: function onSecurityChange(progress, request,
|
||||
state) {
|
||||
},
|
||||
|
||||
QueryInterface: function QueryInterface(aIID) {
|
||||
if (aIID.equals(Ci.nsIWebProgressListener) ||
|
||||
aIID.equals(Ci.nsISupportsWeakReference) ||
|
||||
aIID.equals(Ci.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
let flags = Ci.nsIWebProgress.NOTIFY_LOCATION;
|
||||
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebProgress);
|
||||
flags = Ci.nsIWebProgress.NOTIFY_ALL;
|
||||
webProgress.addProgressListener(progressListener, flags);
|
||||
})();
|
||||
|
||||
// MozKeyboard
|
||||
(function VirtualKeyboardManager() {
|
||||
let activeElement = null;
|
||||
|
@ -139,27 +84,6 @@ XPCOMUtils.defineLazyGetter(Services, 'fm', function() {
|
|||
});
|
||||
})();
|
||||
|
||||
|
||||
function MozKeyboard() {
|
||||
}
|
||||
|
||||
MozKeyboard.prototype = {
|
||||
sendKey: function mozKeyboardSendKey(keyCode, charCode) {
|
||||
charCode = (charCode == undefined) ? keyCode : charCode;
|
||||
|
||||
let utils = content.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils);
|
||||
['keydown', 'keypress', 'keyup'].forEach(function sendKey(type) {
|
||||
utils.sendKeyEvent(type, keyCode, charCode, null);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import('resource://gre/modules/Geometry.jsm');
|
||||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
|
||||
const ContentPanning = {
|
||||
init: function cp_init() {
|
||||
['mousedown', 'mouseup', 'mousemove'].forEach(function(type) {
|
||||
|
@ -328,7 +252,6 @@ const ContentPanning = {
|
|||
|
||||
ContentPanning.init();
|
||||
|
||||
|
||||
// Min/max velocity of kinetic panning. This is in pixels/millisecond.
|
||||
const kMinVelocity = 0.4;
|
||||
const kMaxVelocity = 6;
|
||||
|
@ -497,4 +420,3 @@ const KineticPanning = {
|
|||
content.mozRequestAnimationFrame(callback);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -13,3 +13,8 @@ contract @mozilla.org/alerts-service;1 {5dce03b2-8faa-4b6e-9242-6ddb0411750c}
|
|||
# ContentPermissionPrompt.js
|
||||
component {8c719f03-afe0-4aac-91ff-6c215895d467} ContentPermissionPrompt.js
|
||||
contract @mozilla.org/content-permission/prompt;1 {8c719f03-afe0-4aac-91ff-6c215895d467}
|
||||
|
||||
# MozKeyboard.js
|
||||
component {397a7fdf-2254-47be-b74e-76625a1a66d5} MozKeyboard.js
|
||||
contract @mozilla.org/b2g-keyboard;1 {397a7fdf-2254-47be-b74e-76625a1a66d5}
|
||||
category JavaScript-navigator-property mozKeyboard @mozilla.org/b2g-keyboard;1
|
||||
|
|
|
@ -53,6 +53,7 @@ EXTRA_PP_COMPONENTS = \
|
|||
CameraContent.js \
|
||||
AlertsService.js \
|
||||
ContentPermissionPrompt.js \
|
||||
MozKeyboard.js \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/* 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/. */
|
||||
|
||||
'use strict';
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// MozKeyboard
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
function MozKeyboard() { }
|
||||
|
||||
MozKeyboard.prototype = {
|
||||
classID: Components.ID("{397a7fdf-2254-47be-b74e-76625a1a66d5}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIB2GKeyboard, Ci.nsIDOMGlobalPropertyInitializer, Ci.nsIObserver]),
|
||||
classInfo: XPCOMUtils.generateCI({classID: Components.ID("{397a7fdf-2254-47be-b74e-76625a1a66d5}"),
|
||||
contractID: "@mozilla.org/b2g-keyboard;1",
|
||||
interfaces: [Ci.nsIB2GKeyboard],
|
||||
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
||||
classDescription: "B2G Virtual Keyboard"}),
|
||||
|
||||
init: function(aWindow) {
|
||||
this._utils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
||||
Services.obs.addObserver(this, "inner-window-destroyed", false);
|
||||
this.innerWindowID = this._utils.currentInnerWindowID;
|
||||
},
|
||||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
if (aTopic == "inner-window-destroyed") {
|
||||
let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
||||
if (wId == this.innerWindowID) {
|
||||
Services.obs.removeObserver(this, "inner-window-destroyed");
|
||||
this._utils = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
sendKey: function mozKeyboardSendKey(keyCode, charCode) {
|
||||
charCode = (charCode == undefined) ? keyCode : charCode;
|
||||
['keydown', 'keypress', 'keyup'].forEach((function sendKey(type) {
|
||||
this._utils.sendKeyEvent(type, keyCode, charCode, null);
|
||||
}).bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
const NSGetFactory = XPCOMUtils.generateNSGetFactory([MozKeyboard]);
|
|
@ -10,3 +10,9 @@ interface nsIB2GCameraContent : nsISupports
|
|||
/* temporary solution, waiting for getUserMedia */
|
||||
DOMString getCameraURI([optional] in jsval options);
|
||||
};
|
||||
|
||||
[scriptable, uuid(80ad05f8-e5f6-4a36-b25d-5d5a969b365d)]
|
||||
interface nsIB2GKeyboard : nsISupports
|
||||
{
|
||||
void sendKey(in long aKeyCode, in long aCharCode);
|
||||
};
|
||||
|
|
|
@ -619,3 +619,4 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DLL_SUFFIX@
|
|||
@BINPATH@/components/CameraContent.js
|
||||
@BINPATH@/components/AlertsService.js
|
||||
@BINPATH@/components/ContentPermissionPrompt.js
|
||||
@BINPATH@/components/MozKeyboard.js
|
||||
|
|
Загрузка…
Ссылка в новой задаче