зеркало из https://github.com/mozilla/pjs.git
Fix for bug 195481. Automatic image resize: Image status should be reflected in document title bar and Tab marker.
r=bz, sr=jag
This commit is contained in:
Родитель
f2912cb0b1
Коммит
6da7d33496
|
@ -34,3 +34,6 @@ MediaTitleWithFile=%S (%S Object)
|
|||
MediaTitleWithNoInfo=(%S Object)
|
||||
|
||||
InvalidImage=The image \u201c%S\u201d cannot be displayed, because it contains errors.
|
||||
ScaledImage=Scaled (%S%%)
|
||||
|
||||
TitleWithStatus=%S - %S
|
||||
|
|
|
@ -114,6 +114,11 @@ protected:
|
|||
|
||||
void UpdateTitleAndCharset();
|
||||
|
||||
float GetRatio() {
|
||||
return PR_MIN((float)mVisibleWidth / mImageWidth,
|
||||
(float)mVisibleHeight / mImageHeight);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMElement> mImageElement;
|
||||
|
||||
PRInt32 mVisibleWidth;
|
||||
|
@ -219,7 +224,6 @@ nsImageDocument::Init()
|
|||
mImageResizingEnabled = temp;
|
||||
}
|
||||
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -321,15 +325,14 @@ nsImageDocument::ShrinkToFit()
|
|||
{
|
||||
if (mImageResizingEnabled) {
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> image = do_QueryInterface(mImageElement);
|
||||
|
||||
float ratio = PR_MIN((float)mVisibleWidth / mImageWidth,
|
||||
(float)mVisibleHeight / mImageHeight);
|
||||
image->SetWidth(NSToCoordFloor(mImageWidth * ratio));
|
||||
image->SetWidth(NSToCoordFloor(GetRatio() * mImageWidth));
|
||||
|
||||
mImageElement->SetAttribute(NS_LITERAL_STRING("style"),
|
||||
NS_LITERAL_STRING("cursor: move"));
|
||||
|
||||
mImageIsResized = PR_TRUE;
|
||||
|
||||
UpdateTitleAndCharset();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -345,6 +348,8 @@ nsImageDocument::RestoreImage()
|
|||
}
|
||||
|
||||
mImageIsResized = PR_FALSE;
|
||||
|
||||
UpdateTitleAndCharset();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -600,6 +605,18 @@ nsImageDocument::UpdateTitleAndCharset()
|
|||
typeStr = mimeType;
|
||||
}
|
||||
}
|
||||
|
||||
nsXPIDLString status;
|
||||
if (mImageIsResized) {
|
||||
nsAutoString ratioStr;
|
||||
ratioStr.AppendInt(NSToCoordFloor(GetRatio() * 100));
|
||||
|
||||
const PRUnichar* formatString[1] = { ratioStr.get() };
|
||||
mStringBundle->FormatStringFromName(NS_LITERAL_STRING("ScaledImage").get(),
|
||||
formatString, 1,
|
||||
getter_Copies(status));
|
||||
}
|
||||
|
||||
static const char* const formatNames[4] =
|
||||
{
|
||||
"ImageTitleWithNeitherDimensionsNorFile",
|
||||
|
@ -608,8 +625,8 @@ nsImageDocument::UpdateTitleAndCharset()
|
|||
"ImageTitleWithDimensionsAndFile",
|
||||
};
|
||||
|
||||
nsMediaDocument::UpdateTitleAndCharset(typeStr, formatNames,
|
||||
mImageWidth, mImageHeight);
|
||||
nsMediaDocument::UpdateTitleAndCharset(typeStr, formatNames,
|
||||
mImageWidth, mImageHeight, status);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -242,9 +242,10 @@ nsMediaDocument::StartLayout()
|
|||
}
|
||||
|
||||
void
|
||||
nsMediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
|
||||
const char* const* aFormatNames,
|
||||
PRInt32 aWidth, PRInt32 aHeight)
|
||||
nsMediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
|
||||
const char* const* aFormatNames,
|
||||
PRInt32 aWidth, PRInt32 aHeight,
|
||||
const nsAString& aStatus)
|
||||
{
|
||||
nsXPIDLString fileStr;
|
||||
nsCOMPtr<nsIURI> uri = do_QueryInterface(mDocumentURL);
|
||||
|
@ -287,14 +288,14 @@ nsMediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
|
|||
const PRUnichar *formatStrings[4] = {fileStr.get(), typeStr.get(),
|
||||
widthStr.get(), heightStr.get()};
|
||||
NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithDimAndFile]);
|
||||
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 4,
|
||||
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,
|
||||
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 3,
|
||||
getter_Copies(title));
|
||||
}
|
||||
}
|
||||
|
@ -303,18 +304,29 @@ nsMediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
|
|||
if (!fileStr.IsEmpty()) {
|
||||
const PRUnichar *formatStrings[2] = {fileStr.get(), typeStr.get()};
|
||||
NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithFile]);
|
||||
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
|
||||
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
|
||||
getter_Copies(title));
|
||||
}
|
||||
}
|
||||
else {
|
||||
const PRUnichar *formatStrings[1] = {typeStr.get()};
|
||||
const PRUnichar *formatStrings[1] = {typeStr.get()};
|
||||
NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithNoInfo]);
|
||||
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 1,
|
||||
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 1,
|
||||
getter_Copies(title));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set it on the document
|
||||
SetTitle(title);
|
||||
if (aStatus.IsEmpty()) {
|
||||
SetTitle(title);
|
||||
}
|
||||
else {
|
||||
nsXPIDLString titleWithStatus;
|
||||
const nsPromiseFlatString& status = PromiseFlatString(aStatus);
|
||||
const PRUnichar *formatStrings[2] = {title.get(), status.get()};
|
||||
NS_NAMED_LITERAL_STRING(fmtName, "TitleWithStatus");
|
||||
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
|
||||
getter_Copies(titleWithStatus));
|
||||
SetTitle(titleWithStatus);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,13 +78,14 @@ protected:
|
|||
// 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,
|
||||
void UpdateTitleAndCharset(const nsACString& aTypeStr,
|
||||
const char* const* aFormatNames = sFormatNames,
|
||||
PRInt32 aWidth = 0,
|
||||
PRInt32 aHeight = 0);
|
||||
PRInt32 aWidth = 0,
|
||||
PRInt32 aHeight = 0,
|
||||
const nsAString& aStatus = NS_LITERAL_STRING(""));
|
||||
|
||||
nsCOMPtr<nsIStringBundle> mStringBundle;
|
||||
static const char* const sFormatNames[4];
|
||||
static const char* const sFormatNames[4];
|
||||
|
||||
private:
|
||||
enum {eWithNoInfo, eWithFile, eWithDim, eWithDimAndFile};
|
||||
|
|
Загрузка…
Ссылка в новой задаче