////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package mx.styles
{
import flash.events.*;
import mx.core.FlexGlobals;
import mx.core.IFlexDisplayObject;
import mx.core.IFlexModule;
import mx.core.IFlexModuleFactory;
import mx.core.IMXMLObject;
import mx.core.UIComponent;
import mx.styles.*;
import mx.utils.NameUtil;
/**
* A base class that can be used
* when implementing an object that uses the
* IAdvancedStyleClient
interface. The base class supplies
* implementations of the methods and properties required for an object
* to participate in the style subsystem.
*
*
In addition to the IAdvancedStyleClient
interface,
* this object also implements the IFlexModule
and
* IMXMLObject
interfaces. The IMXMLObject
* interface contains an initialized
method that is called
* when the class is instantiated using an MXML declaration.
* The implementation of the initialized
method provided
* by this base class will add the class instance to the document object
* that contains the MXML declaration. For more details, see the description
* of the initilized
method.
getStyle()
method simply accesses
* nonInheritingStyles[styleName]
to search the entire
* prototype-linked chain.
* This object is set up by initProtoChain()
.
* Developers typically never need to access this property directly.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function get nonInheritingStyles():Object
{
return _nonInheritingStyles;
}
/**
* @private
*/
public function set nonInheritingStyles(value:Object):void
{
_nonInheritingStyles = value;
}
//----------------------------------
// styleDeclaration
//----------------------------------
/**
* @private
*/
private var _styleDeclarationVar:CSSStyleDeclaration;
[Inspectable(environment="none")]
/**
* The style declaration that holds the inline styles declared by this
* object.
*
* @see mx.styles.CSSStyleDeclaration
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function get styleDeclaration():CSSStyleDeclaration
{
return _styleDeclarationVar;
}
/**
* @private
*/
public function set styleDeclaration(value:CSSStyleDeclaration):void
{
_styleDeclarationVar = value;
}
//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------
/**
* Returns the StyleManager instance used by this component.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function get styleManager():IStyleManager2
{
return StyleManager.getStyleManager(moduleFactory);
}
private function setDeferredStyles():void
{
if (!deferredSetStyles)
return;
for (var styleProp:String in deferredSetStyles)
{
StyleProtoChain.setStyle(
this, styleProp, deferredSetStyles[styleProp]);
}
deferredSetStyles = null;
}
[Bindable(style="true")]
/**
* @inheritDoc
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function getStyle(styleProp:String):*
{
// If a moduleFactory has not be set yet, first check for any deferred
// styles. If there are no deferred styles or the styleProp is not in
// the deferred styles, the look in the proto chain.
if (!moduleFactory)
{
if (deferredSetStyles && deferredSetStyles[styleProp] !== undefined)
return deferredSetStyles[styleProp];
}
return styleManager.inheritingStyles[styleProp] ?
(_inheritingStyles ? _inheritingStyles[styleProp]
: undefined) :
(_nonInheritingStyles ? _nonInheritingStyles[styleProp]
: undefined);
}
/**
* @inheritDoc
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function setStyle(styleProp:String, newValue:*):void
{
// If there is no module factory then defer the set
// style until a module factory is set.
if (moduleFactory)
{
StyleProtoChain.setStyle(this, styleProp, newValue);
}
else
{
if (!deferredSetStyles)
deferredSetStyles = new Object();
deferredSetStyles[styleProp] = newValue;
}
}
/**
* @inheritDoc
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function clearStyle(styleProp:String):void
{
setStyle(styleProp, undefined);
}
/**
* @inheritDoc
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function getClassStyleDeclarations():Array
{
return StyleProtoChain.getClassStyleDeclarations(this);
}
/**
* Propagates style changes to the children of this style client
* instance. A non-visual style client (i.e. a style client that is
* not a DisplayObject) does not have children, therefore this method
* does not do anything for non-visual style clients.
*
* @param styleProp Name of the style property.
*
* @param recursive Whether to propagate the style changes to the
* children's children.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function notifyStyleChangeInChildren(
styleProp:String, recursive:Boolean):void
{
}
/**
* Sets up the internal style cache values so that the
* getStyle()
* method functions.
*
* @param recursive Regenerate the proto chains of the children.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function regenerateStyleCache(recursive:Boolean):void
{
StyleProtoChain.initProtoChain(this);
}
/**
* Registers the EffectManager as one of the event listeners
* for each effect event.
*
* @param effects An Array of Strings of effect names.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function registerEffects(effects:Array /* of String */):void
{
}
/**
* Detects changes to style properties. When any style property is set,
* Flex calls the styleChanged()
method,
* passing to it the name of the style being set.
*
* This is an advanced method that you might override
* when creating a subclass of AdvancedStyleClient
.
* When you create a custom class,
* you can override the styleChanged()
method
* to check the style name passed to it, and handle the change
* accordingly.
* This lets you override the default behavior of an existing style,
* or add your own custom style properties.
* If the document that created this object is a UIComponent
,
* (e.g. Application, Module, etc.) then the UIComponent's
* addStyleClient
method will be called to add this object to the
* UIComponent's list of non-visual style clients. This allows the
* object to inherit styles from the document.