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.

This commit is contained in:
bryner%netscape.com 2002-03-17 23:41:22 +00:00
parent e09687ddf6
commit 21df11ab85
5 changed files with 28 additions and 26 deletions

View File

@ -654,7 +654,7 @@
]]>
</constructor>
</implementation>
<content sizetopopup="always">
<content>
<xul:hbox class="select-label-box" flex="1">
<xul:label flex="1" value=" " inherits="value=label"/>
</xul:hbox>

View File

@ -654,7 +654,7 @@
]]>
</constructor>
</implementation>
<content sizetopopup="always">
<content>
<xul:hbox class="select-label-box" flex="1">
<xul:label flex="1" value=" " inherits="value=label"/>
</xul:hbox>

View File

@ -938,6 +938,24 @@ nsMenuFrame::GetMenuChildrenElement(nsIContent** aResult)
}
}
PRBool
nsMenuFrame::IsSizedToPopup(nsIContent* aContent, PRBool aRequireAlways)
{
nsCOMPtr<nsIAtom> 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;

View File

@ -196,6 +196,8 @@ public:
mFrameConstructor = aFC;
}
static PRBool IsSizedToPopup(nsIContent* aContent, PRBool aRequireAlways);
protected:
virtual void RePositionPopup(nsBoxLayoutState& aState);

View File

@ -1163,14 +1163,10 @@ nsMenuPopupFrame::SyncViewWithFrame(nsIPresContext* aPresContext,
aFrame->GetContent(getter_AddRefs(parentContent));
nsCOMPtr<nsIAtom> 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;