зеркало из https://github.com/mozilla/gecko-dev.git
Bug 903737 - Fix: right click on non-selected content with selected text in page brings up text selection context menu. r=rsilveira
This commit is contained in:
Родитель
285f7fc115
Коммит
f91e1bd439
|
@ -293,7 +293,7 @@ var ContextMenuHandler = {
|
|||
// If this is text and has a selection, we want to bring
|
||||
// up the copy option on the context menu.
|
||||
let selection = targetWindow.getSelection();
|
||||
if (selection && selection.toString().length > 0) {
|
||||
if (selection && this._tapInSelection(selection, aX, aY)) {
|
||||
state.string = targetWindow.getSelection().toString();
|
||||
state.types.push("copy");
|
||||
state.types.push("selected-text");
|
||||
|
@ -323,6 +323,20 @@ var ContextMenuHandler = {
|
|||
sendAsyncMessage("Content:ContextMenu", state);
|
||||
},
|
||||
|
||||
_tapInSelection: function (aSelection, aX, aY) {
|
||||
if (!aSelection || !aSelection.rangeCount) {
|
||||
return false;
|
||||
}
|
||||
for (let idx = 0; idx < aSelection.rangeCount; idx++) {
|
||||
let range = aSelection.getRangeAt(idx);
|
||||
let rect = range.getBoundingClientRect();
|
||||
if (Util.pointWithinDOMRect(aX, aY, rect)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_getLinkURL: function ch_getLinkURL(aLink) {
|
||||
let href = aLink.href;
|
||||
if (href)
|
||||
|
|
|
@ -22,6 +22,16 @@ was to get out again.
|
|||
The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly
|
||||
down, so suddenly that Alice had not a moment to think about stopping herself before she
|
||||
found herself falling down a very deep well.
|
||||
<div id="seldiv" style="width:300px; height:100px;">The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly
|
||||
down, so suddenly that Alice had not a moment to think about stopping herself before she
|
||||
found herself falling down a very deep well.
|
||||
</div>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<div id="emptydiv" style="width:300px; height:100px; border: solid 1px black;"></div>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
|
|
|
@ -284,12 +284,15 @@ gTests.push({
|
|||
400,
|
||||
400,
|
||||
400,
|
||||
200);
|
||||
350);
|
||||
|
||||
yield waitForCondition(function () {
|
||||
return !SelectionHelperUI.isSelectionUIVisible;
|
||||
}, kCommonWaitMs, kCommonPollMs);
|
||||
|
||||
// cancel fling from scroll above
|
||||
TouchModule.cancelPending();
|
||||
|
||||
// active state - should be disabled after a page scroll
|
||||
is(SelectionHelperUI.isActive, false, "selection inactive");
|
||||
},
|
||||
|
@ -347,6 +350,32 @@ gTests.push({
|
|||
tearDown: setUpAndTearDown,
|
||||
});
|
||||
|
||||
gTests.push({
|
||||
desc: "bug 903737 - right click targeting",
|
||||
setUp: setUpAndTearDown,
|
||||
run: function test() {
|
||||
yield hideContextUI();
|
||||
let range = gWindow.document.createRange();
|
||||
range.selectNode(gWindow.document.getElementById("seldiv"));
|
||||
gWindow.getSelection().addRange(range);
|
||||
let promise = waitForEvent(document, "popupshown");
|
||||
sendContextMenuClickToElement(gWindow, gWindow.document.getElementById("seldiv"));
|
||||
yield promise;
|
||||
promise = waitForEvent(document, "popuphidden");
|
||||
ContextMenuUI.hide();
|
||||
yield promise;
|
||||
let emptydiv = gWindow.document.getElementById("emptydiv");
|
||||
let coords = logicalCoordsForElement(emptydiv);
|
||||
InputSourceHelper.isPrecise = true;
|
||||
sendContextMenuClick(coords.x, coords.y);
|
||||
yield waitForCondition(function () {
|
||||
return ContextUI.tabbarVisible;
|
||||
});
|
||||
yield hideContextUI();
|
||||
},
|
||||
tearDown: setUpAndTearDown,
|
||||
});
|
||||
|
||||
function test() {
|
||||
if (!isLandscapeMode()) {
|
||||
todo(false, "browser_selection_tests need landscape mode to run.");
|
||||
|
|
|
@ -134,7 +134,7 @@ gTests.push({
|
|||
is(getTrimmedSelection(gFrame).toString(), "started", "selection test");
|
||||
|
||||
let promise = waitForEvent(document, "popupshown");
|
||||
sendContextMenuClick(527, 188);
|
||||
sendContextMenuClickToSelection(gFrame.contentDocument.defaultView);
|
||||
|
||||
yield promise;
|
||||
ok(promise && !(promise instanceof Error), "promise error");
|
||||
|
|
|
@ -79,7 +79,7 @@ gTests.push({
|
|||
|
||||
is(SelectionHelperUI.isActive, true, "selection active");
|
||||
is(getTrimmedSelection(textarea).toString(), "Alice", "selection test");
|
||||
|
||||
|
||||
let xpos = SelectionHelperUI.endMark.xPos;
|
||||
let ypos = SelectionHelperUI.endMark.yPos + 10;
|
||||
|
||||
|
|
|
@ -582,6 +582,26 @@ function sendContextMenuClick(aX, aY) {
|
|||
1, Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH);
|
||||
}
|
||||
|
||||
/*
|
||||
* sendContextMenuClickToSelection - simulates a press-hold touch input event
|
||||
* selected text in a window.
|
||||
*/
|
||||
function sendContextMenuClickToSelection(aWindow) {
|
||||
let selection = aWindow.getSelection();
|
||||
if (!selection || !selection.rangeCount) {
|
||||
ok(false, "no selection to tap!");
|
||||
return;
|
||||
}
|
||||
let range = selection.getRangeAt(0);
|
||||
let rect = range.getBoundingClientRect();
|
||||
let x = rect.left + (rect.width / 2);
|
||||
let y = rect.top + (rect.height / 2);
|
||||
let utils = aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||
utils.sendMouseEventToWindow("contextmenu", x, y, 2, 1, 0, true,
|
||||
1, Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH);
|
||||
}
|
||||
|
||||
/*
|
||||
* sendContextMenuClickToWindow - simulates a press-hold touch input event.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче