Visit Mozilla.org

nsIBidiKeyboard

From MDC

DRAFT
This page is not complete.

Bidi Keyboard is a Mozilla component that lets the application detect Bidi Writer users, and do some magic for them. A user is a Bidi Writer, if has keyboard layouts in both left-to-right and right-to-left directions (i.e. users who use Arabic, Iranian (Persian), or Israel (Hebrew) keyboard layout, beside an US (English) layout.)

nsIBidiKeyboard is defined in widget/public/nsIBidiKeyboard.idl. It is scriptable and unfrozen (hasn't changed since Mozilla 1.9).

Contents


[edit] Interface

[edit] Checking whether the user is a Bidi Writer

(supported on: nothing yet)

boolean nsIBidiKeyboard::isKeyboardsBidi() determines if user have keyboard layouts in both left-to-right and right-to-left directions. This value is initialized on startup, and will be updated whenever user changes keyboard layouts. You can use it to enable some features in UI, etc.

[edit] Getting the direction of active keyboard layout

(supported on: win32, mac, gtk2)

boolean nsIBidiKeyboard::isLangRTL(in PRUint8 aLevel) determines if the current keyboard language is right-to-left. For example, Mozilla uses this method to change the direction of the caret on text-input fields. Throws NS_ERROR_FAILURE if no right-to-left (FIXME: or left-to-right) keyboards are installed

[edit] Setting the keyboard layout based on the direction

(supported on: win32)

void nsIBidiKeyboard::setLangFromBidiLevel(in PRUint8 aLevel) sets the keyboard layout to left-to-right or right-to-left based on aLevel; if odd sets the keyboard to a right-to-left layout, if even sets the keyboard to a left-to-right layout. (FIXME: last-used or first in the list?). This method throws NS_ERROR_FAILURE if no right-to-left (FIXME: or left-to-right) keyboard is installed.

[edit] Implementation

[edit] Windows

This implementation uses win32 API to get the language of the keyboard layout, and the direction of those languages.

[edit] Linux

This implementation depends on the Mozilla and GTK+ version.

In mozilla1.8 branch, just isLangRTL method had been implemented, and uses GDK's API to check the direction of keyboard layout, which has a problem with Hebrew language. The problem is fixed on GTK+ version 2.10.1 and 2.12.

In mozilla1.9 branch, we are going to implement all the interface, with XKB functions for xlib and gtk2 backends. On the gtk2 backend, we will have GTK+ version checking, to use GTK+ implementations, if the problem doesn't exist. Some other part of the code is going to be on GTK+ later, and we will use GTK+ API instead.

Both GTK+ and Mozilla versions, check keysym's on keyboard layout to detect the direction of the layout. For GTK+ (>=2.10.1, >=2.12.0) and all Mozilla versions, we check only the first shift-level of the layout, to fix the problem with Hebrew layouts.

More info: bug 348724, bug 348724, and Gnome bug: 116626

[edit] Mac

Only isLangRTL is supported on this platform. bug 266551

[edit] See Also