Skip to content

Commit cd2dbd7

Browse files
author
bors-servo
authored
Auto merge of servo#15363 - hiikezoe:transform-animatable, r=heycam,Manishearth
Make transform property animatable for stylo <!-- Please describe your changes on the following line: --> This is the servo side fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1332657 Reviewed by @heycam and @Manishearth. Thanks! --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because this is for stylo. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15363) <!-- Reviewable:end -->
2 parents 50dca76 + d588427 commit cd2dbd7

File tree

5 files changed

+950
-840
lines changed

5 files changed

+950
-840
lines changed

components/style/gecko_bindings/bindings.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,35 @@ extern "C" {
738738
extern "C" {
739739
pub fn Gecko_NewCSSValueSharedList(len: u32) -> *mut nsCSSValueSharedList;
740740
}
741+
extern "C" {
742+
pub fn Gecko_CSSValue_GetArrayItem(css_value: nsCSSValueBorrowedMut,
743+
index: i32) -> nsCSSValueBorrowedMut;
744+
}
745+
extern "C" {
746+
pub fn Gecko_CSSValue_GetArrayItemConst(css_value: nsCSSValueBorrowed,
747+
index: i32) -> nsCSSValueBorrowed;
748+
}
749+
extern "C" {
750+
pub fn Gecko_CSSValue_GetAbsoluteLength(css_value: nsCSSValueBorrowed)
751+
-> nscoord;
752+
}
753+
extern "C" {
754+
pub fn Gecko_CSSValue_GetAngle(css_value: nsCSSValueBorrowed) -> f32;
755+
}
756+
extern "C" {
757+
pub fn Gecko_CSSValue_GetKeyword(aCSSValue: nsCSSValueBorrowed)
758+
-> nsCSSKeyword;
759+
}
760+
extern "C" {
761+
pub fn Gecko_CSSValue_GetNumber(css_value: nsCSSValueBorrowed) -> f32;
762+
}
763+
extern "C" {
764+
pub fn Gecko_CSSValue_GetPercentage(css_value: nsCSSValueBorrowed) -> f32;
765+
}
766+
extern "C" {
767+
pub fn Gecko_CSSValue_GetCalc(aCSSValue: nsCSSValueBorrowed)
768+
-> nsStyleCoord_CalcValue;
769+
}
741770
extern "C" {
742771
pub fn Gecko_CSSValue_SetAbsoluteLength(css_value: nsCSSValueBorrowedMut,
743772
len: nscoord);
@@ -766,10 +795,6 @@ extern "C" {
766795
pub fn Gecko_CSSValue_SetFunction(css_value: nsCSSValueBorrowedMut,
767796
len: i32);
768797
}
769-
extern "C" {
770-
pub fn Gecko_CSSValue_GetArrayItem(css_value: nsCSSValueBorrowedMut,
771-
index: i32) -> nsCSSValueBorrowedMut;
772-
}
773798
extern "C" {
774799
pub fn Gecko_CSSValue_Drop(css_value: nsCSSValueBorrowedMut);
775800
}

components/style/gecko_bindings/sugar/ns_css_value.rs

+39
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
//! Little helpers for `nsCSSValue`.
66
7+
use app_units::Au;
78
use gecko_bindings::bindings::Gecko_CSSValue_Drop;
9+
use gecko_bindings::bindings::Gecko_CSSValue_GetAbsoluteLength;
10+
use gecko_bindings::bindings::Gecko_CSSValue_GetCalc;
11+
use gecko_bindings::bindings::Gecko_CSSValue_GetPercentage;
12+
use gecko_bindings::bindings::Gecko_CSSValue_SetAbsoluteLength;
13+
use gecko_bindings::bindings::Gecko_CSSValue_SetCalc;
14+
use gecko_bindings::bindings::Gecko_CSSValue_SetPercentage;
815
use gecko_bindings::structs::{nsCSSValue, nsCSSUnit, nsCSSValue_Array};
916
use std::mem;
1017
use std::ops::Index;
1118
use std::slice;
19+
use values::computed::LengthOrPercentage;
1220

1321
impl nsCSSValue {
1422
/// Create a CSSValue with null unit, useful to be used as a return value.
@@ -42,6 +50,37 @@ impl nsCSSValue {
4250
debug_assert!(!array.is_null());
4351
&*array
4452
}
53+
54+
/// Sets LengthOrPercentage value to this nsCSSValue.
55+
pub unsafe fn set_lop(&mut self, lop: LengthOrPercentage) {
56+
match lop {
57+
LengthOrPercentage::Length(au) => {
58+
Gecko_CSSValue_SetAbsoluteLength(self, au.0)
59+
}
60+
LengthOrPercentage::Percentage(pc) => {
61+
Gecko_CSSValue_SetPercentage(self, pc)
62+
}
63+
LengthOrPercentage::Calc(calc) => {
64+
Gecko_CSSValue_SetCalc(self, calc.into())
65+
}
66+
}
67+
}
68+
69+
/// Returns LengthOrPercentage value.
70+
pub unsafe fn get_lop(&self) -> LengthOrPercentage {
71+
match self.mUnit {
72+
nsCSSUnit::eCSSUnit_Pixel => {
73+
LengthOrPercentage::Length(Au(Gecko_CSSValue_GetAbsoluteLength(self)))
74+
},
75+
nsCSSUnit::eCSSUnit_Percent => {
76+
LengthOrPercentage::Percentage(Gecko_CSSValue_GetPercentage(self))
77+
},
78+
nsCSSUnit::eCSSUnit_Calc => {
79+
LengthOrPercentage::Calc(Gecko_CSSValue_GetCalc(self).into())
80+
},
81+
x => panic!("The unit should not be {:?}", x),
82+
}
83+
}
4584
}
4685

4786
impl Drop for nsCSSValue {

components/style/properties/gecko.mako.rs

+66-16
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ fn static_assert() {
13171317
css_value_setters = {
13181318
"length" : "bindings::Gecko_CSSValue_SetAbsoluteLength(%s, %s.0)",
13191319
"percentage" : "bindings::Gecko_CSSValue_SetPercentage(%s, %s)",
1320-
"lop" : "set_lop(%s, %s)",
1320+
"lop" : "%s.set_lop(%s)",
13211321
"angle" : "bindings::Gecko_CSSValue_SetAngle(%s, %s.0)",
13221322
"number" : "bindings::Gecko_CSSValue_SetNumber(%s, %s)",
13231323
}
@@ -1341,21 +1341,6 @@ fn static_assert() {
13411341
use gecko_bindings::sugar::refptr::RefPtr;
13421342
use properties::longhands::transform::computed_value::ComputedMatrix;
13431343
use properties::longhands::transform::computed_value::ComputedOperation;
1344-
use values::computed::LengthOrPercentage;
1345-
1346-
unsafe fn set_lop(value: &mut structs::nsCSSValue, lop: LengthOrPercentage) {
1347-
match lop {
1348-
LengthOrPercentage::Length(au) => {
1349-
bindings::Gecko_CSSValue_SetAbsoluteLength(value, au.0)
1350-
}
1351-
LengthOrPercentage::Percentage(pc) => {
1352-
bindings::Gecko_CSSValue_SetPercentage(value, pc)
1353-
}
1354-
LengthOrPercentage::Calc(calc) => {
1355-
bindings::Gecko_CSSValue_SetCalc(value, calc.into())
1356-
}
1357-
}
1358-
}
13591344

13601345
let vec = if let Some(v) = other.0 {
13611346
v
@@ -1396,6 +1381,71 @@ fn static_assert() {
13961381
unsafe { self.gecko.mSpecifiedTransform.set(&other.gecko.mSpecifiedTransform); }
13971382
}
13981383

1384+
<%def name="computed_operation_arm(name, keyword, items)">
1385+
<%
1386+
# %s is substituted with the call to GetArrayItem.
1387+
css_value_getters = {
1388+
"length" : "Au(bindings::Gecko_CSSValue_GetAbsoluteLength(%s))",
1389+
"lop" : "%s.get_lop()",
1390+
"angle" : "Angle(bindings::Gecko_CSSValue_GetAngle(%s))",
1391+
"number" : "bindings::Gecko_CSSValue_GetNumber(%s)",
1392+
}
1393+
%>
1394+
eCSSKeyword_${keyword} => {
1395+
ComputedOperation::${name.title()}(
1396+
% if name == "matrix":
1397+
ComputedMatrix {
1398+
% endif
1399+
% for index, item in enumerate(items):
1400+
% if name == "matrix":
1401+
m${index / 4 + 1}${index % 4 + 1}:
1402+
% endif
1403+
${css_value_getters[item] % (
1404+
"bindings::Gecko_CSSValue_GetArrayItemConst(gecko_value, %d)" % (index + 1)
1405+
)},
1406+
% endfor
1407+
% if name == "matrix":
1408+
}
1409+
% endif
1410+
)
1411+
},
1412+
</%def>
1413+
pub fn clone_transform(&self) -> longhands::transform::computed_value::T {
1414+
use app_units::Au;
1415+
use gecko_bindings::structs::nsCSSKeyword::*;
1416+
use properties::longhands::transform::computed_value;
1417+
use properties::longhands::transform::computed_value::ComputedMatrix;
1418+
use properties::longhands::transform::computed_value::ComputedOperation;
1419+
use values::computed::Angle;
1420+
1421+
if self.gecko.mSpecifiedTransform.mRawPtr.is_null() {
1422+
return computed_value::T(None);
1423+
}
1424+
1425+
let mut result = vec![];
1426+
let mut cur = unsafe { (*self.gecko.mSpecifiedTransform.to_safe().get()).mHead };
1427+
while !cur.is_null() {
1428+
let gecko_value = unsafe { &(*cur).mValue };
1429+
let transform_function = unsafe {
1430+
bindings::Gecko_CSSValue_GetKeyword(bindings::Gecko_CSSValue_GetArrayItemConst(gecko_value, 0))
1431+
};
1432+
let servo = unsafe {
1433+
match transform_function {
1434+
${computed_operation_arm("matrix", "matrix3d", ["number"] * 16)}
1435+
${computed_operation_arm("skew", "skew", ["angle"] * 2)}
1436+
${computed_operation_arm("translate", "translate3d", ["lop", "lop", "length"])}
1437+
${computed_operation_arm("scale", "scale3d", ["number"] * 3)}
1438+
${computed_operation_arm("rotate", "rotate3d", ["number"] * 3 + ["angle"])}
1439+
${computed_operation_arm("perspective", "perspective", ["length"])}
1440+
_ => panic!("We shouldn't set any other transform function types"),
1441+
}
1442+
};
1443+
result.push(servo);
1444+
unsafe { cur = (&*cur).mNext };
1445+
}
1446+
computed_value::T(Some(result))
1447+
}
1448+
13991449
pub fn set_animation_name(&mut self, v: longhands::animation_name::computed_value::T) {
14001450
use nsstring::nsCString;
14011451
unsafe { self.gecko.mAnimations.ensure_len(v.0.len()) };

0 commit comments

Comments
 (0)