removing dom listeners on descruction

exposed absolutely positioning of the dropdown
now tries to SyncFrameWithView


git-svn-id: svn://10.0.0.236/trunk@45339 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rods%netscape.com
1999-08-31 13:22:40 +00:00
parent 280b982d3a
commit 0bd721ba73
4 changed files with 72 additions and 14 deletions

View File

@@ -103,6 +103,14 @@ nsComboboxControlFrame::nsComboboxControlFrame()
//--------------------------------------------------------------
nsComboboxControlFrame::~nsComboboxControlFrame()
{
// get the reciever interface from the browser button's content node
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(mButtonContent));
reciever->RemoveEventListenerByIID((nsIDOMMouseListener *)this, kIDOMMouseListenerIID);
nsCOMPtr<nsIDOMEventReceiver> displayReciever(do_QueryInterface(mDisplayContent));
displayReciever->RemoveEventListenerByIID((nsIDOMMouseListener *)this, kIDOMMouseListenerIID);
//selectReciever->RemoveEventListenerByIID((nsIDOMFocusListener *)this, nsCOMTypeInfo<nsIDOMFocusListener>::GetIID());
mFormFrame = nsnull;
NS_IF_RELEASE(mPresContext);
NS_IF_RELEASE(mDisplayContent);
@@ -732,6 +740,7 @@ nsComboboxControlFrame::Reflow(nsIPresContext& aPresContext,
// Reflow display + button
nsAreaFrame::Reflow(aPresContext, aDesiredSize, firstPassState, aStatus);
displayFrame->GetRect(displayRect);
buttonFrame->GetRect(buttonRect);
// Reflow the dropdown list to match the width of the display + button
ReflowComboChildFrame(dropdownFrame, aPresContext, dropdownDesiredSize, firstPassState, aStatus, aDesiredSize.width, NS_UNCONSTRAINEDSIZE);
@@ -927,10 +936,12 @@ nsComboboxControlFrame::ShowDropDown(PRBool aDoDropDown)
nsIFrame * displayFrame = GetDisplayFrame(*mPresContext);
nsRect displayRect;
// Get the current sizes of the combo box child frames
displayFrame->GetRect(displayRect);
GetAbsoluteFramePosition(*mPresContext, displayFrame, absoluteTwips, absolutePixels);
PositionDropdown(*mPresContext, displayRect.height, absoluteTwips, absolutePixels);
//displayFrame->GetRect(displayRect);
//GetAbsoluteFramePosition(*mPresContext, displayFrame, absoluteTwips, absolutePixels);
//PositionDropdown(*mPresContext, displayRect.height, absoluteTwips, absolutePixels);
if (mListControlFrame) {
mListControlFrame->SyncViewWithFrame();
}
ToggleList(mPresContext);
return NS_OK;
} else if (mDroppedDown && !aDoDropDown) {
@@ -944,7 +955,7 @@ nsComboboxControlFrame::ShowDropDown(PRBool aDoDropDown)
NS_IMETHODIMP
nsComboboxControlFrame::SetDropDown(nsIFrame* aDropDownFrame)
{
mDropdownFrame = aDropDownFrame;
mDropdownFrame = aDropDownFrame;
if (NS_OK != mDropdownFrame->QueryInterface(kIListControlFrameIID, (void**)&mListControlFrame)) {
return NS_ERROR_FAILURE;
@@ -1017,6 +1028,21 @@ nsComboboxControlFrame::UpdateSelection(PRBool aDoDispatchEvent, PRBool aForceUp
return NS_OK;
}
NS_IMETHODIMP
nsComboboxControlFrame::AbsolutelyPositionDropDown()
{
nsRect absoluteTwips;
nsRect absolutePixels;
nsIFrame* displayFrame = GetDisplayFrame(*mPresContext);
nsRect rect;
displayFrame->GetRect(rect);
GetAbsoluteFramePosition(*mPresContext, displayFrame, absoluteTwips, absolutePixels);
PositionDropdown(*mPresContext, rect.height, absoluteTwips, absolutePixels);
return NS_OK;
}
///////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsComboboxControlFrame::SelectionChanged(PRBool aDoDispatchEvent)
{
@@ -1180,11 +1206,11 @@ nsComboboxControlFrame::CreateAnonymousContent(nsISupportsArray& aChildList)
NS_NewHTMLInputElement(&mDisplayContent, tag);
NS_ADDREF(mDisplayContent);
mDisplayContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, nsAutoString("button"), PR_FALSE);
//mDisplayContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::readonly, nsAutoString("true"), PR_FALSE);
//XXX: Do not use nsHTMLAtoms::id use nsHTMLAtoms::kClass instead. There will end up being multiple
//ids set to the same value which is illegal.
mDisplayContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::id, nsAutoString("-moz-display"), PR_FALSE);
// This is
mDisplayContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, nsAutoString("X"), PR_TRUE);
aChildList.AppendElement(mDisplayContent);

View File

@@ -139,6 +139,7 @@ public:
NS_IMETHOD SetDropDown(nsIFrame* aDropDownFrame);
NS_IMETHOD ListWasSelected(nsIPresContext* aPresContext);
NS_IMETHOD UpdateSelection(PRBool aDoDispatchEvent, PRBool aForceUpdate, PRInt32 aNewIndex);
NS_IMETHOD AbsolutelyPositionDropDown();
// nsISelectControlFrame
NS_IMETHOD AddOption(PRInt32 index);
@@ -173,6 +174,7 @@ protected:
nscoord aAvailableHeight);
nsresult GetScreenHeight(nsIPresContext& aPresContext, nscoord& aHeight);
public:
nsresult PositionDropdown(nsIPresContext& aPresContext,
nscoord aHeight,
nsRect aAbsoluteTwipsRect,
@@ -181,13 +183,14 @@ protected:
nsIFrame *aFrame,
nsRect& aAbsoluteTwipsRect,
nsRect& aAbsolutePixelRect);
nsIFrame* GetDisplayFrame(nsIPresContext& aPresContext);
protected:
void ShowPopup(PRBool aShowPopup);
void ShowList(nsIPresContext* aPresContext, PRBool aShowList);
void SetChildFrameSize(nsIFrame* aFrame, nscoord aWidth, nscoord aHeight);
void InitTextStr(PRBool aUpdate);
nsresult GetPrimaryComboFrame(nsIPresContext& aPresContext, nsIContent* aContent, nsIFrame** aFrame);
nsIFrame* GetButtonFrame(nsIPresContext& aPresContext);
nsIFrame* GetDisplayFrame(nsIPresContext& aPresContext);
nsIFrame* GetDropdownFrame();
NS_IMETHOD ToggleList(nsIPresContext* aPresContext);

View File

@@ -103,6 +103,14 @@ nsComboboxControlFrame::nsComboboxControlFrame()
//--------------------------------------------------------------
nsComboboxControlFrame::~nsComboboxControlFrame()
{
// get the reciever interface from the browser button's content node
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(mButtonContent));
reciever->RemoveEventListenerByIID((nsIDOMMouseListener *)this, kIDOMMouseListenerIID);
nsCOMPtr<nsIDOMEventReceiver> displayReciever(do_QueryInterface(mDisplayContent));
displayReciever->RemoveEventListenerByIID((nsIDOMMouseListener *)this, kIDOMMouseListenerIID);
//selectReciever->RemoveEventListenerByIID((nsIDOMFocusListener *)this, nsCOMTypeInfo<nsIDOMFocusListener>::GetIID());
mFormFrame = nsnull;
NS_IF_RELEASE(mPresContext);
NS_IF_RELEASE(mDisplayContent);
@@ -732,6 +740,7 @@ nsComboboxControlFrame::Reflow(nsIPresContext& aPresContext,
// Reflow display + button
nsAreaFrame::Reflow(aPresContext, aDesiredSize, firstPassState, aStatus);
displayFrame->GetRect(displayRect);
buttonFrame->GetRect(buttonRect);
// Reflow the dropdown list to match the width of the display + button
ReflowComboChildFrame(dropdownFrame, aPresContext, dropdownDesiredSize, firstPassState, aStatus, aDesiredSize.width, NS_UNCONSTRAINEDSIZE);
@@ -927,10 +936,12 @@ nsComboboxControlFrame::ShowDropDown(PRBool aDoDropDown)
nsIFrame * displayFrame = GetDisplayFrame(*mPresContext);
nsRect displayRect;
// Get the current sizes of the combo box child frames
displayFrame->GetRect(displayRect);
GetAbsoluteFramePosition(*mPresContext, displayFrame, absoluteTwips, absolutePixels);
PositionDropdown(*mPresContext, displayRect.height, absoluteTwips, absolutePixels);
//displayFrame->GetRect(displayRect);
//GetAbsoluteFramePosition(*mPresContext, displayFrame, absoluteTwips, absolutePixels);
//PositionDropdown(*mPresContext, displayRect.height, absoluteTwips, absolutePixels);
if (mListControlFrame) {
mListControlFrame->SyncViewWithFrame();
}
ToggleList(mPresContext);
return NS_OK;
} else if (mDroppedDown && !aDoDropDown) {
@@ -944,7 +955,7 @@ nsComboboxControlFrame::ShowDropDown(PRBool aDoDropDown)
NS_IMETHODIMP
nsComboboxControlFrame::SetDropDown(nsIFrame* aDropDownFrame)
{
mDropdownFrame = aDropDownFrame;
mDropdownFrame = aDropDownFrame;
if (NS_OK != mDropdownFrame->QueryInterface(kIListControlFrameIID, (void**)&mListControlFrame)) {
return NS_ERROR_FAILURE;
@@ -1017,6 +1028,21 @@ nsComboboxControlFrame::UpdateSelection(PRBool aDoDispatchEvent, PRBool aForceUp
return NS_OK;
}
NS_IMETHODIMP
nsComboboxControlFrame::AbsolutelyPositionDropDown()
{
nsRect absoluteTwips;
nsRect absolutePixels;
nsIFrame* displayFrame = GetDisplayFrame(*mPresContext);
nsRect rect;
displayFrame->GetRect(rect);
GetAbsoluteFramePosition(*mPresContext, displayFrame, absoluteTwips, absolutePixels);
PositionDropdown(*mPresContext, rect.height, absoluteTwips, absolutePixels);
return NS_OK;
}
///////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsComboboxControlFrame::SelectionChanged(PRBool aDoDispatchEvent)
{
@@ -1180,11 +1206,11 @@ nsComboboxControlFrame::CreateAnonymousContent(nsISupportsArray& aChildList)
NS_NewHTMLInputElement(&mDisplayContent, tag);
NS_ADDREF(mDisplayContent);
mDisplayContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, nsAutoString("button"), PR_FALSE);
//mDisplayContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::readonly, nsAutoString("true"), PR_FALSE);
//XXX: Do not use nsHTMLAtoms::id use nsHTMLAtoms::kClass instead. There will end up being multiple
//ids set to the same value which is illegal.
mDisplayContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::id, nsAutoString("-moz-display"), PR_FALSE);
// This is
mDisplayContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, nsAutoString("X"), PR_TRUE);
aChildList.AppendElement(mDisplayContent);

View File

@@ -139,6 +139,7 @@ public:
NS_IMETHOD SetDropDown(nsIFrame* aDropDownFrame);
NS_IMETHOD ListWasSelected(nsIPresContext* aPresContext);
NS_IMETHOD UpdateSelection(PRBool aDoDispatchEvent, PRBool aForceUpdate, PRInt32 aNewIndex);
NS_IMETHOD AbsolutelyPositionDropDown();
// nsISelectControlFrame
NS_IMETHOD AddOption(PRInt32 index);
@@ -173,6 +174,7 @@ protected:
nscoord aAvailableHeight);
nsresult GetScreenHeight(nsIPresContext& aPresContext, nscoord& aHeight);
public:
nsresult PositionDropdown(nsIPresContext& aPresContext,
nscoord aHeight,
nsRect aAbsoluteTwipsRect,
@@ -181,13 +183,14 @@ protected:
nsIFrame *aFrame,
nsRect& aAbsoluteTwipsRect,
nsRect& aAbsolutePixelRect);
nsIFrame* GetDisplayFrame(nsIPresContext& aPresContext);
protected:
void ShowPopup(PRBool aShowPopup);
void ShowList(nsIPresContext* aPresContext, PRBool aShowList);
void SetChildFrameSize(nsIFrame* aFrame, nscoord aWidth, nscoord aHeight);
void InitTextStr(PRBool aUpdate);
nsresult GetPrimaryComboFrame(nsIPresContext& aPresContext, nsIContent* aContent, nsIFrame** aFrame);
nsIFrame* GetButtonFrame(nsIPresContext& aPresContext);
nsIFrame* GetDisplayFrame(nsIPresContext& aPresContext);
nsIFrame* GetDropdownFrame();
NS_IMETHOD ToggleList(nsIPresContext* aPresContext);