138 lines
3.8 KiB
C++
138 lines
3.8 KiB
C++
/* -*- 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 "nsTableCaptionFrame.h"
|
|
#include "nsBodyFrame.h"
|
|
#include "nsIReflowCommand.h"
|
|
#include "nsIStyleContext.h"
|
|
#include "nsStyleConsts.h"
|
|
#include "nsIPresContext.h"
|
|
#include "nsIRenderingContext.h"
|
|
#include "nsCSSRendering.h"
|
|
#include "nsIContent.h"
|
|
#include "nsIContentDelegate.h"
|
|
#include "nsCSSLayout.h"
|
|
|
|
#ifdef NS_DEBUG
|
|
static PRBool gsDebug = PR_FALSE;
|
|
#else
|
|
static const PRBool gsDebug = PR_FALSE;
|
|
#endif
|
|
|
|
/**
|
|
*/
|
|
nsTableCaptionFrame::nsTableCaptionFrame(nsIContent* aContent,
|
|
nsIFrame* aParentFrame)
|
|
: nsBodyFrame(aContent, aParentFrame),
|
|
mMinWidth(0),
|
|
mMaxWidth(0)
|
|
{
|
|
}
|
|
|
|
nsTableCaptionFrame::~nsTableCaptionFrame()
|
|
{
|
|
}
|
|
|
|
/** return the min legal width for this caption
|
|
* minWidth is the minWidth of it's content plus any insets
|
|
*/
|
|
PRInt32 nsTableCaptionFrame::GetMinWidth()
|
|
{
|
|
return mMinWidth;
|
|
}
|
|
|
|
/** return the max legal width for this caption
|
|
* maxWidth is the maxWidth of it's content when given an infinite space
|
|
* plus any insets
|
|
*/
|
|
PRInt32 nsTableCaptionFrame::GetMaxWidth()
|
|
{
|
|
return mMaxWidth;
|
|
}
|
|
|
|
/**
|
|
* Align the frame's child frame within the caption
|
|
*/
|
|
void nsTableCaptionFrame::VerticallyAlignChild(nsIPresContext* aPresContext)
|
|
{
|
|
|
|
const nsStyleText* textStyle =
|
|
(const nsStyleText*)mStyleContext->GetStyleData(eStyleStruct_Text);
|
|
const nsStyleSpacing* spacing =
|
|
(const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
|
nsMargin borderPadding;
|
|
spacing->CalcBorderPaddingFor(this, borderPadding);
|
|
|
|
nscoord topInset = borderPadding.top;
|
|
nscoord bottomInset = borderPadding.bottom;
|
|
PRUint8 verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_MIDDLE;
|
|
|
|
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
|
|
verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
|
|
}
|
|
|
|
nscoord height = mRect.height;
|
|
|
|
nsRect kidRect;
|
|
mFirstChild->GetRect(kidRect);
|
|
nscoord childHeight = kidRect.height;
|
|
|
|
|
|
// Vertically align the child
|
|
nscoord kidYTop = 0;
|
|
switch (verticalAlignFlags)
|
|
{
|
|
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
|
|
// Align the child's baseline at the max baseline
|
|
//kidYTop = aMaxAscent - kidAscent;
|
|
break;
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TOP:
|
|
// Align the top of the child frame with the top of the box,
|
|
// minus the top padding
|
|
kidYTop = topInset;
|
|
break;
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
|
|
kidYTop = height - childHeight - bottomInset;
|
|
break;
|
|
|
|
default:
|
|
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
|
|
kidYTop = height/2 - childHeight/2;
|
|
}
|
|
mFirstChild->MoveTo(kidRect.x, kidYTop);
|
|
}
|
|
|
|
/* ----- static methods ----- */
|
|
|
|
nsresult nsTableCaptionFrame::NewFrame( nsIFrame** aInstancePtrResult,
|
|
nsIContent* aContent,
|
|
nsIFrame* aParent)
|
|
{
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
if (nsnull == aInstancePtrResult) {
|
|
return NS_ERROR_NULL_POINTER;
|
|
}
|
|
nsIFrame* it = new nsTableCaptionFrame(aContent, aParent);
|
|
if (nsnull == it) {
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
*aInstancePtrResult = it;
|
|
return NS_OK;
|
|
}
|