Added mOverflow to nsStylePosition

This commit is contained in:
troy
1998-04-25 04:07:18 +00:00
parent 4ffef519d7
commit aaf7dee790
10 changed files with 129 additions and 85 deletions

View File

@@ -218,6 +218,7 @@ struct StylePositionImpl: public nsStylePosition {
StylePositionImpl(void) StylePositionImpl(void)
{ {
mPosition = NS_STYLE_POSITION_STATIC; mPosition = NS_STYLE_POSITION_STATIC;
mOverflow = NS_STYLE_OVERFLOW_VISIBLE;
mLeftOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; mLeftOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO;
mLeftOffset = 0; mLeftOffset = 0;
mTopOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; mTopOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO;

View File

@@ -668,6 +668,11 @@ void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* a
position->mPosition = ourPosition->mPosition.GetIntValue(); 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 // box offsets. note: default value is auto so we don't check for it here
if (ourPosition->mLeft.IsLengthUnit()) { if (ourPosition->mLeft.IsLengthUnit()) {
position->mLeftOffset = CalcLength(ourPosition->mLeft, font, aPresContext); position->mLeftOffset = CalcLength(ourPosition->mLeft, font, aPresContext);

View File

@@ -116,6 +116,7 @@ struct nsStyleList : public nsStyleStruct {
struct nsStylePosition : public nsStyleStruct { struct nsStylePosition : public nsStyleStruct {
PRUint8 mPosition; // see nsStyleConsts.h PRUint8 mPosition; // see nsStyleConsts.h
PRUint8 mOverflow; // see nsStyleConsts.h
PRUint8 mLeftOffsetFlags; // see nsStyleConsts.h PRUint8 mLeftOffsetFlags; // see nsStyleConsts.h
nscoord mLeftOffset; nscoord mLeftOffset;

View File

@@ -62,9 +62,6 @@
#define NS_STYLE_CLEAR_RIGHT 0x2 #define NS_STYLE_CLEAR_RIGHT 0x2
#define NS_STYLE_CLEAR_BOTH 0x3 #define NS_STYLE_CLEAR_BOTH 0x3
// See nsStyleMolecule.clipFlags
#define NS_STYLE_CLIP_AUTO 0
// See nsStyleMolecule.cursor // See nsStyleMolecule.cursor
#define NS_STYLE_CURSOR_INHERIT 0 #define NS_STYLE_CURSOR_INHERIT 0
#define NS_STYLE_CURSOR_DEFAULT 1 #define NS_STYLE_CURSOR_DEFAULT 1
@@ -112,7 +109,7 @@
#define NS_STYLE_FONT_SIZE_LARGER 7 #define NS_STYLE_FONT_SIZE_LARGER 7
#define NS_STYLE_FONT_SIZE_SMALLER 8 #define NS_STYLE_FONT_SIZE_SMALLER 8
// See nsStylePosition // See nsStylePosition.mPosition
#define NS_STYLE_POSITION_STATIC 0 #define NS_STYLE_POSITION_STATIC 0
#define NS_STYLE_POSITION_RELATIVE 1 #define NS_STYLE_POSITION_RELATIVE 1
#define NS_STYLE_POSITION_ABSOLUTE 2 #define NS_STYLE_POSITION_ABSOLUTE 2
@@ -123,6 +120,16 @@
#define NS_STYLE_POSITION_VALUE_AUTO 2 #define NS_STYLE_POSITION_VALUE_AUTO 2
#define NS_STYLE_POSITION_VALUE_INHERIT 3 #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_HEIGHT_AUTO 0
#define NS_STYLE_LEFT_AUTO 0 #define NS_STYLE_LEFT_AUTO 0
@@ -147,11 +154,6 @@
#define NS_STYLE_MARGIN_SIZE_AUTO 0 #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_SPACING_NORMAL 0
#define NS_STYLE_TEXT_ALIGN_LEFT 0 #define NS_STYLE_TEXT_ALIGN_LEFT 0

View File

@@ -218,6 +218,7 @@ struct StylePositionImpl: public nsStylePosition {
StylePositionImpl(void) StylePositionImpl(void)
{ {
mPosition = NS_STYLE_POSITION_STATIC; mPosition = NS_STYLE_POSITION_STATIC;
mOverflow = NS_STYLE_OVERFLOW_VISIBLE;
mLeftOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; mLeftOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO;
mLeftOffset = 0; mLeftOffset = 0;
mTopOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; mTopOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO;

View File

@@ -64,15 +64,12 @@ AbsoluteFrame::~AbsoluteFrame()
{ {
} }
nsIView* AbsoluteFrame::CreateView(nsIFrame* aContainingBlock, nsIView* AbsoluteFrame::CreateView(nsIView* aContainingView,
const nsRect& aRect, const nsRect& aRect,
PRInt32 aZIndex) PRInt32 aZIndex)
{ {
nsIView* containingView;
nsIView* view; 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(kViewCID, NS_VIEW_CID);
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID); static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
@@ -81,7 +78,7 @@ nsIView* AbsoluteFrame::CreateView(nsIFrame* aContainingBlock,
kIViewIID, kIViewIID,
(void **)&view); (void **)&view);
if (NS_OK == result) { if (NS_OK == result) {
nsIViewManager* viewManager = containingView->GetViewManager(); nsIViewManager* viewManager = aContainingView->GetViewManager();
// Initialize the view // Initialize the view
NS_ASSERTION(nsnull != viewManager, "null view manager"); NS_ASSERTION(nsnull != viewManager, "null view manager");
@@ -90,7 +87,7 @@ nsIView* AbsoluteFrame::CreateView(nsIFrame* aContainingBlock,
nsIScrollableView* scrollView = nsnull; nsIScrollableView* scrollView = nsnull;
nsresult result; nsresult result;
result = containingView->QueryInterface(kIScrollableViewIID, (void**)&scrollView); result = aContainingView->QueryInterface(kIScrollableViewIID, (void**)&scrollView);
if (NS_OK == result) { if (NS_OK == result) {
nsIView* scrolledView = scrollView->GetScrolledView(); nsIView* scrolledView = scrollView->GetScrolledView();
@@ -99,85 +96,78 @@ nsIView* AbsoluteFrame::CreateView(nsIFrame* aContainingBlock,
NS_RELEASE(scrolledView); NS_RELEASE(scrolledView);
NS_RELEASE(scrollView); NS_RELEASE(scrollView);
} else { } else {
view->Init(viewManager, aRect, containingView, nsnull, nsnull, nsnull, aZIndex); view->Init(viewManager, aRect, aContainingView, nsnull, nsnull, nsnull, aZIndex);
viewManager->InsertChild(containingView, view, 0); viewManager->InsertChild(aContainingView, view, 0);
} }
NS_RELEASE(viewManager); NS_RELEASE(viewManager);
} }
NS_RELEASE(containingView);
return view; 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 // Compute the offset and size of the view based on the position properties
// when computing the size of our view // and the inner rect of the containing block
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
nsStylePosition* position = (nsStylePosition*)mStyleContext->GetData(kStylePositionSID); nsStylePosition* position = (nsStylePosition*)mStyleContext->GetData(kStylePositionSID);
// x-offset
if (NS_STYLE_POSITION_VALUE_AUTO == position->mLeftOffsetFlags) { if (NS_STYLE_POSITION_VALUE_AUTO == position->mLeftOffsetFlags) {
// Left offset should be automatically computed // XXX This isn't correct. We should use the current x-offset of our frame
if (NS_STYLE_POSITION_VALUE_AUTO == position->mWidthFlags) { // translated into the coordinate space of the containing block. But, we
// When both properties are 'auto' the width is the same as the width of // don't know it yet...
// the containing block
aRect.width = containingRect.width;
aRect.x = 0; aRect.x = 0;
} else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mWidthFlags) { } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mLeftOffsetFlags) {
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 {
aRect.x = position->mLeftOffset; aRect.x = position->mLeftOffset;
} 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) {
// 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);
}
// width
if (NS_STYLE_POSITION_VALUE_AUTO == position->mWidthFlags) { if (NS_STYLE_POSITION_VALUE_AUTO == position->mWidthFlags) {
aRect.width = containingRect.width - aRect.x; // Use the right-edge of the containing block
aRect.width = aContainingInnerRect.width - aRect.x;
} else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mWidthFlags) { } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mWidthFlags) {
aRect.width = position->mWidth; aRect.width = position->mWidth;
} else { } else {
NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mWidthFlags, "unexpected width"); NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mWidthFlags,
aRect.width = containingRect.width * position->mWidth / 100; "unexpected width type");
} aRect.width = aContainingInnerRect.width * position->mWidth / 100;
} }
if (NS_STYLE_POSITION_VALUE_AUTO == position->mTopOffsetFlags) { // height
// Top offset should be automatically computed
if (NS_STYLE_POSITION_VALUE_AUTO == position->mHeightFlags) { if (NS_STYLE_POSITION_VALUE_AUTO == position->mHeightFlags) {
// When both properties are 'auto' the height is the same as the height of // Allow it to be as high as it wants
// the containing block aRect.height = NS_UNCONSTRAINEDSIZE;
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 {
aRect.y = position->mTopOffset;
if (NS_STYLE_POSITION_VALUE_AUTO == position->mHeightFlags) {
aRect.height = containingRect.height - aRect.y;
} else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mHeightFlags) { } else if (NS_STYLE_POSITION_VALUE_LENGTH == position->mHeightFlags) {
aRect.height = position->mHeight; aRect.height = position->mHeight;
} else { } else {
NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mHeightFlags, "unexpected height"); NS_ASSERTION(NS_STYLE_POSITION_VALUE_PCT == position->mHeightFlags,
aRect.height = containingRect.height * position->mHeight / 100; "unexpected height type");
} aRect.height = aContainingInnerRect.height * position->mHeight / 100;
} }
} }
@@ -239,17 +229,30 @@ NS_METHOD AbsoluteFrame::ResizeReflow(nsIPresContext* aPresContext,
mFrame->SetStyleContext(mStyleContext); mFrame->SetStyleContext(mStyleContext);
} }
// Get the containing block // Get the containing block, and its associated view
nsIFrame* containingBlock = GetContainingBlock(); nsIFrame* containingBlock = GetContainingBlock();
// Determine the view's rect // 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;
// 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;
// Use the position properties to determine the offset and size
nsStylePosition* position = (nsStylePosition*)mStyleContext->GetData(kStylePositionSID);
nsRect rect; nsRect rect;
ComputeViewsRect(containingBlock, rect); ComputeViewBounds(containingRect, position, rect);
// Create a view for the frame // Create a view for the frame
nsStylePosition* position = (nsStylePosition*)mStyleContext->GetData(kStylePositionSID); nsIView* view = CreateView(containingView, rect, position->mZIndex);
nsIView* view = CreateView(containingBlock, rect, position->mZIndex); NS_RELEASE(containingView);
mFrame->SetView(view); mFrame->SetView(view);
NS_RELEASE(view); NS_RELEASE(view);
@@ -257,7 +260,25 @@ NS_METHOD AbsoluteFrame::ResizeReflow(nsIPresContext* aPresContext,
// Resize reflow the absolutely positioned element // Resize reflow the absolutely positioned element
nsSize availSize(rect.width, rect.height); 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); 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); mFrame->SizeTo(rect.width, rect.height);
} }

View File

@@ -53,11 +53,13 @@ protected:
virtual ~AbsoluteFrame(); virtual ~AbsoluteFrame();
nsIView* CreateView(nsIFrame* aContainingBlock, nsIView* CreateView(nsIView* aContainingView,
const nsRect& aRect, const nsRect& aRect,
PRInt32 aZIndex); PRInt32 aZIndex);
nsIFrame* GetContainingBlock(); nsIFrame* GetContainingBlock();
void ComputeViewsRect(nsIFrame* aContainingBlock, nsRect& aRect); void ComputeViewBounds(const nsRect& aContainingInnerRect,
nsStylePosition* aPosition,
nsRect& aRect);
}; };
#endif /* nsAbsoluteFrame_h___ */ #endif /* nsAbsoluteFrame_h___ */

