bug 198598 Update the window title bar and doc. charset for nsMediaDocument

so that save/save as works correctly for non-8859-1 string. rename
ImageDocument.properties to MediaDocument.properties and move to
content/html/document/src. (r=cbiesinger for an earlier patch, sr=bzbarsky)


git-svn-id: svn://10.0.0.236/trunk@141073 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jshin%mailaps.org
2003-04-13 00:40:26 +00:00
parent 7585508ffb
commit b32399e610
9 changed files with 196 additions and 146 deletions

View File

@@ -0,0 +1 @@
MediaDocument.properties

View File

@@ -24,9 +24,13 @@
#LOCALIZATION NOTE (ImageTitleWithoutDimensions): first %S is filename, second %S is type
#LOCALIZATION NOTE (ImageTitleWithDimensions): first %S is type, second %S is width and third %S is height
#LOCALIZATION NOTE (ImageTitleWithNeitherDimensionsNorFile): first %S is type
#LOCALIZATION NOTE (MediaTitleWithFile): first %S is filename, second %S is type
#LOCALIZATION NOTE (MediaTitleWithNoInfo): first %S is type
ImageTitleWithDimensionsAndFile=%S (%S Image, %Sx%S pixels)
ImageTitleWithoutDimensions=%S (%S Image)
ImageTitleWithDimensions=(%S Image, %Sx%S pixels)
ImageTitleWithNeitherDimensionsNorFile=(%S Image)
MediaTitleWithFile=%S (%S Object)
MediaTitleWithNoInfo=(%S Object)
InvalidImage=The image \u201c%S\u201d cannot be displayed, because it contains errors.

View File

@@ -0,0 +1,2 @@
en-US.jar:
locale/en-US/communicator/layout/MediaDocument.properties

View File

@@ -52,17 +52,13 @@
#include "imgILoader.h"
#include "imgIContainer.h"
#include "imgIDecoderObserver.h"
#include "nsIURL.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsStyleContext.h"
#include "nsIStringBundle.h"
#include "nsIPrefService.h"
#include "nsITextToSubURI.h"
#include "nsAutoPtr.h"
#include "nsMediaDocument.h"
#define NSIMAGEDOCUMENT_PROPERTIES_URI "chrome://communicator/locale/layout/ImageDocument.properties"
#define AUTOMATIC_IMAGE_RESIZING_PREF "browser.enable_automatic_image_resizing"
class nsImageDocument;
@@ -89,8 +85,7 @@ public:
NS_DECL_ISUPPORTS
// nsIHTMLDocument
nsresult Init();
virtual nsresult Init();
NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
@@ -117,15 +112,14 @@ protected:
nsresult CheckOverflowing();
nsresult UpdateTitle();
void UpdateTitleAndCharset();
nsCOMPtr<nsIStringBundle> mStringBundle;
nsCOMPtr<nsIDOMElement> mImageElement;
nscoord mVisibleWidth;
nscoord mVisibleHeight;
nscoord mImageWidth;
nscoord mImageHeight;
PRInt32 mVisibleWidth;
PRInt32 mVisibleHeight;
PRInt32 mImageWidth;
PRInt32 mImageHeight;
PRPackedBool mImageResizingEnabled;
PRPackedBool mImageIsOverflowing;
@@ -174,7 +168,7 @@ ImageListener::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
{
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
nsImageDocument *imgDoc = (nsImageDocument*)mDocument.get();
imgDoc->UpdateTitle();
imgDoc->UpdateTitleAndCharset();
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(imgDoc->mImageElement);
NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
@@ -215,7 +209,7 @@ NS_INTERFACE_MAP_END_INHERITING(nsMediaDocument)
nsresult
nsImageDocument::Init()
{
nsresult rv = nsHTMLDocument::Init();
nsresult rv = nsMediaDocument::Init();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
@@ -225,13 +219,6 @@ nsImageDocument::Init()
mImageResizingEnabled = temp;
}
// Create a bundle for the localization
nsCOMPtr<nsIStringBundleService> stringService(
do_GetService(NS_STRINGBUNDLE_CONTRACTID));
if (stringService) {
stringService->CreateBundle(NSIMAGEDOCUMENT_PROPERTIES_URI,
getter_AddRefs(mStringBundle));
}
return NS_OK;
}
@@ -574,127 +561,55 @@ nsImageDocument::CheckOverflowing()
return NS_OK;
}
nsresult
nsImageDocument::UpdateTitle()
void
nsImageDocument::UpdateTitleAndCharset()
{
if (mStringBundle) {
nsXPIDLString fileStr;
nsAutoString widthStr;
nsAutoString heightStr;
nsAutoString typeStr;
nsXPIDLString valUni;
nsCOMPtr<nsIURL> url = do_QueryInterface(mDocumentURL);
if (url) {
nsresult rv;
nsCAutoString fileName;
url->GetFileName(fileName);
nsCOMPtr<nsITextToSubURI> textToSubURI =
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
{
nsCAutoString originCharset;
rv = url->GetOriginCharset(originCharset);
if (NS_SUCCEEDED(rv))
rv = textToSubURI->UnEscapeURIForUI(originCharset, fileName, fileStr);
}
if (NS_FAILED(rv))
fileStr.Assign(NS_ConvertUTF8toUCS2(fileName));
}
widthStr.AppendInt(mImageWidth);
heightStr.AppendInt(mImageHeight);
nsCOMPtr<imgIRequest> imageRequest;
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageElement);
if (imageLoader) {
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
getter_AddRefs(imageRequest));
}
nsCAutoString typeStr;
nsCOMPtr<imgIRequest> imageRequest;
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mImageElement);
if (imageLoader) {
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
getter_AddRefs(imageRequest));
}
if (imageRequest) {
nsXPIDLCString mimeType;
imageRequest->GetMimeType(getter_Copies(mimeType));
ToUpperCase(mimeType);
nsXPIDLCString::const_iterator start, end;
mimeType.BeginReading(start);
mimeType.EndReading(end);
nsXPIDLCString::const_iterator iter = end;
if (FindInReadable(NS_LITERAL_CSTRING("IMAGE/"), start, iter) &&
iter != end) {
// strip out "X-" if any
if (*iter == 'X') {
if (imageRequest) {
nsXPIDLCString mimeType;
imageRequest->GetMimeType(getter_Copies(mimeType));
ToUpperCase(mimeType);
nsXPIDLCString::const_iterator start, end;
mimeType.BeginReading(start);
mimeType.EndReading(end);
nsXPIDLCString::const_iterator iter = end;
if (FindInReadable(NS_LITERAL_CSTRING("IMAGE/"), start, iter) &&
iter != end) {
// strip out "X-" if any
if (*iter == 'X') {
++iter;
if (iter != end && *iter == '-') {
++iter;
if (iter != end && *iter == '-') {
++iter;
if (iter == end) {
// looks like "IMAGE/X-" is the type?? Bail out of here.
mimeType.BeginReading(iter);
}
} else {
--iter;
if (iter == end) {
// looks like "IMAGE/X-" is the type?? Bail out of here.
mimeType.BeginReading(iter);
}
} else {
--iter;
}
CopyASCIItoUCS2(Substring(iter, end), typeStr);
} else {
CopyASCIItoUCS2(mimeType, typeStr);
}
}
// If we got a filename, display it
if (!fileStr.IsEmpty()) {
// if we got a valid size (sometimes we do not) then display it
if (mImageWidth != 0 && mImageHeight != 0){
const PRUnichar *formatStrings[4] =
{
fileStr.get(),
typeStr.get(),
widthStr.get(),
heightStr.get()
};
NS_NAMED_LITERAL_STRING(str, "ImageTitleWithDimensionsAndFile");
mStringBundle->FormatStringFromName(str.get(), formatStrings, 4,
getter_Copies(valUni));
} else {
const PRUnichar *formatStrings[2] =
{
fileStr.get(),
typeStr.get()
};
NS_NAMED_LITERAL_STRING(str, "ImageTitleWithoutDimensions");
mStringBundle->FormatStringFromName(str.get(), formatStrings, 2,
getter_Copies(valUni));
}
typeStr = Substring(iter, end);
} else {
// if we got a valid size (sometimes we do not) then display it
if (mImageWidth != 0 && mImageHeight != 0){
const PRUnichar *formatStrings[3] =
{
typeStr.get(),
widthStr.get(),
heightStr.get()
};
NS_NAMED_LITERAL_STRING(str, "ImageTitleWithDimensions");
mStringBundle->FormatStringFromName(str.get(), formatStrings, 3,
getter_Copies(valUni));
} else {
const PRUnichar *formatStrings[1] =
{
typeStr.get()
};
NS_NAMED_LITERAL_STRING(str, "ImageTitleWithNeitherDimensionsNorFile");
mStringBundle->FormatStringFromName(str.get(), formatStrings, 1,
getter_Copies(valUni));
}
}
if (valUni) {
// set it on the document
SetTitle(valUni);
typeStr = mimeType;
}
}
static const char* const formatNames[4] =
{
"ImageTitleWithNeitherDimensionsNorFile",
"ImageTitleWithoutDimensions",
"ImageTitleWithDimesions",
"ImageTitleWithDimensionsAndFile",
};
return NS_OK;
nsMediaDocument::UpdateTitleAndCharset(typeStr, formatNames,
mImageWidth, mImageHeight);
}

View File

@@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jungshik Shin <jshin@mailaps.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -42,6 +43,9 @@
#include "nsIPresShell.h"
#include "nsIScrollable.h"
#include "nsIViewManager.h"
#include "nsITextToSubURI.h"
#include "nsIURL.h"
#include "nsPrintfCString.h"
nsMediaDocumentStreamListener::nsMediaDocumentStreamListener(nsMediaDocument *aDocument)
{
@@ -108,6 +112,15 @@ nsMediaDocumentStreamListener::OnDataAvailable(nsIRequest* request,
return NS_OK;
}
// default format names for nsMediaDocument.
const char* const nsMediaDocument::sFormatNames[4] =
{
"MediaTitleWithNoInfo", // eWithNoInfo
"MediaTitleWithFile", // eWithFile
"", // eWithDim
"" // eWithDimAndFile
};
nsMediaDocument::nsMediaDocument()
{
}
@@ -115,6 +128,23 @@ nsMediaDocument::~nsMediaDocument()
{
}
nsresult
nsMediaDocument::Init()
{
nsresult rv = nsHTMLDocument::Init();
NS_ENSURE_SUCCESS(rv, rv);
// Create a bundle for the localization
nsCOMPtr<nsIStringBundleService> stringService(
do_GetService(NS_STRINGBUNDLE_CONTRACTID));
if (stringService) {
stringService->CreateBundle(NSMEDIADOCUMENT_PROPERTIES_URI,
getter_AddRefs(mStringBundle));
}
return NS_OK;
}
NS_IMETHODIMP
nsMediaDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
@@ -210,3 +240,81 @@ nsMediaDocument::StartLayout()
return NS_OK;
}
void
nsMediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
const char* const* aFormatNames,
PRInt32 aWidth, PRInt32 aHeight)
{
nsXPIDLString fileStr;
nsCOMPtr<nsIURI> uri = do_QueryInterface(mDocumentURL);
if (uri) {
nsCAutoString originCharset;
uri->GetOriginCharset(originCharset);
nsCAutoString fileName;
nsCOMPtr<nsIURL> url = do_QueryInterface(uri);
if (url)
url->GetFileName(fileName);
if (!originCharset.IsEmpty()) {
// set doc. charset to that of the referring document if known so that
// filepicker comes up with the correct non-ascii filename.
SetDocumentCharacterSet(NS_ConvertASCIItoUCS2(originCharset));
if (!fileName.IsEmpty()) {
nsresult rv;
nsCOMPtr<nsITextToSubURI> textToSubURI =
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
rv = textToSubURI->UnEscapeURIForUI(originCharset, fileName, fileStr);
}
}
if (fileStr.IsEmpty())
fileStr.Assign(NS_ConvertUTF8toUCS2(fileName));
}
NS_ConvertASCIItoUCS2 typeStr(aTypeStr);
nsXPIDLString title;
if (mStringBundle) {
// if we got a valid size (not all media have a size)
if (aWidth != 0 && aHeight != 0) {
nsAutoString widthStr;
nsAutoString heightStr;
widthStr.AppendInt(aWidth);
heightStr.AppendInt(aHeight);
// If we got a filename, display it
if (!fileStr.IsEmpty()) {
const PRUnichar *formatStrings[4] = {fileStr.get(), typeStr.get(),
widthStr.get(), heightStr.get()};
NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithDimAndFile]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 4,
getter_Copies(title));
}
else {
const PRUnichar *formatStrings[3] = {typeStr.get(), widthStr.get(),
heightStr.get()};
NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithDim]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 3,
getter_Copies(title));
}
}
else {
// If we got a filename, display it
if (!fileStr.IsEmpty()) {
const PRUnichar *formatStrings[2] = {fileStr.get(), typeStr.get()};
NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithFile]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
getter_Copies(title));
}
else {
const PRUnichar *formatStrings[1] = {typeStr.get()};
NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithNoInfo]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 1,
getter_Copies(title));
}
}
}
// set it on the document
SetTitle(title);
}

View File

@@ -41,6 +41,9 @@
#include "nsHTMLDocument.h"
#include "nsGenericHTMLElement.h"
#include "nsAutoPtr.h"
#include "nsIStringBundle.h"
#define NSMEDIADOCUMENT_PROPERTIES_URI "chrome://communicator/locale/layout/MediaDocument.properties"
class nsMediaDocument : public nsHTMLDocument
{
@@ -48,6 +51,8 @@ public:
nsMediaDocument();
virtual ~nsMediaDocument();
virtual nsresult Init();
NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
@@ -61,6 +66,28 @@ protected:
friend class nsMediaDocumentStreamListener;
nsresult StartLayout();
// |aFormatNames[]| needs to have four elements in the following order:
// a format name with neither dimension nor file, a format name with
// filename but w/o dimension, a format name with dimension but w/o filename,
// a format name with both of them. For instance, it can have
// "ImageTitleWithNeitherDimensionsNorFile", "ImageTitleWithoutDimensions",
// "ImageTitleWithDimesions", "ImageTitleWithDimensionsAndFile".
//
// Also see MediaDocument.properties if you want to define format names
// for a new subclass. aWidth and aHeight are pixels for |nsImageDocument|,
// but could be in other units for other 'media', in which case you have to
// define format names accordingly.
void UpdateTitleAndCharset(const nsACString& aTypeStr,
const char* const* aFormatNames = sFormatNames,
PRInt32 aWidth = 0,
PRInt32 aHeight = 0);
nsCOMPtr<nsIStringBundle> mStringBundle;
static const char* const sFormatNames[4];
private:
enum {eWithNoInfo, eWithFile, eWithDim, eWithDimAndFile};
};

