Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions
CHClickListener Class Reference

#include <CHClickListener.h>

Inheritance diagram for CHClickListener:
Inheritance graph
[legend]
Collaboration diagram for CHClickListener:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CHClickListener ()
virtual ~CHClickListener ()
NS_DECL_ISUPPORTS NS_IMETHOD HandleEvent (nsIDOMEvent *aEvent)
NS_IMETHOD MouseDown (nsIDOMEvent *aMouseEvent)
 Processes a mouse down event.
NS_IMETHOD MouseUp (nsIDOMEvent *aMouseEvent)
 Processes a mouse up event.
NS_IMETHOD MouseClick (nsIDOMEvent *aMouseEvent)
 Processes a mouse click event.
NS_IMETHOD MouseDblClick (nsIDOMEvent *aMouseEvent)
 Processes a mouse click event.
NS_IMETHOD MouseOver (nsIDOMEvent *aMouseEvent)
 Processes a mouse enter event.
NS_IMETHOD MouseOut (nsIDOMEvent *aMouseEvent)
 Processes a mouse leave event.
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Detailed Description

Definition at line 46 of file CHClickListener.h.


Constructor & Destructor Documentation

Definition at line 109 of file CHClickListener.mm.

{
}

Definition at line 113 of file CHClickListener.mm.

{
}

Member Function Documentation

Definition at line 55 of file CHClickListener.h.

{ return NS_OK; };

This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Parameters:
evtThe Event contains contextual information about the event. It also contains the stopPropagation and preventDefault methods which are used in determining the event's flow and default action.
NS_IMETHOD CHClickListener::MouseClick ( nsIDOMEvent aMouseEvent) [inline, virtual]

Processes a mouse click event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 58 of file CHClickListener.h.

{ return NS_OK; };
NS_IMETHOD CHClickListener::MouseDblClick ( nsIDOMEvent aMouseEvent) [inline, virtual]

Processes a mouse click event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 59 of file CHClickListener.h.

{ return NS_OK; };

Processes a mouse down event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 118 of file CHClickListener.mm.

{
  nsCOMPtr<nsIDOMEventTarget> target;
  aEvent->GetTarget(getter_AddRefs(target));
  if (!target)
    return NS_OK;
  nsCOMPtr<nsIDOMHTMLSelectElement> sel(do_QueryInterface(target));
  if (sel) {
    PRInt32 size = 0;
    sel->GetSize(&size);
    PRBool multiple = PR_FALSE;
    sel->GetMultiple(&multiple);
    if(size > 1 || multiple)
      return NS_OK;
      
    NSMenu* menu = [[NSMenu alloc] init]; // Retain the menu.

    // We'll set the disabled state as the options are created, so disable
    // auto-enabling via NSMenuValidation.
    [menu setAutoenablesItems: NO];

    nsCOMPtr<nsIDOMHTMLOptionsCollection> options;
    sel->GetOptions(getter_AddRefs(options));
    PRUint32 count;
    options->GetLength(&count);
    PRInt32 selIndex = 0;
    for (PRUint32 i = 0; i < count; i++) {
      nsCOMPtr<nsIDOMNode> node;
      options->Item(i, getter_AddRefs(node));
      nsCOMPtr<nsIDOMHTMLOptionElement> option(do_QueryInterface(node));
      nsAutoString text;
      option->GetLabel(text);
      if (text.IsEmpty())
        option->GetText(text);
      NSString* title = [[NSString stringWith_nsAString: text] stringByTruncatingTo:75 at:kTruncateAtMiddle];
      NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
      [menu addItem: menuItem];
      [menuItem setTag: (int)option.get()];
      PRBool selected;
      option->GetSelected(&selected);
      if (selected) {
        [menuItem setState: NSOnState];
        selIndex = i;
      }
      PRBool disabled;
      option->GetDisabled(&disabled);
      if (disabled)
        [menuItem setEnabled: NO];
      CHOptionSelector* optSelector = [[CHOptionSelector alloc] initWithSelect: sel];
      [menuItem setTarget: optSelector];
      [menuItem setAction: @selector(selectOption:)];
    }

    nsCOMPtr<nsIDOMNSHTMLElement> nsSel(do_QueryInterface(sel));
    PRInt32 left, top, height;
    PRInt32 clientX, clientY;
    nsSel->GetOffsetLeft(&left);
    nsSel->GetOffsetTop(&top);
    nsSel->GetOffsetHeight(&height);

    nsCOMPtr<nsIDOMElement> currOffsetParent;
    nsSel->GetOffsetParent(getter_AddRefs(currOffsetParent));
    while (currOffsetParent) {
      nsCOMPtr<nsIDOMNSHTMLElement> currNS(do_QueryInterface(currOffsetParent));
      PRInt32 currLeft, currTop;
      currNS->GetOffsetLeft(&currLeft);
      currNS->GetOffsetTop(&currTop);
      left += currLeft;
      top += currTop;
      currNS->GetOffsetParent(getter_AddRefs(currOffsetParent));
    }
    
    nsCOMPtr<nsIDOMMouseEvent> msEvent(do_QueryInterface(aEvent));
    msEvent->GetClientX(&clientX);
    msEvent->GetClientY(&clientY);

    PRInt32 xDelta = clientX - left;
    PRInt32 yDelta = top + height - clientY;

    nsCOMPtr<nsIContent> selContent = do_QueryInterface(sel);
    nsCOMPtr<nsIDocument> doc = selContent->GetDocument();

    // I'm going to assume that if we got a mousedown for a content node,
    // it's actually in a document.

    nsCOMPtr<nsIScriptGlobalObject> sgo;
    doc->GetScriptGlobalObject(getter_AddRefs(sgo));
    nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(sgo);
    if (!window)
      return NS_OK;

    PRInt32 scrollX, scrollY;
    window->GetScrollX(&scrollX);
    window->GetScrollY(&scrollY);
    xDelta += scrollX; // Normal direction.
    yDelta -= scrollY; // Remember, y is flipped.
    
#define XMENUOFFSET 20
#define MENUHEIGHT 20
    
    xDelta += XMENUOFFSET;
    yDelta -= MENUHEIGHT*(selIndex+1);
    
    NSEvent* event = [NSApp currentEvent];
    NSPoint point = [event locationInWindow];
    point.x -= xDelta;
    point.y -= yDelta;

    NSEvent* mouseEvent = [NSEvent mouseEventWithType: NSLeftMouseDown location: point
                                        modifierFlags: 0 timestamp: [event timestamp]
                                         windowNumber: [event windowNumber] context: [event context]
                                          eventNumber: [event eventNumber] clickCount: [event clickCount]                                                                                                                                                           pressure: [event pressure]];
    [NSMenu popUpContextMenu: menu withEvent: mouseEvent forView: [[event window] contentView]];
  }
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHOD CHClickListener::MouseOut ( nsIDOMEvent aMouseEvent) [inline, virtual]

Processes a mouse leave event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 61 of file CHClickListener.h.

{ return NS_OK; };
NS_IMETHOD CHClickListener::MouseOver ( nsIDOMEvent aMouseEvent) [inline, virtual]

Processes a mouse enter event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 60 of file CHClickListener.h.

{ return NS_OK; };
NS_IMETHOD CHClickListener::MouseUp ( nsIDOMEvent aMouseEvent) [inline, virtual]

Processes a mouse up event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 57 of file CHClickListener.h.

{ return NS_OK; };

The documentation for this class was generated from the following files: