Bug 807326 - Context menu Search should be available in textareas/inputs as well. Port |Bug 565717|. r=Neil

This commit is contained in:
Edmund Wong 2013-03-02 11:10:40 +08:00
Родитель 64b96b3bfa
Коммит f10c134a0a
4 изменённых файлов: 88 добавлений и 26 удалений

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

@ -10,6 +10,7 @@ Browser context menu subtest.
<a id="test-link" href="http://mozilla.com">Click the monkey!</a>
<a id="test-mailto" href="mailto:codemonkey@mozilla.com">Mail the monkey!</a><br>
<input id="test-input"><br>
<input id="test-input-select"><br>
<img id="test-image" src="ctxmenu-image.png">
<canvas id="test-canvas" width="100" height="100" style="background-color: blue"></canvas>
<video controls id="test-video-ok" src="video.ogg" width="100" height="100" style="background-color: green"></video>
@ -22,6 +23,7 @@ Browser context menu subtest.
<iframe id="test-video-in-iframe" src="video.ogg" width="98" height="98" style="border: 1px solid black"></iframe>
<iframe id="test-image-in-iframe" src="ctxmenu-image.png" width="98" height="98" style="border: 1px solid black"></iframe>
<textarea id="test-textarea">chssseesbbbie</textarea> <!-- a weird word which generates only one suggestion -->
<textarea id="test-textarea-sel">test</textarea>
<div id="test-contenteditable" contenteditable="true">chssseefsbbbie</div> <!-- a more weird word which generates no suggestions -->
<input id="test-input-spellcheck" type="text" spellcheck="true" autofocus value="prodkjfgigrty"> <!-- this one also generates one suggestion -->
<div contextmenu="myMenu">

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

