Skip to content

Commit

Permalink
Backed out 2 changesets (bug 1609737) for causing build bustages on n…
Browse files Browse the repository at this point in the history
…sCSSRenderingGradients after backing out Bug 1609711. CLOSED TREE

Backed out changeset d12980bbc425 (bug 1609737)
Backed out changeset 51f3f1a1efb8 (bug 1609737)
  • Loading branch information
CosminSabou committed Jan 23, 2020
1 parent c104f4b commit 4d6c79b
Show file tree
Hide file tree
Showing 27 changed files with 265 additions and 127 deletions.
5 changes: 2 additions & 3 deletions accessible/base/StyleInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void StyleInfo::TextIndent(nsAString& aValue) {

const auto& textIndent = mComputedStyle->StyleText()->mTextIndent;
if (textIndent.ConvertsToLength()) {
aValue.AppendFloat(textIndent.ToLengthInCSSPixels());
aValue.AppendFloat(textIndent.LengthInCSSPixels());
aValue.AppendLiteral("px");
return;
}
Expand All @@ -46,8 +46,7 @@ void StyleInfo::TextIndent(nsAString& aValue) {
aValue.AppendLiteral("%");
return;
}
// FIXME: This doesn't handle calc in any meaningful way? Probably should just
// use the Servo serialization code...
// FIXME: This doesn't handle calc in any meaningful way?
aValue.AppendLiteral("0px");
}

Expand Down
67 changes: 36 additions & 31 deletions layout/style/ServoStyleConstsInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,43 +563,55 @@ LengthPercentage LengthPercentage::FromPercentage(float aPercentage) {
return l;
}

