Skip to content

Commit

Permalink
closes #493: fix height for flexbox case M1030952 M1180107
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Apr 8, 2018
1 parent 5f4c3c9 commit 2a28a03
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 75 deletions.
17 changes: 17 additions & 0 deletions layout/base/FramePropertyTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ class FramePropertyTable {
*/
void DeleteAll();

/**
* Check if a property exists (added for TenFourFox issue 493).
*/
bool Has(const nsIFrame* aFrame, const FramePropertyDescriptor* aProperty)
{
bool foundResult = false;
(void)Get(aFrame, aProperty, &foundResult);
return foundResult;
}

size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;

protected:
Expand Down Expand Up @@ -238,6 +248,13 @@ class FrameProperties {
{
mTable->Delete(mFrame, aProperty);
}
// TenFourFox issue 493
bool Has(const FramePropertyDescriptor* aProperty)
{
bool foundResult;
(void)mTable->Get(mFrame, aProperty, &foundResult);
return foundResult;
}

private:
FramePropertyTable* mTable;
Expand Down
61 changes: 43 additions & 18 deletions layout/base/nsLayoutUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5165,33 +5165,58 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
bool isFlexItem = aFrame->IsFlexItem();
bool isInlineFlexItem = false;

Maybe<nsStyleCoord> imposedMainSizeStyleCoord;

// If this is a flex item, and we're measuring its cross size after flexing
// to resolve its main size, then we need to use the resolved main size
// that the container provides to us *instead of* the main-size coordinate
// from our style struct. (Otherwise, we'll be using an irrelevant value in
// the aspect-ratio calculations below.)
if (isFlexItem) {
// Flex items use their "flex-basis" property in place of their main-size
// property (e.g. "width") for sizing purposes, *unless* they have
// "flex-basis:auto", in which case they use their main-size property after
// all.
uint32_t flexDirection =
aFrame->GetParent()->StylePosition()->mFlexDirection;
isInlineFlexItem =
flexDirection == NS_STYLE_FLEX_DIRECTION_ROW ||
flexDirection == NS_STYLE_FLEX_DIRECTION_ROW_REVERSE;

// NOTE: The logic here should match the similar chunk for determining
// inlineStyleCoord and blockStyleCoord in nsFrame::ComputeSize().
const nsStyleCoord* flexBasis = &(stylePos->mFlexBasis);
if (flexBasis->GetUnit() != eStyleUnit_Auto) {
// If FlexItemMainSizeOverride frame-property is set, then that means the
// flex container is imposing a main-size on this flex item for it to use
// as its size in the container's main axis.
FrameProperties props = aFrame->Properties();
bool didImposeMainSize;
nscoord imposedMainSize =
props.Get(nsIFrame::FlexItemMainSizeOverride(), &didImposeMainSize);
if (didImposeMainSize) {
imposedMainSizeStyleCoord.emplace(imposedMainSize,
nsStyleCoord::CoordConstructor);
if (isInlineFlexItem) {
inlineStyleCoord = flexBasis;
inlineStyleCoord = imposedMainSizeStyleCoord.ptr();
} else {
// One caveat for vertical flex items: We don't support enumerated
// values (e.g. "max-content") for height properties yet. So, if our
// computed flex-basis is an enumerated value, we'll just behave as if
// it were "auto", which means "use the main-size property after all"
// (which is "height", in this case).
// NOTE: Once we support intrinsic sizing keywords for "height",
// we should remove this check.
if (flexBasis->GetUnit() != eStyleUnit_Enumerated) {
blockStyleCoord = flexBasis;
blockStyleCoord = imposedMainSizeStyleCoord.ptr();
}

} else {
// Flex items use their "flex-basis" property in place of their main-size
// property (e.g. "width") for sizing purposes, *unless* they have
// "flex-basis:auto", in which case they use their main-size property
// after all.
// NOTE: The logic here should match the similar chunk for determining
// inlineStyleCoord and blockStyleCoord in nsFrame::ComputeSize().
const nsStyleCoord* flexBasis = &(stylePos->mFlexBasis);
if (flexBasis->GetUnit() != eStyleUnit_Auto) {
if (isInlineFlexItem) {
inlineStyleCoord = flexBasis;
} else {
// One caveat for vertical flex items: We don't support enumerated
// values (e.g. "max-content") for height properties yet. So, if our
// computed flex-basis is an enumerated value, we'll just behave as if
// it were "auto", which means "use the main-size property after all"
// (which is "height", in this case).
// NOTE: Once we support intrinsic sizing keywords for "height",
// we should remove this check.
if (flexBasis->GetUnit() != eStyleUnit_Enumerated) {
blockStyleCoord = flexBasis;
}
}
}
}
Expand Down
Loading

0 comments on commit 2a28a03

Please sign in to comment.