mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Remove nsStyleCoord.
And move the useful bits of it somewhere else (ServoStyleConstInlines.h for the inline function definitions, and nsFrame.cpp for the static assertions). Differential Revision: https://phabricator.services.mozilla.com/D36120
This commit is contained in:
parent
8d127014c3
commit
31b166fb1b
4 changed files with 5 additions and 584 deletions
|
@ -7,165 +7,15 @@
|
|||
//! Different kind of helpers to interact with Gecko values.
|
||||
|
||||
use crate::counter_style::{Symbol, Symbols};
|
||||
use crate::gecko_bindings::structs::{nsStyleCoord, CounterStylePtr};
|
||||
use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||
use crate::values::computed::{Length, LengthPercentage};
|
||||
use crate::values::computed::{Number, NumberOrPercentage, Percentage};
|
||||
use crate::values::generics::length::LengthPercentageOrAuto;
|
||||
use crate::values::generics::{CounterStyleOrNone, NonNegative};
|
||||
use crate::gecko_bindings::structs::CounterStylePtr;
|
||||
use crate::values::generics::CounterStyleOrNone;
|
||||
use crate::values::Either;
|
||||
use crate::{Atom, Zero};
|
||||
use crate::Atom;
|
||||
use app_units::Au;
|
||||
use cssparser::RGBA;
|
||||
use nsstring::{nsACString, nsCStr};
|
||||
use std::cmp::max;
|
||||
|
||||
/// A trait that defines an interface to convert from and to `nsStyleCoord`s.
|
||||
///
|
||||
/// TODO(emilio): Almost everything that is in this file should be somehow
|
||||
/// switched to cbindgen.
|
||||
pub trait GeckoStyleCoordConvertible: Sized {
|
||||
/// Convert this to a `nsStyleCoord`.
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T);
|
||||
/// Given a `nsStyleCoord`, try to get a value of this type..
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self>;
|
||||
}
|
||||
|
||||
impl nsStyleCoord {
|
||||
#[inline]
|
||||
/// Set this `nsStyleCoord` value to `val`.
|
||||
pub fn set<T: GeckoStyleCoordConvertible>(&mut self, val: T) {
|
||||
val.to_gecko_style_coord(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner> GeckoStyleCoordConvertible for NonNegative<Inner>
|
||||
where
|
||||
Inner: GeckoStyleCoordConvertible,
|
||||
{
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
self.0.to_gecko_style_coord(coord)
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
Some(NonNegative(Inner::from_gecko_style_coord(coord)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for Number {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::Factor(*self));
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Factor(f) => Some(f),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for Percentage {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::Percent(self.0));
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Percent(p) => Some(Percentage(p)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for NumberOrPercentage {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
NumberOrPercentage::Number(ref n) => n.to_gecko_style_coord(coord),
|
||||
NumberOrPercentage::Percentage(ref p) => p.to_gecko_style_coord(coord),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Factor(f) => Some(NumberOrPercentage::Number(f)),
|
||||
CoordDataValue::Percent(p) => Some(NumberOrPercentage::Percentage(Percentage(p))),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for LengthPercentage {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
if self.was_calc {
|
||||
return coord.set_value(CoordDataValue::Calc((*self).into()));
|
||||
}
|
||||
debug_assert!(!self.has_percentage || self.unclamped_length() == Length::zero());
|
||||
if self.has_percentage {
|
||||
return coord.set_value(CoordDataValue::Percent(self.percentage()));
|
||||
}
|
||||
coord.set_value(CoordDataValue::Coord(self.unclamped_length().to_i32_au()))
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Coord(coord) => Some(LengthPercentage::new(Au(coord).into(), None)),
|
||||
CoordDataValue::Percent(p) => {
|
||||
Some(LengthPercentage::new(Au(0).into(), Some(Percentage(p))))
|
||||
},
|
||||
CoordDataValue::Calc(calc) => Some(calc.into()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for Length {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::Coord(self.to_i32_au()));
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Coord(coord) => Some(Au(coord).into()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<LengthPercentage> GeckoStyleCoordConvertible for LengthPercentageOrAuto<LengthPercentage>
|
||||
where
|
||||
LengthPercentage: GeckoStyleCoordConvertible,
|
||||
{
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
LengthPercentageOrAuto::Auto => coord.set_value(CoordDataValue::Auto),
|
||||
LengthPercentageOrAuto::LengthPercentage(ref lp) => lp.to_gecko_style_coord(coord),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Auto => Some(LengthPercentageOrAuto::Auto),
|
||||
_ => LengthPercentage::from_gecko_style_coord(coord)
|
||||
.map(LengthPercentageOrAuto::LengthPercentage),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for Option<T> {
|
||||
fn to_gecko_style_coord<U: CoordDataMut>(&self, coord: &mut U) {
|
||||
if let Some(ref me) = *self {
|
||||
me.to_gecko_style_coord(coord);
|
||||
} else {
|
||||
coord.set_value(CoordDataValue::None);
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<U: CoordData>(coord: &U) -> Option<Self> {
|
||||
Some(T::from_gecko_style_coord(coord))
|
||||
}
|
||||
}
|
||||
|
||||
/// 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