Remove nsFormControlHelper::GetLocalizedString, improve string bundle methods in nsContentUtils, and convert callers. b=273829 r+sr=bryner

This commit is contained in:
dbaron%dbaron.org 2004-12-17 20:40:48 +00:00
Родитель b29fe5517c
Коммит 48a696beb8
14 изменённых файлов: 156 добавлений и 184 удалений

Просмотреть файл

@ -469,6 +469,9 @@ public:
eXBL_PROPERTIES, eXBL_PROPERTIES,
eXUL_PROPERTIES, eXUL_PROPERTIES,
eLAYOUT_PROPERTIES, eLAYOUT_PROPERTIES,
eFORMS_PROPERTIES,
ePRINTING_PROPERTIES,
eDOM_PROPERTIES,
PropertiesFile_COUNT PropertiesFile_COUNT
}; };
static nsresult ReportToConsole(PropertiesFile aFile, static nsresult ReportToConsole(PropertiesFile aFile,
@ -482,6 +485,24 @@ public:
PRUint32 aErrorFlags, PRUint32 aErrorFlags,
const char *aCategory); const char *aCategory);
/**
* Get the localized string named |aKey| in properties file |aFile|.
*/
static nsresult GetLocalizedString(PropertiesFile aFile,
const char* aKey,
nsString& aResult);
/**
* Fill (with the parameters given) the localized string named |aKey| in
* properties file |aFile|.
*/
static nsresult FormatLocalizedString(PropertiesFile aFile,
const char* aKey,
const PRUnichar **aParams,
PRUint32 aParamsLength,
nsString& aResult);
private: private:
static nsresult doReparentContentWrapper(nsIContent *aChild, static nsresult doReparentContentWrapper(nsIContent *aChild,
nsIDocument *aNewDocument, nsIDocument *aNewDocument,
@ -489,6 +510,8 @@ private:
JSContext *cx, JSContext *cx,
JSObject *parent_obj); JSObject *parent_obj);
static nsresult EnsureStringBundle(PropertiesFile aFile);
static nsIDOMScriptObjectFactory *sDOMScriptObjectFactory; static nsIDOMScriptObjectFactory *sDOMScriptObjectFactory;

Просмотреть файл

@ -2141,14 +2141,72 @@ nsCxPusher::Pop()
mScriptIsRunning = PR_FALSE; mScriptIsRunning = PR_FALSE;
} }
static const char gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT][48] = { static const char gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT][56] = {
// Must line up with the enum values in |PropertiesFile| enum. // Must line up with the enum values in |PropertiesFile| enum.
"chrome://global/locale/css.properties", "chrome://global/locale/css.properties",
"chrome://global/locale/xbl.properties", "chrome://global/locale/xbl.properties",
"chrome://global/locale/xul.properties", "chrome://global/locale/xul.properties",
"chrome://global/locale/layout_errors.properties" "chrome://global/locale/layout_errors.properties",
"chrome://communicator/locale/layout/HtmlForm.properties",
"chrome://global/locale/printing.properties",
"chrome://communicator/locale/dom/dom.properties"
}; };
/* static */ nsresult
nsContentUtils::EnsureStringBundle(PropertiesFile aFile)
{
if (!sStringBundles[aFile]) {
if (!sStringBundleService) {
nsresult rv =
CallGetService(NS_STRINGBUNDLE_CONTRACTID, &sStringBundleService);
NS_ENSURE_SUCCESS(rv, rv);
}
nsIStringBundle *bundle;
nsresult rv =
sStringBundleService->CreateBundle(gPropertiesFiles[aFile], &bundle);
NS_ENSURE_SUCCESS(rv, rv);
sStringBundles[aFile] = bundle; // transfer ownership
}
return NS_OK;
}
/* static */
nsresult nsContentUtils::GetLocalizedString(PropertiesFile aFile,
const char* aKey,
nsString& aResult)
{
nsresult rv = EnsureStringBundle(aFile);
NS_ENSURE_SUCCESS(rv, rv);
nsIStringBundle *bundle = sStringBundles[aFile];
nsXPIDLString result;
rv = bundle->GetStringFromName(NS_ConvertASCIItoUCS2(aKey).get(),
getter_Copies(result));
NS_ENSURE_SUCCESS(rv, rv);
aResult = result;
return NS_OK;
}
/* static */
nsresult nsContentUtils::FormatLocalizedString(PropertiesFile aFile,
const char* aKey,
const PRUnichar **aParams,
PRUint32 aParamsLength,
nsString& aResult)
{
nsresult rv = EnsureStringBundle(aFile);
NS_ENSURE_SUCCESS(rv, rv);
nsIStringBundle *bundle = sStringBundles[aFile];
nsXPIDLString result;
rv = bundle->FormatStringFromName(NS_ConvertASCIItoUCS2(aKey).get(),
aParams, aParamsLength,
getter_Copies(result));
NS_ENSURE_SUCCESS(rv, rv);
aResult = result;
return NS_OK;
}
/* static */ nsresult /* static */ nsresult
nsContentUtils::ReportToConsole(PropertiesFile aFile, nsContentUtils::ReportToConsole(PropertiesFile aFile,
const char *aMessageName, const char *aMessageName,
@ -2162,25 +2220,14 @@ nsContentUtils::ReportToConsole(PropertiesFile aFile,
const char *aCategory) const char *aCategory)
{ {
nsresult rv; nsresult rv;
nsIStringBundle *bundle = sStringBundles[aFile];
if (!bundle) {
if (!sStringBundleService) {
rv = CallGetService(NS_STRINGBUNDLE_CONTRACTID, &sStringBundleService);
NS_ENSURE_SUCCESS(rv, rv);
}
if (!sConsoleService) { // only need to bother null-checking here if (!sConsoleService) { // only need to bother null-checking here
rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService); rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
sStringBundleService->CreateBundle(gPropertiesFiles[aFile], &bundle);
sStringBundles[aFile] = bundle; // transfer ownership
}
nsXPIDLString errorText; nsString errorText;
rv = bundle->FormatStringFromName(NS_ConvertASCIItoUCS2(aMessageName).get(), rv = FormatLocalizedString(aFile, aMessageName, aParams, aParamsLength,
aParams, aParamsLength, errorText);
getter_Copies(errorText));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString spec; nsCAutoString spec;

Просмотреть файл

@ -223,7 +223,7 @@ public:
*/ */
static nsresult static nsresult
SendJSWarning(nsIHTMLContent* aContent, SendJSWarning(nsIHTMLContent* aContent,
const nsAFlatString& aWarningName); const char* aWarningName);
/** /**
* Send a warning to the JS console * Send a warning to the JS console
* @param aContent the content the warning is about * @param aContent the content the warning is about
@ -233,7 +233,7 @@ SendJSWarning(nsIHTMLContent* aContent,
*/ */
static nsresult static nsresult
SendJSWarning(nsIHTMLContent* aContent, SendJSWarning(nsIHTMLContent* aContent,
const nsAFlatString& aWarningName, const char* aWarningName,
const nsAFlatString& aWarningArg1); const nsAFlatString& aWarningArg1);
/** /**
* Send a warning to the JS console * Send a warning to the JS console
@ -245,7 +245,7 @@ SendJSWarning(nsIHTMLContent* aContent,
*/ */
static nsresult static nsresult
SendJSWarning(nsIHTMLContent* aContent, SendJSWarning(nsIHTMLContent* aContent,
const nsAFlatString& aWarningName, const char* aWarningName,
const PRUnichar** aWarningArgs, PRUint32 aWarningArgsLen); const PRUnichar** aWarningArgs, PRUint32 aWarningArgsLen);
@ -339,7 +339,7 @@ nsFSURLEncoded::AddNameValuePair(nsIDOMHTMLElement* aSource,
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aSource); nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aSource);
if (formControl->GetType() == NS_FORM_INPUT_FILE) { if (formControl->GetType() == NS_FORM_INPUT_FILE) {
nsCOMPtr<nsIHTMLContent> content = do_QueryInterface(aSource); nsCOMPtr<nsIHTMLContent> content = do_QueryInterface(aSource);
SendJSWarning(content, NS_LITERAL_STRING("ForgotFileEnctypeWarning")); SendJSWarning(content, "ForgotFileEnctypeWarning");
mWarnedFileControl = PR_TRUE; mWarnedFileControl = PR_TRUE;
} }
} }
@ -1072,14 +1072,14 @@ NS_INTERFACE_MAP_END
static nsresult static nsresult
SendJSWarning(nsIHTMLContent* aContent, SendJSWarning(nsIHTMLContent* aContent,
const nsAFlatString& aWarningName) const char* aWarningName)
{ {
return SendJSWarning(aContent, aWarningName, nsnull, 0); return SendJSWarning(aContent, aWarningName, nsnull, 0);
} }
static nsresult static nsresult
SendJSWarning(nsIHTMLContent* aContent, SendJSWarning(nsIHTMLContent* aContent,
const nsAFlatString& aWarningName, const char* aWarningName,
const nsAFlatString& aWarningArg1) const nsAFlatString& aWarningArg1)
{ {
const PRUnichar* formatStrings[1] = { aWarningArg1.get() }; const PRUnichar* formatStrings[1] = { aWarningArg1.get() };
@ -1088,65 +1088,25 @@ SendJSWarning(nsIHTMLContent* aContent,
static nsresult static nsresult
SendJSWarning(nsIHTMLContent* aContent, SendJSWarning(nsIHTMLContent* aContent,
const nsAFlatString& aWarningName, const char* aWarningName,
const PRUnichar** aWarningArgs, PRUint32 aWarningArgsLen) const PRUnichar** aWarningArgs, PRUint32 aWarningArgsLen)
{ {
nsresult rv = NS_OK;
//
// Get the document URL to use as the filename // Get the document URL to use as the filename
//
nsCAutoString documentURISpec;
nsIDocument* document = aContent->GetDocument(); nsIDocument* document = aContent->GetDocument();
nsIURI *documentURI = nsnull;
if (document) { if (document) {
nsIURI *documentURI = document->GetDocumentURI(); documentURI = document->GetDocumentURI();
NS_ENSURE_TRUE(documentURI, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(documentURI, NS_ERROR_UNEXPECTED);
documentURI->GetPath(documentURISpec);
} }
// return nsContentUtils::ReportToConsole(nsContentUtils::eFORMS_PROPERTIES,
// Get the error string aWarningName,
//
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(
"chrome://communicator/locale/layout/HtmlForm.properties",
getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLString warningStr;
if (aWarningArgsLen > 0) {
bundle->FormatStringFromName(aWarningName.get(),
aWarningArgs, aWarningArgsLen, aWarningArgs, aWarningArgsLen,
getter_Copies(warningStr)); documentURI,
} else { NS_LITERAL_STRING(""), 0, 0,
bundle->GetStringFromName(aWarningName.get(), getter_Copies(warningStr)); nsIScriptError::warningFlag,
}
//
// Create the error
//
nsCOMPtr<nsIScriptError>
scriptError(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
NS_ENSURE_TRUE(scriptError, NS_ERROR_UNEXPECTED);
rv = scriptError->Init(warningStr.get(),
NS_ConvertUTF8toUTF16(documentURISpec).get(),
nsnull, (uintN)0,
0, nsIScriptError::warningFlag,
"HTML"); "HTML");
NS_ENSURE_SUCCESS(rv,rv);
//
// Send the error to the console
//
nsCOMPtr<nsIConsoleService>
consoleService(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
NS_ENSURE_TRUE(consoleService, NS_ERROR_UNEXPECTED);
return consoleService->LogMessage(scriptError);
} }
nsresult nsresult
@ -1207,7 +1167,7 @@ GetSubmissionFromForm(nsIHTMLContent* aForm,
enctype == NS_FORM_ENCTYPE_TEXTPLAIN) { enctype == NS_FORM_ENCTYPE_TEXTPLAIN) {
nsAutoString enctypeStr; nsAutoString enctypeStr;
aForm->GetAttr(kNameSpaceID_None, nsHTMLAtoms::enctype, enctypeStr); aForm->GetAttr(kNameSpaceID_None, nsHTMLAtoms::enctype, enctypeStr);
SendJSWarning(aForm, NS_LITERAL_STRING("ForgotPostWarning"), PromiseFlatString(enctypeStr)); SendJSWarning(aForm, "ForgotPostWarning", PromiseFlatString(enctypeStr));
} }
*aFormSubmission = new nsFSURLEncoded(charset, encoder, *aFormSubmission = new nsFSURLEncoded(charset, encoder,
formProcessor, bidiOptions, method); formProcessor, bidiOptions, method);

Просмотреть файл

@ -100,7 +100,6 @@
#include "nsContentCID.h" #include "nsContentCID.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsIDocShell.h" #include "nsIDocShell.h"
#include "nsFormControlHelper.h"
#include "nsObjectFrame.h" #include "nsObjectFrame.h"
#include "nsRuleNode.h" #include "nsRuleNode.h"
#include "nsIDOMMutationEvent.h" #include "nsIDOMMutationEvent.h"
@ -10372,8 +10371,8 @@ void nsCSSFrameConstructor::GetAlternateTextFor(nsIContent* aContent,
// If there's no "value" attribute either, then use the localized string // If there's no "value" attribute either, then use the localized string
// for "Submit" as the alternate text. // for "Submit" as the alternate text.
if (NS_CONTENT_ATTR_NOT_THERE == rv) { if (NS_CONTENT_ATTR_NOT_THERE == rv) {
nsFormControlHelper::GetLocalizedString(nsFormControlHelper::GetHTMLPropertiesFileName(), nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
NS_LITERAL_STRING("Submit").get(), aAltText); "Submit", aAltText);
} }
} }
} }

Просмотреть файл

@ -169,7 +169,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
// Print error dialog // Print error dialog
#include "nsIPrompt.h" #include "nsIPrompt.h"
#include "nsIWindowWatcher.h" #include "nsIWindowWatcher.h"
#include "nsIStringBundle.h"
// Printing // Printing
#include "nsPrintEngine.h" #include "nsPrintEngine.h"
@ -194,10 +193,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
#include "prenv.h" #include "prenv.h"
#include <stdio.h> #include <stdio.h>
static const char kDOMStringBundleURL[] =
"chrome://communicator/locale/dom/dom.properties";
#ifdef NS_DEBUG #ifdef NS_DEBUG
#undef NOISY_VIEWER #undef NOISY_VIEWER
@ -989,21 +984,16 @@ DocumentViewerImpl::PermitUnload(PRBool *aPermitUnload)
nsCOMPtr<nsIPrompt> prompt(do_GetInterface(mContainer)); nsCOMPtr<nsIPrompt> prompt(do_GetInterface(mContainer));
if (prompt) { if (prompt) {
nsCOMPtr<nsIStringBundleService> nsString preMsg, postMsg;
stringService(do_GetService(NS_STRINGBUNDLE_CONTRACTID)); rv = nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
NS_ENSURE_TRUE(stringService, NS_OK); "OnBeforeUnloadPreMessage",
preMsg);
nsCOMPtr<nsIStringBundle> bundle; rv |= nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
stringService->CreateBundle(kDOMStringBundleURL, getter_AddRefs(bundle)); "OnBeforeUnloadPostMessage",
NS_ENSURE_TRUE(bundle, NS_OK); postMsg);
nsXPIDLString preMsg, postMsg;
nsresult rv;
rv = bundle->GetStringFromName(NS_LITERAL_STRING("OnBeforeUnloadPreMessage").get(), getter_Copies(preMsg));
rv |= bundle->GetStringFromName(NS_LITERAL_STRING("OnBeforeUnloadPostMessage").get(), getter_Copies(postMsg));
// GetStringFromName can succeed, yet give NULL strings back. // GetStringFromName can succeed, yet give NULL strings back.
if (NS_FAILED(rv) || !preMsg || !postMsg) { if (NS_FAILED(rv) || preMsg.IsEmpty() || postMsg.IsEmpty()) {
NS_ERROR("Failed to get strings from dom.properties!"); NS_ERROR("Failed to get strings from dom.properties!");
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -65,6 +65,9 @@ REQUIRES = xpcom \
accessibility \ accessibility \
unicharutil \ unicharutil \
commandhandler \ commandhandler \
xpconnect \
js \
pref \
$(NULL) $(NULL)
EXPORTS = \ EXPORTS = \

Просмотреть файл

@ -73,6 +73,7 @@
#include "nsITextControlElement.h" #include "nsITextControlElement.h"
#include "nsNodeInfoManager.h" #include "nsNodeInfoManager.h"
#include "nsContentCreatorFunctions.h" #include "nsContentCreatorFunctions.h"
#include "nsContentUtils.h"
#define SYNC_TEXT 0x1 #define SYNC_TEXT 0x1
#define SYNC_BUTTON 0x2 #define SYNC_BUTTON 0x2
@ -309,8 +310,8 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
// Get Loc title // Get Loc title
nsString title; nsString title;
nsFormControlHelper::GetLocalizedString(nsFormControlHelper::GetHTMLPropertiesFileName(), nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
NS_LITERAL_STRING("FileUpload").get(), title); "FileUpload", title);
nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1"); nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1");
if (!filePicker) if (!filePicker)

Просмотреть файл

@ -381,35 +381,6 @@ nsFormControlHelper::GetValueAttr(nsIContent* aContent, nsAString* aResult)
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Return localised string for resource string (e.g. "Submit" -> "Submit Query")
// This code is derived from nsBookmarksService::Init() and cookie_Localize()
nsresult
nsFormControlHelper::GetLocalizedString(const char * aPropFileName, const PRUnichar* aKey, nsString& oVal)
{
NS_ENSURE_ARG_POINTER(aKey);
nsresult rv;
nsCOMPtr<nsIStringBundle> bundle;
// Create a bundle for the localization
nsCOMPtr<nsIStringBundleService> stringService =
do_GetService(kStringBundleServiceCID, &rv);
if (NS_SUCCEEDED(rv) && stringService)
rv = stringService->CreateBundle(aPropFileName, getter_AddRefs(bundle));
// Determine default label from string bundle
if (NS_SUCCEEDED(rv) && bundle) {
nsXPIDLString valUni;
rv = bundle->GetStringFromName(aKey, getter_Copies(valUni));
if (NS_SUCCEEDED(rv) && valUni) {
oVal.Assign(valUni);
} else {
oVal.Truncate();
}
}
return rv;
}
nsresult nsresult
nsFormControlHelper::Reset(nsIFrame* aFrame, nsPresContext* aPresContext) nsFormControlHelper::Reset(nsIFrame* aFrame, nsPresContext* aPresContext)

Просмотреть файл

@ -58,10 +58,6 @@ class nsStyleContext;
#define NS_STRING_TRUE NS_LITERAL_STRING("1") #define NS_STRING_TRUE NS_LITERAL_STRING("1")
#define NS_STRING_FALSE NS_LITERAL_STRING("0") #define NS_STRING_FALSE NS_LITERAL_STRING("0")
// for localization
#define FORM_PROPERTIES "chrome://communicator/locale/layout/HtmlForm.properties"
/** /**
* Enumeration of possible mouse states used to detect mouse clicks * Enumeration of possible mouse states used to detect mouse clicks
*/ */
@ -170,10 +166,6 @@ public:
static nsresult GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp); static nsresult GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp);
// Localization Helper
static nsresult GetLocalizedString(const char * aPropFileName, const PRUnichar* aKey, nsString& oVal);
static const char * GetHTMLPropertiesFileName() { return FORM_PROPERTIES; }
// //
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// Utility methods for managing checkboxes and radiobuttons // Utility methods for managing checkboxes and radiobuttons

