<pre class='metadata'>
Title: CSS Round Display Module Level 1
Level: 1
Status: ED
Work Status: Exploring
ED: https://drafts.csswg.org/css-round-display/
Shortname: css-round-display
TR: https://www.w3.org/TR/css-round-display-1/
Group: csswg
Previous Version: https://www.w3.org/TR/2016/WD-css-round-display-1-20161222/
Previous Version: https://www.w3.org/TR/2016/WD-css-round-display-1-20160301/
Previous Version: https://www.w3.org/TR/2015/WD-css-round-display-1-20150922/
Editor: Hyojin Song, LG Electronics, hyojin22.song@lge.com, w3cid 54503
Editor: Jihye Hong, LG Electronics, jh.hong@lge.com, w3cid 79168
Editor: Soonbo Han (until June 2015), LG Electronics, soonbo.han@lge.com, w3cid 45470
Abstract: This document describes CSS extensions to support a round display. The extensions help web authors to build a web page suitable for a round display.
</pre>
<pre class=link-defaults>
spec:css-shapes-1; type: type; text:<basic-shape>
</pre>

<style>
/* example in table layout*/
.example-table {
    display:table;
    margin: 0 auto 1em; 
    border-spacing: 2em 0; 
    min-width: 672px;
}
.example-table > .desc {
    display: table-cell;
    vertical-align: top;
    width: 250px;
    text-align: center;
}
</style>

Introduction {#introduction}
==================================================

Conventionally, web pages have been shown through a rectangular screen such as PC, tablet, and smart phone. The window content area in a web browser is a rectangle. Each HTML element follows the W3C box model and thus is also a rectangle.
<br>
Nowadays, devices come in varied shapes of the displays.
It needs to consider the shape of the display when implementing web pages on devices.
However, current web standards lack some features to support the devices as follows:
<ol>
    <li>Lack of the capability to detect the shape of a display</li>
    <li>Lack of layout mechanisms suitable for the shape of a display</li>
</ol>
In order to facilitate the use of the web especially on a round display, there could be some features to support it.

The '@media/shape' media feature is added to Media Queries.
Current user agents are not capable of detecting the shape of a display so that authors cannot apply various layouts for a round display. To resolve the issue, '@media/shape' informs the web page of the property regarding the shape of the display.
<br><br>
To apply the shape of a display to content area, we extend the 'shape-inside' property of CSS Shapes. The position of the element which is overflowed from the display is adjusted inside the display when using this property even if the authors don’t know the exact shape of the display.
<br><br>
We also add the 'border-boundary' property to CSS Backgrounds and Borders. The borders of the element can be drawn along the edge of the display even if the element is overflowed.
<br><br>

This module provides features such as:

    * Detecting the rounded display
    * Aligning contents in the display’s shape
    * Drawing borders along the display’s edge

Value Definitions {#values}
-----------------

This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS21]]
using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Values &amp; Units [[!CSS-VALUES-3]].
Combination with other CSS modules may expand the definitions of these value types.

In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> as their property value.
For readability they have not been repeated explicitly.

Terminology {#terminology}
==================================================

This specification follows the CSS property definition conventions from [[!CSS21]]. <br/>
The detailed description of Media Queries is defined in [[MEDIAQUERIES-4]]<br/>
The detailed description of CSS Shapes is defined in [[CSS-SHAPES-2]]<br/>
The detailed description of Backgrounds and Borders is defined in [[CSS3BG]]<br/>
The detailed description of Positioned Layout is defined in [[CSS3-POSITIONING]]<br/>

Detecting the shape of the display {#extending-media-queries}
==================================================

Media Queries [[MEDIAQUERIES-4]] define mechanisms to support media-dependent style sheets, 
tailored for different environments. We propose to extend Media Queries 
by adding the '@media/shape' media feature to support various types of displays.
This will allow web authors to apply different styles to a web page on the rounded display.

<h3 id="shape-media-feature">The '@media/shape' media feature</h3>

<pre class='descdef mq'>
    Name: shape
    Type: discrete
    For: @media
    Value: rect | round
</pre>

Describes the general shape of the targeted display area of the output device.
It accepts the following values:

    <dl dfn-type=value dfn-for="@media/shape">
        <dt><dfn>rect</dfn>
        <dd>
            The shape is an axis aligned rectangle or square, or a similar shape 
            such as rounded rectangle for which the traditional designs are appropriate.

        <dt><dfn>round</dfn>
        <dd>
            The shape is rounded or a similar shape to the circle such as an oval, an ellipse for which distinctively rounded designs are appropriate.
    </dl>

<div class='example'>
    The following examples show what '@media/shape' media feature can do when the web page
    is on the various shapes of displays.
    The sample web page is a simple clock application written in HTML and seen through
    the rectangular display and the rounded display.

    In the first example, the clock application doesn't implemented with '@media/shape' media feature,
    so it can't deal with different types of displays.
    It only uses 'rectangle.css' which is designed for the rectangular display
    no matter what the type of the display is.
    On the round display, some parts of the clock application would be clipped.

    <pre class="lang-html">
    &lt;!DOCTYPE html>
    &lt;html>
    &lt;head>
        &lt;link rel="stylesheet" href="rectangle.css" />
    &lt;/head>
    &lt;body>
        &lt;div id="clockLayer">
            &lt;div id="clockLayer">
                &lt;div id="date">2015/02/28 (SAT)&lt;/div>
                &lt;div id="time">10:11&lt;/div>
                &lt;div id="weather">&lt;img src="cloudy.png" />&lt;/div>
            &lt;/div>
        &lt;/div>
    &lt;/body>
    &lt;/html>
    </pre>

    <figure>
        <div class="example-table">
            <div class="desc">
                <img src="images/device_radius_clock_a.png" width="330" height="330"
                     alt="An image of a clock within a rectangle display">
                <p>(A) Rectangle Display</p>
            </div>
            <div class="desc">
                <img src="images/device_radius_clock_b.png" width="330" height="330"
                     alt="An image of a clock within a round display">
                <p>(B) Round Display</p>
            </div>
        </div>
        <figcaption>
            Clock Application without the '@media/shape' media feature
        </figcaption>
    </figure>

    On the other hand, in the second example, the clock application uses '@media/shape' media feature.
    The following media queries are added to the code of the clock application from
    the first example.

    <pre class="lang-html">
    &lt;!-- index.html -->
    &lt;head>
        &lt;link media="screen and (shape: rect)" rel="stylesheet" href="rectangle.css" />
        &lt;link media="screen and (shape: round)" rel="stylesheet" href="round.css" />
    &lt;/head>
    </pre>

    If the clock application is loaded in a round display, 'round.css' which is the design for
    the round display will be applied by the Media Queries mechanism.

    <figure>
        <div class="example-table">
            <div class="desc">
                <img src="images/device_radius_clock_a.png" width="330" height="330"
                     alt="An image of a clock within a rectangle display">
                <p>(A) Rectangle Display<br>(when 'shape: rect' returns ''true'')</p>
            </div>
            <div class="desc">
                <img src="images/device_radius_clock_c.png" width="330" height="330"
                     alt="An image of a clock within a round display">
                <p>(B) Round Display<br>(when 'shape: round' returns ''true'')</p>
            </div>
        </div>
        <figcaption>
            Clock Application with the '@media/shape' media feature
        </figcaption>
    </figure>
</div>
<p class="note">
Note: So far, the only standard APIs of Operating System which exposes 
information about the display's shape is 
<a href="https://developer.android.com/reference/android/content/res/Configuration.html?hl=es#isScreenRound%28%29">''isScreenRound()'' API</a>
in Android. 
<a href="https://developer.android.com/reference/android/content/res/Configuration.html?hl=es#isScreenRound%28%29">''isScreenRound()'' API</a>
 returns a boolean that says round or not.<br>
Referred the semantics of this API, when isScreenRound() returns ''true'', ''shape: round'' should evaluate
 to ''true''
and ''shape: rect'' should evaluate to ''false'' when isScreenRound() returns ''false''.<br>
'@media/shape' is dealing with 2 shapes, but it can be extended if there are the needs about
configuring other shapes from the developers.
</p>
<p class="note">Note: There are cases when the UA may know the shape even in the absence of OS APIs. 
For example, when rendering to PDF, the shape is known to be a rectangle, so 'shape: rect' evaluates to
 ''true'' while ''shape: round'' to ''false''
</p>

Extending the viewport <code class=html>&lt;meta&gt;</code> element {#extending-viewport-meta}
==================================================

<h3 id="viewport-fit-property">The [=viewport-fit=] property</h3>

The <dfn export><code class="index">viewport-fit</code></dfn> property is recognized in the
[[css-viewport#viewport-meta]].
[=viewport-fit=] can set the size of the layout viewport.

On rounded screen, the part of the page that’s currently shown on-screen is round but
the viewport is rectangular.
Because of this, depending on the size of the viewport, some part of the page may be clipped.

<figure>
    <img src="images/viewport_clipped_area.png" width="680" height="798" style="width: 250px"
         alt="An image of the clipped area between the viewport bounding box and the device's border">
    <figcaption>
        Clipped area
    </figcaption>
</figure>

[=viewport-fit=] can control the clipped area by setting the size of the layout viewport.

Values have the following meanings:

<dl dfn-type=value dfn-for=viewport-fit>
    <dt><dfn>auto</dfn></dt>
    <dd>
        This value doesn’t affect the initial layout viewport, 
        and the whole web page is viewable.
        What the UA paints outside of the viewport is undefined. 
        It may be the background color of the canvas, or anything else 
        that the UA deems appropriate.
    </dd>

    <dt><dfn>contain</dfn></dt>
    <dd>
        The initial layout viewport and the visual viewport are set to the largest rectangle 
        which is inscribed in the display of the device.
        What the UA paints outside of the viewport is undefined. 
        It may be the background color of the canvas, or anything else that
        the UA deems appropriate.
    </dd>
    <p class="note">Note: With this value, 'border-boundary: display' and 
    'shape-inside: display' have no effect.</p>

    <dt><dfn>cover</dfn></dt>
    <dd>
        The initial layout viewport and the visual viewport are set to the circumscribed 
        rectangle of the physical screen of the device.
    </dd>
</dl>

When setting the size of the bounding box for the viewport on the non-rectangular display, we have to consider the factors like below:

<ul>
    <li>Clipped area which is caused because the area of the viewport bounding box is larger than the area of the display</li>
    <li>Gap between the bounding box for the viewport and the area of the display</li>
</ul>
    
The author can decide which factor is more critical than another. 
If it have to be guaranteed that any part of the web page isn’t hidden, avoiding clipping is more important than having a gap between the bounding box of the viewport and the border of the screen. If the author doesn’t want web pages to be small for the readability, then it would be better to set [=viewport-fit=] as <a href="#valdef-viewport-fit-cover">cover</a> and to implement pages with considering the clipped parts.

<div class='example'>

    This example shows the size of the bounding box for the viewport specified with [=viewport-fit=] on the rounded display.
    
    When the [=viewport-fit=] is specified with <a href="#valdef-viewport-fit-contain">contain</a>, the initial viewport is applied to the largest inscribed rectangle of the display.

    <pre class="lang-html">
    &lt;meta name="viewport" content="viewport-fit=contain"&gt;
    </pre>

    <figure>
        <img src="images/viewport_fit_contain.png" width="636" height="721" style="width: 300px; text-align: center"
             alt="An image about the viewport applied to the bounding box specified with 'viewport-fit: contain'">
        <figcaption>
            With '<code>viewport-fit: contain</code>'
        </figcaption>
    </figure>

    When <a href="#valdef-viewport-fit-cover">cover</a> is given to the [=viewport-fit=], the initial viewport is applied to the circumscribed rectangle of the display.

    <pre class="lang-html">
    &lt;meta name="viewport" content="viewport-fit=cover"&gt;
    &lt;style&gt;
        @media (shape: round){
            /* styles for the round design */
        }
        @media (shape: rect){
            /* styles for the rectangular design */
        }
    &lt;/style&gt;
    </pre>

    <figure>
        <img src="images/viewport_fit_cover.png" width="656" height="711" style="width: 300px; text-align: center"
             alt="An image about the viewport applied to the bounding box specified with 'viewport-fit: cover'">
        <figcaption>
            With '<code>viewport-fit: cover</code>'
        </figcaption>
    </figure>    
</div>

Aligning content along the display border {#aligning-content}
==================================================

<h3 id="shape-inside-property">The 'shape-inside' property</h3>

CSS Shapes [[CSS-SHAPES-2]] define the 'shape-inside' property that aligns contents along the edge of a possibly non-rectangular wrapping area. Web authors may use this feature to fit contents inside a round display. However, it can be challenging to specify the wrapping area to be identical to the shape of a display. To address such cases, 'shape-inside' is extended with a new value named '<code>display</code>', such an element having this value will have its content (or contained elements) aligned along the display border automatically.

<pre class='link-defaults'>
spec:css2; type:type; text:<uri>
</pre>
<pre class='propdef'>
    Name: shape-inside
    Applies to: block-level elements
    Value: auto | outside-shape | [ <<basic-shape>> || shape-box ] | <<image>> | <code>display</code>
    Initial: auto
    Inherited: no
    Computed value: computed lengths for <<basic-shape>>, the absolute URI for <<uri>>, otherwise as specified
    Animation Type: as defined for <<basic-shape>>, otherwise discrete
</pre>

The example below shows how the 'shape-inside' property works when it is set to '<code>display</code>'.
Without using Media Queries, contents can be aligned within the display edge automatically.

<div class='example'>
    <pre class="lang-html">
    &lt;style>
        #container {
            shape-inside: display;
            // the same as circle(50% at 50%, 50%) in a regular round display
        }
        #green-box { float: left; }
        #blue-box { float: right; }
    &lt;/style>
    &lt;div id="container">
        &lt;p>
            Some inline content
            &lt;img id="green-box" src="green-box.jpg" />
            with a float left and float right, in a
            &lt;img id="blue-box" src="blue-box.jpg" />
            simple box with a circle shape-inside.
        &lt;/p>
    &lt;/div>
    </pre>
    <br />

    <figure>
        <div class="example-table">
            <div class="desc">
                <img src="images/shape_inside_watch_a.png" width="330" height="450" style="width: 230px"
                     alt="A layout of web contents without shape-inside:display">
                <p>(A) Without '<code>shape-inside</code>'</p>
            </div>
            <div class="desc">
                <img src="images/shape_inside_watch_b.png" width="330" height="450" style="width: 230px"
                     alt="A layout of web contents with shape-inside: display">
                <p>(B) With '<code>shape-inside: display</code>'</p>
            </div>
        </div>
        <figcaption>
            Align the content along the display border
        </figcaption>
    </figure>
</div>

This property is specially useful for complex shapes (e.g. curved, stelliform, polygonal), that wouldn't be covered by <<basic-shape>> (i.e. circle() or ellipse()), allowing web authors to conveniently align contents with the display edge.

When a containing block is placed on one end of the display and the containing block has 'shape-inside: display', the descendant blocks of the containing block are basically put on the overlapping region between the containing block and the display area. The overlapping region's shape is mostly complicated shape, so it's difficult to define the shape using previous method like basic-shape. The figure 4 describes these circumstances as follows.

<figure>
    <img src="images/shape_inside_a.png" width="500" height="273" style="width: 500px"
         alt="An image of two examples to show the principle of shape-inside: display">
    <figcaption>
        Align the content along the display border
    </figcaption>
</figure>

<p class="issue">
What if content overflows? Clipping or scrolling?
</p>

Drawing borders around the display border {#drawing-borders}
==================================================

<h3 id="border-boundary-property">The 'border-boundary' property</h3>

We add the 'border-boundary' property to set a boundary constraint that affects the borders of an element.

<pre class='propdef'>
    Name: border-boundary
    Applies to: all elements
    Value: none | parent | display
    Initial: none
    Inherited: yes
    Computed value: specified keyword
    Animation type: discrete
</pre>

When the 'border-boundary' property on an element is set to '<code>parent</code>', additional borders of the element could be drawn where the element's area and the borders of its parent are met. When it is set to '<code>display</code>', additional borders could be drawn where the element's area and the borders of screen are met. The default value is '<code>none</code>', imposing no boundary constraint on the borders.

<div class='example'>
The example below shows how the 'border-boundary' property works on drawing borders. The result is shown in Figure 5B.
    <pre class="lang-html">
    &lt;style>
        #container {
            border-boundary: display;
        }
        #redBox {
            border: 5px red solid;
        }
        #greenBox {
            border: 5px green solid;
        }
        #blueBox {
            border: 5px blue solid;
        }
    &lt;/style>
    &lt;div id="container">
        &lt;div id="redBox">&lt;/div>
        &lt;div id="greenBox">&lt;/div>
        &lt;div id="blueBox">&lt;/div>
    &lt;/div>
    </pre>
    <br />

    <figure>
        <div class="example-table">
            <div class="desc">
                <img src="images/border_boundary_a.png" width="300" height="300" style="width: 200px"
                     alt="An image of circle drawing border lines without border-boundary: display">
                <p>(A) Without '<code>border-boundary</code>'</p>
            </div>
            <div class="desc">
                <img src="images/border_boundary_b.png" width="300" height="300" style="width: 200px"
                     alt="An image of circle drawing border lines with border-boundary: display">
                <p>(B) With '<code>border-boundary: display</code>'</p>
            </div>
        </div>
        <figcaption>
            Align the content along the display border
        </figcaption>
    </figure>

</div>

<p class="note">Note: If the value of 'border-boundary' is parent or display, border lines of the element are actually just a visual effect. It triggers a layout for rendering in a general way, but in the above cases (border-boundary: parent|display), the layout doesn't occur and it only draws the border lines inward from the containing block's borders. With this situation, the borders might hide contents around the display edge.
</p>

Use Cases {#usecases}
==================================================

    Use cases are described on
    <a href="https://wiki.csswg.org/ideas/round-display">these</a>.

Changes {#changes}
==================================================

<h3 id="changes_from_December_22_2016">
Changes from <a href="http://www.w3.org/TR/2016/WD-css-round-display-1-20161222/">December 22<sup>th</sup> 2016</a> version</h3>

    <ul>
        <li>Updated [=viewport-fit=] to property of viewport <code class=html>&lt;meta&gt;</code> element.</li>
    </ul>

<h3 id="changes_from_March_01_2016">
Changes from <a href="http://www.w3.org/TR/2016/WD-css-round-display-1-20160301/">March 1<sup>th</sup> 2016</a> version</h3>

    <ul>
        <li>Changed naming of the media query feature for detecting the shape of a display from
            <a href="https://www.w3.org/TR/css-round-display-1/#device-radius-media-feature">''device-radius''</a> to '@media/shape'.</li>
        <li>Defined the value type of '@media/shape' as ''round'' and ''rect''.</li>
        <li>Added [=viewport-fit=] descriptor for ''@viewport'' rule.</li>
        <li>Removed polar positioning and Merged it into Motion Path [[motion-1]].<br>
            The element gets positioned in polar coordinate system using 'offset-path' with the ray function, 'offset-distance', and 'offset-position'.<br>
            (see <a href="https://github.com/w3c/csswg-drafts/issues/214">issue #214</a>)<br>
        </li>
    </ul>

See also <a href="https://www.w3.org/TR/css-round-display-1/#changes_from_Sep_22_2015">previous changes</a>.

Security Considerations {#security-considerations}
==================================================

    There are no known security issues introduced by these features.

Privacy Considerations {#privacy-considerations}
==================================================

    There are no known privacy issues introduced by these features.

Acknowledgements {#acks}
==================================================
    This specification is made possible by input from Dong-Young Lee, Soonbo Han, Florian Rivoal, Joone Hur,
    Kang-Soo Seo, Sangjo Park, Woojun Jung, Chisoon Jeong, Yunbum Sung, Alan Stearns, Brad Kemper, and the CSS Working Group members.
    Thanks also to Adenilson Cavalcanti for editorial input.
