mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
style: Add a Document::elements_with_id API.
MozReview-Commit-ID: BNtbJp0RI68 Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
3b0940342c
commit
2783297fa9
2 changed files with 31 additions and 0 deletions
|
@ -146,6 +146,17 @@ pub trait TDocument : Sized + Copy + Clone {
|
||||||
|
|
||||||
/// Returns the quirks mode of this document.
|
/// Returns the quirks mode of this document.
|
||||||
fn quirks_mode(&self) -> QuirksMode;
|
fn quirks_mode(&self) -> QuirksMode;
|
||||||
|
|
||||||
|
/// Get a list of elements with a given ID in this document.
|
||||||
|
///
|
||||||
|
/// Can return an error to signal that this list is not available, or also
|
||||||
|
/// return an empty slice.
|
||||||
|
fn elements_with_id(
|
||||||
|
&self,
|
||||||
|
_id: &Atom,
|
||||||
|
) -> Result<&[<Self::ConcreteNode as TNode>::ConcreteElement], ()> {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The `TNode` trait. This is the main generic trait over which the style
|
/// The `TNode` trait. This is the main generic trait over which the style
|
||||||
|
|
|
@ -110,6 +110,26 @@ impl<'ld> TDocument for GeckoDocument<'ld> {
|
||||||
fn quirks_mode(&self) -> QuirksMode {
|
fn quirks_mode(&self) -> QuirksMode {
|
||||||
self.0.mCompatMode.into()
|
self.0.mCompatMode.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn elements_with_id(&self, id: &Atom) -> Result<&[GeckoElement<'ld>], ()> {
|
||||||
|
unsafe {
|
||||||
|
let array = bindings::Gecko_GetElementsWithId(self.0, id.as_ptr());
|
||||||
|
if array.is_null() {
|
||||||
|
return Ok(&[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let elements: &[*mut RawGeckoElement] = &**array;
|
||||||
|
|
||||||
|
// NOTE(emilio): We rely on the in-memory representation of
|
||||||
|
// GeckoElement<'ld> and *mut RawGeckoElement being the same.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
unsafe fn static_assert() {
|
||||||
|
mem::transmute::<*mut RawGeckoElement, GeckoElement<'static>>(0xbadc0de as *mut _);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(mem::transmute(elements))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A simple wrapper over a non-null Gecko node (`nsINode`) pointer.
|
/// A simple wrapper over a non-null Gecko node (`nsINode`) pointer.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue