Back to index

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

#include <mozXMLTermListeners.h>

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

List of all members.

Public Member Functions

 mozXMLTermKeyListener ()
virtual ~mozXMLTermKeyListener ()
void SetXMLTerminal (mozIXMLTerminal *aXMLTerminal)
 Save non-owning reference to containing XMLTerminal object.
virtual NS_DECL_ISUPPORTS nsresult HandleEvent (nsIDOMEvent *aEvent)
virtual nsresult KeyDown (nsIDOMEvent *aKeyEvent)
 Processes a key pressed event.
virtual nsresult KeyUp (nsIDOMEvent *aKeyEvent)
 Processes a key release event.
virtual nsresult KeyPress (nsIDOMEvent *aKeyEvent)
 Processes a key typed event.
NS_IMETHOD GetSuspend (PRBool *aSuspend)
NS_IMETHOD SetSuspend (const PRBool aSuspend)
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Public Attributes

attribute boolean suspend

Protected Attributes

mozIXMLTerminalmXMLTerminal
 non-owning reference to containing XMLTerminal object (for callback)
PRBool mSuspend
 suspend flag

Detailed Description

Definition at line 58 of file mozXMLTermListeners.h.


Constructor & Destructor Documentation

Definition at line 125 of file mozXMLTermListeners.cpp.

Definition at line 132 of file mozXMLTermListeners.cpp.

{
}

Member Function Documentation

Definition at line 175 of file mozXMLTermListeners.cpp.