bool LengthPercentage::HasPercent() const {
return IsPercentage() || IsCalc();
CSSCoord LengthPercentage::LengthInCSSPixels() const {
if (IsLength()) {
return AsLength().ToCSSPixels();
}
if (IsPercentage()) {
return 0;
}
return AsCalc().length.ToCSSPixels();
}

bool LengthPercentage::ConvertsToLength() const { return IsLength(); }
float LengthPercentage::Percentage() const {
if (IsLength()) {
return 0;
}
if (IsPercentage()) {
return AsPercentage()._0;
}
return AsCalc().percentage._0;
}

nscoord LengthPercentage::ToLength() const {
MOZ_ASSERT(ConvertsToLength());
return AsLength().ToAppUnits();
bool LengthPercentage::HasPercent() const {
return IsPercentage() || (IsCalc() && AsCalc().has_percentage);
}

CSSCoord LengthPercentage::ToLengthInCSSPixels() const {
bool LengthPercentage::ConvertsToLength() const { return !HasPercent(); }

nscoord LengthPercentage::ToLength() const {
MOZ_ASSERT(ConvertsToLength());
return AsLength().ToCSSPixels();
return IsLength() ? AsLength().ToAppUnits() : AsCalc().length.ToAppUnits();
}

bool LengthPercentage::ConvertsToPercentage() const {
if (IsPercentage()) {
return true;
}
MOZ_ASSERT(IsLength() || !AsCalc().length.IsZero(),
"Should've been simplified to a percentage");
if (IsCalc()) {
auto& calc = AsCalc();
return calc.has_percentage && calc.length.IsZero();
}
return false;
}

float LengthPercentage::ToPercentage() const {
MOZ_ASSERT(ConvertsToPercentage());
return AsPercentage()._0;
return Percentage();
}

bool LengthPercentage::HasLengthAndPercentage() const {
if (!IsCalc()) {
return false;
}
MOZ_ASSERT(!ConvertsToLength() && !ConvertsToPercentage(),
"Should've been simplified earlier");
return true;
return IsCalc() && !ConvertsToLength() && !ConvertsToPercentage();
}

bool LengthPercentage::IsDefinitelyZero() const {
Expand All @@ -609,28 +621,20 @@ bool LengthPercentage::IsDefinitelyZero() const {
if (IsPercentage()) {
return AsPercentage()._0 == 0.0f;
}
MOZ_ASSERT(!AsCalc().length.IsZero(),
"Should've been simplified to a percentage");
return false;
auto& calc = AsCalc();
return calc.length.IsZero() && calc.percentage._0 == 0.0f;
}

CSSCoord LengthPercentage::ResolveToCSSPixels(CSSCoord aPercentageBasis) const {
if (IsLength()) {
return AsLength().ToCSSPixels();
}
if (IsPercentage()) {
return AsPercentage()._0 * aPercentageBasis;
}
auto& calc = AsCalc();
return calc.length.ToCSSPixels() + calc.percentage._0 * aPercentageBasis;
return LengthInCSSPixels() + Percentage() * aPercentageBasis;
}

template <typename T>
CSSCoord LengthPercentage::ResolveToCSSPixelsWith(T aPercentageGetter) const {
static_assert(std::is_same<decltype(aPercentageGetter()), CSSCoord>::value,
"Should return CSS pixels");
if (ConvertsToLength()) {
return ToLengthInCSSPixels();
return LengthInCSSPixels();
}
return ResolveToCSSPixels(aPercentageGetter());
}
Expand Down Expand Up @@ -664,14 +668,15 @@ nscoord LengthPercentage::Resolve(nscoord aPercentageBasis) const {

template <typename T>
nscoord LengthPercentage::Resolve(T aPercentageGetter) const {
static_assert(std::is_same<decltype(aPercentageGetter()), nscoord>::value,
"Should return app units");
return Resolve(aPercentageGetter, NSToCoordFloorClamped);
}

template <typename T>
nscoord LengthPercentage::Resolve(nscoord aPercentageBasis,
T aPercentageRounder) const {
return Resolve([aPercentageBasis] { return aPercentageBasis; },
aPercentageRounder);
return Resolve([=] { return aPercentageBasis; }, aPercentageRounder);
}

void LengthPercentage::ScaleLengthsBy(float aScale) {
Expand Down
17 changes: 15 additions & 2 deletions layout/style/nsComputedDOMStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2288,8 +2288,21 @@ void nsComputedDOMStyle::SetValueToLengthPercentage(
return aValue->SetPercent(result);
}

nsAutoString result;
Servo_LengthPercentage_ToCss(&aLength, &result);
// TODO(emilio): This intentionally matches the serialization of
// SetValueToCalc, but goes against the spec. Update this when possible.
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
nsAutoString tmp, result;
result.AppendLiteral("calc(");
val->SetAppUnits(CSSPixel::ToAppUnits(aLength.LengthInCSSPixels()));
val->GetCssText(tmp);
result.Append(tmp);
if (aLength.HasPercent()) {
result.AppendLiteral(" + ");
val->SetPercent(aLength.Percentage());
val->GetCssText(tmp);
result.Append(tmp);
}
result.Append(')');
aValue->SetString(result);
}

Expand Down
11 changes: 7 additions & 4 deletions layout/style/nsStyleUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,18 @@ static bool ObjectPositionCoordMightCauseOverflow(
// Any nonzero length in "object-position" can push us to overflow
// (particularly if our concrete object size is exactly the same size as the
// replaced element's content-box).
if (!aCoord.ConvertsToPercentage()) {
return !aCoord.ConvertsToLength() || aCoord.ToLengthInCSSPixels() != 0.0f;
if (aCoord.LengthInCSSPixels() != 0.) {
return true;
}

// Percentages are interpreted as a fraction of the extra space. So,
// percentages in the 0-100% range are safe, but values outside of that
// range could cause overflow.
float percentage = aCoord.ToPercentage();
return percentage < 0.0f || percentage > 1.0f;
if (aCoord.HasPercent() &&
(aCoord.Percentage() < 0.0f || aCoord.Percentage() > 1.0f)) {
return true;
}
return false;
}

/* static */
Expand Down
7 changes: 3 additions & 4 deletions servo/components/style/values/animated/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use super::{Animate, Procedure};
use crate::values::computed::length::LengthPercentage;
use crate::values::computed::Percentage;
use style_traits::values::specified::AllowedNumericType;

/// <https://drafts.csswg.org/css-transitions/#animtype-lpcalc>
impl Animate for LengthPercentage {
Expand All @@ -28,8 +27,8 @@ impl Animate for LengthPercentage {
let percentage =
animate_percentage_half(self.specified_percentage(), other.specified_percentage())?;

// Gets clamped as needed after the animation if needed, so no need to
// specify any particular AllowedNumericType.
Ok(LengthPercentage::new_calc(length, percentage, AllowedNumericType::All))
// Gets clamped as needed after the animation, so no need to specify any
// particular AllowedNumericType.
Ok(LengthPercentage::new_calc(length, percentage))
}
}
9 changes: 4 additions & 5 deletions servo/components/style/values/animated/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,11 +1168,10 @@ impl ComputeSquaredDistance for ComputedTransformOperation {
// However, dropping percentage makes us impossible to compute
// the distance for the percentage-percentage case, but Gecko
// uses the same formula, so it's fine for now.
let basis = Length::new(0.);
let fx = fx.resolve(basis).px();
let fy = fy.resolve(basis).px();
let tx = tx.resolve(basis).px();
let ty = ty.resolve(basis).px();
let fx = fx.length_component().px();
let fy = fy.length_component().px();
let tx = tx.length_component().px();
let ty = ty.length_component().px();

Ok(fx.compute_squared_distance(&tx)? +
fy.compute_squared_distance(&ty)? +
Expand Down
2 changes: 1 addition & 1 deletion servo/components/style/values/computed/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl ToComputedValue for specified::Length {
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
match *self {
specified::Length::NoCalc(l) => l.to_computed_value(context),
specified::Length::Calc(ref calc) => calc.to_computed_value(context).to_length().unwrap(),
specified::Length::Calc(ref calc) => calc.to_computed_value(context).length_component(),
}
}

Expand Down
Loading

0 comments on commit 4d6c79b

Please sign in to comment.