Attachment #307428: Rediffered for ff2 with fix (comment 201) for bug #69230

View | Details | Raw Unified | Return to bug 69230
Collapse All | Expand All

(-)widget/src/gtk2/nsWindow.cpp (-6 / +67 lines)
Line     Link Here 
 Lines 1810-1825   nsWindow::OnContainerFocusOutEvent(GtkWi Link Here 
1810
1810
1811
    gFocusWindow = nsnull;
1811
    gFocusWindow = nsnull;
1812
1812
1813
    mActivatePending = PR_FALSE;
1813
    mActivatePending = PR_FALSE;
1814
1814
1815
    LOGFOCUS(("Done with container focus out [%p]\n", (void *)this));
1815
    LOGFOCUS(("Done with container focus out [%p]\n", (void *)this));
1816
}
1816
}
1817
1817
1818
inline PRBool
1819
is_latin_shortcut_key(guint aKeyval)
1820
{
1821
    return ((GDK_0 <= aKeyval && aKeyval <= GDK_9) ||
1822
            (GDK_A <= aKeyval && aKeyval <= GDK_Z) ||
1823
            (GDK_a <= aKeyval && aKeyval <= GDK_z));
1824
}
1825
1818
gboolean
1826
gboolean
1819
nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent)
1827
nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent)
1820
{
1828
{
1821
    LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this));
1829
    LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this));
1822
1830
1823
#ifdef USE_XIM
1831
#ifdef USE_XIM
1824
    // if we are in the middle of composing text, XIM gets to see it
1832
    // if we are in the middle of composing text, XIM gets to see it
1825
    // before mozilla does.
