Changed styles to use case-insensitive matching
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / builder-impl.cpp
index d16c64f..de3fbe1 100644 (file)
@@ -1,36 +1,49 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed 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.
+ *
+ */
 
 // CLASS HEADER
 #include <dali-toolkit/internal/builder/builder-impl.h>
 
 // EXTERNAL INCLUDES
 #include <sys/stat.h>
-
-// INTERNAL INCLUDES
-#include <dali/dali.h>
+#include <sstream>
+
+#include <dali/public-api/render-tasks/render-task-list.h>
+#include <dali/public-api/object/type-info.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/object/property-array.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/actors/camera-actor.h>
+#include <dali/devel-api/scripting/scripting.h>
+#include <dali/public-api/signals/functor-delegate.h>
 #include <dali/integration-api/debug.h>
 
+// INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control.h>
-#include <dali-toolkit/public-api/builder/json-parser.h>
+#include <dali-toolkit/devel-api/builder/json-parser.h>
 
 #include <dali-toolkit/internal/builder/builder-get-is.inl.h>
 #include <dali-toolkit/internal/builder/builder-filesystem.h>
 #include <dali-toolkit/internal/builder/builder-declarations.h>
+#include <dali-toolkit/internal/builder/builder-set-property.h>
 #include <dali-toolkit/internal/builder/replacement.h>
+#include <dali-toolkit/internal/builder/tree-node-manipulator.h>
+
+#include <dali-toolkit/internal/builder/builder-impl-debug.h>
 
 namespace Dali
 {
@@ -42,15 +55,9 @@ namespace Internal
 {
 class Replacement;
 
-extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot );
-extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value );
-extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& replacements );
-extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value );
-extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements );
-extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
-extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor);
-extern Actor SetupActor( const TreeNode& node, Actor& actor );
-extern Control SetupControl( const TreeNode& node, Control& actor );
+extern Animation CreateAnimation(const TreeNode& child, const Replacement& replacements, const Dali::Actor searchRoot, Builder* const builder );
+extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder);
+extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor, Dali::Toolkit::Internal::Builder* const builder);
 
 #if defined(DEBUG_ENABLED)
 Integration::Log::Filter* gFilterScript  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_SCRIPT");
@@ -59,6 +66,8 @@ Integration::Log::Filter* gFilterScript  = Integration::Log::Filter::New(Debug::
 namespace
 {
 
+#define TOKEN_STRING(x) #x
+
 const std::string KEYNAME_STYLES    = "styles";
 const std::string KEYNAME_TYPE      = "type";
 const std::string KEYNAME_ACTORS    = "actors";
@@ -66,119 +75,34 @@ const std::string KEYNAME_SIGNALS   = "signals";
 const std::string KEYNAME_NAME      = "name";
 const std::string KEYNAME_TEMPLATES = "templates";
 const std::string KEYNAME_INCLUDES  = "includes";
+const std::string KEYNAME_MAPPINGS  = "mappings";
 
-typedef std::vector<const TreeNode*> TreeNodeList;
-
-template <typename T>
-std::string ToString(const T& value)
-{
-  std::stringstream ss;
-  ss << value;
-  return ss.str();
-}
+const std::string PROPERTIES = "properties";
+const std::string ANIMATABLE_PROPERTIES = "animatableProperties";
 
-template <>
-std::string ToString(const Rect<int>& value)
-{
-  std::stringstream ss;
-  ss << value.x << "," << value.y << "," << value.width << "," << value.height;
-  return ss.str();
-}
+typedef std::vector<const TreeNode*> TreeNodeList;
 
 
-std::string PropertyValueToString( const Property::Value& value )
+bool GetMappingKey( const std::string& str, std::string& key )
 {
-  std::string ret;
-
-  switch( value.GetType() )
+  bool result = false;
+  std::string test( str );
+  if( ! test.empty() )
   {
-    case Property::NONE:
-    {
-      ret = "NONE";
-      break;
-    }            ///< No type
-    case Property::BOOLEAN:
-    {
-      ret = value.Get<bool>() ? "True" : "False";
-      break;
-    }
-    case Property::FLOAT:
-    {
-
-      ret = ToString( value.Get<float>() );
-      break;
-    }
-    case Property::INTEGER:
-    {
-      ret = ToString( value.Get<int>() );
-      break;
-    }
-    case Property::UNSIGNED_INTEGER:
-    {
-      ret = ToString( value.Get<unsigned int>() );
-      break;
-    }
-    case Property::VECTOR2:
-    {
-      ret = ToString( value.Get<Vector2>() );
-      break;
-    }
-    case Property::VECTOR3:
-    {
-      ret = ToString( value.Get<Vector3>() );
-      break;
-    }
-    case Property::VECTOR4:
-    {
-      ret = ToString( value.Get<Vector4>() );
-      break;
-    }
-    case Property::MATRIX3:
-    {
-      ret = ToString( value.Get<Matrix3>() );
-      break;
-    }
-    case Property::MATRIX:
-    {
-      ret = ToString( value.Get<Matrix>() );
-      break;
-    }
-    case Property::RECTANGLE:
-    {
-      ret = ToString( value.Get< Rect<int> >() );
-      break;
-    }
-    case Property::ROTATION:
-    {
-      break;
-    }
-    case Property::STRING:
-    {
-      ret = value.Get<std::string>();
-      break;
-    }
-    case Property::ARRAY:
+    if( test.at(0) == '<' )
     {
-      ret = std::string("Array Size=") + ToString( value.Get<Property::Array>().size() );
-      break;
-    }
-    case Property::MAP:
-    {
-      ret = std::string("Map Size=") + ToString( value.Get<Property::Map>().size() );
-      break;
-    }
-    case Property::TYPE_COUNT:
-    {
-      ret = "";
-      break;
+      if( test.at(test.length()-1) == '>' )
+      {
+        key = test.substr( 1, test.length()-2 );
+        result = true;
+      }
     }
   }
-
-  return ret;
+  return result;
 }
 
 /*
- * Recursively collects all stylesin a node (An array of style names).
+ * Recursively collects all styles in a node (An array of style names).
  *
  * stylesCollection The set of styles from the json file (a json object of named styles)
  * style The style array to begin the collection from
@@ -193,7 +117,7 @@ void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style,
     {
       if( OptionalString styleName = IsString( (*iter).second ) )
       {
-        if( OptionalChild node = IsChild( stylesCollection, *styleName) )
+        if( OptionalChild node = IsChildIgnoreCase( stylesCollection, *styleName) )
         {
           styleList.push_back( &(*node) );
 
@@ -207,6 +131,7 @@ void CollectAllStyles( const TreeNode& stylesCollection, const TreeNode& style,
   }
 }
 
+
 } // namespace anon
 
 /*
@@ -216,89 +141,50 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace
 {
   if( handle )
   {
+
     for( TreeNode::ConstIterator iter = node.CBegin(); iter != node.CEnd(); ++iter )
     {
       const TreeNode::KeyNodePair& keyChild = *iter;
 
       std::string key( keyChild.first );
 
-      // ignore special fields; type,actors,signals
-      if(key == KEYNAME_TYPE || key == KEYNAME_ACTORS || key == KEYNAME_SIGNALS || key == KEYNAME_STYLES)
-      {
-        continue;
-      }
-
-      // special field 'image' usually contains an json object description
-      // although sometimes refers to a framebuffer
-      if( 0 == keyChild.second.Size() )
-      {
-        if(key == "image")
-        {
-          ImageActor imageActor = ImageActor::DownCast(handle);
-          if(imageActor)
-          {
-            if( OptionalString s = constant.IsString( keyChild.second ) )
-            {
-              FrameBufferImage fb = GetFrameBufferImage(*s, constant);
-              if(fb)
-              {
-                imageActor.SetImage( fb );
-              }
-            }
-          }
-        }
-      }
-
-      // special field 'effect' references the shader effect instances
-      if(key == "effect")
+      // ignore special fields; type,actors,signals,styles
+      if(key == KEYNAME_TYPE || key == KEYNAME_ACTORS || key == KEYNAME_SIGNALS || key == KEYNAME_STYLES || key == KEYNAME_MAPPINGS )
       {
-        Actor actor = Actor::DownCast(handle);
-        OptionalString s = constant.IsString( keyChild.second );
-        if(actor && s)
-        {
-          ShaderEffect e = GetShaderEffect(*s, constant);
-          actor.SetShaderEffect(e);
-        }
-        else
-        {
-          DALI_SCRIPT_WARNING("Could not find or set shader effect\n");
-        }
-
         continue;
       }
 
       Handle propertyObject( handle );
 
-      Property::Index index = propertyObject.GetPropertyIndex( key );
+      Dali::Property::Index index = propertyObject.GetPropertyIndex( key );
 
-      if( Property::INVALID_INDEX == index )
+      if( Property::INVALID_INDEX != index )
       {
-        Actor actor = Actor::DownCast(propertyObject);
-        if( actor )
+        Property::Type type = propertyObject.GetPropertyType(index);
+        Property::Value value;
+        bool mapped = false;
+
+        // if node.value is a mapping, get the property value from the "mappings" table
+        if( keyChild.second.GetType() == TreeNode::STRING )
         {
-          if( ShaderEffect effect = actor.GetShaderEffect() )
+          std::string mappingKey;
+          if( GetMappingKey(keyChild.second.GetString(), mappingKey) )
           {
-            index = effect.GetPropertyIndex( key );
-            if(index != Property::INVALID_INDEX)
-            {
-              propertyObject = effect;
-            }
+            OptionalChild mappingRoot = IsChild( mParser.GetRoot(), KEYNAME_MAPPINGS );
+            mapped = GetPropertyMap( *mappingRoot, mappingKey.c_str(), type, value );
           }
         }
-      }
-
-      if( Property::INVALID_INDEX != index )
-      {
-        Property::Type type = propertyObject.GetPropertyType(index);
-
-        Property::Value value;
-        if( !SetPropertyFromNode( keyChild.second, type, value, constant ) )
+        if( ! mapped )
         {
-          // verbose as this might not be a problem
-          // eg parent-origin can be a string which is picked up later
-          DALI_SCRIPT_VERBOSE("Could not convert property:%s\n", key.c_str());
+          mapped = DeterminePropertyFromNode( keyChild.second, type, value, constant );
+          if( ! mapped )
+          {
+            // Just determine the property from the node and if it's valid, let the property object handle it
+            DeterminePropertyFromNode( keyChild.second, value, constant );
+            mapped = ( value.GetType() != Property::NONE );
+          }
         }
-        else
+        if( mapped )
         {
           DALI_SCRIPT_VERBOSE("SetProperty '%s' Index=:%d Value Type=%d Value '%s'\n", key.c_str(), index, value.GetType(), PropertyValueToString(value).c_str() );
 
@@ -310,6 +196,10 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace
         DALI_SCRIPT_VERBOSE("SetProperty INVALID '%s' Index=:%d\n", key.c_str(), index);
       }
 
+      // Add custom properties
+      SetCustomProperties(node, handle, constant, PROPERTIES, Property::READ_WRITE);
+      SetCustomProperties(node, handle, constant, ANIMATABLE_PROPERTIES, Property::ANIMATABLE);
+
     } // for property nodes
   }
   else
@@ -318,6 +208,27 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace
   }
 }
 
+void Builder::SetCustomProperties( const TreeNode& node, Handle& handle, const Replacement& constant,
+                          const std::string& childName, Property::AccessMode accessMode )
+{
+  // Add custom properties
+  if( OptionalChild customPropertiesChild = IsChild(node, childName) )
+  {
+    const TreeNode& customPropertiesNode = *customPropertiesChild;
+    const TreeConstIter endIter = customPropertiesNode.CEnd();
+    for( TreeConstIter iter = customPropertiesNode.CBegin(); endIter != iter; ++iter )
+    {
+      const TreeNode::KeyNodePair& keyChild = *iter;
+      std::string key( keyChild.first );
+
+      Property::Value value;
+      DeterminePropertyFromNode( keyChild.second, value, constant );
+      // Register/Set property.
+      handle.RegisterProperty( key, value, accessMode );
+    }
+  }
+}
+
 // Set properties from node on handle.
 void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
                                Dali::Handle& handle, const Replacement& constant )
@@ -328,19 +239,9 @@ void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node,
 
     if( actor )
     {
-      SetupActor( node, actor );
-
-      Control control  = Control::DownCast(actor);
-
-      if( control )
-      {
-        SetupControl( node, control );
-      }
-
       // add signals
-      SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor );
-
-      SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor );
+      SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor, this );
+      SetupPropertyNotification( mSlotDelegate.GetConnectionTracker(), root, node, actor, this );
    }
   }
   else
@@ -472,7 +373,6 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
     baseHandle       = typeInfo.CreateInstance();
     Handle handle    = Handle::DownCast(baseHandle);
     Actor actor      = Actor::DownCast(handle);
-    Control control  = Control::DownCast(handle);
 
     if(handle)
     {
@@ -491,6 +391,7 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
         DALI_SCRIPT_VERBOSE("  Is Actor id=%d\n", actor.GetId());
       }
 
+      Toolkit::Control control  = Toolkit::Control::DownCast(handle);
       if(control)
       {
         DALI_SCRIPT_VERBOSE("  Is Control id=%d\n", actor.GetId());
@@ -510,9 +411,7 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
         }
       }
 
-      ApplyProperties( root, node, handle, replacements );
-
-      if( actor)
+      if( actor )
       {
         // add children of all the styles
         if( OptionalChild actors = IsChild( node, KEYNAME_ACTORS ) )
@@ -532,7 +431,10 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
           parent.Add( actor );
         }
       }
-
+      else
+      {
+        ApplyProperties( root, node, handle, replacements );
+      }
     }
     else
     {
@@ -543,25 +445,12 @@ BaseHandle Builder::DoCreate( const TreeNode& root, const TreeNode& node,
   return baseHandle;
 }
 
-
-ActorContainer Builder::GetTopLevelActors() const
-{
-  // deprecated function.
-  return ActorContainer();
-}
-
-Animation Builder::GetAnimation( const std::string &name ) const
-{
-  // deprecated
-  return Animation();
-}
-
 void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replacement& constant )
 {
   const Stage& stage = Stage::GetCurrent();
   Layer root  = stage.GetRootLayer();
 
-  if( OptionalString s = constant.IsString( IsChild(node, "source-actor") ) )
+  if( OptionalString s = constant.IsString( IsChild(node, "sourceActor") ) )
   {
     Actor actor = root.FindChildByName(*s);
     if(actor)
@@ -574,7 +463,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme
     }
   }
 
-  if( OptionalString s = constant.IsString( IsChild(node, "camera-actor") ) )
+  if( OptionalString s = constant.IsString( IsChild(node, "cameraActor") ) )
   {
     CameraActor actor = CameraActor::DownCast( root.FindChildByName(*s) );
     if(actor)
@@ -587,7 +476,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme
     }
   }
 
-  if( OptionalString s = constant.IsString( IsChild(node, "target-frame-buffer") ) )
+  if( OptionalString s = constant.IsString( IsChild(node, "targetFrameBuffer") ) )
   {
     FrameBufferImage fb = GetFrameBufferImage( *s, constant );
     if(fb)
@@ -600,7 +489,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme
     }
   }
 
-  if( OptionalString s = constant.IsString( IsChild(node, "screen-to-frame-buffer-function") ) )
+  if( OptionalString s = constant.IsString( IsChild(node, "screenToFrameBufferFunction") ) )
   {
     if("DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION" == *s)
     {
@@ -617,8 +506,7 @@ void Builder::SetupTask( RenderTask& task, const TreeNode& node, const Replaceme
   }
 
   // other setup is via the property system
-  SetProperties( node, task, constant ); // @ todo, remove 'source-actor', 'camera-actor'?
-
+  SetProperties( node, task, constant );
 }
 
 void Builder::CreateRenderTask( const std::string &name )
@@ -629,7 +517,7 @@ void Builder::CreateRenderTask( const std::string &name )
 
   const Stage& stage = Stage::GetCurrent();
 
-  OptionalChild tasks = IsChild(*mParser.GetRoot(), "render-tasks");
+  OptionalChild tasks = IsChild(*mParser.GetRoot(), "renderTasks");
 
   if(tasks)
   {
@@ -668,34 +556,40 @@ void Builder::CreateRenderTask( const std::string &name )
   }
 }
 
-ShaderEffect Builder::GetShaderEffect( const std::string &name)
+FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
 {
   Replacement constant( mReplacementMap );
-  return GetShaderEffect( name, constant );
+  return GetFrameBufferImage(name, constant);
 }
 
-ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacement& constant )
+FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
 {
   DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
 
-  ShaderEffect ret;
+  FrameBufferImage ret;
 
-  ShaderEffectLut::const_iterator iter( mShaderEffectLut.find( name ) );
-  if( iter != mShaderEffectLut.end() )
+  ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
+  if( iter != mFrameBufferImageLut.end() )
   {
     ret = iter->second;
   }
   else
   {
-    if( OptionalChild effects = IsChild( *mParser.GetRoot(), "shader-effects") )
+    if( OptionalChild images = IsChild( *mParser.GetRoot(), "frameBufferImages") )
     {
-      if( OptionalChild effect = IsChild( *effects, name ) )
+      if( OptionalChild image = IsChild( *images, name ) )
       {
-        Dali::Property::Value propertyMap(Property::MAP);
-        if( SetPropertyFromNode( *effect, Property::MAP, propertyMap, constant ) )
+        Dali::Property::Value property(Property::MAP);
+        if( DeterminePropertyFromNode( *image, Property::MAP, property, constant ) )
         {
-          ret = Dali::Scripting::NewShaderEffect( propertyMap );
-          mShaderEffectLut[ name ] = ret;
+          Property::Map* map = property.GetMap();
+
+          if( map )
+          {
+            (*map)[ KEYNAME_TYPE ] = Property::Value(std::string("FrameBufferImage") );
+            ret = FrameBufferImage::DownCast( Dali::Scripting::NewImage( property ) );
+            mFrameBufferImageLut[ name ] = ret;
+          }
         }
       }
     }
@@ -704,66 +598,283 @@ ShaderEffect Builder::GetShaderEffect( const std::string &name, const Replacemen
   return ret;
 }
 
-FrameBufferImage Builder::GetFrameBufferImage( const std::string &name )
-{
-  Replacement constant( mReplacementMap );
-  return GetFrameBufferImage(name, constant);
-}
-
-FrameBufferImage Builder::GetFrameBufferImage( const std::string &name, const Replacement& constant )
+Path Builder::GetPath( const std::string& name )
 {
   DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
 
-  FrameBufferImage ret;
+  Path ret;
 
-  ImageLut::const_iterator iter( mFrameBufferImageLut.find( name ) );
-  if( iter != mFrameBufferImageLut.end() )
+  PathLut::const_iterator iter( mPathLut.find( name ) );
+  if( iter != mPathLut.end() )
   {
     ret = iter->second;
   }
   else
   {
-    if( OptionalChild images = IsChild( *mParser.GetRoot(), "frame-buffer-images") )
+    if( OptionalChild paths = IsChild( *mParser.GetRoot(), "paths") )
     {
-      if( OptionalChild image = IsChild( *images, name ) )
+      if( OptionalChild path = IsChild( *paths, name ) )
+      {
+        //points property
+        if( OptionalChild pointsProperty = IsChild( *path, "points") )
+        {
+          Dali::Property::Value points(Property::ARRAY);
+          if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+          {
+            ret = Path::New();
+            ret.SetProperty( Path::Property::POINTS, points);
+
+            //controlPoints property
+            if( OptionalChild pointsProperty = IsChild( *path, "controlPoints") )
+            {
+              Dali::Property::Value points(Property::ARRAY);
+              if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+              {
+                ret.SetProperty( Path::Property::CONTROL_POINTS, points);
+              }
+            }
+            else
+            {
+              //Curvature
+              float curvature(0.25f);
+              if( OptionalFloat pointsProperty = IsFloat( *path, "curvature") )
+              {
+                curvature = *pointsProperty;
+              }
+              ret.GenerateControlPoints(curvature);
+            }
+
+            //Add the new path to the hash table for paths
+            mPathLut[ name ] = ret;
+          }
+        }
+        else
+        {
+          //Interpolation points not specified
+          DALI_SCRIPT_WARNING("Interpolation points not specified for path '%s'\n", name.c_str() );
+        }
+      }
+
+    }
+  }
+
+  return ret;
+}
+
+PathConstrainer Builder::GetPathConstrainer( const std::string& name )
+{
+  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+  //Search the pathConstrainer in the LUT
+  size_t count( mPathConstrainerLut.size() );
+  for( size_t i(0); i!=count; ++i )
+  {
+    if( mPathConstrainerLut[i].name == name )
+    {
+      //PathConstrainer has already been created
+      return mPathConstrainerLut[i].pathConstrainer;
+    }
+  }
+
+  //Create a new PathConstrainer
+  PathConstrainer ret;
+  if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") )
+  {
+    if( OptionalChild pathConstrainer = IsChild( *constrainers, name ) )
+    {
+      OptionalString constrainerType(IsString(IsChild(*pathConstrainer, "type")));
+      if(!constrainerType)
+      {
+        DALI_SCRIPT_WARNING("Constrainer type not specified for constrainer '%s'\n", name.c_str() );
+      }
+      else if( *constrainerType == "PathConstrainer")
       {
-        Dali::Property::Value propertyMap(Property::MAP);
-        if( SetPropertyFromNode( *image, Property::MAP, propertyMap, constant ) )
+        //points property
+        if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "points") )
+        {
+          Dali::Property::Value points(Property::ARRAY);
+          if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+          {
+            ret = PathConstrainer::New();
+            ret.SetProperty( PathConstrainer::Property::POINTS, points);
+
+            //controlPoints property
+            if( OptionalChild pointsProperty = IsChild( *pathConstrainer, "controlPoints") )
+            {
+              Dali::Property::Value points(Property::ARRAY);
+              if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+              {
+                ret.SetProperty( PathConstrainer::Property::CONTROL_POINTS, points);
+              }
+
+              //Forward vector
+              OptionalVector3 forward( IsVector3( IsChild(*pathConstrainer, "forward" ) ) );
+              if( forward )
+              {
+                ret.SetProperty( PathConstrainer::Property::FORWARD, *forward);
+              }
+
+              //Add the new constrainer to the vector of PathConstrainer
+              PathConstrainerEntry entry = {name,ret};
+              mPathConstrainerLut.push_back( entry );
+            }
+            else
+            {
+              //Control points not specified
+              DALI_SCRIPT_WARNING("Control points not specified for pathConstrainer '%s'\n", name.c_str() );
+            }
+          }
+        }
+        else
         {
-          propertyMap.SetValue(KEYNAME_TYPE, Property::Value(std::string("FrameBufferImage")));
-          ret = Dali::Scripting::NewImage( propertyMap );
-          mFrameBufferImageLut[ name ] = ret;
+          //Interpolation points not specified
+          DALI_SCRIPT_WARNING("Interpolation points not specified for pathConstrainer '%s'\n", name.c_str() );
         }
       }
+      else
+      {
+        DALI_SCRIPT_WARNING("Constrainer '%s' is not a PathConstrainer\n", name.c_str() );
+      }
     }
   }
 
   return ret;
 }
 
-Font Builder::GetFont( const std::string& name ) const
+bool Builder::IsPathConstrainer( const std::string& name )
+{
+  size_t count( mPathConstrainerLut.size() );
+  for( size_t i(0); i!=count; ++i )
+  {
+    if( mPathConstrainerLut[i].name == name )
+    {
+      return true;
+    }
+  }
+
+  if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") )
+  {
+    if( OptionalChild constrainer = IsChild( *constrainers, name ) )
+    {
+      OptionalString constrainerType(IsString(IsChild(*constrainer, "type")));
+      if(!constrainerType)
+      {
+        return false;
+      }
+      else
+      {
+         return *constrainerType == "PathConstrainer";
+      }
+    }
+  }
+  return false;
+}
+
+Dali::LinearConstrainer Builder::GetLinearConstrainer( const std::string& name )
 {
-  // deprecated function.
-  Font font;
-  return font;
+  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+  //Search the LinearConstrainer in the LUT
+  size_t count( mLinearConstrainerLut.size() );
+  for( size_t i(0); i!=count; ++i )
+  {
+    if( mLinearConstrainerLut[i].name == name )
+    {
+      //LinearConstrainer has already been created
+      return mLinearConstrainerLut[i].linearConstrainer;
+    }
+  }
+
+  //Create a new LinearConstrainer
+  LinearConstrainer ret;
+  if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") )
+  {
+    if( OptionalChild linearConstrainer = IsChild( *constrainers, name ) )
+    {
+      OptionalString constrainerType(IsString(IsChild(*linearConstrainer, "type")));
+      if(!constrainerType)
+      {
+        DALI_SCRIPT_WARNING("Constrainer type not specified for constrainer '%s'\n", name.c_str() );
+      }
+      else if( *constrainerType == "LinearConstrainer")
+      {
+        //points property
+        if( OptionalChild pointsProperty = IsChild( *linearConstrainer, "value") )
+        {
+          Dali::Property::Value points(Property::ARRAY);
+          if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+          {
+            ret = Dali::LinearConstrainer::New();
+            ret.SetProperty( LinearConstrainer::Property::VALUE, points);
+
+            //controlPoints property
+            if( OptionalChild pointsProperty = IsChild( *linearConstrainer, "progress") )
+            {
+              Dali::Property::Value points(Property::ARRAY);
+              if( DeterminePropertyFromNode( *pointsProperty, Property::ARRAY, points ) )
+              {
+                ret.SetProperty( LinearConstrainer::Property::PROGRESS, points);
+              }
+            }
+            //Add the new constrainer to vector of LinearConstrainer
+            LinearConstrainerEntry entry = {name,ret};
+            mLinearConstrainerLut.push_back( entry );
+          }
+        }
+        else
+        {
+          //Interpolation points not specified
+          DALI_SCRIPT_WARNING("Values not specified for LinearConstrainer '%s'\n", name.c_str() );
+        }
+      }
+      else
+      {
+        DALI_SCRIPT_WARNING("Constrainer '%s' is not a LinearConstrainer\n", name.c_str() );
+      }
+    }
+  }
+
+  return ret;
 }
 
-TextStyle Builder::GetTextStyle( const std::string& name ) const
+bool Builder::IsLinearConstrainer( const std::string& name )
 {
-  // deprecated
-  return TextStyle();
+  // Search the LinearConstrainer in the LUT
+  size_t count( mLinearConstrainerLut.size() );
+  for( size_t i(0); i!=count; ++i )
+  {
+    if( mLinearConstrainerLut[i].name == name )
+    {
+      return true;
+    }
+  }
+
+  if( OptionalChild constrainers = IsChild( *mParser.GetRoot(), "constrainers") )
+  {
+    if( OptionalChild constrainer = IsChild( *constrainers, name ) )
+    {
+      OptionalString constrainerType(IsString(IsChild(*constrainer, "type")));
+      if(!constrainerType)
+      {
+        return false;
+      }
+      else
+      {
+         return *constrainerType == "LinearConstrainer";
+      }
+    }
+  }
+  return false;
 }
 
-Image Builder::GetImage( const std::string& name) const
+Toolkit::Builder::BuilderSignalType& Builder::QuitSignal()
 {
-  // deprecated function.
-  return Image();
+  return mQuitSignal;
 }
 
-Actor Builder::GetActor( const std::string &name ) const
+void Builder::EmitQuitSignal()
 {
-  // deprecated function.
-  return Actor();
+  mQuitSignal.Emit();
 }
 
 void Builder::AddActors( Actor toActor )
@@ -776,7 +887,7 @@ void Builder::AddActors( const std::string &sectionName, Actor toActor )
 {
   DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
 
-  PropertyValueMap overrideMap;
+  Property::Map overrideMap;
   Replacement replacements(overrideMap, mReplacementMap);
 
   OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
@@ -798,7 +909,7 @@ void Builder::AddActors( const std::string &sectionName, Actor toActor )
     // to add automatically
     if( "stage" == sectionName )
     {
-      if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "render-tasks") )
+      if( OptionalChild renderTasks = IsChild(*mParser.GetRoot(), "renderTasks") )
       {
         if( OptionalChild tasks = IsChild(*renderTasks, "stage") )
         {
@@ -819,7 +930,7 @@ Animation Builder::CreateAnimation( const std::string& animationName, const Repl
   {
     if( OptionalChild animation = IsChild(*animations, animationName) )
     {
-      anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor );
+      anim = Dali::Toolkit::Internal::CreateAnimation( *animation, replacement, sourceActor, this );
     }
     else
     {
@@ -834,13 +945,13 @@ Animation Builder::CreateAnimation( const std::string& animationName, const Repl
   return anim;
 }
 
-Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor )
+Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor )
 {
   Replacement replacement(map, mReplacementMap);
   return CreateAnimation( animationName, replacement, sourceActor);
 }
 
-Animation Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map )
+Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map )
 {
   Replacement replacement(map, mReplacementMap);
   return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
@@ -860,10 +971,126 @@ Animation Builder::CreateAnimation( const std::string& animationName )
   return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
 }
 
-void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
+bool Builder::ConvertChildValue( const TreeNode& mappingRoot, KeyStack& keyStack, Property::Value& child )
 {
-  DALI_ASSERT_ALWAYS( format == Dali::Toolkit::Builder::JSON && "Currently only JSON is supported" );
+  bool result = false;
 
+  switch( child.GetType() )
+  {
+    case Property::STRING:
+    {
+      std::string value;
+      if( child.Get( value ) )
+      {
+        std::string key;
+        if( GetMappingKey( value, key ) )
+        {
+          // Check key for cycles:
+          result=true;
+          for( KeyStack::iterator iter = keyStack.begin() ; iter != keyStack.end(); ++iter )
+          {
+            if( key.compare(*iter) == 0 )
+            {
+              // key is already in stack; stop.
+              DALI_LOG_WARNING("Detected cycle in stylesheet mapping table:%s\n", key.c_str());
+              child = Property::Value("");
+              result=false;
+              break;
+            }
+          }
+
+          if( result )
+          {
+            // The following call will overwrite the child with the value
+            // from the mapping.
+            RecursePropertyMap( mappingRoot, keyStack, key.c_str(), Property::NONE, child );
+            result = true;
+          }
+        }
+      }
+      break;
+    }
+
+    case Property::MAP:
+    {
+      Property::Map* map = child.GetMap();
+      if( map )
+      {
+        for( Property::Map::SizeType i=0; i < map->Count(); ++i )
+        {
+          Property::Value& child = map->GetValue(i);
+          ConvertChildValue(mappingRoot, keyStack, child);
+        }
+      }
+      break;
+    }
+
+    case Property::ARRAY:
+    {
+      Property::Array* array = child.GetArray();
+      if( array )
+      {
+        for( Property::Array::SizeType i=0; i < array->Count(); ++i )
+        {
+          Property::Value& child = array->GetElementAt(i);
+          ConvertChildValue(mappingRoot, keyStack, child);
+        }
+      }
+      break;
+    }
+
+    default:
+      // Ignore other types.
+      break;
+  }
+
+  return result;
+}
+
+bool Builder::RecursePropertyMap( const TreeNode& mappingRoot, KeyStack& keyStack, const char* theKey, Property::Type propertyType, Property::Value& value )
+{
+  Replacement replacer( mReplacementMap );
+  bool result = false;
+
+  keyStack.push_back( theKey );
+
+  for( TreeNode::ConstIterator iter = mappingRoot.CBegin(); iter != mappingRoot.CEnd(); ++iter )
+  {
+    std::string aKey( (*iter).first );
+    if( aKey.compare( theKey ) == 0 )
+    {
+      if( propertyType == Property::NONE )
+      {
+        DeterminePropertyFromNode( (*iter).second, value, replacer );
+        result = true;
+      }
+      else
+      {
+        result = DeterminePropertyFromNode( (*iter).second, propertyType, value, replacer );
+      }
+
+      if( result )
+      {
+        ConvertChildValue(mappingRoot, keyStack, value);
+      }
+      break;
+    }
+  }
+  keyStack.pop_back();
+
+  return result;
+}
+
+
+bool Builder::GetPropertyMap( const TreeNode& mappingRoot, const char* theKey, Property::Type propertyType, Property::Value& value )
+{
+  KeyStack keyStack;
+  return RecursePropertyMap( mappingRoot, keyStack, theKey, propertyType, value );
+}
+
+
+void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::UIFormat format )
+{
   // parser to get constants and includes only
   Dali::Toolkit::JsonParser parser = Dali::Toolkit::JsonParser::New();
 
@@ -875,7 +1102,6 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U
                       parser.GetErrorDescription().c_str() );
 
     DALI_ASSERT_ALWAYS(!"Cannot parse JSON");
-
   }
   else
   {
@@ -912,16 +1138,15 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U
     }
   }
 
-  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
+  DUMP_PARSE_TREE(parser); // This macro only writes out if DEBUG is enabled and the "DUMP_TREE" constant is defined in the stylesheet.
+  DUMP_TEST_MAPPINGS(parser);
 
+  DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
 }
 
-void Builder::AddConstants( const PropertyValueMap& map )
+void Builder::AddConstants( const Property::Map& map )
 {
-  for(PropertyValueMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
-  {
-    mReplacementMap[ (*iter).first ] = (*iter).second;
-  }
+  mReplacementMap.Merge( map );
 }
 
 void Builder::AddConstant( const std::string& key, const Property::Value& value )
@@ -929,17 +1154,17 @@ void Builder::AddConstant( const std::string& key, const Property::Value& value
   mReplacementMap[key] = value;
 }
 
-const PropertyValueMap& Builder::GetConstants() const
+const Property::Map& Builder::GetConstants() const
 {
   return mReplacementMap;
 }
 
 const Property::Value& Builder::GetConstant( const std::string& key ) const
 {
-  PropertyValueMap::const_iterator iter = mReplacementMap.find( key );
-  if( iter  != mReplacementMap.end() )
+  Property::Value* match = mReplacementMap.Find( key );
+  if( match )
   {
-    return (*iter).second;
+    return (*match);
   }
   else
   {
@@ -948,7 +1173,7 @@ const Property::Value& Builder::GetConstant( const std::string& key ) const
   }
 }
 
-void Builder::LoadConstants( const TreeNode& root, PropertyValueMap& intoMap )
+void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap )
 {
   Replacement replacer(intoMap);
 
@@ -963,24 +1188,17 @@ void Builder::LoadConstants( const TreeNode& root, PropertyValueMap& intoMap )
 #if defined(DEBUG_ENABLED)
         DALI_SCRIPT_VERBOSE("Constant set from json '%s'\n", (*iter).second.GetName());
 #endif
-        if( SetPropertyFromNode( (*iter).second, property, replacer ) )
-        {
-          intoMap[ (*iter).second.GetName() ] = property;
-        }
-        else
-        {
-          DALI_SCRIPT_WARNING("Cannot convert property for constant %s\n",
-                              (*iter).second.GetName() == NULL ? "no name?" : (*iter).second.GetName());
-        }
+        DeterminePropertyFromNode( (*iter).second, property, replacer );
+        intoMap[ (*iter).second.GetName() ] = property;
       }
     }
   }
 
 #if defined(DEBUG_ENABLED)
-  PropertyValueMap::const_iterator iter = intoMap.find( "CONFIG_SCRIPT_LOG_LEVEL" );
-  if( iter != intoMap.end() && (*iter).second.GetType() == Property::STRING )
+  Property::Value* iter = intoMap.Find( "CONFIG_SCRIPT_LOG_LEVEL" );
+  if( iter && iter->GetType() == Property::STRING )
   {
-    std::string logLevel( (*iter).second.Get< std::string >() );
+    std::string logLevel( iter->Get< std::string >() );
     if( logLevel == "NoLogging" )
     {
       gFilterScript->SetLogLevel( Integration::Log::NoLogging );
@@ -1002,31 +1220,33 @@ void Builder::LoadConstants( const TreeNode& root, PropertyValueMap& intoMap )
 
 }
 
-void Builder::ApplyStyle( const std::string& styleName, Handle& handle )
+bool Builder::ApplyStyle( const std::string& styleName, Handle& handle )
 {
   Replacement replacer( mReplacementMap );
-  ApplyStyle( styleName, handle, replacer );
+  return ApplyStyle( styleName, handle, replacer );
 }
 
-void Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
+bool Builder::ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement )
 {
   DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
 
   OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
-  OptionalChild style  = IsChild( *styles, styleName );
+
+  std::string styleNameLower(styleName);
+  OptionalChild style  = IsChildIgnoreCase( *styles, styleNameLower );
 
   if( styles && style )
   {
     ApplyAllStyleProperties( *mParser.GetRoot(), *style, handle, replacement );
+    return true;
   }
   else
   {
-    DALI_SCRIPT_WARNING("No styles section to create style '%s'\n", styleName.c_str());
+    return false;
   }
-
 }
 
-BaseHandle Builder::Create( const std::string& templateName, const PropertyValueMap& map )
+BaseHandle Builder::Create( const std::string& templateName, const Property::Map& map )
 {
   Replacement replacement( map, mReplacementMap );
   return Create( templateName, replacement );
@@ -1069,6 +1289,44 @@ BaseHandle Builder::Create( const std::string& templateName, const Replacement&
   return baseHandle;
 }
 
+BaseHandle Builder::CreateFromJson( const std::string& json )
+{
+  BaseHandle ret;
+
+  // merge in new template, hoping no one else has one named '@temp@'
+  std::string newTemplate =
+    std::string("{\"templates\":{\"@temp@\":") +                      \
+    json +                                                            \
+    std::string("}}");
+
+  if( mParser.Parse(newTemplate) )
+  {
+    Replacement replacement( mReplacementMap );
+    ret = Create( "@temp@", replacement );
+  }
+
+  return ret;
+}
+
+bool Builder::ApplyFromJson(  Handle& handle, const std::string& json )
+{
+  bool ret = false;
+
+  // merge new style, hoping no one else has one named '@temp@'
+  std::string newStyle =
+    std::string("{\"styles\":{\"@temp@\":") +                           \
+    json +                                                              \
+    std::string("}}");
+
+  if( mParser.Parse(newStyle) )
+  {
+    Replacement replacement( mReplacementMap );
+    ret = ApplyStyle( "@temp@", handle, replacement );
+  }
+
+  return ret;
+}
+
 
 BaseHandle Builder::Create( const std::string& templateName )
 {
@@ -1080,6 +1338,14 @@ Builder::Builder()
 : mSlotDelegate( this )
 {
   mParser = Dali::Toolkit::JsonParser::New();
+
+  Property::Map defaultDirs;
+  defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ]       = DALI_IMAGE_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_SOUND_DIR) ]       = DALI_SOUND_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_STYLE_DIR) ]       = DALI_STYLE_DIR;
+  defaultDirs[ TOKEN_STRING(DALI_STYLE_IMAGE_DIR) ] = DALI_STYLE_IMAGE_DIR;
+
+  AddConstants( defaultDirs );
 }
 
 Builder::~Builder()