mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Make background-image an array for stylo
This commit is contained in:
parent
3a5a56807a
commit
38b57c435d
2 changed files with 69 additions and 61 deletions
|
@ -10,7 +10,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
"::cssparser::Color::RGBA(::cssparser::RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */",
|
"::cssparser::Color::RGBA(::cssparser::RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */",
|
||||||
animatable=True)}
|
animatable=True)}
|
||||||
|
|
||||||
<%helpers:longhand name="background-image" animatable="False">
|
<%helpers:gecko_autoarray_longhand name="background-image" animatable="False">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::specified::Image;
|
use values::specified::Image;
|
||||||
|
@ -70,7 +70,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:gecko_autoarray_longhand>
|
||||||
|
|
||||||
<%helpers:longhand name="background-position" animatable="True">
|
<%helpers:longhand name="background-position" animatable="True">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
|
|
|
@ -946,7 +946,7 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_background_image(&mut self, image: longhands::background_image::computed_value::T) {
|
fn set_background_image(&mut self, images: longhands::background_image::computed_value::T) {
|
||||||
use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_LINEAR, NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER};
|
use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_LINEAR, NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER};
|
||||||
use gecko_bindings::structs::nsStyleCoord;
|
use gecko_bindings::structs::nsStyleCoord;
|
||||||
use style::values::computed::Image;
|
use style::values::computed::Image;
|
||||||
|
@ -955,76 +955,84 @@ fn static_assert() {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// Prevent leaking of the last element we did set
|
// Prevent leaking of the last element we did set
|
||||||
Gecko_SetNullImageValue(&mut self.gecko.mImage.mLayers.mFirstElement.mImage);
|
for image in &mut self.gecko.mImage.mLayers {
|
||||||
|
Gecko_SetNullImageValue(&mut image.mImage)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.gecko.mImage.mImageCount = cmp::max(1, self.gecko.mImage.mImageCount);
|
self.gecko.mImage.mImageCount = cmp::max(self.gecko.mImage.mLayers.len() as u32,
|
||||||
if let Some(image) = image.0 {
|
self.gecko.mImage.mImageCount);
|
||||||
match image {
|
|
||||||
Image::LinearGradient(ref gradient) => {
|
|
||||||
let stop_count = gradient.stops.len();
|
|
||||||
if stop_count >= ::std::u32::MAX as usize {
|
|
||||||
warn!("stylo: Prevented overflow due to too many gradient stops");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let gecko_gradient = unsafe {
|
// TODO: pre-grow the nsTArray to the right capacity
|
||||||
Gecko_CreateGradient(NS_STYLE_GRADIENT_SHAPE_LINEAR as u8,
|
// otherwise the below code won't work
|
||||||
NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER as u8,
|
for (image, geckoimage) in images.0.into_iter().zip(self.gecko.mImage.mLayers.iter_mut()) {
|
||||||
/* repeating = */ false,
|
if let Some(image) = image.0 {
|
||||||
/* legacy_syntax = */ false,
|
match image {
|
||||||
stop_count as u32)
|
Image::LinearGradient(ref gradient) => {
|
||||||
};
|
let stop_count = gradient.stops.len();
|
||||||
|
if stop_count >= ::std::u32::MAX as usize {
|
||||||
// TODO: figure out what gecko does in the `corner` case.
|
warn!("stylo: Prevented overflow due to too many gradient stops");
|
||||||
if let AngleOrCorner::Angle(angle) = gradient.angle_or_corner {
|
return;
|
||||||
unsafe {
|
|
||||||
(*gecko_gradient).mAngle.set(angle);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let mut coord: nsStyleCoord = unsafe { uninitialized() };
|
let gecko_gradient = unsafe {
|
||||||
for (index, stop) in gradient.stops.iter().enumerate() {
|
Gecko_CreateGradient(NS_STYLE_GRADIENT_SHAPE_LINEAR as u8,
|
||||||
// NB: stops are guaranteed to be none in the gecko side by
|
NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER as u8,
|
||||||
// default.
|
/* repeating = */ false,
|
||||||
coord.set(stop.position);
|
/* legacy_syntax = */ false,
|
||||||
let color = match stop.color {
|
stop_count as u32)
|
||||||
CSSColor::CurrentColor => {
|
|
||||||
// TODO(emilio): gecko just stores an nscolor,
|
|
||||||
// and it doesn't seem to support currentColor
|
|
||||||
// as value in a gradient.
|
|
||||||
//
|
|
||||||
// Double-check it and either remove
|
|
||||||
// currentColor for servo or see how gecko
|
|
||||||
// handles this.
|
|
||||||
0
|
|
||||||
},
|
|
||||||
CSSColor::RGBA(ref rgba) => convert_rgba_to_nscolor(rgba),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut stop = unsafe {
|
// TODO: figure out what gecko does in the `corner` case.
|
||||||
&mut (*gecko_gradient).mStops[index]
|
if let AngleOrCorner::Angle(angle) = gradient.angle_or_corner {
|
||||||
};
|
unsafe {
|
||||||
|
(*gecko_gradient).mAngle.set(angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stop.mColor = color;
|
let mut coord: nsStyleCoord = unsafe { uninitialized() };
|
||||||
stop.mIsInterpolationHint = false;
|
for (index, stop) in gradient.stops.iter().enumerate() {
|
||||||
stop.mLocation.copy_from(&coord);
|
// NB: stops are guaranteed to be none in the gecko side by
|
||||||
}
|
// default.
|
||||||
|
coord.set(stop.position);
|
||||||
|
let color = match stop.color {
|
||||||
|
CSSColor::CurrentColor => {
|
||||||
|
// TODO(emilio): gecko just stores an nscolor,
|
||||||
|
// and it doesn't seem to support currentColor
|
||||||
|
// as value in a gradient.
|
||||||
|
//
|
||||||
|
// Double-check it and either remove
|
||||||
|
// currentColor for servo or see how gecko
|
||||||
|
// handles this.
|
||||||
|
0
|
||||||
|
},
|
||||||
|
CSSColor::RGBA(ref rgba) => convert_rgba_to_nscolor(rgba),
|
||||||
|
};
|
||||||
|
|
||||||
unsafe {
|
let mut stop = unsafe {
|
||||||
Gecko_SetGradientImageValue(&mut self.gecko.mImage.mLayers.mFirstElement.mImage,
|
&mut (*gecko_gradient).mStops[index]
|
||||||
gecko_gradient);
|
};
|
||||||
|
|
||||||
|
stop.mColor = color;
|
||||||
|
stop.mIsInterpolationHint = false;
|
||||||
|
stop.mLocation.copy_from(&coord);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
Gecko_SetGradientImageValue(&mut geckoimage.mImage, gecko_gradient);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Image::Url(_) => {
|
||||||
|
// let utf8_bytes = url.as_bytes();
|
||||||
|
// Gecko_SetUrlImageValue(&mut self.gecko.mImage.mLayers.mFirstElement,
|
||||||
|
// utf8_bytes.as_ptr() as *const _,
|
||||||
|
// utf8_bytes.len());
|
||||||
|
warn!("stylo: imgRequestProxies are not threadsafe in gecko, \
|
||||||
|
background-image: url() not yet implemented");
|
||||||
}
|
}
|
||||||
},
|
|
||||||
Image::Url(_) => {
|
|
||||||
// let utf8_bytes = url.as_bytes();
|
|
||||||
// Gecko_SetUrlImageValue(&mut self.gecko.mImage.mLayers.mFirstElement,
|
|
||||||
// utf8_bytes.as_ptr() as *const _,
|
|
||||||
// utf8_bytes.len());
|
|
||||||
warn!("stylo: imgRequestProxies are not threadsafe in gecko, \
|
|
||||||
background-image: url() not yet implemented");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue