From 70076f9b1f997b8aa0030191461ac46c095e8bb6 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Wed, 11 Aug 2010 12:32:52 -0700 Subject: [PATCH] Consolidate code for determining when widths and heights depend on a container. (Bug 585715) r=bzbarsky a2.0=blocking2.0+ --- layout/generic/nsAbsoluteContainingBlock.cpp | 34 ++++---------------- layout/generic/nsLineLayout.cpp | 17 +++------- layout/style/nsStyleStruct.h | 34 ++++++++++++++++++-- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/layout/generic/nsAbsoluteContainingBlock.cpp b/layout/generic/nsAbsoluteContainingBlock.cpp index f75ad060376..db839118508 100644 --- a/layout/generic/nsAbsoluteContainingBlock.cpp +++ b/layout/generic/nsAbsoluteContainingBlock.cpp @@ -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; diff --git a/layout/generic/nsLineLayout.cpp b/layout/generic/nsLineLayout.cpp index d8e346abe46..d9d51b745e8 100644 --- a/layout/generic/nsLineLayout.cpp +++ b/layout/generic/nsLineLayout.cpp @@ -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; diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index b7493394850..b8b99ae2c3f 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -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 {