Remove OnControl methods & add up-calls 66/65366/5
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 8 Apr 2016 16:55:28 +0000 (17:55 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 11 Apr 2016 10:56:14 +0000 (11:56 +0100)
Additionally, correctly sets the background renderer size when OnSizeSet is called.

Change-Id: I6952e0a2e317b54bdb28adf2b013ca1244595522

23 files changed:
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp
dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp
dali-toolkit/internal/controls/bloom-view/bloom-view-impl.h
dali-toolkit/internal/controls/buttons/button-impl.cpp
dali-toolkit/internal/controls/buttons/button-impl.h
dali-toolkit/internal/controls/effects-view/effects-view-impl.cpp
dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.cpp
dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.h
dali-toolkit/internal/controls/image-view/image-view-impl.cpp
dali-toolkit/internal/controls/magnifier/magnifier-impl.cpp
dali-toolkit/internal/controls/popup/popup-impl.cpp
dali-toolkit/internal/controls/popup/popup-impl.h
dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp
dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp
dali-toolkit/internal/controls/shadow-view/shadow-view-impl.h
dali-toolkit/internal/controls/table-view/table-view-impl.cpp
dali-toolkit/internal/controls/table-view/table-view-impl.h
dali-toolkit/internal/controls/tool-bar/tool-bar-impl.cpp
dali-toolkit/internal/controls/tool-bar/tool-bar-impl.h
dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp
dali-toolkit/public-api/controls/control-impl.cpp
dali-toolkit/public-api/controls/control-impl.h
docs/content/shared-javascript-and-cpp-documentation/creating-custom-controls.md

index 7b0ca45..c4dac4e 100644 (file)
@@ -122,12 +122,12 @@ void DummyControlImplOverride::OnPinch(const PinchGesture& pinch) { pinchCalled
 void DummyControlImplOverride::OnPan(const PanGesture& pan) { panCalled = true; }
 void DummyControlImplOverride::OnTap(const TapGesture& tap) { tapCalled = true; }
 void DummyControlImplOverride::OnLongPress(const LongPressGesture& longPress) { longPressCalled = true; }
-void DummyControlImplOverride::OnStageConnection( int depth ) { stageConnectionCalled = true; }
-void DummyControlImplOverride::OnStageDisconnection() { stageDisconnectionCalled = true; }
+void DummyControlImplOverride::OnStageConnection( int depth ) { Control::OnStageConnection( depth ); stageConnectionCalled = true; }
+void DummyControlImplOverride::OnStageDisconnection() { stageDisconnectionCalled = true; Control::OnStageDisconnection(); }
 void DummyControlImplOverride::OnChildAdd(Actor& child) { childAddCalled = true; }
 void DummyControlImplOverride::OnChildRemove(Actor& child) { childRemoveCalled = true; }
-void DummyControlImplOverride::OnSizeSet(const Vector3& targetSize) { sizeSetCalled = true; }
-void DummyControlImplOverride::OnSizeAnimation(Animation& animation, const Vector3& targetSize) { sizeAnimationCalled = true; }
+void DummyControlImplOverride::OnSizeSet(const Vector3& targetSize) { Control::OnSizeSet( targetSize ); sizeSetCalled = true; }
+void DummyControlImplOverride::OnSizeAnimation(Animation& animation, const Vector3& targetSize) { Control::OnSizeAnimation( animation, targetSize ); sizeAnimationCalled = true; }
 bool DummyControlImplOverride::OnTouchEvent(const TouchEvent& event) { touchEventCalled = true; return false; }
 bool DummyControlImplOverride::OnHoverEvent(const HoverEvent& event) { hoverEventCalled = true; return false; }
 bool DummyControlImplOverride::OnWheelEvent(const WheelEvent& event) { wheelEventCalled = true; return false; }
index 4d088d1..474a16e 100644 (file)
@@ -290,6 +290,8 @@ void BloomView::OnInitialize()
 
 void BloomView::OnSizeSet(const Vector3& targetSize)
 {
+  Control::OnSizeSet( targetSize );
+
   mTargetSize = Vector2(targetSize);
   mChildrenRoot.SetSize(targetSize);
   mCompositeImageActor.SetSize(targetSize);
@@ -313,17 +315,21 @@ void BloomView::OnSizeSet(const Vector3& targetSize)
   }
 }
 
-void BloomView::OnControlChildAdd( Actor& child )
+void BloomView::OnChildAdd( Actor& child )
 {
+  Control::OnChildAdd( child );
+
   if( child != mChildrenRoot && child != mInternalRoot)
   {
     mChildrenRoot.Add( child );
   }
 }
 
-void BloomView::OnControlChildRemove( Actor& child )
+void BloomView::OnChildRemove( Actor& child )
 {
   mChildrenRoot.Remove( child );
+
+  Control::OnChildRemove( child );
 }
 
 void BloomView::AllocateResources()
index ea3f7e5..14e1d3c 100644 (file)
@@ -85,14 +85,14 @@ private:
   virtual void OnSizeSet(const Vector3& targetSize);
 
   /**
-   * @copydoc Control::OnControlChildAdd()
+   * @copydoc Control::OnChildAdd()
    */
-  virtual void OnControlChildAdd( Actor& child );
+  virtual void OnChildAdd( Actor& child );
 
   /**
-   * @copydoc Control::OnControlChildRemove()
+   * @copydoc Control::OnChildRemove()
    */
-  virtual void OnControlChildRemove( Actor& child );
+  virtual void OnChildRemove( Actor& child );
 
   void AllocateResources();
   void CreateRenderTasks();
index 3132b20..b923295 100644 (file)
@@ -1049,10 +1049,12 @@ bool Button::OnKeyboardEnter()
   return ret;
 }
 
-void Button::OnControlStageDisconnection()
+void Button::OnStageDisconnection()
 {
   OnButtonStageDisconnection(); // Notification for derived classes.
   mState = ButtonUp;
+
+  Control::OnStageDisconnection();
 }
 
 void Button::OnTap(Actor actor, const TapGesture& tap)
index 7adb67c..2ff121d 100644 (file)
@@ -511,7 +511,7 @@ private: // From Control
    * Callback received when the button is disconnected from the stage.
    * It resets the button status.
    */
-  void OnControlStageDisconnection();
+  void OnStageDisconnection();
 
 private:
 
index 8d1a3b3..28b64fa 100644 (file)
@@ -317,6 +317,8 @@ void EffectsView::OnInitialize()
 
 void EffectsView::OnSizeSet(const Vector3& targetSize)
 {
+  Control::OnSizeSet( targetSize );
+
   mTargetSize = Vector2(targetSize);
 
   // if we are already on stage, need to update render target sizes now to reflect the new size of this actor
@@ -365,6 +367,8 @@ void EffectsView::OnStageDisconnection()
   {
     mFilters[i]->Disable();
   }
+
+  Control::OnStageDisconnection();
 }
 
 void EffectsView::SetupFilters()
index 8a608f1..6081c0b 100644 (file)
@@ -331,6 +331,8 @@ void GaussianBlurView::OnInitialize()
 
 void GaussianBlurView::OnSizeSet(const Vector3& targetSize)
 {
+  Control::OnSizeSet( targetSize );
+
   mTargetSize = Vector2(targetSize);
 
   mChildrenRoot.SetSize(targetSize);
@@ -357,17 +359,21 @@ void GaussianBlurView::OnSizeSet(const Vector3& targetSize)
   }
 }
 
-void GaussianBlurView::OnControlChildAdd( Actor& child )
+void GaussianBlurView::OnChildAdd( Actor& child )
 {
+  Control::OnChildAdd( child );
+
   if( child != mChildrenRoot && child != mInternalRoot)
   {
     mChildrenRoot.Add( child );
   }
 }
 
-void GaussianBlurView::OnControlChildRemove( Actor& child )
+void GaussianBlurView::OnChildRemove( Actor& child )
 {
   mChildrenRoot.Remove( child );
+
+  Control::OnChildRemove( child );
 }
 
 void GaussianBlurView::AllocateResources()
