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 = [
'keyup',
'keydown',
'keypress',
'mouseup',
'mousedown',
'mouseover',

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

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

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

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

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

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

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

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

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

@ -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();
}