Set max-element-size when computing reflow metrics

This commit is contained in:
kipp@netscape.com
1998-07-21 21:20:55 +00:00
parent ed5b92b235
commit 518b6bf201
2 changed files with 56 additions and 46 deletions

View File

@@ -48,7 +48,7 @@ protected:
nsReflowMetrics& aDesiredSize); nsReflowMetrics& aDesiredSize);
nsresult CreateWidget(nsIPresContext* aPresContext, nsresult CreateWidget(nsIPresContext* aPresContext,
nscoord aWidth, nscoord aHeight); nscoord aWidth, nscoord aHeight);
}; };
nsObjectFrame::nsObjectFrame(nsIContent* aContent, nsIFrame* aParentFrame) nsObjectFrame::nsObjectFrame(nsIContent* aContent, nsIFrame* aParentFrame)
@@ -66,7 +66,7 @@ static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID);
nsresult nsresult
nsObjectFrame::CreateWidget(nsIPresContext* aPresContext, nsObjectFrame::CreateWidget(nsIPresContext* aPresContext,
nscoord aWidth, nscoord aHeight) nscoord aWidth, nscoord aHeight)
{ {
nsIView* view; nsIView* view;
@@ -92,8 +92,8 @@ nsObjectFrame::CreateWidget(nsIPresContext* aPresContext,
// nsWidgetInitData* initData = GetWidgetInitData(*aPresContext); // needs to be deleted // nsWidgetInitData* initData = GetWidgetInitData(*aPresContext); // needs to be deleted
// initialize the view as hidden since we don't know the (x,y) until Paint // initialize the view as hidden since we don't know the (x,y) until Paint
result = view->Init(viewMan, boundBox, parView, &kWidgetCID, nsnull, result = view->Init(viewMan, boundBox, parView, &kWidgetCID, nsnull,
nsnull, 0, nsnull, nsnull, 0, nsnull,
1.0f, nsViewVisibility_kHide); 1.0f, nsViewVisibility_kHide);
// if (nsnull != initData) { // if (nsnull != initData) {
// delete(initData); // delete(initData);
// } // }
@@ -129,8 +129,8 @@ nsObjectFrame::CreateWidget(nsIPresContext* aPresContext,
void void
nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext, nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsReflowState& aReflowState, const nsReflowState& aReflowState,
nsReflowMetrics& aDesiredSize) nsReflowMetrics& aMetrics)
{ {
// Determine our size stylistically // Determine our size stylistically
nsSize styleSize; nsSize styleSize;
@@ -138,45 +138,49 @@ nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext,
PRBool haveWidth = PR_FALSE; PRBool haveWidth = PR_FALSE;
PRBool haveHeight = PR_FALSE; PRBool haveHeight = PR_FALSE;
if (0 != (ss & NS_SIZE_HAS_WIDTH)) { if (0 != (ss & NS_SIZE_HAS_WIDTH)) {
aDesiredSize.width = styleSize.width; aMetrics.width = styleSize.width;
haveWidth = PR_TRUE; haveWidth = PR_TRUE;
} }
if (0 != (ss & NS_SIZE_HAS_HEIGHT)) { if (0 != (ss & NS_SIZE_HAS_HEIGHT)) {
aDesiredSize.height = styleSize.height; aMetrics.height = styleSize.height;
haveHeight = PR_TRUE; haveHeight = PR_TRUE;
} }
// XXX Temporary auto-sizing logic // XXX Temporary auto-sizing logic
if (!haveWidth) { if (!haveWidth) {
if (haveHeight) { if (haveHeight) {
aDesiredSize.width = aDesiredSize.height; aMetrics.width = aMetrics.height;
} }
else { else {
float p2t = aPresContext->GetPixelsToTwips(); float p2t = aPresContext->GetPixelsToTwips();
aDesiredSize.width = nscoord(p2t * EMBED_DEF_DIM); aMetrics.width = nscoord(p2t * EMBED_DEF_DIM);
} }
} }
if (!haveHeight) { if (!haveHeight) {
if (haveWidth) { if (haveWidth) {
aDesiredSize.height = aDesiredSize.width; aMetrics.height = aMetrics.width;
} }
else { else {
float p2t = aPresContext->GetPixelsToTwips(); float p2t = aPresContext->GetPixelsToTwips();
aDesiredSize.height = nscoord(p2t * EMBED_DEF_DIM); aMetrics.height = nscoord(p2t * EMBED_DEF_DIM);
} }
} }
aDesiredSize.ascent = aDesiredSize.height; aMetrics.ascent = aMetrics.height;
aDesiredSize.descent = 0; aMetrics.descent = 0;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsObjectFrame::Reflow(nsIPresContext& aPresContext, nsObjectFrame::Reflow(nsIPresContext& aPresContext,
nsReflowMetrics& aDesiredSize, nsReflowMetrics& aMetrics,
const nsReflowState& aReflowState, const nsReflowState& aReflowState,
nsReflowStatus& aStatus) nsReflowStatus& aStatus)
{ {
// Get our desired size // Get our desired size
GetDesiredSize(&aPresContext, aReflowState, aDesiredSize); GetDesiredSize(&aPresContext, aReflowState, aMetrics);
if (nsnull != aMetrics.maxElementSize) {
aMetrics.maxElementSize->width = aMetrics.width;
aMetrics.maxElementSize->height = aMetrics.height;
}
// XXX deal with border and padding the usual way...wrap it up! // XXX deal with border and padding the usual way...wrap it up!
@@ -184,8 +188,8 @@ nsObjectFrame::Reflow(nsIPresContext& aPresContext,
nsIView* view; nsIView* view;
GetView(view); GetView(view);
if (nsnull == view) { if (nsnull == view) {
nsresult rv = CreateWidget(&aPresContext, aDesiredSize.width, nsresult rv = CreateWidget(&aPresContext, aMetrics.width,
aDesiredSize.height); aMetrics.height);
if (NS_OK != rv) { if (NS_OK != rv) {
return rv; return rv;
} }
@@ -200,7 +204,7 @@ nsObjectFrame::Reflow(nsIPresContext& aPresContext,
NS_IMETHODIMP NS_IMETHODIMP
nsObjectFrame::DidReflow(nsIPresContext& aPresContext, nsObjectFrame::DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus) nsDidReflowStatus aStatus)
{ {
nsresult rv = nsObjectFrameSuper::DidReflow(aPresContext, aStatus); nsresult rv = nsObjectFrameSuper::DidReflow(aPresContext, aStatus);
@@ -217,8 +221,9 @@ nsObjectFrame::DidReflow(nsIPresContext& aPresContext,
return rv; return rv;
} }
nsresult NS_NewObjectFrame(nsIFrame*& aFrameResult, nsIContent* aContent, nsresult
nsIFrame* aParentFrame) NS_NewObjectFrame(nsIFrame*& aFrameResult, nsIContent* aContent,
nsIFrame* aParentFrame)
{ {
aFrameResult = new nsObjectFrame(aContent, aParentFrame); aFrameResult = new nsObjectFrame(aContent, aParentFrame);
if (nsnull == aFrameResult) { if (nsnull == aFrameResult) {

View File

@@ -48,7 +48,7 @@ protected:
nsReflowMetrics& aDesiredSize); nsReflowMetrics& aDesiredSize);
nsresult CreateWidget(nsIPresContext* aPresContext, nsresult CreateWidget(nsIPresContext* aPresContext,
nscoord aWidth, nscoord aHeight); nscoord aWidth, nscoord aHeight);
}; };
nsObjectFrame::nsObjectFrame(nsIContent* aContent, nsIFrame* aParentFrame) nsObjectFrame::nsObjectFrame(nsIContent* aContent, nsIFrame* aParentFrame)
@@ -66,7 +66,7 @@ static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID);
nsresult nsresult
nsObjectFrame::CreateWidget(nsIPresContext* aPresContext, nsObjectFrame::CreateWidget(nsIPresContext* aPresContext,
nscoord aWidth, nscoord aHeight) nscoord aWidth, nscoord aHeight)
{ {
nsIView* view; nsIView* view;
@@ -92,8 +92,8 @@ nsObjectFrame::CreateWidget(nsIPresContext* aPresContext,
// nsWidgetInitData* initData = GetWidgetInitData(*aPresContext); // needs to be deleted // nsWidgetInitData* initData = GetWidgetInitData(*aPresContext); // needs to be deleted
// initialize the view as hidden since we don't know the (x,y) until Paint // initialize the view as hidden since we don't know the (x,y) until Paint
result = view->Init(viewMan, boundBox, parView, &kWidgetCID, nsnull, result = view->Init(viewMan, boundBox, parView, &kWidgetCID, nsnull,
nsnull, 0, nsnull, nsnull, 0, nsnull,
1.0f, nsViewVisibility_kHide); 1.0f, nsViewVisibility_kHide);
// if (nsnull != initData) { // if (nsnull != initData) {
// delete(initData); // delete(initData);
// } // }
@@ -129,8 +129,8 @@ nsObjectFrame::CreateWidget(nsIPresContext* aPresContext,
void void
nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext, nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsReflowState& aReflowState, const nsReflowState& aReflowState,
nsReflowMetrics& aDesiredSize) nsReflowMetrics& aMetrics)
{ {
// Determine our size stylistically // Determine our size stylistically
nsSize styleSize; nsSize styleSize;
@@ -138,45 +138,49 @@ nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext,
PRBool haveWidth = PR_FALSE; PRBool haveWidth = PR_FALSE;
PRBool haveHeight = PR_FALSE; PRBool haveHeight = PR_FALSE;
if (0 != (ss & NS_SIZE_HAS_WIDTH)) { if (0 != (ss & NS_SIZE_HAS_WIDTH)) {
aDesiredSize.width = styleSize.width; aMetrics.width = styleSize.width;
haveWidth = PR_TRUE; haveWidth = PR_TRUE;
} }
if (0 != (ss & NS_SIZE_HAS_HEIGHT)) { if (0 != (ss & NS_SIZE_HAS_HEIGHT)) {
aDesiredSize.height = styleSize.height; aMetrics.height = styleSize.height;
haveHeight = PR_TRUE; haveHeight = PR_TRUE;
} }
// XXX Temporary auto-sizing logic // XXX Temporary auto-sizing logic
if (!haveWidth) { if (!haveWidth) {
if (haveHeight) { if (haveHeight) {
aDesiredSize.width = aDesiredSize.height; aMetrics.width = aMetrics.height;
} }
else { else {
float p2t = aPresContext->GetPixelsToTwips(); float p2t = aPresContext->GetPixelsToTwips();
aDesiredSize.width = nscoord(p2t * EMBED_DEF_DIM); aMetrics.width = nscoord(p2t * EMBED_DEF_DIM);
} }
} }
if (!haveHeight) { if (!haveHeight) {
if (haveWidth) { if (haveWidth) {
aDesiredSize.height = aDesiredSize.width; aMetrics.height = aMetrics.width;
} }
else { else {
float p2t = aPresContext->GetPixelsToTwips(); float p2t = aPresContext->GetPixelsToTwips();
aDesiredSize.height = nscoord(p2t * EMBED_DEF_DIM); aMetrics.height = nscoord(p2t * EMBED_DEF_DIM);
} }
} }
aDesiredSize.ascent = aDesiredSize.height; aMetrics.ascent = aMetrics.height;
aDesiredSize.descent = 0; aMetrics.descent = 0;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsObjectFrame::Reflow(nsIPresContext& aPresContext, nsObjectFrame::Reflow(nsIPresContext& aPresContext,
nsReflowMetrics& aDesiredSize, nsReflowMetrics& aMetrics,
const nsReflowState& aReflowState, const nsReflowState& aReflowState,
nsReflowStatus& aStatus) nsReflowStatus& aStatus)
{ {
// Get our desired size // Get our desired size
GetDesiredSize(&aPresContext, aReflowState, aDesiredSize); GetDesiredSize(&aPresContext, aReflowState, aMetrics);
if (nsnull != aMetrics.maxElementSize) {
aMetrics.maxElementSize->width = aMetrics.width;
aMetrics.maxElementSize->height = aMetrics.height;
}
// XXX deal with border and padding the usual way...wrap it up! // XXX deal with border and padding the usual way...wrap it up!
@@ -184,8 +188,8 @@ nsObjectFrame::Reflow(nsIPresContext& aPresContext,
nsIView* view; nsIView* view;
GetView(view); GetView(view);
if (nsnull == view) { if (nsnull == view) {
nsresult rv = CreateWidget(&aPresContext, aDesiredSize.width, nsresult rv = CreateWidget(&aPresContext, aMetrics.width,
aDesiredSize.height); aMetrics.height);
if (NS_OK != rv) { if (NS_OK != rv) {
return rv; return rv;
} }
@@ -200,7 +204,7 @@ nsObjectFrame::Reflow(nsIPresContext& aPresContext,
NS_IMETHODIMP NS_IMETHODIMP
nsObjectFrame::DidReflow(nsIPresContext& aPresContext, nsObjectFrame::DidReflow(nsIPresContext& aPresContext,
nsDidReflowStatus aStatus) nsDidReflowStatus aStatus)
{ {
nsresult rv = nsObjectFrameSuper::DidReflow(aPresContext, aStatus); nsresult rv = nsObjectFrameSuper::DidReflow(aPresContext, aStatus);
@@ -217,8 +221,9 @@ nsObjectFrame::DidReflow(nsIPresContext& aPresContext,
return rv; return rv;
} }
nsresult NS_NewObjectFrame(nsIFrame*& aFrameResult, nsIContent* aContent, nsresult
nsIFrame* aParentFrame) NS_NewObjectFrame(nsIFrame*& aFrameResult, nsIContent* aContent,
nsIFrame* aParentFrame)
{ {
aFrameResult = new nsObjectFrame(aContent, aParentFrame); aFrameResult = new nsObjectFrame(aContent, aParentFrame);
if (nsnull == aFrameResult) { if (nsnull == aFrameResult) {