mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 889219. Part 1: Clean up nsPrintEngine string usage for document titles/URLs. r=mats
--HG-- extra : rebase_source : 17a67d9956e9df9e19c86ea70ac3045e636c49ae
This commit is contained in:
parent
5ced2fb4ac
commit
9dfcbeeab2
@ -472,15 +472,15 @@ nsDeviceContext::InitForPrinting(nsIDeviceContextSpec *aDevice)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDeviceContext::BeginDocument(PRUnichar* aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage)
|
||||
nsDeviceContext::BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage)
|
||||
{
|
||||
static const PRUnichar kEmpty[] = { '\0' };
|
||||
nsresult rv;
|
||||
|
||||
rv = mPrintingSurface->BeginPrinting(nsDependentString(aTitle ? aTitle : kEmpty),
|
||||
rv = mPrintingSurface->BeginPrinting(aTitle,
|
||||
nsDependentString(aPrintToFileName ? aPrintToFileName : kEmpty));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && mDeviceContextSpec)
|
||||
|
@ -171,10 +171,10 @@ public:
|
||||
*
|
||||
* @return error status
|
||||
*/
|
||||
nsresult BeginDocument(PRUnichar *aTitle,
|
||||
PRUnichar *aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage);
|
||||
nsresult BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage);
|
||||
|
||||
/**
|
||||
* Inform the output device that output of a document is ending.
|
||||
|
@ -35,10 +35,10 @@ public:
|
||||
* and the start page is greater than the total number of pages
|
||||
* NS_ERROR_FAILURE if there is an error
|
||||
*/
|
||||
NS_IMETHOD StartPrint(nsPresContext* aPresContext,
|
||||
NS_IMETHOD StartPrint(nsPresContext* aPresContext,
|
||||
nsIPrintSettings* aPrintOptions,
|
||||
PRUnichar* aDocTitle,
|
||||
PRUnichar* aDocURL) = 0;
|
||||
const nsAString& aDocTitle,
|
||||
const nsAString& aDocURL) = 0;
|
||||
|
||||
NS_IMETHOD PrePrintNextPage(nsITimerCallback* aCallback, bool* aDone) = 0;
|
||||
NS_IMETHOD PrintNextPage() = 0;
|
||||
|
@ -221,20 +221,12 @@ nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
||||
|
||||
NS_NAMED_LITERAL_STRING(kTitle, "&T");
|
||||
if (aStr.Find(kTitle) != kNotFound) {
|
||||
if (mPD->mDocTitle != nullptr) {
|
||||
aNewStr.ReplaceSubstring(kTitle.get(), mPD->mDocTitle);
|
||||
} else {
|
||||
aNewStr.ReplaceSubstring(kTitle.get(), EmptyString().get());
|
||||
}
|
||||
aNewStr.ReplaceSubstring(kTitle.get(), mPD->mDocTitle.get());
|
||||
}
|
||||
|
||||
NS_NAMED_LITERAL_STRING(kDocURL, "&U");
|
||||
if (aStr.Find(kDocURL) != kNotFound) {
|
||||
if (mPD->mDocURL != nullptr) {
|
||||
aNewStr.ReplaceSubstring(kDocURL.get(), mPD->mDocURL);
|
||||
} else {
|
||||
aNewStr.ReplaceSubstring(kDocURL.get(), EmptyString().get());
|
||||
}
|
||||
aNewStr.ReplaceSubstring(kDocURL.get(), mPD->mDocURL.get());
|
||||
}
|
||||
|
||||
NS_NAMED_LITERAL_STRING(kPageTotal, "&L");
|
||||
|
@ -63,8 +63,6 @@ nsSharedPageData::nsSharedPageData() :
|
||||
mHeadFootFont(nullptr),
|
||||
mPageNumFormat(nullptr),
|
||||
mPageNumAndTotalsFormat(nullptr),
|
||||
mDocTitle(nullptr),
|
||||
mDocURL(nullptr),
|
||||
mReflowSize(0,0),
|
||||
mReflowMargin(0,0,0,0),
|
||||
mEdgePaperMargin(0,0,0,0),
|
||||
@ -79,8 +77,6 @@ nsSharedPageData::~nsSharedPageData()
|
||||
delete mHeadFootFont;
|
||||
nsMemory::Free(mPageNumFormat);
|
||||
nsMemory::Free(mPageNumAndTotalsFormat);
|
||||
if (mDocTitle) nsMemory::Free(mDocTitle);
|
||||
if (mDocURL) nsMemory::Free(mDocURL);
|
||||
}
|
||||
|
||||
nsIFrame*
|
||||
@ -403,10 +399,10 @@ nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSimplePageSequenceFrame::StartPrint(nsPresContext* aPresContext,
|
||||
nsSimplePageSequenceFrame::StartPrint(nsPresContext* aPresContext,
|
||||
nsIPrintSettings* aPrintSettings,
|
||||
PRUnichar* aDocTitle,
|
||||
PRUnichar* aDocURL)
|
||||
const nsAString& aDocTitle,
|
||||
const nsAString& aDocURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPresContext);
|
||||
NS_ENSURE_ARG_POINTER(aPrintSettings);
|
||||
@ -415,9 +411,12 @@ nsSimplePageSequenceFrame::StartPrint(nsPresContext* aPresContext,
|
||||
mPageData->mPrintSettings = aPrintSettings;
|
||||
}
|
||||
|
||||
// Only set them if they are not null
|
||||
if (aDocTitle) mPageData->mDocTitle = aDocTitle;
|
||||
if (aDocURL) mPageData->mDocURL = aDocURL;
|
||||
if (!aDocTitle.IsEmpty()) {
|
||||
mPageData->mDocTitle = aDocTitle;
|
||||
}
|
||||
if (!aDocURL.IsEmpty()) {
|
||||
mPageData->mDocURL = aDocURL;
|
||||
}
|
||||
|
||||
aPrintSettings->GetStartPageRange(&mFromPageNum);
|
||||
aPrintSettings->GetEndPageRange(&mToPageNum);
|
||||
|
@ -26,8 +26,8 @@ public:
|
||||
nsFont * mHeadFootFont;
|
||||
PRUnichar * mPageNumFormat;
|
||||
PRUnichar * mPageNumAndTotalsFormat;
|
||||
PRUnichar * mDocTitle;
|
||||
PRUnichar * mDocURL;
|
||||
nsString mDocTitle;
|
||||
nsString mDocURL;
|
||||
|
||||
nsSize mReflowSize;
|
||||
nsMargin mReflowMargin;
|
||||
@ -71,10 +71,10 @@ public:
|
||||
NS_IMETHOD GetSTFPercent(float& aSTFPercent) MOZ_OVERRIDE;
|
||||
|
||||
// Async Printing
|
||||
NS_IMETHOD StartPrint(nsPresContext* aPresContext,
|
||||
NS_IMETHOD StartPrint(nsPresContext* aPresContext,
|
||||
nsIPrintSettings* aPrintSettings,
|
||||
PRUnichar* aDocTitle,
|
||||
PRUnichar* aDocURL) MOZ_OVERRIDE;
|
||||
const nsAString& aDocTitle,
|
||||
const nsAString& aDocURL) MOZ_OVERRIDE;
|
||||
NS_IMETHOD PrePrintNextPage(nsITimerCallback* aCallback, bool* aDone) MOZ_OVERRIDE;
|
||||
NS_IMETHOD PrintNextPage() MOZ_OVERRIDE;
|
||||
NS_IMETHOD ResetPrintCanvasList() MOZ_OVERRIDE;
|
||||
|
@ -41,15 +41,6 @@ public:
|
||||
|
||||
typedef enum {eIsPrinting, eIsPrintPreview } ePrintDataType;
|
||||
|
||||
// This enum tells indicates what the default should be for the title
|
||||
// if the title from the document is null
|
||||
enum eDocTitleDefault {
|
||||
eDocTitleDefNone,
|
||||
eDocTitleDefBlank,
|
||||
eDocTitleDefURLDoc
|
||||
};
|
||||
|
||||
|
||||
nsPrintData(ePrintDataType aType);
|
||||
~nsPrintData(); // non-virtual
|
||||
|
||||
|
@ -906,26 +906,15 @@ nsPrintEngine::EnumerateDocumentNames(uint32_t* aCount,
|
||||
for (int32_t i=0;i<numDocs;i++) {
|
||||
nsPrintObject* po = mPrt->mPrintDocList.ElementAt(i);
|
||||
NS_ASSERTION(po, "nsPrintObject can't be null!");
|
||||
PRUnichar * docTitleStr;
|
||||
PRUnichar * docURLStr;
|
||||
GetDocumentTitleAndURL(po->mDocument, &docTitleStr, &docURLStr);
|
||||
nsAutoString docTitleStr;
|
||||
nsAutoString docURLStr;
|
||||
GetDocumentTitleAndURL(po->mDocument, docTitleStr, docURLStr);
|
||||
|
||||
// Use the URL if the doc is empty
|
||||
if (!docTitleStr || !*docTitleStr) {
|
||||
if (docURLStr && *docURLStr) {
|
||||
nsMemory::Free(docTitleStr);
|
||||
docTitleStr = docURLStr;
|
||||
} else {
|
||||
nsMemory::Free(docURLStr);
|
||||
}
|
||||
docURLStr = nullptr;
|
||||
if (!docTitleStr || !*docTitleStr) {
|
||||
CleanupDocTitleArray(array, i);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
if (docTitleStr.IsEmpty() && !docURLStr.IsEmpty()) {
|
||||
docTitleStr = docURLStr;
|
||||
}
|
||||
array[i] = docTitleStr;
|
||||
if (docURLStr) nsMemory::Free(docURLStr);
|
||||
array[i] = ToNewUnicode(docTitleStr);
|
||||
}
|
||||
*aCount = numDocs;
|
||||
*aResult = array;
|
||||
@ -1208,22 +1197,16 @@ nsPrintEngine::BuildDocTree(nsIDocShellTreeNode * aParentNode,
|
||||
//---------------------------------------------------------------------
|
||||
void
|
||||
nsPrintEngine::GetDocumentTitleAndURL(nsIDocument* aDoc,
|
||||
PRUnichar** aTitle,
|
||||
PRUnichar** aURLStr)
|
||||
nsAString& aTitle,
|
||||
nsAString& aURLStr)
|
||||
{
|
||||
NS_ASSERTION(aDoc, "Pointer is null!");
|
||||
NS_ASSERTION(aTitle, "Pointer is null!");
|
||||
NS_ASSERTION(aURLStr, "Pointer is null!");
|
||||
NS_ASSERTION(aDoc, "Pointer is null!");
|
||||
|
||||
*aTitle = nullptr;
|
||||
*aURLStr = nullptr;
|
||||
aTitle.Truncate();
|
||||
aURLStr.Truncate();
|
||||
|
||||
nsAutoString docTitle;
|
||||
nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(aDoc);
|
||||
doc->GetTitle(docTitle);
|
||||
if (!docTitle.IsEmpty()) {
|
||||
*aTitle = ToNewUnicode(docTitle);
|
||||
}
|
||||
doc->GetTitle(aTitle);
|
||||
|
||||
nsIURI* url = aDoc->GetDocumentURI();
|
||||
if (!url) return;
|
||||
@ -1244,12 +1227,8 @@ nsPrintEngine::GetDocumentTitleAndURL(nsIDocument* aDoc,
|
||||
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
nsAutoString unescapedURI;
|
||||
rv = textToSubURI->UnEscapeURIForUI(NS_LITERAL_CSTRING("UTF-8"),
|
||||
urlCStr, unescapedURI);
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
*aURLStr = ToNewUnicode(unescapedURI);
|
||||
textToSubURI->UnEscapeURIForUI(NS_LITERAL_CSTRING("UTF-8"),
|
||||
urlCStr, aURLStr);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
@ -1448,74 +1427,58 @@ nsPrintEngine::SetPrintPO(nsPrintObject* aPO, bool aPrint)
|
||||
// then if not title is there we will make sure we send something back
|
||||
// depending on the situation.
|
||||
void
|
||||
nsPrintEngine::GetDisplayTitleAndURL(nsPrintObject* aPO,
|
||||
PRUnichar** aTitle,
|
||||
PRUnichar** aURLStr,
|
||||
eDocTitleDefault aDefType)
|
||||
nsPrintEngine::GetDisplayTitleAndURL(nsPrintObject* aPO,
|
||||
nsAString& aTitle,
|
||||
nsAString& aURLStr,
|
||||
eDocTitleDefault aDefType)
|
||||
{
|
||||
NS_ASSERTION(aPO, "Pointer is null!");
|
||||
NS_ASSERTION(aTitle, "Pointer is null!");
|
||||
NS_ASSERTION(aURLStr, "Pointer is null!");
|
||||
|
||||
*aTitle = nullptr;
|
||||
*aURLStr = nullptr;
|
||||
|
||||
if (!mPrt)
|
||||
return;
|
||||
|
||||
aTitle.Truncate();
|
||||
aURLStr.Truncate();
|
||||
|
||||
// First check to see if the PrintSettings has defined an alternate title
|
||||
// and use that if it did
|
||||
PRUnichar * docTitleStrPS = nullptr;
|
||||
PRUnichar * docURLStrPS = nullptr;
|
||||
if (mPrt->mPrintSettings) {
|
||||
PRUnichar * docTitleStrPS = nullptr;
|
||||
PRUnichar * docURLStrPS = nullptr;
|
||||
mPrt->mPrintSettings->GetTitle(&docTitleStrPS);
|
||||
mPrt->mPrintSettings->GetDocURL(&docURLStrPS);
|
||||
|
||||
if (docTitleStrPS && *docTitleStrPS) {
|
||||
*aTitle = docTitleStrPS;
|
||||
if (docTitleStrPS) {
|
||||
aTitle = docTitleStrPS;
|
||||
}
|
||||
|
||||
if (docURLStrPS && *docURLStrPS) {
|
||||
*aURLStr = docURLStrPS;
|
||||
if (docURLStrPS) {
|
||||
aURLStr = docURLStrPS;
|
||||
}
|
||||
|
||||
// short circut
|
||||
if (docTitleStrPS && docURLStrPS) {
|
||||
return;
|
||||
}
|
||||
nsMemory::Free(docTitleStrPS);
|
||||
nsMemory::Free(docURLStrPS);
|
||||
}
|
||||
|
||||
PRUnichar* docTitle;
|
||||
PRUnichar* docUrl;
|
||||
GetDocumentTitleAndURL(aPO->mDocument, &docTitle, &docUrl);
|
||||
nsAutoString docTitle;
|
||||
nsAutoString docUrl;
|
||||
GetDocumentTitleAndURL(aPO->mDocument, docTitle, docUrl);
|
||||
|
||||
if (docUrl) {
|
||||
if (!docURLStrPS)
|
||||
*aURLStr = docUrl;
|
||||
else
|
||||
nsMemory::Free(docUrl);
|
||||
if (aURLStr.IsEmpty() && !docUrl.IsEmpty()) {
|
||||
aURLStr = docUrl;
|
||||
}
|
||||
|
||||
if (docTitle) {
|
||||
if (!docTitleStrPS)
|
||||
*aTitle = docTitle;
|
||||
else
|
||||
nsMemory::Free(docTitle);
|
||||
} else if (!docTitleStrPS) {
|
||||
switch (aDefType) {
|
||||
case eDocTitleDefBlank: *aTitle = ToNewUnicode(EmptyString());
|
||||
break;
|
||||
|
||||
case eDocTitleDefURLDoc:
|
||||
if (*aURLStr) {
|
||||
*aTitle = NS_strdup(*aURLStr);
|
||||
if (aTitle.IsEmpty()) {
|
||||
if (!docTitle.IsEmpty()) {
|
||||
aTitle = docTitle;
|
||||
} else {
|
||||
if (aDefType == eDocTitleDefURLDoc) {
|
||||
if (!aURLStr.IsEmpty()) {
|
||||
aTitle = aURLStr;
|
||||
} else if (mPrt->mBrandName) {
|
||||
*aTitle = NS_strdup(mPrt->mBrandName);
|
||||
aTitle = mPrt->mBrandName;
|
||||
}
|
||||
break;
|
||||
case eDocTitleDefNone:
|
||||
// *aTitle defaults to nullptr
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1804,9 +1767,9 @@ nsPrintEngine::SetupToPrintContent()
|
||||
mPrt->mPrintSettings->GetToFileName(&fileName);
|
||||
}
|
||||
|
||||
PRUnichar * docTitleStr;
|
||||
PRUnichar * docURLStr;
|
||||
GetDisplayTitleAndURL(mPrt->mPrintObject, &docTitleStr, &docURLStr, eDocTitleDefURLDoc);
|
||||
nsAutoString docTitleStr;
|
||||
nsAutoString docURLStr;
|
||||
GetDisplayTitleAndURL(mPrt->mPrintObject, docTitleStr, docURLStr, eDocTitleDefURLDoc);
|
||||
|
||||
int32_t startPage = 1;
|
||||
int32_t endPage = mPrt->mNumPrintablePages;
|
||||
@ -1831,18 +1794,14 @@ nsPrintEngine::SetupToPrintContent()
|
||||
}
|
||||
|
||||
if (mIsCreatingPrintPreview) {
|
||||
// Print Preview -- Pass ownership of docTitleStr and docURLStr
|
||||
// to the pageSequenceFrame, to be displayed in the header
|
||||
// Copy docTitleStr and docURLStr to the pageSequenceFrame, to be displayed
|
||||
// in the header
|
||||
nsIPageSequenceFrame *seqFrame = mPrt->mPrintObject->mPresShell->GetPageSequenceFrame();
|
||||
if (seqFrame) {
|
||||
seqFrame->StartPrint(mPrt->mPrintObject->mPresContext,
|
||||
mPrt->mPrintSettings, docTitleStr, docURLStr);
|
||||
docTitleStr = nullptr;
|
||||
docURLStr = nullptr;
|
||||
}
|
||||
}
|
||||
if (docTitleStr) nsMemory::Free(docTitleStr);
|
||||
if (docURLStr) nsMemory::Free(docURLStr);
|
||||
|
||||
PR_PL(("****************** Begin Document ************************\n"));
|
||||
|
||||
@ -2285,8 +2244,8 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
|
||||
|
||||
#ifdef EXTENDED_DEBUG_PRINTING
|
||||
if (kPrintingLogMod && kPrintingLogMod->level == DUMP_LAYOUT_LEVEL) {
|
||||
char * docStr;
|
||||
char * urlStr;
|
||||
nsAutoCString docStr;
|
||||
nsAutoCString urlStr;
|
||||
GetDocTitleAndURL(aPO, docStr, urlStr);
|
||||
char filename[256];
|
||||
sprintf(filename, "print_dump_%d.txt", gDumpFileNameCnt++);
|
||||
@ -2295,8 +2254,8 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
|
||||
if (fd) {
|
||||
nsIFrame *theRootFrame =
|
||||
aPO->mPresShell->FrameManager()->GetRootFrame();
|
||||
fprintf(fd, "Title: %s\n", docStr?docStr:"");
|
||||
fprintf(fd, "URL: %s\n", urlStr?urlStr:"");
|
||||
fprintf(fd, "Title: %s\n", docStr.get());
|
||||
fprintf(fd, "URL: %s\n", urlStr.get());
|
||||
fprintf(fd, "--------------- Frames ----------------\n");
|
||||
nsRefPtr<nsRenderingContext> renderingContext;
|
||||
mPrt->mPrintDocDC->CreateRenderingContext(*getter_AddRefs(renderingContext));
|
||||
@ -2317,8 +2276,6 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO)
|
||||
}
|
||||
fclose(fd);
|
||||
}
|
||||
if (docStr) nsMemory::Free(docStr);
|
||||
if (urlStr) nsMemory::Free(urlStr);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2517,12 +2474,10 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO)
|
||||
#ifdef EXTENDED_DEBUG_PRINTING
|
||||
nsIFrame* rootFrame = poPresShell->FrameManager()->GetRootFrame();
|
||||
if (aPO->IsPrintable()) {
|
||||
char * docStr;
|
||||
char * urlStr;
|
||||
nsAutoCString docStr;
|
||||
nsAutoCString urlStr;
|
||||
GetDocTitleAndURL(aPO, docStr, urlStr);
|
||||
DumpLayoutData(docStr, urlStr, poPresContext, mPrt->mPrintDocDC, rootFrame, docShell, nullptr);
|
||||
if (docStr) nsMemory::Free(docStr);
|
||||
if (urlStr) nsMemory::Free(urlStr);
|
||||
DumpLayoutData(docStr.get(), urlStr.get(), poPresContext, mPrt->mPrintDocDC, rootFrame, docShell, nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2532,10 +2487,9 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRUnichar * docTitleStr = nullptr;
|
||||
PRUnichar * docURLStr = nullptr;
|
||||
|
||||
GetDisplayTitleAndURL(aPO, &docTitleStr, &docURLStr, eDocTitleDefBlank);
|
||||
nsAutoString docTitleStr;
|
||||
nsAutoString docURLStr;
|
||||
GetDisplayTitleAndURL(aPO, docTitleStr, docURLStr, eDocTitleDefBlank);
|
||||
|
||||
if (nsIPrintSettings::kRangeSelection == printRangeType) {
|
||||
CloneSelection(aPO->mDocument->GetOriginalDocument(), aPO->mDocument);
|
||||
@ -2613,8 +2567,6 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO)
|
||||
nsIFrame * seqFrame = do_QueryFrame(pageSequence);
|
||||
if (!seqFrame) {
|
||||
SetIsPrinting(false);
|
||||
if (docTitleStr) nsMemory::Free(docTitleStr);
|
||||
if (docURLStr) nsMemory::Free(docURLStr);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -2635,48 +2587,40 @@ void
|
||||
nsPrintEngine::SetDocAndURLIntoProgress(nsPrintObject* aPO,
|
||||
nsIPrintProgressParams* aParams)
|
||||
{
|
||||
NS_ASSERTION(aPO, "Must have vaild nsPrintObject");
|
||||
NS_ASSERTION(aParams, "Must have vaild nsIPrintProgressParams");
|
||||
NS_ASSERTION(aPO, "Must have valid nsPrintObject");
|
||||
NS_ASSERTION(aParams, "Must have valid nsIPrintProgressParams");
|
||||
|
||||
if (!aPO || !aPO->mDocShell || !aParams) {
|
||||
return;
|
||||
}
|
||||
const uint32_t kTitleLength = 64;
|
||||
|
||||
PRUnichar * docTitleStr;
|
||||
PRUnichar * docURLStr;
|
||||
GetDisplayTitleAndURL(aPO, &docTitleStr, &docURLStr, eDocTitleDefURLDoc);
|
||||
nsAutoString docTitleStr;
|
||||
nsAutoString docURLStr;
|
||||
GetDisplayTitleAndURL(aPO, docTitleStr, docURLStr, eDocTitleDefURLDoc);
|
||||
|
||||
// Make sure the Titles & URLS don't get too long for the progress dialog
|
||||
ElipseLongString(docTitleStr, kTitleLength, false);
|
||||
ElipseLongString(docURLStr, kTitleLength, true);
|
||||
EllipseLongString(docTitleStr, kTitleLength, false);
|
||||
EllipseLongString(docURLStr, kTitleLength, true);
|
||||
|
||||
aParams->SetDocTitle(docTitleStr);
|
||||
aParams->SetDocURL(docURLStr);
|
||||
|
||||
if (docTitleStr != nullptr) nsMemory::Free(docTitleStr);
|
||||
if (docURLStr != nullptr) nsMemory::Free(docURLStr);
|
||||
aParams->SetDocTitle(docTitleStr.get());
|
||||
aParams->SetDocURL(docURLStr.get());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
void
|
||||
nsPrintEngine::ElipseLongString(PRUnichar *& aStr, const uint32_t aLen, bool aDoFront)
|
||||
nsPrintEngine::EllipseLongString(nsAString& aStr, const uint32_t aLen, bool aDoFront)
|
||||
{
|
||||
// Make sure the URLS don't get too long for the progress dialog
|
||||
if (aStr && NS_strlen(aStr) > aLen) {
|
||||
if (aLen >= 3 && aStr.Length() > aLen) {
|
||||
if (aDoFront) {
|
||||
PRUnichar * ptr = &aStr[NS_strlen(aStr) - aLen + 3];
|
||||
nsAutoString newStr;
|
||||
newStr.AppendLiteral("...");
|
||||
newStr += ptr;
|
||||
nsMemory::Free(aStr);
|
||||
aStr = ToNewUnicode(newStr);
|
||||
newStr += Substring(aStr, aStr.Length() - (aLen - 3), aLen - 3);
|
||||
aStr = newStr;
|
||||
} else {
|
||||
nsAutoString newStr(aStr);
|
||||
newStr.SetLength(aLen-3);
|
||||
newStr.AppendLiteral("...");
|
||||
nsMemory::Free(aStr);
|
||||
aStr = ToNewUnicode(newStr);
|
||||
aStr.SetLength(aLen - 3);
|
||||
aStr.AppendLiteral("...");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3942,28 +3886,15 @@ static void DumpPrintObjectsTree(nsPrintObject * aPO, int aLevel, FILE* aFD)
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------
|
||||
static void GetDocTitleAndURL(nsPrintObject* aPO, char *& aDocStr, char *& aURLStr)
|
||||
static void GetDocTitleAndURL(nsPrintObject* aPO, nsACString& aDocStr, nsACString& aURLStr)
|
||||
{
|
||||
aDocStr = nullptr;
|
||||
aURLStr = nullptr;
|
||||
|
||||
PRUnichar * docTitleStr;
|
||||
PRUnichar * docURLStr;
|
||||
nsAutoString docTitleStr;
|
||||
nsAutoString docURLStr;
|
||||
nsPrintEngine::GetDisplayTitleAndURL(aPO,
|
||||
&docTitleStr, &docURLStr,
|
||||
nsPrintEngine::eDocTitleDefURLDoc);
|
||||
|
||||
if (docTitleStr) {
|
||||
nsAutoString strDocTitle(docTitleStr);
|
||||
aDocStr = ToNewCString(strDocTitle);
|
||||
nsMemory::Free(docTitleStr);
|
||||
}
|
||||
|
||||
if (docURLStr) {
|
||||
nsAutoString strURL(docURLStr);
|
||||
aURLStr = ToNewCString(strURL);
|
||||
nsMemory::Free(docURLStr);
|
||||
}
|
||||
docTitleStr, docURLStr,
|
||||
nsPrintEngine::eDocTitleDefURLDoc);
|
||||
aDocStr = NS_ConvertUTF16toUTF8(docTitleStr);
|
||||
aURLStr = NS_ConvertUTF16toUTF8(docURLStr);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------
|
||||
@ -3995,12 +3926,10 @@ static void DumpPrintObjectsTreeLayout(nsPrintObject * aPO,
|
||||
fprintf(fd, "%s %p %p %p %p %d %d,%d,%d,%d\n", types[aPO->mFrameType], aPO, aPO->mDocShell.get(), aPO->mSeqFrame,
|
||||
aPO->mPageFrame, aPO->mPageNum, aPO->mRect.x, aPO->mRect.y, aPO->mRect.width, aPO->mRect.height);
|
||||
if (aPO->IsPrintable()) {
|
||||
char * docStr;
|
||||
char * urlStr;
|
||||
nsAutoCString docStr;
|
||||
nsAutoCString urlStr;
|
||||
GetDocTitleAndURL(aPO, docStr, urlStr);
|
||||
DumpLayoutData(docStr, urlStr, aPO->mPresContext, aDC, rootFrame, aPO->mDocShell, fd);
|
||||
if (docStr) nsMemory::Free(docStr);
|
||||
if (urlStr) nsMemory::Free(urlStr);
|
||||
DumpLayoutData(docStr.get(), urlStr.get(), aPO->mPresContext, aDC, rootFrame, aPO->mDocShell, fd);
|
||||
}
|
||||
fprintf(fd, "<***************************************************>\n");
|
||||
|
||||
|
@ -71,7 +71,6 @@ public:
|
||||
// This enum tells indicates what the default should be for the title
|
||||
// if the title from the document is null
|
||||
enum eDocTitleDefault {
|
||||
eDocTitleDefNone,
|
||||
eDocTitleDefBlank,
|
||||
eDocTitleDefURLDoc
|
||||
};
|
||||
@ -135,7 +134,7 @@ public:
|
||||
static void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
|
||||
void SetDocAndURLIntoProgress(nsPrintObject* aPO,
|
||||
nsIPrintProgressParams* aParams);
|
||||
void ElipseLongString(PRUnichar *& aStr, const uint32_t aLen, bool aDoFront);
|
||||
void EllipseLongString(nsAString& aStr, const uint32_t aLen, bool aDoFront);
|
||||
nsresult CheckForPrinters(nsIPrintSettings* aPrintSettings);
|
||||
void CleanupDocTitleArray(PRUnichar**& aArray, int32_t& aCount);
|
||||
|
||||
@ -163,12 +162,12 @@ public:
|
||||
// Static Methods
|
||||
//---------------------------------------------------------------------
|
||||
static void GetDocumentTitleAndURL(nsIDocument* aDoc,
|
||||
PRUnichar** aTitle,
|
||||
PRUnichar** aURLStr);
|
||||
void GetDisplayTitleAndURL(nsPrintObject* aPO,
|
||||
PRUnichar** aTitle,
|
||||
PRUnichar** aURLStr,
|
||||
eDocTitleDefault aDefType);
|
||||
nsAString& aTitle,
|
||||
nsAString& aURLStr);
|
||||
void GetDisplayTitleAndURL(nsPrintObject* aPO,
|
||||
nsAString& aTitle,
|
||||
nsAString& aURLStr,
|
||||
eDocTitleDefault aDefType);
|
||||
static void ShowPrintErrorDialog(nsresult printerror,
|
||||
bool aIsPrinting = true);
|
||||
|
||||
|
@ -51,10 +51,10 @@ nsDeviceContextSpecAndroid::Init(nsIWidget* aWidget,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDeviceContextSpecAndroid::BeginDocument(PRUnichar* aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage)
|
||||
nsDeviceContextSpecAndroid::BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
NS_IMETHOD Init(nsIWidget* aWidget,
|
||||
nsIPrintSettings* aPS,
|
||||
bool aIsPrintPreview);
|
||||
NS_IMETHOD BeginDocument(PRUnichar* aTitle,
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage);
|
||||
|
@ -19,10 +19,10 @@ public:
|
||||
|
||||
NS_IMETHOD Init(nsIWidget *aWidget, nsIPrintSettings* aPS, bool aIsPrintPreview);
|
||||
NS_IMETHOD GetSurfaceForPrinter(gfxASurface **surface);
|
||||
NS_IMETHOD BeginDocument(PRUnichar* aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage);
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage);
|
||||
NS_IMETHOD EndDocument();
|
||||
NS_IMETHOD BeginPage();
|
||||
NS_IMETHOD EndPage();
|
||||
|
@ -57,15 +57,15 @@ NS_IMETHODIMP nsDeviceContextSpecX::Init(nsIWidget *aWidget,
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(PRUnichar* aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage)
|
||||
NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (aTitle) {
|
||||
CFStringRef cfString = ::CFStringCreateWithCharacters(NULL, aTitle, NS_strlen(aTitle));
|
||||
if (!aTitle.IsEmpty()) {
|
||||
CFStringRef cfString = ::CFStringCreateWithCharacters(NULL, aTitle, aTitle.Length());
|
||||
if (cfString) {
|
||||
::PMPrintSettingsSetJobName(mPrintSettings, cfString);
|
||||
::CFRelease(cfString);
|
||||
|
@ -551,7 +551,7 @@ ns_release_macro(gpointer aData) {
|
||||
NS_RELEASE(spoolFile);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK::BeginDocument(PRUnichar * aTitle, PRUnichar * aPrintToFileName,
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK::BeginDocument(const nsAString& aTitle, PRUnichar * aPrintToFileName,
|
||||
int32_t aStartPage, int32_t aEndPage)
|
||||
{
|
||||
if (mToPrinter) {
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
NS_IMETHOD GetSurfaceForPrinter(gfxASurface **surface);
|
||||
|
||||
NS_IMETHOD Init(nsIWidget *aWidget, nsIPrintSettings* aPS, bool aIsPrintPreview);
|
||||
NS_IMETHOD BeginDocument(PRUnichar * aTitle, PRUnichar * aPrintToFileName, int32_t aStartPage, int32_t aEndPage);
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle, PRUnichar * aPrintToFileName, int32_t aStartPage, int32_t aEndPage);
|
||||
NS_IMETHOD EndDocument();
|
||||
NS_IMETHOD BeginPage() { return NS_OK; }
|
||||
NS_IMETHOD EndPage() { return NS_OK; }
|
||||
|
@ -13,8 +13,8 @@ class nsIPrintSettings;
|
||||
class gfxASurface;
|
||||
|
||||
#define NS_IDEVICE_CONTEXT_SPEC_IID \
|
||||
{ 0x205c614f, 0x39f8, 0x42e1, \
|
||||
{ 0x92, 0x53, 0x04, 0x9b, 0x48, 0xc3, 0xcb, 0xd8 } }
|
||||
{ 0xb5548fb1, 0xf43e, 0x4921, \
|
||||
{ 0x82, 0x19, 0xc3, 0x82, 0x06, 0xee, 0x74, 0x5c } }
|
||||
|
||||
class nsIDeviceContextSpec : public nsISupports
|
||||
{
|
||||
@ -34,10 +34,10 @@ public:
|
||||
|
||||
NS_IMETHOD GetSurfaceForPrinter(gfxASurface **nativeSurface) = 0;
|
||||
|
||||
NS_IMETHOD BeginDocument(PRUnichar* aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage) = 0;
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage) = 0;
|
||||
|
||||
NS_IMETHOD EndDocument() = 0;
|
||||
NS_IMETHOD BeginPage() = 0;
|
||||
|
@ -432,28 +432,35 @@ NS_IMETHODIMP nsDeviceContextSpecOS2::GetSurfaceForPrinter(gfxASurface **surface
|
||||
|
||||
// Helper function to convert the string to the native codepage,
|
||||
// similar to UnicodeToCodepage() in nsDragService.cpp.
|
||||
char *GetACPString(const PRUnichar* aStr)
|
||||
char *GetACPString(const nsAString& aStr)
|
||||
{
|
||||
nsString str(aStr);
|
||||
if (str.Length() == 0) {
|
||||
if (aStr.Length() == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsAutoCharBuffer buffer;
|
||||
int32_t bufLength;
|
||||
WideCharToMultiByte(0, PromiseFlatString(str).get(), str.Length(),
|
||||
WideCharToMultiByte(0, PromiseFlatString(aStr).get(), aStr.Length(),
|
||||
buffer, bufLength);
|
||||
return ToNewCString(nsDependentCString(buffer.Elements()));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecOS2::BeginDocument(PRUnichar* aTitle,
|
||||
// Helper function to convert the string to the native codepage,
|
||||
// similar to UnicodeToCodepage() in nsDragService.cpp.
|
||||
char *GetACPString(const PRUnichar* aStr)
|
||||
{
|
||||
nsString str(aStr);
|
||||
return GetACPString(str);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecOS2::BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage)
|
||||
{
|
||||
#ifdef debug_thebes_print
|
||||
printf("nsDeviceContextSpecOS2[%#x]::BeginPrinting(%s, %s)\n", (unsigned)this,
|
||||
NS_LossyConvertUTF16toASCII(nsString(aTitle)).get(),
|
||||
NS_LossyConvertUTF16toASCII(aTitle).get(),
|
||||
NS_LossyConvertUTF16toASCII(nsString(aPrintToFileName)).get());
|
||||
#endif
|
||||
// don't try to send device escapes for non-native output (like PDF)
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
NS_IMETHOD GetPRTQUEUE(PRTQUEUE *&p);
|
||||
|
||||
NS_IMETHOD GetSurfaceForPrinter(gfxASurface **nativeSurface);
|
||||
NS_IMETHOD BeginDocument(PRUnichar* aTitle, PRUnichar* aPrintToFileName,
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle, PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage, int32_t aEndPage);
|
||||
NS_IMETHOD EndDocument();
|
||||
NS_IMETHOD BeginPage();
|
||||
|
@ -161,7 +161,7 @@ NS_IMETHODIMP nsDeviceContextSpecQt::GetPath(const char** aPath)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecQt::BeginDocument(
|
||||
PRUnichar* aTitle,
|
||||
const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage)
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
NS_IMETHOD Init(nsIWidget* aWidget,
|
||||
nsIPrintSettings* aPS,
|
||||
bool aIsPrintPreview);
|
||||
NS_IMETHOD BeginDocument(PRUnichar* aTitle,
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage);
|
||||
|
@ -24,10 +24,10 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetSurfaceForPrinter(gfxASurface **surface);
|
||||
NS_IMETHOD BeginDocument(PRUnichar* aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage) { return NS_OK; }
|
||||
NS_IMETHOD BeginDocument(const nsAString& aTitle,
|
||||
PRUnichar* aPrintToFileName,
|
||||
int32_t aStartPage,
|
||||
int32_t aEndPage) { return NS_OK; }
|
||||
NS_IMETHOD EndDocument() { return NS_OK; }
|
||||
NS_IMETHOD BeginPage() { return NS_OK; }
|
||||
NS_IMETHOD EndPage() { return NS_OK; }
|
||||
|
Loading…
Reference in New Issue
Block a user