From d521111d48a5f27a0790131985fa2ff0c688b2a3 Mon Sep 17 00:00:00 2001 From: Tim Chien Date: Mon, 25 Aug 2014 22:47:00 +0200 Subject: [PATCH] Bug 1054839 - Revive detail object in selectionchange and surrendingtextchange event. r=khuey,yxl --- dom/inputmethod/MozKeyboard.js | 16 +++++++++------- dom/inputmethod/mochitest/test_basic.html | 16 ++++++++++------ dom/webidl/InputMethod.webidl | 23 ++++++++++++----------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/dom/inputmethod/MozKeyboard.js b/dom/inputmethod/MozKeyboard.js index ac6dc93321325..c8808565a65d5 100644 --- a/dom/inputmethod/MozKeyboard.js +++ b/dom/inputmethod/MozKeyboard.js @@ -232,7 +232,7 @@ MozInputMethod.prototype = { break; case 'Keyboard:SelectionChange': if (this.inputcontext) { - this._inputcontext.updateSelectionContext(json); + this._inputcontext.updateSelectionContext(json, false); } break; case 'Keyboard:GetContext:Result:OK': @@ -454,7 +454,7 @@ MozInputContext.prototype = { // Update context first before resolving promise to avoid race condition if (json.selectioninfo) { - this.updateSelectionContext(json.selectioninfo); + this.updateSelectionContext(json.selectioninfo, true); } switch (msg.name) { @@ -491,7 +491,7 @@ MozInputContext.prototype = { } }, - updateSelectionContext: function ic_updateSelectionContext(ctx) { + updateSelectionContext: function ic_updateSelectionContext(ctx, ownAction) { if (!this._context) { return; } @@ -509,14 +509,16 @@ MozInputContext.prototype = { if (selectionDirty) { this._fireEvent("selectionchange", { selectionStart: ctx.selectionStart, - selectionEnd: ctx.selectionEnd + selectionEnd: ctx.selectionEnd, + ownAction: ownAction }); } if (surroundDirty) { this._fireEvent("surroundingtextchange", { beforeString: ctx.textBeforeCursor, - afterString: ctx.textAfterCursor + afterString: ctx.textAfterCursor, + ownAction: ownAction }); } }, @@ -526,8 +528,8 @@ MozInputContext.prototype = { detail: aDetail }; - let event = new this._window.Event(eventName, - Cu.cloneInto(aDetail, this._window)); + let event = new this._window.CustomEvent(eventName, + Cu.cloneInto(detail, this._window)); this.__DOM_IMPL__.dispatchEvent(event); }, diff --git a/dom/inputmethod/mochitest/test_basic.html b/dom/inputmethod/mochitest/test_basic.html index 75cbdbbebdf00..dec747b8be4c8 100644 --- a/dom/inputmethod/mochitest/test_basic.html +++ b/dom/inputmethod/mochitest/test_basic.html @@ -144,13 +144,15 @@ } } - gContext.onselectionchange = function() { + gContext.onselectionchange = function(evt) { ok(true, 'onselectionchange fired'); - cleanup(); + is(evt.detail.selectionStart, 10); + is(evt.detail.selectionEnd, 10); + ok(evt.detail.ownAction); }; gContext.sendKey(0, 'j'.charCodeAt(0), 0).then(function() { - // do nothing and wait for onselectionchange event + cleanup(); }, function(e) { ok(false, 'sendKey failed: ' + e.name); cleanup(true); @@ -175,13 +177,15 @@ } } - gContext.onsurroundingtextchange = function() { + gContext.onsurroundingtextchange = function(evt) { ok(true, 'onsurroundingtextchange fired'); - cleanup(); + is(evt.detail.beforeString, 'Xulei2013jj'); + is(evt.detail.afterString, ''); + ok(evt.detail.ownAction); }; gContext.sendKey(0, 'j'.charCodeAt(0), 0).then(function() { - // do nothing and wait for onselectionchange event + cleanup(); }, function(e) { ok(false, 'sendKey failed: ' + e.name); cleanup(true); diff --git a/dom/webidl/InputMethod.webidl b/dom/webidl/InputMethod.webidl index b18c082a700cc..b429c886692c9 100644 --- a/dom/webidl/InputMethod.webidl +++ b/dom/webidl/InputMethod.webidl @@ -138,6 +138,10 @@ interface MozInputContext: EventTarget { /* User moves the cursor, or changes the selection with other means. If the text around * cursor has changed, but the cursor has not been moved, the IME won't get notification. + * + * A dict is provided in the detail property of the event containing the new values, and + * an "ownAction" property to denote the event is the result of our own mutation to + * the input field. */ attribute EventHandler onselectionchange; @@ -163,17 +167,14 @@ interface MozInputContext: EventTarget { Promise deleteSurroundingText(long offset, long length); /* - * Notifies when the text around the cursor is changed, due to either text - * editing or cursor movement. If the cursor has been moved, but the text around has not - * changed, the IME won't get notification. - * - * The event handler function is specified as: - * @param beforeString Text before and including cursor position. - * @param afterString Text after and excluing cursor position. - * function(DOMString beforeText, DOMString afterText) { - * ... - * } - */ + * Notifies when the text around the cursor is changed, due to either text + * editing or cursor movement. If the cursor has been moved, but the text around has not + * changed, the IME won't get notification. + * + * A dict is provided in the detail property of the event containing the new values, and + * an "ownAction" property to denote the event is the result of our own mutation to + * the input field. + */ attribute EventHandler onsurroundingtextchange; /*