mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Backed out 2 changesets (bug 1609737) for causing build bustages on nsCSSRenderingGradients after backing out Bug 1609711. CLOSED TREE
Backed out changeset d12980bbc425 (bug 1609737) Backed out changeset 51f3f1a1efb8 (bug 1609737)
This commit is contained in:
parent
c562fe95c5
commit
39c82e1497
@ -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;
|
||||
}
|
||||
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
bool LengthPercentage::HasPercent() const {
|
||||
return IsPercentage() || (IsCalc() && AsCalc().has_percentage);
|
||||
}
|
||||
|
||||
bool LengthPercentage::ConvertsToLength() const { return !HasPercent(); }
|
||||
|
||||
nscoord LengthPercentage::ToLength() const {
|
||||
MOZ_ASSERT(ConvertsToLength());
|
||||
return AsLength().ToAppUnits();
|
||||
}
|
||||
|
||||
CSSCoord LengthPercentage::ToLengthInCSSPixels() 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 {
|
||||
@ -609,20 +621,12 @@ 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>
|
||||
@ -630,7 +634,7 @@ 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());
|
||||
}
|
||||
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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 {
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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)? +
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,23 +205,8 @@ impl LengthPercentage {
|
||||
|
||||
/// Constructs a `calc()` value.
|
||||
#[inline]
|
||||
pub fn new_calc(
|
||||
length: Length,
|
||||
percentage: Option<Percentage>,
|
||||
clamping_mode: AllowedNumericType,
|
||||
) -> Self {
|
||||
let percentage = match percentage {
|
||||
Some(p) => p,
|
||||
None => return Self::new_length(Length::new(clamping_mode.clamp(length.px()))),
|
||||
};
|
||||
if length.is_zero() {
|
||||
return Self::new_percent(Percentage(clamping_mode.clamp(percentage.0)))
|
||||
}
|
||||
Self::new_calc_unchecked(Box::new(CalcLengthPercentage {
|
||||
length,
|
||||
percentage,
|
||||
clamping_mode,
|
||||
}))
|
||||
pub fn new_calc(l: Length, percentage: Option<Percentage>) -> Self {
|
||||
CalcLengthPercentage::new(l, percentage).to_length_percentge()
|
||||
}
|
||||
|
||||
/// Private version of new_calc() that constructs a calc() variant without
|
||||
@ -284,10 +269,7 @@ impl LengthPercentage {
|
||||
match self.unpack() {
|
||||
Unpacked::Length(l) => l.px() == 0.0,
|
||||
Unpacked::Percentage(p) => p.0 == 0.0,
|
||||
Unpacked::Calc(ref c) => {
|
||||
debug_assert_ne!(c.length.px(), 0.0, "Should've been simplified to a percentage");
|
||||
false
|
||||
},
|
||||
Unpacked::Calc(ref c) => c.is_definitely_zero(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,6 +316,16 @@ impl LengthPercentage {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the `<length>` component of this `calc()`, clamped.
|
||||
#[inline]
|
||||
pub fn as_percentage(&self) -> Option<Percentage> {
|
||||
match self.unpack() {
|
||||
Unpacked::Length(..) => None,
|
||||
Unpacked::Percentage(p) => Some(p),
|
||||
Unpacked::Calc(ref c) => c.as_percentage(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves the percentage.
|
||||
#[inline]
|
||||
pub fn resolve(&self, basis: Length) -> Length {
|
||||
@ -355,18 +347,8 @@ impl LengthPercentage {
|
||||
pub fn has_percentage(&self) -> bool {
|
||||
match self.unpack() {
|
||||
Unpacked::Length(..) => false,
|
||||
Unpacked::Percentage(..) | Unpacked::Calc(..) => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts to a `<length>` if possible.
|
||||
pub fn to_length(&self) -> Option<Length> {
|
||||
match self.unpack() {
|
||||
Unpacked::Length(l) => Some(l),
|
||||
Unpacked::Percentage(..) | Unpacked::Calc(..) => {
|
||||
debug_assert!(self.has_percentage());
|
||||
return None;
|
||||
}
|
||||
Unpacked::Percentage(..) => true,
|
||||
Unpacked::Calc(ref c) => c.has_percentage,
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,10 +358,7 @@ impl LengthPercentage {
|
||||
match self.unpack() {
|
||||
Unpacked::Length(..) => None,
|
||||
Unpacked::Percentage(p) => Some(p),
|
||||
Unpacked::Calc(ref c) => {
|
||||
debug_assert!(self.has_percentage());
|
||||
Some(c.percentage)
|
||||
}
|
||||
Unpacked::Calc(ref c) => c.specified_percentage(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,7 +396,7 @@ impl LengthPercentage {
|
||||
match self.unpack() {
|
||||
Unpacked::Length(l) => Self::new_length(l.clamp_to_non_negative()),
|
||||
Unpacked::Percentage(p) => Self::new_percent(p.clamp_to_non_negative()),
|
||||
Unpacked::Calc(c) => c.clamp_to_non_negative(),
|
||||
Unpacked::Calc(c) => c.clamp_to_non_negative().to_length_percentge(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -466,7 +445,7 @@ impl ToComputedValue for specified::LengthPercentage {
|
||||
LengthPercentage::new_percent(value)
|
||||
},
|
||||
specified::LengthPercentage::Calc(ref calc) => {
|
||||
(**calc).to_computed_value(context)
|
||||
(**calc).to_computed_value(context).to_length_percentge()
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -480,8 +459,12 @@ impl ToComputedValue for specified::LengthPercentage {
|
||||
specified::LengthPercentage::Percentage(p)
|
||||
}
|
||||
Unpacked::Calc(c) => {
|
||||
// We simplify before constructing the LengthPercentage if
|
||||
// needed, so this is always fine.
|
||||
if let Some(p) = c.as_percentage() {
|
||||
return specified::LengthPercentage::Percentage(p)
|
||||
}
|
||||
if !c.has_percentage {
|
||||
return specified::LengthPercentage::Length(ToComputedValue::from_computed_value(&c.length_component()))
|
||||
}
|
||||
specified::LengthPercentage::Calc(Box::new(specified::CalcLengthPercentage::from_computed_value(c)))
|
||||
}
|
||||
}
|
||||
@ -491,12 +474,13 @@ impl ToComputedValue for specified::LengthPercentage {
|
||||
impl ComputeSquaredDistance for LengthPercentage {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
// A somewhat arbitrary base, it doesn't really make sense to mix
|
||||
// lengths with percentages, but we can't do much better here, and this
|
||||
// ensures that the distance between length-only and percentage-only
|
||||
// lengths makes sense.
|
||||
let basis = Length::new(100.);
|
||||
self.resolve(basis).compute_squared_distance(&other.resolve(basis))
|
||||
// FIXME(nox): This looks incorrect to me, to add a distance between lengths
|
||||
// with a distance between percentages.
|
||||
Ok(self
|
||||
.unclamped_length()
|
||||
.compute_squared_distance(&other.unclamped_length())? +
|
||||
self.percentage()
|
||||
.compute_squared_distance(&other.percentage())?)
|
||||
}
|
||||
}
|
||||
|
||||
@ -538,7 +522,7 @@ impl<'de> Deserialize<'de> for LengthPercentage {
|
||||
}
|
||||
}
|
||||
|
||||
/// The representation of a calc() function with mixed lengths and percentages.
|
||||
/// The representation of a calc() function.
|
||||
#[derive(
|
||||
Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue,
|
||||
)]
|
||||
@ -550,15 +534,70 @@ pub struct CalcLengthPercentage {
|
||||
|
||||
#[animation(constant)]
|
||||
clamping_mode: AllowedNumericType,
|
||||
|
||||
/// Whether we specified a percentage or not.
|
||||
#[animation(constant)]
|
||||
pub has_percentage: bool,
|
||||
}
|
||||
|
||||
impl CalcLengthPercentage {
|
||||
/// Returns a new `LengthPercentage`.
|
||||
#[inline]
|
||||
pub fn new(length: Length, percentage: Option<Percentage>) -> Self {
|
||||
Self::with_clamping_mode(length, percentage, AllowedNumericType::All)
|
||||
}
|
||||
|
||||
/// Converts this to a `LengthPercentage`, simplifying if possible.
|
||||
#[inline]
|
||||
pub fn to_length_percentge(self) -> LengthPercentage {
|
||||
if !self.has_percentage {
|
||||
return LengthPercentage::new_length(self.length_component())
|
||||
}
|
||||
if self.length.is_zero() {
|
||||
return LengthPercentage::new_percent(Percentage(self.clamping_mode.clamp(self.percentage.0)));
|
||||
}
|
||||
LengthPercentage::new_calc_unchecked(Box::new(self))
|
||||
}
|
||||
|
||||
fn specified_percentage(&self) -> Option<Percentage> {
|
||||
if self.has_percentage {
|
||||
Some(self.percentage)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a new `LengthPercentage` with a specific clamping mode.
|
||||
#[inline]
|
||||
fn with_clamping_mode(
|
||||
length: Length,
|
||||
percentage: Option<Percentage>,
|
||||
clamping_mode: AllowedNumericType,
|
||||
) -> Self {
|
||||
Self {
|
||||
clamping_mode,
|
||||
length,
|
||||
percentage: percentage.unwrap_or_default(),
|
||||
has_percentage: percentage.is_some(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the length component of this `calc()`, clamped.
|
||||
#[inline]
|
||||
fn length_component(&self) -> Length {
|
||||
pub fn length_component(&self) -> Length {
|
||||
Length::new(self.clamping_mode.clamp(self.length.px()))
|
||||
}
|
||||
|
||||
/// Returns the percentage component if this could be represented as a
|
||||
/// non-calc percentage.
|
||||
fn as_percentage(&self) -> Option<Percentage> {
|
||||
if !self.has_percentage || self.length.px() != 0. {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(Percentage(self.clamping_mode.clamp(self.percentage.0)))
|
||||
}
|
||||
|
||||
/// Resolves the percentage.
|
||||
#[inline]
|
||||
pub fn resolve(&self, basis: Length) -> Length {
|
||||
@ -566,16 +605,44 @@ impl CalcLengthPercentage {
|
||||
Length::new(self.clamping_mode.clamp(length))
|
||||
}
|
||||
|
||||
/// Resolves the percentage.
|
||||
#[inline]
|
||||
pub fn percentage_relative_to(&self, basis: Length) -> Length {
|
||||
self.resolve(basis)
|
||||
}
|
||||
|
||||
/// Returns the length, without clamping.
|
||||
#[inline]
|
||||
fn unclamped_length(&self) -> Length {
|
||||
pub fn unclamped_length(&self) -> Length {
|
||||
self.length
|
||||
}
|
||||
|
||||
/// Returns true if the computed value is absolute 0 or 0%.
|
||||
#[inline]
|
||||
fn is_definitely_zero(&self) -> bool {
|
||||
self.length.px() == 0.0 && self.percentage.0 == 0.0
|
||||
}
|
||||
|
||||
/// Returns the clamped non-negative values.
|
||||
#[inline]
|
||||
fn clamp_to_non_negative(&self) -> LengthPercentage {
|
||||
LengthPercentage::new_calc(self.length, Some(self.percentage), AllowedNumericType::NonNegative)
|
||||
fn clamp_to_non_negative(&self) -> Self {
|
||||
if self.has_percentage {
|
||||
// If we can eagerly clamp the percentage then just do that.
|
||||
if self.length.is_zero() {
|
||||
return Self::with_clamping_mode(
|
||||
Length::zero(),
|
||||
Some(self.percentage.clamp_to_non_negative()),
|
||||
AllowedNumericType::NonNegative,
|
||||
);
|
||||
}
|
||||
return Self::with_clamping_mode(self.length, Some(self.percentage), AllowedNumericType::NonNegative);
|
||||
}
|
||||
|
||||
Self::with_clamping_mode(
|
||||
self.length.clamp_to_non_negative(),
|
||||
None,
|
||||
AllowedNumericType::NonNegative,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -593,7 +660,9 @@ impl CalcLengthPercentage {
|
||||
// maybe.
|
||||
impl PartialEq for CalcLengthPercentage {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.length == other.length && self.percentage == other.percentage
|
||||
self.length == other.length &&
|
||||
self.percentage == other.percentage &&
|
||||
self.has_percentage == other.has_percentage
|
||||
}
|
||||
}
|
||||
|
||||
@ -604,7 +673,7 @@ impl specified::CalcLengthPercentage {
|
||||
context: &Context,
|
||||
zoom_fn: F,
|
||||
base_size: FontBaseSize,
|
||||
) -> LengthPercentage
|
||||
) -> CalcLengthPercentage
|
||||
where
|
||||
F: Fn(Length) -> Length,
|
||||
{
|
||||
@ -640,7 +709,7 @@ impl specified::CalcLengthPercentage {
|
||||
}
|
||||
}
|
||||
|
||||
LengthPercentage::new_calc(
|
||||
CalcLengthPercentage::with_clamping_mode(
|
||||
Length::new(length.min(f32::MAX).max(f32::MIN)),
|
||||
self.percentage,
|
||||
self.clamping_mode,
|
||||
@ -652,7 +721,7 @@ impl specified::CalcLengthPercentage {
|
||||
&self,
|
||||
context: &Context,
|
||||
base_size: FontBaseSize,
|
||||
) -> LengthPercentage {
|
||||
) -> CalcLengthPercentage {
|
||||
self.to_computed_value_with_zoom(
|
||||
context,
|
||||
|abs| context.maybe_zoom_text(abs.into()),
|
||||
@ -686,7 +755,7 @@ impl specified::CalcLengthPercentage {
|
||||
}
|
||||
|
||||
/// Compute the calc using the current font-size (and without text-zoom).
|
||||
pub fn to_computed_value(&self, context: &Context) -> LengthPercentage {
|
||||
pub fn to_computed_value(&self, context: &Context) -> CalcLengthPercentage {
|
||||
self.to_computed_value_with_zoom(context, |abs| abs, FontBaseSize::CurrentStyle)
|
||||
}
|
||||
|
||||
@ -697,7 +766,7 @@ impl specified::CalcLengthPercentage {
|
||||
specified::CalcLengthPercentage {
|
||||
clamping_mode: computed.clamping_mode,
|
||||
absolute: Some(AbsoluteLength::from_computed_value(&computed.length)),
|
||||
percentage: Some(computed.percentage),
|
||||
percentage: computed.specified_percentage(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ impl ToAbsoluteLength for ComputedLengthPercentage {
|
||||
// distance without any layout info.
|
||||
//
|
||||
// FIXME(emilio): This looks wrong.
|
||||
None => Ok(self.resolve(Zero::zero()).px()),
|
||||
None => Ok(self.length_component().px()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -614,6 +614,12 @@ pub enum FontSize {
|
||||
System(SystemFont),
|
||||
}
|
||||
|
||||
impl From<LengthPercentage> for FontSize {
|
||||
fn from(other: LengthPercentage) -> Self {
|
||||
FontSize::Length(other)
|
||||
}
|
||||
}
|
||||
|
||||
/// Specifies a prioritized list of font family names or generic family names.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, ToCss, ToShmem)]
|
||||
#[cfg_attr(feature = "servo", derive(Hash))]
|
||||
|
@ -23,7 +23,6 @@ use selectors::parser::SelectorParseErrorKind;
|
||||
use servo_arc::Arc;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
|
||||
/// The specified value of a CSS `<position>`
|
||||
pub type Position = GenericPosition<HorizontalPosition, VerticalPosition>;
|
||||
@ -298,7 +297,7 @@ impl<S: Side> ToComputedValue for PositionComponent<S> {
|
||||
let p = Percentage(1. - length.percentage());
|
||||
let l = -length.unclamped_length();
|
||||
// We represent `<end-side> <length>` as `calc(100% - <length>)`.
|
||||
ComputedLengthPercentage::new_calc(l, Some(p), AllowedNumericType::All)
|
||||
ComputedLengthPercentage::new_calc(l, Some(p))
|
||||
},
|
||||
PositionComponent::Side(_, Some(ref length)) |
|
||||
PositionComponent::Length(ref length) => length.to_computed_value(context),
|
||||
|
@ -97,7 +97,7 @@ impl ToComputedValue for LineHeight {
|
||||
let computed_calc =
|
||||
calc.to_computed_value_zoomed(context, FontBaseSize::CurrentStyle);
|
||||
let base = context.style().get_font().clone_font_size().size();
|
||||
computed_calc.resolve(base)
|
||||
computed_calc.percentage_relative_to(base)
|
||||
},
|
||||
};
|
||||
GenericLineHeight::Length(result.into())
|
||||
|
@ -248,7 +248,7 @@ renaming_overrides_prefixing = true
|
||||
"CSSPixelLength" = """
|
||||
inline nscoord ToAppUnits() const;
|
||||
inline bool IsZero() const;
|
||||
CSSCoord ToCSSPixels() const { return _0; }
|
||||
float ToCSSPixels() const { return _0; }
|
||||
inline void ScaleBy(float);
|
||||
"""
|
||||
|
||||
@ -296,10 +296,11 @@ renaming_overrides_prefixing = true
|
||||
static inline Self FromPercentage(float);
|
||||
|
||||
inline void ScaleLengthsBy(float);
|
||||
inline CSSCoord LengthInCSSPixels() const;
|
||||
inline float Percentage() const;
|
||||
inline bool HasPercent() const;
|
||||
inline bool ConvertsToLength() const;
|
||||
inline nscoord ToLength() const;
|
||||
inline CSSCoord ToLengthInCSSPixels() const;
|
||||
inline bool ConvertsToPercentage() const;
|
||||
inline bool HasLengthAndPercentage() const;
|
||||
inline float ToPercentage() const;
|
||||
|
@ -4966,9 +4966,9 @@ pub extern "C" fn Servo_DeclarationBlock_SetLengthValue(
|
||||
use style::properties::PropertyDeclaration;
|
||||
use style::values::generics::length::{LengthPercentageOrAuto, Size};
|
||||
use style::values::generics::NonNegative;
|
||||
use style::values::specified::length::{LengthPercentage, NoCalcLength};
|
||||
use style::values::specified::length::LengthPercentage;
|
||||
use style::values::specified::length::NoCalcLength;
|
||||
use style::values::specified::length::{AbsoluteLength, FontRelativeLength};
|
||||
use style::values::specified::FontSize;
|
||||
|
||||
let long = get_longhand_from_id!(property);
|
||||
let nocalc = match unit {
|
||||
@ -5002,7 +5002,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetLengthValue(
|
||||
R => NonNegative(LengthPercentage::Length(nocalc)),
|
||||
Rx => LengthPercentageOrAuto::LengthPercentage(NonNegative(LengthPercentage::Length(nocalc))),
|
||||
Ry => LengthPercentageOrAuto::LengthPercentage(NonNegative(LengthPercentage::Length(nocalc))),
|
||||
FontSize => FontSize::Length(LengthPercentage::Length(nocalc)),
|
||||
FontSize => LengthPercentage::from(nocalc).into(),
|
||||
MozScriptMinSize => MozScriptMinSize(nocalc),
|
||||
};
|
||||
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
||||
@ -5045,7 +5045,6 @@ pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(
|
||||
use style::values::generics::length::{LengthPercentageOrAuto, Size};
|
||||
use style::values::generics::NonNegative;
|
||||
use style::values::specified::length::LengthPercentage;
|
||||
use style::values::specified::FontSize;
|
||||
|
||||
let long = get_longhand_from_id!(property);
|
||||
let pc = Percentage(value);
|
||||
@ -5066,7 +5065,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(
|
||||
MarginRight => lp_or_auto,
|
||||
MarginBottom => lp_or_auto,
|
||||
MarginLeft => lp_or_auto,
|
||||
FontSize => FontSize::Length(LengthPercentage::Percentage(pc)),
|
||||
FontSize => LengthPercentage::from(pc).into(),
|
||||
};
|
||||
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
||||
decls.push(prop, Importance::Normal);
|
||||
@ -6852,11 +6851,3 @@ pub unsafe extern "C" fn Servo_LoadData_GetLazy(
|
||||
) -> *const url::LoadData {
|
||||
source.get()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_LengthPercentage_ToCss(
|
||||
lp: &computed::LengthPercentage,
|
||||
result: &mut nsAString
|
||||
) {
|
||||
lp.to_css(&mut CssWriter::new(result)).unwrap();
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
[max-block-size-computed.html]
|
||||
[Property max-block-size value 'calc(20% + 10px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[max-inline-size-computed.html]
|
||||
[Property max-inline-size value 'calc(20% + 10px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[min-block-size-computed.html]
|
||||
[Property min-block-size value 'calc(20% + 10px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[min-inline-size-computed.html]
|
||||
[Property min-inline-size value 'calc(20% + 10px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[bottom-computed.html]
|
||||
[Property bottom value 'calc(50% + 60px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[left-computed.html]
|
||||
[Property left value 'calc(50% + 60px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[right-computed.html]
|
||||
[Property right value 'calc(50% + 60px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[top-computed.html]
|
||||
[Property top value 'calc(50% + 60px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[max-height-computed.html]
|
||||
[Property max-height value 'calc(10% + 40px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[max-width-computed.html]
|
||||
[Property max-width value 'calc(10% + 40px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[min-height-computed.html]
|
||||
[Property min-height value 'calc(10% + 40px)']
|
||||
expected: FAIL
|
||||
|
@ -0,0 +1,4 @@
|
||||
[min-width-computed.html]
|
||||
[Property min-width value 'calc(10% + 40px)']
|
||||
expected: FAIL
|
||||
|
@ -1,4 +1,10 @@
|
||||
[sizing-properties-computed.svg]
|
||||
[resolved value is computed value when display is none]
|
||||
expected: FAIL
|
||||
|
||||
[resolved value is computed value when display is contents]
|
||||
expected: FAIL
|
||||
|
||||
[Property width value 'calc(50% + 1.5em)']
|
||||
expected: FAIL
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user