gecko-dev/layout/generic/nsLeafFrame.cpp

125 lines
4.5 KiB
C++
Raw Normal View History

1998-04-13 20:24:54 +00:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#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"
#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
nsLeafFrame::Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
1998-12-18 15:54:23 +00:00
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer)
1998-04-13 20:24:54 +00:00
{
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
1998-12-18 15:54:23 +00:00
const nsStyleDisplay* disp = (const nsStyleDisplay*)
mStyleContext->GetStyleData(eStyleStruct_Display);
if (disp->mVisible) {
const nsStyleColor* myColor = (const nsStyleColor*)
mStyleContext->GetStyleData(eStyleStruct_Color);
const nsStyleSpacing* mySpacing = (const nsStyleSpacing*)
mStyleContext->GetStyleData(eStyleStruct_Spacing);
nsRect rect(0, 0, mRect.width, mRect.height);
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
aDirtyRect, rect, *myColor, *mySpacing, 0, 0);
1998-12-18 15:54:23 +00:00
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
aDirtyRect, rect, *mySpacing, mStyleContext, 0);
1998-12-18 15:54:23 +00:00
}
}
return NS_OK;
1998-04-13 20:24:54 +00:00
}
1998-11-17 01:03:59 +00:00
NS_IMETHODIMP
nsLeafFrame::Reflow(nsIPresContext& aPresContext,
1998-11-17 01:03:59 +00:00
nsHTMLReflowMetrics& aMetrics,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
1998-04-13 20:24:54 +00:00
{
1998-11-17 01:03:59 +00:00
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
("enter nsLeafFrame::Reflow: aMaxSize=%d,%d",
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
1998-11-17 01:03:59 +00:00
GetDesiredSize(&aPresContext, aReflowState, aMetrics);
nsMargin borderPadding;
AddBordersAndPadding(&aPresContext, aReflowState, aMetrics, borderPadding);
1998-11-17 01:03:59 +00:00
if (nsnull != aMetrics.maxElementSize) {
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));
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,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aMetrics,
nsMargin& aBorderPadding)
1998-04-13 20:24:54 +00:00
{
aBorderPadding = aReflowState.mComputedBorderPadding;
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
{
1998-06-09 04:51:44 +00:00
// Generate a reflow command with this frame as the target frame
nsIReflowCommand* cmd;
nsresult rv;
1998-06-09 04:51:44 +00:00
rv = NS_NewHTMLReflowCommand(&cmd, this, nsIReflowCommand::ContentChanged);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIPresShell> shell;
rv = aPresContext->GetShell(getter_AddRefs(shell));
if (NS_SUCCEEDED(rv) && shell) {
shell->AppendReflowCommand(cmd);
}
1998-06-09 04:51:44 +00:00
NS_RELEASE(cmd);
}
return rv;
1998-04-13 20:24:54 +00:00
}
1998-06-09 04:51:44 +00:00