View File

@@ -668,6 +668,11 @@ void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* a
position->mPosition = ourPosition->mPosition.GetIntValue(); 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 // box offsets. note: default value is auto so we don't check for it here
if (ourPosition->mLeft.IsLengthUnit()) { if (ourPosition->mLeft.IsLengthUnit()) {
position->mLeftOffset = CalcLength(ourPosition->mLeft, font, aPresContext); position->mLeftOffset = CalcLength(ourPosition->mLeft, font, aPresContext);

View File

@@ -668,6 +668,11 @@ void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* a
position->mPosition = ourPosition->mPosition.GetIntValue(); 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 // box offsets. note: default value is auto so we don't check for it here
if (ourPosition->mLeft.IsLengthUnit()) { if (ourPosition->mLeft.IsLengthUnit()) {
position->mLeftOffset = CalcLength(ourPosition->mLeft, font, aPresContext); position->mLeftOffset = CalcLength(ourPosition->mLeft, font, aPresContext);

View File

@@ -218,6 +218,7 @@ struct StylePositionImpl: public nsStylePosition {
StylePositionImpl(void) StylePositionImpl(void)
{ {
mPosition = NS_STYLE_POSITION_STATIC; mPosition = NS_STYLE_POSITION_STATIC;
mOverflow = NS_STYLE_OVERFLOW_VISIBLE;
mLeftOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; mLeftOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO;
mLeftOffset = 0; mLeftOffset = 0;
mTopOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO; mTopOffsetFlags = NS_STYLE_POSITION_VALUE_AUTO;