Initially show scroll indicator for a brief period
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-view-impl.cpp
index 690704d..3063cbc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -26,6 +26,7 @@
 #include <dali/public-api/events/touch-data.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/object/property-map.h>
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
@@ -624,7 +625,7 @@ Dali::Toolkit::ScrollView ScrollView::New()
 }
 
 ScrollView::ScrollView()
-: ScrollBase( ControlBehaviour( REQUIRES_WHEEL_EVENTS ) ),   // Enable size negotiation
+: ScrollBase( ControlBehaviour( REQUIRES_WHEEL_EVENTS | DISABLE_STYLE_CHANGE_SIGNALS ) ),   // Enable size negotiation
   mTouchDownTime(0u),
   mGestureStackDepth(0),
   mScrollStateFlags(0),
@@ -658,7 +659,8 @@ ScrollView::ScrollView()
   mAlterChild(false),
   mDefaultMaxOvershoot(true),
   mCanScrollHorizontal(true),
-  mCanScrollVertical(true)
+  mCanScrollVertical(true),
+  mTransientScrollBar(true)
 {
 }
 
@@ -701,8 +703,6 @@ void ScrollView::OnInitialize()
 
 void ScrollView::OnStageConnection( int depth )
 {
-  ScrollBase::OnStageConnection( depth );
-
   DALI_LOG_SCROLL_STATE("[0x%X]", this);
 
   if ( mSensitive )
@@ -710,11 +710,14 @@ void ScrollView::OnStageConnection( int depth )
     SetScrollSensitive( false );
     SetScrollSensitive( true );
   }
+
   if(IsOvershootEnabled())
   {
     // try and make sure property notifications are set
     EnableScrollOvershoot(true);
   }
+
+  ScrollBase::OnStageConnection( depth );
 }
 
 void ScrollView::OnStageDisconnection()
@@ -1176,19 +1179,6 @@ Vector2 ScrollView::GetCurrentScrollPosition() const
   return -GetPropertyPosition();
 }
 
-Vector2 ScrollView::GetDomainSize() const
-{
-  Vector3 size = Self().GetCurrentSize();
-
-  const RulerDomain& xDomain = GetRulerX()->GetDomain();
-  const RulerDomain& yDomain = GetRulerY()->GetDomain();
-
-  Vector2 domainSize;
-  domainSize.x = xDomain.max - xDomain.min - size.x;
-  domainSize.y = yDomain.max - yDomain.min - size.y;
-  return domainSize;
-}
-
 void ScrollView::TransformTo(const Vector2& position,
                              DirectionBias horizontalBias, DirectionBias verticalBias)
 {
@@ -1706,6 +1696,7 @@ bool ScrollView::AnimateTo(const Vector2& position, const Vector2& positionDurat
   // Position Delta ///////////////////////////////////////////////////////
   if(positionChanged)
   {
+    UpdateMainInternalConstraint();
     if(mWrapMode && findShortcuts)
     {
       // In Wrap Mode, the shortest distance is a little less intuitive...
@@ -1792,6 +1783,15 @@ void ScrollView::RemoveOverlay(Actor actor)
   mInternalActor.Remove( actor );
 }
 
+void ScrollView::SetOvershootSize( const Vector2& size )
+{
+  mOvershootSize = size;
+  if( IsOvershootEnabled() && mOvershootIndicator )
+  {
+    mOvershootIndicator->AttachToScrollable(*this);
+  }
+}
+
 void ScrollView::SetOvershootEffectColor( const Vector4& color )
 {
   mOvershootEffectColor = color;
@@ -1953,6 +1953,8 @@ void ScrollView::OnSizeSet( const Vector3& size )
   {
     mOvershootIndicator->Reset();
   }
+
+  ScrollBase::OnSizeSet( size );
 }
 
 void ScrollView::OnChildAdd(Actor& child)
@@ -1960,24 +1962,34 @@ void ScrollView::OnChildAdd(Actor& child)
   ScrollBase::OnChildAdd( child );
 
   Dali::Toolkit::ScrollBar scrollBar = Dali::Toolkit::ScrollBar::DownCast(child);
-  if(scrollBar)
+  if( scrollBar )
   {
-    mInternalActor.Add(scrollBar);
-    if(scrollBar.GetScrollDirection() == Toolkit::ScrollBar::Horizontal)
+    mScrollBar = scrollBar;
+    scrollBar.SetName("ScrollBar");
+
+    mInternalActor.Add( scrollBar );
+    if( scrollBar.GetScrollDirection() == Toolkit::ScrollBar::Horizontal )
     {
-      scrollBar.SetScrollPropertySource(Self(),
-                                        Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_X,
-                                        Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_X,
-                                        Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_X,
-                                        Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_X);
+      scrollBar.SetScrollPropertySource( Self(),
+                                         Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_X,
+                                         Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_X,
+                                         Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_X,
+                                         Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_X );
     }
     else
     {
-      scrollBar.SetScrollPropertySource(Self(),
-                                        Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_Y,
-                                        Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_Y,
-                                        Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_Y,
-                                        Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_Y);
+      scrollBar.SetScrollPropertySource( Self(),
+                                         Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_Y,
+                                         Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_Y,
+                                         Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_Y,
+                                         Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_Y );
+    }
+
+    if( mTransientScrollBar )
+    {
+      // Show the scroll-indicator for a brief period
+      Property::Map emptyMap;
+      scrollBar.DoAction( "ShowTransientIndicator", emptyMap );
     }
   }
   else if(mAlterChild)
@@ -2476,6 +2488,18 @@ void ScrollView::OnPan( const PanGesture& gesture )
       self.SetProperty( Toolkit::ScrollView::Property::START_PAGE_POSITION, Vector3(gesture.position.x, gesture.position.y, 0.0f) );
 
       UpdateMainInternalConstraint();
+      Toolkit::ScrollBar scrollBar = mScrollBar.GetHandle();
+      if( scrollBar && mTransientScrollBar )
+      {
+        Vector3 size = Self().GetCurrentSize();
+        const Toolkit::RulerDomain& rulerDomainX = mRulerX->GetDomain();
+        const Toolkit::RulerDomain& rulerDomainY = mRulerY->GetDomain();
+
+        if( ( rulerDomainX.max > size.width ) || ( rulerDomainY.max > size.height ) )
+        {
+          scrollBar.ShowIndicator();
+        }
+      }
       break;
     }
 
@@ -2510,6 +2534,12 @@ void ScrollView::OnPan( const PanGesture& gesture )
         {
           mScrollMainInternalPrePositionConstraint.Remove();
         }
+
+        Toolkit::ScrollBar scrollBar = mScrollBar.GetHandle();
+        if( scrollBar && mTransientScrollBar )
+        {
+          scrollBar.HideIndicator();
+        }
       }
       else
       {