Bug 1221459 - Remove SelectionStateChangedEvent. r=mtseng, r=smaug

SelectionStateChangedEvent is dispatched only by SelectionCarets. Hence
the removal. The modification in mochitest browserElement_CopyPaste.js
is effectively the reverting of [1] with AccessibleCaret enabled.

The DoCommandHelper is shell.js is removed as well, which handles the
'do-command' event dispatched from old text_selection_dialog.js in Gaia.

[1] https://bugzilla.mozilla.org/page.cgi?id=splinter.html&bug=1155493&attachment=8612154

DONTBUILD

--HG--
extra : amend_source : 1348306b0eee27ae08cef1b947e383dfded7798c
This commit is contained in:
Ting-Yu Lin 2015-12-22 14:14:12 +08:00
Родитель 4f08edc623
Коммит 00f0ffd013
12 изменённых файлов: 18 добавлений и 328 удалений

Просмотреть файл

@ -430,7 +430,6 @@ var shell = {
window.addEventListener('sizemodechange', this);
window.addEventListener('unload', this);
this.contentBrowser.addEventListener('mozbrowserloadstart', this, true);
this.contentBrowser.addEventListener('mozbrowserselectionstatechanged', this, true);
this.contentBrowser.addEventListener('mozbrowserscrollviewchange', this, true);
this.contentBrowser.addEventListener('mozbrowsercaretstatechanged', this);
@ -464,7 +463,6 @@ var shell = {
window.removeEventListener('MozApplicationManifest', this);
window.removeEventListener('sizemodechange', this);
this.contentBrowser.removeEventListener('mozbrowserloadstart', this, true);
this.contentBrowser.removeEventListener('mozbrowserselectionstatechanged', this, true);
this.contentBrowser.removeEventListener('mozbrowserscrollviewchange', this, true);
this.contentBrowser.removeEventListener('mozbrowsercaretstatechanged', this);
ppmm.removeMessageListener("content-handler", this);
@ -584,29 +582,6 @@ var shell = {
detail: evt.detail,
});
break;
case 'mozbrowserselectionstatechanged':
// The mozbrowserselectionstatechanged event, may have crossed the chrome-content boundary.
// This event always dispatch to shell.js. But the offset we got from this event is
// based on tab's coordinate. So get the actual offsets between shell and evt.target.
let elt = evt.target;
let win = elt.ownerDocument.defaultView;
let offsetX = win.mozInnerScreenX - window.mozInnerScreenX;
let offsetY = win.mozInnerScreenY - window.mozInnerScreenY;
let rect = elt.getBoundingClientRect();
offsetX += rect.left;
offsetY += rect.top;
let data = evt.detail;
data.offsetX = offsetX;
data.offsetY = offsetY;
DoCommandHelper.setEvent(evt);
shell.sendChromeEvent({
type: 'selectionstatechanged',
detail: data,
});
break;
case 'mozbrowsercaretstatechanged':
{
let elt = evt.target;
@ -883,9 +858,6 @@ var CustomEventManager = {
case 'inputregistry-remove':
KeyboardHelper.handleEvent(detail);
break;
case 'do-command':
DoCommandHelper.handleEvent(detail.cmd);
break;
case 'copypaste-do-command':
Services.obs.notifyObservers({ wrappedJSObject: shell.contentBrowser },
'ask-children-to-execute-copypaste-command', detail.cmd);
@ -933,21 +905,6 @@ var CustomEventManager = {
}
}
var DoCommandHelper = {
_event: null,
setEvent: function docommand_setEvent(evt) {
this._event = evt;
},
handleEvent: function docommand_handleEvent(cmd) {
if (this._event) {
Services.obs.notifyObservers({ wrappedJSObject: this._event.target },
'copypaste-docommand', cmd);
this._event = null;
}
}
}
var WebappsHelper = {
_installers: {},
_count: 0,

Просмотреть файл

@ -139,7 +139,6 @@ function BrowserElementChild() {
this._isContentWindowCreated = false;
this._pendingSetInputMethodActive = [];
this._selectionStateChangedTarget = null;
this.forwarder = new BrowserElementProxyForwarder();
@ -224,11 +223,6 @@ BrowserElementChild.prototype = {
/* useCapture = */ true,
/* wantsUntrusted = */ false);
addEventListener('mozselectionstatechanged',
this._selectionStateChangedHandler.bind(this),
/* useCapture = */ true,
/* wantsUntrusted = */ false);
addEventListener('scrollviewchange',
this._ScrollViewChangeHandler.bind(this),
/* useCapture = */ true,
@ -719,97 +713,6 @@ BrowserElementChild.prototype = {
}
},
_selectionStateChangedHandler: function(e) {
e.stopPropagation();
if (!this._isContentWindowCreated) {
return;
}
let boundingClientRect = e.boundingClientRect;
let isCollapsed = (e.selectedText.length == 0);
let isMouseUp = (e.states.indexOf('mouseup') == 0);
let canPaste = this._isCommandEnabled("paste");
if (this._selectionStateChangedTarget != e.target) {
// SelectionStateChanged events with the following states are not
// necessary to trigger the text dialog, bypass these events
// by default.
//
if(e.states.length == 0 ||
e.states.indexOf('drag') == 0 ||
e.states.indexOf('keypress') == 0 ||
e.states.indexOf('mousedown') == 0) {
return;
}
// The collapsed SelectionStateChanged event is unnecessary to dispatch,
// bypass this event by default, but here comes some exceptional cases
if (isCollapsed) {
if (isMouseUp && canPaste) {
// Always dispatch to support shortcut mode which can paste previous
// copied content easily
} else if (e.states.indexOf('blur') == 0) {
// Always dispatch to notify the blur for the focus content
} else if (e.states.indexOf('taponcaret') == 0) {
// Always dispatch to notify the caret be touched
} else {
return;
}
}
}
// If we select something and selection range is visible, we cache current
// event's target to selectionStateChangedTarget.
// And dispatch the next SelectionStateChagne event if target is matched, so
// that the parent side can hide the text dialog.
// We clear selectionStateChangedTarget if selection carets are invisible.
if (e.visible && !isCollapsed) {
this._selectionStateChangedTarget = e.target;
} else if (canPaste && isCollapsed) {
this._selectionStateChangedTarget = e.target;
} else {
this._selectionStateChangedTarget = null;
}
let zoomFactor = content.screen.width / content.innerWidth;
let detail = {
rect: {
width: boundingClientRect ? boundingClientRect.width : 0,
height: boundingClientRect ? boundingClientRect.height : 0,
top: boundingClientRect ? boundingClientRect.top : 0,
bottom: boundingClientRect ? boundingClientRect.bottom : 0,
left: boundingClientRect ? boundingClientRect.left : 0,
right: boundingClientRect ? boundingClientRect.right : 0,
},
commands: {
canSelectAll: this._isCommandEnabled("selectall"),
canCut: this._isCommandEnabled("cut"),
canCopy: this._isCommandEnabled("copy"),
canPaste: this._isCommandEnabled("paste"),
},
zoomFactor: zoomFactor,
states: e.states,
isCollapsed: (e.selectedText.length == 0),
visible: e.visible,
};
// Get correct geometry information if we have nested iframe.
let currentWindow = e.target.defaultView;
while (currentWindow.realFrameElement) {
let currentRect = currentWindow.realFrameElement.getBoundingClientRect();
detail.rect.top += currentRect.top;
detail.rect.bottom += currentRect.top;
detail.rect.left += currentRect.left;
detail.rect.right += currentRect.left;
currentWindow = currentWindow.realFrameElement.ownerDocument.defaultView;
}
sendAsyncMsg('selectionstatechanged', detail);
},
_genericMetaHandler: function(name, eventType, target) {
let meta = {
name: name,
@ -1481,7 +1384,6 @@ BrowserElementChild.prototype = {
_recvDoCommand: function(data) {
if (this._isCommandEnabled(data.json.command)) {
this._selectionStateChangedTarget = null;
docShell.doCommand(COMMAND_MAP[data.json.command]);
}
},

Просмотреть файл

@ -81,7 +81,7 @@ BrowserElementParentProxyCallHandler.prototype = {
"contextmenu", "securitychange", "locationchange",
"iconchange", "scrollareachanged", "titlechange",
"opensearch", "manifestchange", "metachange",
"resize", "selectionstatechanged", "scrollviewchange",
"resize", "scrollviewchange",
"caretstatechanged", "activitydone", "scroll", "opentab"]),
init: function(frameElement, mm) {
@ -380,7 +380,6 @@ BrowserElementParent.prototype = {
"got-visible": this._gotDOMRequestResult,
"visibilitychange": this._childVisibilityChange,
"got-set-input-method-active": this._gotDOMRequestResult,
"selectionstatechanged": this._handleSelectionStateChanged,
"scrollviewchange": this._handleScrollViewChange,
"caretstatechanged": this._handleCaretStateChanged,
"findchange": this._handleFindChange,
@ -619,12 +618,6 @@ BrowserElementParent.prototype = {
}
},
_handleSelectionStateChanged: function(data) {
let evt = this._createEvent('selectionstatechanged', data.json,
/* cancelable = */ false);
this._frameElement.dispatchEvent(evt);
},
// Called when state of accessible caret in child has changed.
// The fields of data is as following:
// - rect: Contains bounding rectangle of selection, Include width, height,

Просмотреть файл

@ -65,10 +65,6 @@ const browserElementTestHelpers = {
this._setPref('dom.mozBrowserFramesEnabled', value);
},
setSelectionChangeEnabledPref: function(value) {
this._setPref('selectioncaret.enabled', value);
},
setAccessibleCaretEnabledPref: function(value) {
this._setPref('layout.accessiblecaret.enabled', value);
},

Просмотреть файл

@ -1,14 +1,12 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that "cut, copy, paste, selectall" and selectionstatechanged event works from inside an <iframe mozbrowser>.
// Test that "cut, copy, paste, selectall" and caretstatechanged event works from inside an <iframe mozbrowser>.
"use strict";
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");
SimpleTest.requestLongerTimeout(2); // slow on android
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.setSelectionChangeEnabledPref(false);
browserElementTestHelpers.setAccessibleCaretEnabledPref(true);
browserElementTestHelpers.addPermission();
const { Services } = SpecialPowers.Cu.import('resource://gre/modules/Services.jsm');
@ -92,14 +90,6 @@ function doCommand(cmd) {
'copypaste-docommand', cmd);
}
function rerunTest() {
// clean up and run test again.
document.body.removeChild(iframeOuter);
document.body.removeChild(gTextarea);
state = 0;
runTest();
}
function dispatchTest(e) {
iframeInner.addEventListener("mozbrowserloadend", function onloadend2(e) {
iframeInner.removeEventListener("mozbrowserloadend", onloadend2);
@ -171,23 +161,15 @@ function dispatchTest(e) {
break;
default:
if (createEmbededFrame || browserElementTestHelpers.getOOPByDefaultPref()) {
if (testSelectionChange) {
SimpleTest.finish();
return;
} else {
testSelectionChange = true;
createEmbededFrame = false;
SpecialPowers.pushPrefEnv(
{'set':
[['selectioncaret.enabled', true],
['layout.accessiblecaret.enabled', false]]},
function() {
rerunTest();
});
}
SimpleTest.finish();
} else {
createEmbededFrame = true;
rerunTest();
// clean up and run test again.
document.body.removeChild(iframeOuter);
document.body.removeChild(gTextarea);
state = 0;
runTest();
}
break;
}
@ -202,25 +184,20 @@ function isChildProcess() {
function testSelectAll(e) {
// Skip mozbrowser test if we're at child process.
if (!isChildProcess()) {
let eventName = testSelectionChange ? "mozbrowserselectionstatechanged" : "mozbrowsercaretstatechanged";
iframeOuter.addEventListener(eventName, function selectchangeforselectall(e) {
if (!e.detail.states || e.detail.states.indexOf('selectall') == 0) {
iframeOuter.removeEventListener(eventName, selectchangeforselectall, true);
ok(true, "got mozbrowserselectionstatechanged event." + stateMeaning);
ok(e.detail, "event.detail is not null." + stateMeaning);
ok(e.detail.width != 0, "event.detail.width is not zero" + stateMeaning);
ok(e.detail.height != 0, "event.detail.height is not zero" + stateMeaning);
if (testSelectionChange) {
ok(e.detail.states, "event.detail.state " + e.detail.states);
}
SimpleTest.executeSoon(function() { testCopy1(e); });
}
let eventName = "mozbrowsercaretstatechanged";
iframeOuter.addEventListener(eventName, function caretchangeforselectall(e) {
iframeOuter.removeEventListener(eventName, caretchangeforselectall, true);
ok(true, "got mozbrowsercaretstatechanged event." + stateMeaning);
ok(e.detail, "event.detail is not null." + stateMeaning);
ok(e.detail.width != 0, "event.detail.width is not zero" + stateMeaning);
ok(e.detail.height != 0, "event.detail.height is not zero" + stateMeaning);
SimpleTest.executeSoon(function() { testCopy1(e); });
}, true);
}
mm.addMessageListener('content-focus', function messageforfocus(msg) {
mm.removeMessageListener('content-focus', messageforfocus);
// test selectall command, after calling this the selectionstatechanged event should be fired.
// test selectall command, after calling this the caretstatechanged event should be fired.
doCommand('selectall');
if (isChildProcess()) {
SimpleTest.executeSoon(function() { testCopy1(e); });

Просмотреть файл

@ -1,57 +0,0 @@
/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Bug 1111433: Send out the SelectionStateChanged event with Blur state
"use strict";
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.setSelectionChangeEnabledPref(true);
browserElementTestHelpers.addPermission();
var mm;
var iframe;
var changefocus = function () {
var elt = content.document.getElementById("text");
if (elt) {
elt.focus();
elt.select();
elt.blur();
}
}
function runTest() {
iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
document.body.appendChild(iframe);
mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
iframe.src = "data:text/html,<html><body>" +
"<textarea id='text'> Bug 1111433 </textarea>"+
"</body></html>";
var loadtime = 0;
iframe.addEventListener("mozbrowserloadend", function onloadend(e) {
loadtime++;
if (loadtime === 2) {
iframe.removeEventListener("mozbrowserloadend", onloadend);
SimpleTest.executeSoon(function() { testBlur(e); });
}
});
}
function testBlur(e) {
iframe.addEventListener("mozbrowserselectionstatechanged", function selectionstatechanged(e) {
iframe.removeEventListener("mozbrowserselectionstatechanged", selectionstatechanged, true);
ok(e.detail.states.indexOf('blur') == 0, "received state " + e.detail.states);
SimpleTest.finish();
}, true);
iframe.focus();
mm.loadFrameScript('data:,(' + changefocus.toString() + ')();', false);
}
addEventListener('testready', runTest);

Просмотреть файл

@ -87,9 +87,6 @@ skip-if = (toolkit == 'gonk')
[test_browserElement_oop_ScrollEvent.html]
[test_browserElement_oop_SecurityChange.html]
skip-if = toolkit == 'android' || (toolkit == 'gonk' && !debug) #TIMED_OUT, bug 766586
[test_browserElement_oop_SelectionStateBlur.html]
skip-if = (os == "android" || toolkit == 'gonk') # Disabled on b2g due to bug 1097419
# Disabled on Android, see bug 1230230
[test_browserElement_oop_SendEvent.html]
[test_browserElement_oop_SetInputMethodActive.html]
skip-if = (os == "android")

Просмотреть файл

@ -64,7 +64,6 @@ support-files =
browserElement_ScrollEvent.js
browserElement_SecurityChange.js
browserElement_SendEvent.js
browserElement_SelectionStateBlur.js
browserElement_SetInputMethodActive.js
browserElement_SetNFCFocus.js
browserElement_SetVisible.js
@ -222,9 +221,6 @@ skip-if = (toolkit == 'gonk')
[test_browserElement_inproc_ScrollEvent.html]
[test_browserElement_inproc_SecurityChange.html]
skip-if = toolkit == 'android' || (toolkit == 'gonk' && !debug) # android(TIMED_OUT, bug 766586) androidx86(TIMED_OUT, bug 766586)
[test_browserElement_inproc_SelectionStateBlur.html]
skip-if = (os == "android" || toolkit == 'gonk') # Disabled on b2g due to bug 1097419
# Disabled on Android, see bug 1230230
[test_browserElement_inproc_SendEvent.html]
# The setInputMethodActive() tests will timed out on Android
[test_browserElement_inproc_SetInputMethodActive.html]

Просмотреть файл

@ -1,18 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1111433
-->
<head>
<title>Test for Bug 1111433</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1111433">Mozilla Bug 1111433</a>
<script type="application/javascript;version=1.7" src="browserElement_SelectionStateBlur.js">
</script>
</body>
</html>

Просмотреть файл

@ -1,18 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1111433
-->
<head>
<title>Test for Bug 1111433</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1111433">Mozilla Bug 1111433</a>
<script type="application/javascript;version=1.7" src="browserElement_SelectionStateBlur.js">
</script>
</body>
</html>

Просмотреть файл

@ -1,34 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
enum SelectionState {
"drag",
"mousedown",
"mouseup",
"keypress",
"selectall",
"collapsetostart",
"collapsetoend",
"blur",
"updateposition",
"taponcaret"
};
dictionary SelectionStateChangedEventInit : EventInit {
boolean visible = true;
DOMString selectedText = "";
DOMRectReadOnly? boundingClientRect = null;
sequence<SelectionState> states = [];
};
[Constructor(DOMString type, optional SelectionStateChangedEventInit eventInit),
ChromeOnly]
interface SelectionStateChangedEvent : Event {
readonly attribute boolean visible;
readonly attribute DOMString selectedText;
readonly attribute DOMRectReadOnly? boundingClientRect;
[Cached, Pure] readonly attribute sequence<SelectionState> states;
};

Просмотреть файл

@ -815,7 +815,6 @@ GENERATED_EVENTS_WEBIDL_FILES = [
'ProgressEvent.webidl',
'RecordErrorEvent.webidl',
'ScrollViewChangeEvent.webidl',
'SelectionStateChangedEvent.webidl',
'StyleRuleChangeEvent.webidl',
'StyleSheetApplicableStateChangeEvent.webidl',
'StyleSheetChangeEvent.webidl',