Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
nsGtkKeyUtils.cpp File Reference
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkevents.h>
#include <gdk/gdkx.h>
#include "nsGUIEvent.h"
#include "keysym2ucs.h"

Go to the source code of this file.

Classes

struct  nsKeyConverter

Defines

#define IS_XSUN_XSERVER(dpy)   (strstr(XServerVendor(dpy), "Sun Microsystems") != NULL)

Functions

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

Class Documentation

struct nsKeyConverter

Definition at line 2227 of file nsWindow.cpp.

Collaboration diagram for nsKeyConverter:
Class Members
char bekeycode
unsigned int keysym
int keysym
unsigned long keysym
PRUint32 vkCode
int vkCode

Define Documentation

#define IS_XSUN_XSERVER (   dpy)    (strstr(XServerVendor(dpy), "Sun Microsystems") != NULL)

Definition at line 157 of file nsGtkKeyUtils.cpp.


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 257 of file nsGtkKeyUtils.cpp.

{
    // Anything above 0xf000 is considered a non-printable
    // Exception: directly encoded UCS characters
    if (aEvent->keyval > 0xf000 && (aEvent->keyval & 0xff000000) != 0x01000000) {

        // Keypad keys are an exception: they return a value different
        // from their non-keypad equivalents, but mozilla doesn't distinguish.
        switch (aEvent->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;
    }

    // we're supposedly printable, let's try to convert
    long ucs = keysym2ucs(aEvent->keyval);
    if ((ucs != -1) && (ucs < 0x10000))
        return ucs;

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

Here is the call graph for this function: