mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Move get_attr and get_attrs into TElementAttributes.
These methods are only called on LayoutElement.
This commit is contained in:
parent
2ff18b6b95
commit
34e35df986
9 changed files with 36 additions and 45 deletions
|
@ -40,7 +40,7 @@ use string_cache::Atom;
|
|||
use style::computed_values::content::ContentItem;
|
||||
use style::computed_values::{border_collapse, clear, mix_blend_mode, overflow_wrap, position};
|
||||
use style::computed_values::{text_align, text_decoration, white_space, word_break};
|
||||
use style::node::{TElement, TNode};
|
||||
use style::node::TNode;
|
||||
use style::properties::{self, ComputedValues, cascade_anonymous};
|
||||
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
use style::values::computed::{LengthOrPercentageOrNone};
|
||||
|
|
|
@ -536,18 +536,6 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
|
|||
self.element.namespace()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_attr(self, namespace: &Namespace, name: &Atom) -> Option<&'le str> {
|
||||
unsafe { self.element.get_attr_val_for_layout(namespace, name) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_attrs(self, name: &Atom) -> Vec<&'le str> {
|
||||
unsafe {
|
||||
self.element.get_attr_vals_for_layout(name)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_link(self) -> Option<&'le str> {
|
||||
// FIXME: This is HTML only.
|
||||
let node: &Node = NodeCast::from_actual(self.element);
|
||||
|
@ -650,7 +638,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'le> TElementAttributes for LayoutElement<'le> {
|
||||
impl<'le> TElementAttributes<'le> for LayoutElement<'le> {
|
||||
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, hints: &mut V)
|
||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
|
||||
{
|
||||
|
@ -676,6 +664,18 @@ impl<'le> TElementAttributes for LayoutElement<'le> {
|
|||
self.element.get_unsigned_integer_attribute_for_layout(attribute)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_attr(self, namespace: &Namespace, name: &Atom) -> Option<&'le str> {
|
||||
unsafe { self.element.get_attr_val_for_layout(namespace, name) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_attrs(self, name: &Atom) -> Vec<&'le str> {
|
||||
unsafe {
|
||||
self.element.get_attr_vals_for_layout(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_content(content_list: &content::T) -> Vec<ContentItem> {
|
||||
|
|
|
@ -1495,27 +1495,6 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
|
||||
impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
||||
#[allow(unsafe_code)]
|
||||
fn get_attr(self, namespace: &Namespace, local_name: &Atom) -> Option<&'a str> {
|
||||
self.get_attribute(namespace, local_name).root().map(|attr| {
|
||||
// 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) }
|
||||
})
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
fn get_attrs(self, local_name: &Atom) -> Vec<&'a str> {
|
||||
let mut attributes = RootedVec::new();
|
||||
self.get_attributes(local_name, &mut attributes);
|
||||
attributes.iter().map(|attr| attr.root()).map(|attr| {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attr = attr.r();
|
||||
let value: &str = &**attr.value();
|
||||
// This transmute is used to cheat the lifetime restriction.
|
||||
unsafe { mem::transmute(value) }
|
||||
}).collect()
|
||||
}
|
||||
fn get_link(self) -> Option<&'a str> {
|
||||
// FIXME: This is HTML only.
|
||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
|
@ -1523,7 +1502,15 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
|||
// https://html.spec.whatwg.org/multipage/#selector-link
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => self.get_attr(&ns!(""), &atom!("href")),
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
|
||||
self.get_attribute(&ns!(""), &atom!("href")).root().map(|attr| {
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
|
|
2
components/servo/Cargo.lock
generated
2
components/servo/Cargo.lock
generated
|
@ -1055,7 +1055,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "selectors"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/servo/rust-selectors#1fda09bf0c59acfcb697f71b38dad22108b3d27a"
|
||||
source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be"
|
||||
dependencies = [
|
||||
"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)",
|
||||
|
|
|
@ -63,7 +63,7 @@ pub trait PresentationalHintSynthesis {
|
|||
matching_rules_list: &mut V,
|
||||
shareable: &mut bool)
|
||||
where N: TNode<'a>,
|
||||
N::Element: TElementAttributes,
|
||||
N::Element: TElementAttributes<'a>,
|
||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||
/// Synthesizes rules for the legacy `border` attribute.
|
||||
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
|
||||
|
@ -73,7 +73,7 @@ pub trait PresentationalHintSynthesis {
|
|||
shareable: &mut bool)
|
||||
where
|
||||
E: TElement<'a> +
|
||||
TElementAttributes,
|
||||
TElementAttributes<'a>,
|
||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ impl PresentationalHintSynthesis for Stylist {
|
|||
matching_rules_list: &mut V,
|
||||
shareable: &mut bool)
|
||||
where N: TNode<'a>,
|
||||
N::Element: TElementAttributes,
|
||||
N::Element: TElementAttributes<'a>,
|
||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
|
||||
let element = node.as_element();
|
||||
|
||||
|
@ -199,7 +199,7 @@ impl PresentationalHintSynthesis for Stylist {
|
|||
shareable: &mut bool)
|
||||
where
|
||||
E: TElement<'a> +
|
||||
TElementAttributes,
|
||||
TElementAttributes<'a>,
|
||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
|
||||
match element.get_unsigned_integer_attribute(UnsignedIntegerAttribute::Border) {
|
||||
None => {}
|
||||
|
|
|
@ -12,11 +12,15 @@ use util::str::LengthOrPercentageOrAuto;
|
|||
|
||||
use selectors::matching::DeclarationBlock;
|
||||
pub use selectors::tree::{TNode, TElement};
|
||||
use string_cache::{Atom, Namespace};
|
||||
|
||||
pub trait TElementAttributes : Copy {
|
||||
pub trait TElementAttributes<'a> : Copy {
|
||||
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, &mut V)
|
||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||
fn get_length_attribute(self, attribute: LengthAttribute) -> LengthOrPercentageOrAuto;
|
||||
fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option<i32>;
|
||||
fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32>;
|
||||
|
||||
fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str>;
|
||||
fn get_attrs(self, attr: &Atom) -> Vec<&'a str>;
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ impl Stylist {
|
|||
applicable_declarations: &mut V)
|
||||
-> bool
|
||||
where N: TNode<'a>,
|
||||
N::Element: TElementAttributes,
|
||||
N::Element: TElementAttributes<'a>,
|
||||
V: VecLike<DeclarationBlock> {
|
||||
assert!(!self.is_dirty);
|
||||
assert!(element.is_element());
|
||||
|
|
2
ports/cef/Cargo.lock
generated
2
ports/cef/Cargo.lock
generated
|
@ -1037,7 +1037,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "selectors"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/servo/rust-selectors#1fda09bf0c59acfcb697f71b38dad22108b3d27a"
|
||||
source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be"
|
||||
dependencies = [
|
||||
"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)",
|
||||
|
|
2
ports/gonk/Cargo.lock
generated
2
ports/gonk/Cargo.lock
generated
|
@ -908,7 +908,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "selectors"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/servo/rust-selectors#1fda09bf0c59acfcb697f71b38dad22108b3d27a"
|
||||
source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be"
|
||||
dependencies = [
|
||||
"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)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue