diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-10-27 11:45:34 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-11-03 13:49:15 +0100 |
commit | db65c2d3460c8a64f7913611e85e09cbfe78756b (patch) | |
tree | 85a321d4f9d3be128e5d881d850d2e9322127d9a | |
parent | c494d25e24d515509a5d8bb86a30669ee01742b9 (diff) | |
download | servo-db65c2d3460c8a64f7913611e85e09cbfe78756b.tar.gz servo-db65c2d3460c8a64f7913611e85e09cbfe78756b.zip |
style: Add a Document::elements_with_id API.
MozReview-Commit-ID: BNtbJp0RI68
-rw-r--r-- | components/style/dom.rs | 11 | ||||
-rw-r--r-- | components/style/gecko/wrapper.rs | 20 |
2 files changed, 31 insertions, 0 deletions
diff --git a/components/style/dom.rs b/components/style/dom.rs index 721625e33a9..9c49b37f704 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -146,6 +146,17 @@ pub trait TDocument : Sized + Copy + Clone { /// Returns the quirks mode of this document. 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 diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 91a9578c912..a8851fb6e1f 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -110,6 +110,26 @@ impl<'ld> TDocument for GeckoDocument<'ld> { fn quirks_mode(&self) -> QuirksMode { 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. |