Просмотреть файл

@ -52,6 +52,7 @@
#include "nsReflowPath.h" #include "nsReflowPath.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsStyleSet.h" #include "nsStyleSet.h"
#include "nsContentUtils.h"
// MouseEvent suppression in PP // MouseEvent suppression in PP
#include "nsGUIEvent.h" #include "nsGUIEvent.h"
@ -284,23 +285,25 @@ else {
nsresult nsresult
nsGfxButtonControlFrame::GetDefaultLabel(nsString& aString) nsGfxButtonControlFrame::GetDefaultLabel(nsString& aString)
{ {
const char * propname = nsFormControlHelper::GetHTMLPropertiesFileName();
nsresult rv = NS_OK; nsresult rv = NS_OK;
PRInt32 type = GetFormControlType(); PRInt32 type = GetFormControlType();
const char *prop;
if (type == NS_FORM_INPUT_RESET) { if (type == NS_FORM_INPUT_RESET) {
rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Reset").get(), aString); prop = "Reset";
} }
else if (type == NS_FORM_INPUT_SUBMIT) { else if (type == NS_FORM_INPUT_SUBMIT) {
rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Submit").get(), aString); prop = "Submit";
} }
else if (IsFileBrowseButton(type)) { else if (IsFileBrowseButton(type)) {
rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Browse").get(), aString); prop = "Browse";
} }
else { else {
aString.Truncate(); aString.Truncate();
rv = NS_OK; return NS_OK;
} }
return rv;
return nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
prop, aString);
} }
NS_IMETHODIMP NS_IMETHODIMP

Просмотреть файл

@ -79,6 +79,7 @@
#include "nsContentCID.h" #include "nsContentCID.h"
#include "nsNodeInfoManager.h" #include "nsNodeInfoManager.h"
#include "nsContentCreatorFunctions.h" #include "nsContentCreatorFunctions.h"
#include "nsContentUtils.h"
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
@ -153,8 +154,9 @@ nsIsIndexFrame::UpdatePromptLabel()
// We can't make any assumption as to what the default would be // We can't make any assumption as to what the default would be
// because the value is localized for non-english platforms, thus // because the value is localized for non-english platforms, thus
// it might not be the string "This is a searchable index. Enter search keywords: " // it might not be the string "This is a searchable index. Enter search keywords: "
result = nsFormControlHelper::GetLocalizedString(nsFormControlHelper::GetHTMLPropertiesFileName(), result =
NS_LITERAL_STRING("IsIndexPrompt").get(), prompt); nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
"IsIndexPrompt", prompt);
} }
mTextContent->SetText(prompt, PR_TRUE); mTextContent->SetText(prompt, PR_TRUE);

Просмотреть файл

@ -186,7 +186,6 @@ include $(topsrcdir)/config/rules.mk
LOCAL_INCLUDES += \ LOCAL_INCLUDES += \
-I$(srcdir) \ -I$(srcdir) \
-I$(srcdir)/../base \ -I$(srcdir)/../base \
-I$(srcdir)/../forms \
-I$(srcdir)/../tables \ -I$(srcdir)/../tables \
-I$(srcdir)/../xul/base/src \ -I$(srcdir)/../xul/base/src \
-I$(srcdir)/../../content/xul/content/src \ -I$(srcdir)/../../content/xul/content/src \

