Spannable: Add BackgroundSpan
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / spannable / spans / background-color-span-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_BACKGROUND_COLOR_SPAN_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_BACKGROUND_COLOR_SPAN_IMPL_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/devel-api/text/spans/background-color-span.h>
23 #include <memory>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/logical-model-impl.h>
27 #include <dali-toolkit/internal/text/spannable/spans/base-span-impl.h>
28 #include <dali/public-api/math/vector4.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Text
35 {
36 namespace Internal
37 {
38 class BackgroundColorSpan;
39 using BackgroundColorSpanPtr = IntrusivePtr<BackgroundColorSpan>;
40
41 /**
42  * @copydoc Dali::Toolkit::Text::BackgroundColorSpan
43  */
44 class BackgroundColorSpan : public BaseSpan
45 {
46 public:
47   /**
48    * @brief Creates a new BackgroundColorSpan object.
49    */
50   static Dali::Toolkit::Text::BackgroundColorSpan New(const Vector4 &color);
51
52   /**
53    * Default Constructor
54    */
55   BackgroundColorSpan();
56
57   ///< Deleted copy constructor
58   BackgroundColorSpan(const BackgroundColorSpan&) = delete;
59
60   ///< Deleted move constructor
61   BackgroundColorSpan(BackgroundColorSpan&&) = delete;
62
63   ///< Deleted copy assignment operator
64   BackgroundColorSpan& operator=(const BackgroundColorSpan&) = delete;
65
66   ///< Deleted move assignment operator
67   BackgroundColorSpan& operator=(BackgroundColorSpan&&) = delete;
68
69   /**
70    * @brief Destructor
71    *
72    * A reference counted object may only be deleted by calling Unreference()
73    */
74   ~BackgroundColorSpan() override;
75
76 public: //Methods
77   /**
78    * @copydoc Dali::Toolkit::Text::BackgroundColorSpan::GetBackgroundColor()
79    */
80   const Vector4 GetBackgroundColor() const;
81
82   /**
83    * @copydoc Dali::Toolkit::Text::BackgroundColorSpan::IsBackgroundColorDefined()
84    */
85   bool IsBackgroundColorDefined() const;
86
87 public: //Methods. Not intended for application developers
88   /**
89    * @brief Set the background-color.
90    *
91    * @param[in] color The background-color.
92    */
93   void SetBackgroundColor(const Vector4 &color);
94
95 public: //Methods for internal only
96   /**
97    * @copydoc Dali::Toolkit::Text::BaseSpan::CreateStyleCharacterRun
98    */
99   void CreateStyleCharacterRun(IntrusivePtr<LogicalModel>& logicalModel, const Dali::Toolkit::Text::Range& range) const override;
100
101 private:
102   struct Impl;
103   std::unique_ptr<Impl> mImpl{nullptr};
104
105 }; // class BackgroundColorSpan
106
107 } // namespace Internal
108
109 // Helpers for public-api forwarding methods
110
111 inline Internal::BackgroundColorSpan& GetImplementation(Dali::Toolkit::Text::BackgroundColorSpan& BackgroundColorSpan)
112 {
113   DALI_ASSERT_ALWAYS(BackgroundColorSpan && "BackgroundColorSpan handle is empty");
114
115   BaseObject& object = BackgroundColorSpan.GetBaseObject();
116
117   return static_cast<Internal::BackgroundColorSpan&>(object);
118 }
119
120 inline const Internal::BackgroundColorSpan& GetImplementation(const Dali::Toolkit::Text::BackgroundColorSpan& BackgroundColorSpan)
121 {
122   DALI_ASSERT_ALWAYS(BackgroundColorSpan && "BackgroundColorSpan handle is empty");
123
124   const BaseObject& object = BackgroundColorSpan.GetBaseObject();
125
126   return static_cast<const Internal::BackgroundColorSpan&>(object);
127 }
128
129 } // namespace Text
130
131 } // namespace Toolkit
132
133 } // namespace Dali
134
135 #endif // DALI_TOOLKIT_INTERNAL_TEXT_BACKGROUND_COLOR_SPAN_IMPL_H