Bug 1322570 Part 2 - Resolve {align,justify}-self using StyleContext from alignment container frame in ReflowInput::InitConstraints().
Per
bug 1322570 comment 46, it's not easy to replace ComputedJustifyItems()
and UsedJustifySelf()'s internal nsStyleContext::GetParent() without
correctness penalty, so we use GetParentAllowServo() for now.
Also, fix the reftest.list added in
bug 1334403 which incorrectly wrote test
page as reference page.
MozReview-Commit-ID: 6kAAWSFojd5
--- a/layout/generic/ReflowInput.cpp
+++ b/layout/generic/ReflowInput.cpp
@@ -2394,19 +2394,20 @@ ReflowInput::InitConstraints(nsPresConte
if (parentCBType == nsGkAtoms::gridContainerFrame) {
alignCB = alignCB->GetParent();
alignCBType = parentCBType;
}
}
if (alignCBType == nsGkAtoms::gridContainerFrame) {
// Shrink-wrap grid items that will be aligned (rather than stretched)
// in its inline axis.
- auto inlineAxisAlignment = wm.IsOrthogonalTo(cbwm) ?
- mStylePosition->UsedAlignSelf(mFrame->StyleContext()->GetParent()) :
- mStylePosition->UsedJustifySelf(mFrame->StyleContext()->GetParent());
+ auto inlineAxisAlignment =
+ wm.IsOrthogonalTo(cbwm)
+ ? mStylePosition->UsedAlignSelf(alignCB->StyleContext())
+ : mStylePosition->UsedJustifySelf(alignCB->StyleContext());
if ((inlineAxisAlignment != NS_STYLE_ALIGN_STRETCH &&
inlineAxisAlignment != NS_STYLE_ALIGN_NORMAL) ||
mStyleMargin->mMargin.GetIStartUnit(wm) == eStyleUnit_Auto ||
mStyleMargin->mMargin.GetIEndUnit(wm) == eStyleUnit_Auto) {
computeSizeFlags =
ComputeSizeFlags(computeSizeFlags | ComputeSizeFlags::eShrinkWrap);
}
} else {
--- a/layout/reftests/css-grid/grid-item-table-stretch-002-ref.html
+++ b/layout/reftests/css-grid/grid-item-table-stretch-002-ref.html
@@ -21,16 +21,17 @@
table {
border: 1px solid;
padding: 0;
margin: 0;
background: lightgrey;
}
caption { border: 1px dashed blue; }
+caption { justify-self: stretch; } /* XXX: Workaround bug 1350037. */
x { display:block; width:16px; height:16px; }
t { display:block; width:6px; height:6px; }
.w20 { width: 20px }
.mxw2 { width: 2px }
.mxw10 { width: 10px }
.mw20 { width: 20px }
.wfill { width:32px }
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -4641,17 +4641,17 @@ nsComputedDOMStyle::DoGetJustifyContent(
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetJustifyItems()
{
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
nsAutoString str;
auto justify =
- StylePosition()->ComputedJustifyItems(mStyleContext->GetParent());
+ StylePosition()->ComputedJustifyItems(mStyleContext->GetParentAllowServo());
nsCSSValue::AppendAlignJustifyValueToString(justify, str);
val->SetString(str);
return val.forget();
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetJustifySelf()
{
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -8664,17 +8664,17 @@ nsRuleNode::ComputePositionData(void* aS
parentPos->mJustifyContent,
NS_STYLE_JUSTIFY_NORMAL);
// justify-items: enum, inherit, initial
const auto& justifyItemsValue = *aRuleData->ValueForJustifyItems();
if (MOZ_UNLIKELY(justifyItemsValue.GetUnit() == eCSSUnit_Inherit)) {
if (MOZ_LIKELY(parentContext)) {
pos->mJustifyItems =
- parentPos->ComputedJustifyItems(parentContext->GetParent());
+ parentPos->ComputedJustifyItems(parentContext->GetParentAllowServo());
} else {
pos->mJustifyItems = NS_STYLE_JUSTIFY_NORMAL;
}
conditions.SetUncacheable();
} else {
SetValue(justifyItemsValue,
pos->mJustifyItems, conditions,
SETVAL_ENUMERATED | SETVAL_UNSET_INITIAL,
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1673,36 +1673,36 @@ nsStylePosition::UsedAlignSelf(nsStyleCo
uint8_t
nsStylePosition::ComputedJustifyItems(nsStyleContext* aParent) const
{
if (mJustifyItems != NS_STYLE_JUSTIFY_AUTO) {
return mJustifyItems;
}
if (MOZ_LIKELY(aParent)) {
- auto inheritedJustifyItems =
- aParent->StylePosition()->ComputedJustifyItems(aParent->GetParent());
+ auto inheritedJustifyItems = aParent->StylePosition()->ComputedJustifyItems(
+ aParent->GetParentAllowServo());
// "If the inherited value of justify-items includes the 'legacy' keyword,
// 'auto' computes to the inherited value." Otherwise, 'normal'.
if (inheritedJustifyItems & NS_STYLE_JUSTIFY_LEGACY) {
return inheritedJustifyItems;
}
}
return NS_STYLE_JUSTIFY_NORMAL;
}
uint8_t
nsStylePosition::UsedJustifySelf(nsStyleContext* aParent) const
{
if (mJustifySelf != NS_STYLE_JUSTIFY_AUTO) {
return mJustifySelf;
}
if (MOZ_LIKELY(aParent)) {
- auto inheritedJustifyItems = aParent->StylePosition()->
- ComputedJustifyItems(aParent->GetParent());
+ auto inheritedJustifyItems = aParent->StylePosition()->ComputedJustifyItems(
+ aParent->GetParentAllowServo());
return inheritedJustifyItems & ~NS_STYLE_JUSTIFY_LEGACY;
}
return NS_STYLE_JUSTIFY_NORMAL;
}
// --------------------
// nsStyleTable
//