Bug 597399 - Panorama: Typing in a digit when the search box isn't displayed produces letter in the box [r=ian, a=blocking2.0]

--HG--
extra : rebase_source : eedb975c38bf3adf82f5329d7f69bee5b233238e
This commit is contained in:
Raymond Lee 2010-11-17 18:49:59 +08:00
Родитель dd3ee4613e
Коммит d75816f987
6 изменённых файлов: 129 добавлений и 47 удалений

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

@ -699,6 +699,7 @@ iQClass.prototype = {
let events = [ let events = [
'keyup', 'keyup',
'keydown', 'keydown',
'keypress',
'mouseup', 'mouseup',
'mousedown', 'mousedown',
'mouseover', 'mouseover',

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

@ -335,9 +335,9 @@ SearchEventHandlerClass.prototype = {
// Handles all keypresses before the search interface is brought up. // Handles all keypresses before the search interface is brought up.
beforeSearchKeyHandler: function (event) { beforeSearchKeyHandler: function (event) {
// Only match reasonable text-like characters for quick search. // Only match reasonable text-like characters for quick search.
var key = String.fromCharCode(event.which);
// TODO: Also include funky chars. Bug 593904 // TODO: Also include funky chars. Bug 593904
if (!key.match(/[A-Z0-9]/) || event.altKey || event.ctrlKey || event.metaKey) if (!String.fromCharCode(event.which).match(/[a-zA-Z0-9]/) || event.altKey ||
event.ctrlKey || event.metaKey)
return; return;
// If we are already in an input field, allow typing as normal. // If we are already in an input field, allow typing as normal.
@ -353,16 +353,17 @@ SearchEventHandlerClass.prototype = {
// Handles all keypresses while search mode. // Handles all keypresses while search mode.
inSearchKeyHandler: function (event) { inSearchKeyHandler: function (event) {
var term = iQ("#searchbox").val(); var term = iQ("#searchbox").val();
if (event.which == event.DOM_VK_ESCAPE) if ((event.keyCode == event.DOM_VK_ESCAPE) ||
hideSearch(event); (event.keyCode == event.DOM_VK_BACK_SPACE && term.length <= 1)) {
if (event.which == event.DOM_VK_BACK_SPACE && term.length <= 1)
hideSearch(event); hideSearch(event);
return;
}
var matcher = new TabMatcher(term); var matcher = new TabMatcher(term);
var matches = matcher.matched(); var matches = matcher.matched();
var others = matcher.matchedTabsFromOtherWindows(); var others = matcher.matchedTabsFromOtherWindows();
if (event.which == event.DOM_VK_RETURN && (matches.length > 0 || others.length > 0)) { if (event.keyCode == event.DOM_VK_RETURN && (matches.length > 0 || others.length > 0)) {
hideSearch(event); hideSearch(event);
if (matches.length > 0) if (matches.length > 0)
matches[0].zoomIn(); matches[0].zoomIn();
@ -378,9 +379,9 @@ SearchEventHandlerClass.prototype = {
switchToBeforeMode: function switchToBeforeMode() { switchToBeforeMode: function switchToBeforeMode() {
var self = this; var self = this;
if (this.currentHandler) if (this.currentHandler)
iQ(document).unbind("keydown", this.currentHandler); iQ(window).unbind("keypress", this.currentHandler);
this.currentHandler = function(event) self.beforeSearchKeyHandler(event); this.currentHandler = function(event) self.beforeSearchKeyHandler(event);
iQ(document).keydown(self.currentHandler); iQ(window).keypress(this.currentHandler);
}, },
// ---------- // ----------
@ -390,9 +391,9 @@ SearchEventHandlerClass.prototype = {
switchToInMode: function switchToInMode() { switchToInMode: function switchToInMode() {
var self = this; var self = this;
if (this.currentHandler) if (this.currentHandler)
iQ(document).unbind("keydown", this.currentHandler); iQ(window).unbind("keypress", this.currentHandler);
this.currentHandler = function(event) self.inSearchKeyHandler(event); this.currentHandler = function(event) self.inSearchKeyHandler(event);
iQ(document).keydown(self.currentHandler); iQ(window).keypress(this.currentHandler);
} }
}; };
@ -488,13 +489,13 @@ function hideSearch(event){
event.stopPropagation(); event.stopPropagation();
} }
let newEvent = document.createEvent("Events");
newEvent.initEvent("tabviewsearchdisabled", false, false);
dispatchEvent(newEvent);
// Return focus to the tab window // Return focus to the tab window
UI.blurAll(); UI.blurAll();
gTabViewFrame.contentWindow.focus(); gTabViewFrame.contentWindow.focus();
let newEvent = document.createEvent("Events");
newEvent.initEvent("tabviewsearchdisabled", false, false);
dispatchEvent(newEvent);
} }
function performSearch() { function performSearch() {
@ -513,13 +514,13 @@ function ensureSearchShown(event){
var $search = iQ("#search"); var $search = iQ("#search");
var $searchbox = iQ("#searchbox"); var $searchbox = iQ("#searchbox");
iQ("#searchbutton").css({ opacity: 1 }); iQ("#searchbutton").css({ opacity: 1 });
if ($search.css("display") == "none") { if (!isSearchEnabled()) {
$search.show(); $search.show();
var mainWindow = gWindow.document.getElementById("main-window"); var mainWindow = gWindow.document.getElementById("main-window");
mainWindow.setAttribute("activetitlebarcolor", "#717171"); mainWindow.setAttribute("activetitlebarcolor", "#717171");
// Marshal the focusing, otherwise you end up with // Marshal the focusing, otherwise you end up with
// a race condition where only sometimes would the // a race condition where only sometimes would the
// first keystroke be registered by the search box. // first keystroke be registered by the search box.
@ -529,18 +530,20 @@ function ensureSearchShown(event){
$searchbox[0].focus(); $searchbox[0].focus();
$searchbox[0].val = '0'; $searchbox[0].val = '0';
$searchbox.css({"z-index":"1015"}); $searchbox.css({"z-index":"1015"});
if (event != null){ if (event != null)
var keyCode = event.which + (event.shiftKey ? 0 : 32); $searchbox.val(String.fromCharCode(event.charCode));
$searchbox.val(String.fromCharCode(keyCode));
}
}, 0);
let newEvent = document.createEvent("Events"); let newEvent = document.createEvent("Events");
newEvent.initEvent("tabviewsearchenabled", false, false); newEvent.initEvent("tabviewsearchenabled", false, false);
dispatchEvent(newEvent); dispatchEvent(newEvent);
}, 0);
} }
} }
function isSearchEnabled() {
return iQ("#search").css("display") != "none";
}
var SearchEventHandler = new SearchEventHandlerClass(); var SearchEventHandler = new SearchEventHandlerClass();
// Features to add: // Features to add:

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

@ -843,11 +843,16 @@ let UI = {
var self = this; var self = this;
iQ(window).keyup(function(event) { iQ(window).keyup(function(event) {
if (!event.metaKey) Keys.meta = false; if (!event.metaKey)
Keys.meta = false;
}); });
iQ(window).keydown(function(event) { iQ(window).keydown(function(event) {
if (event.metaKey) Keys.meta = true; if (event.metaKey)
Keys.meta = true;
if (isSearchEnabled())
return;
function getClosestTabBy(norm) { function getClosestTabBy(norm) {
if (!self.getActiveTab()) if (!self.getActiveTab())

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

@ -60,6 +60,7 @@ _BROWSER_FILES = \
browser_tabview_bug595804.js \ browser_tabview_bug595804.js \
browser_tabview_bug595930.js \ browser_tabview_bug595930.js \
browser_tabview_bug595943.js \ browser_tabview_bug595943.js \
browser_tabview_bug597399.js \
browser_tabview_bug598600.js \ browser_tabview_bug598600.js \
browser_tabview_bug599626.js \ browser_tabview_bug599626.js \
browser_tabview_dragdrop.js \ browser_tabview_dragdrop.js \

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

@ -55,10 +55,10 @@ function onTabViewWindowLoaded() {
ok(searchButton, "Search button exists"); ok(searchButton, "Search button exists");
let onSearchEnabled = function() { let onSearchEnabled = function() {
let search = contentWindow.document.getElementById("search");
ok(search.style.display != "none", "Search is enabled");
contentWindow.removeEventListener( contentWindow.removeEventListener(
"tabviewsearchenabled", onSearchEnabled, false); "tabviewsearchenabled", onSearchEnabled, false);
let search = contentWindow.document.getElementById("search");
ok(search.style.display != "none", "Search is enabled");
escapeTest(contentWindow); escapeTest(contentWindow);
} }
contentWindow.addEventListener("tabviewsearchenabled", onSearchEnabled, contentWindow.addEventListener("tabviewsearchenabled", onSearchEnabled,
@ -70,21 +70,16 @@ function onTabViewWindowLoaded() {
function escapeTest(contentWindow) { function escapeTest(contentWindow) {
let onSearchDisabled = function() { let onSearchDisabled = function() {
let search = contentWindow.document.getElementById("search");
ok(search.style.display == "none", "Search is disabled");
contentWindow.removeEventListener( contentWindow.removeEventListener(
"tabviewsearchdisabled", onSearchDisabled, false); "tabviewsearchdisabled", onSearchDisabled, false);
let search = contentWindow.document.getElementById("search");
ok(search.style.display == "none", "Search is disabled");
toggleTabViewTest(contentWindow); toggleTabViewTest(contentWindow);
} }
contentWindow.addEventListener("tabviewsearchdisabled", onSearchDisabled, contentWindow.addEventListener("tabviewsearchdisabled", onSearchDisabled,
false); false);
// the search box focus()es in a function on the timeout queue, so we just EventUtils.synthesizeKey("VK_ESCAPE", { type: "keypress" }, contentWindow);
// want to queue behind it.
setTimeout( function() {
EventUtils.synthesizeKey("VK_ESCAPE", {});
}, 0);
} }
function toggleTabViewTest(contentWindow) { function toggleTabViewTest(contentWindow) {
@ -92,14 +87,9 @@ function toggleTabViewTest(contentWindow) {
contentWindow.removeEventListener("tabviewhidden", onTabViewHidden, false); contentWindow.removeEventListener("tabviewhidden", onTabViewHidden, false);
ok(!TabView.isVisible(), "Tab View is hidden"); ok(!TabView.isVisible(), "Tab View is hidden");
finish(); finish();
} }
contentWindow.addEventListener("tabviewhidden", onTabViewHidden, false); contentWindow.addEventListener("tabviewhidden", onTabViewHidden, false);
// When search is hidden, it focus()es on the background, so avert the // Use keyboard shortcut to toggle back to browser view
// race condition by delaying ourselves on the timeout queue EventUtils.synthesizeKey("e", { accelKey: true });
setTimeout( function() {
// Use keyboard shortcut to toggle back to browser view
EventUtils.synthesizeKey("e", { accelKey: true });
}, 0);
} }

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

@ -0,0 +1,82 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is a test for bug 597399.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Raymond Lee <raymond@appcoast.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
function test() {
waitForExplicitFinish();
window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
TabView.toggle();
}
function onTabViewWindowLoaded() {
window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
let contentWindow = document.getElementById("tab-view").contentWindow;
let number = -1;
let onSearchEnabled = function() {
let searchBox = contentWindow.document.getElementById("searchbox");
is(searchBox.value, number, "The seach box matches the number: " + number);
contentWindow.hideSearch(null);
}
let onSearchDisabled = function() {
if (++number <= 9) {
EventUtils.synthesizeKey(String(number), { }, contentWindow);
} else {
contentWindow.removeEventListener(
"tabviewsearchenabled", onSearchEnabled, false);
contentWindow.removeEventListener(
"tabviewsearchdisabled", onSearchDisabled, false);
let endGame = function() {
window.removeEventListener("tabviewhidden", endGame, false);
ok(!TabView.isVisible(), "Tab View is hidden");
finish();
}
window.addEventListener("tabviewhidden", endGame, false);
TabView.toggle();
}
}
contentWindow.addEventListener(
"tabviewsearchenabled", onSearchEnabled, false);
contentWindow.addEventListener(
"tabviewsearchdisabled", onSearchDisabled, false);
onSearchDisabled();
}