2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* struct containing the input to nsIFrame::Reflow */
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
2011-04-07 18:05:49 -07:00
|
|
|
#include "nsFontMetrics.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsLineBox.h"
|
2012-09-29 23:38:46 -07:00
|
|
|
#include "nsFlexContainerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsImageFrame.h"
|
|
|
|
#include "nsTableFrame.h"
|
2007-06-18 16:19:39 -07:00
|
|
|
#include "nsTableCellFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIPercentHeightObserver.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2011-05-24 23:31:59 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBidiUtils.h"
|
2012-04-16 15:32:12 -07:00
|
|
|
#include "nsFontInflationData.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
#undef NOISY_VERTICAL_ALIGN
|
|
|
|
#else
|
|
|
|
#undef NOISY_VERTICAL_ALIGN
|
|
|
|
#endif
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
using namespace mozilla;
|
2012-01-24 17:21:29 -08:00
|
|
|
using namespace mozilla::layout;
|
2010-03-28 18:46:55 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Prefs-driven control for |text-decoration: blink|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sPrefIsLoaded = false;
|
|
|
|
static bool sBlinkIsAllowed = true;
|
2007-03-22 10:30:00 -07: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
|
|
|
|
};
|
|
|
|
|
|
|
|
static eNormalLineHeightControl sNormalLineHeightControl = eUninitialized;
|
|
|
|
|
|
|
|
// Initialize a <b>root</b> reflow state with a rendering context to
|
|
|
|
// use for measuring things.
|
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aRenderingContext,
|
2012-06-13 12:49:41 -07:00
|
|
|
const nsSize& aAvailableSpace,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsCSSOffsetState(aFrame, aRenderingContext)
|
2007-08-20 13:07:50 -07:00
|
|
|
, mBlockDelta(0)
|
2008-02-14 20:14:53 -08:00
|
|
|
, mReflowDepth(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPresContext, "no pres context");
|
|
|
|
NS_PRECONDITION(aRenderingContext, "no rendering context");
|
|
|
|
NS_PRECONDITION(aFrame, "no frame");
|
2012-07-30 07:20:58 -07:00
|
|
|
parentReflowState = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
2012-07-30 07:20:58 -07:00
|
|
|
mFloatManager = nullptr;
|
|
|
|
mLineLayout = nullptr;
|
2012-02-12 13:21:51 -08:00
|
|
|
memset(&mFlags, 0, sizeof(mFlags));
|
2012-07-30 07:20:58 -07:00
|
|
|
mDiscoveredClearance = nullptr;
|
|
|
|
mPercentHeightObserver = nullptr;
|
2012-06-13 12:49:41 -07:00
|
|
|
|
|
|
|
if (aFlags & DUMMY_PARENT_REFLOW_STATE) {
|
|
|
|
mFlags.mDummyParentReflowState = true;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
Init(aPresContext);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool CheckNextInFlowParenthood(nsIFrame* aFrame, nsIFrame* aParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIFrame* frameNext = aFrame->GetNextInFlow();
|
|
|
|
nsIFrame* parentNext = aParent->GetNextInFlow();
|
|
|
|
return frameNext && parentNext && frameNext->GetParent() == parentNext;
|
|
|
|
}
|
|
|
|
|
2012-07-10 08:46:07 -07:00
|
|
|
/**
|
|
|
|
* Adjusts the margin for a list (ol, ul), if necessary, depending on
|
|
|
|
* font inflation settings. Unfortunately, because bullets from a list are
|
|
|
|
* placed in the margin area, we only have ~40px in which to place the
|
|
|
|
* bullets. When they are inflated, however, this causes problems, since
|
|
|
|
* the text takes up more space than is available in the margin.
|
|
|
|
*
|
|
|
|
* This method will return a small amount (in app units) by which the
|
|
|
|
* margin can be adjusted, so that the space is available for list
|
|
|
|
* bullets to be rendered with font inflation enabled.
|
|
|
|
*/
|
|
|
|
static nscoord
|
|
|
|
FontSizeInflationListMarginAdjustment(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(aFrame);
|
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eBlockFrame)) {
|
|
|
|
const nsBlockFrame* blockFrame = static_cast<const nsBlockFrame*>(aFrame);
|
|
|
|
const nsStyleList* styleList = aFrame->GetStyleList();
|
|
|
|
|
|
|
|
// We only want to adjust the margins if we're dealing with an ordered
|
|
|
|
// list.
|
|
|
|
if (inflation > 1.0f &&
|
|
|
|
blockFrame->HasBullet() &&
|
|
|
|
styleList->mListStyleType != NS_STYLE_LIST_STYLE_NONE &&
|
|
|
|
styleList->mListStyleType != NS_STYLE_LIST_STYLE_DISC &&
|
|
|
|
styleList->mListStyleType != NS_STYLE_LIST_STYLE_CIRCLE &&
|
|
|
|
styleList->mListStyleType != NS_STYLE_LIST_STYLE_SQUARE &&
|
|
|
|
inflation > 1.0f) {
|
|
|
|
|
|
|
|
// The HTML spec states that the default padding for ordered lists begins
|
|
|
|
// at 40px, indicating that we have 40px of space to place a bullet. When
|
|
|
|
// performing font inflation calculations, we add space equivalent to this,
|
|
|
|
// but simply inflated at the same amount as the text, in app units.
|
|
|
|
return nsPresContext::CSSPixelsToAppUnits(40) * (inflation - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
// Initialize a reflow state for a child frames reflow. Some state
|
|
|
|
// is copied from the parent reflow state; the remaining state is
|
|
|
|
// computed.
|
|
|
|
nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aParentReflowState,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsSize& aAvailableSpace,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aInit)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsCSSOffsetState(aFrame, aParentReflowState.rendContext)
|
2008-02-14 20:14:53 -08:00
|
|
|
, mBlockDelta(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mReflowDepth(aParentReflowState.mReflowDepth + 1)
|
|
|
|
, mFlags(aParentReflowState.mFlags)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPresContext, "no pres context");
|
|
|
|
NS_PRECONDITION(aFrame, "no frame");
|
|
|
|
NS_PRECONDITION((aContainingBlockWidth == -1) ==
|
|
|
|
(aContainingBlockHeight == -1),
|
|
|
|
"cb width and height should only be non-default together");
|
|
|
|
NS_PRECONDITION(!mFlags.mSpecialHeightReflow ||
|
2007-05-06 12:16:51 -07:00
|
|
|
!NS_SUBTREE_DIRTY(aFrame),
|
2007-03-22 10:30:00 -07:00
|
|
|
"frame should be clean when getting special height reflow");
|
|
|
|
|
|
|
|
parentReflowState = &aParentReflowState;
|
|
|
|
|
|
|
|
// If the parent is dirty, then the child is as well.
|
|
|
|
// XXX Are the other cases where the parent reflows a child a second
|
|
|
|
// time, as a resize?
|
|
|
|
if (!mFlags.mSpecialHeightReflow)
|
|
|
|
frame->AddStateBits(parentReflowState->frame->GetStateBits() &
|
|
|
|
NS_FRAME_IS_DIRTY);
|
|
|
|
|
|
|
|
availableWidth = aAvailableSpace.width;
|
|
|
|
availableHeight = aAvailableSpace.height;
|
|
|
|
|
2009-01-04 16:39:54 -08:00
|
|
|
mFloatManager = aParentReflowState.mFloatManager;
|
2007-05-17 23:04:04 -07:00
|
|
|
if (frame->IsFrameOfType(nsIFrame::eLineParticipant))
|
|
|
|
mLineLayout = aParentReflowState.mLineLayout;
|
|
|
|
else
|
2012-07-30 07:20:58 -07:00
|
|
|
mLineLayout = nullptr;
|
2011-10-21 13:41:12 -07:00
|
|
|
|
|
|
|
// Note: mFlags was initialized as a copy of aParentReflowState.mFlags up in
|
|
|
|
// this constructor's init list, so the only flags that we need to explicitly
|
|
|
|
// initialize here are those that may need a value other than our parent's.
|
2007-03-22 10:30:00 -07:00
|
|
|
mFlags.mNextInFlowUntouched = aParentReflowState.mFlags.mNextInFlowUntouched &&
|
|
|
|
CheckNextInFlowParenthood(aFrame, aParentReflowState.frame);
|
2011-10-17 07:59:28 -07:00
|
|
|
mFlags.mAssumingHScrollbar = mFlags.mAssumingVScrollbar = false;
|
|
|
|
mFlags.mHasClearance = false;
|
2012-02-12 13:21:51 -08:00
|
|
|
mFlags.mIsColumnBalancing = false;
|
2012-09-29 23:38:46 -07:00
|
|
|
mFlags.mIsFlexContainerMeasuringHeight = false;
|
2012-06-13 12:49:41 -07:00
|
|
|
mFlags.mDummyParentReflowState = false;
|
2011-10-21 13:41:12 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mDiscoveredClearance = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
mPercentHeightObserver = (aParentReflowState.mPercentHeightObserver &&
|
|
|
|
aParentReflowState.mPercentHeightObserver->NeedsToObserve(*this))
|
2012-07-30 07:20:58 -07:00
|
|
|
? aParentReflowState.mPercentHeightObserver : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aInit) {
|
|
|
|
Init(aPresContext, aContainingBlockWidth, aContainingBlockHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-03 16:11:00 -07:00
|
|
|
inline nscoord
|
|
|
|
nsCSSOffsetState::ComputeWidthValue(nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContentEdgeToBoxSizing,
|
|
|
|
nscoord aBoxSizingToMarginEdge,
|
|
|
|
const nsStyleCoord& aCoord)
|
|
|
|
{
|
|
|
|
return nsLayoutUtils::ComputeWidthValue(rendContext, frame,
|
|
|
|
aContainingBlockWidth,
|
|
|
|
aContentEdgeToBoxSizing,
|
|
|
|
aBoxSizingToMarginEdge,
|
|
|
|
aCoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsCSSOffsetState::ComputeWidthValue(nscoord aContainingBlockWidth,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aBoxSizing,
|
2007-05-03 16:11:00 -07:00
|
|
|
const nsStyleCoord& aCoord)
|
|
|
|
{
|
|
|
|
nscoord inside = 0, outside = mComputedBorderPadding.LeftRight() +
|
|
|
|
mComputedMargin.LeftRight();
|
|
|
|
switch (aBoxSizing) {
|
|
|
|
case NS_STYLE_BOX_SIZING_BORDER:
|
|
|
|
inside = mComputedBorderPadding.LeftRight();
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING:
|
|
|
|
inside = mComputedPadding.LeftRight();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
outside -= inside;
|
|
|
|
|
|
|
|
return ComputeWidthValue(aContainingBlockWidth, inside,
|
|
|
|
outside, aCoord);
|
|
|
|
}
|
|
|
|
|
2012-08-08 08:58:26 -07:00
|
|
|
nscoord
|
|
|
|
nsCSSOffsetState::ComputeHeightValue(nscoord aContainingBlockHeight,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aBoxSizing,
|
2012-08-08 08:58:26 -07:00
|
|
|
const nsStyleCoord& aCoord)
|
|
|
|
{
|
|
|
|
nscoord inside = 0;
|
|
|
|
switch (aBoxSizing) {
|
|
|
|
case NS_STYLE_BOX_SIZING_BORDER:
|
|
|
|
inside = mComputedBorderPadding.TopBottom();
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING:
|
|
|
|
inside = mComputedPadding.TopBottom();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return nsLayoutUtils::ComputeHeightValue(aContainingBlockHeight,
|
|
|
|
inside, aCoord);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsHTMLReflowState::SetComputedWidth(nscoord aComputedWidth)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(frame, "Must have a frame!");
|
|
|
|
// It'd be nice to assert that |frame| is not in reflow, but this fails for
|
|
|
|
// two reasons:
|
|
|
|
//
|
|
|
|
// 1) Viewport frames reset the computed width on a copy of their reflow
|
|
|
|
// state when reflowing fixed-pos kids. In that case we actually don't
|
|
|
|
// want to mess with the resize flags, because comparing the frame's rect
|
|
|
|
// to the munged computed width is pointless.
|
|
|
|
// 2) nsFrame::BoxReflow creates a reflow state for its parent. This reflow
|
|
|
|
// state is not used to reflow the parent, but just as a parent for the
|
|
|
|
// frame's own reflow state. So given a nsBoxFrame inside some non-XUL
|
|
|
|
// (like a text control, for example), we'll end up creating a reflow
|
|
|
|
// state for the parent while the parent is reflowing.
|
|
|
|
|
2007-05-04 23:13:48 -07:00
|
|
|
NS_PRECONDITION(aComputedWidth >= 0, "Invalid computed width");
|
|
|
|
if (mComputedWidth != aComputedWidth) {
|
|
|
|
mComputedWidth = aComputedWidth;
|
2011-06-10 16:02:14 -07:00
|
|
|
nsIAtom* frameType = frame->GetType();
|
|
|
|
if (frameType != nsGkAtoms::viewportFrame) { // Or check GetParent()?
|
|
|
|
InitResizeFlags(frame->PresContext(), frameType);
|
2007-05-04 23:13:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-02 11:08:05 -07:00
|
|
|
void
|
|
|
|
nsHTMLReflowState::SetComputedHeight(nscoord aComputedHeight)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(frame, "Must have a frame!");
|
2009-01-29 12:39:22 -08:00
|
|
|
// It'd be nice to assert that |frame| is not in reflow, but this fails
|
|
|
|
// because:
|
2007-08-02 11:08:05 -07:00
|
|
|
//
|
2009-01-29 12:39:22 -08:00
|
|
|
// nsFrame::BoxReflow creates a reflow state for its parent. This reflow
|
2007-08-02 11:08:05 -07:00
|
|
|
// state is not used to reflow the parent, but just as a parent for the
|
|
|
|
// frame's own reflow state. So given a nsBoxFrame inside some non-XUL
|
|
|
|
// (like a text control, for example), we'll end up creating a reflow
|
|
|
|
// state for the parent while the parent is reflowing.
|
|
|
|
|
|
|
|
NS_PRECONDITION(aComputedHeight >= 0, "Invalid computed height");
|
|
|
|
if (mComputedHeight != aComputedHeight) {
|
|
|
|
mComputedHeight = aComputedHeight;
|
2011-06-10 16:02:14 -07:00
|
|
|
InitResizeFlags(frame->PresContext(), frame->GetType());
|
2007-08-02 11:08:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsHTMLReflowState::Init(nsPresContext* aPresContext,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
const nsMargin* aBorder,
|
|
|
|
const nsMargin* aPadding)
|
|
|
|
{
|
2009-10-28 20:22:28 -07:00
|
|
|
NS_WARN_IF_FALSE(availableWidth != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mStylePosition = frame->GetStylePosition();
|
|
|
|
mStyleDisplay = frame->GetStyleDisplay();
|
|
|
|
mStyleVisibility = frame->GetStyleVisibility();
|
|
|
|
mStyleBorder = frame->GetStyleBorder();
|
|
|
|
mStyleMargin = frame->GetStyleMargin();
|
|
|
|
mStylePadding = frame->GetStylePadding();
|
|
|
|
mStyleText = frame->GetStyleText();
|
|
|
|
|
2011-06-10 16:02:14 -07:00
|
|
|
nsIAtom* type = frame->GetType();
|
|
|
|
|
|
|
|
InitFrameType(type);
|
2007-03-22 10:30:00 -07:00
|
|
|
InitCBReflowState();
|
|
|
|
|
2011-06-10 16:02:14 -07:00
|
|
|
InitConstraints(aPresContext, aContainingBlockWidth, aContainingBlockHeight,
|
|
|
|
aBorder, aPadding, type);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-10 16:02:14 -07:00
|
|
|
InitResizeFlags(aPresContext, type);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
nsIFrame *parent = frame->GetParent();
|
|
|
|
if (parent &&
|
|
|
|
(parent->GetStateBits() & NS_FRAME_IN_CONSTRAINED_HEIGHT) &&
|
|
|
|
!(parent->GetType() == nsGkAtoms::scrollFrame &&
|
|
|
|
parent->GetStyleDisplay()->mOverflowY != NS_STYLE_OVERFLOW_HIDDEN)) {
|
|
|
|
frame->AddStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
|
2012-06-10 16:44:50 -07:00
|
|
|
} else if (type == nsGkAtoms::svgForeignObjectFrame) {
|
|
|
|
// An SVG foreignObject frame is inherently constrained height.
|
|
|
|
frame->AddStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
|
2012-03-23 20:47:43 -07:00
|
|
|
} else if ((mStylePosition->mHeight.GetUnit() != eStyleUnit_Auto ||
|
|
|
|
mStylePosition->mMaxHeight.GetUnit() != eStyleUnit_None) &&
|
|
|
|
// Don't set NS_FRAME_IN_CONSTRAINED_HEIGHT on body or html
|
|
|
|
// elements.
|
|
|
|
(frame->GetContent() &&
|
|
|
|
!(frame->GetContent()->IsHTML(nsGkAtoms::body) ||
|
|
|
|
frame->GetContent()->IsHTML(nsGkAtoms::html)))) {
|
2012-05-04 10:07:37 -07:00
|
|
|
|
|
|
|
// If our height was specified as a percentage, then this could
|
|
|
|
// actually resolve to 'auto', based on:
|
|
|
|
// http://www.w3.org/TR/CSS21/visudet.html#the-height-property
|
|
|
|
nsIFrame* containingBlk = frame;
|
|
|
|
while (containingBlk) {
|
|
|
|
const nsStylePosition* stylePos = containingBlk->GetStylePosition();
|
|
|
|
if ((stylePos->mHeight.IsCoordPercentCalcUnit() &&
|
|
|
|
!stylePos->mHeight.HasPercent()) ||
|
|
|
|
(stylePos->mMaxHeight.IsCoordPercentCalcUnit() &&
|
|
|
|
!stylePos->mMaxHeight.HasPercent())) {
|
|
|
|
frame->AddStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
|
|
|
|
break;
|
|
|
|
} else if ((stylePos->mHeight.IsCoordPercentCalcUnit() &&
|
|
|
|
stylePos->mHeight.HasPercent()) ||
|
|
|
|
(stylePos->mMaxHeight.IsCoordPercentCalcUnit() &&
|
|
|
|
stylePos->mMaxHeight.HasPercent())) {
|
|
|
|
if (!(containingBlk = containingBlk->GetContainingBlock())) {
|
|
|
|
// If we've reached the top of the tree, then we don't have
|
|
|
|
// a constrained height.
|
|
|
|
frame->RemoveStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
frame->RemoveStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-11-23 18:48:23 -08:00
|
|
|
} else {
|
|
|
|
frame->RemoveStateBits(NS_FRAME_IN_CONSTRAINED_HEIGHT);
|
|
|
|
}
|
|
|
|
|
2009-10-28 20:22:28 -07:00
|
|
|
NS_WARN_IF_FALSE((mFrameType == NS_CSS_FRAME_TYPE_INLINE &&
|
|
|
|
!frame->IsFrameOfType(nsIFrame::eReplaced)) ||
|
2011-06-10 16:02:14 -07:00
|
|
|
type == nsGkAtoms::textFrame ||
|
2009-10-28 20:22:28 -07:00
|
|
|
mComputedWidth != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLReflowState::InitCBReflowState()
|
|
|
|
{
|
|
|
|
if (!parentReflowState) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mCBReflowState = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-11 21:04:30 -07:00
|
|
|
if (parentReflowState->frame == frame->GetContainingBlock()) {
|
|
|
|
// Inner table frames need to use the containing block of the outer
|
|
|
|
// table frame.
|
|
|
|
if (frame->GetType() == nsGkAtoms::tableFrame) {
|
|
|
|
mCBReflowState = parentReflowState->mCBReflowState;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
mCBReflowState = parentReflowState;
|
|
|
|
}
|
2011-05-11 21:04:30 -07:00
|
|
|
} else {
|
|
|
|
mCBReflowState = parentReflowState->mCBReflowState;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-15 14:52:44 -07:00
|
|
|
/* Check whether CalcQuirkContainingBlockHeight would stop on the
|
|
|
|
* given reflow state, using its block as a height. (essentially
|
|
|
|
* returns false for any case in which CalcQuirkContainingBlockHeight
|
|
|
|
* has a "continue" in its main loop.)
|
|
|
|
*
|
|
|
|
* XXX Maybe refactor CalcQuirkContainingBlockHeight so it uses
|
|
|
|
* this function as well
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-06-10 16:02:14 -07:00
|
|
|
IsQuirkContainingBlockHeight(const nsHTMLReflowState* rs, nsIAtom* aFrameType)
|
2007-05-15 14:52:44 -07:00
|
|
|
{
|
2011-06-10 16:02:14 -07:00
|
|
|
if (nsGkAtoms::blockFrame == aFrameType ||
|
2008-12-29 07:07:38 -08:00
|
|
|
#ifdef MOZ_XUL
|
2011-06-10 16:02:14 -07:00
|
|
|
nsGkAtoms::XULLabelFrame == aFrameType ||
|
2008-12-29 07:07:38 -08:00
|
|
|
#endif
|
2011-06-10 16:02:14 -07:00
|
|
|
nsGkAtoms::scrollFrame == aFrameType) {
|
2007-05-15 14:52:44 -07:00
|
|
|
// Note: This next condition could change due to a style change,
|
|
|
|
// but that would cause a style reflow anyway, which means we're ok.
|
2007-08-02 11:08:05 -07:00
|
|
|
if (NS_AUTOHEIGHT == rs->ComputedHeight()) {
|
2012-08-02 04:38:50 -07:00
|
|
|
if (!rs->frame->IsAbsolutelyPositioned()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-05-15 14:52:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-05-15 14:52:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2011-06-10 16:02:14 -07:00
|
|
|
nsHTMLReflowState::InitResizeFlags(nsPresContext* aPresContext, nsIAtom* aFrameType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-11 13:57:35 -07:00
|
|
|
bool isHResize = frame->GetSize().width !=
|
|
|
|
mComputedWidth + mComputedBorderPadding.LeftRight();
|
|
|
|
|
|
|
|
if ((frame->GetStateBits() & NS_FRAME_FONT_INFLATION_FLOW_ROOT) &&
|
2012-06-10 17:36:18 -07:00
|
|
|
nsLayoutUtils::FontSizeInflationEnabled(aPresContext)) {
|
2012-06-11 13:57:35 -07:00
|
|
|
// Create our font inflation data if we don't have it already, and
|
|
|
|
// give it our current width information.
|
2012-06-13 12:49:41 -07:00
|
|
|
bool dirty = nsFontInflationData::UpdateFontInflationDataWidthFor(*this) &&
|
|
|
|
// Avoid running this at the box-to-block interface
|
|
|
|
// (where we shouldn't be inflating anyway, and where
|
|
|
|
// reflow state construction is probably to construct a
|
|
|
|
// dummy parent reflow state anyway).
|
|
|
|
!mFlags.mDummyParentReflowState;
|
|
|
|
|
2012-06-11 13:57:35 -07:00
|
|
|
if (dirty || (!frame->GetParent() && isHResize)) {
|
|
|
|
// When font size inflation is enabled, a change in either:
|
|
|
|
// * the effective width of a font inflation flow root
|
|
|
|
// * the width of the frame
|
|
|
|
// needs to cause a dirty reflow since they change the font size
|
|
|
|
// inflation calculations, which in turn change the size of text,
|
|
|
|
// line-heights, etc. This is relatively similar to a classic
|
|
|
|
// case of style change reflow, except that because inflation
|
|
|
|
// doesn't affect the intrinsic sizing codepath, there's no need
|
|
|
|
// to invalidate intrinsic sizes.
|
|
|
|
//
|
|
|
|
// Note that this makes horizontal resizing a good bit more
|
|
|
|
// expensive. However, font size inflation is targeted at a set of
|
|
|
|
// devices (zoom-and-pan devices) where the main use case for
|
|
|
|
// horizontal resizing needing to be efficient (window resizing) is
|
|
|
|
// not present. It does still increase the cost of dynamic changes
|
|
|
|
// caused by script where a style or content change in one place
|
|
|
|
// causes a resize in another (e.g., rebalancing a table).
|
|
|
|
|
|
|
|
// FIXME: This isn't so great for the cases where
|
|
|
|
// nsHTMLReflowState::SetComputedWidth is called, if the first time
|
|
|
|
// we go through InitResizeFlags we set mHResize to true, and then
|
|
|
|
// the second time we'd set it to false even without the
|
|
|
|
// NS_FRAME_IS_DIRTY bit already set.
|
|
|
|
if (frame->GetType() == nsGkAtoms::svgForeignObjectFrame) {
|
|
|
|
// Foreign object frames use dirty bits in a special way.
|
|
|
|
frame->AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
nsIFrame *kid = frame->GetFirstPrincipalChild();
|
|
|
|
if (kid) {
|
|
|
|
kid->AddStateBits(NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
frame->AddStateBits(NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
2012-06-11 13:57:35 -07:00
|
|
|
|
|
|
|
// Mark intrinsic widths on all descendants dirty. We need to do
|
|
|
|
// this (1) since we're changing the size of text and need to
|
|
|
|
// clear text runs on text frames and (2) since we actually are
|
|
|
|
// changing some intrinsic widths, but only those that live inside
|
|
|
|
// of containers.
|
|
|
|
|
|
|
|
// It makes sense to do this for descendants but not ancestors
|
|
|
|
// (which is unusual) because we're only changing the unusual
|
|
|
|
// inflation-dependent intrinsic widths (i.e., ones computed with
|
|
|
|
// nsPresContext::mInflationDisabledForShrinkWrap set to false),
|
|
|
|
// which should never affect anything outside of their inflation
|
|
|
|
// flow root (or, for that matter, even their inflation
|
|
|
|
// container).
|
|
|
|
|
|
|
|
// This is also different from what PresShell::FrameNeedsReflow
|
|
|
|
// does because it doesn't go through placeholders. It doesn't
|
|
|
|
// need to because we're actually doing something that cares about
|
|
|
|
// frame tree geometry (the width on an ancestor) rather than
|
|
|
|
// style.
|
|
|
|
|
|
|
|
nsAutoTArray<nsIFrame*, 32> stack;
|
|
|
|
stack.AppendElement(frame);
|
|
|
|
|
|
|
|
do {
|
|
|
|
nsIFrame *f = stack.ElementAt(stack.Length() - 1);
|
|
|
|
stack.RemoveElementAt(stack.Length() - 1);
|
|
|
|
|
|
|
|
nsIFrame::ChildListIterator lists(f);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
|
|
|
nsIFrame* kid = childFrames.get();
|
|
|
|
kid->MarkIntrinsicWidthsDirty();
|
|
|
|
stack.AppendElement(kid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (stack.Length() != 0);
|
2012-06-11 13:57:35 -07:00
|
|
|
}
|
2012-06-10 17:36:18 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-11 13:57:35 -07:00
|
|
|
mFlags.mHResize = !(frame->GetStateBits() & NS_FRAME_IS_DIRTY) &&
|
|
|
|
isHResize;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX Should we really need to null check mCBReflowState? (We do for
|
|
|
|
// at least nsBoxFrame).
|
2011-06-10 16:02:14 -07:00
|
|
|
if (IS_TABLE_CELL(aFrameType) &&
|
2007-06-18 16:19:39 -07:00
|
|
|
(mFlags.mSpecialHeightReflow ||
|
|
|
|
(frame->GetFirstInFlow()->GetStateBits() &
|
|
|
|
NS_TABLE_CELL_HAD_SPECIAL_REFLOW)) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(frame->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT)) {
|
2007-06-18 16:19:39 -07:00
|
|
|
// Need to set the bit on the cell so that
|
|
|
|
// mCBReflowState->mFlags.mVResize is set correctly below when
|
|
|
|
// reflowing descendant.
|
2011-10-17 07:59:28 -07:00
|
|
|
mFlags.mVResize = true;
|
2011-05-11 21:04:30 -07:00
|
|
|
} else if (mCBReflowState && !nsLayoutUtils::IsNonWrapperBlock(frame)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX Is this problematic for relatively positioned inlines acting
|
|
|
|
// as containing block for absolutely positioned elements?
|
2010-03-03 15:53:18 -08:00
|
|
|
// Possibly; in that case we should at least be checking
|
|
|
|
// NS_SUBTREE_DIRTY, I'd think.
|
2007-03-22 10:30:00 -07:00
|
|
|
mFlags.mVResize = mCBReflowState->mFlags.mVResize;
|
|
|
|
} else if (mComputedHeight == NS_AUTOHEIGHT) {
|
|
|
|
if (eCompatibility_NavQuirks == aPresContext->CompatibilityMode() &&
|
|
|
|
mCBReflowState) {
|
|
|
|
mFlags.mVResize = mCBReflowState->mFlags.mVResize;
|
|
|
|
} else {
|
2009-10-12 15:27:24 -07:00
|
|
|
mFlags.mVResize = mFlags.mHResize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-10-12 15:27:24 -07:00
|
|
|
mFlags.mVResize = mFlags.mVResize || NS_SUBTREE_DIRTY(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// not 'auto' height
|
|
|
|
mFlags.mVResize = frame->GetSize().height !=
|
|
|
|
mComputedHeight + mComputedBorderPadding.TopBottom();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dependsOnCBHeight =
|
2010-08-25 03:17:55 -07:00
|
|
|
(mStylePosition->HeightDependsOnContainer() &&
|
|
|
|
// FIXME: condition this on not-abspos?
|
|
|
|
mStylePosition->mHeight.GetUnit() != eStyleUnit_Auto) ||
|
2012-07-27 15:52:40 -07:00
|
|
|
mStylePosition->MinHeightDependsOnContainer() ||
|
|
|
|
mStylePosition->MaxHeightDependsOnContainer() ||
|
2010-08-25 03:17:56 -07:00
|
|
|
mStylePosition->OffsetHasPercent(NS_SIDE_TOP) ||
|
2007-12-04 19:05:57 -08:00
|
|
|
mStylePosition->mOffset.GetBottomUnit() != eStyleUnit_Auto ||
|
2011-06-12 18:52:32 -07:00
|
|
|
frame->IsBoxFrame();
|
2007-06-18 16:19:39 -07:00
|
|
|
|
2009-06-19 18:39:40 -07:00
|
|
|
if (mStyleText->mLineHeight.GetUnit() == eStyleUnit_Enumerated) {
|
|
|
|
NS_ASSERTION(mStyleText->mLineHeight.GetIntValue() ==
|
|
|
|
NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT,
|
|
|
|
"bad line-height value");
|
|
|
|
|
|
|
|
// line-height depends on block height
|
|
|
|
frame->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_HEIGHT);
|
|
|
|
// but only on containing blocks if this frame is not a suitable block
|
2011-05-11 21:04:30 -07:00
|
|
|
dependsOnCBHeight |= !nsLayoutUtils::IsNonWrapperBlock(frame);
|
2009-06-19 18:39:40 -07:00
|
|
|
}
|
|
|
|
|
2008-02-21 13:02:07 -08:00
|
|
|
// If we're the descendant of a table cell that performs special height
|
2007-06-18 16:19:39 -07:00
|
|
|
// reflows and we could be the child that requires them, always set
|
|
|
|
// the vertical resize in case this is the first pass before the
|
2008-11-25 13:27:53 -08:00
|
|
|
// special height reflow. However, don't do this if it actually is
|
|
|
|
// the special height reflow, since in that case it will already be
|
|
|
|
// set correctly above if we need it set.
|
2007-06-18 16:19:39 -07:00
|
|
|
if (!mFlags.mVResize && mCBReflowState &&
|
2008-02-21 13:02:07 -08:00
|
|
|
(IS_TABLE_CELL(mCBReflowState->frame->GetType()) ||
|
|
|
|
mCBReflowState->mFlags.mHeightDependsOnAncestorCell) &&
|
2008-11-25 13:27:53 -08:00
|
|
|
!mCBReflowState->mFlags.mSpecialHeightReflow &&
|
2008-02-21 13:02:07 -08:00
|
|
|
dependsOnCBHeight) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mFlags.mVResize = true;
|
|
|
|
mFlags.mHeightDependsOnAncestorCell = true;
|
2008-02-21 13:02:07 -08:00
|
|
|
}
|
2007-06-18 16:19:39 -07:00
|
|
|
|
|
|
|
// Set NS_FRAME_CONTAINS_RELATIVE_HEIGHT if it's needed.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// It would be nice to check that |mComputedHeight != NS_AUTOHEIGHT|
|
|
|
|
// &&ed with the percentage height check. However, this doesn't get
|
|
|
|
// along with table special height reflows, since a special height
|
|
|
|
// reflow (a quirk that makes such percentage heights work on children
|
|
|
|
// of table cells) can cause not just a single percentage height to
|
|
|
|
// become fixed, but an entire descendant chain of percentage heights
|
|
|
|
// to become fixed.
|
2007-06-18 16:19:39 -07:00
|
|
|
if (dependsOnCBHeight && mCBReflowState) {
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsHTMLReflowState *rs = this;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hitCBReflowState = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
do {
|
|
|
|
rs = rs->parentReflowState;
|
2007-05-15 14:52:44 -07:00
|
|
|
if (!rs) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rs->frame->GetStateBits() & NS_FRAME_CONTAINS_RELATIVE_HEIGHT)
|
|
|
|
break; // no need to go further
|
|
|
|
rs->frame->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_HEIGHT);
|
2007-05-15 14:52:44 -07:00
|
|
|
|
|
|
|
// Keep track of whether we've hit the containing block, because
|
|
|
|
// we need to go at least that far.
|
|
|
|
if (rs == mCBReflowState) {
|
2011-10-17 07:59:28 -07:00
|
|
|
hitCBReflowState = true;
|
2007-05-15 14:52:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-15 14:52:44 -07:00
|
|
|
} while (!hitCBReflowState ||
|
|
|
|
(eCompatibility_NavQuirks == aPresContext->CompatibilityMode() &&
|
2011-06-10 16:02:14 -07:00
|
|
|
!IsQuirkContainingBlockHeight(rs, rs->frame->GetType())));
|
2007-05-15 14:52:44 -07:00
|
|
|
// Note: We actually don't need to set the
|
|
|
|
// NS_FRAME_CONTAINS_RELATIVE_HEIGHT bit for the cases
|
|
|
|
// where we hit the early break statements in
|
|
|
|
// CalcQuirkContainingBlockHeight. But it doesn't hurt
|
|
|
|
// us to set the bit in these cases.
|
|
|
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (frame->GetStateBits() & NS_FRAME_IS_DIRTY) {
|
|
|
|
// If we're reflowing everything, then we'll find out if we need
|
|
|
|
// to re-set this.
|
|
|
|
frame->RemoveStateBits(NS_FRAME_CONTAINS_RELATIVE_HEIGHT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
nscoord
|
|
|
|
nsHTMLReflowState::GetContainingBlockContentWidth(const nsHTMLReflowState* aReflowState)
|
|
|
|
{
|
|
|
|
const nsHTMLReflowState* rs = aReflowState->mCBReflowState;
|
|
|
|
if (!rs)
|
|
|
|
return 0;
|
|
|
|
return rs->mComputedWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-10 16:02:14 -07:00
|
|
|
nsHTMLReflowState::InitFrameType(nsIAtom* aFrameType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const nsStyleDisplay *disp = mStyleDisplay;
|
|
|
|
nsCSSFrameType frameType;
|
|
|
|
|
|
|
|
// Section 9.7 of the CSS2 spec indicates that absolute position
|
|
|
|
// takes precedence over float which takes precedence over display.
|
|
|
|
// XXXldb nsRuleNode::ComputeDisplayData should take care of this, right?
|
2009-02-24 10:38:20 -08:00
|
|
|
// Make sure the frame was actually moved out of the flow, and don't
|
|
|
|
// just assume what the style says, because we might not have had a
|
|
|
|
// useful float/absolute containing block
|
2010-05-01 14:40:16 -07:00
|
|
|
|
2011-05-09 17:36:10 -07:00
|
|
|
DISPLAY_INIT_TYPE(frame, this);
|
2010-05-01 14:40:16 -07:00
|
|
|
|
2011-06-10 16:02:14 -07:00
|
|
|
if (aFrameType == nsGkAtoms::tableFrame) {
|
2011-05-09 17:36:10 -07:00
|
|
|
mFrameType = NS_CSS_FRAME_TYPE_BLOCK;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-02 04:38:50 -07:00
|
|
|
NS_ASSERTION(frame->GetStyleDisplay()->IsAbsolutelyPositionedStyle() ==
|
|
|
|
disp->IsAbsolutelyPositionedStyle(),
|
2009-02-24 10:38:20 -08:00
|
|
|
"Unexpected position style");
|
2012-08-02 04:38:49 -07:00
|
|
|
NS_ASSERTION(frame->GetStyleDisplay()->IsFloatingStyle() ==
|
|
|
|
disp->IsFloatingStyle(), "Unexpected float style");
|
2011-05-09 17:36:10 -07:00
|
|
|
if (frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) {
|
2012-08-02 04:38:50 -07:00
|
|
|
if (disp->IsAbsolutelyPositioned(frame)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
frameType = NS_CSS_FRAME_TYPE_ABSOLUTE;
|
2007-10-01 22:57:45 -07:00
|
|
|
//XXXfr hack for making frames behave properly when in overflow container lists
|
|
|
|
// see bug 154892; need to revisit later
|
2011-05-09 17:36:10 -07:00
|
|
|
if (frame->GetPrevInFlow())
|
2007-10-01 22:57:45 -07:00
|
|
|
frameType = NS_CSS_FRAME_TYPE_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-02 04:38:49 -07:00
|
|
|
else if (disp->IsFloating(frame)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
frameType = NS_CSS_FRAME_TYPE_FLOATING;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(disp->mDisplay == NS_STYLE_DISPLAY_POPUP,
|
|
|
|
"unknown out of flow frame type");
|
|
|
|
frameType = NS_CSS_FRAME_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-08-02 04:38:51 -07:00
|
|
|
switch (GetDisplay()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_STYLE_DISPLAY_BLOCK:
|
|
|
|
case NS_STYLE_DISPLAY_LIST_ITEM:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_CAPTION:
|
2012-09-29 23:38:46 -07:00
|
|
|
#ifdef MOZ_FLEXBOX
|
|
|
|
case NS_STYLE_DISPLAY_FLEX:
|
|
|
|
#endif // MOZ_FLEXBOX
|
2007-03-22 10:30:00 -07:00
|
|
|
frameType = NS_CSS_FRAME_TYPE_BLOCK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_INLINE:
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_BLOCK:
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_TABLE:
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_BOX:
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_GRID:
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_STACK:
|
2012-09-29 23:38:46 -07:00
|
|
|
#ifdef MOZ_FLEXBOX
|
|
|
|
case NS_STYLE_DISPLAY_INLINE_FLEX:
|
|
|
|
#endif // MOZ_FLEXBOX
|
2007-03-22 10:30:00 -07:00
|
|
|
frameType = NS_CSS_FRAME_TYPE_INLINE;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the frame is replaced
|
|
|
|
if (frame->IsFrameOfType(nsIFrame::eReplacedContainsBlock)) {
|
|
|
|
frameType = NS_FRAME_REPLACED_CONTAINS_BLOCK(frameType);
|
|
|
|
} else if (frame->IsFrameOfType(nsIFrame::eReplaced)) {
|
|
|
|
frameType = NS_FRAME_REPLACED(frameType);
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrameType = frameType;
|
|
|
|
}
|
|
|
|
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
/* static */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLReflowState::ComputeRelativeOffsets(uint8_t aCBDirection,
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
nsIFrame* aFrame,
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord aContainingBlockWidth,
|
2008-04-18 00:40:35 -07:00
|
|
|
nscoord aContainingBlockHeight,
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
nsMargin& aComputedOffsets)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
const nsStylePosition* position = aFrame->GetStylePosition();
|
|
|
|
|
2007-03-22 10:30:00 -07: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
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
bool leftIsAuto = eStyleUnit_Auto == position->mOffset.GetLeftUnit();
|
|
|
|
bool rightIsAuto = eStyleUnit_Auto == position->mOffset.GetRightUnit();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If neither 'left' not 'right' are auto, then we're over-constrained and
|
|
|
|
// we ignore one of them
|
|
|
|
if (!leftIsAuto && !rightIsAuto) {
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
if (aCBDirection == NS_STYLE_DIRECTION_RTL) {
|
2011-10-17 07:59:28 -07:00
|
|
|
leftIsAuto = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
rightIsAuto = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leftIsAuto) {
|
|
|
|
if (rightIsAuto) {
|
|
|
|
// If both are 'auto' (their initial values), the computed values are 0
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.left = aComputedOffsets.right = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// 'Right' isn't 'auto' so compute its value
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.right = nsLayoutUtils::
|
2008-07-17 16:37:12 -07:00
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
position->mOffset.GetRight());
|
2008-07-17 16:37:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Computed value for 'left' is minus the value of 'right'
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.left = -aComputedOffsets.right;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(rightIsAuto, "unexpected specified constraint");
|
|
|
|
|
|
|
|
// 'Left' isn't 'auto' so compute its value
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.left = nsLayoutUtils::
|
2008-07-17 16:37:12 -07:00
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
position->mOffset.GetLeft());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Computed value for 'right' is minus the value of 'left'
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.right = -aComputedOffsets.left;
|
2007-03-22 10:30:00 -07: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
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
bool topIsAuto = eStyleUnit_Auto == position->mOffset.GetTopUnit();
|
|
|
|
bool bottomIsAuto = eStyleUnit_Auto == position->mOffset.GetBottomUnit();
|
2007-03-22 10:30:00 -07: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) {
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
if (position->OffsetHasPercent(NS_SIDE_TOP)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
topIsAuto = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
if (position->OffsetHasPercent(NS_SIDE_BOTTOM)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
bottomIsAuto = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If neither is 'auto', 'bottom' is ignored
|
|
|
|
if (!topIsAuto && !bottomIsAuto) {
|
2011-10-17 07:59:28 -07:00
|
|
|
bottomIsAuto = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (topIsAuto) {
|
|
|
|
if (bottomIsAuto) {
|
|
|
|
// If both are 'auto' (their initial values), the computed values are 0
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.top = aComputedOffsets.bottom = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// 'Bottom' isn't 'auto' so compute its value
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.bottom = nsLayoutUtils::
|
2008-07-17 16:37:12 -07:00
|
|
|
ComputeHeightDependentValue(aContainingBlockHeight,
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
position->mOffset.GetBottom());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Computed value for 'top' is minus the value of 'bottom'
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.top = -aComputedOffsets.bottom;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(bottomIsAuto, "unexpected specified constraint");
|
|
|
|
|
|
|
|
// 'Top' isn't 'auto' so compute its value
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.top = nsLayoutUtils::
|
2008-07-17 16:37:12 -07:00
|
|
|
ComputeHeightDependentValue(aContainingBlockHeight,
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
position->mOffset.GetTop());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Computed value for 'bottom' is minus the value of 'top'
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
aComputedOffsets.bottom = -aComputedOffsets.top;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-04-18 00:40:35 -07:00
|
|
|
|
|
|
|
// Store the offset
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
FrameProperties props = aFrame->Properties();
|
2008-04-18 00:40:35 -07:00
|
|
|
nsPoint* offsets = static_cast<nsPoint*>
|
2010-03-28 18:46:55 -07:00
|
|
|
(props.Get(nsIFrame::ComputedOffsetProperty()));
|
|
|
|
if (offsets) {
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
offsets->MoveTo(aComputedOffsets.left, aComputedOffsets.top);
|
2010-03-28 18:46:55 -07:00
|
|
|
} else {
|
|
|
|
props.Set(nsIFrame::ComputedOffsetProperty(),
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
new nsPoint(aComputedOffsets.left, aComputedOffsets.top));
|
2008-04-18 00:40:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
2008-11-25 15:22:39 -08:00
|
|
|
nsHTMLReflowState::GetHypotheticalBoxContainer(nsIFrame* aFrame,
|
|
|
|
nscoord& aCBLeftEdge,
|
|
|
|
nscoord& aCBWidth)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-05-11 21:04:30 -07:00
|
|
|
aFrame = aFrame->GetContainingBlock();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(aFrame != frame, "How did that happen?");
|
|
|
|
|
|
|
|
/* Now aFrame is the containing block we want */
|
|
|
|
|
2009-07-27 01:47:02 -07:00
|
|
|
/* Check whether the containing block is currently being reflowed.
|
2007-03-22 10:30:00 -07:00
|
|
|
If so, use the info from the reflow state. */
|
|
|
|
const nsHTMLReflowState* state;
|
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_IN_REFLOW) {
|
|
|
|
for (state = parentReflowState; state && state->frame != aFrame;
|
|
|
|
state = state->parentReflowState) {
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
state = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
aCBLeftEdge = state->mComputedBorderPadding.left;
|
|
|
|
aCBWidth = state->mComputedWidth;
|
|
|
|
} else {
|
|
|
|
/* Didn't find a reflow state for aFrame. Just compute the information we
|
|
|
|
want, on the assumption that aFrame already knows its size. This really
|
|
|
|
ought to be true by now. */
|
|
|
|
NS_ASSERTION(!(aFrame->GetStateBits() & NS_FRAME_IN_REFLOW),
|
|
|
|
"aFrame shouldn't be in reflow; we'll lie if it is");
|
|
|
|
nsMargin borderPadding = aFrame->GetUsedBorderAndPadding();
|
|
|
|
aCBLeftEdge = borderPadding.left;
|
|
|
|
aCBWidth = aFrame->GetSize().width - borderPadding.LeftRight();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2008-02-25 13:16:21 -08:00
|
|
|
// offsets from left edge of containing block (which is a padding edge)
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord mLeft, mRight;
|
2008-02-25 13:16:21 -08:00
|
|
|
// offset from top edge of containing block (which is a padding edge)
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord mTop;
|
2008-06-03 15:25:31 -07:00
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mLeftIsExact, mRightIsExact;
|
2008-06-03 15:25:31 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsHypotheticalBox() {
|
2008-06-03 15:25:31 -07:00
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
mLeftIsExact = mRightIsExact = false;
|
2008-06-03 15:25:31 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-06-10 16:02:14 -07:00
|
|
|
GetIntrinsicSizeFor(nsIFrame* aFrame, nsSize& aIntrinsicSize, nsIAtom* aFrameType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// See if it is an image frame
|
2011-09-28 23:19:26 -07:00
|
|
|
bool success = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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...
|
2011-06-10 16:02:14 -07:00
|
|
|
if (aFrameType == nsGkAtoms::imageFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsImageFrame* imageFrame = (nsImageFrame*)aFrame;
|
|
|
|
|
2010-09-08 13:40:38 -07:00
|
|
|
if (NS_SUCCEEDED(imageFrame->GetIntrinsicImageSize(aIntrinsicSize))) {
|
|
|
|
success = (aIntrinsicSize != nsSize(0, 0));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-09-08 13:40:38 -07:00
|
|
|
return success;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-03 16:11:00 -07:00
|
|
|
/**
|
|
|
|
* aInsideBoxSizing returns the part of the horizontal padding, border,
|
|
|
|
* and margin that goes inside the edge given by -moz-box-sizing;
|
|
|
|
* aOutsideBoxSizing returns the rest.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::CalculateHorizBorderPaddingMargin(
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord* aInsideBoxSizing,
|
|
|
|
nscoord* aOutsideBoxSizing)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-30 22:19:49 -07:00
|
|
|
const nsMargin& border = mStyleBorder->GetComputedBorder();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMargin padding, margin;
|
|
|
|
|
|
|
|
// See if the style system can provide us the padding directly
|
|
|
|
if (!mStylePadding->GetPadding(padding)) {
|
|
|
|
// We have to compute the left and right values
|
2008-07-17 16:37:12 -07:00
|
|
|
padding.left = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
|
|
|
mStylePadding->mPadding.GetLeft());
|
|
|
|
padding.right = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
|
|
|
mStylePadding->mPadding.GetRight());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if the style system can provide us the margin directly
|
|
|
|
if (!mStyleMargin->GetMargin(margin)) {
|
|
|
|
// We have to compute the left and right values
|
|
|
|
if (eStyleUnit_Auto == mStyleMargin->mMargin.GetLeftUnit()) {
|
|
|
|
// XXX FIXME (or does CalculateBlockSideMargins do this?)
|
|
|
|
margin.left = 0; // just ignore
|
|
|
|
} else {
|
2008-07-17 16:37:12 -07:00
|
|
|
margin.left = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
|
|
|
mStyleMargin->mMargin.GetLeft());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (eStyleUnit_Auto == mStyleMargin->mMargin.GetRightUnit()) {
|
|
|
|
// XXX FIXME (or does CalculateBlockSideMargins do this?)
|
|
|
|
margin.right = 0; // just ignore
|
|
|
|
} else {
|
2008-07-17 16:37:12 -07:00
|
|
|
margin.right = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
|
|
|
mStyleMargin->mMargin.GetRight());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-03 16:11:00 -07:00
|
|
|
nscoord outside =
|
|
|
|
padding.LeftRight() + border.LeftRight() + margin.LeftRight();
|
|
|
|
nscoord inside = 0;
|
|
|
|
switch (mStylePosition->mBoxSizing) {
|
|
|
|
case NS_STYLE_BOX_SIZING_BORDER:
|
|
|
|
inside += border.LeftRight();
|
|
|
|
// fall through
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING:
|
|
|
|
inside += padding.LeftRight();
|
|
|
|
}
|
|
|
|
outside -= inside;
|
|
|
|
*aInsideBoxSizing = inside;
|
|
|
|
*aOutsideBoxSizing = outside;
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* Returns true iff a pre-order traversal of the normal child
|
2007-03-22 10:30:00 -07:00
|
|
|
* frames rooted at aFrame finds no non-empty frame before aDescendant.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool AreAllEarlierInFlowFramesEmpty(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aDescendant, bool* aFound) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aFrame == aDescendant) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aFound = true;
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (!aFrame->IsSelfEmpty()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aFound = false;
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-24 13:54:30 -07:00
|
|
|
for (nsIFrame* f = aFrame->GetFirstPrincipalChild(); f; f = f->GetNextSibling()) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allEmpty = AreAllEarlierInFlowFramesEmpty(f, aDescendant, aFound);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (*aFound || !allEmpty) {
|
|
|
|
return allEmpty;
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
*aFound = false;
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07: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
|
2008-11-25 15:22:39 -08:00
|
|
|
// aContainingBlock is the placeholder's containing block (XXX rename it?)
|
|
|
|
// cbrs->frame is the actual containing block
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsHTMLReflowState::CalculateHypotheticalBox(nsPresContext* aPresContext,
|
2011-11-06 21:25:56 -08:00
|
|
|
nsIFrame* aPlaceholderFrame,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aContainingBlock,
|
|
|
|
nscoord aBlockLeftContentEdge,
|
|
|
|
nscoord aBlockContentWidth,
|
|
|
|
const nsHTMLReflowState* cbrs,
|
2011-06-10 16:02:14 -07:00
|
|
|
nsHypotheticalBox& aHypotheticalBox,
|
|
|
|
nsIAtom* aFrameType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mStyleDisplay->mOriginalDisplay != NS_STYLE_DISPLAY_NONE,
|
|
|
|
"mOriginalDisplay has not been properly initialized");
|
|
|
|
|
|
|
|
// 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
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isAutoWidth = mStylePosition->mWidth.GetUnit() == eStyleUnit_Auto;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize intrinsicSize;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool knowIntrinsicSize = false;
|
2007-05-03 16:11:00 -07:00
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType) && isAutoWidth) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// See if we can get the intrinsic size of the element
|
2011-06-10 16:02:14 -07:00
|
|
|
knowIntrinsicSize = GetIntrinsicSizeFor(frame, intrinsicSize, aFrameType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if we can calculate what the box width would have been if the
|
|
|
|
// element had been in the flow
|
|
|
|
nscoord boxWidth;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool knowBoxWidth = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((NS_STYLE_DISPLAY_INLINE == mStyleDisplay->mOriginalDisplay) &&
|
|
|
|
!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
|
|
|
|
|
|
|
|
// 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
|
2007-05-03 16:11:00 -07:00
|
|
|
nscoord insideBoxSizing, outsideBoxSizing;
|
|
|
|
CalculateHorizBorderPaddingMargin(aBlockContentWidth,
|
|
|
|
&insideBoxSizing, &outsideBoxSizing);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-03 16:11:00 -07:00
|
|
|
if (NS_FRAME_IS_REPLACED(mFrameType) && isAutoWidth) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// It's a replaced element with an 'auto' width so the box width is
|
|
|
|
// its intrinsic size plus any border/padding/margin
|
|
|
|
if (knowIntrinsicSize) {
|
2007-05-03 16:11:00 -07:00
|
|
|
boxWidth = intrinsicSize.width + outsideBoxSizing + insideBoxSizing;
|
2011-10-17 07:59:28 -07:00
|
|
|
knowBoxWidth = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-03 16:11:00 -07:00
|
|
|
} else if (isAutoWidth) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The box width is the containing block width
|
|
|
|
boxWidth = aBlockContentWidth;
|
2011-10-17 07:59:28 -07:00
|
|
|
knowBoxWidth = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// We need to compute it. It's important we do this, because if it's
|
2008-02-25 13:16:21 -08:00
|
|
|
// percentage based this computed value may be different from the computed
|
2007-03-22 10:30:00 -07:00
|
|
|
// value calculated using the absolute containing block width
|
2007-05-03 16:11:00 -07:00
|
|
|
boxWidth = ComputeWidthValue(aBlockContentWidth,
|
|
|
|
insideBoxSizing, outsideBoxSizing,
|
|
|
|
mStylePosition->mWidth) +
|
|
|
|
insideBoxSizing + outsideBoxSizing;
|
2011-10-17 07:59:28 -07:00
|
|
|
knowBoxWidth = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the 'direction' of the block
|
|
|
|
const nsStyleVisibility* blockVis = aContainingBlock->GetStyleVisibility();
|
|
|
|
|
|
|
|
// Get the placeholder x-offset and y-offset in the coordinate
|
2010-04-01 19:09:05 -07:00
|
|
|
// space of its containing block
|
2009-07-27 01:47:02 -07:00
|
|
|
// XXXbz the placeholder is not fully reflowed yet if our containing block is
|
2007-03-22 10:30:00 -07:00
|
|
|
// relatively positioned...
|
|
|
|
nsPoint placeholderOffset = aPlaceholderFrame->GetOffsetTo(aContainingBlock);
|
|
|
|
|
2010-04-01 19:09:05 -07:00
|
|
|
// First, determine the hypothetical box's mTop. We want to check the
|
|
|
|
// content insertion frame of aContainingBlock for block-ness, but make
|
|
|
|
// sure to compute all coordinates in the coordinate system of
|
|
|
|
// aContainingBlock.
|
|
|
|
nsBlockFrame* blockFrame =
|
|
|
|
nsLayoutUtils::GetAsBlock(aContainingBlock->GetContentInsertionFrame());
|
2008-07-13 15:10:23 -07:00
|
|
|
if (blockFrame) {
|
2010-04-01 19:09:05 -07:00
|
|
|
nscoord blockYOffset = blockFrame->GetOffsetTo(aContainingBlock).y;
|
2011-11-06 21:25:56 -08:00
|
|
|
bool isValid;
|
|
|
|
nsBlockInFlowLineIterator iter(blockFrame, aPlaceholderFrame, &isValid);
|
|
|
|
if (!isValid) {
|
2010-10-06 21:25:47 -07:00
|
|
|
// Give up. We're probably dealing with somebody using
|
|
|
|
// position:absolute inside native-anonymous content anyway.
|
|
|
|
aHypotheticalBox.mTop = placeholderOffset.y;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2011-11-06 21:25:56 -08:00
|
|
|
NS_ASSERTION(iter.GetContainer() == blockFrame,
|
|
|
|
"Found placeholder in wrong block!");
|
|
|
|
nsBlockFrame::line_iterator lineBox = iter.GetLine();
|
|
|
|
|
2010-10-06 21:25:47 -07:00
|
|
|
// How we determine the hypothetical box depends on whether the element
|
|
|
|
// would have been inline-level or block-level
|
2012-08-02 04:38:51 -07:00
|
|
|
if (mStyleDisplay->IsOriginalDisplayInlineOutsideStyle()) {
|
2010-10-06 21:25:47 -07:00
|
|
|
// Use the top of the inline box which the placeholder lives in
|
|
|
|
// as the hypothetical box's top.
|
|
|
|
aHypotheticalBox.mTop = lineBox->mBounds.y + blockYOffset;
|
|
|
|
} else {
|
|
|
|
// The element would have been block-level which means it would
|
|
|
|
// be below 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.
|
|
|
|
// XXXbz the line box is not fully reflowed yet if our
|
|
|
|
// containing block is relatively positioned...
|
2011-11-06 21:25:56 -08:00
|
|
|
if (lineBox != iter.End()) {
|
2010-10-06 21:25:47 -07:00
|
|
|
nsIFrame * firstFrame = lineBox->mFirstChild;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool found = false;
|
2011-11-06 21:25:56 -08:00
|
|
|
bool allEmpty = true;
|
2010-10-06 21:25:47 -07:00
|
|
|
while (firstFrame) { // See bug 223064
|
|
|
|
allEmpty = AreAllEarlierInFlowFramesEmpty(firstFrame,
|
|
|
|
aPlaceholderFrame, &found);
|
|
|
|
if (found || !allEmpty)
|
|
|
|
break;
|
|
|
|
firstFrame = firstFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
NS_ASSERTION(firstFrame, "Couldn't find placeholder!");
|
|
|
|
|
2011-11-06 21:25:56 -08:00
|
|
|
if (allEmpty) {
|
|
|
|
// 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 + blockYOffset;
|
|
|
|
} else {
|
|
|
|
// The top of the hypothetical box is just below the line
|
|
|
|
// containing the placeholder.
|
|
|
|
aHypotheticalBox.mTop = lineBox->mBounds.YMost() + blockYOffset;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2011-11-06 21:25:56 -08:00
|
|
|
// Just use the placeholder's y-offset wrt the containing block
|
|
|
|
aHypotheticalBox.mTop = placeholderOffset.y;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The containing block is not a block, so it's probably something
|
|
|
|
// like a XUL box, etc.
|
|
|
|
// Just use the placeholder's y-offset
|
|
|
|
aHypotheticalBox.mTop = placeholderOffset.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2012-08-02 04:38:51 -07:00
|
|
|
if (mStyleDisplay->IsOriginalDisplayInlineOutsideStyle()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The placeholder represents the left edge of the hypothetical box
|
|
|
|
aHypotheticalBox.mLeft = placeholderOffset.x;
|
|
|
|
} else {
|
|
|
|
aHypotheticalBox.mLeft = aBlockLeftContentEdge;
|
|
|
|
}
|
2008-06-03 15:25:31 -07:00
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
aHypotheticalBox.mLeftIsExact = true;
|
2008-06-03 15:25:31 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (knowBoxWidth) {
|
|
|
|
aHypotheticalBox.mRight = aHypotheticalBox.mLeft + boxWidth;
|
2008-06-03 15:25:31 -07:00
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
aHypotheticalBox.mRightIsExact = true;
|
2008-06-03 15:25:31 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// We can't compute the right edge because we don't know the desired
|
|
|
|
// width. So instead use the right content edge of the block parent,
|
|
|
|
// but remember it's not exact
|
|
|
|
aHypotheticalBox.mRight = aBlockLeftContentEdge + aBlockContentWidth;
|
2008-06-03 15:25:31 -07:00
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
aHypotheticalBox.mRightIsExact = false;
|
2008-06-03 15:25:31 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// The placeholder represents the right edge of the hypothetical box
|
2012-08-02 04:38:51 -07:00
|
|
|
if (mStyleDisplay->IsOriginalDisplayInlineOutsideStyle()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aHypotheticalBox.mRight = placeholderOffset.x;
|
|
|
|
} else {
|
|
|
|
aHypotheticalBox.mRight = aBlockLeftContentEdge + aBlockContentWidth;
|
|
|
|
}
|
2008-06-03 15:25:31 -07:00
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
aHypotheticalBox.mRightIsExact = true;
|
2008-06-03 15:25:31 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (knowBoxWidth) {
|
|
|
|
aHypotheticalBox.mLeft = aHypotheticalBox.mRight - boxWidth;
|
2008-06-03 15:25:31 -07:00
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
aHypotheticalBox.mLeftIsExact = true;
|
2008-06-03 15:25:31 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
} 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 = aBlockLeftContentEdge;
|
2008-06-03 15:25:31 -07:00
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
aHypotheticalBox.mLeftIsExact = false;
|
2008-06-03 15:25:31 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// The current coordinate space is that of the nearest block to the placeholder.
|
|
|
|
// Convert to the coordinate space of the absolute containing block
|
|
|
|
// One weird thing here is that for fixed-positioned elements we want to do
|
|
|
|
// the conversion incorrectly; specifically we want to ignore any scrolling
|
|
|
|
// that may have happened;
|
|
|
|
nsPoint cbOffset;
|
2008-11-25 15:22:39 -08:00
|
|
|
if (mStyleDisplay->mPosition == NS_STYLE_POSITION_FIXED &&
|
|
|
|
// Exclude cases inside -moz-transform where fixed is like absolute.
|
|
|
|
nsLayoutUtils::IsReallyFixedPos(frame)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// In this case, cbrs->frame will always be an ancestor of
|
|
|
|
// aContainingBlock, so can just walk our way up the frame tree.
|
|
|
|
// Make sure to not add positions of frames whose parent is a
|
|
|
|
// scrollFrame, since we're doing fixed positioning, which assumes
|
|
|
|
// everything is scrolled to (0,0).
|
|
|
|
cbOffset.MoveTo(0, 0);
|
|
|
|
do {
|
|
|
|
NS_ASSERTION(aContainingBlock,
|
|
|
|
"Should hit cbrs->frame before we run off the frame tree!");
|
|
|
|
cbOffset += aContainingBlock->GetPositionIgnoringScrolling();
|
|
|
|
aContainingBlock = aContainingBlock->GetParent();
|
|
|
|
} while (aContainingBlock != cbrs->frame);
|
|
|
|
} else {
|
2008-11-25 15:22:39 -08:00
|
|
|
// XXXldb We need to either ignore scrolling for the absolute
|
|
|
|
// positioning case too (and take the incompatibility) or figure out
|
|
|
|
// how to make these positioned elements actually *move* when we
|
|
|
|
// scroll, and thus avoid the resulting incremental reflow bugs.
|
2007-03-22 10:30:00 -07:00
|
|
|
cbOffset = aContainingBlock->GetOffsetTo(cbrs->frame);
|
|
|
|
}
|
|
|
|
aHypotheticalBox.mLeft += cbOffset.x;
|
|
|
|
aHypotheticalBox.mTop += cbOffset.y;
|
|
|
|
aHypotheticalBox.mRight += cbOffset.x;
|
|
|
|
|
|
|
|
// The specified offsets are relative to the absolute containing block's
|
|
|
|
// padding edge and our current values are relative to the border edge, so
|
|
|
|
// translate.
|
|
|
|
nsMargin border = cbrs->mComputedBorderPadding - cbrs->mComputedPadding;
|
|
|
|
aHypotheticalBox.mLeft -= border.left;
|
2008-02-25 13:16:21 -08:00
|
|
|
aHypotheticalBox.mRight -= border.left;
|
2007-03-22 10:30:00 -07:00
|
|
|
aHypotheticalBox.mTop -= border.top;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::InitAbsoluteConstraints(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState* cbrs,
|
|
|
|
nscoord containingBlockWidth,
|
2011-06-10 16:02:14 -07:00
|
|
|
nscoord containingBlockHeight,
|
|
|
|
nsIAtom* aFrameType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(containingBlockHeight != NS_AUTOHEIGHT,
|
|
|
|
"containing block height must be constrained");
|
|
|
|
|
2011-06-10 16:02:14 -07:00
|
|
|
NS_ASSERTION(aFrameType != nsGkAtoms::tableFrame,
|
2011-05-09 17:36:10 -07:00
|
|
|
"InitAbsoluteConstraints should not be called on table frames");
|
|
|
|
NS_ASSERTION(frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW,
|
2009-02-24 10:38:20 -08:00
|
|
|
"Why are we here?");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get the placeholder frame
|
2011-11-06 21:25:56 -08:00
|
|
|
nsIFrame* placeholderFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-06 21:25:56 -08:00
|
|
|
placeholderFrame = aPresContext->PresShell()->GetPlaceholderFrameFor(frame);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != placeholderFrame, "no placeholder frame");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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()))) {
|
2008-11-25 15:22:39 -08:00
|
|
|
// Find the nearest containing block frame to the placeholder frame,
|
|
|
|
// and return its left edge and width.
|
|
|
|
nscoord cbLeftEdge, cbWidth;
|
|
|
|
nsIFrame* cbFrame = GetHypotheticalBoxContainer(placeholderFrame,
|
|
|
|
cbLeftEdge,
|
|
|
|
cbWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
CalculateHypotheticalBox(aPresContext, placeholderFrame, cbFrame,
|
2011-06-10 16:02:14 -07:00
|
|
|
cbLeftEdge, cbWidth, cbrs, hypotheticalBox, aFrameType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the 'left' and 'right' computed offsets
|
|
|
|
// XXX Handle new 'static-position' value...
|
2011-09-28 23:19:26 -07:00
|
|
|
bool leftIsAuto = false, rightIsAuto = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eStyleUnit_Auto == mStylePosition->mOffset.GetLeftUnit()) {
|
|
|
|
mComputedOffsets.left = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
leftIsAuto = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2008-07-17 16:37:12 -07:00
|
|
|
mComputedOffsets.left = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(containingBlockWidth,
|
|
|
|
mStylePosition->mOffset.GetLeft());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (eStyleUnit_Auto == mStylePosition->mOffset.GetRightUnit()) {
|
|
|
|
mComputedOffsets.right = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
rightIsAuto = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2008-07-17 16:37:12 -07:00
|
|
|
mComputedOffsets.right = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(containingBlockWidth,
|
|
|
|
mStylePosition->mOffset.GetRight());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Use the horizontal component of the hypothetical box in the cases
|
|
|
|
// where it's needed.
|
|
|
|
if (leftIsAuto && rightIsAuto) {
|
2008-02-22 05:44:07 -08:00
|
|
|
// Use the direction of the original ("static-position") containing block
|
|
|
|
// to dictate whether 'left' or 'right' is treated like 'static-position'.
|
2011-05-11 21:04:30 -07:00
|
|
|
if (NS_STYLE_DIRECTION_LTR == placeholderFrame->GetContainingBlock()
|
2008-11-25 15:22:39 -08:00
|
|
|
->GetStyleVisibility()->mDirection) {
|
2008-06-03 15:25:31 -07:00
|
|
|
NS_ASSERTION(hypotheticalBox.mLeftIsExact, "should always have "
|
|
|
|
"exact value on containing block's start side");
|
|
|
|
mComputedOffsets.left = hypotheticalBox.mLeft;
|
2011-10-17 07:59:28 -07:00
|
|
|
leftIsAuto = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2008-06-03 15:25:31 -07:00
|
|
|
NS_ASSERTION(hypotheticalBox.mRightIsExact, "should always have "
|
|
|
|
"exact value on containing block's start side");
|
|
|
|
mComputedOffsets.right = containingBlockWidth - hypotheticalBox.mRight;
|
2011-10-17 07:59:28 -07:00
|
|
|
rightIsAuto = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the 'top' and 'bottom' computed offsets
|
2011-09-28 23:19:26 -07:00
|
|
|
bool topIsAuto = false, bottomIsAuto = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eStyleUnit_Auto == mStylePosition->mOffset.GetTopUnit()) {
|
|
|
|
mComputedOffsets.top = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
topIsAuto = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2008-07-17 16:37:12 -07:00
|
|
|
mComputedOffsets.top = nsLayoutUtils::
|
|
|
|
ComputeHeightDependentValue(containingBlockHeight,
|
|
|
|
mStylePosition->mOffset.GetTop());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (eStyleUnit_Auto == mStylePosition->mOffset.GetBottomUnit()) {
|
|
|
|
mComputedOffsets.bottom = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
bottomIsAuto = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2008-07-17 16:37:12 -07:00
|
|
|
mComputedOffsets.bottom = nsLayoutUtils::
|
|
|
|
ComputeHeightDependentValue(containingBlockHeight,
|
|
|
|
mStylePosition->mOffset.GetBottom());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (topIsAuto && bottomIsAuto) {
|
|
|
|
// Treat 'top' like 'static-position'
|
|
|
|
mComputedOffsets.top = hypotheticalBox.mTop;
|
2011-10-17 07:59:28 -07:00
|
|
|
topIsAuto = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool widthIsAuto = eStyleUnit_Auto == mStylePosition->mWidth.GetUnit();
|
|
|
|
bool heightIsAuto = eStyleUnit_Auto == mStylePosition->mHeight.GetUnit();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t computeSizeFlags = 0;
|
2012-03-16 11:01:05 -07:00
|
|
|
if (leftIsAuto || rightIsAuto) {
|
|
|
|
computeSizeFlags |= nsIFrame::eShrinkWrap;
|
|
|
|
}
|
|
|
|
|
2012-01-24 17:21:29 -08:00
|
|
|
{
|
2012-05-20 22:18:27 -07:00
|
|
|
AutoMaybeDisableFontInflation an(frame);
|
2012-01-24 17:21:29 -08:00
|
|
|
|
|
|
|
nsSize size =
|
|
|
|
frame->ComputeSize(rendContext,
|
|
|
|
nsSize(containingBlockWidth,
|
|
|
|
containingBlockHeight),
|
|
|
|
containingBlockWidth, // XXX or availableWidth?
|
|
|
|
nsSize(mComputedMargin.LeftRight() +
|
|
|
|
mComputedOffsets.LeftRight(),
|
|
|
|
mComputedMargin.TopBottom() +
|
|
|
|
mComputedOffsets.TopBottom()),
|
|
|
|
nsSize(mComputedBorderPadding.LeftRight() -
|
|
|
|
mComputedPadding.LeftRight(),
|
|
|
|
mComputedBorderPadding.TopBottom() -
|
|
|
|
mComputedPadding.TopBottom()),
|
|
|
|
nsSize(mComputedPadding.LeftRight(),
|
2007-03-22 10:30:00 -07:00
|
|
|
mComputedPadding.TopBottom()),
|
2012-03-16 11:01:05 -07:00
|
|
|
computeSizeFlags);
|
2012-01-24 17:21:29 -08:00
|
|
|
mComputedWidth = size.width;
|
|
|
|
mComputedHeight = size.height;
|
|
|
|
}
|
2008-02-14 20:14:53 -08:00
|
|
|
NS_ASSERTION(mComputedWidth >= 0, "Bogus width");
|
|
|
|
NS_ASSERTION(mComputedHeight == NS_UNCONSTRAINEDSIZE ||
|
|
|
|
mComputedHeight >= 0, "Bogus height");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX Now that we have ComputeSize, can we condense many of the
|
|
|
|
// branches off of widthIsAuto?
|
|
|
|
|
|
|
|
if (leftIsAuto) {
|
|
|
|
// We know 'right' is not 'auto' anymore thanks to the hypothetical
|
|
|
|
// box code above.
|
|
|
|
// Solve for 'left'.
|
|
|
|
if (widthIsAuto) {
|
|
|
|
// XXXldb This, and the corresponding code in
|
|
|
|
// nsAbsoluteContainingBlock.cpp, could probably go away now that
|
|
|
|
// we always compute widths.
|
|
|
|
mComputedOffsets.left = NS_AUTOOFFSET;
|
|
|
|
} else {
|
|
|
|
mComputedOffsets.left = containingBlockWidth - mComputedMargin.left -
|
|
|
|
mComputedBorderPadding.left - mComputedWidth - mComputedBorderPadding.right -
|
|
|
|
mComputedMargin.right - mComputedOffsets.right;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if (rightIsAuto) {
|
|
|
|
// We know 'left' is not 'auto' anymore thanks to the hypothetical
|
|
|
|
// box code above.
|
|
|
|
// Solve for 'right'.
|
|
|
|
if (widthIsAuto) {
|
|
|
|
// XXXldb This, and the corresponding code in
|
|
|
|
// nsAbsoluteContainingBlock.cpp, could probably go away now that
|
|
|
|
// we always compute widths.
|
|
|
|
mComputedOffsets.right = NS_AUTOOFFSET;
|
|
|
|
} else {
|
|
|
|
mComputedOffsets.right = containingBlockWidth - mComputedOffsets.left -
|
|
|
|
mComputedMargin.left - mComputedBorderPadding.left - mComputedWidth -
|
|
|
|
mComputedBorderPadding.right - mComputedMargin.right;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Neither 'left' nor 'right' is 'auto'. However, the width might
|
|
|
|
// still not fill all the available space (even though we didn't
|
|
|
|
// shrink-wrap) in case:
|
|
|
|
// * width was specified
|
|
|
|
// * we're dealing with a replaced element
|
|
|
|
// * width was constrained by min-width or max-width.
|
|
|
|
|
|
|
|
nscoord availMarginSpace = containingBlockWidth -
|
|
|
|
mComputedOffsets.LeftRight() -
|
|
|
|
mComputedMargin.LeftRight() -
|
|
|
|
mComputedBorderPadding.LeftRight() -
|
|
|
|
mComputedWidth;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool marginLeftIsAuto =
|
2007-03-22 10:30:00 -07:00
|
|
|
eStyleUnit_Auto == mStyleMargin->mMargin.GetLeftUnit();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool marginRightIsAuto =
|
2007-03-22 10:30:00 -07:00
|
|
|
eStyleUnit_Auto == mStyleMargin->mMargin.GetRightUnit();
|
|
|
|
|
2011-03-03 13:18:42 -08:00
|
|
|
if (marginLeftIsAuto) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (marginRightIsAuto) {
|
2011-03-03 13:18:42 -08:00
|
|
|
if (availMarginSpace < 0) {
|
|
|
|
// Note that this case is different from the neither-'auto'
|
|
|
|
// case below, where the spec says to ignore 'left'/'right'.
|
|
|
|
if (cbrs &&
|
|
|
|
NS_STYLE_DIRECTION_RTL == cbrs->mStyleVisibility->mDirection) {
|
|
|
|
// Ignore the specified value for 'margin-left'.
|
|
|
|
mComputedMargin.left = availMarginSpace;
|
|
|
|
} else {
|
|
|
|
// Ignore the specified value for 'margin-right'.
|
|
|
|
mComputedMargin.right = availMarginSpace;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Both 'margin-left' and 'margin-right' are 'auto', so they get
|
|
|
|
// equal values
|
|
|
|
mComputedMargin.left = availMarginSpace / 2;
|
|
|
|
mComputedMargin.right = availMarginSpace - mComputedMargin.left;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// Just 'margin-left' is 'auto'
|
2008-02-24 10:28:57 -08:00
|
|
|
mComputedMargin.left = availMarginSpace;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
2011-03-03 13:18:42 -08:00
|
|
|
if (marginRightIsAuto) {
|
|
|
|
// Just 'margin-right' is 'auto'
|
|
|
|
mComputedMargin.right = availMarginSpace;
|
|
|
|
} else {
|
|
|
|
// We're over-constrained so use the direction of the containing
|
|
|
|
// block to dictate which value to ignore. (And note that the
|
|
|
|
// spec says to ignore 'left' or 'right' rather than
|
|
|
|
// 'margin-left' or 'margin-right'.)
|
|
|
|
// Note that this case is different from the both-'auto' case
|
|
|
|
// above, where the spec says to ignore
|
|
|
|
// 'margin-left'/'margin-right'.
|
|
|
|
if (cbrs &&
|
|
|
|
NS_STYLE_DIRECTION_RTL == cbrs->mStyleVisibility->mDirection) {
|
|
|
|
// Ignore the specified value for 'left'.
|
|
|
|
mComputedOffsets.left += availMarginSpace;
|
|
|
|
} else {
|
|
|
|
// Ignore the specified value for 'right'.
|
|
|
|
mComputedOffsets.right += availMarginSpace;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topIsAuto) {
|
|
|
|
// solve for 'top'
|
|
|
|
if (heightIsAuto) {
|
|
|
|
mComputedOffsets.top = NS_AUTOOFFSET;
|
|
|
|
} else {
|
|
|
|
mComputedOffsets.top = containingBlockHeight - mComputedMargin.top -
|
|
|
|
mComputedBorderPadding.top - mComputedHeight - mComputedBorderPadding.bottom -
|
|
|
|
mComputedMargin.bottom - mComputedOffsets.bottom;
|
|
|
|
}
|
|
|
|
} else if (bottomIsAuto) {
|
|
|
|
// solve for 'bottom'
|
|
|
|
if (heightIsAuto) {
|
|
|
|
mComputedOffsets.bottom = NS_AUTOOFFSET;
|
|
|
|
} else {
|
|
|
|
mComputedOffsets.bottom = containingBlockHeight - mComputedOffsets.top -
|
|
|
|
mComputedMargin.top - mComputedBorderPadding.top - mComputedHeight -
|
|
|
|
mComputedBorderPadding.bottom - mComputedMargin.bottom;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Neither 'top' nor 'bottom' is 'auto'.
|
|
|
|
nscoord autoHeight = containingBlockHeight -
|
|
|
|
mComputedOffsets.TopBottom() -
|
|
|
|
mComputedMargin.TopBottom() -
|
|
|
|
mComputedBorderPadding.TopBottom();
|
|
|
|
if (autoHeight < 0) {
|
|
|
|
autoHeight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mComputedHeight == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
// For non-replaced elements with 'height' auto, the 'height'
|
|
|
|
// fills the remaining space.
|
|
|
|
mComputedHeight = autoHeight;
|
|
|
|
|
|
|
|
// XXX Do these need box-sizing adjustments?
|
|
|
|
if (mComputedHeight > mComputedMaxHeight)
|
|
|
|
mComputedHeight = mComputedMaxHeight;
|
|
|
|
if (mComputedHeight < mComputedMinHeight)
|
|
|
|
mComputedHeight = mComputedMinHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The height might still not fill all the available space in case:
|
|
|
|
// * height was specified
|
|
|
|
// * we're dealing with a replaced element
|
|
|
|
// * height was constrained by min-height or max-height.
|
|
|
|
nscoord availMarginSpace = autoHeight - mComputedHeight;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool marginTopIsAuto =
|
2007-03-22 10:30:00 -07:00
|
|
|
eStyleUnit_Auto == mStyleMargin->mMargin.GetTopUnit();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool marginBottomIsAuto =
|
2007-03-22 10:30:00 -07:00
|
|
|
eStyleUnit_Auto == mStyleMargin->mMargin.GetBottomUnit();
|
|
|
|
|
2011-03-03 13:18:42 -08:00
|
|
|
if (marginTopIsAuto) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (marginBottomIsAuto) {
|
2011-03-03 13:18:42 -08:00
|
|
|
if (availMarginSpace < 0) {
|
|
|
|
// FIXME: Note that the spec doesn't actually say we should do this!
|
|
|
|
mComputedMargin.bottom = availMarginSpace;
|
|
|
|
} else {
|
|
|
|
// Both 'margin-top' and 'margin-bottom' are 'auto', so they get
|
|
|
|
// equal values
|
|
|
|
mComputedMargin.top = availMarginSpace / 2;
|
|
|
|
mComputedMargin.bottom = availMarginSpace - mComputedMargin.top;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// Just 'margin-top' is 'auto'
|
2010-10-17 19:36:26 -07:00
|
|
|
mComputedMargin.top = availMarginSpace;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
2011-03-03 13:18:42 -08:00
|
|
|
if (marginBottomIsAuto) {
|
|
|
|
// Just 'margin-bottom' is 'auto'
|
|
|
|
mComputedMargin.bottom = availMarginSpace;
|
|
|
|
} else {
|
|
|
|
// We're over-constrained so ignore the specified value for
|
|
|
|
// 'bottom'. (And note that the spec says to ignore 'bottom'
|
|
|
|
// rather than 'margin-bottom'.)
|
|
|
|
mComputedOffsets.bottom += availMarginSpace;
|
|
|
|
}
|
2007-03-22 10:30:00 -07: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
|
|
|
|
* This will walk up the chain of containing blocks looking for a computed height
|
|
|
|
* 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)
|
|
|
|
*
|
2009-01-04 11:52:38 -08:00
|
|
|
* When we encounter scrolledContent block frames, we skip over them, since they are guaranteed to not be useful for computing the containing block.
|
2007-05-15 14:52:44 -07:00
|
|
|
*
|
|
|
|
* See also IsQuirkContainingBlockHeight.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-05-15 14:52:44 -07:00
|
|
|
static nscoord
|
2007-03-22 10:30:00 -07:00
|
|
|
CalcQuirkContainingBlockHeight(const nsHTMLReflowState* aCBReflowState)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsHTMLReflowState* firstAncestorRS = nullptr; // a candidate for html frame
|
|
|
|
nsHTMLReflowState* secondAncestorRS = nullptr; // a candidate for body frame
|
2007-03-22 10:30:00 -07: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;
|
|
|
|
|
|
|
|
const nsHTMLReflowState* rs = aCBReflowState;
|
2007-05-15 14:52:44 -07:00
|
|
|
for (; rs; rs = (nsHTMLReflowState *)(rs->parentReflowState)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* frameType = rs->frame->GetType();
|
|
|
|
// if the ancestor is auto height then skip it and continue up if it
|
2009-01-04 11:52:38 -08:00
|
|
|
// is the first block frame and possibly the body/html
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nsGkAtoms::blockFrame == frameType ||
|
2008-12-29 07:07:38 -08:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
nsGkAtoms::XULLabelFrame == frameType ||
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::scrollFrame == frameType) {
|
|
|
|
|
|
|
|
secondAncestorRS = firstAncestorRS;
|
|
|
|
firstAncestorRS = (nsHTMLReflowState*)rs;
|
|
|
|
|
|
|
|
// 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.
|
2007-08-02 11:08:05 -07:00
|
|
|
if (NS_AUTOHEIGHT == rs->ComputedHeight()) {
|
2012-08-02 04:38:50 -07:00
|
|
|
if (rs->frame->IsAbsolutelyPositioned()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsGkAtoms::canvasFrame == frameType) {
|
2007-12-04 19:05:57 -08:00
|
|
|
// Always continue on to the height calculation
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (nsGkAtoms::pageContentFrame == frameType) {
|
|
|
|
nsIFrame* prevInFlow = rs->frame->GetPrevInFlow();
|
|
|
|
// only use the page content frame for a height basis if it is the first in flow
|
|
|
|
if (prevInFlow)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the ancestor is the page content frame then the percent base is
|
|
|
|
// the avail height, otherwise it is the computed height
|
|
|
|
result = (nsGkAtoms::pageContentFrame == frameType)
|
2007-08-02 11:08:05 -07:00
|
|
|
? rs->availableHeight : rs->ComputedHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
// if unconstrained - don't sutract borders - would result in huge height
|
|
|
|
if (NS_AUTOHEIGHT == result) return result;
|
|
|
|
|
|
|
|
// if we got to the canvas or page content frame, then subtract out
|
|
|
|
// margin/border/padding for the BODY and HTML elements
|
|
|
|
if ((nsGkAtoms::canvasFrame == frameType) ||
|
|
|
|
(nsGkAtoms::pageContentFrame == frameType)) {
|
|
|
|
|
|
|
|
result -= GetVerticalMarginBorderPadding(firstAncestorRS);
|
|
|
|
result -= GetVerticalMarginBorderPadding(secondAncestorRS);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// make sure the first ancestor is the HTML and the second is the BODY
|
|
|
|
if (firstAncestorRS) {
|
|
|
|
nsIContent* frameContent = firstAncestorRS->frame->GetContent();
|
|
|
|
if (frameContent) {
|
|
|
|
nsIAtom *contentTag = frameContent->Tag();
|
|
|
|
NS_ASSERTION(contentTag == nsGkAtoms::html, "First ancestor is not HTML");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (secondAncestorRS) {
|
|
|
|
nsIContent* frameContent = secondAncestorRS->frame->GetContent();
|
|
|
|
if (frameContent) {
|
|
|
|
nsIAtom *contentTag = frameContent->Tag();
|
|
|
|
NS_ASSERTION(contentTag == nsGkAtoms::body, "Second ancestor is not BODY");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
2008-12-29 07:07:38 -08:00
|
|
|
// if we got to the html frame (a block child of the canvas) ...
|
|
|
|
else if (nsGkAtoms::blockFrame == frameType &&
|
2011-11-08 20:22:36 -08:00
|
|
|
rs->parentReflowState &&
|
2008-12-29 07:07:38 -08:00
|
|
|
nsGkAtoms::canvasFrame ==
|
|
|
|
rs->parentReflowState->frame->GetType()) {
|
|
|
|
// ... then subtract out margin/border/padding for the BODY element
|
|
|
|
result -= GetVerticalMarginBorderPadding(secondAncestorRS);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure not to return a negative height here!
|
2013-01-15 04:22:03 -08:00
|
|
|
return std::max(result, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-07-08 18:09:50 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Called by InitConstraints() to compute the containing block rectangle for
|
|
|
|
// the element. Handles the special logic for absolutely positioned elements
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::ComputeContainingBlockRectangle(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState* aContainingBlockRS,
|
|
|
|
nscoord& aContainingBlockWidth,
|
|
|
|
nscoord& aContainingBlockHeight)
|
|
|
|
{
|
|
|
|
// Unless the element is absolutely positioned, the containing block is
|
|
|
|
// formed by the content edge of the nearest block-level ancestor
|
|
|
|
aContainingBlockWidth = aContainingBlockRS->mComputedWidth;
|
|
|
|
aContainingBlockHeight = aContainingBlockRS->mComputedHeight;
|
2011-05-11 21:04:30 -07:00
|
|
|
|
|
|
|
// mFrameType for abs-pos tables is NS_CSS_FRAME_TYPE_BLOCK, so we need to
|
|
|
|
// special case them here.
|
|
|
|
if (NS_FRAME_GET_TYPE(mFrameType) == NS_CSS_FRAME_TYPE_ABSOLUTE ||
|
|
|
|
(frame->GetType() == nsGkAtoms::tableFrame &&
|
2012-08-02 04:38:50 -07:00
|
|
|
frame->IsAbsolutelyPositioned() &&
|
2011-05-11 21:04:30 -07:00
|
|
|
(frame->GetParent()->GetStateBits() & NS_FRAME_OUT_OF_FLOW))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// See if the ancestor is block-level or inline-level
|
|
|
|
if (NS_FRAME_GET_TYPE(aContainingBlockRS->mFrameType) == NS_CSS_FRAME_TYPE_INLINE) {
|
|
|
|
// 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
|
2011-04-29 16:02:33 -07:00
|
|
|
// called, since the code in nsInlineFrame::Reflow will pass in
|
2007-03-22 10:30:00 -07:00
|
|
|
// the containing block dimensions to our constructor.
|
|
|
|
// XXXbz we should be taking the in-flows into account too, but
|
|
|
|
// that's very hard.
|
|
|
|
nsMargin computedBorder = aContainingBlockRS->mComputedBorderPadding -
|
|
|
|
aContainingBlockRS->mComputedPadding;
|
|
|
|
aContainingBlockWidth = aContainingBlockRS->frame->GetRect().width -
|
2012-07-08 18:09:50 -07:00
|
|
|
computedBorder.LeftRight();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(aContainingBlockWidth >= 0,
|
|
|
|
"Negative containing block width!");
|
|
|
|
aContainingBlockHeight = aContainingBlockRS->frame->GetRect().height -
|
|
|
|
computedBorder.TopBottom();
|
|
|
|
NS_ASSERTION(aContainingBlockHeight >= 0,
|
|
|
|
"Negative containing block height!");
|
|
|
|
} else {
|
|
|
|
// If the ancestor is block-level, the containing block is formed by the
|
|
|
|
// padding edge of the ancestor
|
|
|
|
aContainingBlockWidth += aContainingBlockRS->mComputedPadding.LeftRight();
|
2008-09-08 01:13:17 -07:00
|
|
|
aContainingBlockHeight += aContainingBlockRS->mComputedPadding.TopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 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
|
2010-08-25 03:17:55 -07:00
|
|
|
// Note: We don't emulate this quirk for percents in calc().
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
|
|
|
if (eCompatibility_NavQuirks == aPresContext->CompatibilityMode() &&
|
|
|
|
mStylePosition->mHeight.GetUnit() == eStyleUnit_Percent) {
|
|
|
|
aContainingBlockHeight = CalcQuirkContainingBlockHeight(aContainingBlockRS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prefs callback to pick up changes
|
2008-10-10 08:04:34 -07:00
|
|
|
static int
|
2007-03-22 10:30:00 -07:00
|
|
|
PrefsChanged(const char *aPrefName, void *instance)
|
|
|
|
{
|
|
|
|
sBlinkIsAllowed =
|
2011-05-24 23:31:59 -07:00
|
|
|
Preferences::GetBool("browser.blink_allowed", sBlinkIsAllowed);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return 0; /* PREF_OK */
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if |text-decoration: blink| is allowed. The first time
|
|
|
|
// called, register the callback and then force-load the pref. After that,
|
|
|
|
// just use the cached value.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool BlinkIsAllowed(void)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!sPrefIsLoaded) {
|
|
|
|
// Set up a listener and check the initial value
|
2011-05-28 16:42:57 -07:00
|
|
|
Preferences::RegisterCallback(PrefsChanged, "browser.blink_allowed");
|
2012-07-30 07:20:58 -07:00
|
|
|
PrefsChanged(nullptr, nullptr);
|
2011-10-17 07:59:28 -07:00
|
|
|
sPrefIsLoaded = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return sBlinkIsAllowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static eNormalLineHeightControl GetNormalLineHeightCalcControl(void)
|
|
|
|
{
|
|
|
|
if (sNormalLineHeightControl == eUninitialized) {
|
|
|
|
// browser.display.normal_lineheight_calc_control is not user
|
|
|
|
// changeable, so no need to register callback for it.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t val =
|
2011-05-24 23:32:00 -07:00
|
|
|
Preferences::GetInt("browser.display.normal_lineheight_calc_control",
|
|
|
|
eNoExternalLeading);
|
|
|
|
sNormalLineHeightControl = static_cast<eNormalLineHeightControl>(val);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return sNormalLineHeightControl;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool
|
2008-02-26 18:02:50 -08:00
|
|
|
IsSideCaption(nsIFrame* aFrame, const nsStyleDisplay* aStyleDisplay)
|
|
|
|
{
|
|
|
|
if (aStyleDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CAPTION)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t captionSide = aFrame->GetStyleTableBorder()->mCaptionSide;
|
2008-02-26 18:02:50 -08:00
|
|
|
return captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
|
|
|
|
captionSide == NS_STYLE_CAPTION_SIDE_RIGHT;
|
|
|
|
}
|
|
|
|
|
2012-09-29 23:38:46 -07:00
|
|
|
#ifdef MOZ_FLEXBOX
|
|
|
|
static nsFlexContainerFrame*
|
|
|
|
GetFlexContainer(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
if (!parent ||
|
|
|
|
parent->GetType() != nsGkAtoms::flexContainerFrame) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast<nsFlexContainerFrame*>(parent);
|
|
|
|
}
|
|
|
|
#endif // MOZ_FLEXBOX
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX refactor this code to have methods for each set of properties
|
|
|
|
// we are computing: width,height,line-height; margin; offsets
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::InitConstraints(nsPresContext* aPresContext,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
const nsMargin* aBorder,
|
2011-06-10 16:02:14 -07:00
|
|
|
const nsMargin* aPadding,
|
|
|
|
nsIAtom* aFrameType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-01 14:40:16 -07:00
|
|
|
DISPLAY_INIT_CONSTRAINTS(frame, this,
|
|
|
|
aContainingBlockWidth, aContainingBlockHeight,
|
|
|
|
aBorder, aPadding);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If this is the root frame, then set the computed width and
|
|
|
|
// height equal to the available space
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr == parentReflowState) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXXldb This doesn't mean what it used to!
|
2011-06-10 16:02:14 -07:00
|
|
|
InitOffsets(aContainingBlockWidth, aFrameType, aBorder, aPadding);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Override mComputedMargin since reflow roots start from the
|
|
|
|
// frame's boundary, which is inside the margin.
|
|
|
|
mComputedMargin.SizeTo(0, 0, 0, 0);
|
|
|
|
mComputedOffsets.SizeTo(0, 0, 0, 0);
|
|
|
|
|
|
|
|
mComputedWidth = availableWidth - mComputedBorderPadding.LeftRight();
|
|
|
|
if (mComputedWidth < 0)
|
|
|
|
mComputedWidth = 0;
|
|
|
|
if (availableHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
mComputedHeight = availableHeight - mComputedBorderPadding.TopBottom();
|
|
|
|
if (mComputedHeight < 0)
|
|
|
|
mComputedHeight = 0;
|
|
|
|
} else {
|
|
|
|
mComputedHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mComputedMinWidth = mComputedMinHeight = 0;
|
|
|
|
mComputedMaxWidth = mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
} else {
|
|
|
|
// Get the containing block reflow state
|
|
|
|
const nsHTMLReflowState* cbrs = mCBReflowState;
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != cbrs, "no containing block");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If we weren't given a containing block width and height, then
|
|
|
|
// compute one
|
|
|
|
if (aContainingBlockWidth == -1) {
|
|
|
|
ComputeContainingBlockRectangle(aPresContext, cbrs, aContainingBlockWidth,
|
|
|
|
aContainingBlockHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the containing block height is based on the size of its
|
|
|
|
// content
|
|
|
|
nsIAtom* fType;
|
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
2007-12-04 19:05:57 -08:00
|
|
|
// See if the containing block is a cell frame which needs
|
2007-03-22 10:30:00 -07:00
|
|
|
// to use the mComputedHeight of the cell instead of what the cell block passed in.
|
2007-12-04 19:05:57 -08:00
|
|
|
// XXX It seems like this could lead to bugs with min-height and friends
|
2007-03-22 10:30:00 -07:00
|
|
|
if (cbrs->parentReflowState) {
|
2007-12-04 19:05:57 -08:00
|
|
|
fType = cbrs->frame->GetType();
|
|
|
|
if (IS_TABLE_CELL(fType)) {
|
|
|
|
// use the cell's computed height
|
|
|
|
aContainingBlockHeight = cbrs->mComputedHeight;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-10 16:02:14 -07:00
|
|
|
InitOffsets(aContainingBlockWidth, aFrameType, aBorder, aPadding);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-25 03:17:55 -07:00
|
|
|
const nsStyleCoord &height = mStylePosition->mHeight;
|
|
|
|
nsStyleUnit heightUnit = height.GetUnit();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Check for a percentage based height and a containing block height
|
|
|
|
// that depends on the content height
|
|
|
|
// XXX twiddling heightUnit doesn't help anymore
|
2010-08-25 03:17:55 -07:00
|
|
|
// FIXME Shouldn't we fix that?
|
|
|
|
if (height.HasPercent()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_AUTOHEIGHT == aContainingBlockHeight) {
|
|
|
|
// 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 ||
|
|
|
|
NS_FRAME_REPLACED_CONTAINS_BLOCK(
|
|
|
|
NS_CSS_FRAME_TYPE_INLINE) == mFrameType) {
|
|
|
|
// Get the containing block reflow state
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != cbrs, "no containing block");
|
2007-03-22 10:30:00 -07:00
|
|
|
// in quirks mode, get the cb height using the special quirk method
|
|
|
|
if (eCompatibility_NavQuirks == aPresContext->CompatibilityMode()) {
|
|
|
|
if (!IS_TABLE_CELL(fType)) {
|
|
|
|
aContainingBlockHeight = CalcQuirkContainingBlockHeight(cbrs);
|
|
|
|
if (aContainingBlockHeight == NS_AUTOHEIGHT) {
|
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2012-08-02 04:38:50 -07:00
|
|
|
if (mStyleDisplay->IsRelativelyPositioned(frame)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t direction = NS_STYLE_DIRECTION_LTR;
|
Bug 157681 - Part 2: Optimize positioned frame offset changes by moving the frame as opposed to reflowing it in case we know that the size of the frame will not change; r=dbaron
This patch adds a change hint to signal that one of the offsets on a
frame has been changed. When processing the hint, we do one of the
following things based on the position property of the frame.
* For static frames, we ignore the offset changes completely, as they
will not change the layout.
* For relative positioned frames, this patch refactors the
nsHTMLReflowState::ComputeRelativeOffsets function so that it can be
used from other callers, and it uses that to compute the new relative
offsets, and uses the offsets computed previously to compute the new
position of the frame.
* For absolute positioned frames, we set up a fake parent reflow state
object, and then we create a new reflow state object for the frame in
question. This setup is similar to what nsFrame::BoxReflow does.
Once we have the new reflow state object, we use it to compute the
absolute offsets, and then we use the computed offsets to set the new
position of the frame. The offset computation is similar to what
nsAbsoluteContainingBlock::ReflowAbsoluteFrame does. In some cases
where it is possible for the dimensions of the frame to change based
on the offset changes, we fall back to a full reflow.
2012-06-05 21:53:48 -07:00
|
|
|
if (cbrs && NS_STYLE_DIRECTION_RTL == cbrs->mStyleVisibility->mDirection) {
|
|
|
|
direction = NS_STYLE_DIRECTION_RTL;
|
|
|
|
}
|
|
|
|
ComputeRelativeOffsets(direction, frame, aContainingBlockWidth,
|
|
|
|
aContainingBlockHeight, mComputedOffsets);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
// Initialize offsets to 0
|
|
|
|
mComputedOffsets.SizeTo(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the computed values for min and max properties. Note that
|
|
|
|
// this MUST come after we've computed our border and padding.
|
|
|
|
ComputeMinMaxValues(aContainingBlockWidth, aContainingBlockHeight, cbrs);
|
|
|
|
|
|
|
|
// Calculate the computed width and height. This varies by frame type
|
|
|
|
|
|
|
|
if (NS_CSS_FRAME_TYPE_INTERNAL_TABLE == mFrameType) {
|
|
|
|
// Internal table elements. The rules vary depending on the type.
|
|
|
|
// Calculate the computed width
|
2011-09-28 23:19:26 -07:00
|
|
|
bool rowOrRowGroup = false;
|
2010-08-25 03:17:55 -07:00
|
|
|
const nsStyleCoord &width = mStylePosition->mWidth;
|
|
|
|
nsStyleUnit widthUnit = width.GetUnit();
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((NS_STYLE_DISPLAY_TABLE_ROW == mStyleDisplay->mDisplay) ||
|
|
|
|
(NS_STYLE_DISPLAY_TABLE_ROW_GROUP == mStyleDisplay->mDisplay)) {
|
|
|
|
// 'width' property doesn't apply to table rows and row groups
|
|
|
|
widthUnit = eStyleUnit_Auto;
|
2011-10-17 07:59:28 -07:00
|
|
|
rowOrRowGroup = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-11-21 08:19:37 -08:00
|
|
|
// calc() with percentages acts like auto on internal table elements
|
|
|
|
if (eStyleUnit_Auto == widthUnit ||
|
|
|
|
(width.IsCalcUnit() && width.CalcHasPercent())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mComputedWidth = availableWidth;
|
|
|
|
|
|
|
|
if ((mComputedWidth != NS_UNCONSTRAINEDSIZE) && !rowOrRowGroup){
|
|
|
|
// Internal table elements don't have margins. Only tables and
|
|
|
|
// cells have border and padding
|
|
|
|
mComputedWidth -= mComputedBorderPadding.left +
|
|
|
|
mComputedBorderPadding.right;
|
2008-02-14 20:14:53 -08:00
|
|
|
if (mComputedWidth < 0)
|
|
|
|
mComputedWidth = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-02-14 20:14:53 -08:00
|
|
|
NS_ASSERTION(mComputedWidth >= 0, "Bogus computed width");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(widthUnit == mStylePosition->mWidth.GetUnit(),
|
|
|
|
"unexpected width unit change");
|
2007-05-03 16:11:00 -07:00
|
|
|
mComputedWidth = ComputeWidthValue(aContainingBlockWidth,
|
|
|
|
mStylePosition->mBoxSizing,
|
|
|
|
mStylePosition->mWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the computed height
|
|
|
|
if ((NS_STYLE_DISPLAY_TABLE_COLUMN == mStyleDisplay->mDisplay) ||
|
|
|
|
(NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP == mStyleDisplay->mDisplay)) {
|
|
|
|
// 'height' property doesn't apply to table columns and column groups
|
|
|
|
heightUnit = eStyleUnit_Auto;
|
|
|
|
}
|
2012-11-21 08:19:30 -08:00
|
|
|
// calc() with percentages acts like 'auto' on internal table elements
|
|
|
|
if (eStyleUnit_Auto == heightUnit ||
|
|
|
|
(height.IsCalcUnit() && height.CalcHasPercent())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mComputedHeight = NS_AUTOHEIGHT;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(heightUnit == mStylePosition->mHeight.GetUnit(),
|
|
|
|
"unexpected height unit change");
|
2012-08-08 08:58:26 -07:00
|
|
|
mComputedHeight = ComputeHeightValue(aContainingBlockHeight,
|
|
|
|
mStylePosition->mBoxSizing,
|
|
|
|
mStylePosition->mHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Doesn't apply to table elements
|
|
|
|
mComputedMinWidth = mComputedMinHeight = 0;
|
|
|
|
mComputedMaxWidth = mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
|
|
|
} else if (NS_FRAME_GET_TYPE(mFrameType) == NS_CSS_FRAME_TYPE_ABSOLUTE) {
|
|
|
|
// XXX not sure if this belongs here or somewhere else - cwk
|
|
|
|
InitAbsoluteConstraints(aPresContext, cbrs, aContainingBlockWidth,
|
2011-06-10 16:02:14 -07:00
|
|
|
aContainingBlockHeight, aFrameType);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-05-20 22:18:27 -07:00
|
|
|
AutoMaybeDisableFontInflation an(frame);
|
2012-01-24 17:21:29 -08:00
|
|
|
|
2012-04-13 08:52:13 -07:00
|
|
|
bool isBlock = NS_CSS_FRAME_TYPE_BLOCK == NS_FRAME_GET_TYPE(mFrameType);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t computeSizeFlags = isBlock ? 0 : nsIFrame::eShrinkWrap;
|
2012-04-13 08:52:13 -07:00
|
|
|
|
|
|
|
// Make sure legend frames with display:block and width:auto still
|
|
|
|
// shrink-wrap.
|
|
|
|
if (isBlock &&
|
|
|
|
((aFrameType == nsGkAtoms::legendFrame &&
|
|
|
|
frame->GetStyleContext()->GetPseudo() != nsCSSAnonBoxes::scrolledContent) ||
|
|
|
|
(aFrameType == nsGkAtoms::scrollFrame &&
|
|
|
|
frame->GetContentInsertionFrame()->GetType() == nsGkAtoms::legendFrame))) {
|
2012-03-16 11:01:05 -07:00
|
|
|
computeSizeFlags |= nsIFrame::eShrinkWrap;
|
|
|
|
}
|
|
|
|
|
2012-09-29 23:38:46 -07:00
|
|
|
#ifdef MOZ_FLEXBOX
|
|
|
|
const nsFlexContainerFrame* flexContainerFrame = GetFlexContainer(frame);
|
|
|
|
if (flexContainerFrame) {
|
|
|
|
computeSizeFlags |= nsIFrame::eShrinkWrap;
|
|
|
|
|
|
|
|
// If we're inside of a flex container that needs to measure our
|
|
|
|
// auto height, pass that information along to ComputeSize().
|
|
|
|
if (mFlags.mIsFlexContainerMeasuringHeight) {
|
|
|
|
computeSizeFlags |= nsIFrame::eUseAutoHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(!mFlags.mIsFlexContainerMeasuringHeight,
|
|
|
|
"We're not in a flex container, so the flag "
|
|
|
|
"'mIsFlexContainerMeasuringHeight' shouldn't be set");
|
2012-09-29 23:38:46 -07:00
|
|
|
}
|
2012-09-29 23:38:46 -07:00
|
|
|
#endif // MOZ_FLEXBOX
|
2012-09-29 23:38:46 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize size =
|
|
|
|
frame->ComputeSize(rendContext,
|
|
|
|
nsSize(aContainingBlockWidth,
|
|
|
|
aContainingBlockHeight),
|
|
|
|
availableWidth,
|
|
|
|
nsSize(mComputedMargin.LeftRight(),
|
|
|
|
mComputedMargin.TopBottom()),
|
|
|
|
nsSize(mComputedBorderPadding.LeftRight() -
|
|
|
|
mComputedPadding.LeftRight(),
|
|
|
|
mComputedBorderPadding.TopBottom() -
|
|
|
|
mComputedPadding.TopBottom()),
|
|
|
|
nsSize(mComputedPadding.LeftRight(),
|
|
|
|
mComputedPadding.TopBottom()),
|
2012-03-16 11:01:05 -07:00
|
|
|
computeSizeFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mComputedWidth = size.width;
|
|
|
|
mComputedHeight = size.height;
|
2008-02-14 20:14:53 -08:00
|
|
|
NS_ASSERTION(mComputedWidth >= 0, "Bogus width");
|
|
|
|
NS_ASSERTION(mComputedHeight == NS_UNCONSTRAINEDSIZE ||
|
|
|
|
mComputedHeight >= 0, "Bogus height");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-29 23:38:46 -07:00
|
|
|
// Exclude inline tables and flex items from the block margin calculations
|
|
|
|
if (isBlock &&
|
|
|
|
!IsSideCaption(frame, mStyleDisplay) &&
|
|
|
|
mStyleDisplay->mDisplay != NS_STYLE_DISPLAY_INLINE_TABLE
|
|
|
|
#ifdef MOZ_FLEXBOX
|
|
|
|
&& !flexContainerFrame
|
|
|
|
#endif // MOZ_FLEXBOX
|
|
|
|
)
|
2011-06-10 16:02:14 -07:00
|
|
|
CalculateBlockSideMargins(availableWidth, mComputedWidth, aFrameType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check for blinking text and permission to display it
|
|
|
|
mFlags.mBlinks = (parentReflowState && parentReflowState->mFlags.mBlinks);
|
|
|
|
if (!mFlags.mBlinks && BlinkIsAllowed()) {
|
|
|
|
const nsStyleTextReset* st = frame->GetStyleTextReset();
|
2011-04-22 22:16:41 -07:00
|
|
|
mFlags.mBlinks = (st->mTextBlink != NS_STYLE_TEXT_BLINK_NONE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 13:14:05 -08:00
|
|
|
static void
|
|
|
|
UpdateProp(FrameProperties& aProps,
|
|
|
|
const FramePropertyDescriptor* aProperty,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNeeded,
|
2010-11-09 13:14:05 -08:00
|
|
|
nsMargin& aNewValue)
|
|
|
|
{
|
|
|
|
if (aNeeded) {
|
|
|
|
nsMargin* propValue = static_cast<nsMargin*>(aProps.Get(aProperty));
|
|
|
|
if (propValue) {
|
|
|
|
*propValue = aNewValue;
|
|
|
|
} else {
|
|
|
|
aProps.Set(aProperty, new nsMargin(aNewValue));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aProps.Delete(aProperty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsCSSOffsetState::InitOffsets(nscoord aContainingBlockWidth,
|
2011-06-10 16:02:14 -07:00
|
|
|
nsIAtom* aFrameType,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsMargin *aBorder,
|
|
|
|
const nsMargin *aPadding)
|
|
|
|
{
|
2010-05-01 14:40:16 -07:00
|
|
|
DISPLAY_INIT_OFFSETS(frame, this, aContainingBlockWidth, aBorder, aPadding);
|
|
|
|
|
2010-11-09 13:14:05 -08:00
|
|
|
// Since we are in reflow, we don't need to store these properties anymore
|
|
|
|
// unless they are dependent on width, in which case we store the new value.
|
|
|
|
nsPresContext *presContext = frame->PresContext();
|
|
|
|
FrameProperties props(presContext->PropertyTable(), frame);
|
|
|
|
props.Delete(nsIFrame::UsedBorderProperty());
|
|
|
|
|
2007-03-22 10:30:00 -07: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
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needMarginProp = ComputeMargin(aContainingBlockWidth);
|
2010-11-09 13:14:05 -08:00
|
|
|
// XXX We need to include 'auto' horizontal margins in this too!
|
|
|
|
// ... but if we did that, we'd need to fix nsFrame::GetUsedMargin
|
|
|
|
// to use it even when the margins are all zero (since sometimes
|
|
|
|
// they get treated as auto)
|
|
|
|
::UpdateProp(props, nsIFrame::UsedMarginProperty(), needMarginProp,
|
|
|
|
mComputedMargin);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const nsStyleDisplay *disp = frame->GetStyleDisplay();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isThemed = frame->IsThemed(disp);
|
|
|
|
bool needPaddingProp;
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntMargin widget;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isThemed &&
|
|
|
|
presContext->GetTheme()->GetWidgetPadding(presContext->DeviceContext(),
|
|
|
|
frame, disp->mAppearance,
|
2009-01-14 19:27:09 -08:00
|
|
|
&widget)) {
|
|
|
|
mComputedPadding.top = presContext->DevPixelsToAppUnits(widget.top);
|
|
|
|
mComputedPadding.right = presContext->DevPixelsToAppUnits(widget.right);
|
|
|
|
mComputedPadding.bottom = presContext->DevPixelsToAppUnits(widget.bottom);
|
|
|
|
mComputedPadding.left = presContext->DevPixelsToAppUnits(widget.left);
|
2011-10-17 07:59:28 -07:00
|
|
|
needPaddingProp = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-02 04:38:48 -07:00
|
|
|
else if (frame->GetStateBits() & NS_FRAME_IS_SVG_TEXT) {
|
|
|
|
mComputedPadding.SizeTo(0, 0, 0, 0);
|
2012-08-22 18:24:19 -07:00
|
|
|
needPaddingProp = false;
|
2012-08-02 04:38:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (aPadding) { // padding is an input arg
|
2010-11-09 13:14:05 -08:00
|
|
|
mComputedPadding = *aPadding;
|
|
|
|
needPaddingProp = frame->GetStylePadding()->IsWidthDependent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-06-10 16:02:14 -07:00
|
|
|
needPaddingProp = ComputePadding(aContainingBlockWidth, aFrameType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isThemed) {
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntMargin widget;
|
2007-03-22 10:30:00 -07:00
|
|
|
presContext->GetTheme()->GetWidgetBorder(presContext->DeviceContext(),
|
|
|
|
frame, disp->mAppearance,
|
2009-01-14 19:27:09 -08:00
|
|
|
&widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
mComputedBorderPadding.top =
|
2009-01-14 19:27:09 -08:00
|
|
|
presContext->DevPixelsToAppUnits(widget.top);
|
2007-03-22 10:30:00 -07:00
|
|
|
mComputedBorderPadding.right =
|
2009-01-14 19:27:09 -08:00
|
|
|
presContext->DevPixelsToAppUnits(widget.right);
|
2007-03-22 10:30:00 -07:00
|
|
|
mComputedBorderPadding.bottom =
|
2009-01-14 19:27:09 -08:00
|
|
|
presContext->DevPixelsToAppUnits(widget.bottom);
|
2007-03-22 10:30:00 -07:00
|
|
|
mComputedBorderPadding.left =
|
2009-01-14 19:27:09 -08:00
|
|
|
presContext->DevPixelsToAppUnits(widget.left);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-02 04:38:48 -07:00
|
|
|
else if (frame->GetStateBits() & NS_FRAME_IS_SVG_TEXT) {
|
|
|
|
mComputedBorderPadding.SizeTo(0, 0, 0, 0);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (aBorder) { // border is an input arg
|
|
|
|
mComputedBorderPadding = *aBorder;
|
|
|
|
}
|
|
|
|
else {
|
2012-05-30 22:19:49 -07:00
|
|
|
mComputedBorderPadding = frame->GetStyleBorder()->GetComputedBorder();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
mComputedBorderPadding += mComputedPadding;
|
|
|
|
|
2011-06-10 16:02:14 -07:00
|
|
|
if (aFrameType == nsGkAtoms::tableFrame) {
|
2007-07-08 00:08:04 -07:00
|
|
|
nsTableFrame *tableFrame = static_cast<nsTableFrame*>(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (tableFrame->IsBorderCollapse()) {
|
|
|
|
// border-collapsed tables don't use any of their padding, and
|
|
|
|
// only part of their border. We need to do this here before we
|
|
|
|
// try to do anything like handling 'auto' widths,
|
|
|
|
// '-moz-box-sizing', or 'auto' margins.
|
|
|
|
mComputedPadding.SizeTo(0,0,0,0);
|
|
|
|
mComputedBorderPadding = tableFrame->GetIncludedOuterBCBorder();
|
|
|
|
}
|
Bug 659828 - Part 1: Apply table margins to the outer table frame instead of the inner table frame (also fixes bug 87277); r=dbaron
Outer table frames act as CSS2.1 table wrapper boxes. We used to lay them out
without taking their margins into the account, which meant that their width was
always equal to the available width. This breaks horizontal positioning of
absolutely positioned kids of a table frame.
The main purpose of this patch is to apply the margins of tables to their outer
frame, instead of the inner frame. This means that the inner table frame will
always have a zero margin, which means that a lot of the stuff which used to
rely on the fact that table margins are applied to the inner frame need to
change.
In particular, in order to get the computed margins of a table, we used to query
the inner table frame, and this patch corrects that. Also, when shrink wrapping
tables, we used to not take the margins of the inner table frame into account,
which is fixed by this patch too. nsBlockReflowState::
ComputeReplacedBlockOffsetsForFloats also needed to be changed to read the
margin values from the outer frame too.
Also, as part of this patch, we start to respect the CSS2.1 margin model for
captions on all sides. This means that in particular, the top/bottom margins on
the top-outside and bottom-outside captions will not be collapsed with the
top/bottom margins of the table, and that the margins of the caption element
contribute to the width and height of the outer table frame. The
427129-table-caption reftest has been modified to match this new behavior.
Another side effect of this bug is fixing bug 87277, and the reftests for that
bug are marked as passing in this patch.
2011-05-31 16:02:56 -07:00
|
|
|
|
|
|
|
// The margin is inherited to the outer table frame via
|
|
|
|
// the ::-moz-table-outer rule in ua.css.
|
|
|
|
mComputedMargin.SizeTo(0, 0, 0, 0);
|
2011-06-10 16:02:14 -07:00
|
|
|
} else if (aFrameType == nsGkAtoms::scrollbarFrame) {
|
2009-07-29 20:43:22 -07:00
|
|
|
// scrollbars may have had their width or height smashed to zero
|
|
|
|
// by the associated scrollframe, in which case we must not report
|
2009-08-17 15:38:12 -07:00
|
|
|
// any padding or border.
|
2009-07-29 20:43:22 -07:00
|
|
|
nsSize size(frame->GetSize());
|
2009-08-17 15:38:12 -07:00
|
|
|
if (size.width == 0 || size.height == 0) {
|
2010-11-09 13:14:05 -08:00
|
|
|
mComputedPadding.SizeTo(0,0,0,0);
|
|
|
|
mComputedBorderPadding.SizeTo(0,0,0,0);
|
2009-07-29 20:43:22 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-11-09 13:14:05 -08:00
|
|
|
::UpdateProp(props, nsIFrame::UsedPaddingProperty(), needPaddingProp,
|
|
|
|
mComputedPadding);
|
2007-03-22 10:30:00 -07: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
|
|
|
|
//
|
|
|
|
// Note: the width unit is not auto when this is called
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::CalculateBlockSideMargins(nscoord aAvailWidth,
|
2011-06-10 16:02:14 -07:00
|
|
|
nscoord aComputedWidth,
|
|
|
|
nsIAtom* aFrameType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-28 20:22:28 -07:00
|
|
|
NS_WARN_IF_FALSE(NS_UNCONSTRAINEDSIZE != aComputedWidth &&
|
|
|
|
NS_UNCONSTRAINEDSIZE != aAvailWidth,
|
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nscoord sum = mComputedMargin.left + mComputedBorderPadding.left +
|
|
|
|
aComputedWidth + mComputedBorderPadding.right + mComputedMargin.right;
|
|
|
|
if (sum == aAvailWidth)
|
|
|
|
// The sum is already correct
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Determine the left and right margin values. The width value
|
|
|
|
// remains constant while we do this.
|
|
|
|
|
|
|
|
// Calculate how much space is available for margins
|
|
|
|
nscoord availMarginSpace = aAvailWidth - sum;
|
|
|
|
|
|
|
|
// If the available margin space is negative, then don't follow the
|
|
|
|
// usual overconstraint rules.
|
|
|
|
if (availMarginSpace < 0) {
|
|
|
|
if (mCBReflowState &&
|
|
|
|
mCBReflowState->mStyleVisibility->mDirection == NS_STYLE_DIRECTION_RTL) {
|
|
|
|
mComputedMargin.left += availMarginSpace;
|
|
|
|
} else {
|
|
|
|
mComputedMargin.right += availMarginSpace;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The css2 spec clearly defines how block elements should behave
|
|
|
|
// in section 10.3.3.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isAutoLeftMargin =
|
2007-03-22 10:30:00 -07:00
|
|
|
eStyleUnit_Auto == mStyleMargin->mMargin.GetLeftUnit();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isAutoRightMargin =
|
2007-03-22 10:30:00 -07:00
|
|
|
eStyleUnit_Auto == mStyleMargin->mMargin.GetRightUnit();
|
|
|
|
if (!isAutoLeftMargin && !isAutoRightMargin) {
|
|
|
|
// Neither margin is 'auto' so we're over constrained. Use the
|
|
|
|
// 'direction' property of the parent to tell which margin to
|
|
|
|
// ignore
|
|
|
|
// First check if there is an HTML alignment that we should honor
|
|
|
|
const nsHTMLReflowState* prs = parentReflowState;
|
2011-06-10 16:02:14 -07:00
|
|
|
if (aFrameType == nsGkAtoms::tableFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(prs->frame->GetType() == nsGkAtoms::tableOuterFrame,
|
|
|
|
"table not inside outer table");
|
|
|
|
// Center the table within the outer table based on the alignment
|
|
|
|
// of the outer table's parent.
|
|
|
|
prs = prs->parentReflowState;
|
|
|
|
}
|
|
|
|
if (prs &&
|
|
|
|
(prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_LEFT ||
|
|
|
|
prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER ||
|
|
|
|
prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT)) {
|
|
|
|
isAutoLeftMargin =
|
|
|
|
prs->mStyleText->mTextAlign != NS_STYLE_TEXT_ALIGN_MOZ_LEFT;
|
|
|
|
isAutoRightMargin =
|
|
|
|
prs->mStyleText->mTextAlign != NS_STYLE_TEXT_ALIGN_MOZ_RIGHT;
|
|
|
|
}
|
|
|
|
// Otherwise apply the CSS rules, and ignore one margin by forcing
|
|
|
|
// it to 'auto', depending on 'direction'.
|
|
|
|
else if (mCBReflowState &&
|
|
|
|
NS_STYLE_DIRECTION_RTL == mCBReflowState->mStyleVisibility->mDirection) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isAutoLeftMargin = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
isAutoRightMargin = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Logic which is common to blocks and tables
|
2008-08-30 09:25:38 -07:00
|
|
|
// The computed margins need not be zero because the 'auto' could come from
|
|
|
|
// overconstraint or from HTML alignment so values need to be accumulated
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isAutoLeftMargin) {
|
|
|
|
if (isAutoRightMargin) {
|
2008-08-30 09:25:38 -07:00
|
|
|
// Both margins are 'auto' so the computed addition should be equal
|
|
|
|
nscoord forLeft = availMarginSpace / 2;
|
|
|
|
mComputedMargin.left += forLeft;
|
|
|
|
mComputedMargin.right += availMarginSpace - forLeft;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
mComputedMargin.left += availMarginSpace;
|
|
|
|
}
|
|
|
|
} else if (isAutoRightMargin) {
|
|
|
|
mComputedMargin.right += availMarginSpace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#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
|
2011-04-07 18:05:49 -07:00
|
|
|
GetNormalLineHeight(nsFontMetrics* aFontMetrics)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nullptr != aFontMetrics, "no font metrics");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nscoord normalLineHeight;
|
|
|
|
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord externalLeading = aFontMetrics->ExternalLeading();
|
|
|
|
nscoord internalLeading = aFontMetrics->InternalLeading();
|
|
|
|
nscoord emHeight = aFontMetrics->EmHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
return normalLineHeight;
|
|
|
|
}
|
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
static inline nscoord
|
2009-05-18 15:13:12 -07:00
|
|
|
ComputeLineHeight(nsStyleContext* aStyleContext,
|
2011-11-23 18:48:23 -08:00
|
|
|
nscoord aBlockHeight,
|
2012-01-24 17:21:29 -08:00
|
|
|
float aFontSizeInflation)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const nsStyleCoord& lhCoord = aStyleContext->GetStyleText()->mLineHeight;
|
2008-07-17 16:37:12 -07:00
|
|
|
|
2012-01-24 17:21:29 -08:00
|
|
|
if (lhCoord.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
nscoord result = lhCoord.GetCoordValue();
|
|
|
|
if (aFontSizeInflation != 1.0f) {
|
|
|
|
result = NSToCoordRound(result * aFontSizeInflation);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2008-07-17 16:37:12 -07:00
|
|
|
|
|
|
|
if (lhCoord.GetUnit() == eStyleUnit_Factor)
|
|
|
|
// For factor units the computed value of the line-height property
|
|
|
|
// is found by multiplying the factor by the font's computed size
|
|
|
|
// (adjusted for min-size prefs and text zoom).
|
2012-01-24 17:21:29 -08:00
|
|
|
return NSToCoordRound(lhCoord.GetFactorValue() * aFontSizeInflation *
|
2008-07-17 16:37:12 -07:00
|
|
|
aStyleContext->GetStyleFont()->mFont.size);
|
|
|
|
|
2009-05-18 15:13:12 -07:00
|
|
|
NS_ASSERTION(lhCoord.GetUnit() == eStyleUnit_Normal ||
|
|
|
|
lhCoord.GetUnit() == eStyleUnit_Enumerated,
|
|
|
|
"bad line-height unit");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-18 15:13:12 -07:00
|
|
|
if (lhCoord.GetUnit() == eStyleUnit_Enumerated) {
|
|
|
|
NS_ASSERTION(lhCoord.GetIntValue() == NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT,
|
|
|
|
"bad line-height value");
|
2011-11-23 18:48:23 -08:00
|
|
|
if (aBlockHeight != NS_AUTOHEIGHT) {
|
2009-05-18 15:13:12 -07:00
|
|
|
return aBlockHeight;
|
2011-11-23 18:48:23 -08:00
|
|
|
}
|
2009-05-18 15:13:12 -07:00
|
|
|
}
|
|
|
|
|
2011-04-07 18:05:49 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
2008-07-17 16:37:12 -07:00
|
|
|
nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext,
|
2012-01-24 17:21:29 -08:00
|
|
|
getter_AddRefs(fm),
|
|
|
|
aFontSizeInflation);
|
2008-07-17 16:37:12 -07:00
|
|
|
return GetNormalLineHeight(fm);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2009-05-18 15:13:12 -07:00
|
|
|
nsHTMLReflowState::CalcLineHeight() const
|
|
|
|
{
|
|
|
|
nscoord blockHeight =
|
2011-05-11 21:04:30 -07:00
|
|
|
nsLayoutUtils::IsNonWrapperBlock(frame) ? mComputedHeight :
|
2009-05-18 15:13:12 -07:00
|
|
|
(mCBReflowState ? mCBReflowState->mComputedHeight : NS_AUTOHEIGHT);
|
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
return CalcLineHeight(frame->GetStyleContext(), blockHeight,
|
2012-05-20 22:18:28 -07:00
|
|
|
nsLayoutUtils::FontSizeInflationFor(frame));
|
2009-05-18 15:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
|
|
|
nsHTMLReflowState::CalcLineHeight(nsStyleContext* aStyleContext,
|
2011-11-23 18:48:23 -08:00
|
|
|
nscoord aBlockHeight,
|
|
|
|
float aFontSizeInflation)
|
2007-05-04 22:30:10 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aStyleContext, "Must have a style context");
|
2011-11-23 18:48:23 -08:00
|
|
|
|
|
|
|
nscoord lineHeight =
|
2012-01-24 17:21:29 -08:00
|
|
|
ComputeLineHeight(aStyleContext, aBlockHeight, aFontSizeInflation);
|
2007-05-04 22:30:10 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up");
|
|
|
|
|
|
|
|
return lineHeight;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSOffsetState::ComputeMargin(nscoord aContainingBlockWidth)
|
|
|
|
{
|
2012-08-02 04:38:48 -07:00
|
|
|
// SVG text frames have no margin.
|
|
|
|
if (frame->GetStateBits() & NS_FRAME_IS_SVG_TEXT) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If style style can provide us the margin directly, then use it.
|
|
|
|
const nsStyleMargin *styleMargin = frame->GetStyleMargin();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isWidthDependent = !styleMargin->GetMargin(mComputedMargin);
|
2010-11-09 13:14:05 -08:00
|
|
|
if (isWidthDependent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We have to compute the value
|
2010-08-31 09:05:12 -07:00
|
|
|
mComputedMargin.left = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
|
|
|
styleMargin->mMargin.GetLeft());
|
|
|
|
mComputedMargin.right = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
|
|
|
styleMargin->mMargin.GetRight());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
// XXX This isn't true for page boxes, if we implement them.
|
2008-07-17 16:37:12 -07:00
|
|
|
mComputedMargin.top = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
|
|
|
styleMargin->mMargin.GetTop());
|
|
|
|
mComputedMargin.bottom = nsLayoutUtils::
|
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
|
|
|
styleMargin->mMargin.GetBottom());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-07-10 08:46:07 -07:00
|
|
|
|
|
|
|
nscoord marginAdjustment = FontSizeInflationListMarginAdjustment(frame);
|
|
|
|
|
|
|
|
if (marginAdjustment > 0) {
|
|
|
|
const nsStyleVisibility* visibility = frame->GetStyleVisibility();
|
|
|
|
if (visibility->mDirection == NS_STYLE_DIRECTION_RTL) {
|
|
|
|
mComputedMargin.right = mComputedMargin.right + marginAdjustment;
|
|
|
|
} else {
|
|
|
|
mComputedMargin.left = mComputedMargin.left + marginAdjustment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 13:14:05 -08:00
|
|
|
return isWidthDependent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-06-10 16:02:14 -07:00
|
|
|
nsCSSOffsetState::ComputePadding(nscoord aContainingBlockWidth, nsIAtom* aFrameType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// If style can provide us the padding directly, then use it.
|
|
|
|
const nsStylePadding *stylePadding = frame->GetStylePadding();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isWidthDependent = !stylePadding->GetPadding(mComputedPadding);
|
2010-11-09 13:14:05 -08:00
|
|
|
// a table row/col group, row/col doesn't have padding
|
|
|
|
// XXXldb Neither do border-collapse tables.
|
2011-06-10 16:02:14 -07:00
|
|
|
if (nsGkAtoms::tableRowGroupFrame == aFrameType ||
|
|
|
|
nsGkAtoms::tableColGroupFrame == aFrameType ||
|
|
|
|
nsGkAtoms::tableRowFrame == aFrameType ||
|
|
|
|
nsGkAtoms::tableColFrame == aFrameType) {
|
2010-11-09 13:14:05 -08:00
|
|
|
mComputedPadding.SizeTo(0,0,0,0);
|
|
|
|
}
|
|
|
|
else if (isWidthDependent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We have to compute the value
|
2010-09-09 08:21:46 -07:00
|
|
|
// clamp negative calc() results to 0
|
2013-01-15 04:22:03 -08:00
|
|
|
mComputedPadding.left = std::max(0, nsLayoutUtils::
|
2008-07-17 16:37:12 -07:00
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
2010-09-09 08:21:46 -07:00
|
|
|
stylePadding->mPadding.GetLeft()));
|
2013-01-15 04:22:03 -08:00
|
|
|
mComputedPadding.right = std::max(0, nsLayoutUtils::
|
2008-07-17 16:37:12 -07:00
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
2010-09-09 08:21:46 -07:00
|
|
|
stylePadding->mPadding.GetRight()));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// According to the CSS2 spec, percentages are calculated with respect to
|
|
|
|
// containing block width for padding-top and padding-bottom
|
2013-01-15 04:22:03 -08:00
|
|
|
mComputedPadding.top = std::max(0, nsLayoutUtils::
|
2008-07-17 16:37:12 -07:00
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
2010-09-09 08:21:46 -07:00
|
|
|
stylePadding->mPadding.GetTop()));
|
2013-01-15 04:22:03 -08:00
|
|
|
mComputedPadding.bottom = std::max(0, nsLayoutUtils::
|
2008-07-17 16:37:12 -07:00
|
|
|
ComputeWidthDependentValue(aContainingBlockWidth,
|
2010-09-09 08:21:46 -07:00
|
|
|
stylePadding->mPadding.GetBottom()));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-11-09 13:14:05 -08:00
|
|
|
return isWidthDependent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::ComputeMinMaxValues(nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
const nsHTMLReflowState* aContainingBlockRS)
|
|
|
|
{
|
2012-09-29 23:38:46 -07:00
|
|
|
#ifdef MOZ_FLEXBOX
|
|
|
|
nsFlexContainerFrame* flexContainerFrame = GetFlexContainer(frame);
|
|
|
|
#endif // MOZ_FLEXBOX
|
|
|
|
|
2012-09-04 16:26:10 -07:00
|
|
|
// Handle "min-width: auto"
|
|
|
|
if (eStyleUnit_Auto == mStylePosition->mMinWidth.GetUnit()) {
|
|
|
|
mComputedMinWidth = 0;
|
2012-09-29 23:38:46 -07:00
|
|
|
#ifdef MOZ_FLEXBOX
|
|
|
|
if (flexContainerFrame && flexContainerFrame->IsHorizontal()) {
|
|
|
|
mComputedMinWidth =
|
|
|
|
ComputeWidthValue(aContainingBlockWidth,
|
|
|
|
mStylePosition->mBoxSizing,
|
|
|
|
nsStyleCoord(NS_STYLE_WIDTH_MIN_CONTENT,
|
|
|
|
eStyleUnit_Enumerated));
|
|
|
|
}
|
|
|
|
#endif // MOZ_FLEXBOX
|
2012-09-04 16:26:10 -07:00
|
|
|
} else {
|
|
|
|
mComputedMinWidth = ComputeWidthValue(aContainingBlockWidth,
|
|
|
|
mStylePosition->mBoxSizing,
|
|
|
|
mStylePosition->mMinWidth);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-10 23:01:31 -07:00
|
|
|
if (eStyleUnit_None == mStylePosition->mMaxWidth.GetUnit()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Specified value of 'none'
|
|
|
|
mComputedMaxWidth = NS_UNCONSTRAINEDSIZE; // no limit
|
|
|
|
} else {
|
2007-05-03 16:11:00 -07:00
|
|
|
mComputedMaxWidth = ComputeWidthValue(aContainingBlockWidth,
|
|
|
|
mStylePosition->mBoxSizing,
|
|
|
|
mStylePosition->mMaxWidth);
|
2007-03-22 10:30:00 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for percentage based values and a containing block height that
|
|
|
|
// depends on the content height. Treat them like 'auto'
|
2012-11-21 08:19:30 -08:00
|
|
|
// Likewise, check for calc() with percentages on internal table elements;
|
|
|
|
// that's treated as 'auto' too.
|
2012-09-29 23:38:46 -07:00
|
|
|
// Likewise, if we're a child of a flex container who's measuring our
|
|
|
|
// intrinsic height, then we want to disregard our min-height.
|
|
|
|
|
2012-09-04 16:26:11 -07:00
|
|
|
// NOTE: We treat "min-height:auto" as "0" for the purpose of this code,
|
|
|
|
// since that's what it means in all cases except for on flex items -- and
|
|
|
|
// even there, we're supposed to ignore it (i.e. treat it as 0) until the
|
|
|
|
// flex container explicitly considers it.
|
2010-08-25 03:17:55 -07:00
|
|
|
const nsStyleCoord &minHeight = mStylePosition->mMinHeight;
|
2012-09-04 16:26:11 -07:00
|
|
|
if (eStyleUnit_Auto == minHeight.GetUnit() ||
|
|
|
|
(NS_AUTOHEIGHT == aContainingBlockHeight &&
|
2010-08-25 03:17:55 -07:00
|
|
|
minHeight.HasPercent()) ||
|
|
|
|
(mFrameType == NS_CSS_FRAME_TYPE_INTERNAL_TABLE &&
|
2012-11-21 08:19:30 -08:00
|
|
|
minHeight.IsCalcUnit() && minHeight.CalcHasPercent()) ||
|
2012-09-29 23:38:46 -07:00
|
|
|
mFlags.mIsFlexContainerMeasuringHeight) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mComputedMinHeight = 0;
|
|
|
|
} else {
|
2012-08-08 08:58:26 -07:00
|
|
|
mComputedMinHeight = ComputeHeightValue(aContainingBlockHeight,
|
|
|
|
mStylePosition->mBoxSizing,
|
|
|
|
minHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-25 03:17:55 -07:00
|
|
|
const nsStyleCoord &maxHeight = mStylePosition->mMaxHeight;
|
|
|
|
nsStyleUnit maxHeightUnit = maxHeight.GetUnit();
|
2007-05-10 23:01:31 -07:00
|
|
|
if (eStyleUnit_None == maxHeightUnit) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Specified value of 'none'
|
|
|
|
mComputedMaxHeight = NS_UNCONSTRAINEDSIZE; // no limit
|
|
|
|
} else {
|
|
|
|
// Check for percentage based values and a containing block height that
|
2012-09-29 23:38:46 -07:00
|
|
|
// depends on the content height. Treat them like 'none'
|
2012-11-21 08:19:30 -08:00
|
|
|
// Likewise, check for calc() with percentages on internal table elements;
|
|
|
|
// that's treated as 'auto' too.
|
2012-09-29 23:38:46 -07:00
|
|
|
// Likewise, if we're a child of a flex container who's measuring our
|
|
|
|
// intrinsic height, then we want to disregard our max-height.
|
2010-08-25 03:17:55 -07:00
|
|
|
if ((NS_AUTOHEIGHT == aContainingBlockHeight &&
|
|
|
|
maxHeight.HasPercent()) ||
|
|
|
|
(mFrameType == NS_CSS_FRAME_TYPE_INTERNAL_TABLE &&
|
2012-11-21 08:19:30 -08:00
|
|
|
maxHeight.IsCalcUnit() && maxHeight.CalcHasPercent()) ||
|
2012-09-29 23:38:46 -07:00
|
|
|
mFlags.mIsFlexContainerMeasuringHeight) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
} else {
|
2012-08-08 08:58:26 -07:00
|
|
|
mComputedMaxHeight = ComputeHeightValue(aContainingBlockHeight,
|
|
|
|
mStylePosition->mBoxSizing,
|
|
|
|
maxHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLReflowState::SetTruncated(const nsHTMLReflowMetrics& aMetrics,
|
|
|
|
nsReflowStatus* aStatus) const
|
|
|
|
{
|
|
|
|
if (availableHeight != NS_UNCONSTRAINEDSIZE &&
|
|
|
|
availableHeight < aMetrics.height &&
|
|
|
|
!mFlags.mIsTopOfPage) {
|
|
|
|
*aStatus |= NS_FRAME_TRUNCATED;
|
|
|
|
} else {
|
|
|
|
*aStatus &= ~NS_FRAME_TRUNCATED;
|
|
|
|
}
|
|
|
|
}
|