1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:expandtab:shiftwidth=4:tabstop=4: 3 */ 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #include "prlink.h" 9 10 #include "nsBidiKeyboard.h" 11 #include "nsIWidget.h" 12 #include <gtk/gtk.h> 13 NS_IMPL_ISUPPORTS(nsBidiKeyboard,nsIBidiKeyboard)14NS_IMPL_ISUPPORTS(nsBidiKeyboard, nsIBidiKeyboard) 15 16 nsBidiKeyboard::nsBidiKeyboard() { Reset(); } 17 18 NS_IMETHODIMP Reset()19nsBidiKeyboard::Reset() { 20 // NB: The default keymap can be null (e.g. in xpcshell). In that case, 21 // simply assume that we don't have bidi keyboards. 22 mHaveBidiKeyboards = false; 23 24 GdkDisplay* display = gdk_display_get_default(); 25 if (!display) return NS_OK; 26 27 GdkKeymap* keymap = gdk_keymap_get_for_display(display); 28 mHaveBidiKeyboards = keymap && gdk_keymap_have_bidi_layouts(keymap); 29 return NS_OK; 30 } 31 32 nsBidiKeyboard::~nsBidiKeyboard() = default; 33 34 NS_IMETHODIMP IsLangRTL(bool * aIsRTL)35nsBidiKeyboard::IsLangRTL(bool* aIsRTL) { 36 if (!mHaveBidiKeyboards) return NS_ERROR_FAILURE; 37 38 *aIsRTL = (gdk_keymap_get_direction(gdk_keymap_get_default()) == 39 PANGO_DIRECTION_RTL); 40 41 return NS_OK; 42 } 43 GetHaveBidiKeyboards(bool * aResult)44NS_IMETHODIMP nsBidiKeyboard::GetHaveBidiKeyboards(bool* aResult) { 45 // not implemented yet 46 return NS_ERROR_NOT_IMPLEMENTED; 47 } 48 49 // static CreateBidiKeyboardInner()50already_AddRefed<nsIBidiKeyboard> nsIWidget::CreateBidiKeyboardInner() { 51 return do_AddRef(new nsBidiKeyboard()); 52 } 53