Cancel button inoperative on "Download Font" dialog
r/sr=jag,bienvenu
initial patch by smontagu@netscape.com
This commit is contained in:
sspitzer%netscape.com 2003-06-12 03:27:20 +00:00
Родитель b56a675840
Коммит ee553ff8fe
5 изменённых файлов: 53 добавлений и 74 удалений

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

@ -49,6 +49,10 @@ enum {
eInstalled
};
/* Keep the languages handled here in sync with handled_languages in
* mozilla/xpfe/global/resources/content/fontpackage.properties
* and the contents of http://www.mozilla.org/projects/intl/fonts/win/redirect/
*/
static PRInt8 mJAState = eInit;
static PRInt8 mKOState = eInit;
static PRInt8 mZHTWState = eInit;
@ -114,7 +118,7 @@ nsresult nsFontPackageService::CallDownload(const char *aFontPackID, PRInt8 aInS
const char *langID = &aFontPackID[5];
rv = fontEnum->HaveFontFor(langID, &have);
if (NS_SUCCEEDED(rv)) {
if (!have) {
if (!have) {
*aOutState = eDownload;
rv = mHandler->NeedFontPackage(aFontPackID);
if (rv == NS_ERROR_ABORT) {

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

@ -21,6 +21,8 @@
*
* Contributor(s):
* Roy Yokoyama <yokoyama@netscape.com>
* Simon Montagu <smontagu@netscape.com>
* Seth Spitzer <sspitzer@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -40,25 +42,18 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIServiceManager.h"
#include "nsIURI.h"
#include "nsIDOMWindow.h"
#include "nsIFontPackageService.h"
#include "nsIFontPackageHandler.h"
#include "nsILocale.h"
#include "nsTextFormatter.h"
#include "nsIStringBundle.h"
#include "nsIWindowWatcher.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsFontPackageHandler.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIWindowMediator.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define FONTPACKAGE_REGIONAL_URL "chrome://global-region/locale/region.properties"
#include "nsISupportsPrimitives.h"
#include "nsIStringBundle.h"
//==============================================================================
/* Implementation file */
@ -78,9 +73,38 @@ NS_IMETHODIMP nsFontPackageHandler::NeedFontPackage(const char *aFontPackID)
// no FontPackage is passed, return
NS_ENSURE_ARG_POINTER(aFontPackID);
if (!strlen(aFontPackID))
return NS_ERROR_UNEXPECTED;
nsresult rv;
nsCOMPtr <nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr <nsIStringBundle> bundle;
rv = bundleService->CreateBundle("chrome://global/locale/fontpackage.properties", getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv,rv);
nsXPIDLString handledLanguages;
rv = bundle->GetStringFromName(NS_LITERAL_STRING("handled_languages").get(), getter_Copies(handledLanguages));
NS_ENSURE_SUCCESS(rv, rv);
// aFontPackID is of the form lang:xx or lang:xx-YY
const char *colonPos = strchr(aFontPackID,':');
if (!colonPos || !*(colonPos + 1))
return NS_ERROR_UNEXPECTED;
// turn (const char *)xx-YY into (PRUnichar *)xx-yy
nsAutoString langCode;
CopyASCIItoUCS2(nsDependentCString(colonPos + 1), langCode);
ToLowerCase(langCode);
// check for xx or xx-yy in handled_languages
// if not handled, return now, don't show the font dialog
if (!FindInReadable(langCode, handledLanguages))
return NS_OK; // XXX should be error?
// check whether the topmost window is a mailnews window. If it is,
// or if any of the calls fail, return NS_ERROR_ABORT
nsresult rv;
nsCOMPtr<nsIWindowMediator> windowMediator = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, NS_ERROR_ABORT);
@ -121,65 +145,24 @@ NS_IMETHODIMP nsFontPackageHandler::NeedFontPackage(const char *aFontPackID)
}
}
nsXPIDLCString absUrl;
rv = CreateURLString(aFontPackID, getter_Copies(absUrl));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIWindowWatcher> windowWatch = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIWindowWatcher> windowWatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
NS_ENSURE_TRUE(windowWatch, NS_ERROR_FAILURE);
nsCOMPtr<nsISupportsString> langID = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
langID->SetData(langCode);
nsCOMPtr<nsIDOMWindow> dialog;
rv = windowWatch->OpenWindow(nsnull, absUrl,
rv = windowWatch->OpenWindow(nsnull, "chrome://global/content/fontpackage.xul",
"_blank",
"chrome,centerscreen,titlebar,resizable",
nsnull,
"chrome,centerscreen,titlebar,resizeable=no", // XXX should this be modal?
langID,
getter_AddRefs(dialog));
nsCOMPtr<nsIFontPackageService> fontService(do_GetService(NS_FONTPACKAGESERVICE_CONTRACTID));
NS_ENSURE_TRUE(fontService, NS_ERROR_FAILURE);
fontService->FontPackageHandled(NS_SUCCEEDED(rv), PR_FALSE, aFontPackID);
return rv;
}
nsresult nsFontPackageHandler::CreateURLString(const char *aPackID, char **aURL)
{
nsresult rv = NS_OK;
NS_ASSERTION(aPackID, "illegal value- null ptr- aPackID");
NS_ASSERTION(aURL, "illegal value- null ptr- aURL");
if (strlen(aPackID) <= 5)
return NS_ERROR_INVALID_ARG;
nsCOMPtr<nsIStringBundleService> strings(do_GetService(kStringBundleServiceCID));
nsCOMPtr<nsIStringBundle> bundle;
// get the font downloading URL from properties file
rv = strings->CreateBundle(FONTPACKAGE_REGIONAL_URL, getter_AddRefs(bundle));
if (NS_FAILED(rv))
return rv;
nsXPIDLString fontURL;
bundle->GetStringFromName(NS_LITERAL_STRING("fontDownloadURL").get(),
getter_Copies(fontURL));
if (!fontURL.get()) {
NS_ERROR("No item is found. Check chrome://global-region/locale/region.properties");
return NS_ERROR_FAILURE;
}
// aPackID="lang:xxxx", strip "lang:" and get the actual langID
const char *langID = &aPackID[5];
PRUnichar *urlString = nsnull;
urlString = nsTextFormatter::smprintf(fontURL.get(), langID);
if (!urlString) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aURL = ToNewUTF8String(nsDependentString(urlString));
nsTextFormatter::smprintf_free(urlString);
return NS_OK;
}

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

@ -73,6 +73,8 @@ toolkit.jar:
content/global/bindings/tree.xml (resources/content/bindings/tree.xml)
content/global/bindings/wizard.xml (resources/content/bindings/wizard.xml)
content/global/buildconfig.html (buildconfig.html)
content/global/fontpackage.xul (resources/content/fontpackage.xul)
content/global/fontpackage.js (resources/content/fontpackage.js)
en-US.jar:
locale/en-US/global/contents.rdf (resources/locale/en-US/contents.rdf)
@ -101,6 +103,8 @@ en-US.jar:
locale/en-US/global/printdialog.dtd (resources/locale/en-US/printdialog.dtd)
locale/en-US/global/printProgress.dtd (resources/locale/en-US/printProgress.dtd)
locale/en-US/global/printPreviewProgress.dtd (resources/locale/en-US/printPreviewProgress.dtd)
locale/en-US/global/fontpackage.dtd (resources/locale/en-US/fontpackage.dtd)
locale/en-US/global/fontpackage.properties (resources/locale/en-US/fontpackage.properties)
US.jar:
locale/US/global-region/contents.rdf (resources/locale/en-US/contents-region.rdf)

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

@ -1,6 +0,0 @@
<!ENTITY window.title "Download Font">
<!ENTITY info.label "To display language characters correctly, you need to install the following components:">
<!ENTITY size.label "Download Size:">
<!ENTITY downloadbutton.label "Download Font">
<!ENTITY cancelbutton.label "Cancel">
<!ENTITY install "Use the Regional Options Control Panel to install these components.">

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

@ -7,9 +7,3 @@ pluginStartupMessage=Starting Plugin for type
#
getNewThemesURL=http://mozilla.org/themes/download/
smartBrowsingURL=http://www.mozilla.org/docs/end-user/internet-keywords.html
#
# fontdownload.properties
#
fontDownloadURL=http://www.mozilla.org/projects/intl/fonts/win/en/package_%1$s.xul