2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-05 22:44:41 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
1999-01-05 22:44:41 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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 22:44:41 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-01-05 22:44:41 +03:00
|
|
|
#include "nsStyleConsts.h"
|
2003-10-06 17:13:37 +04:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
1999-03-05 07:24:20 +03:00
|
|
|
#include "nsFrame.h"
|
1999-01-05 22:44:41 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1999-01-13 09:37:31 +03:00
|
|
|
#include "nsIPresShell.h"
|
1999-02-14 07:43:44 +03:00
|
|
|
#include "nsLayoutAtoms.h"
|
2000-05-17 10:47:56 +04:00
|
|
|
#include "nsIDeviceContext.h"
|
1999-03-31 08:11:40 +04:00
|
|
|
#include "nsIRenderingContext.h"
|
1999-09-10 01:03:27 +04:00
|
|
|
#include "nsIFontMetrics.h"
|
2000-04-16 08:07:02 +04:00
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsLineBox.h"
|
|
|
|
#include "nsImageFrame.h"
|
2001-10-24 08:51:34 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2002-04-11 01:32:41 +04:00
|
|
|
#include "nsIPercentHeightObserver.h"
|
2004-04-30 03:34:19 +04:00
|
|
|
#include "nsContentUtils.h"
|
2002-07-10 04:52:17 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsBidiUtils.h"
|
|
|
|
#endif
|
1999-01-05 22:44:41 +03:00
|
|
|
|
1999-03-08 22:26:30 +03:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#undef NOISY_VERTICAL_ALIGN
|
|
|
|
#else
|
|
|
|
#undef NOISY_VERTICAL_ALIGN
|
|
|
|
#endif
|
|
|
|
|
2001-10-24 08:51:34 +04:00
|
|
|
// Prefs-driven control for |text-decoration: blink|
|
2002-04-11 04:00:40 +04:00
|
|
|
static PRPackedBool sPrefIsLoaded = PR_FALSE;
|
2001-10-24 08:51:34 +04:00
|
|
|
static PRPackedBool sBlinkIsAllowed = PR_TRUE;
|
|
|
|
|
2002-04-11 04:00:40 +04:00
|
|
|
enum eNormalLineHeightControl {
|
|
|
|
eUninitialized = -1,
|
|
|
|
eNoExternalLeading = 0, // does not include external leading
|
|
|
|
eIncludeExternalLeading, // use whatever value font vendor provides
|
|
|
|
eCompensateLeading // compensate leading if leading provided by font vendor is not enough
|
|
|
|
};
|
2003-09-27 08:18:26 +04:00
|
|
|
|
|
|
|
#ifdef FONT_LEADING_APIS_V2
|
2002-04-11 04:00:40 +04:00
|
|
|
static eNormalLineHeightControl sNormalLineHeightControl = eUninitialized;
|
2003-09-27 08:18:26 +04:00
|
|
|
#endif
|
2002-04-11 04:00:40 +04:00
|
|
|
|
2001-09-06 00:27:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
const char*
|
|
|
|
nsHTMLReflowState::ReasonToString(nsReflowReason aReason)
|
|
|
|
{
|
|
|
|
static const char* reasons[] = {
|
|
|
|
"initial", "incremental", "resize", "style-change", "dirty"
|
|
|
|
};
|
|
|
|
|
|
|
|
return reasons[aReason];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-03-05 07:24:20 +03:00
|
|
|
// Initialize a <b>root</b> reflow state with a rendering context to
|
|
|
|
// use for measuring things.
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
|
1999-03-05 07:24:20 +03:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsReflowReason aReason,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
const nsSize& aAvailableSpace)
|
1999-08-28 01:48:54 +04:00
|
|
|
: mReflowDepth(0)
|
1999-03-05 07:24:20 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aRenderingContext, "no rendering context");
|
|
|
|
parentReflowState = nsnull;
|
|
|
|
frame = aFrame;
|
|
|
|
reason = aReason;
|
2002-05-10 22:22:41 +04:00
|
|
|
path = nsnull;
|
1999-03-05 07:24:20 +03:00
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
rendContext = aRenderingContext;
|
1999-07-20 07:41:03 +04:00
|
|
|
mSpaceManager = nsnull;
|
1999-07-20 07:51:46 +04:00
|
|
|
mLineLayout = nsnull;
|
2003-01-19 23:07:39 +03:00
|
|
|
mFlags.mSpecialHeightReflow = PR_FALSE;
|
2001-12-07 17:51:12 +03:00
|
|
|
mFlags.mIsTopOfPage = PR_FALSE;
|
2003-01-19 23:07:39 +03:00
|
|
|
mFlags.mUnused = 0;
|
2001-12-07 17:51:12 +03:00
|
|
|
mPercentHeightObserver = nsnull;
|
2002-04-01 10:46:17 +04:00
|
|
|
mPercentHeightReflowInitiator = nsnull;
|
1999-03-05 07:24:20 +03:00
|
|
|
Init(aPresContext);
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
2002-07-10 04:52:17 +04:00
|
|
|
mFlags.mVisualBidiFormControl = IsBidiFormControl(aPresContext);
|
2001-03-09 06:29:00 +03:00
|
|
|
mRightEdge = NS_UNCONSTRAINEDSIZE;
|
|
|
|
#endif
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize a <b>root</b> reflow state for an <b>incremental</b>
|
|
|
|
// reflow.
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
|
1999-03-05 07:24:20 +03:00
|
|
|
nsIFrame* aFrame,
|
2002-05-10 22:22:41 +04:00
|
|
|
nsReflowPath* aReflowPath,
|
1999-03-05 07:24:20 +03:00
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
const nsSize& aAvailableSpace)
|
1999-08-28 01:48:54 +04:00
|
|
|
: mReflowDepth(0)
|
1999-03-05 07:24:20 +03:00
|
|
|
{
|
2000-01-12 11:28:24 +03:00
|
|
|
NS_PRECONDITION(nsnull != aRenderingContext, "no rendering context");
|
1999-03-05 07:24:20 +03:00
|
|
|
|
2000-01-12 11:28:24 +03:00
|
|
|
reason = eReflowReason_Incremental;
|
2002-05-10 22:22:41 +04:00
|
|
|
path = aReflowPath;
|
1999-03-05 07:24:20 +03:00
|
|
|
parentReflowState = nsnull;
|
|
|
|
frame = aFrame;
|
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
rendContext = aRenderingContext;
|
1999-07-20 07:41:03 +04:00
|
|
|
mSpaceManager = nsnull;
|
1999-07-20 07:51:46 +04:00
|
|
|
mLineLayout = nsnull;
|
2003-01-19 23:07:39 +03:00
|
|
|
mFlags.mSpecialHeightReflow = PR_FALSE;
|
2001-12-07 17:51:12 +03:00
|
|
|
mFlags.mIsTopOfPage = PR_FALSE;
|
2003-01-19 23:07:39 +03:00
|
|
|
mFlags.mUnused = 0;
|
2001-12-07 17:51:12 +03:00
|
|
|
mPercentHeightObserver = nsnull;
|
2002-04-01 10:46:17 +04:00
|
|
|
mPercentHeightReflowInitiator = nsnull;
|
1999-03-05 07:24:20 +03:00
|
|
|
Init(aPresContext);
|
2001-03-09 06:29:00 +03:00
|
|
|
#ifdef IBMBIDI
|
2002-07-10 04:52:17 +04:00
|
|
|
mFlags.mVisualBidiFormControl = IsBidiFormControl(aPresContext);
|
2001-03-09 06:29:00 +03:00
|
|
|
mRightEdge = NS_UNCONSTRAINEDSIZE;
|
|
|
|
#endif // IBMBIDI
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize a reflow state for a child frames reflow. Some state
|
|
|
|
// is copied from the parent reflow state; the remaining state is
|
|
|
|
// computed.
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
|
1999-03-05 07:24:20 +03:00
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsSize& aAvailableSpace,
|
2002-02-19 18:48:28 +03:00
|
|
|
nsReflowReason aReason,
|
|
|
|
PRBool aInit)
|
2001-11-05 03:15:51 +03:00
|
|
|
: mReflowDepth(aParentReflowState.mReflowDepth + 1),
|
|
|
|
mFlags(aParentReflowState.mFlags)
|
1999-03-05 07:24:20 +03:00
|
|
|
{
|
|
|
|
parentReflowState = &aParentReflowState;
|
|
|
|
frame = aFrame;
|
|
|
|
reason = aReason;
|
2002-05-10 22:22:41 +04:00
|
|
|
if (reason == eReflowReason_Incremental) {
|
|
|
|
// If the child frame isn't along the reflow path, then convert
|
|
|
|
// the incremental reflow to a dirty reflow.
|
|
|
|
path = aParentReflowState.path->GetSubtreeFor(aFrame);
|
|
|
|
if (! path)
|
|
|
|
reason = eReflowReason_Dirty;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
path = nsnull;
|
|
|
|
|
1999-03-05 07:24:20 +03:00
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
|
|
|
|
rendContext = aParentReflowState.rendContext;
|
1999-07-20 07:41:03 +04:00
|
|
|
mSpaceManager = aParentReflowState.mSpaceManager;
|
1999-07-20 07:51:46 +04:00
|
|
|
mLineLayout = aParentReflowState.mLineLayout;
|
2001-12-07 17:51:12 +03:00
|
|
|
mFlags.mIsTopOfPage = aParentReflowState.mFlags.mIsTopOfPage;
|
2002-04-11 01:32:41 +04:00
|
|
|
mPercentHeightObserver = (aParentReflowState.mPercentHeightObserver &&
|
|
|
|
aParentReflowState.mPercentHeightObserver->NeedsToObserve(*this))
|
|
|
|
? aParentReflowState.mPercentHeightObserver : nsnull;
|
2002-04-01 10:46:17 +04:00
|
|
|
mPercentHeightReflowInitiator = aParentReflowState.mPercentHeightReflowInitiator;
|
1999-03-05 07:24:20 +03:00
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
if (aInit) {
|
|
|
|
Init(aPresContext);
|
|
|
|
}
|
2001-03-09 06:29:00 +03:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
2002-07-10 04:52:17 +04:00
|
|
|
mFlags.mVisualBidiFormControl = (aParentReflowState.mFlags.mVisualBidiFormControl) ?
|
|
|
|
PR_TRUE : IsBidiFormControl(aPresContext);
|
2001-03-09 06:29:00 +03:00
|
|
|
mRightEdge = aParentReflowState.mRightEdge;
|
|
|
|
#endif // IBMBIDI
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same as the previous except that the reason is taken from the
|
|
|
|
// parent's reflow state.
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
|
1999-03-05 07:24:20 +03:00
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsSize& aAvailableSpace)
|
2001-11-05 03:15:51 +03:00
|
|
|
: mReflowDepth(aParentReflowState.mReflowDepth + 1),
|
|
|
|
mFlags(aParentReflowState.mFlags)
|
1999-03-05 07:24:20 +03:00
|
|
|
{
|
|
|
|
parentReflowState = &aParentReflowState;
|
|
|
|
frame = aFrame;
|
|
|
|
reason = aParentReflowState.reason;
|
2002-05-10 22:22:41 +04:00
|
|
|
if (reason == eReflowReason_Incremental) {
|
|
|
|
// If the child frame isn't along the reflow path, then convert
|
|
|
|
// the incremental reflow to a dirty reflow.
|
|
|
|
path = aParentReflowState.path->GetSubtreeFor(aFrame);
|
|
|
|
if (! path)
|
|
|
|
reason = eReflowReason_Dirty;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
path = nsnull;
|
|
|
|
|
1999-03-05 07:24:20 +03:00
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
|
|
|
|
rendContext = aParentReflowState.rendContext;
|
1999-07-20 07:41:03 +04:00
|
|
|
mSpaceManager = aParentReflowState.mSpaceManager;
|
1999-07-20 07:51:46 +04:00
|
|
|
mLineLayout = aParentReflowState.mLineLayout;
|
2001-12-07 17:51:12 +03:00
|
|
|
mFlags.mIsTopOfPage = aParentReflowState.mFlags.mIsTopOfPage;
|
2002-04-11 01:32:41 +04:00
|
|
|
mPercentHeightObserver = (aParentReflowState.mPercentHeightObserver &&
|
|
|
|
aParentReflowState.mPercentHeightObserver->NeedsToObserve(*this))
|
|
|
|
? aParentReflowState.mPercentHeightObserver : nsnull;
|
2002-04-01 10:46:17 +04:00
|
|
|
mPercentHeightReflowInitiator = aParentReflowState.mPercentHeightReflowInitiator;
|
1999-03-05 07:24:20 +03:00
|
|
|
|
|
|
|
Init(aPresContext);
|
2001-03-09 06:29:00 +03:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
2002-07-10 04:52:17 +04:00
|
|
|
mFlags.mVisualBidiFormControl = (aParentReflowState.mFlags.mVisualBidiFormControl) ?
|
|
|
|
PR_TRUE : IsBidiFormControl(aPresContext);
|
2001-03-09 06:29:00 +03:00
|
|
|
mRightEdge = aParentReflowState.mRightEdge;
|
|
|
|
#endif // IBMBIDI
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
|
|
|
|
1999-09-16 18:33:19 +04:00
|
|
|
// Version that species the containing block width and height
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
|
1999-09-16 18:33:19 +04:00
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsSize& aAvailableSpace,
|
|
|
|
nscoord aContainingBlockWidth,
|
2002-05-10 22:22:41 +04:00
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
nsReflowReason aReason)
|
2001-11-05 03:15:51 +03:00
|
|
|
: mReflowDepth(aParentReflowState.mReflowDepth + 1),
|
|
|
|
mFlags(aParentReflowState.mFlags)
|
1999-09-16 18:33:19 +04:00
|
|
|
{
|
|
|
|
parentReflowState = &aParentReflowState;
|
|
|
|
frame = aFrame;
|
2002-05-10 22:22:41 +04:00
|
|
|
reason = aReason;
|
|
|
|
if (reason == eReflowReason_Incremental) {
|
|
|
|
// If the child frame isn't along the reflow path, then convert
|
|
|
|
// the incremental reflow to a dirty reflow.
|
|
|
|
path = aParentReflowState.path->GetSubtreeFor(aFrame);
|
|
|
|
if (! path)
|
|
|
|
reason = eReflowReason_Dirty;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
path = nsnull;
|
|
|
|
|
1999-09-16 18:33:19 +04:00
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
|
|
|
|
rendContext = aParentReflowState.rendContext;
|
|
|
|
mSpaceManager = aParentReflowState.mSpaceManager;
|
|
|
|
mLineLayout = aParentReflowState.mLineLayout;
|
2001-12-07 17:51:12 +03:00
|
|
|
mFlags.mIsTopOfPage = aParentReflowState.mFlags.mIsTopOfPage;
|
2002-04-11 01:32:41 +04:00
|
|
|
mPercentHeightObserver = (aParentReflowState.mPercentHeightObserver &&
|
|
|
|
aParentReflowState.mPercentHeightObserver->NeedsToObserve(*this))
|
|
|
|
? aParentReflowState.mPercentHeightObserver : nsnull;
|
2002-04-01 10:46:17 +04:00
|
|
|
mPercentHeightReflowInitiator = aParentReflowState.mPercentHeightReflowInitiator;
|
1999-09-16 18:33:19 +04:00
|
|
|
|
|
|
|
Init(aPresContext, aContainingBlockWidth, aContainingBlockHeight);
|
2001-03-09 06:29:00 +03:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
2002-07-10 04:52:17 +04:00
|
|
|
mFlags.mVisualBidiFormControl = (aParentReflowState.mFlags.mVisualBidiFormControl) ?
|
|
|
|
PR_TRUE : IsBidiFormControl(aPresContext);
|
2001-03-09 06:29:00 +03:00
|
|
|
mRightEdge = aParentReflowState.mRightEdge;
|
|
|
|
#endif // IBMBIDI
|
1999-09-16 18:33:19 +04:00
|
|
|
}
|
|
|
|
|
1999-03-05 07:24:20 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::Init(nsPresContext* aPresContext,
|
1999-09-16 18:33:19 +04:00
|
|
|
nscoord aContainingBlockWidth,
|
2002-02-19 18:48:28 +03:00
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
nsMargin* aBorder,
|
|
|
|
nsMargin* aPadding)
|
1999-03-05 07:24:20 +03:00
|
|
|
{
|
|
|
|
mCompactMarginWidth = 0;
|
2001-02-01 05:26:26 +03:00
|
|
|
#ifdef DEBUG
|
2001-01-25 18:55:51 +03:00
|
|
|
mDebugHook = nsnull;
|
2001-01-25 18:57:46 +03:00
|
|
|
#endif
|
1999-03-05 07:24:20 +03:00
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
mStylePosition = frame->GetStylePosition();
|
|
|
|
mStyleDisplay = frame->GetStyleDisplay();
|
|
|
|
mStyleVisibility = frame->GetStyleVisibility();
|
|
|
|
mStyleBorder = frame->GetStyleBorder();
|
|
|
|
mStyleMargin = frame->GetStyleMargin();
|
|
|
|
mStylePadding = frame->GetStylePadding();
|
|
|
|
mStyleText = frame->GetStyleText();
|
2001-11-28 08:06:17 +03:00
|
|
|
|
2003-11-17 03:35:17 +03:00
|
|
|
InitFrameType();
|
2002-05-14 16:59:55 +04:00
|
|
|
InitCBReflowState();
|
2002-02-19 18:48:28 +03:00
|
|
|
InitConstraints(aPresContext, aContainingBlockWidth, aContainingBlockHeight, aBorder, aPadding);
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
|
|
|
|
2002-05-14 16:59:55 +04:00
|
|
|
void nsHTMLReflowState::InitCBReflowState()
|
1999-01-05 22:44:41 +03:00
|
|
|
{
|
2004-04-24 21:56:23 +04:00
|
|
|
if (!parentReflowState) {
|
|
|
|
mCBReflowState = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parentReflowState->frame->IsContainingBlock() ||
|
|
|
|
// Absolutely positioned frames should always be kids of the frames that
|
|
|
|
// determine their containing block
|
|
|
|
(NS_FRAME_GET_TYPE(mFrameType) == NS_CSS_FRAME_TYPE_ABSOLUTE)) {
|
2002-05-14 16:59:55 +04:00
|
|
|
// a block inside a table cell needs to use the table cell
|
2004-04-24 21:56:23 +04:00
|
|
|
if (parentReflowState->parentReflowState &&
|
|
|
|
IS_TABLE_CELL(parentReflowState->parentReflowState->frame->GetType())) {
|
|
|
|
mCBReflowState = parentReflowState->parentReflowState;
|
|
|
|
} else {
|
|
|
|
mCBReflowState = parentReflowState;
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
2004-04-24 21:56:23 +04:00
|
|
|
|
2002-05-14 16:59:55 +04:00
|
|
|
return;
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
2004-04-24 21:56:23 +04:00
|
|
|
|
2002-05-14 16:59:55 +04:00
|
|
|
mCBReflowState = parentReflowState->mCBReflowState;
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsHTMLReflowState*
|
1999-10-30 06:52:11 +04:00
|
|
|
nsHTMLReflowState::GetPageBoxReflowState(const nsHTMLReflowState* aParentRS)
|
1999-01-05 22:44:41 +03:00
|
|
|
{
|
|
|
|
// XXX write me as soon as we can ask a frame if it's a page frame...
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2004-04-24 21:56:23 +04:00
|
|
|
nsHTMLReflowState::GetContainingBlockContentWidth(const nsHTMLReflowState* aReflowState)
|
1999-01-05 22:44:41 +03:00
|
|
|
{
|
2004-04-24 21:56:23 +04:00
|
|
|
const nsHTMLReflowState* rs = aReflowState->mCBReflowState;
|
2002-05-14 16:59:55 +04:00
|
|
|
if (!rs)
|
|
|
|
return 0;
|
|
|
|
return rs->mComputedWidth;
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
|
|
|
|
2003-11-17 03:35:17 +03:00
|
|
|
void
|
|
|
|
nsHTMLReflowState::InitFrameType()
|
1999-01-05 22:44:41 +03:00
|
|
|
{
|
2003-11-17 03:35:17 +03:00
|
|
|
const nsStyleDisplay *disp = mStyleDisplay;
|
1999-02-23 22:33:06 +03:00
|
|
|
nsCSSFrameType frameType;
|
1999-01-05 22:44:41 +03:00
|
|
|
|
1999-02-23 22:33:06 +03:00
|
|
|
// Section 9.7 of the CSS2 spec indicates that absolute position
|
|
|
|
// takes precedence over float which takes precedence over display.
|
1999-09-29 03:42:35 +04:00
|
|
|
// Make sure the frame was actually moved out of the flow, and don't
|
|
|
|
// just assume what the style says
|
2003-11-17 03:35:17 +03:00
|
|
|
// XXXldb nsRuleNode::ComputeDisplayData should take care of this, right?
|
|
|
|
if (frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) {
|
|
|
|
if (disp->IsAbsolutelyPositioned()) {
|
1999-09-29 03:42:35 +04:00
|
|
|
frameType = NS_CSS_FRAME_TYPE_ABSOLUTE;
|
|
|
|
}
|
2003-11-17 03:35:17 +03:00
|
|
|
else {
|
|
|
|
NS_ASSERTION(NS_STYLE_FLOAT_NONE != disp->mFloats,
|
|
|
|
"unknown out of flow frame type");
|
1999-09-29 03:42:35 +04:00
|
|
|
frameType = NS_CSS_FRAME_TYPE_FLOATING;
|
|
|
|
}
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
|
|
|
else {
|
2003-11-17 03:35:17 +03:00
|
|
|
switch (disp->mDisplay) {
|
1999-01-05 22:44:41 +03:00
|
|
|
case NS_STYLE_DISPLAY_BLOCK:
|
|
|
|
case NS_STYLE_DISPLAY_LIST_ITEM:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE:
|
2000-05-04 18:47:37 +04:00
|
|
|
case NS_STYLE_DISPLAY_TABLE_CAPTION:
|
1999-01-05 22:44:41 +03:00
|
|
|
frameType = NS_CSS_FRAME_TYPE_BLOCK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_INLINE:
|
|
|
|
case NS_STYLE_DISPLAY_MARKER:
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_TABLE:
|
2001-03-04 00:57:56 +03:00
|
|
|
case NS_STYLE_DISPLAY_INLINE_BOX:
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_GRID:
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_STACK:
|
1999-01-05 22:44:41 +03:00
|
|
|
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_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 08:59:19 +03:00
|
|
|
// See if the frame is replaced
|
2003-11-17 03:35:17 +03:00
|
|
|
if (frame->GetStateBits() & NS_FRAME_REPLACED_ELEMENT) {
|
1999-01-05 22:44:41 +03:00
|
|
|
frameType = NS_FRAME_REPLACED(frameType);
|
|
|
|
}
|
1999-02-23 22:33:06 +03:00
|
|
|
|
2003-11-17 03:35:17 +03:00
|
|
|
mFrameType = frameType;
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-04-22 08:27:47 +04:00
|
|
|
nsHTMLReflowState::ComputeRelativeOffsets(const nsHTMLReflowState* cbrs,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight)
|
1999-01-16 23:58:17 +03:00
|
|
|
{
|
1999-04-22 08:27:47 +04:00
|
|
|
nsStyleCoord coord;
|
1999-01-16 23:58:17 +03:00
|
|
|
|
1999-01-22 07:12:03 +03: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 07:24:20 +03:00
|
|
|
PRBool leftIsAuto = eStyleUnit_Auto == mStylePosition->mOffset.GetLeftUnit();
|
|
|
|
PRBool rightIsAuto = eStyleUnit_Auto == mStylePosition->mOffset.GetRightUnit();
|
1999-01-22 07:12:03 +03:00
|
|
|
|
1999-01-23 07:49:15 +03:00
|
|
|
// Check for percentage based values and an unconstrained containing
|
|
|
|
// block width. Treat them like 'auto'
|
1999-04-22 08:27:47 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
|
1999-03-05 07:24:20 +03:00
|
|
|
if (eStyleUnit_Percent == mStylePosition->mOffset.GetLeftUnit()) {
|
1999-01-23 07:49:15 +03:00
|
|
|
leftIsAuto = PR_TRUE;
|
|
|
|
}
|
1999-03-05 07:24:20 +03:00
|
|
|
if (eStyleUnit_Percent == mStylePosition->mOffset.GetRightUnit()) {
|
1999-01-23 07:49:15 +03:00
|
|
|
rightIsAuto = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-22 07:12:03 +03:00
|
|
|
// If neither 'left' not 'right' are auto, then we're over-constrained and
|
|
|
|
// we ignore one of them
|
|
|
|
if (!leftIsAuto && !rightIsAuto) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleVisibility* vis = frame->GetStyleVisibility();
|
1999-01-22 07:12:03 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
if (NS_STYLE_DIRECTION_LTR == vis->mDirection) {
|
1999-01-22 07:12:03 +03:00
|
|
|
rightIsAuto = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
leftIsAuto = PR_TRUE;
|
|
|
|
}
|
1999-01-16 23:58:17 +03:00
|
|
|
}
|
|
|
|
|
1999-01-22 07:12:03 +03:00
|
|
|
if (leftIsAuto) {
|
|
|
|
if (rightIsAuto) {
|
|
|
|
// If both are 'auto' (their initial values), the computed values are 0
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.left = mComputedOffsets.right = 0;
|
1999-01-22 07:12:03 +03:00
|
|
|
} else {
|
|
|
|
// 'Right' isn't 'auto' so compute its value
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStylePosition->mOffset.GetRightUnit(),
|
|
|
|
mStylePosition->mOffset.GetRight(coord),
|
|
|
|
mComputedOffsets.right);
|
1999-01-22 07:12:03 +03:00
|
|
|
|
|
|
|
// Computed value for 'left' is minus the value of 'right'
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.left = -mComputedOffsets.right;
|
1999-01-22 07:12:03 +03:00
|
|
|
}
|
|
|
|
|
1999-01-16 23:58:17 +03:00
|
|
|
} else {
|
1999-01-22 07:12:03 +03:00
|
|
|
NS_ASSERTION(rightIsAuto, "unexpected specified constraint");
|
|
|
|
|
|
|
|
// 'Left' isn't 'auto' so compute its value
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStylePosition->mOffset.GetLeftUnit(),
|
|
|
|
mStylePosition->mOffset.GetLeft(coord),
|
|
|
|
mComputedOffsets.left);
|
1999-01-22 07:12:03 +03:00
|
|
|
|
|
|
|
// Computed value for 'right' is minus the value of 'left'
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.right = -mComputedOffsets.left;
|
1999-01-16 23:58:17 +03:00
|
|
|
}
|
|
|
|
|
1999-01-22 07:12:03 +03: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 07:24:20 +03:00
|
|
|
PRBool topIsAuto = eStyleUnit_Auto == mStylePosition->mOffset.GetTopUnit();
|
|
|
|
PRBool bottomIsAuto = eStyleUnit_Auto == mStylePosition->mOffset.GetBottomUnit();
|
1999-01-22 07:12:03 +03:00
|
|
|
|
1999-01-23 07:49:15 +03:00
|
|
|
// Check for percentage based values and a containing block height that
|
|
|
|
// depends on the content height. Treat them like 'auto'
|
1999-04-22 08:27:47 +04:00
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
1999-03-05 07:24:20 +03:00
|
|
|
if (eStyleUnit_Percent == mStylePosition->mOffset.GetTopUnit()) {
|
1999-01-23 07:49:15 +03:00
|
|
|
topIsAuto = PR_TRUE;
|
|
|
|
}
|
1999-03-05 07:24:20 +03:00
|
|
|
if (eStyleUnit_Percent == mStylePosition->mOffset.GetBottomUnit()) {
|
1999-01-23 07:49:15 +03:00
|
|
|
bottomIsAuto = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-22 07:12:03 +03:00
|
|
|
// If neither is 'auto', 'bottom' is ignored
|
|
|
|
if (!topIsAuto && !bottomIsAuto) {
|
|
|
|
bottomIsAuto = PR_TRUE;
|
1999-01-16 23:58:17 +03:00
|
|
|
}
|
|
|
|
|
1999-01-22 07:12:03 +03:00
|
|
|
if (topIsAuto) {
|
|
|
|
if (bottomIsAuto) {
|
|
|
|
// If both are 'auto' (their initial values), the computed values are 0
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.top = mComputedOffsets.bottom = 0;
|
1999-01-22 07:12:03 +03:00
|
|
|
} else {
|
|
|
|
// 'Bottom' isn't 'auto' so compute its value
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight,
|
|
|
|
mStylePosition->mOffset.GetBottomUnit(),
|
|
|
|
mStylePosition->mOffset.GetBottom(coord),
|
|
|
|
mComputedOffsets.bottom);
|
1999-01-22 07:12:03 +03:00
|
|
|
|
|
|
|
// Computed value for 'top' is minus the value of 'bottom'
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.top = -mComputedOffsets.bottom;
|
1999-01-22 07:12:03 +03:00
|
|
|
}
|
|
|
|
|
1999-01-16 23:58:17 +03:00
|
|
|
} else {
|
1999-01-22 07:12:03 +03:00
|
|
|
NS_ASSERTION(bottomIsAuto, "unexpected specified constraint");
|
|
|
|
|
|
|
|
// 'Top' isn't 'auto' so compute its value
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight,
|
|
|
|
mStylePosition->mOffset.GetTopUnit(),
|
|
|
|
mStylePosition->mOffset.GetTop(coord),
|
|
|
|
mComputedOffsets.top);
|
1999-01-22 07:12:03 +03:00
|
|
|
|
|
|
|
// Computed value for 'bottom' is minus the value of 'top'
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.bottom = -mComputedOffsets.top;
|
1999-01-16 23:58:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-16 08:07:02 +04: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)
|
|
|
|
{
|
2003-06-29 07:43:05 +04:00
|
|
|
aFrame = aFrame->GetParent();
|
2000-04-16 08:07:02 +04:00
|
|
|
while (aFrame) {
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
|
|
|
PRBool isBlock =
|
|
|
|
(frameType == nsLayoutAtoms::blockFrame) ||
|
|
|
|
(frameType == nsLayoutAtoms::areaFrame);
|
2000-04-16 08:07:02 +04:00
|
|
|
|
|
|
|
if (isBlock) {
|
|
|
|
break;
|
|
|
|
}
|
2003-06-29 07:43:05 +04:00
|
|
|
aFrame = aFrame->GetParent();
|
2000-04-16 08:07:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFrame) {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsSize size = aFrame->GetSize();
|
|
|
|
|
2000-04-16 08:07:02 +04:00
|
|
|
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
|
2001-02-07 12:57:26 +03:00
|
|
|
nsStyleBorderPadding bPad;
|
|
|
|
nsMargin borderPadding;
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* styleContext = aFrame->GetStyleContext();
|
2001-06-01 02:19:43 +04:00
|
|
|
styleContext->GetBorderPaddingFor(bPad);
|
2001-02-07 12:57:26 +03:00
|
|
|
if (bPad.GetBorderPadding(borderPadding)) {
|
2000-04-16 08:07:02 +04:00
|
|
|
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
|
|
|
|
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...
|
2003-10-31 23:19:18 +03:00
|
|
|
if (aFrame->GetType() == nsLayoutAtoms::imageFrame) {
|
2000-04-16 08:07:02 +04:00
|
|
|
nsImageFrame* imageFrame = (nsImageFrame*)aFrame;
|
|
|
|
|
|
|
|
imageFrame->GetIntrinsicImageSize(aIntrinsicSize);
|
|
|
|
result = (aIntrinsicSize != nsSize(0, 0));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsHTMLReflowState::CalculateHorizBorderPaddingMargin(nscoord aContainingBlockWidth)
|
|
|
|
{
|
|
|
|
nsMargin border, padding, margin;
|
|
|
|
|
|
|
|
// Get the border
|
2001-02-07 12:57:26 +03:00
|
|
|
if (!mStyleBorder->GetBorder(border)) {
|
2000-04-16 08:07:02 +04:00
|
|
|
// CSS2 has no percentage borders
|
|
|
|
border.SizeTo(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the style system can provide us the padding directly
|
2001-02-07 12:57:26 +03:00
|
|
|
if (!mStylePadding->GetPadding(padding)) {
|
2000-04-16 08:07:02 +04:00
|
|
|
nsStyleCoord left, right;
|
|
|
|
|
|
|
|
// We have to compute the left and right values
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStylePadding->mPadding.GetLeftUnit(),
|
|
|
|
mStylePadding->mPadding.GetLeft(left),
|
|
|
|
padding.left);
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStylePadding->mPadding.GetRightUnit(),
|
|
|
|
mStylePadding->mPadding.GetRight(right),
|
|
|
|
padding.right);
|
2000-04-16 08:07:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if the style system can provide us the margin directly
|
2001-02-07 12:57:26 +03:00
|
|
|
if (!mStyleMargin->GetMargin(margin)) {
|
2000-04-16 08:07:02 +04:00
|
|
|
nsStyleCoord left, right;
|
|
|
|
|
|
|
|
// We have to compute the left and right values
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == mStyleMargin->mMargin.GetLeftUnit()) {
|
2000-04-16 08:07:02 +04:00
|
|
|
margin.left = 0; // just ignore
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
2001-02-07 12:57:26 +03:00
|
|
|
mStyleMargin->mMargin.GetLeftUnit(),
|
|
|
|
mStyleMargin->mMargin.GetLeft(left),
|
2000-04-16 08:07:02 +04:00
|
|
|
margin.left);
|
|
|
|
}
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == mStyleMargin->mMargin.GetRightUnit()) {
|
2000-04-16 08:07:02 +04:00
|
|
|
margin.right = 0; // just ignore
|
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
2001-02-07 12:57:26 +03:00
|
|
|
mStyleMargin->mMargin.GetRightUnit(),
|
|
|
|
mStyleMargin->mMargin.GetRight(right),
|
2000-04-16 08:07:02 +04:00
|
|
|
margin.right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return padding.left + padding.right + border.left + border.right +
|
|
|
|
margin.left + margin.right;
|
|
|
|
}
|
|
|
|
|
2000-04-20 08:44:32 +04:00
|
|
|
static void
|
|
|
|
GetPlaceholderOffset(nsIFrame* aPlaceholderFrame,
|
|
|
|
nsIFrame* aBlockFrame,
|
|
|
|
nsPoint& aOffset)
|
|
|
|
{
|
2003-06-29 07:43:05 +04:00
|
|
|
aOffset = aPlaceholderFrame->GetPosition();
|
2000-04-20 08:44:32 +04:00
|
|
|
|
|
|
|
// Convert the placeholder position to the coordinate space of the block
|
|
|
|
// frame that contains it
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIFrame* parent = aPlaceholderFrame->GetParent();
|
2000-04-20 08:44:32 +04:00
|
|
|
while (parent && (parent != aBlockFrame)) {
|
2003-06-29 07:43:05 +04:00
|
|
|
aOffset += parent->GetPosition();
|
|
|
|
parent = parent->GetParent();
|
2000-04-20 08:44:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIFrame*
|
|
|
|
FindImmediateChildOf(nsIFrame* aParent, nsIFrame* aDescendantFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* result = aDescendantFrame;
|
|
|
|
|
|
|
|
while (result) {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIFrame* parent = result->GetParent();
|
2000-04-20 08:44:32 +04:00
|
|
|
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 08:07:02 +04: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 09:37:31 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::CalculateHypotheticalBox(nsPresContext* aPresContext,
|
2000-04-16 08:07:02 +04:00
|
|
|
nsIFrame* aPlaceholderFrame,
|
|
|
|
nsIFrame* aBlockFrame,
|
|
|
|
nsMargin& aBlockContentArea,
|
2004-04-24 21:56:23 +04:00
|
|
|
const nsHTMLReflowState* cbrs,
|
2000-04-16 08:07:02 +04:00
|
|
|
nsHypotheticalBox& aHypotheticalBox)
|
1999-01-13 09:37:31 +03:00
|
|
|
{
|
2002-08-16 03:00:23 +04:00
|
|
|
NS_ASSERTION(mStyleDisplay->mOriginalDisplay != NS_STYLE_DISPLAY_NONE,
|
|
|
|
"mOriginalDisplay has not been properly initialized");
|
|
|
|
|
2000-04-16 08:07:02 +04: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;
|
2002-08-16 03:00:23 +04:00
|
|
|
if ((NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) &&
|
2000-04-16 08:07:02 +04:00
|
|
|
!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;
|
|
|
|
}
|
|
|
|
|
2003-11-24 22:46:25 +03:00
|
|
|
} else if (eStyleUnit_Auto == widthUnit) {
|
2000-04-16 08:07:02 +04:00
|
|
|
// The box width is the containing block width
|
|
|
|
boxWidth = aBlockContentArea.right - aBlockContentArea.left;
|
|
|
|
knowBoxWidth = PR_TRUE;
|
1999-01-13 09:37:31 +03:00
|
|
|
|
2000-04-16 08:07:02 +04: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
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleVisibility* blockVis = aBlockFrame->GetStyleVisibility();
|
2000-04-16 08:07:02 +04:00
|
|
|
|
2003-01-29 14:35:10 +03:00
|
|
|
// Get the placeholder x-offset and y-offset in the coordinate
|
|
|
|
// space of the block frame that contains it
|
2004-04-24 21:56:23 +04:00
|
|
|
// XXXbz the placeholder is not fully reflown yet if our containing block is
|
|
|
|
// relatively positioned...
|
2003-01-29 14:35:10 +03:00
|
|
|
nsPoint placeholderOffset;
|
|
|
|
GetPlaceholderOffset(aPlaceholderFrame, aBlockFrame, placeholderOffset);
|
|
|
|
|
|
|
|
// First, determine the hypothetical box's mTop
|
|
|
|
if (aBlockFrame) {
|
|
|
|
// We need the immediate child of the block frame, and that may not be
|
|
|
|
// the placeholder frame
|
|
|
|
nsBlockFrame* blockFrame = NS_STATIC_CAST(nsBlockFrame*, aBlockFrame);
|
|
|
|
nsIFrame *blockChild = FindImmediateChildOf(aBlockFrame, aPlaceholderFrame);
|
|
|
|
nsBlockFrame::line_iterator lineBox = blockFrame->FindLineFor(blockChild);
|
|
|
|
|
|
|
|
// 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->mOriginalDisplay) {
|
|
|
|
// Use the top of the inline box which the placeholder lives in as the
|
|
|
|
// hypothetical box's top.
|
|
|
|
aHypotheticalBox.mTop = lineBox->mBounds.y;
|
2000-04-16 08:07:02 +04:00
|
|
|
} else {
|
2003-01-29 14:35:10 +03:00
|
|
|
// The element would have been block-level which means it would be below
|
2003-10-18 12:04:37 +04:00
|
|
|
// the line containing the placeholder frame, unless all the frames
|
|
|
|
// before it are empty. In that case, it would have been just before
|
|
|
|
// this line.
|
2004-04-24 21:56:23 +04:00
|
|
|
// XXXbz the line box is not fully reflown yet if our containing block is
|
|
|
|
// relatively positioned...
|
2002-04-26 23:19:39 +04:00
|
|
|
if (lineBox != blockFrame->end_lines()) {
|
2003-10-18 12:04:37 +04:00
|
|
|
nsIFrame * firstFrame = lineBox->mFirstChild;
|
|
|
|
while (firstFrame != aPlaceholderFrame) {
|
|
|
|
NS_ASSERTION(firstFrame, "Must reach our placeholder before end of list!");
|
2003-10-22 11:01:35 +04:00
|
|
|
if (!firstFrame) // This can be removed when we split out-of-flow
|
|
|
|
break; // frames correctly, see bug 223064
|
2003-11-11 02:36:06 +03:00
|
|
|
if (!firstFrame->IsEmpty()) {
|
2003-10-18 12:04:37 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
firstFrame = firstFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
if (firstFrame == aPlaceholderFrame) {
|
|
|
|
// The top of the hypothetical box is the top of the line containing
|
|
|
|
// the placeholder, since there is nothing in the line before our
|
|
|
|
// placeholder except empty frames.
|
|
|
|
aHypotheticalBox.mTop = lineBox->mBounds.y;
|
|
|
|
} else {
|
|
|
|
// The top of the hypothetical box is just below the line containing
|
|
|
|
// the placeholder.
|
|
|
|
aHypotheticalBox.mTop = lineBox->mBounds.YMost();
|
|
|
|
}
|
2000-04-20 08:44:32 +04:00
|
|
|
} else {
|
|
|
|
// Just use the placeholder's y-offset
|
|
|
|
aHypotheticalBox.mTop = placeholderOffset.y;
|
2000-04-16 08:07:02 +04:00
|
|
|
}
|
|
|
|
}
|
2003-01-29 14:35:10 +03:00
|
|
|
}
|
1999-02-08 03:32:02 +03:00
|
|
|
|
2003-01-29 14:35:10 +03:00
|
|
|
// Second, determine the hypothetical box's mLeft & mRight
|
|
|
|
// To determine the left and right offsets we need to look at the block's 'direction'
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == blockVis->mDirection) {
|
|
|
|
// 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->mOriginalDisplay) {
|
|
|
|
// The placeholder represents the left edge of the hypothetical box
|
|
|
|
aHypotheticalBox.mLeft = placeholderOffset.x;
|
|
|
|
} else {
|
2000-04-16 08:07:02 +04:00
|
|
|
aHypotheticalBox.mLeft = aBlockContentArea.left;
|
2003-01-29 14:35:10 +03:00
|
|
|
}
|
|
|
|
aHypotheticalBox.mLeftIsExact = PR_TRUE;
|
2000-04-16 08:07:02 +04:00
|
|
|
|
2003-01-29 14:35:10 +03:00
|
|
|
if (knowBoxWidth) {
|
|
|
|
aHypotheticalBox.mRight = aHypotheticalBox.mLeft + boxWidth;
|
|
|
|
aHypotheticalBox.mRightIsExact = PR_TRUE;
|
2000-04-16 08:07:02 +04:00
|
|
|
} else {
|
2003-01-29 14:35:10 +03:00
|
|
|
// 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
|
2000-04-16 08:07:02 +04:00
|
|
|
aHypotheticalBox.mRight = aBlockContentArea.right;
|
2003-01-29 14:35:10 +03:00
|
|
|
aHypotheticalBox.mRightIsExact = PR_FALSE;
|
|
|
|
}
|
2000-04-16 08:07:02 +04:00
|
|
|
|
2003-01-29 14:35:10 +03:00
|
|
|
} else {
|
|
|
|
// The placeholder represents the right edge of the hypothetical box
|
|
|
|
if (NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) {
|
|
|
|
aHypotheticalBox.mRight = placeholderOffset.x;
|
|
|
|
} else {
|
|
|
|
aHypotheticalBox.mRight = aBlockContentArea.right;
|
|
|
|
}
|
|
|
|
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 09:37:31 +03:00
|
|
|
}
|
2003-01-29 14:35:10 +03:00
|
|
|
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
|
|
|
|
2000-04-16 08:07:02 +04:00
|
|
|
// The current coordinate space is that of the nearest block to the placeholder.
|
|
|
|
// Convert to the coordinate space of the absolute containing block
|
2004-04-24 21:56:23 +04:00
|
|
|
nsIFrame* absoluteContainingBlock = cbrs->frame;
|
|
|
|
if (aBlockFrame != absoluteContainingBlock) {
|
|
|
|
nsIFrame* parent;
|
|
|
|
nsIFrame* stop;
|
|
|
|
if (NS_FRAME_GET_TYPE(cbrs->mFrameType) == NS_CSS_FRAME_TYPE_INLINE) {
|
|
|
|
// The absolute containing block is an inline frame... so it will be a
|
|
|
|
// descendant of aBlockFrame
|
|
|
|
parent = absoluteContainingBlock;
|
|
|
|
stop = aBlockFrame;
|
|
|
|
} else {
|
|
|
|
// aBlockFrame may be a descendant of absoluteContainingBlock
|
|
|
|
parent = aBlockFrame;
|
|
|
|
stop = absoluteContainingBlock;
|
|
|
|
}
|
2000-04-16 08:07:02 +04:00
|
|
|
do {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsPoint origin = parent->GetPosition();
|
2000-04-16 08:07:02 +04:00
|
|
|
|
|
|
|
aHypotheticalBox.mLeft += origin.x;
|
|
|
|
aHypotheticalBox.mRight += origin.x;
|
|
|
|
aHypotheticalBox.mTop += origin.y;
|
|
|
|
|
|
|
|
// Move up the tree one level
|
2003-06-29 07:43:05 +04:00
|
|
|
parent = parent->GetParent();
|
2004-04-24 21:56:23 +04:00
|
|
|
} while (parent && parent != stop);
|
2000-04-16 08:07:02 +04:00
|
|
|
}
|
|
|
|
|
2004-04-24 21:56:23 +04:00
|
|
|
// The specified offsets are relative to the absolute containing block's
|
|
|
|
// padding edge or content edge, and our current values are relative to the
|
|
|
|
// border edge, so translate.
|
|
|
|
if (NS_FRAME_GET_TYPE(cbrs->mFrameType) == NS_CSS_FRAME_TYPE_INLINE) {
|
|
|
|
// content edge
|
|
|
|
const nsMargin& borderPadding = cbrs->mComputedBorderPadding;
|
|
|
|
aHypotheticalBox.mLeft -= borderPadding.left;
|
|
|
|
aHypotheticalBox.mRight -= borderPadding.right;
|
|
|
|
aHypotheticalBox.mTop -= borderPadding.top;
|
|
|
|
} else {
|
|
|
|
// padding edge
|
|
|
|
nsMargin border = cbrs->mComputedBorderPadding - cbrs->mComputedPadding;
|
|
|
|
aHypotheticalBox.mLeft -= border.left;
|
|
|
|
aHypotheticalBox.mRight -= border.right;
|
|
|
|
aHypotheticalBox.mTop -= border.top;
|
2000-04-16 08:07:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::InitAbsoluteConstraints(nsPresContext* aPresContext,
|
2000-04-16 08:07:02 +04:00
|
|
|
const nsHTMLReflowState* cbrs,
|
|
|
|
nscoord containingBlockWidth,
|
|
|
|
nscoord containingBlockHeight)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(containingBlockHeight != NS_AUTOHEIGHT,
|
|
|
|
"containing block height must be constrained");
|
|
|
|
|
|
|
|
// Get the placeholder frame
|
|
|
|
nsIFrame* placeholderFrame;
|
|
|
|
|
2003-12-21 08:36:36 +03:00
|
|
|
aPresContext->PresShell()->GetPlaceholderFrameFor(frame, &placeholderFrame);
|
2000-04-16 08:07:02 +04:00
|
|
|
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,
|
2004-04-24 21:56:23 +04:00
|
|
|
blockContentArea, cbrs, hypotheticalBox);
|
2000-04-16 08:07:02 +04:00
|
|
|
}
|
1999-01-13 09:37:31 +03:00
|
|
|
|
|
|
|
// Initialize the 'left' and 'right' computed offsets
|
2000-04-16 08:07:02 +04:00
|
|
|
// XXX Handle new 'static-position' value...
|
1999-01-13 09:37:31 +03:00
|
|
|
PRBool leftIsAuto = PR_FALSE, rightIsAuto = PR_FALSE;
|
|
|
|
nsStyleCoord coord;
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == mStylePosition->mOffset.GetLeftUnit()) {
|
2000-04-16 08:07:02 +04:00
|
|
|
mComputedOffsets.left = 0;
|
|
|
|
leftIsAuto = PR_TRUE;
|
1999-01-13 09:37:31 +03:00
|
|
|
} else {
|
1999-03-05 07:24:20 +03:00
|
|
|
ComputeHorizontalValue(containingBlockWidth, mStylePosition->mOffset.GetLeftUnit(),
|
|
|
|
mStylePosition->mOffset.GetLeft(coord),
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.left);
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == mStylePosition->mOffset.GetRightUnit()) {
|
2000-04-16 08:07:02 +04:00
|
|
|
mComputedOffsets.right = 0;
|
|
|
|
rightIsAuto = PR_TRUE;
|
1999-01-13 09:37:31 +03:00
|
|
|
} else {
|
1999-03-05 07:24:20 +03:00
|
|
|
ComputeHorizontalValue(containingBlockWidth, mStylePosition->mOffset.GetRightUnit(),
|
|
|
|
mStylePosition->mOffset.GetRight(coord),
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.right);
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
|
|
|
|
2004-07-15 10:10:53 +04:00
|
|
|
PRUint8 direction = mStyleVisibility->mDirection;
|
1999-07-20 06:48:18 +04:00
|
|
|
|
2000-04-16 08:07:02 +04:00
|
|
|
// Initialize the 'width' computed value
|
|
|
|
nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();
|
|
|
|
PRBool widthIsAuto = (eStyleUnit_Auto == widthUnit);
|
|
|
|
if (!widthIsAuto) {
|
2003-11-24 22:46:25 +03:00
|
|
|
// Use the specified value for the computed width
|
|
|
|
ComputeHorizontalValue(containingBlockWidth, widthUnit,
|
|
|
|
mStylePosition->mWidth, mComputedWidth);
|
2001-03-06 08:56:19 +03:00
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedWidth(PR_TRUE);
|
1999-07-20 06:48:18 +04:00
|
|
|
}
|
1999-01-13 09:37:31 +03:00
|
|
|
|
2000-04-16 08:07:02 +04: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 06:48:18 +04:00
|
|
|
}
|
2000-04-16 08:07:02 +04:00
|
|
|
|
1999-01-13 09:37:31 +03:00
|
|
|
} else {
|
2000-04-16 08:07:02 +04:00
|
|
|
// Calculate any 'auto' margin values
|
2001-02-07 12:57:26 +03:00
|
|
|
PRBool marginLeftIsAuto = (eStyleUnit_Auto == mStyleMargin->mMargin.GetLeftUnit());
|
|
|
|
PRBool marginRightIsAuto = (eStyleUnit_Auto == mStyleMargin->mMargin.GetRightUnit());
|
2000-04-29 04:24:53 +04:00
|
|
|
PRInt32 availMarginSpace = availContentSpace - mComputedWidth;
|
2000-04-16 08:07:02 +04:00
|
|
|
|
1999-07-20 06:48:18 +04:00
|
|
|
if (marginLeftIsAuto) {
|
|
|
|
if (marginRightIsAuto) {
|
|
|
|
// Both 'margin-left' and 'margin-right' are 'auto', so they get
|
|
|
|
// equal values
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedMargin.left = availMarginSpace / 2;
|
|
|
|
mComputedMargin.right = availMarginSpace - mComputedMargin.left;
|
1999-07-20 06:48:18 +04:00
|
|
|
} else {
|
|
|
|
// Just 'margin-left' is 'auto'
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedMargin.left = availMarginSpace - mComputedMargin.right;
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
1999-07-20 06:48:18 +04:00
|
|
|
} else {
|
|
|
|
// Just 'margin-right' is 'auto'
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedMargin.right = availMarginSpace - mComputedMargin.left;
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
|
|
|
}
|
2000-04-16 08:07:02 +04: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;
|
|
|
|
|
2002-09-25 01:02:20 +04:00
|
|
|
PRInt32 maxWidth = containingBlockWidth;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != maxWidth) {
|
|
|
|
maxWidth -= mComputedOffsets.left + mComputedMargin.left + mComputedBorderPadding.left +
|
|
|
|
mComputedBorderPadding.right + mComputedMargin.right + mComputedOffsets.right;
|
|
|
|
}
|
2000-04-16 08:07:02 +04:00
|
|
|
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;
|
|
|
|
|
2004-04-24 21:56:23 +04:00
|
|
|
mComputedWidth = PR_MAX(mComputedWidth, 0);
|
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedWidth(PR_FALSE);
|
2000-04-16 08:07:02 +04:00
|
|
|
|
|
|
|
// 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 09:37:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the 'top' and 'bottom' computed offsets
|
2000-04-16 08:07:02 +04:00
|
|
|
nsStyleUnit heightUnit = mStylePosition->mHeight.GetUnit();
|
|
|
|
PRBool topIsAuto = PR_FALSE, bottomIsAuto = PR_FALSE;
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == mStylePosition->mOffset.GetTopUnit()) {
|
2000-04-16 08:07:02 +04:00
|
|
|
mComputedOffsets.top = 0;
|
|
|
|
topIsAuto = PR_TRUE;
|
1999-01-13 09:37:31 +03:00
|
|
|
} else {
|
1999-05-11 02:28:30 +04:00
|
|
|
nsStyleCoord c;
|
|
|
|
ComputeVerticalValue(containingBlockHeight,
|
|
|
|
mStylePosition->mOffset.GetTopUnit(),
|
|
|
|
mStylePosition->mOffset.GetTop(c),
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.top);
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == mStylePosition->mOffset.GetBottomUnit()) {
|
2000-04-16 08:07:02 +04:00
|
|
|
mComputedOffsets.bottom = 0;
|
|
|
|
bottomIsAuto = PR_TRUE;
|
1999-01-13 09:37:31 +03:00
|
|
|
} else {
|
1999-05-11 02:28:30 +04:00
|
|
|
nsStyleCoord c;
|
|
|
|
ComputeVerticalValue(containingBlockHeight,
|
|
|
|
mStylePosition->mOffset.GetBottomUnit(),
|
|
|
|
mStylePosition->mOffset.GetBottom(c),
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.bottom);
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
|
|
|
|
2000-04-16 08:07:02 +04:00
|
|
|
// Initialize the 'height' computed value
|
|
|
|
PRBool heightIsAuto = (eStyleUnit_Auto == heightUnit);
|
|
|
|
if (!heightIsAuto) {
|
2003-11-24 22:46:25 +03:00
|
|
|
// Use the specified value for the computed height
|
|
|
|
ComputeVerticalValue(containingBlockHeight, heightUnit,
|
|
|
|
mStylePosition->mHeight, mComputedHeight);
|
2001-03-06 08:56:19 +03:00
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedHeight(PR_TRUE);
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
|
|
|
|
2000-04-16 08:07:02 +04: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 09:37:31 +03:00
|
|
|
} else {
|
2000-04-16 08:07:02 +04:00
|
|
|
// Calculate any 'auto' margin values
|
2001-02-07 12:57:26 +03:00
|
|
|
PRBool marginTopIsAuto = (eStyleUnit_Auto == mStyleMargin->mMargin.GetTopUnit());
|
|
|
|
PRBool marginBottomIsAuto = (eStyleUnit_Auto == mStyleMargin->mMargin.GetBottomUnit());
|
2000-04-29 04:24:53 +04:00
|
|
|
PRInt32 availMarginSpace = availContentSpace - mComputedHeight;
|
2000-04-16 08:07:02 +04: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 09:37:31 +03:00
|
|
|
|
|
|
|
} else {
|
2000-04-16 08:07:02 +04:00
|
|
|
// Only 'height' is 'auto' so just solve for 'height'
|
|
|
|
mComputedHeight = containingBlockHeight - mComputedOffsets.top -
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedMargin.top - mComputedBorderPadding.top -
|
1999-03-05 07:24:20 +03:00
|
|
|
mComputedBorderPadding.bottom -
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedMargin.bottom - mComputedOffsets.bottom;
|
2000-04-16 08:07:02 +04:00
|
|
|
|
2004-04-24 21:56:23 +04:00
|
|
|
mComputedHeight = PR_MAX(mComputedHeight, 0);
|
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedHeight(PR_FALSE);
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
2000-04-16 08:07:02 +04:00
|
|
|
|
1999-02-18 07:40:16 +03:00
|
|
|
} else {
|
2000-04-16 08:07:02 +04: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 09:37:31 +03:00
|
|
|
|
2000-04-16 08:07:02 +04:00
|
|
|
if (topIsAuto) {
|
|
|
|
// Solve for 'top'
|
|
|
|
mComputedOffsets.top = containingBlockHeight - mComputedMargin.top -
|
|
|
|
mComputedBorderPadding.top - mComputedHeight - mComputedBorderPadding.bottom -
|
|
|
|
mComputedMargin.bottom - mComputedOffsets.bottom;
|
1999-07-28 07:51:37 +04:00
|
|
|
|
2000-04-16 08:07:02 +04:00
|
|
|
} else if (bottomIsAuto) {
|
|
|
|
// Solve for 'bottom'
|
|
|
|
mComputedOffsets.bottom = containingBlockHeight - mComputedOffsets.top -
|
|
|
|
mComputedMargin.top - mComputedBorderPadding.top - mComputedHeight -
|
|
|
|
mComputedBorderPadding.bottom - mComputedMargin.bottom;
|
1999-07-28 07:51:37 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-20 06:48:18 +04:00
|
|
|
}
|
2004-04-24 21:56:23 +04:00
|
|
|
|
|
|
|
// Now that we've solved for our auto offsets and so forth, we need to adjust
|
|
|
|
// the offsets to what the rest of layout actually expects them to be. The
|
|
|
|
// offsets as computed now are relative to the parent's padding edge if the
|
|
|
|
// parent is a block and the parent's content edge if the parent is an
|
|
|
|
// inline. We need them to be relative to the parent's padding edge for
|
|
|
|
// nsAbsoluteContainer reflow to work right.
|
|
|
|
if (NS_FRAME_GET_TYPE(cbrs->mFrameType) == NS_CSS_FRAME_TYPE_INLINE) {
|
|
|
|
mComputedOffsets += cbrs->mComputedPadding;
|
|
|
|
}
|
2000-04-16 08:07:02 +04:00
|
|
|
}
|
1999-03-11 18:13:17 +03:00
|
|
|
|
2000-04-16 08:07:02 +04:00
|
|
|
static PRBool
|
|
|
|
IsInitialContainingBlock(nsIFrame* aFrame)
|
|
|
|
{
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2000-04-16 08:07:02 +04:00
|
|
|
|
2003-07-29 01:25:13 +04:00
|
|
|
if (content && !content->GetParent()) {
|
|
|
|
// The containing block corresponds to the document element so it's
|
|
|
|
// the initial containing block
|
|
|
|
return PR_TRUE;
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
2003-06-29 07:43:05 +04:00
|
|
|
return PR_FALSE;
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
|
|
|
|
2000-04-29 01:05:31 +04: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
|
2001-09-09 00:09:08 +04:00
|
|
|
* This will walk up the chain of containing blocks looking for a computed height
|
2003-10-06 17:13:37 +04:00
|
|
|
* until it finds the canvas frame, or it encounters a frame that is not a block,
|
|
|
|
* area, or scroll frame. This handles compatibility with IE (see bug 85016 and bug 219693)
|
2001-09-11 04:12:28 +04:00
|
|
|
*
|
2003-10-06 17:13:37 +04:00
|
|
|
* When we encounter scrolledContent area frames, we skip over them, since they are guaranteed to not be useful for computing the containing block.
|
2000-04-29 01:05:31 +04:00
|
|
|
*/
|
|
|
|
nscoord
|
2003-10-19 00:22:22 +04:00
|
|
|
CalcQuirkContainingBlockHeight(const nsHTMLReflowState& aReflowState)
|
2000-04-29 01:05:31 +04:00
|
|
|
{
|
2003-10-06 17:13:37 +04:00
|
|
|
nsHTMLReflowState* firstAncestorRS = nsnull; // a candidate for html frame
|
|
|
|
nsHTMLReflowState* secondAncestorRS = nsnull; // a candidate for body frame
|
2003-01-28 08:19:20 +03:00
|
|
|
|
|
|
|
// initialize the default to NS_AUTOHEIGHT as this is the containings block
|
|
|
|
// computed height when this function is called. It is possible that we
|
|
|
|
// don't alter this height especially if we are restricted to one level
|
|
|
|
nscoord result = NS_AUTOHEIGHT;
|
|
|
|
|
2000-04-29 01:05:31 +04:00
|
|
|
const nsHTMLReflowState* rs = &aReflowState;
|
2002-04-11 01:32:41 +04:00
|
|
|
for (; rs && rs->frame; rs = (nsHTMLReflowState *)(rs->parentReflowState)) {
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* frameType = rs->frame->GetType();
|
2000-04-29 01:05:31 +04:00
|
|
|
// 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
|
2003-10-06 17:13:37 +04:00
|
|
|
if (nsLayoutAtoms::blockFrame == frameType ||
|
|
|
|
nsLayoutAtoms::areaFrame == frameType ||
|
|
|
|
nsLayoutAtoms::scrollFrame == frameType) {
|
2003-10-18 04:24:28 +04:00
|
|
|
|
2003-10-06 17:13:37 +04:00
|
|
|
if (nsLayoutAtoms::areaFrame == frameType) {
|
2003-10-18 04:24:28 +04:00
|
|
|
// Skip over scrolled-content area frames
|
2003-10-17 06:38:37 +04:00
|
|
|
if (rs->frame->GetStyleContext()->GetPseudoType() ==
|
|
|
|
nsCSSAnonBoxes::scrolledContent) {
|
2003-10-06 17:13:37 +04:00
|
|
|
continue;
|
|
|
|
}
|
2000-04-29 01:05:31 +04:00
|
|
|
}
|
2003-10-18 04:24:28 +04:00
|
|
|
|
2003-10-06 17:13:37 +04:00
|
|
|
secondAncestorRS = firstAncestorRS;
|
|
|
|
firstAncestorRS = (nsHTMLReflowState*)rs;
|
2003-10-18 04:24:28 +04:00
|
|
|
|
|
|
|
// If the current frame we're looking at is positioned, we don't want to
|
|
|
|
// go any further (see bug 221784). The behavior we want here is: 1) If
|
|
|
|
// not auto-height, use this as the percentage base. 2) If auto-height,
|
|
|
|
// keep looking, unless the frame is positioned.
|
2001-09-09 00:09:08 +04:00
|
|
|
if (NS_AUTOHEIGHT == rs->mComputedHeight) {
|
2003-10-18 04:24:28 +04:00
|
|
|
if (rs->frame->GetStyleDisplay()->IsAbsolutelyPositioned()) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2000-04-29 01:05:31 +04:00
|
|
|
}
|
|
|
|
}
|
2003-10-06 17:13:37 +04:00
|
|
|
else if (nsLayoutAtoms::canvasFrame == frameType) {
|
2000-05-17 02:02:16 +04:00
|
|
|
// Use scroll frames' computed height if we have one, this will
|
|
|
|
// allow us to get viewport height for native scrollbars.
|
|
|
|
nsHTMLReflowState* scrollState = (nsHTMLReflowState *)rs->parentReflowState;
|
2003-10-31 23:19:18 +03:00
|
|
|
if (nsLayoutAtoms::scrollFrame == scrollState->frame->GetType()) {
|
2000-05-17 02:02:16 +04:00
|
|
|
rs = scrollState;
|
|
|
|
}
|
2000-11-30 01:31:57 +03:00
|
|
|
}
|
2003-10-06 17:13:37 +04:00
|
|
|
else if (nsLayoutAtoms::pageContentFrame == frameType) {
|
2002-04-11 01:32:41 +04:00
|
|
|
nsIFrame* prevInFlow;
|
|
|
|
rs->frame->GetPrevInFlow(&prevInFlow);
|
|
|
|
// only use the page content frame for a height basis if it is the first in flow
|
|
|
|
if (prevInFlow)
|
|
|
|
break;
|
|
|
|
}
|
2000-05-17 02:02:16 +04:00
|
|
|
else {
|
2000-04-29 01:05:31 +04:00
|
|
|
break;
|
|
|
|
}
|
2000-05-17 02:02:16 +04:00
|
|
|
|
2002-04-11 01:32:41 +04:00
|
|
|
// if the ancestor is the page content frame then the percent base is
|
|
|
|
// the avail height, otherwise it is the computed height
|
2003-10-06 17:13:37 +04:00
|
|
|
result = (nsLayoutAtoms::pageContentFrame == frameType)
|
2002-04-11 01:32:41 +04:00
|
|
|
? rs->availableHeight : rs->mComputedHeight;
|
2000-05-17 02:02:16 +04:00
|
|
|
// if unconstrained - don't sutract borders - would result in huge height
|
|
|
|
if (NS_AUTOHEIGHT == result) return result;
|
|
|
|
|
2002-04-11 01:32:41 +04:00
|
|
|
// if we got to the canvas or page content frame, then subtract out
|
2000-04-29 01:05:31 +04:00
|
|
|
// margin/border/padding for the BODY and HTML elements
|
2003-10-06 17:13:37 +04:00
|
|
|
if ((nsLayoutAtoms::canvasFrame == frameType) ||
|
|
|
|
(nsLayoutAtoms::pageContentFrame == frameType)) {
|
2001-09-09 00:09:08 +04:00
|
|
|
|
2003-10-06 17:13:37 +04:00
|
|
|
result -= GetVerticalMarginBorderPadding(firstAncestorRS);
|
|
|
|
result -= GetVerticalMarginBorderPadding(secondAncestorRS);
|
2001-09-09 00:09:08 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2003-10-06 17:13:37 +04:00
|
|
|
// make sure the first ancestor is the HTML and the second is the BODY
|
|
|
|
if (firstAncestorRS) {
|
|
|
|
nsIContent* frameContent = firstAncestorRS->frame->GetContent();
|
2001-09-09 00:09:08 +04:00
|
|
|
if (frameContent) {
|
2003-11-19 04:20:56 +03:00
|
|
|
nsIAtom *contentTag = frameContent->Tag();
|
2003-10-06 17:13:37 +04:00
|
|
|
NS_ASSERTION(contentTag == nsHTMLAtoms::html, "First ancestor is not HTML");
|
2001-09-09 00:09:08 +04:00
|
|
|
}
|
|
|
|
}
|
2003-10-06 17:13:37 +04:00
|
|
|
if (secondAncestorRS) {
|
|
|
|
nsIContent* frameContent = secondAncestorRS->frame->GetContent();
|
2001-09-09 00:09:08 +04:00
|
|
|
if (frameContent) {
|
2003-11-19 04:20:56 +03:00
|
|
|
nsIAtom *contentTag = frameContent->Tag();
|
2003-10-06 17:13:37 +04:00
|
|
|
NS_ASSERTION(contentTag == nsHTMLAtoms::body, "Second ancestor is not BODY");
|
2001-09-09 00:09:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-04-29 01:05:31 +04:00
|
|
|
}
|
|
|
|
// if we got to the html frame, then subtract out
|
|
|
|
// margin/border/padding for the BODY element
|
2003-10-06 17:13:37 +04:00
|
|
|
else if (nsLayoutAtoms::areaFrame == frameType) {
|
2000-04-29 01:05:31 +04:00
|
|
|
// make sure it is the body
|
2003-10-31 23:19:18 +03:00
|
|
|
if (nsLayoutAtoms::canvasFrame == rs->parentReflowState->frame->GetType()) {
|
2003-10-06 17:13:37 +04:00
|
|
|
result -= GetVerticalMarginBorderPadding(secondAncestorRS);
|
2000-04-29 01:05:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1999-04-22 08:27:47 +04:00
|
|
|
// Called by InitConstraints() to compute the containing block rectangle for
|
|
|
|
// the element. Handles the special logic for absolutely positioned elements
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::ComputeContainingBlockRectangle(nsPresContext* aPresContext,
|
2000-04-29 01:05:31 +04:00
|
|
|
const nsHTMLReflowState* aContainingBlockRS,
|
|
|
|
nscoord& aContainingBlockWidth,
|
|
|
|
nscoord& aContainingBlockHeight)
|
1999-04-22 08:27:47 +04: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 07:41:03 +04:00
|
|
|
aContainingBlockWidth = aContainingBlockRS->mComputedWidth;
|
|
|
|
aContainingBlockHeight = aContainingBlockRS->mComputedHeight;
|
1999-04-22 08:27:47 +04:00
|
|
|
|
1999-07-20 07:41:03 +04:00
|
|
|
if (NS_FRAME_GET_TYPE(mFrameType) == NS_CSS_FRAME_TYPE_ABSOLUTE) {
|
1999-04-22 08:27:47 +04:00
|
|
|
// See if the ancestor is block-level or inline-level
|
1999-07-20 07:41:03 +04:00
|
|
|
if (NS_FRAME_GET_TYPE(aContainingBlockRS->mFrameType) == NS_CSS_FRAME_TYPE_INLINE) {
|
2004-04-24 21:56:23 +04:00
|
|
|
// Base our size on the actual size of the frame. In cases when this is
|
|
|
|
// completely bogus (eg initial reflow), this code shouldn't even be
|
|
|
|
// called, since the code in nsPositionedInlineFrame::Reflow will pass in
|
|
|
|
// the containing block dimensions to our constructor.
|
|
|
|
// XXXbz we should be taking the in-flows into account too, but
|
|
|
|
// that's very hard.
|
|
|
|
aContainingBlockWidth = aContainingBlockRS->frame->GetRect().width -
|
|
|
|
(aContainingBlockRS->mComputedBorderPadding.left +
|
|
|
|
aContainingBlockRS->mComputedBorderPadding.right);
|
|
|
|
NS_ASSERTION(aContainingBlockWidth >= 0,
|
|
|
|
"Negative containing block width!");
|
|
|
|
aContainingBlockHeight = aContainingBlockRS->frame->GetRect().height -
|
|
|
|
(aContainingBlockRS->mComputedBorderPadding.top +
|
|
|
|
aContainingBlockRS->mComputedBorderPadding.bottom);
|
|
|
|
NS_ASSERTION(aContainingBlockHeight >= 0,
|
|
|
|
"Negative containing block height!");
|
1999-04-22 08:27:47 +04:00
|
|
|
} 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 08:07:02 +04: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 08:27:47 +04:00
|
|
|
}
|
2000-01-30 21:40:48 +03: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;
|
|
|
|
}
|
2003-10-18 09:09:42 +04:00
|
|
|
// an element in quirks mode gets a containing block based on looking for a
|
|
|
|
// parent with a non-auto height if the element has a percent height
|
2000-04-29 01:05:31 +04:00
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
2003-12-25 00:51:50 +03:00
|
|
|
if (eCompatibility_NavQuirks == aPresContext->CompatibilityMode() &&
|
2003-10-18 09:09:42 +04:00
|
|
|
mStylePosition->mHeight.GetUnit() == eStyleUnit_Percent) {
|
2003-10-19 00:22:22 +04:00
|
|
|
aContainingBlockHeight = CalcQuirkContainingBlockHeight(*aContainingBlockRS);
|
2000-04-29 01:05:31 +04:00
|
|
|
}
|
|
|
|
}
|
1999-04-22 08:27:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-11 08:11:02 +03:00
|
|
|
// Prefs callback to pick up changes
|
2004-04-30 03:34:19 +04:00
|
|
|
PR_STATIC_CALLBACK(int)
|
|
|
|
PrefsChanged(const char *aPrefName, void *instance)
|
2002-12-11 02:41:12 +03:00
|
|
|
{
|
2004-04-30 03:34:19 +04:00
|
|
|
sBlinkIsAllowed =
|
|
|
|
nsContentUtils::GetBoolPref("browser.blink_allowed", sBlinkIsAllowed);
|
|
|
|
|
2002-12-11 08:11:02 +03:00
|
|
|
return 0; /* PREF_OK */
|
2001-10-24 08:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if |text-decoration: blink| is allowed. The first time
|
2002-12-11 08:11:02 +03:00
|
|
|
// called, register the callback and then force-load the pref. After that,
|
2001-10-24 08:51:34 +04:00
|
|
|
// just use the cached value.
|
2002-12-11 08:11:02 +03:00
|
|
|
static PRBool BlinkIsAllowed(void)
|
2001-10-24 08:51:34 +04:00
|
|
|
{
|
2002-04-11 04:00:40 +04:00
|
|
|
if (!sPrefIsLoaded) {
|
2002-12-11 08:11:02 +03:00
|
|
|
// Set up a listener and check the initial value
|
2004-04-30 03:34:19 +04:00
|
|
|
nsContentUtils::RegisterPrefCallback("browser.blink_allowed", PrefsChanged,
|
|
|
|
nsnull);
|
2002-12-11 08:11:02 +03:00
|
|
|
PrefsChanged(nsnull, nsnull);
|
2002-04-11 04:00:40 +04:00
|
|
|
sPrefIsLoaded = PR_TRUE;
|
|
|
|
}
|
|
|
|
return sBlinkIsAllowed;
|
|
|
|
}
|
|
|
|
|
2003-09-23 01:40:12 +04:00
|
|
|
#ifdef FONT_LEADING_APIS_V2
|
2002-04-11 04:00:40 +04:00
|
|
|
static eNormalLineHeightControl GetNormalLineHeightCalcControl(void)
|
|
|
|
{
|
|
|
|
if (sNormalLineHeightControl == eUninitialized) {
|
2004-04-30 03:34:19 +04:00
|
|
|
// browser.display.normal_lineheight_calc_control is not user
|
|
|
|
// changable, so no need to register callback for it.
|
|
|
|
sNormalLineHeightControl =
|
|
|
|
NS_STATIC_CAST(eNormalLineHeightControl,
|
|
|
|
nsContentUtils::GetIntPref("browser.display.normal_lineheight_calc_control", eNoExternalLeading));
|
2002-04-11 04:00:40 +04:00
|
|
|
}
|
|
|
|
return sNormalLineHeightControl;
|
2001-10-24 08:51:34 +04:00
|
|
|
}
|
2003-09-23 01:40:12 +04:00
|
|
|
#endif
|
2001-10-24 08:51:34 +04:00
|
|
|
|
1999-02-23 22:33:06 +03: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 22:44:41 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::InitConstraints(nsPresContext* aPresContext,
|
1999-09-16 18:33:19 +04:00
|
|
|
nscoord aContainingBlockWidth,
|
2002-02-19 18:48:28 +03:00
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
nsMargin* aBorder,
|
|
|
|
nsMargin* aPadding)
|
1999-01-05 22:44:41 +03:00
|
|
|
{
|
1999-04-22 08:27:47 +04:00
|
|
|
// If this is the root frame, then set the computed width and
|
1999-01-05 22:44:41 +03:00
|
|
|
// height equal to the available space
|
|
|
|
if (nsnull == parentReflowState) {
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedWidth = availableWidth;
|
|
|
|
mComputedHeight = availableHeight;
|
|
|
|
mComputedMargin.SizeTo(0, 0, 0, 0);
|
1999-03-05 07:24:20 +03:00
|
|
|
mComputedPadding.SizeTo(0, 0, 0, 0);
|
|
|
|
mComputedBorderPadding.SizeTo(0, 0, 0, 0);
|
1999-07-20 07:51:46 +04:00
|
|
|
mComputedOffsets.SizeTo(0, 0, 0, 0);
|
1999-03-11 04:23:10 +03:00
|
|
|
mComputedMinWidth = mComputedMinHeight = 0;
|
|
|
|
mComputedMaxWidth = mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
1999-01-05 22:44:41 +03:00
|
|
|
} else {
|
|
|
|
// Get the containing block reflow state
|
2004-04-24 21:56:23 +04:00
|
|
|
const nsHTMLReflowState* cbrs = mCBReflowState;
|
1999-01-05 22:44:41 +03:00
|
|
|
NS_ASSERTION(nsnull != cbrs, "no containing block");
|
|
|
|
|
1999-09-16 18:33:19 +04:00
|
|
|
// If we weren't given a containing block width and height, then
|
|
|
|
// compute one
|
|
|
|
if (aContainingBlockWidth == -1) {
|
2000-04-29 01:05:31 +04:00
|
|
|
ComputeContainingBlockRectangle(aPresContext, cbrs, aContainingBlockWidth,
|
|
|
|
aContainingBlockHeight);
|
1999-09-16 18:33:19 +04:00
|
|
|
}
|
1999-04-22 08:27:47 +04:00
|
|
|
|
1999-03-05 07:24:20 +03:00
|
|
|
#if 0
|
2000-10-29 02:17:53 +04:00
|
|
|
nsFrame::ListTag(stdout, frame); printf(": cb=");
|
|
|
|
nsFrame::ListTag(stdout, cbrs->frame); printf(" size=%d,%d\n", aContainingBlockWidth, aContainingBlockHeight);
|
1999-03-05 07:24:20 +03:00
|
|
|
#endif
|
1999-02-14 07:43:44 +03:00
|
|
|
|
1999-07-28 07:51:37 +04:00
|
|
|
// See if the containing block height is based on the size of its
|
1999-02-14 07:43:44 +03:00
|
|
|
// content
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* fType;
|
1999-09-16 18:33:19 +04:00
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
2001-11-07 01:57:17 +03:00
|
|
|
// See if the containing block is (1) a scrolled frame, i.e. its
|
1999-07-28 07:51:37 +04:00
|
|
|
// parent is a scroll frame. The presence of the intervening
|
1999-03-05 07:24:20 +03:00
|
|
|
// frame (that the scroll frame scrolls) needs to be hidden from
|
2001-11-07 01:57:17 +03:00
|
|
|
// the containingBlockHeight calcuation, or (2) a cell frame which needs
|
|
|
|
// to use the mComputedHeight of the cell instead of what the cell block passed in.
|
1999-02-14 07:43:44 +03:00
|
|
|
if (cbrs->parentReflowState) {
|
|
|
|
nsIFrame* f = cbrs->parentReflowState->frame;
|
2003-10-31 23:19:18 +03:00
|
|
|
fType = f->GetType();
|
|
|
|
if (nsLayoutAtoms::scrollFrame == fType) {
|
1999-02-14 07:43:44 +03:00
|
|
|
// Use the scroll frame's computed height instead
|
2004-01-18 10:13:40 +03:00
|
|
|
aContainingBlockHeight = cbrs->parentReflowState->mComputedHeight;
|
1999-02-14 07:43:44 +03:00
|
|
|
}
|
2001-11-07 01:57:17 +03:00
|
|
|
else {
|
2003-10-31 23:19:18 +03:00
|
|
|
fType = cbrs->frame->GetType();
|
|
|
|
if (IS_TABLE_CELL(fType)) {
|
2001-11-07 01:57:17 +03:00
|
|
|
// use the cell's computed height
|
2004-01-18 10:13:40 +03:00
|
|
|
aContainingBlockHeight = cbrs->mComputedHeight;
|
2001-11-07 01:57:17 +03:00
|
|
|
}
|
|
|
|
}
|
1999-02-14 07:43:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-06 01:24:27 +03: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 18:33:19 +04:00
|
|
|
ComputeMargin(aContainingBlockWidth, cbrs);
|
2002-02-19 18:48:28 +03:00
|
|
|
if (aPadding) { // padding is an input arg
|
|
|
|
mComputedPadding.top = aPadding->top;
|
|
|
|
mComputedPadding.right = aPadding->right;
|
|
|
|
mComputedPadding.bottom = aPadding->bottom;
|
|
|
|
mComputedPadding.left = aPadding->left;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ComputePadding(aContainingBlockWidth, cbrs);
|
|
|
|
}
|
|
|
|
if (aBorder) { // border is an input arg
|
|
|
|
mComputedBorderPadding.top = aBorder->top;
|
|
|
|
mComputedBorderPadding.right = aBorder->right;
|
|
|
|
mComputedBorderPadding.bottom = aBorder->bottom;
|
|
|
|
mComputedBorderPadding.left = aBorder->left;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!mStyleBorder->GetBorder(mComputedBorderPadding)) {
|
|
|
|
// CSS2 has no percentage borders
|
|
|
|
mComputedBorderPadding.SizeTo(0, 0, 0, 0);
|
|
|
|
}
|
1999-03-06 03:48:45 +03:00
|
|
|
}
|
1999-03-06 01:24:27 +03:00
|
|
|
mComputedBorderPadding += mComputedPadding;
|
|
|
|
|
1999-03-05 07:24:20 +03:00
|
|
|
nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();
|
|
|
|
nsStyleUnit heightUnit = mStylePosition->mHeight.GetUnit();
|
1999-01-05 22:44:41 +03:00
|
|
|
|
1999-01-13 09:37:31 +03:00
|
|
|
// Check for a percentage based width and an unconstrained containing
|
|
|
|
// block width
|
|
|
|
if (eStyleUnit_Percent == widthUnit) {
|
2000-06-15 18:54:04 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
|
1999-01-13 09:37:31 +03:00
|
|
|
widthUnit = eStyleUnit_Auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check for a percentage based height and a containing block height
|
|
|
|
// that depends on the content height
|
1999-01-05 22:44:41 +03:00
|
|
|
if (eStyleUnit_Percent == heightUnit) {
|
1999-09-16 18:33:19 +04:00
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
2000-10-10 01:19:36 +04:00
|
|
|
// this if clause enables %-height on replaced inline frames,
|
|
|
|
// such as images. See bug 54119. The else clause "heightUnit = eStyleUnit_Auto;"
|
|
|
|
// used to be called exclusively.
|
|
|
|
if (NS_FRAME_REPLACED(NS_CSS_FRAME_TYPE_INLINE) == mFrameType) {
|
|
|
|
// Get the containing block reflow state
|
|
|
|
NS_ASSERTION(nsnull != cbrs, "no containing block");
|
|
|
|
// in quirks mode, get the cb height using the special quirk method
|
2003-12-25 00:51:50 +03:00
|
|
|
if (eCompatibility_NavQuirks == aPresContext->CompatibilityMode()) {
|
2002-09-04 08:00:41 +04:00
|
|
|
if (!IS_TABLE_CELL(fType)) {
|
2003-10-19 00:22:22 +04:00
|
|
|
aContainingBlockHeight = CalcQuirkContainingBlockHeight(*cbrs);
|
2003-10-24 11:31:50 +04:00
|
|
|
if (aContainingBlockHeight == NS_AUTOHEIGHT) {
|
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
2002-09-04 08:00:41 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
2000-10-10 01:19:36 +04:00
|
|
|
}
|
|
|
|
// in standard mode, use the cb height. if it's "auto", as will be the case
|
|
|
|
// by default in BODY, use auto height as per CSS2 spec.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NS_AUTOHEIGHT != cbrs->mComputedHeight)
|
|
|
|
aContainingBlockHeight = cbrs->mComputedHeight;
|
|
|
|
else
|
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// default to interpreting the height like 'auto'
|
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-06 02:48:57 +03:00
|
|
|
// Compute our offsets if the element is relatively positioned. We need
|
|
|
|
// the correct containing block width and height here, which is why we need
|
|
|
|
// to do it after all the quirks-n-such above.
|
|
|
|
if (NS_STYLE_POSITION_RELATIVE == mStyleDisplay->mPosition) {
|
|
|
|
ComputeRelativeOffsets(cbrs, aContainingBlockWidth, aContainingBlockHeight);
|
|
|
|
} else {
|
|
|
|
// Initialize offsets to 0
|
|
|
|
mComputedOffsets.SizeTo(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
1999-03-11 04:23:10 +03:00
|
|
|
// Calculate the computed values for min and max properties
|
1999-09-16 18:33:19 +04:00
|
|
|
ComputeMinMaxValues(aContainingBlockWidth, aContainingBlockHeight, cbrs);
|
1999-03-11 04:23:10 +03:00
|
|
|
|
1999-01-05 22:44:41 +03:00
|
|
|
// Calculate the computed width and height. This varies by frame type
|
1999-07-20 07:41:03 +04:00
|
|
|
if ((NS_FRAME_REPLACED(NS_CSS_FRAME_TYPE_INLINE) == mFrameType) ||
|
|
|
|
(NS_FRAME_REPLACED(NS_CSS_FRAME_TYPE_FLOATING) == mFrameType)) {
|
1999-01-05 22:44:41 +03:00
|
|
|
// Inline replaced element and floating replaced element are basically
|
1999-03-11 18:13:17 +03:00
|
|
|
// treated the same. First calculate the computed width
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == widthUnit) {
|
1999-01-05 22:44:41 +03:00
|
|
|
// A specified value of 'auto' uses the element's intrinsic width
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedWidth = NS_INTRINSICSIZE;
|
1999-01-05 22:44:41 +03:00
|
|
|
} else {
|
1999-09-16 18:33:19 +04:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, widthUnit,
|
2003-01-19 23:07:39 +03:00
|
|
|
mStylePosition->mWidth, mComputedWidth);
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
1999-07-28 07:51:37 +04:00
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedWidth(PR_TRUE);
|
1999-03-11 18:13:17 +03:00
|
|
|
|
|
|
|
// Now calculate the computed height
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == heightUnit) {
|
1999-01-05 22:44:41 +03:00
|
|
|
// A specified value of 'auto' uses the element's intrinsic height
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedHeight = NS_INTRINSICSIZE;
|
1999-01-05 22:44:41 +03:00
|
|
|
} else {
|
1999-09-16 18:33:19 +04:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight, heightUnit,
|
1999-03-05 07:24:20 +03:00
|
|
|
mStylePosition->mHeight,
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedHeight);
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
1999-07-28 07:51:37 +04:00
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedHeight(PR_TRUE);
|
2001-03-06 08:56:19 +03:00
|
|
|
|
1999-07-20 07:41:03 +04:00
|
|
|
} else if (NS_CSS_FRAME_TYPE_FLOATING == mFrameType) {
|
1999-03-11 18:13:17 +03:00
|
|
|
// Floating non-replaced element. First calculate the computed width
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == widthUnit) {
|
2000-02-13 20:55:18 +03:00
|
|
|
if ((NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) &&
|
|
|
|
(eStyleUnit_Percent == mStylePosition->mWidth.GetUnit())) {
|
2000-04-16 08:07:02 +04: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 20:55:18 +03:00
|
|
|
mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
2000-04-16 08:07:02 +04:00
|
|
|
} else if (NS_STYLE_DISPLAY_TABLE == mStyleDisplay->mDisplay) {
|
2000-04-29 01:05:31 +04: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 08:07:02 +04: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
|
2002-09-25 01:02:20 +04:00
|
|
|
nscoord widthFromCB = aContainingBlockWidth;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != widthFromCB) {
|
|
|
|
widthFromCB -= mComputedBorderPadding.left + mComputedBorderPadding.right +
|
|
|
|
mComputedMargin.left + mComputedMargin.right;
|
|
|
|
}
|
2001-07-19 06:33:43 +04:00
|
|
|
if (mComputedMaxWidth > widthFromCB) {
|
|
|
|
mComputedMaxWidth = widthFromCB;
|
2000-04-16 08:07:02 +04:00
|
|
|
}
|
2000-02-13 20:55:18 +03:00
|
|
|
}
|
2000-04-16 08:07:02 +04:00
|
|
|
|
1999-01-05 22:44:41 +03:00
|
|
|
} else {
|
1999-09-16 18:33:19 +04:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, widthUnit,
|
2003-01-19 23:07:39 +03:00
|
|
|
mStylePosition->mWidth, mComputedWidth);
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
1999-07-28 07:51:37 +04:00
|
|
|
|
|
|
|
// Take into account minimum and maximum sizes
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedWidth(PR_TRUE);
|
1999-07-28 07:51:37 +04:00
|
|
|
|
1999-03-11 18:13:17 +03:00
|
|
|
// Now calculate the computed height
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == heightUnit) {
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedHeight = NS_AUTOHEIGHT; // let it choose its height
|
1999-01-05 22:44:41 +03:00
|
|
|
} else {
|
1999-09-16 18:33:19 +04:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight, heightUnit,
|
1999-03-05 07:24:20 +03:00
|
|
|
mStylePosition->mHeight,
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedHeight);
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
1999-07-28 07:51:37 +04:00
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedHeight(PR_TRUE);
|
1999-03-11 18:13:17 +03:00
|
|
|
|
1999-07-20 07:41:03 +04:00
|
|
|
} else if (NS_CSS_FRAME_TYPE_INTERNAL_TABLE == mFrameType) {
|
1999-03-11 18:13:17 +03:00
|
|
|
// Internal table elements. The rules vary depending on the type.
|
1999-01-05 22:44:41 +03:00
|
|
|
// Calculate the computed width
|
2000-10-06 03:49:25 +04:00
|
|
|
PRBool rowOrRowGroup = PR_FALSE;
|
1999-03-05 07:24:20 +03:00
|
|
|
if ((NS_STYLE_DISPLAY_TABLE_ROW == mStyleDisplay->mDisplay) ||
|
|
|
|
(NS_STYLE_DISPLAY_TABLE_ROW_GROUP == mStyleDisplay->mDisplay)) {
|
1999-01-05 22:44:41 +03:00
|
|
|
// 'width' property doesn't apply to table rows and row groups
|
|
|
|
widthUnit = eStyleUnit_Auto;
|
2000-10-06 03:49:25 +04:00
|
|
|
rowOrRowGroup = PR_TRUE;
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
|
|
|
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == widthUnit) {
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedWidth = availableWidth;
|
1999-01-13 09:37:31 +03:00
|
|
|
|
2000-10-06 03:49:25 +04:00
|
|
|
if ((mComputedWidth != NS_UNCONSTRAINEDSIZE) && !rowOrRowGroup){
|
|
|
|
// Internal table elements don't have margins. Only tables and
|
|
|
|
// cells have border and padding
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedWidth -= mComputedBorderPadding.left +
|
1999-03-05 07:24:20 +03:00
|
|
|
mComputedBorderPadding.right;
|
1999-01-13 09:37:31 +03:00
|
|
|
}
|
|
|
|
|
1999-01-05 22:44:41 +03:00
|
|
|
} else {
|
1999-09-16 18:33:19 +04:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, widthUnit,
|
2003-01-19 23:07:39 +03:00
|
|
|
mStylePosition->mWidth, mComputedWidth);
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the computed height
|
1999-03-05 07:24:20 +03:00
|
|
|
if ((NS_STYLE_DISPLAY_TABLE_COLUMN == mStyleDisplay->mDisplay) ||
|
|
|
|
(NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP == mStyleDisplay->mDisplay)) {
|
1999-01-05 22:44:41 +03:00
|
|
|
// 'height' property doesn't apply to table columns and column groups
|
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == heightUnit) {
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedHeight = NS_AUTOHEIGHT;
|
1999-01-05 22:44:41 +03:00
|
|
|
} else {
|
1999-09-16 18:33:19 +04:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight, heightUnit,
|
1999-03-05 07:24:20 +03:00
|
|
|
mStylePosition->mHeight,
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedHeight);
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
1999-03-11 04:23:10 +03:00
|
|
|
|
|
|
|
// Doesn't apply to table elements
|
|
|
|
mComputedMinWidth = mComputedMinHeight = 0;
|
|
|
|
mComputedMaxWidth = mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
1999-07-20 07:41:03 +04:00
|
|
|
} else if (NS_FRAME_GET_TYPE(mFrameType) == NS_CSS_FRAME_TYPE_ABSOLUTE) {
|
1999-05-11 02:59:03 +04:00
|
|
|
// XXX not sure if this belongs here or somewhere else - cwk
|
2004-01-10 08:36:32 +03:00
|
|
|
InitAbsoluteConstraints(aPresContext, cbrs, aContainingBlockWidth,
|
|
|
|
aContainingBlockHeight);
|
1999-07-20 07:41:03 +04:00
|
|
|
} else if (NS_CSS_FRAME_TYPE_INLINE == mFrameType) {
|
1999-03-05 07:24:20 +03:00
|
|
|
// Inline non-replaced elements do not have computed widths or heights
|
|
|
|
// XXX add this check to HaveFixedContentHeight/Width too
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
mComputedHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
mComputedMargin.top = 0;
|
|
|
|
mComputedMargin.bottom = 0;
|
1999-03-11 04:23:10 +03:00
|
|
|
mComputedMinWidth = mComputedMinHeight = 0;
|
|
|
|
mComputedMaxWidth = mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 07:24:20 +03:00
|
|
|
} else {
|
|
|
|
ComputeBlockBoxData(aPresContext, cbrs, widthUnit, heightUnit,
|
1999-09-16 18:33:19 +04:00
|
|
|
aContainingBlockWidth,
|
|
|
|
aContainingBlockHeight);
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
|
|
|
}
|
2001-10-24 08:51:34 +04:00
|
|
|
// Check for blinking text and permission to display it
|
2001-12-07 17:51:12 +03:00
|
|
|
mFlags.mBlinks = (parentReflowState && parentReflowState->mFlags.mBlinks);
|
|
|
|
if (!mFlags.mBlinks && BlinkIsAllowed()) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleTextReset* st = frame->GetStyleTextReset();
|
2002-05-08 03:26:02 +04:00
|
|
|
mFlags.mBlinks =
|
|
|
|
((st->mTextDecoration & NS_STYLE_TEXT_DECORATION_BLINK) != 0);
|
2001-10-11 04:15:09 +04:00
|
|
|
}
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the box data for block and block-replaced elements in the
|
|
|
|
// normal flow.
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::ComputeBlockBoxData(nsPresContext* aPresContext,
|
1999-03-05 07:24:20 +03:00
|
|
|
const nsHTMLReflowState* cbrs,
|
|
|
|
nsStyleUnit aWidthUnit,
|
|
|
|
nsStyleUnit aHeightUnit,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight)
|
|
|
|
{
|
|
|
|
// Compute the content width
|
|
|
|
if (eStyleUnit_Auto == aWidthUnit) {
|
1999-07-20 07:41:03 +04:00
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType)) {
|
1999-03-05 07:24:20 +03:00
|
|
|
// Block-level replaced element in the flow. A specified value of
|
1999-05-04 00:53:27 +04:00
|
|
|
// 'auto' uses the element's intrinsic width (CSS2 10.3.4)
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedWidth = NS_INTRINSICSIZE;
|
1999-01-05 22:44:41 +03:00
|
|
|
} else {
|
1999-05-04 00:53:27 +04:00
|
|
|
// Block-level non-replaced element in the flow. 'auto' values
|
1999-07-28 07:51:37 +04:00
|
|
|
// for margin-left and margin-right become 0, and the sum of the
|
1999-05-04 00:53:27 +04:00
|
|
|
// areas must equal the width of the content-area of the parent
|
|
|
|
// element.
|
1999-03-05 07:24:20 +03:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == availableWidth) {
|
1999-05-04 00:53:27 +04:00
|
|
|
// During pass1 table reflow, auto side margin values are
|
|
|
|
// uncomputable (== 0).
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
2000-01-03 07:32:13 +03: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
|
2002-09-25 01:02:20 +04:00
|
|
|
nscoord maxWidth = cbrs->mComputedMaxWidth;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != maxWidth) {
|
|
|
|
maxWidth -= mComputedMargin.left + mComputedBorderPadding.left +
|
|
|
|
mComputedMargin.right + mComputedBorderPadding.right;
|
|
|
|
}
|
2000-01-03 07:32:13 +03:00
|
|
|
if (maxWidth < mComputedMaxWidth) {
|
|
|
|
mComputedMaxWidth = maxWidth;
|
|
|
|
}
|
|
|
|
|
1999-03-05 07:24:20 +03:00
|
|
|
} else {
|
2000-04-29 01:05:31 +04:00
|
|
|
// tables act like replaced elements regarding mComputedWidth
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* fType = frame->GetType();
|
|
|
|
if (nsLayoutAtoms::tableOuterFrame == fType) {
|
2000-05-01 02:29:01 +04:00
|
|
|
mComputedWidth = 0; // XXX temp fix for trees
|
2003-10-31 23:19:18 +03:00
|
|
|
} else if ((nsLayoutAtoms::tableFrame == fType) ||
|
|
|
|
(nsLayoutAtoms::tableCaptionFrame == fType)) {
|
2000-04-29 01:05:31 +04:00
|
|
|
mComputedWidth = NS_SHRINKWRAPWIDTH;
|
2001-02-07 12:57:26 +03:00
|
|
|
if (eStyleUnit_Auto == mStyleMargin->mMargin.GetLeftUnit()) {
|
2000-04-29 01:05:31 +04:00
|
|
|
mComputedMargin.left = NS_AUTOMARGIN;
|
|
|
|
}
|
2001-02-07 12:57:26 +03:00
|
|
|
if (eStyleUnit_Auto == mStyleMargin->mMargin.GetRightUnit()) {
|
2000-04-29 01:05:31 +04:00
|
|
|
mComputedMargin.right = NS_AUTOMARGIN;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mComputedWidth = availableWidth - mComputedMargin.left -
|
|
|
|
mComputedMargin.right - mComputedBorderPadding.left -
|
|
|
|
mComputedBorderPadding.right;
|
2004-01-08 06:38:25 +03:00
|
|
|
mComputedWidth = PR_MAX(mComputedWidth, 0);
|
2000-04-29 01:05:31 +04:00
|
|
|
}
|
1999-03-11 18:13:17 +03:00
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedWidth(PR_FALSE);
|
2004-01-18 09:06:13 +03:00
|
|
|
CalculateBlockSideMargins(cbrs->mComputedWidth, mComputedWidth);
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, aWidthUnit,
|
|
|
|
mStylePosition->mWidth, mComputedWidth);
|
1999-01-05 22:44:41 +03:00
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedWidth(PR_TRUE);
|
1999-07-28 07:51:37 +04:00
|
|
|
|
1999-05-04 00:53:27 +04:00
|
|
|
// Now that we have the computed-width, compute the side margins
|
2000-05-05 03:16:42 +04:00
|
|
|
CalculateBlockSideMargins(cbrs->mComputedWidth, mComputedWidth);
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
1999-05-04 00:53:27 +04:00
|
|
|
|
1999-03-05 07:24:20 +03:00
|
|
|
// Compute the content height
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Auto == aHeightUnit) {
|
1999-07-20 07:41:03 +04:00
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType)) {
|
1999-03-05 07:24:20 +03:00
|
|
|
// For replaced elements use the intrinsic size for "auto"
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedHeight = NS_INTRINSICSIZE;
|
1999-03-05 07:24:20 +03:00
|
|
|
} else {
|
|
|
|
// For non-replaced elements auto means unconstrained
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedHeight = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ComputeVerticalValue(aContainingBlockHeight, aHeightUnit,
|
1999-07-20 07:41:03 +04:00
|
|
|
mStylePosition->mHeight, mComputedHeight);
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
2004-01-06 02:59:25 +03:00
|
|
|
AdjustComputedHeight(PR_TRUE);
|
1999-03-05 07:24:20 +03:00
|
|
|
}
|
1999-01-05 22:44:41 +03:00
|
|
|
|
1999-05-04 00:53:27 +04: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 07:24:20 +03:00
|
|
|
//
|
1999-05-04 00:53:27 +04:00
|
|
|
// Note: the width unit is not auto when this is called
|
1999-03-05 07:24:20 +03:00
|
|
|
void
|
2000-05-05 03:16:42 +04:00
|
|
|
nsHTMLReflowState::CalculateBlockSideMargins(nscoord aAvailWidth,
|
1999-09-21 04:15:16 +04:00
|
|
|
nscoord aComputedWidth)
|
1999-05-04 00:53:27 +04:00
|
|
|
{
|
2004-02-04 08:18:37 +03:00
|
|
|
// Because of the ugly way we do intrinsic sizing within Reflow, this method
|
|
|
|
// doesn't necessarily produce the right results. The results will be
|
|
|
|
// adjusted in nsBlockReflowContext::AlignBlockHorizontally after reflow.
|
|
|
|
// The code for tables is particularly sensitive to regressions; the
|
|
|
|
// numerous |isTable| checks are technically incorrect, but necessary
|
|
|
|
// for basic testcases.
|
|
|
|
|
1999-05-04 00:53:27 +04: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...
|
2004-02-04 08:18:37 +03:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aComputedWidth ||
|
|
|
|
NS_UNCONSTRAINEDSIZE == aAvailWidth)
|
1999-05-04 00:53:27 +04:00
|
|
|
return;
|
|
|
|
|
1999-07-20 07:41:03 +04:00
|
|
|
nscoord sum = mComputedMargin.left + mComputedBorderPadding.left +
|
1999-09-21 04:15:16 +04:00
|
|
|
aComputedWidth + mComputedBorderPadding.right + mComputedMargin.right;
|
2004-02-04 08:18:37 +03:00
|
|
|
if (sum == aAvailWidth)
|
1999-05-04 00:53:27 +04:00
|
|
|
// The sum is already correct
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Determine the left and right margin values. The width value
|
|
|
|
// remains constant while we do this.
|
2004-02-04 08:18:37 +03:00
|
|
|
|
|
|
|
PRBool isTable = mStyleDisplay->mDisplay == NS_STYLE_DISPLAY_TABLE ||
|
|
|
|
mStyleDisplay->mDisplay == NS_STYLE_DISPLAY_TABLE_CAPTION;
|
1999-05-04 00:53:27 +04:00
|
|
|
|
|
|
|
// Calculate how much space is available for margins
|
2004-02-04 08:18:37 +03:00
|
|
|
nscoord availMarginSpace = aAvailWidth - sum;
|
|
|
|
|
|
|
|
// XXXldb Should this be quirks-mode only? And why captions?
|
|
|
|
if (isTable)
|
|
|
|
// XXXldb Why does this break things so badly if this is changed to
|
|
|
|
// availMarginSpace += mComputedBorderPadding.left +
|
|
|
|
// mComputedBorderPadding.right;
|
2001-10-24 18:36:33 +04:00
|
|
|
availMarginSpace = aAvailWidth - aComputedWidth;
|
|
|
|
|
2004-02-04 08:18:37 +03:00
|
|
|
// If the available margin space is negative, then don't follow the
|
|
|
|
// usual overconstraint rules.
|
|
|
|
if (availMarginSpace < 0) {
|
|
|
|
if (!isTable) {
|
|
|
|
if (mStyleVisibility->mDirection == NS_STYLE_DIRECTION_LTR) {
|
|
|
|
mComputedMargin.right += availMarginSpace;
|
|
|
|
} else {
|
|
|
|
mComputedMargin.left += availMarginSpace;
|
|
|
|
}
|
|
|
|
} else {
|
1999-09-21 04:15:16 +04:00
|
|
|
mComputedMargin.left = 0;
|
|
|
|
mComputedMargin.right = 0;
|
2004-02-04 08:18:37 +03:00
|
|
|
if (mStyleVisibility->mDirection == NS_STYLE_DIRECTION_RTL) {
|
1999-09-21 04:15:16 +04:00
|
|
|
mComputedMargin.left = availMarginSpace;
|
|
|
|
}
|
1999-07-05 22:45:12 +04:00
|
|
|
}
|
2004-02-04 08:18:37 +03:00
|
|
|
return;
|
1999-07-05 22:45:12 +04:00
|
|
|
}
|
2004-02-04 08:18:37 +03:00
|
|
|
|
|
|
|
// The css2 spec clearly defines how block elements should behave
|
|
|
|
// in section 10.3.3.
|
|
|
|
PRBool isAutoLeftMargin =
|
|
|
|
eStyleUnit_Auto == mStyleMargin->mMargin.GetLeftUnit();
|
|
|
|
PRBool isAutoRightMargin =
|
|
|
|
eStyleUnit_Auto == mStyleMargin->mMargin.GetRightUnit();
|
|
|
|
if (!isAutoLeftMargin && !isAutoRightMargin && !isTable) {
|
|
|
|
// Neither margin is 'auto' so we're over constrained. Use the
|
|
|
|
// 'direction' property of the parent to tell which margin to
|
|
|
|
// ignore
|
|
|
|
// First check if there is an HTML alignment that we should honor
|
|
|
|
const nsHTMLReflowState* prs = parentReflowState;
|
|
|
|
if (prs &&
|
|
|
|
(prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER ||
|
|
|
|
prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT)) {
|
|
|
|
isAutoLeftMargin = PR_TRUE;
|
|
|
|
isAutoRightMargin =
|
|
|
|
prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER;
|
|
|
|
}
|
|
|
|
// Otherwise apply the CSS rules, and ignore one margin by forcing
|
|
|
|
// it to 'auto', depending on 'direction'.
|
|
|
|
else if (NS_STYLE_DIRECTION_LTR == mStyleVisibility->mDirection) {
|
|
|
|
isAutoRightMargin = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
isAutoLeftMargin = PR_TRUE;
|
1999-05-04 00:53:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-21 04:15:16 +04: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 {
|
2004-02-04 08:18:37 +03:00
|
|
|
mComputedMargin.left = availMarginSpace;
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
1999-09-21 04:15:16 +04:00
|
|
|
} else if (isAutoRightMargin) {
|
2004-02-04 08:18:37 +03:00
|
|
|
mComputedMargin.right = availMarginSpace;
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-13 03:25:49 +04:00
|
|
|
PRBool
|
|
|
|
nsHTMLReflowState::UseComputedHeight()
|
|
|
|
{
|
|
|
|
static PRBool useComputedHeight = PR_FALSE;
|
|
|
|
|
2003-04-03 02:45:08 +04:00
|
|
|
#if defined(XP_UNIX) || defined(XP_WIN) || defined(XP_OS2) || defined(XP_BEOS)
|
1999-10-13 03:25:49 +04:00
|
|
|
static PRBool firstTime = 1;
|
|
|
|
if (firstTime) {
|
|
|
|
if (getenv("GECKO_USE_COMPUTED_HEIGHT")) {
|
|
|
|
useComputedHeight = PR_TRUE;
|
|
|
|
}
|
|
|
|
firstTime = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return useComputedHeight;
|
|
|
|
}
|
|
|
|
|
2002-04-11 04:00:40 +04:00
|
|
|
#define NORMAL_LINE_HEIGHT_FACTOR 1.2f // in term of emHeight
|
|
|
|
// For "normal" we use the font's normal line height (em height + leading).
|
|
|
|
// If both internal leading and external leading specified by font itself
|
|
|
|
// are zeros, we should compensate this by creating extra (external) leading
|
|
|
|
// in eCompensateLeading mode. This is necessary because without this
|
|
|
|
// compensation, normal line height might looks too tight.
|
|
|
|
|
|
|
|
// For risk management, we use preference to control the behavior, and
|
|
|
|
// eNoExternalLeading is the old behavior.
|
|
|
|
static nscoord
|
|
|
|
GetNormalLineHeight(nsIFontMetrics* aFontMetrics)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFontMetrics, "no font metrics");
|
|
|
|
|
|
|
|
nscoord normalLineHeight;
|
|
|
|
|
|
|
|
#ifdef FONT_LEADING_APIS_V2
|
2002-09-03 01:26:11 +04:00
|
|
|
nscoord externalLeading, internalLeading, emHeight;
|
2002-04-11 04:00:40 +04:00
|
|
|
aFontMetrics->GetExternalLeading(externalLeading);
|
|
|
|
aFontMetrics->GetInternalLeading(internalLeading);
|
|
|
|
aFontMetrics->GetEmHeight(emHeight);
|
|
|
|
switch (GetNormalLineHeightCalcControl()) {
|
|
|
|
case eIncludeExternalLeading:
|
|
|
|
normalLineHeight = emHeight+ internalLeading + externalLeading;
|
|
|
|
break;
|
|
|
|
case eCompensateLeading:
|
|
|
|
if (!internalLeading && !externalLeading)
|
|
|
|
normalLineHeight = NSToCoordRound(emHeight * NORMAL_LINE_HEIGHT_FACTOR);
|
|
|
|
else
|
|
|
|
normalLineHeight = emHeight+ internalLeading + externalLeading;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//case eNoExternalLeading:
|
|
|
|
normalLineHeight = emHeight + internalLeading;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
aFontMetrics->GetNormalLineHeight(normalLineHeight);
|
|
|
|
#endif // FONT_LEADING_APIS_V2
|
|
|
|
return normalLineHeight;
|
|
|
|
}
|
|
|
|
|
1999-09-10 01:03:27 +04:00
|
|
|
static nscoord
|
2004-08-01 03:15:21 +04:00
|
|
|
ComputeLineHeight(nsPresContext* aPresContext,
|
2002-04-11 04:00:40 +04:00
|
|
|
nsIRenderingContext* aRenderingContext,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aStyleContext)
|
1999-09-10 01:03:27 +04:00
|
|
|
{
|
2000-01-12 01:15:20 +03:00
|
|
|
NS_PRECONDITION(nsnull != aRenderingContext, "no rendering context");
|
|
|
|
|
1999-10-13 03:25:49 +04:00
|
|
|
nscoord lineHeight = -1;
|
1999-09-10 01:03:27 +04:00
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleText* text = aStyleContext->GetStyleText();
|
|
|
|
const nsStyleFont* font = aStyleContext->GetStyleFont();
|
|
|
|
const nsStyleVisibility* vis = aStyleContext->GetStyleVisibility();
|
2001-06-01 02:19:43 +04:00
|
|
|
|
1999-09-10 01:03:27 +04:00
|
|
|
nsStyleUnit unit = text->mLineHeight.GetUnit();
|
1999-01-05 22:44:41 +03:00
|
|
|
|
2002-04-11 04:00:40 +04:00
|
|
|
if (unit == eStyleUnit_Coord) {
|
1999-09-10 01:03:27 +04:00
|
|
|
// For length values just use the pre-computed value
|
|
|
|
lineHeight = text->mLineHeight.GetCoordValue();
|
2002-04-11 04:00:40 +04:00
|
|
|
} else {
|
2000-05-17 10:47:56 +04:00
|
|
|
nsCOMPtr<nsIDeviceContext> deviceContext;
|
|
|
|
aRenderingContext->GetDeviceContext(*getter_AddRefs(deviceContext));
|
2000-05-15 23:40:42 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
2004-06-09 03:53:59 +04:00
|
|
|
deviceContext->GetMetricsFor(font->mFont, vis->mLangGroup,
|
|
|
|
*getter_AddRefs(fm));
|
2002-04-11 04:00:40 +04:00
|
|
|
if (unit == eStyleUnit_Factor) {
|
|
|
|
// For factor units the computed value of the line-height property
|
|
|
|
// is found by multiplying the factor by the font's <b>actual</b>
|
|
|
|
// em height.
|
|
|
|
float factor;
|
|
|
|
factor = text->mLineHeight.GetFactorValue();
|
|
|
|
// 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.
|
|
|
|
nscoord emHeight = font->mFont.size;
|
2002-05-03 02:24:59 +04:00
|
|
|
if (!nsHTMLReflowState::UseComputedHeight()) {
|
2002-04-11 04:00:40 +04:00
|
|
|
fm->GetEmHeight(emHeight);
|
|
|
|
}
|
|
|
|
lineHeight = NSToCoordRound(factor * emHeight);
|
|
|
|
} else {
|
2001-11-06 10:48:02 +03:00
|
|
|
NS_ASSERTION(eStyleUnit_Normal == unit, "bad unit");
|
2002-04-11 04:00:40 +04:00
|
|
|
lineHeight = font->mFont.size;
|
2002-05-03 02:24:59 +04:00
|
|
|
if (!nsHTMLReflowState::UseComputedHeight()) {
|
2002-04-11 04:00:40 +04:00
|
|
|
lineHeight = GetNormalLineHeight(fm);
|
|
|
|
}
|
1999-09-10 01:03:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return lineHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::CalcLineHeight(nsPresContext* aPresContext,
|
1999-09-10 01:03:27 +04:00
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
2004-04-19 00:10:09 +04:00
|
|
|
NS_ASSERTION(aFrame && aFrame->GetStyleContext(),
|
|
|
|
"Bogus data passed in to CalcLineHeight");
|
|
|
|
|
|
|
|
nscoord lineHeight = ComputeLineHeight(aPresContext, aRenderingContext,
|
|
|
|
aFrame->GetStyleContext());
|
|
|
|
|
|
|
|
NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up");
|
|
|
|
|
1999-01-05 22:44:41 +03:00
|
|
|
return lineHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::ComputeHorizontalValue(nscoord aContainingBlockWidth,
|
|
|
|
nsStyleUnit aUnit,
|
|
|
|
const nsStyleCoord& aCoord,
|
|
|
|
nscoord& aResult)
|
|
|
|
{
|
|
|
|
aResult = 0;
|
|
|
|
if (eStyleUnit_Percent == aUnit) {
|
1999-03-26 06:57:46 +03:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
|
|
|
|
aResult = 0;
|
|
|
|
} else {
|
|
|
|
float pct = aCoord.GetPercentValue();
|
|
|
|
aResult = NSToCoordFloor(aContainingBlockWidth * pct);
|
|
|
|
}
|
1999-01-05 22:44:41 +03:00
|
|
|
|
|
|
|
} else if (eStyleUnit_Coord == aUnit) {
|
|
|
|
aResult = aCoord.GetCoordValue();
|
|
|
|
}
|
1999-03-31 08:11:40 +04: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 {
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* styleContext = frame->GetStyleContext();
|
2002-05-25 00:11:14 +04:00
|
|
|
SetFontFromStyle(rendContext, styleContext);
|
1999-03-31 08:11:40 +04:00
|
|
|
nscoord fontWidth;
|
|
|
|
rendContext->GetWidth('M', fontWidth);
|
|
|
|
aResult = aCoord.GetIntValue() * fontWidth;
|
|
|
|
}
|
|
|
|
}
|
1999-01-05 22:44:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::ComputeVerticalValue(nscoord aContainingBlockHeight,
|
|
|
|
nsStyleUnit aUnit,
|
|
|
|
const nsStyleCoord& aCoord,
|
|
|
|
nscoord& aResult)
|
|
|
|
{
|
|
|
|
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");
|
2000-08-24 08:38:08 +04:00
|
|
|
if (NS_AUTOHEIGHT!=aContainingBlockHeight)
|
|
|
|
{
|
|
|
|
float pct = aCoord.GetPercentValue();
|
|
|
|
aResult = NSToCoordFloor(aContainingBlockHeight * pct);
|
|
|
|
}
|
|
|
|
else { // safest thing to do for an undefined height is to make it 0
|
|
|
|
aResult = 0;
|
|
|
|
}
|
1999-01-05 22:44:41 +03:00
|
|
|
|
|
|
|
} else if (eStyleUnit_Coord == aUnit) {
|
|
|
|
aResult = aCoord.GetCoordValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-06 01:24:27 +03:00
|
|
|
void
|
1999-03-26 06:57:46 +03:00
|
|
|
nsHTMLReflowState::ComputeMargin(nscoord aContainingBlockWidth,
|
|
|
|
const nsHTMLReflowState* aContainingBlockRS)
|
1999-03-06 01:24:27 +03:00
|
|
|
{
|
|
|
|
// If style style can provide us the margin directly, then use it.
|
2001-02-07 12:57:26 +03:00
|
|
|
if (!mStyleMargin->GetMargin(mComputedMargin)) {
|
1999-03-26 06:57:46 +03:00
|
|
|
// We have to compute the value
|
1999-03-06 01:24:27 +03:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aContainingBlockWidth) {
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedMargin.left = 0;
|
|
|
|
mComputedMargin.right = 0;
|
1999-03-06 01:24:27 +03:00
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
if (eStyleUnit_Coord == mStyleMargin->mMargin.GetLeftUnit()) {
|
2000-01-03 07:32:13 +03:00
|
|
|
nsStyleCoord left;
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
mStyleMargin->mMargin.GetLeft(left),
|
2000-01-03 07:32:13 +03:00
|
|
|
mComputedMargin.left = left.GetCoordValue();
|
|
|
|
}
|
2001-02-07 12:57:26 +03:00
|
|
|
if (eStyleUnit_Coord == mStyleMargin->mMargin.GetRightUnit()) {
|
2000-01-03 07:32:13 +03:00
|
|
|
nsStyleCoord right;
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
mStyleMargin->mMargin.GetRight(right),
|
2000-01-03 07:32:13 +03:00
|
|
|
mComputedMargin.right = right.GetCoordValue();
|
|
|
|
}
|
|
|
|
|
1999-03-06 01:24:27 +03:00
|
|
|
} else {
|
|
|
|
nsStyleCoord left, right;
|
1999-03-26 06:57:46 +03:00
|
|
|
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleMargin->mMargin.GetLeftUnit(),
|
|
|
|
mStyleMargin->mMargin.GetLeft(left),
|
|
|
|
mComputedMargin.left);
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStyleMargin->mMargin.GetRightUnit(),
|
|
|
|
mStyleMargin->mMargin.GetRight(right),
|
|
|
|
mComputedMargin.right);
|
1999-03-06 01:24:27 +03: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.
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeVerticalValue(rs2->mComputedHeight,
|
|
|
|
mStyleMargin->mMargin.GetTopUnit(),
|
|
|
|
mStyleMargin->mMargin.GetTop(top),
|
|
|
|
mComputedMargin.top);
|
|
|
|
ComputeVerticalValue(rs2->mComputedHeight,
|
|
|
|
mStyleMargin->mMargin.GetBottomUnit(),
|
|
|
|
mStyleMargin->mMargin.GetBottom(bottom),
|
|
|
|
mComputedMargin.bottom);
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
2001-02-07 12:57:26 +03:00
|
|
|
mStyleMargin->mMargin.GetTopUnit(),
|
|
|
|
mStyleMargin->mMargin.GetTop(top),
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedMargin.top);
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
2001-02-07 12:57:26 +03:00
|
|
|
mStyleMargin->mMargin.GetBottomUnit(),
|
|
|
|
mStyleMargin->mMargin.GetBottom(bottom),
|
1999-07-20 07:41:03 +04:00
|
|
|
mComputedMargin.bottom);
|
1999-03-06 01:24:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-06 03:36:59 +03:00
|
|
|
void
|
1999-03-26 06:57:46 +03:00
|
|
|
nsHTMLReflowState::ComputePadding(nscoord aContainingBlockWidth,
|
|
|
|
const nsHTMLReflowState* aContainingBlockRS)
|
|
|
|
|
1999-03-06 03:36:59 +03:00
|
|
|
{
|
|
|
|
// If style can provide us the padding directly, then use it.
|
2001-02-07 12:57:26 +03:00
|
|
|
if (!mStylePadding->GetPadding(mComputedPadding)) {
|
1999-03-26 06:57:46 +03:00
|
|
|
// We have to compute the value
|
1999-03-06 03:36:59 +03:00
|
|
|
nsStyleCoord left, right, top, bottom;
|
1999-03-26 06:57:46 +03:00
|
|
|
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStylePadding->mPadding.GetLeftUnit(),
|
|
|
|
mStylePadding->mPadding.GetLeft(left),
|
|
|
|
mComputedPadding.left);
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStylePadding->mPadding.GetRightUnit(),
|
|
|
|
mStylePadding->mPadding.GetRight(right),
|
|
|
|
mComputedPadding.right);
|
1999-03-26 06:57:46 +03:00
|
|
|
|
|
|
|
// According to the CSS2 spec, percentages are calculated with respect to
|
|
|
|
// containing block width for padding-top and padding-bottom
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStylePadding->mPadding.GetTopUnit(),
|
|
|
|
mStylePadding->mPadding.GetTop(top),
|
|
|
|
mComputedPadding.top);
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth,
|
|
|
|
mStylePadding->mPadding.GetBottomUnit(),
|
|
|
|
mStylePadding->mPadding.GetBottom(bottom),
|
|
|
|
mComputedPadding.bottom);
|
1999-03-06 03:36:59 +03:00
|
|
|
}
|
2000-12-22 02:05:15 +03:00
|
|
|
// a table row/col group, row/col doesn't have padding
|
|
|
|
if (frame) {
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* frameType = frame->GetType();
|
|
|
|
if ((nsLayoutAtoms::tableRowGroupFrame == frameType) ||
|
|
|
|
(nsLayoutAtoms::tableColGroupFrame == frameType) ||
|
|
|
|
(nsLayoutAtoms::tableRowFrame == frameType) ||
|
|
|
|
(nsLayoutAtoms::tableColFrame == frameType)) {
|
2000-12-22 02:05:15 +03:00
|
|
|
mComputedPadding.top = 0;
|
|
|
|
mComputedPadding.right = 0;
|
|
|
|
mComputedPadding.bottom = 0;
|
|
|
|
mComputedPadding.left = 0;
|
|
|
|
}
|
|
|
|
}
|
1999-03-06 03:36:59 +03:00
|
|
|
}
|
|
|
|
|
1999-03-11 04:23:10 +03:00
|
|
|
void
|
|
|
|
nsHTMLReflowState::ComputeMinMaxValues(nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
const nsHTMLReflowState* aContainingBlockRS)
|
|
|
|
{
|
|
|
|
nsStyleUnit minWidthUnit = mStylePosition->mMinWidth.GetUnit();
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, minWidthUnit,
|
|
|
|
mStylePosition->mMinWidth, mComputedMinWidth);
|
1999-03-11 04:23:10 +03:00
|
|
|
nsStyleUnit maxWidthUnit = mStylePosition->mMaxWidth.GetUnit();
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Null == maxWidthUnit) {
|
1999-03-11 18:13:17 +03:00
|
|
|
// Specified value of 'none'
|
|
|
|
mComputedMaxWidth = NS_UNCONSTRAINEDSIZE; // no limit
|
1999-03-11 04:23:10 +03:00
|
|
|
} else {
|
|
|
|
ComputeHorizontalValue(aContainingBlockWidth, maxWidthUnit,
|
|
|
|
mStylePosition->mMaxWidth, mComputedMaxWidth);
|
|
|
|
}
|
1999-03-11 18:13:17 +03: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 04:23:10 +03:00
|
|
|
nsStyleUnit minHeightUnit = mStylePosition->mMinHeight.GetUnit();
|
2003-11-24 22:46:25 +03: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;
|
1999-03-11 04:23:10 +03:00
|
|
|
} else {
|
2003-11-24 22:46:25 +03:00
|
|
|
ComputeVerticalValue(aContainingBlockHeight, minHeightUnit,
|
|
|
|
mStylePosition->mMinHeight, mComputedMinHeight);
|
1999-03-11 04:23:10 +03:00
|
|
|
}
|
|
|
|
nsStyleUnit maxHeightUnit = mStylePosition->mMaxHeight.GetUnit();
|
2003-11-24 22:46:25 +03:00
|
|
|
if (eStyleUnit_Null == maxHeightUnit) {
|
1999-03-11 18:13:17 +03:00
|
|
|
// Specified value of 'none'
|
|
|
|
mComputedMaxHeight = NS_UNCONSTRAINEDSIZE; // no limit
|
1999-03-11 04:23:10 +03:00
|
|
|
} else {
|
1999-03-11 18:13:17 +03: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 04:23:10 +03:00
|
|
|
}
|
|
|
|
}
|
2001-03-06 08:56:19 +03:00
|
|
|
|
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
void nsHTMLReflowState::AdjustComputedHeight(PRBool aAdjustForBoxSizing)
|
2001-03-06 08:56:19 +03:00
|
|
|
{
|
|
|
|
// only do the math if the height is not a symbolic value
|
2004-01-06 02:59:25 +03:00
|
|
|
if (mComputedHeight == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
return;
|
2001-03-06 08:56:19 +03:00
|
|
|
}
|
2004-01-06 02:59:25 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(mComputedHeight >= 0, "Negative Height Input - very bad");
|
|
|
|
|
|
|
|
// Factor in any minimum and maximum size information
|
|
|
|
if (mComputedHeight > mComputedMaxHeight) {
|
|
|
|
mComputedHeight = mComputedMaxHeight;
|
|
|
|
} else if (mComputedHeight < mComputedMinHeight) {
|
|
|
|
mComputedHeight = mComputedMinHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAdjustForBoxSizing) {
|
|
|
|
// remove extra padding/border if box-sizing property is set
|
|
|
|
switch (mStylePosition->mBoxSizing) {
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING : {
|
|
|
|
mComputedHeight -= mComputedPadding.top + mComputedPadding.bottom;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_STYLE_BOX_SIZING_BORDER : {
|
|
|
|
mComputedHeight -= mComputedBorderPadding.top + mComputedBorderPadding.bottom;
|
|
|
|
}
|
|
|
|
default : break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it did go bozo because of too much border or padding, set to 0
|
|
|
|
if(mComputedHeight < 0) mComputedHeight = 0;
|
|
|
|
}
|
2001-03-06 08:56:19 +03:00
|
|
|
}
|
|
|
|
|
2004-01-06 02:59:25 +03:00
|
|
|
void nsHTMLReflowState::AdjustComputedWidth(PRBool aAdjustForBoxSizing)
|
2001-03-06 08:56:19 +03:00
|
|
|
{
|
|
|
|
// only do the math if the width is not a symbolic value
|
2004-01-06 02:59:25 +03:00
|
|
|
if (mComputedWidth == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mComputedWidth >= 0, "Negative Width Input - very bad");
|
|
|
|
|
|
|
|
// Factor in any minimum and maximum size information
|
|
|
|
if (mComputedWidth > mComputedMaxWidth) {
|
|
|
|
mComputedWidth = mComputedMaxWidth;
|
|
|
|
} else if (mComputedWidth < mComputedMinWidth) {
|
|
|
|
mComputedWidth = mComputedMinWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAdjustForBoxSizing) {
|
|
|
|
// remove extra padding/border if box-sizing property is set
|
|
|
|
switch (mStylePosition->mBoxSizing) {
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING : {
|
|
|
|
mComputedWidth -= mComputedPadding.left + mComputedPadding.right;
|
|
|
|
break;
|
2001-03-06 08:56:19 +03:00
|
|
|
}
|
2004-01-06 02:59:25 +03:00
|
|
|
case NS_STYLE_BOX_SIZING_BORDER : {
|
|
|
|
mComputedWidth -= mComputedBorderPadding.left + mComputedBorderPadding.right;
|
|
|
|
}
|
|
|
|
default : break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it did go bozo because of too much border or padding, set to 0
|
|
|
|
if(mComputedWidth < 0) mComputedWidth = 0;
|
|
|
|
}
|
2001-03-06 08:56:19 +03:00
|
|
|
}
|
2002-07-10 04:52:17 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLReflowState::IsBidiFormControl(nsPresContext* aPresContext)
|
2002-07-10 04:52:17 +04:00
|
|
|
{
|
|
|
|
// This check is only necessary on visual bidi pages, because most
|
|
|
|
// visual pages use logical order for form controls so that they will
|
|
|
|
// display correctly on native widgets in OSs with Bidi support.
|
|
|
|
// So bail out if the page is not Bidi, or not visual, or if the pref is
|
|
|
|
// set to use visual order on forms in visual pages
|
2004-04-13 04:28:44 +04:00
|
|
|
if (!aPresContext->BidiEnabled()) {
|
2002-07-10 04:52:17 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-02-20 20:49:01 +03:00
|
|
|
if (!aPresContext->IsVisualMode()) {
|
2002-07-10 04:52:17 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
PRUint32 options = aPresContext->GetBidi();
|
2002-07-10 04:52:17 +04:00
|
|
|
if (IBMBIDI_CONTROLSTEXTMODE_LOGICAL != GET_BIDI_OPTION_CONTROLSTEXTMODE(options)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIContent* content = frame->GetContent();
|
2002-07-10 04:52:17 +04:00
|
|
|
if (!content) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is a root reflow, we have to walk up the content tree to
|
|
|
|
// find out if the reflow root is a descendant of a form control.
|
|
|
|
// Otherwise, just test this content node
|
|
|
|
if (mReflowDepth == 0) {
|
2003-07-29 01:25:13 +04:00
|
|
|
for ( ; content; content = content->GetParent()) {
|
2003-06-29 07:43:05 +04:00
|
|
|
if (content->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) {
|
2002-07-10 04:52:17 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return (content->IsContentOfType(nsIContent::eHTML_FORM_CONTROL));
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|