[Tizen](ATSPI) squashed implementation
[platform/core/uifw/dali-demo.git] / shared / dali-table-view.cpp
index 6791aaa..2832236 100644 (file)
@@ -27,6 +27,7 @@
 #include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
 
 // INTERNAL INCLUDES
 #include "shared/view.h"
@@ -41,9 +42,6 @@ namespace
 {
 
 const std::string LOGO_PATH( DEMO_IMAGE_DIR "Logo-for-demo.png" );
-const std::string TILE_BACKGROUND(DEMO_IMAGE_DIR "item-background.9.png");
-const std::string TILE_BACKGROUND_ALPHA( DEMO_IMAGE_DIR "demo-tile-texture.9.png" );
-const std::string TILE_FOCUS( DEMO_IMAGE_DIR "tile-focus.9.png" );
 
 // Keyboard focus effect constants.
 const float KEYBOARD_FOCUS_ANIMATION_DURATION = 1.0f;           ///< The total duration of the keyboard focus animation
@@ -71,7 +69,7 @@ const float STENCIL_RELATIVE_SIZE = 1.0f;
 const float EFFECT_SNAP_DURATION = 0.66f;                       ///< Scroll Snap Duration for Effects
 const float EFFECT_FLICK_DURATION = 0.5f;                       ///< Scroll Flick Duration for Effects
 const Vector3 ANGLE_CUBE_PAGE_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f);
