mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 23:05:42 +00:00
Bug 1338898 fix 150 char limit for context menu text selection, r=aswan,mattw
MozReview-Commit-ID: IqECfaFSbGZ --HG-- extra : rebase_source : 312c3887d16d4b4dd0bf96fd77e4ec970a8d6393
This commit is contained in:
parent
acb0601c26
commit
5a4e0a5450
@ -116,7 +116,7 @@ nsContextMenu.prototype = {
|
||||
pageUrl: this.browser ? this.browser.currentURI.spec : undefined,
|
||||
linkText: this.linkTextStr,
|
||||
linkUrl: this.linkURL,
|
||||
selectionText: this.isTextSelected ? this.selectionInfo.text : undefined,
|
||||
selectionText: this.isTextSelected ? this.selectionInfo.fullText : undefined,
|
||||
frameId: this.frameOuterWindowID,
|
||||
};
|
||||
subject.wrappedJSObject = subject;
|
||||
|
@ -177,7 +177,7 @@ var gMenuBuilder = {
|
||||
let label = item.title;
|
||||
if (label) {
|
||||
if (contextData.isTextSelected && label.indexOf("%s") > -1) {
|
||||
let selection = contextData.selectionText;
|
||||
let selection = contextData.selectionText.trim();
|
||||
// The rendering engine will truncate the title if it's longer than 64 characters.
|
||||
// But if it makes sense let's try truncate selection text only, to handle cases like
|
||||
// 'look up "%s" in MyDictionary' more elegantly.
|
||||
|
@ -59,6 +59,13 @@ add_task(async function() {
|
||||
},
|
||||
|
||||
background: async function() {
|
||||
browser.test.onMessage.addListener(msg => {
|
||||
if (msg == "removeall") {
|
||||
browser.contextMenus.removeAll();
|
||||
browser.test.sendMessage("removed");
|
||||
}
|
||||
});
|
||||
|
||||
// A generic onclick callback function.
|
||||
function genericOnClick(info, tab) {
|
||||
browser.test.sendMessage("onclick", {info, tab});
|
||||
@ -86,10 +93,7 @@ add_task(async function() {
|
||||
if (context == "selection") {
|
||||
browser.contextMenus.update("ext-selection", {
|
||||
title: "selection is: '%s'",
|
||||
onclick: (info, tab) => {
|
||||
browser.contextMenus.removeAll();
|
||||
genericOnClick(info, tab);
|
||||
},
|
||||
onclick: genericOnClick,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -290,7 +294,7 @@ add_task(async function() {
|
||||
expectedClickInfo = {
|
||||
menuItemId: "ext-selection",
|
||||
pageUrl: PAGE,
|
||||
selectionText: "just some text 1234567890123456789012345678901234567890123456789012345678901234567890123456789012",
|
||||
selectionText: " just some text 1234567890123456789012345678901234567890123456789012345678901234567890123456789012",
|
||||
};
|
||||
|
||||
result = await extension.awaitMessage("onclick");
|
||||
@ -298,6 +302,72 @@ add_task(async function() {
|
||||
result = await extension.awaitMessage("browser.contextMenus.onClicked");
|
||||
checkClickInfo(result);
|
||||
|
||||
// Select a lot of text
|
||||
await ContentTask.spawn(gBrowser.selectedBrowser, { }, function* (arg) {
|
||||
let doc = content.document;
|
||||
let range = doc.createRange();
|
||||
let selection = content.getSelection();
|
||||
selection.removeAllRanges();
|
||||
let textNode = doc.getElementById("longtext").firstChild;
|
||||
range.setStart(textNode, 0);
|
||||
range.setEnd(textNode, textNode.length);
|
||||
selection.addRange(range);
|
||||
});
|
||||
|
||||
// Bring up context menu again
|
||||
extensionMenuRoot = await openExtensionContextMenu("#longtext");
|
||||
|
||||
// Check some menu items
|
||||
items = extensionMenuRoot.getElementsByAttribute("label", "selection is: 'Sed ut perspiciatis unde omnis iste natus err...'");
|
||||
is(items.length, 1, `contextMenu item for longtext selection was found (context=selection)`);
|
||||
await closeExtensionContextMenu(items[0]);
|
||||
|
||||
expectedClickInfo = {
|
||||
menuItemId: "ext-selection",
|
||||
pageUrl: PAGE,
|
||||
};
|
||||
|
||||
result = await extension.awaitMessage("onclick");
|
||||
checkClickInfo(result);
|
||||
result = await extension.awaitMessage("browser.contextMenus.onClicked");
|
||||
checkClickInfo(result);
|
||||
ok(result.info.selectionText.endsWith("quo voluptas nulla pariatur?"), "long text selection worked");
|
||||
|
||||
|
||||
// Select a lot of text, excercise the nsIDOMNSEditableElement code path in
|
||||
// the Browser:GetSelection handler.
|
||||
await ContentTask.spawn(gBrowser.selectedBrowser, { }, function(arg) {
|
||||
let doc = content.document;
|
||||
let node = doc.getElementById("editabletext");
|
||||
// content.js handleContentContextMenu fails intermittently without focus.
|
||||
node.focus();
|
||||
node.selectionStart = 0;
|
||||
node.selectionEnd = 844;
|
||||
});
|
||||
|
||||
// Bring up context menu again
|
||||
extensionMenuRoot = await openExtensionContextMenu("#editabletext");
|
||||
|
||||
// Check some menu items
|
||||
items = extensionMenuRoot.getElementsByAttribute("label", "editable");
|
||||
is(items.length, 1, "contextMenu item for text input element was found (context=editable)");
|
||||
await closeExtensionContextMenu(items[0]);
|
||||
|
||||
expectedClickInfo = {
|
||||
menuItemId: "ext-editable",
|
||||
editable: true,
|
||||
pageUrl: PAGE,
|
||||
};
|
||||
|
||||
result = await extension.awaitMessage("onclick");
|
||||
checkClickInfo(result);
|
||||
result = await extension.awaitMessage("browser.contextMenus.onClicked");
|
||||
checkClickInfo(result);
|
||||
ok(result.info.selectionText.endsWith("perferendis doloribus asperiores repellat."), "long text selection worked");
|
||||
|
||||
extension.sendMessage("removeall");
|
||||
await extension.awaitMessage("removed");
|
||||
|
||||
let contentAreaContextMenu = await openContextMenu("#img1");
|
||||
items = contentAreaContextMenu.getElementsByAttribute("ext-type", "top-level-menu");
|
||||
is(items.length, 0, "top level item was not found (after removeAll()");
|
||||
|
@ -1,3 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
@ -20,6 +21,20 @@
|
||||
<input type="text" id="edit-me"><br>
|
||||
<input type="password" id="password">
|
||||
</p>
|
||||
<iframe id="frame" src="context_frame.html"/>
|
||||
<iframe id="frame" src="context_frame.html"></iframe>
|
||||
<p id="longtext">Sed ut perspiciatis unde omnis iste natus error sit
|
||||
voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque
|
||||
ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta
|
||||
sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut
|
||||
odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem
|
||||
sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit
|
||||
amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora
|
||||
incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad
|
||||
minima veniam, quis nostrum exercitationem ullam corporis suscipit
|
||||
laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
|
||||
iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
|
||||
consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
|
||||
|
||||
<input id="editabletext" type="text" value="At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat." />
|
||||
</body>
|
||||
</html>
|
||||
|
@ -414,6 +414,7 @@ this.BrowserUtils = {
|
||||
|
||||
let selection = focusedWindow.getSelection();
|
||||
let selectionStr = selection.toString();
|
||||
let fullText;
|
||||
|
||||
let collapsed = selection.isCollapsed;
|
||||
|
||||
@ -482,6 +483,10 @@ this.BrowserUtils = {
|
||||
}
|
||||
|
||||
if (selectionStr) {
|
||||
// Pass up to 16K through unmolested. If an add-on needs more, they will
|
||||
// have to use a content script.
|
||||
fullText = selectionStr.substr(0, 16384);
|
||||
|
||||
if (selectionStr.length > charLen) {
|
||||
// only use the first charLen important chars. see bug 221361
|
||||
var pattern = new RegExp("^(?:\\s*.){0," + charLen + "}");
|
||||
@ -500,7 +505,7 @@ this.BrowserUtils = {
|
||||
url = null;
|
||||
}
|
||||
|
||||
return { text: selectionStr, docSelectionIsCollapsed: collapsed,
|
||||
return { text: selectionStr, docSelectionIsCollapsed: collapsed, fullText,
|
||||
linkURL: url ? url.spec : null, linkText: url ? linkText : "" };
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user