Removed nsCSSLayout::GetStyleSize and converted callers to use state in the html reflow state

This commit is contained in:
kipp%netscape.com 1998-10-12 17:00:32 +00:00
Родитель 25b03013ae
Коммит a77548baff
29 изменённых файлов: 348 добавлений и 691 удалений

Просмотреть файл

@ -121,191 +121,3 @@ nsCSSLayout::RelativePositionChildren(nsIPresContext* aCX,
kid->GetNextSibling(kid);
}
}
#if XXX
// XXX if this can handle proportional widths then do so
// XXX check against other possible values and update
static PRBool
GetStyleDimension(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
const nsStylePosition* aStylePos,
const nsStyleCoord& aCoord,
nscoord& aResult)
{
PRBool rv = PR_FALSE;
PRIntn unit = aCoord.GetUnit();
if (eStyleUnit_Coord == unit) {
aResult = aCoord.GetCoordValue();
rv = PR_TRUE;
}
// XXX This isn't correct to use the containg block's width for a percentage
// height. According to the CSS2 spec: "The percentage is calculated with respect
// to the height of the generated box's containing block. If the height of the
// containing block is not specified explicitly (i.e., it depends on content
// height), the value is interpreted like 'auto'".
else if (eStyleUnit_Percent == unit) {
// CSS2 has specified that percentage width/height values are basd
// on the containing block's <B>width</B>.
// XXX need to subtract out padding, also this needs
// to be synced with nsFrame's IsPercentageBase
const nsReflowState* rs = &aReflowState;
while (nsnull != rs) {
nsIFrame* block = nsnull;
rs->frame->QueryInterface(kBlockFrameCID, (void**) &block);
if (nsnull != block) {
if (NS_UNCONSTRAINEDSIZE == rs->maxSize.width) {
// When we find an unconstrained block it means that pass1
// table reflow is occuring. In this case the percentage
// value is unknown so assume it's epsilon for now.
aResult = 1;
}
else {
// We found the nearest containing block which defines what a
// percentage size is relative to. Use the width that it will
// reflow to as the basis for computing our width.
aResult = nscoord(rs->maxSize.width * aCoord.GetPercentValue());
}
rv = PR_TRUE;
break;
}
aResult = 0;
rs = rs->parentReflowState;
}
}
else {
aResult = 0;
}
// Negative width's are ignored
if (aResult <= 0) {
rv = PR_FALSE;
}
return rv;
}
#endif
// XXX if display == row || rowspan ignore width
// XXX if display == col || colspan ignore height
PRIntn
nsCSSLayout::GetStyleSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aStyleSize)
{
PRIntn rv = NS_SIZE_HAS_NONE;
const nsStylePosition* pos;
nsresult result =
aReflowState.frame->GetStyleData(eStyleStruct_Position,
(const nsStyleStruct*&)pos);
if (NS_OK == result) {
nscoord containingBlockWidth, containingBlockHeight;
nscoord width = -1, height = -1;
PRIntn widthUnit = pos->mWidth.GetUnit();
PRIntn heightUnit = pos->mHeight.GetUnit();
// When a percentage is specified we need to find the containing
// block to use as the basis for the percentage computation.
if ((eStyleUnit_Percent == widthUnit) ||
(eStyleUnit_Percent == heightUnit)) {
// Find the containing block for this frame
nsIFrame* containingBlock = nsnull;
// XXX this cast is just plain wrong
const nsHTMLReflowState* rs = (const nsHTMLReflowState*)
aReflowState.parentReflowState;
while (nsnull != rs) {
if (nsnull != rs->frame) {
PRBool isContainingBlock;
if (NS_OK == rs->frame->IsPercentageBase(isContainingBlock)) {
if (isContainingBlock) {
containingBlock = rs->frame;
break;
}
}
}
// XXX this cast is just plain wrong
rs = (const nsHTMLReflowState*) rs->parentReflowState;
}
// If there is no containing block then pretend the width or
// height units are auto.
if (nsnull == containingBlock) {
if (eStyleUnit_Percent == widthUnit) {
widthUnit = eStyleUnit_Auto;
}
if (eStyleUnit_Percent == heightUnit) {
heightUnit = eStyleUnit_Auto;
}
}
else {
if (eStyleUnit_Percent == widthUnit) {
if (eHTMLFrameConstraint_Unconstrained == rs->widthConstraint) {
if (NS_UNCONSTRAINEDSIZE == rs->maxSize.width) {
// When we don't know the width (yet) of the containing
// block we use a dummy value, assuming that the frame
// depending on the percentage value will be reflowed a
// second time.
containingBlockWidth = 1;
}
else {
containingBlockWidth = rs->maxSize.width;
}
}
else {
containingBlockWidth = rs->minWidth;
}
}
if (eStyleUnit_Percent == heightUnit) {
if (eHTMLFrameConstraint_Unconstrained == rs->heightConstraint) {
if (NS_UNCONSTRAINEDSIZE == rs->maxSize.height) {
// CSS2 spec, 10.5: if the height of the containing block
// is not specified explicitly then the value is
// interpreted like auto.
heightUnit = eStyleUnit_Auto;
}
else {
containingBlockHeight = rs->maxSize.height;
}
}
else {
containingBlockHeight = rs->minHeight;
}
}
}
}
switch (widthUnit) {
case eStyleUnit_Coord:
width = pos->mWidth.GetCoordValue();
break;
case eStyleUnit_Percent:
width = nscoord(pos->mWidth.GetPercentValue() * containingBlockWidth);
break;
case eStyleUnit_Auto:
// XXX See section 10.3 of the css2 spec and then write this code!
break;
}
switch (heightUnit) {
case eStyleUnit_Coord:
height = pos->mHeight.GetCoordValue();
break;
case eStyleUnit_Percent:
height = nscoord(pos->mHeight.GetPercentValue() * containingBlockHeight);
break;
case eStyleUnit_Auto:
// XXX See section 10.6 of the css2 spec and then write this code!
break;
}
if (width > 0) {
aStyleSize.width = width;
rv |= NS_SIZE_HAS_WIDTH;
}
if (height > 0) {
aStyleSize.height = height;
rv |= NS_SIZE_HAS_HEIGHT;
}
}
return rv;
}

Просмотреть файл

@ -44,7 +44,6 @@
#include "nsISupports.h"
#include "nsStyleConsts.h"
#include "nsUnitConversion.h"
#include "nsCSSLayout.h"
#include "nsStyleUtil.h"
#include "nsFormFrame.h"
#include "nsIContent.h"
@ -556,15 +555,21 @@ NS_METHOD nsFormControlFrame::HandleEvent(nsIPresContext& aPresContext,
return NS_OK;
}
void nsFormControlFrame::GetStyleSize(nsIPresContext& aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aSize)
void
nsFormControlFrame::GetStyleSize(nsIPresContext& aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aSize)
{
PRIntn ss = nsCSSLayout::GetStyleSize(&aPresContext, aReflowState, aSize);
if (0 == (ss & NS_SIZE_HAS_WIDTH)) {
if (aReflowState.HaveConstrainedWidth()) {
aSize.width = aReflowState.minWidth;
}
else {
aSize.width = CSS_NOTSET;
}
if (0 == (ss & NS_SIZE_HAS_HEIGHT)) {
if (aReflowState.HaveConstrainedHeight()) {
aSize.height = aReflowState.minHeight;
}
else {
aSize.height = CSS_NOTSET;
}
}

Просмотреть файл

@ -20,7 +20,6 @@
#include "nsFrameReflowState.h"
#include "nsLineLayout.h"
#include "nsInlineReflow.h"
#include "nsCSSLayout.h"
#include "nsAbsoluteFrame.h"
#include "nsPlaceholderFrame.h"
#include "nsStyleConsts.h"
@ -3871,45 +3870,55 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
nsBlockReflowState& aState,
nsIFrame* aFloaterFrame)
{
// Prepare the reflow state for the floater frame. Note that initially
// it's maxSize will be 0,0 until we compute it (we need the reflowState
// for nsLayout::GetStyleSize so we have to do this first)
// Prepare the reflow state for the floater frame. Note that
// initially it's maxSize will be 0,0 until we compute it.
nsSize kidAvailSize(0, 0);
nsHTMLReflowState reflowState(aPresContext, aFloaterFrame, aState,
kidAvailSize, eReflowReason_Initial);
// Compute the available space for the floater. Use the default
// 'auto' width and height values
nsSize styleSize;
PRIntn styleSizeFlags =
nsCSSLayout::GetStyleSize(&aPresContext, reflowState, styleSize);
// If either dimension is constrained then get the border and
// padding values in advance.
nsMargin bp(0, 0, 0, 0);
if (reflowState.HaveConstrainedWidth() ||
reflowState.HaveConstrainedHeight()) {
const nsStyleSpacing* spacing;
if (NS_OK == aFloaterFrame->GetStyleData(eStyleStruct_Spacing,
(const nsStyleStruct*&)spacing)) {
spacing->CalcBorderPaddingFor(aFloaterFrame, bp);
}
}
// XXX The width and height are for the content area only. Add in space for
// border and padding
if (styleSizeFlags & NS_SIZE_HAS_WIDTH) {
kidAvailSize.width = styleSize.width;
// Compute the available width for the floater
if (reflowState.HaveConstrainedWidth()) {
// When the floater has a contrained width, give it just enough
// space for its styled width plus its borders and paddings.
kidAvailSize.width = reflowState.minWidth + bp.left + bp.right;
}
else {
// If we are floating something and we don't know the width then
// find a maximum width for it to reflow into.
// XXX if the child is a block (instead of a table, say) then this
// will do the wrong thing. A better choice would be
// NS_UNCONSTRAINEDSIZE, but that has special meaning to tables.
const nsReflowState* rsp = &aState;
// find a maximum width for it to reflow into. Walk upwards until
// we find something with an unconstrained width.
const nsHTMLReflowState* rsp = &aState;
kidAvailSize.width = 0;
while (nsnull != rsp) {
if ((0 != rsp->maxSize.width) &&
(NS_UNCONSTRAINEDSIZE != rsp->maxSize.width)) {
kidAvailSize.width = rsp->maxSize.width;
if (eHTMLFrameConstraint_Unconstrained != rsp->widthConstraint) {
kidAvailSize.width = rsp->minWidth;
break;
}
rsp = rsp->parentReflowState;
else if (NS_UNCONSTRAINEDSIZE != rsp->widthConstraint) {
kidAvailSize.width = rsp->maxSize.width;
if (kidAvailSize.width > 0) {
break;
}
}
// XXX This cast is unfortunate!
rsp = (const nsHTMLReflowState*) rsp->parentReflowState;
}
NS_ASSERTION(0 != kidAvailSize.width, "no width for block found");
}
if (styleSizeFlags & NS_SIZE_HAS_HEIGHT) {
kidAvailSize.height = styleSize.height;
// Compute the available height for the floater
if (reflowState.HaveConstrainedHeight()) {
kidAvailSize.height = reflowState.minHeight + bp.top + bp.bottom;
}
else {
kidAvailSize.height = NS_UNCONSTRAINEDSIZE;
@ -3917,9 +3926,9 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
reflowState.maxSize = kidAvailSize;
// Resize reflow the anchored item into the available space
// XXX Check for complete?
nsIHTMLReflow* floaterReflow;
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID, (void**)&floaterReflow)) {
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID,
(void**)&floaterReflow)) {
nsHTMLReflowMetrics desiredSize(nsnull);
nsReflowStatus status;
floaterReflow->WillReflow(aPresContext);

Просмотреть файл

@ -20,7 +20,6 @@
#include "nsFrameReflowState.h"
#include "nsLineLayout.h"
#include "nsInlineReflow.h"
#include "nsCSSLayout.h"
#include "nsAbsoluteFrame.h"
#include "nsPlaceholderFrame.h"
#include "nsStyleConsts.h"
@ -3871,45 +3870,55 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
nsBlockReflowState& aState,
nsIFrame* aFloaterFrame)
{
// Prepare the reflow state for the floater frame. Note that initially
// it's maxSize will be 0,0 until we compute it (we need the reflowState
// for nsLayout::GetStyleSize so we have to do this first)
// Prepare the reflow state for the floater frame. Note that
// initially it's maxSize will be 0,0 until we compute it.
nsSize kidAvailSize(0, 0);
nsHTMLReflowState reflowState(aPresContext, aFloaterFrame, aState,
kidAvailSize, eReflowReason_Initial);
// Compute the available space for the floater. Use the default
// 'auto' width and height values
nsSize styleSize;
PRIntn styleSizeFlags =
nsCSSLayout::GetStyleSize(&aPresContext, reflowState, styleSize);
// If either dimension is constrained then get the border and
// padding values in advance.
nsMargin bp(0, 0, 0, 0);
if (reflowState.HaveConstrainedWidth() ||
reflowState.HaveConstrainedHeight()) {
const nsStyleSpacing* spacing;
if (NS_OK == aFloaterFrame->GetStyleData(eStyleStruct_Spacing,
(const nsStyleStruct*&)spacing)) {
spacing->CalcBorderPaddingFor(aFloaterFrame, bp);
}
}
// XXX The width and height are for the content area only. Add in space for
// border and padding
if (styleSizeFlags & NS_SIZE_HAS_WIDTH) {
kidAvailSize.width = styleSize.width;
// Compute the available width for the floater
if (reflowState.HaveConstrainedWidth()) {
// When the floater has a contrained width, give it just enough
// space for its styled width plus its borders and paddings.
kidAvailSize.width = reflowState.minWidth + bp.left + bp.right;
}
else {
// If we are floating something and we don't know the width then
// find a maximum width for it to reflow into.
// XXX if the child is a block (instead of a table, say) then this
// will do the wrong thing. A better choice would be
// NS_UNCONSTRAINEDSIZE, but that has special meaning to tables.
const nsReflowState* rsp = &aState;
// find a maximum width for it to reflow into. Walk upwards until
// we find something with an unconstrained width.
const nsHTMLReflowState* rsp = &aState;
kidAvailSize.width = 0;
while (nsnull != rsp) {
if ((0 != rsp->maxSize.width) &&
(NS_UNCONSTRAINEDSIZE != rsp->maxSize.width)) {
kidAvailSize.width = rsp->maxSize.width;
if (eHTMLFrameConstraint_Unconstrained != rsp->widthConstraint) {
kidAvailSize.width = rsp->minWidth;
break;
}
rsp = rsp->parentReflowState;
else if (NS_UNCONSTRAINEDSIZE != rsp->widthConstraint) {
kidAvailSize.width = rsp->maxSize.width;
if (kidAvailSize.width > 0) {
break;
}
}
// XXX This cast is unfortunate!
rsp = (const nsHTMLReflowState*) rsp->parentReflowState;
}
NS_ASSERTION(0 != kidAvailSize.width, "no width for block found");
}
if (styleSizeFlags & NS_SIZE_HAS_HEIGHT) {
kidAvailSize.height = styleSize.height;
// Compute the available height for the floater
if (reflowState.HaveConstrainedHeight()) {
kidAvailSize.height = reflowState.minHeight + bp.top + bp.bottom;
}
else {
kidAvailSize.height = NS_UNCONSTRAINEDSIZE;
@ -3917,9 +3926,9 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
reflowState.maxSize = kidAvailSize;
// Resize reflow the anchored item into the available space
// XXX Check for complete?
nsIHTMLReflow* floaterReflow;
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID, (void**)&floaterReflow)) {
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID,
(void**)&floaterReflow)) {
nsHTMLReflowMetrics desiredSize(nsnull);
nsReflowStatus status;
floaterReflow->WillReflow(aPresContext);

Просмотреть файл

@ -20,7 +20,6 @@
#include "nsFrameReflowState.h"
#include "nsLineLayout.h"
#include "nsInlineReflow.h"
#include "nsCSSLayout.h"
#include "nsAbsoluteFrame.h"
#include "nsPlaceholderFrame.h"
#include "nsStyleConsts.h"
@ -3871,45 +3870,55 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
nsBlockReflowState& aState,
nsIFrame* aFloaterFrame)
{
// Prepare the reflow state for the floater frame. Note that initially
// it's maxSize will be 0,0 until we compute it (we need the reflowState
// for nsLayout::GetStyleSize so we have to do this first)
// Prepare the reflow state for the floater frame. Note that
// initially it's maxSize will be 0,0 until we compute it.
nsSize kidAvailSize(0, 0);
nsHTMLReflowState reflowState(aPresContext, aFloaterFrame, aState,
kidAvailSize, eReflowReason_Initial);
// Compute the available space for the floater. Use the default
// 'auto' width and height values
nsSize styleSize;
PRIntn styleSizeFlags =
nsCSSLayout::GetStyleSize(&aPresContext, reflowState, styleSize);
// If either dimension is constrained then get the border and
// padding values in advance.
nsMargin bp(0, 0, 0, 0);
if (reflowState.HaveConstrainedWidth() ||
reflowState.HaveConstrainedHeight()) {
const nsStyleSpacing* spacing;
if (NS_OK == aFloaterFrame->GetStyleData(eStyleStruct_Spacing,
(const nsStyleStruct*&)spacing)) {
spacing->CalcBorderPaddingFor(aFloaterFrame, bp);
}
}
// XXX The width and height are for the content area only. Add in space for
// border and padding
if (styleSizeFlags & NS_SIZE_HAS_WIDTH) {
kidAvailSize.width = styleSize.width;
// Compute the available width for the floater
if (reflowState.HaveConstrainedWidth()) {
// When the floater has a contrained width, give it just enough
// space for its styled width plus its borders and paddings.
kidAvailSize.width = reflowState.minWidth + bp.left + bp.right;
}
else {
// If we are floating something and we don't know the width then
// find a maximum width for it to reflow into.
// XXX if the child is a block (instead of a table, say) then this
// will do the wrong thing. A better choice would be
// NS_UNCONSTRAINEDSIZE, but that has special meaning to tables.
const nsReflowState* rsp = &aState;
// find a maximum width for it to reflow into. Walk upwards until
// we find something with an unconstrained width.
const nsHTMLReflowState* rsp = &aState;
kidAvailSize.width = 0;
while (nsnull != rsp) {
if ((0 != rsp->maxSize.width) &&
(NS_UNCONSTRAINEDSIZE != rsp->maxSize.width)) {
kidAvailSize.width = rsp->maxSize.width;
if (eHTMLFrameConstraint_Unconstrained != rsp->widthConstraint) {
kidAvailSize.width = rsp->minWidth;
break;
}
rsp = rsp->parentReflowState;
else if (NS_UNCONSTRAINEDSIZE != rsp->widthConstraint) {
kidAvailSize.width = rsp->maxSize.width;
if (kidAvailSize.width > 0) {
break;
}
}
// XXX This cast is unfortunate!
rsp = (const nsHTMLReflowState*) rsp->parentReflowState;
}
NS_ASSERTION(0 != kidAvailSize.width, "no width for block found");
}
if (styleSizeFlags & NS_SIZE_HAS_HEIGHT) {
kidAvailSize.height = styleSize.height;
// Compute the available height for the floater
if (reflowState.HaveConstrainedHeight()) {
kidAvailSize.height = reflowState.minHeight + bp.top + bp.bottom;
}
else {
kidAvailSize.height = NS_UNCONSTRAINEDSIZE;
@ -3917,9 +3926,9 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
reflowState.maxSize = kidAvailSize;
// Resize reflow the anchored item into the available space
// XXX Check for complete?
nsIHTMLReflow* floaterReflow;
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID, (void**)&floaterReflow)) {
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID,
(void**)&floaterReflow)) {
nsHTMLReflowMetrics desiredSize(nsnull);
nsReflowStatus status;
floaterReflow->WillReflow(aPresContext);

Просмотреть файл

@ -35,7 +35,6 @@
#include "nsStyleCoord.h"
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsCSSLayout.h"
#include "nsIDocumentLoader.h"
#include "nsIPref.h"
#include "nsFrameSetFrame.h"
@ -236,19 +235,19 @@ nsHTMLFrameOuterFrame::GetDesiredSize(nsIPresContext* aPresContext,
// <frame> processing does not use this routine, only <iframe>
float p2t = aPresContext->GetPixelsToTwips();
nsSize size;
PRIntn ss = nsCSSLayout::GetStyleSize(aPresContext, aReflowState, size);
// XXX this needs to be changed from (200,200) to a better default for inline frames
if (0 == (ss & NS_SIZE_HAS_WIDTH)) {
size.width = NSIntPixelsToTwips(200, p2t);
if (aReflowState.HaveConstrainedWidth()) {
aDesiredSize.width = aReflowState.minWidth;
}
if (0 == (ss & NS_SIZE_HAS_HEIGHT)) {
size.height = NSIntPixelsToTwips(200, p2t);
else {
aDesiredSize.width = NSIntPixelsToTwips(200, p2t);
}
if (aReflowState.HaveConstrainedHeight()) {
aDesiredSize.height = aReflowState.minHeight;
}
else {
aDesiredSize.height = NSIntPixelsToTwips(200, p2t);
}
aDesiredSize.width = size.width;
aDesiredSize.height = size.height;
aDesiredSize.ascent = aDesiredSize.height;
aDesiredSize.descent = 0;
}

Просмотреть файл

@ -37,7 +37,6 @@
#include "nsIURL.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsCSSLayout.h"
#include "nsHTMLContainerFrame.h"
#include "prprf.h"
#include "nsISizeOfHandler.h"
@ -271,20 +270,23 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
nsFrameImageLoaderCB aCallBack,
nsHTMLReflowMetrics& aDesiredSize)
{
nsSize styleSize;
PRIntn ss = nsCSSLayout::GetStyleSize(aPresContext, aReflowState, styleSize);
// Start the image loading
PRIntn loadStatus;
if (0 != ss) {
if (NS_SIZE_HAS_BOTH == ss) {
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
PR_FALSE, loadStatus);
aDesiredSize.width = styleSize.width;
aDesiredSize.height = styleSize.height;
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
!aReflowState.HaveConstrainedWidthAndHeight(),
loadStatus);
// Choose reflow size
if (aReflowState.HaveConstrainedWidth() ||
aReflowState.HaveConstrainedHeight()) {
if (aReflowState.HaveConstrainedWidthAndHeight()) {
// The image is fully constrained. Use the constraints directly.
aDesiredSize.width = aReflowState.minWidth;
aDesiredSize.height = aReflowState.minHeight;
}
else {
// Preserve aspect ratio of image with unbound dimension.
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
PR_TRUE, loadStatus);
// The image is partially constrained. Preserve aspect ratio of
// image with unbound dimension.
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
(nsnull == mImageLoader)) {
// Provide a dummy size for now; later on when the image size
@ -299,19 +301,19 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
float imageWidth = imageSize.width * p2t;
float imageHeight = imageSize.height * p2t;
if (0.0f != imageHeight) {
if (0 != (ss & NS_SIZE_HAS_WIDTH)) {
if (aReflowState.HaveConstrainedWidth()) {
// We have a width, and an auto height. Compute height
// from width.
aDesiredSize.width = styleSize.width;
aDesiredSize.height =
(nscoord)NSToIntRound(styleSize.width * imageHeight / imageWidth);
aDesiredSize.width = aReflowState.minWidth;
aDesiredSize.height = (nscoord)
NSToIntRound(aReflowState.minWidth * imageHeight / imageWidth);
}
else {
// We have a height and an auto width. Compute width from
// height.
aDesiredSize.height = styleSize.height;
aDesiredSize.width =
(nscoord)NSToIntRound(styleSize.height * imageWidth / imageHeight);
aDesiredSize.height = aReflowState.minHeight;
aDesiredSize.width = (nscoord)
NSToIntRound(aReflowState.minHeight * imageWidth / imageHeight);
}
}
else {
@ -323,21 +325,19 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
}
}
else {
StartLoadImage(aPresContext, aTargetFrame, aCallBack, PR_TRUE, loadStatus);
// The image is unconstrained
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
(nsnull == mImageLoader)) {
// Provide a dummy size for now; later on when the image size
// shows up we will reflow to the new size.
aDesiredSize.width = 1;
aDesiredSize.height = 1;
// printf ("in image loader, dummy size of 1 returned\n");
} else {
float p2t = aPresContext->GetPixelsToTwips();
nsSize imageSize;
mImageLoader->GetSize(imageSize);
aDesiredSize.width = NSIntPixelsToTwips(imageSize.width, p2t);
aDesiredSize.height = NSIntPixelsToTwips(imageSize.height, p2t);
// printf ("in image loader, real size of %d returned\n", aDesiredSize.width);
}
}
}

Просмотреть файл

@ -18,7 +18,6 @@
*/
#include "nsLineLayout.h"
#include "nsInlineReflow.h"
#include "nsCSSLayout.h"
#include "nsStyleConsts.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"

Просмотреть файл

@ -18,7 +18,6 @@
*/
#include "nsHTMLParts.h"
#include "nsLeafFrame.h"
#include "nsCSSLayout.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsWidgetsCID.h"
@ -301,16 +300,14 @@ nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext,
nsHTMLReflowMetrics& aMetrics)
{
// Determine our size stylistically
nsSize styleSize;
PRIntn ss = nsCSSLayout::GetStyleSize(aPresContext, aReflowState, styleSize);
PRBool haveWidth = PR_FALSE;
PRBool haveHeight = PR_FALSE;
if (0 != (ss & NS_SIZE_HAS_WIDTH)) {
aMetrics.width = styleSize.width;
if (aReflowState.HaveConstrainedWidth()) {
aMetrics.width = aReflowState.minWidth;
haveWidth = PR_TRUE;
}
if (0 != (ss & NS_SIZE_HAS_HEIGHT)) {
aMetrics.height = styleSize.height;
if (aReflowState.HaveConstrainedHeight()) {
aMetrics.height = aReflowState.minHeight;
haveHeight = PR_TRUE;
}

Просмотреть файл

@ -16,7 +16,6 @@
* Reserved.
*/
#include "nsPlaceholderFrame.h"
#include "nsCSSLayout.h"
#include "nsLineLayout.h"
#include "nsHTMLIIDs.h"

Просмотреть файл

@ -20,7 +20,6 @@
#include "nsFrameReflowState.h"
#include "nsLineLayout.h"
#include "nsInlineReflow.h"
#include "nsCSSLayout.h"
#include "nsAbsoluteFrame.h"
#include "nsPlaceholderFrame.h"
#include "nsStyleConsts.h"
@ -3871,45 +3870,55 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
nsBlockReflowState& aState,
nsIFrame* aFloaterFrame)
{
// Prepare the reflow state for the floater frame. Note that initially
// it's maxSize will be 0,0 until we compute it (we need the reflowState
// for nsLayout::GetStyleSize so we have to do this first)
// Prepare the reflow state for the floater frame. Note that
// initially it's maxSize will be 0,0 until we compute it.
nsSize kidAvailSize(0, 0);
nsHTMLReflowState reflowState(aPresContext, aFloaterFrame, aState,
kidAvailSize, eReflowReason_Initial);
// Compute the available space for the floater. Use the default
// 'auto' width and height values
nsSize styleSize;
PRIntn styleSizeFlags =
nsCSSLayout::GetStyleSize(&aPresContext, reflowState, styleSize);
// If either dimension is constrained then get the border and
// padding values in advance.
nsMargin bp(0, 0, 0, 0);
if (reflowState.HaveConstrainedWidth() ||
reflowState.HaveConstrainedHeight()) {
const nsStyleSpacing* spacing;
if (NS_OK == aFloaterFrame->GetStyleData(eStyleStruct_Spacing,
(const nsStyleStruct*&)spacing)) {
spacing->CalcBorderPaddingFor(aFloaterFrame, bp);
}
}
// XXX The width and height are for the content area only. Add in space for
// border and padding
if (styleSizeFlags & NS_SIZE_HAS_WIDTH) {
kidAvailSize.width = styleSize.width;
// Compute the available width for the floater
if (reflowState.HaveConstrainedWidth()) {
// When the floater has a contrained width, give it just enough
// space for its styled width plus its borders and paddings.
kidAvailSize.width = reflowState.minWidth + bp.left + bp.right;
}
else {
// If we are floating something and we don't know the width then
// find a maximum width for it to reflow into.
// XXX if the child is a block (instead of a table, say) then this
// will do the wrong thing. A better choice would be
// NS_UNCONSTRAINEDSIZE, but that has special meaning to tables.
const nsReflowState* rsp = &aState;
// find a maximum width for it to reflow into. Walk upwards until
// we find something with an unconstrained width.
const nsHTMLReflowState* rsp = &aState;
kidAvailSize.width = 0;
while (nsnull != rsp) {
if ((0 != rsp->maxSize.width) &&
(NS_UNCONSTRAINEDSIZE != rsp->maxSize.width)) {
kidAvailSize.width = rsp->maxSize.width;
if (eHTMLFrameConstraint_Unconstrained != rsp->widthConstraint) {
kidAvailSize.width = rsp->minWidth;
break;
}
rsp = rsp->parentReflowState;
else if (NS_UNCONSTRAINEDSIZE != rsp->widthConstraint) {
kidAvailSize.width = rsp->maxSize.width;
if (kidAvailSize.width > 0) {
break;
}
}
// XXX This cast is unfortunate!
rsp = (const nsHTMLReflowState*) rsp->parentReflowState;
}
NS_ASSERTION(0 != kidAvailSize.width, "no width for block found");
}
if (styleSizeFlags & NS_SIZE_HAS_HEIGHT) {
kidAvailSize.height = styleSize.height;
// Compute the available height for the floater
if (reflowState.HaveConstrainedHeight()) {
kidAvailSize.height = reflowState.minHeight + bp.top + bp.bottom;
}
else {
kidAvailSize.height = NS_UNCONSTRAINEDSIZE;
@ -3917,9 +3926,9 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
reflowState.maxSize = kidAvailSize;
// Resize reflow the anchored item into the available space
// XXX Check for complete?
nsIHTMLReflow* floaterReflow;
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID, (void**)&floaterReflow)) {
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID,
(void**)&floaterReflow)) {
nsHTMLReflowMetrics desiredSize(nsnull);
nsReflowStatus status;
floaterReflow->WillReflow(aPresContext);

Просмотреть файл

@ -20,7 +20,6 @@
#include "nsFrameReflowState.h"
#include "nsLineLayout.h"
#include "nsInlineReflow.h"
#include "nsCSSLayout.h"
#include "nsAbsoluteFrame.h"
#include "nsPlaceholderFrame.h"
#include "nsStyleConsts.h"
@ -3871,45 +3870,55 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
nsBlockReflowState& aState,
nsIFrame* aFloaterFrame)
{
// Prepare the reflow state for the floater frame. Note that initially
// it's maxSize will be 0,0 until we compute it (we need the reflowState
// for nsLayout::GetStyleSize so we have to do this first)
// Prepare the reflow state for the floater frame. Note that
// initially it's maxSize will be 0,0 until we compute it.
nsSize kidAvailSize(0, 0);
nsHTMLReflowState reflowState(aPresContext, aFloaterFrame, aState,
kidAvailSize, eReflowReason_Initial);
// Compute the available space for the floater. Use the default
// 'auto' width and height values
nsSize styleSize;
PRIntn styleSizeFlags =
nsCSSLayout::GetStyleSize(&aPresContext, reflowState, styleSize);
// If either dimension is constrained then get the border and
// padding values in advance.
nsMargin bp(0, 0, 0, 0);
if (reflowState.HaveConstrainedWidth() ||
reflowState.HaveConstrainedHeight()) {
const nsStyleSpacing* spacing;
if (NS_OK == aFloaterFrame->GetStyleData(eStyleStruct_Spacing,
(const nsStyleStruct*&)spacing)) {
spacing->CalcBorderPaddingFor(aFloaterFrame, bp);
}
}
// XXX The width and height are for the content area only. Add in space for
// border and padding
if (styleSizeFlags & NS_SIZE_HAS_WIDTH) {
kidAvailSize.width = styleSize.width;
// Compute the available width for the floater
if (reflowState.HaveConstrainedWidth()) {
// When the floater has a contrained width, give it just enough
// space for its styled width plus its borders and paddings.
kidAvailSize.width = reflowState.minWidth + bp.left + bp.right;
}
else {
// If we are floating something and we don't know the width then
// find a maximum width for it to reflow into.
// XXX if the child is a block (instead of a table, say) then this
// will do the wrong thing. A better choice would be
// NS_UNCONSTRAINEDSIZE, but that has special meaning to tables.
const nsReflowState* rsp = &aState;
// find a maximum width for it to reflow into. Walk upwards until
// we find something with an unconstrained width.
const nsHTMLReflowState* rsp = &aState;
kidAvailSize.width = 0;
while (nsnull != rsp) {
if ((0 != rsp->maxSize.width) &&
(NS_UNCONSTRAINEDSIZE != rsp->maxSize.width)) {
kidAvailSize.width = rsp->maxSize.width;
if (eHTMLFrameConstraint_Unconstrained != rsp->widthConstraint) {
kidAvailSize.width = rsp->minWidth;
break;
}
rsp = rsp->parentReflowState;
else if (NS_UNCONSTRAINEDSIZE != rsp->widthConstraint) {
kidAvailSize.width = rsp->maxSize.width;
if (kidAvailSize.width > 0) {
break;
}
}
// XXX This cast is unfortunate!
rsp = (const nsHTMLReflowState*) rsp->parentReflowState;
}
NS_ASSERTION(0 != kidAvailSize.width, "no width for block found");
}
if (styleSizeFlags & NS_SIZE_HAS_HEIGHT) {
kidAvailSize.height = styleSize.height;
// Compute the available height for the floater
if (reflowState.HaveConstrainedHeight()) {
kidAvailSize.height = reflowState.minHeight + bp.top + bp.bottom;
}
else {
kidAvailSize.height = NS_UNCONSTRAINEDSIZE;
@ -3917,9 +3926,9 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
reflowState.maxSize = kidAvailSize;
// Resize reflow the anchored item into the available space
// XXX Check for complete?
nsIHTMLReflow* floaterReflow;
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID, (void**)&floaterReflow)) {
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID,
(void**)&floaterReflow)) {
nsHTMLReflowMetrics desiredSize(nsnull);
nsReflowStatus status;
floaterReflow->WillReflow(aPresContext);

Просмотреть файл

@ -20,7 +20,6 @@
#include "nsFrameReflowState.h"
#include "nsLineLayout.h"
#include "nsInlineReflow.h"
#include "nsCSSLayout.h"
#include "nsAbsoluteFrame.h"
#include "nsPlaceholderFrame.h"
#include "nsStyleConsts.h"
@ -3871,45 +3870,55 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
nsBlockReflowState& aState,
nsIFrame* aFloaterFrame)
{
// Prepare the reflow state for the floater frame. Note that initially
// it's maxSize will be 0,0 until we compute it (we need the reflowState
// for nsLayout::GetStyleSize so we have to do this first)
// Prepare the reflow state for the floater frame. Note that
// initially it's maxSize will be 0,0 until we compute it.
nsSize kidAvailSize(0, 0);
nsHTMLReflowState reflowState(aPresContext, aFloaterFrame, aState,
kidAvailSize, eReflowReason_Initial);
// Compute the available space for the floater. Use the default
// 'auto' width and height values
nsSize styleSize;
PRIntn styleSizeFlags =
nsCSSLayout::GetStyleSize(&aPresContext, reflowState, styleSize);
// If either dimension is constrained then get the border and
// padding values in advance.
nsMargin bp(0, 0, 0, 0);
if (reflowState.HaveConstrainedWidth() ||
reflowState.HaveConstrainedHeight()) {
const nsStyleSpacing* spacing;
if (NS_OK == aFloaterFrame->GetStyleData(eStyleStruct_Spacing,
(const nsStyleStruct*&)spacing)) {
spacing->CalcBorderPaddingFor(aFloaterFrame, bp);
}
}
// XXX The width and height are for the content area only. Add in space for
// border and padding
if (styleSizeFlags & NS_SIZE_HAS_WIDTH) {
kidAvailSize.width = styleSize.width;
// Compute the available width for the floater
if (reflowState.HaveConstrainedWidth()) {
// When the floater has a contrained width, give it just enough
// space for its styled width plus its borders and paddings.
kidAvailSize.width = reflowState.minWidth + bp.left + bp.right;
}
else {
// If we are floating something and we don't know the width then
// find a maximum width for it to reflow into.
// XXX if the child is a block (instead of a table, say) then this
// will do the wrong thing. A better choice would be
// NS_UNCONSTRAINEDSIZE, but that has special meaning to tables.
const nsReflowState* rsp = &aState;
// find a maximum width for it to reflow into. Walk upwards until
// we find something with an unconstrained width.
const nsHTMLReflowState* rsp = &aState;
kidAvailSize.width = 0;
while (nsnull != rsp) {
if ((0 != rsp->maxSize.width) &&
(NS_UNCONSTRAINEDSIZE != rsp->maxSize.width)) {
kidAvailSize.width = rsp->maxSize.width;
if (eHTMLFrameConstraint_Unconstrained != rsp->widthConstraint) {
kidAvailSize.width = rsp->minWidth;
break;
}
rsp = rsp->parentReflowState;
else if (NS_UNCONSTRAINEDSIZE != rsp->widthConstraint) {
kidAvailSize.width = rsp->maxSize.width;
if (kidAvailSize.width > 0) {
break;
}
}
// XXX This cast is unfortunate!
rsp = (const nsHTMLReflowState*) rsp->parentReflowState;
}
NS_ASSERTION(0 != kidAvailSize.width, "no width for block found");
}
if (styleSizeFlags & NS_SIZE_HAS_HEIGHT) {
kidAvailSize.height = styleSize.height;
// Compute the available height for the floater
if (reflowState.HaveConstrainedHeight()) {
kidAvailSize.height = reflowState.minHeight + bp.top + bp.bottom;
}
else {
kidAvailSize.height = NS_UNCONSTRAINEDSIZE;
@ -3917,9 +3926,9 @@ nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
reflowState.maxSize = kidAvailSize;
// Resize reflow the anchored item into the available space
// XXX Check for complete?
nsIHTMLReflow* floaterReflow;
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID, (void**)&floaterReflow)) {
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID,
(void**)&floaterReflow)) {
nsHTMLReflowMetrics desiredSize(nsnull);
nsReflowStatus status;
floaterReflow->WillReflow(aPresContext);

Просмотреть файл

@ -34,7 +34,6 @@
#include "nsIWebShell.h"
#include "nsHTMLValue.h"
#include "nsHTMLParts.h"
#include "nsCSSLayout.h"
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
@ -530,11 +529,8 @@ nsBodyFrame::ComputeDesiredSize(nsIPresContext& aPresContext,
// Apply style size if present; XXX note the inner value (style-size -
// border+padding) should be given to the child as a max-size
nsSize styleSize;
PRIntn ss =
nsCSSLayout::GetStyleSize(&aPresContext, aReflowState, styleSize);
if (NS_SIZE_HAS_WIDTH & ss) {
width = styleSize.width + aBorderPadding.left + aBorderPadding.right;
if (aReflowState.HaveConstrainedWidth()) {
width = aReflowState.minWidth + aBorderPadding.left + aBorderPadding.right;
}
else {
if ((0 == (NS_BODY_SHRINK_WRAP & mFlags)) &&
@ -543,8 +539,9 @@ nsBodyFrame::ComputeDesiredSize(nsIPresContext& aPresContext,
width = PR_MAX(aMetrics.width, aMaxSize.width);
}
}
if (NS_SIZE_HAS_HEIGHT & ss) {
height = styleSize.height + aBorderPadding.top + aBorderPadding.bottom;
if (aReflowState.HaveConstrainedHeight()) {
height = aReflowState.minHeight +
aBorderPadding.top + aBorderPadding.bottom;
}
else {
// aBorderPadding.top is already reflected in the

Просмотреть файл

@ -30,7 +30,6 @@
#include "nsIHTMLAttributes.h"
#include "nsStyleConsts.h"
#include "nsCSSRendering.h"
#include "nsCSSLayout.h"
#include "nsIDOMHTMLHRElement.h"
static NS_DEFINE_IID(kIDOMHTMLHRElementIID, NS_IDOMHTMLHRELEMENT_IID);
@ -224,10 +223,8 @@ HRuleFrame::Reflow(nsIPresContext& aPresContext,
// otherwise tables behave badly. This makes sense they are springy.
if (nsnull != aDesiredSize.maxElementSize) {
nscoord onePixel = NSIntPixelsToTwips(1, aPresContext.GetPixelsToTwips());
nsSize size;
PRIntn ss = nsCSSLayout::GetStyleSize(&aPresContext, aReflowState, size);
if (NS_SIZE_HAS_WIDTH & ss) {
aDesiredSize.maxElementSize->width = size.width;
if (aReflowState.HaveConstrainedWidth()) {
aDesiredSize.maxElementSize->width = aReflowState.minWidth;
aDesiredSize.maxElementSize->height = onePixel;
}
else {
@ -245,10 +242,8 @@ HRuleFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize)
{
nsSize size;
PRIntn ss = nsCSSLayout::GetStyleSize(aPresContext, aReflowState, size);
if (NS_SIZE_HAS_WIDTH & ss) {
aDesiredSize.width = size.width;
if (aReflowState.HaveConstrainedWidth()) {
aDesiredSize.width = aReflowState.minWidth;
}
else {
if (NS_UNCONSTRAINEDSIZE == aReflowState.maxSize.width) {

Просмотреть файл

@ -196,6 +196,18 @@ struct nsHTMLReflowState : nsReflowState {
const nsSize& aMaxSize,
nsReflowReason aReflowReason);
PRBool HaveConstrainedWidth() const {
return eHTMLFrameConstraint_Unconstrained != widthConstraint;
}
PRBool HaveConstrainedHeight() const {
return eHTMLFrameConstraint_Unconstrained != heightConstraint;
}
PRBool HaveConstrainedWidthAndHeight() const {
return HaveConstrainedWidth() && HaveConstrainedHeight();
}
protected:
// This method initializes the widthConstraint, heightConstraint and
// minSize values appropriately. It also initializes the frameType

Просмотреть файл

@ -37,7 +37,6 @@
#include "nsIURL.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsCSSLayout.h"
#include "nsHTMLContainerFrame.h"
#include "prprf.h"
#include "nsISizeOfHandler.h"
@ -271,20 +270,23 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
nsFrameImageLoaderCB aCallBack,
nsHTMLReflowMetrics& aDesiredSize)
{
nsSize styleSize;
PRIntn ss = nsCSSLayout::GetStyleSize(aPresContext, aReflowState, styleSize);
// Start the image loading
PRIntn loadStatus;
if (0 != ss) {
if (NS_SIZE_HAS_BOTH == ss) {
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
PR_FALSE, loadStatus);
aDesiredSize.width = styleSize.width;
aDesiredSize.height = styleSize.height;
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
!aReflowState.HaveConstrainedWidthAndHeight(),
loadStatus);
// Choose reflow size
if (aReflowState.HaveConstrainedWidth() ||
aReflowState.HaveConstrainedHeight()) {
if (aReflowState.HaveConstrainedWidthAndHeight()) {
// The image is fully constrained. Use the constraints directly.
aDesiredSize.width = aReflowState.minWidth;
aDesiredSize.height = aReflowState.minHeight;
}
else {
// Preserve aspect ratio of image with unbound dimension.
StartLoadImage(aPresContext, aTargetFrame, aCallBack,
PR_TRUE, loadStatus);
// The image is partially constrained. Preserve aspect ratio of
// image with unbound dimension.
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
(nsnull == mImageLoader)) {
// Provide a dummy size for now; later on when the image size
@ -299,19 +301,19 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
float imageWidth = imageSize.width * p2t;
float imageHeight = imageSize.height * p2t;
if (0.0f != imageHeight) {
if (0 != (ss & NS_SIZE_HAS_WIDTH)) {
if (aReflowState.HaveConstrainedWidth()) {
// We have a width, and an auto height. Compute height
// from width.
aDesiredSize.width = styleSize.width;
aDesiredSize.height =
(nscoord)NSToIntRound(styleSize.width * imageHeight / imageWidth);
aDesiredSize.width = aReflowState.minWidth;
aDesiredSize.height = (nscoord)
NSToIntRound(aReflowState.minWidth * imageHeight / imageWidth);
}
else {
// We have a height and an auto width. Compute width from
// height.
aDesiredSize.height = styleSize.height;
aDesiredSize.width =
(nscoord)NSToIntRound(styleSize.height * imageWidth / imageHeight);
aDesiredSize.height = aReflowState.minHeight;
aDesiredSize.width = (nscoord)
NSToIntRound(aReflowState.minHeight * imageWidth / imageHeight);
}
}
else {
@ -323,21 +325,19 @@ nsHTMLImageLoader::GetDesiredSize(nsIPresContext* aPresContext,
}
}
else {
StartLoadImage(aPresContext, aTargetFrame, aCallBack, PR_TRUE, loadStatus);
// The image is unconstrained
if ((0 == (loadStatus & NS_IMAGE_LOAD_STATUS_SIZE_AVAILABLE)) ||
(nsnull == mImageLoader)) {
// Provide a dummy size for now; later on when the image size
// shows up we will reflow to the new size.
aDesiredSize.width = 1;
aDesiredSize.height = 1;
// printf ("in image loader, dummy size of 1 returned\n");
} else {
float p2t = aPresContext->GetPixelsToTwips();
nsSize imageSize;
mImageLoader->GetSize(imageSize);
aDesiredSize.width = NSIntPixelsToTwips(imageSize.width, p2t);
aDesiredSize.height = NSIntPixelsToTwips(imageSize.height, p2t);
// printf ("in image loader, real size of %d returned\n", aDesiredSize.width);
}
}
}

Просмотреть файл

@ -18,7 +18,6 @@
*/
#include "nsLineLayout.h"
#include "nsInlineReflow.h"
#include "nsCSSLayout.h"
#include "nsStyleConsts.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"

Просмотреть файл

@ -18,7 +18,6 @@
*/
#include "nsHTMLParts.h"
#include "nsLeafFrame.h"
#include "nsCSSLayout.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsWidgetsCID.h"
@ -301,16 +300,14 @@ nsObjectFrame::GetDesiredSize(nsIPresContext* aPresContext,
nsHTMLReflowMetrics& aMetrics)
{
// Determine our size stylistically
nsSize styleSize;
PRIntn ss = nsCSSLayout::GetStyleSize(aPresContext, aReflowState, styleSize);
PRBool haveWidth = PR_FALSE;
PRBool haveHeight = PR_FALSE;
if (0 != (ss & NS_SIZE_HAS_WIDTH)) {
aMetrics.width = styleSize.width;
if (aReflowState.HaveConstrainedWidth()) {
aMetrics.width = aReflowState.minWidth;
haveWidth = PR_TRUE;
}
if (0 != (ss & NS_SIZE_HAS_HEIGHT)) {
aMetrics.height = styleSize.height;
if (aReflowState.HaveConstrainedHeight()) {
aMetrics.height = aReflowState.minHeight;
haveHeight = PR_TRUE;
}

Просмотреть файл

@ -16,7 +16,6 @@
* Reserved.
*/
#include "nsPlaceholderFrame.h"
#include "nsCSSLayout.h"
#include "nsLineLayout.h"
#include "nsHTMLIIDs.h"

Просмотреть файл

@ -26,7 +26,6 @@
#include "nsIViewManager.h"
#include "nsBodyFrame.h"
#include "nsHTMLContainerFrame.h"
#include "nsCSSLayout.h"
#include "nsHTMLIIDs.h"
#include "nsBodyFrame.h"
@ -481,17 +480,15 @@ nsScrollOuterFrame::Reflow(nsIPresContext& aPresContext,
// Get style size and determine how much area is available for the
// child (the scroll inner frame) to layout into.
nsSize maxSize, styleSize;
PRIntn sf = nsCSSLayout::GetStyleSize(&aPresContext, aReflowState,
styleSize);
if (NS_SIZE_HAS_WIDTH & sf) {
maxSize.width = styleSize.width - lr;
nsSize maxSize;
if (aReflowState.HaveConstrainedWidth()) {
maxSize.width = aReflowState.minWidth - lr;
}
else {
maxSize.width = aReflowState.maxSize.width;
}
if (NS_SIZE_HAS_HEIGHT & sf) {
maxSize.height = styleSize.height - tb;
if (aReflowState.HaveConstrainedHeight()) {
maxSize.height = aReflowState.minHeight - tb;
}
else {
maxSize.height = NS_UNCONSTRAINEDSIZE;
@ -515,14 +512,14 @@ nsScrollOuterFrame::Reflow(nsIPresContext& aPresContext,
// The scroll outer frame either shrink wraps around it's single
// child OR uses the style width/height.
if (NS_SIZE_HAS_WIDTH & sf) {
aDesiredSize.width = styleSize.width;
if (aReflowState.HaveConstrainedWidth()) {
aDesiredSize.width = aReflowState.minWidth;
}
else {
aDesiredSize.width += lr;
}
if (NS_SIZE_HAS_HEIGHT & sf) {
aDesiredSize.height = styleSize.height;
if (aReflowState.HaveConstrainedHeight()) {
aDesiredSize.height = aReflowState.minHeight;
}
else {
aDesiredSize.height += tb;

Просмотреть файл

@ -35,7 +35,6 @@
#include "nsStyleCoord.h"
#include "nsIStyleContext.h"
#include "nsStyleConsts.h"
#include "nsCSSLayout.h"
#include "nsIDocumentLoader.h"
#include "nsIPref.h"
#include "nsFrameSetFrame.h"
@ -236,19 +235,19 @@ nsHTMLFrameOuterFrame::GetDesiredSize(nsIPresContext* aPresContext,
// <frame> processing does not use this routine, only <iframe>
float p2t = aPresContext->GetPixelsToTwips();
nsSize size;
PRIntn ss = nsCSSLayout::GetStyleSize(aPresContext, aReflowState, size);
// XXX this needs to be changed from (200,200) to a better default for inline frames
if (0 == (ss & NS_SIZE_HAS_WIDTH)) {
size.width = NSIntPixelsToTwips(200, p2t);
if (aReflowState.HaveConstrainedWidth()) {
aDesiredSize.width = aReflowState.minWidth;
}
if (0 == (ss & NS_SIZE_HAS_HEIGHT)) {
size.height = NSIntPixelsToTwips(200, p2t);
else {
aDesiredSize.width = NSIntPixelsToTwips(200, p2t);
}
if (aReflowState.HaveConstrainedHeight()) {
aDesiredSize.height = aReflowState.minHeight;
}
else {
aDesiredSize.height = NSIntPixelsToTwips(200, p2t);
}
aDesiredSize.width = size.width;
aDesiredSize.height = size.height;
aDesiredSize.ascent = aDesiredSize.height;
aDesiredSize.descent = 0;
}

Просмотреть файл

@ -44,7 +44,6 @@
#include "nsISupports.h"
#include "nsStyleConsts.h"
#include "nsUnitConversion.h"
#include "nsCSSLayout.h"
#include "nsStyleUtil.h"
#include "nsFormFrame.h"
#include "nsIContent.h"
@ -556,15 +555,21 @@ NS_METHOD nsFormControlFrame::HandleEvent(nsIPresContext& aPresContext,
return NS_OK;
}
void nsFormControlFrame::GetStyleSize(nsIPresContext& aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aSize)
void
nsFormControlFrame::GetStyleSize(nsIPresContext& aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aSize)
{
PRIntn ss = nsCSSLayout::GetStyleSize(&aPresContext, aReflowState, aSize);
if (0 == (ss & NS_SIZE_HAS_WIDTH)) {
if (aReflowState.HaveConstrainedWidth()) {
aSize.width = aReflowState.minWidth;
}
else {
aSize.width = CSS_NOTSET;
}
if (0 == (ss & NS_SIZE_HAS_HEIGHT)) {
if (aReflowState.HaveConstrainedHeight()) {
aSize.height = aReflowState.minHeight;
}
else {
aSize.height = CSS_NOTSET;
}
}

Просмотреть файл

@ -121,191 +121,3 @@ nsCSSLayout::RelativePositionChildren(nsIPresContext* aCX,
kid->GetNextSibling(kid);
}
}
#if XXX
// XXX if this can handle proportional widths then do so
// XXX check against other possible values and update
static PRBool
GetStyleDimension(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
const nsStylePosition* aStylePos,
const nsStyleCoord& aCoord,
nscoord& aResult)
{
PRBool rv = PR_FALSE;
PRIntn unit = aCoord.GetUnit();
if (eStyleUnit_Coord == unit) {
aResult = aCoord.GetCoordValue();
rv = PR_TRUE;
}
// XXX This isn't correct to use the containg block's width for a percentage
// height. According to the CSS2 spec: "The percentage is calculated with respect
// to the height of the generated box's containing block. If the height of the
// containing block is not specified explicitly (i.e., it depends on content
// height), the value is interpreted like 'auto'".
else if (eStyleUnit_Percent == unit) {
// CSS2 has specified that percentage width/height values are basd
// on the containing block's <B>width</B>.
// XXX need to subtract out padding, also this needs
// to be synced with nsFrame's IsPercentageBase
const nsReflowState* rs = &aReflowState;
while (nsnull != rs) {
nsIFrame* block = nsnull;
rs->frame->QueryInterface(kBlockFrameCID, (void**) &block);
if (nsnull != block) {
if (NS_UNCONSTRAINEDSIZE == rs->maxSize.width) {
// When we find an unconstrained block it means that pass1
// table reflow is occuring. In this case the percentage
// value is unknown so assume it's epsilon for now.
aResult = 1;
}
else {
// We found the nearest containing block which defines what a
// percentage size is relative to. Use the width that it will
// reflow to as the basis for computing our width.
aResult = nscoord(rs->maxSize.width * aCoord.GetPercentValue());
}
rv = PR_TRUE;
break;
}
aResult = 0;
rs = rs->parentReflowState;
}
}
else {
aResult = 0;
}
// Negative width's are ignored
if (aResult <= 0) {
rv = PR_FALSE;
}
return rv;
}
#endif
// XXX if display == row || rowspan ignore width
// XXX if display == col || colspan ignore height
PRIntn
nsCSSLayout::GetStyleSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aStyleSize)
{
PRIntn rv = NS_SIZE_HAS_NONE;
const nsStylePosition* pos;
nsresult result =
aReflowState.frame->GetStyleData(eStyleStruct_Position,
(const nsStyleStruct*&)pos);
if (NS_OK == result) {
nscoord containingBlockWidth, containingBlockHeight;
nscoord width = -1, height = -1;
PRIntn widthUnit = pos->mWidth.GetUnit();
PRIntn heightUnit = pos->mHeight.GetUnit();
// When a percentage is specified we need to find the containing
// block to use as the basis for the percentage computation.
if ((eStyleUnit_Percent == widthUnit) ||
(eStyleUnit_Percent == heightUnit)) {
// Find the containing block for this frame
nsIFrame* containingBlock = nsnull;
// XXX this cast is just plain wrong
const nsHTMLReflowState* rs = (const nsHTMLReflowState*)
aReflowState.parentReflowState;
while (nsnull != rs) {
if (nsnull != rs->frame) {
PRBool isContainingBlock;
if (NS_OK == rs->frame->IsPercentageBase(isContainingBlock)) {
if (isContainingBlock) {
containingBlock = rs->frame;
break;
}
}
}
// XXX this cast is just plain wrong
rs = (const nsHTMLReflowState*) rs->parentReflowState;
}
// If there is no containing block then pretend the width or
// height units are auto.
if (nsnull == containingBlock) {
if (eStyleUnit_Percent == widthUnit) {
widthUnit = eStyleUnit_Auto;
}
if (eStyleUnit_Percent == heightUnit) {
heightUnit = eStyleUnit_Auto;
}
}
else {
if (eStyleUnit_Percent == widthUnit) {
if (eHTMLFrameConstraint_Unconstrained == rs->widthConstraint) {
if (NS_UNCONSTRAINEDSIZE == rs->maxSize.width) {
// When we don't know the width (yet) of the containing
// block we use a dummy value, assuming that the frame
// depending on the percentage value will be reflowed a
// second time.
containingBlockWidth = 1;
}
else {
containingBlockWidth = rs->maxSize.width;
}
}
else {
containingBlockWidth = rs->minWidth;
}
}
if (eStyleUnit_Percent == heightUnit) {
if (eHTMLFrameConstraint_Unconstrained == rs->heightConstraint) {
if (NS_UNCONSTRAINEDSIZE == rs->maxSize.height) {
// CSS2 spec, 10.5: if the height of the containing block
// is not specified explicitly then the value is
// interpreted like auto.
heightUnit = eStyleUnit_Auto;
}
else {
containingBlockHeight = rs->maxSize.height;
}
}
else {
containingBlockHeight = rs->minHeight;
}
}
}
}
switch (widthUnit) {
case eStyleUnit_Coord:
width = pos->mWidth.GetCoordValue();
break;
case eStyleUnit_Percent:
width = nscoord(pos->mWidth.GetPercentValue() * containingBlockWidth);
break;
case eStyleUnit_Auto:
// XXX See section 10.3 of the css2 spec and then write this code!
break;
}
switch (heightUnit) {
case eStyleUnit_Coord:
height = pos->mHeight.GetCoordValue();
break;
case eStyleUnit_Percent:
height = nscoord(pos->mHeight.GetPercentValue() * containingBlockHeight);
break;
case eStyleUnit_Auto:
// XXX See section 10.6 of the css2 spec and then write this code!
break;
}
if (width > 0) {
aStyleSize.width = width;
rv |= NS_SIZE_HAS_WIDTH;
}
if (height > 0) {
aStyleSize.height = height;
rv |= NS_SIZE_HAS_HEIGHT;
}
}
return rv;
}

Просмотреть файл

@ -47,22 +47,6 @@ public:
nsIFrame* aContainer,
nsIFrame* aFirstChild,
PRInt32 aChildCount);
/**
* Get the CSS size (width & height) values for the given
* frame. The value returned indicates which values were set
* stylistically.
*/
static PRIntn GetStyleSize(nsIPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsSize& aStyleSize);
// Return value from GetStyleSize
#define NS_SIZE_HAS_NONE 0x0
#define NS_SIZE_HAS_WIDTH 0x1
#define NS_SIZE_HAS_HEIGHT 0x2
#define NS_SIZE_HAS_BOTH 0x3
};
#endif /* nsCSSLayout_h___ */

Просмотреть файл

@ -25,7 +25,6 @@
#include "nsIContent.h"
#include "nsIHTMLContent.h"
#include "nsHTMLIIDs.h"
#include "nsCSSLayout.h"
#include "nsHTMLParts.h"
#include "nsHTMLValue.h"
#include "nsHTMLAtoms.h"

Просмотреть файл

@ -25,7 +25,6 @@
#include "nsIRenderingContext.h"
#include "nsCSSRendering.h"
#include "nsIContent.h"
#include "nsCSSLayout.h"
#include "nsVoidArray.h"
#include "nsIPtr.h"
#include "prinrval.h"

Просмотреть файл

@ -25,7 +25,6 @@
#include "nsIContent.h"
#include "nsIHTMLContent.h"
#include "nsHTMLIIDs.h"
#include "nsCSSLayout.h"
#include "nsHTMLParts.h"
#include "nsHTMLValue.h"
#include "nsHTMLAtoms.h"

Просмотреть файл

@ -25,7 +25,6 @@
#include "nsIRenderingContext.h"
#include "nsCSSRendering.h"
#include "nsIContent.h"
#include "nsCSSLayout.h"
#include "nsVoidArray.h"
#include "nsIPtr.h"
#include "prinrval.h"