mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
Implement serialization of linear-gradient the same ways as in Gecko
This commit is contained in:
parent
9d74ae890b
commit
6ae4bf6ee8
3 changed files with 81 additions and 49 deletions
|
@ -15,6 +15,7 @@ use gecko_bindings::bindings::{Gecko_InitializeImageCropRect, Gecko_SetImageElem
|
|||
use gecko_bindings::structs::{nsCSSUnit, nsStyleCoord_CalcValue, nsStyleImage};
|
||||
use gecko_bindings::structs::{nsresult, SheetType};
|
||||
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
|
||||
use std::f32::consts::PI;
|
||||
use stylesheets::{Origin, RulesMutateError};
|
||||
use values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image};
|
||||
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
|
@ -215,10 +216,35 @@ impl nsStyleImage {
|
|||
|
||||
match direction {
|
||||
LineDirection::Angle(angle) => {
|
||||
// PI radians (180deg) is ignored because it is the default value.
|
||||
if angle.radians() != PI {
|
||||
unsafe {
|
||||
(*gecko_gradient).mAngle.set(angle);
|
||||
}
|
||||
}
|
||||
},
|
||||
LineDirection::Horizontal(x) => {
|
||||
let x = match x {
|
||||
X::Left => 0.0,
|
||||
X::Right => 1.0,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
(*gecko_gradient).mAngle.set(angle);
|
||||
(*gecko_gradient).mBgPosX.set_value(CoordDataValue::None);
|
||||
(*gecko_gradient).mBgPosY.set_value(CoordDataValue::None);
|
||||
(*gecko_gradient).mBgPosX
|
||||
.set_value(CoordDataValue::Percent(x));
|
||||
(*gecko_gradient).mBgPosY
|
||||
.set_value(CoordDataValue::Percent(0.5));
|
||||
}
|
||||
},
|
||||
LineDirection::Vertical(y) => {
|
||||
// Y::Bottom (to bottom) is ignored because it is the default value.
|
||||
if y == Y::Top {
|
||||
unsafe {
|
||||
(*gecko_gradient).mBgPosX
|
||||
.set_value(CoordDataValue::Percent(0.5));
|
||||
(*gecko_gradient).mBgPosY
|
||||
.set_value(CoordDataValue::Percent(0.0));
|
||||
}
|
||||
}
|
||||
},
|
||||
LineDirection::Corner(horiz, vert) => {
|
||||
|
@ -232,7 +258,6 @@ impl nsStyleImage {
|
|||
};
|
||||
|
||||
unsafe {
|
||||
(*gecko_gradient).mAngle.set_value(CoordDataValue::None);
|
||||
(*gecko_gradient).mBgPosX
|
||||
.set_value(CoordDataValue::Percent(percent_x));
|
||||
(*gecko_gradient).mBgPosY
|
||||
|
@ -245,14 +270,9 @@ impl nsStyleImage {
|
|||
if let Some(position) = position {
|
||||
(*gecko_gradient).mBgPosX.set(position.horizontal);
|
||||
(*gecko_gradient).mBgPosY.set(position.vertical);
|
||||
} else {
|
||||
(*gecko_gradient).mBgPosX.set_value(CoordDataValue::None);
|
||||
(*gecko_gradient).mBgPosY.set_value(CoordDataValue::None);
|
||||
}
|
||||
if let Some(angle) = angle {
|
||||
(*gecko_gradient).mAngle.set(angle);
|
||||
} else {
|
||||
(*gecko_gradient).mAngle.set_value(CoordDataValue::None);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -304,12 +324,7 @@ impl nsStyleImage {
|
|||
unsafe {
|
||||
if let Some(angle) = angle {
|
||||
(*gecko_gradient).mAngle.set(angle);
|
||||
} else {
|
||||
(*gecko_gradient).mAngle.set_value(CoordDataValue::None);
|
||||
}
|
||||
|
||||
(*gecko_gradient).mBgPosX.set_value(CoordDataValue::None);
|
||||
(*gecko_gradient).mBgPosY.set_value(CoordDataValue::None);
|
||||
}
|
||||
|
||||
// Setting radius values depending shape
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue