зеркало из https://github.com/mozilla/gecko-dev.git
Added new method to tell the listcontrolframe it is about to be rolled up by the combobox
this enables it to unset any temporary selections and restore the actual selection
This commit is contained in:
Родитель
3d3b8bda38
Коммит
e6b0939762
|
@ -551,7 +551,7 @@ nsComboboxControlFrame::PositionDropdown(nsIPresContext& aPresContext,
|
|||
|
||||
//if (currentRect != dropdownRect) {
|
||||
dropdownFrame->SetRect(dropdownRect);
|
||||
#ifdef DEBUG_rods
|
||||
#ifdef DEBUG_rodsXXX
|
||||
printf("%d Position Dropdown at: %d %d %d %d\n", counter++, dropdownRect.x, dropdownRect.y, dropdownRect.width, dropdownRect.height);
|
||||
#endif
|
||||
//}
|
||||
|
@ -645,7 +645,7 @@ nsComboboxControlFrame::Reflow(nsIPresContext& aPresContext,
|
|||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
#ifdef DEBUG_rods
|
||||
#ifdef DEBUG_rodsXXX
|
||||
printf("nsComboboxControlFrame::Reflow %d Reason: ", myCounter++);
|
||||
switch (aReflowState.reason) {
|
||||
case eReflowReason_Initial:printf("eReflowReason_Initial\n");break;
|
||||
|
@ -1079,11 +1079,13 @@ nsComboboxControlFrame::SelectionChanged(PRBool aDoDispatchEvent)
|
|||
// Now have the frame handle the event
|
||||
nsIFrame* frame = nsnull;
|
||||
nsIFrame* dropdownFrame = GetDropdownFrame();
|
||||
if (nsnull != dropdownFrame) {
|
||||
nsresult result = dropdownFrame->QueryInterface(kIFrameIID, (void**)&frame);
|
||||
if ((NS_SUCCEEDED(result)) && (nsnull != frame)) {
|
||||
frame->HandleEvent(*mPresContext, &event, status);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1346,6 +1348,7 @@ NS_IMETHODIMP
|
|||
nsComboboxControlFrame::Rollup()
|
||||
{
|
||||
if (mDroppedDown) {
|
||||
mListControlFrame->AboutToRollup();
|
||||
ShowDropDown(PR_FALSE);
|
||||
mListControlFrame->CaptureMouseEvents(PR_FALSE);
|
||||
}
|
||||
|
|
|
@ -86,6 +86,11 @@ public:
|
|||
*/
|
||||
NS_IMETHOD AboutToDropDown() = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD AboutToRollup() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -171,7 +171,7 @@ nsListControlFrame::Reflow(nsIPresContext& aPresContext,
|
|||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
#ifdef DEBUG_rods
|
||||
#ifdef DEBUG_rodsXXX
|
||||
printf("nsListControlFrame::Reflow Reason: ");
|
||||
switch (aReflowState.reason) {
|
||||
case eReflowReason_Initial:printf("eReflowReason_Initial\n");break;
|
||||
|
@ -1838,6 +1838,16 @@ nsListControlFrame::AboutToDropDown()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// We are about to be rolledup from the outside (ComboboxFrame)
|
||||
// this is a "cancelled" action not a selected action
|
||||
NS_IMETHODIMP
|
||||
nsListControlFrame::AboutToRollup()
|
||||
{
|
||||
ResetSelectedItem();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
nsresult
|
||||
nsListControlFrame::GetScrollingParentView(nsIFrame* aParent, nsIView** aParentView)
|
||||
|
@ -1941,6 +1951,14 @@ nsListControlFrame::IsTargetOptionDisabled(PRBool &aIsDisabled)
|
|||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// This is used to reset the the list and it's selection because the
|
||||
// selection was cancelled and the list rolled up.
|
||||
void nsListControlFrame::ResetSelectedItem()
|
||||
{
|
||||
ToggleSelected(mSelectedIndexWhenPoppedDown);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsIDOMMouseListener
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -1958,7 +1976,7 @@ nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
|
|||
if (NS_OK == IsTargetOptionDisabled(optionIsDisabled)) {
|
||||
if (optionIsDisabled) {
|
||||
if (IsInDropDownMode() == PR_TRUE && mComboboxFrame) {
|
||||
mSelectedIndex = mSelectedIndexWhenPoppedDown;
|
||||
ResetSelectedItem();
|
||||
mComboboxFrame->ListWasSelected(mPresContext);
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -2003,7 +2021,7 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent,
|
|||
if (NS_OK == mPresContext->GetEventStateManager(&stateManager)) {
|
||||
nsIContent * content;
|
||||
stateManager->GetEventTargetContent(&content);
|
||||
#ifdef DEBUG_rods
|
||||
#ifdef DEBUG_rodsXXX
|
||||
///////////////////
|
||||
{
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> optElem;
|
||||
|
@ -2043,7 +2061,7 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
|
|||
if (NS_OK == IsTargetOptionDisabled(optionIsDisabled)) {
|
||||
if (optionIsDisabled) {
|
||||
if (IsInDropDownMode() == PR_TRUE) {
|
||||
mSelectedIndex = mSelectedIndexWhenPoppedDown;
|
||||
ResetSelectedItem();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -2175,7 +2193,7 @@ nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
|
|||
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aKeyEvent);
|
||||
if (uiEvent) {
|
||||
PRUint32 code;
|
||||
uiEvent->GetCharCode(&code);
|
||||
//uiEvent->GetCharCode(&code);
|
||||
//printf("%c %d ", code, code);
|
||||
uiEvent->GetKeyCode(&code);
|
||||
//printf("%c %d\n", code, code);
|
||||
|
@ -2218,25 +2236,28 @@ nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
|
|||
}
|
||||
} if (code == nsIDOMUIEvent::DOM_VK_ESCAPE) {
|
||||
if (IsInDropDownMode() == PR_TRUE && mComboboxFrame) {
|
||||
mSelectedIndex = mSelectedIndexWhenPoppedDown;
|
||||
ResetSelectedItem();
|
||||
mComboboxFrame->ListWasSelected(mPresContext);
|
||||
}
|
||||
} else {
|
||||
// Not I18N compliant
|
||||
PRInt32 selectedIndex = (mSelectedIndex == kNothingSelected ? 0 : mSelectedIndex+1);
|
||||
PRInt32 inx;
|
||||
for (inx = selectedIndex;inx<(PRInt32)numOptions;inx++) {
|
||||
nsIDOMHTMLOptionElement* optionElement = GetOption(*options, inx);
|
||||
PRInt32 startedAtIndex = selectedIndex;
|
||||
PRBool loopedAround = PR_FALSE;
|
||||
if (selectedIndex == (PRInt32)numOptions) {
|
||||
selectedIndex = 0;
|
||||
}
|
||||
while ((selectedIndex < startedAtIndex && loopedAround) || !loopedAround) {
|
||||
nsIDOMHTMLOptionElement* optionElement = GetOption(*options, selectedIndex);
|
||||
if (nsnull != optionElement) {
|
||||
nsAutoString text;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == optionElement->GetText(text)) {
|
||||
//printf("%d == %d\n", text.CharAt(0), code);
|
||||
char * buf = text.ToNewCString();
|
||||
//printf("[%s] ", buf);
|
||||
char c = buf[0];
|
||||
delete [] buf;
|
||||
if (c == (char)code) {
|
||||
mOldSelectedIndex = mSelectedIndex;
|
||||
mSelectedIndex = inx;
|
||||
mSelectedIndex = selectedIndex;
|
||||
SingleSelection();
|
||||
if (nsnull != mComboboxFrame) {
|
||||
mComboboxFrame->UpdateSelection(PR_FALSE, PR_TRUE, mSelectedIndex); // don't dispatch event
|
||||
|
@ -2246,7 +2267,13 @@ nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
|
|||
}
|
||||
NS_RELEASE(optionElement);
|
||||
}
|
||||
selectedIndex++;
|
||||
if (selectedIndex == (PRInt32)numOptions) {
|
||||
selectedIndex = 0;
|
||||
loopedAround = PR_TRUE;
|
||||
}
|
||||
|
||||
} // while
|
||||
}
|
||||
}
|
||||
NS_RELEASE(options);
|
||||
|
|
|
@ -118,6 +118,7 @@ public:
|
|||
NS_IMETHOD GetNumberOfOptions(PRInt32* aNumOptions);
|
||||
NS_IMETHOD SyncViewWithFrame();
|
||||
NS_IMETHOD AboutToDropDown();
|
||||
NS_IMETHOD AboutToRollup();
|
||||
|
||||
// nsISelectControlFrame
|
||||
NS_IMETHOD AddOption(PRInt32 index);
|
||||
|
@ -198,6 +199,7 @@ protected:
|
|||
void ToggleSelected(PRInt32 aIndex);
|
||||
void ClearSelection();
|
||||
void ExtendedSelection(PRInt32 aStartIndex, PRInt32 aEndIndex, PRBool aDoInvert, PRBool aSetValue);
|
||||
void ResetSelectedItem();
|
||||
|
||||
PRBool HasSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2);
|
||||
void HandleListSelection(nsIDOMEvent * aDOMEvent);
|
||||
|
|
|
@ -86,6 +86,11 @@ public:
|
|||
*/
|
||||
NS_IMETHOD AboutToDropDown() = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD AboutToRollup() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -551,7 +551,7 @@ nsComboboxControlFrame::PositionDropdown(nsIPresContext& aPresContext,
|
|||
|
||||
//if (currentRect != dropdownRect) {
|
||||
dropdownFrame->SetRect(dropdownRect);
|
||||
#ifdef DEBUG_rods
|
||||
#ifdef DEBUG_rodsXXX
|
||||
printf("%d Position Dropdown at: %d %d %d %d\n", counter++, dropdownRect.x, dropdownRect.y, dropdownRect.width, dropdownRect.height);
|
||||
#endif
|
||||
//}
|
||||
|
@ -645,7 +645,7 @@ nsComboboxControlFrame::Reflow(nsIPresContext& aPresContext,
|
|||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
#ifdef DEBUG_rods
|
||||
#ifdef DEBUG_rodsXXX
|
||||
printf("nsComboboxControlFrame::Reflow %d Reason: ", myCounter++);
|
||||
switch (aReflowState.reason) {
|
||||
case eReflowReason_Initial:printf("eReflowReason_Initial\n");break;
|
||||
|
@ -1079,11 +1079,13 @@ nsComboboxControlFrame::SelectionChanged(PRBool aDoDispatchEvent)
|
|||
// Now have the frame handle the event
|
||||
nsIFrame* frame = nsnull;
|
||||
nsIFrame* dropdownFrame = GetDropdownFrame();
|
||||
if (nsnull != dropdownFrame) {
|
||||
nsresult result = dropdownFrame->QueryInterface(kIFrameIID, (void**)&frame);
|
||||
if ((NS_SUCCEEDED(result)) && (nsnull != frame)) {
|
||||
frame->HandleEvent(*mPresContext, &event, status);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1346,6 +1348,7 @@ NS_IMETHODIMP
|
|||
nsComboboxControlFrame::Rollup()
|
||||
{
|
||||
if (mDroppedDown) {
|
||||
mListControlFrame->AboutToRollup();
|
||||
ShowDropDown(PR_FALSE);
|
||||
mListControlFrame->CaptureMouseEvents(PR_FALSE);
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ nsListControlFrame::Reflow(nsIPresContext& aPresContext,
|
|||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
#ifdef DEBUG_rods
|
||||
#ifdef DEBUG_rodsXXX
|
||||
printf("nsListControlFrame::Reflow Reason: ");
|
||||
switch (aReflowState.reason) {
|
||||
case eReflowReason_Initial:printf("eReflowReason_Initial\n");break;
|
||||
|
@ -1838,6 +1838,16 @@ nsListControlFrame::AboutToDropDown()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// We are about to be rolledup from the outside (ComboboxFrame)
|
||||
// this is a "cancelled" action not a selected action
|
||||
NS_IMETHODIMP
|
||||
nsListControlFrame::AboutToRollup()
|
||||
{
|
||||
ResetSelectedItem();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
nsresult
|
||||
nsListControlFrame::GetScrollingParentView(nsIFrame* aParent, nsIView** aParentView)
|
||||
|
@ -1941,6 +1951,14 @@ nsListControlFrame::IsTargetOptionDisabled(PRBool &aIsDisabled)
|
|||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// This is used to reset the the list and it's selection because the
|
||||
// selection was cancelled and the list rolled up.
|
||||
void nsListControlFrame::ResetSelectedItem()
|
||||
{
|
||||
ToggleSelected(mSelectedIndexWhenPoppedDown);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsIDOMMouseListener
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -1958,7 +1976,7 @@ nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
|
|||
if (NS_OK == IsTargetOptionDisabled(optionIsDisabled)) {
|
||||
if (optionIsDisabled) {
|
||||
if (IsInDropDownMode() == PR_TRUE && mComboboxFrame) {
|
||||
mSelectedIndex = mSelectedIndexWhenPoppedDown;
|
||||
ResetSelectedItem();
|
||||
mComboboxFrame->ListWasSelected(mPresContext);
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -2003,7 +2021,7 @@ nsListControlFrame::GetIndexFromDOMEvent(nsIDOMEvent* aMouseEvent,
|
|||
if (NS_OK == mPresContext->GetEventStateManager(&stateManager)) {
|
||||
nsIContent * content;
|
||||
stateManager->GetEventTargetContent(&content);
|
||||
#ifdef DEBUG_rods
|
||||
#ifdef DEBUG_rodsXXX
|
||||
///////////////////
|
||||
{
|
||||
nsCOMPtr<nsIDOMHTMLOptionElement> optElem;
|
||||
|
@ -2043,7 +2061,7 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
|
|||
if (NS_OK == IsTargetOptionDisabled(optionIsDisabled)) {
|
||||
if (optionIsDisabled) {
|
||||
if (IsInDropDownMode() == PR_TRUE) {
|
||||
mSelectedIndex = mSelectedIndexWhenPoppedDown;
|
||||
ResetSelectedItem();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -2175,7 +2193,7 @@ nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
|
|||
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aKeyEvent);
|
||||
if (uiEvent) {
|
||||
PRUint32 code;
|
||||
uiEvent->GetCharCode(&code);
|
||||
//uiEvent->GetCharCode(&code);
|
||||
//printf("%c %d ", code, code);
|
||||
uiEvent->GetKeyCode(&code);
|
||||
//printf("%c %d\n", code, code);
|
||||
|
@ -2218,25 +2236,28 @@ nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
|
|||
}
|
||||
} if (code == nsIDOMUIEvent::DOM_VK_ESCAPE) {
|
||||
if (IsInDropDownMode() == PR_TRUE && mComboboxFrame) {
|
||||
mSelectedIndex = mSelectedIndexWhenPoppedDown;
|
||||
ResetSelectedItem();
|
||||
mComboboxFrame->ListWasSelected(mPresContext);
|
||||
}
|
||||
} else {
|
||||
// Not I18N compliant
|
||||
PRInt32 selectedIndex = (mSelectedIndex == kNothingSelected ? 0 : mSelectedIndex+1);
|
||||
PRInt32 inx;
|
||||
for (inx = selectedIndex;inx<(PRInt32)numOptions;inx++) {
|
||||
nsIDOMHTMLOptionElement* optionElement = GetOption(*options, inx);
|
||||
PRInt32 startedAtIndex = selectedIndex;
|
||||
PRBool loopedAround = PR_FALSE;
|
||||
if (selectedIndex == (PRInt32)numOptions) {
|
||||
selectedIndex = 0;
|
||||
}
|
||||
while ((selectedIndex < startedAtIndex && loopedAround) || !loopedAround) {
|
||||
nsIDOMHTMLOptionElement* optionElement = GetOption(*options, selectedIndex);
|
||||
if (nsnull != optionElement) {
|
||||
nsAutoString text;
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == optionElement->GetText(text)) {
|
||||
//printf("%d == %d\n", text.CharAt(0), code);
|
||||
char * buf = text.ToNewCString();
|
||||
//printf("[%s] ", buf);
|
||||
char c = buf[0];
|
||||
delete [] buf;
|
||||
if (c == (char)code) {
|
||||
mOldSelectedIndex = mSelectedIndex;
|
||||
mSelectedIndex = inx;
|
||||
mSelectedIndex = selectedIndex;
|
||||
SingleSelection();
|
||||
if (nsnull != mComboboxFrame) {
|
||||
mComboboxFrame->UpdateSelection(PR_FALSE, PR_TRUE, mSelectedIndex); // don't dispatch event
|
||||
|
@ -2246,7 +2267,13 @@ nsListControlFrame::KeyDown(nsIDOMEvent* aKeyEvent)
|
|||
}
|
||||
NS_RELEASE(optionElement);
|
||||
}
|
||||
selectedIndex++;
|
||||
if (selectedIndex == (PRInt32)numOptions) {
|
||||
selectedIndex = 0;
|
||||
loopedAround = PR_TRUE;
|
||||
}
|
||||
|
||||
} // while
|
||||
}
|
||||
}
|
||||
NS_RELEASE(options);
|
||||
|
|
|
@ -118,6 +118,7 @@ public:
|
|||
NS_IMETHOD GetNumberOfOptions(PRInt32* aNumOptions);
|
||||
NS_IMETHOD SyncViewWithFrame();
|
||||
NS_IMETHOD AboutToDropDown();
|
||||
NS_IMETHOD AboutToRollup();
|
||||
|
||||
// nsISelectControlFrame
|
||||
NS_IMETHOD AddOption(PRInt32 index);
|
||||
|
@ -198,6 +199,7 @@ protected:
|
|||
void ToggleSelected(PRInt32 aIndex);
|
||||
void ClearSelection();
|
||||
void ExtendedSelection(PRInt32 aStartIndex, PRInt32 aEndIndex, PRBool aDoInvert, PRBool aSetValue);
|
||||
void ResetSelectedItem();
|
||||
|
||||
PRBool HasSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2);
|
||||
void HandleListSelection(nsIDOMEvent * aDOMEvent);
|
||||
|
|
Загрузка…
Ссылка в новой задаче