From 7e289eedd88f1a51397e7c191f27088e60d880b0 Mon Sep 17 00:00:00 2001 From: Jan Jongboom Date: Wed, 4 Sep 2013 08:29:22 -0400 Subject: [PATCH] Bug 906096 - Move InputMethod API behind a pref instead of build option. r=kanru, r=sicking --HG-- rename : b2g/components/Keyboard.jsm => dom/inputmethod/Keyboard.jsm rename : b2g/components/MozKeyboard.js => dom/inputmethod/MozKeyboard.js --- b2g/app/b2g.js | 3 + b2g/components/B2GComponents.manifest | 8 --- b2g/components/b2g.idl | 68 ------------------ b2g/components/moz.build | 2 - b2g/installer/package-manifest.in | 1 + dom/inputmethod/InputMethod.manifest | 6 ++ .../inputmethod}/Keyboard.jsm | 0 .../inputmethod}/MozKeyboard.js | 0 dom/inputmethod/moz.build | 26 +++++++ dom/inputmethod/nsIB2GKeyboard.idl | 71 +++++++++++++++++++ dom/moz.build | 3 +- dom/webidl/InputMethod.webidl | 13 +++- dom/webidl/WebIDL.mk | 7 +- modules/libpref/src/init/all.js | 3 + 14 files changed, 123 insertions(+), 88 deletions(-) create mode 100644 dom/inputmethod/InputMethod.manifest rename {b2g/components => dom/inputmethod}/Keyboard.jsm (100%) rename {b2g/components => dom/inputmethod}/MozKeyboard.js (100%) create mode 100644 dom/inputmethod/moz.build create mode 100644 dom/inputmethod/nsIB2GKeyboard.idl diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index 0fe4804e343d..be954a9e5c4a 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -750,3 +750,6 @@ pref("dom.promise.enabled", false); // (only applies when marionette is disabled) // 0 disables the timer. pref("b2g.adb.timeout-hours", 12); + +// InputMethod so we can do soft keyboards +pref("dom.mozInputMethod.enabled", true); diff --git a/b2g/components/B2GComponents.manifest b/b2g/components/B2GComponents.manifest index 07bf3fe11ad4..5198a35cfcab 100644 --- a/b2g/components/B2GComponents.manifest +++ b/b2g/components/B2GComponents.manifest @@ -15,14 +15,6 @@ component {88b3eb21-d072-4e3b-886d-f89d8c49fe59} UpdatePrompt.js contract @mozilla.org/updates/update-prompt;1 {88b3eb21-d072-4e3b-886d-f89d8c49fe59} #endif -# 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 - -component {4607330d-e7d2-40a4-9eb8-43967eae0142} MozKeyboard.js -contract @mozilla.org/b2g-inputmethod;1 {4607330d-e7d2-40a4-9eb8-43967eae0142} - # DirectoryProvider.js component {9181eb7c-6f87-11e1-90b1-4f59d80dd2e5} DirectoryProvider.js contract @mozilla.org/browser/directory-provider;1 {9181eb7c-6f87-11e1-90b1-4f59d80dd2e5} diff --git a/b2g/components/b2g.idl b/b2g/components/b2g.idl index a6f489241129..6f24657b6a94 100644 --- a/b2g/components/b2g.idl +++ b/b2g/components/b2g.idl @@ -4,77 +4,9 @@ #include "domstubs.idl" -interface nsIDOMDOMRequest; - [scriptable, uuid(3615a616-571d-4194-bf54-ccf546067b14)] interface nsIB2GCameraContent : nsISupports { /* temporary solution, waiting for getUserMedia */ DOMString getCameraURI([optional] in jsval options); }; - -[scriptable, uuid(40ad96b2-9efa-41fb-84c7-fbcec9b153f0)] -interface nsIB2GKeyboard : nsISupports -{ - void sendKey(in long keyCode, in long charCode); - - // Select the that support multiple - // selection, then the option specified by index will be added to - // the selection. - // If this method is called for a select that does not support multiple - // selection the previous element will be unselected. - void setSelectedOption(in jsval index); - - // Select the that does not support multiple - // selection, then the last index specified in indexes will be selected. - void setSelectedOptions(in jsval indexes); - - // Set the value on the currently focused element. This has to be used - // for special situations where the value had to be chosen amongst a - // list (type=month) or a widget (type=date, time, etc.). - // If the value passed in parameter isn't valid (in the term of HTML5 - // Forms Validation), the value will simply be ignored by the element. - void setValue(in jsval value); - - void removeFocus(); - - attribute nsIDOMEventListener onfocuschange; - - // Fires when user moves the cursor, changes the selection, or alters the - // composing text length - attribute nsIDOMEventListener onselectionchange; - - // The start position of the selection. - readonly attribute long selectionStart; - - // The stop position of the selection. - readonly attribute long selectionEnd; - - /* - * Set the selection range of the the editable text. - * - * @param start The beginning of the selected text. - * @param end The end of the selected text. - * - * Note that the start position should be less or equal to the end position. - * To move the cursor, set the start and end position to the same value. - */ - void setSelectionRange(in long start, in long end); - - /* - * Replace text around the beginning of the current selection range of the - * editable text. - * - * @param text The string to be replaced with. - * @param beforeLength The number of characters to be deleted before the - * beginning of the current selection range. Defaults to 0. - * @param afterLength The number of characters to be deleted after the - * beginning of the current selection range. Defaults to 0. - */ - void replaceSurroundingText(in DOMString text, - [optional] in long beforeLength, - [optional] in long afterLength); -}; diff --git a/b2g/components/moz.build b/b2g/components/moz.build index 915bac5a93e1..78d7b30739ae 100644 --- a/b2g/components/moz.build +++ b/b2g/components/moz.build @@ -20,7 +20,6 @@ EXTRA_COMPONENTS += [ 'ContentPermissionPrompt.js', 'FilePicker.js', 'MailtoProtocolHandler.js', - 'MozKeyboard.js', 'PaymentGlue.js', 'ProcessGlobal.js', 'SmsProtocolHandler.js', @@ -41,7 +40,6 @@ if CONFIG['MOZ_UPDATER']: EXTRA_JS_MODULES += [ 'ErrorPage.jsm', - 'Keyboard.jsm', 'SignInToWebsite.jsm', 'TelURIParser.jsm', ] diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index 2553cf7659ae..d52988cb8b9d 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -213,6 +213,7 @@ @BINPATH@/components/dom_xpath.xpt @BINPATH@/components/dom_xul.xpt @BINPATH@/components/dom_time.xpt +@BINPATH@/components/dom_inputmethod.xpt @BINPATH@/components/downloads.xpt @BINPATH@/components/editor.xpt @BINPATH@/components/embed_base.xpt diff --git a/dom/inputmethod/InputMethod.manifest b/dom/inputmethod/InputMethod.manifest new file mode 100644 index 000000000000..77fd07313b34 --- /dev/null +++ b/dom/inputmethod/InputMethod.manifest @@ -0,0 +1,6 @@ +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 + +component {4607330d-e7d2-40a4-9eb8-43967eae0142} MozKeyboard.js +contract @mozilla.org/b2g-inputmethod;1 {4607330d-e7d2-40a4-9eb8-43967eae0142} diff --git a/b2g/components/Keyboard.jsm b/dom/inputmethod/Keyboard.jsm similarity index 100% rename from b2g/components/Keyboard.jsm rename to dom/inputmethod/Keyboard.jsm diff --git a/b2g/components/MozKeyboard.js b/dom/inputmethod/MozKeyboard.js similarity index 100% rename from b2g/components/MozKeyboard.js rename to dom/inputmethod/MozKeyboard.js diff --git a/dom/inputmethod/moz.build b/dom/inputmethod/moz.build new file mode 100644 index 000000000000..965397cfe0cf --- /dev/null +++ b/dom/inputmethod/moz.build @@ -0,0 +1,26 @@ +# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +XPIDL_SOURCES += [ + 'nsIB2GKeyboard.idl', +] + +XPIDL_MODULE = 'dom_inputmethod' + +MODULE = 'dom' + +EXTRA_COMPONENTS += [ + 'InputMethod.manifest', + 'MozKeyboard.js', +] + +EXTRA_JS_MODULES += [ + 'Keyboard.jsm', +] + +FAIL_ON_WARNINGS = True + +LIBXUL_LIBRARY = True diff --git a/dom/inputmethod/nsIB2GKeyboard.idl b/dom/inputmethod/nsIB2GKeyboard.idl new file mode 100644 index 000000000000..be205282384a --- /dev/null +++ b/dom/inputmethod/nsIB2GKeyboard.idl @@ -0,0 +1,71 @@ +/* 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/. */ + +#include "domstubs.idl" + +[scriptable, uuid(40ad96b2-9efa-41fb-84c7-fbcec9b153f0)] +interface nsIB2GKeyboard : nsISupports +{ + void sendKey(in long keyCode, in long charCode); + + // Select the that support multiple + // selection, then the option specified by index will be added to + // the selection. + // If this method is called for a select that does not support multiple + // selection the previous element will be unselected. + void setSelectedOption(in jsval index); + + // Select the that does not support multiple + // selection, then the last index specified in indexes will be selected. + void setSelectedOptions(in jsval indexes); + + // Set the value on the currently focused element. This has to be used + // for special situations where the value had to be chosen amongst a + // list (type=month) or a widget (type=date, time, etc.). + // If the value passed in parameter isn't valid (in the term of HTML5 + // Forms Validation), the value will simply be ignored by the element. + void setValue(in jsval value); + + void removeFocus(); + + attribute nsIDOMEventListener onfocuschange; + + // Fires when user moves the cursor, changes the selection, or alters the + // composing text length + attribute nsIDOMEventListener onselectionchange; + + // The start position of the selection. + readonly attribute long selectionStart; + + // The stop position of the selection. + readonly attribute long selectionEnd; + + /* + * Set the selection range of the the editable text. + * + * @param start The beginning of the selected text. + * @param end The end of the selected text. + * + * Note that the start position should be less or equal to the end position. + * To move the cursor, set the start and end position to the same value. + */ + void setSelectionRange(in long start, in long end); + + /* + * Replace text around the beginning of the current selection range of the + * editable text. + * + * @param text The string to be replaced with. + * @param beforeLength The number of characters to be deleted before the + * beginning of the current selection range. Defaults to 0. + * @param afterLength The number of characters to be deleted after the + * beginning of the current selection range. Defaults to 0. + */ + void replaceSurroundingText(in DOMString text, + [optional] in long beforeLength, + [optional] in long afterLength); +}; diff --git a/dom/moz.build b/dom/moz.build index 5aeb1ba6a7a5..77aa7032d97e 100644 --- a/dom/moz.build +++ b/dom/moz.build @@ -72,7 +72,8 @@ PARALLEL_DIRS += [ 'camera', 'audiochannel', 'promise', - 'wappush' + 'wappush', + 'inputmethod' ] if CONFIG['OS_ARCH'] == 'WINNT': diff --git a/dom/webidl/InputMethod.webidl b/dom/webidl/InputMethod.webidl index 5c0812c12ef4..ae48dd0044bc 100644 --- a/dom/webidl/InputMethod.webidl +++ b/dom/webidl/InputMethod.webidl @@ -5,7 +5,8 @@ */ [JSImplementation="@mozilla.org/b2g-inputmethod;1", - NavigatorProperty="mozInputMethod"] + NavigatorProperty="mozInputMethod", + Pref="dom.mozInputMethod.enabled"] interface MozInputMethod : EventTarget { // Input Method Manager contain a few global methods expose to apps readonly attribute MozInputMethodManager mgmt; @@ -27,7 +28,8 @@ interface MozInputMethod : EventTarget { // Manages the list of IMEs, enables/disables IME and switches to an // IME. -[JSImplementation="@mozilla.org/b2g-imm;1"] +[JSImplementation="@mozilla.org/b2g-imm;1", + Pref="dom.mozInputMethod.enabled"] interface MozInputMethodManager { // Ask the OS to show a list of available IMEs for users to switch from. // OS should ignore this request if the app is currently not the active one. @@ -55,7 +57,8 @@ interface MozInputMethodManager { // It also hosts the methods available to the keyboard app to mutate the input field represented. // An "input context" gets void when the app is no longer allowed to interact with the text field, // e.g., the text field does no longer exist, the app is being switched to background, and etc. -[JSImplementation="@mozilla.org/b2g-inputcontext;1"] +[JSImplementation="@mozilla.org/b2g-inputcontext;1", + Pref="dom.mozInputMethod.enabled"] interface MozInputContext: EventTarget { // The tag name of input field, which is enum of "input", "textarea", or "contenteditable" readonly attribute DOMString? type; @@ -82,6 +85,10 @@ interface MozInputContext: EventTarget { readonly attribute long selectionStart; readonly attribute long selectionEnd; + // The start and stop position of the selection. + readonly attribute DOMString? textBeforeCursor; + readonly attribute DOMString? textAfterCursor; + /* * Set the selection range of the the editable text. * Note: This method cannot be used to move the cursor during composition. Calling this diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index f18ce2bddd4b..c0856a026e6f 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -180,6 +180,7 @@ webidl_files = \ IDBVersionChangeEvent.webidl \ ImageData.webidl \ ImageDocument.webidl \ + InputMethod.webidl \ InspectorUtils.webidl \ KeyboardEvent.webidl \ KeyEvent.webidl \ @@ -541,9 +542,3 @@ test_webidl_files := \ else test_webidl_files := $(NULL) endif - -ifdef MOZ_B2G -webidl_files += \ - InputMethod.webidl \ - $(NULL) -endif diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 33257ad28834..1b83cf99569b 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -4380,3 +4380,6 @@ pref("dom.forms.inputmode", false); #else pref("dom.forms.inputmode", true); #endif + +// InputMethods for soft keyboards in B2G +pref("dom.mozInputMethod.enabled", false);