21 September 2011
Note: This article was originally written for the release of AIR 2. It has been updated to include the new features and capabilities of AIR 2.5 and AIR 3.
Adobe AIR 3 includes a number of new APIs and improvements. One of the improvements is the updated HTML engine used in for the HTML-based AIR applications and for displaying HTML content in ActionScript applications.
AIR 3 includes a snapshot of the WebKit branch used in Safari 5.0.3 as well as the latest security fixes. You can review the original source at webkit.org; for the WebKit sources used in AIR go to Adobe Open Source. Thus, in most respects, you can use Safari 5.0.3 as a reference implementation of the behavior you can expect to find in AIR 3.
This article provides an overview of the new features and highlights the differences between the HTML support available in Adobe AIR 3 and in the corresponding WebKit revision. New versions of web browsers also support a new generation of very fast JavaScript engines (Google V8, WebKit SquirrelFish, and Mozilla TraceMonkey) and HTML5. If you are wondering about the JavaScript and HTML capabilities of AIR, or if you want to know whether your favorite features found in WebKit work in AIR, then this article is for you.
This section lists the highlights of the new Safari features.
Table 1. Performance comparison of JavaScript engines
| Operating System / Benchmark | AIR 2.5 | AIR 3 | Safari 5.0.3 |
|---|---|---|---|
| Windows 7 / V8 (higher is better) | 1377 | 1698 | 1870 |
| Windows 7 / SunSpider (lower is better) | 1358 | 1023 | 423 |
| Mac OS X 10.6 / V8 (higher is better) | 2085 | 2431 | 2475 |
| Mac OS X 10.6 / SunSpider (lower is better) | 819 | 669 | 340 |
HTML5 sectioning elements match typical sections of a web page, such as headers and footers, navigation sections, articles and excerpts, time stamps (for instance the time a certain post was published on a blog). These new tags are <section>, <nav>, <article>, <aside>, <hgroup>, <header>, <footer>, <time>, <mark>. A brief overview of these new tags can be found on this page. AIR 3 fully supports these new HTML5 sectioning elements.
<input> tag, effectively defining new types of input (for example, number, range, email, URL, date, etc.). Currently, only a few browsers implement the necessary user interface for the new input types—and with big differences in the UI representation of the controls. However, almost all major browsers support the newly added properties and methods of the input control, while rendering the actual elements as generic text inputs (that can be styled to automatically reflect whether or not the input values are valid or not).AIR 3 supports the new input types but renders them as text inputs, too. However, the new methods and properties (for example, stepUp(), stepDown(), min, max, step, valueAsNumber, etc.) as well as appropriate styling options are available and can be used, for instance in conjunction with a JavaScript library that would draw the necessary, more interactive UI. One thing to note about AIR 3 is that, just as in Safari, form validation is not enabled—neither in terms of UI elements to signal invalid values nor in terms of preventing the submission of forms that don't meet the required criteria (required fields are filled-in, inputs have valid values).
window.postMessage() method and the corresponding onmessage event, windows can broadcast textual messages and subscribe to such messages. For increased security, messages can be dispatched only to subscribers that match a certain origin. This feature is supported since AIR 2.6.history.pushState() and history.replaceState() methods as well as the onpopstate event to modify the history stack as well as the URL displayed in the address bar of the browsers, without triggering a reload of the page.AIR 3 supports the new history API, allowing web applications that use it to run properly and seamlessly in AIR as well as in all current browsers.
AIR 3 is backward compatible with AIR 2.7 and earlier. As such, it includes improved support for the following JavaScript, CSS3, and HTML5 features:
WebKit includes a number of new CSS properties. Some are part of the CSS3 working draft and some are WebKit-specific extensions.
-webkit-transform* and -webkit-perspective* properties and the associated transformation functions.The -webkit-transition* properties can be used to perform smooth transitions between CSS properties, including (but not limited to) colors, position, and dimensions. They can be used in conjunction with transformation properties and functions to create simple animations.
Animations take the concept of transforms and transitions a step further, allowing developers to use keyframes to modify the behavior of the animation throughout its duration in a declarative way. The CSS properties used are -webkit-animation* and the new @keyframes rule.
::-webkit-scrollbar* properties, namely -webkit-scrollbar, -webkit-scrollbar-button, -webkit-scrollbar-track, -webkit-scrollbar-track-piece, -webkit-scrollbar-thumb, -webkit-scrollbar-corner and -webkit-resizer. A more detailed description of this feature can be found on the WebKit blog.Using these properties to skin a typical web application can be problematic because of browsers that do not support them (either non-WebKit based browsers or browsers based on older WebKit versions). In an AIR application, however, these properties can be a better alternative than using JavaScript-simulated scroll bars.
-webkit-column-count and -webkit-column-gap properties. These can be used to reflow the text in a container across an arbitrary number of columns.zoom property, which can be used to specify the magnification of an element. Changes to the zoom property can be animated.@font-face declaration, which allows a font file to be placed on a server with other web assets and to be used to render web page content. Note that AIR 3 supports only TTF and OTF web fonts.AIR 3 supports the <canvas> tag, including the ImageData API (getImageData(), createImageData(), and putImageData()), and the use of canvas objects as background images in CSS.
AIR 2 added support for data: URLs. There are some restrictions due to the potential security risks. A data: URL can be used:
data: URLs.<img src="data:image/png;base64,..." /> ), input tags of type image (for example, <input type="image" src="data:image/png;base64,..." /> ), and CSS rules allowing image URLs (for example, background: url('data:image/png;base64,...'); ). @font-face declarations for embedding fonts in the CSS file, as in the following example:@font-face {
font-family: "MyDataFont";
src: url("data:font/opentype;base64,...");
})
The inclusion of a new HTML engine changed some of the behavior of AIR 2.5. To ensure your existing AIR 1.5 applications don't break, this behavior has been versioned according to the namespace used in the application descriptor. These versioned changes include:
<HEAD> element, one is implicitly created. In AIR 1.5 no <HEAD> element is created if it's not present in the document.content.length == 0 ) doesn't get automatically transformed into an XHR with the GET method. In AIR 1.5 zero-length POST requests get transformed to corresponding GET requests.Even though AIR 3 includes the Safari 5 branch of WebKit, some HTML, CSS, and JavaScript features that are present in Safari are currently disabled in AIR either for security or performance reasons or because of architectural incompatibilities. The following list highlights the features that are currently disabled, along with possible workarounds:
<audio> and <video> tags aim to provide a standard way of playing media in HTML pages. However, with codec support still subject to browser vendor decision and a big number of libraries abstracting and providing fallback solutions for media delivery, applications using only these tags as a mechanism for delivering media are not very common. For this reason, the <audio> and <video> tags are not supported. However, AIR is distributed with a copy of Flash Player for video and audio support.-webkit-background-clip: text and -webkit-mask-clip: text are currently not supported due to the lack of support for using text as a mask in the Cairo library used by the rendering engine in AIR.<select> (the drop-down variant): Changing the background color for the expanded list does not work, nor does changing the font color or font-family for individual items in the expanded state.
<input type="checkbox" /> and <input type="radio" />: Most of the CSS properties don't change the appearance of these controls. However, this behavior is consistent with the behavior in Safari.
HTML5 introduced support for client-side databases in the form of a lightweight relational database that exposes an SQL-like API for data access. However, since current implementations have a number of limitations and AIR offers a set of features that includes and exceeds the one specified by the HTML5 standard, support for HTML5 client-side databases is disabled.
<iframe> element. Using this attribute, developers can grant or restrict privileges for the content loaded inside an iframe. Because of the different security and sandboxing model present in AIR HTML this feature is disabled.document.print() function. However, after calling this function, the developer of the web application had little to no control over the way actual printing is done (this includes, but is not limited to whether color printing is available or not, paper sizes available, number of copies, and so on). Some control over the overall styling can be achieved via CSS media types, but everything still relies on a combination of the logic implemented in the browser and the user's settings.In AIR 3, the document.print() function is disabled, with the PrintJob API being the recommended way to control the printing process. This API allows rendering of content that is visible, dynamic, or off-screen, as well as prompting a system Print dialog box and reading the user's printer settings related to page width, height, and orientation in addition to color support.
Tables 2 and 3 sum up the feature set of AIR as compared to Safari 5.0.3.
Table 2. CSS features supported in AIR 3
| CSS Feature | AIR 3 |
|---|---|
| CSS3 –webkit selectors | Yes, with one exception: text clipping |
Web Fonts ( @font-face ) |
Yes |
| Transforms 2D | Yes |
| Transforms 3D | No |
| Transitions | Yes |
| Animations | Yes |
| Reflections | Yes |
| Masks | Yes |
| Styling scroll bars | Yes |
| Gradients | Yes |
| Zoom | Yes |
| Native CSS query selectors | Yes |
| CSS media device queries | Yes |
Table 3. HTML5 features supported in AIR 3
HTML5 Features |
AIR 3 |
|---|---|
| Faster JavaScript Engine | Yes, WebKit's Squirrelfish Extreme JavaScript Engine. |
| Canvas | Yes. |
| SVG | No. |
| HTML5 section tags |
Yes. |
| Video/Audio tags | No. |
| Web workers | No. |
| Client-side database | No. AIR has a custom database API. It is not an HTML5 database, but it is available to JavaScript developers like any other AIR API. |
| Offline detection and caching | AIR is offline by design and provides an API for detecting network status. |
| XMLHttpRequest with cross-origin requests | No, but by default XHR initiated from Application Sandbox can reach any domain (has cross domain capabilities). |
| Cross-document messaging | Yes. |
| Web storage | No. AIR has support for direct file system access, Flash shared objects, an encrypted local store, and local SQLite databases. |
| Web sockets | No. AIR has its own Socket API. |
| Server-sent DOM events | No. |
| Geolocation | No. |
| Drag-and-drop support | Yes. AIR has its own drag-and-drop API that offers deeper desktop integration than HTML. |
| Forms | Yes. |
| History state / back button | Yes. |
| Widgets | AIR is similar in design to the Widgets specification. |
This article presented an overview of the new HTML5 features in AIR for JavaScript developers. As the HTML engine used in AIR is based on the WebKit version used in Safari 5.0.3, they share many features in terms of HTML/JavaScript and CSS rendering. For the features that make sense for the AIR story and that are present in WebKit/Safari but not AIR, you can usually find alternatives that offer at least matching functionality. In some cases broader and more flexible APIs are available in AIR, as is the case with local storage, networking or desktop integration. For more details on JavaScript development in AIR, refer to the HTML Developer's Guide for Adobe AIR.
For a list of new features in AIR 3 read Christian Cantrell's What's new in Adobe AIR 3.
| 04/11/2012 | Surround sound 5.1 with Air 3.2 on desktop app? |
|---|---|
| 12/12/2011 | Live Streaming H.264 Video on iOS using AIR |
| 04/17/2012 | HTMLLoader - Google Maps? |
| 04/12/2012 | Tabindex in forms on mobile? |