mirror of
https://github.com/servo/servo.git
synced 2025-09-09 06:28:22 +01:00
stylo: Implement support for the contents property.
This commit is contained in:
parent
d85a60e366
commit
46afc56c41
3 changed files with 120 additions and 4 deletions
|
@ -314,6 +314,9 @@ extern "C" {
|
|||
capacity: usize, elem_size: usize);
|
||||
pub fn Gecko_ClearPODTArray(array: *mut ::std::os::raw::c_void,
|
||||
elem_size: usize, elem_align: usize);
|
||||
pub fn Gecko_ClearStyleContents(content: *mut nsStyleContent);
|
||||
pub fn Gecko_CopyStyleContentsFrom(content: *mut nsStyleContent,
|
||||
other: *const nsStyleContent);
|
||||
pub fn Gecko_EnsureImageLayersLength(layers: *mut nsStyleImageLayers,
|
||||
len: usize);
|
||||
pub fn Gecko_InitializeImageLayer(layer: *mut Layer,
|
||||
|
|
|
@ -2,7 +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/. */
|
||||
|
||||
use bindings::Gecko_EnsureTArrayCapacity;
|
||||
use bindings;
|
||||
use std::mem;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::os::raw::c_void;
|
||||
|
@ -38,6 +38,7 @@ impl<T> nsTArray<T> {
|
|||
// unsafe, since header may be in shared static or something
|
||||
unsafe fn header_mut<'a>(&'a mut self) -> &'a mut nsTArrayHeader {
|
||||
debug_assert!(!self.mBuffer.is_null());
|
||||
|
||||
mem::transmute(self.mBuffer)
|
||||
}
|
||||
|
||||
|
@ -47,12 +48,37 @@ impl<T> nsTArray<T> {
|
|||
(self.mBuffer as *const nsTArrayHeader).offset(1) as *mut _
|
||||
}
|
||||
|
||||
fn ensure_capacity(&mut self, cap: usize) {
|
||||
unsafe {
|
||||
Gecko_EnsureTArrayCapacity(self as *mut nsTArray<T> as *mut c_void, cap, mem::size_of::<T>())
|
||||
/// Ensures the array has enough capacity at least to hold `cap` elements.
|
||||
///
|
||||
/// NOTE: This doesn't call the constructor on the values!
|
||||
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>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Clears the array storage without calling the destructor on the values.
|
||||
#[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>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Clears a POD array. This is safe since copy types are memcopyable.
|
||||
#[inline]
|
||||
pub fn clear_pod(&mut self)
|
||||
where T: Copy
|
||||
{
|
||||
unsafe { self.clear() }
|
||||
}
|
||||
|
||||
// unsafe because the array may contain uninits
|
||||
// This will not call constructors, either manually
|
||||
// add bindings or run the typed ensurecapacity call
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue