[AT-SPI] Add notification for a11y name/description change
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / button-impl.h
index 96787dc..ebe34e0 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_BUTTON_H
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
-#include <dali-toolkit/public-api/controls/buttons/button.h>
+#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
-
-//#if defined(DEBUG_ENABLED)
-//  Debug::Filter* gLogButtonFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_BUTTON_CONTROL");
-//#endif
+#include <dali-toolkit/internal/controls/control/control-data-impl.h>
 
 namespace Dali
 {
@@ -73,92 +70,61 @@ public:
 public:
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetDisabled
+   * @brief Sets the button as \e disabled.
+   * @param[in] disabled Disabled property
    */
   void SetDisabled( bool disabled );
 
   /**
-   * @copydoc Dali::Toolkit::Button::IsDisabled
+   * @brief Returns if the button is disabled.
+   * @return \e true if the button is \e disabled
    */
   bool IsDisabled() const;
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetAutoRepeating
+   * @brief Sets the \e autorepeating property.
+   * @param[in] autoRepeating \e autorepeating property
    */
   void SetAutoRepeating( bool autoRepeating );
 
   /**
-   * @copydoc Dali::Toolkit::Button::IsAutoRepeating
-   */
-  bool IsAutoRepeating() const;
-
-  /**
-   * @copydoc Dali::Toolkit::Button::SetInitialAutoRepeatingDelay
+   * @brief Sets the initial autorepeating delay.
+   * @param[in] initialAutoRepeatingDelay in seconds
    */
   void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
 
   /**
-   * @copydoc Dali::Toolkit::Button::GetInitialAutoRepeatingDelay
-   */
-  float GetInitialAutoRepeatingDelay() const;
-
-  /**
-   * @copydoc Dali::Toolkit::Button::SetNextAutoRepeatingDelay
+   * @brief Sets the next autorepeating delay.
+   * @param[in] nextAutoRepeatingDelay in seconds
    */
   void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
 
   /**
-   * @copydoc Dali::Toolkit::Button::GetNextAutoRepeatingDelay
-   */
-  float GetNextAutoRepeatingDelay() const;
-
-  /**
-   * @copydoc Dali::Toolkit::Button::SetTogglableButton
+   * @brief Sets the \e togglable property.
+   * @param[in] togglable Togglable property
    */
   void SetTogglableButton( bool togglable );
 
   /**
-   * @copydoc Dali::Toolkit::Button::IsTogglableButton
-   */
-  bool IsTogglableButton() const;
-
-  /**
-   * @copydoc Dali::Toolkit::Button::SetSelected
+   * @brief Sets the button as selected or unselected.
+   * @param[in] selected Selected property
    */
   void SetSelected( bool selected );
 
   /**
-   * @copydoc Dali::Toolkit::Button::IsSelected
+   * @brief Returns if the selected property is set and the button is togglable.
+   * @return \e true if the button is \e selected
    */
   bool IsSelected() const;
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetAnimationTime
-   */
-  void SetAnimationTime( float animationTime );
-
-  /**
-   * @copydoc Dali::Toolkit::Button::GetAnimationTime
-   */
-  float GetAnimationTime() const;
-
-  /**
-   * @copydoc Dali::Toolkit::Button::SetLabelText
-   */
-  void SetLabelText( const std::string& label );
-
-  /**
-   * @copydoc Dali::Toolkit::Button::GetLabelText
-   */
-  std::string GetLabelText() const;
-
-  /**
-   * @brief Sets the specified properties on the button label.
+   * @brief Produces a Property::Map of Text properties to create a Text Visual, merging existing properties with supplied map
    * If the label does not exist yet, it is created.
    * The derived buttons are notified if any properties are changed.
    * @param[in] properties A Property::Map of key-value pairs of properties to set.
+   * @param[out] properties A Property::Map of text visual properties to set after merging inMap with existing maps
    */
-  void SetupLabel( const Property::Map& properties );
+  void MergeWithExistingLabelProperties( const Property::Map& inMap, Property::Map& outMap );
 
   /**
    * Performs actions as requested using the action name.
@@ -169,109 +135,6 @@ public:
    */
   static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
 
-public: // Deprecated API
-
-  /**
-   * @copydoc Dali::Toolkit::Button::SetLabel( Actor label )
-   */
-  void SetLabel( Actor label );
-
-  /**
-   * @deprecated Sets the unselected image with an url.
-   * @param[in] image The Actor to use.
-   */
-  void SetUnselectedImage( const std::string& filename );
-
-  /**
-   * @deprecated Sets the selected image with an url.
-   * @param[in] filename The url of the image to use to use.
-   */
-  void SetSelectedImage( const std::string& filename );
-
-  /**
-   * @deprecated Sets the selected background image with an url.
-   * @param[in] filename The url of the image to use to use.
-   */
-  void SetSelectedBackgroundImage( const std::string& filename );
-
-  /**
-   * @deprecated Sets the background image with an url.
-   * @param[in] filename The url of the image to use to use.
-   */
-  void SetBackgroundImage( const std::string& filename );
-
-  /**
-   * @deprecated Sets the disabled unselected background image with an url.
-   * @param[in] filename The url of the image to use to use.
-   */
-  void SetDisabledBackgroundImage( const std::string& filename );
-
-  /**
-   * @deprecated Sets the disabled unselected image with an url.
-   * @param[in] filename The url of the image to use to use.
-   */
-  void SetDisabledImage( const std::string& filename );
-
-  /**
-   * @deprecated Sets the disabled selected image with an url.
-   * @param[in] filename The url of the image to use to use.
-   */
-  void SetDisabledSelectedImage( const std::string& filename );
-
-  /**
-   * @deprecated Sets the unselected image with an Actor.
-   * @param[in] image The Actor to use.
-   */
-  void SetUnselectedImage( Actor image );
-
-  /**
-   * @deprecated Sets the selected image with an Actor.
-   * @param[in] image The Actor to use.
-   */
-  void SetSelectedImage( Actor image );
-
-  /**
-   * @deprecated Sets the selected background image with an Actor.
-   * @param[in] image The Actor to use.
-   */
-  void SetSelectedBackgroundImage( Actor image );
-
-  /**
-   * @deprecated Sets the disabled image with an Actor.
-   * @param[in] image The Actor to use.
-   */
-  void SetDisabledImage( Actor image );
-
-  /**
-   * @deprecated Sets the disabled selected image with an Actor.
-   * @param[in] image The Actor to use.
-   */
-  void SetDisabledSelectedImage( Actor image );
-
-  /**
-   * @deprecated Sets the disabled background image with an Actor.
-   * @param[in] image The Actor to use.
-   */
-  void SetDisabledBackgroundImage( Actor image );
-
-  /**
-   * @Gets url of a image visual, used by GetProperty but for deprecated Properties
-   * @param[in] index Visual index of url required
-   * @return filename for the corresponding visual
-   */
-  std::string GetUrlForImageVisual( Property::Index index );
-
-
-  /**
-   * @copydoc Dali::Toolkit::Button::GetButtonImage
-   */
-  Actor GetButtonImage() const;
-
-  /**
-   * @copydoc Dali::Toolkit::Button::GetSelectedImage
-   */
-  Actor GetSelectedImage() const;
-
 public:
 
   /**
@@ -316,8 +179,7 @@ protected:
 
   /**
    * Button press state which is not the same as the actual button's state.
-   * A button can be DEPRESSED but the until released the button state may have not changed,
-   * For example DEPRESSING a toggle button that is already in the SELECTED state will not change the button state untill released.
+   * For example An UNSELECTED button can be DEPRESSED, but until released, the actual button state doesn't change to SELECTED
    */
   enum PressState
   {
@@ -360,57 +222,11 @@ private:
   bool DoClickAction( const Property::Map& attributes );
 
   /**
-   * This method is called when the label is set.
-   * @param[in] noPadding Used to bypass padding if the label is to be treated generically.
-   */
-  virtual void OnLabelSet( bool noPadding ) {}
-
-  /**
-   * This method is called when the unselected button image is set
-   */
-  virtual void OnUnselectedImageSet() {}
-
-  /**
-   * This method is called when the selected image is set
-   */
-  virtual void OnSelectedImageSet() {}
-
-  /**
-   * This method is called when the background image is set
-   */
-  virtual void OnBackgroundImageSet() {}
-
-  /**
-   * This method is called when the selected background image is set
-   */
-  virtual void OnSelectedBackgroundImageSet() {}
-
-  /**
-   * This method is called when the disabled button image is set
-   */
-  virtual void OnDisabledImageSet() {}
-
-  /**
-   * This method is called when the disabled selected image is set
-   */
-  virtual void OnDisabledSelectedImageSet() {}
-
-  /**
-   * This method is called when the disabled background image is set
-   */
-  virtual void OnDisabledBackgroundImageSet() {}
-
-  /**
-   * This method is called the button is down.
-   * Could be reimplemented in subclasses to provide specific behaviour.
-   */
-  virtual void OnButtonDown();
-
-  /**
-   * This method is called when the button is up.
+   * This method is called when the button is a Toggle button and released
    * Could be reimplemented in subclasses to provide specific behaviour.
+   * @return bool returns true if state changed.
    */
-  virtual void OnButtonUp();
+  virtual bool OnToggleReleased();
 
   /**
    * This method is called when touch leaves the boundary of the button or several touch points are received.
@@ -501,43 +317,43 @@ protected: // From Control
    * @copydoc Toolkit::Control::OnInitialize()
    * @note If overridden by deriving button classes, then an up-call to Button::OnInitialize MUST be made at the start.
    */
-  virtual void OnInitialize();
+  void OnInitialize() override;
 
   /**
    * @copydoc Toolkit::Control::OnAccessibilityActivated()
    */
-  virtual bool OnAccessibilityActivated();
+  bool OnAccessibilityActivated() override;
 
   /**
    * @copydoc Toolkit::Control::OnKeyboardEnter()
    */
-  virtual bool OnKeyboardEnter();
+  bool OnKeyboardEnter() override;
 
   /**
-   * @copydoc Toolkit::Control::OnStageDisconnection()
-   * @note If overridden by deriving button classes, then an up-call to Button::OnStageDisconnection MUST be made at the end.
+   * @copydoc Toolkit::Control::OnSceneDisconnection()
+   * @note If overridden by deriving button classes, then an up-call to Button::OnSceneDisconnection MUST be made at the end.
    */
-  virtual void OnStageDisconnection();
+  void OnSceneDisconnection() override;
 
   /**
-   * @copydoc Toolkit::Control::OnStageConnnection()
+   * @copydoc Toolkit::Control::OnSceneConnection()
    */
-  virtual void OnStageConnection( int depth );
+  void OnSceneConnection( int depth ) override;
 
   /**
    * @copydoc Toolkit::Control::GetNaturalSize
    */
-  virtual Vector3 GetNaturalSize();
+  Vector3 GetNaturalSize() override;
 
   /**
    * @copydoc Toolkit::Control::OnSetResizePolicy
    */
-  virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
+  void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) override;
 
   /**
    * @copydoc Toolkit::Control::OnRelayout
    */
-  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
+  void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
 
 private:
 
@@ -547,7 +363,7 @@ private:
    * @param[in]  touch  The touch info.
    * @return true, if consumed, false otherwise.
    */
-  bool OnTouch( Actor actor, const TouchData& touch );
+  bool OnTouch( Actor actor, const TouchEvent& touch );
 
   /**
    * Handler for tap events.
@@ -571,6 +387,16 @@ private:
   void Pressed();
 
   /**
+   * This method is called the button is down.
+   */
+  void ButtonDown();
+
+  /**
+   * This method is called when the button is up.
+   */
+  void ButtonUp();
+
+  /**
    * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
    */
   bool AutoRepeatingSlot();
@@ -584,45 +410,12 @@ private:
   bool ValidateState( State requestedState );
 
   /**
-   * Perform the given function on the visuals in the given state. Can be used to add and remove visuals.
-   * @param[in] functionPtr pointer to the function to perform an action on a visual
-   * @param[in] state Visuals in this state will be the target
-   */
-  void PerformFunctionOnVisualsInState( void(Button::*functionPtr)( Property::Index visualIndex), State state  );
-
-  /**
-   * Transition the visual in or out using the set animation
-   * @param[in] state State to transition in or out
-   */
-  void SetVisualsForTransition( State state );
-
-  /**
    * Changes the button state when an action occurs on it
    * @param[in] requestedState the state to change to
    */
   void ChangeState( State requestedState );
 
   /**
-   * @brief Get unselected button color
-   * @return color as vector4
-   */
-  const Vector4 GetUnselectedColor() const;
-
-  /**
-   * @brief Get selected button color
-   * @return color as vector4
-   */
-  const Vector4 GetSelectedColor() const;
-
-  /**
-   * Sets the color of button in selected or unselected state, if image also supplied this color will be appplied to it.
-   * If no visual exists, it is created.
-   * @param[in]  color The color to use.
-   * @param[in]  visualIndex The Visual to apply the color
-   */
-  void SetColor( const Vector4& color, Property::Index visualIndex );
-
-  /**
    * This method is called when the button is released.
    */
   void Released();
@@ -654,84 +447,39 @@ protected:
   Padding GetForegroundPadding();
 
   /**
-   * @brief Get the pressed state of the button
-   * @return ButtonPressedState the state the button is in
-   */
-  PressState GetPressedState();
-
-  /**
-   * @brief Get the state of the button
-   * @return PaintState the state the button is in
-   */
-  State GetButtonState();
-
-  /**
    * @brief Setup the button components for example foregrounds and background
    * @param[in] index the index of the visual to set
    * @param[in] value the value to set on the component
    * @param[in] visualDepth the depth of the visual if overlapping another
    */
-  void CreateVisualsForComponent( Property::Index index ,const Property::Value& value, const float visualDepth );
+  void CreateVisualsForComponent( Property::Index index, const Property::Value& value, const int visualDepth );
 
   /**
+   * @brief Get the Property map for the given Visual
+   * @param[in] visualIndex visual index of the required visual
+   * @param[out] retreivedMap the property map used to construct the required visual
+   * @return bool success flag, true if visual found
+   */
+  bool GetPropertyMapForVisual( Property::Index visualIndex, Property::Map& retreivedMap ) const;
+  /**
    * Returns the animation to be used for transition, creating the animation if needed.
    * @return The initialised transition animation.
    */
   Dali::Animation GetTransitionAnimation();
 
   /**
-   * @brief Set distance between label and foreground/icon, if both present
-   * @param[in] length length of strut
-   */
-  void SetLabelStrutLength( unsigned int length );
-
-  /**
    * @brief Set the position of the label relative to foreground/icon, if both present
    * @param[in] labelAlignment given alignment setting
    */
   void SetLabelAlignment( Align labelAlignment);
 
   /**
-   * @brief Get set distance between label and foreground/icon visual
-   * @return length of strut
-   */
-  float GetLabelStrutLength();
-
-  /**
    * @brief Get set alignment of label in relation to foreground/icon
    * @return Set alignment value
    */
   Align GetLabelAlignment();
 
   /**
-   * Prepares the actor to be transitioned in.
-   * @param[in]  actor  The actor that will be transitioned in.
-   */
-  virtual void PrepareForTransitionIn( Actor actor ) {}
-
-  /**
-   * Prepares the actor to be transitioned in.
-   * @param[in]  actor  The actor that will be transitioned out.
-   */
-  virtual void PrepareForTransitionOut( Actor actor ) {}
-
-  /**
-   * Transitions the actor in, allowing derived classes to configure
-   * the GetTransitionAnimation() animation ready.
-   * Button is in charge of calling Dali::Animation::Play and so derived classes
-   * only need to add the animation.
-   */
-  virtual void OnTransitionIn( Actor actor );
-
-  /**
-   * Transitions the actor out, allowing derived classes to configure
-   * the GetTransitionAnimation() animation ready.
-   * Button is in charge of calling Dali::Animation::Play and so derived classes
-   * only need to add the animation.
-   */
-  virtual void OnTransitionOut( Actor actor ) {}
-
-  /**
    * Removes the visual from the button (un-staged)
    * If the derived button does not want the visual removed then use this virtual function to
    * define the required behaviour.
@@ -743,32 +491,6 @@ protected:
 private:
 
   /**
-   * Starts the transition animation.
-   * Button::TransitionFinished is called when the animation finishes.
-   */
-  void StartTransitionAnimation();
-
-  /**
-   * This method stops and clears animations
-   */
-  void ClearTransitionAnimation();
-
-  /**
-   * Called when the transition animation finishes.
-   */
-  void TransitionAnimationFinished( Dali::Animation& source );
-
-  /**
-   * Transition button visual using an animation before removal from Stage
-   */
-  void TransitionButtonVisualOut( Property::Index visualIndex );
-
-  /**
-   * Transition button visual using an animation before adding to Stage
-   */
-  void TransitionButtonVisualIn( Property::Index visualIndex );
-
-  /**
    * Removes the visual from the button and prepares it to be transitioned out
    * @param[in] visualIndex the visual to remove
    */
@@ -800,18 +522,14 @@ private:
   Padding          mLabelPadding;               ///< The padding around the label (if present).
   Padding          mForegroundPadding;          ///< The padding around the foreground/icon visual (if present).
 
-  unsigned int     mForeGroundToLabelStrutLength; ///< Distance between foreground/icon and label.
   Align            mTextLabelAlignment;           ///< Position of text label in relation to foreground/icon when both are present.
 
-  Animation        mTransitionAnimation;        ///< Used in the state transitions.
-
   TapGestureDetector mTapDetector;
 
-  Vector4          mUnselectedColor;
-  Vector4          mSelectedColor;
-
   bool             mAutoRepeating;              ///< Stores the autorepeating property.
   bool             mTogglableButton;            ///< Stores the togglable property as a flag.
+  bool             mTextStringSetFlag;          ///< Stores if text has been set. Required in relayout but don't want to calculate there.
+
   float            mInitialAutoRepeatingDelay;  ///< Stores the initial autorepeating delay in seconds.
   float            mNextAutoRepeatingDelay;     ///< Stores the next autorepeating delay in seconds.
 
@@ -823,6 +541,16 @@ private:
 
   // Actions
   bool             mClickActionPerforming;      ///< Used to manage signal emissions during action
+
+protected:
+  struct AccessibleImpl : public Control::Impl::AccessibleImpl
+  {
+    using Control::Impl::AccessibleImpl::AccessibleImpl;
+
+    Dali::Accessibility::States CalculateStates() override;
+    std::string GetNameRaw() override;
+    Property::Index GetNamePropertyIndex() override;
+  };
 };
 
 } // namespace Internal