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