Fix for 93171. r=pink, sr=blake

git-svn-id: svn://10.0.0.236/trunk@100552 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
hyatt%netscape.com 2001-08-08 01:38:05 +00:00
parent bdd4a1c661
commit 3c023c2a2c
7 changed files with 117 additions and 21 deletions

View File

@ -712,6 +712,53 @@ GetImmediateChild(nsIContent* aContent, nsIAtom *aTag, nsIContent** aResult)
return;
}
static void ConvertPosition(nsIDOMElement* aPopupElt, nsString& aAnchor, nsString& aAlign, PRInt32& aY)
{
nsAutoString position;
aPopupElt->GetAttribute(NS_LITERAL_STRING("position"), position);
if (position.IsEmpty())
return;
if (position.Equals(NS_LITERAL_STRING("before_start"))) {
aAnchor.AssignWithConversion("topleft");
aAlign.AssignWithConversion("bottomleft");
}
else if (position.Equals(NS_LITERAL_STRING("before_end"))) {
aAnchor.AssignWithConversion("topright");
aAlign.AssignWithConversion("bottomright");
}
else if (position.Equals(NS_LITERAL_STRING("after_start"))) {
aAnchor.AssignWithConversion("bottomleft");
aAlign.AssignWithConversion("topleft");
}
else if (position.Equals(NS_LITERAL_STRING("after_end"))) {
aAnchor.AssignWithConversion("bottomright");
aAlign.AssignWithConversion("topright");
}
else if (position.Equals(NS_LITERAL_STRING("start_before"))) {
aAnchor.AssignWithConversion("topleft");
aAlign.AssignWithConversion("topright");
}
else if (position.Equals(NS_LITERAL_STRING("start_after"))) {
aAnchor.AssignWithConversion("bottomleft");
aAlign.AssignWithConversion("bottomright");
}
else if (position.Equals(NS_LITERAL_STRING("end_before"))) {
aAnchor.AssignWithConversion("topright");
aAlign.AssignWithConversion("topleft");
}
else if (position.Equals(NS_LITERAL_STRING("end_after"))) {
aAnchor.AssignWithConversion("bottomright");
aAlign.AssignWithConversion("bottomleft");
}
else if (position.Equals(NS_LITERAL_STRING("overlap"))) {
aAnchor.AssignWithConversion("topleft");
aAlign.AssignWithConversion("topleft");
}
else if (position.Equals(NS_LITERAL_STRING("after_pointer")))
aY += 21;
}
//
// LaunchPopup
//
@ -818,15 +865,19 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY)
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(global);
if (domWindow != nsnull) {
// Find out if we're anchored.
nsAutoString anchorAlignment; anchorAlignment.AssignWithConversion("none");
mElement->GetAttribute(NS_LITERAL_STRING("popupanchor"), anchorAlignment);
mPopupContent = popupContent.get();
nsAutoString popupAlignment; popupAlignment.AssignWithConversion("topleft");
mElement->GetAttribute(NS_LITERAL_STRING("popupalign"), popupAlignment);
nsAutoString anchorAlignment;
mPopupContent->GetAttribute(NS_LITERAL_STRING("popupanchor"), anchorAlignment);
nsAutoString popupAlignment;
mPopupContent->GetAttribute(NS_LITERAL_STRING("popupalign"), popupAlignment);
PRInt32 xPos = aClientX, yPos = aClientY;
mPopupContent = popupContent.get();
ConvertPosition(mPopupContent, anchorAlignment, popupAlignment, yPos);
if (!anchorAlignment.IsEmpty() && !popupAlignment.IsEmpty())
xPos = yPos = -1;
nsCOMPtr<nsIDOMNode> parent;
mPopupContent->GetParentNode(getter_AddRefs(parent));

View File

@ -1007,6 +1007,50 @@ nsMenuFrame::SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, PRBool aDebug)
return NS_OK;
}
static void ConvertPosition(nsIContent* aPopupElt, nsString& aAnchor, nsString& aAlign)
{
nsAutoString position;
aPopupElt->GetAttribute(kNameSpaceID_None, nsXULAtoms::position, position);
if (position.IsEmpty())
return;
if (position.Equals(NS_LITERAL_STRING("before_start"))) {
aAnchor.AssignWithConversion("topleft");
aAlign.AssignWithConversion("bottomleft");
}
else if (position.Equals(NS_LITERAL_STRING("before_end"))) {
aAnchor.AssignWithConversion("topright");
aAlign.AssignWithConversion("bottomright");
}
else if (position.Equals(NS_LITERAL_STRING("after_start"))) {
aAnchor.AssignWithConversion("bottomleft");
aAlign.AssignWithConversion("topleft");
}
else if (position.Equals(NS_LITERAL_STRING("after_end"))) {
aAnchor.AssignWithConversion("bottomright");
aAlign.AssignWithConversion("topright");
}
else if (position.Equals(NS_LITERAL_STRING("start_before"))) {
aAnchor.AssignWithConversion("topleft");
aAlign.AssignWithConversion("topright");
}
else if (position.Equals(NS_LITERAL_STRING("start_after"))) {
aAnchor.AssignWithConversion("bottomleft");
aAlign.AssignWithConversion("bottomright");
}
else if (position.Equals(NS_LITERAL_STRING("end_before"))) {
aAnchor.AssignWithConversion("topright");
aAlign.AssignWithConversion("topleft");
}
else if (position.Equals(NS_LITERAL_STRING("end_after"))) {
aAnchor.AssignWithConversion("bottomright");
aAlign.AssignWithConversion("bottomleft");
}
else if (position.Equals(NS_LITERAL_STRING("overlap"))) {
aAnchor.AssignWithConversion("topleft");
aAlign.AssignWithConversion("topleft");
}
}
void
nsMenuFrame::RePositionPopup(nsBoxLayoutState& aState)
@ -1024,6 +1068,8 @@ nsMenuFrame::RePositionPopup(nsBoxLayoutState& aState)
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupanchor, popupAnchor);
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupalign, popupAlign);
ConvertPosition(menuPopupContent, popupAnchor, popupAlign);
PRBool onMenuBar = PR_TRUE;
if (mMenuParent)
mMenuParent->IsMenuBar(onMenuBar);

