[Tizen] Support asan build option
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / image-view / image-view-impl.h
index 334754b..8cf8d3a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H
 
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 class ImageView;
 
 namespace Internal
@@ -39,11 +37,12 @@ namespace Internal
 class ImageView : public Control
 {
 protected:
-
   /**
    * Construct a new ImageView.
+   *
+   * @param[in] additionalBehaviour additional behaviour flags for this ImageView
    */
-  ImageView();
+  ImageView(ControlBehaviour additionalBehaviour);
 
   /**
    * A reference counted object may only be deleted by calling Unreference()
@@ -53,14 +52,11 @@ protected:
 public:
   /**
    * Create a new ImageView.
+   *
+   * @param[in] additionalBehaviour custom behavior flags for this ImageView. Default is CONTROL_BEHAVIOUR_DEFAULT
    * @return A smart-pointer to the newly allocated ImageView.
    */
-  static Toolkit::ImageView New();
-
-  /**
-   * @copydoc Dali::Toolkit::SetImage
-   */
-  void SetImage( Image image );
+  static Toolkit::ImageView New(ControlBehaviour additionalBehaviour = ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT);
 
   /**
    * @brief Sets this ImageView from an Dali::Property::Map
@@ -68,29 +64,31 @@ public:
    * If the handle is empty, ImageView will display nothing
    * @param[in] map The Dali::Property::Map to use for to display.
    */
-  void SetImage( const Dali::Property::Map& map );
+  void SetImage(const Dali::Property::Map& map);
 
   /**
    * @copydoc Dali::Toolkit::SetImage
    */
-  void SetImage( const std::string& imageUrl, ImageDimensions size );
+  void SetImage(const std::string& imageUrl, ImageDimensions size);
 
   /**
-   * @copydoc Dali::Toolkit::GetImage
+   * @brief Unregister ImageView IMAGE visual
+   *
+   * ImageView will display nothing
    */
-  Image GetImage() const;
+  void ClearImageVisual();
 
   /**
    * @brief Set whether the Pre-multiplied Alpha Blending is required
    *
    * @param[in] preMultipled whether alpha is pre-multiplied.
    */
-  void EnablePreMultipliedAlpha( bool preMultipled );
+  void EnablePreMultipliedAlpha(bool preMultipled);
 
   /**
    * @brief Query whether alpha is pre-multiplied.
    *
-   * @return True is alpha is pre-multiplied, false otherwise.
+   * @return True if alpha is pre-multiplied, false otherwise.
    */
   bool IsPreMultipliedAlphaEnabled() const;
 
@@ -101,7 +99,7 @@ public:
    * @param[in] index The property index.
    * @param[in] value The new property value.
    */
-  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
+  static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
 
   /**
    * Called to retrieve a property of an object of this type.
@@ -109,7 +107,7 @@ public:
    * @param[in] index The property index.
    * @return The current value of the property.
    */
-  static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
+  static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
 
   /**
    * @brief Set the depth index of this image renderer
@@ -118,11 +116,35 @@ public:
    *
    * @param[in] depthIndex The depth index of this renderer
    */
-  void SetDepthIndex( int depthIndex );
+  void SetDepthIndex(int depthIndex);
 
-private: // From Control
+  /**
+   * @brief Set the placeholder url
+   */
+  void SetPlaceholderUrl(const std::string& url);
+
+  /**
+   * @brief Get the placeholder url
+   */
+  std::string GetPlaceholderUrl() const;
+
+  /**
+   * @brief Enable the transition effect
+   */
+  void EnableTransitionEffect(bool effectEnable);
+
+  /**
+   * @brief Query whether transition effect is enabled
+   */
+  bool IsTransitionEffectEnabled() const;
 
   /**
+   * @brief callback when animation for placeholder or previous visual transition effect is finished
+   */
+  void OnTransitionAnimationFinishedCallback(Animation& animation);
+
+private: // From Control
+  /**
    * @copydoc Toolkit::Control::OnInitialize
    */
   void OnInitialize();
@@ -130,59 +152,119 @@ private: // From Control
   /**
    * @copydoc Toolkit::Control::GetNaturalSize
    */
-  virtual Vector3 GetNaturalSize();
+  Vector3 GetNaturalSize() override;
 
   /**
    * @copydoc Toolkit::Control::GetHeightForWidth()
    */
-  virtual float GetHeightForWidth( float width );
+  float GetHeightForWidth(float width) override;
 
   /**
    * @copydoc Toolkit::Control::GetWidthForHeight()
    */
-  virtual float GetWidthForHeight( float height );
+  float GetWidthForHeight(float height) override;
 
   /**
    * @copydoc Toolkit::Control::OnRelayout()
    */
-  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
+  void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
 
-private:
+  /**
+   * @copydoc Toolkit::Control::OnCreateTransitions()
+   */
+  virtual void OnCreateTransitions(std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& sourceProperties,
+                                   std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& destinationProperties,
+                                   Dali::Toolkit::Control                                              source,
+                                   Dali::Toolkit::Control                                              destination) override;
 
   /**
+   * @copydoc Toolkit::Control::OnUpdateVisualProperties()
+   */
+  virtual void OnUpdateVisualProperties(const std::vector<std::pair<Dali::Property::Index, Dali::Property::Map>>& properties) override;
+
+private:
+  /**
    * @brief Callback for ResourceReadySignal
    * param[in] control signal prototype
    */
-  void OnResourceReady( Toolkit::Control control );
+  void OnResourceReady(Toolkit::Control control);
+
+  /**
+   * @brief Set TransformMap for fittingMode
+   * param[in] finalSize The size for fittingMode
+   * param[in] textureSize The size of texture
+   * param[in] offset The offset for fittingMode
+   * param[in] fittingMode The mode for fitting image
+   * param[in] transformMap  The map for fitting image
+   */
+  void SetTransformMapForFittingMode(Vector2 finalSize, Vector2 textureSize, Vector2 offset, Visual::FittingMode fittingMode, Property::Map& transformMap);
+
+  /**
+   * @brief Apply fittingMode
+   */
+  void ApplyFittingMode(const Vector2& size);
+
+   /**
+   * @brief Create placeholder image if it set. placeholder image is shown when image view is waiting for the image to load.
+   */
+  void CreatePlaceholderImage();
+
+  /**
+   * @brief Show placeholder image if it set. placeholder image is shown when image view is waiting for the image to load.
+   */
+  void ShowPlaceholderImage();
+
+  /**
+   * @brief Hide placeholder image if it set.
+   */
+  void HidePlaceholderImage();
+
+  /**
+   * @brief Transition image with effect when image is replaced.
+   */
+  void TransitionImageWithEffect();
+
+  /**
+   * @brief Clear the transition animation
+   */
+  void ClearTransitionAnimation();
 
 private:
   // Undefined
-  ImageView( const ImageView& );
-  ImageView& operator=( const ImageView& );
+  ImageView(const ImageView&);
+  ImageView& operator=(const ImageView&);
 
 private:
-  Toolkit::Visual::Base  mVisual;
-
-  std::string      mUrl;          ///< the url for the image if the image came from a URL, empty otherwise
-  Image            mImage;        ///< the Image if the image came from a Image, null otherwise
-  Property::Map    mPropertyMap;  ///< the Property::Map if the image came from a Property::Map, empty otherwise
-  Property::Map    mShaderMap;    ///< the Property::Map if the custom shader is set, empty otherwise
-  ImageDimensions  mImageSize;    ///< the image size
-
-  bool mImageVisualPaddingSetByTransform :1; //< Flag to indicate Padding was set using a transform.
+  Toolkit::Visual::Base mVisual;
+  Toolkit::Visual::Base mPreviousVisual;
+  Toolkit::Visual::Base mPlaceholderVisual;
+
+  std::string     mUrl;                                    ///< the url for the image if the image came from a URL, empty otherwise
+  std::string     mPlaceholderUrl;                         ///< the url for the placeholder image if the image came from a PLACEHOLDER_IMAGE, empty otherwise
+  Property::Map   mPropertyMap;                            ///< the Property::Map if the image came from a Property::Map, empty otherwise
+  Property::Map   mShaderMap;                              ///< the Property::Map if the custom shader is set, empty otherwise
+  ImageDimensions mImageSize;                              ///< the image size
+
+  Animation       mTransitionAnimation;                    ///< the animation for transition effect
+  float           mTransitionTargetAlpha;                  ///< Keep image's alpha value
+  bool            mImageVisualPaddingSetByTransform : 1;   ///< Flag to indicate Padding was set using a transform.
+  bool            mImageViewPixelAreaSetByFittingMode : 1; ///< Flag to indicate pixel area was set by fitting Mode
+  bool            mTransitionEffect :1;                    ///< Flag to indicate TransitionEffect is enabled
+  bool            mNeedLazyFittingMode:1;                  ///< Flag to indicate FittingMode will be applying lazy
+  bool            mImageReplaced:1;                        ///< Flag to indicate image is replaced
 };
 
 } // namespace Internal
 
 // Helpers for public-api forwarding methods
-inline Toolkit::Internal::ImageView& GetImpl( Toolkit::ImageView& obj )
+inline Toolkit::Internal::ImageView& GetImpl(Toolkit::ImageView& obj)
 {
   DALI_ASSERT_ALWAYS(obj);
   Dali::RefObject& handle = obj.GetImplementation();
   return static_cast<Toolkit::Internal::ImageView&>(handle);
 }
 
-inline const Toolkit::Internal::ImageView& GetImpl( const Toolkit::ImageView& obj )
+inline const Toolkit::Internal::ImageView& GetImpl(const Toolkit::ImageView& obj)
 {
   DALI_ASSERT_ALWAYS(obj);
   const Dali::RefObject& handle = obj.GetImplementation();