mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
style: Use placement new/delete StyleChildrenIterator FFI functions.
MozReview-Commit-ID: L0bhymGJqRx
This commit is contained in:
parent
07ede8cb2a
commit
25dde5120c
1 changed files with 20 additions and 9 deletions
|
@ -30,7 +30,7 @@ use gecko::global_style_data::GLOBAL_STYLE_DATA;
|
||||||
use gecko::selector_parser::{SelectorImpl, NonTSPseudoClass, PseudoElement};
|
use gecko::selector_parser::{SelectorImpl, NonTSPseudoClass, PseudoElement};
|
||||||
use gecko::snapshot_helpers;
|
use gecko::snapshot_helpers;
|
||||||
use gecko_bindings::bindings;
|
use gecko_bindings::bindings;
|
||||||
use gecko_bindings::bindings::{Gecko_DropStyleChildrenIterator, Gecko_MaybeCreateStyleChildrenIterator};
|
use gecko_bindings::bindings::{Gecko_ConstructStyleChildrenIterator, Gecko_DestroyStyleChildrenIterator};
|
||||||
use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentLWTheme};
|
use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentLWTheme};
|
||||||
use gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetNextStyleChild};
|
use gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetNextStyleChild};
|
||||||
use gecko_bindings::bindings::{Gecko_IsRootElement, Gecko_MatchesElement, Gecko_Namespace};
|
use gecko_bindings::bindings::{Gecko_IsRootElement, Gecko_MatchesElement, Gecko_Namespace};
|
||||||
|
@ -282,13 +282,24 @@ impl<'ln> TNode for GeckoNode<'ln> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traversal_children(&self) -> LayoutIterator<GeckoChildrenIterator<'ln>> {
|
fn traversal_children(&self) -> LayoutIterator<GeckoChildrenIterator<'ln>> {
|
||||||
let maybe_iter = unsafe { Gecko_MaybeCreateStyleChildrenIterator(self.0) };
|
if let Some(element) = self.as_element() {
|
||||||
if let Some(iter) = maybe_iter.into_owned_opt() {
|
// This condition is similar to the check that
|
||||||
LayoutIterator(GeckoChildrenIterator::GeckoIterator(iter))
|
// StyleChildrenIterator::IsNeeded does, except that it might return
|
||||||
} else {
|
// true if we used to (but no longer) have anonymous content from
|
||||||
LayoutIterator(self.dom_children())
|
// ::before/::after, XBL bindings, or nsIAnonymousContentCreators.
|
||||||
|
if self.is_in_anonymous_subtree() ||
|
||||||
|
element.has_xbl_binding_with_content() ||
|
||||||
|
self.may_have_anonymous_children() {
|
||||||
|
unsafe {
|
||||||
|
let mut iter: structs::StyleChildrenIterator = ::std::mem::zeroed();
|
||||||
|
Gecko_ConstructStyleChildrenIterator(element.0, &mut iter);
|
||||||
|
return LayoutIterator(GeckoChildrenIterator::GeckoIterator(iter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LayoutIterator(self.dom_children())
|
||||||
|
}
|
||||||
|
|
||||||
fn opaque(&self) -> OpaqueNode {
|
fn opaque(&self) -> OpaqueNode {
|
||||||
let ptr: usize = self.0 as *const _ as usize;
|
let ptr: usize = self.0 as *const _ as usize;
|
||||||
|
@ -351,14 +362,14 @@ pub enum GeckoChildrenIterator<'a> {
|
||||||
/// replaces it with the next sibling when requested.
|
/// replaces it with the next sibling when requested.
|
||||||
Current(Option<GeckoNode<'a>>),
|
Current(Option<GeckoNode<'a>>),
|
||||||
/// A Gecko-implemented iterator we need to drop appropriately.
|
/// A Gecko-implemented iterator we need to drop appropriately.
|
||||||
GeckoIterator(bindings::StyleChildrenIteratorOwned),
|
GeckoIterator(structs::StyleChildrenIterator),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for GeckoChildrenIterator<'a> {
|
impl<'a> Drop for GeckoChildrenIterator<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let GeckoChildrenIterator::GeckoIterator(ref it) = *self {
|
if let GeckoChildrenIterator::GeckoIterator(ref mut it) = *self {
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_DropStyleChildrenIterator(ptr::read(it as *const _));
|
Gecko_DestroyStyleChildrenIterator(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue