mirror of
https://github.com/servo/servo.git
synced 2025-07-30 02:30:21 +01:00
Implement get_attr_for_layout that returns an AttrValue.
This commit is contained in:
parent
9951e0b4d6
commit
1b99fd7ecb
2 changed files with 16 additions and 0 deletions
|
@ -306,6 +306,7 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub trait AttrHelpersForLayout {
|
pub trait AttrHelpersForLayout {
|
||||||
|
unsafe fn value_forever(&self) -> &'static AttrValue;
|
||||||
unsafe fn value_ref_forever(&self) -> &'static str;
|
unsafe fn value_ref_forever(&self) -> &'static str;
|
||||||
unsafe fn value_atom_forever(&self) -> Option<Atom>;
|
unsafe fn value_atom_forever(&self) -> Option<Atom>;
|
||||||
unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>;
|
unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>;
|
||||||
|
@ -314,6 +315,12 @@ pub trait AttrHelpersForLayout {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
impl AttrHelpersForLayout for Attr {
|
impl AttrHelpersForLayout for Attr {
|
||||||
|
#[inline]
|
||||||
|
unsafe fn value_forever(&self) -> &'static AttrValue {
|
||||||
|
// This transmute is used to cheat the lifetime restriction.
|
||||||
|
mem::transmute::<&AttrValue, &AttrValue>(self.value.borrow_for_layout())
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn value_ref_forever(&self) -> &'static str {
|
unsafe fn value_ref_forever(&self) -> &'static str {
|
||||||
// This transmute is used to cheat the lifetime restriction.
|
// This transmute is used to cheat the lifetime restriction.
|
||||||
|
|
|
@ -156,6 +156,8 @@ impl Element {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub trait RawLayoutElementHelpers {
|
pub trait RawLayoutElementHelpers {
|
||||||
|
unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||||
|
-> Option<&'a AttrValue>;
|
||||||
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||||
-> Option<&'a str>;
|
-> Option<&'a str>;
|
||||||
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &Atom) -> Vec<&'a str>;
|
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &Atom) -> Vec<&'a str>;
|
||||||
|
@ -190,6 +192,13 @@ unsafe fn get_attr_for_layout(elem: &Element, namespace: &Namespace, name: &Atom
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
impl RawLayoutElementHelpers for Element {
|
impl RawLayoutElementHelpers for Element {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||||
|
-> Option<&'a AttrValue> {
|
||||||
|
get_attr_for_layout(self, namespace, name).map(|attr| {
|
||||||
|
(*attr.unsafe_get()).value_forever()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||||
-> Option<&'a str> {
|
-> Option<&'a str> {
|
||||||
get_attr_for_layout(self, namespace, name).map(|attr| {
|
get_attr_for_layout(self, namespace, name).map(|attr| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue