Bug 1395586: Add accessors and privatize trivial nsStyleDisplay members. r?heycam
While at it, also reorder some of them to save some space.
The idea is to autogenerate code for these, and to pack them using bitfields. It
still needs some more code, but I think I'll try to get something next week.
This is preliminary anyway, but I wanted to land it since they're huge changes.
MozReview-Commit-ID: JQPiaqSHCuy
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -715,17 +715,17 @@ nsStyleList::CalcDifference(const nsStyl
}
nsChangeHint hint = nsChangeHint(0);
// Only elements whose display value is list-item can be affected by
// list-style-position and list-style-type. If the old display struct
// doesn't exist, assume it isn't affected by display value at all,
// and thus these properties should not affect it either. This also
// relies on that when the display value changes from something else
// to list-item, that change itself would cause ReconstructFrame.
- if (aOldDisplay && aOldDisplay->mDisplay == StyleDisplay::ListItem) {
+ if (aOldDisplay && aOldDisplay->Display() == StyleDisplay::ListItem) {
if (mListStylePosition != aNewData.mListStylePosition) {
return nsChangeHint_ReconstructFrame;
}
if (mCounterStyle != aNewData.mCounterStyle) {
return NS_STYLE_HINT_REFLOW;
}
} else if (mListStylePosition != aNewData.mListStylePosition ||
mCounterStyle != aNewData.mCounterStyle) {
@@ -3412,22 +3412,22 @@ nsStyleDisplay::nsStyleDisplay(const nsP
, mOrient(StyleOrient::Inline)
, mIsolation(NS_STYLE_ISOLATION_AUTO)
, mTopLayer(NS_STYLE_TOP_LAYER_NONE)
, mWillChangeBitField(0)
, mTouchAction(NS_STYLE_TOUCH_ACTION_AUTO)
, mScrollBehavior(NS_STYLE_SCROLL_BEHAVIOR_AUTO)
, mScrollSnapTypeX(NS_STYLE_SCROLL_SNAP_TYPE_NONE)
, mScrollSnapTypeY(NS_STYLE_SCROLL_SNAP_TYPE_NONE)
- , mScrollSnapPointsX(eStyleUnit_None)
- , mScrollSnapPointsY(eStyleUnit_None)
, mBackfaceVisibility(NS_STYLE_BACKFACE_VISIBILITY_VISIBLE)
, mTransformStyle(NS_STYLE_TRANSFORM_STYLE_FLAT)
, mTransformBox(StyleGeometryBox::BorderBox)
, mSpecifiedTransform(nullptr)
+ , mScrollSnapPointsX(eStyleUnit_None)
+ , mScrollSnapPointsY(eStyleUnit_None)
, mTransformOrigin{ {0.5f, eStyleUnit_Percent}, // Transform is centered on origin
{0.5f, eStyleUnit_Percent},
{0, nsStyleCoord::CoordConstructor} }
, mChildPerspective(eStyleUnit_None)
, mPerspectiveOrigin{ {0.5f, eStyleUnit_Percent},
{0.5f, eStyleUnit_Percent} }
, mVerticalAlign(NS_STYLE_VERTICAL_ALIGN_BASELINE, eStyleUnit_Enumerated)
, mTransitions(nsStyleAutoArray<StyleTransition>::WITH_SINGLE_INITIAL_ELEMENT)
@@ -3470,29 +3470,29 @@ nsStyleDisplay::nsStyleDisplay(const nsS
, mOverflowX(aSource.mOverflowX)
, mOverflowY(aSource.mOverflowY)
, mOverflowClipBox(aSource.mOverflowClipBox)
, mResize(aSource.mResize)
, mOrient(aSource.mOrient)
, mIsolation(aSource.mIsolation)
, mTopLayer(aSource.mTopLayer)
, mWillChangeBitField(aSource.mWillChangeBitField)
- , mWillChange(aSource.mWillChange)
, mTouchAction(aSource.mTouchAction)
, mScrollBehavior(aSource.mScrollBehavior)
, mScrollSnapTypeX(aSource.mScrollSnapTypeX)
, mScrollSnapTypeY(aSource.mScrollSnapTypeY)
- , mScrollSnapPointsX(aSource.mScrollSnapPointsX)
- , mScrollSnapPointsY(aSource.mScrollSnapPointsY)
- , mScrollSnapDestination(aSource.mScrollSnapDestination)
- , mScrollSnapCoordinate(aSource.mScrollSnapCoordinate)
, mBackfaceVisibility(aSource.mBackfaceVisibility)
, mTransformStyle(aSource.mTransformStyle)
, mTransformBox(aSource.mTransformBox)
, mSpecifiedTransform(aSource.mSpecifiedTransform)
+ , mScrollSnapDestination(aSource.mScrollSnapDestination)
+ , mScrollSnapCoordinate(aSource.mScrollSnapCoordinate)
+ , mWillChange(aSource.mWillChange)
+ , mScrollSnapPointsX(aSource.mScrollSnapPointsX)
+ , mScrollSnapPointsY(aSource.mScrollSnapPointsY)
, mTransformOrigin{ aSource.mTransformOrigin[0],
aSource.mTransformOrigin[1],
aSource.mTransformOrigin[2] }
, mChildPerspective(aSource.mChildPerspective)
, mPerspectiveOrigin{ aSource.mPerspectiveOrigin[0],
aSource.mPerspectiveOrigin[1] }
, mVerticalAlign(aSource.mVerticalAlign)
, mTransitions(aSource.mTransitions)
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -2658,16 +2658,30 @@ public:
mozilla::css::URLValue* operator->() const { return Get(); }
mozilla::css::URLValue* Get() const { return (mPtr && mPtr->GetURI()) ? mPtr.get() : nullptr; }
mozilla::css::URLValue* ForceGet() const { return mPtr.get(); }
void Set(mozilla::css::URLValue* aPtr) { mPtr = aPtr; }
private:
RefPtr<mozilla::css::URLValue> mPtr;
};
+// Please keep the fields that use this macro private, the idea is for them to
+// be packed in the near future.
+//
+// TODO(emilio): It'd be nice for style structs to be auto-generated.
+#define PRIVATE_MEMBER(type_, name_) \
+ private: \
+ type_ m##name_; \
+ \
+ public: \
+ type_ name_() const { return m##name_; } \
+ void Set##name_(type_ a##name_) { \
+ m##name_ = a##name_; \
+ }
+
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay
{
typedef mozilla::StyleGeometryBox StyleGeometryBox;
explicit nsStyleDisplay(const nsPresContext* aContext);
nsStyleDisplay(const nsStyleDisplay& aOther);
~nsStyleDisplay();
@@ -2684,68 +2698,77 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
aContext->PresShell()->
FreeByObjectID(mozilla::eArenaObjectID_nsStyleDisplay, this);
}
nsChangeHint CalcDifference(const nsStyleDisplay& aNewData) const;
// We guarantee that if mBinding is non-null, so are mBinding->GetURI() and
// mBinding->mOriginPrincipal.
- BindingHolder mBinding; // [reset]
- mozilla::StyleDisplay mDisplay; // [reset] see nsStyleConsts.h StyleDisplay
- mozilla::StyleDisplay mOriginalDisplay; // [reset] saved mDisplay for
- // position:absolute/fixed
- // and float:left/right;
- // otherwise equal to
- // mDisplay
- uint8_t mContain; // [reset] see nsStyleConsts.h NS_STYLE_CONTAIN_*
- uint8_t mAppearance; // [reset]
- uint8_t mPosition; // [reset] see nsStyleConsts.h
+ BindingHolder mBinding; // [reset]
+
+ PRIVATE_MEMBER(mozilla::StyleDisplay, Display); // [reset] see nsStyleConsts.h
+
+ // [reset] saved mDisplay for position:absolute/fixed and float:left/right;
+ // otherwise equal to mDisplay
+ PRIVATE_MEMBER(mozilla::StyleDisplay, OriginalDisplay);
+
+ PRIVATE_MEMBER(uint8_t, Contain); // [reset] see nsStyleConsts.h NS_STYLE_CONTAIN_*
+ PRIVATE_MEMBER(uint8_t, Appearance); // [reset]
+ PRIVATE_MEMBER(uint8_t, Position); // [reset]
// [reset] See StyleFloat in nsStyleConsts.h.
- mozilla::StyleFloat mFloat;
+ PRIVATE_MEMBER(mozilla::StyleFloat, Float);
// [reset] Save mFloat for position:absolute/fixed; otherwise equal to mFloat.
- mozilla::StyleFloat mOriginalFloat;
-
- mozilla::StyleClear mBreakType; // [reset]
- uint8_t mBreakInside; // [reset] NS_STYLE_PAGE_BREAK_AUTO/AVOID
- bool mBreakBefore; // [reset]
- bool mBreakAfter; // [reset]
- uint8_t mOverflowX; // [reset] see nsStyleConsts.h
- uint8_t mOverflowY; // [reset] see nsStyleConsts.h
- uint8_t mOverflowClipBox; // [reset] see nsStyleConsts.h
- uint8_t mResize; // [reset] see nsStyleConsts.h
- mozilla::StyleOrient mOrient; // [reset] see nsStyleConsts.h
- uint8_t mIsolation; // [reset] see nsStyleConsts.h
- uint8_t mTopLayer; // [reset] see nsStyleConsts.h
- uint8_t mWillChangeBitField; // [reset] see nsStyleConsts.h. Stores a
- // bitfield representation of the properties
- // that are frequently queried. This should
- // match mWillChange. Also tracks if any of the
- // properties in the will-change list require
- // a stacking context.
- nsCOMArray<nsIAtom> mWillChange;
-
- uint8_t mTouchAction; // [reset] see nsStyleConsts.h
- uint8_t mScrollBehavior; // [reset] see nsStyleConsts.h NS_STYLE_SCROLL_BEHAVIOR_*
- uint8_t mScrollSnapTypeX; // [reset] see nsStyleConsts.h NS_STYLE_SCROLL_SNAP_TYPE_*
- uint8_t mScrollSnapTypeY; // [reset] see nsStyleConsts.h NS_STYLE_SCROLL_SNAP_TYPE_*
- nsStyleCoord mScrollSnapPointsX; // [reset]
- nsStyleCoord mScrollSnapPointsY; // [reset]
- mozilla::Position mScrollSnapDestination; // [reset]
- nsTArray<mozilla::Position> mScrollSnapCoordinate; // [reset]
+ PRIVATE_MEMBER(mozilla::StyleFloat, OriginalFloat);
+
+ PRIVATE_MEMBER(mozilla::StyleClear, BreakType); // [reset]
+ PRIVATE_MEMBER(uint8_t, BreakInside); // [reset] NS_STYLE_PAGE_BREAK_AUTO/AVOID
+ PRIVATE_MEMBER(bool, BreakBefore); // [reset]
+ PRIVATE_MEMBER(bool, BreakAfter); // [reset]
+ PRIVATE_MEMBER(uint8_t, OverflowX); // [reset]
+ PRIVATE_MEMBER(uint8_t, OverflowY); // [reset]
+ PRIVATE_MEMBER(uint8_t, OverflowClipBox); // [reset]
+ PRIVATE_MEMBER(uint8_t, Resize); // [reset]
+ PRIVATE_MEMBER(mozilla::StyleOrient, Orient); // [reset]
+ PRIVATE_MEMBER(uint8_t, Isolation); // [reset]
+ PRIVATE_MEMBER(uint8_t, TopLayer); // [reset]
+
+ // [reset] Stores a bitfield representation of the properties that are
+ // frequently queried. This should match mWillChange.
+ //
+ // Also tracks if any of the properties in the will-change list
+ // require a stacking context.
+ PRIVATE_MEMBER(uint8_t, WillChangeBitField);
+
+ PRIVATE_MEMBER(uint8_t, TouchAction); // [reset]
+ PRIVATE_MEMBER(uint8_t, ScrollBehavior); // [reset]
+ PRIVATE_MEMBER(uint8_t, ScrollSnapTypeX); // [reset]
+ PRIVATE_MEMBER(uint8_t, ScrollSnapTypeY); // [reset]
// mSpecifiedTransform is the list of transform functions as
// specified, or null to indicate there is no transform. (inherit or
// initial are replaced by an actual list of transform functions, or
// null, as appropriate.)
- uint8_t mBackfaceVisibility;
- uint8_t mTransformStyle;
- StyleGeometryBox mTransformBox; // [reset] see nsStyleConsts.h
+ PRIVATE_MEMBER(uint8_t, BackfaceVisibility);
+ PRIVATE_MEMBER(uint8_t, TransformStyle);
+
+ // [reset] We don't reserve space for MozAlmostPadding, since it should never
+ // be set on a style struct.
+ PRIVATE_MEMBER(StyleGeometryBox, TransformBox);
RefPtr<nsCSSValueSharedList> mSpecifiedTransform; // [reset]
+
+ mozilla::Position mScrollSnapDestination; // [reset]
+ nsTArray<mozilla::Position> mScrollSnapCoordinate; // [reset]
+
+ // [reset] moved down for better packing.
+ nsCOMArray<nsIAtom> mWillChange;
+
+ nsStyleCoord mScrollSnapPointsX; // [reset]
+ nsStyleCoord mScrollSnapPointsY; // [reset]
nsStyleCoord mTransformOrigin[3]; // [reset] percent, coord, calc, 3rd param is coord, calc only
nsStyleCoord mChildPerspective; // [reset] none, coord
nsStyleCoord mPerspectiveOrigin[2]; // [reset] percent, coord, calc
nsStyleCoord mVerticalAlign; // [reset] coord, percent, calc, enum (see nsStyleConsts.h)
nsStyleAutoArray<mozilla::StyleTransition> mTransitions; // [reset]
@@ -2755,16 +2778,19 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
mTransitionDurationCount,
mTransitionDelayCount,
mTransitionPropertyCount;
nsStyleAutoArray<mozilla::StyleAnimation> mAnimations; // [reset]
// The number of elements in mAnimations that are not from repeating
// a list due to another property being longer.
+ //
+ // FIXME(emilio): This takes lots of space in the common no transitions and
+ // no animations case. Can we do better?
uint32_t mAnimationTimingFunctionCount,
mAnimationDurationCount,
mAnimationDelayCount,
mAnimationNameCount,
mAnimationDirectionCount,
mAnimationFillModeCount,
mAnimationPlayStateCount,
mAnimationIterationCountCount;