[Project_owners] Programmatically open the context menu

Todd Long longfocus at gmail.com
Fri Feb 10 16:43:58 EST 2006


Thanks for the suggestions.

1. Yeah, there are definitely too many options to go pick and choose what
should be set.
2. I am not trying to spawn the context menu from a right-click, sorry for
the confusion. What I'm trying to do is spawn the context menu when the user
left clicks.

Ok, now I have successfully gotten the context menu to appear when the user
left clicks. But I'm still getting an error in the javascript console
(though it looks like it is after the fact and nothing gets affected). What
I have is a function that is called when the context menu is showing
(generated from onpopupshowing). From this function I execute code to
display the context menu (which works fine) but it seems like after the
function has finished there is more code getting executed. I tried adding
preventDefault and stopPropagation but that completely blocked the popup
from showing and I still got the same error. I have included the error below
and the onpopupshowing code (assume the left click has been initiated).

=============
Error: node has no properties
Source File: chrome://browser/content/browser.js
Line: 3946
=============

var listener = document.getElementById("contentAreaContextMenu");
listener.addEventListener("popupshowing", onContextShowing, false);

function onContextShowing(aEvent) {
  // Display context menu
  document.popupNode = this;
  gContextMenu = new nsContextMenu(this);
}

I put some logStringMessage and the error appears after this function is
called and also the popupshown callback. Here is the flow of events:

onpopupshowing
onpopupshown
ERROR
onpopuphiding

Thanks,
Todd


On 2/10/06, Matthew Waymost <waymost at gmail.com> wrote:
>
> Two suggestions.
>
> 1. nsContextMenu has quite a few flags that determine what gets shown (as
> already mentioned). While admittedly not the best practice in the world,
> could you manually set those right before you spawn the context menu to get
> the menu items you want. I don't know exactly why you want to spawn the
> context menu so this may not be feasible, but a thought. I don't think it
> would interfere with its normal operation either since I assume it
> dynamically updates all of those flags when the right click is performed.
>
> 2. Is there a specific reason you want to spawn the context menu via a
> right mouse click event? I would think that you could attach the popup to
> whatever event you want to bring it up. One example is LastTab, which has a
> popup for all the tabs in a given window when you hit Ctrl+Tab. Could
> something similar be done in your case to simplify what you're doing?
>
> Matt
>
> On 2/10/06, Todd Long < longfocus at gmail.com> wrote:
> >
> > Hey Matt, thanks for the reply. Yeah, I have checked that out and
> > understand that I am getting the unfiltered list (all items are being
> > shown). Though somehow there should be a way to create a right-click
> > MouseEvent and dispatch it to the document. After dispatching this
> > right-click MouseEvent it should then display the appropriate context menu
> > (depending if text is selected, not selected, or if your on a link, etc..).
> > Something gets executed when I right-click with my mouse and almost need a
> > way to record that.
> >
> > var evt = document.createEvent("MouseEvent");
> > evt.initMouseEvent("click", 1, 1, window, 1, 10, 50, 10, 50, 0, 0, 0, 0,
> > 2, null);
> >
> > Above I have created the MouseEvent but not sure how it should be
> > dispatched to the tabbrowser so that it will display the appropriate context
> > menu (filtered for what my selection is).
> >
> > Thanks,
> > Todd
> >
> >
> > On 2/10/06, Matthew Waymost < waymost at gmail.com > wrote:
> > >
> > > I think the reason you're getting a long context menu is because when
> > > you right click in the context area, what you right click on determines what
> > > items in the menu get hidden. I would surmise that by calling it the way you
> > > do, you're getting everything unfiltered. In browser.js, you'll find
> > > an object called nsContextMenu, which has all that code. I haven't dug
> > > through it recently, so I can't tell you exactly what you need, but it
> > > should point you in the right direction.
> > >
> > > HTH, Matt
> > >
> > > On 2/10/06, Todd Long < longfocus at gmail.com> wrote:
> > > >
> > > > Hey, Soyapi. Thanks for the link but it isn't exactly what I was
> > > > looking for (some nice obfuscated code though). What I'm trying to do is get
> > > > the Firefox context menu to popup and not a custom popup menu.
> > > >
> > > > var evt = document.createEvent("MouseEvent");
> > > > evt.initMouseEvent("click", 1, 1, window, 1, 10, 50, 10, 50, 0, 0,
> > > > 0, 0, 2, null);
> > > >
> > > > document.popupNode=evt.target;
> > > >
> > > > var cacm = document.getElementById ("contentAreaContextMenu")
> > > > cacm.showPopup(getBrowser(), evt.clientX, evt.clientY, "context",
> > > > "bottomleft", "topleft");
> > > >
> > > > Here is some code I have. But when this gets executed it pops up a
> > > > loooong context menu with about every option available. I need to replace
> > > > what ever click this was executed to the right-click (button 2). Any other
> > > > thoughts on this? Thanks for all the help!
> > > >
> > > > Thanks,
> > > > Todd
> > > >
> > > > On 2/10/06, Soyapi Mumba < soyapim at gmail.com> wrote:
> > > > >
> > > > >
> > > > > Todd Long wrote:
> > > > > > Is it possible to programmatically open the context menu
> > > > > > (contentAreaContextMenu)? Basically, I just want to have the
> > > > > ability to
> > > > > > send a right-click MouseEvent to the tabbrowser when a certain
> > > > > action is
> > > > > > performed. I wasn't quite sure how to piece the code below to
> > > > > achieve
> > > > > > this behaviour.
> > > > >
> > > > > I haven't looked at how they do it but that's what Hyperwords
> > > > > does. Check it out
> > > > > http://www.hyperwords.net/
> > > > >
> > > > > - Soyapi
> > > > > --
> > > > > Soyapi Mumba
> > > > > http://soyapi.blogspot.com
> > > > > http://configuru.sourceforge.net
> > > > > +265 (0) 9953 449
> > > > > _______________________________________________
> > > > > Project_owners mailing list
> > > > > Project_owners at mozdev.org
> > > > > http://mozdev.org/mailman/listinfo/project_owners
> > > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > Project_owners mailing list
> > > > Project_owners at mozdev.org
> > > > http://mozdev.org/mailman/listinfo/project_owners
> > > >
> > > >
> > > >
> > >
> > > _______________________________________________
> > > Project_owners mailing list
> > > Project_owners at mozdev.org
> > > http://mozdev.org/mailman/listinfo/project_owners
> > >
> > >
> > >
> >
> > _______________________________________________
> > Project_owners mailing list
> > Project_owners at mozdev.org
> > http://mozdev.org/mailman/listinfo/project_owners
> >
> >
> >
>
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mozdev.org/pipermail/project_owners/attachments/20060210/9052e7b5/attachment.htm


More information about the Project_owners mailing list