1833
    // before mozilla does.
 Lines 1884-1899   nsWindow::OnKeyPressEvent(GtkWidget *aWi Link Here 
1884
    if (event.charCode) {
1892
    if (event.charCode) {
1885
        event.keyCode = 0;
1893
        event.keyCode = 0;
1886
        // if the control, meta, or alt key is down, then we should leave
1894
        // if the control, meta, or alt key is down, then we should leave
1887
        // the isShift flag alone (probably not a printable character)
1895
        // the isShift flag alone (probably not a printable character)
1888
        // if none of the other modifier keys are pressed then we need to
1896
        // if none of the other modifier keys are pressed then we need to
1889
        // clear isShift so the character can be inserted in the editor
1897
        // clear isShift so the character can be inserted in the editor
1890
1898
1891
        if (event.isControl || event.isAlt || event.isMeta) {
1899
        if (event.isControl || event.isAlt || event.isMeta) {
1900
            GdkEventKey tmpEvent = *aEvent;
1901
1902
            // Fix for bug 69230:
1903
            // if modifier key is pressed and key pressed is not latin character,
1904
            // we should try other keyboard layouts to find out correct latin
1905
            // character corresponding to pressed key;
1906
            // that way shortcuts like Ctrl+C will work no matter what
1907
            // keyboard layout is selected
1908
            // We don't try to fix up punctuation accelerators here,
1909
            // because their location differs between latin layouts
1910
            if (event.isControl && !is_latin_shortcut_key(event.charCode)) {
1911
                // We have a non-latin char, try other keyboard groups
1912
                GdkKeymapKey *keys;
1913
                guint *keyvals;
1914
                gint n_entries;
1915
                PRUint32 latinCharCode;
1916
                gint level;
1917
1918
                if (gdk_keymap_translate_keyboard_state(NULL,
1919
                                                        tmpEvent.hardware_keycode,
1920
                                                        (GdkModifierType)tmpEvent.state,
1921
                                                        tmpEvent.group,
1922
                                                        NULL, NULL, &level, NULL)
1923
                    && gdk_keymap_get_entries_for_keycode(NULL,
1924
                                                          tmpEvent.hardware_keycode,
1925
                                                          &keys, &keyvals,
1926
                                                          &n_entries)) {
1927
                    gint n;
1928
                    for (n=0; n<n_entries; n++) {
1929
                        if (keys[n].group == tmpEvent.group) {
1930
                            // Skip keys from the same group
1931
                            continue;
1932
                        }
1933
                        if (keys[n].level != level) {
1934
                            // Allow only same level keys
1935
                            continue;
1936
                        }
1937
                        if (is_latin_shortcut_key(keyvals[n])) {
1938
                            // Latin character found
1939
                            if (event.isShift)
1940
                                tmpEvent.keyval = gdk_keyval_to_upper(keyvals[n]);
1941
                            else
1942
                                tmpEvent.keyval = gdk_keyval_to_lower(keyvals[n]);
1943
                            tmpEvent.group = keys[n].group;
1944
                            latinCharCode = nsConvertCharCodeToUnicode(&tmpEvent);
1945
                            if (latinCharCode) {
1946
                                event.charCode = latinCharCode;
1947
                                break;
1948
                            }
1949
                        }
1950
                    }
1951
                    g_free(keys);
1952
                    g_free(keyvals);
1953
                }
1954
            }
1955
1892
           // make Ctrl+uppercase functional as same as Ctrl+lowercase
1956
           // make Ctrl+uppercase functional as same as Ctrl+lowercase
1893
           // when Ctrl+uppercase(eg.Ctrl+C) is pressed,convert the charCode
1957
           // when Ctrl+uppercase(eg.Ctrl+C) is pressed,convert the charCode
1894
           // from uppercase to lowercase(eg.Ctrl+c),so do Alt and Meta Key
1958
           // from uppercase to lowercase(eg.Ctrl+c),so do Alt and Meta Key
1895
           // It is hack code for bug 61355, there is same code snip for
1959
           // It is hack code for bug 61355, there is same code snip for
1896
           // Windows platform in widget/src/windows/nsWindow.cpp: See bug 16486
1960
           // Windows platform in widget/src/windows/nsWindow.cpp: See bug 16486
1897
           // Note: if Shift is pressed at the same time, do not to_lower()
1961
           // Note: if Shift is pressed at the same time, do not to_lower()
1898
           // Because Ctrl+Shift has different function with Ctrl
1962
           // Because Ctrl+Shift has different function with Ctrl
1899
           if (!event.isShift &&
1963
           if (!event.isShift &&
 Lines 1901-1924   nsWindow::OnKeyPressEvent(GtkWidget *aWi Link Here 
1901
               event.charCode <= GDK_Z)
1965
               event.charCode <= GDK_Z)
1902
            event.charCode = gdk_keyval_to_lower(event.charCode);
1966
            event.charCode = gdk_keyval_to_lower(event.charCode);
1903
1967
1904
           // Keep the characters unshifted for shortcuts and accesskeys and
1968
           // Keep the characters unshifted for shortcuts and accesskeys and
1905
           // make sure that numbers are always passed as such (among others:
1969
           // make sure that numbers are always passed as such (among others:
1906
           // bugs 50255 and 351310)
1970
           // bugs 50255 and 351310)
1907
           if (!event.isControl && event.isShift &&
1971
           if (!event.isControl && event.isShift &&
1908
               (event.charCode < GDK_0 || event.charCode > GDK_9)) {
1972
               (event.charCode < GDK_0 || event.charCode > GDK_9)) {
1909
               GdkKeymapKey k = { aEvent->hardware_keycode, aEvent->group, 0 };
1973
               GdkKeymapKey k = { tmpEvent.hardware_keycode, tmpEvent.group, 0 };
1910
               guint savedKeyval = aEvent->keyval;
1974
               tmpEvent.keyval = gdk_keymap_lookup_key(gdk_keymap_get_default(), &k);
1911
               aEvent->keyval = gdk_keymap_lookup_key(gdk_keymap_get_default(), &k);
1975
               PRUint32 unshiftedCharCode = nsConvertCharCodeToUnicode(&tmpEvent);
1912
               PRUint32 unshiftedCharCode = nsConvertCharCodeToUnicode(aEvent);
1913
               if (unshiftedCharCode)
1976
               if (unshiftedCharCode)
1914
                   event.charCode = unshiftedCharCode;
1977
                   event.charCode = unshiftedCharCode;
1915
               else
1916
                   aEvent->keyval = savedKeyval;
1917
           }
1978
           }
1918
        }
1979
        }
1919
    }
1980
    }
1920
1981
1921
    // before we dispatch a key, check if it's the context menu key.
1982
    // before we dispatch a key, check if it's the context menu key.
1922
    // If so, send a context menu key event instead.
1983
    // If so, send a context menu key event instead.
1923
    if (is_context_menu_key(event)) {
1984
    if (is_context_menu_key(event)) {
1924
        nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal);
1985
        nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal);

Return to bug 69230