Implement clone_transform.

The implementation of clone_transform is an adaptation of set_transform.

MozReview-Commit-ID: ESE1ha0x666
This commit is contained in:
Hiroyuki Ikezoe 2017-02-03 13:51:52 +09:00
parent 50dca76ae3
commit 10b6c1bb4f
2 changed files with 105 additions and 16 deletions

View file

@ -4,11 +4,19 @@
//! Little helpers for `nsCSSValue`.
use app_units::Au;
use gecko_bindings::bindings::Gecko_CSSValue_Drop;
use gecko_bindings::bindings::Gecko_CSSValue_GetAbsoluteLength;
use gecko_bindings::bindings::Gecko_CSSValue_GetCalc;
use gecko_bindings::bindings::Gecko_CSSValue_GetPercentage;
use gecko_bindings::bindings::Gecko_CSSValue_SetAbsoluteLength;
use gecko_bindings::bindings::Gecko_CSSValue_SetCalc;
use gecko_bindings::bindings::Gecko_CSSValue_SetPercentage;
use gecko_bindings::structs::{nsCSSValue, nsCSSUnit, nsCSSValue_Array};
use std::mem;
use std::ops::Index;
use std::slice;
use values::computed::LengthOrPercentage;
impl nsCSSValue {
/// Create a CSSValue with null unit, useful to be used as a return value.
@ -42,6 +50,37 @@ impl nsCSSValue {
debug_assert!(!array.is_null());
&*array
}
/// Sets LengthOrPercentage value to this nsCSSValue.
pub unsafe fn set_lop(&mut self, lop: LengthOrPercentage) {
match lop {
LengthOrPercentage::Length(au) => {
Gecko_CSSValue_SetAbsoluteLength(self, au.0)
}
LengthOrPercentage::Percentage(pc) => {
Gecko_CSSValue_SetPercentage(self, pc)
}
LengthOrPercentage::Calc(calc) => {
Gecko_CSSValue_SetCalc(self, calc.into())
}
}
}
/// Returns LengthOrPercentage value.
pub unsafe fn get_lop(&self) -> LengthOrPercentage {
match self.mUnit {
nsCSSUnit::eCSSUnit_Pixel => {
LengthOrPercentage::Length(Au(Gecko_CSSValue_GetAbsoluteLength(self)))
},
nsCSSUnit::eCSSUnit_Percent => {
LengthOrPercentage::Percentage(Gecko_CSSValue_GetPercentage(self))
},
nsCSSUnit::eCSSUnit_Calc => {
LengthOrPercentage::Calc(Gecko_CSSValue_GetCalc(self).into())
},
x => panic!("The unit should not be {:?}", x),
}
}
}
impl Drop for nsCSSValue {