Bug 258514. Click on anchor with location hash sometimes first focusable child a focus rectangle. r=mats, sr=bryner

This commit is contained in:
aaronleventhal%moonset.net 2004-10-29 13:40:25 +00:00
Родитель 147b99f635
Коммит a699892779
5 изменённых файлов: 33 добавлений и 26 удалений

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

@ -50,18 +50,25 @@ class nsIView;
class nsIWidget;
/*
* Event listener manager interface.
* Event state manager interface.
*/
// {5D47ACA5-B50B-479b-A1C6-2A90C0B8095F}
#define NS_IEVENTSTATEMANAGER_IID \
{ /* 4d45b9d0-fcf2-11d8-9669-0800200c9a66 */ \
0x4d45b9d0, 0xfcf2, 0x11d8, \
{0x96, 0x69, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66} }
{ 0x5d47aca5, 0xb50b, 0x479b, { 0xa1, 0xc6, 0x2a, 0x90, 0xc0, 0xb8, 0x9, 0x5f } };
#define NS_EVENT_NEEDS_FRAME(event) (!NS_IS_FOCUS_EVENT(event))
class nsIEventStateManager : public nsISupports {
public:
enum EFocusedWithType {
eEventFocusedByUnknown, // focus gained via unknown method
eEventFocusedByMouse, // focus gained via mouse
eEventFocusedByKey, // focus gained via key press (like tab)
eEventFocusedByContextMenu, // focus gained via context menu
eEventFocusedByApplication // focus gained via Application (like script)
};
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IEVENTSTATEMANAGER_IID)
NS_IMETHOD Init() = 0;
@ -104,6 +111,10 @@ public:
NS_IMETHOD MoveFocusToCaret(PRBool aCanFocusDoc, PRBool *aIsSelectionWithFocus) = 0;
NS_IMETHOD MoveCaretToFocus() = 0;
// Set focus on any element that can receive focus, or on document via aFocusContent == nsnull
// Must supply method that focus is being set with
NS_IMETHOD ChangeFocusWith(nsIContent *aFocusContent, EFocusedWithType aFocusedWith) = 0;
// This is an experiment and may be temporary
NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) = 0;
@ -129,12 +140,4 @@ public:
// The following states are used only for ContentStatesChanged
#define NS_EVENT_STATE_CHECKED 0x0020
enum EFocusedWithType {
eEventFocusedByUnknown, // focus gained via unknown method
eEventFocusedByMouse, // focus gained via mouse
eEventFocusedByKey, // focus gained via key press (like tab)
eEventFocusedByContextMenu, // focus gained via context menu
eEventFocusedByApplication // focus gained via Application (like script)
};
#endif // nsIEventStateManager_h__

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

@ -1008,7 +1008,7 @@ nsEventStateManager::HandleAccessKey(nsPresContext* aPresContext,
} else { // otherwise, it must be HTML
// It's hard to say what HTML4 wants us to do in all cases.
// So for now we'll settle for A) Set focus
ChangeFocus(content, eEventFocusedByKey);
ChangeFocusWith(content, eEventFocusedByKey);
if (sKeyCausesActivation) {
// B) Click on it if the users prefs indicate to do so.
@ -1891,7 +1891,7 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
}
if (newFocus && currFrame)
ChangeFocus(newFocus, eEventFocusedByMouse);
ChangeFocusWith(newFocus, eEventFocusedByMouse);
else if (!suppressBlur) {
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
}
@ -2972,10 +2972,15 @@ nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext,
return ret;
}
PRBool
nsEventStateManager::ChangeFocus(nsIContent* aFocusContent,
PRInt32 aFocusedWith)
NS_IMETHODIMP
nsEventStateManager::ChangeFocusWith(nsIContent* aFocusContent,
EFocusedWithType aFocusedWith)
{
mLastFocusedWith = aFocusedWith;
if (!aFocusContent) {
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
return NS_OK;
}
aFocusContent->SetFocus(mPresContext);
if (aFocusedWith != eEventFocusedByMouse) {
MoveCaretToFocus();
@ -2996,8 +3001,7 @@ nsEventStateManager::ChangeFocus(nsIContent* aFocusContent,
}
}
mLastFocusedWith = aFocusedWith;
return PR_FALSE;
return NS_OK;
}
//---------------------------------------------------------
@ -3169,7 +3173,7 @@ nsEventStateManager::ShiftFocusInternal(PRBool aForward, nsIContent* aStart)
getter_AddRefs(nextFocus), &nextFocusFrame);
// Clear out mCurrentTabIndex. It has a garbage value because of GetNextTabbableContent()'s side effects
// It will be set correctly when focus is changed via ChangeFocus()
// It will be set correctly when focus is changed via ChangeFocusWith()
mCurrentTabIndex = 0;
if (nextFocus) {
@ -3216,9 +3220,9 @@ nsEventStateManager::ShiftFocusInternal(PRBool aForward, nsIContent* aStart)
SetFrameExternalReference(mCurrentTarget);
nsCOMPtr<nsIContent> oldFocus(mCurrentFocus);
ChangeFocus(nextFocus, eEventFocusedByKey);
ChangeFocusWith(nextFocus, eEventFocusedByKey);
if (!mCurrentFocus && oldFocus) {
// ChangeFocus failed to move focus to nextFocus because a blur handler
// ChangeFocusWith failed to move focus to nextFocus because a blur handler
// made it unfocusable. (bug #118685)
// Try again unless it's from the same point, bug 232368.
if (oldFocus != aStart) {

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

@ -139,6 +139,7 @@ public:
NS_IMETHOD MoveFocusToCaret(PRBool aCanFocusDoc, PRBool *aIsSelectionWithFocus);
NS_IMETHOD MoveCaretToFocus();
NS_IMETHOD ChangeFocusWith(nsIContent* aFocus, EFocusedWithType aFocusedWith);
static void StartHandlingUserInput()
{
@ -172,7 +173,6 @@ protected:
void GenerateDragDropEnterExit(nsPresContext* aPresContext, nsGUIEvent* aEvent);
nsresult SetClickCount(nsPresContext* aPresContext, nsMouseEvent *aEvent, nsEventStatus* aStatus);
nsresult CheckForAndDispatchClick(nsPresContext* aPresContext, nsMouseEvent *aEvent, nsEventStatus* aStatus);
PRBool ChangeFocus(nsIContent* aFocus, PRInt32 aFocusedWith);
nsresult GetNextTabbableContent(nsIContent* aRootContent,
nsIContent* aStartContent,
nsIFrame* aStartFrame,
@ -279,7 +279,7 @@ protected:
nsCOMPtr<nsIContent> mURLTargetContent;
nsCOMPtr<nsIContent> mCurrentFocus;
nsIFrame* mCurrentFocusFrame;
PRInt32 mLastFocusedWith;
EFocusedWithType mLastFocusedWith;
PRInt32 mCurrentTabIndex;
// DocShell Traversal Data Memebers

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

@ -4022,7 +4022,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
}
PRBool isSelectionWithFocus;
esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus);
esm->ChangeFocusWith(nsnull, nsIEventStateManager::eEventFocusedByApplication);
}
}
} else {

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

@ -4022,7 +4022,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
}
PRBool isSelectionWithFocus;
esm->MoveFocusToCaret(PR_TRUE, &isSelectionWithFocus);
esm->ChangeFocusWith(nsnull, nsIEventStateManager::eEventFocusedByApplication);
}
}
} else {