index 1d8332e..9b6d564 100644 (file)
@@ -99,14 +99,14 @@ private:
   virtual void OnSizeSet(const Vector3& targetSize);
 
   /**
-   * @copydoc Control::OnControlChildAdd()
+   * @copydoc Control::OnChildAdd()
    */
-  virtual void OnControlChildAdd( Actor& child );
+  virtual void OnChildAdd( Actor& child );
 
   /**
-   * @copydoc Control::OnControlChildRemove()
+   * @copydoc Control::OnChildRemove()
    */
-  virtual void OnControlChildRemove( Actor& child );
+  virtual void OnChildRemove( Actor& child );
 
   void SetBlurBellCurveWidth(float blurBellCurveWidth);
   float CalcGaussianWeight(float x);
index f7c36a7..3eb0144 100644 (file)
@@ -246,6 +246,8 @@ void ImageView::OnStageDisconnection()
 
 void ImageView::OnSizeSet( const Vector3& targetSize )
 {
+  Control::OnSizeSet( targetSize );
+
   if( mRenderer )
   {
     Vector2 size( targetSize );
index 796e7bb..dfc7e1b 100644 (file)
@@ -280,6 +280,8 @@ void Magnifier::SetFrameVisibility(bool visible)
 
 void Magnifier::OnSizeSet(const Vector3& targetSize)
 {
+  Control::OnSizeSet( targetSize );
+
   // TODO: Once Camera/CameraActor properties function as proper animatable properties
   // this code can disappear.
   // whenever the size of the magnifier changes, the field of view needs to change
index 4a260c5..de35289 100755 (executable)
@@ -1506,14 +1506,18 @@ bool Popup::OnDialogTouched(Actor actor, const TouchEvent& event)
   return true;
 }
 
-void Popup::OnControlStageConnection()
+void Popup::OnStageConnection( int depth )
 {
+  Control::OnStageConnection( depth );
+
   mLayoutDirty = true;
   RelayoutRequest();
 }
 
-void Popup::OnControlChildAdd( Actor& child )
+void Popup::OnChildAdd( Actor& child )
 {
+  Control::OnChildAdd( child );
+
   // Re-parent any children added by user to the body layer.
   if( mAlterAddedChild )
   {
index 6893716..91d68b7 100755 (executable)
@@ -432,13 +432,13 @@ private:
   /**
    * Called when the popup is directly or indirectly parented to the stage.
    */
-  virtual void OnControlStageConnection();
+  virtual void OnStageConnection( int depth );
 
   /**
    * From Control; called after a child has been added to the owning actor.
    * @param[in] child The child which has been added.
    */
-  virtual void OnControlChildAdd( Actor& child );
+  virtual void OnChildAdd( Actor& child );
 
   /**
    * @copydoc Control::OnRelayOut()
index 82df8cc..33dbe22 100644 (file)
@@ -1956,6 +1956,8 @@ void ScrollView::OnSizeSet( const Vector3& size )
 
 void ScrollView::OnChildAdd(Actor& child)
 {
+  ScrollBase::OnChildAdd( child );
+
   Dali::Toolkit::ScrollBar scrollBar = Dali::Toolkit::ScrollBar::DownCast(child);
   if(scrollBar)
   {
@@ -1987,6 +1989,8 @@ void ScrollView::OnChildRemove(Actor& child)
 {
   // TODO: Actor needs a RemoveConstraint method to take out an individual constraint.
   UnbindActor(child);
+
+  ScrollBase::OnChildRemove( child );
 }
 
 void ScrollView::StartTouchDownTimer()
index d3f3f87..7ae8fa4 100644 (file)
@@ -293,17 +293,21 @@ void ShadowView::OnInitialize()
   blurStrengthConstraint.Apply();
 }
 
-void ShadowView::OnControlChildAdd( Actor& child )
+void ShadowView::OnChildAdd( Actor& child )
 {
+  Control::OnChildAdd( child );
+
   if( child != mChildrenRoot && child != mBlurRootActor)
   {
     mChildrenRoot.Add( child );
   }
 }
 
-void ShadowView::OnControlChildRemove( Actor& child )
+void ShadowView::OnChildRemove( Actor& child )
 {
   mChildrenRoot.Remove( child );
+
+  Control::OnChildRemove( child );
 }
 
 void ShadowView::ConstrainCamera()
index 9f7d9d6..10c0887 100644 (file)
@@ -118,14 +118,14 @@ private:
   virtual void OnInitialize();
 
   /**
-   * @copydoc Control::OnControlChildAdd()
+   * @copydoc Control::OnChildAdd()
    */
-  virtual void OnControlChildAdd( Actor& child );
+  virtual void OnChildAdd( Actor& child );
 
   /**
-   * @copydoc Control::OnControlChildRemove()
+   * @copydoc Control::OnChildRemove()
    */
-  virtual void OnControlChildRemove( Actor& child );
+  virtual void OnChildRemove( Actor& child );
 
   /**
    * Constrain the camera actor to the position of the point light, pointing
index a730e40..bac0402 100644 (file)
@@ -287,7 +287,7 @@ Actor TableView::RemoveChildAt( const Toolkit::TableView::CellPosition& position
   if( child )
   {
     RelayoutingLock lock( *this );
-    // Remove the child, this will trigger a call to OnControlChildRemove
+    // Remove the child, this will trigger a call to OnChildRemove
     Self().Remove( child );
 
     // relayout the table only if instances were found
@@ -968,8 +968,10 @@ Property::Value TableView::GetProperty( BaseObject* object, Property::Index inde
   return value;
 }
 
-void TableView::OnControlChildAdd( Actor& child )
+void TableView::OnChildAdd( Actor& child )
 {
+  Control::OnChildAdd( child );
+
   if( mLayoutingChild )
   {
     // we're in the middle of laying out children so no point doing anything here
@@ -1061,7 +1063,7 @@ void TableView::OnControlChildAdd( Actor& child )
   RelayoutRequest();
 }
 
-void TableView::OnControlChildRemove( Actor& child )
+void TableView::OnChildRemove( Actor& child )
 {
   // dont process if we're in the middle of bigger operation like delete row, column or resize
   if( !mLayoutingChild )
@@ -1072,6 +1074,8 @@ void TableView::OnControlChildRemove( Actor& child )
       RelayoutRequest();
     }
   }
+
+  Control::OnChildRemove( child );
 }
 
 TableView::TableView( unsigned int initialRows, unsigned int initialColumns )
index d6ccf4b..d6e62b6 100644 (file)
@@ -212,14 +212,14 @@ public:
 private: // From Control
 
   /**
-   * @copydoc Control::OnControlChildAdd(Actor& child)
+   * @copydoc Control::OnChildAdd(Actor& child)
    */
-  virtual void OnControlChildAdd( Actor& child );
+  virtual void OnChildAdd( Actor& child );
 
   /**
-   * @copydoc Control::OnControlChildRemove(Actor& child)
+   * @copydoc Control::OnChildRemove(Actor& child)
    */
-  virtual void OnControlChildRemove( Actor& child );
+  virtual void OnChildRemove( Actor& child );
 
   /**
    * @copydoc Control::OnRelayout
index a3e4d00..4cb2ec6 100644 (file)
@@ -315,8 +315,10 @@ void ToolBar::OnInitialize()
   mLayout.SetRelativeWidth( 1, mRightRelativeSpace );
 }
 
-void ToolBar::OnControlChildAdd(Actor& child)
+void ToolBar::OnChildAdd(Actor& child)
 {
+  Control::OnChildAdd( child );
+
   if( !mInitializing )
   {
     // An actor is being added through the Actor's API.
@@ -330,7 +332,7 @@ void ToolBar::OnControlChildAdd(Actor& child)
     AddControl( child, DEFAULT_RELATIVE_SIZE, DEFAULT_ALIGNMENT, Toolkit::ToolBar::DEFAULT_PADDING );
   }
 
-  // No OnControlChildRemove method required because Actors are added to the mLayout table view, so if an
+  // No OnChildRemove method required because Actors are added to the mLayout table view, so if an
   // actor is removed using the Actor::RemoveChild method it will not remove anything because the
   // actor is in mLayout not in Self().
 }
index 7caaed5..f64d9e8 100644 (file)
@@ -72,9 +72,9 @@ private: // From Control
    * Adds a control using some default values (the control uses 10% of the tool bar space and is placed on the left group).
    * @param child The control to be added.
    *
-   * @see Control::OnControlChildAdd()
+   * @see Control::OnChildAdd()
    */
-  virtual void OnControlChildAdd(Actor& child);
+  virtual void OnChildAdd(Actor& child);
 
 private:
   /**
index b8ecd96..5a76197 100644 (file)
@@ -270,6 +270,8 @@ void CubeTransitionEffect::Initialize()
 
 void CubeTransitionEffect::OnStageConnection( int depth )
 {
+  Control::OnStageConnection( depth );
+
   Geometry geometry = CreateQuadGeometry();
   Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
 
@@ -306,6 +308,8 @@ void CubeTransitionEffect::OnStageDisconnection()
     }
     mTargetRenderer.Reset();
   }
+
+  Control::OnStageDisconnection();
 }
 
 void CubeTransitionEffect::SetTransitionDuration( float duration )
index 7cc7571..841e3d3 100644 (file)
@@ -187,8 +187,7 @@ public:
   mLongPressGestureDetector(),
   mFlags( Control::ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ),
   mIsKeyboardNavigationSupported( false ),
-  mIsKeyboardFocusGroup( false ),
-  mAddRemoveBackgroundChild( false )
+  mIsKeyboardFocusGroup( false )
 {
 }
 
@@ -384,7 +383,6 @@ public:
   ControlBehaviour mFlags :CONTROL_BEHAVIOUR_FLAG_COUNT;    ///< Flags passed in from constructor.
   bool mIsKeyboardNavigationSupported :1;  ///< Stores whether keyboard navigation is supported by the control.
   bool mIsKeyboardFocusGroup :1;           ///< Stores whether the control is a focus group.
-  bool mAddRemoveBackgroundChild:1;        ///< Flag to know when we are adding or removing our own actor to avoid call to OnControlChildAdd
 
   // Properties - these need to be members of Internal::Control::Impl as they need to function within this class.
   static const PropertyRegistration PROPERTY_1;
@@ -841,31 +839,23 @@ void Control::OnKeyInputFocusLost()
 
 void Control::OnChildAdd(Actor& child)
 {
-  // If this is the background actor, then we do not want to inform deriving classes
-  if ( mImpl->mAddRemoveBackgroundChild )
-  {
-    return;
-  }
-
   // Notify derived classes.
   OnControlChildAdd( child );
 }
 
 void Control::OnChildRemove(Actor& child)
 {
-  // If this is the background actor, then we do not want to inform deriving classes
-  if ( mImpl->mAddRemoveBackgroundChild )
-  {
-    return;
-  }
-
   // Notify derived classes.
   OnControlChildRemove( child );
 }
 
 void Control::OnSizeSet(const Vector3& targetSize)
 {
-  // Background is resized through size negotiation
+  if( mImpl->mBackgroundRenderer )
+  {
+    Vector2 size( targetSize );
+    mImpl->mBackgroundRenderer.SetSize( size );
+  }
 }
 
 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
index b3d0c1e..4779d58 100644 (file)
@@ -301,31 +301,37 @@ protected: // From CustomActorImpl, not to be used by application developers
 
   /**
    * @copydoc CustomActorImpl::OnStageConnection()
+   * @note If overridden, then an up-call to Control::OnStageConnection MUST be made at the start.
    */
   virtual void OnStageConnection( int depth );
 
   /**
    * @copydoc CustomActorImpl::OnStageDisconnection()
+   * @note If overridden, then an up-call to Control::OnStageDisconnection MUST be made at the end.
    */
   virtual void OnStageDisconnection();
 
   /**
    * @copydoc CustomActorImpl::OnChildAdd()
+   * @note If overridden, then an up-call to Control::OnChildAdd MUST be made at the start.
    */
   virtual void OnChildAdd( Actor& child );
 
   /**
    * @copydoc CustomActorImpl::OnChildRemove()
+   * @note If overridden, then an up-call to Control::OnChildRemove MUST be made at the end.
    */
   virtual void OnChildRemove( Actor& child );
 
   /**
    * @copydoc CustomActorImpl::OnSizeSet()
+   * @note If overridden, then an up-call to Control::OnSizeSet MUST be made at the start.
    */
   virtual void OnSizeSet( const Vector3& targetSize );
 
   /**
    * @copydoc CustomActorImpl::OnSizeAnimation()
+   * @note If overridden, then an up-call to Control::OnSizeAnimation MUST be made at the start.
    */
   virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize );
 
@@ -436,6 +442,8 @@ public: // API for derived classes to override
   virtual void OnInitialize();
 
   /**
+   * @DEPRECATED_1_1.30. Override OnChildAdd instead.
+   *
    * @brief Called whenever an Actor is added to the control.
    *
    * Could be overridden by derived classes.
@@ -446,6 +454,8 @@ public: // API for derived classes to override
   virtual void OnControlChildAdd( Actor& child );
 
   /**
+   * @DEPRECATED_1_1.30. Override OnChildRemove instead.
+   *
    * @brief Called whenever an Actor is removed from the control.
    *
    * Could be overridden by derived classes.
index b40262b..7410978 100644 (file)
@@ -327,6 +327,93 @@ void AppFunction()
 
 customControl.MyCustomSignal.Connect( this, &AppFunction );
 ~~~
+___________________________________________________________________________________________________
+
+### Children Added/Removed {#creating-controls-children}
+
+Methods are provided that can be overridden if notification is required when a child is added or removed from our control.
+An up call to the Control class is necessary if these methods are overridden.
+~~~{.cpp}
+// C++
+void MyUIControlImpl::OnChildAdd( Actor& child );
+{
+  // Up call to Control first
+  Control::OnChildAdd( child );
+
+  // Do any other operations required upon child addition
+}
+~~~
+~~~{.cpp}
+// C++
+void MyUIControlImpl::OnChildRemove( Actor& child );
+{
+  // Do any other operations required upon child removal
+
+  // Up call to Control at the end
+  Control::OnChildRemove( child );
+}
+~~~
+Avoid adding or removing the child again within these methods.
+___________________________________________________________________________________________________
+
+### Stage Connection {#creating-controls-stage}
+
+Methods are provided that can be overridden if notification is required when our control is connected to or disconnected from the stage.
+An up call to the Control class is necessary if these methods are overridden.
+~~~{.cpp}
+// C++
+void MyUIControlImpl::OnStageConnection( int depth )
+{
+  // Up call to Control first
+  Control::OnStageConnection( depth );
+
+  // Do any other operations required upon stage connection
+}
+~~~
+~~~{.cpp}
+// C++
+void MyUIControlImpl::OnStageDisconnection()
+{
+  // Do any other operations required upon stage disconnection
+
+  // Up call to Control at the end
+  Control::OnStageDisconnection();
+}
+~~~
+___________________________________________________________________________________________________
+
+### Size {#creating-controls-size}
+
+Methods are provided that can be overridden if notification is required when our control's size is manipulated.
+An up call to the Control class is necessary if these methods are overridden.
+~~~{.cpp}
+// C++
+void MyUIControlImpl::OnSizeSet( const Vector3& targetSize )
+{
+  // Up call to Control
+  Control::OnSizeSet( targetSize );
+
+  // Do any other operations required upon size set
+}
+~~~
+~~~{.cpp}
+// C++
+void MyUIControlImpl::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
+{
+  // Up call to Control
+  Control::OnSizeAnimation( animation, targetSize );
+
+  // Do any other operations required upon size animation
+}
+~~~
 ___________________________________________________________________________________________________
 
 ### Other Features {#creating-controls-other}