Bug 204777. Prevent backspace to send us back in history in general embedded case. r=brade, sr=sfraser

This commit is contained in:
aaronl%netscape.com 2003-05-25 19:39:21 +00:00
Родитель dad664049f
Коммит 5158d785de
7 изменённых файлов: 78 добавлений и 23 удалений

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

@ -107,11 +107,6 @@
<handler event="keypress" keycode="VK_END" modifiers="shift" command="cmd_selectEndLine" />
<handler event="keypress" keycode="VK_UP" modifiers="shift" command="cmd_selectLinePrevious" />
<handler event="keypress" keycode="VK_DOWN" modifiers="shift" command="cmd_selectLineNext" />
<!-- Supporting IE forward and back accelerators out of courtesy
to transitioning IE users -->
<handler event="keypress" keycode="VK_BACK" command="cmd_browserBack"/>
<handler event="keypress" keycode="VK_BACK" modifiers="shift" command="cmd_browserForward" />
</handlers>
</binding>

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

@ -676,6 +676,7 @@ protected:
// no member variables, please, we're stateless!
};
#if 0 // Remove unless needed again, bug 204777
class nsGoForwardCommand : public nsWebNavigationBaseCommand
{
protected:
@ -693,6 +694,7 @@ protected:
virtual nsresult DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWebNavigation);
// no member variables, please, we're stateless!
};
#endif
/*---------------------------------------------------------------------------
@ -756,6 +758,7 @@ nsWebNavigationBaseCommand::GetWebNavigationFromContext(nsISupports *aContext, n
#pragma mark -
#endif
#if 0 // Remove unless needed again, bug 204777
nsresult
nsGoForwardCommand::IsWebNavCommandEnabled(const char * aCommandName, nsIWebNavigation* aWebNavigation, PRBool *outCmdEnabled)
{
@ -779,6 +782,7 @@ nsGoBackCommand::DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWe
{
return aWebNavigation->GoBack();
}
#endif
/*---------------------------------------------------------------------------
@ -959,8 +963,10 @@ nsWindowCommandRegistration::RegisterWindowCommands(
NS_REGISTER_ONE_COMMAND(nsClipboardGetContentsCommand, "cmd_getContents");
#if 0 // Remove unless needed again, bug 204777
NS_REGISTER_ONE_COMMAND(nsGoBackCommand, "cmd_browserBack");
NS_REGISTER_ONE_COMMAND(nsGoForwardCommand, "cmd_browserForward");
#endif
NS_REGISTER_ONE_COMMAND(nsClipboardDragDropHookCommand, "cmd_clipboardDragDropHook");

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

@ -53,24 +53,38 @@
interface nsIDOMEvent;
[uuid(AD1C62CC-72F4-4c5b-BE78-503854F9E0D8)]
[scriptable, uuid(AD1C62CC-72F4-4c5b-BE78-503854F9E0D8)]
interface nsITypeAheadFind : nsISupports
{
// Is type ahead find mode currently on?
/** Is type ahead find mode currently on? */
readonly attribute boolean isActive;
// Manually start or cancel type ahead find mode
/** Manually start type ahead find mode */
void startNewFind(in nsIDOMWindow aWindow, in boolean aLinksOnly);
/** Manually cancel type ahead find mode */
void cancelFind();
// If no automatic typeaheadfind start in this window,
// it must be started manually with startNewFind()
void setAutoStart(in nsIDOMWindow aWindow, in boolean aAutoStartOn);
/**
* Will find as you type start automatically if the user
* types with the focus on page content other than a textfield or select?
* If autostart is off, the startNewFind() method can be used to enact
* type ahead find, as well as cmd_findTypeLinks or cmd_findTypeText.
*/
void setAutoStart(in nsIDOMWindow aWindow, in boolean aIsAutoStartOn);
boolean getAutoStart(in nsIDOMWindow aWindow);
// Find next recurrence if typeaheadfind was the last used find,
// as opposed to regular find. Returns false in nsISupportsPRBool if we
// don't handle the request.
/**
* Find next recurrence if typeaheadfind was the last used find,
* as opposed to regular find. Returns false in nsISupportsPRBool if we
* don't handle the request.
*/
void findNext(in boolean aReverse, in nsISupportsInterfacePointer aCallerWindowSupports);
/*
* Go back and remove one character from find string
* Returns true if backspace used
*/
boolean backOneChar();
};

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

@ -664,7 +664,13 @@ nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
// ----------- Back space -------------------------
if (keyCode == nsIDOMKeyEvent::DOM_VK_BACK_SPACE) {
if (HandleBackspace()) {
// The order of seeing keystrokes is:
// 1) Chrome, 2) Typeahead, 3) [platform]HTMLBindings.xml
// If chrome handles backspace, it needs to do this work
// Otherwise, we handle backspace here.
PRBool backspaceUsed;
BackOneChar(&backspaceUsed);
if (backspaceUsed) {
aEvent->PreventDefault(); // Prevent normal processing of this keystroke
}
@ -693,13 +699,15 @@ nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
}
PRBool
nsTypeAheadFind::HandleBackspace()
NS_IMETHODIMP
nsTypeAheadFind::BackOneChar(PRBool *aIsBackspaceUsed)
{
// In normal type ahead find, remove a printable char from
// mTypeAheadBuffer, then search for buffer contents
// Or, in repeated char find, go backwards
*aIsBackspaceUsed = PR_TRUE;
// ---------- No chars in string ------------
if (mTypeAheadBuffer.IsEmpty() || !mStartFindRange) {
if (!mFindNextBuffer.IsEmpty() &&
@ -722,9 +730,12 @@ nsTypeAheadFind::HandleBackspace()
soundInterface->Beep(); // beep to warn
}
mIsBackspaceProtectOn = PR_FALSE;
return PR_TRUE;
}
return PR_FALSE;
else {
*aIsBackspaceUsed = PR_FALSE;
}
return NS_OK;
}
}
@ -742,7 +753,7 @@ nsTypeAheadFind::HandleBackspace()
CancelFind();
mIsBackspaceProtectOn = PR_TRUE;
return PR_TRUE;
return NS_OK;
}
// ---------- Multiple chars in string ----------
@ -763,7 +774,7 @@ nsTypeAheadFind::HandleBackspace()
--mBadKeysSinceMatch;
DisplayStatus(PR_FALSE, nsnull, PR_FALSE); // Display failure status
SaveFind();
return PR_TRUE;
return NS_OK;
}
mBadKeysSinceMatch = 0;
@ -785,7 +796,8 @@ nsTypeAheadFind::HandleBackspace()
}
}
if (!presShell) {
return PR_FALSE;
*aIsBackspaceUsed = PR_FALSE;
return NS_ERROR_FAILURE;
}
// Set the selection to the where the first character was found
// so that find starts from there
@ -808,7 +820,7 @@ nsTypeAheadFind::HandleBackspace()
SaveFind();
return PR_TRUE; // Backspace handled
return NS_OK; // Backspace handled
}

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

@ -740,6 +740,27 @@ function BrowserBack()
}
}
function BrowserHandleBackspace()
{
// The order of seeing keystrokes is this:
// 1) Chrome, 2) Typeahead, 3) [platform]HTMLBindings.xml
// Rather than have typeaheadfind responsible for making VK_BACK
// go back in history, we handle backspace it here as follows:
// When backspace is pressed, it might mean back
// in typeaheadfind if that's active, or it might mean back in history
var typeAhead = null;
const TYPE_AHEAD_FIND_CONTRACTID = "@mozilla.org/typeaheadfind;1";
if (TYPE_AHEAD_FIND_CONTRACTID in Components.classes) {
typeAhead = Components.classes[TYPE_AHEAD_FIND_CONTRACTID]
.getService(Components.interfaces.nsITypeAheadFind);
}
if (!typeAhead || !typeAhead.backOneChar()) {
BrowserBack();
}
}
function BrowserForward()
{
try {

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

@ -113,6 +113,7 @@
<command id="cmd_newNavigator"/>
<command id="cmd_newNavigatorTab" oncommand="BrowserOpenTab();"/>
<command id="cmd_newTabWithTarget" oncommand="contentAreaClick(event);"/>
<command id="cmd_handleBackspace" oncommand="BrowserHandleBackspace();" />
<command id="cmd_newEditor"/>
<!-- NOT IMPLEMENTED

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

@ -9,6 +9,12 @@
<key id="goBackKb" keycode="VK_LEFT" command="Browser:Back" modifiers="alt"/>
<key id="goForwardKb" keycode="VK_RIGHT" command="Browser:Forward" modifiers="alt"/>
<!-- Supporting IE forward and back accelerators out of courtesy
to transitioning IE users -->
<!-- Backspace is also used by type ahead find -->
<key keycode="VK_BACK" command="cmd_handleBackspace"/>
<key keycode="VK_BACK" command="Browser:Forward" modifiers="shift"/>
<!-- Supporting IE 'refresh' shortcut key -->
<key keycode="VK_F5" oncommand="BrowserReload();"/>
<key keycode="VK_F5" modifiers="control" oncommand="BrowserReloadSkipCache();"/>