stylo: Add sugar for nsCSSShadowArray

This commit is contained in:
Manish Goregaokar 2016-08-28 11:16:47 +05:30
parent 5aa95979f5
commit a4a95dafd1
6 changed files with 77 additions and 7 deletions

View file

@ -143,7 +143,7 @@ COMPILATION_TARGETS = {
"nsChangeHint", "SheetParsingMode", "nsMainThreadPtrHandle",
"nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList",
"FontFamilyType", "nsIAtom", "nsStyleContext", "StyleClipPath",
"StyleBasicShapeType", "StyleBasicShape"
"StyleBasicShapeType", "StyleBasicShape", "nsCSSShadowArray",
],
"void_types": [
"nsINode", "nsIDocument", "nsIPrincipal", "nsIURI",

View file

@ -157,6 +157,7 @@ impl HeapSizeOf for nsStyleContext { fn heap_size_of_children(&self) -> usize {
use structs::StyleClipPath;
use structs::StyleBasicShapeType;
use structs::StyleBasicShape;
use structs::nsCSSShadowArray;
pub type RawGeckoNode = nsINode;
pub enum Element { }
@ -345,6 +346,11 @@ extern "C" {
max_len: u32);
pub fn Gecko_AddRefCalcArbitraryThread(aPtr: *mut Calc);
pub fn Gecko_ReleaseCalcArbitraryThread(aPtr: *mut Calc);
pub fn Gecko_NewCSSShadowArray(len: u32) -> *mut nsCSSShadowArray;
pub fn Gecko_AddRefCSSShadowArrayArbitraryThread(aPtr:
*mut nsCSSShadowArray);
pub fn Gecko_ReleaseCSSShadowArrayArbitraryThread(aPtr:
*mut nsCSSShadowArray);
pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont);
pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont,
other: *const nsStyleFont);

View file

@ -5917,14 +5917,13 @@ fn bindgen_test_layout_nsCSSShadowItem() {
#[repr(C)]
#[derive(Debug)]
pub struct nsCSSShadowArray {
pub mRefCnt: nsAutoRefCnt,
pub _mOwningThread: nsAutoOwningThread,
pub mRefCnt: ThreadSafeAutoRefCnt,
pub mLength: u32,
pub mArray: [nsCSSShadowItem; 1usize],
}
#[test]
fn bindgen_test_layout_nsCSSShadowArray() {
assert_eq!(::std::mem::size_of::<nsCSSShadowArray>() , 48usize);
assert_eq!(::std::mem::size_of::<nsCSSShadowArray>() , 40usize);
assert_eq!(::std::mem::align_of::<nsCSSShadowArray>() , 8usize);
}
#[repr(C)]

View file

@ -5895,14 +5895,13 @@ fn bindgen_test_layout_nsCSSShadowItem() {
#[repr(C)]
#[derive(Debug)]
pub struct nsCSSShadowArray {
pub mRefCnt: nsAutoRefCnt,
pub _mOwningThread: nsAutoOwningThread,
pub mRefCnt: ThreadSafeAutoRefCnt,
pub mLength: u32,
pub mArray: [nsCSSShadowItem; 1usize],
}
#[test]
fn bindgen_test_layout_nsCSSShadowArray() {
assert_eq!(::std::mem::size_of::<nsCSSShadowArray>() , 48usize);
assert_eq!(::std::mem::size_of::<nsCSSShadowArray>() , 40usize);
assert_eq!(::std::mem::align_of::<nsCSSShadowArray>() , 8usize);
}
#[repr(C)]

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
mod ns_css_shadow_array;
mod ns_style_auto_array;
pub mod ns_style_coord;
mod ns_t_array;

View file

@ -0,0 +1,65 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use bindings::Gecko_AddRefCSSShadowArrayArbitraryThread;
use bindings::Gecko_NewCSSShadowArray;
use bindings::Gecko_ReleaseCSSShadowArrayArbitraryThread;
use std::ops::{Deref, DerefMut};
use std::{ptr, slice};
use structs::{nsCSSShadowArray, nsCSSShadowItem, RefPtr};
impl RefPtr<nsCSSShadowArray> {
pub fn replace_with_new(&mut self, len: u32) {
unsafe {
if !self.mRawPtr.is_null() {
Gecko_ReleaseCSSShadowArrayArbitraryThread(self.mRawPtr);
}
self.mRawPtr = if len == 0 {
ptr::null_mut()
} else {
Gecko_NewCSSShadowArray(len)
}
}
}
pub fn copy_from(&mut self, other: &Self) {
unsafe {
if !self.mRawPtr.is_null() {
Gecko_ReleaseCSSShadowArrayArbitraryThread(self.mRawPtr);
}
if !other.mRawPtr.is_null() {
Gecko_AddRefCSSShadowArrayArbitraryThread(other.mRawPtr);
}
self.mRawPtr = other.mRawPtr;
}
}
}
impl Deref for RefPtr<nsCSSShadowArray> {
type Target = [nsCSSShadowItem];
fn deref(&self) -> &[nsCSSShadowItem] {
if self.mRawPtr.is_null() {
&[]
} else {
unsafe {
slice::from_raw_parts((*self.mRawPtr).mArray.as_ptr(),
(*self.mRawPtr).mLength as usize)
}
}
}
}
impl DerefMut for RefPtr<nsCSSShadowArray> {
fn deref_mut(&mut self) -> &mut [nsCSSShadowItem] {
if self.mRawPtr.is_null() {
&mut []
} else {
unsafe {
slice::from_raw_parts_mut((*self.mRawPtr).mArray.as_mut_ptr(),
(*self.mRawPtr).mLength as usize)
}
}
}
}