Added the proper event processing for disabled options

ListBoxes (as dropdowns) are now notified before the are about to be dropped down
This commit is contained in:
rods%netscape.com 1999-09-08 14:27:38 +00:00
Родитель 7957e6f515
Коммит bd89429f51
8 изменённых файлов: 152 добавлений и 12 удалений

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

@ -357,6 +357,7 @@ nsComboboxControlFrame::ShowList(nsIPresContext* aPresContext, PRBool aShowList)
mDroppedDown = PR_TRUE; mDroppedDown = PR_TRUE;
// The listcontrol frame will call back to the nsComboboxControlFrame's ListWasSelected // The listcontrol frame will call back to the nsComboboxControlFrame's ListWasSelected
// which will stop the capture. // which will stop the capture.
mListControlFrame->AboutToDropDown();
mListControlFrame->CaptureMouseEvents(PR_TRUE); mListControlFrame->CaptureMouseEvents(PR_TRUE);
} else { } else {
ShowPopup(PR_FALSE); ShowPopup(PR_FALSE);
@ -892,7 +893,7 @@ nsComboboxControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
PositionDropdown(*mPresContext, displayRect.height, absoluteTwips, absolutePixels); PositionDropdown(*mPresContext, displayRect.height, absoluteTwips, absolutePixels);
ToggleList(mPresContext); ToggleList(mPresContext);
mIgnoreMouseUp = PR_TRUE; //mIgnoreMouseUp = PR_TRUE;
*/ */
return NS_OK; return NS_OK;
} }

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

@ -81,6 +81,11 @@ public:
*/ */
NS_IMETHOD SyncViewWithFrame() = 0; NS_IMETHOD SyncViewWithFrame() = 0;
/**
*
*/
NS_IMETHOD AboutToDropDown() = 0;
}; };
#endif #endif

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

@ -201,6 +201,8 @@ nsListControlFrame::Reflow(nsIPresContext& aPresContext,
//longest element in the list //longest element in the list
nsHTMLReflowState secondPassState(aReflowState); nsHTMLReflowState secondPassState(aReflowState);
nsHTMLReflowState firstPassState(aReflowState); nsHTMLReflowState firstPassState(aReflowState);
//nsHTMLReflowState firstPassState(aPresContext, nsnull,
// this, aDesiredSize);
// Get the size of option elements inside the listbox // Get the size of option elements inside the listbox
// Compute the width based on the longest line in the listbox. // Compute the width based on the longest line in the listbox.
@ -261,6 +263,12 @@ nsListControlFrame::Reflow(nsIPresContext& aPresContext,
border.SizeTo(0, 0, 0, 0); border.SizeTo(0, 0, 0, 0);
} }
nsMargin padding;
if (!aReflowState.mStyleSpacing->GetPadding(padding)) {
NS_NOTYETIMPLEMENTED("percentage padding");
padding.SizeTo(0, 0, 0, 0);
}
mBorderOffsetY = border.top; mBorderOffsetY = border.top;
scrolledAreaWidth -= (border.left + border.right); scrolledAreaWidth -= (border.left + border.right);
@ -1122,6 +1130,7 @@ nsListControlFrame::IsContentSelected(nsIContent* aContent)
{ {
nsString value; nsString value;
nsIAtom * selectedAtom = NS_NewAtom(kMozSelected); nsIAtom * selectedAtom = NS_NewAtom(kMozSelected);
//nsIAtom * selectedAtom = NS_NewAtom("selected");
nsresult result = aContent->GetAttribute(kNameSpaceID_None, selectedAtom, value); nsresult result = aContent->GetAttribute(kNameSpaceID_None, selectedAtom, value);
NS_RELEASE(selectedAtom); NS_RELEASE(selectedAtom);
@ -1751,6 +1760,14 @@ nsListControlFrame::SyncViewWithFrame()
return NS_OK; return NS_OK;
} }
//---------------------------------------------------------
NS_IMETHODIMP
nsListControlFrame::AboutToDropDown()
{
mSelectedIndexWhenPoppedDown = mSelectedIndex;
return NS_OK;
}
//--------------------------------------------------------- //---------------------------------------------------------
nsresult nsresult
nsListControlFrame::GetScrollingParentView(nsIFrame* aParent, nsIView** aParentView) nsListControlFrame::GetScrollingParentView(nsIFrame* aParent, nsIView** aParentView)
@ -1829,20 +1846,55 @@ nsListControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight)
return NS_OK; return NS_OK;
} }
//---------------------------------------------------------
NS_IMETHODIMP
nsListControlFrame::IsTargetOptionDisabled(PRBool &aIsDisabled)
{
nsresult rv = NS_ERROR_FAILURE;
aIsDisabled = PR_FALSE;
nsIEventStateManager *stateManager;
rv = mPresContext->GetEventStateManager(&stateManager);
if (NS_OK == rv) {
nsIContent * content;
rv = stateManager->GetEventTargetContent(&content);
if (NS_OK == rv && nsnull != content) {
if (IsOptionElement(content)) {
aIsDisabled = nsFormFrame::GetDisabled(this, content);
} else {
rv = NS_ERROR_FAILURE; // return error when it is not an option
}
NS_RELEASE(content);
}
NS_RELEASE(stateManager);
}
return rv;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// nsIDOMMouseListener // nsIDOMMouseListener
//---------------------------------------------------------------------- //----------------------------------------------------------------------
nsresult nsresult
nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent) nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
{ {
//if (nsEventStatus_eConsumeNoDefault == aEventStatus) {
// return NS_OK;
//}
if (nsFormFrame::GetDisabled(this)) { if (nsFormFrame::GetDisabled(this)) {
return NS_OK; return NS_OK;
} }
// Check to see if the disabled option was clicked on
// NS_ERROR_FAILURE is returned is it isn't over an option
PRBool optionIsDisabled;
if (NS_OK == IsTargetOptionDisabled(optionIsDisabled)) {
if (optionIsDisabled) {
mSelectedIndex = mSelectedIndexWhenPoppedDown;
if (IsInDropDownMode() == PR_TRUE && mComboboxFrame) {
mComboboxFrame->ListWasSelected(mPresContext);
}
return NS_OK;
}
}
const nsStyleDisplay* disp = (const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display); const nsStyleDisplay* disp = (const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
if (!disp->mVisible) { if (!disp->mVisible) {
return NS_OK; return NS_OK;
@ -1912,6 +1964,15 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
if (nsFormFrame::GetDisabled(this)) { if (nsFormFrame::GetDisabled(this)) {
return NS_OK; return NS_OK;
} }
// Check to see if the disabled option was clicked on
// NS_ERROR_FAILURE is returned is it isn't over an option
PRBool optionIsDisabled;
if (NS_OK == IsTargetOptionDisabled(optionIsDisabled)) {
mSelectedIndex = mSelectedIndexWhenPoppedDown;
return NS_OK;
}
PRInt32 oldIndex; PRInt32 oldIndex;
PRInt32 curIndex = mSelectedIndex; PRInt32 curIndex = mSelectedIndex;
@ -1927,6 +1988,7 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
HandleListSelection(aMouseEvent); HandleListSelection(aMouseEvent);
} }
} else { } else {
// NOTE: the combo box is responsible for dropping it down
if (mComboboxFrame) { if (mComboboxFrame) {
PRBool isDroppedDown; PRBool isDroppedDown;
mComboboxFrame->IsDroppedDown(&isDroppedDown); mComboboxFrame->IsDroppedDown(&isDroppedDown);

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

@ -114,6 +114,7 @@ public:
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight); NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
NS_IMETHOD GetNumberOfOptions(PRInt32* aNumOptions); NS_IMETHOD GetNumberOfOptions(PRInt32* aNumOptions);
NS_IMETHOD SyncViewWithFrame(); NS_IMETHOD SyncViewWithFrame();
NS_IMETHOD AboutToDropDown();
// nsISelectControlFrame // nsISelectControlFrame
NS_IMETHOD AddOption(PRInt32 index); NS_IMETHOD AddOption(PRInt32 index);
@ -147,7 +148,8 @@ public:
protected: protected:
NS_IMETHOD GetSelectedIndexFromDOM(PRInt32* aIndex); // from DOM NS_IMETHOD GetSelectedIndexFromDOM(PRInt32* aIndex); // from DOM
NS_IMETHOD IsTargetOptionDisabled(PRBool &aIsDisabled);
nsListControlFrame(); nsListControlFrame();
virtual ~nsListControlFrame(); virtual ~nsListControlFrame();
@ -191,12 +193,12 @@ protected:
PRBool HasSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2); PRBool HasSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2);
void HandleListSelection(nsIDOMEvent * aDOMEvent); void HandleListSelection(nsIDOMEvent * aDOMEvent);
PRInt32 GetSelectedIndexFromFrame(nsIFrame *aHitFrame); PRInt32 GetSelectedIndexFromFrame(nsIFrame *aHitFrame);
// Data Members // Data Members
nscoord mBorderOffsetY; nscoord mBorderOffsetY;
nsFormFrame* mFormFrame; nsFormFrame* mFormFrame;
PRInt32 mSelectedIndex; PRInt32 mSelectedIndex;
PRInt32 mOldSelectedIndex; PRInt32 mOldSelectedIndex;
PRInt32 mSelectedIndexWhenPoppedDown;
PRInt32 mStartExtendedIndex; PRInt32 mStartExtendedIndex;
PRInt32 mEndExtendedIndex; PRInt32 mEndExtendedIndex;
nsIFrame* mHitFrame; nsIFrame* mHitFrame;

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

@ -81,6 +81,11 @@ public:
*/ */
NS_IMETHOD SyncViewWithFrame() = 0; NS_IMETHOD SyncViewWithFrame() = 0;
/**
*
*/
NS_IMETHOD AboutToDropDown() = 0;
}; };
#endif #endif

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

