@@ -370,9 +370,9 @@ $(function() {
370370 too.
371371
372372 In the context of this class, visual objects can be of one of the
373- following four kinds: primary, secondary, unknown and container. A
374- visual object is a certain DOM node in the tree. Section boundaries
375- and hierarchy has no relation to the DOM hierarchy.
373+ following four kinds: primary, secondary, heading, unknown and
374+ container. A visual object is a certain DOM node in the tree. Section
375+ boundaries and hierarchy has no relation to the DOM hierarchy.
376376
377377 Primary
378378
@@ -386,8 +386,17 @@ $(function() {
386386
387387 Secondary
388388
389- Secondary objects don't affect the visibility of sections. Secondary
390- objects do not contain other objects.
389+ Secondary objects don't affect the visibility of sections if there are
390+ primary on unknown elements in it. If the section contains only
391+ secondary elements, it is are hidden if all secondary elements are
392+ hidden.
393+
394+ Secondary objects do not contain other objects.
395+
396+ Heading
397+
398+ Heading elements never affect the visibility of sections. All other
399+ elements in the section are hidden, headings are hidden too.
391400
392401 Container
393402
@@ -423,9 +432,10 @@ $(function() {
423432 var ObjectType = {
424433 PRIMARY : 0 ,
425434 SECONDARY : 1 ,
426- UNKNOWN : 2 ,
427- SECTION : 3 ,
428- CONTAINER : 4
435+ HEADING : 2 ,
436+ UNKNOWN : 3 ,
437+ SECTION : 4 ,
438+ CONTAINER : 5
429439 } ;
430440
431441 // internal classes for SectionContentsTracker
@@ -507,8 +517,13 @@ $(function() {
507517 } ;
508518
509519 // Adds a secondary object to the current section and container
510- SectionContentsTracker . prototype . add_secondary = function ( obj ) {
511- this . add_object ( obj , ObjectType . SECONDARY , null ) ;
520+ SectionContentsTracker . prototype . add_secondary = function ( obj , visible ) {
521+ this . add_object ( obj , ObjectType . SECONDARY , visible ) ;
522+ } ;
523+
524+ // Adds a heading object to the current section and container
525+ SectionContentsTracker . prototype . add_heading = function ( obj ) {
526+ this . add_object ( obj , ObjectType . HEADING , null ) ;
512527 } ;
513528
514529 // Adds an unknown object to the current section and container
@@ -532,25 +547,46 @@ $(function() {
532547 // Recursively evaluates visibility of a section object
533548 SectionContentsTracker . prototype . eval_section_visibility = function ( obj ) {
534549 var visible = new VisibilityMap ( ) ;
550+ var secondary_visible = new VisibilityMap ( ) ;
535551 var i , child ;
552+ var has_non_secondary = false ;
553+
536554 for ( i = 0 ; i < obj . children . length ; i ++ ) {
537555 child = obj . children [ i ] ;
538556 switch ( child . type ) {
539557 case ObjectType . PRIMARY :
540558 case ObjectType . UNKNOWN :
541559 visible . combine_or ( child . visible ) ;
560+ has_non_secondary = true ;
561+ break ;
562+ case ObjectType . SECONDARY :
563+ secondary_visible . combine_or ( child . visible ) ;
542564 break ;
543- case ObjectType . SECONDARY : // ignoring secondary objects
565+ case ObjectType . HEADING :
544566 break ;
545567 case ObjectType . SECTION :
546568 visible . combine_or ( this . eval_section_visibility ( child ) ) ;
569+ has_non_secondary = true ;
547570 break ;
548571 }
549572 }
550573
574+ if ( has_non_secondary ) {
575+ // Apply the resolved visibility to secondary children elements, if any
576+ for ( i = 0 ; i < obj . children . length ; i ++ ) {
577+ child = obj . children [ i ] ;
578+ if ( child . type === ObjectType . SECONDARY ) {
579+ child . visible = visible ;
580+ }
581+ }
582+ } else {
583+ visible = secondary_visible ;
584+ }
585+
586+ // Apply the resolved visibility to heading children elements, if any
551587 for ( i = 0 ; i < obj . children . length ; i ++ ) {
552588 child = obj . children [ i ] ;
553- if ( child . type === ObjectType . SECONDARY ) {
589+ if ( child . type === ObjectType . HEADING ) {
554590 child . visible = visible ;
555591 }
556592 }
@@ -589,8 +625,8 @@ $(function() {
589625 return visible_mask ;
590626 } ;
591627
592- // Recursively evaluates the contents of a container and hides container
593- // and secondary elements if needed. visible_mask identifies which
628+ // Recursively evaluates the contents of a container and hides container,
629+ // heading and secondary elements if needed. visible_mask identifies which
594630 // revisions the object may be visible in certain revision (it may not be
595631 // visible in case parent container is not visible).
596632 SectionContentsTracker . prototype . perform_hide = function ( obj , tracker , visible_mask ) {
@@ -607,6 +643,7 @@ $(function() {
607643 this . perform_hide ( child , tracker , visible_mask ) ;
608644 break ;
609645 case ObjectType . SECONDARY :
646+ case ObjectType . HEADING :
610647 this . perform_hide_obj ( child , tracker , visible_mask ) ;
611648 break ;
612649 }
@@ -634,6 +671,8 @@ $(function() {
634671 return this . debug_obj_impl ( obj , 'secondary object' , level ) ;
635672 case ObjectType . UNKNOWN :
636673 return this . debug_obj_impl ( obj , 'unknown object' , level ) ;
674+ case ObjectType . HEADING :
675+ return this . debug_obj_impl ( obj , 'heading object' , level ) ;
637676 }
638677 return '' ;
639678 } ;
@@ -864,7 +903,7 @@ $(function() {
864903 rev_elems . each ( function ( ) {
865904 var visible = get_visibility_map ( $ ( this ) ) ;
866905 visible . add ( Rev . DIFF ) ;
867- total_visible . combine_or ( visible ) ;
906+ table_visible . combine_or ( visible ) ;
868907
869908 self . tracker . add_diff_object ( $ ( this ) , visible ) ;
870909 } ) ;
@@ -895,10 +934,19 @@ $(function() {
895934
896935 // Returns true if the given jQuery object defines a secondary visual object
897936 StandardRevisionPlugin . prototype . is_secondary = function ( el ) {
937+ if ( el . is ( 'p' ) ||
938+ el . is ( '.t-rev-begin' ) )
939+ {
940+ return true ;
941+ }
942+ return false ;
943+ } ;
944+
945+ // Returns true if the given jQuery object defines a heading visual object
946+ StandardRevisionPlugin . prototype . is_heading = function ( el ) {
898947 if ( el . is ( 'h2' ) ||
899948 el . is ( 'h3' ) ||
900949 el . is ( 'h5' ) ||
901- el . is ( 'p' ) ||
902950 ( el . is ( 'tr' ) && el . has ( 'td > h5' ) . length ) ||
903951 el . is ( '.t-dsc-header' ) )
904952 {
@@ -956,13 +1004,17 @@ $(function() {
9561004 // elements. Note that the set of primary elements may be
9571005 // expanded in the future.
9581006 self . prepare_dsc_table ( section_tracker , el ) ;
959- } else {
960- self . set_level_if_needed ( section_tracker , el ) ;
961- if ( self . is_secondary ( el ) ) {
962- section_tracker . add_secondary ( el ) ;
1007+ } else if ( self . is_secondary ( el ) ) {
1008+ if ( el . is ( '.t-rev-begin' ) ) {
1009+ section_tracker . add_secondary ( el , el . data ( 'visible' ) ) ;
9631010 } else {
964- section_tracker . add_unknown ( el ) ;
1011+ section_tracker . add_secondary ( el , visibility_fill ( true ) ) ;
9651012 }
1013+ } else if ( self . is_heading ( el ) ) {
1014+ self . set_level_if_needed ( section_tracker , el ) ;
1015+ section_tracker . add_heading ( el ) ;
1016+ } else {
1017+ section_tracker . add_unknown ( el ) ;
9661018 }
9671019 } ) ;
9681020 section_tracker . run ( this . tracker ) ;
@@ -978,13 +1030,13 @@ $(function() {
9781030 var el = $ ( this ) ;
9791031 if ( el . is ( '.t-dsc' ) ) {
9801032 section_tracker . add_primary ( el , self . prepare_dsc ( el ) ) ;
981- } else {
1033+ } else if ( self . is_secondary ( el ) ) {
1034+ section_tracker . add_secondary ( el , visibility_fill ( true ) ) ;
1035+ } else if ( self . is_heading ( el ) ) {
9821036 self . set_level_if_needed ( section_tracker , el ) ;
983- if ( self . is_secondary ( el ) ) {
984- section_tracker . add_secondary ( el ) ;
985- } else {
986- section_tracker . add_unknown ( el ) ;
987- }
1037+ section_tracker . add_heading ( el ) ;
1038+ } else {
1039+ section_tracker . add_unknown ( el ) ;
9881040 }
9891041 } ) ;
9901042 section_tracker . exit_container ( ) ;
@@ -1742,7 +1794,9 @@ $(function() {
17421794 var rev = parseInt ( this . select . val ( ) ) ;
17431795 this . tracker . to_rev ( rev ) ;
17441796
1745- // special treatment for rev boxes
1797+ // special treatment for rev boxes. Since these containers are very
1798+ // simple, we can apply a CSS class to hide the border and rev markers
1799+ // on non-diff revision.
17461800 if ( this . curr_rev === Rev . DIFF && rev !== Rev . DIFF ) {
17471801 this . for_all_scopes ( function ( ) {
17481802 this . rev_tables . each ( function ( ) {
0 commit comments