Просмотреть файл

@ -58,12 +58,6 @@ static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
#define OFFSET_NOT_SET -1 #define OFFSET_NOT_SET -1
// This is for localization of the "x of n" pages string
// this class contains a helper method we need to get
// a string from a string bundle
#include "nsFormControlHelper.h"
#define PRINTING_PROPERTIES "chrome://global/locale/printing.properties"
// Print Options // Print Options
#include "nsIPrintSettings.h" #include "nsIPrintSettings.h"
#include "nsIPrintOptions.h" #include "nsIPrintOptions.h"
@ -573,7 +567,9 @@ nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char
// Doing this here so we only have to go get these formats once // Doing this here so we only have to go get these formats once
nsAutoString pageNumberFormat; nsAutoString pageNumberFormat;
// Now go get the Localized Page Formating String // Now go get the Localized Page Formating String
nsresult rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, NS_ConvertUTF8toUCS2(aPropName).get(), pageNumberFormat); nsresult rv =
nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES,
aPropName, pageNumberFormat);
if (NS_FAILED(rv)) { // back stop formatting if (NS_FAILED(rv)) { // back stop formatting
pageNumberFormat.AssignASCII(aDefPropVal); pageNumberFormat.AssignASCII(aDefPropVal);
} }
@ -716,14 +712,16 @@ nsSimplePageSequenceFrame::StartPrint(nsPresContext* aPresContext,
// //
// Get default font name and size to be used for the headers and footers // Get default font name and size to be used for the headers and footers
nsAutoString fontName; nsAutoString fontName;
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, NS_LITERAL_STRING("fontname").get(), fontName); rv = nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES,
"fontname", fontName);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
fontName.AssignLiteral("serif"); fontName.AssignLiteral("serif");
} }
nsAutoString fontSizeStr; nsAutoString fontSizeStr;
nscoord pointSize = 10;; nscoord pointSize = 10;;
rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, NS_LITERAL_STRING("fontsize").get(), fontSizeStr); rv = nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES,
"fontsize", fontSizeStr);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
PRInt32 errCode; PRInt32 errCode;
pointSize = fontSizeStr.ToInteger(&errCode); pointSize = fontSizeStr.ToInteger(&errCode);

