Add SelectionStarted signal
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-editor-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-editor-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/object/property-helper-devel.h>
25 #include <dali/integration-api/adaptor-framework/adaptor.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 #include <limits>
33
34 // INTERNAL INCLUDES
35 #include <dali-toolkit/devel-api/controls/control-devel.h>
36 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/devel-api/text/rendering-backend.h>
38 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
39 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
40 #include <dali-toolkit/internal/controls/text-controls/text-editor-property-handler.h>
41 #include <dali-toolkit/internal/styling/style-manager-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
45 #include <dali-toolkit/internal/text/text-font-style.h>
46 #include <dali-toolkit/internal/text/text-view.h>
47 #include <dali-toolkit/public-api/text/text-enumerations.h>
48 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
49 #include <dali-toolkit/public-api/visuals/visual-properties.h>
50
51 using namespace Dali::Toolkit::Text;
52
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gTextEditorLogFilter = 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 float        DEFAULT_SCROLL_SPEED      = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
67 } // unnamed namespace
68
69 namespace
70 {
71 const char* const SCROLL_BAR_POSITION("sourcePosition");
72 const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin");
73 const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax");
74 const char* const SCROLL_BAR_CONTENT_SIZE("sourceContentSize");
75
76 // Type registration
77 BaseHandle Create()
78 {
79   return Toolkit::TextEditor::New();
80 }
81
82 // clang-format off
83 // Setup properties, signals and actions using the type-registry.
84 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextEditor, Toolkit::Control, Create);
85
86 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "text",                                 STRING,    TEXT                                )
87 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "textColor",                            VECTOR4,   TEXT_COLOR                          )
88 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "fontFamily",                           STRING,    FONT_FAMILY                         )
89 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "fontStyle",                            MAP,       FONT_STYLE                          )
90 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "pointSize",                            FLOAT,     POINT_SIZE                          )
91 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "horizontalAlignment",                  STRING,    HORIZONTAL_ALIGNMENT                )
92 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "scrollThreshold",                      FLOAT,     SCROLL_THRESHOLD                    )
93 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "scrollSpeed",                          FLOAT,     SCROLL_SPEED                        )
94 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "primaryCursorColor",                   VECTOR4,   PRIMARY_CURSOR_COLOR                )
95 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "secondaryCursorColor",                 VECTOR4,   SECONDARY_CURSOR_COLOR              )
96 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "enableCursorBlink",                    BOOLEAN,   ENABLE_CURSOR_BLINK                 )
97 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "cursorBlinkInterval",                  FLOAT,     CURSOR_BLINK_INTERVAL               )
98 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "cursorBlinkDuration",                  FLOAT,     CURSOR_BLINK_DURATION               )
99 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "cursorWidth",                          INTEGER,   CURSOR_WIDTH                        )
100 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "grabHandleImage",                      STRING,    GRAB_HANDLE_IMAGE                   )
101 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "grabHandlePressedImage",               STRING,    GRAB_HANDLE_PRESSED_IMAGE           )
102 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "selectionHandleImageLeft",             MAP,       SELECTION_HANDLE_IMAGE_LEFT         )
103 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "selectionHandleImageRight",            MAP,       SELECTION_HANDLE_IMAGE_RIGHT        )
104 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "selectionHandlePressedImageLeft",      MAP,       SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "selectionHandlePressedImageRight",     MAP,       SELECTION_HANDLE_PRESSED_IMAGE_RIGHT)
106 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "selectionHandleMarkerImageLeft",       MAP,       SELECTION_HANDLE_MARKER_IMAGE_LEFT  )
107 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "selectionHandleMarkerImageRight",      MAP,       SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "selectionHighlightColor",              VECTOR4,   SELECTION_HIGHLIGHT_COLOR           )
109 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "decorationBoundingBox",                RECTANGLE, DECORATION_BOUNDING_BOX             )
110 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "enableMarkup",                         BOOLEAN,   ENABLE_MARKUP                       )
111 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "inputColor",                           VECTOR4,   INPUT_COLOR                         )
112 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "inputFontFamily",                      STRING,    INPUT_FONT_FAMILY                   )
113 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "inputFontStyle",                       MAP,       INPUT_FONT_STYLE                    )
114 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "inputPointSize",                       FLOAT,     INPUT_POINT_SIZE                    )
115 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "lineSpacing",                          FLOAT,     LINE_SPACING                        )
116 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "inputLineSpacing",                     FLOAT,     INPUT_LINE_SPACING                  )
117 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "underline",                            MAP,       UNDERLINE                           )
118 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "inputUnderline",                       MAP,       INPUT_UNDERLINE                     )
119 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "shadow",                               MAP,       SHADOW                              )
120 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "inputShadow",                          MAP,       INPUT_SHADOW                        )
121 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "emboss",                               MAP,       EMBOSS                              )
122 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "inputEmboss",                          MAP,       INPUT_EMBOSS                        )
123 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "outline",                              MAP,       OUTLINE                             )
124 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "inputOutline",                         MAP,       INPUT_OUTLINE                       )
125 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "smoothScroll",                         BOOLEAN,   SMOOTH_SCROLL                       )
126 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "smoothScrollDuration",                 FLOAT,     SMOOTH_SCROLL_DURATION              )
127 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "enableScrollBar",                      BOOLEAN,   ENABLE_SCROLL_BAR                   )
128 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "scrollBarShowDuration",                FLOAT,     SCROLL_BAR_SHOW_DURATION            )
129 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "scrollBarFadeDuration",                FLOAT,     SCROLL_BAR_FADE_DURATION            )
130 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "pixelSize",                            FLOAT,     PIXEL_SIZE                          )
131 DALI_PROPERTY_REGISTRATION_READ_ONLY(Toolkit,       TextEditor, "lineCount",                            INTEGER,   LINE_COUNT                          )
132 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "enableSelection",                      BOOLEAN,   ENABLE_SELECTION                    )
133 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "placeholder",                          MAP,       PLACEHOLDER                         )
134 DALI_PROPERTY_REGISTRATION(Toolkit,                 TextEditor, "lineWrapMode",                         INTEGER,   LINE_WRAP_MODE                      )
135 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "placeholderText",                      STRING,    PLACEHOLDER_TEXT                    )
136 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "placeholderTextColor",                 VECTOR4,   PLACEHOLDER_TEXT_COLOR              )
137 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "enableShiftSelection",                 BOOLEAN,   ENABLE_SHIFT_SELECTION              )
138 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "enableGrabHandle",                     BOOLEAN,   ENABLE_GRAB_HANDLE                  )
139 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "matchSystemLanguageDirection",         BOOLEAN,   MATCH_SYSTEM_LANGUAGE_DIRECTION     )
140 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "renderingBackend",                     INTEGER,   RENDERING_BACKEND                   )
141 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "maxLength",                            INTEGER,   MAX_LENGTH                          )
142 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "selectedTextStart",                    INTEGER,   SELECTED_TEXT_START                 )
143 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "selectedTextEnd",                      INTEGER,   SELECTED_TEXT_END                   )
144 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "horizontalScrollPosition",             FLOAT,     HORIZONTAL_SCROLL_POSITION          )
145 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "verticalScrollPosition",               INTEGER,   VERTICAL_SCROLL_POSITION            )
146 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "enableEditing",                        BOOLEAN,   ENABLE_EDITING                      )
147 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Toolkit, TextEditor, "selectedText",                         STRING,    SELECTED_TEXT                       )
148 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "fontSizeScale",                        FLOAT,     FONT_SIZE_SCALE                     )
149 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "enableFontSizeScale",                  BOOLEAN,   ENABLE_FONT_SIZE_SCALE              )
150 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "primaryCursorPosition",                INTEGER,   PRIMARY_CURSOR_POSITION             )
151 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "grabHandleColor",                      VECTOR4,   GRAB_HANDLE_COLOR                   )
152 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "enableGrabHandlePopup",                BOOLEAN,   ENABLE_GRAB_HANDLE_POPUP            )
153 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "inputMethodSettings",                  MAP,       INPUT_METHOD_SETTINGS               )
154 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "inputFilter",                          MAP,       INPUT_FILTER                        )
155 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "ellipsis",                             BOOLEAN,   ELLIPSIS                            )
156 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "ellipsisPosition",                     INTEGER,   ELLIPSIS_POSITION                   )
157 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "minLineSize",                          FLOAT,     MIN_LINE_SIZE                       )
158 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "strikethrough",                        MAP,       STRIKETHROUGH                       )
159 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "inputStrikethrough",                   MAP,       INPUT_STRIKETHROUGH                 )
160
161 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged",           SIGNAL_TEXT_CHANGED           )
162 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged",     SIGNAL_INPUT_STYLE_CHANGED    )
163 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "maxLengthReached",      SIGNAL_MAX_LENGTH_REACHED     )
164 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "anchorClicked",         SIGNAL_ANCHOR_CLICKED         )
165 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputFiltered",         SIGNAL_INPUT_FILTERED         )
166 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
167 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionChanged",      SIGNAL_SELECTION_CHANGED      )
168 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionCleared",      SIGNAL_SELECTION_CLEARED      )
169 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "selectionStarted",      SIGNAL_SELECTION_STARTED      )
170
171 DALI_TYPE_REGISTRATION_END()
172 // clang-format on
173
174 Toolkit::TextEditor::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask inputStyleMask)
175 {
176   Toolkit::TextEditor::InputStyle::Mask editorInputStyleMask = Toolkit::TextEditor::InputStyle::NONE;
177
178   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_COLOR))
179   {
180     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::COLOR);
181   }
182   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_FAMILY))
183   {
184     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_FAMILY);
185   }
186   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_POINT_SIZE))
187   {
188     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::POINT_SIZE);
189   }
190   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WEIGHT))
191   {
192     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
193   }
194   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_WIDTH))
195   {
196     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
197   }
198   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_FONT_SLANT))
199   {
200     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::FONT_STYLE);
201   }
202   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_LINE_SPACING))
203   {
204     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::LINE_SPACING);
205   }
206   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_UNDERLINE))
207   {
208     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::UNDERLINE);
209   }
210   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_SHADOW))
211   {
212     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::SHADOW);
213   }
214   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_EMBOSS))
215   {
216     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::EMBOSS);
217   }
218   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_OUTLINE))
219   {
220     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::OUTLINE);
221   }
222   if(InputStyle::NONE != static_cast<InputStyle::Mask>(inputStyleMask & InputStyle::INPUT_STRIKETHROUGH))
223   {
224     editorInputStyleMask = static_cast<Toolkit::TextEditor::InputStyle::Mask>(editorInputStyleMask | Toolkit::TextEditor::InputStyle::STRIKETHROUGH);
225   }
226
227   return editorInputStyleMask;
228 }
229
230 } // namespace
231
232 Toolkit::TextEditor TextEditor::New()
233 {
234   // Create the implementation, temporarily owned by this handle on stack
235   IntrusivePtr<TextEditor> impl = new TextEditor();
236
237   // Pass ownership to CustomActor handle
238   Toolkit::TextEditor handle(*impl);
239
240   // Second-phase init of the implementation
241   // This can only be done after the CustomActor connection has been made...
242   impl->Initialize();
243
244   return handle;
245 }
246
247 void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
248 {
249   Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
250
251   DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor SetProperty\n");
252
253   if(textEditor)
254   {
255     PropertyHandler::SetProperty(textEditor, index, value);
256   }
257 }
258
259 Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index index)
260 {
261   Property::Value value;
262
263   Toolkit::TextEditor textEditor = Toolkit::TextEditor::DownCast(Dali::BaseHandle(object));
264
265   if(textEditor)
266   {
267     value = PropertyHandler::GetProperty(textEditor, index);
268   }
269   return value;
270 }
271
272 void TextEditor::SelectWholeText()
273 {
274   if(mController && mController->IsShowingRealText())
275   {
276     mController->SelectWholeText();
277     SetKeyInputFocus();
278   }
279 }
280
281 void TextEditor::SelectNone()
282 {
283   if(mController && mController->IsShowingRealText())
284   {
285     mController->SelectNone();
286   }
287 }
288
289 void TextEditor::SelectText(const uint32_t start, const uint32_t end)
290 {
291   if(mController && mController->IsShowingRealText())
292   {
293     mController->SelectText(start, end);
294     SetKeyInputFocus();
295   }
296 }
297
298 string TextEditor::CopyText()
299 {
300   string copiedText = "";
301   if(mController && mController->IsShowingRealText())
302   {
303     copiedText = mController->CopyText();
304   }
305   return copiedText;
306 }
307
308 string TextEditor::CutText()
309 {
310   string cutText = "";
311   if(mController && mController->IsShowingRealText())
312   {
313     cutText = mController->CutText();
314   }
315   return cutText;
316 }
317
318 void TextEditor::PasteText()
319 {
320   if(mController)
321   {
322     SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus.
323     mController->PasteText();
324   }
325 }
326
327 void TextEditor::ScrollBy(Vector2 scroll)
328 {
329   if(mController && mController->IsShowingRealText())
330   {
331     mController->ScrollBy(scroll);
332   }
333 }
334
335 float TextEditor::GetHorizontalScrollPosition()
336 {
337   if(mController && mController->IsShowingRealText())
338   {
339     return mController->GetHorizontalScrollPosition();
340   }
341   return 0;
342 }
343
344 float TextEditor::GetVerticalScrollPosition()
345 {
346   if(mController && mController->IsShowingRealText())
347   {
348     return mController->GetVerticalScrollPosition();
349   }
350   return 0;
351 }
352
353 Vector<Vector2> TextEditor::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const
354 {
355   return mController->GetTextSize(startIndex, endIndex);
356 }
357
358 Vector<Vector2> TextEditor::GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const
359 {
360   return mController->GetTextPosition(startIndex, endIndex);
361 }
362
363 string TextEditor::GetSelectedText() const
364 {
365   string selectedText = "";
366   if(mController && mController->IsShowingRealText())
367   {
368     selectedText = mController->GetSelectedText();
369   }
370   return selectedText;
371 }
372
373 InputMethodContext TextEditor::GetInputMethodContext()
374 {
375   return mInputMethodContext;
376 }
377
378 DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
379 {
380   return mMaxLengthReachedSignal;
381 }
382
383 DevelTextEditor::AnchorClickedSignalType& TextEditor::AnchorClickedSignal()
384 {
385   return mAnchorClickedSignal;
386 }
387
388 DevelTextEditor::CursorPositionChangedSignalType& TextEditor::CursorPositionChangedSignal()
389 {
390   return mCursorPositionChangedSignal;
391 }
392
393 DevelTextEditor::InputFilteredSignalType& TextEditor::InputFilteredSignal()
394 {
395   return mInputFilteredSignal;
396 }
397
398 DevelTextEditor::SelectionChangedSignalType& TextEditor::SelectionChangedSignal()
399 {
400   return mSelectionChangedSignal;
401 }
402
403 DevelTextEditor::SelectionClearedSignalType& TextEditor::SelectionClearedSignal()
404 {
405   return mSelectionClearedSignal;
406 }
407
408 DevelTextEditor::SelectionStartedSignalType& TextEditor::SelectionStartedSignal()
409 {
410   return mSelectionStartedSignal;
411 }
412
413 Text::ControllerPtr TextEditor::GetTextController()
414 {
415   return mController;
416 }
417
418 bool TextEditor::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
419 {
420   Dali::BaseHandle handle(object);
421
422   bool                connected(true);
423   Toolkit::TextEditor editor = Toolkit::TextEditor::DownCast(handle);
424
425   if(0 == strcmp(signalName.c_str(), SIGNAL_TEXT_CHANGED))
426   {
427     editor.TextChangedSignal().Connect(tracker, functor);
428   }
429   else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED))
430   {
431     editor.InputStyleChangedSignal().Connect(tracker, functor);
432   }
433   else if(0 == strcmp(signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED))
434   {
435     if(editor)
436     {
437       Internal::TextEditor& editorImpl(GetImpl(editor));
438       editorImpl.MaxLengthReachedSignal().Connect(tracker, functor);
439     }
440   }
441   else if(0 == strcmp(signalName.c_str(), SIGNAL_ANCHOR_CLICKED))
442   {
443     if(editor)
444     {
445       Internal::TextEditor& editorImpl(GetImpl(editor));
446       editorImpl.AnchorClickedSignal().Connect(tracker, functor);
447     }
448   }
449   else if(0 == strcmp(signalName.c_str(), SIGNAL_CURSOR_POSITION_CHANGED))
450   {
451     if(editor)
452     {
453       Internal::TextEditor& editorImpl(GetImpl(editor));
454       editorImpl.CursorPositionChangedSignal().Connect(tracker, functor);
455     }
456   }
457   else if(0 == strcmp(signalName.c_str(), SIGNAL_INPUT_FILTERED))
458   {
459     if(editor)
460     {
461       Internal::TextEditor& editorImpl(GetImpl(editor));
462       editorImpl.InputFilteredSignal().Connect(tracker, functor);
463     }
464   }
465   else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CHANGED))
466   {
467     if(editor)
468     {
469       Internal::TextEditor& editorImpl(GetImpl(editor));
470       editorImpl.SelectionChangedSignal().Connect(tracker, functor);
471     }
472   }
473   else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_CLEARED))
474   {
475     if(editor)
476     {
477       Internal::TextEditor& editorImpl(GetImpl(editor));
478       editorImpl.SelectionClearedSignal().Connect(tracker, functor);
479     }
480   }
481   else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
482   {
483     if(editor)
484     {
485       Internal::TextEditor& editorImpl(GetImpl(editor));
486       editorImpl.SelectionStartedSignal().Connect(tracker, functor);
487     }
488   }
489   else
490   {
491     // signalName does not match any signal
492     connected = false;
493   }
494
495   return connected;
496 }
497
498 Toolkit::TextEditor::TextChangedSignalType& TextEditor::TextChangedSignal()
499 {
500   return mTextChangedSignal;
501 }
502
503 Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedSignal()
504 {
505   return mInputStyleChangedSignal;
506 }
507
508 Toolkit::TextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
509 {
510   return mScrollStateChangedSignal;
511 }
512
513 void TextEditor::OnAccessibilityStatusChanged()
514 {
515   CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
516 }
517
518 void TextEditor::OnInitialize()
519 {
520   Actor self = Self();
521
522   mController = Text::Controller::New(this, this, this, this);
523
524   mDecorator = Text::Decorator::New(*mController,
525                                     *mController);
526
527   mInputMethodContext = InputMethodContext::New(self);
528
529   mController->GetLayoutEngine().SetLayout(Layout::Engine::MULTI_LINE_BOX);
530
531   // Enables the text input.
532   mController->EnableTextInput(mDecorator, mInputMethodContext);
533
534   // Enables the vertical scrolling after the text input has been enabled.
535   mController->SetVerticalScrollEnabled(true);
536
537   // Disables the horizontal scrolling.
538   mController->SetHorizontalScrollEnabled(false);
539
540   // Sets the maximum number of characters.
541   mController->SetMaximumNumberOfCharacters(std::numeric_limits<Length>::max());
542
543   // Enable the smooth handle panning.
544   mController->SetSmoothHandlePanEnabled(true);
545
546   mController->SetNoTextDoubleTapAction(Controller::NoTextTap::HIGHLIGHT);
547   mController->SetNoTextLongPressAction(Controller::NoTextTap::HIGHLIGHT);
548
549   // Sets layoutDirection value
550   Dali::Stage                 stage           = Dali::Stage::GetCurrent();
551   Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
552   mController->SetLayoutDirection(layoutDirection);
553
554   self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged);
555
556   // Forward input events to controller
557   EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS));
558   GetTapGestureDetector().SetMaximumTapsRequired(2);
559   GetTapGestureDetector().ReceiveAllTapEvents(true);
560
561   self.TouchedSignal().Connect(this, &TextEditor::OnTouched);
562
563   // Set BoundingBox to stage size if not already set.
564   Rect<int> boundingBox;
565   mDecorator->GetBoundingBox(boundingBox);
566
567   if(boundingBox.IsEmpty())
568   {
569     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
570     mDecorator->SetBoundingBox(Rect<int>(0.0f, 0.0f, stageSize.width, stageSize.height));
571   }
572
573   // Whether to flip the selection handles as soon as they cross.
574   mDecorator->FlipSelectionHandlesOnCrossEnabled(true);
575
576   // Set the default scroll speed.
577   mDecorator->SetScrollSpeed(DEFAULT_SCROLL_SPEED);
578
579   // Fill-parent area by default
580   self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
581   self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
582   self.OnSceneSignal().Connect(this, &TextEditor::OnSceneConnect);
583
584   //Enable highightability
585   self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
586
587   DevelControl::SetInputMethodContext(*this, mInputMethodContext);
588
589   // Creates an extra control to be used as stencil buffer.
590   mStencil = Control::New();
591   mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
592   mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
593
594   // Creates a background visual. Even if the color is transparent it updates the stencil.
595   mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND,
596                        Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR).Add(ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT));
597
598   // Enable the clipping property.
599   mStencil.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX);
600   mStencil.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
601
602   self.Add(mStencil);
603
604   DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
605     return std::unique_ptr<Dali::Accessibility::Accessible>(
606       new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY));
607   });
608
609   Accessibility::Bridge::EnabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
610   Accessibility::Bridge::DisabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged);
611 }
612
613 void TextEditor::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
614 {
615   DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n");
616
617   switch(change)
618   {
619     case StyleChange::DEFAULT_FONT_CHANGE:
620     {
621       DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange DEFAULT_FONT_CHANGE\n");
622       const std::string& newFont = GetImpl(styleManager).GetDefaultFontFamily();
623       // Property system did not set the font so should update it.
624       mController->UpdateAfterFontChange(newFont);
625       RelayoutRequest();
626       break;
627     }
628
629     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
630     {
631       GetImpl(styleManager).ApplyThemeStyle(Toolkit::Control(GetOwner()));
632       RelayoutRequest();
633       break;
634     }
635     case StyleChange::THEME_CHANGE:
636     {
637       // Nothing to do, let control base class handle this
638       break;
639     }
640   }
641
642   // Up call to Control
643   Control::OnStyleChange(styleManager, change);
644 }
645
646 Vector3 TextEditor::GetNaturalSize()
647 {
648   Extents padding;
649   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
650
651   Vector3 naturalSize = mController->GetNaturalSize();
652   naturalSize.width += (padding.start + padding.end);
653   naturalSize.height += (padding.top + padding.bottom);
654
655   return naturalSize;
656 }
657
658 float TextEditor::GetHeightForWidth(float width)
659 {
660   Extents padding;
661   padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
662   return mController->GetHeightForWidth(width) + padding.top + padding.bottom;
663 }
664
665 void TextEditor::ResizeActor(Actor& actor, const Vector2& size)
666 {
667   if(actor.GetProperty<Vector3>(Dali::Actor::Property::SIZE).GetVectorXY() != size)
668   {
669     actor.SetProperty(Actor::Property::SIZE, size);
670   }
671 }
672
673 void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container)
674 {
675   DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor OnRelayout\n");
676
677   Actor self = Self();
678
679   Extents padding;
680   padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
681
682   Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom));
683
684   // Support Right-To-Left of padding
685   Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
686
687   if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
688   {
689     std::swap(padding.start, padding.end);
690   }
691
692   if(mStencil)
693   {
694     mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
695     ResizeActor(mStencil, contentSize);
696   }
697   if(mActiveLayer)
698   {
699     mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
700     ResizeActor(mActiveLayer, contentSize);
701   }
702
703   // If there is text changed, callback is called.
704   if(mTextChanged)
705   {
706     EmitTextChangedSignal();
707   }
708
709   const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection);
710
711   if((Text::Controller::NONE_UPDATED != updateTextType) ||
712      !mRenderer)
713   {
714     DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnRelayout %p Displaying new contents\n", mController.Get());
715
716     if(mDecorator &&
717        (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
718     {
719       mDecorator->Relayout(contentSize);
720     }
721
722     if(!mRenderer)
723     {
724       mRenderer = Backend::Get().NewRenderer(mRenderingBackend);
725     }
726
727     RenderText(updateTextType);
728   }
729
730   if(mCursorPositionChanged)
731   {
732     EmitCursorPositionChangedSignal();
733   }
734
735   if(mSelectionStarted)
736   {
737     EmitSelectionStartedSignal();
738   }
739
740   if(mSelectionChanged)
741   {
742     EmitSelectionChangedSignal();
743   }
744
745   if(mSelectionCleared)
746   {
747     EmitSelectionClearedSignal();
748   }
749
750   // The text-editor emits signals when the input style changes. These changes of style are
751   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
752   // can't be emitted during the size negotiation as the callbacks may update the UI.
753   // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
754   if(!mController->IsInputStyleChangedSignalsQueueEmpty())
755   {
756     if(Adaptor::IsAvailable())
757     {
758       Adaptor& adaptor = Adaptor::Get();
759
760       if(NULL == mIdleCallback)
761       {
762         // @note: The callback manager takes the ownership of the callback object.
763         mIdleCallback = MakeCallback(this, &TextEditor::OnIdleSignal);
764         adaptor.AddIdle(mIdleCallback, false);
765       }
766     }
767   }
768 }
769
770 void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
771 {
772   CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType);
773   if(mRenderableActor)
774   {
775     ApplyScrollPosition();
776   }
777   UpdateScrollBar();
778 }
779
780 void TextEditor::OnKeyInputFocusGained()
781 {
782   DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get());
783   if(mInputMethodContext && IsEditable())
784   {
785     // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows).
786     mInputMethodContext.ApplyOptions(mInputMethodOptions);
787     mInputMethodContext.NotifyTextInputMultiLine(true);
788
789     mInputMethodContext.StatusChangedSignal().Connect(this, &TextEditor::KeyboardStatusChanged);
790
791     mInputMethodContext.EventReceivedSignal().Connect(this, &TextEditor::OnInputMethodContextEvent);
792
793     // Notify that the text editing start.
794     mInputMethodContext.Activate();
795
796     // When window gain lost focus, the InputMethodContext is deactivated. Thus when window gain focus again, the InputMethodContext must be activated.
797     mInputMethodContext.SetRestoreAfterFocusLost(true);
798   }
799   ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
800
801   if(notifier)
802   {
803     notifier.ContentSelectedSignal().Connect(this, &TextEditor::OnClipboardTextSelected);
804   }
805
806   mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
807
808   EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
809 }
810
811 void TextEditor::OnKeyInputFocusLost()
812 {
813   DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get());
814   if(mInputMethodContext)
815   {
816     mInputMethodContext.StatusChangedSignal().Disconnect(this, &TextEditor::KeyboardStatusChanged);
817
818     // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
819     mInputMethodContext.SetRestoreAfterFocusLost(false);
820
821     // Notify that the text editing finish.
822     mInputMethodContext.Deactivate();
823
824     mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent);
825   }
826   ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
827
828   if(notifier)
829   {
830     notifier.ContentSelectedSignal().Disconnect(this, &TextEditor::OnClipboardTextSelected);
831   }
832
833   mController->KeyboardFocusLostEvent();
834
835   EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
836 }
837
838 bool TextEditor::OnAccessibilityActivated()
839 {
840   SetKeyInputFocus();
841   return true;
842 }
843
844 void TextEditor::OnTap(const TapGesture& gesture)
845 {
846   DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get());
847   if(mInputMethodContext && IsEditable())
848   {
849     mInputMethodContext.Activate();
850   }
851   // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
852   Extents padding;
853   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
854   const Vector2& localPoint = gesture.GetLocalPoint();
855   mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top);
856   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
857
858   SetKeyInputFocus();
859 }
860
861 void TextEditor::OnPan(const PanGesture& gesture)
862 {
863   mController->PanEvent(gesture.GetState(), gesture.GetDisplacement());
864 }
865
866 void TextEditor::OnLongPress(const LongPressGesture& gesture)
867 {
868   if(mInputMethodContext && IsEditable())
869   {
870     mInputMethodContext.Activate();
871   }
872   Extents padding;
873   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
874   const Vector2& localPoint = gesture.GetLocalPoint();
875   mController->LongPressEvent(gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top);
876
877   SetKeyInputFocus();
878 }
879
880 bool TextEditor::OnKeyEvent(const KeyEvent& event)
881 {
882   DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode());
883
884   if(Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape())
885   {
886     // Make sure ClearKeyInputFocus when only key is up
887     if(event.GetState() == KeyEvent::UP)
888     {
889       ClearKeyInputFocus();
890     }
891
892     return true;
893   }
894
895   return mController->KeyEvent(event);
896 }
897
898 void TextEditor::RequestTextRelayout()
899 {
900   RelayoutRequest();
901 }
902
903 void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content)
904 {
905   if(Accessibility::IsUp())
906   {
907     Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
908   }
909 }
910
911 void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
912 {
913   if(Accessibility::IsUp())
914   {
915     Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
916   }
917 }
918
919 void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
920 {
921   if(Accessibility::IsUp())
922   {
923     Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
924   }
925
926   if((oldPosition != newPosition) && !mCursorPositionChanged)
927   {
928     mCursorPositionChanged = true;
929     mOldPosition           = oldPosition;
930   }
931 }
932
933 void TextEditor::TextChanged(bool immediate)
934 {
935   if(immediate) // Emits TextChangedSignal immediately
936   {
937     EmitTextChangedSignal();
938   }
939   else
940   {
941     mTextChanged = true;
942   }
943 }
944
945 void TextEditor::EmitTextChangedSignal()
946 {
947   Dali::Toolkit::TextEditor handle(GetOwner());
948   mTextChangedSignal.Emit(handle);
949   mTextChanged = false;
950 }
951
952 void TextEditor::MaxLengthReached()
953 {
954   Dali::Toolkit::TextEditor handle(GetOwner());
955   mMaxLengthReachedSignal.Emit(handle);
956 }
957
958 void TextEditor::InputStyleChanged(Text::InputStyle::Mask inputStyleMask)
959 {
960   Dali::Toolkit::TextEditor handle(GetOwner());
961   mInputStyleChangedSignal.Emit(handle, ConvertInputStyle(inputStyleMask));
962 }
963
964 void TextEditor::AnchorClicked(const std::string& href)
965 {
966   Dali::Toolkit::TextEditor handle(GetOwner());
967   mAnchorClickedSignal.Emit(handle, href.c_str(), href.length());
968 }
969
970 void TextEditor::EmitCursorPositionChangedSignal()
971 {
972   Dali::Toolkit::TextEditor handle(GetOwner());
973   mCursorPositionChanged = false;
974   mCursorPositionChangedSignal.Emit(handle, mOldPosition);
975 }
976
977 void TextEditor::InputFiltered(Toolkit::InputFilter::Property::Type type)
978 {
979   Dali::Toolkit::TextEditor handle(GetOwner());
980   mInputFilteredSignal.Emit(handle, type);
981 }
982
983 void TextEditor::EmitSelectionChangedSignal()
984 {
985   Dali::Toolkit::TextEditor handle(GetOwner());
986   mSelectionChangedSignal.Emit(handle, mOldSelectionStart, mOldSelectionEnd);
987   mSelectionChanged = false;
988 }
989
990 void TextEditor::EmitSelectionClearedSignal()
991 {
992   Dali::Toolkit::TextEditor handle(GetOwner());
993   mSelectionClearedSignal.Emit(handle);
994   mSelectionCleared = false;
995 }
996
997 void TextEditor::EmitSelectionStartedSignal()
998 {
999   Dali::Toolkit::TextEditor handle(GetOwner());
1000   mSelectionStartedSignal.Emit(handle);
1001   mSelectionStarted = false;
1002 }
1003
1004 void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
1005 {
1006   if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
1007   {
1008     if(newStart == newEnd)
1009     {
1010       mSelectionCleared = true;
1011     }
1012     else
1013     {
1014       if(oldStart == oldEnd)
1015       {
1016         mSelectionStarted = true;
1017       }
1018     }
1019
1020     mSelectionChanged  = true;
1021     mOldSelectionStart = oldStart;
1022     mOldSelectionEnd   = oldEnd;
1023
1024     if(mOldSelectionStart > mOldSelectionEnd)
1025     {
1026       //swap
1027       uint32_t temp      = mOldSelectionStart;
1028       mOldSelectionStart = mOldSelectionEnd;
1029       mOldSelectionEnd   = temp;
1030     }
1031   }
1032 }
1033
1034 void TextEditor::AddDecoration(Actor& actor, bool needsClipping)
1035 {
1036   if(actor)
1037   {
1038     if(needsClipping)
1039     {
1040       mClippingDecorationActors.push_back(actor);
1041     }
1042     else
1043     {
1044       actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1045       actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1046       Self().Add(actor);
1047       mActiveLayer = actor;
1048     }
1049   }
1050 }
1051
1052 void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1053 {
1054   if(mController && mController->IsShowingRealText())
1055   {
1056     mController->SetTextSelectionRange(start, end);
1057     SetKeyInputFocus();
1058   }
1059 }
1060
1061 Uint32Pair TextEditor::GetTextSelectionRange() const
1062 {
1063   Uint32Pair range(0, 0);
1064   if(mController && mController->IsShowingRealText())
1065   {
1066     range = mController->GetTextSelectionRange();
1067   }
1068   return range;
1069 }
1070
1071 void TextEditor::GetControlBackgroundColor(Vector4& color) const
1072 {
1073   Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
1074   Property::Map*  resultMap = propValue.GetMap();
1075
1076   Property::Value* colorValue = nullptr;
1077   if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR)))
1078   {
1079     colorValue->Get(color);
1080   }
1081 }
1082
1083 void TextEditor::UpdateScrollBar()
1084 {
1085   using namespace Dali;
1086
1087   float scrollPosition;
1088   float controlSize;
1089   float layoutSize;
1090   bool  latestScrolled;
1091
1092   if(!mScrollBarEnabled)
1093   {
1094     return;
1095   }
1096   latestScrolled = mController->GetTextScrollInfo(scrollPosition, controlSize, layoutSize);
1097   if(!latestScrolled || controlSize > layoutSize)
1098   {
1099     return;
1100   }
1101
1102   CustomActor self = Self();
1103   if(!mScrollBar)
1104   {
1105     mScrollBar = Toolkit::ScrollBar::New(Toolkit::ScrollBar::VERTICAL);
1106     mScrollBar.SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
1107     mScrollBar.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
1108     mScrollBar.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
1109     mScrollBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
1110     mScrollBar.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH);
1111
1112     // Register the scroll position property
1113     Property::Index propertyScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION, scrollPosition);
1114     // Register the minimum scroll position property
1115     Property::Index propertyMinScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MIN, 0.0f);
1116     // Register the maximum scroll position property
1117     Property::Index propertyMaxScrollPosition = self.RegisterProperty(SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize));
1118     // Register the scroll content size property
1119     Property::Index propertyScrollContentSize = self.RegisterProperty(SCROLL_BAR_CONTENT_SIZE, layoutSize);
1120
1121     mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
1122
1123     // Set style name of ScrollBar for styling
1124     mScrollBar.SetStyleName("TextEditorScrollBar");
1125     Toolkit::Control scrollIndicator = Toolkit::Control::DownCast(mScrollBar.GetScrollIndicator());
1126     if(scrollIndicator)
1127     {
1128       // Set style name of ScrollBarIndicator for styling
1129       scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
1130     }
1131
1132     self.Add(mScrollBar);
1133   }
1134   else
1135   {
1136     Property::Index propertyScrollPosition    = self.GetPropertyIndex(SCROLL_BAR_POSITION);
1137     Property::Index propertyMaxScrollPosition = self.GetPropertyIndex(SCROLL_BAR_POSITION_MAX);
1138     Property::Index propertyScrollContentSize = self.GetPropertyIndex(SCROLL_BAR_CONTENT_SIZE);
1139
1140     self.SetProperty(propertyScrollPosition, scrollPosition);
1141     self.SetProperty(propertyMaxScrollPosition, (layoutSize - controlSize));
1142     self.SetProperty(propertyScrollContentSize, layoutSize);
1143   }
1144
1145   // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
1146   if(!mScrollStarted)
1147   {
1148     mScrollStarted = true;
1149     Dali::Toolkit::TextEditor handle(GetOwner());
1150     mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::STARTED);
1151   }
1152
1153   Actor indicator = mScrollBar.GetScrollIndicator();
1154   if(mAnimation)
1155   {
1156     mAnimation.Stop(); // Cancel any animation
1157   }
1158   else
1159   {
1160     mAnimation = Animation::New(mAnimationPeriod.durationSeconds);
1161   }
1162   indicator.SetProperty(Actor::Property::OPACITY, 1.0f);
1163   mAnimation.AnimateTo(Property(indicator, Actor::Property::COLOR_ALPHA), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod);
1164   mAnimation.Play();
1165   mAnimation.FinishedSignal().Connect(this, &TextEditor::OnScrollIndicatorAnimationFinished);
1166 }
1167
1168 void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation)
1169 {
1170   // If animation is successfully ended, then emit ScrollStateChangedSignal
1171   if(animation.GetCurrentProgress() == 0.0f)
1172   {
1173     mScrollStarted = false;
1174     Dali::Toolkit::TextEditor handle(GetOwner());
1175     mScrollStateChangedSignal.Emit(handle, Toolkit::TextEditor::Scroll::FINISHED);
1176   }
1177 }
1178
1179 void TextEditor::OnSceneConnect(Dali::Actor actor)
1180 {
1181   if(mHasBeenStaged)
1182   {
1183     RenderText(static_cast<Text::Controller::UpdateTextType>(Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED));
1184   }
1185   else
1186   {
1187     mHasBeenStaged = true;
1188   }
1189 }
1190
1191 InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent(Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1192 {
1193   DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName);
1194   return mController->OnInputMethodContextEvent(inputMethodContext, inputMethodContextEvent);
1195 }
1196
1197 void TextEditor::GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType)
1198 {
1199   if(mDecorator)
1200   {
1201     Property::Map map;
1202     map[TextEditor::PropertyHandler::IMAGE_MAP_FILENAME_STRING] = mDecorator->GetHandleImage(handleType, handleImageType);
1203
1204     value = map;
1205   }
1206 }
1207
1208 void TextEditor::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
1209 {
1210   mController->PasteClipboardItemEvent();
1211 }
1212
1213 void TextEditor::KeyboardStatusChanged(bool keyboardShown)
1214 {
1215   DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
1216
1217   // Just hide the grab handle when keyboard is hidden.
1218   if(!keyboardShown)
1219   {
1220     mController->KeyboardFocusLostEvent();
1221   }
1222   else
1223   {
1224     mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1225   }
1226 }
1227
1228 void TextEditor::OnSceneConnection(int depth)
1229 {
1230   // Sets the depth to the visuals inside the text's decorator.
1231   mDecorator->SetTextDepth(depth);
1232
1233   // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1234
1235   // Call the Control::OnSceneConnection() to set the depth of the background.
1236   Control::OnSceneConnection(depth);
1237 }
1238
1239 bool TextEditor::OnTouched(Actor actor, const TouchEvent& touch)
1240 {
1241   return false;
1242 }
1243
1244 void TextEditor::OnIdleSignal()
1245 {
1246   // Emits the change of input style signals.
1247   mController->ProcessInputStyleChangedSignals();
1248
1249   // Set the pointer to null as the callback manager deletes the callback after execute it.
1250   mIdleCallback = NULL;
1251 }
1252
1253 void TextEditor::ApplyScrollPosition()
1254 {
1255   const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1256   float          scrollAmount = 0.0f;
1257
1258   if(mScrollAnimationEnabled)
1259   {
1260     scrollAmount = mController->GetScrollAmountByUserInput();
1261   }
1262   if(mTextVerticalScroller)
1263   {
1264     mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1265   }
1266   else if(Equals(scrollAmount, 0.0f, Math::MACHINE_EPSILON_1))
1267   {
1268     mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount));
1269   }
1270   else
1271   {
1272     mTextVerticalScroller = Text::TextVerticalScroller::New();
1273     if(!Equals(mScrollAnimationDuration, 0.0f, Math::MACHINE_EPSILON_1))
1274     {
1275       mTextVerticalScroller->SetDuration(mScrollAnimationDuration);
1276     }
1277     mTextVerticalScroller->CheckStartAnimation(mRenderableActor, scrollOffset.x + mAlignmentOffset, scrollOffset.y - scrollAmount, scrollAmount);
1278   }
1279 }
1280
1281 bool TextEditor::IsEditable() const
1282 {
1283   return mController->IsEditable();
1284 }
1285
1286 void TextEditor::SetEditable(bool editable)
1287 {
1288   mController->SetEditable(editable);
1289   if(mInputMethodContext && !editable)
1290   {
1291     mInputMethodContext.Deactivate();
1292   }
1293 }
1294
1295 void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
1296 {
1297   mController->ChangedLayoutDirection();
1298 }
1299
1300 TextEditor::TextEditor()
1301 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
1302   mAnimationPeriod(0.0f, 0.0f),
1303   mIdleCallback(NULL),
1304   mAlignmentOffset(0.f),
1305   mScrollAnimationDuration(0.f),
1306   mLineSpacing(0.f),
1307   mRenderingBackend(DEFAULT_RENDERING_BACKEND),
1308   mHasBeenStaged(false),
1309   mScrollAnimationEnabled(false),
1310   mScrollBarEnabled(false),
1311   mScrollStarted(false),
1312   mTextChanged(false),
1313   mCursorPositionChanged(false),
1314   mSelectionChanged(false),
1315   mSelectionCleared(false),
1316   mOldPosition(0u),
1317   mOldSelectionStart(0u),
1318   mOldSelectionEnd(0u),
1319   mSelectionStarted(false)
1320 {
1321 }
1322
1323 TextEditor::~TextEditor()
1324 {
1325   UnparentAndReset(mStencil);
1326
1327   if((NULL != mIdleCallback) && Adaptor::IsAvailable())
1328   {
1329     // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
1330     Adaptor::Get().RemoveIdle(mIdleCallback);
1331   }
1332 }
1333
1334 std::string TextEditor::AccessibleImpl::GetName() const
1335 {
1336   auto self = Toolkit::TextEditor::DownCast(Self());
1337   return self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1338 }
1339
1340 std::string TextEditor::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const
1341 {
1342   if(endOffset <= startOffset)
1343   {
1344     return {};
1345   }
1346
1347   auto self = Toolkit::TextEditor::DownCast(Self());
1348   auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1349
1350   if(startOffset > text.size() || endOffset > text.size())
1351   {
1352     return {};
1353   }
1354
1355   return text.substr(startOffset, endOffset - startOffset);
1356 }
1357
1358 size_t TextEditor::AccessibleImpl::GetCharacterCount() const
1359 {
1360   auto self = Toolkit::TextEditor::DownCast(Self());
1361   auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1362
1363   return text.size();
1364 }
1365
1366 size_t TextEditor::AccessibleImpl::GetCursorOffset() const
1367 {
1368   auto slf = Toolkit::TextEditor::DownCast(Self());
1369   return Dali::Toolkit::GetImpl(slf).GetTextController()->GetCursorPosition();
1370 }
1371
1372 bool TextEditor::AccessibleImpl::SetCursorOffset(size_t offset)
1373 {
1374   auto slf = Toolkit::TextEditor::DownCast(Self());
1375   auto txt = slf.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1376   if(offset > txt.size())
1377   {
1378     return false;
1379   }
1380
1381   auto& slfImpl = Dali::Toolkit::GetImpl(slf);
1382   slfImpl.GetTextController()->ResetCursorPosition(offset);
1383   slfImpl.RequestTextRelayout();
1384
1385   return true;
1386 }
1387
1388 Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary) const
1389 {
1390   auto self     = Toolkit::TextEditor::DownCast(Self());
1391   auto text     = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1392   auto textSize = text.size();
1393
1394   auto range = Dali::Accessibility::Range{};
1395
1396   switch(boundary)
1397   {
1398     case Dali::Accessibility::TextBoundary::CHARACTER:
1399     {
1400       if(offset < textSize)
1401       {
1402         range.content     = text[offset];
1403         range.startOffset = offset;
1404         range.endOffset   = offset + 1;
1405       }
1406       break;
1407     }
1408     case Dali::Accessibility::TextBoundary::WORD:
1409     case Dali::Accessibility::TextBoundary::LINE:
1410     {
1411       auto textString = text.c_str();
1412       auto breaks     = std::vector<char>(textSize, 0);
1413
1414       if(boundary == Dali::Accessibility::TextBoundary::WORD)
1415       {
1416         Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1417       }
1418       else
1419       {
1420         Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
1421       }
1422
1423       auto index   = 0u;
1424       auto counter = 0u;
1425       while(index < textSize && counter <= offset)
1426       {
1427         auto start = index;
1428         if(breaks[index])
1429         {
1430           while(breaks[index])
1431           {
1432             index++;
1433           }
1434           counter++;
1435         }
1436         else
1437         {
1438           if(boundary == Dali::Accessibility::TextBoundary::WORD)
1439           {
1440             index++;
1441           }
1442           if(boundary == Dali::Accessibility::TextBoundary::LINE)
1443           {
1444             counter++;
1445           }
1446         }
1447
1448         if((counter > 0) && ((counter - 1) == offset))
1449         {
1450           range.content     = text.substr(start, index - start + 1);
1451           range.startOffset = start;
1452           range.endOffset   = index + 1;
1453         }
1454
1455         if(boundary == Dali::Accessibility::TextBoundary::LINE)
1456         {
1457           index++;
1458         }
1459       }
1460       break;
1461     }
1462     case Dali::Accessibility::TextBoundary::SENTENCE:
1463     {
1464       /* not supported by default */
1465       break;
1466     }
1467     case Dali::Accessibility::TextBoundary::PARAGRAPH:
1468     {
1469       /* Paragraph is not supported by libunibreak library */
1470       break;
1471     }
1472     default:
1473       break;
1474   }
1475
1476   return range;
1477 }
1478
1479 Dali::Accessibility::Range TextEditor::AccessibleImpl::GetRangeOfSelection(size_t selectionIndex) const
1480 {
1481   // Since DALi supports only one selection indexes higher than 0 are ignored
1482   if(selectionIndex > 0)
1483   {
1484     return {};
1485   }
1486
1487   auto        self       = Toolkit::TextEditor::DownCast(Self());
1488   auto        controller = Dali::Toolkit::GetImpl(self).GetTextController();
1489   std::string value{};
1490   controller->RetrieveSelection(value);
1491   auto indices = controller->GetSelectionIndexes();
1492
1493   return {static_cast<size_t>(indices.first), static_cast<size_t>(indices.second), value};
1494 }
1495
1496 bool TextEditor::AccessibleImpl::RemoveSelection(size_t selectionIndex)
1497 {
1498   // Since DALi supports only one selection indexes higher than 0 are ignored
1499   if(selectionIndex > 0)
1500   {
1501     return false;
1502   }
1503
1504   auto self = Toolkit::TextEditor::DownCast(Self());
1505   Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
1506   return true;
1507 }
1508
1509 bool TextEditor::AccessibleImpl::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset)
1510 {
1511   // Since DALi supports only one selection indexes higher than 0 are ignored
1512   if(selectionIndex > 0)
1513   {
1514     return false;
1515   }
1516
1517   auto self = Toolkit::TextEditor::DownCast(Self());
1518   Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
1519   return true;
1520 }
1521
1522 bool TextEditor::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
1523 {
1524   if(endPosition <= startPosition)
1525   {
1526     return false;
1527   }
1528
1529   auto self = Toolkit::TextEditor::DownCast(Self());
1530   auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1531   Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1532
1533   return true;
1534 }
1535
1536 bool TextEditor::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
1537 {
1538   if(endPosition <= startPosition)
1539   {
1540     return false;
1541   }
1542
1543   auto self = Toolkit::TextEditor::DownCast(Self());
1544   auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1545   Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
1546
1547   self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1548
1549   return true;
1550 }
1551
1552 bool TextEditor::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
1553 {
1554   if(endPosition <= startPosition)
1555   {
1556     return false;
1557   }
1558
1559   auto self = Toolkit::TextEditor::DownCast(Self());
1560   auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1561
1562   self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
1563
1564   return true;
1565 }
1566
1567 Dali::Accessibility::States TextEditor::AccessibleImpl::CalculateStates()
1568 {
1569   using namespace Dali::Accessibility;
1570
1571   auto states              = DevelControl::ControlAccessible::CalculateStates();
1572   states[State::EDITABLE]  = true;
1573   states[State::FOCUSABLE] = true;
1574
1575   Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
1576   if(Self() == focusControl)
1577   {
1578     states[State::FOCUSED] = true;
1579   }
1580
1581   return states;
1582 }
1583
1584 bool TextEditor::AccessibleImpl::InsertText(size_t startPosition, std::string text)
1585 {
1586   auto self         = Toolkit::TextEditor::DownCast(Self());
1587   auto insertedText = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get<std::string>();
1588
1589   insertedText.insert(startPosition, text);
1590
1591   self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(insertedText));
1592
1593   return true;
1594 }
1595
1596 bool TextEditor::AccessibleImpl::SetTextContents(std::string newContents)
1597 {
1598   auto self = Toolkit::TextEditor::DownCast(Self());
1599   self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(newContents));
1600   return true;
1601 }
1602
1603 int32_t TextEditor::AccessibleImpl::GetLinkCount() const
1604 {
1605   auto self = Toolkit::TextEditor::DownCast(Self());
1606   return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
1607 }
1608
1609 Accessibility::Hyperlink* TextEditor::AccessibleImpl::GetLink(int32_t linkIndex) const
1610 {
1611   if(linkIndex < 0 || linkIndex >= GetLinkCount())
1612   {
1613     return nullptr;
1614   }
1615   auto self        = Toolkit::TextEditor::DownCast(Self());
1616   auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
1617   return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
1618 }
1619
1620 int32_t TextEditor::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
1621 {
1622   auto self       = Toolkit::TextEditor::DownCast(Self());
1623   auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
1624   return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
1625 }
1626
1627 } // namespace Internal
1628
1629 } // namespace Toolkit
1630
1631 } // namespace Dali