1999-01-05 19:44:41 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +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/
|
1999-01-05 19:44:41 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +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.
|
1999-01-05 19:44:41 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 03:40:37 +00:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-01-05 19:44:41 +00:00
|
|
|
*/
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-01-05 19:44:41 +00:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
1999-03-05 04:24:20 +00:00
|
|
|
#include "nsFrame.h"
|
1999-01-05 19:44:41 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
1999-01-13 06:37:31 +00:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
1999-02-14 04:43:44 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-03-31 04:11:40 +00:00
|
|
|
#include "nsIRenderingContext.h"
|
1999-09-09 21:03:27 +00:00
|
|
|
#include "nsIFontMetrics.h"
|
2000-04-16 04:07:02 +00:00
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsLineBox.h"
|
|
|
|
#include "nsImageFrame.h"
|
1999-01-05 19:44:41 +00:00
|
|
|
|
1999-03-08 19:26:30 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#undef NOISY_VERTICAL_ALIGN
|
|
|
|
#else
|
|
|
|
#undef NOISY_VERTICAL_ALIGN
|
|
|
|
#endif
|
|
|
|
|
1999-03-05 04:24:20 +00:00
|
|
|
// Initialize a <b>root</b> reflow state with a rendering context to
|
|
|
|
// use for measuring things.
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsIPresContext* aPresContext,
|
1999-03-05 04:24:20 +00:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsReflowReason aReason,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
const nsSize& aAvailableSpace)
|
1999-08-27 21:48:54 +00:00
|
|
|
: mReflowDepth(0)
|
1999-03-05 04:24:20 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aRenderingContext, "no rendering context");
|
|
|
|
|
|
|
|
parentReflowState = nsnull;
|
|
|
|
frame = aFrame;
|
|
|
|
reason = aReason;
|
|
|
|
reflowCommand = nsnull;
|
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
rendContext = aRenderingContext;
|
1999-07-20 03:41:03 +00:00
|
|
|
mSpaceManager = nsnull;
|
1999-07-20 03:51:46 +00:00
|
|
|
mLineLayout = nsnull;
|
1999-03-05 04:24:20 +00:00
|
|
|
isTopOfPage = PR_FALSE;
|
|
|
|
Init(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize a <b>root</b> reflow state for an <b>incremental</b>
|
|
|
|
// reflow.
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsIPresContext* aPresContext,
|
1999-03-05 04:24:20 +00:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIReflowCommand& aReflowCommand,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
const nsSize& aAvailableSpace)
|
1999-08-27 21:48:54 +00:00
|
|
|
: mReflowDepth(0)
|
1999-03-05 04:24:20 +00:00
|
|
|
{
|
2000-01-12 08:28:24 +00:00
|
|
|
NS_PRECONDITION(nsnull != aRenderingContext, "no rendering context");
|
1999-03-05 04:24:20 +00:00
|
|
|
|
2000-01-12 08:28:24 +00:00
|
|
|
reason = eReflowReason_Incremental;
|
1999-03-05 04:24:20 +00:00
|
|
|
parentReflowState = nsnull;
|
|
|
|
frame = aFrame;
|
|
|
|
reflowCommand = &aReflowCommand;
|
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
rendContext = aRenderingContext;
|
1999-07-20 03:41:03 +00:00
|
|
|
mSpaceManager = nsnull;
|
1999-07-20 03:51:46 +00:00
|
|
|
mLineLayout = nsnull;
|
1999-03-05 04:24:20 +00:00
|
|
|
isTopOfPage = PR_FALSE;
|
|
|
|
Init(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize a reflow state for a child frames reflow. Some state
|
|
|
|
// is copied from the parent reflow state; the remaining state is
|
|
|
|
// computed.
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsIPresContext* aPresContext,
|
1999-03-05 04:24:20 +00:00
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsSize& aAvailableSpace,
|
|
|
|
nsReflowReason aReason)
|
1999-08-27 21:48:54 +00:00
|
|
|
: mReflowDepth(aParentReflowState.mReflowDepth + 1)
|
1999-03-05 04:24:20 +00:00
|
|
|
{
|
|
|
|
parentReflowState = &aParentReflowState;
|
|
|
|
frame = aFrame;
|
|
|
|
reason = aReason;
|
|
|
|
reflowCommand = (reason == eReflowReason_Incremental)
|
|
|
|
? aParentReflowState.reflowCommand
|
|
|
|
: nsnull;
|
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
|
|
|
|
rendContext = aParentReflowState.rendContext;
|
1999-07-20 03:41:03 +00:00
|
|
|
mSpaceManager = aParentReflowState.mSpaceManager;
|
1999-07-20 03:51:46 +00:00
|
|
|
mLineLayout = aParentReflowState.mLineLayout;
|
1999-03-05 04:24:20 +00:00
|
|
|
isTopOfPage = aParentReflowState.isTopOfPage;
|
|
|
|
|
|
|
|
Init(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as the previous except that the reason is taken from the
|
|
|
|
// parent's reflow state.
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsIPresContext* aPresContext,
|
1999-03-05 04:24:20 +00:00
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsSize& aAvailableSpace)
|
1999-08-27 21:48:54 +00:00
|
|
|
: mReflowDepth(aParentReflowState.mReflowDepth + 1)
|
1999-03-05 04:24:20 +00:00
|
|
|
{
|
|
|
|
parentReflowState = &aParentReflowState;
|
|
|
|
frame = aFrame;
|
|
|
|
reason = aParentReflowState.reason;
|
|
|
|
reflowCommand = aParentReflowState.reflowCommand;
|
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
|
|
|
|
rendContext = aParentReflowState.rendContext;
|
1999-07-20 03:41:03 +00:00
|
|
|
mSpaceManager = aParentReflowState.mSpaceManager;
|
1999-07-20 03:51:46 +00:00
|
|
|
mLineLayout = aParentReflowState.mLineLayout;
|
1999-03-05 04:24:20 +00:00
|
|
|
isTopOfPage = aParentReflowState.isTopOfPage;
|
|
|
|
|
|
|
|
Init(aPresContext);
|
|
|
|
}
|
|
|
|
|
1999-09-16 14:33:19 +00:00
|
|
|
// Version that species the containing block width and height
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsIPresContext* aPresContext,
|
1999-09-16 14:33:19 +00:00
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsSize& aAvailableSpace,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight)
|
|
|
|
: mReflowDepth(aParentReflowState.mReflowDepth + 1)
|
|
|
|
{
|
|
|
|
parentReflowState = &aParentReflowState;
|
|
|
|
frame = aFrame;
|
|
|
|
reason = aParentReflowState.reason;
|
|
|
|
reflowCommand = aParentReflowState.reflowCommand;
|
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
|
|
|
|
rendContext = aParentReflowState.rendContext;
|
|
|
|
mSpaceManager = aParentReflowState.mSpaceManager;
|
|
|
|
mLineLayout = aParentReflowState.mLineLayout;
|
|
|
|
isTopOfPage = aParentReflowState.isTopOfPage;
|
|
|
|
|
|
|
|
Init(aPresContext, aContainingBlockWidth, aContainingBlockHeight);
|
|
|
|
}
|
|
|
|
|
1999-03-05 04:24:20 +00:00
|
|
|
void
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLReflowState::Init(nsIPresContext* aPresContext,
|
1999-09-16 14:33:19 +00:00
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight)
|
1999-03-05 04:24:20 +00:00
|
|
|
{
|
|
|
|
mCompactMarginWidth = 0;
|
|
|
|
mAlignCharOffset = 0;
|
|
|
|
mUseAlignCharOffset = 0;
|
|
|
|
|
|
|
|
frame->GetStyleData(eStyleStruct_Position,
|
|
|
|
(const nsStyleStruct*&)mStylePosition);
|
|
|
|
frame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&)mStyleDisplay);
|
|
|
|
frame->GetStyleData(eStyleStruct_Spacing,
|
|
|
|
(const nsStyleStruct*&)mStyleSpacing);
|
1999-07-20 03:41:03 +00:00
|
|
|
mFrameType = DetermineFrameType(frame, mStylePosition, mStyleDisplay);
|
1999-09-16 14:33:19 +00:00
|
|
|
InitConstraints(aPresContext, aContainingBlockWidth, aContainingBlockHeight);
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
|
|
|
|
1999-01-05 19:44:41 +00:00
|
|
|
const nsHTMLReflowState*
|
1999-10-30 02:52:11 +00:00
|
|
|
nsHTMLReflowState::GetContainingBlockReflowState(const nsHTMLReflowState* aParentRS)
|
1999-01-05 19:44:41 +00:00
|
|
|
{
|
|
|
|
while (nsnull != aParentRS) {
|
|
|
|
if (nsnull != aParentRS->frame) {
|
|
|
|
PRBool isContainingBlock;
|
|
|
|
// XXX This needs to go and we need to start using the info in the
|
|
|
|
// reflow state...
|
|
|
|
nsresult rv = aParentRS->frame->IsPercentageBase(isContainingBlock);
|
|
|
|
if (NS_SUCCEEDED(rv) && isContainingBlock) {
|
1999-10-30 02:52:11 +00:00
|
|
|
return aParentRS;
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
aParentRS = aParentRS->parentReflowState;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsHTMLReflowState*
|
1999-10-30 02:52:11 +00:00
|
|
|
nsHTMLReflowState::GetPageBoxReflowState(const nsHTMLReflowState* aParentRS)
|
1999-01-05 19:44:41 +00:00
|
|
|
{
|
|
|
|
// XXX write me as soon as we can ask a frame if it's a page frame...
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
1999-10-30 02:52:11 +00:00
|
|
|
nsHTMLReflowState::GetContainingBlockContentWidth(const nsHTMLReflowState* aParentRS)
|
1999-01-05 19:44:41 +00:00
|
|
|
{
|
|
|
|
nscoord width = 0;
|
|
|
|
const nsHTMLReflowState* rs =
|
|
|
|
GetContainingBlockReflowState(aParentRS);
|
|
|
|
if (nsnull != rs) {
|
1999-10-30 02:52:11 +00:00
|
|
|
return aParentRS->mComputedWidth;
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
1999-02-23 19:33:06 +00:00
|
|
|
nsCSSFrameType
|
|
|
|
nsHTMLReflowState::DetermineFrameType(nsIFrame* aFrame)
|
1999-03-05 04:24:20 +00:00
|
|
|
{
|
|
|
|
const nsStylePosition* stylePosition;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Position,
|
|
|
|
(const nsStyleStruct*&)stylePosition);
|
|
|
|
const nsStyleDisplay* styleDisplay;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&)styleDisplay);
|
|
|
|
return DetermineFrameType(aFrame, stylePosition, styleDisplay);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSFrameType
|
|
|
|
nsHTMLReflowState::DetermineFrameType(nsIFrame* aFrame,
|
|
|
|
const nsStylePosition* aPosition,
|
|
|
|
const nsStyleDisplay* aDisplay)
|
1999-01-05 19:44:41 +00:00
|
|
|
{
|
1999-02-23 19:33:06 +00:00
|
|
|
nsCSSFrameType frameType;
|
1999-01-05 19:44:41 +00:00
|
|
|
|
1999-09-28 23:42:35 +00:00
|
|
|
// Get the frame state
|
|
|
|
nsFrameState frameState;
|
|
|
|
aFrame->GetFrameState(&frameState);
|
|
|
|
|
1999-02-23 19:33:06 +00:00
|
|
|
// Section 9.7 of the CSS2 spec indicates that absolute position
|
|
|
|
// takes precedence over float which takes precedence over display.
|
1999-09-28 23:42:35 +00:00
|
|
|
// Make sure the frame was actually moved out of the flow, and don't
|
|
|
|
// just assume what the style says
|
|
|
|
if (frameState & NS_FRAME_OUT_OF_FLOW) {
|
|
|
|
if (aPosition->IsAbsolutelyPositioned()) {
|
|
|
|
frameType = NS_CSS_FRAME_TYPE_ABSOLUTE;
|
|
|
|
}
|
|
|
|
else if (NS_STYLE_FLOAT_NONE != aDisplay->mFloats) {
|
|
|
|
frameType = NS_CSS_FRAME_TYPE_FLOATING;
|
|
|
|
}
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-03-05 04:24:20 +00:00
|
|
|
switch (aDisplay->mDisplay) {
|
1999-01-05 19:44:41 +00:00
|
|
|
case NS_STYLE_DISPLAY_BLOCK:
|
|
|
|
case NS_STYLE_DISPLAY_LIST_ITEM:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE:
|
|
|
|
frameType = NS_CSS_FRAME_TYPE_BLOCK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_INLINE:
|
|
|
|
case NS_STYLE_DISPLAY_MARKER:
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_TABLE:
|
|
|
|
frameType = NS_CSS_FRAME_TYPE_INLINE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_RUN_IN:
|
|
|
|
case NS_STYLE_DISPLAY_COMPACT:
|
|
|
|
// XXX need to look ahead at the frame's sibling
|
|
|
|
frameType = NS_CSS_FRAME_TYPE_BLOCK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_CELL:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_CAPTION:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_ROW_GROUP:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_COLUMN:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_HEADER_GROUP:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_ROW:
|
|
|
|
frameType = NS_CSS_FRAME_TYPE_INTERNAL_TABLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_NONE:
|
|
|
|
default:
|
|
|
|
frameType = NS_CSS_FRAME_TYPE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-13 05:59:19 +00:00
|
|
|
// See if the frame is replaced
|
|
|
|
if (frameState & NS_FRAME_REPLACED_ELEMENT) {
|
1999-01-05 19:44:41 +00:00
|
|
|
frameType = NS_FRAME_REPLACED(frameType);
|
|
|
|
}
|
1999-02-23 19:33:06 +00:00
|
|
|
|
|
|
|
return frameType;
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-04-22 04:27:47 +00:00
|
|
|
nsHTMLReflowState::ComputeRelativeOffsets(const nsHTMLReflowState* cbrs,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight)
|
1999-01-16 20:58:17 +00:00
|
|
|
{
|
1999-04-22 04:27:47 +00:00
|
|
|
nsStyleCoord coord;
|
1999-01-16 20:58:17 +00:00
|
|
|
|
1999-01-22 04:12:03 +00:00
|
|
|
// Compute the 'left' and 'right' values. 'Left' moves the boxes to the right,
|
|
|
|
// and 'right' moves the boxes to the left. The computed values are always:
|
|
|
|
// left=-right
|
1999-03-05 04:24:20 +00:00
|
|
|
PRBool leftIsAuto = eStyleUnit_Auto == mStylePosition->mOffset.GetLeftUnit();
|
|
|
|
PRBool rightIsAuto = eStyleUnit_Auto == mStylePosition->mOffset.GetRightUnit();
|
1999-01-22 04:12:03 +00:00
|
|
|
|
1999-01-23 04:49:15 +00:00
|
|
|
// Check for percentage based values and an unconstrained containing
|
|
|
|
// block width. Treat them like 'auto'
|
1999-04-22 04:27:47 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Percent == mStylePosition->mOffset.GetLeftUnit()) {
|
1999-01-23 04:49:15 +00:00
|
|
|
leftIsAuto = PR_TRUE;
|
|
|
|
}
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Percent == mStylePosition->mOffset.GetRightUnit()) {
|
1999-01-23 04:49:15 +00:00
|
|
|
rightIsAuto = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-22 04:12:03 +00:00
|
|
|
// If neither 'left' not 'right' are auto, then we're over-constrained and
|
|
|
|
// we ignore one of them
|
|
|
|
if (!leftIsAuto && !rightIsAuto) {
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
|
|
|
|
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == display->mDirection) {
|
|
|
|
rightIsAuto = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
leftIsAuto = PR_TRUE;
|
|
|
|
}
|
1999-01-16 20:58:17 +00:00
|
|
|
}
|
|
|
|
|
1999-01-22 04:12:03 +00:00
|
|
|
if (leftIsAuto) {
|
|
|
|
if (rightIsAuto) {
|
|
|
|
// If both are 'auto' (their initial values), the computed values are 0
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.left = mComputedOffsets.right = 0;
|
1999-01-22 04:12:03 +00:00
|
|
|
} else {
|
|
|
|
// 'Right' isn't 'auto' so compute its value
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Inherit == mStylePosition->mOffset.GetRightUnit()) {
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.right = cbrs->mComputedOffsets.right;
|
1999-01-22 04:12:03 +00:00
|
|
|
} else {
|
1999-04-22 04:27:47 +00:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, mStylePosition->mOffset.GetRightUnit(),
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mOffset.GetRight(coord),
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.right);
|
1999-01-22 04:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Computed value for 'left' is minus the value of 'right'
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.left = -mComputedOffsets.right;
|
1999-01-22 04:12:03 +00:00
|
|
|
}
|
|
|
|
|
1999-01-16 20:58:17 +00:00
|
|
|
} else {
|
1999-01-22 04:12:03 +00:00
|
|
|
NS_ASSERTION(rightIsAuto, "unexpected specified constraint");
|
|
|
|
|
|
|
|
// 'Left' isn't 'auto' so compute its value
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Inherit == mStylePosition->mOffset.GetLeftUnit()) {
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.left = cbrs->mComputedOffsets.left;
|
1999-01-22 04:12:03 +00:00
|
|
|
} else {
|
1999-04-22 04:27:47 +00:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, mStylePosition->mOffset.GetLeftUnit(),
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mOffset.GetLeft(coord),
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.left);
|
1999-01-22 04:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Computed value for 'right' is minus the value of 'left'
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.right = -mComputedOffsets.left;
|
1999-01-16 20:58:17 +00:00
|
|
|
}
|
|
|
|
|
1999-01-22 04:12:03 +00:00
|
|
|
// Compute the 'top' and 'bottom' values. The 'top' and 'bottom' properties
|
|
|
|
// move relatively positioned elements up and down. They also must be each
|
|
|
|
// other's negative
|
1999-03-05 04:24:20 +00:00
|
|
|
PRBool topIsAuto = eStyleUnit_Auto == mStylePosition->mOffset.GetTopUnit();
|
|
|
|
PRBool bottomIsAuto = eStyleUnit_Auto == mStylePosition->mOffset.GetBottomUnit();
|
1999-01-22 04:12:03 +00:00
|
|
|
|
1999-01-23 04:49:15 +00:00
|
|
|
// Check for percentage based values and a containing block height that
|
|
|
|
// depends on the content height. Treat them like 'auto'
|
1999-04-22 04:27:47 +00:00
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Percent == mStylePosition->mOffset.GetTopUnit()) {
|
1999-01-23 04:49:15 +00:00
|
|
|
topIsAuto = PR_TRUE;
|
|
|
|
}
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Percent == mStylePosition->mOffset.GetBottomUnit()) {
|
1999-01-23 04:49:15 +00:00
|
|
|
bottomIsAuto = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-22 04:12:03 +00:00
|
|
|
// If neither is 'auto', 'bottom' is ignored
|
|
|
|
if (!topIsAuto && !bottomIsAuto) {
|
|
|
|
bottomIsAuto = PR_TRUE;
|
1999-01-16 20:58:17 +00:00
|
|
|
}
|
|
|
|
|
1999-01-22 04:12:03 +00:00
|
|
|
if (topIsAuto) {
|
|
|
|
if (bottomIsAuto) {
|
|
|
|
// If both are 'auto' (their initial values), the computed values are 0
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.top = mComputedOffsets.bottom = 0;
|
1999-01-22 04:12:03 +00:00
|
|
|
} else {
|
|
|
|
// 'Bottom' isn't 'auto' so compute its value
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Inherit == mStylePosition->mOffset.GetBottomUnit()) {
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.bottom = cbrs->mComputedOffsets.bottom;
|
1999-01-22 04:12:03 +00:00
|
|
|
} else {
|
1999-04-22 04:27:47 +00:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight, mStylePosition->mOffset.GetBottomUnit(),
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mOffset.GetBottom(coord),
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.bottom);
|
1999-01-22 04:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Computed value for 'top' is minus the value of 'bottom'
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.top = -mComputedOffsets.bottom;
|
1999-01-22 04:12:03 +00:00
|
|
|
}
|
|
|
|
|
1999-01-16 20:58:17 +00:00
|
|
|
} else {
|
1999-01-22 04:12:03 +00:00
|
|
|
NS_ASSERTION(bottomIsAuto, "unexpected specified constraint");
|
|
|
|
|
|
|
|
// 'Top' isn't 'auto' so compute its value
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Inherit == mStylePosition->mOffset.GetTopUnit()) {
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.top = cbrs->mComputedOffsets.top;
|
1999-01-22 04:12:03 +00:00
|
|
|
} else {
|
1999-04-22 04:27:47 +00:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight, mStylePosition->mOffset.GetTopUnit(),
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mOffset.GetTop(coord),
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.top);
|
1999-01-22 04:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Computed value for 'bottom' is minus the value of 'top'
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.bottom = -mComputedOffsets.top;
|
1999-01-16 20:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
// Returns the nearest containing block frame for the specified frame.
|
|
|
|
// Also returns the left, top, right, and bottom edges of the specified
|
|
|
|
// frame's content area. These are in the coordinate space of the block
|
|
|
|
// frame itself
|
|
|
|
static nsIFrame*
|
|
|
|
GetNearestContainingBlock(nsIFrame* aFrame, nsMargin& aContentArea)
|
|
|
|
{
|
|
|
|
aFrame->GetParent(&aFrame);
|
|
|
|
while (aFrame) {
|
|
|
|
nsIAtom* frameType;
|
|
|
|
PRBool isBlock;
|
|
|
|
|
|
|
|
aFrame->GetFrameType(&frameType);
|
2000-04-19 03:27:31 +00:00
|
|
|
isBlock = (frameType == nsLayoutAtoms::blockFrame) ||
|
|
|
|
(frameType == nsLayoutAtoms::areaFrame);
|
2000-04-16 04:07:02 +00:00
|
|
|
NS_IF_RELEASE(frameType);
|
|
|
|
|
|
|
|
if (isBlock) {
|
|
|
|
break;
|
|
|
|
}
|
2000-04-18 05:03:42 +00:00
|
|
|
aFrame->GetParent(&aFrame);
|
2000-04-16 04:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFrame) {
|
|
|
|
nsSize size;
|
|
|
|
|
|
|
|
aFrame->GetSize(size);
|
|
|
|
aContentArea.left = 0;
|
|
|
|
aContentArea.top = 0;
|
|
|
|
aContentArea.right = size.width;
|
|
|
|
aContentArea.bottom = size.height;
|
|
|
|
|
|
|
|
// Subtract off for border and padding. If it can't be computed because
|
|
|
|
// it's percentage based (for example) then just ignore it
|
|
|
|
nsStyleSpacing* spacing;
|
|
|
|
nsMargin borderPadding;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct*&)spacing);
|
|
|
|
if (spacing->GetBorderPadding(borderPadding)) {
|
|
|
|
aContentArea.left += borderPadding.left;
|
|
|
|
aContentArea.top += borderPadding.top;
|
|
|
|
aContentArea.right -= borderPadding.right;
|
|
|
|
aContentArea.bottom -= borderPadding.bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When determining the hypothetical box that would have been if the element
|
|
|
|
// had been in the flow we may not be able to exactly determine both the left
|
|
|
|
// and right edges. For example, if the element is a non-replaced inline-level
|
|
|
|
// element we would have to reflow it in order to determine it desired width.
|
|
|
|
// In that case depending on the progression direction either the left or
|
|
|
|
// right edge would be marked as not being exact
|
|
|
|
struct nsHypotheticalBox {
|
|
|
|
nscoord mLeft, mRight;
|
|
|
|
nscoord mTop;
|
|
|
|
PRPackedBool mLeftIsExact, mRightIsExact;
|
|
|
|
|
|
|
|
nsHypotheticalBox() {
|
|
|
|
mLeftIsExact = mRightIsExact = PR_FALSE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
GetIntrinsicSizeFor(nsIFrame* aFrame, nsSize& aIntrinsicSize)
|
|
|
|
{
|
|
|
|
// See if it is an image frame
|
|
|
|
nsIAtom* frameType;
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
// Currently the only type of replaced frame that we can get the intrinsic
|
|
|
|
// size for is an image frame
|
|
|
|
// XXX We should add back the GetReflowMetrics() function and one of the
|
|
|
|
// things should be the intrinsic size...
|
|
|
|
aFrame->GetFrameType(&frameType);
|
|
|
|
if (frameType == nsLayoutAtoms::imageFrame) {
|
|
|
|
nsImageFrame* imageFrame = (nsImageFrame*)aFrame;
|
|
|
|
|
|
|
|
imageFrame->GetIntrinsicImageSize(aIntrinsicSize);
|
|
|
|
result = (aIntrinsicSize != nsSize(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(frameType);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsHTMLReflowState::CalculateHorizBorderPaddingMargin(nscoord aContainingBlockWidth)
|
|
|
|
{
|
|
|
|
nsMargin border, padding, margin;
|
|
|
|
|
|
|
|
// Get the border
|
|
|
|
if (!mStyleSpacing->GetBorder(border)) {
|
|
|
|
// CSS2 has no percentage borders
|
|
|
|
border.SizeTo(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the style system can provide us the padding directly
|
|
|
|
if (!mStyleSpacing->GetPadding(padding)) {
|
|
|
|
nsStyleCoord left, right;
|
|
|
|
|
|
|
|
// We have to compute the left and right values
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mPadding.GetLeftUnit()) {
|
|
|
|
padding.left = 0; // just ignore
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mPadding.GetLeftUnit(),
|
|
|
|
mStyleSpacing->mPadding.GetLeft(left),
|
|
|
|
padding.left);
|
|
|
|
}
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mPadding.GetRightUnit()) {
|
|
|
|
padding.right = 0; // just ignore
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mPadding.GetRightUnit(),
|
|
|
|
mStyleSpacing->mPadding.GetRight(right),
|
|
|
|
padding.right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the style system can provide us the margin directly
|
|
|
|
if (!mStyleSpacing->GetMargin(margin)) {
|
|
|
|
nsStyleCoord left, right;
|
|
|
|
|
|
|
|
// We have to compute the left and right values
|
|
|
|
if ((eStyleUnit_Auto == mStyleSpacing->mMargin.GetLeftUnit()) ||
|
|
|
|
(eStyleUnit_Inherit == mStyleSpacing->mMargin.GetLeftUnit())) {
|
|
|
|
margin.left = 0; // just ignore
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mMargin.GetLeftUnit(),
|
|
|
|
mStyleSpacing->mMargin.GetLeft(left),
|
|
|
|
margin.left);
|
|
|
|
}
|
|
|
|
if ((eStyleUnit_Auto == mStyleSpacing->mMargin.GetRightUnit()) ||
|
|
|
|
(eStyleUnit_Inherit == mStyleSpacing->mMargin.GetRightUnit())) {
|
|
|
|
margin.right = 0; // just ignore
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mMargin.GetRightUnit(),
|
|
|
|
mStyleSpacing->mMargin.GetRight(right),
|
|
|
|
margin.right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return padding.left + padding.right + border.left + border.right +
|
|
|
|
margin.left + margin.right;
|
|
|
|
}
|
|
|
|
|
2000-04-20 04:44:32 +00:00
|
|
|
static void
|
|
|
|
GetPlaceholderOffset(nsIFrame* aPlaceholderFrame,
|
|
|
|
nsIFrame* aBlockFrame,
|
|
|
|
nsPoint& aOffset)
|
|
|
|
{
|
|
|
|
aPlaceholderFrame->GetOrigin(aOffset);
|
|
|
|
|
|
|
|
// Convert the placeholder position to the coordinate space of the block
|
|
|
|
// frame that contains it
|
|
|
|
nsIFrame* parent;
|
|
|
|
aPlaceholderFrame->GetParent(&parent);
|
|
|
|
while (parent && (parent != aBlockFrame)) {
|
|
|
|
nsPoint origin;
|
|
|
|
|
|
|
|
parent->GetOrigin(origin);
|
|
|
|
aOffset += origin;
|
|
|
|
parent->GetParent(&parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIFrame*
|
|
|
|
FindImmediateChildOf(nsIFrame* aParent, nsIFrame* aDescendantFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* result = aDescendantFrame;
|
|
|
|
|
|
|
|
while (result) {
|
|
|
|
nsIFrame* parent;
|
|
|
|
|
|
|
|
result->GetParent(&parent);
|
|
|
|
if (parent == aParent) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The frame is not an immediate child of aParent so walk up another level
|
|
|
|
result = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
// Calculate the hypothetical box that the element would have if it were in
|
|
|
|
// the flow. The values returned are relative to the padding edge of the
|
|
|
|
// absolute containing block
|
1999-01-13 06:37:31 +00:00
|
|
|
void
|
2000-04-16 04:07:02 +00:00
|
|
|
nsHTMLReflowState::CalculateHypotheticalBox(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aPlaceholderFrame,
|
|
|
|
nsIFrame* aBlockFrame,
|
|
|
|
nsMargin& aBlockContentArea,
|
|
|
|
nsIFrame* aAbsoluteContainingBlockFrame,
|
|
|
|
nsHypotheticalBox& aHypotheticalBox)
|
1999-01-13 06:37:31 +00:00
|
|
|
{
|
2000-04-16 04:07:02 +00:00
|
|
|
// If it's a replaced element and it has a 'auto' value for 'width', see if we
|
|
|
|
// can get the intrinsic size. This will allow us to exactly determine both the
|
|
|
|
// left and right edges
|
|
|
|
nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();
|
|
|
|
nsSize intrinsicSize;
|
|
|
|
PRBool knowIntrinsicSize = PR_FALSE;
|
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType) && (eStyleUnit_Auto == widthUnit)) {
|
|
|
|
// See if we can get the intrinsic size of the element
|
|
|
|
knowIntrinsicSize = GetIntrinsicSizeFor(frame, intrinsicSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if we can calculate what the box width would have been if the
|
|
|
|
// element had been in the flow
|
|
|
|
nscoord boxWidth;
|
|
|
|
PRBool knowBoxWidth = PR_FALSE;
|
|
|
|
if ((NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mDisplay) &&
|
|
|
|
!NS_FRAME_IS_REPLACED(mFrameType)) {
|
|
|
|
// For non-replaced inline-level elements the 'width' property doesn't apply,
|
|
|
|
// so we don't know what the width would have been without reflowing it
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// It's either a replaced inline-level element or a block-level element
|
|
|
|
nscoord horizBorderPaddingMargin;
|
|
|
|
|
|
|
|
// Determine the total amount of horizontal border/padding/margin that
|
|
|
|
// the element would have had if it had been in the flow. Note that we
|
|
|
|
// ignore any 'auto' and 'inherit' values
|
|
|
|
horizBorderPaddingMargin = CalculateHorizBorderPaddingMargin(aBlockContentArea.right -
|
|
|
|
aBlockContentArea.left);
|
|
|
|
|
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType) && (eStyleUnit_Auto == widthUnit)) {
|
|
|
|
// It's a replaced element with an 'auto' width so the box width is
|
|
|
|
// its intrinsic size plus any border/padding/margin
|
|
|
|
if (knowIntrinsicSize) {
|
|
|
|
boxWidth = intrinsicSize.width + horizBorderPaddingMargin;
|
|
|
|
knowBoxWidth = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ((eStyleUnit_Inherit == widthUnit) || (eStyleUnit_Auto == widthUnit)) {
|
|
|
|
// The box width is the containing block width
|
|
|
|
boxWidth = aBlockContentArea.right - aBlockContentArea.left;
|
|
|
|
knowBoxWidth = PR_TRUE;
|
1999-01-13 06:37:31 +00:00
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
} else {
|
|
|
|
// We need to compute it. It's important we do this, because if it's
|
|
|
|
// percentage based this computed value may be different from the comnputed
|
|
|
|
// value calculated using the absolute containing block width
|
|
|
|
ComputeHorizontalValue(aBlockContentArea.right - aBlockContentArea.left,
|
|
|
|
widthUnit, mStylePosition->mWidth, boxWidth);
|
|
|
|
boxWidth += horizBorderPaddingMargin;
|
|
|
|
knowBoxWidth = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the 'direction' of the block
|
|
|
|
const nsStyleDisplay* blockDisplay;
|
|
|
|
aBlockFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)blockDisplay);
|
|
|
|
|
|
|
|
// How we determine the hypothetical box depends on whether the element
|
|
|
|
// would have been inline-level or block-level
|
|
|
|
if (NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mDisplay) {
|
|
|
|
nsPoint placeholderOffset;
|
|
|
|
|
2000-04-20 04:44:32 +00:00
|
|
|
// Get the placeholder x-offset and y-offset in the coordinate
|
|
|
|
// space of the block frame that contains it
|
|
|
|
GetPlaceholderOffset(aPlaceholderFrame, aBlockFrame, placeholderOffset);
|
2000-04-16 04:07:02 +00:00
|
|
|
|
|
|
|
// The y-offset is the baseline of where the text would be if it were
|
|
|
|
// in the flow. We need the top position and not the baseline position
|
|
|
|
nsIFontMetrics* metrics;
|
|
|
|
const nsStyleFont* font;
|
|
|
|
|
|
|
|
frame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font);
|
|
|
|
aPresContext->GetMetricsFor(font->mFont, &metrics);
|
|
|
|
if (metrics) {
|
|
|
|
nscoord ascent;
|
|
|
|
|
|
|
|
// Adjust the y-offset up by the font ascent. That will translate from
|
|
|
|
// the baseline to the top of where the text would be
|
|
|
|
metrics->GetMaxAscent(ascent);
|
|
|
|
placeholderOffset.y -= ascent;
|
|
|
|
NS_RELEASE(metrics);
|
|
|
|
}
|
|
|
|
aHypotheticalBox.mTop = placeholderOffset.y;
|
|
|
|
|
|
|
|
// To determine the left and right offsets we need to look at the block's 'direction'
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == blockDisplay->mDirection) {
|
|
|
|
// The placeholder represents the left edge of the hypothetical box
|
|
|
|
aHypotheticalBox.mLeft = placeholderOffset.x;
|
|
|
|
aHypotheticalBox.mLeftIsExact = PR_TRUE;
|
|
|
|
|
|
|
|
if (knowBoxWidth) {
|
|
|
|
aHypotheticalBox.mRight = aHypotheticalBox.mLeft + boxWidth;
|
|
|
|
aHypotheticalBox.mRightIsExact = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// We can't compute the right edge because we don't know the desired
|
|
|
|
// width. So instead use the right content edge of the block parent,
|
|
|
|
// but remember it's not exact
|
|
|
|
aHypotheticalBox.mRight = aBlockContentArea.right;
|
|
|
|
aHypotheticalBox.mRightIsExact = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// The placeholder represents the right edge of the hypothetical box
|
|
|
|
aHypotheticalBox.mRight = placeholderOffset.x;
|
|
|
|
aHypotheticalBox.mRightIsExact = PR_TRUE;
|
|
|
|
|
|
|
|
if (knowBoxWidth) {
|
|
|
|
aHypotheticalBox.mLeft = aHypotheticalBox.mRight - boxWidth;
|
|
|
|
aHypotheticalBox.mLeftIsExact = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// We can't compute the left edge because we don't know the desired
|
|
|
|
// width. So instead use the left content edge of the block parent,
|
|
|
|
// but remember it's not exact
|
|
|
|
aHypotheticalBox.mLeft = aBlockContentArea.left;
|
|
|
|
aHypotheticalBox.mLeftIsExact = PR_FALSE;
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
2000-04-16 04:07:02 +00:00
|
|
|
}
|
1999-02-08 00:32:02 +00:00
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
} else {
|
|
|
|
// The element would have been block-level which means it would be below
|
|
|
|
// the line containing the placeholder frame
|
|
|
|
if (aBlockFrame) {
|
2000-04-20 04:44:32 +00:00
|
|
|
nsIFrame* blockChild;
|
2000-04-16 04:07:02 +00:00
|
|
|
nsLineBox* lineBox;
|
|
|
|
nsLineBox* prevLineBox;
|
|
|
|
PRBool isFloater;
|
|
|
|
|
2000-04-20 04:44:32 +00:00
|
|
|
// We need the immediate child of the block frame, and that may not be
|
|
|
|
// the placeholder frame
|
|
|
|
blockChild = FindImmediateChildOf(aBlockFrame, aPlaceholderFrame);
|
|
|
|
lineBox = ((nsBlockFrame*)aBlockFrame)->FindLineFor(blockChild, &prevLineBox,
|
2000-04-16 04:07:02 +00:00
|
|
|
&isFloater);
|
|
|
|
if (lineBox) {
|
|
|
|
// The top of the hypothetical box is just below the line containing
|
|
|
|
// the placeholder
|
|
|
|
aHypotheticalBox.mTop = lineBox->mBounds.YMost();
|
2000-04-20 04:44:32 +00:00
|
|
|
} else {
|
|
|
|
nsPoint placeholderOffset;
|
|
|
|
|
|
|
|
// Just use the placeholder's y-offset
|
|
|
|
GetPlaceholderOffset(aPlaceholderFrame, aBlockFrame, placeholderOffset);
|
|
|
|
aHypotheticalBox.mTop = placeholderOffset.y;
|
2000-04-16 04:07:02 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-08 00:32:02 +00:00
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
// To determine the left and right offsets we need to look at the block's 'direction'
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == blockDisplay->mDirection) {
|
|
|
|
aHypotheticalBox.mLeft = aBlockContentArea.left;
|
|
|
|
aHypotheticalBox.mLeftIsExact = PR_TRUE;
|
|
|
|
|
|
|
|
// If we know the box width then we can determine the right edge
|
|
|
|
if (knowBoxWidth) {
|
|
|
|
aHypotheticalBox.mRight = aHypotheticalBox.mLeft + boxWidth;
|
|
|
|
aHypotheticalBox.mRightIsExact = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// We can't compute the right edge because we don't know the intrinsic
|
|
|
|
// width yet. So instead use the right content edge of the block parent,
|
|
|
|
// but remember it's not exact
|
|
|
|
aHypotheticalBox.mRight = aBlockContentArea.right;
|
|
|
|
aHypotheticalBox.mRightIsExact = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
aHypotheticalBox.mRight = aBlockContentArea.right;
|
|
|
|
aHypotheticalBox.mRightIsExact = PR_TRUE;
|
|
|
|
|
|
|
|
// If we know the box width then we can determine the left edge
|
|
|
|
if (knowBoxWidth) {
|
|
|
|
aHypotheticalBox.mLeft = aHypotheticalBox.mRight - boxWidth;
|
|
|
|
aHypotheticalBox.mLeftIsExact = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// We can't compute the left edge because we don't know the intrinsic
|
|
|
|
// width yet. So instead use the left content edge of the block parent,
|
|
|
|
// but remember it's not exact
|
|
|
|
aHypotheticalBox.mLeft = aBlockContentArea.left;
|
|
|
|
aHypotheticalBox.mLeftIsExact = PR_FALSE;
|
1999-07-28 04:48:34 +00:00
|
|
|
}
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
// The current coordinate space is that of the nearest block to the placeholder.
|
|
|
|
// Convert to the coordinate space of the absolute containing block
|
|
|
|
if (aBlockFrame != aAbsoluteContainingBlockFrame) {
|
|
|
|
nsIFrame* parent = aBlockFrame;
|
|
|
|
do {
|
|
|
|
nsPoint origin;
|
|
|
|
|
|
|
|
parent->GetOrigin(origin);
|
|
|
|
aHypotheticalBox.mLeft += origin.x;
|
|
|
|
aHypotheticalBox.mRight += origin.x;
|
|
|
|
aHypotheticalBox.mTop += origin.y;
|
|
|
|
|
|
|
|
// Move up the tree one level
|
|
|
|
parent->GetParent(&parent);
|
|
|
|
} while (parent && (parent != aAbsoluteContainingBlockFrame));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The specified offsets are relative to the absolute containing block's padding
|
|
|
|
// edge, and our current values are relative to the border edge so translate
|
|
|
|
nsMargin border;
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
|
|
|
|
aAbsoluteContainingBlockFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct*&)spacing);
|
|
|
|
if (!spacing->GetBorder(border)) {
|
|
|
|
NS_NOTYETIMPLEMENTED("percentage border");
|
|
|
|
}
|
|
|
|
aHypotheticalBox.mLeft -= border.left;
|
|
|
|
aHypotheticalBox.mRight -= border.left;
|
|
|
|
aHypotheticalBox.mTop -= border.top;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::InitAbsoluteConstraints(nsIPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState* cbrs,
|
|
|
|
nscoord containingBlockWidth,
|
|
|
|
nscoord containingBlockHeight)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(containingBlockHeight != NS_AUTOHEIGHT,
|
|
|
|
"containing block height must be constrained");
|
|
|
|
|
|
|
|
// Get the placeholder frame
|
|
|
|
nsIFrame* placeholderFrame;
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
|
|
|
|
presShell->GetPlaceholderFrameFor(frame, &placeholderFrame);
|
|
|
|
NS_ASSERTION(nsnull != placeholderFrame, "no placeholder frame");
|
|
|
|
|
|
|
|
// Find the nearest containing block frame to the placeholder frame,
|
|
|
|
// and return its content area left, top, right, and bottom edges
|
|
|
|
nsMargin blockContentArea;
|
|
|
|
nsIFrame* blockFrame = GetNearestContainingBlock(placeholderFrame,
|
|
|
|
blockContentArea);
|
|
|
|
|
|
|
|
// If both 'left' and 'right' are 'auto' or both 'top' and 'bottom' are
|
|
|
|
// 'auto', then compute the hypothetical box of where the element would
|
|
|
|
// have been if it had been in the flow
|
|
|
|
nsHypotheticalBox hypotheticalBox;
|
|
|
|
if (((eStyleUnit_Auto == mStylePosition->mOffset.GetLeftUnit()) &&
|
|
|
|
(eStyleUnit_Auto == mStylePosition->mOffset.GetRightUnit())) ||
|
|
|
|
((eStyleUnit_Auto == mStylePosition->mOffset.GetTopUnit()) &&
|
|
|
|
(eStyleUnit_Auto == mStylePosition->mOffset.GetBottomUnit()))) {
|
|
|
|
|
|
|
|
CalculateHypotheticalBox(aPresContext, placeholderFrame, blockFrame,
|
|
|
|
blockContentArea, cbrs->frame, hypotheticalBox);
|
|
|
|
}
|
1999-01-13 06:37:31 +00:00
|
|
|
|
|
|
|
// Initialize the 'left' and 'right' computed offsets
|
2000-04-16 04:07:02 +00:00
|
|
|
// XXX Handle new 'static-position' value...
|
1999-01-13 06:37:31 +00:00
|
|
|
PRBool leftIsAuto = PR_FALSE, rightIsAuto = PR_FALSE;
|
|
|
|
nsStyleCoord coord;
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Inherit == mStylePosition->mOffset.GetLeftUnit()) {
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.left = cbrs->mComputedOffsets.left;
|
1999-03-05 04:24:20 +00:00
|
|
|
} else if (eStyleUnit_Auto == mStylePosition->mOffset.GetLeftUnit()) {
|
2000-04-16 04:07:02 +00:00
|
|
|
mComputedOffsets.left = 0;
|
|
|
|
leftIsAuto = PR_TRUE;
|
1999-01-13 06:37:31 +00:00
|
|
|
} else {
|
1999-03-05 04:24:20 +00:00
|
|
|
ComputeHorizontalValue(containingBlockWidth, mStylePosition->mOffset.GetLeftUnit(),
|
|
|
|
mStylePosition->mOffset.GetLeft(coord),
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.left);
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Inherit == mStylePosition->mOffset.GetRightUnit()) {
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.right = cbrs->mComputedOffsets.right;
|
1999-03-05 04:24:20 +00:00
|
|
|
} else if (eStyleUnit_Auto == mStylePosition->mOffset.GetRightUnit()) {
|
2000-04-16 04:07:02 +00:00
|
|
|
mComputedOffsets.right = 0;
|
|
|
|
rightIsAuto = PR_TRUE;
|
1999-01-13 06:37:31 +00:00
|
|
|
} else {
|
1999-03-05 04:24:20 +00:00
|
|
|
ComputeHorizontalValue(containingBlockWidth, mStylePosition->mOffset.GetRightUnit(),
|
|
|
|
mStylePosition->mOffset.GetRight(coord),
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.right);
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
// When the CSS2 spec refers to direction it means the containing block's
|
|
|
|
// direction and not the direction of the absolutely positioned element itself
|
|
|
|
PRUint8 direction = cbrs->mStyleDisplay->mDirection;
|
1999-07-20 02:48:18 +00:00
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
// Initialize the 'width' computed value
|
|
|
|
nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();
|
|
|
|
PRBool widthIsAuto = (eStyleUnit_Auto == widthUnit);
|
|
|
|
if (!widthIsAuto) {
|
1999-02-18 04:40:16 +00:00
|
|
|
if (eStyleUnit_Inherit == widthUnit) {
|
2000-04-16 04:07:02 +00:00
|
|
|
// The inherited value comes from the parent and not the absolute
|
|
|
|
// containing block
|
|
|
|
mComputedWidth = blockContentArea.right - blockContentArea.left;
|
|
|
|
|
1999-02-18 04:40:16 +00:00
|
|
|
} else {
|
|
|
|
// Use the specified value for the computed width
|
1999-03-05 04:24:20 +00:00
|
|
|
ComputeHorizontalValue(containingBlockWidth, widthUnit,
|
1999-07-20 03:41:03 +00:00
|
|
|
mStylePosition->mWidth, mComputedWidth);
|
1999-02-18 04:40:16 +00:00
|
|
|
}
|
2000-04-16 04:07:02 +00:00
|
|
|
|
1999-07-20 02:48:18 +00:00
|
|
|
// Factor in any minimum and maximum size information
|
1999-07-20 03:41:03 +00:00
|
|
|
if (mComputedWidth > mComputedMaxWidth) {
|
|
|
|
mComputedWidth = mComputedMaxWidth;
|
|
|
|
} else if (mComputedWidth < mComputedMinWidth) {
|
|
|
|
mComputedWidth = mComputedMinWidth;
|
1999-03-11 15:13:17 +00:00
|
|
|
}
|
1999-07-20 02:48:18 +00:00
|
|
|
}
|
1999-01-13 06:37:31 +00:00
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
// See if none of 'left', 'width', and 'right', is 'auto'
|
|
|
|
if (!leftIsAuto && !widthIsAuto && !rightIsAuto) {
|
|
|
|
// See whether we're over-constrained
|
|
|
|
PRInt32 availBoxSpace = containingBlockWidth - mComputedOffsets.left - mComputedOffsets.right;
|
|
|
|
PRInt32 availContentSpace = availBoxSpace - mComputedBorderPadding.left -
|
|
|
|
mComputedBorderPadding.right;
|
|
|
|
|
|
|
|
if (availContentSpace < mComputedWidth) {
|
|
|
|
// We're over-constrained so use 'direction' to dictate which value to
|
|
|
|
// ignore
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == direction) {
|
|
|
|
// Ignore the specified value for 'right'
|
|
|
|
mComputedOffsets.right = containingBlockWidth - mComputedOffsets.left -
|
|
|
|
mComputedBorderPadding.left - mComputedWidth - mComputedBorderPadding.right;
|
|
|
|
} else {
|
|
|
|
// Ignore the specified value for 'left'
|
|
|
|
mComputedOffsets.left = containingBlockWidth - mComputedBorderPadding.left -
|
|
|
|
mComputedWidth - mComputedBorderPadding.right - mComputedOffsets.right;
|
1999-07-20 02:48:18 +00:00
|
|
|
}
|
2000-04-16 04:07:02 +00:00
|
|
|
|
1999-01-13 06:37:31 +00:00
|
|
|
} else {
|
2000-04-16 04:07:02 +00:00
|
|
|
// Calculate any 'auto' margin values
|
|
|
|
PRBool marginLeftIsAuto = (eStyleUnit_Auto == mStyleSpacing->mMargin.GetLeftUnit());
|
|
|
|
PRBool marginRightIsAuto = (eStyleUnit_Auto == mStyleSpacing->mMargin.GetRightUnit());
|
2000-04-29 00:24:53 +00:00
|
|
|
PRInt32 availMarginSpace = availContentSpace - mComputedWidth;
|
2000-04-16 04:07:02 +00:00
|
|
|
|
1999-07-20 02:48:18 +00:00
|
|
|
if (marginLeftIsAuto) {
|
|
|
|
if (marginRightIsAuto) {
|
|
|
|
// Both 'margin-left' and 'margin-right' are 'auto', so they get
|
|
|
|
// equal values
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.left = availMarginSpace / 2;
|
|
|
|
mComputedMargin.right = availMarginSpace - mComputedMargin.left;
|
1999-07-20 02:48:18 +00:00
|
|
|
} else {
|
|
|
|
// Just 'margin-left' is 'auto'
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.left = availMarginSpace - mComputedMargin.right;
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
1999-07-20 02:48:18 +00:00
|
|
|
} else {
|
|
|
|
// Just 'margin-right' is 'auto'
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.right = availMarginSpace - mComputedMargin.left;
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
|
|
|
}
|
2000-04-16 04:07:02 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// See if all three of 'left', 'width', and 'right', are 'auto'
|
|
|
|
if (leftIsAuto && widthIsAuto && rightIsAuto) {
|
|
|
|
// Use the 'direction' to dictate whether 'left' or 'right' is
|
|
|
|
// treated like 'static-position'
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == direction) {
|
|
|
|
if (hypotheticalBox.mLeftIsExact) {
|
|
|
|
mComputedOffsets.left = hypotheticalBox.mLeft;
|
|
|
|
leftIsAuto = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
// Well, we don't know 'left' so we have to use 'right' and
|
|
|
|
// then solve for 'left'
|
|
|
|
mComputedOffsets.right = hypotheticalBox.mRight;
|
|
|
|
rightIsAuto = PR_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (hypotheticalBox.mRightIsExact) {
|
|
|
|
mComputedOffsets.right = containingBlockWidth - hypotheticalBox.mRight;
|
|
|
|
rightIsAuto = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
// Well, we don't know 'right' so we have to use 'left' and
|
|
|
|
// then solve for 'right'
|
|
|
|
mComputedOffsets.left = hypotheticalBox.mLeft;
|
|
|
|
leftIsAuto = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point we know that at least one of 'left', 'width', and 'right'
|
|
|
|
// is 'auto', but not all three. Examine the various combinations
|
|
|
|
if (widthIsAuto) {
|
|
|
|
if (leftIsAuto || rightIsAuto) {
|
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType)) {
|
|
|
|
// For a replaced element we use the intrinsic size
|
|
|
|
mComputedWidth = NS_INTRINSICSIZE;
|
|
|
|
} else {
|
|
|
|
// The width is shrink-to-fit but constrained by the containing block width
|
|
|
|
mComputedWidth = NS_SHRINKWRAPWIDTH;
|
|
|
|
|
|
|
|
PRInt32 maxWidth = containingBlockWidth - mComputedOffsets.left -
|
|
|
|
mComputedMargin.left - mComputedBorderPadding.left -
|
|
|
|
mComputedBorderPadding.right - mComputedMargin.right -
|
|
|
|
mComputedOffsets.right;
|
|
|
|
if (maxWidth <= 0) {
|
|
|
|
maxWidth = 1;
|
|
|
|
}
|
|
|
|
if (mComputedMaxWidth > maxWidth) {
|
|
|
|
mComputedMaxWidth = maxWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leftIsAuto) {
|
|
|
|
mComputedOffsets.left = NS_AUTOOFFSET; // solve for 'left'
|
|
|
|
} else {
|
|
|
|
mComputedOffsets.right = NS_AUTOOFFSET; // solve for 'right'
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Only 'width' is 'auto' so just solve for 'width'
|
|
|
|
mComputedWidth = containingBlockWidth - mComputedOffsets.left -
|
|
|
|
mComputedMargin.left - mComputedBorderPadding.left -
|
|
|
|
mComputedBorderPadding.right -
|
|
|
|
mComputedMargin.right - mComputedOffsets.right;
|
|
|
|
|
|
|
|
// Factor in any minimum and maximum size information
|
|
|
|
if (mComputedWidth > mComputedMaxWidth) {
|
|
|
|
mComputedWidth = mComputedMaxWidth;
|
|
|
|
} else if (mComputedWidth < mComputedMinWidth) {
|
|
|
|
mComputedWidth = mComputedMinWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX If the direction is rtl then we need to reevaluate left...
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Either 'left' or 'right' or both is 'auto'
|
|
|
|
if (leftIsAuto && rightIsAuto) {
|
|
|
|
// Use the 'direction' to dictate whether 'left' or 'right' is treated like
|
|
|
|
// 'static-position'
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == direction) {
|
|
|
|
if (hypotheticalBox.mLeftIsExact) {
|
|
|
|
mComputedOffsets.left = hypotheticalBox.mLeft;
|
|
|
|
leftIsAuto = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
// Well, we don't know 'left' so we have to use 'right' and
|
|
|
|
// then solve for 'left'
|
|
|
|
mComputedOffsets.right = hypotheticalBox.mRight;
|
|
|
|
rightIsAuto = PR_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (hypotheticalBox.mRightIsExact) {
|
|
|
|
mComputedOffsets.right = containingBlockWidth - hypotheticalBox.mRight;
|
|
|
|
rightIsAuto = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
// Well, we don't know 'right' so we have to use 'left' and
|
|
|
|
// then solve for 'right'
|
|
|
|
mComputedOffsets.left = hypotheticalBox.mLeft;
|
|
|
|
leftIsAuto = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leftIsAuto) {
|
|
|
|
// Solve for 'left'
|
|
|
|
mComputedOffsets.left = containingBlockWidth - mComputedMargin.left -
|
|
|
|
mComputedBorderPadding.left - mComputedWidth - mComputedBorderPadding.right -
|
|
|
|
mComputedMargin.right - mComputedOffsets.right;
|
|
|
|
|
|
|
|
} else if (rightIsAuto) {
|
|
|
|
// Solve for 'right'
|
|
|
|
mComputedOffsets.right = containingBlockWidth - mComputedOffsets.left -
|
|
|
|
mComputedMargin.left - mComputedBorderPadding.left - mComputedWidth -
|
|
|
|
mComputedBorderPadding.right - mComputedMargin.right;
|
|
|
|
}
|
|
|
|
}
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the 'top' and 'bottom' computed offsets
|
2000-04-16 04:07:02 +00:00
|
|
|
nsStyleUnit heightUnit = mStylePosition->mHeight.GetUnit();
|
|
|
|
PRBool topIsAuto = PR_FALSE, bottomIsAuto = PR_FALSE;
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Inherit == mStylePosition->mOffset.GetTopUnit()) {
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.top = cbrs->mComputedOffsets.top;
|
2000-04-16 04:07:02 +00:00
|
|
|
} else if (eStyleUnit_Auto == mStylePosition->mOffset.GetTopUnit()) {
|
|
|
|
mComputedOffsets.top = 0;
|
|
|
|
topIsAuto = PR_TRUE;
|
1999-01-13 06:37:31 +00:00
|
|
|
} else {
|
1999-05-10 22:28:30 +00:00
|
|
|
nsStyleCoord c;
|
|
|
|
ComputeVerticalValue(containingBlockHeight,
|
|
|
|
mStylePosition->mOffset.GetTopUnit(),
|
|
|
|
mStylePosition->mOffset.GetTop(c),
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.top);
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
1999-03-05 04:24:20 +00:00
|
|
|
if (eStyleUnit_Inherit == mStylePosition->mOffset.GetBottomUnit()) {
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.bottom = cbrs->mComputedOffsets.bottom;
|
2000-04-16 04:07:02 +00:00
|
|
|
} else if (eStyleUnit_Auto == mStylePosition->mOffset.GetBottomUnit()) {
|
|
|
|
mComputedOffsets.bottom = 0;
|
|
|
|
bottomIsAuto = PR_TRUE;
|
1999-01-13 06:37:31 +00:00
|
|
|
} else {
|
1999-05-10 22:28:30 +00:00
|
|
|
nsStyleCoord c;
|
|
|
|
ComputeVerticalValue(containingBlockHeight,
|
|
|
|
mStylePosition->mOffset.GetBottomUnit(),
|
|
|
|
mStylePosition->mOffset.GetBottom(c),
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.bottom);
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
// Initialize the 'height' computed value
|
|
|
|
PRBool heightIsAuto = (eStyleUnit_Auto == heightUnit);
|
|
|
|
if (!heightIsAuto) {
|
|
|
|
if (eStyleUnit_Inherit == heightUnit) {
|
|
|
|
// The inherited value comes from the parent and not the absolute
|
|
|
|
// containing block
|
|
|
|
mComputedHeight = blockContentArea.bottom - blockContentArea.top;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Use the specified value for the computed height
|
|
|
|
// XXX Handle 'inherit'. The inherited value comes from the parent
|
|
|
|
// and not the containing block
|
|
|
|
ComputeVerticalValue(containingBlockHeight, heightUnit,
|
|
|
|
mStylePosition->mHeight, mComputedHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Factor in any minimum and maximum size information
|
|
|
|
if (mComputedHeight > mComputedMaxHeight) {
|
|
|
|
mComputedHeight = mComputedMaxHeight;
|
|
|
|
} else if (mComputedHeight < mComputedMinHeight) {
|
|
|
|
mComputedHeight = mComputedMinHeight;
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
// See if none of 'top', 'height', and 'bottom', is 'auto'
|
|
|
|
if (!topIsAuto && !heightIsAuto && !bottomIsAuto) {
|
|
|
|
// See whether we're over-constrained
|
|
|
|
PRInt32 availBoxSpace = containingBlockHeight - mComputedOffsets.top - mComputedOffsets.bottom;
|
|
|
|
PRInt32 availContentSpace = availBoxSpace - mComputedBorderPadding.top -
|
|
|
|
mComputedBorderPadding.bottom;
|
|
|
|
|
|
|
|
if (availContentSpace < mComputedHeight) {
|
|
|
|
// We're over-constrained so ignore the specified value for 'bottom'
|
|
|
|
mComputedOffsets.bottom = containingBlockHeight - mComputedOffsets.top -
|
|
|
|
mComputedBorderPadding.top - mComputedHeight - mComputedBorderPadding.bottom;
|
|
|
|
|
1999-01-13 06:37:31 +00:00
|
|
|
} else {
|
2000-04-16 04:07:02 +00:00
|
|
|
// Calculate any 'auto' margin values
|
|
|
|
PRBool marginTopIsAuto = (eStyleUnit_Auto == mStyleSpacing->mMargin.GetTopUnit());
|
|
|
|
PRBool marginBottomIsAuto = (eStyleUnit_Auto == mStyleSpacing->mMargin.GetBottomUnit());
|
2000-04-29 00:24:53 +00:00
|
|
|
PRInt32 availMarginSpace = availContentSpace - mComputedHeight;
|
2000-04-16 04:07:02 +00:00
|
|
|
|
|
|
|
if (marginTopIsAuto) {
|
|
|
|
if (marginBottomIsAuto) {
|
|
|
|
// Both 'margin-top' and 'margin-bottom' are 'auto', so they get
|
|
|
|
// equal values
|
|
|
|
mComputedMargin.top = availMarginSpace / 2;
|
|
|
|
mComputedMargin.bottom = availMarginSpace - mComputedMargin.top;
|
|
|
|
} else {
|
|
|
|
// Just 'margin-top' is 'auto'
|
|
|
|
mComputedMargin.top = availMarginSpace - mComputedMargin.bottom;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Just 'margin-bottom' is 'auto'
|
|
|
|
mComputedMargin.bottom = availMarginSpace - mComputedMargin.top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// See if all three of 'top', 'height', and 'bottom', are 'auto'
|
|
|
|
if (topIsAuto && heightIsAuto && bottomIsAuto) {
|
|
|
|
// Treat 'top' like 'static-position'
|
|
|
|
mComputedOffsets.top = hypotheticalBox.mTop;
|
|
|
|
topIsAuto = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point we know that at least one of 'top', 'height', and 'bottom'
|
|
|
|
// is 'auto', but not all three. Examine the various combinations
|
|
|
|
if (heightIsAuto) {
|
|
|
|
if (topIsAuto || bottomIsAuto) {
|
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType)) {
|
|
|
|
// For a replaced element we use the intrinsic size
|
|
|
|
mComputedHeight = NS_INTRINSICSIZE;
|
|
|
|
} else {
|
|
|
|
// The height is based on the content
|
|
|
|
mComputedHeight = NS_AUTOHEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topIsAuto) {
|
|
|
|
mComputedOffsets.top = NS_AUTOOFFSET; // solve for 'top'
|
|
|
|
} else {
|
|
|
|
mComputedOffsets.bottom = NS_AUTOOFFSET; // solve for 'bottom'
|
|
|
|
}
|
1999-01-13 06:37:31 +00:00
|
|
|
|
|
|
|
} else {
|
2000-04-16 04:07:02 +00:00
|
|
|
// Only 'height' is 'auto' so just solve for 'height'
|
|
|
|
mComputedHeight = containingBlockHeight - mComputedOffsets.top -
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.top - mComputedBorderPadding.top -
|
1999-03-05 04:24:20 +00:00
|
|
|
mComputedBorderPadding.bottom -
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedMargin.bottom - mComputedOffsets.bottom;
|
2000-04-16 04:07:02 +00:00
|
|
|
|
1999-07-20 02:48:18 +00:00
|
|
|
// Factor in any minimum and maximum size information
|
1999-07-20 03:41:03 +00:00
|
|
|
if (mComputedHeight > mComputedMaxHeight) {
|
|
|
|
mComputedHeight = mComputedMaxHeight;
|
|
|
|
} else if (mComputedHeight < mComputedMinHeight) {
|
|
|
|
mComputedHeight = mComputedMinHeight;
|
1999-03-11 15:13:17 +00:00
|
|
|
}
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
2000-04-16 04:07:02 +00:00
|
|
|
|
1999-02-18 04:40:16 +00:00
|
|
|
} else {
|
2000-04-16 04:07:02 +00:00
|
|
|
// Either 'top' or 'bottom' or both is 'auto'
|
|
|
|
if (topIsAuto && bottomIsAuto) {
|
|
|
|
// Treat 'top' like 'static-position'
|
|
|
|
mComputedOffsets.top = hypotheticalBox.mTop;
|
|
|
|
topIsAuto = PR_FALSE;
|
|
|
|
}
|
1999-01-13 06:37:31 +00:00
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
if (topIsAuto) {
|
|
|
|
// Solve for 'top'
|
|
|
|
mComputedOffsets.top = containingBlockHeight - mComputedMargin.top -
|
|
|
|
mComputedBorderPadding.top - mComputedHeight - mComputedBorderPadding.bottom -
|
|
|
|
mComputedMargin.bottom - mComputedOffsets.bottom;
|
1999-07-28 03:51:37 +00:00
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
} else if (bottomIsAuto) {
|
|
|
|
// Solve for 'bottom'
|
|
|
|
mComputedOffsets.bottom = containingBlockHeight - mComputedOffsets.top -
|
|
|
|
mComputedMargin.top - mComputedBorderPadding.top - mComputedHeight -
|
|
|
|
mComputedBorderPadding.bottom - mComputedMargin.bottom;
|
1999-07-28 03:51:37 +00:00
|
|
|
}
|
|
|
|
}
|
1999-07-20 02:48:18 +00:00
|
|
|
}
|
2000-04-16 04:07:02 +00:00
|
|
|
}
|
1999-03-11 15:13:17 +00:00
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
static PRBool
|
|
|
|
IsInitialContainingBlock(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIContent* content;
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
aFrame->GetContent(&content);
|
|
|
|
if (content) {
|
|
|
|
nsIContent* parentContent;
|
|
|
|
|
|
|
|
content->GetParent(parentContent);
|
|
|
|
if (!parentContent) {
|
|
|
|
// The containing block corresponds to the document element so it's
|
|
|
|
// the initial containing block
|
|
|
|
result = PR_TRUE;
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
2000-04-16 04:07:02 +00:00
|
|
|
NS_IF_RELEASE(parentContent);
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
2000-04-16 04:07:02 +00:00
|
|
|
NS_IF_RELEASE(content);
|
|
|
|
return result;
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
|
|
|
|
2000-04-28 21:05:31 +00:00
|
|
|
nscoord
|
|
|
|
GetVerticalMarginBorderPadding(const nsHTMLReflowState* aReflowState)
|
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
if (!aReflowState) return result;
|
|
|
|
|
|
|
|
// zero auto margins
|
|
|
|
nsMargin margin = aReflowState->mComputedMargin;
|
|
|
|
if (NS_AUTOMARGIN == margin.top)
|
|
|
|
margin.top = 0;
|
|
|
|
if (NS_AUTOMARGIN == margin.bottom)
|
|
|
|
margin.bottom = 0;
|
|
|
|
|
|
|
|
result += margin.top + margin.bottom;
|
|
|
|
result += aReflowState->mComputedBorderPadding.top +
|
|
|
|
aReflowState->mComputedBorderPadding.bottom;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the height based on the viewport of the containing block specified
|
|
|
|
* in aReflowState when the containing block has mComputedHeight == NS_AUTOHEIGHT
|
|
|
|
* and it is the body.
|
|
|
|
*/
|
|
|
|
nscoord
|
|
|
|
CalcQuirkContainingBlockHeight(const nsHTMLReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
nsHTMLReflowState* firstBlockRS = nsnull; // a candidate for body frame
|
|
|
|
nsHTMLReflowState* firstAreaRS = nsnull; // a candidate for html frame
|
|
|
|
nscoord result = 0;
|
|
|
|
|
|
|
|
const nsHTMLReflowState* rs = &aReflowState;
|
|
|
|
for (; rs; rs = (nsHTMLReflowState *)(rs->parentReflowState)) {
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
rs->frame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
// if the ancestor is auto height then skip it and continue up if it
|
|
|
|
// is the first block/area frame and possibly the body/html
|
|
|
|
if (nsLayoutAtoms::blockFrame == frameType.get()) {
|
|
|
|
if (!firstBlockRS) {
|
|
|
|
firstBlockRS = (nsHTMLReflowState*)rs;
|
|
|
|
if (NS_AUTOHEIGHT == rs->mComputedHeight) continue;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
else if (nsLayoutAtoms::areaFrame == frameType.get()) {
|
|
|
|
if (!firstAreaRS) {
|
|
|
|
firstAreaRS = (nsHTMLReflowState*)rs;
|
|
|
|
if (NS_AUTOHEIGHT == rs->mComputedHeight) continue;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
else if (nsLayoutAtoms::canvasFrame != frameType.get()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// the ancestor has a computed height, it is the percent base
|
|
|
|
result = rs->mComputedHeight;
|
|
|
|
// if we got to the canvas frame, then subtract out
|
|
|
|
// margin/border/padding for the BODY and HTML elements
|
|
|
|
if (nsLayoutAtoms::canvasFrame == frameType.get()) {
|
|
|
|
result -= GetVerticalMarginBorderPadding(firstBlockRS);
|
|
|
|
result -= GetVerticalMarginBorderPadding(firstAreaRS);
|
|
|
|
}
|
|
|
|
// if we got to the html frame, then subtract out
|
|
|
|
// margin/border/padding for the BODY element
|
|
|
|
else if (nsLayoutAtoms::areaFrame == frameType.get()) {
|
|
|
|
// make sure it is the body
|
|
|
|
nsCOMPtr<nsIAtom> fType;
|
|
|
|
rs->parentReflowState->frame->GetFrameType(getter_AddRefs(fType));
|
|
|
|
if (nsLayoutAtoms::canvasFrame == fType.get()) {
|
|
|
|
result -= GetVerticalMarginBorderPadding(firstBlockRS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1999-04-22 04:27:47 +00:00
|
|
|
// Called by InitConstraints() to compute the containing block rectangle for
|
|
|
|
// the element. Handles the special logic for absolutely positioned elements
|
|
|
|
void
|
2000-04-28 21:05:31 +00:00
|
|
|
nsHTMLReflowState::ComputeContainingBlockRectangle(nsIPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState* aContainingBlockRS,
|
|
|
|
nscoord& aContainingBlockWidth,
|
|
|
|
nscoord& aContainingBlockHeight)
|
1999-04-22 04:27:47 +00:00
|
|
|
{
|
|
|
|
// Unless the element is absolutely positioned, the containing block is
|
|
|
|
// formed by the content edge of the nearest block-level ancestor
|
1999-07-20 03:41:03 +00:00
|
|
|
aContainingBlockWidth = aContainingBlockRS->mComputedWidth;
|
|
|
|
aContainingBlockHeight = aContainingBlockRS->mComputedHeight;
|
1999-04-22 04:27:47 +00:00
|
|
|
|
1999-07-20 03:41:03 +00:00
|
|
|
if (NS_FRAME_GET_TYPE(mFrameType) == NS_CSS_FRAME_TYPE_ABSOLUTE) {
|
1999-04-22 04:27:47 +00:00
|
|
|
// See if the ancestor is block-level or inline-level
|
1999-07-20 03:41:03 +00:00
|
|
|
if (NS_FRAME_GET_TYPE(aContainingBlockRS->mFrameType) == NS_CSS_FRAME_TYPE_INLINE) {
|
1999-04-22 04:27:47 +00:00
|
|
|
// The CSS2 spec says that if the ancestor is inline-level, the containing
|
|
|
|
// block depends on the 'direction' property of the ancestor. For direction
|
|
|
|
// 'ltr', it's the top and left of the content edges of the first box and
|
|
|
|
// the bottom and right content edges of the last box
|
|
|
|
//
|
|
|
|
// XXX This is a pain because it isn't top-down and it requires that we've
|
|
|
|
// completely reflowed the ancestor. It also isn't clear what happens when
|
|
|
|
// a relatively positioned ancestor is split across pages. So instead use
|
|
|
|
// the computed width and height of the nearest block-level ancestor
|
|
|
|
const nsHTMLReflowState* cbrs = aContainingBlockRS;
|
|
|
|
while (cbrs) {
|
1999-07-20 03:41:03 +00:00
|
|
|
nsCSSFrameType type = NS_FRAME_GET_TYPE(cbrs->mFrameType);
|
1999-04-22 04:27:47 +00:00
|
|
|
if ((NS_CSS_FRAME_TYPE_BLOCK == type) ||
|
|
|
|
(NS_CSS_FRAME_TYPE_FLOATING == type) ||
|
|
|
|
(NS_CSS_FRAME_TYPE_ABSOLUTE == type)) {
|
|
|
|
|
1999-07-20 03:41:03 +00:00
|
|
|
aContainingBlockWidth = cbrs->mComputedWidth;
|
|
|
|
aContainingBlockHeight = cbrs->mComputedHeight;
|
1999-04-22 04:27:47 +00:00
|
|
|
|
|
|
|
if (NS_CSS_FRAME_TYPE_ABSOLUTE == type) {
|
|
|
|
aContainingBlockWidth += cbrs->mComputedPadding.left +
|
|
|
|
cbrs->mComputedPadding.right;
|
|
|
|
aContainingBlockHeight += cbrs->mComputedPadding.top +
|
|
|
|
cbrs->mComputedPadding.bottom;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cbrs = (const nsHTMLReflowState*)cbrs->parentReflowState; // XXX cast
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// If the ancestor is block-level, the containing block is formed by the
|
|
|
|
// padding edge of the ancestor
|
|
|
|
aContainingBlockWidth += aContainingBlockRS->mComputedPadding.left +
|
|
|
|
aContainingBlockRS->mComputedPadding.right;
|
2000-04-16 04:07:02 +00:00
|
|
|
|
|
|
|
// If the containing block is the initial containing block and it has a
|
|
|
|
// height that depends on its content, then use the viewport height instead.
|
|
|
|
// This gives us a reasonable value against which to compute percentage
|
|
|
|
// based heights and to do bottom relative positioning
|
|
|
|
if ((NS_AUTOHEIGHT == aContainingBlockHeight) &&
|
|
|
|
IsInitialContainingBlock(aContainingBlockRS->frame)) {
|
|
|
|
|
|
|
|
// Use the viewport height as the containing block height
|
|
|
|
const nsHTMLReflowState* rs = aContainingBlockRS->parentReflowState;
|
|
|
|
while (rs) {
|
|
|
|
aContainingBlockHeight = rs->mComputedHeight;
|
|
|
|
rs = rs->parentReflowState;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
aContainingBlockHeight += aContainingBlockRS->mComputedPadding.top +
|
|
|
|
aContainingBlockRS->mComputedPadding.bottom;
|
|
|
|
}
|
1999-04-22 04:27:47 +00:00
|
|
|
}
|
2000-01-30 18:40:48 +00:00
|
|
|
} else {
|
|
|
|
// If this is an unconstrained reflow, then reset the containing block
|
|
|
|
// width to NS_UNCONSTRAINEDSIZE. This way percentage based values have
|
|
|
|
// no effect
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == availableWidth) {
|
|
|
|
aContainingBlockWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
2000-04-28 21:05:31 +00:00
|
|
|
// a table in quirks mode gets a containing block based on the viewport (less
|
|
|
|
// body margins, border, padding) if the table is a child of the body.
|
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
|
|
|
nsCOMPtr<nsIAtom> fType;
|
|
|
|
frame->GetFrameType(getter_AddRefs(fType));
|
|
|
|
if (nsLayoutAtoms::tableFrame == fType.get()) {
|
|
|
|
nsCompatibility mode;
|
|
|
|
aPresContext->GetCompatibilityMode(&mode);
|
|
|
|
if (eCompatibility_NavQuirks == mode) {
|
|
|
|
aContainingBlockHeight = CalcQuirkContainingBlockHeight(*aContainingBlockRS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-22 04:27:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-23 19:33:06 +00:00
|
|
|
// XXX refactor this code to have methods for each set of properties
|
|
|
|
// we are computing: width,height,line-height; margin; offsets
|
|
|
|
|
1999-01-05 19:44:41 +00:00
|
|
|
void
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLReflowState::InitConstraints(nsIPresContext* aPresContext,
|
1999-09-16 14:33:19 +00:00
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight)
|
1999-01-05 19:44:41 +00:00
|
|
|
{
|
1999-04-22 04:27:47 +00:00
|
|
|
// If this is the root frame, then set the computed width and
|
1999-01-05 19:44:41 +00:00
|
|
|
// height equal to the available space
|
|
|
|
if (nsnull == parentReflowState) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = availableWidth;
|
|
|
|
mComputedHeight = availableHeight;
|
|
|
|
mComputedMargin.SizeTo(0, 0, 0, 0);
|
1999-03-05 04:24:20 +00:00
|
|
|
mComputedPadding.SizeTo(0, 0, 0, 0);
|
|
|
|
mComputedBorderPadding.SizeTo(0, 0, 0, 0);
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.SizeTo(0, 0, 0, 0);
|
1999-03-11 01:23:10 +00:00
|
|
|
mComputedMinWidth = mComputedMinHeight = 0;
|
|
|
|
mComputedMaxWidth = mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
1999-01-05 19:44:41 +00:00
|
|
|
} else {
|
|
|
|
// Get the containing block reflow state
|
|
|
|
const nsHTMLReflowState* cbrs =
|
|
|
|
GetContainingBlockReflowState(parentReflowState);
|
|
|
|
NS_ASSERTION(nsnull != cbrs, "no containing block");
|
|
|
|
|
1999-09-16 14:33:19 +00:00
|
|
|
// If we weren't given a containing block width and height, then
|
|
|
|
// compute one
|
|
|
|
if (aContainingBlockWidth == -1) {
|
2000-04-28 21:05:31 +00:00
|
|
|
ComputeContainingBlockRectangle(aPresContext, cbrs, aContainingBlockWidth,
|
|
|
|
aContainingBlockHeight);
|
1999-09-16 14:33:19 +00:00
|
|
|
}
|
1999-04-22 04:27:47 +00:00
|
|
|
|
1999-01-16 20:58:17 +00:00
|
|
|
// See if the element is relatively positioned
|
1999-03-05 04:24:20 +00:00
|
|
|
if (NS_STYLE_POSITION_RELATIVE == mStylePosition->mPosition) {
|
1999-09-16 14:33:19 +00:00
|
|
|
ComputeRelativeOffsets(cbrs, aContainingBlockWidth, aContainingBlockHeight);
|
1999-01-16 20:58:17 +00:00
|
|
|
} else {
|
|
|
|
// Initialize offsets to 0
|
1999-07-20 03:51:46 +00:00
|
|
|
mComputedOffsets.SizeTo(0, 0, 0, 0);
|
1999-01-16 20:58:17 +00:00
|
|
|
}
|
|
|
|
|
1999-03-05 04:24:20 +00:00
|
|
|
#if 0
|
|
|
|
nsFrame::ListTag(stdout, frame); printf(": cb=");
|
1999-09-16 14:33:19 +00:00
|
|
|
nsFrame::ListTag(stdout, cbrs->frame); printf(" size=%d,%d\n", aContainingBlockWidth, aContainingBlockHeight);
|
1999-03-05 04:24:20 +00:00
|
|
|
#endif
|
1999-02-14 04:43:44 +00:00
|
|
|
|
1999-07-28 03:51:37 +00:00
|
|
|
// See if the containing block height is based on the size of its
|
1999-02-14 04:43:44 +00:00
|
|
|
// content
|
1999-09-16 14:33:19 +00:00
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
1999-03-05 04:24:20 +00:00
|
|
|
// See if the containing block is a scrolled frame, i.e. its
|
1999-07-28 03:51:37 +00:00
|
|
|
// parent is a scroll frame. The presence of the intervening
|
1999-03-05 04:24:20 +00:00
|
|
|
// frame (that the scroll frame scrolls) needs to be hidden from
|
|
|
|
// the containingBlockHeight calcuation.
|
1999-02-14 04:43:44 +00:00
|
|
|
if (cbrs->parentReflowState) {
|
|
|
|
nsIFrame* f = cbrs->parentReflowState->frame;
|
1999-05-10 22:28:30 +00:00
|
|
|
nsIAtom* cbFrameType;
|
1999-02-14 04:43:44 +00:00
|
|
|
|
1999-05-10 22:28:30 +00:00
|
|
|
f->GetFrameType(&cbFrameType);
|
|
|
|
if (nsLayoutAtoms::scrollFrame == cbFrameType) {
|
1999-02-14 04:43:44 +00:00
|
|
|
// Use the scroll frame's computed height instead
|
1999-09-16 14:33:19 +00:00
|
|
|
aContainingBlockHeight =
|
1999-07-20 03:41:03 +00:00
|
|
|
((nsHTMLReflowState*)cbrs->parentReflowState)->mComputedHeight;
|
1999-02-14 04:43:44 +00:00
|
|
|
}
|
1999-05-10 22:28:30 +00:00
|
|
|
NS_IF_RELEASE(cbFrameType);
|
1999-02-14 04:43:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-05 22:24:27 +00:00
|
|
|
// Compute margins from the specified margin style information. These
|
|
|
|
// become the default computed values, and may be adjusted below
|
|
|
|
// XXX fix to provide 0,0 for the top&bottom margins for
|
|
|
|
// inline-non-replaced elements
|
1999-09-16 14:33:19 +00:00
|
|
|
ComputeMargin(aContainingBlockWidth, cbrs);
|
|
|
|
ComputePadding(aContainingBlockWidth, cbrs);
|
1999-03-06 00:48:45 +00:00
|
|
|
if (!mStyleSpacing->GetBorder(mComputedBorderPadding)) {
|
|
|
|
// CSS2 has no percentage borders
|
|
|
|
mComputedBorderPadding.SizeTo(0, 0, 0, 0);
|
|
|
|
}
|
1999-03-05 22:24:27 +00:00
|
|
|
mComputedBorderPadding += mComputedPadding;
|
|
|
|
|
1999-03-05 04:24:20 +00:00
|
|
|
nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();
|
|
|
|
nsStyleUnit heightUnit = mStylePosition->mHeight.GetUnit();
|
1999-01-05 19:44:41 +00:00
|
|
|
|
1999-01-13 06:37:31 +00:00
|
|
|
// Check for a percentage based width and an unconstrained containing
|
|
|
|
// block width
|
|
|
|
if (eStyleUnit_Percent == widthUnit) {
|
1999-09-16 14:33:19 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
|
1999-01-13 06:37:31 +00:00
|
|
|
// Interpret the width like 'auto'
|
|
|
|
widthUnit = eStyleUnit_Auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check for a percentage based height and a containing block height
|
|
|
|
// that depends on the content height
|
1999-01-05 19:44:41 +00:00
|
|
|
if (eStyleUnit_Percent == heightUnit) {
|
1999-09-16 14:33:19 +00:00
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
1999-01-13 06:37:31 +00:00
|
|
|
// Interpret the height like 'auto'
|
1999-01-05 19:44:41 +00:00
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-11 01:23:10 +00:00
|
|
|
// Calculate the computed values for min and max properties
|
1999-09-16 14:33:19 +00:00
|
|
|
ComputeMinMaxValues(aContainingBlockWidth, aContainingBlockHeight, cbrs);
|
1999-03-11 01:23:10 +00:00
|
|
|
|
1999-01-05 19:44:41 +00:00
|
|
|
// Calculate the computed width and height. This varies by frame type
|
1999-07-20 03:41:03 +00:00
|
|
|
if ((NS_FRAME_REPLACED(NS_CSS_FRAME_TYPE_INLINE) == mFrameType) ||
|
|
|
|
(NS_FRAME_REPLACED(NS_CSS_FRAME_TYPE_FLOATING) == mFrameType)) {
|
1999-01-05 19:44:41 +00:00
|
|
|
// Inline replaced element and floating replaced element are basically
|
1999-03-11 15:13:17 +00:00
|
|
|
// treated the same. First calculate the computed width
|
1999-02-18 04:40:16 +00:00
|
|
|
if (eStyleUnit_Inherit == widthUnit) {
|
1999-09-16 14:33:19 +00:00
|
|
|
mComputedWidth = aContainingBlockWidth;
|
1999-02-18 04:40:16 +00:00
|
|
|
} else if (eStyleUnit_Auto == widthUnit) {
|
1999-01-05 19:44:41 +00:00
|
|
|
// A specified value of 'auto' uses the element's intrinsic width
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = NS_INTRINSICSIZE;
|
1999-01-05 19:44:41 +00:00
|
|
|
} else {
|
1999-09-16 14:33:19 +00:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, widthUnit,
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mWidth,
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth);
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
1999-07-28 03:51:37 +00:00
|
|
|
|
|
|
|
if (mComputedWidth != NS_INTRINSICSIZE) {
|
|
|
|
// Take into account minimum and maximum sizes
|
|
|
|
if (mComputedWidth > mComputedMaxWidth) {
|
|
|
|
mComputedWidth = mComputedMaxWidth;
|
|
|
|
} else if (mComputedWidth < mComputedMinWidth) {
|
|
|
|
mComputedWidth = mComputedMinWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See what edge the width applies to (the default is the content
|
|
|
|
// edge)
|
|
|
|
if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_PADDING) {
|
|
|
|
mComputedWidth -= mComputedPadding.left + mComputedPadding.right;
|
|
|
|
} else if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
|
|
|
mComputedWidth -= mComputedBorderPadding.left + mComputedBorderPadding.right;
|
|
|
|
}
|
1999-03-11 15:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now calculate the computed height
|
1999-02-18 04:40:16 +00:00
|
|
|
if (eStyleUnit_Inherit == heightUnit) {
|
1999-09-16 14:33:19 +00:00
|
|
|
mComputedHeight = aContainingBlockHeight;
|
1999-02-18 04:40:16 +00:00
|
|
|
} else if (eStyleUnit_Auto == heightUnit) {
|
1999-01-05 19:44:41 +00:00
|
|
|
// A specified value of 'auto' uses the element's intrinsic height
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight = NS_INTRINSICSIZE;
|
1999-01-05 19:44:41 +00:00
|
|
|
} else {
|
1999-09-16 14:33:19 +00:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight, heightUnit,
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mHeight,
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight);
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
1999-07-28 03:51:37 +00:00
|
|
|
|
|
|
|
if (mComputedHeight != NS_INTRINSICSIZE) {
|
|
|
|
// Take into account minimum and maximum sizes
|
|
|
|
if (mComputedHeight > mComputedMaxHeight) {
|
|
|
|
mComputedHeight = mComputedMaxHeight;
|
|
|
|
} else if (mComputedHeight < mComputedMinHeight) {
|
|
|
|
mComputedHeight = mComputedMinHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See what edge the height applies to (the default is the content
|
|
|
|
// edge)
|
|
|
|
if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_PADDING) {
|
|
|
|
mComputedHeight -= mComputedPadding.top + mComputedPadding.bottom;
|
|
|
|
} else if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
|
|
|
mComputedHeight -= mComputedBorderPadding.top + mComputedBorderPadding.bottom;
|
|
|
|
}
|
1999-03-11 15:13:17 +00:00
|
|
|
}
|
|
|
|
|
1999-07-20 03:41:03 +00:00
|
|
|
} else if (NS_CSS_FRAME_TYPE_FLOATING == mFrameType) {
|
1999-03-11 15:13:17 +00:00
|
|
|
// Floating non-replaced element. First calculate the computed width
|
1999-02-18 04:40:16 +00:00
|
|
|
if (eStyleUnit_Inherit == widthUnit) {
|
1999-09-16 14:33:19 +00:00
|
|
|
mComputedWidth = aContainingBlockWidth;
|
1999-02-18 04:40:16 +00:00
|
|
|
} else if (eStyleUnit_Auto == widthUnit) {
|
2000-02-13 17:55:18 +00:00
|
|
|
if ((NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) &&
|
|
|
|
(eStyleUnit_Percent == mStylePosition->mWidth.GetUnit())) {
|
2000-04-16 04:07:02 +00:00
|
|
|
// The element has a percentage width, but since the containing
|
|
|
|
// block width is unconstrained we set 'widthUnit' to 'auto'
|
|
|
|
// above. However, we want the element to be unconstrained, too
|
2000-02-13 17:55:18 +00:00
|
|
|
mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
2000-04-16 04:07:02 +00:00
|
|
|
} else if (NS_STYLE_DISPLAY_TABLE == mStyleDisplay->mDisplay) {
|
2000-04-28 21:05:31 +00:00
|
|
|
// It's an outer table because an inner table is not positioned
|
|
|
|
// shrink wrap its width since the outer table is anonymous
|
|
|
|
mComputedWidth = NS_SHRINKWRAPWIDTH;
|
2000-04-16 04:07:02 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// The CSS2 spec says the computed width should be 0; however, that's
|
|
|
|
// not what Nav and IE do and even the spec doesn't really want that
|
|
|
|
// to happen.
|
|
|
|
//
|
|
|
|
// Instead, have the element shrink wrap its width
|
|
|
|
mComputedWidth = NS_SHRINKWRAPWIDTH;
|
|
|
|
|
|
|
|
// Limnit the width to the containing block width
|
|
|
|
if (mComputedMaxWidth > aContainingBlockWidth) {
|
|
|
|
mComputedMaxWidth = aContainingBlockWidth;
|
|
|
|
}
|
2000-02-13 17:55:18 +00:00
|
|
|
}
|
2000-04-16 04:07:02 +00:00
|
|
|
|
1999-01-05 19:44:41 +00:00
|
|
|
} else {
|
1999-09-16 14:33:19 +00:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, widthUnit,
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mWidth,
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth);
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
1999-07-28 03:51:37 +00:00
|
|
|
|
|
|
|
// Take into account minimum and maximum sizes
|
2000-01-03 04:32:13 +00:00
|
|
|
if (mComputedWidth != NS_SHRINKWRAPWIDTH) {
|
|
|
|
if (mComputedWidth > mComputedMaxWidth) {
|
|
|
|
mComputedWidth = mComputedMaxWidth;
|
|
|
|
} else if (mComputedWidth < mComputedMinWidth) {
|
|
|
|
mComputedWidth = mComputedMinWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See what edge the width applies to (the default is the content
|
|
|
|
// edge)
|
|
|
|
if (mComputedWidth > 0) {
|
|
|
|
if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_PADDING) {
|
|
|
|
mComputedWidth -= mComputedPadding.left + mComputedPadding.right;
|
|
|
|
} else if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
|
|
|
mComputedWidth -= mComputedBorderPadding.left + mComputedBorderPadding.right;
|
|
|
|
}
|
1999-07-28 03:51:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-11 15:13:17 +00:00
|
|
|
// Now calculate the computed height
|
1999-02-18 04:40:16 +00:00
|
|
|
if (eStyleUnit_Inherit == heightUnit) {
|
1999-09-16 14:33:19 +00:00
|
|
|
mComputedHeight = aContainingBlockHeight;
|
1999-02-18 04:40:16 +00:00
|
|
|
} else if (eStyleUnit_Auto == heightUnit) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight = NS_AUTOHEIGHT; // let it choose its height
|
1999-01-05 19:44:41 +00:00
|
|
|
} else {
|
1999-09-16 14:33:19 +00:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight, heightUnit,
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mHeight,
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight);
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
1999-07-28 03:51:37 +00:00
|
|
|
|
|
|
|
// Take into account minimum and maximum sizes
|
|
|
|
if (mComputedHeight != NS_AUTOHEIGHT) {
|
2000-01-03 04:32:13 +00:00
|
|
|
if (mComputedHeight > mComputedMaxHeight) {
|
|
|
|
mComputedHeight = mComputedMaxHeight;
|
|
|
|
} else if (mComputedHeight < mComputedMinHeight) {
|
|
|
|
mComputedHeight = mComputedMinHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See what edge the height applies to (the default is the content
|
|
|
|
// edge)
|
1999-07-28 03:51:37 +00:00
|
|
|
if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_PADDING) {
|
|
|
|
mComputedHeight -= mComputedPadding.top + mComputedPadding.bottom;
|
|
|
|
} else if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
|
|
|
mComputedHeight -= mComputedBorderPadding.top + mComputedBorderPadding.bottom;
|
|
|
|
}
|
|
|
|
}
|
1999-03-11 15:13:17 +00:00
|
|
|
|
1999-07-20 03:41:03 +00:00
|
|
|
} else if (NS_CSS_FRAME_TYPE_INTERNAL_TABLE == mFrameType) {
|
1999-03-11 15:13:17 +00:00
|
|
|
// Internal table elements. The rules vary depending on the type.
|
1999-01-05 19:44:41 +00:00
|
|
|
// Calculate the computed width
|
1999-03-05 04:24:20 +00:00
|
|
|
if ((NS_STYLE_DISPLAY_TABLE_ROW == mStyleDisplay->mDisplay) ||
|
|
|
|
(NS_STYLE_DISPLAY_TABLE_ROW_GROUP == mStyleDisplay->mDisplay)) {
|
1999-01-05 19:44:41 +00:00
|
|
|
// 'width' property doesn't apply to table rows and row groups
|
|
|
|
widthUnit = eStyleUnit_Auto;
|
|
|
|
}
|
|
|
|
|
1999-02-18 04:40:16 +00:00
|
|
|
if (eStyleUnit_Inherit == widthUnit) {
|
1999-09-16 14:33:19 +00:00
|
|
|
mComputedWidth = aContainingBlockWidth;
|
1999-02-18 04:40:16 +00:00
|
|
|
} else if (eStyleUnit_Auto == widthUnit) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = availableWidth;
|
1999-01-13 06:37:31 +00:00
|
|
|
|
1999-07-20 03:41:03 +00:00
|
|
|
if (mComputedWidth != NS_UNCONSTRAINEDSIZE) {
|
1999-01-13 06:37:31 +00:00
|
|
|
// Internal table elements don't have margins, but they have border
|
|
|
|
// and padding
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth -= mComputedBorderPadding.left +
|
1999-03-05 04:24:20 +00:00
|
|
|
mComputedBorderPadding.right;
|
1999-01-13 06:37:31 +00:00
|
|
|
}
|
|
|
|
|
1999-01-05 19:44:41 +00:00
|
|
|
} else {
|
1999-09-16 14:33:19 +00:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, widthUnit,
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mWidth,
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth);
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the computed height
|
1999-03-05 04:24:20 +00:00
|
|
|
if ((NS_STYLE_DISPLAY_TABLE_COLUMN == mStyleDisplay->mDisplay) ||
|
|
|
|
(NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP == mStyleDisplay->mDisplay)) {
|
1999-01-05 19:44:41 +00:00
|
|
|
// 'height' property doesn't apply to table columns and column groups
|
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
1999-02-18 04:40:16 +00:00
|
|
|
if (eStyleUnit_Inherit == heightUnit) {
|
1999-09-16 14:33:19 +00:00
|
|
|
mComputedHeight = aContainingBlockHeight;
|
1999-02-18 04:40:16 +00:00
|
|
|
} else if (eStyleUnit_Auto == heightUnit) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight = NS_AUTOHEIGHT;
|
1999-01-05 19:44:41 +00:00
|
|
|
} else {
|
1999-09-16 14:33:19 +00:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight, heightUnit,
|
1999-03-05 04:24:20 +00:00
|
|
|
mStylePosition->mHeight,
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight);
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
1999-03-11 01:23:10 +00:00
|
|
|
|
|
|
|
// Doesn't apply to table elements
|
|
|
|
mComputedMinWidth = mComputedMinHeight = 0;
|
|
|
|
mComputedMaxWidth = mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
1999-07-20 03:41:03 +00:00
|
|
|
} else if (NS_FRAME_GET_TYPE(mFrameType) == NS_CSS_FRAME_TYPE_ABSOLUTE) {
|
1999-05-10 22:59:03 +00:00
|
|
|
// XXX not sure if this belongs here or somewhere else - cwk
|
|
|
|
// an nsHTMLFrameInnerFrame doesn't get a placeholder frame, the nsHTMLFrameOuterFrame does
|
|
|
|
nsIAtom* targetFrameType;
|
|
|
|
frame->GetFrameType(&targetFrameType);
|
|
|
|
if (nsLayoutAtoms::htmlFrameInnerFrame != targetFrameType) {
|
1999-09-16 14:33:19 +00:00
|
|
|
InitAbsoluteConstraints(aPresContext, cbrs, aContainingBlockWidth,
|
|
|
|
aContainingBlockHeight);
|
1999-05-10 22:59:03 +00:00
|
|
|
}
|
|
|
|
NS_IF_RELEASE(targetFrameType);
|
1999-07-20 03:41:03 +00:00
|
|
|
} else if (NS_CSS_FRAME_TYPE_INLINE == mFrameType) {
|
1999-03-05 04:24:20 +00:00
|
|
|
// Inline non-replaced elements do not have computed widths or heights
|
|
|
|
// XXX add this check to HaveFixedContentHeight/Width too
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
mComputedHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
mComputedMargin.top = 0;
|
|
|
|
mComputedMargin.bottom = 0;
|
1999-03-11 01:23:10 +00:00
|
|
|
mComputedMinWidth = mComputedMinHeight = 0;
|
|
|
|
mComputedMaxWidth = mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 04:24:20 +00:00
|
|
|
} else {
|
|
|
|
ComputeBlockBoxData(aPresContext, cbrs, widthUnit, heightUnit,
|
1999-09-16 14:33:19 +00:00
|
|
|
aContainingBlockWidth,
|
|
|
|
aContainingBlockHeight);
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the box data for block and block-replaced elements in the
|
|
|
|
// normal flow.
|
|
|
|
void
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLReflowState::ComputeBlockBoxData(nsIPresContext* aPresContext,
|
1999-03-05 04:24:20 +00:00
|
|
|
const nsHTMLReflowState* cbrs,
|
|
|
|
nsStyleUnit aWidthUnit,
|
|
|
|
nsStyleUnit aHeightUnit,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight)
|
|
|
|
{
|
|
|
|
// Compute the content width
|
|
|
|
if (eStyleUnit_Auto == aWidthUnit) {
|
1999-07-20 03:41:03 +00:00
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType)) {
|
1999-03-05 04:24:20 +00:00
|
|
|
// Block-level replaced element in the flow. A specified value of
|
1999-05-03 20:53:27 +00:00
|
|
|
// 'auto' uses the element's intrinsic width (CSS2 10.3.4)
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = NS_INTRINSICSIZE;
|
1999-01-05 19:44:41 +00:00
|
|
|
} else {
|
1999-05-03 20:53:27 +00:00
|
|
|
// Block-level non-replaced element in the flow. 'auto' values
|
1999-07-28 03:51:37 +00:00
|
|
|
// for margin-left and margin-right become 0, and the sum of the
|
1999-05-03 20:53:27 +00:00
|
|
|
// areas must equal the width of the content-area of the parent
|
|
|
|
// element.
|
1999-03-05 04:24:20 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == availableWidth) {
|
1999-05-03 20:53:27 +00:00
|
|
|
// During pass1 table reflow, auto side margin values are
|
|
|
|
// uncomputable (== 0).
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
2000-01-03 04:32:13 +00:00
|
|
|
} else if (NS_SHRINKWRAPWIDTH == aContainingBlockWidth) {
|
|
|
|
// The containing block should shrink wrap its width, so have
|
|
|
|
// the child block do the same
|
|
|
|
mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
|
|
|
// Let its content area be as wide as the containing block's max width
|
|
|
|
// minus any margin and border/padding
|
|
|
|
nscoord maxWidth = cbrs->mComputedMaxWidth - mComputedMargin.left -
|
|
|
|
mComputedBorderPadding.left - mComputedMargin.right -
|
|
|
|
mComputedBorderPadding.right;
|
|
|
|
|
|
|
|
if (maxWidth < mComputedMaxWidth) {
|
|
|
|
mComputedMaxWidth = maxWidth;
|
|
|
|
}
|
|
|
|
|
1999-03-05 04:24:20 +00:00
|
|
|
} else {
|
2000-04-28 21:05:31 +00:00
|
|
|
// tables act like replaced elements regarding mComputedWidth
|
|
|
|
nsCOMPtr<nsIAtom> fType;
|
|
|
|
frame->GetFrameType(getter_AddRefs(fType));
|
|
|
|
if (nsLayoutAtoms::tableOuterFrame == fType.get()) {
|
2000-04-30 22:29:01 +00:00
|
|
|
mComputedWidth = 0; // XXX temp fix for trees
|
2000-04-28 21:05:31 +00:00
|
|
|
} else if (nsLayoutAtoms::tableFrame == fType.get()) {
|
|
|
|
mComputedWidth = NS_SHRINKWRAPWIDTH;
|
|
|
|
if (eStyleUnit_Auto == mStyleSpacing->mMargin.GetLeftUnit()) {
|
|
|
|
mComputedMargin.left = NS_AUTOMARGIN;
|
|
|
|
}
|
|
|
|
if (eStyleUnit_Auto == mStyleSpacing->mMargin.GetRightUnit()) {
|
|
|
|
mComputedMargin.right = NS_AUTOMARGIN;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mComputedWidth = availableWidth - mComputedMargin.left -
|
|
|
|
mComputedMargin.right - mComputedBorderPadding.left -
|
|
|
|
mComputedBorderPadding.right;
|
|
|
|
}
|
1999-03-11 15:13:17 +00:00
|
|
|
|
|
|
|
// Take into account any min and max values
|
1999-07-20 03:41:03 +00:00
|
|
|
if (mComputedWidth > mComputedMaxWidth) {
|
2000-04-16 04:07:02 +00:00
|
|
|
// Use 'max-width' as the value for 'width'
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = mComputedMaxWidth;
|
|
|
|
} else if (mComputedWidth < mComputedMinWidth) {
|
2000-04-16 04:07:02 +00:00
|
|
|
// Use 'min-width' as the value for 'width'
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = mComputedMinWidth;
|
1999-03-11 15:13:17 +00:00
|
|
|
}
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (eStyleUnit_Inherit == aWidthUnit) {
|
1999-07-28 03:51:37 +00:00
|
|
|
// Use parent element's width. Note that if its width was
|
1999-03-05 21:26:49 +00:00
|
|
|
// 'inherit', then it already did this so we don't need to
|
|
|
|
// recurse upwards.
|
1999-03-05 04:24:20 +00:00
|
|
|
//
|
1999-07-28 03:51:37 +00:00
|
|
|
// We use the containing block's width here for the "parent"
|
1999-03-05 21:26:49 +00:00
|
|
|
// elements width, because we want to skip over any intervening
|
1999-03-05 04:24:20 +00:00
|
|
|
// inline elements (since width doesn't apply to them).
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != aContainingBlockWidth) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = aContainingBlockWidth;
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, aWidthUnit,
|
1999-07-20 03:41:03 +00:00
|
|
|
mStylePosition->mWidth, mComputedWidth);
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
1999-01-05 19:44:41 +00:00
|
|
|
|
1999-03-11 15:13:17 +00:00
|
|
|
// Take into account any min and max values
|
1999-07-20 03:41:03 +00:00
|
|
|
if (mComputedWidth > mComputedMaxWidth) {
|
|
|
|
mComputedWidth = mComputedMaxWidth;
|
|
|
|
} else if (mComputedWidth < mComputedMinWidth) {
|
|
|
|
mComputedWidth = mComputedMinWidth;
|
1999-03-11 15:13:17 +00:00
|
|
|
}
|
|
|
|
|
1999-07-28 03:51:37 +00:00
|
|
|
// See what edge the width applies to (the default is the content
|
|
|
|
// edge)
|
|
|
|
if (mComputedWidth != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_PADDING) {
|
|
|
|
mComputedWidth -= mComputedPadding.left + mComputedPadding.right;
|
|
|
|
} else if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
|
|
|
mComputedWidth -= mComputedBorderPadding.left + mComputedBorderPadding.right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-03 20:53:27 +00:00
|
|
|
// Now that we have the computed-width, compute the side margins
|
1999-07-20 03:41:03 +00:00
|
|
|
CalculateBlockSideMargins(cbrs, mComputedWidth);
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
1999-05-03 20:53:27 +00:00
|
|
|
|
1999-03-05 04:24:20 +00:00
|
|
|
// Compute the content height
|
|
|
|
if (eStyleUnit_Inherit == aHeightUnit) {
|
|
|
|
// Use parent elements height (note that if its height was inherit
|
|
|
|
// then it already did this so we don't need to recurse upwards).
|
|
|
|
//
|
|
|
|
// We use the containing blocks height here for the "parent"
|
|
|
|
// elements height because we want to skip over any interveening
|
|
|
|
// inline elements (since height doesn't apply to them).
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != aContainingBlockHeight) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight = aContainingBlockHeight;
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
|
|
|
} else if (eStyleUnit_Auto == aHeightUnit) {
|
1999-07-20 03:41:03 +00:00
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType)) {
|
1999-03-05 04:24:20 +00:00
|
|
|
// For replaced elements use the intrinsic size for "auto"
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight = NS_INTRINSICSIZE;
|
1999-03-05 04:24:20 +00:00
|
|
|
} else {
|
|
|
|
// For non-replaced elements auto means unconstrained
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedHeight = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ComputeVerticalValue(aContainingBlockHeight, aHeightUnit,
|
1999-07-20 03:41:03 +00:00
|
|
|
mStylePosition->mHeight, mComputedHeight);
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
1999-07-28 03:51:37 +00:00
|
|
|
// Take into account any min and max values
|
2000-04-16 04:07:02 +00:00
|
|
|
if (mComputedHeight != NS_AUTOHEIGHT) {
|
|
|
|
if (mComputedHeight > mComputedMaxHeight) {
|
|
|
|
mComputedHeight = mComputedMaxHeight;
|
|
|
|
} else if (mComputedHeight < mComputedMinHeight) {
|
|
|
|
mComputedHeight = mComputedMinHeight;
|
|
|
|
}
|
1999-03-11 15:13:17 +00:00
|
|
|
}
|
1999-07-28 03:51:37 +00:00
|
|
|
// See what edge the height applies to (the default is the content
|
|
|
|
// edge)
|
|
|
|
if (mComputedHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_PADDING) {
|
|
|
|
mComputedHeight -= mComputedPadding.top + mComputedPadding.bottom;
|
|
|
|
} else if (mStylePosition->mBoxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
|
|
|
mComputedHeight -= mComputedBorderPadding.top + mComputedBorderPadding.bottom;
|
|
|
|
}
|
|
|
|
}
|
1999-03-05 04:24:20 +00:00
|
|
|
}
|
1999-01-05 19:44:41 +00:00
|
|
|
|
1999-05-03 20:53:27 +00:00
|
|
|
// This code enforces section 10.3.3 of the CSS2 spec for this formula:
|
|
|
|
//
|
|
|
|
// 'margin-left' + 'border-left-width' + 'padding-left' + 'width' +
|
|
|
|
// 'padding-right' + 'border-right-width' + 'margin-right'
|
|
|
|
// = width of containing block
|
1999-03-05 04:24:20 +00:00
|
|
|
//
|
1999-05-03 20:53:27 +00:00
|
|
|
// Note: the width unit is not auto when this is called
|
1999-03-05 04:24:20 +00:00
|
|
|
void
|
1999-05-03 20:53:27 +00:00
|
|
|
nsHTMLReflowState::CalculateBlockSideMargins(const nsHTMLReflowState* cbrs,
|
1999-09-21 00:15:16 +00:00
|
|
|
nscoord aComputedWidth)
|
1999-05-03 20:53:27 +00:00
|
|
|
{
|
|
|
|
// We can only provide values for auto side margins in a constrained
|
|
|
|
// reflow. For unconstrained reflow there is no effective width to
|
|
|
|
// compute against...
|
1999-09-21 00:15:16 +00:00
|
|
|
if ((NS_UNCONSTRAINEDSIZE == aComputedWidth) ||
|
1999-07-20 03:41:03 +00:00
|
|
|
(NS_UNCONSTRAINEDSIZE == cbrs->mComputedWidth)) {
|
1999-05-03 20:53:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-07-20 03:41:03 +00:00
|
|
|
nscoord sum = mComputedMargin.left + mComputedBorderPadding.left +
|
1999-09-21 00:15:16 +00:00
|
|
|
aComputedWidth + mComputedBorderPadding.right + mComputedMargin.right;
|
1999-07-20 03:41:03 +00:00
|
|
|
if (sum == cbrs->mComputedWidth) {
|
1999-05-03 20:53:27 +00:00
|
|
|
// The sum is already correct
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the left and right margin values. The width value
|
|
|
|
// remains constant while we do this.
|
|
|
|
PRBool isAutoLeftMargin =
|
|
|
|
eStyleUnit_Auto == mStyleSpacing->mMargin.GetLeftUnit();
|
|
|
|
PRBool isAutoRightMargin =
|
|
|
|
eStyleUnit_Auto == mStyleSpacing->mMargin.GetRightUnit();
|
|
|
|
|
|
|
|
// Calculate how much space is available for margins
|
1999-09-21 00:15:16 +00:00
|
|
|
nscoord availMarginSpace = cbrs->mComputedWidth - aComputedWidth -
|
1999-05-03 20:53:27 +00:00
|
|
|
mComputedBorderPadding.left - mComputedBorderPadding.right;
|
1999-09-21 00:15:16 +00:00
|
|
|
|
|
|
|
if (mStyleDisplay->mDisplay == NS_STYLE_DISPLAY_TABLE) {
|
|
|
|
// Special rules for tables. In general, tables will stick to the
|
|
|
|
// left edge when they are too large otherwise they behave like
|
|
|
|
// blocks.
|
|
|
|
if (availMarginSpace < 0) {
|
|
|
|
// Whoops - the TABLE element is too large for the available
|
|
|
|
// space. In this case use the "direction" property to pin the
|
|
|
|
// element to the left or right side. Note that we look at the
|
|
|
|
// parent's direction since the parent will be placing this
|
|
|
|
// element.
|
|
|
|
mComputedMargin.left = 0;
|
|
|
|
mComputedMargin.right = 0;
|
|
|
|
const nsHTMLReflowState* prs = (const nsHTMLReflowState*)
|
|
|
|
parentReflowState;
|
|
|
|
if (prs && (NS_STYLE_DIRECTION_RTL == prs->mStyleDisplay->mDirection)) {
|
|
|
|
mComputedMargin.left = availMarginSpace;
|
|
|
|
}
|
|
|
|
isAutoLeftMargin = isAutoRightMargin = PR_FALSE;
|
1999-07-05 18:45:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1999-09-21 00:15:16 +00:00
|
|
|
// The css2 spec clearly defines how block elements should be have
|
|
|
|
// in section 10.3.3.
|
|
|
|
if (!isAutoLeftMargin && !isAutoRightMargin) {
|
|
|
|
// Neither margin is 'auto' so we're over constrained. Use the
|
|
|
|
// 'direction' property of the parent to tell which margin to
|
|
|
|
// ignore
|
|
|
|
const nsHTMLReflowState* prs = (const nsHTMLReflowState*)
|
|
|
|
parentReflowState;
|
|
|
|
if (prs) {
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == prs->mStyleDisplay->mDirection) {
|
|
|
|
// The specified value of margin-right is ignored (== forced
|
|
|
|
// to auto)
|
|
|
|
isAutoRightMargin = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
1999-07-05 18:45:12 +00:00
|
|
|
isAutoLeftMargin = PR_TRUE;
|
|
|
|
}
|
1999-05-10 22:28:30 +00:00
|
|
|
}
|
1999-09-21 00:15:16 +00:00
|
|
|
else {
|
|
|
|
// No parent reflow state -- assume direction is ltr
|
|
|
|
isAutoRightMargin = PR_TRUE;
|
1999-07-05 18:45:12 +00:00
|
|
|
}
|
1999-05-03 20:53:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-21 00:15:16 +00:00
|
|
|
// Logic which is common to blocks and tables
|
|
|
|
if (isAutoLeftMargin) {
|
|
|
|
if (isAutoRightMargin) {
|
|
|
|
// Both margins are 'auto' so their computed values are equal
|
|
|
|
mComputedMargin.left = availMarginSpace / 2;
|
|
|
|
mComputedMargin.right = availMarginSpace - mComputedMargin.left;
|
|
|
|
} else {
|
|
|
|
mComputedMargin.left = availMarginSpace - mComputedMargin.right;
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
1999-09-21 00:15:16 +00:00
|
|
|
} else if (isAutoRightMargin) {
|
|
|
|
mComputedMargin.right = availMarginSpace - mComputedMargin.left;
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-12 23:25:49 +00:00
|
|
|
PRBool
|
|
|
|
nsHTMLReflowState::UseComputedHeight()
|
|
|
|
{
|
|
|
|
static PRBool useComputedHeight = PR_FALSE;
|
|
|
|
|
|
|
|
#if defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
|
|
|
|
static PRBool firstTime = 1;
|
|
|
|
if (firstTime) {
|
|
|
|
if (getenv("GECKO_USE_COMPUTED_HEIGHT")) {
|
|
|
|
useComputedHeight = PR_TRUE;
|
|
|
|
}
|
|
|
|
firstTime = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return useComputedHeight;
|
|
|
|
}
|
|
|
|
|
1999-09-09 21:03:27 +00:00
|
|
|
static nsIStyleContext*
|
|
|
|
GetNonInheritedLineHeightStyleContext(nsIStyleContext* aStyleContext)
|
1999-01-05 19:44:41 +00:00
|
|
|
{
|
1999-09-09 21:54:20 +00:00
|
|
|
nsIStyleContext* parentSC;
|
|
|
|
parentSC = aStyleContext->GetParent();
|
1999-09-09 21:03:27 +00:00
|
|
|
if (parentSC) {
|
|
|
|
const nsStyleText* text = (const nsStyleText*)
|
|
|
|
parentSC->GetStyleData(eStyleStruct_Text);
|
|
|
|
if (eStyleUnit_Inherit == text->mLineHeight.GetUnit()) {
|
1999-09-09 21:54:20 +00:00
|
|
|
nsIStyleContext* sc = GetNonInheritedLineHeightStyleContext(parentSC);
|
|
|
|
NS_RELEASE(parentSC);
|
|
|
|
return sc;
|
1999-09-09 21:03:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return parentSC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nscoord
|
|
|
|
ComputeLineHeight(nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIStyleContext* aStyleContext)
|
|
|
|
{
|
2000-01-11 22:15:20 +00:00
|
|
|
NS_PRECONDITION(nsnull != aRenderingContext, "no rendering context");
|
|
|
|
|
1999-10-12 23:25:49 +00:00
|
|
|
nscoord lineHeight = -1;
|
1999-09-09 21:03:27 +00:00
|
|
|
|
|
|
|
const nsStyleText* text = (const nsStyleText*)
|
|
|
|
aStyleContext->GetStyleData(eStyleStruct_Text);
|
|
|
|
const nsStyleFont* font = (const nsStyleFont*)
|
|
|
|
aStyleContext->GetStyleData(eStyleStruct_Font);
|
|
|
|
|
|
|
|
nsStyleUnit unit = text->mLineHeight.GetUnit();
|
|
|
|
if (eStyleUnit_Inherit == unit) {
|
|
|
|
// Inherit parents line-height value
|
|
|
|
nsCOMPtr<nsIStyleContext> parentSC =
|
|
|
|
getter_AddRefs(GetNonInheritedLineHeightStyleContext(aStyleContext));
|
|
|
|
if (parentSC) {
|
|
|
|
text = (const nsStyleText*) parentSC->GetStyleData(eStyleStruct_Text);
|
|
|
|
unit = text->mLineHeight.GetUnit();
|
|
|
|
if (eStyleUnit_Percent == unit) {
|
1999-10-12 23:25:49 +00:00
|
|
|
// For percent, we inherit the computed value so update the
|
1999-09-09 21:03:27 +00:00
|
|
|
// font to use the parent's font not our font.
|
|
|
|
font = (const nsStyleFont*) parentSC->GetStyleData(eStyleStruct_Font);
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-09 21:03:27 +00:00
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
// For length values just use the pre-computed value
|
|
|
|
lineHeight = text->mLineHeight.GetCoordValue();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For "normal", factor or percentage units the computed value of
|
|
|
|
// the line-height property is found by multiplying the factor by
|
|
|
|
// the font's <b>actual</b> height. For "normal" we use a factor
|
|
|
|
// value of "1.0".
|
|
|
|
float factor = 1.0f;
|
|
|
|
if (eStyleUnit_Factor == unit) {
|
|
|
|
factor = text->mLineHeight.GetFactorValue();
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Percent == unit) {
|
|
|
|
factor = text->mLineHeight.GetPercentValue();
|
|
|
|
}
|
|
|
|
aRenderingContext->SetFont(font->mFont);
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
aRenderingContext->GetFontMetrics(*getter_AddRefs(fm));
|
|
|
|
if (fm) {
|
|
|
|
fm->GetHeight(lineHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: we normally use the actual font height for computing the
|
|
|
|
// line-height raw value from the style context. On systems where
|
|
|
|
// they disagree the actual font height is more appropriate. This
|
|
|
|
// little hack lets us override that behavior to allow for more
|
|
|
|
// precise layout in the face of imprecise fonts.
|
1999-10-12 23:25:49 +00:00
|
|
|
if (nsHTMLReflowState::UseComputedHeight()) {
|
1999-09-09 21:03:27 +00:00
|
|
|
lineHeight = font->mFont.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
lineHeight = NSToCoordRound(factor * lineHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
return lineHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
1999-11-24 06:03:41 +00:00
|
|
|
nsHTMLReflowState::CalcLineHeight(nsIPresContext* aPresContext,
|
1999-09-09 21:03:27 +00:00
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
1999-10-12 23:25:49 +00:00
|
|
|
nscoord lineHeight = -1;
|
1999-09-09 21:03:27 +00:00
|
|
|
nsCOMPtr<nsIStyleContext> sc;
|
|
|
|
aFrame->GetStyleContext(getter_AddRefs(sc));
|
|
|
|
if (sc) {
|
|
|
|
lineHeight = ComputeLineHeight(aRenderingContext, sc);
|
|
|
|
}
|
|
|
|
if (lineHeight < 0) {
|
1999-10-12 23:25:49 +00:00
|
|
|
// Negative line-heights are not allowed by the spec. Translate
|
|
|
|
// them into "normal" (== 1.0) when found.
|
|
|
|
const nsStyleFont* font = (const nsStyleFont*)
|
|
|
|
sc->GetStyleData(eStyleStruct_Font);
|
|
|
|
if (UseComputedHeight()) {
|
|
|
|
lineHeight = font->mFont.size;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRenderingContext->SetFont(font->mFont);
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
aRenderingContext->GetFontMetrics(*getter_AddRefs(fm));
|
|
|
|
if (fm) {
|
|
|
|
fm->GetHeight(lineHeight);
|
|
|
|
}
|
|
|
|
}
|
1999-09-09 21:03:27 +00:00
|
|
|
}
|
1999-01-05 19:44:41 +00:00
|
|
|
return lineHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::ComputeHorizontalValue(nscoord aContainingBlockWidth,
|
|
|
|
nsStyleUnit aUnit,
|
|
|
|
const nsStyleCoord& aCoord,
|
|
|
|
nscoord& aResult)
|
|
|
|
{
|
1999-01-16 20:58:17 +00:00
|
|
|
NS_PRECONDITION(eStyleUnit_Inherit != aUnit, "unexpected unit");
|
1999-01-05 19:44:41 +00:00
|
|
|
aResult = 0;
|
|
|
|
if (eStyleUnit_Percent == aUnit) {
|
1999-03-26 03:57:46 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
|
|
|
|
aResult = 0;
|
|
|
|
} else {
|
|
|
|
float pct = aCoord.GetPercentValue();
|
|
|
|
aResult = NSToCoordFloor(aContainingBlockWidth * pct);
|
|
|
|
}
|
1999-01-05 19:44:41 +00:00
|
|
|
|
|
|
|
} else if (eStyleUnit_Coord == aUnit) {
|
|
|
|
aResult = aCoord.GetCoordValue();
|
|
|
|
}
|
1999-03-31 04:11:40 +00:00
|
|
|
else if (eStyleUnit_Chars == aUnit) {
|
|
|
|
if ((nsnull == rendContext) || (nsnull == frame)) {
|
|
|
|
// We can't compute it without a rendering context or frame, so
|
|
|
|
// pretend its zero...
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const nsStyleFont* font;
|
|
|
|
frame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&) font);
|
|
|
|
rendContext->SetFont(font->mFont);
|
|
|
|
nscoord fontWidth;
|
|
|
|
rendContext->GetWidth('M', fontWidth);
|
|
|
|
aResult = aCoord.GetIntValue() * fontWidth;
|
|
|
|
}
|
|
|
|
}
|
1999-01-05 19:44:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::ComputeVerticalValue(nscoord aContainingBlockHeight,
|
|
|
|
nsStyleUnit aUnit,
|
|
|
|
const nsStyleCoord& aCoord,
|
|
|
|
nscoord& aResult)
|
|
|
|
{
|
1999-01-16 20:58:17 +00:00
|
|
|
NS_PRECONDITION(eStyleUnit_Inherit != aUnit, "unexpected unit");
|
1999-01-05 19:44:41 +00:00
|
|
|
aResult = 0;
|
|
|
|
if (eStyleUnit_Percent == aUnit) {
|
|
|
|
// Verify no one is trying to calculate a percentage based height against
|
|
|
|
// a height that's shrink wrapping to its content. In that case they should
|
|
|
|
// treat the specified value like 'auto'
|
|
|
|
NS_ASSERTION(NS_AUTOHEIGHT != aContainingBlockHeight, "unexpected containing block height");
|
|
|
|
float pct = aCoord.GetPercentValue();
|
|
|
|
aResult = NSToCoordFloor(aContainingBlockHeight * pct);
|
|
|
|
|
|
|
|
} else if (eStyleUnit_Coord == aUnit) {
|
|
|
|
aResult = aCoord.GetCoordValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-05 22:24:27 +00:00
|
|
|
void
|
1999-03-26 03:57:46 +00:00
|
|
|
nsHTMLReflowState::ComputeMargin(nscoord aContainingBlockWidth,
|
|
|
|
const nsHTMLReflowState* aContainingBlockRS)
|
1999-03-05 22:24:27 +00:00
|
|
|
{
|
|
|
|
// If style style can provide us the margin directly, then use it.
|
1999-07-20 03:41:03 +00:00
|
|
|
if (!mStyleSpacing->GetMargin(mComputedMargin)) {
|
1999-03-26 03:57:46 +00:00
|
|
|
// We have to compute the value
|
1999-03-05 22:24:27 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.left = 0;
|
|
|
|
mComputedMargin.right = 0;
|
1999-03-05 22:24:27 +00:00
|
|
|
|
2000-01-03 04:32:13 +00:00
|
|
|
if (eStyleUnit_Coord == mStyleSpacing->mMargin.GetLeftUnit()) {
|
|
|
|
nsStyleCoord left;
|
|
|
|
|
|
|
|
mStyleSpacing->mMargin.GetLeft(left),
|
|
|
|
mComputedMargin.left = left.GetCoordValue();
|
|
|
|
}
|
|
|
|
if (eStyleUnit_Coord == mStyleSpacing->mMargin.GetRightUnit()) {
|
|
|
|
nsStyleCoord right;
|
|
|
|
|
|
|
|
mStyleSpacing->mMargin.GetRight(right),
|
|
|
|
mComputedMargin.right = right.GetCoordValue();
|
|
|
|
}
|
|
|
|
|
1999-03-05 22:24:27 +00:00
|
|
|
} else {
|
|
|
|
nsStyleCoord left, right;
|
1999-03-26 03:57:46 +00:00
|
|
|
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mMargin.GetLeftUnit()) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.left = aContainingBlockRS->mComputedMargin.left;
|
1999-03-26 03:57:46 +00:00
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mMargin.GetLeftUnit(),
|
|
|
|
mStyleSpacing->mMargin.GetLeft(left),
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.left);
|
1999-03-26 03:57:46 +00:00
|
|
|
}
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mMargin.GetRightUnit()) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.right = aContainingBlockRS->mComputedMargin.right;
|
1999-03-26 03:57:46 +00:00
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mMargin.GetRightUnit(),
|
|
|
|
mStyleSpacing->mMargin.GetRight(right),
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.right);
|
1999-03-26 03:57:46 +00:00
|
|
|
}
|
1999-03-05 22:24:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsHTMLReflowState* rs2 = GetPageBoxReflowState(parentReflowState);
|
|
|
|
nsStyleCoord top, bottom;
|
|
|
|
if (nsnull != rs2) {
|
|
|
|
// According to the CSS2 spec, margin percentages are
|
|
|
|
// calculated with respect to the *height* of the containing
|
|
|
|
// block when in a paginated context.
|
1999-03-26 03:57:46 +00:00
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mMargin.GetTopUnit()) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.top = aContainingBlockRS->mComputedMargin.top;
|
1999-03-26 03:57:46 +00:00
|
|
|
} else {
|
1999-07-20 03:41:03 +00:00
|
|
|
ComputeVerticalValue(rs2->mComputedHeight,
|
1999-03-26 03:57:46 +00:00
|
|
|
mStyleSpacing->mMargin.GetTopUnit(),
|
|
|
|
mStyleSpacing->mMargin.GetTop(top),
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.top);
|
1999-03-26 03:57:46 +00:00
|
|
|
}
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mMargin.GetBottomUnit()) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.bottom = aContainingBlockRS->mComputedMargin.bottom;
|
1999-03-26 03:57:46 +00:00
|
|
|
} else {
|
1999-07-20 03:41:03 +00:00
|
|
|
ComputeVerticalValue(rs2->mComputedHeight,
|
1999-03-26 03:57:46 +00:00
|
|
|
mStyleSpacing->mMargin.GetBottomUnit(),
|
|
|
|
mStyleSpacing->mMargin.GetBottom(bottom),
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.bottom);
|
1999-03-26 03:57:46 +00:00
|
|
|
}
|
1999-03-05 22:24:27 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// According to the CSS2 spec, margin percentages are
|
|
|
|
// calculated with respect to the *width* of the containing
|
|
|
|
// block, even for margin-top and margin-bottom.
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.top = 0;
|
|
|
|
mComputedMargin.bottom = 0;
|
1999-03-05 22:24:27 +00:00
|
|
|
|
|
|
|
} else {
|
1999-03-26 03:57:46 +00:00
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mMargin.GetTopUnit()) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.top = aContainingBlockRS->mComputedMargin.top;
|
1999-03-26 03:57:46 +00:00
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mMargin.GetTopUnit(),
|
|
|
|
mStyleSpacing->mMargin.GetTop(top),
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.top);
|
1999-03-26 03:57:46 +00:00
|
|
|
}
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mMargin.GetBottomUnit()) {
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.bottom = aContainingBlockRS->mComputedMargin.bottom;
|
1999-03-26 03:57:46 +00:00
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mMargin.GetBottomUnit(),
|
|
|
|
mStyleSpacing->mMargin.GetBottom(bottom),
|
1999-07-20 03:41:03 +00:00
|
|
|
mComputedMargin.bottom);
|
1999-03-26 03:57:46 +00:00
|
|
|
}
|
1999-03-05 22:24:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-06 00:36:59 +00:00
|
|
|
void
|
1999-03-26 03:57:46 +00:00
|
|
|
nsHTMLReflowState::ComputePadding(nscoord aContainingBlockWidth,
|
|
|
|
const nsHTMLReflowState* aContainingBlockRS)
|
|
|
|
|
1999-03-06 00:36:59 +00:00
|
|
|
{
|
|
|
|
// If style can provide us the padding directly, then use it.
|
1999-03-26 03:57:46 +00:00
|
|
|
if (!mStyleSpacing->GetPadding(mComputedPadding)) {
|
|
|
|
// We have to compute the value
|
1999-03-06 00:36:59 +00:00
|
|
|
nsStyleCoord left, right, top, bottom;
|
1999-03-26 03:57:46 +00:00
|
|
|
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mPadding.GetLeftUnit()) {
|
|
|
|
mComputedPadding.left = aContainingBlockRS->mComputedPadding.left;
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mPadding.GetLeftUnit(),
|
|
|
|
mStyleSpacing->mPadding.GetLeft(left),
|
|
|
|
mComputedPadding.left);
|
|
|
|
}
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mPadding.GetRightUnit()) {
|
|
|
|
mComputedPadding.right = aContainingBlockRS->mComputedPadding.right;
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mPadding.GetRightUnit(),
|
|
|
|
mStyleSpacing->mPadding.GetRight(right),
|
|
|
|
mComputedPadding.right);
|
|
|
|
}
|
|
|
|
|
|
|
|
// According to the CSS2 spec, percentages are calculated with respect to
|
|
|
|
// containing block width for padding-top and padding-bottom
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mPadding.GetTopUnit()) {
|
|
|
|
mComputedPadding.top = aContainingBlockRS->mComputedPadding.top;
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mPadding.GetTopUnit(),
|
|
|
|
mStyleSpacing->mPadding.GetTop(top),
|
|
|
|
mComputedPadding.top);
|
|
|
|
}
|
|
|
|
if (eStyleUnit_Inherit == mStyleSpacing->mPadding.GetBottomUnit()) {
|
|
|
|
mComputedPadding.bottom = aContainingBlockRS->mComputedPadding.bottom;
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleSpacing->mPadding.GetBottomUnit(),
|
|
|
|
mStyleSpacing->mPadding.GetBottom(bottom),
|
|
|
|
mComputedPadding.bottom);
|
|
|
|
}
|
1999-03-06 00:36:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-11 01:23:10 +00:00
|
|
|
void
|
|
|
|
nsHTMLReflowState::ComputeMinMaxValues(nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
const nsHTMLReflowState* aContainingBlockRS)
|
|
|
|
{
|
|
|
|
nsStyleUnit minWidthUnit = mStylePosition->mMinWidth.GetUnit();
|
|
|
|
if (eStyleUnit_Inherit == minWidthUnit) {
|
|
|
|
mComputedMinWidth = aContainingBlockRS->mComputedMinWidth;
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, minWidthUnit,
|
|
|
|
mStylePosition->mMinWidth, mComputedMinWidth);
|
|
|
|
}
|
|
|
|
nsStyleUnit maxWidthUnit = mStylePosition->mMaxWidth.GetUnit();
|
|
|
|
if (eStyleUnit_Inherit == maxWidthUnit) {
|
|
|
|
mComputedMaxWidth = aContainingBlockRS->mComputedMaxWidth;
|
1999-03-11 15:13:17 +00:00
|
|
|
} else if (eStyleUnit_Null == maxWidthUnit) {
|
|
|
|
// Specified value of 'none'
|
|
|
|
mComputedMaxWidth = NS_UNCONSTRAINEDSIZE; // no limit
|
1999-03-11 01:23:10 +00:00
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, maxWidthUnit,
|
|
|
|
mStylePosition->mMaxWidth, mComputedMaxWidth);
|
|
|
|
}
|
1999-03-11 15:13:17 +00:00
|
|
|
|
|
|
|
// If the computed value of 'min-width' is greater than the value of
|
|
|
|
// 'max-width', 'max-width' is set to the value of 'min-width'
|
|
|
|
if (mComputedMinWidth > mComputedMaxWidth) {
|
|
|
|
mComputedMaxWidth = mComputedMinWidth;
|
|
|
|
}
|
|
|
|
|
1999-03-11 01:23:10 +00:00
|
|
|
nsStyleUnit minHeightUnit = mStylePosition->mMinHeight.GetUnit();
|
|
|
|
if (eStyleUnit_Inherit == minHeightUnit) {
|
|
|
|
mComputedMinHeight = aContainingBlockRS->mComputedMinHeight;
|
|
|
|
} else {
|
1999-03-11 15:13:17 +00:00
|
|
|
// Check for percentage based values and a containing block height that
|
|
|
|
// depends on the content height. Treat them like 'auto'
|
|
|
|
if ((NS_AUTOHEIGHT == aContainingBlockHeight) &&
|
|
|
|
(eStyleUnit_Percent == minHeightUnit)) {
|
|
|
|
mComputedMinHeight = 0;
|
|
|
|
} else {
|
|
|
|
ComputeVerticalValue(aContainingBlockHeight, minHeightUnit,
|
|
|
|
mStylePosition->mMinHeight, mComputedMinHeight);
|
|
|
|
}
|
1999-03-11 01:23:10 +00:00
|
|
|
}
|
|
|
|
nsStyleUnit maxHeightUnit = mStylePosition->mMaxHeight.GetUnit();
|
|
|
|
if (eStyleUnit_Inherit == maxHeightUnit) {
|
|
|
|
mComputedMaxHeight = aContainingBlockRS->mComputedMaxHeight;
|
1999-03-11 15:13:17 +00:00
|
|
|
} else if (eStyleUnit_Null == maxHeightUnit) {
|
|
|
|
// Specified value of 'none'
|
|
|
|
mComputedMaxHeight = NS_UNCONSTRAINEDSIZE; // no limit
|
1999-03-11 01:23:10 +00:00
|
|
|
} else {
|
1999-03-11 15:13:17 +00:00
|
|
|
// Check for percentage based values and a containing block height that
|
|
|
|
// depends on the content height. Treat them like 'auto'
|
|
|
|
if ((NS_AUTOHEIGHT == aContainingBlockHeight) &&
|
|
|
|
(eStyleUnit_Percent == maxHeightUnit)) {
|
|
|
|
mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
} else {
|
|
|
|
ComputeVerticalValue(aContainingBlockHeight, maxHeightUnit,
|
|
|
|
mStylePosition->mMaxHeight, mComputedMaxHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the computed value of 'min-height' is greater than the value of
|
|
|
|
// 'max-height', 'max-height' is set to the value of 'min-height'
|
|
|
|
if (mComputedMinHeight > mComputedMaxHeight) {
|
|
|
|
mComputedMaxHeight = mComputedMinHeight;
|
1999-03-11 01:23:10 +00:00
|
|
|
}
|
|
|
|
}
|