-const Vector4 TILE_COLOR( 0.4f, 0.6f, 0.9f, 0.6f );
+
 
 const Vector4 BUBBLE_COLOR[] =
 {
@@ -103,29 +101,6 @@ const Vector4 BACKGROUND_COLOR( 0.3569f, 0.5451f, 0.7294f, 1.0f );
 const float BUBBLE_MIN_Z = -1.0;
 const float BUBBLE_MAX_Z = 0.0f;
 
-// This shader takes a texture.
-// An alpha discard is performed.
-// The shader uses the tiles position within the scroll-view page and the scroll-views rotation position to create a parallax effect.
-const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER(
-  varying mediump vec2  vTexCoord;
-  uniform lowp    vec4  uColor;
-  uniform sampler2D     sTexture;
-  uniform mediump vec3  uCustomPosition;
-
-  void main()
-  {
-    if( texture2D( sTexture, vTexCoord ).a <= 0.0001 )
-    {
-      discard;
-    }
-
-    mediump vec2 wrapTexCoord = vec2( ( vTexCoord.x / 4.0 ) + ( uCustomPosition.x / 4.0 ) + ( uCustomPosition.z / 2.0 ), vTexCoord.y / 4.0 );
-    mediump vec4 color = texture2D( sTexture, wrapTexCoord );
-    mediump float positionWeight = ( uCustomPosition.y + 0.3 ) * color.r * 2.0;
-
-    gl_FragColor = vec4( positionWeight, positionWeight, positionWeight, 0.9 ) * uColor + vec4( uColor.xyz, 0.0 );
-  }
-);
 
 /**
  * Creates the background image
@@ -342,12 +317,12 @@ void DaliTableView::CreateFocusEffect()
   // Hook the required signals to manage the focus.
   KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &DaliTableView::OnKeyboardPreFocusChange );
   KeyboardFocusManager::Get().FocusedActorEnterKeySignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
-  AccessibilityManager::Get().FocusedActorActivatedSignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
 
   // Loop to create both actors for the focus highlight effect.
   for( unsigned int i = 0; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i )
   {
-    mFocusEffect[i].actor = ImageView::New( TILE_FOCUS );
+    mFocusEffect[i].actor = ImageView::New();
+    mFocusEffect[i].actor.SetStyleName( "FocusActor" );
     mFocusEffect[i].actor.SetParentOrigin( ParentOrigin::CENTER );
     mFocusEffect[i].actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
     mFocusEffect[i].actor.SetInheritScale( false );
@@ -409,7 +384,6 @@ void DaliTableView::Populate()
       sort( mExampleList.begin(), mExampleList.end(), CompareByTitle );
     }
 
-    unsigned int exampleCount = 0;
     ExampleListConstIter iter = mExampleList.begin();
 
     for( int t = 0; t < mTotalPages; t++ )
@@ -434,14 +408,6 @@ void DaliTableView::Populate()
           // Calculate the tiles relative position on the page (between 0 & 1 in each dimension).
           Vector2 position( static_cast<float>( column ) / ( EXAMPLES_PER_ROW - 1.0f ), static_cast<float>( row ) / ( EXAMPLES_PER_ROW - 1.0f ) );
           Actor tile = CreateTile( example.name, example.title, Vector3( tileParentMultiplier, tileParentMultiplier, 1.0f ), position );
-          AccessibilityManager accessibilityManager = AccessibilityManager::Get();
-          accessibilityManager.SetFocusOrder( tile, ++exampleCount );
-          accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_LABEL,
-                                                  example.title );
-          accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_TRAIT, "Tile" );
-          accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_HINT,
-                                                  "You can run this example" );
-
           tile.SetPadding( Padding( margin, margin, margin, margin ) );
           page.AddChild( tile, TableView::CellPosition( row, column ) );
 
@@ -502,7 +468,9 @@ void DaliTableView::Rotate( unsigned int degrees )
 
 Actor DaliTableView::CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Vector2& position )
 {
-  Actor focusableTile = Actor::New();
+  Toolkit::ImageView focusableTile = ImageView::New();
+
+  focusableTile.SetStyleName( "DemoTile" );
   focusableTile.SetParentOrigin( ParentOrigin::CENTER );
   focusableTile.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
   focusableTile.SetSizeModeFactor( sizeMultiplier );
@@ -511,42 +479,27 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit
   // Set the tile to be keyboard focusable
   focusableTile.SetKeyboardFocusable( true );
 
-  Toolkit::ImageView tileContent = ImageView::New();
-  tileContent.SetParentOrigin( ParentOrigin::CENTER );
-  tileContent.SetAnchorPoint( AnchorPoint::CENTER );
-  tileContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-
- // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
+  // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
   Property::Value value = Vector3( 0.0f, 0.0f, 0.0f );
-  Property::Index propertyIndex = tileContent.RegisterProperty( "uCustomPosition", value );
-
-  // Add a shader to the image (details in shader source).
-  Property::Map customShader;
-  customShader[ Visual::Shader::Property::FRAGMENT_SHADER ] = FRAGMENT_SHADER_TEXTURED;
-
-  // Set the Image URL and the custom shader
-  Property::Map imageMap;
-  imageMap.Add( ImageVisual::Property::URL, TILE_BACKGROUND_ALPHA );
-  imageMap.Add( Visual::Property::SHADER, customShader );
-  tileContent.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
-
-  tileContent.SetColor( TILE_COLOR );
+  Property::Index propertyIndex = focusableTile.RegisterProperty( "uCustomPosition", value );
 
   // We create a constraint to perform a precalculation on the scroll-view X offset
   // and pass it to the shader uniform, along with the tile's position.
-  Constraint shaderPosition = Constraint::New < Vector3 > ( tileContent, propertyIndex, TileShaderPositionConstraint( mPageWidth, position.x ) );
+  Constraint shaderPosition = Constraint::New < Vector3 > ( focusableTile, propertyIndex, TileShaderPositionConstraint( mPageWidth, position.x ) );
   shaderPosition.AddSource( Source( mScrollView, ScrollView::Property::SCROLL_POSITION ) );
   shaderPosition.SetRemoveAction( Constraint::Discard );
   shaderPosition.Apply();
-  focusableTile.Add( tileContent );
+  //focusableTile.Add( tileContent );
 
   // Create an ImageView for the 9-patch border around the tile.
-  ImageView borderImage = ImageView::New( TILE_BACKGROUND );
+  ImageView borderImage = ImageView::New();
+  borderImage.SetStyleName("DemoTileBorder");
   borderImage.SetAnchorPoint( AnchorPoint::CENTER );
   borderImage.SetParentOrigin( ParentOrigin::CENTER );
   borderImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
   borderImage.SetOpacity( 0.8f );
-  tileContent.Add( borderImage );
+  DevelControl::AppendAccessibilityRelation( borderImage, focusableTile, Accessibility::RelationType::CONTROLLED_BY );
+  focusableTile.Add( borderImage );
 
   TextLabel label = TextLabel::New();
   label.SetAnchorPoint( AnchorPoint::CENTER );
@@ -560,11 +513,18 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit
 
   // Pad around the label as its size is the same as the 9-patch border. It will overlap it without padding.
   label.SetPadding( Padding( TILE_LABEL_PADDING, TILE_LABEL_PADDING, TILE_LABEL_PADDING, TILE_LABEL_PADDING ) );
+  label.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false );
+  DevelControl::AppendAccessibilityRelation( label, focusableTile, Accessibility::RelationType::CONTROLLED_BY );
   focusableTile.Add( label );
 
   // Connect to the touch events
   focusableTile.TouchSignal().Connect( this, &DaliTableView::OnTilePressed );
   focusableTile.HoveredSignal().Connect( this, &DaliTableView::OnTileHovered );
+  focusableTile.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::PUSH_BUTTON );
+  DevelControl::AccessibilityActivateSignal( focusableTile ).Connect( this, [=]() {
+    DoTilePress( focusableTile, PointState::DOWN );
+    DoTilePress( focusableTile, PointState::UP );
+  } );
 
   return focusableTile;
 }
@@ -656,10 +616,6 @@ void DaliTableView::OnScrollStart( const Dali::Vector2& position )
 void DaliTableView::OnScrollComplete( const Dali::Vector2& position )
 {
   mScrolling = false;
-
-  // move focus to 1st item of new page
-  AccessibilityManager accessibilityManager = AccessibilityManager::Get();
-  accessibilityManager.SetCurrentFocusActor(mPages[mScrollView.GetCurrentPage()].GetChildAt(0) );
 }
 
 bool DaliTableView::OnScrollTouched( Actor actor, const TouchData& event )
@@ -792,7 +748,7 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count )
     Dali::Property::Map effect = Toolkit::CreateDistanceFieldEffect();
     Property::Map imageMap;
     imageMap.Add( ImageVisual::Property::URL, SHAPE_IMAGE_TABLE[ shapeType ] );
-    imageMap.Add( Visual::Property::SHADER, effect );
+    imageMap.Add( Toolkit::Visual::Property::SHADER, effect );
     dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
 
     dfActor.SetColor( BUBBLE_COLOR[ i%NUMBER_OF_BUBBLE_COLOR ] );