mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add bindings for list and pair list value of nsCSSValue.
This commit is contained in:
parent
0722031726
commit
f733958f2e
2 changed files with 57 additions and 9 deletions
|
@ -221,7 +221,7 @@ impl ToNsCssValue for counter_style::Ranges {
|
|||
if self.0.is_empty() {
|
||||
nscssvalue.set_auto();
|
||||
} else {
|
||||
for range in &self.0 {
|
||||
nscssvalue.set_pair_list(self.0.iter().map(|range| {
|
||||
fn set_bound(bound: Option<i32>, nscssvalue: &mut nsCSSValue) {
|
||||
if let Some(finite) = bound {
|
||||
nscssvalue.set_integer(finite)
|
||||
|
@ -233,8 +233,8 @@ impl ToNsCssValue for counter_style::Ranges {
|
|||
let mut end = nsCSSValue::null();
|
||||
set_bound(range.start, &mut start);
|
||||
set_bound(range.end, &mut end);
|
||||
// FIXME: add bindings for nsCSSValuePairList
|
||||
}
|
||||
(start, end)
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,16 +256,24 @@ impl ToNsCssValue for counter_style::Fallback {
|
|||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::Symbols {
|
||||
fn convert(&self, _nscssvalue: &mut nsCSSValue) {
|
||||
debug_assert!(!self.0.is_empty());
|
||||
// FIXME: add bindings for nsCSSValueList
|
||||
fn convert(&self, nscssvalue: &mut nsCSSValue) {
|
||||
nscssvalue.set_list(self.0.iter().map(|item| {
|
||||
let mut value = nsCSSValue::null();
|
||||
value.set_from(item);
|
||||
value
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::AdditiveSymbols {
|
||||
fn convert(&self, _nscssvalue: &mut nsCSSValue) {
|
||||
debug_assert!(!self.0.is_empty());
|
||||
// FIXME: add bindings for nsCSSValuePairList
|
||||
fn convert(&self, nscssvalue: &mut nsCSSValue) {
|
||||
nscssvalue.set_pair_list(self.0.iter().map(|tuple| {
|
||||
let mut weight = nsCSSValue::null();
|
||||
let mut symbol = nsCSSValue::null();
|
||||
weight.set_integer(tuple.weight as i32);
|
||||
symbol.set_from(&tuple.symbol);
|
||||
(weight, symbol)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use app_units::Au;
|
||||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs;
|
||||
use gecko_bindings::structs::{nsCSSValue, nsCSSUnit};
|
||||
use gecko_bindings::structs::{nsCSSValue_Array, nscolor};
|
||||
use gecko_string_cache::Atom;
|
||||
|
@ -220,6 +221,45 @@ impl nsCSSValue {
|
|||
pub fn set_pair(&mut self, x: &nsCSSValue, y: &nsCSSValue) {
|
||||
unsafe { bindings::Gecko_CSSValue_SetPair(self, x, y) }
|
||||
}
|
||||
|
||||
/// Set to a list value
|
||||
///
|
||||
/// This is only supported on the main thread.
|
||||
pub fn set_list<I>(&mut self, mut 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); }
|
||||
debug_assert_eq!(self.mUnit, nsCSSUnit::eCSSUnit_List);
|
||||
let mut item_ptr = &mut unsafe {
|
||||
self.mValue.mList.as_ref() // &*nsCSSValueList_heap
|
||||
.as_mut().expect("List pointer should be non-null")
|
||||
}._base as *mut structs::nsCSSValueList;
|
||||
while let Some(item) = unsafe { item_ptr.as_mut() } {
|
||||
item.mValue = values.next().expect("Values shouldn't have been exhausted");
|
||||
item_ptr = item.mNext;
|
||||
}
|
||||
debug_assert!(values.next().is_none(), "Values should have been exhausted");
|
||||
}
|
||||
|
||||
/// Set to a pair list value
|
||||
///
|
||||
/// 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)> {
|
||||
debug_assert!(values.len() > 0, "Empty list is not supported");
|
||||
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
|
||||
.as_mut().expect("List pointer should be non-null")
|
||||
}._base as *mut structs::nsCSSValuePairList;
|
||||
while let Some(item) = unsafe { item_ptr.as_mut() } {
|
||||
let value = values.next().expect("Values shouldn't have been exhausted");
|
||||
item.mXValue = value.0;
|
||||
item.mYValue = value.1;
|
||||
item_ptr = item.mNext;
|
||||
}
|
||||
debug_assert!(values.next().is_none(), "Values should have been exhausted");
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for nsCSSValue {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue