[Tizen][ATSPI] Accessibility initial implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
3
4 /*
5  * Copyright (c) 2017 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/public-api/object/property-map.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
27 #include <dali-toolkit/internal/text/text-control-interface.h>
28 #include <dali-toolkit/internal/text/text-controller.h>
29 #include <dali-toolkit/internal/text/text-scroller-interface.h>
30 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
31 #include <dali-toolkit/internal/text/text-scroller.h>
32 #include <dali-toolkit/internal/visuals/text/text-visual.h>
33
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 /**
45  * @brief A control which renders a short text string.
46  */
47 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface
48 {
49 public:
50
51   /**
52    * @copydoc Dali::Toollkit::TextLabel::New()
53    */
54   static Toolkit::TextLabel New();
55
56   // Properties
57
58   /**
59    * @brief Called when a property of an object of this type is set.
60    *
61    * @param[in] object The object whose property is set.
62    * @param[in] index The property index.
63    * @param[in] value The new property value.
64    */
65   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
66
67   /**
68    * @brief Called to retrieve a property of an object of this type.
69    *
70    * @param[in] object The object whose property is to be retrieved.
71    * @param[in] index The property index.
72    * @return The current value of the property.
73    */
74   static Property::Value GetProperty( BaseObject* object, Property::Index index );
75
76   Text::ControllerPtr getController();
77
78 private: // From Control
79
80   /**
81    * @copydoc Control::OnInitialize()
82    */
83   virtual void OnInitialize() override ;
84
85   /**
86    * @copydoc Control::OnStyleChange()
87    */
88   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override ;
89
90   /**
91    * @copydoc Control::OnRelayout()
92    */
93   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) override ;
94
95   /**
96    * @copydoc Control::GetNaturalSize()
97    */
98   virtual Vector3 GetNaturalSize() override ;
99
100   /**
101    * @copydoc Control::GetHeightForWidth()
102    */
103   virtual float GetHeightForWidth( float width ) override ;
104
105   /**
106    * @copydoc Control::OnPropertySet()
107    */
108   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) override ;
109
110   // From ControlInterface
111
112   /**
113    * @copydoc Text::ControlInterface::RequestTextRelayout()
114    */
115   virtual void RequestTextRelayout() override ;
116
117 private: // from TextScroller
118
119   /**
120    * @copydoc Text::ScrollerInterface::ScrollingFinished()
121    */
122   virtual void ScrollingFinished();
123
124 private: // Implementation
125
126   /**
127    * Construct a new TextLabel.
128    */
129   TextLabel();
130
131   /**
132    * A reference counted object may only be deleted by calling Unreference()
133    */
134   virtual ~TextLabel();
135
136 private:
137
138   // Undefined copy constructor and assignment operators
139   TextLabel(const TextLabel&);
140   TextLabel& operator=(const TextLabel& rhs);
141
142   /**
143    * @brief Set up Autoscrolling
144    */
145   void SetUpAutoScrolling();
146
147 private: // Data
148
149   Text::ControllerPtr mController;
150   Text::TextScrollerPtr mTextScroller;
151
152   Toolkit::Visual::Base mVisual;
153
154   int mRenderingBackend;
155   bool mTextUpdateNeeded:1;
156
157 protected:
158   struct AccessibleImpl : public Control::AccessibleImpl,
159                           public virtual Dali::Accessibility::Text
160   {
161     using Control::AccessibleImpl::AccessibleImpl;
162
163     std::string GetName() override;
164     std::string GetText( size_t startOffset, size_t endOffset ) override;
165     size_t GetCharacterCount() override;
166     Dali::Accessibility::Range
167     GetTextAtOffset( size_t offset,
168                      Dali::Accessibility::TextBoundary boundary ) override;
169     Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
170     bool RemoveSelection( size_t selectionNum ) override;
171     bool SetSelection( size_t selectionNum, size_t startOffset,
172                        size_t endOffset ) override;
173   };
174 };
175
176 } // namespace Internal
177
178 // Helpers for public-api forwarding methods
179
180 inline Toolkit::Internal::TextLabel& GetImpl( Toolkit::TextLabel& textLabel )
181 {
182   DALI_ASSERT_ALWAYS(textLabel);
183
184   Dali::RefObject& handle = textLabel.GetImplementation();
185
186   return static_cast<Toolkit::Internal::TextLabel&>(handle);
187 }
188
189 inline const Toolkit::Internal::TextLabel& GetImpl( const Toolkit::TextLabel& textLabel )
190 {
191   DALI_ASSERT_ALWAYS(textLabel);
192
193   const Dali::RefObject& handle = textLabel.GetImplementation();
194
195   return static_cast<const Toolkit::Internal::TextLabel&>(handle);
196 }
197
198 } // namespace Toolkit
199
200 } // namespace Dali
201
202 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H