d95da08370e71e80a99d2ad6ab79889fff098ffc
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/adaptor-framework/key-devel.h>
24 #include <dali/devel-api/common/stage.h>
25 #include <dali/devel-api/object/property-helper-devel.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/key.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <cstring>
32
33 // INTERNAL INCLUDES
34 #include <dali-toolkit/devel-api/controls/control-devel.h>
35 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
36 #include <dali-toolkit/devel-api/text/rendering-backend.h>
37 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
38 #include <dali-toolkit/internal/controls/text-controls/text-field-property-handler.h>
39 #include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
40 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/public-api/text/text-enumerations.h>
47 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
48 #include <dali-toolkit/public-api/visuals/visual-properties.h>
49 #include <dali/integration-api/adaptor-framework/adaptor.h>
50
51 using namespace Dali::Toolkit::Text;
52
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gTextFieldLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
55 #endif
56
57 namespace Dali
58 {
59 namespace Toolkit
60 {
61 namespace Internal
62 {
63 namespace // unnamed namespace
64 {
65 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
66 } // unnamed namespace
67
68 namespace
69 {
70 // Type registration
71 BaseHandle Create()
72 {
73   return Toolkit::TextField::New();
74 }
75
76 // clang-format off
77 // Setup properties, signals and actions using the type-registry.
78 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
79
80 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "text",                             STRING,    TEXT                                )
81 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "placeholderText",                  STRING,    PLACEHOLDER_TEXT                    )
82 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "placeholderTextFocused",           STRING,    PLACEHOLDER_TEXT_FOCUSED            )
83 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "fontFamily",                       STRING,    FONT_FAMILY                         )
84 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "fontStyle",                        MAP,       FONT_STYLE                          )
85 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "pointSize",                        FLOAT,     POINT_SIZE                          )
86 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "maxLength",                        INTEGER,   MAX_LENGTH                          )
87 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "exceedPolicy",                     INTEGER,   EXCEED_POLICY                       )
88 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "horizontalAlignment",              STRING,    HORIZONTAL_ALIGNMENT                )
89 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "verticalAlignment",                STRING,    VERTICAL_ALIGNMENT                  )
90 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "textColor",                        VECTOR4,   TEXT_COLOR                          )
91 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "placeholderTextColor",             VECTOR4,   PLACEHOLDER_TEXT_COLOR              )
92 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "primaryCursorColor",               VECTOR4,   PRIMARY_CURSOR_COLOR                )
93 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "secondaryCursorColor",             VECTOR4,   SECONDARY_CURSOR_COLOR              )
94 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "enableCursorBlink",                BOOLEAN,   ENABLE_CURSOR_BLINK                 )
95 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "cursorBlinkInterval",              FLOAT,     CURSOR_BLINK_INTERVAL               )
96 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "cursorBlinkDuration",              FLOAT,     CURSOR_BLINK_DURATION               )
97 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "cursorWidth",                      INTEGER,   CURSOR_WIDTH                        )
98 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "grabHandleImage",                  STRING,    GRAB_HANDLE_IMAGE                   )
99 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "grabHandlePressedImage",           STRING,    GRAB_HANDLE_PRESSED_IMAGE           )
100 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "scrollThreshold",                  FLOAT,     SCROLL_THRESHOLD                    )
101 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "scrollSpeed",                      FLOAT,     SCROLL_SPEED                        )
102 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "selectionHandleImageLeft",         MAP,       SELECTION_HANDLE_IMAGE_LEFT         )
103 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "selectionHandleImageRight",        MAP,       SELECTION_HANDLE_IMAGE_RIGHT        )
104 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "selectionHandlePressedImageLeft",  MAP,       SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "selectionHandlePressedImageRight", MAP,       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
106 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "selectionHandleMarkerImageLeft",   MAP,       SELECTION_HANDLE_MARKER_IMAGE_LEFT  )
107 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "selectionHandleMarkerImageRight",  MAP,       SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "selectionHighlightColor",          VECTOR4,   SELECTION_HIGHLIGHT_COLOR           )
109 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "decorationBoundingBox",            RECTANGLE, DECORATION_BOUNDING_BOX             )
110 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "inputMethodSettings",              MAP,       INPUT_METHOD_SETTINGS               )
111 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "inputColor",                       VECTOR4,   INPUT_COLOR                         )
112 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "enableMarkup",                     BOOLEAN,   ENABLE_MARKUP                       )
113 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "inputFontFamily",                  STRING,    INPUT_FONT_FAMILY                   )
114 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "inputFontStyle",                   MAP,       INPUT_FONT_STYLE                    )
115 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "inputPointSize",                   FLOAT,     INPUT_POINT_SIZE                    )
116 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "underline",                        MAP,       UNDERLINE                           )
117 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "inputUnderline",                   MAP,       INPUT_UNDERLINE                     )
118 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "shadow",                           MAP,       SHADOW                              )
119 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "inputShadow",                      MAP,       INPUT_SHADOW                        )
120 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "emboss",                           MAP,       EMBOSS                              )
121 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "inputEmboss",                      MAP,       INPUT_EMBOSS                        )
122 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "outline",                          MAP,       OUTLINE                             )
123 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "inputOutline",                     MAP,       INPUT_OUTLINE                       )
124 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "hiddenInputSettings",              MAP,       HIDDEN_INPUT_SETTINGS               )
125 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "pixelSize",                        FLOAT,     PIXEL_SIZE                          )
126 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "enableSelection",                  BOOLEAN,   ENABLE_SELECTION                    )
127 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "placeholder",                      MAP,       PLACEHOLDER                         )
128 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextField, "ellipsis",                         BOOLEAN,   ELLIPSIS                            )
129 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "enableShiftSelection",             BOOLEAN,   ENABLE_SHIFT_SELECTION              )
130 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "enableGrabHandle",                 BOOLEAN,   ENABLE_GRAB_HANDLE                  )
131 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "matchSystemLanguageDirection",     BOOLEAN,   MATCH_SYSTEM_LANGUAGE_DIRECTION     )
132 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "enableGrabHandlePopup",            BOOLEAN,   ENABLE_GRAB_HANDLE_POPUP            )
133 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "textBackground",                   VECTOR4,   BACKGROUND                          )
134 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextField, "selectedText",                     STRING,    SELECTED_TEXT                       )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "renderingBackend",                 INTEGER,   RENDERING_BACKEND                   )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "selectedTextStart",                INTEGER,   SELECTED_TEXT_START                 )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "selectedTextEnd",                  INTEGER,   SELECTED_TEXT_END                   )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "enableEditing",                    BOOLEAN,   ENABLE_EDITING                      )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "fontSizeScale",                    FLOAT,     FONT_SIZE_SCALE                     )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "enableFontSizeScale",              BOOLEAN,   ENABLE_FONT_SIZE_SCALE              )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "primaryCursorPosition",            INTEGER,   PRIMARY_CURSOR_POSITION             )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "grabHandleColor",                  VECTOR4,   GRAB_HANDLE_COLOR                   )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "inputFilter",                      MAP,       INPUT_FILTER                        )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "ellipsisPosition",                 INTEGER,   ELLIPSIS_POSITION                   )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "strikethrough",                    MAP,       STRIKETHROUGH                       )
146 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "inputStrikethrough",               MAP,       INPUT_STRIKETHROUGH                 )
147 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "characterSpacing",                 FLOAT,     CHARACTER_SPACING                   )
148 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextField, "selectionPopupStyle",              MAP,       SELECTION_POPUP_STYLE               )
149
150 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged",           SIGNAL_TEXT_CHANGED           )
151 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached",      SIGNAL_MAX_LENGTH_REACHED     )
152 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputStyleChanged",     SIGNAL_INPUT_STYLE_CHANGED    )
153 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "anchorClicked",         SIGNAL_ANCHOR_CLICKED         )
154 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "inputFiltered",         SIGNAL_INPUT_FILTERED         )
155 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
156 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionChanged",      SIGNAL_SELECTION_CHANGED      )
157 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionCleared",      SIGNAL_SELECTION_CLEARED      )
158 DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionStarted",      SIGNAL_SELECTION_STARTED      )
159
160 DALI_TYPE_REGISTRATION_END()
161 // clang-format on
162
163 Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
164 {
165   Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
166
167   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
168   {
169     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR);
170   }
171   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
172   {
173     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY);
174   }
175   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
176   {
177     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE);
178   }
179   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
180   {
181     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
182   }
183   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
184   {
185     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
186   }
187   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
188   {
189     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE);
190   }
191   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
192   {
193     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE);
194   }
195   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
196   {
197     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW);
198   }
199   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
200   {
201     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS);
202   }
203   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
204   {
205     fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>(fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE);
206   }
207   return fieldInputStyleMask;
208 }
209
210 } // namespace
211
212 Toolkit::TextField TextField::New(ControlBehaviour additionalBehaviour)
213 {
214   // Create the implementation, temporarily owned by this handle on stack
215   IntrusivePtr<TextField> impl = new TextField(additionalBehaviour);
216
217   // Pass ownership to CustomActor handle
218   Toolkit::TextField handle(*impl);
219
220   // Second-phase init of the implementation
221   // This can only be done after the CustomActor connection has been made...
222   impl->Initialize();
223
224   return handle;
225 }
226
227 void TextField::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
228 {
229   Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
230
231   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField SetProperty\n");
232
233   if(textField)
234   {
235     PropertyHandler::SetProperty(textField, index, value);
236   }
237 }
238
239 Property::Value TextField::GetProperty(BaseObject* object, Property::Index index)
240 {
241   Property::Value value;
242
243   Toolkit::TextField textField = Toolkit::TextField::DownCast(Dali::BaseHandle(object));
244
245   if(textField)
246   {
247     value = PropertyHandler::GetProperty(textField, index);
248   }
249
250   return value;
251 }
252
253 void TextField::SelectWholeText()
254 {
255   if(mController && mController->IsShowingRealText())
256   {
257     mController->SelectWholeText();
258     SetKeyInputFocus();
259   }
260 }
261
262 void TextField::SelectNone()
263 {
264   if(mController && mController->IsShowingRealText())
265   {
266     mController->SelectNone();
267   }
268 }
269
270 void TextField::SelectText(const uint32_t start, const uint32_t end)
271 {
272   if(mController && mController->IsShowingRealText())
273   {
274     mController->SelectText(start, end);
275     SetKeyInputFocus();
276   }
277 }
278
279 string TextField::GetSelectedText() const
280 {
281   string selectedText = "";
282   if(mController && mController->IsShowingRealText())
283   {
284     selectedText = mController->GetSelectedText();
285   }
286   return selectedText;
287 }
288
289 void TextField::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
290 {
291   if(mController && mController->IsShowingRealText())
292   {
293     mController->SetTextSelectionRange(start, end);
294     SetKeyInputFocus();
295   }
296 }
297
298 Uint32Pair TextField::GetTextSelectionRange() const
299 {
300   Uint32Pair range;
301   if(mController && mController->IsShowingRealText())
302   {
303     range = mController->GetTextSelectionRange();
304   }
305   return range;
306 }
307
308 string TextField::CopyText()
309 {
310   string copiedText = "";
311   if(mController && mController->IsShowingRealText())
312   {
313     copiedText = mController->CopyText();
314   }
315   return copiedText;
316 }
317
318 string TextField::CutText()
319 {
320   string cutText = "";
321   if(mController && mController->IsShowingRealText())
322   {
323     cutText = mController->CutText();
324   }
325   return cutText;
326 }
327
328 void TextField::PasteText()
329 {
330   if(mController)
331   {
332     SetKeyInputFocus(); //Giving focus to the field that was passed to the PasteText in case the passed field (current field) doesn't have focus.
333     mController->PasteText();
334   }
335 }
336
337 InputMethodContext TextField::GetInputMethodContext()
338 {
339   return mInputMethodContext;
340 }
341
342 bool TextField::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
343 {
344   Dali::BaseHandle handle(object);
345
346   bool               connected(true);
347   Toolkit::TextField field = Toolkit::TextField::DownCast(handle);
348
349   if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
350   {
351     field.TextChangedSignal().Connect(tracker, functor);
352   }
353   else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
354   {
355     field.MaxLengthReachedSignal().Connect(tracker, functor);
356   }
357   else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
358   {
359     field.InputStyleChangedSignal().Connect(tracker, functor);
360   }
361   else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
362   {
363     if(field)
364     {
365       Internal::TextField& fieldImpl(GetImpl(field));
366       fieldImpl.AnchorClickedSignal().Connect(tracker, functor);
367     }
368   }
369   else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
370   {
371     if(field)
372     {
373       Internal::TextField& fieldImpl(GetImpl(field));
374       fieldImpl.CursorPositionChangedSignal().Connect(tracker, functor);
375     }
376   }
377   else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
378   {
379     if(field)
380     {
381       Internal::TextField& fieldImpl(GetImpl(field));
382       fieldImpl.InputFilteredSignal().Connect(tracker, functor);
383     }
384   }
385   else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
386   {
387     if(field)
388     {
389       Internal::TextField& fieldImpl(GetImpl(field));
390       fieldImpl.SelectionChangedSignal().Connect(tracker, functor);
391     }
392   }
393   else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
394   {
395     if(field)
396     {
397       Internal::TextField& fieldImpl(GetImpl(field));
398       fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
399     }
400   }
401   else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
402   {
403     if(field)
404     {
405       Internal::TextField& fieldImpl(GetImpl(field));
406       fieldImpl.SelectionStartedSignal().Connect(tracker, functor);
407     }
408   }
409   else
410   {
411     // signalName does not match any signal
412     connected = false;
413   }
414
415   return connected;
416 }
417
418 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
419 {
420   return mTextChangedSignal;
421 }
422
423 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
424 {
425   return mMaxLengthReachedSignal;
426 }
427
428 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
429 {
430   return mInputStyleChangedSignal;
431 }
432
433 DevelTextField::AnchorClickedSignalType& TextField::AnchorClickedSignal()
434 {
435   return mAnchorClickedSignal;
436 }
437
438 DevelTextField::CursorPositionChangedSignalType& TextField::CursorPositionChangedSignal()
439 {
440   return mCursorPositionChangedSignal;
441 }
442
443 DevelTextField::InputFilteredSignalType& TextField::InputFilteredSignal()
444 {
445   return mInputFilteredSignal;
446 }
447
448 DevelTextField::SelectionChangedSignalType& TextField::SelectionChangedSignal()
449 {
450   return mSelectionChangedSignal;
451 }
452
453 DevelTextField::SelectionClearedSignalType& TextField::SelectionClearedSignal()
454 {
455   return mSelectionClearedSignal;
456 }
457
458 DevelTextField::SelectionStartedSignalType& TextField::SelectionStartedSignal()
459 {
460   return mSelectionStartedSignal;
461 }
462
463 void TextField::OnAccessibilityStatusChanged()
464 {
465   CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
466 }
467
468 void TextField::OnInitialize()
469 {
470   Actor self = Self();
471
472   mController = Text::Controller::New(this, this, this, this);
473
474   // When using the vector-based rendering, the size of the GLyphs are different
475   TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
476   mController->SetGlyphType(glyphType);
477
478   mDecorator = Text::Decorator::New(*mController,
479                                     *mController);
480
481   mInputMethodContext = InputMethodContext::New(self);
482
483   mController->GetLayoutEngine().SetLayout(Layout::Engine::SINGLE_LINE_BOX);
484
485   // Enables the text input.
486   mController->EnableTextInput(mDecorator, mInputMethodContext);
487
488   // Enables the horizontal scrolling after the text input has been enabled.
489   mController->SetHorizontalScrollEnabled(true);
490
491   // Disables the vertical scrolling.
492   mController->SetVerticalScrollEnabled(false);
493
494   // Disable the smooth handle panning.
495   mController->SetSmoothHandlePanEnabled(false);
496
497   mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
498   mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
499
500   // Sets layoutDirection value
501   Dali::Stage                 stage           = Dali::Stage::GetCurrent();
502   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
503   mController->SetLayoutDirection(layoutDirection);
504
505   self.LayoutDirectionChangedSignal().Connect(this, &TextField::OnLayoutDirectionChanged);
506
507   // Forward input events to controller
508   EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
509   GetTapGestureDetector().SetMaximumTapsRequired(2);
510   GetTapGestureDetector().ReceiveAllTapEvents(true);
511
512   self.TouchedSignal().Connect(this, &TextField::OnTouched);
513
514   // Set BoundingBox to stage size if not already set.
515   Rect<int> boundingBox;
516   mDecorator->GetBoundingBox(boundingBox);
517
518   if(boundingBox.IsEmpty())
519   {
520     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
521     mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
522   }
523
524   // Flip vertically the 'left' selection handle
525   mDecorator->FlipHandleVertically(LEFT_SELECTION_HANDLE, true);
526
527   // Fill-parent area by default
528   self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
529   self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
530   self.OnSceneSignal().Connect(this, &TextField::OnSceneConnect);
531
532   DevelControl::SetInputMethodContext(*this, mInputMethodContext);
533
534   if(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy)
535   {
536     EnableClipping();
537   }
538
539   // Accessibility
540   self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::ENTRY);
541   self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
542
543   Accessibility::Bridge::EnabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
544   Accessibility::Bridge::DisabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
545 }
546
547 DevelControl::ControlAccessible* TextField::CreateAccessibleObject()
548 {
549   return new TextFieldAccessible(Self());
550 }
551
552 void TextField::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
553 {
554   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
555
556   switch(change)
557   {
558     case StyleChange::DEFAULT_FONT_CHANGE:
559     {
560       DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
561       const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
562       // Property system did not set the font so should update it.
563       mController->UpdateAfterFontChange(newFont);
564       RelayoutRequest();
565       break;
566     }
567
568     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
569     {
570       GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
571       RelayoutRequest();
572       break;
573     }
574     case StyleChange::THEME_CHANGE:
575     {
576       // Nothing to do, let control base class handle this
577       break;
578     }
579   }
580
581   // Up call to Control
582   Control::OnStyleChange(styleManager, change);
583 }
584
585 Vector3 TextField::GetNaturalSize()
586 {
587   Extents padding;
588   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
589
590   Vector3 naturalSize = mController->GetNaturalSize();
591   naturalSize.width += (padding.start + padding.end);
592   naturalSize.height += (padding.top + padding.bottom);
593
594   return naturalSize;
595 }
596
597 float TextField::GetHeightForWidth(float width)
598 {
599   Extents padding;
600   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
601   return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
602 }
603
604 void TextField::ResizeActor(Actor& actor, const Vector2& size)
605 {
606   if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
607   {
608     actor.SetProperty(Actor::Property::SIZE, size);
609   }
610 }
611
612 void TextField::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
613 {
614   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnPropertySet index[%d]\n", index);
615
616   switch(index)
617   {
618     case DevelActor::Property::USER_INTERACTION_ENABLED:
619     {
620       const bool enabled = propertyValue.Get<bool>();
621       mController->SetUserInteractionEnabled(enabled);
622       if(mStencil)
623       {
624         float opacity = enabled ? 1.0f : mController->GetDisabledColorOpacity();
625         mStencil.SetProperty(Actor::Property::OPACITY, opacity);
626       }
627       break;
628     }
629     default:
630     {
631       Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties
632       break;
633     }
634   }
635 }
636
637 void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container)
638 {
639   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField OnRelayout\n");
640
641   Actor self = Self();
642
643   Extents padding;
644   padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
645
646   Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
647
648   // Support Right-To-Left of padding
649   Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
650
651   if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
652   {
653     std::swap(padding.start, padding.end);
654   }
655
656   if(mStencil)
657   {
658     mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
659     ResizeActor(mStencil, contentSize);
660   }
661   if(mActiveLayer)
662   {
663     mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
664     ResizeActor(mActiveLayer, contentSize);
665   }
666   if(mCursorLayer)
667   {
668     mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
669     ResizeActor(mCursorLayer, contentSize);
670   }
671
672   // If there is text changed, callback is called.
673   if(mTextChanged)
674   {
675     EmitTextChangedSignal();
676   }
677
678   const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
679
680   if((Text::Controller::NONE_UPDATED != updateTextType) ||
681      !mRenderer)
682   {
683     DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get());
684
685     if(mDecorator &&
686        (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
687     {
688       mDecorator->Relayout(contentSize);
689     }
690
691     if(!mRenderer)
692     {
693       mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
694     }
695
696     RenderText(updateTextType);
697   }
698
699   if(mCursorPositionChanged)
700   {
701     EmitCursorPositionChangedSignal();
702   }
703
704   if(mSelectionStarted)
705   {
706     EmitSelectionStartedSignal();
707   }
708
709   if(mSelectionChanged)
710   {
711     EmitSelectionChangedSignal();
712   }
713
714   if(mSelectionCleared)
715   {
716     EmitSelectionClearedSignal();
717   }
718
719   // The text-field emits signals when the input style changes. These changes of style are
720   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
721   // can't be emitted during the size negotiation as the callbacks may update the UI.
722   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
723   if(!mController->IsInputStyleChangedSignalsQueueEmpty())
724   {
725     if(Adaptor::IsAvailable())
726     {
727       Adaptor& adaptor = Adaptor::Get();
728
729       if(NULL == mIdleCallback)
730       {
731         // @note: The callback manager takes the ownership of the callback object.
732         mIdleCallback = MakeCallback(this, &TextField::OnIdleSignal);
733         adaptor.AddIdle(mIdleCallback, false);
734       }
735     }
736   }
737 }
738
739 Text::ControllerPtr TextField::GetTextController()
740 {
741   return mController;
742 }
743
744 void TextField::RenderText(Text::Controller::UpdateTextType updateTextType)
745 {
746   CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mCursorLayer, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
747 }
748
749 void TextField::OnKeyInputFocusGained()
750 {
751   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get());
752   if(mInputMethodContext && IsEditable())
753   {
754     // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
755     mInputMethodContext.ApplyOptions(mInputMethodOptions);
756     mInputMethodContext.NotifyTextInputMultiLine(false);
757
758     mInputMethodContext.StatusChangedSignal().Connect(this, &TextField::KeyboardStatusChanged);
759
760     mInputMethodContext.EventReceivedSignal().Connect(this, &TextField::OnInputMethodContextEvent);
761
762     // Notify that the text editing start.
763     mInputMethodContext.Activate();
764
765     // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
766     mInputMethodContext.SetRestoreAfterFocusLost(true);
767   }
768
769   if(IsEditable() && mController->IsUserInteractionEnabled())
770   {
771     mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
772   }
773
774   EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
775 }
776
777 void TextField::OnKeyInputFocusLost()
778 {
779   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get());
780   if(mInputMethodContext)
781   {
782     mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextField::KeyboardStatusChanged);
783     // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
784     mInputMethodContext.SetRestoreAfterFocusLost(false);
785
786     // Notify that the text editing finish.
787     mInputMethodContext.Deactivate();
788
789     mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
790   }
791
792   mController->KeyboardFocusLostEvent();
793
794   EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
795 }
796
797 bool TextField::OnAccessibilityActivated()
798 {
799   SetKeyInputFocus();
800   return true;
801 }
802
803 void TextField::OnTap(const TapGesture& gesture)
804 {
805   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
806
807   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
808   Extents padding;
809   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
810   const Vector2& localPoint = gesture.GetLocalPoint();
811   mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
812   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
813
814   Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
815   if(keyboardFocusManager)
816   {
817     keyboardFocusManager.SetCurrentFocusActor(Self());
818   }
819   SetKeyInputFocus();
820 }
821
822 void TextField::OnPan(const PanGesture& gesture)
823 {
824   mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
825   if(gesture.GetState() == GestureState::STARTED && !mController->IsScrollable(gesture.GetDisplacement()))
826   {
827     Dali::DevelActor::SetNeedGesturePropagation(Self(), true);
828   }
829 }
830
831 void TextField::OnLongPress(const LongPressGesture& gesture)
832 {
833   if(mInputMethodContext && IsEditable())
834   {
835     mInputMethodContext.Activate();
836   }
837   Extents padding;
838   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
839   const Vector2& localPoint = gesture.GetLocalPoint();
840   mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
841
842   SetKeyInputFocus();
843 }
844
845 bool TextField::OnKeyEvent(const KeyEvent& event)
846 {
847   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
848
849   if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
850   {
851     // Make sure ClearKeyInputFocus when only key is up
852     if(event.GetState() == KeyEvent::UP)
853     {
854       Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
855       if(keyboardFocusManager)
856       {
857         keyboardFocusManager.ClearFocus();
858       }
859       ClearKeyInputFocus();
860     }
861
862     return true;
863   }
864   else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
865   {
866     // Do nothing when enter is comming.
867     return false;
868   }
869
870   return mController->KeyEvent(event);
871 }
872
873 void TextField::RequestTextRelayout()
874 {
875   RelayoutRequest();
876 }
877
878 bool TextField::IsEditable() const
879 {
880   return mController->IsEditable();
881 }
882
883 void TextField::SetEditable(bool editable)
884 {
885   mController->SetEditable(editable);
886   if(mInputMethodContext && !editable)
887   {
888     mInputMethodContext.Deactivate();
889   }
890 }
891
892 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
893 {
894   GetAccessibleObject()->EmitTextInserted(position, length, content);
895 }
896
897 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
898 {
899   GetAccessibleObject()->EmitTextDeleted(position, length, content);
900 }
901
902 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
903 {
904   GetAccessibleObject()->EmitTextCursorMoved(newPosition);
905
906   if((oldPosition != newPosition) && !mCursorPositionChanged)
907   {
908     mCursorPositionChanged = true;
909     mOldPosition           = oldPosition;
910   }
911 }
912
913 void TextField::TextChanged(bool immediate)
914 {
915   if(immediate) // Emits TextChangedSignal immediately
916   {
917     EmitTextChangedSignal();
918   }
919   else
920   {
921     mTextChanged = true;
922   }
923 }
924
925 void TextField::EmitTextChangedSignal()
926 {
927   Dali::Toolkit::TextField handle(GetOwner());
928   mTextChangedSignal.Emit(handle);
929   mTextChanged = false;
930 }
931
932 void TextField::MaxLengthReached()
933 {
934   Dali::Toolkit::TextField handle(GetOwner());
935   mMaxLengthReachedSignal.Emit(handle);
936 }
937
938 void TextField::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
939 {
940   Dali::Toolkit::TextField handle(GetOwner());
941   mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
942 }
943
944 void TextField::AnchorClicked(const std::string& href)
945 {
946   Dali::Toolkit::TextField handle(GetOwner());
947   mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
948 }
949
950 void TextField::EmitCursorPositionChangedSignal()
951 {
952   Dali::Toolkit::TextField handle(GetOwner());
953   mCursorPositionChangedSignal.Emit(handle, mOldPosition);
954   mCursorPositionChanged = false;
955 }
956
957 void TextField::InputFiltered(Toolkit::InputFilter::Property::Type type)
958 {
959   Dali::Toolkit::TextField handle(GetOwner());
960   mInputFilteredSignal.Emit(handle, type);
961 }
962
963 void TextField::EmitSelectionChangedSignal()
964 {
965   Dali::Toolkit::TextField handle(GetOwner());
966   mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
967   mSelectionChanged = false;
968 }
969
970 void TextField::EmitSelectionClearedSignal()
971 {
972   Dali::Toolkit::TextField handle(GetOwner());
973   mSelectionClearedSignal.Emit(handle);
974   mSelectionCleared = false;
975 }
976
977 void TextField::EmitSelectionStartedSignal()
978 {
979   Dali::Toolkit::TextField handle(GetOwner());
980   mSelectionStartedSignal.Emit(handle);
981   mSelectionStarted = false;
982 }
983
984 void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
985 {
986   if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
987   {
988     if(newStart == newEnd)
989     {
990       mSelectionCleared = true;
991     }
992     else
993     {
994       if(oldStart == oldEnd)
995       {
996         mSelectionStarted = true;
997       }
998     }
999
1000     mSelectionChanged  = true;
1001     mOldSelectionStart = oldStart;
1002     mOldSelectionEnd   = oldEnd;
1003
1004     if(mOldSelectionStart > mOldSelectionEnd)
1005     {
1006       //swap
1007       uint32_t temp      = mOldSelectionStart;
1008       mOldSelectionStart = mOldSelectionEnd;
1009       mOldSelectionEnd   = temp;
1010     }
1011   }
1012 }
1013
1014 void TextField::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
1015 {
1016   if(actor)
1017   {
1018     if(needsClipping)
1019     {
1020       mClippingDecorationActors.push_back(actor);
1021     }
1022
1023     // If the actor is a layer type, add it.
1024     if(type == DecorationType::ACTIVE_LAYER)
1025     {
1026       AddLayer(mActiveLayer, actor);
1027     }
1028     else if(type == DecorationType::CURSOR_LAYER)
1029     {
1030       AddLayer(mCursorLayer, actor);
1031     }
1032   }
1033 }
1034
1035 void TextField::AddLayer(Actor& layer, Actor& actor)
1036 {
1037   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1038   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1039   Self().Add(actor);
1040   layer = actor;
1041 }
1042
1043 void TextField::GetControlBackgroundColor(Vector4& color) const
1044 {
1045   Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1046   Property::Map*  resultMap = propValue.GetMap();
1047
1048   Property::Value* colorValue = nullptr;
1049   if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1050   {
1051     colorValue->Get(color);
1052   }
1053 }
1054
1055 void TextField::OnSceneConnect(Dali::Actor actor)
1056 {
1057   if(mHasBeenStaged)
1058   {
1059     RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1060   }
1061   else
1062   {
1063     mHasBeenStaged = true;
1064   }
1065 }
1066
1067 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1068 {
1069   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1070   return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1071 }
1072
1073 void TextField::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1074 {
1075   if(mDecorator)
1076   {
1077     Property::Map map;
1078     map[PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1079
1080     value = map;
1081   }
1082 }
1083
1084 void TextField::EnableClipping()
1085 {
1086   if(!mStencil)
1087   {
1088     // Creates an extra control to be used as stencil buffer.
1089     mStencil = Control::New();
1090     mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1091     mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1092     mStencil.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN, true);
1093
1094     // Creates a background visual. Even if the color is transparent it updates the stencil.
1095     mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
1096                          Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
1097
1098     // Enable the clipping property.
1099     mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
1100     mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1101
1102     Self().Add(mStencil);
1103   }
1104 }
1105
1106 void TextField::KeyboardStatusChanged(bool keyboardShown)
1107 {
1108   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1109
1110   // Just hide the grab handle when keyboard is hidden.
1111   if(!keyboardShown)
1112   {
1113     mController->KeyboardFocusLostEvent();
1114   }
1115   else
1116   {
1117     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1118   }
1119 }
1120
1121 void TextField::OnSceneConnection(int depth)
1122 {
1123   // Sets the depth to the visuals inside the text's decorator.
1124   mDecorator->SetTextDepth(depth);
1125
1126   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1127
1128   // Call the Control::OnSceneConnection() to set the depth of the background.
1129   Control::OnSceneConnection(depth);
1130 }
1131
1132 bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
1133 {
1134   return false;
1135 }
1136
1137 void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1138 {
1139   mController->ChangedLayoutDirection();
1140 }
1141
1142 void TextField::OnIdleSignal()
1143 {
1144   // Emits the change of input style signals.
1145   mController->ProcessInputStyleChangedSignals();
1146
1147   // Set the pointer to null as the callback manager deletes the callback after execute it.
1148   mIdleCallback = NULL;
1149 }
1150
1151 TextField::TextField(ControlBehaviour additionalBehaviour)
1152 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
1153   mIdleCallback(NULL),
1154   mAlignmentOffset(0.f),
1155   mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1156   mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
1157   mHasBeenStaged(false),
1158   mTextChanged(false),
1159   mCursorPositionChanged(false),
1160   mSelectionChanged(false),
1161   mSelectionCleared(false),
1162   mOldPosition(0u),
1163   mOldSelectionStart(0u),
1164   mOldSelectionEnd(0u),
1165   mSelectionStarted(false)
1166 {
1167 }
1168
1169 TextField::~TextField()
1170 {
1171   UnparentAndReset(mStencil);
1172
1173   if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1174   {
1175     Adaptor::Get().RemoveIdle(mIdleCallback);
1176   }
1177 }
1178
1179 Vector<Vector2> TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1180 {
1181   return mController->GetTextSize(startIndex, endIndex);
1182 }
1183
1184 Vector<Vector2> TextField::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1185 {
1186   return mController->GetTextPosition(startIndex, endIndex);
1187 }
1188
1189 Rect<float> TextField::GetLineBoundingRectangle(const uint32_t lineIndex) const
1190 {
1191   return mController->GetLineBoundingRectangle(lineIndex);
1192 }
1193
1194 Rect<float> TextField::GetCharacterBoundingRectangle(const uint32_t charIndex) const
1195 {
1196   return mController->GetCharacterBoundingRectangle(charIndex);
1197 }
1198
1199 int TextField::GetCharacterIndexAtPosition(float visualX, float visualY) const
1200 {
1201   return mController->GetCharacterIndexAtPosition(visualX, visualY);
1202 }
1203
1204 Rect<> TextField::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
1205 {
1206   return mController->GetTextBoundingRectangle(startIndex, endIndex);
1207 }
1208
1209 void TextField::SetSpannedText(const Text::Spanned& spannedText)
1210 {
1211   mController->SetSpannedText(spannedText);
1212 }
1213
1214 std::string TextField::TextFieldAccessible::GetName() const
1215 {
1216   if(IsHiddenInput())
1217   {
1218     return {};
1219   }
1220
1221   return GetWholeText();
1222 }
1223
1224 const std::vector<Toolkit::TextAnchor>& TextField::TextFieldAccessible::GetTextAnchors() const
1225 {
1226   auto self = Toolkit::TextField::DownCast(Self());
1227
1228   return Toolkit::GetImpl(self).mAnchorActors;
1229 }
1230
1231 Toolkit::Text::ControllerPtr TextField::TextFieldAccessible::GetTextController() const
1232 {
1233   auto self = Toolkit::TextField::DownCast(Self());
1234
1235   return Toolkit::GetImpl(self).GetTextController();
1236 }
1237
1238 std::uint32_t TextField::TextFieldAccessible::GetSubstituteCharacter() const
1239 {
1240   auto self                = Toolkit::TextField::DownCast(Self());
1241   auto hiddenInputSettings = self.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
1242   auto substChar           = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
1243
1244   if(substChar)
1245   {
1246     return static_cast<std::uint32_t>(substChar->Get<int>());
1247   }
1248
1249   return TextControlAccessible::GetSubstituteCharacter();
1250 }
1251
1252 bool TextField::TextFieldAccessible::IsHiddenInput() const
1253 {
1254   auto self                = Toolkit::TextField::DownCast(Self());
1255   auto hiddenInputSettings = self.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
1256   auto mode                = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
1257
1258   return (mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE));
1259 }
1260
1261 void TextField::TextFieldAccessible::RequestTextRelayout()
1262 {
1263   auto  self     = Toolkit::TextField::DownCast(Self());
1264   auto& selfImpl = Toolkit::GetImpl(self);
1265
1266   selfImpl.RequestTextRelayout();
1267 }
1268
1269 } // namespace Internal
1270
1271 } // namespace Toolkit
1272
1273 } // namespace Dali