From 0bd721ba73519f8ae2a14d238460442ab8c305f4 Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Tue, 31 Aug 1999 13:22:40 +0000 Subject: [PATCH] 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 --- .../layout/forms/nsComboboxControlFrame.cpp | 38 ++++++++++++++++--- mozilla/layout/forms/nsComboboxControlFrame.h | 5 ++- .../html/forms/src/nsComboboxControlFrame.cpp | 38 ++++++++++++++++--- .../html/forms/src/nsComboboxControlFrame.h | 5 ++- 4 files changed, 72 insertions(+), 14 deletions(-) diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index cf990ac990a..c74c4c6b462 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -103,6 +103,14 @@ nsComboboxControlFrame::nsComboboxControlFrame() //-------------------------------------------------------------- nsComboboxControlFrame::~nsComboboxControlFrame() { + // get the reciever interface from the browser button's content node + nsCOMPtr reciever(do_QueryInterface(mButtonContent)); + reciever->RemoveEventListenerByIID((nsIDOMMouseListener *)this, kIDOMMouseListenerIID); + + nsCOMPtr displayReciever(do_QueryInterface(mDisplayContent)); + displayReciever->RemoveEventListenerByIID((nsIDOMMouseListener *)this, kIDOMMouseListenerIID); + //selectReciever->RemoveEventListenerByIID((nsIDOMFocusListener *)this, nsCOMTypeInfo::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); diff --git a/mozilla/layout/forms/nsComboboxControlFrame.h b/mozilla/layout/forms/nsComboboxControlFrame.h index 02757badf9d..34539e60562 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.h +++ b/mozilla/layout/forms/nsComboboxControlFrame.h @@ -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); diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index cf990ac990a..c74c4c6b462 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -103,6 +103,14 @@ nsComboboxControlFrame::nsComboboxControlFrame() //-------------------------------------------------------------- nsComboboxControlFrame::~nsComboboxControlFrame() { + // get the reciever interface from the browser button's content node + nsCOMPtr reciever(do_QueryInterface(mButtonContent)); + reciever->RemoveEventListenerByIID((nsIDOMMouseListener *)this, kIDOMMouseListenerIID); + + nsCOMPtr displayReciever(do_QueryInterface(mDisplayContent)); + displayReciever->RemoveEventListenerByIID((nsIDOMMouseListener *)this, kIDOMMouseListenerIID); + //selectReciever->RemoveEventListenerByIID((nsIDOMFocusListener *)this, nsCOMTypeInfo::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); diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h index 02757badf9d..34539e60562 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.h +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.h @@ -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);