@@ -761,6 +761,53 @@ fn matches_compound_selector_internal<'a,E,N>(selector: &CompoundSelector,
761
761
}
762
762
}
763
763
764
+ bitflags ! {
765
+ flags CommonStyleAffectingAttributes : u8 {
766
+ static HiddenAttribute = 0x01 ,
767
+ static NoWrapAttribute = 0x02 ,
768
+ static AlignLeftAttribute = 0x04 ,
769
+ static AlignCenterAttribute = 0x08 ,
770
+ static AlignRightAttribute = 0x10 ,
771
+ }
772
+ }
773
+
774
+ pub struct CommonStyleAffectingAttributeInfo {
775
+ pub atom : Atom ,
776
+ pub mode : CommonStyleAffectingAttributeMode ,
777
+ }
778
+
779
+ pub enum CommonStyleAffectingAttributeMode {
780
+ AttrIsPresentMode ( CommonStyleAffectingAttributes ) ,
781
+ AttrIsEqualMode ( & ' static str , CommonStyleAffectingAttributes ) ,
782
+ }
783
+
784
+ // NB: This must match the order in `layout::css::matching::CommonStyleAffectingAttributes`.
785
+ #[ inline]
786
+ pub fn common_style_affecting_attributes ( ) -> [ CommonStyleAffectingAttributeInfo , ..5 ] {
787
+ [
788
+ CommonStyleAffectingAttributeInfo {
789
+ atom : atom ! ( "hidden" ) ,
790
+ mode : AttrIsPresentMode ( HiddenAttribute ) ,
791
+ } ,
792
+ CommonStyleAffectingAttributeInfo {
793
+ atom : atom ! ( "nowrap" ) ,
794
+ mode : AttrIsPresentMode ( NoWrapAttribute ) ,
795
+ } ,
796
+ CommonStyleAffectingAttributeInfo {
797
+ atom : atom ! ( "align" ) ,
798
+ mode : AttrIsEqualMode ( "left" , AlignLeftAttribute ) ,
799
+ } ,
800
+ CommonStyleAffectingAttributeInfo {
801
+ atom : atom ! ( "align" ) ,
802
+ mode : AttrIsEqualMode ( "center" , AlignCenterAttribute ) ,
803
+ } ,
804
+ CommonStyleAffectingAttributeInfo {
805
+ atom : atom ! ( "align" ) ,
806
+ mode : AttrIsEqualMode ( "right" , AlignRightAttribute ) ,
807
+ }
808
+ ]
809
+ }
810
+
764
811
/// Determines whether the given element matches the given single selector.
765
812
///
766
813
/// NB: If you add support for any new kinds of selectors to this routine, be sure to set
@@ -781,7 +828,6 @@ pub fn matches_simple_selector<'a,E,N>(selector: &SimpleSelector,
781
828
}
782
829
783
830
NamespaceSelector ( ref namespace) => {
784
- * shareable = false ;
785
831
let element = element. as_element ( ) ;
786
832
element. get_namespace ( ) == namespace
787
833
}
@@ -799,11 +845,26 @@ pub fn matches_simple_selector<'a,E,N>(selector: &SimpleSelector,
799
845
}
800
846
801
847
AttrExists ( ref attr) => {
802
- * shareable = false ;
848
+ // NB(pcwalton): If you update this, remember to update the corresponding list in
849
+ // `can_share_style_with()` as well.
850
+ if common_style_affecting_attributes ( ) . iter ( ) . all ( |common_attr_info| {
851
+ !( common_attr_info. atom == attr. name && match common_attr_info. mode {
852
+ AttrIsPresentMode ( _) => true ,
853
+ AttrIsEqualMode ( ..) => false ,
854
+ } )
855
+ } ) {
856
+ * shareable = false ;
857
+ }
803
858
element. match_attr ( attr, |_| true )
804
859
}
805
860
AttrEqual ( ref attr, ref value, case_sensitivity) => {
806
- if value. as_slice ( ) != "DIR" {
861
+ if value. as_slice ( ) != "DIR" &&
862
+ common_style_affecting_attributes ( ) . iter ( ) . all ( |common_attr_info| {
863
+ !( common_attr_info. atom == attr. name && match common_attr_info. mode {
864
+ AttrIsEqualMode ( target_value, _) => target_value == value. as_slice ( ) ,
865
+ AttrIsPresentMode ( _) => false ,
866
+ } )
867
+ } ) {
807
868
// FIXME(pcwalton): Remove once we start actually supporting RTL text. This is in
808
869
// here because the UA style otherwise disables all style sharing completely.
809
870
* shareable = false
@@ -853,15 +914,15 @@ pub fn matches_simple_selector<'a,E,N>(selector: &SimpleSelector,
853
914
element. get_link ( ) . is_some ( )
854
915
}
855
916
Link => {
856
- * shareable = false ;
857
917
let elem = element. as_element ( ) ;
858
918
match elem. get_link ( ) {
859
919
Some ( url) => !url_is_visited ( url) ,
860
920
None => false ,
861
921
}
862
922
}
863
923
Visited => {
864
- * shareable = false ;
924
+ // NB(pcwalton): When we actually start supporting visited links, remember to update
925
+ // `can_share_style_with`.
865
926
let elem = element. as_element ( ) ;
866
927
match elem. get_link ( ) {
867
928
Some ( url) => url_is_visited ( url) ,
@@ -947,6 +1008,7 @@ fn url_is_visited(_url: &str) -> bool {
947
1008
// FIXME: implement this.
948
1009
// This function will probably need to take a "session"
949
1010
// or something containing browsing history as an additional parameter.
1011
+ // NB(pcwalton): When you implement this, remember to update `can_share_style_with`!
950
1012
false
951
1013
}
952
1014
0 commit comments