From 5180cb29d89b85d7bf48d5fd4cb94fd26e83bb58 Mon Sep 17 00:00:00 2001 From: "smontagu%smontagu.org" Date: Sun, 17 Oct 2004 17:10:06 +0000 Subject: [PATCH] Add UI for changing direction of the document and input fields. Bug 85420, patch by Asaf Romano , r=smontagu, sr=neil --- xpfe/browser/resources/content/navigator.js | 52 +++++++++++++++++++ .../resources/content/navigatorOverlay.xul | 21 +++++++- .../resources/locale/en-US/navigator.dtd | 5 ++ .../content/contentAreaContextOverlay.xul | 9 ++++ .../resources/content/contentAreaUtils.js | 5 ++ .../resources/content/nsContextMenu.js | 8 +++ .../resources/content/utilityOverlay.js | 6 +++ .../locale/en-US/contentAreaCommands.dtd | 5 ++ 8 files changed, 109 insertions(+), 2 deletions(-) diff --git a/xpfe/browser/resources/content/navigator.js b/xpfe/browser/resources/content/navigator.js index 93467ed92ca8..cf0d67a21b7b 100644 --- a/xpfe/browser/resources/content/navigator.js +++ b/xpfe/browser/resources/content/navigator.js @@ -660,6 +660,14 @@ function Startup() gClickSelectsAll = pref.getBoolPref("browser.urlbar.clickSelectsAll"); gClickAtEndSelects = pref.getBoolPref("browser.urlbar.clickAtEndSelects"); + // BiDi UI + gShowBiDi = isBidiEnabled(); + if (gShowBiDi) { + document.getElementById("documentDirection-swap").hidden = false; + document.getElementById("textfieldDirection-separator").hidden = false; + document.getElementById("textfieldDirection-swap").hidden = false; + } + // now load bookmarks after a delay setTimeout(LoadBookmarksCallback, 0); } @@ -2507,3 +2515,47 @@ function updateFileUploadItem() else item.setAttribute('disabled', 'true'); } + +function isBidiEnabled() +{ + var rv = false; + + var systemLocale; + try { + var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"] + .getService(Components.interfaces.nsILocaleService); + systemLocale = localeService.getSystemLocale().getCategory("NSILOCALE_CTYPE"); + rv = /^(he|ar|syr|fa|ur)-/.test(systemLocale); + } catch (e) {} + + if (!rv) { + // check the overriding pref + try { + rv = pref.getBoolPref("bidi.browser.ui"); + } + catch (e) {} + } + + return rv; +} + +function SwitchDocumentDirection(aWindow) +{ + aWindow.document.dir = (aWindow.document.dir == "ltr" ? "rtl" : "ltr"); + + for (var run = 0; run < aWindow.frames.length; run++) + SwitchDocumentDirection(aWindow.frames[run]); +} + +function SwitchFocusedTextEntryDirection() +{ + // The keybinding shoudn't work if the menu item is hidden + if (gShowBiDi) { + var focusedElement = document.commandDispatcher.focusedElement; + if (focusedElement) + if (window.getComputedStyle(focusedElement, "").direction == "ltr") + focusedElement.style.direction = "rtl"; + else + focusedElement.style.direction = "ltr"; + } +} diff --git a/xpfe/browser/resources/content/navigatorOverlay.xul b/xpfe/browser/resources/content/navigatorOverlay.xul index c53be6afab6d..e56fbeafb8c7 100644 --- a/xpfe/browser/resources/content/navigatorOverlay.xul +++ b/xpfe/browser/resources/content/navigatorOverlay.xul @@ -86,7 +86,11 @@ - + + @@ -154,6 +158,7 @@ + @@ -164,7 +169,8 @@ - + + @@ -374,6 +380,13 @@ +