From a1f1e1d1e581f69ea28914578c592f6e5cacc998 Mon Sep 17 00:00:00 2001 From: "smontagu%smontagu.org" Date: Sun, 28 Nov 2004 18:36:23 +0000 Subject: [PATCH] Mac implementation of nsIBidiKeyboard. Bug 266551, patch by Asaf Romano , r=jhpedemonte, sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@165854 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/mac/nsBidiKeyboard.cpp | 50 ++++++++++++++++++++++- mozilla/widget/src/mac/nsBidiKeyboard.h | 10 ++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/mozilla/widget/src/mac/nsBidiKeyboard.cpp b/mozilla/widget/src/mac/nsBidiKeyboard.cpp index 8a3e478dcd1..8306a5e5317 100644 --- a/mozilla/widget/src/mac/nsBidiKeyboard.cpp +++ b/mozilla/widget/src/mac/nsBidiKeyboard.cpp @@ -22,6 +22,7 @@ * * Contributor(s): * Simon Montagu + * Asaf Romano * * 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; } NS_IMETHODIMP nsBidiKeyboard::SetLangFromBidiLevel(PRUint8 aLevel) @@ -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); +} diff --git a/mozilla/widget/src/mac/nsBidiKeyboard.h b/mozilla/widget/src/mac/nsBidiKeyboard.h index 3011affdd16..970109118a3 100644 --- a/mozilla/widget/src/mac/nsBidiKeyboard.h +++ b/mozilla/widget/src/mac/nsBidiKeyboard.h @@ -22,6 +22,7 @@ * * Contributor(s): * Simon Montagu + * Asaf Romano * * 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 + +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); };