@ -357,6 +357,7 @@ nsComboboxControlFrame::ShowList(nsIPresContext* aPresContext, PRBool aShowList)
mDroppedDown = PR_TRUE; mDroppedDown = PR_TRUE;
// The listcontrol frame will call back to the nsComboboxControlFrame's ListWasSelected // The listcontrol frame will call back to the nsComboboxControlFrame's ListWasSelected
// which will stop the capture. // which will stop the capture.
mListControlFrame->AboutToDropDown();
mListControlFrame->CaptureMouseEvents(PR_TRUE); mListControlFrame->CaptureMouseEvents(PR_TRUE);
} else { } else {
ShowPopup(PR_FALSE); ShowPopup(PR_FALSE);
@ -892,7 +893,7 @@ nsComboboxControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
PositionDropdown(*mPresContext, displayRect.height, absoluteTwips, absolutePixels); PositionDropdown(*mPresContext, displayRect.height, absoluteTwips, absolutePixels);
ToggleList(mPresContext); ToggleList(mPresContext);
mIgnoreMouseUp = PR_TRUE; //mIgnoreMouseUp = PR_TRUE;
*/ */
return NS_OK; return NS_OK;
} }

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

@ -201,6 +201,8 @@ nsListControlFrame::Reflow(nsIPresContext& aPresContext,
//longest element in the list //longest element in the list
nsHTMLReflowState secondPassState(aReflowState); nsHTMLReflowState secondPassState(aReflowState);
nsHTMLReflowState firstPassState(aReflowState); nsHTMLReflowState firstPassState(aReflowState);
//nsHTMLReflowState firstPassState(aPresContext, nsnull,
// this, aDesiredSize);
// Get the size of option elements inside the listbox // Get the size of option elements inside the listbox
// Compute the width based on the longest line in the listbox. // Compute the width based on the longest line in the listbox.
@ -261,6 +263,12 @@ nsListControlFrame::Reflow(nsIPresContext& aPresContext,
border.SizeTo(0, 0, 0, 0); border.SizeTo(0, 0, 0, 0);
} }
nsMargin padding;
if (!aReflowState.mStyleSpacing->GetPadding(padding)) {
NS_NOTYETIMPLEMENTED("percentage padding");
padding.SizeTo(0, 0, 0, 0);
}
mBorderOffsetY = border.top; mBorderOffsetY = border.top;
scrolledAreaWidth -= (border.left + border.right); scrolledAreaWidth -= (border.left + border.right);
@ -1122,6 +1130,7 @@ nsListControlFrame::IsContentSelected(nsIContent* aContent)
{ {
nsString value; nsString value;
nsIAtom * selectedAtom = NS_NewAtom(kMozSelected); nsIAtom * selectedAtom = NS_NewAtom(kMozSelected);
//nsIAtom * selectedAtom = NS_NewAtom("selected");
nsresult result = aContent->GetAttribute(kNameSpaceID_None, selectedAtom, value); nsresult result = aContent->GetAttribute(kNameSpaceID_None, selectedAtom, value);
NS_RELEASE(selectedAtom); NS_RELEASE(selectedAtom);
@ -1751,6 +1760,14 @@ nsListControlFrame::SyncViewWithFrame()
return NS_OK; return NS_OK;
} }
//---------------------------------------------------------
NS_IMETHODIMP
nsListControlFrame::AboutToDropDown()
{
mSelectedIndexWhenPoppedDown = mSelectedIndex;
return NS_OK;
}
//--------------------------------------------------------- //---------------------------------------------------------
nsresult nsresult
nsListControlFrame::GetScrollingParentView(nsIFrame* aParent, nsIView** aParentView) nsListControlFrame::GetScrollingParentView(nsIFrame* aParent, nsIView** aParentView)
@ -1829,20 +1846,55 @@ nsListControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight)
return NS_OK; return NS_OK;
} }
//---------------------------------------------------------
NS_IMETHODIMP
nsListControlFrame::IsTargetOptionDisabled(PRBool &aIsDisabled)
{
nsresult rv = NS_ERROR_FAILURE;
aIsDisabled = PR_FALSE;
nsIEventStateManager *stateManager;
rv = mPresContext->GetEventStateManager(&stateManager);
if (NS_OK == rv) {
nsIContent * content;
rv = stateManager->GetEventTargetContent(&content);
if (NS_OK == rv && nsnull != content) {
if (IsOptionElement(content)) {
aIsDisabled = nsFormFrame::GetDisabled(this, content);
} else {
rv = NS_ERROR_FAILURE; // return error when it is not an option
}
NS_RELEASE(content);
}
NS_RELEASE(stateManager);
}
return rv;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// nsIDOMMouseListener // nsIDOMMouseListener
//---------------------------------------------------------------------- //----------------------------------------------------------------------
nsresult nsresult
nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent) nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
{ {
//if (nsEventStatus_eConsumeNoDefault == aEventStatus) {
// return NS_OK;
//}
if (nsFormFrame::GetDisabled(this)) { if (nsFormFrame::GetDisabled(this)) {
return NS_OK; return NS_OK;
} }
// Check to see if the disabled option was clicked on
// NS_ERROR_FAILURE is returned is it isn't over an option
PRBool optionIsDisabled;
if (NS_OK == IsTargetOptionDisabled(optionIsDisabled)) {
if (optionIsDisabled) {
mSelectedIndex = mSelectedIndexWhenPoppedDown;
if (IsInDropDownMode() == PR_TRUE && mComboboxFrame) {
mComboboxFrame->ListWasSelected(mPresContext);
}
return NS_OK;
}
}
const nsStyleDisplay* disp = (const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display); const nsStyleDisplay* disp = (const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
if (!disp->mVisible) { if (!disp->mVisible) {
return NS_OK; return NS_OK;
@ -1912,6 +1964,15 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
if (nsFormFrame::GetDisabled(this)) { if (nsFormFrame::GetDisabled(this)) {
return NS_OK; return NS_OK;
} }
// Check to see if the disabled option was clicked on
// NS_ERROR_FAILURE is returned is it isn't over an option
PRBool optionIsDisabled;
if (NS_OK == IsTargetOptionDisabled(optionIsDisabled)) {
mSelectedIndex = mSelectedIndexWhenPoppedDown;
return NS_OK;
}
PRInt32 oldIndex; PRInt32 oldIndex;
PRInt32 curIndex = mSelectedIndex; PRInt32 curIndex = mSelectedIndex;
@ -1927,6 +1988,7 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
HandleListSelection(aMouseEvent); HandleListSelection(aMouseEvent);
} }
} else { } else {
// NOTE: the combo box is responsible for dropping it down
if (mComboboxFrame) { if (mComboboxFrame) {
PRBool isDroppedDown; PRBool isDroppedDown;
mComboboxFrame->IsDroppedDown(&isDroppedDown); mComboboxFrame->IsDroppedDown(&isDroppedDown);

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

@ -114,6 +114,7 @@ public:
NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight); NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight);
NS_IMETHOD GetNumberOfOptions(PRInt32* aNumOptions); NS_IMETHOD GetNumberOfOptions(PRInt32* aNumOptions);
NS_IMETHOD SyncViewWithFrame(); NS_IMETHOD SyncViewWithFrame();
NS_IMETHOD AboutToDropDown();
// nsISelectControlFrame // nsISelectControlFrame
NS_IMETHOD AddOption(PRInt32 index); NS_IMETHOD AddOption(PRInt32 index);
@ -147,7 +148,8 @@ public:
protected: protected:
NS_IMETHOD GetSelectedIndexFromDOM(PRInt32* aIndex); // from DOM NS_IMETHOD GetSelectedIndexFromDOM(PRInt32* aIndex); // from DOM
NS_IMETHOD IsTargetOptionDisabled(PRBool &aIsDisabled);
nsListControlFrame(); nsListControlFrame();
virtual ~nsListControlFrame(); virtual ~nsListControlFrame();
@ -191,12 +193,12 @@ protected:
PRBool HasSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2); PRBool HasSameContent(nsIFrame* aFrame1, nsIFrame* aFrame2);
void HandleListSelection(nsIDOMEvent * aDOMEvent); void HandleListSelection(nsIDOMEvent * aDOMEvent);
PRInt32 GetSelectedIndexFromFrame(nsIFrame *aHitFrame); PRInt32 GetSelectedIndexFromFrame(nsIFrame *aHitFrame);
// Data Members // Data Members
nscoord mBorderOffsetY; nscoord mBorderOffsetY;
nsFormFrame* mFormFrame; nsFormFrame* mFormFrame;
PRInt32 mSelectedIndex; PRInt32 mSelectedIndex;
PRInt32 mOldSelectedIndex; PRInt32 mOldSelectedIndex;
PRInt32 mSelectedIndexWhenPoppedDown;
PRInt32 mStartExtendedIndex; PRInt32 mStartExtendedIndex;
PRInt32 mEndExtendedIndex; PRInt32 mEndExtendedIndex;
nsIFrame* mHitFrame; nsIFrame* mHitFrame;