View File

@ -449,6 +449,9 @@ nsMenuPopupFrame :: AdjustPositionForAnchorAlign ( PRInt32* ioXPos, PRInt32* ioY
if (aPopupAnchor == NS_LITERAL_STRING("topright") && aPopupAlign == NS_LITERAL_STRING("topleft")) {
*ioXPos += inParentRect.width;
}
else if (aPopupAnchor == NS_LITERAL_STRING("topleft") && aPopupAlign == NS_LITERAL_STRING("topleft")) {
*outFlushWithTopBottom = PR_TRUE;
}
else if (aPopupAnchor == NS_LITERAL_STRING("topright") && aPopupAlign == NS_LITERAL_STRING("bottomright")) {
*ioXPos -= (mRect.width - inParentRect.width);
*ioYPos -= mRect.height;

View File

@ -348,25 +348,12 @@ nsPopupSetFrame::RePositionPopup(nsBoxLayoutState& aState)
// Sync up the view.
nsIFrame* activeChild = GetActiveChild();
if (activeChild && mElementContent) {
nsCOMPtr<nsIContent> menuPopupContent;
activeChild->GetContent(getter_AddRefs(menuPopupContent));
nsAutoString popupAnchor, popupAlign;
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupanchor, popupAnchor);
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupalign, popupAlign);
if (popupAnchor.IsEmpty())
popupAnchor.AssignWithConversion("bottomleft");
if (popupAlign.IsEmpty())
popupAlign.AssignWithConversion("topleft");
nsIFrame* frameToSyncTo = nsnull;
nsCOMPtr<nsIPresShell> presShell;
nsIPresContext* presContext = aState.GetPresContext();
presContext->GetShell(getter_AddRefs(presShell));
presShell->GetPrimaryFrameFor ( mElementContent, &frameToSyncTo );
((nsMenuPopupFrame*)activeChild)->SyncViewWithFrame(presContext, popupAnchor, popupAlign, frameToSyncTo, mXPos, mYPos);
((nsMenuPopupFrame*)activeChild)->SyncViewWithFrame(presContext, mPopupAnchor, mPopupAlign, frameToSyncTo, mXPos, mYPos);
}
}
@ -453,6 +440,9 @@ nsPopupSetFrame::CreatePopup(nsIContent* aElementContent, nsIContent* aPopupCont
mPopupType = aPopupType;
mElementContent = aElementContent;
mPopupAlign = aPopupAlignment;
mPopupAnchor = anAnchorAlignment;
// Show the popup at the specified position.
mXPos = aXPos;
mYPos = aYPos;

View File

@ -138,6 +138,10 @@ protected:
PRInt32 mXPos; // Active child's x position
PRInt32 mYPos; // Active child's y position
nsString mPopupAnchor; // Active child's anchor.
nsString mPopupAlign; // Active child's align.
nsAutoString mPopupType;
PRBool mCreateHandlerSucceeded; // Did the create handler succeed?
nsSize mLastPref;

View File

@ -114,8 +114,8 @@ Contributor(s): ______________________________________. -->
<popup id="aHTMLTooltip" class="tooltip" onpopupshowing="return FillInHTMLTooltip(document.tooltipNode);" >
<vbox id="HTML_TOOLTIP_tooltipBox"/>
</popup>
<popup id="backMenu" onpopupshowing="return BrowserBackMenu(event);" oncommand="gotoHistoryIndex(event);"/>
<popup id="forwardMenu" onpopupshowing="return BrowserForwardMenu(event);" oncommand="gotoHistoryIndex(event);"/>
<popup id="backMenu" position="after_start" onpopupshowing="return BrowserBackMenu(event);" oncommand="gotoHistoryIndex(event);"/>
<popup id="forwardMenu" position="after_start" onpopupshowing="return BrowserForwardMenu(event);" oncommand="gotoHistoryIndex(event);"/>
<popup id="sidebarPopup"/>
<popupset id="bookmarksPopupset"/>

View File

@ -18,6 +18,8 @@
</content>
<implementation>
<property name="position" onget="return this.getAttribute('position');"
onset="this.setAttribute('position', val); return val;"/>
<method name="openPopup">
<parameter name="element"/>
<parameter name="xpos"/>