1998-04-14 00:24:54 +04: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 "nsLeafFrame.h"
|
1998-09-25 20:33:38 +04:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsCSSRendering.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsHTMLParts.h"
|
1998-09-25 20:33:38 +04:00
|
|
|
#include "nsHTMLAtoms.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsIPresShell.h"
|
1998-09-30 03:48:07 +04:00
|
|
|
#include "nsIPresContext.h"
|
1998-09-25 20:33:38 +04:00
|
|
|
#include "nsIStyleContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-06 03:56:50 +04:00
|
|
|
nsLeafFrame::nsLeafFrame(nsIContent* aContent, nsIFrame* aParentFrame)
|
|
|
|
: nsFrame(aContent, aParentFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLeafFrame::~nsLeafFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD nsLeafFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleDisplay* disp =
|
|
|
|
(const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
1998-05-27 03:15:47 +04:00
|
|
|
|
|
|
|
if (disp->mVisible) {
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleColor* myColor =
|
|
|
|
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
const nsStyleSpacing* mySpacing =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
1998-07-22 09:02:07 +04:00
|
|
|
|
|
|
|
nsRect rect(0, 0, mRect.width, mRect.height);
|
1998-05-27 03:15:47 +04:00
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
1998-09-26 21:17:20 +04:00
|
|
|
aDirtyRect, rect, *myColor, 0, 0);
|
1998-05-27 03:15:47 +04:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
1998-07-22 09:02:07 +04:00
|
|
|
aDirtyRect, rect, *mySpacing, 0);
|
1998-05-27 03:15:47 +04:00
|
|
|
}
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-07-15 06:53:09 +04:00
|
|
|
NS_METHOD nsLeafFrame::Reflow(nsIPresContext& aPresContext,
|
1998-10-01 08:46:11 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
1998-10-02 08:10:00 +04:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
1998-05-25 21:31:49 +04:00
|
|
|
nsReflowStatus& aStatus)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-29 00:12:02 +04:00
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
1998-04-14 00:24:54 +04: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 20:33:10 +04:00
|
|
|
|
1998-07-15 06:53:09 +04:00
|
|
|
GetDesiredSize(&aPresContext, aReflowState, aDesiredSize);
|
|
|
|
AddBordersAndPadding(&aPresContext, aDesiredSize);
|
1998-05-25 21:31:49 +04:00
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
|
|
|
aDesiredSize.maxElementSize->width = aDesiredSize.width;
|
|
|
|
aDesiredSize.maxElementSize->height = aDesiredSize.height;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-05-12 08:17:56 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX how should border&padding effect baseline alignment?
|
|
|
|
// => descent = borderPadding.bottom for example
|
|
|
|
void nsLeafFrame::AddBordersAndPadding(nsIPresContext* aPresContext,
|
1998-10-01 08:46:11 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleSpacing* space =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
1998-05-13 02:28:01 +04:00
|
|
|
nsMargin borderPadding;
|
|
|
|
space->CalcBorderPaddingFor(this, borderPadding);
|
|
|
|
aDesiredSize.width += borderPadding.left + borderPadding.right;
|
|
|
|
aDesiredSize.height += borderPadding.top + borderPadding.bottom;
|
1998-04-14 00:24:54 +04:00
|
|
|
aDesiredSize.ascent = aDesiredSize.height;
|
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsLeafFrame::GetInnerArea(nsIPresContext* aPresContext,
|
|
|
|
nsRect& aInnerArea) const
|
|
|
|
{
|
1998-06-05 10:09:09 +04:00
|
|
|
const nsStyleSpacing* space =
|
|
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
1998-05-13 02:28:01 +04:00
|
|
|
nsMargin borderPadding;
|
|
|
|
space->CalcBorderPaddingFor(this, borderPadding);
|
|
|
|
aInnerArea.x = borderPadding.left;
|
|
|
|
aInnerArea.y = borderPadding.top;
|
1998-04-14 00:24:54 +04:00
|
|
|
aInnerArea.width = mRect.width -
|
1998-05-13 02:28:01 +04:00
|
|
|
(borderPadding.left + borderPadding.right);
|
1998-04-14 00:24:54 +04:00
|
|
|
aInnerArea.height = mRect.height -
|
1998-05-13 02:28:01 +04:00
|
|
|
(borderPadding.top + borderPadding.bottom);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-09-30 03:48:07 +04:00
|
|
|
NS_METHOD nsLeafFrame::ContentChanged(nsIPresContext* aPresContext,
|
1998-06-09 08:51:44 +04:00
|
|
|
nsIContent* aChild,
|
|
|
|
nsISupports* aSubContent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-09 08:51:44 +04:00
|
|
|
// Generate a reflow command with this frame as the target frame
|
|
|
|
nsIReflowCommand* cmd;
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
result = NS_NewHTMLReflowCommand(&cmd, this, nsIReflowCommand::ContentChanged);
|
|
|
|
if (NS_OK == result) {
|
1998-09-30 03:48:07 +04:00
|
|
|
nsIPresShell* shell = aPresContext->GetShell();
|
|
|
|
shell->AppendReflowCommand(cmd);
|
|
|
|
NS_RELEASE(shell);
|
1998-06-09 08:51:44 +04:00
|
|
|
NS_RELEASE(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-06-09 08:51:44 +04:00
|
|
|
|