Selecting a media type on bandwidth-constrained handheld devices

Opera Working Draft, July 17th 2003

Editor:
Ian Hickson, Opera Software, ian@hixie.ch

Abstract

Users of handheld devices expect the Web to the same on their devices as it is on desktops.

Authors of Web sites expect specific control over the rendering of pages on handhelds.

Most Web sites are not designed for handheld devices, so a user stylesheet mode must be provided.

This document describes the technique used to select which mode a bandwidth-constrained handheld device should use.

Table of Contents


1. Introduction

This specification describes three modes of operation.

handheld mode
The preferred mode for handheld devices, this is the spec-compliant handling of CSS stylesheets applied to the document in the context of the handheld media type.
screen mode
In the absence of handheld stylesheets, users should be given the opportunity to switch to this mode, in which the document's CSS stylesheets are applied to the document in the context of the screen media type.
SSR mode
Technically the mode (for which the CSS specifications require support) in which author stylesheets are disabled and the UA uses a custom stylesheet to render the content. This mode is used in preference to the screen mode when the page is not using a mobile DTD and there are no handheld stylesheets available, and is also available from handheld mode in case the handheld stylesheet is unreadable (an unfortunately common occurrence).

2. Mode Selection

There are two features of documents that should be used to decide which mode to use.

2.1. Handheld Stylesheets

When loading a page, the UA must see if any of the embedded inline stylesheets, as well as any links to external stylesheets, mention the handheld media type. This is done without fetching any additional resources. Specifically, this means that during the page load the UA must look for:

  1. A value of handheld in the comma separated media pseudo-attribute of <?xml-stylesheet?> PIs.
  2. A value of handheld in the comma separated media attribute of <link> elements that have a value of stylesheet in their space-separated rel attribute.
  3. A value of handheld in the comma separated media attribute of <style> elements.
  4. An @import or @media rule that mentions the handheld media type in a <style type="text/css"> element with a media of all (the default).
  5. If we support HTTP links, then media="handheld" in an HTTP Link header with stylesheet in its space-separated rel attribute.

Specifically, in the first three cases, UAs should not take into account the type attributes, UAs should not take into account if the stylesheets are alternates or persistent, and UAs should not download the files to check they mention handheld.

Note that links to stylesheets that use the data: URI scheme must be considered external stylesheets and are not parsed during this exploratory stage. Similarly, even if the external stylesheets are available in the cache, they must be ignored during this stage. In particular, if a document has a single external stylesheet with media="all" containing an @media "handheld" {} block, thus triggering SSR mode (no handheld in the main document), then, if the user switches to screen mode, then goes to another document, then returns to the first document, the UA should not switch into handheld mode, even though it technically knows that there is handheld style on the page (since the stylesheet will be in the cache).

2.2. Mobile DTDs

In addition to checking the given media types to decide whether the page should be in handheld mode, the UA should also check for certain DTDs to decide whether to avoid going into SSR mode, regardless of the handheld mode setting. The following languages should trigger normal, non-SSR mode:

Compact HTML
Anything with a DOCTYPE exactly matching <!DOCTYPE HTML PUBLIC "-//W3C//DTD Compact HTML 1.0 Draft//EN">.
XHTML Mobile Profile
Anything with a MIME type of application/vnd.wap.xhtml+xml (ignoring any MIME type attributes such as 'charset'); anything with a MIME type of application/xhtml+xml if it has the attribute profile with the exact value "http://www.wapforum.org/xhtml" (as in application/xhtml+xml;profile="http://www.wapforum.org/xhtml", but other attributes, such as 'charset', shouldn't affect whether it matches or not — note that MIME types and MIME parameters are case insensitive, but MIME parameter values are not); or, for content sent as text/html, anything with a DOCTYPE exactly matching either <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> or <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.1//EN" "http://www.wapforum.org/DTD/xhtml-mobile11.dtd">.
WML
Anything with a DOCTYPE exactly matching either <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"> or <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD WML 2.0//EN" "http://www.wapforum.org/DTD/wml20.dtd">. MIME types are not used to detect WML because all WML documents must start with one of those DOCTYPEs and thus the MIME type check would be redundant.

Comparing DOCTYPEs should be done by parsing the DOCTYPE string as follows. First, the string <!DOCTYPE should be matched, case insensitively. Then, one or more whitespace characters should be skipped, and the string html should be matched case insensitively for CHTML, and case sensitively for WML and XHTML. Then, one or more whitespace characters should be skipped, and the string PUBLIC should be matched case insensitively. Then again, one or more whitespace characters should be skipped, and the FPI, delimited by matching quotes (either " or ') should be matched exactly (case sensitively). Then, for WML and XHTML, but not for CHTML, whitespace characters should be skipped, and then another string, delimited by matching quotes again, should be skipped. Finally, for all DOCTYPEs, a character ">" should be matched.

If any of the above fails to match, then the DOCTYPE is not considered to be an exact match.

3. Mode Handling

After having checked all these possibilities:

  1. If the UA has found no trace of any handheld styles and no mobile DTDs, then it should switch to SSR mode, and give the user the option to use screen as the media type.
  2. If the UA found some handheld style using the steps above, then it should use the handheld media type, and give the user the option to switch to SSR mode.
  3. If the UA found no handheld style but did find a mobile DTD, then it should use the screen media type, and give the user the option to switch to SSR mode.

When the device is not in SSR mode all stylesheets that apply to the chosen media type, including any that are linked using the all media and those that are mentioned in the document before the mention of handheld, must be applied. For example, if an all stylesheet is linked before a screen, handheld stylesheet, then the all stylesheet should still be used while in handheld mode).

4. Compliance

In terms of the CSS specification, this model is compliant, with the liberal interpretation being that the device's media type is selected after loading the stylesheet instead of being constant.