зеркало из https://github.com/mozilla/gecko-dev.git
Bug 595560 - Make / and Ctrl-f TabCandy search shortcuts, have Panorama shortcut act like return [r=dolske, a=beltzner]
This commit is contained in:
Родитель
3516a53948
Коммит
90e6d09462
|
@ -80,7 +80,7 @@
|
|||
<command id="View:PageInfo" oncommand="BrowserPageInfo();"/>
|
||||
<command id="View:FullScreen" oncommand="BrowserFullScreen();"/>
|
||||
<command id="cmd_find"
|
||||
oncommand="gFindBar.onFindCommand();"
|
||||
oncommand="if (TabView.isVisible()) TabView.enableSearch(event); else gFindBar.onFindCommand();"
|
||||
observes="isImage"/>
|
||||
<command id="cmd_findAgain"
|
||||
oncommand="gFindBar.onFindAgainCommand(false);"
|
||||
|
|
|
@ -218,6 +218,12 @@ let TabView = {
|
|||
this._window.GroupItems.moveTabToGroupItem(tab, groupItemId);
|
||||
},
|
||||
|
||||
// ----------
|
||||
enableSearch: function Tabview_enableSearch(event) {
|
||||
if (this._window)
|
||||
this._window.UI.enableSearch(event);
|
||||
},
|
||||
|
||||
// ----------
|
||||
// Adds new key commands to the browser, for invoking the Tab Candy UI
|
||||
// and for switching between groups of tabs when outside of the Tab Candy UI.
|
||||
|
|
|
@ -259,7 +259,7 @@ TabMatcher.prototype = {
|
|||
// Returns all of <TabItem>s that .matched() doesn't return.
|
||||
unmatched: function TabMatcher_unmatched() {
|
||||
var tabs = TabItems.getItems();
|
||||
if ( this.term.length < 2 )
|
||||
if (this.term.length < 2)
|
||||
return tabs;
|
||||
|
||||
return this._filterForUnmatches(tabs);
|
||||
|
@ -284,7 +284,7 @@ TabMatcher.prototype = {
|
|||
matchFunc(tab, i);
|
||||
});
|
||||
|
||||
otherMatches.forEach(function(tab,i){
|
||||
otherMatches.forEach(function(tab,i) {
|
||||
otherFunc(tab, i+matches.length);
|
||||
});
|
||||
|
||||
|
@ -352,18 +352,18 @@ SearchEventHandlerClass.prototype = {
|
|||
// Function: inSearchKeyHandler
|
||||
// Handles all keypresses while search mode.
|
||||
inSearchKeyHandler: function (event) {
|
||||
var term = iQ("#searchbox").val();
|
||||
|
||||
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.keyCode == event.DOM_VK_RETURN && (matches.length > 0 || others.length > 0)) {
|
||||
let matcher = createSearchTabMacher();
|
||||
let matches = matcher.matched();
|
||||
let others = matcher.matchedTabsFromOtherWindows();
|
||||
if ((event.keyCode == event.DOM_VK_RETURN ||
|
||||
event.keyCode == event.DOM_VK_ENTER) &&
|
||||
(matches.length > 0 || others.length > 0)) {
|
||||
hideSearch(event);
|
||||
if (matches.length > 0)
|
||||
matches[0].zoomIn();
|
||||
|
@ -377,7 +377,7 @@ SearchEventHandlerClass.prototype = {
|
|||
// Make sure the event handlers are appropriate for
|
||||
// the before-search mode.
|
||||
switchToBeforeMode: function switchToBeforeMode() {
|
||||
var self = this;
|
||||
let self = this;
|
||||
if (this.currentHandler)
|
||||
iQ(window).unbind("keypress", this.currentHandler);
|
||||
this.currentHandler = function(event) self.beforeSearchKeyHandler(event);
|
||||
|
@ -389,7 +389,7 @@ SearchEventHandlerClass.prototype = {
|
|||
// Make sure the event handlers are appropriate for
|
||||
// the in-search mode.
|
||||
switchToInMode: function switchToInMode() {
|
||||
var self = this;
|
||||
let self = this;
|
||||
if (this.currentHandler)
|
||||
iQ(window).unbind("keypress", this.currentHandler);
|
||||
this.currentHandler = function(event) self.inSearchKeyHandler(event);
|
||||
|
@ -428,7 +428,7 @@ var TabHandlers = {
|
|||
// either be a <TabItem> or a <xul:tab>. In other functions
|
||||
// it is always a <TabItem>. Also note that index is offset
|
||||
// by the number of matches within the window.
|
||||
var item = iQ("<div/>")
|
||||
let item = iQ("<div/>")
|
||||
.addClass("inlineMatch")
|
||||
.click(function(event){
|
||||
hideSearch(event);
|
||||
|
@ -459,10 +459,10 @@ var TabHandlers = {
|
|||
// mode.
|
||||
if (TabHandlers._mouseDownLocation.x == event.clientX &&
|
||||
TabHandlers._mouseDownLocation.y == event.clientY){
|
||||
hideSearch();
|
||||
return;
|
||||
hideSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
iQ("#search").show();
|
||||
iQ("#searchbox")[0].focus();
|
||||
// Marshal the search.
|
||||
|
@ -472,13 +472,17 @@ var TabHandlers = {
|
|||
_mouseDownLocation: null
|
||||
};
|
||||
|
||||
function createSearchTabMacher() {
|
||||
return new TabMatcher(iQ("#searchbox").val());
|
||||
}
|
||||
|
||||
function hideSearch(event){
|
||||
iQ("#searchbox").val("");
|
||||
iQ("#search").hide();
|
||||
|
||||
|
||||
iQ("#searchbutton").css({ opacity:.8 });
|
||||
|
||||
var mainWindow = gWindow.document.getElementById("main-window");
|
||||
|
||||
let mainWindow = gWindow.document.getElementById("main-window");
|
||||
mainWindow.setAttribute("activetitlebarcolor", "#C4C4C4");
|
||||
|
||||
performSearch();
|
||||
|
@ -499,7 +503,7 @@ function hideSearch(event){
|
|||
}
|
||||
|
||||
function performSearch() {
|
||||
var matcher = new TabMatcher(iQ("#searchbox").val());
|
||||
let matcher = new TabMatcher(iQ("#searchbox").val());
|
||||
|
||||
// Remove any previous other-window search results and
|
||||
// hide the display area.
|
||||
|
|
|
@ -931,10 +931,31 @@ let UI = {
|
|||
}
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
} else if (event.keyCode == KeyEvent.DOM_VK_SLASH) {
|
||||
// the / event handler for find bar is defined in the findbar.xml
|
||||
// binding. To keep things in its own module, we handle our slash here.
|
||||
self.enableSearch(event);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// ----------
|
||||
// Function: enableSearch
|
||||
// Enables the search feature.
|
||||
// Parameters:
|
||||
// event - the event triggers this action.
|
||||
enableSearch: function UI_enableSearch(event) {
|
||||
if (!isSearchEnabled()) {
|
||||
ensureSearchShown(null);
|
||||
SearchEventHandler.switchToInMode();
|
||||
|
||||
if (event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// ----------
|
||||
// Function: _createGroupItemOnDrag
|
||||
// Called in response to a mousedown in empty space in the TabView UI;
|
||||
|
@ -1156,17 +1177,31 @@ let UI = {
|
|||
// Exits TabView UI.
|
||||
exit: function UI_exit() {
|
||||
let self = this;
|
||||
|
||||
// If there's an active TabItem, zoom into it. If not (for instance when the
|
||||
// selected tab is an app tab), just go there.
|
||||
let activeTabItem = this.getActiveTab();
|
||||
if (!activeTabItem)
|
||||
activeTabItem = gBrowser.selectedTab.tabItem;
|
||||
|
||||
if (activeTabItem)
|
||||
activeTabItem.zoomIn();
|
||||
else
|
||||
self.goToTab(gBrowser.selectedTab);
|
||||
let zoomedIn = false;
|
||||
|
||||
if (isSearchEnabled()) {
|
||||
let matcher = createSearchTabMacher();
|
||||
let matches = matcher.matched();
|
||||
|
||||
if (matches.length > 0) {
|
||||
matches[0].zoomIn();
|
||||
zoomedIn = true;
|
||||
}
|
||||
hideSearch(null);
|
||||
}
|
||||
|
||||
if (!zoomedIn) {
|
||||
// If there's an active TabItem, zoom into it. If not (for instance when the
|
||||
// selected tab is an app tab), just go there.
|
||||
let activeTabItem = this.getActiveTab();
|
||||
if (!activeTabItem)
|
||||
activeTabItem = gBrowser.selectedTab.tabItem;
|
||||
|
||||
if (activeTabItem)
|
||||
activeTabItem.zoomIn();
|
||||
else
|
||||
self.goToTab(gBrowser.selectedTab);
|
||||
}
|
||||
},
|
||||
|
||||
// ----------
|
||||
|
|
|
@ -59,6 +59,7 @@ _BROWSER_FILES = \
|
|||
browser_tabview_bug595191.js \
|
||||
browser_tabview_bug595518.js \
|
||||
browser_tabview_bug595521.js \
|
||||
browser_tabview_bug595560.js \
|
||||
browser_tabview_bug595804.js \
|
||||
browser_tabview_bug595930.js \
|
||||
browser_tabview_bug595943.js \
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
/* ***** 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 bug 595560 test.
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
let newTabOne;
|
||||
let originalTab;
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
originalTab = gBrowser.visibleTabs[0];
|
||||
newTabOne = gBrowser.addTab("http://mochi.test:8888/");
|
||||
|
||||
let browser = gBrowser.getBrowserForTab(newTabOne);
|
||||
let onLoad = function() {
|
||||
browser.removeEventListener("load", onLoad, true);
|
||||
|
||||
// show the tab view
|
||||
window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
|
||||
TabView.toggle();
|
||||
}
|
||||
browser.addEventListener("load", onLoad, true);
|
||||
}
|
||||
|
||||
function onTabViewWindowLoaded() {
|
||||
window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
|
||||
ok(TabView.isVisible(), "Tab View is visible");
|
||||
|
||||
let contentWindow = document.getElementById("tab-view").contentWindow;
|
||||
testOne(contentWindow);
|
||||
}
|
||||
|
||||
function testOne(contentWindow) {
|
||||
onSearchEnabledAndDisabled(contentWindow, function() {
|
||||
testTwo(contentWindow);
|
||||
});
|
||||
// execute a find command (i.e. press cmd/ctrl F)
|
||||
document.getElementById("cmd_find").doCommand();
|
||||
}
|
||||
|
||||
function testTwo(contentWindow) {
|
||||
onSearchEnabledAndDisabled(contentWindow, function() {
|
||||
testThree(contentWindow);
|
||||
});
|
||||
// press /
|
||||
EventUtils.synthesizeKey("VK_SLASH", { type: "keydown" }, contentWindow);
|
||||
}
|
||||
|
||||
function testThree(contentWindow) {
|
||||
let groupItem = createEmptyGroupItem(contentWindow, 200);
|
||||
|
||||
let onTabViewHidden = function() {
|
||||
window.removeEventListener("tabviewhidden", onTabViewHidden, false);
|
||||
TabView.toggle();
|
||||
};
|
||||
let onTabViewShown = function() {
|
||||
window.removeEventListener("tabviewshown", onTabViewShown, false);
|
||||
|
||||
is(contentWindow.UI.getActiveTab(), groupItem.getChild(0),
|
||||
"The active tab is newly created tab item");
|
||||
|
||||
let onSearchEnabled = function() {
|
||||
contentWindow.removeEventListener(
|
||||
"tabviewsearchenabled", onSearchEnabled, false);
|
||||
|
||||
let searchBox = contentWindow.iQ("#searchbox");
|
||||
searchBox.val(newTabOne.tabItem.nameEl.innerHTML);
|
||||
|
||||
contentWindow.performSearch();
|
||||
|
||||
let checkSelectedTab = function() {
|
||||
window.removeEventListener("tabviewhidden", checkSelectedTab, false);
|
||||
is(newTabOne, gBrowser.selectedTab, "The search result tab is shown");
|
||||
cleanUpAndFinish(groupItem.getChild(0), contentWindow);
|
||||
};
|
||||
window.addEventListener("tabviewhidden", checkSelectedTab, false);
|
||||
|
||||
// use the tabview menu (the same as pressing cmd/ctrl + e)
|
||||
document.getElementById("menu_tabview").doCommand();
|
||||
};
|
||||
contentWindow.addEventListener("tabviewsearchenabled", onSearchEnabled, false);
|
||||
EventUtils.synthesizeKey("VK_SLASH", { type: "keydown" }, contentWindow);
|
||||
};
|
||||
window.addEventListener("tabviewhidden", onTabViewHidden, false);
|
||||
window.addEventListener("tabviewshown", onTabViewShown, false);
|
||||
|
||||
// click on the + button
|
||||
let newTabButton = groupItem.container.getElementsByClassName("newTabButton");
|
||||
ok(newTabButton[0], "New tab button exists");
|
||||
|
||||
EventUtils.sendMouseEvent({ type: "click" }, newTabButton[0], contentWindow);
|
||||
}
|
||||
|
||||
function onSearchEnabledAndDisabled(contentWindow, callback) {
|
||||
let onSearchEnabled = function() {
|
||||
contentWindow.removeEventListener(
|
||||
"tabviewsearchenabled", onSearchEnabled, false);
|
||||
contentWindow.addEventListener("tabviewsearchdisabled", onSearchDisabled, false);
|
||||
contentWindow.hideSearch();
|
||||
}
|
||||
let onSearchDisabled = function() {
|
||||
contentWindow.removeEventListener(
|
||||
"tabviewsearchdisabled", onSearchDisabled, false);
|
||||
callback();
|
||||
}
|
||||
contentWindow.addEventListener("tabviewsearchenabled", onSearchEnabled, false);
|
||||
}
|
||||
|
||||
function cleanUpAndFinish(tabItem, contentWindow) {
|
||||
gBrowser.selectedTab = originalTab;
|
||||
gBrowser.removeTab(newTabOne);
|
||||
gBrowser.removeTab(tabItem.tab);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
function createEmptyGroupItem(contentWindow, padding) {
|
||||
let pageBounds = contentWindow.Items.getPageBounds();
|
||||
pageBounds.inset(padding, padding);
|
||||
|
||||
let box = new contentWindow.Rect(pageBounds);
|
||||
box.width = 300;
|
||||
box.height = 300;
|
||||
|
||||
let emptyGroupItem = new contentWindow.GroupItem([], { bounds: box });
|
||||
|
||||
return emptyGroupItem;
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче