+
+ // a style may have other styles, which has other styles etc so we apply in reverse by convention.
+ for(TreeNodeList::reverse_iterator iter = additionalStyleNodes.rbegin(); iter != additionalStyleNodes.rend(); ++iter)
+ {
+ RecordStyle( style, *(*iter), handle, constant );
+ ApplySignals( root, *(*iter), handle );
+ ApplyStylesByActor( root, *(*iter), handle, constant );
+ }
+ }
+
+ RecordStyle( style, node, handle, constant );
+ mStyles.Add( styleName, style ); // shallow copy
+ matchedStyle = &style;
+ }
+ }
+ }
+
+ if( matchedStyle )
+ {
+ StylePtr style( *matchedStyle );
+ Dictionary<Property::Map> instancedProperties;
+ style->ApplyVisualsAndPropertiesRecursively( handle, instancedProperties );
+ }
+ else // If there were no styles, instead set properties
+ {
+ SetProperties( node, handle, constant );
+ }
+ ApplySignals( root, node, handle );
+ ApplyStylesByActor( root, node, handle, constant );
+}
+
+void Builder::RecordStyle( StylePtr style,
+ const TreeNode& node,
+ Dali::Handle& handle,
+ const Replacement& replacements )
+{
+ // With repeated calls, accumulate inherited states, visuals and properties
+ // but override any with same name
+
+ for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
+ {
+ const TreeNode::KeyNodePair& keyValue = *iter;
+ std::string key( keyValue.first );
+ if( key == KEYNAME_STATES )
+ {
+ const TreeNode& states = keyValue.second;
+ if( states.GetType() != TreeNode::OBJECT )
+ {
+ DALI_LOG_WARNING( "RecordStyle() Node \"%s\" is not a JSON object\n", key.c_str() );
+ continue;
+ }
+
+ for( TreeNode::ConstIterator iter = states.CBegin(); iter != states.CEnd(); ++iter )
+ {
+ const TreeNode& stateNode = (*iter).second;
+ const char* stateName = stateNode.GetName();
+ if( stateNode.GetType() != TreeNode::OBJECT )
+ {
+ DALI_LOG_WARNING( "RecordStyle() Node \"%s\" is not a JSON object\n", stateName );
+ continue;
+ }
+
+ StylePtr* stylePtr = style->subStates.Find( stateName );
+ if( stylePtr )
+ {
+ StylePtr style(*stylePtr);
+ RecordStyle( style, stateNode, handle, replacements );
+ }
+ else
+ {
+ StylePtr subState = Style::New();
+ RecordStyle( subState, stateNode, handle, replacements );
+ style->subStates.Add( stateName, subState );
+ }
+ }
+ }
+ else if( key == KEYNAME_VISUALS )
+ {
+ for( TreeNode::ConstIterator iter = keyValue.second.CBegin(); iter != keyValue.second.CEnd(); ++iter )
+ {
+ // Each key in this table should be a property name matching a visual.
+ const TreeNode::KeyNodePair& visual = *iter;
+ Dali::Property::Value property(Property::MAP);
+ if( DeterminePropertyFromNode( visual.second, Property::MAP, property, replacements ) )
+ {
+ Property::Map* mapPtr = style->visuals.Find( visual.first );
+ if( mapPtr )
+ {
+ // Override existing visuals
+ mapPtr->Clear();
+ mapPtr->Merge( *property.GetMap() );
+ }
+ else
+ {
+ Property::Map* map = property.GetMap();
+ if( map )
+ {
+ style->visuals.Add( visual.first, *map );
+ }
+ }
+ }
+ }
+ }
+ else if( key == KEYNAME_ENTRY_TRANSITION )
+ {
+ RecordTransitionData( keyValue, style->entryTransition, replacements );
+ }
+ else if( key == KEYNAME_EXIT_TRANSITION )
+ {
+ RecordTransitionData( keyValue, style->exitTransition, replacements );
+ }
+ else if( key == KEYNAME_TRANSITIONS )
+ {
+ RecordTransitions( keyValue, style->transitions, replacements );
+ }
+ else if( key == KEYNAME_TYPE ||
+ key == KEYNAME_ACTORS ||
+ key == KEYNAME_SIGNALS ||
+ key == KEYNAME_STYLES ||
+ key == KEYNAME_MAPPINGS ||
+ key == KEYNAME_INHERIT )
+ {
+ continue;
+ }
+ else // It's a property
+ {
+ Property::Index index;
+ Property::Value value;
+ if( MapToTargetProperty( handle, key, keyValue.second, replacements, index, value ) )
+ {
+ Property::Value* existingValuePtr = style->properties.Find( index );
+ if( existingValuePtr != NULL )
+ {
+ *existingValuePtr = value; // Overwrite existing property.
+ }
+ else
+ {
+ style->properties.Add( index, value );