2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsPageFrame.h"
|
1998-12-18 08:44:26 +03:00
|
|
|
#include "nsHTMLParts.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIContent.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIRenderingContext.h"
|
1998-06-25 18:53:45 +04:00
|
|
|
#include "nsHTMLAtoms.h"
|
1999-02-14 06:47:33 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-02-24 07:03:50 +03:00
|
|
|
#include "nsIPresShell.h"
|
2004-01-22 02:05:10 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
#include "nsIDeviceContext.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2002-01-25 17:30:14 +03:00
|
|
|
#include "nsPageContentFrame.h"
|
2002-04-26 15:30:33 +04:00
|
|
|
#include "nsTextFrame.h" // for function BinarySearchForPosition
|
2001-11-03 17:59:39 +03:00
|
|
|
|
|
|
|
#include "nsIView.h" // view flags for clipping
|
2001-12-05 01:46:41 +03:00
|
|
|
#include "nsCSSRendering.h"
|
2001-11-03 17:59:39 +03:00
|
|
|
|
|
|
|
#include "nsHTMLContainerFrame.h" // view creation
|
|
|
|
|
|
|
|
#include "nsSimplePageSequence.h" // for nsSharedPageData
|
2002-08-30 07:32:05 +04:00
|
|
|
#include "nsRegion.h"
|
2002-01-25 17:30:14 +03:00
|
|
|
#include "nsIViewManager.h"
|
2001-01-27 17:09:34 +03:00
|
|
|
|
|
|
|
// for page number localization formatting
|
|
|
|
#include "nsTextFormatter.h"
|
|
|
|
|
2002-04-30 04:37:12 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsBidiUtils.h"
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#endif
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
// Temporary
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
|
2001-09-26 18:01:26 +04:00
|
|
|
// Print Options
|
2002-01-01 15:58:53 +03:00
|
|
|
#include "nsIPrintSettings.h"
|
2001-09-26 18:01:26 +04:00
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
|
2002-01-25 17:30:14 +03:00
|
|
|
// Widget Creation
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
static NS_DEFINE_CID(kCChildCID, NS_CHILD_CID);
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
2001-11-03 17:59:39 +03:00
|
|
|
//#define DEBUG_PRINTING
|
2001-04-12 17:04:29 +04:00
|
|
|
#endif
|
|
|
|
|
2002-06-20 01:51:13 +04:00
|
|
|
#include "prlog.h"
|
|
|
|
#ifdef PR_LOGGING
|
2002-08-27 01:20:31 +04:00
|
|
|
extern PRLogModuleInfo * kLayoutPrintingLogMod;
|
|
|
|
#define PR_PL(_p1) PR_LOG(kLayoutPrintingLogMod, PR_LOG_DEBUG, _p1)
|
2002-06-20 01:51:13 +04:00
|
|
|
#else
|
|
|
|
#define PR_PL(_p1)
|
2001-04-12 17:04:29 +04:00
|
|
|
#endif
|
|
|
|
|
2002-03-10 18:40:51 +03:00
|
|
|
// XXX Part of Temporary fix for Bug 127263
|
|
|
|
PRBool nsPageFrame::mDoCreateWidget = PR_TRUE;
|
2001-11-03 17:59:39 +03:00
|
|
|
|
1999-05-12 02:03:29 +04:00
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewPageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1999-05-12 02:03:29 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
2002-02-01 18:31:15 +03:00
|
|
|
|
1999-12-05 02:49:50 +03:00
|
|
|
nsPageFrame* it = new (aPresShell) nsPageFrame;
|
1999-05-12 02:03:29 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
nsPageFrame::nsPageFrame() :
|
2001-04-12 17:04:29 +04:00
|
|
|
mSupressHF(PR_FALSE),
|
|
|
|
mClipRect(-1, -1, -1, -1)
|
1999-02-19 01:23:36 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
nsPageFrame::~nsPageFrame()
|
|
|
|
{
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
2001-09-26 18:01:26 +04:00
|
|
|
|
2002-01-25 17:30:14 +03:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPageFrame::SetInitialChildList(nsPresContext* aPresContext,
|
2001-11-03 17:59:39 +03:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
2003-06-30 14:46:59 +04:00
|
|
|
nsIView* view = aChildList->GetView();
|
|
|
|
if (view && mDoCreateWidget) {
|
2004-08-01 03:15:21 +04:00
|
|
|
if (aPresContext->Type() == nsPresContext::eContext_PrintPreview &&
|
2004-07-29 23:41:39 +04:00
|
|
|
view->GetNearestWidget(nsnull)) {
|
2002-01-25 17:30:14 +03:00
|
|
|
view->CreateWidget(kCChildCID);
|
2001-11-03 17:59:39 +03:00
|
|
|
}
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
2002-01-25 17:30:14 +03:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
return nsContainerFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHODIMP nsPageFrame::Reflow(nsPresContext* aPresContext,
|
2001-11-03 17:59:39 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-21 18:59:47 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsPageFrame", aReflowState.reason);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
1998-05-12 08:17:56 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE; // initialize out parameter
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-11-28 18:19:47 +03:00
|
|
|
if (eReflowReason_Incremental != aReflowState.reason) {
|
1998-05-25 21:31:49 +04:00
|
|
|
// Do we have any children?
|
1998-11-05 09:12:57 +03:00
|
|
|
// XXX We should use the overflow list instead...
|
2002-01-25 17:30:14 +03:00
|
|
|
nsIFrame* firstFrame = mFrames.FirstChild();
|
|
|
|
nsPageContentFrame* contentPage = NS_STATIC_CAST(nsPageContentFrame*, firstFrame);
|
|
|
|
NS_ASSERTION(contentPage, "There should always be a content page");
|
2003-10-31 23:19:18 +03:00
|
|
|
NS_ASSERTION(nsLayoutAtoms::pageContentFrame == firstFrame->GetType(),
|
|
|
|
"This frame isn't a pageContentFrame");
|
2002-01-25 17:30:14 +03:00
|
|
|
|
2003-01-20 21:04:34 +03:00
|
|
|
if (contentPage && mPrevInFlow) {
|
2002-01-25 17:30:14 +03:00
|
|
|
nsPageFrame* prevPage = NS_STATIC_CAST(nsPageFrame*, mPrevInFlow);
|
|
|
|
nsPageContentFrame* prevContentPage = NS_STATIC_CAST(nsPageContentFrame*, prevPage->mFrames.FirstChild());
|
|
|
|
nsIFrame* prevLastChild = prevContentPage->mFrames.LastChild();
|
1998-11-05 09:12:57 +03:00
|
|
|
|
|
|
|
// Create a continuing child of the previous page's last child
|
1999-02-24 07:03:50 +03:00
|
|
|
nsIFrame* newFrame;
|
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
aPresContext->PresShell()->FrameConstructor()->
|
|
|
|
CreateContinuingFrame(aPresContext, prevLastChild,
|
|
|
|
contentPage, &newFrame);
|
|
|
|
|
2003-01-20 21:04:34 +03:00
|
|
|
// Make the new area frame the 1st child of the page content frame. There may already be
|
|
|
|
// children placeholders which don't get reflowed but must not be destroyed until the
|
|
|
|
// page content frame is destroyed.
|
|
|
|
contentPage->mFrames.InsertFrame(contentPage, nsnull, newFrame);
|
1998-05-25 21:31:49 +04:00
|
|
|
}
|
1998-11-05 09:12:57 +03:00
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
// Resize our frame allowing it only to be as big as we are
|
|
|
|
// XXX Pay attention to the page's border and padding...
|
1999-01-16 01:53:39 +03:00
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
nsIFrame* frame = mFrames.FirstChild();
|
2002-02-12 16:33:39 +03:00
|
|
|
// When availableHeight is NS_UNCONSTRAINEDSIZE it means we are reflowing a single page
|
|
|
|
// to print selection. So this means we want to use NS_UNCONSTRAINEDSIZE without altering it
|
|
|
|
nscoord avHeight;
|
|
|
|
if (aReflowState.availableHeight == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
avHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
} else {
|
|
|
|
avHeight = mPD->mReflowRect.height - mPD->mReflowMargin.top - mPD->mReflowMargin.bottom;
|
|
|
|
}
|
2001-11-03 17:59:39 +03:00
|
|
|
nsSize maxSize(mPD->mReflowRect.width - mPD->mReflowMargin.right - mPD->mReflowMargin.left,
|
2002-02-12 16:33:39 +03:00
|
|
|
avHeight);
|
2002-03-20 15:34:18 +03:00
|
|
|
// Get the number of Twips per pixel from the PresContext
|
2004-07-29 23:41:39 +04:00
|
|
|
nscoord onePixelInTwips = aPresContext->IntScaledPixelsToTwips(1);
|
2002-03-20 15:34:18 +03:00
|
|
|
NS_ASSERTION(maxSize.width >= onePixelInTwips, "maxSize.width must be >= 1 pixel");
|
|
|
|
NS_ASSERTION(maxSize.height >= onePixelInTwips, "maxSize.height must be >= 1 pixel");
|
|
|
|
// insurance against infinite reflow, when reflowing less than a pixel
|
|
|
|
if (maxSize.width < onePixelInTwips || maxSize.height < onePixelInTwips) {
|
|
|
|
aDesiredSize.width = 0;
|
|
|
|
aDesiredSize.height = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame, maxSize);
|
2001-12-07 17:51:12 +03:00
|
|
|
kidReflowState.mFlags.mIsTopOfPage = PR_TRUE;
|
1998-05-30 00:36:05 +04:00
|
|
|
|
2001-11-28 18:19:47 +03:00
|
|
|
// calc location of frame
|
|
|
|
nscoord xc = mPD->mReflowMargin.left + mPD->mDeadSpaceMargin.left + mPD->mExtraMargin.left;
|
|
|
|
nscoord yc = mPD->mReflowMargin.top + mPD->mDeadSpaceMargin.top + mPD->mExtraMargin.top;
|
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// Get the child's desired size
|
2001-11-28 18:19:47 +03:00
|
|
|
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, xc, yc, 0, aStatus);
|
|
|
|
|
2001-11-06 17:34:00 +03:00
|
|
|
|
|
|
|
// Place and size the child
|
2001-12-07 17:51:12 +03:00
|
|
|
FinishReflowChild(frame, aPresContext, &kidReflowState, aDesiredSize, xc, yc, 0);
|
1999-10-30 06:52:11 +04:00
|
|
|
|
|
|
|
// Make sure the child is at least as tall as our max size (the containing window)
|
2002-02-12 16:33:39 +03:00
|
|
|
if (aDesiredSize.height < aReflowState.availableHeight &&
|
|
|
|
aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) {
|
1999-10-30 06:52:11 +04:00
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
|
|
|
}
|
|
|
|
|
2003-06-30 14:46:59 +04:00
|
|
|
nsIView* view = frame->GetView();
|
2002-02-12 16:33:39 +03:00
|
|
|
if (view) {
|
2004-01-10 19:18:36 +03:00
|
|
|
nsRegion region(nsRect(0, 0, aDesiredSize.width, aDesiredSize.height));
|
2003-06-30 14:46:59 +04:00
|
|
|
view->GetViewManager()->SetViewChildClipRegion(view, ®ion);
|
2002-02-12 16:33:39 +03:00
|
|
|
}
|
|
|
|
|
2004-09-14 06:28:03 +04:00
|
|
|
NS_ASSERTION(!NS_FRAME_IS_COMPLETE(aStatus) ||
|
|
|
|
!frame->GetNextInFlow(), "bad child flow list");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2002-06-20 01:51:13 +04:00
|
|
|
PR_PL(("PageFrame::Reflow %p ", this));
|
|
|
|
PR_PL(("[%d,%d][%d,%d]\n", aDesiredSize.width, aDesiredSize.height, aReflowState.availableWidth, aReflowState.availableHeight));
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
// Return our desired size
|
1999-01-06 02:31:18 +03:00
|
|
|
aDesiredSize.width = aReflowState.availableWidth;
|
2002-02-12 16:33:39 +03:00
|
|
|
if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
|
|
|
}
|
1998-05-25 21:31:49 +04:00
|
|
|
}
|
2002-06-20 01:51:13 +04:00
|
|
|
PR_PL(("PageFrame::Reflow %p ", this));
|
|
|
|
PR_PL(("[%d,%d]\n", aReflowState.availableWidth, aReflowState.availableHeight));
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-01-31 17:24:06 +03:00
|
|
|
void nsPageFrame::SetClipRect(nsRect* aClipRect)
|
|
|
|
{
|
|
|
|
mClipRect = *aClipRect;
|
|
|
|
nsIFrame* firstFrame = mFrames.FirstChild();
|
|
|
|
nsPageContentFrame* contentPage = NS_STATIC_CAST(nsPageContentFrame*, firstFrame);
|
|
|
|
NS_ASSERTION(contentPage, "There should always be a content page");
|
|
|
|
contentPage->SetClipRect(aClipRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
|
|
|
nsPageFrame::GetType() const
|
1999-02-14 06:47:33 +03:00
|
|
|
{
|
2003-10-31 23:19:18 +03:00
|
|
|
return nsLayoutAtoms::pageFrame;
|
1999-02-14 06:47:33 +03:00
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1998-11-19 20:22:29 +03:00
|
|
|
NS_IMETHODIMP
|
2001-11-14 04:33:42 +03:00
|
|
|
nsPageFrame::GetFrameName(nsAString& aResult) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Page"), aResult);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-03-12 07:40:17 +03:00
|
|
|
/* virtual */ PRBool
|
|
|
|
nsPageFrame::IsContainingBlock() const
|
1999-03-05 07:28:07 +03:00
|
|
|
{
|
2004-03-12 07:40:17 +03:00
|
|
|
return PR_TRUE;
|
1999-03-05 07:28:07 +03:00
|
|
|
}
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2001-11-16 16:41:12 +03:00
|
|
|
// Remove fix below when string gets fixed
|
|
|
|
#define WORKAROUND_FOR_BUG_110335
|
2001-09-26 18:01:26 +04:00
|
|
|
// replace the &<code> with the value, but if the value is empty
|
|
|
|
// set the string to zero length
|
|
|
|
static void
|
2002-03-19 09:46:56 +03:00
|
|
|
SubstValueForCode(nsString& aStr, const PRUnichar * aUKey, const PRUnichar * aUStr)
|
2001-09-26 18:01:26 +04:00
|
|
|
{
|
2001-11-16 16:41:12 +03:00
|
|
|
#ifdef WORKAROUND_FOR_BUG_110335
|
2002-03-19 09:46:56 +03:00
|
|
|
const PRUnichar* uKeyStr = aUKey;
|
2001-11-16 16:41:12 +03:00
|
|
|
|
|
|
|
// Check to make sure our subst code &<code> isn't in the data string
|
|
|
|
// for example &T for title is in QB&T
|
|
|
|
nsAutoString dataStr(aUStr);
|
|
|
|
nsAutoString newKey(aUKey);
|
2002-03-19 09:46:56 +03:00
|
|
|
PRBool fixingSubstr = (dataStr.Find(newKey) != kNotFound);
|
2001-11-16 16:41:12 +03:00
|
|
|
if (fixingSubstr) {
|
|
|
|
// well, the code is in the data str so make up a new code
|
|
|
|
// but make sure it it isn't in either substs string or the data string
|
|
|
|
char* code = "~!@#$%^*()_+=][}{`';:|?/.,:\"<>";
|
|
|
|
PRInt32 codeInx = 0;
|
|
|
|
PRInt32 codeLen = PRUint32(strlen(code));
|
|
|
|
while ((dataStr.Find(newKey) > -1 || aStr.Find(newKey) > -1) && codeInx < codeLen) {
|
|
|
|
newKey.SetCharAt((PRUnichar)code[codeInx++], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if we can do the substitution
|
|
|
|
if (codeInx == codeLen) {
|
2004-10-20 01:46:45 +04:00
|
|
|
aStr.Truncate();
|
2001-11-16 16:41:12 +03:00
|
|
|
return; // bail we just can't do it
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ok, we have the new code, so repplace the old code
|
|
|
|
// in the dest str with the new code
|
2002-03-19 09:46:56 +03:00
|
|
|
aStr.ReplaceSubstring(aUKey, newKey.get());
|
2001-11-16 16:41:12 +03:00
|
|
|
uKeyStr = ToNewUnicode(newKey);
|
|
|
|
}
|
|
|
|
|
2002-11-17 08:16:49 +03:00
|
|
|
if (!aUStr || !*aUStr) {
|
2004-10-20 01:46:45 +04:00
|
|
|
aStr.Truncate();
|
2001-11-16 16:41:12 +03:00
|
|
|
} else {
|
|
|
|
aStr.ReplaceSubstring(uKeyStr, aUStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free uKeyStr only if we fixed the string.
|
|
|
|
if (fixingSubstr) {
|
2002-03-19 09:46:56 +03:00
|
|
|
nsMemory::Free(NS_CONST_CAST(PRUnichar*, uKeyStr));
|
2001-11-16 16:41:12 +03:00
|
|
|
}
|
|
|
|
#else
|
2002-03-19 09:46:56 +03:00
|
|
|
|
2002-11-17 08:16:49 +03:00
|
|
|
if (!aUStr || !*aUStr) {
|
2004-10-20 01:46:45 +04:00
|
|
|
aStr.Truncate();
|
2001-09-26 18:01:26 +04:00
|
|
|
} else {
|
|
|
|
aStr.ReplaceSubstring(aUKey, aUStr);
|
|
|
|
}
|
2001-11-16 16:41:12 +03:00
|
|
|
#endif // WORKAROUND_FOR_BUG_110335
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
// done with static helper functions
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
|
|
|
|
{
|
|
|
|
|
|
|
|
aNewStr = aStr;
|
|
|
|
|
|
|
|
// Search to see if the &D code is in the string
|
|
|
|
// then subst in the current date/time
|
2002-03-19 09:46:56 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(kDate, "&D");
|
|
|
|
if (aStr.Find(kDate) != kNotFound) {
|
|
|
|
if (mPD->mDateTimeStr != nsnull) {
|
|
|
|
aNewStr.ReplaceSubstring(kDate.get(), mPD->mDateTimeStr);
|
|
|
|
} else {
|
2004-01-30 01:04:45 +03:00
|
|
|
aNewStr.ReplaceSubstring(kDate.get(), EmptyString().get());
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
2002-03-19 09:46:56 +03:00
|
|
|
return;
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Must search for &PT before searching for &P
|
|
|
|
//
|
|
|
|
// Search to see if the "page number and page" total code are in the string
|
2002-03-19 09:46:56 +03:00
|
|
|
// and replace the page number and page total code with the actual
|
|
|
|
// values
|
|
|
|
NS_NAMED_LITERAL_STRING(kPageAndTotal, "&PT");
|
|
|
|
if (aStr.Find(kPageAndTotal) != kNotFound) {
|
|
|
|
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumAndTotalsFormat, mPageNum, mTotNumPages);
|
|
|
|
aNewStr.ReplaceSubstring(kPageAndTotal.get(), uStr);
|
|
|
|
nsMemory::Free(uStr);
|
|
|
|
return;
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Search to see if the page number code is in the string
|
2002-03-19 09:46:56 +03:00
|
|
|
// and replace the page number code with the actual value
|
|
|
|
NS_NAMED_LITERAL_STRING(kPage, "&P");
|
|
|
|
if (aStr.Find(kPage) != kNotFound) {
|
|
|
|
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat, mPageNum);
|
|
|
|
aNewStr.ReplaceSubstring(kPage.get(), uStr);
|
|
|
|
nsMemory::Free(uStr);
|
|
|
|
return;
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
|
2002-03-19 09:46:56 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(kTitle, "&T");
|
|
|
|
if (aStr.Find(kTitle) != kNotFound) {
|
2002-05-07 16:03:37 +04:00
|
|
|
SubstValueForCode(aNewStr, kTitle.get(), mPD->mDocTitle);
|
2002-03-19 09:46:56 +03:00
|
|
|
return;
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
|
2002-03-19 09:46:56 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(kDocURL, "&U");
|
|
|
|
if (aStr.Find(kDocURL) != kNotFound) {
|
2002-05-07 16:03:37 +04:00
|
|
|
SubstValueForCode(aNewStr, kDocURL.get(), mPD->mDocURL);
|
2002-03-19 09:46:56 +03:00
|
|
|
return;
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
nscoord nsPageFrame::GetXPosition(nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aRect,
|
|
|
|
PRInt32 aJust,
|
|
|
|
const nsString& aStr)
|
|
|
|
{
|
|
|
|
PRInt32 width;
|
|
|
|
aRenderingContext.GetWidth(aStr, width);
|
|
|
|
|
|
|
|
nscoord x = aRect.x;
|
|
|
|
switch (aJust) {
|
2002-01-01 15:58:53 +03:00
|
|
|
case nsIPrintSettings::kJustLeft:
|
2002-02-01 18:31:15 +03:00
|
|
|
x += mPD->mExtraMargin.left + mPD->mEdgePaperMargin.left;
|
2001-01-27 17:09:34 +03:00
|
|
|
break;
|
|
|
|
|
2002-01-01 15:58:53 +03:00
|
|
|
case nsIPrintSettings::kJustCenter:
|
2001-01-27 17:09:34 +03:00
|
|
|
x += (aRect.width - width) / 2;
|
|
|
|
break;
|
|
|
|
|
2002-01-01 15:58:53 +03:00
|
|
|
case nsIPrintSettings::kJustRight:
|
2002-02-01 18:31:15 +03:00
|
|
|
x += aRect.width - width - mPD->mExtraMargin.right - mPD->mEdgePaperMargin.right;
|
2001-01-27 17:09:34 +03:00
|
|
|
break;
|
|
|
|
} // switch
|
|
|
|
|
2001-11-28 18:19:47 +03:00
|
|
|
NS_ASSERTION(x >= 0, "x can't be less than zero");
|
|
|
|
x = PR_MAX(x, 0);
|
2001-01-27 17:09:34 +03:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Draw a Header or footer text lrft,right or center justified
|
|
|
|
// @parm aRenderingContext - rendering content ot draw into
|
|
|
|
// @parm aHeaderFooter - indicates whether it is a header or footer
|
|
|
|
// @parm aJust - indicates the justification of the text
|
|
|
|
// @parm aStr - The string to be drawn
|
|
|
|
// @parm aRect - the rect of the page
|
|
|
|
// @parm aHeight - the height of the text
|
|
|
|
// @parm aUseHalfThePage - indicates whether the text should limited to the width
|
|
|
|
// of the entire page or just half the page
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPageFrame::DrawHeaderFooter(nsPresContext* aPresContext,
|
2002-04-30 04:37:12 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-09-26 18:01:26 +04:00
|
|
|
nsIFrame * aFrame,
|
|
|
|
nsHeaderFooterEnum aHeaderFooter,
|
|
|
|
PRInt32 aJust,
|
|
|
|
const nsString& aStr1,
|
|
|
|
const nsString& aStr2,
|
|
|
|
const nsString& aStr3,
|
|
|
|
const nsRect& aRect,
|
2001-10-31 01:58:00 +03:00
|
|
|
nscoord aAscent,
|
2001-09-26 18:01:26 +04:00
|
|
|
nscoord aHeight)
|
|
|
|
{
|
|
|
|
PRInt32 numStrs = 0;
|
|
|
|
if (!aStr1.IsEmpty()) numStrs++;
|
|
|
|
if (!aStr2.IsEmpty()) numStrs++;
|
|
|
|
if (!aStr3.IsEmpty()) numStrs++;
|
|
|
|
|
|
|
|
if (numStrs == 0) return;
|
2001-10-02 03:57:57 +04:00
|
|
|
nscoord strSpace = aRect.width / numStrs;
|
2001-09-26 18:01:26 +04:00
|
|
|
|
|
|
|
if (!aStr1.IsEmpty()) {
|
2002-04-30 04:37:12 +04:00
|
|
|
DrawHeaderFooter(aPresContext, aRenderingContext, aFrame, aHeaderFooter, nsIPrintSettings::kJustLeft, aStr1, aRect, aAscent, aHeight, strSpace);
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
if (!aStr2.IsEmpty()) {
|
2002-04-30 04:37:12 +04:00
|
|
|
DrawHeaderFooter(aPresContext, aRenderingContext, aFrame, aHeaderFooter, nsIPrintSettings::kJustCenter, aStr2, aRect, aAscent, aHeight, strSpace);
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
if (!aStr3.IsEmpty()) {
|
2002-04-30 04:37:12 +04:00
|
|
|
DrawHeaderFooter(aPresContext, aRenderingContext, aFrame, aHeaderFooter, nsIPrintSettings::kJustRight, aStr3, aRect, aAscent, aHeight, strSpace);
|
2001-09-26 18:01:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Draw a Header or footer text lrft,right or center justified
|
|
|
|
// @parm aRenderingContext - rendering content ot draw into
|
|
|
|
// @parm aHeaderFooter - indicates whether it is a header or footer
|
|
|
|
// @parm aJust - indicates the justification of the text
|
|
|
|
// @parm aStr - The string to be drawn
|
|
|
|
// @parm aRect - the rect of the page
|
|
|
|
// @parm aHeight - the height of the text
|
|
|
|
// @parm aWidth - available width for any one of the strings
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPageFrame::DrawHeaderFooter(nsPresContext* aPresContext,
|
2002-04-30 04:37:12 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-01-27 17:09:34 +03:00
|
|
|
nsIFrame * aFrame,
|
|
|
|
nsHeaderFooterEnum aHeaderFooter,
|
|
|
|
PRInt32 aJust,
|
|
|
|
const nsString& aStr,
|
|
|
|
const nsRect& aRect,
|
2001-10-31 01:58:00 +03:00
|
|
|
nscoord aAscent,
|
2001-01-27 17:09:34 +03:00
|
|
|
nscoord aHeight,
|
2001-09-26 18:01:26 +04:00
|
|
|
nscoord aWidth)
|
2001-01-27 17:09:34 +03:00
|
|
|
{
|
2001-04-12 17:04:29 +04:00
|
|
|
|
2002-02-01 18:31:15 +03:00
|
|
|
nscoord contentWidth = aWidth - (mPD->mEdgePaperMargin.left + mPD->mEdgePaperMargin.right);
|
2001-11-28 18:19:47 +03:00
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
// first make sure we have a vaild string and that the height of the
|
|
|
|
// text will fit in the margin
|
2003-05-24 01:34:47 +04:00
|
|
|
if (!aStr.IsEmpty() &&
|
2001-01-27 17:09:34 +03:00
|
|
|
((aHeaderFooter == eHeader && aHeight < mMargin.top) ||
|
|
|
|
(aHeaderFooter == eFooter && aHeight < mMargin.bottom))) {
|
2001-09-26 18:01:26 +04:00
|
|
|
nsAutoString str;
|
|
|
|
ProcessSpecialCodes(aStr, str);
|
|
|
|
|
2002-04-26 15:30:33 +04:00
|
|
|
PRInt32 indx;
|
|
|
|
PRInt32 textWidth = 0;
|
|
|
|
const PRUnichar* text = str.get();
|
2001-09-26 18:01:26 +04:00
|
|
|
|
2002-04-26 15:30:33 +04:00
|
|
|
PRInt32 len = (PRInt32)str.Length();
|
|
|
|
if (len == 0) {
|
|
|
|
return; // bail is empty string
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
2003-03-19 07:35:08 +03:00
|
|
|
// find how much text fits, the "position" is the size of the available area
|
2002-04-26 15:30:33 +04:00
|
|
|
if (BinarySearchForPosition(&aRenderingContext, text, 0, 0, 0, len,
|
|
|
|
PRInt32(contentWidth), indx, textWidth)) {
|
2004-10-20 01:46:45 +04:00
|
|
|
if (indx < len-1 ) {
|
|
|
|
// we can't fit in all the text
|
|
|
|
if (indx > 3) {
|
|
|
|
// But we can fit in at least 4 chars. Show all but 3 of them, then
|
|
|
|
// an ellipsis.
|
|
|
|
// XXXbz for non-plane0 text, this may be cutting things in the
|
|
|
|
// middle of a codepoint! Also, we have no guarantees that the three
|
|
|
|
// dots will fit in the space the three chars we removed took up with
|
|
|
|
// these font metrics!
|
|
|
|
str.Truncate(indx-3);
|
|
|
|
str.AppendLiteral("...");
|
|
|
|
} else {
|
|
|
|
// We can only fit 3 or fewer chars. Just show nothing
|
|
|
|
str.Truncate();
|
|
|
|
}
|
2002-04-26 15:30:33 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return; // bail if couldn't find the correct length
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// cacl the x and y positions of the text
|
|
|
|
nsRect rect(aRect);
|
|
|
|
nscoord x = GetXPosition(aRenderingContext, rect, aJust, str);
|
|
|
|
nscoord y;
|
|
|
|
if (aHeaderFooter == eHeader) {
|
2002-02-01 18:31:15 +03:00
|
|
|
y = rect.y + mPD->mExtraMargin.top + mPD->mEdgePaperMargin.top;
|
2001-01-27 17:09:34 +03:00
|
|
|
} else {
|
2002-02-01 18:31:15 +03:00
|
|
|
y = rect.y + rect.height - aHeight - mPD->mExtraMargin.bottom - mPD->mEdgePaperMargin.bottom;
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// set up new clip and draw the text
|
|
|
|
aRenderingContext.PushState();
|
2001-11-03 17:59:39 +03:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
2004-04-23 19:21:24 +04:00
|
|
|
aRenderingContext.SetClipRect(rect, nsClipCombine_kReplace);
|
2002-04-30 04:37:12 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2004-04-13 04:28:44 +04:00
|
|
|
if (aPresContext->BidiEnabled()) {
|
2004-07-29 23:41:39 +04:00
|
|
|
nsBidiPresUtils* bidiUtils = aPresContext->GetBidiUtils();
|
2002-04-30 04:37:12 +04:00
|
|
|
|
|
|
|
if (bidiUtils) {
|
|
|
|
// Base direction is always LTR for now. If bug 139337 is fixed,
|
|
|
|
// that should change.
|
2004-10-29 16:28:19 +04:00
|
|
|
rv = bidiUtils->RenderText(str.get(), str.Length(), NSBIDI_LTR,
|
2002-04-30 04:37:12 +04:00
|
|
|
aPresContext, aRenderingContext,
|
|
|
|
x, y + aAscent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
#endif // IBMBIDI
|
2001-10-31 01:58:00 +03:00
|
|
|
aRenderingContext.DrawString(str, x, y + aAscent);
|
2004-04-18 17:13:35 +04:00
|
|
|
aRenderingContext.PopState();
|
2002-06-20 01:51:13 +04:00
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
#ifdef DEBUG_PRINTING
|
2002-06-20 01:51:13 +04:00
|
|
|
PR_PL(("Page: %p", this));
|
2003-06-24 05:46:50 +04:00
|
|
|
PR_PL((" [%s]", NS_ConvertUCS2toUTF8(str).get()));
|
2001-04-12 17:04:29 +04:00
|
|
|
char justStr[64];
|
|
|
|
switch (aJust) {
|
2002-01-01 15:58:53 +03:00
|
|
|
case nsIPrintSettings::kJustLeft:strcpy(justStr, "Left");break;
|
|
|
|
case nsIPrintSettings::kJustCenter:strcpy(justStr, "Center");break;
|
|
|
|
case nsIPrintSettings::kJustRight:strcpy(justStr, "Right");break;
|
2001-04-12 17:04:29 +04:00
|
|
|
} // switch
|
2002-06-20 01:51:13 +04:00
|
|
|
PR_PL((" HF: %s ", aHeaderFooter==eHeader?"Header":"Footer"));
|
|
|
|
PR_PL((" JST: %s ", justStr));
|
|
|
|
PR_PL((" x,y: %d,%d", x, y));
|
|
|
|
PR_PL((" Hgt: %d \n", aHeight));
|
2001-04-12 17:04:29 +04:00
|
|
|
#endif
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPageFrame::Paint(nsPresContext* aPresContext,
|
2001-01-27 17:09:34 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
2001-09-19 16:35:19 +04:00
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
2001-01-27 17:09:34 +03:00
|
|
|
{
|
2001-04-12 17:04:29 +04:00
|
|
|
aRenderingContext.PushState();
|
2001-09-26 18:01:26 +04:00
|
|
|
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
|
|
|
|
|
|
|
nsRect rect;
|
2001-11-03 17:59:39 +03:00
|
|
|
PRBool specialClipIsSet = mClipRect.width != -1 || mClipRect.height != -1;
|
|
|
|
|
|
|
|
if (specialClipIsSet) {
|
2001-04-12 17:04:29 +04:00
|
|
|
#ifdef DEBUG_PRINTING
|
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
|
|
|
printf("*** ClipRect: %5d,%5d,%5d,%5d\n", mClipRect.x, mClipRect.y, mClipRect.width, mClipRect.height);
|
|
|
|
}
|
|
|
|
#endif
|
2004-04-23 19:21:24 +04:00
|
|
|
aRenderingContext.SetClipRect(mClipRect, nsClipCombine_kReplace);
|
2001-09-26 18:01:26 +04:00
|
|
|
rect = mClipRect;
|
|
|
|
} else {
|
|
|
|
rect = mRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
2001-12-05 01:46:41 +03:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
if (aPresContext->Type() == nsPresContext::eContext_PrintPreview) {
|
2002-01-25 17:30:14 +03:00
|
|
|
// fill page with White
|
2001-11-03 17:59:39 +03:00
|
|
|
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.width -= mPD->mShadowSize.width;
|
|
|
|
rect.height -= mPD->mShadowSize.height;
|
|
|
|
aRenderingContext.FillRect(rect);
|
2002-01-25 17:30:14 +03:00
|
|
|
// draw line around outside of page
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
|
|
|
aRenderingContext.DrawRect(rect);
|
2001-11-03 17:59:39 +03:00
|
|
|
|
|
|
|
if (mPD->mShadowSize.width > 0 && mPD->mShadowSize.height > 0) {
|
2002-01-25 17:30:14 +03:00
|
|
|
aRenderingContext.SetColor(NS_RGB(51,51,51));
|
2001-11-03 17:59:39 +03:00
|
|
|
nsRect r(0,0, mRect.width, mRect.height);
|
|
|
|
nsRect shadowRect;
|
|
|
|
shadowRect.x = r.x + r.width - mPD->mShadowSize.width;
|
|
|
|
shadowRect.y = r.y + mPD->mShadowSize.height;
|
|
|
|
shadowRect.width = mPD->mShadowSize.width;
|
|
|
|
shadowRect.height = r.height - mPD->mShadowSize.height;
|
|
|
|
aRenderingContext.FillRect(shadowRect);
|
|
|
|
|
|
|
|
shadowRect.x = r.x + mPD->mShadowSize.width;
|
|
|
|
shadowRect.y = r.y + r.height - mPD->mShadowSize.height;
|
|
|
|
shadowRect.width = r.width - mPD->mShadowSize.width;
|
|
|
|
shadowRect.height = mPD->mShadowSize.height;
|
|
|
|
aRenderingContext.FillRect(shadowRect);
|
|
|
|
}
|
|
|
|
}
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
|
2002-02-22 04:45:05 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
|
|
|
DrawBackground(aPresContext,aRenderingContext,aDirtyRect);
|
|
|
|
}
|
2001-12-05 01:46:41 +03:00
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
nsresult rv = nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
|
2001-04-12 17:04:29 +04:00
|
|
|
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
2001-01-27 17:09:34 +03:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
2002-06-20 01:51:13 +04:00
|
|
|
PR_PL(("PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d] SC:%s\n", this,
|
|
|
|
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height, specialClipIsSet?"Yes":"No"));
|
|
|
|
PR_PL(("PF::Paint -> %p SupHF: %s Rect: [%5d,%5d,%5d,%5d] SC:%s\n", this,
|
|
|
|
mSupressHF?"Yes":"No", mRect.x, mRect.y, mRect.width, mRect.height, specialClipIsSet?"Yes":"No"));
|
2001-04-12 17:04:29 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && !mSupressHF) {
|
2002-01-01 15:58:53 +03:00
|
|
|
// For PrintPreview the
|
|
|
|
if (!mPD->mPrintSettings) {
|
2004-08-01 03:15:21 +04:00
|
|
|
if (aPresContext->Type() == nsPresContext::eContext_PrintPreview) {
|
2004-07-29 23:41:39 +04:00
|
|
|
mPD->mPrintSettings = aPresContext->GetPrintSettings();
|
2002-01-01 15:58:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(mPD->mPrintSettings, "Must have a good PrintSettings here!");
|
|
|
|
|
2001-01-27 17:09:34 +03:00
|
|
|
// get the current margin
|
2002-01-01 15:58:53 +03:00
|
|
|
mPD->mPrintSettings->GetMarginInTwips(mMargin);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
rect.SetRect(0, 0, mRect.width - mPD->mShadowSize.width, mRect.height - mPD->mShadowSize.height);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2002-05-25 00:11:14 +04:00
|
|
|
aRenderingContext.SetFont(*mPD->mHeadFootFont, nsnull);
|
2001-01-27 17:09:34 +03:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
|
|
|
|
|
|
|
// Get the FontMetrics to determine width.height of strings
|
|
|
|
nsCOMPtr<nsIFontMetrics> fontMet;
|
2004-02-03 01:17:21 +03:00
|
|
|
aPresContext->DeviceContext()->GetMetricsFor(*mPD->mHeadFootFont, nsnull,
|
|
|
|
*getter_AddRefs(fontMet));
|
2001-10-31 01:58:00 +03:00
|
|
|
nscoord ascent = 0;
|
2001-01-27 17:09:34 +03:00
|
|
|
nscoord visibleHeight = 0;
|
|
|
|
if (fontMet) {
|
|
|
|
fontMet->GetHeight(visibleHeight);
|
2001-10-31 01:58:00 +03:00
|
|
|
fontMet->GetMaxAscent(ascent);
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
2001-09-26 18:01:26 +04:00
|
|
|
// print document headers and footers
|
|
|
|
PRUnichar * headers[3];
|
2002-01-01 15:58:53 +03:00
|
|
|
mPD->mPrintSettings->GetHeaderStrLeft(&headers[0]); // creates memory
|
|
|
|
mPD->mPrintSettings->GetHeaderStrCenter(&headers[1]); // creates memory
|
|
|
|
mPD->mPrintSettings->GetHeaderStrRight(&headers[2]); // creates memory
|
2002-04-30 04:37:12 +04:00
|
|
|
DrawHeaderFooter(aPresContext, aRenderingContext, this, eHeader, nsIPrintSettings::kJustLeft,
|
2001-09-26 18:01:26 +04:00
|
|
|
nsAutoString(headers[0]), nsAutoString(headers[1]), nsAutoString(headers[2]),
|
2001-10-31 01:58:00 +03:00
|
|
|
rect, ascent, visibleHeight);
|
2001-09-26 18:01:26 +04:00
|
|
|
PRInt32 i;
|
|
|
|
for (i=0;i<3;i++) nsMemory::Free(headers[i]);
|
|
|
|
|
|
|
|
PRUnichar * footers[3];
|
2002-01-01 15:58:53 +03:00
|
|
|
mPD->mPrintSettings->GetFooterStrLeft(&footers[0]); // creates memory
|
|
|
|
mPD->mPrintSettings->GetFooterStrCenter(&footers[1]); // creates memory
|
|
|
|
mPD->mPrintSettings->GetFooterStrRight(&footers[2]); // creates memory
|
2002-04-30 04:37:12 +04:00
|
|
|
DrawHeaderFooter(aPresContext, aRenderingContext, this, eFooter, nsIPrintSettings::kJustRight,
|
2001-09-26 18:01:26 +04:00
|
|
|
nsAutoString(footers[0]), nsAutoString(footers[1]), nsAutoString(footers[2]),
|
2001-10-31 01:58:00 +03:00
|
|
|
rect, ascent, visibleHeight);
|
2001-09-26 18:01:26 +04:00
|
|
|
for (i=0;i<3;i++) nsMemory::Free(footers[i]);
|
2001-01-27 17:09:34 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-04-18 17:13:35 +04:00
|
|
|
aRenderingContext.PopState();
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2001-11-03 17:59:39 +03:00
|
|
|
return rv;
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
nsPageFrame::SetPageNumInfo(PRInt32 aPageNumber, PRInt32 aTotalPages)
|
|
|
|
{
|
|
|
|
mPageNum = aPageNumber;
|
2001-04-12 17:04:29 +04:00
|
|
|
mTotNumPages = aTotalPages;
|
2001-01-27 17:09:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-05 01:46:41 +03:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPageFrame::DrawBackground(nsPresContext* aPresContext,
|
2001-12-05 01:46:41 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
|
|
|
nsSimplePageSequenceFrame* seqFrame = NS_STATIC_CAST(nsSimplePageSequenceFrame*, mParent);
|
|
|
|
if (seqFrame != nsnull) {
|
2002-02-22 04:45:05 +03:00
|
|
|
nsIFrame* pageContentFrame = mFrames.FirstChild();
|
|
|
|
NS_ASSERTION(pageContentFrame, "Must always be there.");
|
2001-12-05 01:46:41 +03:00
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBorder* border = GetStyleBorder();
|
|
|
|
const nsStylePadding* padding = GetStylePadding();
|
2001-12-05 01:46:41 +03:00
|
|
|
|
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
2003-06-30 14:46:59 +04:00
|
|
|
aDirtyRect, pageContentFrame->GetRect(), *border, *padding,
|
2003-02-23 05:49:22 +03:00
|
|
|
PR_TRUE);
|
2001-12-05 01:46:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-20 01:45:07 +04:00
|
|
|
void
|
|
|
|
nsPageFrame::SetSharedPageData(nsSharedPageData* aPD)
|
|
|
|
{
|
|
|
|
mPD = aPD;
|
|
|
|
// Set the shared data into the page frame before reflow
|
|
|
|
nsPageContentFrame * pcf = NS_STATIC_CAST(nsPageContentFrame*, mFrames.FirstChild());
|
|
|
|
if (pcf) {
|
|
|
|
pcf->SetSharedPageData(mPD);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-03-18 00:35:08 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewPageBreakFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPresShell && aNewFrame, "null PresShell or OUT ptr");
|
|
|
|
#ifdef DEBUG
|
|
|
|
//check that we are only creating page break frames when printing
|
2004-08-21 00:34:37 +04:00
|
|
|
NS_ASSERTION(aPresShell->GetPresContext()->IsPaginated(), "created a page break frame while not printing");
|
2002-03-18 00:35:08 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsPageBreakFrame* it = new (aPresShell) nsPageBreakFrame;
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPageBreakFrame::nsPageBreakFrame()
|
|
|
|
: mHaveReflowed(PR_FALSE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPageBreakFrame::~nsPageBreakFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPageBreakFrame::GetDesiredSize(nsPresContext* aPresContext,
|
2002-03-18 00:35:08 +03:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPresContext, "null pres context");
|
2004-07-29 23:41:39 +04:00
|
|
|
nscoord onePixel = aPresContext->IntScaledPixelsToTwips(1);
|
2002-03-18 00:35:08 +03:00
|
|
|
|
|
|
|
aDesiredSize.width = onePixel;
|
|
|
|
if (mHaveReflowed) {
|
|
|
|
// If blocks reflow us a 2nd time trying to put us on a new page, then return
|
|
|
|
// a desired height of 0 to avoid an extra page break.
|
|
|
|
aDesiredSize.height = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
|
|
|
// round the height down to the nearest pixel
|
|
|
|
aDesiredSize.height -= aDesiredSize.height % onePixel;
|
|
|
|
}
|
|
|
|
|
2003-01-09 17:26:32 +03:00
|
|
|
if (aDesiredSize.mComputeMEW) {
|
|
|
|
aDesiredSize.mMaxElementWidth = onePixel;
|
2002-03-18 00:35:08 +03:00
|
|
|
}
|
|
|
|
aDesiredSize.ascent = 0;
|
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPageBreakFrame::Reflow(nsPresContext* aPresContext,
|
2002-03-18 00:35:08 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPresContext, "null pres context");
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsTableFrame", aReflowState.reason);
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
GetDesiredSize(aPresContext, aReflowState, aDesiredSize);
|
|
|
|
mHaveReflowed = PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
|
|
|
nsPageBreakFrame::GetType() const
|
2002-03-18 00:35:08 +03:00
|
|
|
{
|
2003-10-31 23:19:18 +03:00
|
|
|
return nsLayoutAtoms::pageBreakFrame;
|
2002-03-18 00:35:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|