mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Make Position a gecko-only vector longhand
This commit is contained in:
parent
65a8a8dccb
commit
979a2798d5
8 changed files with 123 additions and 26 deletions
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -2225,6 +2225,7 @@ dependencies = [
|
||||||
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"plugins 0.0.1",
|
"plugins 0.0.1",
|
||||||
|
|
|
@ -34,6 +34,7 @@ heapsize_plugin = {version = "0.1.2", optional = true}
|
||||||
lazy_static = "0.2"
|
lazy_static = "0.2"
|
||||||
log = "0.3.5"
|
log = "0.3.5"
|
||||||
matches = "0.1"
|
matches = "0.1"
|
||||||
|
num-integer = "0.1.32"
|
||||||
num-traits = "0.1.32"
|
num-traits = "0.1.32"
|
||||||
ordered-float = "0.2.2"
|
ordered-float = "0.2.2"
|
||||||
quickersort = "2.0.0"
|
quickersort = "2.0.0"
|
||||||
|
|
|
@ -56,6 +56,7 @@ extern crate log;
|
||||||
#[allow(unused_extern_crates)]
|
#[allow(unused_extern_crates)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate matches;
|
extern crate matches;
|
||||||
|
extern crate num_integer;
|
||||||
extern crate num_traits;
|
extern crate num_traits;
|
||||||
extern crate ordered_float;
|
extern crate ordered_float;
|
||||||
extern crate quickersort;
|
extern crate quickersort;
|
||||||
|
|
|
@ -944,7 +944,7 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
for (layer, other) in self.gecko.mImage.mLayers.iter_mut()
|
for (layer, other) in self.gecko.mImage.mLayers.iter_mut()
|
||||||
.zip(other.gecko.mImage.mLayers.iter())
|
.zip(other.gecko.mImage.mLayers.iter())
|
||||||
.take(other.gecko.mImage.${field_name}Count) {
|
.take(other.gecko.mImage.${field_name}Count as usize) {
|
||||||
layer.${field_name} = other.${field_name};
|
layer.${field_name} = other.${field_name};
|
||||||
}
|
}
|
||||||
self.gecko.mImage.${field_name}Count = other.gecko.mImage.${field_name}Count;
|
self.gecko.mImage.${field_name}Count = other.gecko.mImage.${field_name}Count;
|
||||||
|
@ -1033,23 +1033,48 @@ fn static_assert() {
|
||||||
self.gecko.mImage.mPositionYCount = cmp::min(1, other.gecko.mImage.mPositionYCount);
|
self.gecko.mImage.mPositionYCount = cmp::min(1, other.gecko.mImage.mPositionYCount);
|
||||||
self.gecko.mImage.mLayers.mFirstElement.mPosition =
|
self.gecko.mImage.mLayers.mFirstElement.mPosition =
|
||||||
other.gecko.mImage.mLayers.mFirstElement.mPosition;
|
other.gecko.mImage.mLayers.mFirstElement.mPosition;
|
||||||
|
unsafe {
|
||||||
|
Gecko_EnsureImageLayersLength(&mut self.gecko.mImage, other.gecko.mImage.mLayers.len());
|
||||||
|
}
|
||||||
|
for (layer, other) in self.gecko.mImage.mLayers.iter_mut()
|
||||||
|
.zip(other.gecko.mImage.mLayers.iter())
|
||||||
|
.take(other.gecko.mImage.mPositionXCount as usize) {
|
||||||
|
layer.mPosition.mXPosition = other.mPosition.mXPosition;
|
||||||
|
}
|
||||||
|
for (layer, other) in self.gecko.mImage.mLayers.iter_mut()
|
||||||
|
.zip(other.gecko.mImage.mLayers.iter())
|
||||||
|
.take(other.gecko.mImage.mPositionYCount as usize) {
|
||||||
|
layer.mPosition.mYPosition = other.mPosition.mYPosition;
|
||||||
|
}
|
||||||
|
self.gecko.mImage.mPositionXCount = other.gecko.mImage.mPositionXCount;
|
||||||
|
self.gecko.mImage.mPositionYCount = other.gecko.mImage.mPositionYCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone_background_position(&self) -> longhands::background_position::computed_value::T {
|
pub fn clone_background_position(&self) -> longhands::background_position::computed_value::T {
|
||||||
use values::computed::position::Position;
|
use values::computed::position::Position;
|
||||||
let position = &self.gecko.mImage.mLayers.mFirstElement.mPosition;
|
longhands::background_position::computed_value::T(
|
||||||
Position {
|
self.gecko.mImage.mLayers.iter()
|
||||||
horizontal: position.mXPosition.into(),
|
.take(self.gecko.mImage.mPositionXCount as usize)
|
||||||
vertical: position.mYPosition.into(),
|
.take(self.gecko.mImage.mPositionYCount as usize)
|
||||||
}
|
.map(|position| Position {
|
||||||
|
horizontal: position.mPosition.mXPosition.into(),
|
||||||
|
vertical: position.mPosition.mYPosition.into(),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_background_position(&mut self, v: longhands::background_position::computed_value::T) {
|
pub fn set_background_position(&mut self, v: longhands::background_position::computed_value::T) {
|
||||||
let position = &mut self.gecko.mImage.mLayers.mFirstElement.mPosition;
|
unsafe {
|
||||||
position.mXPosition = v.horizontal.into();
|
Gecko_EnsureImageLayersLength(&mut self.gecko.mImage, v.0.len());
|
||||||
position.mYPosition = v.vertical.into();
|
}
|
||||||
self.gecko.mImage.mPositionXCount = 1;
|
|
||||||
self.gecko.mImage.mPositionYCount = 1;
|
self.gecko.mImage.mPositionXCount = v.0.len() as u32;
|
||||||
|
self.gecko.mImage.mPositionYCount = v.0.len() as u32;
|
||||||
|
for (servo, geckolayer) in v.0.into_iter().zip(self.gecko.mImage.mLayers.iter_mut()) {
|
||||||
|
geckolayer.mPosition.mXPosition = servo.horizontal.into();
|
||||||
|
geckolayer.mPosition.mYPosition = servo.vertical.into();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_background_image_from(&mut self, other: &Self) {
|
pub fn copy_background_image_from(&mut self, other: &Self) {
|
||||||
|
|
|
@ -155,6 +155,25 @@ pub trait Interpolate: Sized {
|
||||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()>;
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/css-transitions/#animtype-repeatable-list
|
||||||
|
pub trait RepeatableListInterpolate: Interpolate {}
|
||||||
|
|
||||||
|
impl<T: RepeatableListInterpolate> Interpolate for Vec<T> {
|
||||||
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
|
use num_integer::lcm;
|
||||||
|
let len = lcm(self.len(), other.len());
|
||||||
|
let ret = self.iter().cycle().zip(other.iter().cycle())
|
||||||
|
.take(len)
|
||||||
|
.filter_map(|(ref me, ref you)| {
|
||||||
|
me.interpolate(you, time).ok()
|
||||||
|
}).collect::<Self>();
|
||||||
|
if ret.len() == len {
|
||||||
|
Ok(ret)
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// https://drafts.csswg.org/css-transitions/#animtype-number
|
/// https://drafts.csswg.org/css-transitions/#animtype-number
|
||||||
impl Interpolate for Au {
|
impl Interpolate for Au {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -296,6 +315,14 @@ impl Interpolate for BorderSpacing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Interpolate for BackgroundSize {
|
||||||
|
#[inline]
|
||||||
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
|
self.0.interpolate(&other.0, time).map(BackgroundSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-transitions/#animtype-color
|
/// https://drafts.csswg.org/css-transitions/#animtype-color
|
||||||
impl Interpolate for RGBA {
|
impl Interpolate for RGBA {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -496,18 +523,12 @@ impl Interpolate for Position {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Interpolate for BackgroundSize {
|
impl RepeatableListInterpolate for Position {}
|
||||||
|
|
||||||
|
impl Interpolate for BackgroundPosition {
|
||||||
|
#[inline]
|
||||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
use properties::longhands::background_size::computed_value::ExplicitSize;
|
Ok(BackgroundPosition(try!(self.0.interpolate(&other.0, time))))
|
||||||
match (self, other) {
|
|
||||||
(&BackgroundSize::Explicit(ref me), &BackgroundSize::Explicit(ref other)) => {
|
|
||||||
Ok(BackgroundSize::Explicit(ExplicitSize {
|
|
||||||
width: try!(me.width.interpolate(&other.width, time)),
|
|
||||||
height: try!(me.height.interpolate(&other.height, time)),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
_ => Err(()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,10 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
computed_value::T(None)
|
computed_value::T(None)
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
SpecifiedValue(None)
|
||||||
|
}
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||||
Ok(SpecifiedValue(None))
|
Ok(SpecifiedValue(None))
|
||||||
|
@ -75,7 +79,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
}
|
}
|
||||||
</%helpers:vector_longhand>
|
</%helpers:vector_longhand>
|
||||||
|
|
||||||
<%helpers:longhand name="background-position" animatable="True">
|
<%helpers:vector_longhand name="background-position" gecko_only="True" animatable="True">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::LocalToCss;
|
use values::LocalToCss;
|
||||||
|
@ -84,6 +88,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use values::computed::position::Position;
|
use values::computed::position::Position;
|
||||||
|
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||||
|
|
||||||
pub type T = Position;
|
pub type T = Position;
|
||||||
}
|
}
|
||||||
|
@ -98,12 +103,20 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
vertical: computed::LengthOrPercentage::Percentage(0.0),
|
vertical: computed::LengthOrPercentage::Percentage(0.0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
use values::specified::Percentage;
|
||||||
|
Position {
|
||||||
|
horizontal: specified::LengthOrPercentage::Percentage(Percentage(0.0)),
|
||||||
|
vertical: specified::LengthOrPercentage::Percentage(Percentage(0.0)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<SpecifiedValue, ()> {
|
-> Result<SpecifiedValue, ()> {
|
||||||
Ok(try!(Position::parse(input)))
|
Ok(try!(Position::parse(input)))
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:vector_longhand>
|
||||||
|
|
||||||
${helpers.single_keyword("background-repeat",
|
${helpers.single_keyword("background-repeat",
|
||||||
"repeat repeat-x repeat-y no-repeat",
|
"repeat repeat-x repeat-y no-repeat",
|
||||||
|
@ -129,7 +142,7 @@ ${helpers.single_keyword("background-origin",
|
||||||
gecko_only=True,
|
gecko_only=True,
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
<%helpers:longhand name="background-size" animatable="True">
|
<%helpers:vector_longhand name="background-size" animatable="True">
|
||||||
use cssparser::{ToCss, Token};
|
use cssparser::{ToCss, Token};
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -137,6 +150,7 @@ ${helpers.single_keyword("background-origin",
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use values::computed::LengthOrPercentageOrAuto;
|
use values::computed::LengthOrPercentageOrAuto;
|
||||||
|
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -152,6 +166,23 @@ ${helpers.single_keyword("background-origin",
|
||||||
Cover,
|
Cover,
|
||||||
Contain,
|
Contain,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RepeatableListInterpolate for T {}
|
||||||
|
|
||||||
|
impl Interpolate for T {
|
||||||
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
|
use properties::longhands::background_size::single_value::computed_value::ExplicitSize;
|
||||||
|
match (self, other) {
|
||||||
|
(&T::Explicit(ref me), &T::Explicit(ref other)) => {
|
||||||
|
Ok(T::Explicit(ExplicitSize {
|
||||||
|
width: try!(me.width.interpolate(&other.width, time)),
|
||||||
|
height: try!(me.height.interpolate(&other.height, time)),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
_ => Err(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for computed_value::T {
|
impl ToCss for computed_value::T {
|
||||||
|
@ -245,6 +276,13 @@ ${helpers.single_keyword("background-origin",
|
||||||
height: computed::LengthOrPercentageOrAuto::Auto,
|
height: computed::LengthOrPercentageOrAuto::Auto,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
|
SpecifiedValue::Explicit(SpecifiedExplicitSize {
|
||||||
|
width: specified::LengthOrPercentageOrAuto::Auto,
|
||||||
|
height: specified::LengthOrPercentageOrAuto::Auto,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||||
let width;
|
let width;
|
||||||
|
@ -282,4 +320,4 @@ ${helpers.single_keyword("background-origin",
|
||||||
height: height,
|
height: height,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:vector_longhand>
|
||||||
|
|
1
ports/cef/Cargo.lock
generated
1
ports/cef/Cargo.lock
generated
|
@ -2108,6 +2108,7 @@ dependencies = [
|
||||||
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"plugins 0.0.1",
|
"plugins 0.0.1",
|
||||||
|
|
9
ports/geckolib/Cargo.lock
generated
9
ports/geckolib/Cargo.lock
generated
|
@ -234,6 +234,14 @@ dependencies = [
|
||||||
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.1.35"
|
version = "0.1.35"
|
||||||
|
@ -363,6 +371,7 @@ dependencies = [
|
||||||
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue