[Tizen][ATSPI] Accessibility initial implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_FIELD_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/devel-api/adaptor-framework/clipboard-event-notifier.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-field.h>
27 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
28 #include <dali-toolkit/internal/text/text-control-interface.h>
29 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
30 #include <dali-toolkit/internal/text/text-controller.h>
31 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 /**
43  * @brief A control which renders a short text string.
44  */
45 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface
46 {
47 public:
48
49   /**
50    * @copydoc Dali::Toollkit::TextField::New()
51    */
52   static Toolkit::TextField New();
53
54   // Properties
55
56   /**
57    * @brief Called when a property of an object of this type is set.
58    *
59    * @param[in] object The object whose property is set.
60    * @param[in] index The property index.
61    * @param[in] value The new property value.
62    */
63   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
64
65   /**
66    * @brief Called to retrieve a property of an object of this type.
67    *
68    * @param[in] object The object whose property is to be retrieved.
69    * @param[in] index The property index.
70    * @return The current value of the property.
71    */
72   static Property::Value GetProperty( BaseObject* object, Property::Index index );
73
74   /**
75    * Connects a callback function with the object's signals.
76    * @param[in] object The object providing the signal.
77    * @param[in] tracker Used to disconnect the signal.
78    * @param[in] signalName The signal to connect to.
79    * @param[in] functor A newly allocated FunctorDelegate.
80    * @return True if the signal was connected.
81    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
82    */
83   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
84
85   /**
86    * @copydoc TextField::TextChangedSignal()
87    */
88   Toolkit::TextField::TextChangedSignalType&  TextChangedSignal();
89
90   /**
91    * @copydoc TextField::MaxLengthReachedSignal()
92    */
93   Toolkit::TextField::MaxLengthReachedSignalType&  MaxLengthReachedSignal();
94
95   /**
96    * @copydoc TextField::TextChangedSignal()
97    */
98   Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
99
100   Text::ControllerPtr getController();
101
102 private: // From Control
103
104   /**
105    * @copydoc Control::OnInitialize()
106    */
107   virtual void OnInitialize();
108
109   /**
110    * @copydoc Control::OnStyleChange()
111    */
112   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
113
114   /**
115    * @copydoc Control::GetNaturalSize()
116    */
117   virtual Vector3 GetNaturalSize();
118
119   /**
120    * @copydoc Control::GetHeightForWidth()
121    */
122   virtual float GetHeightForWidth( float width );
123
124   /**
125    * @copydoc Control::OnInitialize()
126    */
127   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
128
129   /**
130    * @copydoc Control::OnKeyInputFocusGained()
131    */
132   virtual void OnKeyInputFocusGained();
133
134   /**
135    * @copydoc Control::OnKeyInputFocusLost()
136    */
137   virtual void OnKeyInputFocusLost();
138
139   /**
140    * @copydoc Control::OnTap()
141    */
142   virtual void OnTap( const TapGesture& tap );
143
144   /**
145    * @copydoc Control::OnPan()
146    */
147   virtual void OnPan( const PanGesture& gesture );
148
149   /**
150    * @copydoc Control::OnLongPress()
151    */
152   virtual void OnLongPress( const LongPressGesture& gesture );
153
154   /**
155    * @copydoc Control::OnStageConnection()
156    */
157   virtual void OnStageConnection( int depth );
158
159   /**
160    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
161    */
162   virtual bool OnKeyEvent(const KeyEvent& event);
163
164 // From ControlInterface
165
166   /**
167    * @copydoc Text::ControlInterface::RequestTextRelayout()
168    */
169   virtual void RequestTextRelayout();
170
171 // From EditableControlInterface
172
173   /**
174    * @copydoc Text::ControlInterface::TextChanged()
175    */
176   virtual void TextChanged();
177
178   /**
179    * @copydoc Text::ControlInterface::MaxLengthReached()
180    */
181   virtual void MaxLengthReached();
182
183   /**
184    * @copydoc Text::ControlInterface::InputStyleChanged()
185    */
186   virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
187
188   /**
189    * @copydoc Text::ControlInterface::AddDecoration()
190    */
191   virtual void AddDecoration( Actor& actor, bool needsClipping );
192
193 private: // Implementation
194
195   /**
196    * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
197    */
198   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
199
200   /**
201    * @brief Callback when Clipboard signals an item should be pasted
202    * @param[in] clipboard handle to Clipboard Event Notifier
203    */
204   void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
205
206   /**
207    * @brief Get a Property Map for the image used for the required Handle Image
208    * @param[out] value the returned image property
209    * @param[in] handleType the type of handle
210    * @param[in] handleImageType the type of image for the given handleType
211    */
212   void GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
213
214   /**
215    * @brief Enable or disable clipping.
216    */
217   void EnableClipping();
218
219   /**
220    * @brief Callback when keyboard is shown/hidden.
221    *
222    * @param[in] keyboardShown True if keyboard is shown.
223    */
224   void KeyboardStatusChanged( bool keyboardShown );
225
226   /**
227    * @brief Callback when TextField is touched
228    *
229    * @param[in] actor TextField touched
230    * @param[in] touch Touch information
231    */
232   bool OnTouched( Actor actor, const TouchData& touch );
233
234   /**
235    * @brief Callbacks called on idle.
236    *
237    * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
238    */
239   void OnIdleSignal();
240
241   /**
242    * Construct a new TextField.
243    */
244   TextField();
245
246   /**
247    * A reference counted object may only be deleted by calling Unreference()
248    */
249   virtual ~TextField();
250
251   // Undefined copy constructor and assignment operators
252   TextField(const TextField&);
253   TextField& operator=(const TextField& rhs);
254
255   /**
256    * @brief Render view, create and attach actor(s) to this Text Field.
257    */
258   void RenderText( Text::Controller::UpdateTextType updateTextType );
259
260   // Connection needed to re-render text, when a Text Field returns to the stage.
261   void OnStageConnect( Dali::Actor actor );
262
263 private: // Data
264
265   // Signals
266   Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
267   Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
268   Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
269
270   ImfManager         mImfManager;
271   Text::ControllerPtr mController;
272   Text::RendererPtr mRenderer;
273   Text::DecoratorPtr mDecorator;
274   Toolkit::Control mStencil; ///< For EXCEED_POLICY_CLIP
275   std::vector<Actor> mClippingDecorationActors;   ///< Decoration actors which need clipping.
276   Dali::InputMethodOptions mInputMethodOptions;
277
278   Actor mRenderableActor;
279   Actor mActiveLayer;
280   CallbackBase* mIdleCallback;
281
282   float mAlignmentOffset;
283   int mRenderingBackend;
284   int mExceedPolicy;
285   bool mHasBeenStaged:1;
286
287 protected:
288   struct AccessibleImpl : public Control::AccessibleImpl,
289                           public virtual Dali::Accessibility::Text,
290                           public virtual Dali::Accessibility::EditableText
291   {
292     using Control::AccessibleImpl::AccessibleImpl;
293
294     std::string GetName() override;
295     std::string GetText( size_t startOffset, size_t endOffset ) override;
296     size_t GetCharacterCount() override;
297     Dali::Accessibility::Range
298     GetTextAtOffset( size_t offset,
299                      Dali::Accessibility::TextBoundary boundary ) override;
300     Dali::Accessibility::Range GetSelection( size_t selectionNum ) override;
301     bool RemoveSelection( size_t selectionNum ) override;
302     bool SetSelection( size_t selectionNum, size_t startOffset,
303                        size_t endOffset ) override;
304     bool CopyText( size_t startPosition, size_t endPosition ) override;
305     bool CutText( size_t startPosition, size_t endPosition ) override;
306   };
307 };
308
309 } // namespace Internal
310
311 // Helpers for public-api forwarding methods
312
313 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
314 {
315   DALI_ASSERT_ALWAYS(textField);
316
317   Dali::RefObject& handle = textField.GetImplementation();
318
319   return static_cast<Toolkit::Internal::TextField&>(handle);
320 }
321
322 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
323 {
324   DALI_ASSERT_ALWAYS(textField);
325
326   const Dali::RefObject& handle = textField.GetImplementation();
327
328   return static_cast<const Toolkit::Internal::TextField&>(handle);
329 }
330
331 } // namespace Toolkit
332
333 } // namespace Dali
334
335 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H