Auto merge of #17144 - jryans:link-pres-hints, r=Manishearth

Stylo: Support link preshints on <body>

https://bugzilla.mozilla.org/show_bug.cgi?id=1367923
This commit is contained in:
bors-servo 2017-06-02 13:08:04 -07:00 committed by GitHub
commit 54448305de
8 changed files with 114 additions and 58 deletions

View file

@ -51,7 +51,7 @@ use script_layout_interface::{OpaqueStyleAndLayoutData, StyleData};
use script_layout_interface::wrapper_traits::{DangerousThreadSafeLayoutNode, GetLayoutData, LayoutNode};
use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode};
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint};
use selectors::matching::{ElementSelectorFlags, MatchingContext, RelevantLinkStatus};
use selectors::matching::{ElementSelectorFlags, MatchingContext, RelevantLinkStatus, VisitedHandlingMode};
use servo_atoms::Atom;
use servo_url::ServoUrl;
use std::fmt;
@ -364,7 +364,9 @@ impl<'le> fmt::Debug for ServoLayoutElement<'le> {
}
impl<'le> PresentationalHintsSynthesizer for ServoLayoutElement<'le> {
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self,
_visited_handling: VisitedHandlingMode,
hints: &mut V)
where V: Push<ApplicableDeclarationBlock>
{
unsafe {
@ -1228,6 +1230,8 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
}
impl<'le> PresentationalHintsSynthesizer for ServoThreadSafeLayoutElement<'le> {
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, _hints: &mut V)
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self,
_visited_handling: VisitedHandlingMode,
_hints: &mut V)
where V: Push<ApplicableDeclarationBlock> {}
}

View file

@ -18,7 +18,7 @@ use properties::{ComputedValues, PropertyDeclarationBlock};
#[cfg(feature = "gecko")] use properties::animated_properties::TransitionProperty;
use rule_tree::CascadeLevel;
use selector_parser::{ElementExt, PreExistingComputedValues, PseudoElement};
use selectors::matching::ElementSelectorFlags;
use selectors::matching::{ElementSelectorFlags, VisitedHandlingMode};
use shared_lock::Locked;
use sink::Push;
use std::fmt;
@ -270,7 +270,9 @@ pub unsafe fn raw_note_descendants<E, B>(element: E) -> bool
pub trait PresentationalHintsSynthesizer {
/// Generate the proper applicable declarations due to presentational hints,
/// and insert them into `hints`.
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self,
visited_handling: VisitedHandlingMode,
hints: &mut V)
where V: Push<ApplicableDeclarationBlock>;
}

View file

