зеркало из https://github.com/mozilla/pjs.git
Implementing support for popupanchor and popupalign.
This commit is contained in:
Родитель
af5c8627b2
Коммит
59da512000
|
@ -81,6 +81,8 @@ XUL_ATOM(acceltext, "acceltext") // Text to use for the accelerator
|
|||
XUL_ATOM(popupset, "popupset") // Contains popup menus, context menus, and tooltips
|
||||
XUL_ATOM(popup, "popup") // The popup for a context menu, popup menu, or tooltip
|
||||
XUL_ATOM(menugenerated, "menugenerated") // Internal
|
||||
XUL_ATOM(popupanchor, "popupanchor") // Anchor for popups
|
||||
XUL_ATOM(popupalign, "popupalign") // Alignment for popups
|
||||
|
||||
XUL_ATOM(key, "key") // A key element
|
||||
XUL_ATOM(broadcaster, "broadcaster") // A broadcaster
|
||||
|
|
|
@ -518,11 +518,32 @@ nsMenuFrame::OpenMenuInternal(PRBool aActivateFlag)
|
|||
mMenuParent->SetActive(PR_TRUE);
|
||||
|
||||
// Sync up the view.
|
||||
nsCOMPtr<nsIContent> menuPopupContent;
|
||||
menuPopup->GetContent(getter_AddRefs(menuPopupContent));
|
||||
|
||||
nsAutoString popupAnchor, popupAlign;
|
||||
|
||||
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupanchor, popupAnchor);
|
||||
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupalign, popupAlign);
|
||||
|
||||
PRBool onMenuBar = PR_TRUE;
|
||||
if (mMenuParent)
|
||||
mMenuParent->IsMenuBar(onMenuBar);
|
||||
|
||||
menuPopup->SyncViewWithFrame(mPresContext, onMenuBar, this, -1, -1);
|
||||
if (onMenuBar) {
|
||||
if (popupAnchor == "")
|
||||
popupAnchor = "bottomleft";
|
||||
if (popupAlign == "")
|
||||
popupAlign = "topleft";
|
||||
}
|
||||
else {
|
||||
if (popupAnchor == "")
|
||||
popupAnchor = "topright";
|
||||
if (popupAlign == "")
|
||||
popupAlign = "topleft";
|
||||
}
|
||||
|
||||
menuPopup->SyncViewWithFrame(mPresContext, popupAnchor, popupAlign, this, -1, -1);
|
||||
}
|
||||
|
||||
ActivateMenu(PR_TRUE);
|
||||
|
@ -650,11 +671,31 @@ nsMenuFrame::DidReflow(nsIPresContext* aPresContext,
|
|||
nsIFrame* frame = mPopupFrames.FirstChild();
|
||||
nsMenuPopupFrame* menuPopup = (nsMenuPopupFrame*)frame;
|
||||
if (mMenuOpen && menuPopup) {
|
||||
nsCOMPtr<nsIContent> menuPopupContent;
|
||||
menuPopup->GetContent(getter_AddRefs(menuPopupContent));
|
||||
nsAutoString popupAnchor, popupAlign;
|
||||
|
||||
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupanchor, popupAnchor);
|
||||
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupalign, popupAlign);
|
||||
|
||||
PRBool onMenuBar = PR_TRUE;
|
||||
if (mMenuParent)
|
||||
mMenuParent->IsMenuBar(onMenuBar);
|
||||
|
||||
menuPopup->SyncViewWithFrame(aPresContext, onMenuBar, this, -1, -1);
|
||||
if (onMenuBar) {
|
||||
if (popupAnchor == "")
|
||||
popupAnchor = "bottomleft";
|
||||
if (popupAlign == "")
|
||||
popupAlign = "topleft";
|
||||
}
|
||||
else {
|
||||
if (popupAnchor == "")
|
||||
popupAnchor = "topright";
|
||||
if (popupAlign == "")
|
||||
popupAlign = "topleft";
|
||||
}
|
||||
|
||||
menuPopup->SyncViewWithFrame(aPresContext, popupAnchor, popupAlign, this, -1, -1);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
|
|
@ -213,7 +213,8 @@ nsMenuPopupFrame::GetNearestEnclosingView(nsIPresContext* aPresContext, nsIFrame
|
|||
|
||||
nsresult
|
||||
nsMenuPopupFrame::SyncViewWithFrame(nsIPresContext* aPresContext,
|
||||
PRBool aOnMenuBar,
|
||||
const nsString& aPopupAnchor,
|
||||
const nsString& aPopupAlign,
|
||||
nsIFrame* aFrame,
|
||||
PRInt32 aXPos, PRInt32 aYPos)
|
||||
{
|
||||
|
@ -266,13 +267,41 @@ nsMenuPopupFrame::SyncViewWithFrame(nsIPresContext* aPresContext,
|
|||
ypos = NSIntPixelsToTwips(aYPos, p2t);
|
||||
xpos += offset.x;
|
||||
ypos += offset.y;
|
||||
} else if (aOnMenuBar) {
|
||||
}
|
||||
else {
|
||||
xpos = parentPos.x + offset.x;
|
||||
ypos = parentPos.y + parentRect.height + offset.y;
|
||||
} else {
|
||||
xpos = parentPos.x + parentRect.width + offset.x;
|
||||
ypos = parentPos.y + offset.y;
|
||||
|
||||
if (aPopupAnchor == "topright" && aPopupAlign == "topleft") {
|
||||
xpos += parentRect.width;
|
||||
}
|
||||
else if (aPopupAnchor == "topright" && aPopupAlign == "bottomright") {
|
||||
xpos -= (mRect.width - parentRect.width);
|
||||
ypos -= mRect.height;
|
||||
}
|
||||
else if (aPopupAnchor == "bottomright" && aPopupAlign == "bottomleft") {
|
||||
xpos += parentRect.width;
|
||||
ypos -= (mRect.height - parentRect.height);
|
||||
}
|
||||
else if (aPopupAnchor == "bottomright" && aPopupAlign == "topright") {
|
||||
xpos -= (mRect.width - parentRect.width);
|
||||
ypos += parentRect.height;
|
||||
}
|
||||
else if (aPopupAnchor == "topleft" && aPopupAlign == "topright") {
|
||||
xpos -= mRect.width;
|
||||
}
|
||||
else if (aPopupAnchor == "topleft" && aPopupAlign == "bottomleft") {
|
||||
ypos -= mRect.height;
|
||||
}
|
||||
else if (aPopupAnchor == "bottomleft" && aPopupAlign == "bottomright") {
|
||||
xpos -= mRect.width;
|
||||
ypos -= (mRect.height - parentRect.height);
|
||||
}
|
||||
else if (aPopupAnchor == "bottomleft" && aPopupAlign == "topleft") {
|
||||
ypos += parentRect.height;
|
||||
}
|
||||
}
|
||||
|
||||
viewManager->MoveViewTo(view, xpos, ypos);
|
||||
|
||||
// Check if we fit on the screen, if not, resize and/or move so we do
|
||||
|
|
|
@ -91,7 +91,8 @@ public:
|
|||
void GetViewOffset(nsIViewManager* aManager, nsIView* aView, nsPoint& aPoint);
|
||||
static void GetNearestEnclosingView(nsIPresContext* aPresContext, nsIFrame* aStartFrame, nsIView** aResult);
|
||||
|
||||
nsresult SyncViewWithFrame(nsIPresContext* aPresContext, PRBool aOnMenuBar,
|
||||
nsresult SyncViewWithFrame(nsIPresContext* aPresContext, const nsString& aPopupAnchor,
|
||||
const nsString& aPopupAlign,
|
||||
nsIFrame* aFrame, PRInt32 aXPos, PRInt32 aYPos);
|
||||
|
||||
NS_IMETHOD CaptureMouseEvents(nsIPresContext* aPresContext, PRBool aGrabMouseEvents);
|
||||
|
|
|
@ -248,7 +248,20 @@ nsPopupSetFrame::DidReflow(nsIPresContext* aPresContext,
|
|||
// Sync up the view.
|
||||
nsIFrame* activeChild = GetActiveChild();
|
||||
if (activeChild) {
|
||||
((nsMenuPopupFrame*)activeChild)->SyncViewWithFrame(aPresContext, PR_TRUE, mElementFrame, mXPos, mYPos);
|
||||
|
||||
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 == "")
|
||||
popupAnchor = "bottomleft";
|
||||
if (popupAlign == "")
|
||||
popupAlign = "topleft";
|
||||
|
||||
((nsMenuPopupFrame*)activeChild)->SyncViewWithFrame(aPresContext, popupAnchor, popupAlign, mElementFrame, mXPos, mYPos);
|
||||
}
|
||||
|
||||
return nsBoxFrame::DidReflow(aPresContext, aStatus);
|
||||
|
|
|
@ -81,6 +81,8 @@ XUL_ATOM(acceltext, "acceltext") // Text to use for the accelerator
|
|||
XUL_ATOM(popupset, "popupset") // Contains popup menus, context menus, and tooltips
|
||||
XUL_ATOM(popup, "popup") // The popup for a context menu, popup menu, or tooltip
|
||||
XUL_ATOM(menugenerated, "menugenerated") // Internal
|
||||
XUL_ATOM(popupanchor, "popupanchor") // Anchor for popups
|
||||
XUL_ATOM(popupalign, "popupalign") // Alignment for popups
|
||||
|
||||
XUL_ATOM(key, "key") // A key element
|
||||
XUL_ATOM(broadcaster, "broadcaster") // A broadcaster
|
||||
|
|
Загрузка…
Ссылка в новой задаче