From 7cdaba233244746ccfe40cb8e5542ac63fc1927f Mon Sep 17 00:00:00 2001
From: Leyla Farazha <leyla@lindenlab.com>
Date: Wed, 15 Jul 2009 01:12:51 +0000
Subject: [PATCH] Fixing DEV-35175 regression. Context Windows will now spawn
 up if too far down, and spawn left if too far right. reviewed by James

---
 indra/llui/llmenugl.cpp | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/indra/llui/llmenugl.cpp b/indra/llui/llmenugl.cpp
index d24eb1ec569..4ef4bf996cd 100644
--- a/indra/llui/llmenugl.cpp
+++ b/indra/llui/llmenugl.cpp
@@ -3589,12 +3589,30 @@ void LLContextMenu::show(S32 x, S32 y)
 	const LLRect menu_region_rect = LLMenuGL::sMenuContainer->getMenuRect();
 	LLView* parent_view = getParent();
 
-	if(getParentMenuItem())
+	// Open upwards if menu extends past bottom
+	if (y - height < menu_region_rect.mBottom)
 	{
-		S32 parent_width = getParentMenuItem()->getRect().getWidth();
-		
-		if(x + width > menu_region_rect.getWidth())
-			x -= parent_width + width;
+		if (getParentMenuItem()) // Adjust if this is a submenu
+		{
+			y += height - getParentMenuItem()->getNominalHeight();		
+		}
+		else
+		{
+			y += height;
+		}
+	}
+
+	// Open out to the left if menu extends past right edge
+	if (x + width > menu_region_rect.mRight)
+	{
+		if (getParentMenuItem())
+		{
+			x -= getParentMenuItem()->getRect().getWidth() + width;
+		}
+		else
+		{
+			x -= width;
+		}
 	}
 
 	S32 local_x, local_y;
-- 
GitLab