Просмотреть файл

@ -97,8 +97,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
#include "nsIPrintingPromptService.h" #include "nsIPrintingPromptService.h"
static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingprompt-service;1"; static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingprompt-service;1";
#define NS_ERROR_GFX_PRINTER_BUNDLE_URL "chrome://global/locale/printing.properties"
// Printing Timer // Printing Timer
#include "nsPagePrintTimer.h" #include "nsPagePrintTimer.h"
@ -2199,23 +2197,7 @@ nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting)
PR_PL(("nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError=%lx, PRBool aIsPrinting=%d)\n", (long)aPrintError, (int)aIsPrinting)); PR_PL(("nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError=%lx, PRBool aIsPrinting=%d)\n", (long)aPrintError, (int)aIsPrinting));
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); nsCAutoString stringName;
nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(kCStringBundleServiceCID);
if (!stringBundleService) {
PR_PL(("ShowPrintErrorDialog: Failed to get StringBundle Service instance.\n"));
return;
}
nsCOMPtr<nsIStringBundle> myStringBundle;
nsresult rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle));
if (NS_FAILED(rv)) {
PR_PL(("ShowPrintErrorDialog(): CreateBundle() failure for NS_ERROR_GFX_PRINTER_BUNDLE_URL, rv=%lx\n", (long)rv));
return;
}
nsXPIDLString msg,
title;
nsAutoString stringName;
switch(aPrintError) switch(aPrintError)
{ {
@ -2264,20 +2246,22 @@ nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting)
#undef NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG #undef NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG
} }
PR_PL(("ShowPrintErrorDialog: stringName='%s'\n", NS_LossyConvertUCS2toASCII(stringName).get())); PR_PL(("ShowPrintErrorDialog: stringName='%s'\n", stringName.get()));
myStringBundle->GetStringFromName(stringName.get(), getter_Copies(msg)); nsString msg, title;
if (aIsPrinting) { nsresult rv =
myStringBundle->GetStringFromName(NS_LITERAL_STRING("print_error_dialog_title").get(), getter_Copies(title)); nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES,
} else { stringName.get(), msg);
myStringBundle->GetStringFromName(NS_LITERAL_STRING("printpreview_error_dialog_title").get(), getter_Copies(title)); if (NS_FAILED(rv)) {
} PR_PL(("GetLocalizedString failed\n"));
if (!msg) {
PR_PL(("ShowPrintErrorDialog(): msg==nsnull\n"));
return; return;
} }
rv = nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES,
aIsPrinting ? "print_error_dialog_title"
: "printpreview_error_dialog_title",
title);
nsCOMPtr<nsIWindowWatcher> wwatch = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); nsCOMPtr<nsIWindowWatcher> wwatch = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
PR_PL(("ShowPrintErrorDialog(): wwatch==nsnull\n")); PR_PL(("ShowPrintErrorDialog(): wwatch==nsnull\n"));
@ -2296,7 +2280,7 @@ nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting)
return; return;
} }
dialog->Alert(title, msg); dialog->Alert(title.get(), msg.get());
PR_PL(("ShowPrintErrorDialog(): alert displayed successfully.\n")); PR_PL(("ShowPrintErrorDialog(): alert displayed successfully.\n"));
} }