Merge "fix incorrect index range in emoji-helper" into devel/master
[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()
213 {
214   // Create the implementation, temporarily owned by this handle on stack
215   IntrusivePtr<TextField> impl = new TextField();
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   ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
769
770   if(notifier)
771   {
772     notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected);
773   }
774
775   if(IsEditable() && mController->IsUserInteractionEnabled())
776   {
777     mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
778   }
779
780   EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
781 }
782
783 void TextField::OnKeyInputFocusLost()
784 {
785   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get());
786   if(mInputMethodContext)
787   {
788     mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextField::KeyboardStatusChanged);
789     // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
790     mInputMethodContext.SetRestoreAfterFocusLost(false);
791
792     // Notify that the text editing finish.
793     mInputMethodContext.Deactivate();
794
795     mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent);
796   }
797   ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
798
799   if(notifier)
800   {
801     notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected);
802   }
803
804   mController->KeyboardFocusLostEvent();
805
806   EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
807 }
808
809 bool TextField::OnAccessibilityActivated()
810 {
811   SetKeyInputFocus();
812   return true;
813 }
814
815 void TextField::OnTap(const TapGesture& gesture)
816 {
817   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get());
818   if(mInputMethodContext && IsEditable())
819   {
820     mInputMethodContext.Activate();
821   }
822   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
823   Extents padding;
824   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
825   const Vector2& localPoint = gesture.GetLocalPoint();
826   mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
827   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
828
829   Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
830   if (keyboardFocusManager)
831   {
832     keyboardFocusManager.SetCurrentFocusActor(Self());
833   }
834   SetKeyInputFocus();
835 }
836
837 void TextField::OnPan(const PanGesture& gesture)
838 {
839   mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
840 }
841
842 void TextField::OnLongPress(const LongPressGesture& gesture)
843 {
844   if(mInputMethodContext && IsEditable())
845   {
846     mInputMethodContext.Activate();
847   }
848   Extents padding;
849   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
850   const Vector2& localPoint = gesture.GetLocalPoint();
851   mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
852
853   SetKeyInputFocus();
854 }
855
856 bool TextField::OnKeyEvent(const KeyEvent& event)
857 {
858   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
859
860   if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
861   {
862     // Make sure ClearKeyInputFocus when only key is up
863     if(event.GetState() == KeyEvent::UP)
864     {
865       Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
866       if (keyboardFocusManager)
867       {
868         keyboardFocusManager.ClearFocus();
869       }
870       ClearKeyInputFocus();
871     }
872
873     return true;
874   }
875   else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode())
876   {
877     // Do nothing when enter is comming.
878     return false;
879   }
880
881   return mController->KeyEvent(event);
882 }
883
884 void TextField::RequestTextRelayout()
885 {
886   RelayoutRequest();
887 }
888
889 bool TextField::IsEditable() const
890 {
891   return mController->IsEditable();
892 }
893
894 void TextField::SetEditable(bool editable)
895 {
896   mController->SetEditable(editable);
897   if(mInputMethodContext && !editable)
898   {
899     mInputMethodContext.Deactivate();
900   }
901 }
902
903 void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
904 {
905   GetAccessibleObject()->EmitTextInserted(position, length, content);
906 }
907
908 void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
909 {
910   GetAccessibleObject()->EmitTextDeleted(position, length, content);
911 }
912
913 void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
914 {
915   GetAccessibleObject()->EmitTextCursorMoved(newPosition);
916
917   if((oldPosition != newPosition) && !mCursorPositionChanged)
918   {
919     mCursorPositionChanged = true;
920     mOldPosition           = oldPosition;
921   }
922 }
923
924 void TextField::TextChanged(bool immediate)
925 {
926   if(immediate) // Emits TextChangedSignal immediately
927   {
928     EmitTextChangedSignal();
929   }
930   else
931   {
932     mTextChanged = true;
933   }
934 }
935
936 void TextField::EmitTextChangedSignal()
937 {
938   Dali::Toolkit::TextField handle(GetOwner());
939   mTextChangedSignal.Emit(handle);
940   mTextChanged = false;
941 }
942
943 void TextField::MaxLengthReached()
944 {
945   Dali::Toolkit::TextField handle(GetOwner());
946   mMaxLengthReachedSignal.Emit(handle);
947 }
948
949 void TextField::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
950 {
951   Dali::Toolkit::TextField handle(GetOwner());
952   mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
953 }
954
955 void TextField::AnchorClicked(const std::string& href)
956 {
957   Dali::Toolkit::TextField handle(GetOwner());
958   mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
959 }
960
961 void TextField::EmitCursorPositionChangedSignal()
962 {
963   Dali::Toolkit::TextField handle(GetOwner());
964   mCursorPositionChangedSignal.Emit(handle, mOldPosition);
965   mCursorPositionChanged = false;
966 }
967
968 void TextField::InputFiltered(Toolkit::InputFilter::Property::Type type)
969 {
970   Dali::Toolkit::TextField handle(GetOwner());
971   mInputFilteredSignal.Emit(handle, type);
972 }
973
974 void TextField::EmitSelectionChangedSignal()
975 {
976   Dali::Toolkit::TextField handle(GetOwner());
977   mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
978   mSelectionChanged = false;
979 }
980
981 void TextField::EmitSelectionClearedSignal()
982 {
983   Dali::Toolkit::TextField handle(GetOwner());
984   mSelectionClearedSignal.Emit(handle);
985   mSelectionCleared = false;
986 }
987
988 void TextField::EmitSelectionStartedSignal()
989 {
990   Dali::Toolkit::TextField handle(GetOwner());
991   mSelectionStartedSignal.Emit(handle);
992   mSelectionStarted = false;
993 }
994
995 void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
996 {
997   if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
998   {
999     if(newStart == newEnd)
1000     {
1001       mSelectionCleared = true;
1002     }
1003     else
1004     {
1005       if(oldStart == oldEnd)
1006       {
1007         mSelectionStarted = true;
1008       }
1009     }
1010
1011     mSelectionChanged  = true;
1012     mOldSelectionStart = oldStart;
1013     mOldSelectionEnd   = oldEnd;
1014
1015     if(mOldSelectionStart > mOldSelectionEnd)
1016     {
1017       //swap
1018       uint32_t temp      = mOldSelectionStart;
1019       mOldSelectionStart = mOldSelectionEnd;
1020       mOldSelectionEnd   = temp;
1021     }
1022   }
1023 }
1024
1025 void TextField::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
1026 {
1027   if(actor)
1028   {
1029     if(needsClipping)
1030     {
1031       mClippingDecorationActors.push_back(actor);
1032     }
1033
1034     // If the actor is a layer type, add it.
1035     if(type == DecorationType::ACTIVE_LAYER)
1036     {
1037       AddLayer(mActiveLayer, actor);
1038     }
1039     else if(type == DecorationType::CURSOR_LAYER)
1040     {
1041       AddLayer(mCursorLayer, actor);
1042     }
1043   }
1044 }
1045
1046 void TextField::AddLayer(Actor& layer, Actor& actor)
1047 {
1048   actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1049   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1050   Self().Add(actor);
1051   layer = actor;
1052 }
1053
1054 void TextField::GetControlBackgroundColor(Vector4& color) const
1055 {
1056   Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1057   Property::Map*  resultMap = propValue.GetMap();
1058
1059   Property::Value* colorValue = nullptr;
1060   if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1061   {
1062     colorValue->Get(color);
1063   }
1064 }
1065
1066 void TextField::OnSceneConnect(Dali::Actor actor)
1067 {
1068   if(mHasBeenStaged)
1069   {
1070     RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1071   }
1072   else
1073   {
1074     mHasBeenStaged = true;
1075   }
1076 }
1077
1078 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1079 {
1080   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1081   return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1082 }
1083
1084 void TextField::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1085 {
1086   if(mDecorator)
1087   {
1088     Property::Map map;
1089     map[PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1090
1091     value = map;
1092   }
1093 }
1094
1095 void TextField::EnableClipping()
1096 {
1097   if(!mStencil)
1098   {
1099     // Creates an extra control to be used as stencil buffer.
1100     mStencil = Control::New();
1101     mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1102     mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1103
1104     // Creates a background visual. Even if the color is transparent it updates the stencil.
1105     mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
1106                          Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
1107
1108     // Enable the clipping property.
1109     mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
1110     mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
1111
1112     Self().Add(mStencil);
1113   }
1114 }
1115
1116 void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1117 {
1118   mController->PasteClipboardItemEvent();
1119 }
1120
1121 void TextField::KeyboardStatusChanged(bool keyboardShown)
1122 {
1123   DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1124
1125   // Just hide the grab handle when keyboard is hidden.
1126   if(!keyboardShown)
1127   {
1128     mController->KeyboardFocusLostEvent();
1129   }
1130   else
1131   {
1132     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1133   }
1134 }
1135
1136 void TextField::OnSceneConnection(int depth)
1137 {
1138   // Sets the depth to the visuals inside the text's decorator.
1139   mDecorator->SetTextDepth(depth);
1140
1141   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1142
1143   // Call the Control::OnSceneConnection() to set the depth of the background.
1144   Control::OnSceneConnection(depth);
1145 }
1146
1147 bool TextField::OnTouched(Actor actor, const TouchEvent& touch)
1148 {
1149   return false;
1150 }
1151
1152 void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1153 {
1154   mController->ChangedLayoutDirection();
1155 }
1156
1157 void TextField::OnIdleSignal()
1158 {
1159   // Emits the change of input style signals.
1160   mController->ProcessInputStyleChangedSignals();
1161
1162   // Set the pointer to null as the callback manager deletes the callback after execute it.
1163   mIdleCallback = NULL;
1164 }
1165
1166 TextField::TextField()
1167 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1168   mIdleCallback(NULL),
1169   mAlignmentOffset(0.f),
1170   mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1171   mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP),
1172   mHasBeenStaged(false),
1173   mTextChanged(false),
1174   mCursorPositionChanged(false),
1175   mSelectionChanged(false),
1176   mSelectionCleared(false),
1177   mOldPosition(0u),
1178   mOldSelectionStart(0u),
1179   mOldSelectionEnd(0u),
1180   mSelectionStarted(false)
1181 {
1182 }
1183
1184 TextField::~TextField()
1185 {
1186   UnparentAndReset(mStencil);
1187
1188   if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1189   {
1190     Adaptor::Get().RemoveIdle(mIdleCallback);
1191   }
1192 }
1193
1194 Vector<Vector2> TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
1195 {
1196   return mController->GetTextSize(startIndex, endIndex);
1197 }
1198
1199 Vector<Vector2> TextField::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
1200 {
1201   return mController->GetTextPosition(startIndex, endIndex);
1202 }
1203
1204 std::string TextField::TextFieldAccessible::GetName() const
1205 {
1206   if(IsHiddenInput())
1207   {
1208     return {};
1209   }
1210
1211   return GetWholeText();
1212 }
1213
1214 const std::vector<Toolkit::TextAnchor>& TextField::TextFieldAccessible::GetTextAnchors() const
1215 {
1216   auto self = Toolkit::TextField::DownCast(Self());
1217
1218   return Toolkit::GetImpl(self).mAnchorActors;
1219 }
1220
1221 Toolkit::Text::ControllerPtr TextField::TextFieldAccessible::GetTextController() const
1222 {
1223   auto self = Toolkit::TextField::DownCast(Self());
1224
1225   return Toolkit::GetImpl(self).GetTextController();
1226 }
1227
1228 std::uint32_t TextField::TextFieldAccessible::GetSubstituteCharacter() const
1229 {
1230   auto self                = Toolkit::TextField::DownCast(Self());
1231   auto hiddenInputSettings = self.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
1232   auto substChar           = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
1233
1234   if(substChar)
1235   {
1236     return static_cast<std::uint32_t>(substChar->Get<int>());
1237   }
1238
1239   return TextControlAccessible::GetSubstituteCharacter();
1240 }
1241
1242 bool TextField::TextFieldAccessible::IsHiddenInput() const
1243 {
1244   auto self                = Toolkit::TextField::DownCast(Self());
1245   auto hiddenInputSettings = self.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
1246   auto mode                = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
1247
1248   return (mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE));
1249 }
1250
1251 void TextField::TextFieldAccessible::RequestTextRelayout()
1252 {
1253   auto  self     = Toolkit::TextField::DownCast(Self());
1254   auto& selfImpl = Toolkit::GetImpl(self);
1255
1256   selfImpl.RequestTextRelayout();
1257 }
1258
1259 } // namespace Internal
1260
1261 } // namespace Toolkit
1262
1263 } // namespace Dali