getStyleDeclaration()
method
* to get the corresponding CSSStyleDeclaration object.
* Class selectors are prepended with a period.
*
* @return An Array of all of the selectors
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
[Deprecated(
replacement="IStyleManager2.selectors on a style manager instance from IAdvancedStyleClient.styleManager",
since="4.0")]
public static function get selectors():Array
{
return impl.selectors;
}
...
/**
* Returns the style manager for an object.
*
* @param moduleFactory The module factory of an object you want the
* style manager for. If null, the top-level style manager is returned.
*
* @return the style manager for the given module factory.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4
*/
public static function getStyleManager(moduleFactory:IFlexModule):IStyleManager2
{
...
}
}
### IStyleManager2
* Add a parent property.
* Add a getMergedStyleDelcaration() function;
public interface IStyleManager2 extends IStyleManager
{
//--------------------------------------------------------------------------
//
// Properties
//
//--------------------------------------------------------------------------
/**
* The style manager that is the parent of this style manager.
*
* @return the parent style manager or null if this is the top-level style manager.
*/
function get parent():IStyleManager2;
/**
* @private
*/
function set parent(parent:IStyleMananger2):void;
...
/**
* Gets a CSSStyleDeclaration object that stores the rules
* for the specified CSS selector. The CSSStyleDeclaration object is the created by merging
* the properties of the specified CSS selector of this style manager with all of the parent
* style managers.
*
* If the selector
parameter starts with a period (.),
* the returned CSSStyleDeclaration is a class selector and applies only to those instances
* whose styleName
property specifies that selector
* (not including the period).
* For example, the class selector ".bigMargins"
* applies to any UIComponent whose styleName
* is "bigMargins"
.
If the selector
parameter does not start with a period,
* the returned CSSStyleDeclaration is a type selector and applies to all instances
* of that type.
* For example, the type selector "Button"
* applies to all instances of Button and its subclasses.
The global
selector is similar to a type selector
* and does not start with a period.
selector
property.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
function getMergedStyleDeclaration(selector:String):CSSStyleDeclaration;
...
### IFlexModuleFactory
* Add a styleManager property.
* Move registerImplementation() and getImplementation() from ISystemManager to IFlexModuleFactory.
public interface IFlexModuleFactory
{
...
/**
* Register an implementation for an interface.
* Similar to Singleton.registerClass, but per-
* ISystemManager, and takes an instance not a class
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
function registerImplementation(interfaceName:String,
impl:Object):void;
/**
* Get the implementation for an interface.
* Similar to Singleton.getInstance, but per-
* ISystemManager
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
function getImplementation(interfaceName:String):Object;
...
}
### ISystemManager
* Move registerImplementation() and getImplementation() from ISystemManager to IFlexModuleFactory.
### IModuleInfo
* Add IFlexModuleFactory argument to load().
/**
* Requests that the module be loaded. If the module is already loaded,
* the call does nothing. Otherwise, the module begins loading and dispatches
* progress
events as loading proceeds.
*
* @param applicationDomain The current application domain in which your code is executing.
*
* @param securityDomain The current security "sandbox".
*
* @param bytes A ByteArray object. The ByteArray is expected to contain
* the bytes of a SWF file that represents a compiled Module. The ByteArray
* object can be obtained by using the URLLoader class. If this parameter
* is specified the module will be loaded from the ByteArray. If this
* parameter is null the module will be loaded from the url specified in
* the url property.
*
* @param moduleFactory The module factory that parents the load. The loaded
* module's parent style manager will be determined from this argument.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
function load(applicationDomain:ApplicationDomain = null,
securityDomain:SecurityDomain = null,
bytes:ByteArray = null,
moduleFactory:IFlexModuleFactory = null):void;
### Request
* Add a new GET_PARENT_FLEX_MODULE_FACTORY_REQUEST request so a module or application can ask who its parent module factory is.
/**
* This is an event that is expects its data property to be set by
* a responding listener
*/
public class Request extends Event
{
/**
* Dispatched from a sub-application or module to find the module factory of its parent
* application or module. The recipient of this request should set the data property to
* their module factory.
*
* The message is dispatched from the content of a loaded module or application.
*/
public static const GET_PARENT_FLEX_MODULE_FACTORY_REQUEST:String =
"getParentFlexModuleFactoryRequest";
### UIComponent
* Add styleManager property to get the styleManager for this object.
public function get styleManager():IStyleManager2
{
// TODO:
}
### IStyleModule
* Added a new function to allow a style manager to be passed in for context when the style module sets its styles.
/**
* Creates and sets style declarations from the styles modules into the given
* style manager.
*
* @param styleManager The style manager where the style declarations will be
* loaded into. The style declarations will be created relative to the this
* style manager. The unload() function will unload styles from this style
* manager. If null is passed the top-level style manager is used.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 4
*/
function setStyleDeclarations(styleManager:IStyleManager2):void;
### CSSStyleDeclaration
* Add a second parameter to the constructor so a StyleManager can be passed in. The argument as a default value for backwards compatibility.
* Add a third parameter to control whether the style declaration is set into the style manager.
/**
* Constructor.
*
* @param selector - If the selector is a CSSSelector then advanced
* CSS selectors are supported. If a String is used for the selector then
* only simple CSS selectors are supported. If the String starts with a
* dot it is interpreted as a universal class selector, otherwise it must
* represent a simple type selector. If not null, this CSSStyleDeclaration
* will be registered with StyleManager.
*
* @param styleManager - The style manager to set this declaration into. If the
* styleManager is null the top-level style manager will be used.
*
* @param autoRegisterWithStyleManager - If true set the selector in the styleManager. If setSelector
* is false this style declaration can be set in the styleManager at a later time.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public function CSSStyleDeclaration(selector:Object=null,
styleManager:IStyleManager2=null,
autoRegisterWithStyleManager:Boolean = true)
## Examples and Usage
----
This is an example of an application that loads two modules, "LeftModule" and "RightModule". The main application contains no styles. Both "LeftModule" and "RightModule" declare styles to modify the text alignment of Buttons. The example shows how modules can have different values for the same selector. Prior to this feature, the module that was loaded first would have its styles loaded and the other modules would have to use those styles as well.
### Main Application
The main application contains two buttons. The two buttons toggle the loaded state of modules.
<s:application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minwidth="1024" minheight="768">
<fx:script>
</fx:script>
<s:layout>
<s:verticallayout>
</s:verticallayout></s:layout>
<mx:button label="Left Module" width="300" click="toggleLeftModule()">
<mx:button label="Right Module" width="300" click="toggleRightModule()">
<mx:moduleloader id="lml">
<mx:moduleloader id="rml">
</mx:moduleloader></mx:moduleloader></mx:button></mx:button></s:application>
### LeftModule
This module contains a Style block that sets the Halo Button to be left aligned and sets a skinClass for the Spark button that makes the Spark Button left aligned.
<mx:module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" layout="vertical" width="400" height="100">
<fx:style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
mx|Button {
textAlign: "left";
}
s|Button {
skinClass: ClassReference("MyLeftButtonSkin");
}
</fx:style>
<mx:button label="Left Button" width="300">
<s:button label="Left Skinned Button" width="300">
</s:button></mx:button></mx:module>
### RightModule
This module contains a Style block that sets the Halo Button to be right aligned and sets a skinClass for the Spark button that makes the Spark Button right aligned.
<mx:module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" layout="vertical" width="400" height="100">
<fx:style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
mx|Button {
textAlign: "right";
}
s|Button {
skinClass: ClassReference("MyRightButtonSkin");
}
</fx:style>
<mx:button label="Right Button" width="300">
<s:button label="Right Skinned Button" width="300">
</s:button></mx:button></mx:module>
## Additional Implementation Details
----
### Creation and initialization of StyleManager
The steps involved in creating and initializing a new StyleManager for an application.
1. SWFLoader creates a Loader and adds a listener for an EVENT.INIT event.
2. In the Event.INIT event handler SWFLoader listens for a GET_PARENT_FLEX_MODULE_FACTORY_REQUEST request on the loaderInfo.content.
3. SystemManager creates and initializes the FlexInit mixin.
4. The FlexInit mixin creates a new StyleManager, passing the current IFlexModuleFactory to StyleManager.
5. StyleManager registers its implementation with the IFlexModuleFactory it was passed.
6. StyleManager dispatches a Request.GET_PARENT_FLEX_MODULE_FACTORY_REQUEST unless the IFlexModuleFactory is the top-level SystemManager or this application is a Marshal Plan application (A.2 or A.3). If the IFlexModuleFactory is the top-level SystemManager then this is the top-level StyleManager.
7. SWFLoader handles the Request.GET_PARENT_FLEX_MODULE_FACTORY_REQUEST message and set the data property to be its local module factory.
8. StyleManager get return value of the request and sets its parent StyleManager to be the StyleManager of the returned module factory. If the return value is null then the StyleManager of the top-level SystemManager is set a the parent StyleManager.
The steps involved in creating and initializing a new StyleManager for a module.
1. ModuleLoader get a IModuleInfo instance from ModuleManager.
2. ModuleLoader calls IModuleInfo.load() to load the module, passing its module factory to the load function.
3. IModuleInfo creates a Loader and adds a listener for an EVENT.INIT event.
4. In the Event.INIT event handler ModuleManager adds a listener for a GET_PARENT_FLEX_MODULE_FACTORY_REQUEST request on the loaderInfo.content.
5. FlexModuleFactory creates and initializes the FlexInit mixin.
6. The FlexInit mixin creates a new StyleManager, passing the current IFlexModuleFactory to StyleManager.
7. StyleManager registers its implementation with the IFlexModuleFactory it was passed.
8. StyleManager dispatches a Request.GET_PARENT_FLEX_MODULE_FACTORY_REQUEST.
9. IModule handles the request by setting the request's value property to the module factory passed to the load function.
10. StyleManager get return value of the request and sets its parent StyleManager to the StyleManager of the returned module factory. If the return value is null then the StyleManager of the top-level SystemManager is set a the parent StyleManager.
## Prototype Work
----
Glenn did a prototype of StyleManager using an approach where the StyleManager is modified to track the styles of all modules. This specification describes a different design where each application has its own StyleManager. There is not prototype for this method.
## Compiler Work
----
The generated code for styles will need to be updated.
### Compiler Options
-isolate-styles
An option to determine whether a style manager is created to manage the styles for this application or module. Creating a style manager turns on the Per-Module Styles feature for the application or module being compiled. When this option is set to false the application or module will use its parent's style manager. Compiling all applications and modules with this option set to false will disable the Per-Modules Styles feature.
## Flex Feature Dependencies
----
None.
## Backwards Compatibility
----
* The singleton StyleManager API will still continue to compile and only use the top-level StyleManager.
* Flex 3 apps can be compiled with -compatibility-version=3.0.0 and the sub-ordinate StyleManagers will not be created.
### Behavior
* Modules and sub-applications will be allowed to have independent styles for the same selector. Applications that relied on the first-in wins selector rules may see a difference in behavior.
## Performance
----
* Property merges between StyleManagers could get expensive and is something to watch.
* The deeper applications and modules are nested the more parent/child StyleManagers there will be. The more StyleManagers in a path from the root application to any node, the more property merges will need to happen and the more performance will be impacted.
[[include site:open_commentlogin (not found)]]