Deal with flex values that add up to too much. Bug 345709, r=neil, sr=roc

This commit is contained in:
bzbarsky%mit.edu 2006-08-15 01:08:00 +00:00
Родитель a39233c772
Коммит 6c8c09b78a
2 изменённых файлов: 32 добавлений и 5 удалений

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

@ -4423,7 +4423,7 @@ PRBool CSSParserImpl::ParseSingleValueProperty(nsresult& aErrorCode,
return ParseVariant(aErrorCode, aValue, VARIANT_HK, return ParseVariant(aErrorCode, aValue, VARIANT_HK,
nsCSSProps::kBoxDirectionKTable); nsCSSProps::kBoxDirectionKTable);
case eCSSProperty_box_flex: case eCSSProperty_box_flex:
return ParseVariant(aErrorCode, aValue, VARIANT_HN, nsnull); return ParsePositiveVariant(aErrorCode, aValue, VARIANT_HN, nsnull);
case eCSSProperty_box_orient: case eCSSProperty_box_orient:
return ParseVariant(aErrorCode, aValue, VARIANT_HK, return ParseVariant(aErrorCode, aValue, VARIANT_HK,
nsCSSProps::kBoxOrientKTable); nsCSSProps::kBoxOrientKTable);

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

@ -803,8 +803,12 @@ nsSprocketLayout::PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aState, nsBox
currentBox = aBoxSizes; currentBox = aBoxSizes;
nsBoxSize* last = nsnull; nsBoxSize* last = nsnull;
nscoord maxFlex = 0;
PRInt32 childCount = 0;
while(child) while(child)
{ {
++childCount;
nsSize pref(0,0); nsSize pref(0,0);
nsSize min(0,0); nsSize min(0,0);
nsSize max(NS_INTRINSICSIZE,NS_INTRINSICSIZE); nsSize max(NS_INTRINSICSIZE,NS_INTRINSICSIZE);
@ -864,10 +868,15 @@ nsSprocketLayout::PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aState, nsBox
child->GetFlex(aState, flex); child->GetFlex(aState, flex);
// set them if you collapsed you are not flexible. // set them if you collapsed you are not flexible.
if (collapsed) if (collapsed) {
currentBox->flex = 0; currentBox->flex = 0;
else }
else {
if (flex > maxFlex) {
maxFlex = flex;
}
currentBox->flex = flex; currentBox->flex = flex;
}
// we specified all our children are equal size; // we specified all our children are equal size;
if (frameState & NS_STATE_EQUAL_SIZE) { if (frameState & NS_STATE_EQUAL_SIZE) {
@ -916,6 +925,24 @@ nsSprocketLayout::PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aState, nsBox
} }
if (childCount > 0) {
nscoord maxAllowedFlex = nscoord_MAX / childCount;
if (NS_UNLIKELY(maxFlex > maxAllowedFlex)) {
// clamp all the flexes
currentBox = aBoxSizes;
while (currentBox) {
currentBox->flex = PR_MIN(currentBox->flex, maxAllowedFlex);
currentBox = currentBox->next;
}
}
}
#ifdef DEBUG
else {
NS_ASSERTION(maxFlex == 0, "How did that happen?");
}
#endif
// we specified all our children are equal size; // we specified all our children are equal size;
if (frameState & NS_STATE_EQUAL_SIZE) { if (frameState & NS_STATE_EQUAL_SIZE) {
currentBox = aBoxSizes; currentBox = aBoxSizes;