Back to index

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

editor Implementation of the DragListener interface More...

#include <nsMenuBarListener.h>

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

List of all members.

Public Member Functions

 nsMenuBarListener (nsMenuBarFrame *aMenuBar)
 default constructor
virtual ~nsMenuBarListener ()
 default destructor
NS_IMETHOD HandleEvent (nsIDOMEvent *aEvent)
NS_IMETHOD KeyUp (nsIDOMEvent *aMouseEvent)
 Processes a key release event.
NS_IMETHOD KeyDown (nsIDOMEvent *aMouseEvent)
 Processes a key pressed event.
NS_IMETHOD KeyPress (nsIDOMEvent *aMouseEvent)
 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.

Static Public Member Functions

static nsresult GetMenuAccessKey (PRInt32 *aAccessKey)
static NS_DECL_ISUPPORTS PRBool IsAccessKeyPressed (nsIDOMKeyEvent *event)

Static Protected Member Functions

static void InitAccessKey ()
static PRUint32 GetModifiers (nsIDOMKeyEvent *event)

Protected Attributes

nsMenuBarFramemMenuBarFrame
PRBool mAccessKeyDown

Static Protected Attributes

static PRBool mAccessKeyFocuses = PR_FALSE
static PRInt32 mAccessKey = -1
static PRUint32 mAccessKeyMask = 0

Detailed Description

editor Implementation of the DragListener interface

Definition at line 53 of file nsMenuBarListener.h.


Constructor & Destructor Documentation

default constructor

Definition at line 86 of file nsMenuBarListener.cpp.

default destructor

Definition at line 93 of file nsMenuBarListener.cpp.

{
}

Member Function Documentation

nsresult nsMenuBarListener::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 353 of file nsMenuBarListener.cpp.

{
  if (!mMenuBarFrame->IsOpen() && mMenuBarFrame->IsActive()) {
    mMenuBarFrame->ToggleMenuActiveState();
    PRBool handled;
    mMenuBarFrame->Escape(handled);
    mAccessKeyDown = PR_FALSE;
  }
  return NS_OK; // means I am NOT consuming event
}

Here is the call graph for this function:

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 346 of file nsMenuBarListener.cpp.

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

Definition at line 98 of file nsMenuBarListener.cpp.

{
  if (!aAccessKey)
    return NS_ERROR_INVALID_POINTER;
  InitAccessKey();
  *aAccessKey = mAccessKey;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRUint32 nsMenuBarListener::GetModifiers ( nsIDOMKeyEvent event) [static, protected]

Definition at line 277 of file nsMenuBarListener.cpp.

{
  PRUint32 modifiers = 0;
  PRBool modifier;

  aKeyEvent->GetShiftKey(&modifier);
  if (modifier)
    modifiers |= MODIFIER_SHIFT;

  aKeyEvent->GetCtrlKey(&modifier);
  if (modifier)
    modifiers |= MODIFIER_CONTROL;

  aKeyEvent->GetAltKey(&modifier);
  if (modifier)
    modifiers |= MODIFIER_ALT;

  aKeyEvent->GetMetaKey(&modifier);
  if (modifier)
    modifiers |= MODIFIER_META;

  return modifiers;
}

Here is the caller graph for this function:

Definition at line 417 of file nsMenuBarListener.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.
void nsMenuBarListener::InitAccessKey ( ) [static, protected]

Definition at line 107 of file nsMenuBarListener.cpp.

{
  if (mAccessKey >= 0)
    return;

  // Compiled-in defaults, in case we can't get LookAndFeel --
  // mac doesn't have menu shortcuts, other platforms use alt.
#if !(defined(XP_MAC) || defined(XP_MACOSX))
  mAccessKey = nsIDOMKeyEvent::DOM_VK_ALT;
  mAccessKeyMask = MODIFIER_ALT;
#else
  mAccessKey = 0;
  mAccessKeyMask = 0;
#endif

  // Get the menu access key value from prefs, overriding the default:
  mAccessKey = nsContentUtils::GetIntPref("ui.key.menuAccessKey", mAccessKey);
  if (mAccessKey == nsIDOMKeyEvent::DOM_VK_SHIFT)
    mAccessKeyMask = MODIFIER_SHIFT;
  else if (mAccessKey == nsIDOMKeyEvent::DOM_VK_CONTROL)
    mAccessKeyMask = MODIFIER_CONTROL;
  else if (mAccessKey == nsIDOMKeyEvent::DOM_VK_ALT)
    mAccessKeyMask = MODIFIER_ALT;
  else if (mAccessKey == nsIDOMKeyEvent::DOM_VK_META)
    mAccessKeyMask = MODIFIER_META;

  mAccessKeyFocuses =
    nsContentUtils::GetBoolPref("ui.key.menuAccessKeyFocuses");
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 265 of file nsMenuBarListener.cpp.

{
  InitAccessKey();
  // No other modifiers are allowed to be down except for Shift.
  PRUint32 modifiers = GetModifiers(aKeyEvent);

  return (mAccessKeyMask != MODIFIER_SHIFT &&
          (modifiers & mAccessKeyMask) &&
          (modifiers & ~(mAccessKeyMask | MODIFIER_SHIFT)) == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMenuBarListener::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 303 of file nsMenuBarListener.cpp.

{
  InitAccessKey();

  //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;

  if (mAccessKey && mAccessKeyFocuses)
  {
    nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
    PRUint32 theChar;
    keyEvent->GetKeyCode(&theChar);

    if (theChar == (PRUint32)mAccessKey && (GetModifiers(keyEvent) & ~mAccessKeyMask) == 0) {
      // 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.
      mAccessKeyDown = PR_TRUE;
    }
    else {
      // Some key other than the access key just went down,
      // so we won't activate the menu bar when the access
      // key is released.

      mAccessKeyDown = PR_FALSE;
    }
  }

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

Here is the call graph for this function:

nsresult nsMenuBarListener::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 184 of file nsMenuBarListener.cpp.

{
  mMenuBarFrame->ClearRecentlyRolledUp();

  // if event has already been handled, bail
  nsCOMPtr<nsIDOMNSUIEvent> uiEvent ( do_QueryInterface(aKeyEvent) );
  if ( uiEvent ) {
    PRBool eventHandled = PR_FALSE;
    uiEvent->GetPreventDefault ( &eventHandled );
    if ( eventHandled )
      return NS_OK;       // don't consume 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;

  nsresult retVal = NS_OK;  // default is to not consume event
  
  InitAccessKey();

  if (mAccessKey)
  {
    nsCOMPtr<nsIDOMNSUIEvent> nsUIEvent = do_QueryInterface(aKeyEvent);

    PRBool preventDefault;

    nsUIEvent->GetPreventDefault(&preventDefault);
    if (!preventDefault) {
      nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
      PRUint32 keyCode, charCode;
      keyEvent->GetKeyCode(&keyCode);
      keyEvent->GetCharCode(&charCode);

      // Clear the access key flag unless we are pressing the access key.
      if (keyCode != (PRUint32)mAccessKey)
        mAccessKeyDown = PR_FALSE;

      // If charCode == 0, then it is not a printable character.
      // Don't attempt to handle accesskey for non-printable characters.
      if (IsAccessKeyPressed(keyEvent) && charCode)
      {
        // 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.
        PRBool active = PR_FALSE;
        mMenuBarFrame->ShortcutNavigation(keyEvent, active);

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

          retVal = NS_ERROR_BASE;       // I am consuming event
        }
      }    
#if !defined(XP_MAC) && !defined(XP_MACOSX)
      // Also need to handle F10 specially on Non-Mac platform.
      else if (keyCode == NS_VK_F10) {
        if ((GetModifiers(keyEvent) & ~MODIFIER_CONTROL) == 0) {
          // The F10 key just went down by itself or with ctrl pressed.
          // In Windows, both of these activate the menu bar.
          mMenuBarFrame->ToggleMenuActiveState();

          aKeyEvent->StopPropagation();
          aKeyEvent->PreventDefault();
          return NS_ERROR_BASE; // consume the event
        }
      }
#endif   // !XP_MAC && !XP_MACOSX
    } 
  }
  return retVal;
}

Here is the call graph for this function:

nsresult nsMenuBarListener::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 139 of file nsMenuBarListener.cpp.

{  
  InitAccessKey();

  //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;

  if (mAccessKey && mAccessKeyFocuses)
  {
    // On a press of the ALT key by itself, we toggle the menu's 
    // active/inactive state.
    // Get the ascii key code.
    nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
    PRUint32 theChar;
    keyEvent->GetKeyCode(&theChar);

    if (mAccessKeyDown && (PRInt32)theChar == mAccessKey)
    {
      // The access key was down and is now up, and no other
      // keys were pressed in between.
      mMenuBarFrame->ToggleMenuActiveState();
    }
    mAccessKeyDown = PR_FALSE; 

    PRBool active = mMenuBarFrame->IsActive();
    if (active) {
      aKeyEvent->StopPropagation();
      aKeyEvent->PreventDefault();
      return NS_ERROR_BASE; // I am consuming event
    }
  }
  
  return NS_OK; // means I am NOT consuming event
}

Here is the call graph for this function:

nsresult nsMenuBarListener::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 389 of file nsMenuBarListener.cpp.

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

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 396 of file nsMenuBarListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}
nsresult nsMenuBarListener::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 366 of file nsMenuBarListener.cpp.

{
  if (!mMenuBarFrame->IsOpen() && mMenuBarFrame->IsActive()) {
    mMenuBarFrame->ToggleMenuActiveState();
    PRBool handled;
    mMenuBarFrame->Escape(handled);
  }

  mAccessKeyDown = PR_FALSE;

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

Here is the call graph for this function:

nsresult nsMenuBarListener::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 410 of file nsMenuBarListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}
nsresult nsMenuBarListener::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 403 of file nsMenuBarListener.cpp.

{
  return NS_OK; // means I am NOT consuming event
}
nsresult nsMenuBarListener::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 381 of file nsMenuBarListener.cpp.

{
  mMenuBarFrame->ClearRecentlyRolledUp();

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

Here is the call graph for this function:


Member Data Documentation

PRInt32 nsMenuBarListener::mAccessKey = -1 [static, protected]

Definition at line 93 of file nsMenuBarListener.h.

Definition at line 91 of file nsMenuBarListener.h.

Definition at line 92 of file nsMenuBarListener.h.

Definition at line 94 of file nsMenuBarListener.h.

Definition at line 90 of file nsMenuBarListener.h.


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