mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #5999 - Ms2ger:TElement, r=jdm
<!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5999) <!-- Reviewable:end -->
This commit is contained in:
commit
cf9338cb2e
11 changed files with 51 additions and 51 deletions
|
@ -40,7 +40,7 @@ use string_cache::Atom;
|
||||||
use style::computed_values::content::ContentItem;
|
use style::computed_values::content::ContentItem;
|
||||||
use style::computed_values::{border_collapse, clear, mix_blend_mode, overflow_wrap, position};
|
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::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::properties::{self, ComputedValues, cascade_anonymous};
|
||||||
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||||
use style::values::computed::{LengthOrPercentageOrNone};
|
use style::values::computed::{LengthOrPercentageOrNone};
|
||||||
|
|
|
@ -536,18 +536,6 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
|
||||||
self.element.namespace()
|
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> {
|
fn get_link(self) -> Option<&'le str> {
|
||||||
// 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);
|
||||||
|
@ -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)
|
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, hints: &mut V)
|
||||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
|
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)
|
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> {
|
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> {
|
impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
||||||
#[allow(unsafe_code)]
|
#[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> {
|
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);
|
||||||
|
@ -1523,7 +1502,15 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> {
|
||||||
// https://html.spec.whatwg.org/multipage/#selector-link
|
// https://html.spec.whatwg.org/multipage/#selector-link
|
||||||
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)) => 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,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ use dom::window::WindowHelpers;
|
||||||
use layout_interface::{LayoutChan, Msg};
|
use layout_interface::{LayoutChan, Msg};
|
||||||
use util::str::{DOMString, HTML_SPACE_CHARACTERS};
|
use util::str::{DOMString, HTML_SPACE_CHARACTERS};
|
||||||
use style::media_queries::parse_media_query_list;
|
use style::media_queries::parse_media_query_list;
|
||||||
use style::node::TElement;
|
|
||||||
use cssparser::Parser as CssParser;
|
use cssparser::Parser as CssParser;
|
||||||
|
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
|
@ -145,7 +144,12 @@ impl<'a> PrivateHTMLLinkElementHelpers for JSRef<'a, HTMLLinkElement> {
|
||||||
Ok(url) => {
|
Ok(url) => {
|
||||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
let element: JSRef<Element> = ElementCast::from_ref(self);
|
||||||
|
|
||||||
let mq_str = element.get_attr(&ns!(""), &atom!("media")).unwrap_or("");
|
let mq_attribute = element.get_attribute(&ns!(""), &atom!("media")).root();
|
||||||
|
let value = mq_attribute.r().map(|a| a.value());
|
||||||
|
let mq_str = match value {
|
||||||
|
Some(ref value) => &***value,
|
||||||
|
None => "",
|
||||||
|
};
|
||||||
let mut css_parser = CssParser::new(&mq_str);
|
let mut css_parser = CssParser::new(&mq_str);
|
||||||
let media = parse_media_query_list(&mut css_parser);
|
let media = parse_media_query_list(&mut css_parser);
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::attr::AttrHelpers;
|
||||||
use dom::bindings::codegen::Bindings::HTMLStyleElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLStyleElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLStyleElementDerived, NodeCast};
|
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLStyleElementDerived, NodeCast};
|
||||||
use dom::bindings::js::{JSRef, OptionalRootable, Rootable, Temporary};
|
use dom::bindings::js::{JSRef, OptionalRootable, Rootable, Temporary, RootedReference};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||||
use dom::element::{Element, ElementTypeId};
|
use dom::element::{Element, ElementTypeId, AttributeHandlers};
|
||||||
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
|
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
|
||||||
use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node};
|
use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -17,7 +18,6 @@ use layout_interface::{LayoutChan, Msg};
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
use style::stylesheets::{Origin, Stylesheet};
|
use style::stylesheets::{Origin, Stylesheet};
|
||||||
use style::media_queries::parse_media_query_list;
|
use style::media_queries::parse_media_query_list;
|
||||||
use style::node::TElement;
|
|
||||||
use cssparser::Parser as CssParser;
|
use cssparser::Parser as CssParser;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -59,7 +59,12 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> {
|
||||||
let win = win.r();
|
let win = win.r();
|
||||||
let url = win.get_url();
|
let url = win.get_url();
|
||||||
|
|
||||||
let mq_str = element.get_attr(&ns!(""), &atom!("media")).unwrap_or("");
|
let mq_attribute = element.get_attribute(&ns!(""), &atom!("media")).root();
|
||||||
|
let value = mq_attribute.r().map(|a| a.value());
|
||||||
|
let mq_str = match value {
|
||||||
|
Some(ref value) => &***value,
|
||||||
|
None => "",
|
||||||
|
};
|
||||||
let mut css_parser = CssParser::new(&mq_str);
|
let mut css_parser = CssParser::new(&mq_str);
|
||||||
let media = parse_media_query_list(&mut css_parser);
|
let media = parse_media_query_list(&mut css_parser);
|
||||||
|
|
||||||
|
|
2
components/servo/Cargo.lock
generated
2
components/servo/Cargo.lock
generated
|
@ -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#1fda09bf0c59acfcb697f71b38dad22108b3d27a"
|
source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be"
|
||||||
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)",
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub trait PresentationalHintSynthesis {
|
||||||
matching_rules_list: &mut V,
|
matching_rules_list: &mut V,
|
||||||
shareable: &mut bool)
|
shareable: &mut bool)
|
||||||
where N: TNode<'a>,
|
where N: TNode<'a>,
|
||||||
N::Element: TElementAttributes,
|
N::Element: TElementAttributes<'a>,
|
||||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||||
/// Synthesizes rules for the legacy `border` attribute.
|
/// Synthesizes rules for the legacy `border` attribute.
|
||||||
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
|
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
|
||||||
|
@ -73,7 +73,7 @@ pub trait PresentationalHintSynthesis {
|
||||||
shareable: &mut bool)
|
shareable: &mut bool)
|
||||||
where
|
where
|
||||||
E: TElement<'a> +
|
E: TElement<'a> +
|
||||||
TElementAttributes,
|
TElementAttributes<'a>,
|
||||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ impl PresentationalHintSynthesis for Stylist {
|
||||||
matching_rules_list: &mut V,
|
matching_rules_list: &mut V,
|
||||||
shareable: &mut bool)
|
shareable: &mut bool)
|
||||||
where N: TNode<'a>,
|
where N: TNode<'a>,
|
||||||
N::Element: TElementAttributes,
|
N::Element: TElementAttributes<'a>,
|
||||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
|
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
|
||||||
let element = node.as_element();
|
let element = node.as_element();
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ impl PresentationalHintSynthesis for Stylist {
|
||||||
shareable: &mut bool)
|
shareable: &mut bool)
|
||||||
where
|
where
|
||||||
E: TElement<'a> +
|
E: TElement<'a> +
|
||||||
TElementAttributes,
|
TElementAttributes<'a>,
|
||||||
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
|
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
|
||||||
match element.get_unsigned_integer_attribute(UnsignedIntegerAttribute::Border) {
|
match element.get_unsigned_integer_attribute(UnsignedIntegerAttribute::Border) {
|
||||||
None => {}
|
None => {}
|
||||||
|
|
|
@ -12,11 +12,15 @@ use util::str::LengthOrPercentageOrAuto;
|
||||||
|
|
||||||
use selectors::matching::DeclarationBlock;
|
use selectors::matching::DeclarationBlock;
|
||||||
pub use selectors::tree::{TNode, TElement};
|
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)
|
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, &mut V)
|
||||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||||
fn get_length_attribute(self, attribute: LengthAttribute) -> LengthOrPercentageOrAuto;
|
fn get_length_attribute(self, attribute: LengthAttribute) -> LengthOrPercentageOrAuto;
|
||||||
fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option<i32>;
|
fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option<i32>;
|
||||||
fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32>;
|
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)
|
applicable_declarations: &mut V)
|
||||||
-> bool
|
-> bool
|
||||||
where N: TNode<'a>,
|
where N: TNode<'a>,
|
||||||
N::Element: TElementAttributes,
|
N::Element: TElementAttributes<'a>,
|
||||||
V: VecLike<DeclarationBlock> {
|
V: VecLike<DeclarationBlock> {
|
||||||
assert!(!self.is_dirty);
|
assert!(!self.is_dirty);
|
||||||
assert!(element.is_element());
|
assert!(element.is_element());
|
||||||
|
|
2
ports/cef/Cargo.lock
generated
2
ports/cef/Cargo.lock
generated
|
@ -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#1fda09bf0c59acfcb697f71b38dad22108b3d27a"
|
source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be"
|
||||||
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
2
ports/gonk/Cargo.lock
generated
|
@ -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#1fda09bf0c59acfcb697f71b38dad22108b3d27a"
|
source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be"
|
||||||
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)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue