Replace TElement::get_link() by specific methods.

This commit is contained in:
Ms2ger 2015-05-11 10:52:58 +02:00
parent c76d73d124
commit fa31d7d909
6 changed files with 32 additions and 18 deletions

View file

@ -265,7 +265,7 @@ impl StyleSharingCandidate {
local_name: element.get_local_name().clone(), local_name: element.get_local_name().clone(),
class: element.get_attr(&ns!(""), &atom!("class")) class: element.get_attr(&ns!(""), &atom!("class"))
.map(|string| string.to_owned()), .map(|string| string.to_owned()),
link: element.get_link().is_some(), link: element.is_link(),
namespace: (*element.get_namespace()).clone(), namespace: (*element.get_namespace()).clone(),
common_style_affecting_attributes: common_style_affecting_attributes:
create_common_style_affecting_attributes_from_element(&element) create_common_style_affecting_attributes_from_element(&element)
@ -333,7 +333,7 @@ impl StyleSharingCandidate {
} }
} }
if element.get_link().is_some() != self.link { if element.is_link() != self.link {
return false return false
} }

View file

@ -536,7 +536,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
self.element.namespace() self.element.namespace()
} }
fn get_link(self) -> Option<&'le str> { fn is_link(self) -> bool {
// FIXME: This is HTML only. // FIXME: This is HTML only.
let node: &Node = NodeCast::from_actual(self.element); let node: &Node = NodeCast::from_actual(self.element);
match node.type_id_for_layout() { match node.type_id_for_layout() {
@ -545,13 +545,23 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
unsafe { unsafe {
self.element.get_attr_val_for_layout(&ns!(""), &atom!("href")) self.element.get_attr_val_for_layout(&ns!(""), &atom!("href")).is_some()
} }
} }
_ => None, _ => false,
} }
} }
#[inline]
fn is_unvisited_link(self) -> bool {
self.is_link()
}
#[inline]
fn is_visited_link(self) -> bool {
false
}
#[inline] #[inline]
fn get_hover_state(self) -> bool { fn get_hover_state(self) -> bool {
unsafe { unsafe {

View file

@ -1494,8 +1494,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
} }
impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
#[allow(unsafe_code)] fn is_link(self) -> bool {
fn get_link(self) -> Option<&'a str> {
// FIXME: This is HTML only. // FIXME: This is HTML only.
let node: JSRef<Node> = NodeCast::from_ref(self); let node: JSRef<Node> = NodeCast::from_ref(self);
match node.type_id() { match node.type_id() {
@ -1503,17 +1502,22 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
self.get_attribute(&ns!(""), &atom!("href")).root().map(|attr| { self.has_attribute(&atom!("href"))
// This transmute is used to cheat the lifetime restriction.
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let attr = attr.r();
let value: &str = &**attr.value();
unsafe { mem::transmute(value) }
})
}, },
_ => None, _ => false,
} }
} }
#[inline]
fn is_unvisited_link(self) -> bool {
self.is_link()
}
#[inline]
fn is_visited_link(self) -> bool {
false
}
fn get_local_name(self) -> &'a Atom { fn get_local_name(self) -> &'a Atom {
// FIXME(zwarich): Remove this when UFCS lands and there is a better way // FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods. // of disambiguating methods.

View file

@ -1055,7 +1055,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be" source = "git+https://github.com/servo/rust-selectors#66e21c10cd1feff49e0d934c1861701bc7cd9c44"
dependencies = [ dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",

2
ports/cef/Cargo.lock generated
View file

@ -1037,7 +1037,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be" source = "git+https://github.com/servo/rust-selectors#66e21c10cd1feff49e0d934c1861701bc7cd9c44"
dependencies = [ dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",

2
ports/gonk/Cargo.lock generated
View file

@ -908,7 +908,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be" source = "git+https://github.com/servo/rust-selectors#66e21c10cd1feff49e0d934c1861701bc7cd9c44"
dependencies = [ dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",