mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Introduce <LayoutDom<Element>>::attrs()
This safe method is the basic block to access element attributes from layout. We reuse it in the other attr-related layout methods to remove a pretty big source of rampant unsafe code between script and layout.
This commit is contained in:
parent
0bda174823
commit
5ff931d171
16 changed files with 203 additions and 301 deletions
|
@ -551,28 +551,21 @@ impl Element {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
pub unsafe fn get_attr_for_layout<'dom>(
|
||||
elem: &'dom Element,
|
||||
pub fn get_attr_for_layout<'dom>(
|
||||
elem: LayoutDom<'dom, Element>,
|
||||
namespace: &Namespace,
|
||||
name: &LocalName,
|
||||
) -> Option<LayoutDom<'dom, Attr>> {
|
||||
// cast to point to T in RefCell<T> directly
|
||||
let attrs = elem.attrs.borrow_for_layout();
|
||||
attrs
|
||||
elem.attrs()
|
||||
.iter()
|
||||
.find(|attr| {
|
||||
let attr = attr.to_layout();
|
||||
name == attr.local_name() && namespace == attr.namespace()
|
||||
})
|
||||
.map(|attr| attr.to_layout())
|
||||
.find(|attr| name == attr.local_name() && namespace == attr.namespace())
|
||||
.cloned()
|
||||
}
|
||||
|
||||
pub trait LayoutElementHelpers<'dom> {
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool;
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_classes_for_layout(self) -> Option<&'dom [Atom]>;
|
||||
fn attrs(self) -> &'dom [LayoutDom<'dom, Attr>];
|
||||
fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool;
|
||||
fn get_classes_for_layout(self) -> Option<&'dom [Atom]>;
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(self, _: &mut V)
|
||||
|
@ -595,41 +588,42 @@ pub trait LayoutElementHelpers<'dom> {
|
|||
/// The shadow root this element is a host of.
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_attr_for_layout(
|
||||
fn get_attr_for_layout(
|
||||
self,
|
||||
namespace: &Namespace,
|
||||
name: &LocalName,
|
||||
) -> Option<&'dom AttrValue>;
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_attr_val_for_layout(
|
||||
self,
|
||||
namespace: &Namespace,
|
||||
name: &LocalName,
|
||||
) -> Option<&'dom str>;
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_attr_vals_for_layout(self, name: &LocalName) -> Vec<&'dom AttrValue>;
|
||||
fn get_attr_val_for_layout(self, namespace: &Namespace, name: &LocalName) -> Option<&'dom str>;
|
||||
fn get_attr_vals_for_layout(self, name: &LocalName) -> Vec<&'dom AttrValue>;
|
||||
}
|
||||
|
||||
impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||
#[allow(unsafe_code)]
|
||||
#[inline]
|
||||
unsafe fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
||||
get_attr_for_layout(&*self.unsafe_get(), &ns!(), &local_name!("class")).map_or(
|
||||
false,
|
||||
|attr| {
|
||||
attr.as_tokens()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|atom| case_sensitivity.eq_atom(atom, name))
|
||||
},
|
||||
)
|
||||
fn attrs(self) -> &'dom [LayoutDom<'dom, Attr>] {
|
||||
unsafe {
|
||||
// FIXME(nox): This should probably be done through a ToLayout trait.
|
||||
let attrs: &[Dom<Attr>] = &self.unsafe_get().attrs.borrow_for_layout();
|
||||
// This doesn't compile if Dom and LayoutDom don't have the same
|
||||
// representation.
|
||||
let _ = mem::transmute::<Dom<Attr>, LayoutDom<Attr>>;
|
||||
&*(attrs as *const [Dom<Attr>] as *const [LayoutDom<Attr>])
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[inline]
|
||||
unsafe fn get_classes_for_layout(self) -> Option<&'dom [Atom]> {
|
||||
get_attr_for_layout(&*self.unsafe_get(), &ns!(), &local_name!("class"))
|
||||
fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
||||
get_attr_for_layout(self, &ns!(), &local_name!("class")).map_or(false, |attr| {
|
||||
attr.as_tokens()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|atom| case_sensitivity.eq_atom(atom, name))
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_classes_for_layout(self) -> Option<&'dom [Atom]> {
|
||||
get_attr_for_layout(self, &ns!(), &local_name!("class"))
|
||||
.map(|attr| attr.as_tokens().unwrap())
|
||||
}
|
||||
|
||||
|
@ -1066,34 +1060,25 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
|||
.map(|sr| sr.to_layout())
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[inline]
|
||||
unsafe fn get_attr_for_layout(
|
||||
fn get_attr_for_layout(
|
||||
self,
|
||||
namespace: &Namespace,
|
||||
name: &LocalName,
|
||||
) -> Option<&'dom AttrValue> {
|
||||
get_attr_for_layout(self.unsafe_get(), namespace, name).map(|attr| attr.value())
|
||||
get_attr_for_layout(self, namespace, name).map(|attr| attr.value())
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[inline]
|
||||
unsafe fn get_attr_val_for_layout(
|
||||
self,
|
||||
namespace: &Namespace,
|
||||
name: &LocalName,
|
||||
) -> Option<&'dom str> {
|
||||
get_attr_for_layout(self.unsafe_get(), namespace, name).map(|attr| attr.as_str())
|
||||
fn get_attr_val_for_layout(self, namespace: &Namespace, name: &LocalName) -> Option<&'dom str> {
|
||||
get_attr_for_layout(self, namespace, name).map(|attr| attr.as_str())
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[inline]
|
||||
unsafe fn get_attr_vals_for_layout(self, name: &LocalName) -> Vec<&'dom AttrValue> {
|
||||
let attrs = self.unsafe_get().attrs.borrow_for_layout();
|
||||
attrs
|
||||
fn get_attr_vals_for_layout(self, name: &LocalName) -> Vec<&'dom AttrValue> {
|
||||
self.attrs()
|
||||
.iter()
|
||||
.filter_map(|attr| {
|
||||
let attr = attr.to_layout();
|
||||
if name == attr.local_name() {
|
||||
Some(attr.value())
|
||||
} else {
|
||||
|
|
|
@ -100,34 +100,25 @@ pub trait HTMLBodyElementLayoutHelpers {
|
|||
}
|
||||
|
||||
impl HTMLBodyElementLayoutHelpers for LayoutDom<'_, HTMLBodyElement> {
|
||||
#[allow(unsafe_code)]
|
||||
fn get_background_color(self) -> Option<RGBA> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_color(self) -> Option<RGBA> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("text"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("text"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_background(self) -> Option<ServoUrl> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("background"))
|
||||
.and_then(AttrValue::as_resolved_url)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("background"))
|
||||
.and_then(AttrValue::as_resolved_url)
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,24 +152,18 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_uint_px_dimension)
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_uint_px_dimension)
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_height(self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||
.map(AttrValue::as_uint_px_dimension)
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||
.map(AttrValue::as_uint_px_dimension)
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
|
|
@ -107,32 +107,24 @@ pub trait HTMLFontElementLayoutHelpers {
|
|||
}
|
||||
|
||||
impl HTMLFontElementLayoutHelpers for LayoutDom<'_, HTMLFontElement> {
|
||||
#[allow(unsafe_code)]
|
||||
fn get_color(self) -> Option<RGBA> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("color"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("color"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_face(self) -> Option<Atom> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("face"))
|
||||
.map(AttrValue::as_atom)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("face"))
|
||||
.map(AttrValue::as_atom)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_size(self) -> Option<u32> {
|
||||
let size = unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("size"))
|
||||
};
|
||||
let size = self
|
||||
.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("size"));
|
||||
match size {
|
||||
Some(&AttrValue::UInt(_, s)) => Some(s),
|
||||
_ => None,
|
||||
|
|
|
@ -71,25 +71,19 @@ pub trait HTMLHRLayoutHelpers {
|
|||
}
|
||||
|
||||
impl HTMLHRLayoutHelpers for LayoutDom<'_, HTMLHRElement> {
|
||||
#[allow(unsafe_code)]
|
||||
fn get_color(self) -> Option<RGBA> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("color"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("color"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -499,26 +499,20 @@ impl HTMLIFrameElementLayoutMethods for LayoutDom<'_, HTMLIFrameElement> {
|
|||
unsafe { (*self.unsafe_get()).browsing_context_id.get() }
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_height(self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1415,26 +1415,20 @@ impl LayoutHTMLImageElementHelpers for LayoutDom<'_, HTMLImageElement> {
|
|||
.clone()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_height(self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -730,13 +730,11 @@ impl<'dom> LayoutHTMLInputElementHelpers<'dom> for LayoutDom<'dom, HTMLInputElem
|
|||
input: LayoutDom<'dom, HTMLInputElement>,
|
||||
default: &'static str,
|
||||
) -> Cow<'dom, str> {
|
||||
unsafe {
|
||||
input
|
||||
.upcast::<Element>()
|
||||
.get_attr_val_for_layout(&ns!(), &local_name!("value"))
|
||||
.unwrap_or(default)
|
||||
.into()
|
||||
}
|
||||
input
|
||||
.upcast::<Element>()
|
||||
.get_attr_val_for_layout(&ns!(), &local_name!("value"))
|
||||
.unwrap_or(default)
|
||||
.into()
|
||||
}
|
||||
|
||||
let placeholder = unsafe { &**self.unsafe_get().placeholder.borrow_for_layout() };
|
||||
|
|
|
@ -104,41 +104,32 @@ pub trait HTMLTableCellElementLayoutHelpers {
|
|||
fn get_width(self) -> LengthOrPercentageOrAuto;
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl HTMLTableCellElementLayoutHelpers for LayoutDom<'_, HTMLTableCellElement> {
|
||||
fn get_background_color(self) -> Option<RGBA> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
fn get_colspan(self) -> Option<u32> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("colspan"))
|
||||
.map(AttrValue::as_uint)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("colspan"))
|
||||
.map(AttrValue::as_uint)
|
||||
}
|
||||
|
||||
fn get_rowspan(self) -> Option<u32> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("rowspan"))
|
||||
.map(AttrValue::as_uint)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("rowspan"))
|
||||
.map(AttrValue::as_uint)
|
||||
}
|
||||
|
||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -413,14 +413,11 @@ pub trait HTMLTableElementLayoutHelpers {
|
|||
}
|
||||
|
||||
impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> {
|
||||
#[allow(unsafe_code)]
|
||||
fn get_background_color(self) -> Option<RGBA> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -433,15 +430,12 @@ impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> {
|
|||
unsafe { (*self.unsafe_get()).cellspacing.get() }
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||
.map(AttrValue::as_dimension)
|
||||
.cloned()
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,15 +149,12 @@ pub trait HTMLTableRowElementLayoutHelpers {
|
|||
fn get_background_color(self) -> Option<RGBA>;
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl HTMLTableRowElementLayoutHelpers for LayoutDom<'_, HTMLTableRowElement> {
|
||||
fn get_background_color(self) -> Option<RGBA> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,15 +87,12 @@ pub trait HTMLTableSectionElementLayoutHelpers {
|
|||
fn get_background_color(self) -> Option<RGBA>;
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl HTMLTableSectionElementLayoutHelpers for LayoutDom<'_, HTMLTableSectionElement> {
|
||||
fn get_background_color(self) -> Option<RGBA> {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||
.and_then(AttrValue::as_color)
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,22 +96,16 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> {
|
|||
))
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_cols(self) -> u32 {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("cols"))
|
||||
.map_or(DEFAULT_COLS, AttrValue::as_uint)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("cols"))
|
||||
.map_or(DEFAULT_COLS, AttrValue::as_uint)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_rows(self) -> u32 {
|
||||
unsafe {
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("rows"))
|
||||
.map_or(DEFAULT_ROWS, AttrValue::as_uint)
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("rows"))
|
||||
.map_or(DEFAULT_ROWS, AttrValue::as_uint)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,19 +53,16 @@ pub trait LayoutSVGSVGElementHelpers {
|
|||
}
|
||||
|
||||
impl LayoutSVGSVGElementHelpers for LayoutDom<'_, SVGSVGElement> {
|
||||
#[allow(unsafe_code, non_snake_case)]
|
||||
fn data(self) -> SVGSVGData {
|
||||
unsafe {
|
||||
let width_attr = self
|
||||
.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"));
|
||||
let height_attr = self
|
||||
.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("height"));
|
||||
SVGSVGData {
|
||||
width: width_attr.map_or(DEFAULT_WIDTH, |val| val.as_uint()),
|
||||
height: height_attr.map_or(DEFAULT_HEIGHT, |val| val.as_uint()),
|
||||
}
|
||||
let width_attr = self
|
||||
.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("width"));
|
||||
let height_attr = self
|
||||
.upcast::<Element>()
|
||||
.get_attr_for_layout(&ns!(), &local_name!("height"));
|
||||
SVGSVGData {
|
||||
width: width_attr.map_or(DEFAULT_WIDTH, |val| val.as_uint()),
|
||||
height: height_attr.map_or(DEFAULT_HEIGHT, |val| val.as_uint()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue