Consolidate code for determining when widths and heights depend on a container. (Bug 585715) r=bzbarsky a2.0=blocking2.0+

This commit is contained in:
L. David Baron 2010-08-11 12:32:52 -07:00
parent bc1a47c26f
commit 462a888804
3 changed files with 42 additions and 43 deletions

View File

@ -226,29 +226,9 @@ static inline PRBool IsFixedPaddingSize(nsStyleUnit aUnit) {
static inline PRBool IsFixedMarginSize(nsStyleUnit aUnit) {
return aUnit == eStyleUnit_Coord;
}
static inline PRBool IsFixedMaxSize(nsStyleUnit aUnit) {
return aUnit == eStyleUnit_None || aUnit == eStyleUnit_Coord;
}
static inline PRBool IsFixedOffset(nsStyleUnit aUnit) {
return aUnit == eStyleUnit_Coord;
}
static inline PRBool IsFixedHeight(nsStyleUnit aUnit) {
return aUnit == eStyleUnit_Coord;
}
static inline PRBool IsFixedWidth(const nsStyleCoord& aCoord)
{
return aCoord.GetUnit() == eStyleUnit_Coord ||
(aCoord.GetUnit() == eStyleUnit_Enumerated &&
(aCoord.GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
aCoord.GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT));
}
static inline PRBool IsFixedMaxWidth(const nsStyleCoord& aCoord)
{
return aCoord.GetUnit() == eStyleUnit_None ||
IsFixedWidth(aCoord);
}
PRBool
nsAbsoluteContainingBlock::FrameDependsOnContainer(nsIFrame* f,
@ -286,9 +266,9 @@ nsAbsoluteContainingBlock::FrameDependsOnContainer(nsIFrame* f,
// then our frame width does not depend on the parent width.
// Note that borders never depend on the parent width
// XXX All of the enumerated values except -moz-available are ok too.
if (!IsFixedWidth(pos->mWidth) ||
!IsFixedWidth(pos->mMinWidth) ||
!IsFixedMaxWidth(pos->mMaxWidth) ||
if (pos->WidthDependsOnContainer() ||
pos->MinWidthDependsOnContainer() ||
pos->MaxWidthDependsOnContainer() ||
!IsFixedPaddingSize(padding->mPadding.GetLeftUnit()) ||
!IsFixedPaddingSize(padding->mPadding.GetRightUnit())) {
return PR_TRUE;
@ -325,12 +305,12 @@ nsAbsoluteContainingBlock::FrameDependsOnContainer(nsIFrame* f,
// and height is a length or height and bottom are auto and top is not auto,
// then our frame height does not depend on the parent height.
// Note that borders never depend on the parent height
if (!(IsFixedHeight(pos->mHeight.GetUnit()) ||
(pos->mHeight.GetUnit() == eStyleUnit_Auto &&
if ((pos->HeightDependsOnContainer() &&
!(pos->mHeight.GetUnit() == eStyleUnit_Auto &&
pos->mOffset.GetBottomUnit() == eStyleUnit_Auto &&
pos->mOffset.GetTopUnit() != eStyleUnit_Auto)) ||
!IsFixedHeight(pos->mMinHeight.GetUnit()) ||
!IsFixedMaxSize(pos->mMaxHeight.GetUnit()) ||
pos->MinHeightDependsOnContainer() ||
pos->MaxHeightDependsOnContainer() ||
!IsFixedPaddingSize(padding->mPadding.GetTopUnit()) ||
!IsFixedPaddingSize(padding->mPadding.GetBottomUnit())) {
return PR_TRUE;

View File

@ -653,16 +653,6 @@ HasPercentageUnitSide(const nsStyleSides& aSides)
return PR_FALSE;
}
inline PRBool
WidthDependsOnContainer(const nsStyleCoord& aCoord)
{
return aCoord.GetUnit() == eStyleUnit_Percent ||
(aCoord.GetUnit() == eStyleUnit_Enumerated &&
(aCoord.GetIntValue() == NS_STYLE_WIDTH_AVAILABLE ||
aCoord.GetIntValue() == NS_STYLE_WIDTH_FIT_CONTENT));
}
static PRBool
IsPercentageAware(const nsIFrame* aFrame)
{
@ -694,9 +684,10 @@ IsPercentageAware(const nsIFrame* aFrame)
const nsStylePosition* pos = aFrame->GetStylePosition();
if (WidthDependsOnContainer(pos->mWidth) ||
WidthDependsOnContainer(pos->mMaxWidth) ||
WidthDependsOnContainer(pos->mMinWidth) ||
if ((pos->WidthDependsOnContainer() &&
pos->mWidth.GetUnit() != eStyleUnit_Auto) ||
pos->MaxWidthDependsOnContainer() ||
pos->MinWidthDependsOnContainer() ||
eStyleUnit_Percent == pos->mOffset.GetRightUnit() ||
eStyleUnit_Percent == pos->mOffset.GetLeftUnit()) {
return PR_TRUE;

View File

@ -1052,14 +1052,42 @@ struct nsStylePosition {
static PRBool ForceCompare() { return PR_TRUE; }
nsStyleSides mOffset; // [reset] coord, percent, auto
nsStyleCoord mWidth; // [reset] coord, percent, auto, enum
nsStyleCoord mWidth; // [reset] coord, percent, enum, auto
nsStyleCoord mMinWidth; // [reset] coord, percent, enum
nsStyleCoord mMaxWidth; // [reset] coord, percent, null, enum
nsStyleCoord mMaxWidth; // [reset] coord, percent, enum, none
nsStyleCoord mHeight; // [reset] coord, percent, auto
nsStyleCoord mMinHeight; // [reset] coord, percent
nsStyleCoord mMaxHeight; // [reset] coord, percent, null
nsStyleCoord mMaxHeight; // [reset] coord, percent, none
PRUint8 mBoxSizing; // [reset] see nsStyleConsts.h
nsStyleCoord mZIndex; // [reset] integer, auto
PRBool WidthDependsOnContainer() const
{ return WidthCoordDependsOnContainer(mWidth); }
PRBool MinWidthDependsOnContainer() const
{ return WidthCoordDependsOnContainer(mMinWidth); }
PRBool MaxWidthDependsOnContainer() const
{ return WidthCoordDependsOnContainer(mMaxWidth); }
PRBool HeightDependsOnContainer() const
{ return HeightCoordDependsOnContainer(mHeight); }
PRBool MinHeightDependsOnContainer() const
{ return HeightCoordDependsOnContainer(mMinHeight); }
PRBool MaxHeightDependsOnContainer() const
{ return HeightCoordDependsOnContainer(mMaxHeight); }
private:
static PRBool WidthCoordDependsOnContainer(const nsStyleCoord &aCoord)
{
return aCoord.GetUnit() == eStyleUnit_Auto ||
aCoord.GetUnit() == eStyleUnit_Percent ||
(aCoord.GetUnit() == eStyleUnit_Enumerated &&
(aCoord.GetIntValue() == NS_STYLE_WIDTH_FIT_CONTENT ||
aCoord.GetIntValue() == NS_STYLE_WIDTH_AVAILABLE));
}
static PRBool HeightCoordDependsOnContainer(const nsStyleCoord &aCoord)
{
return aCoord.GetUnit() == eStyleUnit_Auto || // CSS 2.1, 10.6.4, item (5)
aCoord.GetUnit() == eStyleUnit_Percent;
}
};
struct nsStyleTextReset {