Bug 1309119 part 1: Expose nsFlexContainerFrame helper-function IsLegacyBox as a static method. r=mats

MozReview-Commit-ID: 8fztWk2sp0L
This commit is contained in:
Daniel Holbert 2016-10-20 13:23:51 -07:00
Родитель 2aea3c42d5
Коммит 72b186f76f
2 изменённых файлов: 21 добавлений и 25 удалений

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

@ -87,27 +87,24 @@ IsDisplayValueLegacyBox(const nsStyleDisplay* aStyleDisp)
aStyleDisp->mDisplay == mozilla::StyleDisplay::WebkitInlineBox; aStyleDisp->mDisplay == mozilla::StyleDisplay::WebkitInlineBox;
} }
// Helper to check whether our nsFlexContainerFrame is emulating a legacy /* static */ bool
// -webkit-{inline-}box, in which case we should use legacy CSS properties nsFlexContainerFrame::IsLegacyBox(const nsIFrame* aFrame)
// instead of the modern ones. The params are are the nsStyleDisplay and the
// nsStyleContext associated with the nsFlexContainerFrame itself.
static inline bool
IsLegacyBox(const nsStyleDisplay* aStyleDisp,
nsStyleContext* aStyleContext)
{ {
nsStyleContext* styleContext = aFrame->StyleContext();
const nsStyleDisplay* styleDisp = styleContext->StyleDisplay();
// Trivial case: just check "display" directly. // Trivial case: just check "display" directly.
if (IsDisplayValueLegacyBox(aStyleDisp)) { if (IsDisplayValueLegacyBox(styleDisp)) {
return true; return true;
} }
// If this frame is for a scrollable element, then it will actually have // If this frame is for a scrollable element, then it will actually have
// "display:block", and its *parent* will have the real flex-flavored display // "display:block", and its *parent* will have the real flex-flavored display
// value. So in that case, check the parent to find out if we're legacy. // value. So in that case, check the parent to find out if we're legacy.
if (aStyleDisp->mDisplay == mozilla::StyleDisplay::Block) { if (styleDisp->mDisplay == mozilla::StyleDisplay::Block) {
nsStyleContext* parentStyleContext = aStyleContext->GetParent(); nsStyleContext* parentStyleContext = styleContext->GetParent();
NS_ASSERTION(parentStyleContext && NS_ASSERTION(parentStyleContext &&
(aStyleContext->GetPseudo() == nsCSSAnonBoxes::buttonContent || (styleContext->GetPseudo() == nsCSSAnonBoxes::buttonContent ||
aStyleContext->GetPseudo() == nsCSSAnonBoxes::scrolledContent), styleContext->GetPseudo() == nsCSSAnonBoxes::scrolledContent),
"The only way a nsFlexContainerFrame can have 'display:block' " "The only way a nsFlexContainerFrame can have 'display:block' "
"should be if it's the inner part of a scrollable or button " "should be if it's the inner part of a scrollable or button "
"element"); "element");
@ -1070,9 +1067,7 @@ IsOrderLEQWithDOMFallback(nsIFrame* aFrame1,
"this method only intended for comparing flex items"); "this method only intended for comparing flex items");
MOZ_ASSERT(aFrame1->GetParent() == aFrame2->GetParent(), MOZ_ASSERT(aFrame1->GetParent() == aFrame2->GetParent(),
"this method only intended for comparing siblings"); "this method only intended for comparing siblings");
nsStyleContext* parentFrameSC = aFrame1->GetParent()->StyleContext(); bool isInLegacyBox = nsFlexContainerFrame::IsLegacyBox(aFrame1->GetParent());
bool isInLegacyBox = IsLegacyBox(parentFrameSC->StyleDisplay(),
parentFrameSC);
if (aFrame1 == aFrame2) { if (aFrame1 == aFrame2) {
// Anything is trivially LEQ itself, so we return "true" here... but it's // Anything is trivially LEQ itself, so we return "true" here... but it's
@ -1156,9 +1151,7 @@ IsOrderLEQ(nsIFrame* aFrame1,
"this method only intended for comparing flex items"); "this method only intended for comparing flex items");
MOZ_ASSERT(aFrame1->GetParent() == aFrame2->GetParent(), MOZ_ASSERT(aFrame1->GetParent() == aFrame2->GetParent(),
"this method only intended for comparing siblings"); "this method only intended for comparing siblings");
nsStyleContext* parentFrameSC = aFrame1->GetParent()->StyleContext(); bool isInLegacyBox = nsFlexContainerFrame::IsLegacyBox(aFrame1->GetParent());
bool isInLegacyBox = IsLegacyBox(parentFrameSC->StyleDisplay(),
parentFrameSC);
// If we've got a placeholder frame, use its out-of-flow frame's 'order' val. // If we've got a placeholder frame, use its out-of-flow frame's 'order' val.
nsIFrame* aRealFrame1 = nsPlaceholderFrame::GetRealFrameFor(aFrame1); nsIFrame* aRealFrame1 = nsPlaceholderFrame::GetRealFrameFor(aFrame1);
@ -1194,7 +1187,7 @@ nsFlexContainerFrame::GenerateFlexItemForChild(
// FLEX GROW & SHRINK WEIGHTS // FLEX GROW & SHRINK WEIGHTS
// -------------------------- // --------------------------
float flexGrow, flexShrink; float flexGrow, flexShrink;
if (IsLegacyBox(aParentReflowInput.mStyleDisplay, mStyleContext)) { if (IsLegacyBox(this)) {
flexGrow = flexShrink = aChildFrame->StyleXUL()->mBoxFlex; flexGrow = flexShrink = aChildFrame->StyleXUL()->mBoxFlex;
} else { } else {
const nsStylePosition* stylePos = aChildFrame->StylePosition(); const nsStylePosition* stylePos = aChildFrame->StylePosition();
@ -1707,8 +1700,7 @@ FlexItem::FlexItem(ReflowInput& aFlexItemReflowInput,
"out-of-flow frames should not be treated as flex items"); "out-of-flow frames should not be treated as flex items");
const ReflowInput* containerRS = aFlexItemReflowInput.mParentReflowInput; const ReflowInput* containerRS = aFlexItemReflowInput.mParentReflowInput;
if (IsLegacyBox(containerRS->mStyleDisplay, if (IsLegacyBox(containerRS->mFrame)) {
containerRS->mFrame->StyleContext())) {
// For -webkit-box/-webkit-inline-box, we need to: // For -webkit-box/-webkit-inline-box, we need to:
// (1) Use "-webkit-box-align" instead of "align-items" to determine the // (1) Use "-webkit-box-align" instead of "align-items" to determine the
// container's cross-axis alignment behavior. // container's cross-axis alignment behavior.
@ -3240,8 +3232,7 @@ FlexboxAxisTracker::FlexboxAxisTracker(
: mWM(aWM), : mWM(aWM),
mAreAxesInternallyReversed(false) mAreAxesInternallyReversed(false)
{ {
if (IsLegacyBox(aFlexContainer->StyleDisplay(), if (IsLegacyBox(aFlexContainer)) {
aFlexContainer->StyleContext())) {
InitAxesFromLegacyProps(aFlexContainer); InitAxesFromLegacyProps(aFlexContainer);
} else { } else {
InitAxesFromModernProps(aFlexContainer); InitAxesFromModernProps(aFlexContainer);
@ -4139,8 +4130,7 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext,
} }
} }
const auto justifyContent = IsLegacyBox(aReflowInput.mStyleDisplay, const auto justifyContent = IsLegacyBox(aReflowInput.mFrame) ?
mStyleContext) ?
ConvertLegacyStyleToJustifyContent(StyleXUL()) : ConvertLegacyStyleToJustifyContent(StyleXUL()) :
aReflowInput.mStylePosition->mJustifyContent; aReflowInput.mStylePosition->mJustifyContent;

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

@ -102,6 +102,12 @@ public:
uint32_t* aNumPackingSpacesRemaining, uint32_t* aNumPackingSpacesRemaining,
nscoord* aPackingSpaceRemaining); nscoord* aPackingSpaceRemaining);
/**
* Returns true if aFrame is the frame for an element with
* "display:-webkit-box" or "display:-webkit-inline-box".
*/
static bool IsLegacyBox(const nsIFrame* aFrame);
protected: protected:
// Protected constructor & destructor // Protected constructor & destructor
explicit nsFlexContainerFrame(nsStyleContext* aContext) explicit nsFlexContainerFrame(nsStyleContext* aContext)