From 5c5a6660ecda4e0c54ab14773cd4568ec2bc2dce Mon Sep 17 00:00:00 2001 From: "aaronl%netscape.com" Date: Wed, 9 Jul 2003 06:36:33 +0000 Subject: [PATCH] Bug 211846. alt+down not working consistently for dropdowns. Also fixes bug 110801 and bug 205942, dropdown from alt+down not showing in the right place. r=jkieser, sr=bz --- layout/forms/nsComboboxControlFrame.cpp | 12 ++--- layout/forms/nsListControlFrame.cpp | 45 +++++++------------ layout/forms/nsListControlFrame.h | 1 + .../html/forms/src/nsComboboxControlFrame.cpp | 12 ++--- layout/html/forms/src/nsListControlFrame.cpp | 45 +++++++------------ layout/html/forms/src/nsListControlFrame.h | 1 + 6 files changed, 40 insertions(+), 76 deletions(-) diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index 0af0c4b801d7..1405e1f2c2ea 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -1996,18 +1996,12 @@ nsComboboxControlFrame::HandleEvent(nsIPresContext* aPresContext, if (aEvent->message == NS_KEY_PRESS) { nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; nsInputEvent *inputEvent = (nsInputEvent*)aEvent; - if (!inputEvent->isShift && !inputEvent->isControl && !inputEvent->isMeta) { - if (keyEvent->keyCode == NS_VK_F4 && !inputEvent->isAlt) - ToggleList(aPresContext); - else if (inputEvent->isAlt && (keyEvent->keyCode == NS_VK_DOWN || (mDroppedDown && keyEvent->keyCode == NS_VK_UP))) - ToggleList(aPresContext); - else if (!mDroppedDown && keyEvent->keyCode == NS_VK_RETURN) - CheckFireOnChange(); + if (!inputEvent->isShift && !inputEvent->isControl && !inputEvent->isMeta && + !mDroppedDown && keyEvent->keyCode == NS_VK_RETURN) { + CheckFireOnChange(); } } - - // If we have style that affects how we are selected, feed event down to // nsFrame::HandleEvent so that selection takes place when appropriate. const nsStyleUserInterface* uiStyle = GetStyleUserInterface(); diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index dd4d326b2d99..431872ff16d5 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -3243,6 +3243,17 @@ nsListControlFrame::GetIncrementalString() return incrementalString; } +void +nsListControlFrame::DropDownToggleKey(nsIDOMEvent* aKeyEvent) +{ + if (IsInDropDownMode()) { + PRBool isDroppedDown; + mComboboxFrame->IsDroppedDown(&isDroppedDown); + mComboboxFrame->ShowDropDown(!isDroppedDown); + aKeyEvent->PreventDefault(); + } +} + nsresult nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent) { @@ -3269,23 +3280,9 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent) keyEvent->GetAltKey(&isAlt); if (isAlt) { -#ifdef FIX_FOR_BUG_62425 - if (code == nsIDOMKeyEvent::DOM_VK_UP || code == nsIDOMKeyEvent::DOM_VK_DOWN) { - if (IsInDropDownMode() == PR_TRUE) { - PRBool isDroppedDown; - mComboboxFrame->IsDroppedDown(&isDroppedDown); - mComboboxFrame->ShowDropDown(!isDroppedDown); - aKeyEvent->PreventDefault(); - - nsCOMPtr nsevent(do_QueryInterface(aKeyEvent)); - - if (nsevent) { - nsevent->PreventCapture(); - nsevent->PreventBubble(); - } - } + if (keycode == nsIDOMKeyEvent::DOM_VK_UP || keycode == nsIDOMKeyEvent::DOM_VK_DOWN) { + DropDownToggleKey(aKeyEvent); } -#endif return NS_OK; } @@ -3388,19 +3385,9 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent) #if defined(XP_WIN) || defined(XP_OS2) case nsIDOMKeyEvent::DOM_VK_F4: { - if (IsInDropDownMode() == PR_TRUE) { - PRBool isDroppedDown; - mComboboxFrame->IsDroppedDown(&isDroppedDown); - mComboboxFrame->ShowDropDown(!isDroppedDown); - - nsCOMPtr nsevent(do_QueryInterface(aKeyEvent)); - - if (nsevent) { - nsevent->PreventCapture(); - nsevent->PreventBubble(); - } - } - } break; + DropDownToggleKey(aKeyEvent); + return NS_OK; + } break; #endif case nsIDOMKeyEvent::DOM_VK_TAB: { diff --git a/layout/forms/nsListControlFrame.h b/layout/forms/nsListControlFrame.h index 24ba7db1e0e9..87392b208991 100644 --- a/layout/forms/nsListControlFrame.h +++ b/layout/forms/nsListControlFrame.h @@ -336,6 +336,7 @@ public: protected: + void DropDownToggleKey(nsIDOMEvent* aKeyEvent); nsresult IsOptionDisabled(PRInt32 anIndex, PRBool &aIsDisabled); nsresult ScrollToFrame(nsIContent * aOptElement); nsresult ScrollToIndex(PRInt32 anIndex); diff --git a/layout/html/forms/src/nsComboboxControlFrame.cpp b/layout/html/forms/src/nsComboboxControlFrame.cpp index 0af0c4b801d7..1405e1f2c2ea 100644 --- a/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -1996,18 +1996,12 @@ nsComboboxControlFrame::HandleEvent(nsIPresContext* aPresContext, if (aEvent->message == NS_KEY_PRESS) { nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; nsInputEvent *inputEvent = (nsInputEvent*)aEvent; - if (!inputEvent->isShift && !inputEvent->isControl && !inputEvent->isMeta) { - if (keyEvent->keyCode == NS_VK_F4 && !inputEvent->isAlt) - ToggleList(aPresContext); - else if (inputEvent->isAlt && (keyEvent->keyCode == NS_VK_DOWN || (mDroppedDown && keyEvent->keyCode == NS_VK_UP))) - ToggleList(aPresContext); - else if (!mDroppedDown && keyEvent->keyCode == NS_VK_RETURN) - CheckFireOnChange(); + if (!inputEvent->isShift && !inputEvent->isControl && !inputEvent->isMeta && + !mDroppedDown && keyEvent->keyCode == NS_VK_RETURN) { + CheckFireOnChange(); } } - - // If we have style that affects how we are selected, feed event down to // nsFrame::HandleEvent so that selection takes place when appropriate. const nsStyleUserInterface* uiStyle = GetStyleUserInterface(); diff --git a/layout/html/forms/src/nsListControlFrame.cpp b/layout/html/forms/src/nsListControlFrame.cpp index dd4d326b2d99..431872ff16d5 100644 --- a/layout/html/forms/src/nsListControlFrame.cpp +++ b/layout/html/forms/src/nsListControlFrame.cpp @@ -3243,6 +3243,17 @@ nsListControlFrame::GetIncrementalString() return incrementalString; } +void +nsListControlFrame::DropDownToggleKey(nsIDOMEvent* aKeyEvent) +{ + if (IsInDropDownMode()) { + PRBool isDroppedDown; + mComboboxFrame->IsDroppedDown(&isDroppedDown); + mComboboxFrame->ShowDropDown(!isDroppedDown); + aKeyEvent->PreventDefault(); + } +} + nsresult nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent) { @@ -3269,23 +3280,9 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent) keyEvent->GetAltKey(&isAlt); if (isAlt) { -#ifdef FIX_FOR_BUG_62425 - if (code == nsIDOMKeyEvent::DOM_VK_UP || code == nsIDOMKeyEvent::DOM_VK_DOWN) { - if (IsInDropDownMode() == PR_TRUE) { - PRBool isDroppedDown; - mComboboxFrame->IsDroppedDown(&isDroppedDown); - mComboboxFrame->ShowDropDown(!isDroppedDown); - aKeyEvent->PreventDefault(); - - nsCOMPtr nsevent(do_QueryInterface(aKeyEvent)); - - if (nsevent) { - nsevent->PreventCapture(); - nsevent->PreventBubble(); - } - } + if (keycode == nsIDOMKeyEvent::DOM_VK_UP || keycode == nsIDOMKeyEvent::DOM_VK_DOWN) { + DropDownToggleKey(aKeyEvent); } -#endif return NS_OK; } @@ -3388,19 +3385,9 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent) #if defined(XP_WIN) || defined(XP_OS2) case nsIDOMKeyEvent::DOM_VK_F4: { - if (IsInDropDownMode() == PR_TRUE) { - PRBool isDroppedDown; - mComboboxFrame->IsDroppedDown(&isDroppedDown); - mComboboxFrame->ShowDropDown(!isDroppedDown); - - nsCOMPtr nsevent(do_QueryInterface(aKeyEvent)); - - if (nsevent) { - nsevent->PreventCapture(); - nsevent->PreventBubble(); - } - } - } break; + DropDownToggleKey(aKeyEvent); + return NS_OK; + } break; #endif case nsIDOMKeyEvent::DOM_VK_TAB: { diff --git a/layout/html/forms/src/nsListControlFrame.h b/layout/html/forms/src/nsListControlFrame.h index 24ba7db1e0e9..87392b208991 100644 --- a/layout/html/forms/src/nsListControlFrame.h +++ b/layout/html/forms/src/nsListControlFrame.h @@ -336,6 +336,7 @@ public: protected: + void DropDownToggleKey(nsIDOMEvent* aKeyEvent); nsresult IsOptionDisabled(PRInt32 anIndex, PRBool &aIsDisabled); nsresult ScrollToFrame(nsIContent * aOptElement); nsresult ScrollToIndex(PRInt32 anIndex);