Closed Bug 195191 Opened 21 years ago Closed 21 years ago

Popup menu will appear in wrong place when method showPopup() is called

Categories

(Core :: XUL, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: surkov, Assigned: hyatt)

References

Details

(Whiteboard: mozgest)

Attachments

(1 file)

1.04 KB, application/vnd.mozilla.xul+xml
Details
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021123
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021123

When you click mouse button then popup menu will not appear in relative
coordinates specified in showPopup() arguments. 
You can see the same behavior when you get a nsPopupBoxObject object by
popupBoxObject property of the popup element and 

after that call the showPopup method of the nsIPopupBoxObject interface.

Reproducible: Always

Steps to Reproduce:
create new document with next content

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="remote_example"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     title="Simple Example">

<script	type="application/x-javascript">

// The first variant of showing a popup
function showmenu()
{
	var clip=document.getElementById("clipmenu");
	var txt=document.getElementById("txt");
	clip.showPopup(txt,0,0,"popup","bottomleft","topleft");

}
/* Other variant of showmenu() function. Behavior is the same as for the first
variant
function showmenu()
{
	var clip=document.getElementById("clipmenu");
	var txt=document.getElementById("txt");
	var popup_obj=clip.popupBoxObject;
	popup_obj.showPopup(txt, clip, 0, 0, "popup", "bottomleft", "toppleft");
}*/

</script>
<button id="btn" oncommand="showmenu()" label="Show menu"/>
<textbox id="txt"/>

<popupset>
  <popup id="clipmenu">
    <menuitem label="Cut"/>
    <menuitem label="Copy"/>
    <menuitem label="Paste"/>
  </popup>
</popupset>

</window>
Actual Results:  
When you click the left button of the mouse on the 'Show menu' then menu will
appear in specified coordinates relative desktop's coordinates. 
When you click the right button on any place in client's area then after that
popup will always show relative client's area coordinates. 

Expected Results:  
Menu should appears in the specified coordinates relative the element 
which is an argument of the showPopup() method.
Confirming on Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312
Status: UNCONFIRMED → NEW
Ever confirmed: true
Whiteboard: mozgest
Attached file reporter's test case
Sidenote: Fixing this bug would greatly enhance Mouse Gestures usability on
Linux platform. Currently, using RMB for gestures makes the context menu
unusable - we can block it, but not deliberately show it when no gesture was done.
Blocks: 76537
Is this actually broken and not the intended behavior?

Changing:

clip.showPopup(txt,0,0,"popup","bottomleft","topleft");
to
clip.showPopup(txt,-1,-1,"popup","bottomleft","topleft");

does produce a relative popup as wanted.
you can use -1, -1 and get right relative place but you can't use other xpos and
ypos relative to the element.
Aparently this is because get position from rootframe and not from domelement
passed.
Boris, cc you because I think this is layout.
I think that nowhere is it documented what showPopup should actually do, so I'm
not going to even look at it till that happens.
The align/anchor arguments in the current showPopup function are ignored unless
x/y are both -1. If x/y are specified, they are relative to the document the
triggering element is in.

In fact, the current showPopup arguments use an earlier form of
positioning.showPopup should probably work as specified here:

http://www.mozilla.org/projects/xul/layout.html

Although I admit that the positioning is more powerful the existing way. Any
changes would be in nsMenuPopupFrame::SyncViewWithFrame which includes comments
describing what's happens.
Looks like this is more a lack-of-documentation-problem than a bug... If you use
"context" instead of "popup", you can pass any positioning values you want
(relative to the element passed as first parameter). For example, here's the
code Mouse Gestures will use on Linux (suggested by dorando):

contextMenu.showPopup(getBrowser(), e.clientX, e.clientY,
"context","bottomleft","topleft");
(where e is a mouseup event)

Suggesting RESOLVE->INVALID (can't do myself).
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → INVALID
To comment #9. I don't think this bug lies in lack-of-documentation problem.
First, they use right mouse button in mouse gestures code. Popup menu appears in
window coordinates (not descktop coords) on right button click (see testcase).
Second, they use browser window in showPopup() method as first parameter.
Therefore this code work correctly. Another cases will work wrong.

Problem lies in first parameter in showPopup() method is ignored to all
appearances. And you may observe a strange behaviour when popup is showing on
left mouse click.

If this bug is lack-of-documentation then need to say that showPopup() method
shows popup realative browser window (read: post browser window as first
parameter) and on right button click only.
A temporary workaround is to set document.popupNode to the reference node before calling showPopup().  This workaround is from http://www.xulplanet.com/references/elemref/ref_popup.html#prop_showPopup
Component: XP Toolkit/Widgets: Menus → XUL
QA Contact: shrir → xptoolkit.widgets
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: