Skip to content

Commit

Permalink
Bug 1501109 Part 1: Change Flex API growth state to match layout algo…
Browse files Browse the repository at this point in the history
…rithm, and use enums from webidl. r=dholbert

Differential Revision: https://phabricator.services.mozilla.com/D9454

--HG--
extra : moz-landing-system : lando
  • Loading branch information
bradwerth committed Oct 23, 2018
1 parent 5649949 commit 29992e3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 54 deletions.
13 changes: 10 additions & 3 deletions dom/chrome-webidl/Flex.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ interface Flex
};

/**
* Lines with items that have been shrunk are shrinking; with items
* that have grown are growing, and all others are unchanged.
* This indicates which flex factor (flex-grow vs. flex-shrink) the
* flex layout algorithm uses internally when resolving flexible sizes
* in a given flex line, per flexbox spec section 9.7 step 1. Note that
* this value doesn't necessarily mean that any items on this line
* are *actually* growing (or shrinking). This simply indicates what
* the layout algorithm "wants" to do, based on the free space --
* and items will stretch from their flex base size in the corresponding
* direction, if permitted by their min/max constraints and their
* corresponding flex factor.
*/
enum FlexLineGrowthState { "unchanged", "shrinking", "growing" };
enum FlexLineGrowthState { "shrinking", "growing" };

[ChromeOnly]
interface FlexLineValues
Expand Down
13 changes: 1 addition & 12 deletions dom/flex/FlexLineValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@ FlexLineValues::FlexLineValues(Flex* aParent,

// Eagerly copy values from aLine, because we're not
// going to keep it around.
switch (aLine->mGrowthState) {
case ComputedFlexLineInfo::GrowthState::SHRINKING:
mGrowthState = FlexLineGrowthState::Shrinking;
break;

case ComputedFlexLineInfo::GrowthState::GROWING:
mGrowthState = FlexLineGrowthState::Growing;
break;

default:
mGrowthState = FlexLineGrowthState::Unchanged;
};
mGrowthState = aLine->mGrowthState;

// Convert all the app unit values into css pixels.
mCrossStart = nsPresContext::AppUnitsToDoubleCSSPixels(
Expand Down
44 changes: 10 additions & 34 deletions layout/generic/nsFlexContainerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,12 @@ FlexLine::ResolveFlexibleLengths(nscoord aFlexContainerMainSize,
const bool isUsingFlexGrow =
(mTotalOuterHypotheticalMainSize < aFlexContainerMainSize);

if (aLineInfo) {
aLineInfo->mGrowthState = isUsingFlexGrow ?
mozilla::dom::FlexLineGrowthState::Growing :
mozilla::dom::FlexLineGrowthState::Shrinking;
}

// Do an "early freeze" for flex items that obviously can't flex in the
// direction we've chosen:
FreezeItemsEarly(isUsingFlexGrow, aLineInfo);
Expand Down Expand Up @@ -2872,30 +2878,6 @@ FlexLine::ResolveFlexibleLengths(nscoord aFlexContainerMainSize,
aLineInfo->mItems[itemIndex].mMainBaseSize;

aLineInfo->mItems[itemIndex].mMainDeltaSize = deltaSize;
// If any (unfrozen) item on the line is growing, we mark the
// aLineInfo structure; likewise if any item is shrinking.
// (Note: a line can't contain a mix of items that are growing
// and shrinking. Also, the sign of any delta should match the
// type of flex factor we're using [grow vs shrink].)
if (deltaSize > 0) {
MOZ_ASSERT(isUsingFlexGrow,
"Unfrozen items can only grow if we're "
"distributing (positive) space with flex-grow");
MOZ_ASSERT(aLineInfo->mGrowthState !=
ComputedFlexLineInfo::GrowthState::SHRINKING,
"shouldn't flip flop from shrinking to growing");
aLineInfo->mGrowthState =
ComputedFlexLineInfo::GrowthState::GROWING;
} else if (deltaSize < 0) {
MOZ_ASSERT(!isUsingFlexGrow,
"Unfrozen items can only shrink if we're "
"distributing (negative) space with flex-shrink");
MOZ_ASSERT(aLineInfo->mGrowthState !=
ComputedFlexLineInfo::GrowthState::GROWING,
"shouldn't flip flop from growing to shrinking");
aLineInfo->mGrowthState =
ComputedFlexLineInfo::GrowthState::SHRINKING;
}
}
}
}
Expand Down Expand Up @@ -4770,16 +4752,10 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext,
line = line->getNext()) {
ComputedFlexLineInfo* lineInfo =
containerInfo->mLines.AppendElement();
// Most lineInfo properties will be set later, but we set
// mGrowthState to UNCHANGED here because it may be later
// modified by ResolveFlexibleLengths().
lineInfo->mGrowthState =
ComputedFlexLineInfo::GrowthState::UNCHANGED;

// The remaining lineInfo properties will be filled out at the
// end of this function, when we have real values. But we still
// add all the items here, so we can capture computed data for
// each item.
// Most of the remaining lineInfo properties will be filled out at the
// end of this function (some will be provided by other functions),
// when we have real values. But we still add all the items here, so
// we can capture computed data for each item as we proceed.
for (const FlexItem* item = line->GetFirstItem(); item;
item = item->getNext()) {
nsIFrame* frame = item->Frame();
Expand Down
6 changes: 1 addition & 5 deletions layout/generic/nsFlexContainerFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ struct ComputedFlexLineInfo
nscoord mCrossSize;
nscoord mFirstBaselineOffset;
nscoord mLastBaselineOffset;
enum GrowthState {
UNCHANGED,
SHRINKING,
GROWING,
} mGrowthState;
mozilla::dom::FlexLineGrowthState mGrowthState;
};

struct ComputedFlexContainerInfo
Expand Down

0 comments on commit 29992e3

Please sign in to comment.