@ -319,10 +319,32 @@ function runTest(testNum) {
"---", null,
"spell-check-enabled", true]);
closeContextMenu();
openContextMenuFor(img); // Invoke context menu for next test.
input_sel.value = "test";
input_sel.select();
openContextMenuFor(input_sel); // Invoke context menu for next test.
break;
case 6:
// Context menu for text input field with text
checkContextMenu(["popupwindow-reject", true,
"---", null,
"context-undo", false,
"context-redo", false,
"---", null,
"context-cut", true,
"context-copy", true,
"context-paste", null, // ignore clipboard state
"context-delete", true,
"---", null,
"context-selectall", true,
"context-searchselect", true,
"---", null,
"spell-check-enabled", true]);
closeContextMenu();
openContextMenuFor(img); // Invoke context menu for next test.
break;
case 7:
// Context menu for an image
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -345,7 +367,7 @@ function runTest(testNum) {
openContextMenuFor(canvas); // Invoke context menu for next test.
break;
case 7:
case 8:
// Context menu for a canvas
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -358,7 +380,7 @@ function runTest(testNum) {
openContextMenuFor(video_ok); // Invoke context menu for next test.
break;
case 8:
case 9:
// Context menu for a video (with a VALID media source)
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -378,7 +400,7 @@ function runTest(testNum) {
openContextMenuFor(audio_in_video); // Invoke context menu for next test.
break;
case 9:
case 10:
// Context menu for a video (with an audio-only file)
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -394,7 +416,7 @@ function runTest(testNum) {
openContextMenuFor(video_bad); // Invoke context menu for next test.
break;
case 10:
case 11:
// Context menu for a video (with an INVALID media source)
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -414,7 +436,7 @@ function runTest(testNum) {
openContextMenuFor(video_bad2); // Invoke context menu for next test.
break;
case 11:
case 12:
// Context menu for a video (with an INVALID media source)
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -434,7 +456,7 @@ function runTest(testNum) {
openContextMenuFor(iframe); // Invoke context menu for next test.
break;
case 12:
case 13:
// Context menu for an iframe
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -470,7 +492,7 @@ function runTest(testNum) {
openContextMenuFor(video_in_iframe); // Invoke context menu for next test.
break;
case 13:
case 14:
// Context menu for a video in an iframe
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -504,7 +526,7 @@ function runTest(testNum) {
openContextMenuFor(image_in_iframe); // Invoke context menu for next test.
break;
case 14:
case 15:
// Context menu for an image in an iframe
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -541,14 +563,39 @@ function runTest(testNum) {
openContextMenuFor(text); // Invoke context menu for next test.
break;
case 15:
case 16:
// Re-check context menu for plain text to make sure it hasn't changed
checkContextMenu(plainTextItems);
closeContextMenu();
textarea_sel.select();
openContextMenuFor(textarea_sel, false, true);
break;
case 17:
// search for text with text area's selected value
checkContextMenu(["popupwindow-reject", true,
"---", null,
"context-undo", false,
"context-redo", false,
"---", null,
"context-cut", true,
"context-copy", true,
"context-paste", true, // ignore clipboard state
"context-delete", true,
"---", null,
"context-selectall", true,
"context-searchselect", true,
"---", null,
"spell-check-enabled", true,
"spell-dictionaries", true,
["spell-check-dictionary-en-US", true,
"---", null,
"spell-add-dictionaries", true], null]);
closeContextMenu();
openContextMenuFor(textarea, false, true); // Invoke context menu for next test, but wait for the spellcheck.
break;
case 16:
case 18:
// Context menu for textarea
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -578,7 +625,7 @@ function runTest(testNum) {
openContextMenuFor(textarea, false, true); // Invoke context menu for next test.
break;
case 17:
case 19:
// Context menu for textarea after a word has been added
// to the dictionary
checkContextMenu(["popupwindow-reject", true,
@ -607,7 +654,7 @@ function runTest(testNum) {
openContextMenuFor(contenteditable);
break;
case 18:
case 20:
// Context menu for contenteditable
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -636,7 +683,7 @@ function runTest(testNum) {
openContextMenuFor(inputspell); // Invoke context menu for next test.
break;
case 19:
case 21:
// Context menu for spell-check input
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -665,13 +712,13 @@ function runTest(testNum) {
openContextMenuFor(link); // Invoke context menu for next test.
break;
case 20:
case 22:
executeCopyCommand("cmd_copyLink", "http://mozilla.com/");
closeContextMenu();
openContextMenuFor(pagemenu); // Invoke context menu for next test.
break;
case 21:
case 23:
// Context menu for element with assigned content context menu
checkContextMenu(["+Plain item", {type: "", icon: "", checked: false, disabled: false},
"+Disabled item", {type: "", icon: "", checked: false, disabled: true},
@ -715,7 +762,7 @@ function runTest(testNum) {
openContextMenuFor(pagemenu, true); // Invoke context menu for next test.
break;
case 22:
case 24:
// Context menu for element with assigned content context menu
// The shift key should bypass content context menu processing
checkContextMenu(["popupwindow-reject", true,
@ -740,7 +787,7 @@ function runTest(testNum) {
openContextMenuFor(img_link); // Invoke context menu for next test.
break;
case 23:
case 25:
// Context menu for an image with a link
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -769,7 +816,7 @@ function runTest(testNum) {
openContextMenuFor(img_mailto); // Invoke context menu for next test.
break;
case 24:
case 26:
// Context menu for an image with a mailto: link
checkContextMenu(["popupwindow-reject", true,
"---", null,
@ -846,6 +893,7 @@ function startTest() {
link = subwindow.document.getElementById("test-link");
mailto = subwindow.document.getElementById("test-mailto");
input = subwindow.document.getElementById("test-input");
input_sel = subwindow.document.getElementById("test-input-select");
img = subwindow.document.getElementById("test-image");
canvas = subwindow.document.getElementById("test-canvas");
video_ok = subwindow.document.getElementById("test-video-ok");
@ -858,6 +906,7 @@ function startTest() {
video_in_iframe.pause();
image_in_iframe = subwindow.document.getElementById("test-image-in-iframe").contentDocument.getElementsByTagName("img")[0];
textarea = subwindow.document.getElementById("test-textarea");
textarea_sel = subwindow.document.getElementById("test-textarea-sel");
contenteditable = subwindow.document.getElementById("test-contenteditable");
contenteditable.focus(); // content editable needs to be focused to enable spellcheck
inputspell = subwindow.document.getElementById("test-input-spellcheck");

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

@ -245,7 +245,7 @@ nsContextMenu.prototype = {
!(this.isContentSelected || this.onTextInput ||
this.onStandaloneImage || this.onVideo || this.onAudio));
this.showItem("context-bookmarklink", this.onLink && !this.onMailtoLink);
this.showItem("context-searchselect", this.isTextSelected && !this.onTextInput);
this.showItem("context-searchselect", this.isTextSelected);
this.showItem("context-keywordfield", this.onTextInput && this.onKeywordField);
this.showItem("frame", this.inFrame);
this.showItem("frame-sep", this.inFrame);
@ -1251,6 +1251,7 @@ nsContextMenu.prototype = {
*/
isTextSelection: function() {
var searchSelectText = this.searchSelected(16);
if (!searchSelectText)
return false;
@ -1269,11 +1270,11 @@ nsContextMenu.prototype = {
// format "Search <engine> for <selection>" string to show in menu
const bundle = document.getElementById("contentAreaCommandsBundle");
var menuLabel = bundle.getFormattedString("contextMenuSearchText",
var menuLabel = bundle.getFormattedString("searchSelected",
[engineName, searchSelectText]);
this.setItemAttr("context-searchselect", "label", menuLabel);
this.setItemAttr("context-searchselect", "accesskey",
bundle.getString("contextMenuSearchText.accesskey"));
bundle.getString("searchSelected.accesskey"));
return true;
},
@ -1282,6 +1283,16 @@ nsContextMenu.prototype = {
var focusedWindow = document.commandDispatcher.focusedWindow;
var searchStr = focusedWindow.getSelection();
searchStr = searchStr.toString();
if (this.onTextInput) {
var fElem = this.target;
if ((fElem instanceof HTMLInputElement &&
fElem.mozIsTextField(true)) ||
fElem instanceof HTMLTextAreaElement) {
searchStr = fElem.value.substring(fElem.selectionStart, fElem.selectionEnd);
}
}
// searching for more than 150 chars makes no sense
if (!aCharlen)
aCharlen = 150;

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

@ -4,10 +4,10 @@
# context menu strings
# LOCALIZATION NOTE (contextMenuSearchText): %1$S is the search engine,
# LOCALIZATION NOTE (searchSelected): %1$S is the search engine,
# %2$S is the selection string.
contextMenuSearchText=Search %1$S for "%2$S"
contextMenuSearchText.accesskey=S
searchSelected=Search %1$S for "%2$S"
searchSelected.accesskey=e
blockImage=Block Images from %S
blockImage.accesskey=c