mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Add UI for changing direction of the document and input fields. Bug 85420, patch by Asaf Romano <bugs.mano@mail-central.com>, r=smontagu, sr=neil
This commit is contained in:
parent
4bb5627180
commit
5180cb29d8
@ -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";
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,11 @@
|
||||
<key id="key_paste"/>
|
||||
<key id="key_delete"/>
|
||||
<key id="key_selectAll"/>
|
||||
|
||||
<key id="key_SwitchTextDirection"
|
||||
key="&bidiSwitchTextDirectionItem.commandkey;"
|
||||
command="cmd_SwitchTextDirection"
|
||||
modifiers="accel,shift" />
|
||||
|
||||
<!-- View Menu -->
|
||||
<key id="key_reload" key="&reloadCmd.commandkey;" oncommand="BrowserReload();" modifiers="accel"/>
|
||||
<key key="&reloadCmd.commandkey;" oncommand="BrowserReloadSkipCache();" modifiers="accel,shift"/>
|
||||
@ -154,6 +158,7 @@
|
||||
<command id="cmd_paste"/>
|
||||
<command id="cmd_delete"/>
|
||||
<command id="cmd_selectAll" observes="isImage"/>
|
||||
<command id="cmd_SwitchTextDirection" oncommand="SwitchFocusedTextEntryDirection();" disabled="true" />
|
||||
|
||||
<!-- Content area context menu -->
|
||||
<command id="cmd_copyLink"/>
|
||||
@ -164,7 +169,8 @@
|
||||
<command id="View:PageSource" oncommand="BrowserViewSourceOfDocument(content.document);" observes="isImage"/>
|
||||
<command id="View:PageInfo" oncommand="BrowserPageInfo();"/>
|
||||
<command id="View:FullScreen" oncommand="BrowserFullScreen();"/>
|
||||
|
||||
<command id="cmd_SwitchDocumentDirection" oncommand="SwitchDocumentDirection(window.content);" />
|
||||
|
||||
<!-- Search Menu -->
|
||||
<command id="Browser:Find" oncommand="BrowserFind();" observes="isImage"/>
|
||||
<command id="Browser:FindAgain" oncommand="BrowserFindAgain(false);" observes="isImage"/>
|
||||
@ -374,6 +380,13 @@
|
||||
<menuitem id="menu_findTypeLinks"/>
|
||||
<menuitem id="menu_findTypeText"/>
|
||||
|
||||
<menuseparator hidden="true" id="textfieldDirection-separator"/>
|
||||
<menuitem hidden="true" id="textfieldDirection-swap"
|
||||
label="&bidiSwitchTextDirectionItem.label;"
|
||||
key="key_SwitchTextDirection"
|
||||
accesskey="&bidiSwitchTextDirectionItem.accesskey;"
|
||||
command="cmd_SwitchTextDirection"/>
|
||||
|
||||
<menuseparator id="menu_PrefsSeparator"/>
|
||||
<menuitem id="menu_preferences" oncommand="goPreferences('navigator', 'chrome://communicator/content/pref/pref-navigator.xul', 'navigator')"/>
|
||||
</menupopup>
|
||||
@ -409,6 +422,10 @@
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu id="charsetMenu" observes="isImage"/>
|
||||
<menuitem hidden="true" id="documentDirection-swap"
|
||||
label="&bidiSwitchPageDirectionItem.label;"
|
||||
accesskey="&bidiSwitchPageDirectionItem.accesskey;"
|
||||
command="cmd_SwitchDocumentDirection"/>
|
||||
<menuseparator />
|
||||
<menuitem accesskey="&pageSourceCmd.accesskey;" label="&pageSourceCmd.label;" key="key_viewSource" command="View:PageSource"/>
|
||||
<menuitem accesskey="&pageInfoCmd.accesskey;" label="&pageInfoCmd.label;" key="key_viewInfo" command="View:PageInfo"/>
|
||||
|
@ -198,3 +198,8 @@
|
||||
|
||||
<!ENTITY popupIcon.tooltiptext "Unblock this site's popups">
|
||||
|
||||
<!ENTITY bidiSwitchPageDirectionItem.label "Switch Page Direction">
|
||||
<!ENTITY bidiSwitchPageDirectionItem.accesskey "g">
|
||||
<!ENTITY bidiSwitchTextDirectionItem.label "Switch Text Direction">
|
||||
<!ENTITY bidiSwitchTextDirectionItem.accesskey "w">
|
||||
<!ENTITY bidiSwitchTextDirectionItem.commandkey "X">
|
||||
|
@ -244,6 +244,15 @@
|
||||
label="&metadataCmd.label;"
|
||||
accesskey="&metadataCmd.accesskey;"
|
||||
oncommand="gContextMenu.showMetadata();"/>
|
||||
<menuseparator hidden="true" id="context-sep-bidi"/>
|
||||
<menuitem hidden="true" id="context-bidi-text-direction-toggle"
|
||||
label="&bidiSwitchTextDirectionItem.label;"
|
||||
accesskey="&bidiSwitchTextDirectionItem.accesskey;"
|
||||
oncommand="SwitchTextEntryDirection(gContextMenu.target)"/>
|
||||
<menuitem hidden="true" id="context-bidi-page-direction-toggle"
|
||||
label="&bidiSwitchPageDirectionItem.label;"
|
||||
accesskey="&bidiSwitchPageDirectionItem.accesskey;"
|
||||
oncommand="SwitchDocumentDirection(window.content);"/>
|
||||
</popup>
|
||||
</popupset>
|
||||
</overlay>
|
||||
|
@ -843,3 +843,8 @@ function getCharsetforSave(aDocument)
|
||||
|
||||
return window.content.document.characterSet;
|
||||
}
|
||||
|
||||
function SwitchTextEntryDirection(aElement)
|
||||
{
|
||||
aElement.dir = (window.getComputedStyle(aElement, "").direction == "ltr" ? "rtl" : "ltr");
|
||||
}
|
||||
|
@ -48,6 +48,9 @@
|
||||
| Currently, this code is relatively useless for any other purpose. In the |
|
||||
| longer term, this code will be restructured to make it more reusable. |
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
var gShowBiDi = false;
|
||||
|
||||
function nsContextMenu( xulMenu ) {
|
||||
this.target = null;
|
||||
this.menu = null;
|
||||
@ -200,6 +203,11 @@ nsContextMenu.prototype = {
|
||||
this.showItem( "popupwindow-reject", this.popupURL && !blocking);
|
||||
this.showItem( "popupwindow-allow", this.popupURL && blocking);
|
||||
this.showItem( "context-sep-popup", this.popupURL);
|
||||
|
||||
// BiDi UI
|
||||
this.showItem( "context-sep-bidi", gShowBiDi);
|
||||
this.showItem( "context-bidi-text-direction-toggle", this.onTextInput && gShowBiDi);
|
||||
this.showItem( "context-bidi-page-direction-toggle", !this.onTextInput && gShowBiDi);
|
||||
},
|
||||
initClipboardItems : function () {
|
||||
|
||||
|
@ -382,6 +382,12 @@ function goUpdateGlobalEditMenuItems()
|
||||
goUpdateCommand('cmd_paste');
|
||||
goUpdateCommand('cmd_selectAll');
|
||||
goUpdateCommand('cmd_delete');
|
||||
try {
|
||||
// XXX: implement controller for cmd_SwitchTextDirection
|
||||
document.getElementById('cmd_SwitchTextDirection').setAttribute('disabled',
|
||||
!document.commandDispatcher.focusedElement);
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
// update menu items that rely on the current selection
|
||||
|
@ -87,3 +87,8 @@
|
||||
<!ENTITY thisFrameMenu.label "This Frame">
|
||||
<!ENTITY thisFrameMenu.accesskey "h">
|
||||
<!ENTITY search.accesskey "W">
|
||||
<!ENTITY bidiSwitchPageDirectionItem.label "Switch Page Direction">
|
||||
<!ENTITY bidiSwitchPageDirectionItem.accesskey "g">
|
||||
<!ENTITY bidiSwitchTextDirectionItem.label "Switch Text Direction">
|
||||
<!ENTITY bidiSwitchTextDirectionItem.accesskey "w">
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user