Bug 1257688 part 0: Add an "IsLegacyBox" accessor to nsFlexContainerFrame, to enable special handling of display:-webkit-box & display:-webkit-inline-box. r=mats
MozReview-Commit-ID: Dt5Zx2sHN99
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -73,16 +73,54 @@ kAxisOrientationToSidesMap[eNumAxisOrien
{ eSideLeft, eSideRight }, // eAxis_LR
{ eSideRight, eSideLeft }, // eAxis_RL
{ eSideTop, eSideBottom }, // eAxis_TB
{ eSideBottom, eSideTop } // eAxis_BT
};
// Helper structs / classes / methods
// ==================================
+// Returns true iff the given nsStyleDisplay has display:-webkit-{inline-}-box.
+static inline bool
+IsDisplayValueLegacyBox(const nsStyleDisplay* aStyleDisp)
+{
+ return aStyleDisp->mDisplay == NS_STYLE_DISPLAY_WEBKIT_BOX ||
+ aStyleDisp->mDisplay == NS_STYLE_DISPLAY_WEBKIT_INLINE_BOX;
+}
+
+// Helper to check whether our nsFlexContainerFrame is emulating a legacy
+// -webkit-{inline-}box, in which case we should use legacy CSS properties
+// 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)
+{
+ // Trivial case: just check "display" directly.
+ if (IsDisplayValueLegacyBox(aStyleDisp)) {
+ return true;
+ }
+
+ // 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
+ // value. So in that case, check the parent to find out if we're legacy.
+ if (aStyleDisp->mDisplay == NS_STYLE_DISPLAY_BLOCK) {
+ nsStyleContext* parentStyleContext = aStyleContext->GetParent();
+ NS_ASSERTION(parentStyleContext &&
+ aStyleContext->GetPseudo() == nsCSSAnonBoxes::scrolledContent,
+ "The only way a nsFlexContainerFrame can have 'display:block' "
+ "should be if it's the inner part of a scrollable element");
+ if (IsDisplayValueLegacyBox(parentStyleContext->StyleDisplay())) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
// Indicates whether advancing along the given axis is equivalent to
// increasing our X or Y position (as opposed to decreasing it).
static inline bool
AxisGrowsInPositiveDirection(AxisOrientationType aAxis)
{
return eAxis_LR == aAxis || eAxis_TB == aAxis;
}