2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00: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-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsLeafFrame.h"
|
1998-09-25 16:33:38 +00:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsCSSRendering.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
#include "nsHTMLParts.h"
|
1998-09-25 16:33:38 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
#include "nsIPresShell.h"
|
1998-09-29 23:48:07 +00:00
|
|
|
#include "nsIPresContext.h"
|
1998-09-25 16:33:38 +00:00
|
|
|
#include "nsIStyleContext.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
nsLeafFrame::~nsLeafFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-11-17 01:03:59 +00:00
|
|
|
NS_IMETHODIMP
|
2001-09-19 12:35:19 +00:00
|
|
|
nsLeafFrame::Paint(nsIPresContext* aPresContext,
|
1998-11-17 01:03:59 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-09-19 12:35:19 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-03-26 00:39:35 +00:00
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
2001-01-27 14:09:34 +00:00
|
|
|
PRBool isVisible;
|
|
|
|
if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_FALSE, &isVisible)) &&
|
|
|
|
!isVisible) {// just checks selection painting
|
|
|
|
return NS_OK; // not visibility
|
|
|
|
}
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
const nsStyleVisibility* vis =
|
|
|
|
(const nsStyleVisibility*)mStyleContext->GetStyleData(eStyleStruct_Visibility);
|
|
|
|
|
|
|
|
if (vis->IsVisibleOrCollapsed()) {
|
|
|
|
const nsStyleBackground* myColor = (const nsStyleBackground*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Background);
|
2001-02-07 09:57:26 +00:00
|
|
|
const nsStyleBorder* myBorder = (const nsStyleBorder*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Border);
|
|
|
|
const nsStyleOutline* myOutline = (const nsStyleOutline*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Outline);
|
1998-12-18 15:54:23 +00:00
|
|
|
nsRect rect(0, 0, mRect.width, mRect.height);
|
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
2001-02-07 09:57:26 +00:00
|
|
|
aDirtyRect, rect, *myColor, *myBorder, 0, 0);
|
1999-08-19 14:35:48 +00:00
|
|
|
|
1998-12-18 15:54:23 +00:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
2001-02-07 09:57:26 +00:00
|
|
|
aDirtyRect, rect, *myBorder, mStyleContext, 0);
|
1999-08-19 14:35:48 +00:00
|
|
|
|
|
|
|
nsCSSRendering::PaintOutline(aPresContext, aRenderingContext, this,
|
2001-02-07 09:57:26 +00:00
|
|
|
aDirtyRect, rect, *myBorder, *myOutline, mStyleContext, 0);
|
1998-12-18 15:54:23 +00:00
|
|
|
}
|
1998-05-26 23:15:47 +00:00
|
|
|
}
|
2001-03-13 01:47:22 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsLeafFrame", &aRenderingContext);
|
1998-04-17 01:41:24 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-11-17 01:03:59 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsLeafFrame::Reflow(nsIPresContext* aPresContext,
|
1998-11-17 01:03:59 +00:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
1998-11-20 17:13:02 +00:00
|
|
|
nsReflowStatus& aStatus)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
2000-04-21 14:59:47 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsLeafFrame", aReflowState.reason);
|
1998-11-17 01:03:59 +00:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsLeafFrame::Reflow: aMaxSize=%d,%d",
|
1999-01-05 23:31:18 +00:00
|
|
|
aReflowState.availableWidth, aReflowState.availableHeight));
|
1998-11-17 01:03:59 +00:00
|
|
|
|
1998-05-28 20:12:02 +00:00
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// XXX add in code to check for width/height being set via css
|
|
|
|
// and if set use them instead of calling GetDesiredSize.
|
|
|
|
|
1998-06-25 16:33:10 +00:00
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
1998-11-20 17:13:02 +00:00
|
|
|
nsMargin borderPadding;
|
1999-11-24 06:03:41 +00:00
|
|
|
AddBordersAndPadding(aPresContext, aReflowState, aMetrics, borderPadding);
|
1998-11-17 01:03:59 +00:00
|
|
|
if (nsnull != aMetrics.maxElementSize) {
|
1998-12-17 18:54:22 +00:00
|
|
|
aMetrics.AddBorderPaddingToMaxElementSize(borderPadding);
|
1998-11-17 01:03:59 +00:00
|
|
|
aMetrics.maxElementSize->width = aMetrics.width;
|
|
|
|
aMetrics.maxElementSize->height = aMetrics.height;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-05-12 04:17:56 +00:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
1998-11-17 01:03:59 +00:00
|
|
|
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("exit nsLeafFrame::Reflow: size=%d,%d",
|
|
|
|
aMetrics.width, aMetrics.height));
|
1998-04-17 01:41:24 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX how should border&padding effect baseline alignment?
|
|
|
|
// => descent = borderPadding.bottom for example
|
1998-11-17 01:03:59 +00:00
|
|
|
void
|
|
|
|
nsLeafFrame::AddBordersAndPadding(nsIPresContext* aPresContext,
|
1998-11-20 17:13:02 +00:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
nsMargin& aBorderPadding)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1999-03-06 01:40:29 +00:00
|
|
|
aBorderPadding = aReflowState.mComputedBorderPadding;
|
1998-11-20 17:13:02 +00:00
|
|
|
aMetrics.width += aBorderPadding.left + aBorderPadding.right;
|
|
|
|
aMetrics.height += aBorderPadding.top + aBorderPadding.bottom;
|
1998-11-17 01:03:59 +00:00
|
|
|
aMetrics.ascent = aMetrics.height;
|
|
|
|
aMetrics.descent = 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-11-17 01:03:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLeafFrame::ContentChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsISupports* aSubContent)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
/*
|
1998-06-09 04:51:44 +00:00
|
|
|
// Generate a reflow command with this frame as the target frame
|
|
|
|
nsIReflowCommand* cmd;
|
1999-02-12 17:45:58 +00:00
|
|
|
nsresult rv;
|
1998-06-09 04:51:44 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
rv = NS_NewHTMLReflowCommand(&cmd, this, nsIReflowCommand::ContentChanged);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = aPresContext->GetShell(getter_AddRefs(shell));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
1999-02-12 17:45:58 +00:00
|
|
|
shell->AppendReflowCommand(cmd);
|
|
|
|
}
|
1998-06-09 04:51:44 +00:00
|
|
|
NS_RELEASE(cmd);
|
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
return rv;
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
mState |= NS_FRAME_IS_DIRTY;
|
|
|
|
return mParent->ReflowDirtyChild(shell, this);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-09 04:51:44 +00:00
|
|
|
|
1999-09-01 01:02:16 +00:00
|
|
|
#ifdef DEBUG
|
1999-08-31 03:09:40 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLeafFrame::SizeOf(nsISizeOfHandler* aHandler,
|
|
|
|
PRUint32* aResult) const
|
|
|
|
{
|
1999-09-01 01:02:16 +00:00
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-08-31 03:09:40 +00:00
|
|
|
}
|
1999-09-01 01:02:16 +00:00
|
|
|
*aResult = sizeof(*this);
|
|
|
|
return NS_OK;
|
1999-08-31 03:09:40 +00:00
|
|
|
}
|
1999-09-01 01:02:16 +00:00
|
|
|
#endif
|