{
  if (!*aSuspend)
    return NS_ERROR_NULL_POINTER;
  *aSuspend = mSuspend;
  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.

Definition at line 196 of file mozXMLTermListeners.cpp.

{
  return NS_OK;
}

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 204 of file mozXMLTermListeners.cpp.

{
  nsCOMPtr<nsIDOMKeyEvent> keyEvent;
  keyEvent = do_QueryInterface(aKeyEvent);
  if (!keyEvent) {
    // Non-key event passed to keydown, do not consume it
    return NS_OK;
  }

  PRBool shiftKey, ctrlKey, altKey;
  PRUint32 keyCode;

  XMLT_LOG(mozXMLTermKeyListener::KeyDown,50,("mSuspend=0x%x\n",
                                               mSuspend));

  if (NS_SUCCEEDED(keyEvent->GetKeyCode(&keyCode)) && 
      NS_SUCCEEDED(keyEvent->GetShiftKey(&shiftKey)) &&
      NS_SUCCEEDED(keyEvent->GetCtrlKey(&ctrlKey)) &&
      NS_SUCCEEDED(keyEvent->GetAltKey(&altKey)) ) {

    XMLT_LOG(mozXMLTermKeyListener::KeyDown,52,
          ("code=0x%x, shift=%d, ctrl=%d, alt=%d\n",
           keyCode, shiftKey, ctrlKey, altKey));
  }

  // Consume key down event
  return NS_ERROR_BASE;
}

Here is the call graph for this function:

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 243 of file mozXMLTermListeners.cpp.

{
  nsresult result;

  XMLT_LOG(mozXMLTermKeyListener::KeyPress,50,("mSuspend=0x%x\n",
                                               mSuspend));

  nsCOMPtr<nsIDOMKeyEvent> keyEvent;
  keyEvent = do_QueryInterface(aKeyEvent);
  if (!keyEvent) {
    // Non-key event passed to keydown, do not consume it
    return NS_OK;
  }

#if 0  // Debugging
  nsCOMPtr<nsIPresShell> presShell;
  result = mXMLTerminal->GetPresShell(getter_AddRefs(presShell));
  if (NS_SUCCEEDED(result) && presShell) {
    nsCOMPtr<nsISelection> selection;
    result = presShell->GetSelection(SELECTION_NORMAL,
                                     getter_AddRefs(selection));
    if (NS_SUCCEEDED(result) && selection) {
      nsCOMPtr<nsIDOMNode> childNode, parentNode;
      result = selection->GetFocusNode(getter_AddRefs(childNode));
      if (NS_SUCCEEDED(result) && childNode) {
        PRInt32 j;
        nsAutoString nodeName;
        for (j=0; (j<6) && childNode; j++) {
          result = childNode->GetParentNode(getter_AddRefs(parentNode));
          if (NS_SUCCEEDED(result) && parentNode) {
            result = parentNode->GetNodeName(nodeName);
            if (NS_SUCCEEDED(result)) {
              NS_ConvertUTF16toUTF8 CNodeName(nodeName);
              XMLT_LOG(mozXMLTermKeyListener::KeyPress,58,("nodeName=%s\n",
                                              CNodeName.get()));
            }
            childNode = parentNode;
          } else {
            childNode = nsnull;
          }
        }
      }
    }
  }
#endif

  PRUint32 keyCode;
  PRBool shiftKey, ctrlKey, altKey;
  if (NS_SUCCEEDED(keyEvent->GetKeyCode(&keyCode)) && 
      NS_SUCCEEDED(keyEvent->GetShiftKey(&shiftKey)) &&
      NS_SUCCEEDED(keyEvent->GetCtrlKey(&ctrlKey)) &&
      NS_SUCCEEDED(keyEvent->GetAltKey(&altKey)) ) {

    PRUint32 keyChar = 0;
    PRUint32 escPrefix = 0;
    nsAutoString JSCommand; JSCommand.SetLength(0);

    PRBool screenMode = 0;
    result = mXMLTerminal->GetScreenMode(&screenMode);

    result = keyEvent->GetCharCode(&keyChar);

    XMLT_LOG(mozXMLTermKeyListener::KeyPress,52,
          ("code=0x%x, char=0x%x, shift=%d, ctrl=%d, alt=%d, screenMode=%d\n",
           keyCode, keyChar, shiftKey, ctrlKey, altKey, screenMode));

    if (keyChar == 0) {
      // Key that hasn't been mapped to a character code

      switch (keyCode) {
      case nsIDOMKeyEvent::DOM_VK_SHIFT:
      case nsIDOMKeyEvent::DOM_VK_CONTROL:
      case nsIDOMKeyEvent::DOM_VK_ALT:
        break;                         // ignore modifier key event
      case nsIDOMKeyEvent::DOM_VK_BACK_SPACE:
        keyChar = U_BACKSPACE;
        break;
      case nsIDOMKeyEvent::DOM_VK_DELETE:
        keyChar = U_DEL;
        break;
      case nsIDOMKeyEvent::DOM_VK_TAB:
        keyChar = U_TAB;
        break;
      case nsIDOMKeyEvent::DOM_VK_RETURN:
        keyChar = U_CRETURN;
        break;
      case nsIDOMKeyEvent::DOM_VK_UP:
        escPrefix = 1;
        keyChar = U_A_CHAR;
        break;
      case nsIDOMKeyEvent::DOM_VK_DOWN:
        escPrefix = 1;
        keyChar = U_B_CHAR;
        break;
      case nsIDOMKeyEvent::DOM_VK_RIGHT:
        escPrefix = 1;
        keyChar = U_C_CHAR;
        break;
      case nsIDOMKeyEvent::DOM_VK_LEFT:
        escPrefix = 1;
        keyChar = U_D_CHAR;
        break;
      case nsIDOMKeyEvent::DOM_VK_ESCAPE:
        keyChar = U_ESCAPE;
        break;
      case nsIDOMKeyEvent::DOM_VK_HOME:
        JSCommand.AssignLiteral("ScrollHomeKey");
        break;
      case nsIDOMKeyEvent::DOM_VK_END:
        JSCommand.AssignLiteral("ScrollEndKey");
        break;
      case nsIDOMKeyEvent::DOM_VK_PAGE_UP:
        JSCommand.AssignLiteral("ScrollPageUpKey");
        break;
      case nsIDOMKeyEvent::DOM_VK_PAGE_DOWN:
        JSCommand.AssignLiteral("ScrollPageDownKey");
        break;
      case nsIDOMKeyEvent::DOM_VK_F1:
        JSCommand.AssignLiteral("F1Key");
        break;
      case nsIDOMKeyEvent::DOM_VK_F2:
        JSCommand.AssignLiteral("F2Key");
        break;
      case nsIDOMKeyEvent::DOM_VK_F3:
        JSCommand.AssignLiteral("F3Key");
        break;
      case nsIDOMKeyEvent::DOM_VK_F4:
        JSCommand.AssignLiteral("F4Key");
        break;
      case nsIDOMKeyEvent::DOM_VK_F5:
        JSCommand.AssignLiteral("F5Key");
        break;
      case nsIDOMKeyEvent::DOM_VK_F6:
        JSCommand.AssignLiteral("F6Key");
        break;
      case nsIDOMKeyEvent::DOM_VK_F7:
        JSCommand.AssignLiteral("F7Key");
        break;
      case nsIDOMKeyEvent::DOM_VK_F8:
        JSCommand.AssignLiteral("F8Key");
        break;
      case nsIDOMKeyEvent::DOM_VK_F9:
        JSCommand.AssignLiteral("F9Key");
        break;
      default: 
        if ( (ctrlKey && (keyCode ==nsIDOMKeyEvent::DOM_VK_SPACE)) ||
             (ctrlKey && shiftKey && (keyCode ==nsIDOMKeyEvent::DOM_VK_2)) ) {
          // Hack to handle input of NUL characters in NUL-terminated strings
          // See also: mozLineTerm::Write
          keyChar = U_PRIVATE0;
        } else {
          // ignore event without consuming
          return NS_OK;
        }
      }

    } else if ((ctrlKey == PR_TRUE) && (altKey == PR_FALSE) &&
               (keyChar >= 0x40U) && (keyChar < 0x80U)) {
      // Control character, without Alt; adjust character code
      // Is this portable?
      keyChar = (keyChar >= 0x60U) ? keyChar-0x60U : keyChar-0x40U;
    }

    XMLT_LOG(mozXMLTermKeyListener::KeyPress,53,
             ("escPrefix=%d, keyChar=0x%x, \n", escPrefix, keyChar));

    if (!JSCommand.IsEmpty()) {
      // Execute JS command
      nsCOMPtr<nsIDOMDocument> domDocument;
      result = mXMLTerminal->GetDocument(getter_AddRefs(domDocument));

      if (NS_SUCCEEDED(result) && domDocument) {
        nsAutoString JSInput = JSCommand;
        nsAutoString JSOutput; JSOutput.SetLength(0);
        JSInput.AppendLiteral("(");
        JSInput.AppendInt(shiftKey,10);
        JSInput.AppendLiteral(",");
        JSInput.AppendInt(ctrlKey,10);
        JSInput.Append(NS_LITERAL_STRING(");"));
        result = mozXMLTermUtils::ExecuteScript(domDocument,
                                                JSInput,
                                                JSOutput);
      }
    }

    if (!mSuspend && (keyChar > 0) && (keyChar <= 0xFFFDU)) {
      // Transmit valid non-null Unicode character
      nsAutoString keyString; keyString.SetLength(0);
      if (escPrefix) {
        keyString.Append((PRUnichar) U_ESCAPE);
        keyString.Append((PRUnichar) U_LBRACKET);
      }

      keyString.Append((PRUnichar) keyChar);

      result = mXMLTerminal->SendTextAux(keyString.get());
    }
  }

  // Consume key press event
  return NS_ERROR_BASE;
}

Here is the call graph for this function:

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 235 of file mozXMLTermListeners.cpp.

{
  return NS_OK;
}

Definition at line 184 of file mozXMLTermListeners.cpp.

{
  XMLT_LOG(mozXMLTermKeyListener::SetSuspend,50,("aSuspend=0x%x\n",
                                                 aSuspend));
  mSuspend = aSuspend;
  return NS_OK;
}

Save non-owning reference to containing XMLTerminal object.

Parameters:
aXMLTerminalthe XMLTerm instance

Definition at line 68 of file mozXMLTermListeners.h.

    {mXMLTerminal = aXMLTerminal;}

Here is the caller graph for this function:


Member Data Documentation

suspend flag

Definition at line 91 of file mozXMLTermListeners.h.

non-owning reference to containing XMLTerminal object (for callback)

Definition at line 88 of file mozXMLTermListeners.h.

Definition at line 181 of file mozIXMLTerminal.idl.


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