mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Run rustfmt on selectors, servo_arc, and style.
This was generated with: ./mach cargo fmt --package selectors && ./mach cargo fmt --package servo_arc && ./mach cargo fmt --package style Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
This commit is contained in:
parent
f7ae1a37e3
commit
c99bcdd4b8
181 changed files with 9981 additions and 7933 deletions
|
@ -53,8 +53,10 @@ impl Deref for RefPtr<nsCSSShadowArray> {
|
|||
&[]
|
||||
} else {
|
||||
unsafe {
|
||||
slice::from_raw_parts((*self.mRawPtr).mArray.as_ptr(),
|
||||
(*self.mRawPtr).mLength as usize)
|
||||
slice::from_raw_parts(
|
||||
(*self.mRawPtr).mArray.as_ptr(),
|
||||
(*self.mRawPtr).mLength as usize,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +68,10 @@ impl DerefMut for RefPtr<nsCSSShadowArray> {
|
|||
&mut []
|
||||
} else {
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut((*self.mRawPtr).mArray.as_mut_ptr(),
|
||||
(*self.mRawPtr).mLength as usize)
|
||||
slice::from_raw_parts_mut(
|
||||
(*self.mRawPtr).mArray.as_mut_ptr(),
|
||||
(*self.mRawPtr).mLength as usize,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! Rust helpers for Gecko's `nsCSSShadowItem`.
|
||||
|
||||
use app_units::Au;
|
||||
use gecko::values::{convert_rgba_to_nscolor, convert_nscolor_to_rgba};
|
||||
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
|
||||
use gecko_bindings::structs::nsCSSShadowItem;
|
||||
use values::computed::RGBAColor;
|
||||
use values::computed::effects::{BoxShadow, SimpleShadow};
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs;
|
||||
use gecko_bindings::structs::{nsCSSValue, nsCSSUnit};
|
||||
use gecko_bindings::structs::{nsCSSValue_Array, nsCSSValueList};
|
||||
use gecko_bindings::structs::{nsCSSUnit, nsCSSValue};
|
||||
use gecko_bindings::structs::{nsCSSValueList, nsCSSValue_Array};
|
||||
use gecko_string_cache::Atom;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
|
@ -32,15 +32,17 @@ impl nsCSSValue {
|
|||
/// Returns this nsCSSValue value as an integer, unchecked in release
|
||||
/// builds.
|
||||
pub fn integer_unchecked(&self) -> i32 {
|
||||
debug_assert!(self.mUnit == nsCSSUnit::eCSSUnit_Integer ||
|
||||
self.mUnit == nsCSSUnit::eCSSUnit_Enumerated);
|
||||
debug_assert!(
|
||||
self.mUnit == nsCSSUnit::eCSSUnit_Integer ||
|
||||
self.mUnit == nsCSSUnit::eCSSUnit_Enumerated
|
||||
);
|
||||
unsafe { *self.mValue.mInt.as_ref() }
|
||||
}
|
||||
|
||||
/// Checks if it is an integer and returns it if so
|
||||
pub fn integer(&self) -> Option<i32> {
|
||||
if self.mUnit == nsCSSUnit::eCSSUnit_Integer ||
|
||||
self.mUnit == nsCSSUnit::eCSSUnit_Enumerated {
|
||||
if self.mUnit == nsCSSUnit::eCSSUnit_Integer || self.mUnit == nsCSSUnit::eCSSUnit_Enumerated
|
||||
{
|
||||
Some(unsafe { *self.mValue.mInt.as_ref() })
|
||||
} else {
|
||||
None
|
||||
|
@ -57,8 +59,10 @@ impl nsCSSValue {
|
|||
/// Returns this nsCSSValue as a nsCSSValue::Array, unchecked in release
|
||||
/// builds.
|
||||
pub unsafe fn array_unchecked(&self) -> &nsCSSValue_Array {
|
||||
debug_assert!(nsCSSUnit::eCSSUnit_Array as u32 <= self.mUnit as u32 &&
|
||||
self.mUnit as u32 <= nsCSSUnit::eCSSUnit_Calc_Divided as u32);
|
||||
debug_assert!(
|
||||
nsCSSUnit::eCSSUnit_Array as u32 <= self.mUnit as u32 &&
|
||||
self.mUnit as u32 <= nsCSSUnit::eCSSUnit_Calc_Divided as u32
|
||||
);
|
||||
let array = *self.mValue.mArray.as_ref();
|
||||
debug_assert!(!array.is_null());
|
||||
&*array
|
||||
|
@ -67,15 +71,9 @@ impl nsCSSValue {
|
|||
/// Sets LengthOrPercentage value to this nsCSSValue.
|
||||
pub unsafe fn set_lop(&mut self, lop: LengthOrPercentage) {
|
||||
match lop {
|
||||
LengthOrPercentage::Length(px) => {
|
||||
self.set_px(px.px())
|
||||
}
|
||||
LengthOrPercentage::Percentage(pc) => {
|
||||
self.set_percentage(pc.0)
|
||||
}
|
||||
LengthOrPercentage::Calc(calc) => {
|
||||
bindings::Gecko_CSSValue_SetCalc(self, calc.into())
|
||||
}
|
||||
LengthOrPercentage::Length(px) => self.set_px(px.px()),
|
||||
LengthOrPercentage::Percentage(pc) => self.set_percentage(pc.0),
|
||||
LengthOrPercentage::Calc(calc) => bindings::Gecko_CSSValue_SetCalc(self, calc.into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,9 +93,9 @@ impl nsCSSValue {
|
|||
nsCSSUnit::eCSSUnit_Pixel => {
|
||||
LengthOrPercentage::Length(Length::new(bindings::Gecko_CSSValue_GetNumber(self)))
|
||||
},
|
||||
nsCSSUnit::eCSSUnit_Percent => {
|
||||
LengthOrPercentage::Percentage(Percentage(bindings::Gecko_CSSValue_GetPercentage(self)))
|
||||
},
|
||||
nsCSSUnit::eCSSUnit_Percent => LengthOrPercentage::Percentage(Percentage(
|
||||
bindings::Gecko_CSSValue_GetPercentage(self),
|
||||
)),
|
||||
nsCSSUnit::eCSSUnit_Calc => {
|
||||
LengthOrPercentage::Calc(bindings::Gecko_CSSValue_GetCalc(self).into())
|
||||
},
|
||||
|
@ -108,16 +106,17 @@ impl nsCSSValue {
|
|||
/// Returns Length value.
|
||||
pub unsafe fn get_length(&self) -> Length {
|
||||
match self.mUnit {
|
||||
nsCSSUnit::eCSSUnit_Pixel => {
|
||||
Length::new(bindings::Gecko_CSSValue_GetNumber(self))
|
||||
},
|
||||
nsCSSUnit::eCSSUnit_Pixel => Length::new(bindings::Gecko_CSSValue_GetNumber(self)),
|
||||
_ => panic!("Unexpected unit"),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_valueless_unit(&mut self, unit: nsCSSUnit) {
|
||||
debug_assert_eq!(self.mUnit, nsCSSUnit::eCSSUnit_Null);
|
||||
debug_assert!(unit as u32 <= nsCSSUnit::eCSSUnit_DummyInherit as u32, "Not a valueless unit");
|
||||
debug_assert!(
|
||||
unit as u32 <= nsCSSUnit::eCSSUnit_DummyInherit as u32,
|
||||
"Not a valueless unit"
|
||||
);
|
||||
self.mUnit = unit;
|
||||
}
|
||||
|
||||
|
@ -241,9 +240,14 @@ impl nsCSSValue {
|
|||
/// Set to a list value
|
||||
///
|
||||
/// This is only supported on the main thread.
|
||||
pub fn set_list<I>(&mut self, values: I) where I: ExactSizeIterator<Item=nsCSSValue> {
|
||||
pub fn set_list<I>(&mut self, values: I)
|
||||
where
|
||||
I: ExactSizeIterator<Item = nsCSSValue>,
|
||||
{
|
||||
debug_assert!(values.len() > 0, "Empty list is not supported");
|
||||
unsafe { bindings::Gecko_CSSValue_SetList(self, values.len() as u32); }
|
||||
unsafe {
|
||||
bindings::Gecko_CSSValue_SetList(self, values.len() as u32);
|
||||
}
|
||||
debug_assert_eq!(self.mUnit, nsCSSUnit::eCSSUnit_List);
|
||||
let list: &mut structs::nsCSSValueList = &mut unsafe {
|
||||
self.mValue.mList.as_ref() // &*nsCSSValueList_heap
|
||||
|
@ -258,9 +262,13 @@ impl nsCSSValue {
|
|||
///
|
||||
/// This is only supported on the main thread.
|
||||
pub fn set_pair_list<I>(&mut self, mut values: I)
|
||||
where I: ExactSizeIterator<Item=(nsCSSValue, nsCSSValue)> {
|
||||
where
|
||||
I: ExactSizeIterator<Item = (nsCSSValue, nsCSSValue)>,
|
||||
{
|
||||
debug_assert!(values.len() > 0, "Empty list is not supported");
|
||||
unsafe { bindings::Gecko_CSSValue_SetPairList(self, values.len() as u32); }
|
||||
unsafe {
|
||||
bindings::Gecko_CSSValue_SetPairList(self, values.len() as u32);
|
||||
}
|
||||
debug_assert_eq!(self.mUnit, nsCSSUnit::eCSSUnit_PairList);
|
||||
let mut item_ptr = &mut unsafe {
|
||||
self.mValue.mPairList.as_ref() // &*nsCSSValuePairList_heap
|
||||
|
@ -276,13 +284,21 @@ impl nsCSSValue {
|
|||
}
|
||||
|
||||
/// Set a shared list
|
||||
pub fn set_shared_list<I>(&mut self, values: I) where I: ExactSizeIterator<Item=nsCSSValue> {
|
||||
pub fn set_shared_list<I>(&mut self, values: I)
|
||||
where
|
||||
I: ExactSizeIterator<Item = nsCSSValue>,
|
||||
{
|
||||
debug_assert!(values.len() > 0, "Empty list is not supported");
|
||||
unsafe { bindings::Gecko_CSSValue_InitSharedList(self, values.len() as u32) };
|
||||
debug_assert_eq!(self.mUnit, nsCSSUnit::eCSSUnit_SharedList);
|
||||
let list = unsafe {
|
||||
self.mValue.mSharedList.as_ref()
|
||||
.as_mut().expect("List pointer should be non-null").mHead.as_mut()
|
||||
self.mValue
|
||||
.mSharedList
|
||||
.as_ref()
|
||||
.as_mut()
|
||||
.expect("List pointer should be non-null")
|
||||
.mHead
|
||||
.as_mut()
|
||||
};
|
||||
debug_assert!(list.is_some(), "New created shared list shouldn't be null");
|
||||
for (item, new_value) in list.unwrap().into_iter().zip(values) {
|
||||
|
@ -311,7 +327,7 @@ impl<'a> Iterator for nsCSSValueListIterator<'a> {
|
|||
self.current = unsafe { item.mNext.as_ref() };
|
||||
Some(&item.mValue)
|
||||
},
|
||||
None => None
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +337,9 @@ impl<'a> IntoIterator for &'a nsCSSValueList {
|
|||
type IntoIter = nsCSSValueListIterator<'a>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
nsCSSValueListIterator { current: Some(self) }
|
||||
nsCSSValueListIterator {
|
||||
current: Some(self),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,7 +358,7 @@ impl<'a> Iterator for nsCSSValueListMutIterator<'a> {
|
|||
self.current = item.mNext;
|
||||
Some(&mut item.mValue)
|
||||
},
|
||||
None => None
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -350,8 +368,10 @@ impl<'a> IntoIterator for &'a mut nsCSSValueList {
|
|||
type IntoIter = nsCSSValueListMutIterator<'a>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
nsCSSValueListMutIterator { current: self as *mut nsCSSValueList,
|
||||
phantom: PhantomData }
|
||||
nsCSSValueListMutIterator {
|
||||
current: self as *mut nsCSSValueList,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use gecko_bindings::bindings::Gecko_EnsureStyleAnimationArrayLength;
|
|||
use gecko_bindings::bindings::Gecko_EnsureStyleTransitionArrayLength;
|
||||
use gecko_bindings::structs::{StyleAnimation, StyleTransition};
|
||||
use gecko_bindings::structs::nsStyleAutoArray;
|
||||
use std::iter::{once, Chain, Once, IntoIterator};
|
||||
use std::iter::{once, Chain, IntoIterator, Once};
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::slice::{Iter, IterMut};
|
||||
|
||||
|
@ -55,7 +55,10 @@ impl nsStyleAutoArray<StyleAnimation> {
|
|||
/// Ensures that the array has length at least the given length.
|
||||
pub fn ensure_len(&mut self, len: usize) {
|
||||
unsafe {
|
||||
Gecko_EnsureStyleAnimationArrayLength(self as *mut nsStyleAutoArray<StyleAnimation> as *mut _, len);
|
||||
Gecko_EnsureStyleAnimationArrayLength(
|
||||
self as *mut nsStyleAutoArray<StyleAnimation> as *mut _,
|
||||
len,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +67,10 @@ impl nsStyleAutoArray<StyleTransition> {
|
|||
/// Ensures that the array has length at least the given length.
|
||||
pub fn ensure_len(&mut self, len: usize) {
|
||||
unsafe {
|
||||
Gecko_EnsureStyleTransitionArrayLength(self as *mut nsStyleAutoArray<StyleTransition> as *mut _, len);
|
||||
Gecko_EnsureStyleTransitionArrayLength(
|
||||
self as *mut nsStyleAutoArray<StyleTransition> as *mut _,
|
||||
len,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs::{nsStyleCoord, nsStyleCoord_Calc, nsStyleCoord_CalcValue};
|
||||
use gecko_bindings::structs::{nsStyleCorners, nsStyleUnit, nsStyleUnion, nsStyleSides, nscoord};
|
||||
use gecko_bindings::structs::{nscoord, nsStyleCorners, nsStyleSides, nsStyleUnion, nsStyleUnit};
|
||||
use std::mem;
|
||||
|
||||
impl nsStyleCoord {
|
||||
|
@ -23,15 +23,11 @@ impl nsStyleCoord {
|
|||
unsafe impl CoordData for nsStyleCoord {
|
||||
#[inline]
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
unsafe {
|
||||
*self.get_mUnit()
|
||||
}
|
||||
unsafe { *self.get_mUnit() }
|
||||
}
|
||||
#[inline]
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
unsafe {
|
||||
*self.get_mValue()
|
||||
}
|
||||
unsafe { *self.get_mValue() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,8 +52,7 @@ impl nsStyleCoord_CalcValue {
|
|||
|
||||
impl PartialEq for nsStyleCoord_CalcValue {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.mLength == other.mLength &&
|
||||
self.mPercent == other.mPercent &&
|
||||
self.mLength == other.mLength && self.mPercent == other.mPercent &&
|
||||
self.mHasPercent == other.mHasPercent
|
||||
}
|
||||
}
|
||||
|
@ -101,29 +96,21 @@ pub struct SidesDataMut<'a> {
|
|||
unsafe impl<'a> CoordData for SidesData<'a> {
|
||||
#[inline]
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
unsafe {
|
||||
self.sides.get_mUnits()[self.index]
|
||||
}
|
||||
unsafe { self.sides.get_mUnits()[self.index] }
|
||||
}
|
||||
#[inline]
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
unsafe {
|
||||
self.sides.get_mValues()[self.index]
|
||||
}
|
||||
unsafe { self.sides.get_mValues()[self.index] }
|
||||
}
|
||||
}
|
||||
unsafe impl<'a> CoordData for SidesDataMut<'a> {
|
||||
#[inline]
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
unsafe {
|
||||
self.sides.get_mUnits()[self.index]
|
||||
}
|
||||
unsafe { self.sides.get_mUnits()[self.index] }
|
||||
}
|
||||
#[inline]
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
unsafe {
|
||||
self.sides.get_mValues()[self.index]
|
||||
}
|
||||
unsafe { self.sides.get_mValues()[self.index] }
|
||||
}
|
||||
}
|
||||
unsafe impl<'a> CoordDataMut for SidesDataMut<'a> {
|
||||
|
@ -170,26 +157,18 @@ pub struct CornersDataMut<'a> {
|
|||
|
||||
unsafe impl<'a> CoordData for CornersData<'a> {
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
unsafe {
|
||||
self.corners.get_mUnits()[self.index]
|
||||
}
|
||||
unsafe { self.corners.get_mUnits()[self.index] }
|
||||
}
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
unsafe {
|
||||
self.corners.get_mValues()[self.index]
|
||||
}
|
||||
unsafe { self.corners.get_mValues()[self.index] }
|
||||
}
|
||||
}
|
||||
unsafe impl<'a> CoordData for CornersDataMut<'a> {
|
||||
fn unit(&self) -> nsStyleUnit {
|
||||
unsafe {
|
||||
self.corners.get_mUnits()[self.index]
|
||||
}
|
||||
unsafe { self.corners.get_mUnits()[self.index] }
|
||||
}
|
||||
fn union(&self) -> nsStyleUnion {
|
||||
unsafe {
|
||||
self.corners.get_mValues()[self.index]
|
||||
}
|
||||
unsafe { self.corners.get_mValues()[self.index] }
|
||||
}
|
||||
}
|
||||
unsafe impl<'a> CoordDataMut for CornersDataMut<'a> {
|
||||
|
@ -238,9 +217,8 @@ pub enum CoordDataValue {
|
|||
Calc(nsStyleCoord_CalcValue),
|
||||
}
|
||||
|
||||
|
||||
/// A trait to abstract on top of a mutable `nsStyleCoord`-like object.
|
||||
pub unsafe trait CoordDataMut : CoordData {
|
||||
pub unsafe trait CoordDataMut: CoordData {
|
||||
/// Get mutably the unit and the union.
|
||||
///
|
||||
/// This is unsafe since it's possible to modify the unit without changing
|
||||
|
@ -313,63 +291,63 @@ pub unsafe trait CoordDataMut : CoordData {
|
|||
Null => {
|
||||
*unit = eStyleUnit_Null;
|
||||
*union.mInt.as_mut() = 0;
|
||||
}
|
||||
},
|
||||
Normal => {
|
||||
*unit = eStyleUnit_Normal;
|
||||
*union.mInt.as_mut() = 0;
|
||||
}
|
||||
},
|
||||
Auto => {
|
||||
*unit = eStyleUnit_Auto;
|
||||
*union.mInt.as_mut() = 0;
|
||||
}
|
||||
},
|
||||
None => {
|
||||
*unit = eStyleUnit_None;
|
||||
*union.mInt.as_mut() = 0;
|
||||
}
|
||||
},
|
||||
Percent(f) => {
|
||||
*unit = eStyleUnit_Percent;
|
||||
*union.mFloat.as_mut() = f;
|
||||
}
|
||||
},
|
||||
Factor(f) => {
|
||||
*unit = eStyleUnit_Factor;
|
||||
*union.mFloat.as_mut() = f;
|
||||
}
|
||||
},
|
||||
Degree(f) => {
|
||||
*unit = eStyleUnit_Degree;
|
||||
*union.mFloat.as_mut() = f;
|
||||
}
|
||||
},
|
||||
Grad(f) => {
|
||||
*unit = eStyleUnit_Grad;
|
||||
*union.mFloat.as_mut() = f;
|
||||
}
|
||||
},
|
||||
Radian(f) => {
|
||||
*unit = eStyleUnit_Radian;
|
||||
*union.mFloat.as_mut() = f;
|
||||
}
|
||||
},
|
||||
Turn(f) => {
|
||||
*unit = eStyleUnit_Turn;
|
||||
*union.mFloat.as_mut() = f;
|
||||
}
|
||||
},
|
||||
FlexFraction(f) => {
|
||||
*unit = eStyleUnit_FlexFraction;
|
||||
*union.mFloat.as_mut() = f;
|
||||
}
|
||||
},
|
||||
Coord(coord) => {
|
||||
*unit = eStyleUnit_Coord;
|
||||
*union.mInt.as_mut() = coord;
|
||||
}
|
||||
},
|
||||
Integer(i) => {
|
||||
*unit = eStyleUnit_Integer;
|
||||
*union.mInt.as_mut() = i;
|
||||
}
|
||||
},
|
||||
Enumerated(i) => {
|
||||
*unit = eStyleUnit_Enumerated;
|
||||
*union.mInt.as_mut() = i as i32;
|
||||
}
|
||||
},
|
||||
Calc(calc) => {
|
||||
// Gecko_SetStyleCoordCalcValue changes the unit internally
|
||||
bindings::Gecko_SetStyleCoordCalcValue(unit, union, calc);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -400,7 +378,6 @@ pub unsafe trait CoordData {
|
|||
/// Get the `nsStyleUnion` for this object.
|
||||
fn union(&self) -> nsStyleUnion;
|
||||
|
||||
|
||||
#[inline(always)]
|
||||
/// Get the appropriate value for this object.
|
||||
fn as_value(&self) -> CoordDataValue {
|
||||
|
@ -431,10 +408,12 @@ pub unsafe trait CoordData {
|
|||
/// Pretend inner value is a float; obtain it.
|
||||
unsafe fn get_float(&self) -> f32 {
|
||||
use gecko_bindings::structs::nsStyleUnit::*;
|
||||
debug_assert!(self.unit() == eStyleUnit_Percent || self.unit() == eStyleUnit_Factor
|
||||
|| self.unit() == eStyleUnit_Degree || self.unit() == eStyleUnit_Grad
|
||||
|| self.unit() == eStyleUnit_Radian || self.unit() == eStyleUnit_Turn
|
||||
|| self.unit() == eStyleUnit_FlexFraction);
|
||||
debug_assert!(
|
||||
self.unit() == eStyleUnit_Percent || self.unit() == eStyleUnit_Factor ||
|
||||
self.unit() == eStyleUnit_Degree || self.unit() == eStyleUnit_Grad ||
|
||||
self.unit() == eStyleUnit_Radian || self.unit() == eStyleUnit_Turn ||
|
||||
self.unit() == eStyleUnit_FlexFraction
|
||||
);
|
||||
*self.union().mFloat.as_ref()
|
||||
}
|
||||
|
||||
|
@ -442,8 +421,10 @@ pub unsafe trait CoordData {
|
|||
/// Pretend inner value is an int; obtain it.
|
||||
unsafe fn get_integer(&self) -> i32 {
|
||||
use gecko_bindings::structs::nsStyleUnit::*;
|
||||
debug_assert!(self.unit() == eStyleUnit_Coord || self.unit() == eStyleUnit_Integer
|
||||
|| self.unit() == eStyleUnit_Enumerated);
|
||||
debug_assert!(
|
||||
self.unit() == eStyleUnit_Coord || self.unit() == eStyleUnit_Integer ||
|
||||
self.unit() == eStyleUnit_Enumerated
|
||||
);
|
||||
*self.union().mInt.as_ref()
|
||||
}
|
||||
|
||||
|
@ -455,7 +436,6 @@ pub unsafe trait CoordData {
|
|||
(*self.as_calc())._base
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
/// Pretend the inner value is a calc expression, and obtain it.
|
||||
unsafe fn as_calc(&self) -> &nsStyleCoord_Calc {
|
||||
|
|
|
@ -14,19 +14,13 @@ impl<T> Deref for nsTArray<T> {
|
|||
type Target = [T];
|
||||
|
||||
fn deref<'a>(&'a self) -> &'a [T] {
|
||||
unsafe {
|
||||
slice::from_raw_parts(self.slice_begin(),
|
||||
self.header().mLength as usize)
|
||||
}
|
||||
unsafe { slice::from_raw_parts(self.slice_begin(), self.header().mLength as usize) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DerefMut for nsTArray<T> {
|
||||
fn deref_mut<'a>(&'a mut self) -> &'a mut [T] {
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut(self.slice_begin(),
|
||||
self.header().mLength as usize)
|
||||
}
|
||||
unsafe { slice::from_raw_parts_mut(self.slice_begin(), self.header().mLength as usize) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,8 +50,11 @@ impl<T> nsTArray<T> {
|
|||
pub fn ensure_capacity(&mut self, cap: usize) {
|
||||
if cap >= self.len() {
|
||||
unsafe {
|
||||
bindings::Gecko_EnsureTArrayCapacity(self as *mut nsTArray<T> as *mut _,
|
||||
cap, mem::size_of::<T>())
|
||||
bindings::Gecko_EnsureTArrayCapacity(
|
||||
self as *mut nsTArray<T> as *mut _,
|
||||
cap,
|
||||
mem::size_of::<T>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,17 +63,19 @@ impl<T> nsTArray<T> {
|
|||
#[inline]
|
||||
pub unsafe fn clear(&mut self) {
|
||||
if self.len() != 0 {
|
||||
bindings::Gecko_ClearPODTArray(self as *mut nsTArray<T> as *mut _,
|
||||
mem::size_of::<T>(),
|
||||
mem::align_of::<T>());
|
||||
bindings::Gecko_ClearPODTArray(
|
||||
self as *mut nsTArray<T> as *mut _,
|
||||
mem::size_of::<T>(),
|
||||
mem::align_of::<T>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Clears a POD array. This is safe since copy types are memcopyable.
|
||||
#[inline]
|
||||
pub fn clear_pod(&mut self)
|
||||
where T: Copy
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
unsafe { self.clear() }
|
||||
}
|
||||
|
@ -98,7 +97,10 @@ impl<T> nsTArray<T> {
|
|||
/// Resizes an array containing only POD elements
|
||||
///
|
||||
/// This will not leak since it only works on POD types (and thus doesn't assert)
|
||||
pub unsafe fn set_len_pod(&mut self, len: u32) where T: Copy {
|
||||
pub unsafe fn set_len_pod(&mut self, len: u32)
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
self.ensure_capacity(len as usize);
|
||||
let header = self.header_mut();
|
||||
header.mLength = len;
|
||||
|
|
|
@ -12,31 +12,41 @@ use values::specified::transform::TimingFunction;
|
|||
|
||||
impl nsTimingFunction {
|
||||
fn set_as_step(&mut self, function_type: nsTimingFunction_Type, steps: u32) {
|
||||
debug_assert!(function_type == nsTimingFunction_Type::StepStart ||
|
||||
function_type == nsTimingFunction_Type::StepEnd,
|
||||
"function_type should be step-start or step-end");
|
||||
debug_assert!(
|
||||
function_type == nsTimingFunction_Type::StepStart ||
|
||||
function_type == nsTimingFunction_Type::StepEnd,
|
||||
"function_type should be step-start or step-end"
|
||||
);
|
||||
self.mType = function_type;
|
||||
unsafe {
|
||||
self.__bindgen_anon_1.__bindgen_anon_1.as_mut().mStepsOrFrames = steps;
|
||||
self.__bindgen_anon_1
|
||||
.__bindgen_anon_1
|
||||
.as_mut()
|
||||
.mStepsOrFrames = steps;
|
||||
}
|
||||
}
|
||||
|
||||
fn set_as_frames(&mut self, frames: u32) {
|
||||
self.mType = nsTimingFunction_Type::Frames;
|
||||
unsafe {
|
||||
self.__bindgen_anon_1.__bindgen_anon_1.as_mut().mStepsOrFrames = frames;
|
||||
self.__bindgen_anon_1
|
||||
.__bindgen_anon_1
|
||||
.as_mut()
|
||||
.mStepsOrFrames = frames;
|
||||
}
|
||||
}
|
||||
|
||||
fn set_as_bezier(
|
||||
&mut self,
|
||||
function_type: nsTimingFunction_Type,
|
||||
x1: f32, y1: f32, x2: f32, y2: f32,
|
||||
x1: f32,
|
||||
y1: f32,
|
||||
x2: f32,
|
||||
y2: f32,
|
||||
) {
|
||||
self.mType = function_type;
|
||||
unsafe {
|
||||
let ref mut gecko_cubic_bezier =
|
||||
self.__bindgen_anon_1.mFunc.as_mut();
|
||||
let ref mut gecko_cubic_bezier = self.__bindgen_anon_1.mFunc.as_mut();
|
||||
gecko_cubic_bezier.mX1 = x1;
|
||||
gecko_cubic_bezier.mY1 = y1;
|
||||
gecko_cubic_bezier.mX2 = x2;
|
||||
|
@ -71,7 +81,10 @@ impl From<TimingFunction> for nsTimingFunction {
|
|||
GenericTimingFunction::CubicBezier { x1, y1, x2, y2 } => {
|
||||
tf.set_as_bezier(
|
||||
nsTimingFunction_Type::CubicBezier,
|
||||
x1.get(), y1.get(), x2.get(), y2.get(),
|
||||
x1.get(),
|
||||
y1.get(),
|
||||
x2.get(),
|
||||
y2.get(),
|
||||
);
|
||||
},
|
||||
GenericTimingFunction::Keyword(keyword) => {
|
||||
|
@ -86,43 +99,48 @@ impl From<TimingFunction> for nsTimingFunction {
|
|||
impl From<nsTimingFunction> for ComputedTimingFunction {
|
||||
fn from(function: nsTimingFunction) -> ComputedTimingFunction {
|
||||
match function.mType {
|
||||
nsTimingFunction_Type::StepStart => {
|
||||
GenericTimingFunction::Steps(
|
||||
unsafe { function.__bindgen_anon_1.__bindgen_anon_1.as_ref().mStepsOrFrames },
|
||||
StepPosition::Start)
|
||||
},
|
||||
nsTimingFunction_Type::StepEnd => {
|
||||
GenericTimingFunction::Steps(
|
||||
unsafe { function.__bindgen_anon_1.__bindgen_anon_1.as_ref().mStepsOrFrames },
|
||||
StepPosition::End)
|
||||
},
|
||||
nsTimingFunction_Type::Frames => {
|
||||
GenericTimingFunction::Frames(
|
||||
unsafe { function.__bindgen_anon_1.__bindgen_anon_1.as_ref().mStepsOrFrames })
|
||||
}
|
||||
nsTimingFunction_Type::Ease => {
|
||||
GenericTimingFunction::Keyword(TimingKeyword::Ease)
|
||||
},
|
||||
nsTimingFunction_Type::Linear => {
|
||||
GenericTimingFunction::Keyword(TimingKeyword::Linear)
|
||||
},
|
||||
nsTimingFunction_Type::EaseIn => {
|
||||
GenericTimingFunction::Keyword(TimingKeyword::EaseIn)
|
||||
},
|
||||
nsTimingFunction_Type::StepStart => GenericTimingFunction::Steps(
|
||||
unsafe {
|
||||
function
|
||||
.__bindgen_anon_1
|
||||
.__bindgen_anon_1
|
||||
.as_ref()
|
||||
.mStepsOrFrames
|
||||
},
|
||||
StepPosition::Start,
|
||||
),
|
||||
nsTimingFunction_Type::StepEnd => GenericTimingFunction::Steps(
|
||||
unsafe {
|
||||
function
|
||||
.__bindgen_anon_1
|
||||
.__bindgen_anon_1
|
||||
.as_ref()
|
||||
.mStepsOrFrames
|
||||
},
|
||||
StepPosition::End,
|
||||
),
|
||||
nsTimingFunction_Type::Frames => GenericTimingFunction::Frames(unsafe {
|
||||
function
|
||||
.__bindgen_anon_1
|
||||
.__bindgen_anon_1
|
||||
.as_ref()
|
||||
.mStepsOrFrames
|
||||
}),
|
||||
nsTimingFunction_Type::Ease => GenericTimingFunction::Keyword(TimingKeyword::Ease),
|
||||
nsTimingFunction_Type::Linear => GenericTimingFunction::Keyword(TimingKeyword::Linear),
|
||||
nsTimingFunction_Type::EaseIn => GenericTimingFunction::Keyword(TimingKeyword::EaseIn),
|
||||
nsTimingFunction_Type::EaseOut => {
|
||||
GenericTimingFunction::Keyword(TimingKeyword::EaseOut)
|
||||
},
|
||||
nsTimingFunction_Type::EaseInOut => {
|
||||
GenericTimingFunction::Keyword(TimingKeyword::EaseInOut)
|
||||
},
|
||||
nsTimingFunction_Type::CubicBezier => {
|
||||
unsafe {
|
||||
GenericTimingFunction::CubicBezier {
|
||||
x1: function.__bindgen_anon_1.mFunc.as_ref().mX1,
|
||||
y1: function.__bindgen_anon_1.mFunc.as_ref().mY1,
|
||||
x2: function.__bindgen_anon_1.mFunc.as_ref().mX2,
|
||||
y2: function.__bindgen_anon_1.mFunc.as_ref().mY2,
|
||||
}
|
||||
nsTimingFunction_Type::CubicBezier => unsafe {
|
||||
GenericTimingFunction::CubicBezier {
|
||||
x1: function.__bindgen_anon_1.mFunc.as_ref().mX1,
|
||||
y1: function.__bindgen_anon_1.mFunc.as_ref().mY1,
|
||||
x2: function.__bindgen_anon_1.mFunc.as_ref().mX2,
|
||||
y2: function.__bindgen_anon_1.mFunc.as_ref().mY2,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::ops::{Deref, DerefMut};
|
|||
use std::ptr;
|
||||
|
||||
/// Indicates that a given Servo type has a corresponding Gecko FFI type.
|
||||
pub unsafe trait HasFFI : Sized + 'static {
|
||||
pub unsafe trait HasFFI: Sized + 'static {
|
||||
/// The corresponding Gecko type that this rust type represents.
|
||||
///
|
||||
/// See the examples in `components/style/gecko/conversions.rs`.
|
||||
|
@ -20,7 +20,7 @@ pub unsafe trait HasFFI : Sized + 'static {
|
|||
|
||||
/// Indicates that a given Servo type has the same layout as the corresponding
|
||||
/// `HasFFI::FFIType` type.
|
||||
pub unsafe trait HasSimpleFFI : HasFFI {
|
||||
pub unsafe trait HasSimpleFFI: HasFFI {
|
||||
#[inline]
|
||||
/// Given a Servo-side reference, converts it to an FFI-safe reference which
|
||||
/// can be passed to Gecko.
|
||||
|
@ -57,7 +57,7 @@ pub unsafe trait HasSimpleFFI : HasFFI {
|
|||
|
||||
/// Indicates that the given Servo type is passed over FFI
|
||||
/// as a Box
|
||||
pub unsafe trait HasBoxFFI : HasSimpleFFI {
|
||||
pub unsafe trait HasBoxFFI: HasSimpleFFI {
|
||||
#[inline]
|
||||
/// Converts a borrowed Arc to a borrowed FFI reference.
|
||||
///
|
||||
|
@ -73,7 +73,7 @@ pub unsafe trait HasBoxFFI : HasSimpleFFI {
|
|||
/// and Borrowed.
|
||||
///
|
||||
/// In this case, the FFIType is the rough equivalent of ArcInner<Self>.
|
||||
pub unsafe trait HasArcFFI : HasFFI {
|
||||
pub unsafe trait HasArcFFI: HasFFI {
|
||||
// these methods can't be on Borrowed because it leads to an unspecified
|
||||
// impl parameter
|
||||
/// Artificially increments the refcount of a (possibly null) borrowed Arc
|
||||
|
@ -109,9 +109,7 @@ pub unsafe trait HasArcFFI : HasFFI {
|
|||
///
|
||||
/// &GeckoType -> &Arc<ServoType>
|
||||
fn as_arc<'a>(ptr: &'a &Self::FFIType) -> &'a RawOffsetArc<Self> {
|
||||
unsafe {
|
||||
transmute::<&&Self::FFIType, &RawOffsetArc<Self>>(ptr)
|
||||
}
|
||||
unsafe { transmute::<&&Self::FFIType, &RawOffsetArc<Self>>(ptr) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -119,9 +117,7 @@ pub unsafe trait HasArcFFI : HasFFI {
|
|||
///
|
||||
/// &Arc<ServoType> -> &GeckoType
|
||||
fn arc_as_borrowed<'a>(arc: &'a RawOffsetArc<Self>) -> &'a &Self::FFIType {
|
||||
unsafe {
|
||||
transmute::<&RawOffsetArc<Self>, &&Self::FFIType>(arc)
|
||||
}
|
||||
unsafe { transmute::<&RawOffsetArc<Self>, &&Self::FFIType>(arc) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -165,7 +161,8 @@ impl<GeckoType> Strong<GeckoType> {
|
|||
///
|
||||
/// Strong<GeckoType> -> Arc<ServoType>
|
||||
pub fn into_arc<ServoType>(self) -> RawOffsetArc<ServoType>
|
||||
where ServoType: HasArcFFI<FFIType = GeckoType>,
|
||||
where
|
||||
ServoType: HasArcFFI<FFIType = GeckoType>,
|
||||
{
|
||||
self.into_arc_opt().unwrap()
|
||||
}
|
||||
|
@ -177,7 +174,8 @@ impl<GeckoType> Strong<GeckoType> {
|
|||
///
|
||||
/// Strong<GeckoType> -> Arc<ServoType>
|
||||
pub fn into_arc_opt<ServoType>(self) -> Option<RawOffsetArc<ServoType>>
|
||||
where ServoType: HasArcFFI<FFIType = GeckoType>,
|
||||
where
|
||||
ServoType: HasArcFFI<FFIType = GeckoType>,
|
||||
{
|
||||
if self.is_null() {
|
||||
None
|
||||
|
@ -194,7 +192,8 @@ impl<GeckoType> Strong<GeckoType> {
|
|||
///
|
||||
/// Strong<GeckoType> -> Arc<ServoType>
|
||||
pub fn as_arc_opt<ServoType>(&self) -> Option<&RawOffsetArc<ServoType>>
|
||||
where ServoType: HasArcFFI<FFIType = GeckoType>,
|
||||
where
|
||||
ServoType: HasArcFFI<FFIType = GeckoType>,
|
||||
{
|
||||
if self.is_null() {
|
||||
None
|
||||
|
@ -271,7 +270,8 @@ pub struct Owned<GeckoType> {
|
|||
impl<GeckoType> Owned<GeckoType> {
|
||||
/// Gets this `Owned` type as a `Box<ServoType>`.
|
||||
pub fn into_box<ServoType>(self) -> Box<ServoType>
|
||||
where ServoType: HasBoxFFI<FFIType = GeckoType>,
|
||||
where
|
||||
ServoType: HasBoxFFI<FFIType = GeckoType>,
|
||||
{
|
||||
unsafe { transmute(self) }
|
||||
}
|
||||
|
@ -313,7 +313,8 @@ impl<GeckoType> OwnedOrNull<GeckoType> {
|
|||
|
||||
/// Returns an owned pointer if this is non-null, and `None` otherwise.
|
||||
pub fn into_box_opt<ServoType>(self) -> Option<Box<ServoType>>
|
||||
where ServoType: HasBoxFFI<FFIType = GeckoType>,
|
||||
where
|
||||
ServoType: HasBoxFFI<FFIType = GeckoType>,
|
||||
{
|
||||
if self.is_null() {
|
||||
None
|
||||
|
|
|
@ -105,7 +105,9 @@ impl<T: RefCounted> RefPtr<T> {
|
|||
|
||||
/// Addref the inner data, obviously leaky on its own.
|
||||
pub fn addref(&self) {
|
||||
unsafe { (*self.ptr).addref(); }
|
||||
unsafe {
|
||||
(*self.ptr).addref();
|
||||
}
|
||||
}
|
||||
|
||||
/// Release the inner data.
|
||||
|
@ -208,7 +210,9 @@ impl<T: RefCounted> structs::RefPtr<T> {
|
|||
/// `self` must be valid, possibly null.
|
||||
pub fn set_move(&mut self, other: RefPtr<T>) {
|
||||
if !self.mRawPtr.is_null() {
|
||||
unsafe { (*self.mRawPtr).release(); }
|
||||
unsafe {
|
||||
(*self.mRawPtr).release();
|
||||
}
|
||||
}
|
||||
*self = other.forget();
|
||||
}
|
||||
|
@ -217,7 +221,10 @@ impl<T: RefCounted> structs::RefPtr<T> {
|
|||
impl<T> structs::RefPtr<T> {
|
||||
/// Sets the contents to an Arc<T>
|
||||
/// will leak existing contents
|
||||
pub fn set_arc_leaky<U>(&mut self, other: Arc<U>) where U: HasArcFFI<FFIType = T> {
|
||||
pub fn set_arc_leaky<U>(&mut self, other: Arc<U>)
|
||||
where
|
||||
U: HasArcFFI<FFIType = T>,
|
||||
{
|
||||
*self = unsafe { mem::transmute(Arc::into_raw_offset(other)) };
|
||||
}
|
||||
}
|
||||
|
@ -248,7 +255,7 @@ unsafe impl<T: ThreadSafeRefCounted> Send for RefPtr<T> {}
|
|||
unsafe impl<T: ThreadSafeRefCounted> Sync for RefPtr<T> {}
|
||||
|
||||
macro_rules! impl_refcount {
|
||||
($t:ty, $addref:ident, $release:ident) => (
|
||||
($t:ty, $addref:ident, $release:ident) => {
|
||||
unsafe impl RefCounted for $t {
|
||||
fn addref(&self) {
|
||||
unsafe { ::gecko_bindings::bindings::$addref(self as *const _ as *mut _) }
|
||||
|
@ -257,38 +264,51 @@ macro_rules! impl_refcount {
|
|||
::gecko_bindings::bindings::$release(self as *const _ as *mut _)
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
// Companion of NS_DECL_THREADSAFE_FFI_REFCOUNTING.
|
||||
//
|
||||
// Gets you a free RefCounted impl implemented via FFI.
|
||||
macro_rules! impl_threadsafe_refcount {
|
||||
($t:ty, $addref:ident, $release:ident) => (
|
||||
($t:ty, $addref:ident, $release:ident) => {
|
||||
impl_refcount!($t, $addref, $release);
|
||||
unsafe impl ThreadSafeRefCounted for $t {}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
impl_threadsafe_refcount!(::gecko_bindings::structs::RawGeckoURLExtraData,
|
||||
Gecko_AddRefURLExtraDataArbitraryThread,
|
||||
Gecko_ReleaseURLExtraDataArbitraryThread);
|
||||
impl_threadsafe_refcount!(::gecko_bindings::structs::nsStyleQuoteValues,
|
||||
Gecko_AddRefQuoteValuesArbitraryThread,
|
||||
Gecko_ReleaseQuoteValuesArbitraryThread);
|
||||
impl_threadsafe_refcount!(::gecko_bindings::structs::nsCSSValueSharedList,
|
||||
Gecko_AddRefCSSValueSharedListArbitraryThread,
|
||||
Gecko_ReleaseCSSValueSharedListArbitraryThread);
|
||||
impl_threadsafe_refcount!(::gecko_bindings::structs::mozilla::css::URLValue,
|
||||
Gecko_AddRefCSSURLValueArbitraryThread,
|
||||
Gecko_ReleaseCSSURLValueArbitraryThread);
|
||||
impl_threadsafe_refcount!(::gecko_bindings::structs::mozilla::css::GridTemplateAreasValue,
|
||||
Gecko_AddRefGridTemplateAreasValueArbitraryThread,
|
||||
Gecko_ReleaseGridTemplateAreasValueArbitraryThread);
|
||||
impl_threadsafe_refcount!(::gecko_bindings::structs::ImageValue,
|
||||
Gecko_AddRefImageValueArbitraryThread,
|
||||
Gecko_ReleaseImageValueArbitraryThread);
|
||||
impl_threadsafe_refcount!(::gecko_bindings::structs::SharedFontList,
|
||||
Gecko_AddRefSharedFontListArbitraryThread,
|
||||
Gecko_ReleaseSharedFontListArbitraryThread);
|
||||
|
||||
impl_threadsafe_refcount!(
|
||||
::gecko_bindings::structs::RawGeckoURLExtraData,
|
||||
Gecko_AddRefURLExtraDataArbitraryThread,
|
||||
Gecko_ReleaseURLExtraDataArbitraryThread
|
||||
);
|
||||
impl_threadsafe_refcount!(
|
||||
::gecko_bindings::structs::nsStyleQuoteValues,
|
||||
Gecko_AddRefQuoteValuesArbitraryThread,
|
||||
Gecko_ReleaseQuoteValuesArbitraryThread
|
||||
);
|
||||
impl_threadsafe_refcount!(
|
||||
::gecko_bindings::structs::nsCSSValueSharedList,
|
||||
Gecko_AddRefCSSValueSharedListArbitraryThread,
|
||||
Gecko_ReleaseCSSValueSharedListArbitraryThread
|
||||
);
|
||||
impl_threadsafe_refcount!(
|
||||
::gecko_bindings::structs::mozilla::css::URLValue,
|
||||
Gecko_AddRefCSSURLValueArbitraryThread,
|
||||
Gecko_ReleaseCSSURLValueArbitraryThread
|
||||
);
|
||||
impl_threadsafe_refcount!(
|
||||
::gecko_bindings::structs::mozilla::css::GridTemplateAreasValue,
|
||||
Gecko_AddRefGridTemplateAreasValueArbitraryThread,
|
||||
Gecko_ReleaseGridTemplateAreasValueArbitraryThread
|
||||
);
|
||||
impl_threadsafe_refcount!(
|
||||
::gecko_bindings::structs::ImageValue,
|
||||
Gecko_AddRefImageValueArbitraryThread,
|
||||
Gecko_ReleaseImageValueArbitraryThread
|
||||
);
|
||||
impl_threadsafe_refcount!(
|
||||
::gecko_bindings::structs::SharedFontList,
|
||||
Gecko_AddRefSharedFontListArbitraryThread,
|
||||
Gecko_ReleaseSharedFontListArbitraryThread
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue