From 6401d192b23b95aca0b2d0c4e47eb0a3f008f60b Mon Sep 17 00:00:00 2001 From: troy Date: Sat, 25 Apr 1998 04:07:18 +0000 Subject: [PATCH] Added mOverflow to nsStylePosition git-svn-id: svn://10.0.0.236/trunk@637 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsStyleContext.cpp | 1 + .../content/html/style/src/nsCSSStyleRule.cpp | 5 + mozilla/layout/base/public/nsIStyleContext.h | 1 + mozilla/layout/base/src/nsStyleConsts.h | 20 ++- mozilla/layout/base/src/nsStyleContext.cpp | 1 + .../layout/html/base/src/nsAbsoluteFrame.cpp | 169 ++++++++++-------- .../layout/html/base/src/nsAbsoluteFrame.h | 6 +- .../layout/html/style/src/nsCSSStyleRule.cpp | 5 + mozilla/layout/style/nsCSSStyleRule.cpp | 5 + mozilla/layout/style/nsStyleContext.cpp | 1 + 10 files changed, 129 insertions(+), 85 deletions(-) diff --git a/mozilla/content/base/src/nsStyleContext.cpp b/mozilla/content/base/src/nsStyleContext.cpp index 7764a36b211..068c2ed1c13 100644 --- a/mozilla/content/base/src/nsStyleContext.cpp +++ b/mozilla/content/base/src/nsStyleContext.cpp @@ -218,6 +218,7 @@ struct StylePositionImpl: public nsStylePosition { StylePositionImpl(void) { mPosition = NS_STYLE_POSITION_STATIC; + mOverflow = NS_STYLE_OVERFLOW_VISIBLE; mLeftOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; mLeftOffset = 0; mTopOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; diff --git a/mozilla/content/html/style/src/nsCSSStyleRule.cpp b/mozilla/content/html/style/src/nsCSSStyleRule.cpp index 028ab779b33..142fe62d356 100644 --- a/mozilla/content/html/style/src/nsCSSStyleRule.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleRule.cpp @@ -668,6 +668,11 @@ void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* a position->mPosition = ourPosition->mPosition.GetIntValue(); } + // overflow + if (ourPosition->mOverflow.GetUnit() == eCSSUnit_Enumerated) { + position->mOverflow = ourPosition->mOverflow.GetIntValue(); + } + // box offsets. note: default value is auto so we don't check for it here if (ourPosition->mLeft.IsLengthUnit()) { position->mLeftOffset = CalcLength(ourPosition->mLeft, font, aPresContext); diff --git a/mozilla/layout/base/public/nsIStyleContext.h b/mozilla/layout/base/public/nsIStyleContext.h index 492d4cf8b9d..574758167ac 100644 --- a/mozilla/layout/base/public/nsIStyleContext.h +++ b/mozilla/layout/base/public/nsIStyleContext.h @@ -116,6 +116,7 @@ struct nsStyleList : public nsStyleStruct { struct nsStylePosition : public nsStyleStruct { PRUint8 mPosition; // see nsStyleConsts.h + PRUint8 mOverflow; // see nsStyleConsts.h PRUint8 mLeftOffsetFlags; // see nsStyleConsts.h nscoord mLeftOffset; diff --git a/mozilla/layout/base/src/nsStyleConsts.h b/mozilla/layout/base/src/nsStyleConsts.h index 19d0170954f..2837cc1f34d 100644 --- a/mozilla/layout/base/src/nsStyleConsts.h +++ b/mozilla/layout/base/src/nsStyleConsts.h @@ -62,9 +62,6 @@ #define NS_STYLE_CLEAR_RIGHT 0x2 #define NS_STYLE_CLEAR_BOTH 0x3 -// See nsStyleMolecule.clipFlags -#define NS_STYLE_CLIP_AUTO 0 - // See nsStyleMolecule.cursor #define NS_STYLE_CURSOR_INHERIT 0 #define NS_STYLE_CURSOR_DEFAULT 1 @@ -112,7 +109,7 @@ #define NS_STYLE_FONT_SIZE_LARGER 7 #define NS_STYLE_FONT_SIZE_SMALLER 8 -// See nsStylePosition +// See nsStylePosition.mPosition #define NS_STYLE_POSITION_STATIC 0 #define NS_STYLE_POSITION_RELATIVE 1 #define NS_STYLE_POSITION_ABSOLUTE 2 @@ -123,6 +120,16 @@ #define NS_STYLE_POSITION_VALUE_AUTO 2 #define NS_STYLE_POSITION_VALUE_INHERIT 3 +// See nsStylePosition.mClip +#define NS_STYLE_CLIP_AUTO 0 +#define NS_STYLE_CLIP_RECT 1 + +// See nsStylePosition.mOverflow +#define NS_STYLE_OVERFLOW_VISIBLE 0 +#define NS_STYLE_OVERFLOW_HIDDEN 1 +#define NS_STYLE_OVERFLOW_SCROLL 2 +#define NS_STYLE_OVERFLOW_AUTO 3 + #define NS_STYLE_HEIGHT_AUTO 0 #define NS_STYLE_LEFT_AUTO 0 @@ -147,11 +154,6 @@ #define NS_STYLE_MARGIN_SIZE_AUTO 0 -#define NS_STYLE_OVERFLOW_VISIBLE 0 -#define NS_STYLE_OVERFLOW_HIDDEN 1 -#define NS_STYLE_OVERFLOW_SCROLL 2 -#define NS_STYLE_OVERFLOW_AUTO 3 - #define NS_STYLE_SPACING_NORMAL 0 #define NS_STYLE_TEXT_ALIGN_LEFT 0 diff --git a/mozilla/layout/base/src/nsStyleContext.cpp b/mozilla/layout/base/src/nsStyleContext.cpp index 7764a36b211..068c2ed1c13 100644 --- a/mozilla/layout/base/src/nsStyleContext.cpp +++ b/mozilla/layout/base/src/nsStyleContext.cpp @@ -218,6 +218,7 @@ struct StylePositionImpl: public nsStylePosition { StylePositionImpl(void) { mPosition = NS_STYLE_POSITION_STATIC; + mOverflow = NS_STYLE_OVERFLOW_VISIBLE; mLeftOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; mLeftOffset = 0; mTopOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; diff --git a/mozilla/layout/html/base/src/nsAbsoluteFrame.cpp b/mozilla/layout/html/base/src/nsAbsoluteFrame.cpp index 48f79284a7e..da6acb2e9c0 100644 --- a/mozilla/layout/html/base/src/nsAbsoluteFrame.cpp +++ b/mozilla/layout/html/base/src/nsAbsoluteFrame.cpp @@ -64,15 +64,12 @@ AbsoluteFrame::~AbsoluteFrame() { } -nsIView* AbsoluteFrame::CreateView(nsIFrame* aContainingBlock, +nsIView* AbsoluteFrame::CreateView(nsIView* aContainingView, const nsRect& aRect, PRInt32 aZIndex) { - nsIView* containingView; nsIView* view; - // Create a view for the frame and position it - aContainingBlock->GetView(containingView); static NS_DEFINE_IID(kViewCID, NS_VIEW_CID); static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID); @@ -81,7 +78,7 @@ nsIView* AbsoluteFrame::CreateView(nsIFrame* aContainingBlock, kIViewIID, (void **)&view); if (NS_OK == result) { - nsIViewManager* viewManager = containingView->GetViewManager(); + nsIViewManager* viewManager = aContainingView->GetViewManager(); // Initialize the view NS_ASSERTION(nsnull != viewManager, "null view manager"); @@ -90,7 +87,7 @@ nsIView* AbsoluteFrame::CreateView(nsIFrame* aContainingBlock, nsIScrollableView* scrollView = nsnull; nsresult result; - result = containingView->QueryInterface(kIScrollableViewIID, (void**)&scrollView); + result = aContainingView->QueryInterface(kIScrollableViewIID, (void**)&scrollView); if (NS_OK == result) { nsIView* scrolledView = scrollView->GetScrolledView(); @@ -99,85 +96,78 @@ nsIView* AbsoluteFrame::CreateView(nsIFrame* aContainingBlock, NS_RELEASE(scrolledView); NS_RELEASE(scrollView); } else { - view->Init(viewManager, aRect, containingView, nsnull, nsnull, nsnull, aZIndex); - viewManager->InsertChild(containingView, view, 0); + view->Init(viewManager, aRect, aContainingView, nsnull, nsnull, nsnull, aZIndex); + viewManager->InsertChild(aContainingView, view, 0); } NS_RELEASE(viewManager); } - NS_RELEASE(containingView); + return view; } -void AbsoluteFrame::ComputeViewsRect(nsIFrame* aContainingBlock, nsRect& aRect) +void AbsoluteFrame::ComputeViewBounds(const nsRect& aContainingInnerRect, + nsStylePosition* aPosition, + nsRect& aRect) { - // Get the bounding rect for the containing block's view. This is used - // when computing the size of our view - nsIView* containingView; - nsRect containingRect; - - aContainingBlock->GetView(containingView); - NS_ASSERTION(nsnull != containingView, "no view"); - containingView->GetBounds(containingRect); - NS_RELEASE(containingView); - - // Compute the offset and size for the view based on the position properties + // Compute the offset and size of the view based on the position properties + // and the inner rect of the containing block nsStylePosition* position = (nsStylePosition*)mStyleContext->GetData(kStylePositionSID); + // x-offset if (NS_STYLE_POSITION_VALUE_AUTO == position->mLeftOffsetFlags) { - // Left offset should be automatically computed - if (NS_STYLE_POSITION_VALUE_AUTO == position->mWidthFlags) { - // When both properties are 'auto' the width is the same as the width of - // the containing block - aRect.width = containingRect.width; - aRect.x = 0; - } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mWidthFlags) { - aRect.width = position->mWidth; - aRect.x = containingRect.width - aRect.width; - } else { - NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mWidthFlags, "unexpected width"); - aRect.width = containingRect.width * position->mWidth / 100; - aRect.x = 0; - } - } else { + // XXX This isn't correct. We should use the current x-offset of our frame + // translated into the coordinate space of the containing block. But, we + // don't know it yet... + aRect.x = 0; + } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mLeftOffsetFlags) { aRect.x = position->mLeftOffset; - - if (NS_STYLE_POSITION_VALUE_AUTO == position->mWidthFlags) { - aRect.width = containingRect.width - aRect.x; - } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mWidthFlags) { - aRect.width = position->mWidth; - } else { - NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mWidthFlags, "unexpected width"); - aRect.width = containingRect.width * position->mWidth / 100; - } + } else { + NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mLeftOffsetFlags, + "unexpected offset type"); + // Percentage values refer to the width of the containing block + aRect.x = aContainingInnerRect.x + (aContainingInnerRect.width * + position->mLeftOffset / 100); } + // y-offset if (NS_STYLE_POSITION_VALUE_AUTO == position->mTopOffsetFlags) { - // Top offset should be automatically computed - if (NS_STYLE_POSITION_VALUE_AUTO == position->mHeightFlags) { - // When both properties are 'auto' the height is the same as the height of - // the containing block - aRect.height = containingRect.height; - aRect.y = 0; - } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mHeightFlags) { - aRect.height = position->mHeight; - aRect.y = containingRect.height - aRect.height; - } else { - NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mHeightFlags, "unexpected height"); - aRect.height = containingRect.height * position->mHeight / 100; - aRect.y = 0; - } - } else { + // XXX This isn't correct. We should use the current y-offset of our frame + // translated into the coordinate space of the containing block. But, we + // don't know it yet... + aRect.y = 0; + } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mTopOffsetFlags) { aRect.y = position->mTopOffset; + } else { + NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mTopOffsetFlags, + "unexpected offset type"); + // Percentage values refer to the height of the containing block + aRect.y = aContainingInnerRect.y + (aContainingInnerRect.height * + position->mTopOffset / 100); + } - if (NS_STYLE_POSITION_VALUE_AUTO == position->mHeightFlags) { - aRect.height = containingRect.height - aRect.y; - } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mHeightFlags) { - aRect.height = position->mHeight; - } else { - NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mHeightFlags, "unexpected height"); - aRect.height = containingRect.height * position->mHeight / 100; - } + // width + if (NS_STYLE_POSITION_VALUE_AUTO == position->mWidthFlags) { + // Use the right-edge of the containing block + aRect.width = aContainingInnerRect.width - aRect.x; + } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mWidthFlags) { + aRect.width = position->mWidth; + } else { + NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mWidthFlags, + "unexpected width type"); + aRect.width = aContainingInnerRect.width * position->mWidth / 100; + } + + // height + if (NS_STYLE_POSITION_VALUE_AUTO == position->mHeightFlags) { + // Allow it to be as high as it wants + aRect.height = NS_UNCONSTRAINEDSIZE; + } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mHeightFlags) { + aRect.height = position->mHeight; + } else { + NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mHeightFlags, + "unexpected height type"); + aRect.height = aContainingInnerRect.height * position->mHeight / 100; } } @@ -239,17 +229,30 @@ NS_METHOD AbsoluteFrame::ResizeReflow(nsIPresContext* aPresContext, mFrame->SetStyleContext(mStyleContext); } - // Get the containing block + // Get the containing block, and its associated view nsIFrame* containingBlock = GetContainingBlock(); + + // Get the inner rect of the containing block. Because of the way the frame + // sizing protocol works (it's top-down and the size of a container is set + // after reflowing its children), get the rect from the containing block's + // view + nsIView* containingView; + nsRect containingRect; - // Determine the view's rect - nsRect rect; + // XXX We should be using the inner rect, and not just the bounding rect + containingBlock->GetView(containingView); + containingView->GetBounds(containingRect); + containingRect.x = containingRect.y = 0; - ComputeViewsRect(containingBlock, rect); + // Use the position properties to determine the offset and size + nsStylePosition* position = (nsStylePosition*)mStyleContext->GetData(kStylePositionSID); + nsRect rect; + + ComputeViewBounds(containingRect, position, rect); // Create a view for the frame - nsStylePosition* position = (nsStylePosition*)mStyleContext->GetData(kStylePositionSID); - nsIView* view = CreateView(containingBlock, rect, position->mZIndex); + nsIView* view = CreateView(containingView, rect, position->mZIndex); + NS_RELEASE(containingView); mFrame->SetView(view); NS_RELEASE(view); @@ -257,7 +260,25 @@ NS_METHOD AbsoluteFrame::ResizeReflow(nsIPresContext* aPresContext, // Resize reflow the absolutely positioned element nsSize availSize(rect.width, rect.height); + if (NS_STYLE_OVERFLOW_VISIBLE == position->mOverflow) { + // Don't constrain the height since the container should be enlarged to + // contain overflowing frames + availSize.height = NS_UNCONSTRAINEDSIZE; + } + mFrame->ResizeReflow(aPresContext, aDesiredSize, availSize, nsnull, aStatus); + + // Figure out what size to actually use. If the position style is 'auto' or + // the container should be enlarged to contain overflowing frames then use + // the desired size + if ((NS_STYLE_POSITION_VALUE_AUTO == position->mWidthFlags) || + ((aDesiredSize.width > availSize.width) && + (NS_STYLE_OVERFLOW_VISIBLE) == position->mOverflow)) { + rect.width = aDesiredSize.width; + } + if (NS_STYLE_POSITION_VALUE_AUTO == position->mHeightFlags) { + rect.height = aDesiredSize.height; + } mFrame->SizeTo(rect.width, rect.height); } diff --git a/mozilla/layout/html/base/src/nsAbsoluteFrame.h b/mozilla/layout/html/base/src/nsAbsoluteFrame.h index afdc31c9526..e84269153eb 100644 --- a/mozilla/layout/html/base/src/nsAbsoluteFrame.h +++ b/mozilla/layout/html/base/src/nsAbsoluteFrame.h @@ -53,11 +53,13 @@ protected: virtual ~AbsoluteFrame(); - nsIView* CreateView(nsIFrame* aContainingBlock, + nsIView* CreateView(nsIView* aContainingView, const nsRect& aRect, PRInt32 aZIndex); nsIFrame* GetContainingBlock(); - void ComputeViewsRect(nsIFrame* aContainingBlock, nsRect& aRect); + void ComputeViewBounds(const nsRect& aContainingInnerRect, + nsStylePosition* aPosition, + nsRect& aRect); }; #endif /* nsAbsoluteFrame_h___ */ diff --git a/mozilla/layout/html/style/src/nsCSSStyleRule.cpp b/mozilla/layout/html/style/src/nsCSSStyleRule.cpp index 028ab779b33..142fe62d356 100644 --- a/mozilla/layout/html/style/src/nsCSSStyleRule.cpp +++ b/mozilla/layout/html/style/src/nsCSSStyleRule.cpp @@ -668,6 +668,11 @@ void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* a position->mPosition = ourPosition->mPosition.GetIntValue(); } + // overflow + if (ourPosition->mOverflow.GetUnit() == eCSSUnit_Enumerated) { + position->mOverflow = ourPosition->mOverflow.GetIntValue(); + } + // box offsets. note: default value is auto so we don't check for it here if (ourPosition->mLeft.IsLengthUnit()) { position->mLeftOffset = CalcLength(ourPosition->mLeft, font, aPresContext); diff --git a/mozilla/layout/style/nsCSSStyleRule.cpp b/mozilla/layout/style/nsCSSStyleRule.cpp index 028ab779b33..142fe62d356 100644 --- a/mozilla/layout/style/nsCSSStyleRule.cpp +++ b/mozilla/layout/style/nsCSSStyleRule.cpp @@ -668,6 +668,11 @@ void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* a position->mPosition = ourPosition->mPosition.GetIntValue(); } + // overflow + if (ourPosition->mOverflow.GetUnit() == eCSSUnit_Enumerated) { + position->mOverflow = ourPosition->mOverflow.GetIntValue(); + } + // box offsets. note: default value is auto so we don't check for it here if (ourPosition->mLeft.IsLengthUnit()) { position->mLeftOffset = CalcLength(ourPosition->mLeft, font, aPresContext); diff --git a/mozilla/layout/style/nsStyleContext.cpp b/mozilla/layout/style/nsStyleContext.cpp index 7764a36b211..068c2ed1c13 100644 --- a/mozilla/layout/style/nsStyleContext.cpp +++ b/mozilla/layout/style/nsStyleContext.cpp @@ -218,6 +218,7 @@ struct StylePositionImpl: public nsStylePosition { StylePositionImpl(void) { mPosition = NS_STYLE_POSITION_STATIC; + mOverflow = NS_STYLE_OVERFLOW_VISIBLE; mLeftOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; mLeftOffset = 0; mTopOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO;