Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsGtkKeyUtils.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int GdkKeyCodeToDOMKeyCode (int aKeysym)
int DOMKeyCodeToGdkKeyCode (PRUint32 aKeysym)
PRUint32 nsConvertCharCodeToUnicode (GdkEventKey *aEvent)

Function Documentation

Definition at line 220 of file nsGtkKeyUtils.cpp.

{
    int i, length = 0;

    // First, try to handle alphanumeric input, not listed in nsKeycodes:
    // most likely, more letters will be getting typed in than things in
    // the key list, so we will look through these first.

    if (aKeysym >= NS_VK_A && aKeysym <= NS_VK_Z)
      // gdk and DOM both use the ASCII codes for these keys.
      return aKeysym;

    // numbers
    if (aKeysym >= NS_VK_0 && aKeysym <= NS_VK_9)
      // gdk and DOM both use the ASCII codes for these keys.
      return aKeysym - GDK_0 + NS_VK_0;

    // keypad numbers
    if (aKeysym >= NS_VK_NUMPAD0 && aKeysym <= NS_VK_NUMPAD9)
      return aKeysym - NS_VK_NUMPAD0 + GDK_KP_0;

    // misc other things
    length = NS_ARRAY_LENGTH(nsKeycodes);
    for (i = 0; i < length; ++i) {
      if (nsKeycodes[i].vkCode == aKeysym) {
        return nsKeycodes[i].keysym;
      }
    }

    // function keys
    if (aKeysym >= NS_VK_F1 && aKeysym <= NS_VK_F9)
      return aKeysym - NS_VK_F1 + GDK_F1;

    return 0;
}

Definition at line 173 of file nsGtkKeyUtils.cpp.

{
    int i, length = 0;

    // First, try to handle alphanumeric input, not listed in nsKeycodes:
    // most likely, more letters will be getting typed in than things in
    // the key list, so we will look through these first.

    // since X has different key symbols for upper and lowercase letters and
    // mozilla does not, convert gdk's to mozilla's
    if (aKeysym >= GDK_a && aKeysym <= GDK_z)
        return aKeysym - GDK_a + NS_VK_A;
    if (aKeysym >= GDK_A && aKeysym <= GDK_Z)
        return aKeysym - GDK_A + NS_VK_A;

    // numbers
    if (aKeysym >= GDK_0 && aKeysym <= GDK_9)
        return aKeysym - GDK_0 + NS_VK_0;

    // keypad numbers
    if (aKeysym >= GDK_KP_0 && aKeysym <= GDK_KP_9)
        return aKeysym - GDK_KP_0 + NS_VK_NUMPAD0;

    // map Sun Keyboard special keysyms
    if (IS_XSUN_XSERVER(GDK_DISPLAY())) {
        length = sizeof(nsSunKeycodes) / sizeof(struct nsKeyConverter);
        for (i = 0; i < length; i++) {
            if (nsSunKeycodes[i].keysym == aKeysym)
                return(nsSunKeycodes[i].vkCode);
        }
    }

    // misc other things
    length = sizeof(nsKeycodes) / sizeof(struct nsKeyConverter);
    for (i = 0; i < length; i++) {
        if (nsKeycodes[i].keysym == aKeysym)
            return(nsKeycodes[i].vkCode);
    }

    // function keys
    if (aKeysym >= GDK_F1 && aKeysym <= GDK_F24)
        return aKeysym - GDK_F1 + NS_VK_F1;

    return((int)0);
}

Here is the caller graph for this function:

PRUint32 nsConvertCharCodeToUnicode ( GdkEventKey *  aEvent)

Definition at line 279 of file nsGtkEventHandler.cpp.

{
  // Anything above 0xf000 is considered a non-printable
  // Exception: directly encoded UCS characters
  if (aGEK->keyval > 0xf000 && (aGEK->keyval & 0xff000000) != 0x01000000) {
    // Keypad keys are an exception: they return a value different
    // from their non-keypad equivalents, but mozilla doesn't distinguish.
    switch (aGEK->keyval)
    {
      case GDK_KP_Space:
        return ' ';
      case GDK_KP_Equal:
        return '=';
      case GDK_KP_Multiply:
        return '*';
      case GDK_KP_Add:
        return '+';
      case GDK_KP_Separator:
        return ',';
      case GDK_KP_Subtract:
        return '-';
      case GDK_KP_Decimal:
        return '.';
      case GDK_KP_Divide:
        return '/';
      case GDK_KP_0:
        return '0';
      case GDK_KP_1:
        return '1';
      case GDK_KP_2:
        return '2';
      case GDK_KP_3:
        return '3';
      case GDK_KP_4:
        return '4';
      case GDK_KP_5:
        return '5';
      case GDK_KP_6:
        return '6';
      case GDK_KP_7:
        return '7';
      case GDK_KP_8:
        return '8';
      case GDK_KP_9:
        return '9';
    }

    // non-printables
    return 0;
  }

#if defined(USE_XIM) && defined(_AIX)
  // On AIX, GDK doesn't get correct keysyms from XIM. Follow GDK 
  // reference recommending to use the 'string' member of GdkEventKey 
  // instead. See:
  //
  // developer.gnome.org/doc/API/gdk/gdk-event-structures.html#GDKEVENTKEY

  PRBool controlChar = (aGEK->state & GDK_CONTROL_MASK ||
                        aGEK->state & GDK_MOD1_MASK ||
                        aGEK->state & GDK_MOD4_MASK);

  // Use 'string' as opposed to 'keyval' when control, alt, or meta is 
  // not pressed. This allows keyboard shortcuts to continue to function
  // properly, while fixing input problems and mode switching in certain
  // locales where the 'keyval' does not correspond to the actual input.
  // See Bug #157397 and Bug #161581 for more details.

  if (!controlChar && gdk_im_ready() && aGEK->length > 0 
        && aGEK->keyval != (guint)*aGEK->string) {
    nsGtkIMEHelper* IMEHelper = nsGtkIMEHelper::GetSingleton();
    if (IMEHelper != nsnull) {
      PRUnichar* unichars = IMEHelper->GetUnichars();
      PRInt32 unilen = IMEHelper->GetUnicharsSize();
      PRInt32 unichar_size = IMEHelper->MultiByteToUnicode(
                                          aGEK->string, aGEK->length,
                                          &unichars, &unilen);
      if (unichar_size > 0) {
        IMEHelper->SetUnichars(unichars);
        IMEHelper->SetUnicharsSize(unilen);
        return (long)*unichars;
      }
    }
  }
#endif
  // we're supposedly printable, let's try to convert
  long ucs = keysym2ucs(aGEK->keyval);
  if ((ucs != -1) && (ucs < 0x10000))
    return ucs;

  // I guess we couldn't convert
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: