Mac implementation of nsIBidiKeyboard. Bug 266551, patch by Asaf Romano <mozilla.mano@sent.com>, r=jhpedemonte, sr=bzbarsky
git-svn-id: svn://10.0.0.236/trunk@165854 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Simon Montagu
|
||||
* Asaf Romano <mozilla.mano@sent.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -52,8 +53,44 @@ nsBidiKeyboard::~nsBidiKeyboard()
|
||||
NS_IMETHODIMP nsBidiKeyboard::IsLangRTL(PRBool *aIsRTL)
|
||||
{
|
||||
*aIsRTL = PR_FALSE;
|
||||
// XXX Insert platform specific code to determine keyboard direction
|
||||
return NS_OK;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// KLGetCurrentKeyboardLayout and KLGetKeyboardLayoutProperty are only available on OS 10.2 and later.
|
||||
static PRBool checked = PR_FALSE;
|
||||
static fpKLGetCurrentKeyboardLayout_type fpKLGetCurrentKeyboardLayout = NULL;
|
||||
static fpKLGetKeyboardLayoutProperty_type fpKLGetKeyboardLayoutProperty = NULL;
|
||||
|
||||
if (!checked) {
|
||||
CFBundleRef bundle =
|
||||
::CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Carbon"));
|
||||
if (bundle) {
|
||||
fpKLGetCurrentKeyboardLayout =
|
||||
::CFBundleGetFunctionPointerForName(bundle, CFSTR("KLGetCurrentKeyboardLayout"));
|
||||
fpKLGetKeyboardLayoutProperty =
|
||||
::CFBundleGetFunctionPointerForName(bundle, CFSTR("KLGetKeyboardLayoutProperty"));
|
||||
}
|
||||
|
||||
checked = PR_TRUE;
|
||||
}
|
||||
|
||||
if (fpKLGetCurrentKeyboardLayout) {
|
||||
OSStatus err;
|
||||
KeyboardLayoutRef currentKeyboard;
|
||||
const void* currentKeyboardResID;
|
||||
|
||||
err = fpKLGetCurrentKeyboardLayout(¤tKeyboard);
|
||||
if (err == noErr)
|
||||
{
|
||||
err = fpKLGetKeyboardLayoutProperty(currentKeyboard,
|
||||
kKLIdentifier, ¤tKeyboardResID);
|
||||
if (err == noErr)
|
||||
{
|
||||
rv = NS_OK;
|
||||
*aIsRTL = IsRTLLanguage((SInt32)currentKeyboardResID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -61,3 +98,12 @@ NS_IMETHODIMP nsBidiKeyboard::SetLangFromBidiLevel(PRUint8 aLevel)
|
||||
{
|
||||
// XXX Insert platform specific code to set keyboard language
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool nsBidiKeyboard::IsRTLLanguage(SInt32 aKeyboardResID)
|
||||
{
|
||||
// Check if the resource id is BiDi associated (Arabic, Persian, Hebrew)
|
||||
// (Persian is included in the Arabic range)
|
||||
// http://developer.apple.com/documentation/mac/Text/Text-534.html#HEADING534-0
|
||||
// Note: these ^^ values are negative on Mac OS X
|
||||
return (aKeyboardResID >= -18943 && aKeyboardResID <= -17920);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Simon Montagu
|
||||
* Asaf Romano <mozilla.mano@sent.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -40,6 +41,11 @@
|
||||
#ifndef __nsBidiKeyboard
|
||||
#define __nsBidiKeyboard
|
||||
#include "nsIBidiKeyboard.h"
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
typedef OSStatus (*fpKLGetCurrentKeyboardLayout_type) (KeyboardLayoutRef*);
|
||||
typedef OSStatus (*fpKLGetKeyboardLayoutProperty_type)
|
||||
(KeyboardLayoutRef, KeyboardLayoutPropertyTag, void**);
|
||||
|
||||
class nsBidiKeyboard : public nsIBidiKeyboard
|
||||
{
|
||||
@@ -49,7 +55,9 @@ public:
|
||||
|
||||
nsBidiKeyboard();
|
||||
virtual ~nsBidiKeyboard();
|
||||
/* additional members */
|
||||
|
||||
protected:
|
||||
PRBool IsRTLLanguage(SInt32 aKeyboardResID);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user