245static inline bool defaultAlignmentIsStretch(ItemPosition position)
246{
247 return position == ItemPositionStretch || position == ItemPositionAuto;
248}
249
250static inline bool defaultAlignmentChangedToStretchInRowAxis(const RenderStyle& oldStyle, const RenderStyle& newStyle)
251{
252 return !defaultAlignmentIsStretch(oldStyle.justifyItemsPosition()) && defaultAlignmentIsStretch(newStyle.justifyItemsPosition());
253}
254
255static inline bool defaultAlignmentChangedFromStretchInColumnAxis(const RenderStyle& oldStyle, const RenderStyle& newStyle)
256{
257 return defaultAlignmentIsStretch(oldStyle.alignItemsPosition()) && !defaultAlignmentIsStretch(newStyle.alignItemsPosition());
258}
259
260static inline bool selfAlignmentChangedToStretchInRowAxis(const RenderStyle& oldStyle, const RenderStyle& newStyle, const RenderStyle& childStyle)
261{
262 return RenderStyle::resolveJustification(oldStyle, childStyle, ItemPositionStretch) != ItemPositionStretch
263 && RenderStyle::resolveJustification(newStyle, childStyle, ItemPositionStretch) == ItemPositionStretch;
264}
265
266static inline bool selfAlignmentChangedFromStretchInColumnAxis(const RenderStyle& oldStyle, const RenderStyle& newStyle, const RenderStyle& childStyle)
267{
268 return RenderStyle::resolveAlignment(oldStyle, childStyle, ItemPositionStretch) == ItemPositionStretch
269 && RenderStyle::resolveAlignment(newStyle, childStyle, ItemPositionStretch) != ItemPositionStretch;
270}
271
272void RenderGrid::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
273{
274 RenderBlock::styleDidChange(diff, oldStyle);
275 if (!oldStyle || diff != StyleDifferenceLayout)
276 return;
277
278 const RenderStyle& newStyle = style();
279 if (defaultAlignmentChangedToStretchInRowAxis(*oldStyle, newStyle) || defaultAlignmentChangedFromStretchInColumnAxis(*oldStyle, newStyle)) {
280 // Grid items that were not previously stretched in row-axis need to be relayed out so we can compute new available space.
281 // Grid items that were previously stretching in column-axis need to be relayed out so we can compute new available space.
282 // This is only necessary for stretching since other alignment values don't change the size of the box.
283 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
284 if (selfAlignmentChangedToStretchInRowAxis(*oldStyle, newStyle, child->style()) || selfAlignmentChangedFromStretchInColumnAxis(*oldStyle, newStyle, child->style()))
285 child->setChildNeedsLayout();
286 }
287 }
288}
289