@ -694,6 +694,21 @@ extern "C" {
RawGeckoElementBorrowed)
-> RawServoDeclarationBlockStrongBorrowedOrNull;
}
extern "C" {
pub fn Gecko_GetUnvisitedLinkAttrDeclarationBlock(element:
RawGeckoElementBorrowed)
-> RawServoDeclarationBlockStrongBorrowedOrNull;
}
extern "C" {
pub fn Gecko_GetVisitedLinkAttrDeclarationBlock(element:
RawGeckoElementBorrowed)
-> RawServoDeclarationBlockStrongBorrowedOrNull;
}
extern "C" {
pub fn Gecko_GetActiveLinkAttrDeclarationBlock(element:
RawGeckoElementBorrowed)
-> RawServoDeclarationBlockStrongBorrowedOrNull;
}
extern "C" {
pub fn Gecko_GetAnimationRule(aElementOrPseudo: RawGeckoElementBorrowed,
aCascadeLevel:

View file

@ -800,6 +800,11 @@ pub mod root {
4;
pub const NS_STYLE_CONTEXT_PROPERTY_FILL: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_CONTEXT_PROPERTY_STROKE: ::std::os::raw::c_uint = 2;
pub const NS_STYLE_CONTEXT_PROPERTY_FILL_OPACITY: ::std::os::raw::c_uint =
4;
pub const NS_STYLE_CONTEXT_PROPERTY_STROKE_OPACITY: ::std::os::raw::c_uint
=
8;
pub const NS_STYLE_WINDOW_SHADOW_NONE: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_WINDOW_SHADOW_DEFAULT: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WINDOW_SHADOW_MENU: ::std::os::raw::c_uint = 2;
@ -3673,9 +3678,20 @@ pub mod root {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug)]
pub struct EventHandlerNonNull {
_unused: [u8; 0],
pub _base: root::mozilla::dom::CallbackFunction,
}
#[test]
fn bindgen_test_layout_EventHandlerNonNull() {
assert_eq!(::std::mem::size_of::<EventHandlerNonNull>() ,
56usize , concat ! (
"Size of: " , stringify ! ( EventHandlerNonNull )
));
assert_eq! (::std::mem::align_of::<EventHandlerNonNull>() ,
8usize , concat ! (
"Alignment of " , stringify ! (
EventHandlerNonNull ) ));
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@ -14866,26 +14882,6 @@ pub mod root {
pub struct nsIPrincipal_COMTypeInfo {
pub _address: u8,
}
pub const nsIPrincipal_APP_STATUS_NOT_INSTALLED:
root::nsIPrincipal__bindgen_ty_1 =
nsIPrincipal__bindgen_ty_1::APP_STATUS_NOT_INSTALLED;
pub const nsIPrincipal_APP_STATUS_INSTALLED:
root::nsIPrincipal__bindgen_ty_1 =
nsIPrincipal__bindgen_ty_1::APP_STATUS_INSTALLED;
pub const nsIPrincipal_APP_STATUS_PRIVILEGED:
root::nsIPrincipal__bindgen_ty_1 =
nsIPrincipal__bindgen_ty_1::APP_STATUS_PRIVILEGED;
pub const nsIPrincipal_APP_STATUS_CERTIFIED:
root::nsIPrincipal__bindgen_ty_1 =
nsIPrincipal__bindgen_ty_1::APP_STATUS_CERTIFIED;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum nsIPrincipal__bindgen_ty_1 {
APP_STATUS_NOT_INSTALLED = 0,
APP_STATUS_INSTALLED = 1,
APP_STATUS_PRIVILEGED = 2,
APP_STATUS_CERTIFIED = 3,
}
#[test]
fn bindgen_test_layout_nsIPrincipal() {
assert_eq!(::std::mem::size_of::<nsIPrincipal>() , 8usize , concat ! (
@ -33529,7 +33525,7 @@ pub mod root {
root::nsCharTraits ) ));
}
#[test]
fn __bindgen_test_layout__bindgen_ty_id_203478_instantiation_99() {
fn __bindgen_test_layout__bindgen_ty_id_211393_instantiation_99() {
assert_eq!(::std::mem::size_of::<u8>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( u8 )
));
@ -33538,7 +33534,7 @@ pub mod root {
) ));
}
#[test]
fn __bindgen_test_layout__bindgen_ty_id_203514_instantiation_100() {
fn __bindgen_test_layout__bindgen_ty_id_211429_instantiation_100() {
assert_eq!(::std::mem::size_of::<u8>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( u8 )
));

View file

@ -800,6 +800,11 @@ pub mod root {
4;
pub const NS_STYLE_CONTEXT_PROPERTY_FILL: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_CONTEXT_PROPERTY_STROKE: ::std::os::raw::c_uint = 2;
pub const NS_STYLE_CONTEXT_PROPERTY_FILL_OPACITY: ::std::os::raw::c_uint =
4;
pub const NS_STYLE_CONTEXT_PROPERTY_STROKE_OPACITY: ::std::os::raw::c_uint
=
8;
pub const NS_STYLE_WINDOW_SHADOW_NONE: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_WINDOW_SHADOW_DEFAULT: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_WINDOW_SHADOW_MENU: ::std::os::raw::c_uint = 2;
@ -3571,9 +3576,20 @@ pub mod root {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug)]
pub struct EventHandlerNonNull {
_unused: [u8; 0],
pub _base: root::mozilla::dom::CallbackFunction,
}
#[test]
fn bindgen_test_layout_EventHandlerNonNull() {
assert_eq!(::std::mem::size_of::<EventHandlerNonNull>() ,
48usize , concat ! (
"Size of: " , stringify ! ( EventHandlerNonNull )
));
assert_eq! (::std::mem::align_of::<EventHandlerNonNull>() ,
8usize , concat ! (
"Alignment of " , stringify ! (
EventHandlerNonNull ) ));
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@ -14521,26 +14537,6 @@ pub mod root {
pub struct nsIPrincipal_COMTypeInfo {
pub _address: u8,
}
pub const nsIPrincipal_APP_STATUS_NOT_INSTALLED:
root::nsIPrincipal__bindgen_ty_1 =
nsIPrincipal__bindgen_ty_1::APP_STATUS_NOT_INSTALLED;
pub const nsIPrincipal_APP_STATUS_INSTALLED:
root::nsIPrincipal__bindgen_ty_1 =
nsIPrincipal__bindgen_ty_1::APP_STATUS_INSTALLED;
pub const nsIPrincipal_APP_STATUS_PRIVILEGED:
root::nsIPrincipal__bindgen_ty_1 =
nsIPrincipal__bindgen_ty_1::APP_STATUS_PRIVILEGED;
pub const nsIPrincipal_APP_STATUS_CERTIFIED:
root::nsIPrincipal__bindgen_ty_1 =
nsIPrincipal__bindgen_ty_1::APP_STATUS_CERTIFIED;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum nsIPrincipal__bindgen_ty_1 {
APP_STATUS_NOT_INSTALLED = 0,
APP_STATUS_INSTALLED = 1,
APP_STATUS_PRIVILEGED = 2,
APP_STATUS_CERTIFIED = 3,
}
#[test]
fn bindgen_test_layout_nsIPrincipal() {
assert_eq!(::std::mem::size_of::<nsIPrincipal>() , 8usize , concat ! (
@ -33009,7 +33005,7 @@ pub mod root {
root::nsCharTraits ) ));
}
#[test]
fn __bindgen_test_layout__bindgen_ty_id_199539_instantiation_97() {
fn __bindgen_test_layout__bindgen_ty_id_207717_instantiation_97() {
assert_eq!(::std::mem::size_of::<u8>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( u8 )
));
@ -33018,7 +33014,7 @@ pub mod root {
) ));
}
#[test]
fn __bindgen_test_layout__bindgen_ty_id_199575_instantiation_98() {
fn __bindgen_test_layout__bindgen_ty_id_207753_instantiation_98() {
assert_eq!(::std::mem::size_of::<u8>() , 1usize , concat ! (
"Size of template specialization: " , stringify ! ( u8 )
));

View file

@ -35,12 +35,15 @@ use gecko_bindings::bindings::Gecko_ClassOrClassList;
use gecko_bindings::bindings::Gecko_ElementHasAnimations;
use gecko_bindings::bindings::Gecko_ElementHasCSSAnimations;
use gecko_bindings::bindings::Gecko_ElementHasCSSTransitions;
use gecko_bindings::bindings::Gecko_GetActiveLinkAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetAnimationRule;
use gecko_bindings::bindings::Gecko_GetExtraContentStyleDeclarations;
use gecko_bindings::bindings::Gecko_GetHTMLPresentationAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetSMILOverrideDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetStyleAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetStyleContext;
use gecko_bindings::bindings::Gecko_GetUnvisitedLinkAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetVisitedLinkAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_IsSignificantChild;
use gecko_bindings::bindings::Gecko_MatchStringArgPseudo;
use gecko_bindings::bindings::Gecko_UnsetDirtyStyleAttr;
@ -66,7 +69,8 @@ use rule_tree::CascadeLevel as ServoCascadeLevel;
use selector_parser::ElementExt;
use selectors::Element;
use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator, CaseSensitivity, NamespaceConstraint};
use selectors::matching::{ElementSelectorFlags, MatchingContext, MatchingMode, RelevantLinkStatus};
use selectors::matching::{ElementSelectorFlags, MatchingContext, MatchingMode};
use selectors::matching::{RelevantLinkStatus, VisitedHandlingMode};
use shared_lock::Locked;
use sink::Push;
use std::cell::RefCell;
@ -1036,7 +1040,9 @@ impl<'le> Hash for GeckoElement<'le> {
}
impl<'le> PresentationalHintsSynthesizer for GeckoElement<'le> {
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self,
visited_handling: VisitedHandlingMode,
hints: &mut V)
where V: Push<ApplicableDeclarationBlock>,
{
use properties::longhands::_x_lang::SpecifiedValue as SpecifiedLang;
@ -1098,6 +1104,37 @@ impl<'le> PresentationalHintsSynthesizer for GeckoElement<'le> {
);
}
// Support for link, vlink, and alink presentation hints on <body>
if self.is_link() {
// Unvisited vs. visited styles are computed up-front based on the
// visited mode (not the element's actual state).
let declarations = match visited_handling {
VisitedHandlingMode::AllLinksUnvisited => unsafe {
Gecko_GetUnvisitedLinkAttrDeclarationBlock(self.0)
},
VisitedHandlingMode::RelevantLinkVisited => unsafe {
Gecko_GetVisitedLinkAttrDeclarationBlock(self.0)
},
};
let declarations = declarations.and_then(|s| s.as_arc_opt());
if let Some(decl) = declarations {
hints.push(
ApplicableDeclarationBlock::from_declarations(Clone::clone(decl), ServoCascadeLevel::PresHints)
);
}
let active = self.get_state().intersects(NonTSPseudoClass::Active.state_flag());
if active {
let declarations = unsafe { Gecko_GetActiveLinkAttrDeclarationBlock(self.0) };
let declarations = declarations.and_then(|s| s.as_arc_opt());
if let Some(decl) = declarations {
hints.push(
ApplicableDeclarationBlock::from_declarations(Clone::clone(decl), ServoCascadeLevel::PresHints)
);
}
}
}
// xml:lang has precedence over lang, which can be
// set by Gecko_GetHTMLPresentationAttrDeclarationBlock
//

View file

@ -14,7 +14,7 @@ use dom::{TElement, SendElement};
use matching::{ChildCascadeRequirement, MatchMethods};
use properties::ComputedValues;
use selectors::bloom::BloomFilter;
use selectors::matching::{ElementSelectorFlags, StyleRelations};
use selectors::matching::{ElementSelectorFlags, VisitedHandlingMode, StyleRelations};
use smallvec::SmallVec;
use std::mem;
use std::ops::Deref;
@ -66,7 +66,10 @@ impl ValidationData {
{
if self.pres_hints.is_none() {
let mut pres_hints = SmallVec::new();
element.synthesize_presentational_hints_for_legacy_attributes(&mut pres_hints);
element.synthesize_presentational_hints_for_legacy_attributes(
VisitedHandlingMode::AllLinksUnvisited,
&mut pres_hints
);
self.pres_hints = Some(pres_hints);
}
&*self.pres_hints.as_ref().unwrap()

View file

@ -959,7 +959,10 @@ impl Stylist {
if pseudo_element.is_none() && !only_default_rules {
// Step 2: Presentational hints.
let length_before_preshints = applicable_declarations.len();
element.synthesize_presentational_hints_for_legacy_attributes(applicable_declarations);
element.synthesize_presentational_hints_for_legacy_attributes(
context.visited_handling,
applicable_declarations
);
if applicable_declarations.len() != length_before_preshints {
if cfg!(debug_assertions) {
for declaration in &applicable_declarations[length_before_preshints..] {