Bug 565717 - "Search for" context menu entry should be in textareas/inputs too. r=gavin.sharp

This commit is contained in:
OHZEKI Tetsuharu 2011-04-24 12:15:53 -04:00
Родитель 06b33bf856
Коммит da6300702b
8 изменённых файлов: 82 добавлений и 13 удалений

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

@ -292,9 +292,9 @@
oncommand="gContextMenu.viewInfo();"/>
<menuseparator id="spell-separator"/>
<menuitem id="spell-check-enabled"
label="&spellCheckEnable.label;"
label="&spellCheckToggle.label;"
type="checkbox"
accesskey="&spellCheckEnable.accesskey;"
accesskey="&spellCheckToggle.accesskey;"
oncommand="InlineSpellCheckerUI.toggleEnabled();"/>
<menuitem id="spell-add-dictionaries-main"
label="&spellAddDictionaries.label;"

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

@ -5127,9 +5127,25 @@ function getBrowserSelection(aCharLen) {
// selections of more than 150 characters aren't useful
const kMaxSelectionLen = 150;
const charLen = Math.min(aCharLen || kMaxSelectionLen, kMaxSelectionLen);
let commandDispatcher = document.commandDispatcher;
var focusedWindow = document.commandDispatcher.focusedWindow;
var focusedWindow = commandDispatcher.focusedWindow;
var selection = focusedWindow.getSelection().toString();
// try getting a selected text in text input.
if (!selection) {
let element = commandDispatcher.focusedElement;
function isOnTextInput(elem) {
// we avoid to return a value if a selection is in password field.
// ref. bug 565717
return elem instanceof HTMLTextAreaElement ||
(elem instanceof HTMLInputElement && elem.mozIsTextField(true));
};
if (isOnTextInput(element)) {
selection = element.QueryInterface(Ci.nsIDOMNSEditableElement)
.editor.selection.toString();
}
}
if (selection) {
if (selection.length > charLen) {

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

@ -1249,12 +1249,12 @@ nsContextMenu.prototype = {
engineName = ss.defaultEngine.name;
// format "Search <engine> for <selection>" string to show in menu
var menuLabel = gNavigatorBundle.getFormattedString("contextMenuSearchText",
var menuLabel = gNavigatorBundle.getFormattedString("contextMenuSearch",
[engineName,
selectedText]);
document.getElementById("context-searchselect").label = menuLabel;
document.getElementById("context-searchselect").accessKey =
gNavigatorBundle.getString("contextMenuSearchText.accesskey");
gNavigatorBundle.getString("contextMenuSearch.accesskey");
return true;
},

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

@ -63,6 +63,7 @@ Browser context menu subtest.
<div id="test-select-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</div>
<div id="test-select-text-link">http://mozilla.com</div>
<a id="test-image-link" href="#"><img src="ctxmenu-image.png"></a>
<input id="test-select-input-text" type="text" value="input">
<input id="test-select-input-text-type-password" type="password" value="password">
</body>
</html>

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

@ -81,6 +81,13 @@ function selectText(element) {
subwindow.getSelection().addRange(div);
}
function selectInputText(element) {
// Clear any previous selections before selecting new element.
subwindow.getSelection().removeAllRanges();
element.select();
}
function getVisibleMenuItems(aMenu, aData) {
var items = [];
var accessKeys = {};
@ -783,7 +790,50 @@ function runTest(testNum) {
"context-viewimageinfo", true
].concat(inspectItems));
closeContextMenu();
selectInputText(select_inputtext); // Select text prior to opening context menu.
openContextMenuFor(select_inputtext); // Invoke context menu for next test.
return;
case 27:
// Context menu for selected text in input
checkContextMenu(["context-undo", 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
].concat(inspectItems));
closeContextMenu();
selectInputText(select_inputtext_password); // Select text prior to opening context menu.
openContextMenuFor(select_inputtext_password); // Invoke context menu for next test.
return;
case 28:
// Context menu for selected text in input[type="password"]
checkContextMenu(["context-undo", false,
"---", null,
"context-cut", true,
"context-copy", true,
"context-paste", null, // ignore clipboard state
"context-delete", true,
"---", null,
"context-selectall", true,
"---", null,
"spell-check-enabled", true,
//spell checker is shown on input[type="password"] on this testcase
"spell-dictionaries", true,
["spell-check-dictionary-en-US", true,
"---", null,
"spell-add-dictionaries", true], null
].concat(inspectItems));
closeContextMenu();
// finish test
subwindow.close();
SimpleTest.finish();
return;
@ -810,7 +860,7 @@ var subwindow, chromeWin, contextMenu, lastElement;
var text, link, mailto, input, img, canvas, video_ok, video_bad, video_bad2,
iframe, video_in_iframe, image_in_iframe, textarea, contenteditable,
inputspell, pagemenu, dom_full_screen, plainTextItems, audio_in_video,
imagelink;
selecttext, selecttextlink, imagelink, select_inputtext, select_inputtext_password;
function startTest() {
chromeWin = SpecialPowers.wrap(subwindow)
@ -856,6 +906,8 @@ function startTest() {
dom_full_screen = subwindow.document.getElementById("test-dom-full-screen");
selecttext = subwindow.document.getElementById("test-select-text");
selecttextlink = subwindow.document.getElementById("test-select-text-link");
select_inputtext = subwindow.document.getElementById("test-select-input-text");
select_inputtext_password = subwindow.document.getElementById("test-select-input-text-type-password");
contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false);
runTest(1);

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

@ -10,10 +10,10 @@ droponhomemsg=Do you want this document to be your new home page?
# context menu strings
# LOCALIZATION NOTE (contextMenuSearchText): %1$S is the search engine,
# LOCALIZATION NOTE (contextMenuSearch): %1$S is the search engine,
# %2$S is the selection string.
contextMenuSearchText=Search %1$S for "%2$S"
contextMenuSearchText.accesskey=S
contextMenuSearch=Search %1$S for "%2$S"
contextMenuSearch.accesskey=S
# bookmark dialog strings

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

@ -541,7 +541,7 @@
<xul:menuseparator/>
<xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/>
<xul:menuseparator anonid="spell-check-separator"/>
<xul:menuitem label="&spellCheckEnable.label;" type="checkbox" accesskey="&spellCheckEnable.accesskey;" anonid="spell-check-enabled"
<xul:menuitem label="&spellCheckToggle.label;" type="checkbox" accesskey="&spellCheckToggle.accesskey;" anonid="spell-check-enabled"
oncommand="this.parentNode.parentNode.spellCheckerUI.toggleEnabled();"/>
<xul:menu label="&spellDictionaries.label;" accesskey="&spellDictionaries.accesskey;" anonid="spell-dictionaries">
<xul:menupopup anonid="spell-dictionaries-menu"

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

@ -19,8 +19,8 @@
<!ENTITY spellAddToDictionary.accesskey "o">
<!ENTITY spellUndoAddToDictionary.label "Undo Add To Dictionary">
<!ENTITY spellUndoAddToDictionary.accesskey "n">
<!ENTITY spellCheckEnable.label "Check Spelling">
<!ENTITY spellCheckEnable.accesskey "S">
<!ENTITY spellCheckToggle.label "Check Spelling">
<!ENTITY spellCheckToggle.accesskey "g">
<!ENTITY spellNoSuggestions.label "(No Spelling Suggestions)">
<!ENTITY spellDictionaries.label "Languages">
<!ENTITY spellDictionaries.accesskey "l">