mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Use cbindgen for grid track sizing.
Differential Revision: https://phabricator.services.mozilla.com/D36118
This commit is contained in:
parent
034557a717
commit
cc15afa348
6 changed files with 75 additions and 257 deletions
|
@ -14,14 +14,11 @@ use crate::gecko::values::GeckoStyleCoordConvertible;
|
|||
use crate::gecko_bindings::bindings;
|
||||
use crate::gecko_bindings::structs::{self, nsStyleCoord_CalcValue, Matrix4x4Components};
|
||||
use crate::gecko_bindings::structs::{nsStyleImage, nsresult};
|
||||
use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||
use crate::stylesheets::RulesMutateError;
|
||||
use crate::values::computed::transform::Matrix3D;
|
||||
use crate::values::computed::url::ComputedImageUrl;
|
||||
use crate::values::computed::{Angle, Gradient, Image};
|
||||
use crate::values::computed::{Integer, LengthPercentage};
|
||||
use crate::values::computed::{Gradient, Image, LengthPercentage};
|
||||
use crate::values::computed::{Length, Percentage, TextAlign};
|
||||
use crate::values::generics::grid::{TrackListValue, TrackSize};
|
||||
use crate::values::generics::image::GenericImage;
|
||||
use crate::values::generics::rect::Rect;
|
||||
use crate::Zero;
|
||||
|
@ -56,11 +53,6 @@ impl From<nsStyleCoord_CalcValue> for LengthPercentage {
|
|||
)
|
||||
}
|
||||
}
|
||||
impl From<Angle> for CoordDataValue {
|
||||
fn from(reference: Angle) -> Self {
|
||||
CoordDataValue::Degree(reference.degrees())
|
||||
}
|
||||
}
|
||||
|
||||
impl nsStyleImage {
|
||||
/// Set a given Servo `Image` value into this `nsStyleImage`.
|
||||
|
@ -331,73 +323,6 @@ impl From<RulesMutateError> for nsresult {
|
|||
}
|
||||
}
|
||||
|
||||
impl TrackSize<LengthPercentage> {
|
||||
/// Return TrackSize from given two nsStyleCoord
|
||||
pub fn from_gecko_style_coords<T: CoordData>(gecko_min: &T, gecko_max: &T) -> Self {
|
||||
use crate::gecko_bindings::structs::root::nsStyleUnit;
|
||||
use crate::values::generics::grid::TrackBreadth;
|
||||
|
||||
if gecko_min.unit() == nsStyleUnit::eStyleUnit_None {
|
||||
debug_assert!(
|
||||
gecko_max.unit() == nsStyleUnit::eStyleUnit_Coord ||
|
||||
gecko_max.unit() == nsStyleUnit::eStyleUnit_Percent ||
|
||||
gecko_max.unit() == nsStyleUnit::eStyleUnit_Calc
|
||||
);
|
||||
return TrackSize::FitContent(
|
||||
LengthPercentage::from_gecko_style_coord(gecko_max)
|
||||
.expect("gecko_max could not convert to LengthPercentage"),
|
||||
);
|
||||
}
|
||||
|
||||
let min = TrackBreadth::from_gecko_style_coord(gecko_min)
|
||||
.expect("gecko_min could not convert to TrackBreadth");
|
||||
let max = TrackBreadth::from_gecko_style_coord(gecko_max)
|
||||
.expect("gecko_max could not convert to TrackBreadth");
|
||||
if min == max {
|
||||
TrackSize::Breadth(max)
|
||||
} else {
|
||||
TrackSize::Minmax(min, max)
|
||||
}
|
||||
}
|
||||
|
||||
/// Save TrackSize to given gecko fields.
|
||||
pub fn to_gecko_style_coords<T: CoordDataMut>(&self, gecko_min: &mut T, gecko_max: &mut T) {
|
||||
match *self {
|
||||
TrackSize::FitContent(ref lop) => {
|
||||
// Gecko sets min value to None and max value to the actual value in fit-content
|
||||
// https://searchfox.org/mozilla-central/rev/c05d9d61188d32b8/layout/style/nsRuleNode.cpp#7910
|
||||
gecko_min.set_value(CoordDataValue::None);
|
||||
lop.to_gecko_style_coord(gecko_max);
|
||||
},
|
||||
TrackSize::Breadth(ref breadth) => {
|
||||
// Set the value to both fields if there's one breadth value
|
||||
// https://searchfox.org/mozilla-central/rev/c05d9d61188d32b8/layout/style/nsRuleNode.cpp#7919
|
||||
breadth.to_gecko_style_coord(gecko_min);
|
||||
breadth.to_gecko_style_coord(gecko_max);
|
||||
},
|
||||
TrackSize::Minmax(ref min, ref max) => {
|
||||
min.to_gecko_style_coord(gecko_min);
|
||||
max.to_gecko_style_coord(gecko_max);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TrackListValue<LengthPercentage, Integer> {
|
||||
/// Return TrackSize from given two nsStyleCoord
|
||||
pub fn from_gecko_style_coords<T: CoordData>(gecko_min: &T, gecko_max: &T) -> Self {
|
||||
TrackListValue::TrackSize(TrackSize::from_gecko_style_coords(gecko_min, gecko_max))
|
||||
}
|
||||
|
||||
/// Save TrackSize to given gecko fields.
|
||||
pub fn to_gecko_style_coords<T: CoordDataMut>(&self, gecko_min: &mut T, gecko_max: &mut T) {
|
||||
match *self {
|
||||
TrackListValue::TrackSize(ref size) => size.to_gecko_style_coords(gecko_min, gecko_max),
|
||||
_ => unreachable!("Should only transform from track-size computed values"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Rect<T>
|
||||
where
|
||||
T: GeckoStyleCoordConvertible,
|
||||
|
|
|
@ -7,12 +7,10 @@
|
|||
//! Different kind of helpers to interact with Gecko values.
|
||||
|
||||
use crate::counter_style::{Symbol, Symbols};
|
||||
use crate::gecko_bindings::structs::StyleGridTrackBreadth;
|
||||
use crate::gecko_bindings::structs::{nsStyleCoord, CounterStylePtr};
|
||||
use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||
use crate::values::computed::{Angle, Length, LengthPercentage};
|
||||
use crate::values::computed::{Length, LengthPercentage};
|
||||
use crate::values::computed::{Number, NumberOrPercentage, Percentage};
|
||||
use crate::values::generics::grid::{TrackBreadth, TrackKeyword};
|
||||
use crate::values::generics::length::LengthPercentageOrAuto;
|
||||
use crate::values::generics::{CounterStyleOrNone, NonNegative};
|
||||
use crate::values::Either;
|
||||
|
@ -154,41 +152,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<L: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for TrackBreadth<L> {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
TrackBreadth::Breadth(ref lp) => lp.to_gecko_style_coord(coord),
|
||||
TrackBreadth::Fr(fr) => coord.set_value(CoordDataValue::FlexFraction(fr)),
|
||||
TrackBreadth::Keyword(TrackKeyword::Auto) => coord.set_value(CoordDataValue::Auto),
|
||||
TrackBreadth::Keyword(TrackKeyword::MinContent) => coord.set_value(
|
||||
CoordDataValue::Enumerated(StyleGridTrackBreadth::MinContent as u32),
|
||||
),
|
||||
TrackBreadth::Keyword(TrackKeyword::MaxContent) => coord.set_value(
|
||||
CoordDataValue::Enumerated(StyleGridTrackBreadth::MaxContent as u32),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
L::from_gecko_style_coord(coord)
|
||||
.map(TrackBreadth::Breadth)
|
||||
.or_else(|| match coord.as_value() {
|
||||
CoordDataValue::Enumerated(v) => {
|
||||
if v == StyleGridTrackBreadth::MinContent as u32 {
|
||||
Some(TrackBreadth::Keyword(TrackKeyword::MinContent))
|
||||
} else if v == StyleGridTrackBreadth::MaxContent as u32 {
|
||||
Some(TrackBreadth::Keyword(TrackKeyword::MaxContent))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
CoordDataValue::FlexFraction(fr) => Some(TrackBreadth::Fr(fr)),
|
||||
CoordDataValue::Auto => Some(TrackBreadth::Keyword(TrackKeyword::Auto)),
|
||||
_ => L::from_gecko_style_coord(coord).map(TrackBreadth::Breadth),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for Option<T> {
|
||||
fn to_gecko_style_coord<U: CoordDataMut>(&self, coord: &mut U) {
|
||||
if let Some(ref me) = *self {
|
||||
|
@ -203,19 +166,6 @@ impl<T: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for Option<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for Angle {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::from(*self));
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Degree(val) => Some(Angle::from_degrees(val)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a given RGBA value to `nscolor`.
|
||||
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
|
||||
((rgba.alpha as u32) << 24) |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue