Feature selection
From OpenLaszlo
Contents |
Introduction
This proposal calls for the addition of a @features attribute to the <canvas> and <library> tags of a Laszlo application, and a mechanism for the runtime discovery of whether a feature is available. This attribute would allow the application developer to specify which features an application requires, in order to use features that are specific to certain runtimes.
For example, use of the <img> tag within a text field requires Flash player 7. Bitmap caching would require Flash 8. The use of arbitrary script code in embedded swf files (through the <resource> tag) would almost certainly require Flash — this feature would probably not be supported on any other runtime (unlike bitmap caching and the context menu, which would).
This proposal doesn't propose exposing these particular features as features of the OpenLaszlo platform; it simply defines a framework within which these target-specific features could be added to the framework.
The intent is to preserve the information about which OpenLaszlo libraries and applications can be ported between runtimes, and to maintain the current behavior where any application that is written to the OpenLaszlo APIs, and takes no special measures, is portable across different runtimes. Currently this set is likely to be all libraries and applications that are written against the documented interfaces, but the addition of target-specific features would otherwise jeopardize this for all applications; this proposal is intended to limit the risk of non-portability to those applications that require non-portable features.
Proposal
Overview
An optional @features attribute is added to the <canvas> and <library> tags. This attribute is used for the compile-time specification of required features. For example, if an application is not intended to behave correctly unless the runtime supports context menus, the developer can denote this by adding features="context-menu" to the canvas tag.
Compiling an application that names a feature that is not present on the runtime that it is compiled for, results in a compilation warning. For example, compiling <canvas features="context-menu"/> for the Flash 6 player (lzr=swf6) results in a compilation warning.
A Runtime class is added to the runtime library. This API is used tor the runtime discovery of optional features. For example, an application that should select its behavior depending on whether the context menu is available could conditionalize this behavior on the test Runtime.hasFeature("context-menu"). (It might present a static view with buttons linked to the commands in the context menu, for example.)
Runtime discovery is an alternative to compile-time specification. An application whose sources specify that it requires the context-menu feature need not contain code that tests for it at runtime (the compiler is guaranteed to have already generated a warning that the application is being compiled for an unsupported environment); conversely, an application that tests for the presence of a feature at runtime need not contain a @feature attribute that names that feature (since it is prepared to deal with its absence).
Definitions
- Runtime
- A Runtime is a particular software configuration that can execute OpenLaszlo applications. For example, Flash Player 6, Flash Player 7, and Flash Player 8 are runtimes. (The host browser and operating system are not part of the Runtime, since all platform features are currently supported on all browsers and operating systems that are supported at all.)
- Feature Name
- A Feature Name is a string, such as "context-menu", "inline-img", "av", or "bitmap-caching". This string represents a capability that is available on a particular runtime.
- @features attribute
- An optional @features attribute is added to the <canvas> and <library> tags. The value of this attribute is a comma-separated list of feature names: for example, "context-menu", "context-menu, inline-img".
- Required Features
- The set of Required Features of an application is the set of features that are named by its <canvas> and <library> @features attributes.
- Supported Features
- The features that a particular Runtime supports are that runtime's Supported Features.
- Compilation Options
- Compilation Options are a set of attribute name → value pairs that specify the pragmatics of the program: compilation target, debug level, logging level, optimization level, startup conditions. These options supplement the application source with information that varies differently from the application sources. (The application sources are changed to change the program semantics, or presentation and behavior, as the program is developed. The compilation options changes along with the nature of the developers interaction with the program: debugging, optimizing, deploying, profiling.)
- Target Runtime
- One of the Compilation Options is the name of a target runtime. If this option is not present, the compiler may use a heuristic default. (For example, a compiler that only supports one target will use this as the default.) The runtime that this option or default names is the Target Runtime.
- Compilation
- Compilation is the process by which a set of OpenLaszlo source files, together with a set of Compilation Options, is used to generate a set of OpenLaszlo objects.
- Unsupported Application Features
- Unsupported Application Features are those Required Features of an application that are not Supported Features for the Target Runtime. Compilation of an application with Unsupported Application Features results in a compiler error. (In the OpenLaszlo implementation, this error is presented as a compilation warning, since there is not at present a mechanism for displaying non-fatal compiler errors.)
- Runtime class
- A Runtime class is added to the OpenLaszlo runtime. Runtime.hasFeature(String) → Boolean returns true iff the runtime supports the feature named by the string parameter.
Changes
- An optional @features attribute, as defined above, is added to the <canvas> and <library> tags.
- The Runtime class, as defined above, is added to the OpenLaszlo runtime.
- Compilation of an application with Unsupported Application Features results in a compiler error.
- "context-menu" is added to the set of features for swf7 and greater. This feature specifies the availability of the context menu API that was added to OpenLaszlo 3.0.
- "inline-img" is added to the set of features for swf7 and greater. This feature specifies the ability of the runtime to display images within a text field. (In OpenLaszlo 3.0 and 3.1, this capability is only accessible through the use of the setText() API call.)
Examples
Image tag (in JavaScript)
The following code would produce a compilation warning when compiled for Flash Player 6, but not Flash Player 7 or higher or (most likely) alternate runtimes.
<canvas features="inline-img">
<text oninit="this.setText('An image here: <img src=\'logo.png\'/>')"/>
<canvas>
Image tag (in XML)
[This specific feature is not part of this proposal. It illustrates how this proposal could be used to support future extensions.]
<canvas features="inline-img"> <text>An image here: <img src="logo.png"/></text> <canvas>
The following code would produce a compilation warning when compiled for Flash Player 6, but not Flash Player 7 or higher or (most likely) alternate runtimes.
Behavioral Flash import
[This specific feature is not part of this proposal. It illustrates how this proposal could be used to support future extensions.] The following code would produce a compilation warning when compiled for a non-Flash runtime.
<canvas features="swf"> <resource name="panel" src="panel.swf" features="swf"/> </canvas>
The following code would produce a compilation warning when compiled for Flash Player 6, but not Flash Player 7 or higher.
<canvas features="swf7"> <resource name="panel" src="panel.swf" features="swf7"/> </canvas>
Bitmap Caching
[This specific feature is not part of this proposal. It illustrates how this proposal could be used to support future extensions.] The following code would produce a compilation warning when compiled for Flash Players 6 or 7, but not Flash Player 8 or higher or (most likely) alternate runtimes.
<canvas features="bitmap-caching"> <view cached="true"><text>some text</text></view> </canvas>
History
An earlier (unpublished) version of this proposal specified a @target attribute, whose value could be a comma-separated list of "swf6", "swf7", etc., ">swf7", or "swf" (to represent all Flash player runtimes). That version had the problem that even if a feature, such as the inline <img> tag, was likely to be available on all non-Flash platforms, the developer had to specify "swf7" or ">swf7" to specify that an application depended on it. A @target attribute might still be useful as part of a build system or content negotiation system for OpenLaszlo applications, but it doesn't meet the same requirements as this proposal.

