Fix the charset menu.

This resolves #34.
This commit is contained in:
wolfbeast
2016-07-26 21:11:47 +02:00
committed by roytam1
parent cb658cf308
commit 75ccd22bfb
6 changed files with 206 additions and 131 deletions
+37 -120
View File
@@ -9,137 +9,54 @@
#ifndef OMIT_ACCESSKEYS
accesskey="&charsetMenu.accesskey;"
#endif
datasources="rdf:charset-menu"
ref="NC:BrowserCharsetMenuRoot"
oncommand="MultiplexHandler(event)"
onpopupshowing="CreateMenu('browser'); CreateMenu('more-menu');"
onpopupshown="UpdateMenus(event);"
observes="isImage">
<template>
<rule rdf:type="http://home.netscape.com/NC-rdf#BookmarkSeparator">
<menupopup>
<menuseparator uri="..." />
</menupopup>
</rule>
<rule>
<menupopup>
<menuitem type="radio" name="charsetGroup" checked="rdf:http://home.netscape.com/NC-rdf#Checked" uri="..." label="rdf:http://home.netscape.com/NC-rdf#Name"/>
</menupopup>
</rule>
</template>
#ifdef OMIT_ACCESSKEYS
#expand onpopupshowing="CharsetMenu.build(event, '__ID_PREFIX__');"
#else
#expand onpopupshowing="CharsetMenu.build(event, '__ID_PREFIX__', true);"
#endif
onpopupshown="UpdateMenus(event);">
<menupopup>
<menu label="&charsetMenuAutodet.label;"
<menu label="&charsetMenuAutodet.label;"
#ifndef OMIT_ACCESSKEYS
accesskey="&charsetMenuAutodet.accesskey;"
accesskey="&charsetMenuAutodet.accesskey;"
#endif
datasources="rdf:charset-menu" ref="NC:BrowserAutodetMenuRoot">
<template>
<rule rdf:type="http://home.netscape.com/NC-rdf#CharsetDetector">
<menupopup>
<menuitem type="radio" name="detectorGroup" checked="rdf:http://home.netscape.com/NC-rdf#Checked" uri="..." label="rdf:http://home.netscape.com/NC-rdf#Name"/>
</menupopup>
</rule>
</template>
<menupopup>
</menupopup>
</menu>
<menu label="&charsetMenuMore.label;"
>
<menupopup>
<menuitem type="radio"
name="detectorGroup"
#expand id="__ID_PREFIX__chardet.off"
label="&charsetMenuAutodet.off.label;"
#ifndef OMIT_ACCESSKEYS
accesskey="&charsetMenuMore.accesskey;"
accesskey="&charsetMenuAutodet.off.accesskey;"
#endif
datasources="rdf:charset-menu" ref="NC:BrowserMoreCharsetMenuRoot">
<template>
<rule>
<menupopup>
<menuitem uri="..." label="rdf:http://home.netscape.com/NC-rdf#Name"/>
</menupopup>
</rule>
</template>
<menupopup>
<menu label="&charsetMenuMore1.label;"
/>
<menuitem type="radio"
name="detectorGroup"
#expand id="__ID_PREFIX__chardet.ja_parallel_state_machine"
label="&charsetMenuAutodet.ja.label;"
#ifndef OMIT_ACCESSKEYS
accesskey="&charsetMenuMore1.accesskey;"
accesskey="&charsetMenuAutodet.ja.accesskey;"
#endif
datasources="rdf:charset-menu" ref="NC:BrowserMore1CharsetMenuRoot">
<template>
<rule>
<menupopup>
<menuitem uri="..." label="rdf:http://home.netscape.com/NC-rdf#Name"/>
</menupopup>
</rule>
</template>
<menupopup>
</menupopup>
</menu>
<menu label="&charsetMenuMore2.label;"
/>
<menuitem type="radio"
name="detectorGroup"
#expand id="__ID_PREFIX__chardet.ruprob"
label="&charsetMenuAutodet.ru.label;"
#ifndef OMIT_ACCESSKEYS
accesskey="&charsetMenuMore2.accesskey;"
accesskey="&charsetMenuAutodet.ru.accesskey;"
#endif
datasources="rdf:charset-menu" ref="NC:BrowserMore2CharsetMenuRoot">
<template>
<rule>
<menupopup>
<menuitem uri="..." label="rdf:http://home.netscape.com/NC-rdf#Name"/>
</menupopup>
</rule>
</template>
<menupopup>
</menupopup>
</menu>
<menu label="&charsetMenuMore3.label;"
/>
<menuitem type="radio"
name="detectorGroup"
#expand id="__ID_PREFIX__chardet.ukprob"
label="&charsetMenuAutodet.uk.label;"
#ifndef OMIT_ACCESSKEYS
accesskey="&charsetMenuMore3.accesskey;"
accesskey="&charsetMenuAutodet.uk.accesskey;"
#endif
datasources="rdf:charset-menu" ref="NC:BrowserMore3CharsetMenuRoot">
<template>
<rule>
<menupopup>
<menuitem uri="..." label="rdf:http://home.netscape.com/NC-rdf#Name"/>
</menupopup>
</rule>
</template>
<menupopup>
</menupopup>
</menu>
<menu label="&charsetMenuMore4.label;"
#ifndef OMIT_ACCESSKEYS
accesskey="&charsetMenuMore4.accesskey;"
#endif
datasources="rdf:charset-menu" ref="NC:BrowserMore4CharsetMenuRoot">
<template>
<rule>
<menupopup>
<menuitem uri="..." label="rdf:http://home.netscape.com/NC-rdf#Name"/>
</menupopup>
</rule>
</template>
<menupopup>
</menupopup>
</menu>
<menu label="&charsetMenuMore5.label;"
#ifndef OMIT_ACCESSKEYS
accesskey="&charsetMenuMore5.accesskey;"
#endif
datasources="rdf:charset-menu" ref="NC:BrowserMore5CharsetMenuRoot">
<template>
<rule>
<menupopup>
<menuitem uri="..." label="rdf:http://home.netscape.com/NC-rdf#Name"/>
</menupopup>
</rule>
</template>
<menupopup>
</menupopup>
</menu>
<menuseparator />
</menupopup>
</menu>
<menuitem name="charsetCustomize"
#ifndef OMIT_ACCESSKEYS
accesskey="&charsetCustomize.accesskey;"
#endif
label="&charsetCustomize.label;"
oncommand="window.openDialog('chrome://global/content/customizeCharset.xul', 'PrefWindow', 'chrome,modal=yes,resizable=yes', 'browser');"/>
/>
</menupopup>
</menu>
<menuseparator/>
</menupopup>
</menu>
+1 -1
View File
@@ -7,7 +7,7 @@
%palemoonDTD;
<!ENTITY % baseMenuDTD SYSTEM "chrome://browser/locale/baseMenuOverlay.dtd" >
%baseMenuDTD;
<!ENTITY % charsetDTD SYSTEM "chrome://browser/locale/charsetOverlay.dtd" >
<!ENTITY % charsetDTD SYSTEM "chrome://browser/locale/charsetMenu.dtd" >
%charsetDTD;
<!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" >
%textcontextDTD;
+5 -10
View File
@@ -9,9 +9,11 @@ let Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource:///modules/RecentWindow.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "CharsetMenu",
"resource:///modules/CharsetMenu.jsm");
const nsIWebNavigation = Ci.nsIWebNavigation;
var gCharsetMenu = null;
var gLastBrowserCharset = null;
var gPrevCharset = null;
var gProxyFavIcon = null;
@@ -5175,7 +5177,7 @@ function MultiplexHandler(event)
SelectDetector(event, false);
} else if (name == 'charsetGroup') {
var charset = node.getAttribute('id');
charset = charset.substring('charset.'.length, charset.length)
charset = charset.substring(charset.indexOf('charset.') + 'charset.'.length);
BrowserSetForcedCharacterSet(charset);
} else if (name == 'charsetCustomize') {
//do nothing - please remove this else statement, once the charset prefs moves to the pref window
@@ -5188,7 +5190,7 @@ function MultiplexHandler(event)
function SelectDetector(event, doReload)
{
var uri = event.target.getAttribute("id");
var prefvalue = uri.substring('chardet.'.length, uri.length);
var prefvalue = uri.substring(uri.indexOf('chardet.') + 'chardet.'.length);
if ("off" == prefvalue) { // "off" is special value to turn off the detectors
prefvalue = "";
}
@@ -5264,17 +5266,10 @@ function UpdateMenus(event) {
UpdateCharsetDetector(event.target);
}
function CreateMenu(node) {
Services.obs.notifyObservers(null, "charsetmenu-selected", node);
}
function charsetLoadListener() {
var charset = window.content.document.characterSet;
if (charset.length > 0 && (charset != gLastBrowserCharset)) {
if (!gCharsetMenu)
gCharsetMenu = Cc['@mozilla.org/rdf/datasource;1?name=charset-menu'].getService(Ci.nsICurrentCharsetListener);
gCharsetMenu.SetCurrentCharset(charset);
gPrevCharset = gLastBrowserCharset;
gLastBrowserCharset = charset;
}
+2
View File
@@ -21,6 +21,8 @@
locale/browser/baseMenuOverlay.dtd (%chrome/browser/baseMenuOverlay.dtd)
locale/browser/charsetOverlay.dtd (%chrome/browser/charsetOverlay.dtd)
locale/browser/browser.properties (%chrome/browser/browser.properties)
locale/browser/charsetMenu.properties (%chrome/browser/charsetMenu.properties)
locale/browser/charsetMenu.dtd (%chrome/browser/charsetMenu.dtd)
locale/browser/devtools/appcacheutils.properties (%chrome/browser/devtools/appcacheutils.properties)
locale/browser/devtools/debugger.dtd (%chrome/browser/devtools/debugger.dtd)
locale/browser/devtools/debugger.properties (%chrome/browser/devtools/debugger.properties)
+160
View File
@@ -0,0 +1,160 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
this.EXPORTED_SYMBOLS = [ "CharsetMenu" ];
const { classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyGetter(this, "gBundle", function() {
const kUrl = "chrome://browser/locale/charsetMenu.properties";
return Services.strings.createBundle(kUrl);
});
/**
* This set contains encodings that are in the Encoding Standard, except:
* - XSS-dangerous encodings (except ISO-2022-JP which is assumed to be
* too common not to be included).
* - x-user-defined, which practically never makes sense as an end-user-chosen
* override.
* - Encodings that IE11 doesn't have in its correspoding menu.
*/
const kEncodings = new Set([
// Globally relevant
"UTF-8",
"windows-1252",
// Arabic
"windows-1256",
"ISO-8859-6",
// Baltic
"windows-1257",
"ISO-8859-4",
// "ISO-8859-13", // Hidden since not in menu in IE11
// Central European
"windows-1250",
"ISO-8859-2",
// Chinese, Simplified
"gbk",
"gb18030",
// Chinese, Traditional
"Big5",
// Cyrillic
"windows-1251",
"ISO-8859-5",
"KOI8-R",
"KOI8-U",
"IBM866", // Not in menu in Chromium. Maybe drop this?
// "x-mac-cyrillic", // Not in menu in IE11 or Chromium.
// Greek
"windows-1253",
"ISO-8859-7",
// Hebrew
"windows-1255",
"ISO-8859-8-I",
"ISO-8859-8",
// Japanese
"Shift_JIS",
"EUC-JP",
"ISO-2022-JP",
// Korean
"EUC-KR",
// Thai
"windows-874",
// Turkish
"windows-1254",
// Vietnamese
"windows-1258",
// Hiding rare European encodings that aren't in the menu in IE11 and would
// make the menu messy by sorting all over the place
// "ISO-8859-3",
// "ISO-8859-10",
// "ISO-8859-14",
// "ISO-8859-15",
// "ISO-8859-16",
// "macintosh"
]);
// Always at the start of the menu, in this order, followed by a separator.
const kPinned = [
"UTF-8",
"windows-1252"
];
this.CharsetMenu = Object.freeze({
build: function BuildCharsetMenu(event) {
let parent = event.target;
if (parent.lastChild.localName != "menuseparator") {
// Detector menu or charset menu already built
return;
}
let doc = parent.ownerDocument;
function createItem(encoding) {
let menuItem = doc.createElement("menuitem");
menuItem.setAttribute("type", "radio");
menuItem.setAttribute("name", "charsetGroup");
try {
menuItem.setAttribute("label", gBundle.GetStringFromName(encoding));
} catch (e) {
// Localization error but put *something* in the menu to recover.
menuItem.setAttribute("label", encoding);
}
try {
menuItem.setAttribute("accesskey",
gBundle.GetStringFromName(encoding + ".key"));
} catch (e) {
// Some items intentionally don't have an accesskey
}
menuItem.setAttribute("id", "charset." + encoding);
return menuItem;
}
// Clone the set in order to be able to remove the pinned encodings from
// the cloned set.
let encodings = new Set(kEncodings);
for (let encoding of kPinned) {
encodings.delete(encoding);
parent.appendChild(createItem(encoding));
}
parent.appendChild(doc.createElement("menuseparator"));
let list = [];
for (let encoding of encodings) {
list.push(createItem(encoding));
}
list.sort(function (a, b) {
let titleA = a.getAttribute("label");
let titleB = b.getAttribute("label");
// Normal sorting sorts the part in parenthesis in an order that
// happens to make the less frequently-used items first.
let index;
if ((index = titleA.indexOf("(")) > -1) {
titleA = titleA.substring(0, index);
}
if ((index = titleB.indexOf("(")) > -1) {
titleA = titleB.substring(0, index);
}
let comp = titleA.localeCompare(titleB);
if (comp) {
return comp;
}
// secondarily reverse sort by encoding name to sort "windows" or
// "shift_jis" first. This works regardless of localization, because
// the ids aren't localized.
let idA = a.getAttribute("id");
let idB = b.getAttribute("id");
if (idA < idB) {
return 1;
}
if (idB < idA) {
return -1;
}
return 0;
});
for (let item of list) {
parent.appendChild(item);
}
},
});
+1
View File
@@ -10,6 +10,7 @@ EXTRA_JS_MODULES += [ 'promise.js' ]
EXTRA_JS_MODULES += [
'BrowserNewTabPreloader.jsm',
'CharsetMenu.jsm',
'FormSubmitObserver.jsm',
'FormValidationHandler.jsm',
'NetworkPrioritizer.jsm',