зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 3 changesets (bug 1200533) for test failures in reftests/338427-2.html
Backed out changeset 9f3ca77e2d7b (bug 1200533) Backed out changeset b3ad852a044a (bug 1200533) Backed out changeset 74e6798a38a4 (bug 1200533)
This commit is contained in:
Родитель
39b2543e9a
Коммит
a1008eb382
|
@ -590,8 +590,7 @@ nsEditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary)
|
||||||
|
|
||||||
// The purpose of mUpdateDictionaryRunning is to avoid doing all of this if
|
// The purpose of mUpdateDictionaryRunning is to avoid doing all of this if
|
||||||
// UpdateCurrentDictionary's helper method DictionaryFetched, which calls us,
|
// UpdateCurrentDictionary's helper method DictionaryFetched, which calls us,
|
||||||
// is on the stack. In other words: Only do this, if the user manually selected a
|
// is on the stack.
|
||||||
// dictionary to use.
|
|
||||||
if (!mUpdateDictionaryRunning) {
|
if (!mUpdateDictionaryRunning) {
|
||||||
|
|
||||||
// Ignore pending dictionary fetchers by increasing this number.
|
// Ignore pending dictionary fetchers by increasing this number.
|
||||||
|
@ -600,36 +599,23 @@ nsEditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary)
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
mEditor->GetFlags(&flags);
|
mEditor->GetFlags(&flags);
|
||||||
if (!(flags & nsIPlaintextEditor::eEditorMailMask)) {
|
if (!(flags & nsIPlaintextEditor::eEditorMailMask)) {
|
||||||
if (mPreferredLang.IsEmpty() ||
|
if (mPreferredLang.IsEmpty() || !mPreferredLang.Equals(aDictionary)) {
|
||||||
!mPreferredLang.Equals(aDictionary, nsCaseInsensitiveStringComparator())) {
|
|
||||||
// When user sets dictionary manually, we store this value associated
|
// When user sets dictionary manually, we store this value associated
|
||||||
// with editor url, if it doesn't match the document language exactly.
|
// with editor url, if it doesn't match the document language exactly.
|
||||||
// For example on "en" sites, we need to store "en-GB", otherwise
|
// For example on "en" sites, we need to store "en-GB", otherwise
|
||||||
// the language might jump back to en-US although the user explicitly
|
// the language might jump back to en-US although the user explicitly
|
||||||
// chose otherwise.
|
// chose otherwise.
|
||||||
StoreCurrentDictionary(mEditor, aDictionary);
|
StoreCurrentDictionary(mEditor, aDictionary);
|
||||||
#ifdef DEBUG_DICT
|
|
||||||
printf("***** Writing content preferences for |%s|\n",
|
|
||||||
NS_ConvertUTF16toUTF8(aDictionary).get());
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
// If user sets a dictionary matching the language defined by
|
// If user sets a dictionary matching the language defined by
|
||||||
// document, we consider content pref has been canceled, and we clear it.
|
// document, we consider content pref has been canceled, and we clear it.
|
||||||
ClearCurrentDictionary(mEditor);
|
ClearCurrentDictionary(mEditor);
|
||||||
#ifdef DEBUG_DICT
|
|
||||||
printf("***** Clearing content preferences for |%s|\n",
|
|
||||||
NS_ConvertUTF16toUTF8(aDictionary).get());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also store it in as a preference, so we can use it as a fallback.
|
// Also store it in as a preference. It will be used as a default value
|
||||||
// We don't want this for mail composer because it uses
|
// when everything else fails but we don't want this for mail composer
|
||||||
// "spellchecker.dictionary" as a preference.
|
// because it has spellchecked dictionary settings in Preferences.
|
||||||
Preferences::SetString("spellchecker.dictionary", aDictionary);
|
Preferences::SetString("spellchecker.dictionary", aDictionary);
|
||||||
#ifdef DEBUG_DICT
|
|
||||||
printf("***** Storing spellchecker.dictionary |%s|\n",
|
|
||||||
NS_ConvertUTF16toUTF8(aDictionary).get());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mSpellChecker->SetCurrentDictionary(aDictionary);
|
return mSpellChecker->SetCurrentDictionary(aDictionary);
|
||||||
|
@ -737,44 +723,6 @@ nsEditorSpellCheck::UpdateCurrentDictionary(nsIEditorSpellCheckCallback* aCallba
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function that iterates over the list of dictionaries and sets the one
|
|
||||||
// that matches based on a given comparison type.
|
|
||||||
nsresult
|
|
||||||
nsEditorSpellCheck::TryDictionary(nsAutoString aDictName,
|
|
||||||
nsTArray<nsString>& aDictList,
|
|
||||||
enum dictCompare aCompareType)
|
|
||||||
{
|
|
||||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < aDictList.Length(); i++) {
|
|
||||||
nsAutoString dictStr(aDictList.ElementAt(i));
|
|
||||||
bool equals = false;
|
|
||||||
switch (aCompareType) {
|
|
||||||
case DICT_NORMAL_COMPARE:
|
|
||||||
equals = aDictName.Equals(dictStr);
|
|
||||||
break;
|
|
||||||
case DICT_COMPARE_CASE_INSENSITIVE:
|
|
||||||
equals = aDictName.Equals(dictStr, nsCaseInsensitiveStringComparator());
|
|
||||||
break;
|
|
||||||
case DICT_COMPARE_DASHMATCH:
|
|
||||||
equals = nsStyleUtil::DashMatchCompare(dictStr, aDictName, nsCaseInsensitiveStringComparator());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (equals) {
|
|
||||||
rv = SetCurrentDictionary(dictStr);
|
|
||||||
#ifdef DEBUG_DICT
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
printf("***** Set |%s|.\n", NS_ConvertUTF16toUTF8(dictStr).get());
|
|
||||||
#endif
|
|
||||||
// We always break here. We tried to set the dictionary to an existing
|
|
||||||
// dictionary from the list. This must work, if it doesn't, there is
|
|
||||||
// no point trying another one.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
|
nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
|
||||||
{
|
{
|
||||||
|
@ -792,47 +740,8 @@ nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* We try to derive the dictionary to use based on the following priorities:
|
|
||||||
* 1) Content preference, so the language the user set for the site before.
|
|
||||||
* (Introduced in bug 678842 and corrected in bug 717433.)
|
|
||||||
* 2) Language set by the website, or any other dictionary that partly
|
|
||||||
* matches that. (Introduced in bug 338427.)
|
|
||||||
* Eg. if the website is "en-GB", a user who only has "en-US" will get
|
|
||||||
* that. If the website is generic "en", the user will get one of the
|
|
||||||
* "en-*" installed, (almost) at random.
|
|
||||||
* However, we prefer what is stored in "spellchecker.dictionary",
|
|
||||||
* so if the user chose "en-AU" before, they will get "en-AU" on a plain
|
|
||||||
* "en" site. (Introduced in bug 682564.)
|
|
||||||
* 3) The value of "spellchecker.dictionary" which reflects a previous
|
|
||||||
* language choice of the user (on another site).
|
|
||||||
* (This was the original behaviour before the aforementioned bugs
|
|
||||||
* landed).
|
|
||||||
* 4) The user's locale.
|
|
||||||
* 5) Use the current dictionary that is currently set.
|
|
||||||
* 6) The content of the "LANG" environment variable (if set).
|
|
||||||
* 7) The first spell check dictionary installed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Get the language from the element or its closest parent according to:
|
|
||||||
// https://html.spec.whatwg.org/#attr-lang
|
|
||||||
// This is used in SetCurrentDictionary.
|
|
||||||
mPreferredLang.Assign(aFetcher->mRootContentLang);
|
mPreferredLang.Assign(aFetcher->mRootContentLang);
|
||||||
#ifdef DEBUG_DICT
|
|
||||||
printf("***** mPreferredLang (element) |%s|\n",
|
|
||||||
NS_ConvertUTF16toUTF8(mPreferredLang).get());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// If no luck, try the "Content-Language" header.
|
|
||||||
if (mPreferredLang.IsEmpty()) {
|
|
||||||
mPreferredLang.Assign(aFetcher->mRootDocContentLang);
|
|
||||||
#ifdef DEBUG_DICT
|
|
||||||
printf("***** mPreferredLang (content-language) |%s|\n",
|
|
||||||
NS_ConvertUTF16toUTF8(mPreferredLang).get());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Priority 1:
|
|
||||||
// If we successfully fetched a dictionary from content prefs, do not go
|
// If we successfully fetched a dictionary from content prefs, do not go
|
||||||
// further. Use this exact dictionary.
|
// further. Use this exact dictionary.
|
||||||
// Don't use content preferences for editor with eEditorMailMask flag.
|
// Don't use content preferences for editor with eEditorMailMask flag.
|
||||||
|
@ -842,60 +751,51 @@ nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
|
||||||
if (!(flags & nsIPlaintextEditor::eEditorMailMask)) {
|
if (!(flags & nsIPlaintextEditor::eEditorMailMask)) {
|
||||||
dictName.Assign(aFetcher->mDictionary);
|
dictName.Assign(aFetcher->mDictionary);
|
||||||
if (!dictName.IsEmpty()) {
|
if (!dictName.IsEmpty()) {
|
||||||
if (NS_SUCCEEDED(SetCurrentDictionary(dictName))) {
|
if (NS_FAILED(SetCurrentDictionary(dictName))) {
|
||||||
#ifdef DEBUG_DICT
|
// May be dictionary was uninstalled ?
|
||||||
printf("***** Assigned from content preferences |%s|\n",
|
ClearCurrentDictionary(mEditor);
|
||||||
NS_ConvertUTF16toUTF8(dictName).get());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// We take an early exit here, so let's not forget to clear the word
|
|
||||||
// list.
|
|
||||||
DeleteSuggestedWordList();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
// May be dictionary was uninstalled ?
|
return NS_OK;
|
||||||
// Clear the content preference and continue.
|
|
||||||
ClearCurrentDictionary(mEditor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 2:
|
if (mPreferredLang.IsEmpty()) {
|
||||||
// After checking the content preferences, we use the language of the element
|
mPreferredLang.Assign(aFetcher->mRootDocContentLang);
|
||||||
// or document.
|
}
|
||||||
dictName.Assign(mPreferredLang);
|
|
||||||
#ifdef DEBUG_DICT
|
|
||||||
printf("***** Assigned from element/doc |%s|\n",
|
|
||||||
NS_ConvertUTF16toUTF8(dictName).get());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Auxiliary status.
|
// Then, try to use language computed from element
|
||||||
nsresult rv2;
|
if (!mPreferredLang.IsEmpty()) {
|
||||||
|
dictName.Assign(mPreferredLang);
|
||||||
|
}
|
||||||
|
|
||||||
// We obtain a list of available dictionaries.
|
// otherwise, get language from preferences
|
||||||
nsTArray<nsString> dictList;
|
nsAutoString preferedDict(Preferences::GetLocalizedString("spellchecker.dictionary"));
|
||||||
rv2 = mSpellChecker->GetDictionaryList(&dictList);
|
if (dictName.IsEmpty()) {
|
||||||
NS_ENSURE_SUCCESS(rv2, rv2);
|
dictName.Assign(preferedDict);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the preference value.
|
nsresult rv = NS_OK;
|
||||||
nsAutoString preferredDict;
|
if (dictName.IsEmpty()) {
|
||||||
preferredDict = Preferences::GetLocalizedString("spellchecker.dictionary");
|
// Prefs didn't give us a dictionary name, so just get the current
|
||||||
|
// locale and use that as the default dictionary name!
|
||||||
|
|
||||||
// The following will be driven by this status. Once we were able to set a
|
nsCOMPtr<nsIXULChromeRegistry> packageRegistry =
|
||||||
// dictionary successfully, we're done. So we start with a "failed" status.
|
mozilla::services::GetXULChromeRegistryService();
|
||||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
|
||||||
|
|
||||||
if (!dictName.IsEmpty()) {
|
if (packageRegistry) {
|
||||||
// RFC 5646 explicitly states that matches should be case-insensitive.
|
nsAutoCString utf8DictName;
|
||||||
rv = TryDictionary (dictName, dictList, DICT_COMPARE_CASE_INSENSITIVE);
|
rv = packageRegistry->GetSelectedLocale(NS_LITERAL_CSTRING("global"),
|
||||||
|
utf8DictName);
|
||||||
|
AppendUTF8toUTF16(utf8DictName, dictName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv) && !dictName.IsEmpty()) {
|
||||||
|
rv = SetCurrentDictionary(dictName);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
#ifdef DEBUG_DICT
|
// required dictionary was not available. Try to get a dictionary
|
||||||
printf("***** Setting of |%s| failed (or it wasn't available)\n",
|
// matching at least language part of dictName:
|
||||||
NS_ConvertUTF16toUTF8(dictName).get());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Required dictionary was not available. Try to get a dictionary
|
|
||||||
// matching at least language part of dictName.
|
|
||||||
nsAutoString langCode;
|
nsAutoString langCode;
|
||||||
int32_t dashIdx = dictName.FindChar('-');
|
int32_t dashIdx = dictName.FindChar('-');
|
||||||
if (dashIdx != -1) {
|
if (dashIdx != -1) {
|
||||||
|
@ -904,112 +804,80 @@ nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
|
||||||
langCode.Assign(dictName);
|
langCode.Assign(dictName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try dictionary.spellchecker preference, if it starts with langCode,
|
nsDefaultStringComparator comparator;
|
||||||
// so we don't just get any random dictionary matching the language.
|
|
||||||
if (!preferredDict.IsEmpty() &&
|
// try dictionary.spellchecker preference if it starts with langCode (and
|
||||||
nsStyleUtil::DashMatchCompare(preferredDict, langCode, nsDefaultStringComparator())) {
|
// if we haven't tried it already)
|
||||||
#ifdef DEBUG_DICT
|
if (!preferedDict.IsEmpty() && !dictName.Equals(preferedDict) &&
|
||||||
printf("***** Trying preference value |%s| since it matches language code\n",
|
nsStyleUtil::DashMatchCompare(preferedDict, langCode, comparator)) {
|
||||||
NS_ConvertUTF16toUTF8(preferredDict).get());
|
rv = SetCurrentDictionary(preferedDict);
|
||||||
#endif
|
|
||||||
rv = TryDictionary (preferredDict, dictList,
|
|
||||||
DICT_COMPARE_CASE_INSENSITIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Otherwise, try langCode (if we haven't tried it already)
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
// Use any dictionary with the required language.
|
if (!dictName.Equals(langCode) && !preferedDict.Equals(langCode)) {
|
||||||
#ifdef DEBUG_DICT
|
rv = SetCurrentDictionary(langCode);
|
||||||
printf("***** Trying to find match for language code |%s|\n",
|
}
|
||||||
NS_ConvertUTF16toUTF8(langCode).get());
|
}
|
||||||
#endif
|
|
||||||
rv = TryDictionary (langCode, dictList, DICT_COMPARE_DASHMATCH);
|
// Otherwise, try any available dictionary aa-XX
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
// loop over avaible dictionaries; if we find one with required
|
||||||
|
// language, use it
|
||||||
|
nsTArray<nsString> dictList;
|
||||||
|
rv = mSpellChecker->GetDictionaryList(&dictList);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
int32_t i, count = dictList.Length();
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
nsAutoString dictStr(dictList.ElementAt(i));
|
||||||
|
|
||||||
|
if (dictStr.Equals(dictName) ||
|
||||||
|
dictStr.Equals(preferedDict) ||
|
||||||
|
dictStr.Equals(langCode)) {
|
||||||
|
// We have already tried it
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (nsStyleUtil::DashMatchCompare(dictStr, langCode, comparator) &&
|
||||||
|
NS_SUCCEEDED(SetCurrentDictionary(dictStr))) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 3:
|
// If we have not set dictionary, and the editable element doesn't have a
|
||||||
// If the document didn't supply a dictionary or the setting failed,
|
// lang attribute, we try to get a dictionary. First try LANG environment variable,
|
||||||
// try the user preference next.
|
// then en-US. If it does not work, pick the first one.
|
||||||
if (NS_FAILED(rv)) {
|
if (mPreferredLang.IsEmpty()) {
|
||||||
if (!preferredDict.IsEmpty()) {
|
|
||||||
#ifdef DEBUG_DICT
|
|
||||||
printf("***** Trying preference value |%s|\n",
|
|
||||||
NS_ConvertUTF16toUTF8(preferredDict).get());
|
|
||||||
#endif
|
|
||||||
rv = TryDictionary (preferredDict, dictList, DICT_NORMAL_COMPARE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Priority 4:
|
|
||||||
// As next fallback, try the current locale.
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
nsCOMPtr<nsIXULChromeRegistry> packageRegistry =
|
|
||||||
mozilla::services::GetXULChromeRegistryService();
|
|
||||||
|
|
||||||
if (packageRegistry) {
|
|
||||||
nsAutoCString utf8DictName;
|
|
||||||
rv2 = packageRegistry->GetSelectedLocale(NS_LITERAL_CSTRING("global"),
|
|
||||||
utf8DictName);
|
|
||||||
dictName.Assign(EmptyString());
|
|
||||||
AppendUTF8toUTF16(utf8DictName, dictName);
|
|
||||||
#ifdef DEBUG_DICT
|
|
||||||
printf("***** Trying locale |%s|\n",
|
|
||||||
NS_ConvertUTF16toUTF8(dictName).get());
|
|
||||||
#endif
|
|
||||||
rv = TryDictionary (dictName, dictList, DICT_COMPARE_CASE_INSENSITIVE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
// Still no success.
|
|
||||||
|
|
||||||
// Priority 5:
|
|
||||||
// If we have a current dictionary, don't try anything else.
|
|
||||||
nsAutoString currentDictionary;
|
nsAutoString currentDictionary;
|
||||||
rv2 = GetCurrentDictionary(currentDictionary);
|
rv = GetCurrentDictionary(currentDictionary);
|
||||||
#ifdef DEBUG_DICT
|
if (NS_FAILED(rv) || currentDictionary.IsEmpty()) {
|
||||||
if (NS_SUCCEEDED(rv2))
|
// Try to get current dictionary from environment variable LANG
|
||||||
printf("***** Retrieved current dict |%s|\n",
|
|
||||||
NS_ConvertUTF16toUTF8(currentDictionary).get());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (NS_FAILED(rv2) || currentDictionary.IsEmpty()) {
|
|
||||||
// Priority 6:
|
|
||||||
// Try to get current dictionary from environment variable LANG.
|
|
||||||
// LANG = language[_territory][.charset]
|
|
||||||
char* env_lang = getenv("LANG");
|
char* env_lang = getenv("LANG");
|
||||||
if (env_lang != nullptr) {
|
if (env_lang != nullptr) {
|
||||||
nsString lang = NS_ConvertUTF8toUTF16(env_lang);
|
nsString lang = NS_ConvertUTF8toUTF16(env_lang);
|
||||||
// Strip trailing charset, if there is any.
|
// Strip trailing charset if there is any
|
||||||
int32_t dot_pos = lang.FindChar('.');
|
int32_t dot_pos = lang.FindChar('.');
|
||||||
if (dot_pos != -1) {
|
if (dot_pos != -1) {
|
||||||
lang = Substring(lang, 0, dot_pos);
|
lang = Substring(lang, 0, dot_pos);
|
||||||
}
|
}
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
int32_t underScore = lang.FindChar('_');
|
int32_t underScore = lang.FindChar('_');
|
||||||
if (underScore != -1) {
|
if (underScore != -1) {
|
||||||
lang.Replace(underScore, 1, '-');
|
lang.Replace(underScore, 1, '-');
|
||||||
#ifdef DEBUG_DICT
|
rv = SetCurrentDictionary(lang);
|
||||||
printf("***** Trying LANG from environment |%s|\n",
|
}
|
||||||
NS_ConvertUTF16toUTF8(lang).get());
|
|
||||||
#endif
|
|
||||||
nsAutoString lang2;
|
|
||||||
lang2.Assign(lang);
|
|
||||||
rv = TryDictionary(lang2, dictList, DICT_COMPARE_CASE_INSENSITIVE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 7:
|
|
||||||
// If it does not work, pick the first one.
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
if (dictList.Length() > 0) {
|
rv = SetCurrentDictionary(NS_LITERAL_STRING("en-US"));
|
||||||
rv = SetCurrentDictionary(dictList[0]);
|
if (NS_FAILED(rv)) {
|
||||||
#ifdef DEBUG_DICT
|
nsTArray<nsString> dictList;
|
||||||
printf("***** Trying first of list |%s|\n",
|
rv = mSpellChecker->GetDictionaryList(&dictList);
|
||||||
NS_ConvertUTF16toUTF8(dictList[0]).get());
|
if (NS_SUCCEEDED(rv) && dictList.Length() > 0) {
|
||||||
if (NS_SUCCEEDED(rv))
|
SetCurrentDictionary(dictList[0]);
|
||||||
printf ("***** Setting worked.\n");
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,6 @@ class nsITextServicesFilter;
|
||||||
|
|
||||||
class DictionaryFetcher;
|
class DictionaryFetcher;
|
||||||
|
|
||||||
enum dictCompare {
|
|
||||||
DICT_NORMAL_COMPARE,
|
|
||||||
DICT_COMPARE_CASE_INSENSITIVE,
|
|
||||||
DICT_COMPARE_DASHMATCH
|
|
||||||
};
|
|
||||||
|
|
||||||
class nsEditorSpellCheck final : public nsIEditorSpellCheck
|
class nsEditorSpellCheck final : public nsIEditorSpellCheck
|
||||||
{
|
{
|
||||||
friend class DictionaryFetcher;
|
friend class DictionaryFetcher;
|
||||||
|
@ -70,9 +64,6 @@ protected:
|
||||||
|
|
||||||
bool mUpdateDictionaryRunning;
|
bool mUpdateDictionaryRunning;
|
||||||
|
|
||||||
nsresult TryDictionary(nsAutoString aDictName, nsTArray<nsString>& aDictList,
|
|
||||||
enum dictCompare aCompareType);
|
|
||||||
|
|
||||||
nsresult DictionaryFetched(DictionaryFetcher* aFetchState);
|
nsresult DictionaryFetched(DictionaryFetcher* aFetchState);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Language" content="en-US">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<textarea id="none">root en-US</textarea>
|
|
||||||
<textarea id="en-GB" lang="en-GB">root en-US, but element en-GB</textarea>
|
|
||||||
<textarea id="en-gb" lang="en-gb">root en-US, but element en-gb (lower case)</textarea>
|
|
||||||
<textarea id="en-ZA-not-avail" lang="en-ZA">root en-US, but element en-ZA (which is not installed)</textarea>
|
|
||||||
<textarea id="en-generic" lang="en">root en-US, but element en</textarea>
|
|
||||||
<textarea id="ko-not-avail" lang="ko">root en-US, but element ko (which is not installed)</textarea>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -6,4 +6,3 @@ skip-if = buildapp == 'b2g' || os == 'android'
|
||||||
[test_bug434998.xul]
|
[test_bug434998.xul]
|
||||||
[test_bug678842.html]
|
[test_bug678842.html]
|
||||||
[test_bug717433.html]
|
[test_bug717433.html]
|
||||||
[test_bug1200533.html]
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
# Affix file for German English dictionary
|
|
||||||
# Fake file, nothing here.
|
|
|
@ -1,4 +0,0 @@
|
||||||
3
|
|
||||||
Mary
|
|
||||||
Paul
|
|
||||||
Peter
|
|
|
@ -1,2 +0,0 @@
|
||||||
# Affix file for British English dictionary
|
|
||||||
# Fake file, nothing here.
|
|
|
@ -1,4 +0,0 @@
|
||||||
3
|
|
||||||
Mary
|
|
||||||
Paul
|
|
||||||
Peter
|
|
|
@ -3,13 +3,8 @@ skip-if = buildapp == 'b2g' || buildapp == 'mulet'
|
||||||
support-files =
|
support-files =
|
||||||
bug678842_subframe.html
|
bug678842_subframe.html
|
||||||
bug717433_subframe.html
|
bug717433_subframe.html
|
||||||
bug1200533_subframe.html
|
|
||||||
en-GB/en_GB.dic
|
en-GB/en_GB.dic
|
||||||
en-GB/en_GB.aff
|
en-GB/en_GB.aff
|
||||||
en-AU/en_AU.dic
|
|
||||||
en-AU/en_AU.aff
|
|
||||||
de-DE/de_DE.dic
|
|
||||||
de-DE/de_DE.aff
|
|
||||||
|
|
||||||
[test_bug348497.html]
|
[test_bug348497.html]
|
||||||
[test_bug384147.html]
|
[test_bug384147.html]
|
||||||
|
|
|
@ -1,134 +0,0 @@
|
||||||
<!DOCTYPE HTML>
|
|
||||||
<html>
|
|
||||||
<!--
|
|
||||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1200533
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<title>Test for Bug 1200533</title>
|
|
||||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
||||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1200533">Mozilla Bug 1200533</a>
|
|
||||||
<p id="display"></p>
|
|
||||||
<iframe id="content"></iframe>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<pre id="test">
|
|
||||||
<script class="testbody" ttype="application/javascript">
|
|
||||||
|
|
||||||
/** Test for Bug 1200533 **/
|
|
||||||
/** Visit the elements defined above and check the dictionary we got **/
|
|
||||||
SimpleTest.waitForExplicitFinish();
|
|
||||||
var content = document.getElementById('content');
|
|
||||||
|
|
||||||
var tests = [
|
|
||||||
// text area, value of spellchecker.dictionary, result.
|
|
||||||
// Result: Document language.
|
|
||||||
[ "none", "", "en-US" ],
|
|
||||||
// Result: Element language.
|
|
||||||
[ "en-GB", "", "en-GB" ],
|
|
||||||
[ "en-gb", "", "en-GB" ],
|
|
||||||
// Result: Random en-*.
|
|
||||||
[ "en-ZA-not-avail", "", "*" ],
|
|
||||||
[ "en-generic", "", "*" ],
|
|
||||||
// Result: Locale.
|
|
||||||
[ "ko-not-avail", "", "en-US" ],
|
|
||||||
|
|
||||||
// Result: Preference value in all cases.
|
|
||||||
[ "en-ZA-not-avail", "en-AU", "en-AU" ],
|
|
||||||
[ "en-generic", "en-AU", "en-AU" ],
|
|
||||||
[ "ko-not-avail", "en-AU", "en-AU" ],
|
|
||||||
|
|
||||||
// Result: Random en-*.
|
|
||||||
[ "en-ZA-not-avail", "de-DE", "*" ],
|
|
||||||
[ "en-generic", "de-DE", "*" ],
|
|
||||||
// Result: Preference value.
|
|
||||||
[ "ko-not-avail", "de-DE", "de-DE" ],
|
|
||||||
];
|
|
||||||
|
|
||||||
var loadCount = 0;
|
|
||||||
var en_GB;
|
|
||||||
var en_AU;
|
|
||||||
var en_DE;
|
|
||||||
var hunspell;
|
|
||||||
|
|
||||||
var loadListener = function(evt) {
|
|
||||||
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
|
|
||||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
||||||
|
|
||||||
if (loadCount == 0) {
|
|
||||||
var dir = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
||||||
.getService(Components.interfaces.nsIProperties)
|
|
||||||
.get("CurWorkD", Components.interfaces.nsIFile);
|
|
||||||
dir.append("tests");
|
|
||||||
dir.append("editor");
|
|
||||||
dir.append("composer");
|
|
||||||
dir.append("test");
|
|
||||||
|
|
||||||
hunspell = Components.classes["@mozilla.org/spellchecker/engine;1"]
|
|
||||||
.getService(Components.interfaces.mozISpellCheckingEngine);
|
|
||||||
|
|
||||||
// Install en-GB, en-AU and de-DE dictionaries.
|
|
||||||
en_GB = dir.clone();
|
|
||||||
en_AU = dir.clone();
|
|
||||||
de_DE = dir.clone();
|
|
||||||
en_GB.append("en-GB");
|
|
||||||
en_AU.append("en-AU");
|
|
||||||
de_DE.append("de-DE");
|
|
||||||
is(en_GB.exists(), true, "true expected (en-GB directory should exist)");
|
|
||||||
is(en_AU.exists(), true, "true expected (en-AU directory should exist)");
|
|
||||||
is(de_DE.exists(), true, "true expected (de-DE directory should exist)");
|
|
||||||
hunspell.addDirectory(en_GB);
|
|
||||||
hunspell.addDirectory(en_AU);
|
|
||||||
hunspell.addDirectory(de_DE);
|
|
||||||
}
|
|
||||||
|
|
||||||
Services.prefs.setCharPref("spellchecker.dictionary", tests[loadCount][1]);
|
|
||||||
|
|
||||||
var doc = evt.target.contentDocument;
|
|
||||||
var elem = doc.getElementById(tests[loadCount][0]);
|
|
||||||
var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
|
|
||||||
editor.setSpellcheckUserOverride(true);
|
|
||||||
var inlineSpellChecker = editor.getInlineSpellChecker(true);
|
|
||||||
|
|
||||||
onSpellCheck(elem, function () {
|
|
||||||
var spellchecker = inlineSpellChecker.spellChecker;
|
|
||||||
try {
|
|
||||||
var dict = spellchecker.GetCurrentDictionary();
|
|
||||||
} catch(e) {}
|
|
||||||
|
|
||||||
if (tests[loadCount][2] != "*") {
|
|
||||||
is (dict, tests[loadCount][2], "expected " + tests[loadCount][2]);
|
|
||||||
} else {
|
|
||||||
var gotEn = (dict == "en-GB" || dict == "en-AU" || dict == "en-US");
|
|
||||||
is (gotEn, true, "expected en-AU or en-GB or en-US");
|
|
||||||
}
|
|
||||||
|
|
||||||
loadCount++;
|
|
||||||
if (loadCount < tests.length) {
|
|
||||||
// Load the iframe again.
|
|
||||||
content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug1200533_subframe.html?firstload=false';
|
|
||||||
} else {
|
|
||||||
// Remove the fake dictionaries again, since it's otherwise picked up by later tests.
|
|
||||||
hunspell.removeDirectory(en_GB);
|
|
||||||
hunspell.removeDirectory(en_AU);
|
|
||||||
hunspell.removeDirectory(de_DE);
|
|
||||||
|
|
||||||
// Reset the preference, so the last value we set doesn't collide with the next test.
|
|
||||||
Services.prefs.setCharPref("spellchecker.dictionary", "");
|
|
||||||
|
|
||||||
SimpleTest.finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
content.addEventListener('load', loadListener, false);
|
|
||||||
|
|
||||||
content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug1200533_subframe.html?firstload=true';
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</pre>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=678842
|
||||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
|
||||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=678842">Mozilla Bug 678842</a>
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=678842">Mozilla Bug 678842</a>
|
||||||
<p id="display"></p>
|
<p id="display"></p>
|
||||||
<iframe id="content"></iframe>
|
<iframe id="content"></iframe>
|
||||||
|
@ -26,32 +25,9 @@ var content = document.getElementById('content');
|
||||||
// loads.
|
// loads.
|
||||||
|
|
||||||
var firstLoad = true;
|
var firstLoad = true;
|
||||||
var en_GB;
|
|
||||||
var hunspell;
|
|
||||||
|
|
||||||
var loadListener = function(evt) {
|
var loadListener = function(evt) {
|
||||||
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
|
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
|
||||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
||||||
|
|
||||||
if (firstLoad) {
|
|
||||||
var dir = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
||||||
.getService(Components.interfaces.nsIProperties)
|
|
||||||
.get("CurWorkD", Components.interfaces.nsIFile);
|
|
||||||
dir.append("tests");
|
|
||||||
dir.append("editor");
|
|
||||||
dir.append("composer");
|
|
||||||
dir.append("test");
|
|
||||||
|
|
||||||
hunspell = Components.classes["@mozilla.org/spellchecker/engine;1"]
|
|
||||||
.getService(Components.interfaces.mozISpellCheckingEngine);
|
|
||||||
|
|
||||||
// Install en-GB dictionary.
|
|
||||||
en_GB = dir.clone();
|
|
||||||
en_GB.append("en-GB");
|
|
||||||
is(en_GB.exists(), true, "true expected (en-GB directory should exist)");
|
|
||||||
hunspell.addDirectory(en_GB);
|
|
||||||
}
|
|
||||||
|
|
||||||
var doc = evt.target.contentDocument;
|
var doc = evt.target.contentDocument;
|
||||||
var elem = doc.getElementById('textarea');
|
var elem = doc.getElementById('textarea');
|
||||||
var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
|
var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
|
||||||
|
@ -70,23 +46,11 @@ var loadListener = function(evt) {
|
||||||
|
|
||||||
if (firstLoad) {
|
if (firstLoad) {
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
|
is (currentDictonary, "", "unexpected lang " + currentDictonary);
|
||||||
// First time around, the dictionary defaults to the locale.
|
|
||||||
is (currentDictonary, "en-US", "unexpected lang " + currentDictonary + " instead of en-US");
|
|
||||||
|
|
||||||
// Select en-GB.
|
|
||||||
spellchecker.SetCurrentDictionary("en-GB");
|
|
||||||
|
|
||||||
content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug678842_subframe.html?firstload=false';
|
content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug678842_subframe.html?firstload=false';
|
||||||
} else {
|
} else {
|
||||||
is (currentDictonary, "en-GB", "unexpected lang " + currentDictonary + " instead of en-GB");
|
is (currentDictonary, "en-US", "unexpected lang " + currentDictonary + " instead of en-US");
|
||||||
content.removeEventListener('load', loadListener, false);
|
content.removeEventListener('load', loadListener, false);
|
||||||
|
|
||||||
// Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
|
|
||||||
hunspell.removeDirectory(en_GB);
|
|
||||||
|
|
||||||
// Reset the preference, so the last value we set doesn't collide with the next test.
|
|
||||||
Services.prefs.setCharPref("spellchecker.dictionary", "");
|
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717433
|
||||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
|
||||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717433">Mozilla Bug 717433</a>
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717433">Mozilla Bug 717433</a>
|
||||||
<p id="display"></p>
|
<p id="display"></p>
|
||||||
<iframe id="content"></iframe>
|
<iframe id="content"></iframe>
|
||||||
|
@ -32,7 +31,6 @@ var hunspell;
|
||||||
|
|
||||||
var loadListener = function(evt) {
|
var loadListener = function(evt) {
|
||||||
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
|
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
|
||||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
||||||
|
|
||||||
if (firstLoad) {
|
if (firstLoad) {
|
||||||
var dir = Components.classes["@mozilla.org/file/directory_service;1"]
|
var dir = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||||
|
@ -85,9 +83,6 @@ var loadListener = function(evt) {
|
||||||
|
|
||||||
// Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
|
// Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
|
||||||
hunspell.removeDirectory(en_GB);
|
hunspell.removeDirectory(en_GB);
|
||||||
|
|
||||||
// Reset the preference, so the last value we set doesn't collide with the next test.
|
|
||||||
Services.prefs.setCharPref("spellchecker.dictionary", "");
|
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче