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_END" modifiers="shift" command="cmd_selectEndLine" />
<handler event="keypress" keycode="VK_UP" modifiers="shift" command="cmd_selectLinePrevious" /> <handler event="keypress" keycode="VK_UP" modifiers="shift" command="cmd_selectLinePrevious" />
<handler event="keypress" keycode="VK_DOWN" modifiers="shift" command="cmd_selectLineNext" /> <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> </handlers>
</binding> </binding>

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

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

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

@ -53,24 +53,38 @@
interface nsIDOMEvent; interface nsIDOMEvent;
[uuid(AD1C62CC-72F4-4c5b-BE78-503854F9E0D8)] [scriptable, uuid(AD1C62CC-72F4-4c5b-BE78-503854F9E0D8)]
interface nsITypeAheadFind : nsISupports interface nsITypeAheadFind : nsISupports
{ {
// Is type ahead find mode currently on? /** Is type ahead find mode currently on? */
readonly attribute boolean isActive; 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); void startNewFind(in nsIDOMWindow aWindow, in boolean aLinksOnly);
/** Manually cancel type ahead find mode */
void cancelFind(); void cancelFind();
// If no automatic typeaheadfind start in this window, /**
// it must be started manually with startNewFind() * Will find as you type start automatically if the user
void setAutoStart(in nsIDOMWindow aWindow, in boolean aAutoStartOn); * 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); 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 * Find next recurrence if typeaheadfind was the last used find,
// don't handle the request. * as opposed to regular find. Returns false in nsISupportsPRBool if we
* don't handle the request.
*/
void findNext(in boolean aReverse, in nsISupportsInterfacePointer aCallerWindowSupports); 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 ------------------------- // ----------- Back space -------------------------
if (keyCode == nsIDOMKeyEvent::DOM_VK_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 aEvent->PreventDefault(); // Prevent normal processing of this keystroke
} }
@ -693,13 +699,15 @@ nsTypeAheadFind::KeyPress(nsIDOMEvent* aEvent)
} }
PRBool NS_IMETHODIMP
nsTypeAheadFind::HandleBackspace() nsTypeAheadFind::BackOneChar(PRBool *aIsBackspaceUsed)
{ {
// In normal type ahead find, remove a printable char from // In normal type ahead find, remove a printable char from
// mTypeAheadBuffer, then search for buffer contents // mTypeAheadBuffer, then search for buffer contents
// Or, in repeated char find, go backwards // Or, in repeated char find, go backwards
*aIsBackspaceUsed = PR_TRUE;
// ---------- No chars in string ------------ // ---------- No chars in string ------------
if (mTypeAheadBuffer.IsEmpty() || !mStartFindRange) { if (mTypeAheadBuffer.IsEmpty() || !mStartFindRange) {
if (!mFindNextBuffer.IsEmpty() && if (!mFindNextBuffer.IsEmpty() &&
@ -722,9 +730,12 @@ nsTypeAheadFind::HandleBackspace()
soundInterface->Beep(); // beep to warn soundInterface->Beep(); // beep to warn
} }
mIsBackspaceProtectOn = PR_FALSE; mIsBackspaceProtectOn = PR_FALSE;
return PR_TRUE;
} }
return PR_FALSE; else {
*aIsBackspaceUsed = PR_FALSE;
}
return NS_OK;
} }
} }
@ -742,7 +753,7 @@ nsTypeAheadFind::HandleBackspace()
CancelFind(); CancelFind();
mIsBackspaceProtectOn = PR_TRUE; mIsBackspaceProtectOn = PR_TRUE;
return PR_TRUE; return NS_OK;
} }
// ---------- Multiple chars in string ---------- // ---------- Multiple chars in string ----------
@ -763,7 +774,7 @@ nsTypeAheadFind::HandleBackspace()
--mBadKeysSinceMatch; --mBadKeysSinceMatch;
DisplayStatus(PR_FALSE, nsnull, PR_FALSE); // Display failure status DisplayStatus(PR_FALSE, nsnull, PR_FALSE); // Display failure status
SaveFind(); SaveFind();
return PR_TRUE; return NS_OK;
} }
mBadKeysSinceMatch = 0; mBadKeysSinceMatch = 0;
@ -785,7 +796,8 @@ nsTypeAheadFind::HandleBackspace()
} }
} }
if (!presShell) { if (!presShell) {
return PR_FALSE; *aIsBackspaceUsed = PR_FALSE;
return NS_ERROR_FAILURE;
} }
// Set the selection to the where the first character was found // Set the selection to the where the first character was found
// so that find starts from there // so that find starts from there
@ -808,7 +820,7 @@ nsTypeAheadFind::HandleBackspace()
SaveFind(); 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() function BrowserForward()
{ {
try { try {

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

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

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

@ -9,6 +9,12 @@
<key id="goBackKb" keycode="VK_LEFT" command="Browser:Back" modifiers="alt"/> <key id="goBackKb" keycode="VK_LEFT" command="Browser:Back" modifiers="alt"/>
<key id="goForwardKb" keycode="VK_RIGHT" command="Browser:Forward" 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 --> <!-- Supporting IE 'refresh' shortcut key -->
<key keycode="VK_F5" oncommand="BrowserReload();"/> <key keycode="VK_F5" oncommand="BrowserReload();"/>
<key keycode="VK_F5" modifiers="control" oncommand="BrowserReloadSkipCache();"/> <key keycode="VK_F5" modifiers="control" oncommand="BrowserReloadSkipCache();"/>