Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes
nsMenuListener Class Reference

editor Implementation of the DragListener interface More...

#include <nsMenuListener.h>

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

List of all members.

Public Member Functions

 nsMenuListener (nsIMenuParent *aMenuParent)
virtual ~nsMenuListener ()
NS_IMETHOD HandleEvent (nsIDOMEvent *aEvent)
NS_IMETHOD KeyUp (nsIDOMEvent *aKeyEvent)
 Processes a key release event.
NS_IMETHOD KeyDown (nsIDOMEvent *aKeyEvent)
 Processes a key pressed event.
NS_IMETHOD KeyPress (nsIDOMEvent *aKeyEvent)
 Processes a key typed event.
NS_IMETHOD Focus (nsIDOMEvent *aEvent)
 Processes a focus event.
NS_IMETHOD Blur (nsIDOMEvent *aEvent)
 Processes a blur event.
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.

Protected Attributes

nsIMenuParentmMenuParent

Detailed Description

editor Implementation of the DragListener interface

Definition at line 51 of file nsMenuListener.h.


Constructor & Destructor Documentation

Definition at line 78 of file nsMenuListener.cpp.

{
  mMenuParent = aMenuParent;
}

Definition at line 84 of file nsMenuListener.cpp.

{
}

Member Function Documentation

nsresult nsMenuListener::Blur ( nsIDOMEvent aEvent) [virtual]

Processes a blur event.

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

Implements nsIDOMFocusListener.

Definition at line 231 of file nsMenuListener.cpp.

{
  
  return NS_OK; // means I am NOT consuming event
}
nsresult nsMenuListener::Focus ( nsIDOMEvent aEvent) [virtual]

Processes a focus event.

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

Implements nsIDOMFocusListener.

Definition at line 224 of file nsMenuListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}

Definition at line 280 of file nsMenuListener.cpp.

{
  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.
nsresult nsMenuListener::KeyDown ( nsIDOMEvent aKeyEvent) [virtual]

Processes a key pressed event.

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

Implements nsIDOMKeyListener.

Definition at line 102 of file nsMenuListener.cpp.

{
  PRInt32 menuAccessKey = -1;
  
  // If the key just pressed is the access key (usually Alt),
  // dismiss and unfocus the menu.

  nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
  if (menuAccessKey) {
    PRUint32 theChar;
    nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
    keyEvent->GetKeyCode(&theChar);

    if (theChar == (PRUint32)menuAccessKey) {
      // No other modifiers can be down.
      // Especially CTRL.  CTRL+ALT == AltGR, and
      // we'll fuck up on non-US enhanced 102-key
      // keyboards if we don't check this.
      PRBool ctrl = PR_FALSE;
      if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_CONTROL)
        keyEvent->GetCtrlKey(&ctrl);
      PRBool alt=PR_FALSE;
      if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_ALT)
        keyEvent->GetAltKey(&alt);
      PRBool shift=PR_FALSE;
      if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_SHIFT)
        keyEvent->GetShiftKey(&shift);
      PRBool meta=PR_FALSE;
      if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_META)
        keyEvent->GetMetaKey(&meta);
      if (!(ctrl || alt || shift || meta)) {
        // The access key just went down and no other
        // modifiers are already down.
        mMenuParent->DismissChain();
      }
    }
  }

  // Since a menu was open, eat the event to keep other event
  // listeners from becoming confused.
  aKeyEvent->StopPropagation();
  aKeyEvent->PreventDefault();
  return NS_ERROR_BASE; // I am consuming event
}

Here is the call graph for this function:

nsresult nsMenuListener::KeyPress ( nsIDOMEvent aKeyEvent) [virtual]

Processes a key typed event.

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

Implements nsIDOMKeyListener.

Definition at line 149 of file nsMenuListener.cpp.

{
  // Don't check prevent default flag -- menus always get first shot at key events.
  // When a menu is open, the prevent default flag on a keypress is always set, so
  // that no one else uses the key event.

  //handlers shouldn't be triggered by non-trusted events.
  nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aKeyEvent);
  PRBool trustedEvent = PR_FALSE;

  if (domNSEvent) {
    domNSEvent->GetIsTrusted(&trustedEvent);
  }

  if (!trustedEvent)
    return NS_OK;

  nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
  PRUint32 theChar;
       keyEvent->GetKeyCode(&theChar);
  PRBool handled = PR_FALSE;

  if (theChar == NS_VK_LEFT ||
      theChar == NS_VK_RIGHT ||
      theChar == NS_VK_UP ||
      theChar == NS_VK_DOWN ||
      theChar == NS_VK_HOME ||
      theChar == NS_VK_END) {
    // The navigation keys were pressed. User is moving around within
    // the menus.
         mMenuParent->KeyboardNavigation(theChar, handled);
  }
  else if (theChar == NS_VK_ESCAPE) {
    // Close one level.
    // Prevents us from getting destroyed by Escape(), we need to return to ourselves
    NS_ADDREF_THIS();
         mMenuParent->Escape(handled);
    NS_RELEASE_THIS();
    if (!handled)
      mMenuParent->DismissChain();
  }
  else if (theChar == NS_VK_TAB)
    mMenuParent->DismissChain();
  else if (theChar == NS_VK_ENTER ||
           theChar == NS_VK_RETURN) {
    // Open one level.
    mMenuParent->Enter();
  }
#if !defined(XP_MAC) && !defined(XP_MACOSX)
  else if (theChar == NS_VK_F10) {
    // doesn't matter what modifier keys are down in Non-Mac platform
    // if the menu bar is active and F10 is pressed - deactivate it
    mMenuParent->DismissChain();
  }
#endif // !XP_MAC && !XP_MACOSX
  else {
    PRInt32 menuAccessKey = -1;
    nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
    if (menuAccessKey) {
      // Do shortcut navigation.
      // A letter was pressed. We want to see if a shortcut gets matched. If
      // so, we'll know the menu got activated.
      keyEvent->GetCharCode(&theChar);
      mMenuParent->ShortcutNavigation(keyEvent, handled);
    }
  }

  aKeyEvent->StopPropagation();
  aKeyEvent->PreventDefault();
  return NS_ERROR_BASE; // I am consuming event
}

Here is the call graph for this function:

nsresult nsMenuListener::KeyUp ( nsIDOMEvent aKeyEvent) [virtual]

Processes a key release event.

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

Implements nsIDOMKeyListener.

Definition at line 92 of file nsMenuListener.cpp.

{
  aKeyEvent->StopPropagation();
  aKeyEvent->PreventDefault();

  return NS_ERROR_BASE; // I am consuming event
}
nsresult nsMenuListener::MouseClick ( nsIDOMEvent aMouseEvent) [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 252 of file nsMenuListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}
nsresult nsMenuListener::MouseDblClick ( nsIDOMEvent aMouseEvent) [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 259 of file nsMenuListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}
nsresult nsMenuListener::MouseDown ( nsIDOMEvent aMouseEvent) [virtual]

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 239 of file nsMenuListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}
nsresult nsMenuListener::MouseOut ( nsIDOMEvent aMouseEvent) [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 273 of file nsMenuListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}
nsresult nsMenuListener::MouseOver ( nsIDOMEvent aMouseEvent) [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 266 of file nsMenuListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}
nsresult nsMenuListener::MouseUp ( nsIDOMEvent aMouseEvent) [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 246 of file nsMenuListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}

Member Data Documentation

Definition at line 77 of file nsMenuListener.h.


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