mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +01:00
style: Use rust types for gradient stops.
This doesn't clean up all that much, yet, but it's a step in the right direction. Differential Revision: https://phabricator.services.mozilla.com/D29168
This commit is contained in:
parent
e40500622e
commit
8123007717
4 changed files with 52 additions and 63 deletions
|
@ -24,7 +24,7 @@ use crate::values::computed::{Integer, LengthPercentage};
|
|||
use crate::values::computed::{Length, Percentage, TextAlign};
|
||||
use crate::values::generics::box_::VerticalAlign;
|
||||
use crate::values::generics::grid::{TrackListValue, TrackSize};
|
||||
use crate::values::generics::image::{CompatMode, GradientItem, Image as GenericImage};
|
||||
use crate::values::generics::image::{CompatMode, Image as GenericImage};
|
||||
use crate::values::generics::rect::Rect;
|
||||
use crate::Zero;
|
||||
use app_units::Au;
|
||||
|
@ -154,7 +154,6 @@ impl nsStyleImage {
|
|||
|
||||
// FIXME(emilio): This is really complex, we should use cbindgen for this.
|
||||
fn set_gradient(&mut self, gradient: Gradient) {
|
||||
use self::structs::nsStyleCoord;
|
||||
use self::structs::NS_STYLE_GRADIENT_SIZE_CLOSEST_CORNER as CLOSEST_CORNER;
|
||||
use self::structs::NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE as CLOSEST_SIDE;
|
||||
use self::structs::NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER as FARTHEST_CORNER;
|
||||
|
@ -329,26 +328,9 @@ impl nsStyleImage {
|
|||
},
|
||||
};
|
||||
|
||||
for (index, item) in gradient.items.iter().enumerate() {
|
||||
// NB: stops are guaranteed to be none in the gecko side by
|
||||
// default.
|
||||
|
||||
for (index, item) in gradient.items.into_iter().enumerate() {
|
||||
let gecko_stop = unsafe { &mut (*gecko_gradient).mStops[index] };
|
||||
let mut coord = nsStyleCoord::null();
|
||||
|
||||
match *item {
|
||||
GradientItem::ColorStop(ref stop) => {
|
||||
gecko_stop.mColor = stop.color.into();
|
||||
gecko_stop.mIsInterpolationHint = false;
|
||||
coord.set(stop.position);
|
||||
},
|
||||
GradientItem::InterpolationHint(hint) => {
|
||||
gecko_stop.mIsInterpolationHint = true;
|
||||
coord.set(Some(hint));
|
||||
},
|
||||
}
|
||||
|
||||
gecko_stop.mLocation.move_from(coord);
|
||||
*gecko_stop = item;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
|
@ -419,7 +401,7 @@ impl nsStyleImage {
|
|||
use self::structs::NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER as FARTHEST_CORNER;
|
||||
use self::structs::NS_STYLE_GRADIENT_SIZE_FARTHEST_SIDE as FARTHEST_SIDE;
|
||||
use crate::values::computed::position::Position;
|
||||
use crate::values::generics::image::{Circle, ColorStop, Ellipse};
|
||||
use crate::values::generics::image::{Circle, Ellipse};
|
||||
use crate::values::generics::image::{EndingShape, GradientKind, ShapeExtent};
|
||||
|
||||
let gecko_gradient = bindings::Gecko_GetGradientImageValue(self)
|
||||
|
@ -531,24 +513,7 @@ impl nsStyleImage {
|
|||
},
|
||||
};
|
||||
|
||||
let items = gecko_gradient
|
||||
.mStops
|
||||
.iter()
|
||||
.map(|ref stop| {
|
||||
if stop.mIsInterpolationHint {
|
||||
GradientItem::InterpolationHint(
|
||||
LengthPercentage::from_gecko_style_coord(&stop.mLocation)
|
||||
.expect("mLocation could not convert to LengthPercentage"),
|
||||
)
|
||||
} else {
|
||||
GradientItem::ColorStop(ColorStop {
|
||||
color: stop.mColor.into(),
|
||||
position: LengthPercentage::from_gecko_style_coord(&stop.mLocation),
|
||||
})
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let items = gecko_gradient.mStops.iter().cloned().collect();
|
||||
let compat_mode = if gecko_gradient.mMozLegacySyntax {
|
||||
CompatMode::Moz
|
||||
} else if gecko_gradient.mLegacySyntax {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue