W3C

CSS Presentation Levels Module

[LONGSTATUS] [DATE]

This version:
[VERSION]
Latest version:
https://www.w3.org/TR/css3-preslev
Previous version:
https://www.w3.org/TR/2014/NOTE-css3-preslev-20141014/
Feedback:
www-style@w3.org with subject line “[css-preslev] … message topic …” (archives)
Editors:
Ian Hickson <ian @hixie.ch>
HÃ¥kon Wium Lie <howcome @opera.com>
Bert Bos (W3C) <bert @w3.org>

[Here will be included the file "../copyright.inc"]


Abstract

Presentation levels are integer values attached to elements in a document. Elements that are below, at, or above a certain threshold can be styled differently. This feature has two compelling use cases. First, slide presentations with transition effects can be described. For example, list items can be progressively revealed by sliding in from the side. Second, outline views of documents, where only the headings to a certain level are visible, can be generated.

Status of This Document

At this time, the CSS Working Group does not envisage further work on this specification and does not plan to propose it as a W3C Recommendation.

The model

Content reuse has been one of the main motivations for the development of style sheets. By associating documents with different style sheets, the same content can be presented in different ways. The introduction of presentation levels in CSS adds functionality which is very useful in two particular settings. First, slide presentations with transition effects can be described. For example, list items can be progressively revealed by sliding in from the side. Second, outline views of documents, where only the headings to a certain level are visible, can be generated.

The model behind presentation levels is simple. Each element in the document is assigned an integer value which is referred to as the "element's presentation level" (EPL). The EPL can be set explicitly in a style sheet or calculated automatically based on the element's position in the document structure: it is specified by the computed value of the 'presentation-level' property. The User Agent maintains another integer value which is called the User Agent Presentation Value (UAPL). The UAPL starts at a UA-defined value, typically 0.

All elements are in one of three presentation pseudo-classes: 'below-level', 'at-level', and 'above-level'. These pseudo-classes refer to whether the element's EPL was below, at, or above the UAPL the last time the UAPL changed. When an element's state is evaluated, the EPL is compared to the UAPL and pseudo-classes are assigned as follows: If the EPL is equal to 0, the element is always in the below-level state. If the EPL is lower than the UAPL value, it is set to the 'below-level' state, if the EPL is exactly that value it is set to 'at-level', and if the EPL is greater than that value it is set to 'above-level'.

Here is an example of a style sheets using the presentation pseudo-classes:

  :below-level { color: black }
  :at-level { color: red }
  :above-level { color: silver }

This proposal does not describe the user interface of presentation levels. The user agent will need to provide a user interface for setting the UAPL. For example, in projection mode, a user agent may increase the UAPL every time the user hits the space bar. When the user moves to another page (for example by following a hyperlink), the user agent may set the UAPL to be the same as presentation level of the first element on the page. In outline mode, the user agent may provide a vertical slider on the side to increase/decrease the UAPL.

The 'presentation-level' property

Name: presentation-level
Value: <integer> | same | increment
Initial: 0
Applies to: all elements
Inherited: yes
Percentages: N/A
Computed value: integer

User Agents are expected to support this property on all media, including non-visual ones.

This property sets the element's presentation level (EPL). The values have the following meanings:

Example 1: progressively revealing list items

Here is an example of how presentation levels can be used to progressively reveal list items while high-lighting the current one.

                                                   EPL value
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>                                             0
<STYLE>                                            0
  html { color: black; background: white }
  @media projection {
    h1 { page-break-before: always }
    li { presentation-level: increment }
    :below-level { color: black }
    :at-level { color: red }
    :above-level { color: silver }
  }
</STYLE>
<BODY>                                             0
<H1>Strategies</H1>                                0
<H2>Our strategy</H2>                              0
<UL>                                               0
  <LI>divide                                       1
  <LI>conquer                                      2
  <P>(in that order)                               2
</UL>
<H2>Their strategy</H2>                            0
<UL>                                               0
  <LI>obfuscate                                    1
  <LI>propagate                                    2
</UL>

In the example above, the LI elements' EPL value is increased with one compared to the previous element. The other elements' EPL value is the same as the previous element due to the initial 'same' value of the 'presentation-level' property.

Example 2: presenting outline views of a document

Here is an example of how presentation levels can be used to present outline views of a document:

                                                   EPL value
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>                                             0
<STYLE>   
   h1 { presentation-level: 0; }
   h2 { presentation-level: 1; }
   h3 { presentation-level: 2; }
   body * { presentation-level: 3; }
   :above-level { display: none; }
</STYLE>
<BODY>                                             0
<H1>Strategies</H1>                                3
<H2>Our strategy</H2>                              2
<UL>                                               0
<LI>divide                                         0
<LI>conquer                                        0
<P>(in that order)                                 0
</UL>
<H2>Their strategy</H2>                            2
<UL>                                               0
<LI>obfuscate                                      0
<LI>propagate                                      0
</UL>

Presentation levels and the DOM

An element's state is first evaluated when it is created. When the UAPL is changed, all elements in the document have their state reevaluated. A CSSNowBelowLevel event is then sent to all elements that changed to the 'below-level' state, a CSSNowAtLevel event is then sent to all elements that changed to the 'at-level' state, and a CSSNowAboveLevel event is then sent to all elements that changed to the 'above-level' state. Changing an element's 'presentation-level' property, e.g. through the DOM or using a dynamic pseudo-class, does not cause the element's state to be immediately reevaluated.

These events have the following characteristics:

SMIL can be used with this event to declaratively key animations from user requests, based on the 'presentation-index' property.

The events are defined as:

   interface CSSNowBelowLevel : UIEvent { }
   interface CSSNowAtLevel : UIEvent { }
   interface CSSNowAboveLevel : UIEvent { }

These three fragments together will cause a document to have three user-triggered list items, which will scroll in one at a time each time the user hits the space bar (or whatever mechanism the UA uses), with the current item colored white and the past items colored gray.

Markup:

    <ol>
     <li> The Separation of Style and Structure </li>
     <li> Declarative User Interaction </li>
     <li> Potential for Animation </li>
    </ol>

Stylesheet:

     ol { overflow: hidden; }
     li { presentation-level: increment; margin-left: 100%; }
     li:at-level { color: white; }
     li:above-level { color: silver; }

Script:

    // When the element is shown, scroll it in from the right
    // by animating the margin-left property from 100% to 0%
    document.documentElement.addEventListener('CSSNowAtLevel', handler, false);

    function handler(event) {
      // animateFloat is a (fictional) library routine which takes
      // five arguments:
      //  a CSSValue to animate
      //  the start value
      //  the end value
      //  the time over which to animate the property, in milliseconds
      //  the units to animate it with
      // it returns straight away and performs the animation in the
      // background.
      animateFloat(document.getOverrideStyle(event.target,
                                  null).getPropertyCSSValue('margin-left'),
                   100, 0, 1000, CSS_PERCENTAGE);
    }