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