From 21df11ab85d7f562a1dc9b039c1e29d7bc7af877 Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Sun, 17 Mar 2002 23:41:22 +0000 Subject: [PATCH] Hardcode sizetopopup=always behavior for HTML select widgets, that way we don't pollute the HTML DOM with our attribute. Also, factoring out the sizetopopup check into a helper method. Bug 128947, r=jkeiser, sr=brendan, a=dbaron. --- layout/forms/resources/content/select.xml | 2 +- .../html/forms/resources/content/select.xml | 2 +- layout/xul/base/src/nsMenuFrame.cpp | 40 ++++++++++--------- layout/xul/base/src/nsMenuFrame.h | 2 + layout/xul/base/src/nsMenuPopupFrame.cpp | 8 +--- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/layout/forms/resources/content/select.xml b/layout/forms/resources/content/select.xml index 228a5897c9f6..103bb8712f9c 100644 --- a/layout/forms/resources/content/select.xml +++ b/layout/forms/resources/content/select.xml @@ -654,7 +654,7 @@ ]]> - + diff --git a/layout/html/forms/resources/content/select.xml b/layout/html/forms/resources/content/select.xml index 228a5897c9f6..103bb8712f9c 100644 --- a/layout/html/forms/resources/content/select.xml +++ b/layout/html/forms/resources/content/select.xml @@ -654,7 +654,7 @@ ]]> - + diff --git a/layout/xul/base/src/nsMenuFrame.cpp b/layout/xul/base/src/nsMenuFrame.cpp index 822aa0642f24..3f272a7c8b46 100644 --- a/layout/xul/base/src/nsMenuFrame.cpp +++ b/layout/xul/base/src/nsMenuFrame.cpp @@ -938,6 +938,24 @@ nsMenuFrame::GetMenuChildrenElement(nsIContent** aResult) } } +PRBool +nsMenuFrame::IsSizedToPopup(nsIContent* aContent, PRBool aRequireAlways) +{ + nsCOMPtr tag; + aContent->GetTag(*getter_AddRefs(tag)); + PRBool sizeToPopup; + if (tag == nsHTMLAtoms::select) + sizeToPopup = PR_TRUE; + else { + nsAutoString sizedToPopup; + aContent->GetAttr(kNameSpaceID_None, nsXULAtoms::sizetopopup, sizedToPopup); + sizeToPopup = (sizedToPopup.EqualsIgnoreCase("always") || + (!aRequireAlways && sizedToPopup.EqualsIgnoreCase("pref"))); + } + + return sizeToPopup; +} + NS_IMETHODIMP nsMenuFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize) { @@ -953,13 +971,8 @@ nsMenuFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize) nsIFrame* popupChild = mPopupFrames.FirstChild(); - if (popupChild) { - nsAutoString sizedToPopup; - mContent->GetAttr(kNameSpaceID_None, nsXULAtoms::sizetopopup, sizedToPopup); - - if (sizedToPopup.EqualsIgnoreCase("always")) - return GetPrefSize(aBoxLayoutState, aSize); - } + if (popupChild && IsSizedToPopup(mContent, PR_TRUE)) + return GetPrefSize(aBoxLayoutState, aSize); return nsBoxFrame::GetMinSize(aBoxLayoutState, aSize); } @@ -977,11 +990,7 @@ nsMenuFrame::DoLayout(nsBoxLayoutState& aState) nsIFrame* popupChild = mPopupFrames.FirstChild(); if (popupChild) { - nsAutoString sizedToPopup; - mContent->GetAttr(kNameSpaceID_None, nsXULAtoms::sizetopopup, sizedToPopup); - PRBool sizeToPopup = (sizedToPopup.EqualsIgnoreCase("pref") || - sizedToPopup.EqualsIgnoreCase("always")); - + PRBool sizeToPopup = IsSizedToPopup(mContent, PR_FALSE); nsIBox* ibox = nsnull; nsresult rv2 = popupChild->QueryInterface(NS_GET_IID(nsIBox), (void**)&ibox); NS_ASSERTION(NS_SUCCEEDED(rv2) && ibox,"popupChild is not box!!"); @@ -1983,12 +1992,7 @@ nsMenuFrame::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize) aSize.height = 0; nsresult rv = nsBoxFrame::GetPrefSize(aState, aSize); - nsAutoString sizedToPopup; - mContent->GetAttr(kNameSpaceID_None, nsXULAtoms::sizetopopup, sizedToPopup); - PRBool sizeToPopup = (sizedToPopup.EqualsIgnoreCase("pref") || - sizedToPopup.EqualsIgnoreCase("always")); - - if (sizeToPopup) { + if (IsSizedToPopup(mContent, PR_FALSE)) { nsSize tmpSize(-1,0); nsIBox::AddCSSPrefSize(aState, this, tmpSize); nscoord flex; diff --git a/layout/xul/base/src/nsMenuFrame.h b/layout/xul/base/src/nsMenuFrame.h index b2e16278a633..32a3b43a31f7 100644 --- a/layout/xul/base/src/nsMenuFrame.h +++ b/layout/xul/base/src/nsMenuFrame.h @@ -196,6 +196,8 @@ public: mFrameConstructor = aFC; } + static PRBool IsSizedToPopup(nsIContent* aContent, PRBool aRequireAlways); + protected: virtual void RePositionPopup(nsBoxLayoutState& aState); diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index 7dc287759283..88b22c661688 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -1163,14 +1163,10 @@ nsMenuPopupFrame::SyncViewWithFrame(nsIPresContext* aPresContext, aFrame->GetContent(getter_AddRefs(parentContent)); nsCOMPtr tag; mContent->GetTag(*getter_AddRefs(tag)); - if (tag.get() != nsXULAtoms::tooltip) { - nsAutoString sizeToContent; - parentContent->GetAttr(kNameSpaceID_None, nsXULAtoms::sizetopopup, sizeToContent); - if (sizeToContent == NS_LITERAL_STRING("pref") || - sizeToContent == NS_LITERAL_STRING("always")) { + if (tag.get() != nsXULAtoms::tooltip && + nsMenuFrame::IsSizedToPopup(parentContent, PR_FALSE)) { nsBoxLayoutState state(mPresContext); SetBounds(state, nsRect(mRect.x, mRect.y, parentRect.width, mRect.height)); - } } nsAutoString shouldDisplay, menuActive;