View File

@@ -64,10 +64,11 @@ public:
NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
protected:
nsresult CreateSyntheticPluginDocument(nsACString &aMimeType);
nsresult CreateSyntheticPluginDocument();
nsCOMPtr<nsIHTMLContent> mPluginContent;
nsRefPtr<nsMediaDocumentStreamListener> mStreamListener;
nsCString mMimeType;
};
@@ -76,10 +77,6 @@ protected:
nsPluginDocument::nsPluginDocument()
{
// NOTE! nsDocument::operator new() zeroes out all members, so don't
// bother initializing members to 0.
}
nsPluginDocument::~nsPluginDocument()
@@ -121,14 +118,13 @@ nsPluginDocument::StartDocumentLoad(const char* aCommand,
return rv;
}
nsCAutoString mimeType;
rv = aChannel->GetContentType(mimeType);
rv = aChannel->GetContentType(mMimeType);
if (NS_FAILED(rv)) {
return rv;
}
// Create synthetic document
rv = CreateSyntheticPluginDocument(mimeType);
rv = CreateSyntheticPluginDocument();
if (NS_FAILED(rv)) {
return rv;
}
@@ -143,7 +139,7 @@ nsPluginDocument::StartDocumentLoad(const char* aCommand,
}
nsresult
nsPluginDocument::CreateSyntheticPluginDocument(nsACString &aMimeType)
nsPluginDocument::CreateSyntheticPluginDocument()
{
// do not allow message panes to host full-page plugins
// returning an error causes helper apps to take over
@@ -202,7 +198,7 @@ nsPluginDocument::CreateSyntheticPluginDocument(nsACString &aMimeType)
mPluginContent->SetHTMLAttribute(nsHTMLAtoms::src, val, PR_FALSE);
// set mime type
val.SetStringValue(NS_ConvertUTF8toUCS2(aMimeType));
val.SetStringValue(NS_ConvertUTF8toUCS2(mMimeType));
mPluginContent->SetHTMLAttribute(nsHTMLAtoms::type, val, PR_FALSE);
body->AppendChildTo(mPluginContent, PR_FALSE, PR_FALSE);
@@ -218,8 +214,7 @@ nsPluginDocument::SetStreamListener(nsIStreamListener *aListener)
if (mStreamListener)
mStreamListener->SetStreamListener(aListener);
nsAutoString title;
SetTitle(title);
nsMediaDocument::UpdateTitleAndCharset(mMimeType);
return NS_OK;
}

View File

@@ -1,2 +1 @@
HtmlForm.properties
ImageDocument.properties

View File

@@ -1,5 +1,4 @@
en-US.jar:
locale/en-US/communicator/layout/HtmlForm.properties
locale/en-US/communicator/layout/ImageDocument.properties