Bug 1254629 - Let query events fail when content root is wrong; r=masayuki

Make query events fail (including when caching selection) if the queried
content root is different from what we expected.

Also, introduce a fix-up to the selection fix in test_imestate.html.
This commit is contained in:
Jim Chen 2016-03-16 14:20:30 -04:00
parent fb47188c38
commit ae409c5147
2 changed files with 10 additions and 8 deletions

View File

@ -740,10 +740,11 @@ IMEContentObserver::HandleQueryContentEvent(WidgetQueryContentEvent* aEvent)
mIsHandlingQueryContentEvent = true;
ContentEventHandler handler(GetPresContext());
nsresult rv = handler.HandleQueryContentEvent(aEvent);
if (aEvent->mSucceeded) {
// We need to guarantee that mRootContent should be always same value for
// the observing editor.
aEvent->mReply.mContentsRoot = mRootContent;
if (!IsInitializedWithPlugin() &&
NS_WARN_IF(aEvent->mReply.mContentsRoot != mRootContent)) {
// Focus has changed unexpectedly, so make the query fail.
aEvent->mSucceeded = false;
}
return rv;
}
@ -1261,7 +1262,8 @@ IMEContentObserver::UpdateSelectionCache()
WidgetQueryContentEvent selection(true, eQuerySelectedText, mWidget);
ContentEventHandler handler(GetPresContext());
handler.OnQuerySelectedText(&selection);
if (NS_WARN_IF(!selection.mSucceeded)) {
if (NS_WARN_IF(!selection.mSucceeded) ||
NS_WARN_IF(selection.mReply.mContentsRoot != mRootContent)) {
return false;
}

View File

@ -1232,6 +1232,9 @@ function runEditorFlagChangeTests()
var container = document.getElementById("display");
// Reset selection from previous tests.
window.getSelection().collapse(container, 0);
// the editor has focus directly.
container.setAttribute("contenteditable", "true");
container.focus();
@ -1252,9 +1255,6 @@ function runEditorFlagChangeTests()
editor.QueryInterface(Components.interfaces.nsIEditorIMESupport);
var flags = editor.flags;
// Reset selection from previous tests.
editor.selection.collapse(container, 0);
// input characters
synthesizeCompositionChange(
{ "composition":