Merge "[ATSPI] Implementation of Hypertext and Hyperlink in text controls" into devel...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
1 /*
2  * Copyright (c) 2021 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/text/text-controller.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
23 #include <dali/devel-api/adaptor-framework/window-devel.h>
24 #include <dali/integration-api/debug.h>
25 #include <memory.h>
26 #include <cmath>
27 #include <limits>
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
31 #include <dali-toolkit/internal/text/text-controller-event-handler.h>
32 #include <dali-toolkit/internal/text/text-controller-impl.h>
33 #include <dali-toolkit/internal/text/text-controller-input-font-handler.h>
34 #include <dali-toolkit/internal/text/text-controller-input-properties.h>
35 #include <dali-toolkit/internal/text/text-controller-placeholder-handler.h>
36 #include <dali-toolkit/internal/text/text-controller-relayouter.h>
37 #include <dali-toolkit/internal/text/text-controller-text-updater.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39
40 namespace
41 {
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
44 #endif
45
46 constexpr float MAX_FLOAT = std::numeric_limits<float>::max();
47
48 const std::string EMPTY_STRING("");
49
50 template<typename Type>
51 void EnsureCreated(Type*& object)
52 {
53   if(!object)
54   {
55     object = new Type();
56   }
57 }
58
59 template<typename Type>
60 void EnsureCreated(std::unique_ptr<Type>& object)
61 {
62   if(!object)
63   {
64     object = std::unique_ptr<Type>(new Type());
65   }
66 }
67
68 template<typename Type, typename Arg1>
69 void EnsureCreated(Type*& object, Arg1 arg1)
70 {
71   if(!object)
72   {
73     object = new Type(arg1);
74   }
75 }
76
77 template<typename Type, typename Arg1, typename Arg2>
78 void EnsureCreated(Type*& object, Arg1 arg1, Arg2 arg2)
79 {
80   if(!object)
81   {
82     object = new Type(arg1, arg2);
83   }
84 }
85
86 float GetDpi()
87 {
88   unsigned int                      horizontalDpi = 0u;
89   unsigned int                      verticalDpi   = 0u;
90   Dali::TextAbstraction::FontClient fontClient    = Dali::TextAbstraction::FontClient::Get();
91   fontClient.GetDpi(horizontalDpi, verticalDpi);
92   return static_cast<float>(horizontalDpi);
93 }
94
95 float ConvertPixelToPoint(float pixel)
96 {
97   return pixel * 72.0f / GetDpi();
98 }
99
100 float ConvertPointToPixel(float point)
101 {
102   // Pixel size = Point size * DPI / 72.f
103   return point * GetDpi() / 72.0f;
104 }
105
106 void UpdateCursorPosition(Dali::Toolkit::Text::EventData* eventData)
107 {
108   if(eventData && Dali::Toolkit::Text::EventData::IsEditingState(eventData->mState))
109   {
110     // Update the cursor position if it's in editing mode
111     eventData->mDecoratorUpdated     = true;
112     eventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
113   }
114 }
115
116 } // namespace
117
118 namespace Dali::Toolkit::Text
119 {
120
121 void Controller::EnableTextInput(DecoratorPtr decorator, InputMethodContext& inputMethodContext)
122 {
123   if(!decorator)
124   {
125     delete mImpl->mEventData;
126     mImpl->mEventData = NULL;
127
128     // Nothing else to do.
129     return;
130   }
131
132   EnsureCreated(mImpl->mEventData, decorator, inputMethodContext);
133 }
134
135 void Controller::SetGlyphType(TextAbstraction::GlyphType glyphType)
136 {
137   // Metrics for bitmap & vector based glyphs are different
138   mImpl->mMetrics->SetGlyphType(glyphType);
139
140   // Clear the font-specific data
141   mImpl->ClearFontData();
142
143   mImpl->RequestRelayout();
144 }
145
146 void Controller::SetMarkupProcessorEnabled(bool enable)
147 {
148   if(enable != mImpl->mMarkupProcessorEnabled)
149   {
150     //If Text was already set, call the SetText again for enabling or disabling markup
151     mImpl->mMarkupProcessorEnabled = enable;
152     std::string text;
153     GetText(text);
154     SetText(text);
155   }
156
157   mImpl->mModel->mVisualModel->SetMarkupProcessorEnabled(enable);
158 }
159
160 bool Controller::IsMarkupProcessorEnabled() const
161 {
162   return mImpl->mMarkupProcessorEnabled;
163 }
164
165 bool Controller::HasAnchors() const
166 {
167   return (mImpl->mMarkupProcessorEnabled && mImpl->mModel->mLogicalModel->mAnchors.Count() && mImpl->IsShowingRealText());
168 }
169
170 void Controller::SetAutoScrollEnabled(bool enable)
171 {
172   DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable) ? "true" : "false", (mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX) ? "true" : "false", this);
173   mImpl->SetAutoScrollEnabled(enable);
174 }
175
176 bool Controller::IsAutoScrollEnabled() const
177 {
178   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled ? "true" : "false");
179   return mImpl->mIsAutoScrollEnabled;
180 }
181
182 CharacterDirection Controller::GetAutoScrollDirection() const
183 {
184   return mImpl->mIsTextDirectionRTL;
185 }
186
187 float Controller::GetAutoScrollLineAlignment() const
188 {
189   float offset = 0.f;
190   if(mImpl->mModel->mVisualModel && (0u != mImpl->mModel->mVisualModel->mLines.Count()))
191   {
192     offset = (*mImpl->mModel->mVisualModel->mLines.Begin()).alignmentOffset;
193   }
194   return offset;
195 }
196
197 void Controller::SetHorizontalScrollEnabled(bool enable)
198 {
199   if(mImpl->mEventData && mImpl->mEventData->mDecorator)
200   {
201     mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled(enable);
202   }
203 }
204
205 bool Controller::IsHorizontalScrollEnabled() const
206 {
207   return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
208 }
209
210 void Controller::SetVerticalScrollEnabled(bool enable)
211 {
212   if(mImpl->mEventData && mImpl->mEventData->mDecorator)
213   {
214     mImpl->mEventData->mDecorator->SetVerticalScrollEnabled(enable);
215   }
216 }
217
218 bool Controller::IsVerticalScrollEnabled() const
219 {
220   return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
221 }
222
223 void Controller::SetSmoothHandlePanEnabled(bool enable)
224 {
225   if(mImpl->mEventData && mImpl->mEventData->mDecorator)
226   {
227     mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled(enable);
228   }
229 }
230
231 bool Controller::IsSmoothHandlePanEnabled() const
232 {
233   return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
234 }
235
236 void Controller::SetMaximumNumberOfCharacters(Length maxCharacters)
237 {
238   mImpl->mMaximumNumberOfCharacters = maxCharacters;
239 }
240
241 int Controller::GetMaximumNumberOfCharacters()
242 {
243   return mImpl->mMaximumNumberOfCharacters;
244 }
245
246 void Controller::SetEnableCursorBlink(bool enable)
247 {
248   mImpl->SetEnableCursorBlink(enable);
249 }
250
251 bool Controller::GetEnableCursorBlink() const
252 {
253   return mImpl->mEventData && mImpl->mEventData->mCursorBlinkEnabled;
254 }
255
256 void Controller::SetMultiLineEnabled(bool enable)
257 {
258   mImpl->SetMultiLineEnabled(enable);
259 }
260
261 bool Controller::IsMultiLineEnabled() const
262 {
263   return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
264 }
265
266 void Controller::SetHorizontalAlignment(Text::HorizontalAlignment::Type alignment)
267 {
268   mImpl->SetHorizontalAlignment(alignment);
269 }
270
271 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
272 {
273   return mImpl->mModel->mHorizontalAlignment;
274 }
275
276 void Controller::SetVerticalAlignment(VerticalAlignment::Type alignment)
277 {
278   mImpl->SetVerticalAlignment(alignment);
279 }
280
281 VerticalAlignment::Type Controller::GetVerticalAlignment() const
282 {
283   return mImpl->mModel->mVerticalAlignment;
284 }
285
286 bool Controller::IsIgnoreSpacesAfterText() const
287 {
288   return mImpl->mModel->mIgnoreSpacesAfterText;
289 }
290
291 void Controller::SetIgnoreSpacesAfterText(bool ignore)
292 {
293   mImpl->mModel->mIgnoreSpacesAfterText = ignore;
294 }
295
296 void Controller::ChangedLayoutDirection()
297 {
298   mImpl->mIsLayoutDirectionChanged = true;
299 }
300
301 void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type)
302 {
303   mImpl->mModel->mMatchLayoutDirection = type;
304 }
305
306 DevelText::MatchLayoutDirection Controller::GetMatchLayoutDirection() const
307 {
308   return mImpl->mModel->mMatchLayoutDirection;
309 }
310
311 void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
312 {
313   mImpl->mLayoutDirection = layoutDirection;
314 }
315
316 Dali::LayoutDirection::Type Controller::GetLayoutDirection(Dali::Actor& actor) const
317 {
318   if(mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::LOCALE ||
319      (mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::INHERIT && !mImpl->mIsLayoutDirectionChanged))
320   {
321     return static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(actor).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
322   }
323   else
324   {
325     return static_cast<Dali::LayoutDirection::Type>(actor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
326   }
327 }
328
329 bool Controller::IsShowingRealText() const
330 {
331   return mImpl->IsShowingRealText();
332 }
333
334 void Controller::SetLineWrapMode(Text::LineWrap::Mode lineWrapMode)
335 {
336   mImpl->SetLineWrapMode(lineWrapMode);
337 }
338
339 Text::LineWrap::Mode Controller::GetLineWrapMode() const
340 {
341   return mImpl->mModel->mLineWrapMode;
342 }
343
344 void Controller::SetTextElideEnabled(bool enabled)
345 {
346   mImpl->mModel->mElideEnabled = enabled;
347   mImpl->mModel->mVisualModel->SetTextElideEnabled(enabled);
348 }
349
350 bool Controller::IsTextElideEnabled() const
351 {
352   return mImpl->mModel->mElideEnabled;
353 }
354
355 void Controller::SetTextFitEnabled(bool enabled)
356 {
357   mImpl->mTextFitEnabled = enabled;
358 }
359
360 bool Controller::IsTextFitEnabled() const
361 {
362   return mImpl->mTextFitEnabled;
363 }
364
365 void Controller::SetTextFitChanged(bool changed)
366 {
367   mImpl->mTextFitChanged = changed;
368 }
369
370 bool Controller::IsTextFitChanged() const
371 {
372   return mImpl->mTextFitChanged;
373 }
374
375 void Controller::SetTextFitMinSize(float minSize, FontSizeType type)
376 {
377   mImpl->mTextFitMinSize = (type == POINT_SIZE) ? minSize : ConvertPixelToPoint(minSize);
378 }
379
380 float Controller::GetTextFitMinSize() const
381 {
382   return mImpl->mTextFitMinSize;
383 }
384
385 void Controller::SetTextFitMaxSize(float maxSize, FontSizeType type)
386 {
387   mImpl->mTextFitMaxSize = (type == POINT_SIZE) ? maxSize : ConvertPixelToPoint(maxSize);
388 }
389
390 float Controller::GetTextFitMaxSize() const
391 {
392   return mImpl->mTextFitMaxSize;
393 }
394
395 void Controller::SetTextFitStepSize(float step, FontSizeType type)
396 {
397   mImpl->mTextFitStepSize = (type == POINT_SIZE) ? step : ConvertPixelToPoint(step);
398 }
399
400 float Controller::GetTextFitStepSize() const
401 {
402   return mImpl->mTextFitStepSize;
403 }
404
405 void Controller::SetTextFitContentSize(Vector2 size)
406 {
407   mImpl->mTextFitContentSize = size;
408 }
409
410 Vector2 Controller::GetTextFitContentSize() const
411 {
412   return mImpl->mTextFitContentSize;
413 }
414
415 float Controller::GetTextFitPointSize() const
416 {
417   return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFitPointSize : 0.0f;
418 }
419
420 void Controller::SetPlaceholderTextElideEnabled(bool enabled)
421 {
422   PlaceholderHandler::SetPlaceholderTextElideEnabled(*this, enabled);
423 }
424
425 bool Controller::IsPlaceholderTextElideEnabled() const
426 {
427   return PlaceholderHandler::IsPlaceholderTextElideEnabled(*this);
428 }
429
430 void Controller::SetSelectionEnabled(bool enabled)
431 {
432   mImpl->mEventData->mSelectionEnabled = enabled;
433 }
434
435 bool Controller::IsSelectionEnabled() const
436 {
437   return mImpl->mEventData->mSelectionEnabled;
438 }
439
440 void Controller::SetShiftSelectionEnabled(bool enabled)
441 {
442   mImpl->mEventData->mShiftSelectionFlag = enabled;
443 }
444
445 bool Controller::IsShiftSelectionEnabled() const
446 {
447   return mImpl->mEventData->mShiftSelectionFlag;
448 }
449
450 void Controller::SetGrabHandleEnabled(bool enabled)
451 {
452   mImpl->mEventData->mGrabHandleEnabled = enabled;
453 }
454
455 bool Controller::IsGrabHandleEnabled() const
456 {
457   return mImpl->mEventData->mGrabHandleEnabled;
458 }
459
460 void Controller::SetGrabHandlePopupEnabled(bool enabled)
461 {
462   mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
463 }
464
465 bool Controller::IsGrabHandlePopupEnabled() const
466 {
467   return mImpl->mEventData->mGrabHandlePopupEnabled;
468 }
469
470 void Controller::SetText(const std::string& text)
471 {
472   TextUpdater::SetText(*this, text);
473 }
474
475 void Controller::GetText(std::string& text) const
476 {
477   if(!mImpl->IsShowingPlaceholderText())
478   {
479     // Retrieves the text string.
480     mImpl->GetText(0u, text);
481   }
482   else
483   {
484     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this);
485   }
486 }
487
488 void Controller::SetPlaceholderText(PlaceholderType type, const std::string& text)
489 {
490   PlaceholderHandler::SetPlaceholderText(*this, type, text);
491 }
492
493 void Controller::GetPlaceholderText(PlaceholderType type, std::string& text) const
494 {
495   PlaceholderHandler::GetPlaceholderText(*this, type, text);
496 }
497
498 void Controller::UpdateAfterFontChange(const std::string& newDefaultFont)
499 {
500   mImpl->UpdateAfterFontChange(newDefaultFont);
501 }
502
503 void Controller::RetrieveSelection(std::string& selectedText) const
504 {
505   mImpl->RetrieveSelection(selectedText, false);
506 }
507
508 void Controller::SetSelection(int start, int end)
509 {
510   mImpl->SetSelection(start, end);
511 }
512
513 std::pair<int, int> Controller::GetSelectionIndexes() const
514 {
515   return mImpl->GetSelectionIndexes();
516 }
517
518 void Controller::CopyStringToClipboard(const std::string& source)
519 {
520   mImpl->CopyStringToClipboard(source);
521 }
522
523 void Controller::SendSelectionToClipboard(bool deleteAfterSending)
524 {
525   mImpl->SendSelectionToClipboard(deleteAfterSending);
526 }
527
528 void Controller::SetDefaultFontFamily(const std::string& defaultFontFamily)
529 {
530   EnsureCreated(mImpl->mFontDefaults);
531
532   mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
533   DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
534   mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
535
536   // Update the cursor position if it's in editing mode
537   UpdateCursorPosition(mImpl->mEventData);
538
539   // Clear the font-specific data
540   mImpl->ClearFontData();
541
542   mImpl->RequestRelayout();
543 }
544
545 const std::string& Controller::GetDefaultFontFamily() const
546 {
547   return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.family : EMPTY_STRING;
548 }
549
550 void Controller::SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily)
551 {
552   PlaceholderHandler::SetPlaceholderFontFamily(*this, placeholderTextFontFamily);
553 }
554
555 const std::string& Controller::GetPlaceholderFontFamily() const
556 {
557   return PlaceholderHandler::GetPlaceholderFontFamily(*this);
558 }
559
560 void Controller::SetDefaultFontWeight(FontWeight weight)
561 {
562   EnsureCreated(mImpl->mFontDefaults);
563
564   mImpl->mFontDefaults->mFontDescription.weight = weight;
565   mImpl->mFontDefaults->weightDefined           = true;
566
567   // Update the cursor position if it's in editing mode
568   UpdateCursorPosition(mImpl->mEventData);
569
570   // Clear the font-specific data
571   mImpl->ClearFontData();
572
573   mImpl->RequestRelayout();
574 }
575
576 bool Controller::IsDefaultFontWeightDefined() const
577 {
578   return mImpl->mFontDefaults && mImpl->mFontDefaults->weightDefined;
579 }
580
581 FontWeight Controller::GetDefaultFontWeight() const
582 {
583   return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.weight : TextAbstraction::FontWeight::NORMAL;
584 }
585
586 void Controller::SetPlaceholderTextFontWeight(FontWeight weight)
587 {
588   PlaceholderHandler::SetPlaceholderTextFontWeight(*this, weight);
589 }
590
591 bool Controller::IsPlaceholderTextFontWeightDefined() const
592 {
593   return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);
594 }
595
596 FontWeight Controller::GetPlaceholderTextFontWeight() const
597 {
598   return PlaceholderHandler::GetPlaceholderTextFontWeight(*this);
599 }
600
601 void Controller::SetDefaultFontWidth(FontWidth width)
602 {
603   EnsureCreated(mImpl->mFontDefaults);
604
605   mImpl->mFontDefaults->mFontDescription.width = width;
606   mImpl->mFontDefaults->widthDefined           = true;
607
608   // Update the cursor position if it's in editing mode
609   UpdateCursorPosition(mImpl->mEventData);
610
611   // Clear the font-specific data
612   mImpl->ClearFontData();
613
614   mImpl->RequestRelayout();
615 }
616
617 bool Controller::IsDefaultFontWidthDefined() const
618 {
619   return mImpl->mFontDefaults && mImpl->mFontDefaults->widthDefined;
620 }
621
622 FontWidth Controller::GetDefaultFontWidth() const
623 {
624   return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.width : TextAbstraction::FontWidth::NORMAL;
625 }
626
627 void Controller::SetPlaceholderTextFontWidth(FontWidth width)
628 {
629   PlaceholderHandler::SetPlaceholderTextFontWidth(*this, width);
630 }
631
632 bool Controller::IsPlaceholderTextFontWidthDefined() const
633 {
634   return PlaceholderHandler::IsPlaceholderTextFontWidthDefined(*this);
635 }
636
637 FontWidth Controller::GetPlaceholderTextFontWidth() const
638 {
639   return PlaceholderHandler::GetPlaceholderTextFontWidth(*this);
640 }
641
642 void Controller::SetDefaultFontSlant(FontSlant slant)
643 {
644   EnsureCreated(mImpl->mFontDefaults);
645
646   mImpl->mFontDefaults->mFontDescription.slant = slant;
647   mImpl->mFontDefaults->slantDefined           = true;
648
649   // Update the cursor position if it's in editing mode
650   UpdateCursorPosition(mImpl->mEventData);
651
652   // Clear the font-specific data
653   mImpl->ClearFontData();
654
655   mImpl->RequestRelayout();
656 }
657
658 bool Controller::IsDefaultFontSlantDefined() const
659 {
660   return mImpl->mFontDefaults && mImpl->mFontDefaults->slantDefined;
661 }
662
663 FontSlant Controller::GetDefaultFontSlant() const
664 {
665   return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.slant : TextAbstraction::FontSlant::NORMAL;
666 }
667
668 void Controller::SetPlaceholderTextFontSlant(FontSlant slant)
669 {
670   PlaceholderHandler::SetPlaceholderTextFontSlant(*this, slant);
671 }
672
673 bool Controller::IsPlaceholderTextFontSlantDefined() const
674 {
675   return PlaceholderHandler::IsPlaceholderTextFontSlantDefined(*this);
676 }
677
678 FontSlant Controller::GetPlaceholderTextFontSlant() const
679 {
680   return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
681 }
682
683 void Controller::SetFontSizeScale(float scale)
684 {
685   mImpl->mFontSizeScale = scale;
686
687   // Update the cursor position if it's in editing mode
688   UpdateCursorPosition(mImpl->mEventData);
689
690   // Clear the font-specific data
691   mImpl->ClearFontData();
692
693   mImpl->RequestRelayout();
694 }
695
696 float Controller::GetFontSizeScale() const
697 {
698   return mImpl->mFontDefaults ? mImpl->mFontSizeScale : 1.0f;
699 }
700
701 void Controller::SetDefaultFontSize(float fontSize, FontSizeType type)
702 {
703   EnsureCreated(mImpl->mFontDefaults);
704
705   mImpl->mFontDefaults->mDefaultPointSize = (type == POINT_SIZE) ? fontSize : ConvertPixelToPoint(fontSize);
706   mImpl->mFontDefaults->sizeDefined       = true;
707
708   // Update the cursor position if it's in editing mode
709   UpdateCursorPosition(mImpl->mEventData);
710
711   // Clear the font-specific data
712   mImpl->ClearFontData();
713
714   mImpl->RequestRelayout();
715 }
716
717 float Controller::GetDefaultFontSize(FontSizeType type) const
718 {
719   if(mImpl->mFontDefaults)
720   {
721     return (type == POINT_SIZE) ? mImpl->mFontDefaults->mDefaultPointSize : ConvertPointToPixel(mImpl->mFontDefaults->mDefaultPointSize);
722   }
723   return 0.0f;
724 }
725
726 void Controller::SetPlaceholderTextFontSize(float fontSize, FontSizeType type)
727 {
728   PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
729 }
730
731 float Controller::GetPlaceholderTextFontSize(FontSizeType type) const
732 {
733   return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
734 }
735
736 void Controller::SetDefaultColor(const Vector4& color)
737 {
738   mImpl->SetDefaultColor(color);
739 }
740
741 const Vector4& Controller::GetDefaultColor() const
742 {
743   return mImpl->mTextColor;
744 }
745
746 void Controller::SetPlaceholderTextColor(const Vector4& textColor)
747 {
748   PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
749 }
750
751 const Vector4& Controller::GetPlaceholderTextColor() const
752 {
753   return PlaceholderHandler::GetPlaceholderTextColor(*this);
754 }
755
756 void Controller::SetShadowOffset(const Vector2& shadowOffset)
757 {
758   mImpl->mModel->mVisualModel->SetShadowOffset(shadowOffset);
759   mImpl->RequestRelayout();
760 }
761
762 const Vector2& Controller::GetShadowOffset() const
763 {
764   return mImpl->mModel->mVisualModel->GetShadowOffset();
765 }
766
767 void Controller::SetShadowColor(const Vector4& shadowColor)
768 {
769   mImpl->mModel->mVisualModel->SetShadowColor(shadowColor);
770   mImpl->RequestRelayout();
771 }
772
773 const Vector4& Controller::GetShadowColor() const
774 {
775   return mImpl->mModel->mVisualModel->GetShadowColor();
776 }
777
778 void Controller::SetShadowBlurRadius(const float& shadowBlurRadius)
779 {
780   if(fabsf(GetShadowBlurRadius() - shadowBlurRadius) > Math::MACHINE_EPSILON_1)
781   {
782     mImpl->mModel->mVisualModel->SetShadowBlurRadius(shadowBlurRadius);
783     mImpl->RequestRelayout();
784   }
785 }
786
787 const float& Controller::GetShadowBlurRadius() const
788 {
789   return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
790 }
791
792 void Controller::SetUnderlineColor(const Vector4& color)
793 {
794   mImpl->mModel->mVisualModel->SetUnderlineColor(color);
795   mImpl->RequestRelayout();
796 }
797
798 const Vector4& Controller::GetUnderlineColor() const
799 {
800   return mImpl->mModel->mVisualModel->GetUnderlineColor();
801 }
802
803 void Controller::SetUnderlineEnabled(bool enabled)
804 {
805   mImpl->mModel->mVisualModel->SetUnderlineEnabled(enabled);
806   mImpl->RequestRelayout();
807 }
808
809 bool Controller::IsUnderlineEnabled() const
810 {
811   return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
812 }
813
814 void Controller::SetUnderlineHeight(float height)
815 {
816   mImpl->mModel->mVisualModel->SetUnderlineHeight(height);
817   mImpl->RequestRelayout();
818 }
819
820 float Controller::GetUnderlineHeight() const
821 {
822   return mImpl->mModel->mVisualModel->GetUnderlineHeight();
823 }
824
825 void Controller::SetOutlineColor(const Vector4& color)
826 {
827   mImpl->mModel->mVisualModel->SetOutlineColor(color);
828   mImpl->RequestRelayout();
829 }
830
831 const Vector4& Controller::GetOutlineColor() const
832 {
833   return mImpl->mModel->mVisualModel->GetOutlineColor();
834 }
835
836 void Controller::SetOutlineWidth(uint16_t width)
837 {
838   mImpl->mModel->mVisualModel->SetOutlineWidth(width);
839   mImpl->RequestRelayout();
840 }
841
842 uint16_t Controller::GetOutlineWidth() const
843 {
844   return mImpl->mModel->mVisualModel->GetOutlineWidth();
845 }
846
847 void Controller::SetBackgroundColor(const Vector4& color)
848 {
849   mImpl->mModel->mVisualModel->SetBackgroundColor(color);
850   mImpl->RequestRelayout();
851 }
852
853 const Vector4& Controller::GetBackgroundColor() const
854 {
855   return mImpl->mModel->mVisualModel->GetBackgroundColor();
856 }
857
858 void Controller::SetBackgroundEnabled(bool enabled)
859 {
860   mImpl->mModel->mVisualModel->SetBackgroundEnabled(enabled);
861   mImpl->RequestRelayout();
862 }
863
864 bool Controller::IsBackgroundEnabled() const
865 {
866   return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
867 }
868
869 void Controller::SetDefaultEmbossProperties(const std::string& embossProperties)
870 {
871   EnsureCreated(mImpl->mEmbossDefaults);
872   mImpl->mEmbossDefaults->properties = embossProperties;
873 }
874
875 const std::string& Controller::GetDefaultEmbossProperties() const
876 {
877   return mImpl->mEmbossDefaults ? mImpl->mEmbossDefaults->properties : EMPTY_STRING;
878 }
879
880 void Controller::SetDefaultOutlineProperties(const std::string& outlineProperties)
881 {
882   EnsureCreated(mImpl->mOutlineDefaults);
883   mImpl->mOutlineDefaults->properties = outlineProperties;
884 }
885
886 const std::string& Controller::GetDefaultOutlineProperties() const
887 {
888   return mImpl->mOutlineDefaults ? mImpl->mOutlineDefaults->properties : EMPTY_STRING;
889 }
890
891 bool Controller::SetDefaultLineSpacing(float lineSpacing)
892 {
893   return mImpl->SetDefaultLineSpacing(lineSpacing);
894 }
895
896 float Controller::GetDefaultLineSpacing() const
897 {
898   return mImpl->mLayoutEngine.GetDefaultLineSpacing();
899 }
900
901 bool Controller::SetDefaultLineSize(float lineSize)
902 {
903   return mImpl->SetDefaultLineSize(lineSize);
904 }
905
906 float Controller::GetDefaultLineSize() const
907 {
908   return mImpl->mLayoutEngine.GetDefaultLineSize();
909 }
910
911 void Controller::SetInputColor(const Vector4& color)
912 {
913   InputProperties::SetInputColor(*this, color);
914 }
915
916 const Vector4& Controller::GetInputColor() const
917 {
918   return InputProperties::GetInputColor(*this);
919 }
920
921 void Controller::SetInputFontFamily(const std::string& fontFamily)
922 {
923   InputFontHandler::SetInputFontFamily(*this, fontFamily);
924 }
925
926 const std::string& Controller::GetInputFontFamily() const
927 {
928   return InputFontHandler::GetInputFontFamily(*this);
929 }
930
931 void Controller::SetInputFontWeight(FontWeight weight)
932 {
933   InputFontHandler::SetInputFontWeight(*this, weight);
934 }
935
936 bool Controller::IsInputFontWeightDefined() const
937 {
938   return InputFontHandler::IsInputFontWeightDefined(*this);
939 }
940
941 FontWeight Controller::GetInputFontWeight() const
942 {
943   return InputFontHandler::GetInputFontWeight(*this);
944 }
945
946 void Controller::SetInputFontWidth(FontWidth width)
947 {
948   InputFontHandler::SetInputFontWidth(*this, width);
949 }
950
951 bool Controller::IsInputFontWidthDefined() const
952 {
953   return InputFontHandler::IsInputFontWidthDefined(*this);
954 }
955
956 FontWidth Controller::GetInputFontWidth() const
957 {
958   return InputFontHandler::GetInputFontWidth(*this);
959 }
960
961 void Controller::SetInputFontSlant(FontSlant slant)
962 {
963   InputFontHandler::SetInputFontSlant(*this, slant);
964 }
965
966 bool Controller::IsInputFontSlantDefined() const
967 {
968   return InputFontHandler::IsInputFontSlantDefined(*this);
969 }
970
971 FontSlant Controller::GetInputFontSlant() const
972 {
973   return InputFontHandler::GetInputFontSlant(*this);
974 }
975
976 void Controller::SetInputFontPointSize(float size)
977 {
978   InputFontHandler::SetInputFontPointSize(*this, size);
979 }
980
981 float Controller::GetInputFontPointSize() const
982 {
983   return InputFontHandler::GetInputFontPointSize(*this);
984 }
985
986 void Controller::SetInputLineSpacing(float lineSpacing)
987 {
988   InputProperties::SetInputLineSpacing(*this, lineSpacing);
989 }
990
991 float Controller::GetInputLineSpacing() const
992 {
993   return InputProperties::GetInputLineSpacing(*this);
994 }
995
996 void Controller::SetInputShadowProperties(const std::string& shadowProperties)
997 {
998   InputProperties::SetInputShadowProperties(*this, shadowProperties);
999 }
1000
1001 const std::string& Controller::GetInputShadowProperties() const
1002 {
1003   return InputProperties::GetInputShadowProperties(*this);
1004 }
1005
1006 void Controller::SetInputUnderlineProperties(const std::string& underlineProperties)
1007 {
1008   InputProperties::SetInputUnderlineProperties(*this, underlineProperties);
1009 }
1010
1011 const std::string& Controller::GetInputUnderlineProperties() const
1012 {
1013   return InputProperties::GetInputUnderlineProperties(*this);
1014 }
1015
1016 void Controller::SetInputEmbossProperties(const std::string& embossProperties)
1017 {
1018   InputProperties::SetInputEmbossProperties(*this, embossProperties);
1019 }
1020
1021 const std::string& Controller::GetInputEmbossProperties() const
1022 {
1023   return InputProperties::GetInputEmbossProperties(*this);
1024 }
1025
1026 void Controller::SetInputOutlineProperties(const std::string& outlineProperties)
1027 {
1028   InputProperties::SetInputOutlineProperties(*this, outlineProperties);
1029 }
1030
1031 const std::string& Controller::GetInputOutlineProperties() const
1032 {
1033   return InputProperties::GetInputOutlineProperties(*this);
1034 }
1035
1036 void Controller::SetInputModePassword(bool passwordInput)
1037 {
1038   InputProperties::SetInputModePassword(*this, passwordInput);
1039 }
1040
1041 bool Controller::IsInputModePassword()
1042 {
1043   return InputProperties::IsInputModePassword(*this);
1044 }
1045
1046 void Controller::SetNoTextDoubleTapAction(NoTextTap::Action action)
1047 {
1048   if(mImpl->mEventData)
1049   {
1050     mImpl->mEventData->mDoubleTapAction = action;
1051   }
1052 }
1053
1054 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1055 {
1056   return mImpl->mEventData ? mImpl->mEventData->mDoubleTapAction : NoTextTap::NO_ACTION;
1057 }
1058
1059 void Controller::SetNoTextLongPressAction(NoTextTap::Action action)
1060 {
1061   if(mImpl->mEventData)
1062   {
1063     mImpl->mEventData->mLongPressAction = action;
1064   }
1065 }
1066
1067 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1068 {
1069   return mImpl->mEventData ? mImpl->mEventData->mLongPressAction : NoTextTap::NO_ACTION;
1070 }
1071
1072 bool Controller::IsUnderlineSetByString()
1073 {
1074   return mImpl->mUnderlineSetByString;
1075 }
1076
1077 void Controller::UnderlineSetByString(bool setByString)
1078 {
1079   mImpl->mUnderlineSetByString = setByString;
1080 }
1081
1082 bool Controller::IsShadowSetByString()
1083 {
1084   return mImpl->mShadowSetByString;
1085 }
1086
1087 void Controller::ShadowSetByString(bool setByString)
1088 {
1089   mImpl->mShadowSetByString = setByString;
1090 }
1091
1092 bool Controller::IsOutlineSetByString()
1093 {
1094   return mImpl->mOutlineSetByString;
1095 }
1096
1097 void Controller::OutlineSetByString(bool setByString)
1098 {
1099   mImpl->mOutlineSetByString = setByString;
1100 }
1101
1102 bool Controller::IsFontStyleSetByString()
1103 {
1104   return mImpl->mFontStyleSetByString;
1105 }
1106
1107 void Controller::FontStyleSetByString(bool setByString)
1108 {
1109   mImpl->mFontStyleSetByString = setByString;
1110 }
1111
1112 Layout::Engine& Controller::GetLayoutEngine()
1113 {
1114   return mImpl->mLayoutEngine;
1115 }
1116
1117 View& Controller::GetView()
1118 {
1119   return mImpl->mView;
1120 }
1121
1122 Vector3 Controller::GetNaturalSize()
1123 {
1124   return Relayouter::GetNaturalSize(*this);
1125 }
1126
1127 bool Controller::CheckForTextFit(float pointSize, Size& layoutSize)
1128 {
1129   return Relayouter::CheckForTextFit(*this, pointSize, layoutSize);
1130 }
1131
1132 void Controller::FitPointSizeforLayout(Size layoutSize)
1133 {
1134   Relayouter::FitPointSizeforLayout(*this, layoutSize);
1135 }
1136
1137 float Controller::GetHeightForWidth(float width)
1138 {
1139   return Relayouter::GetHeightForWidth(*this, width);
1140 }
1141
1142 int Controller::GetLineCount(float width)
1143 {
1144   GetHeightForWidth(width);
1145   return mImpl->mModel->GetNumberOfLines();
1146 }
1147
1148 const ModelInterface* const Controller::GetTextModel() const
1149 {
1150   return mImpl->mModel.Get();
1151 }
1152
1153 float Controller::GetScrollAmountByUserInput()
1154 {
1155   float scrollAmount = 0.0f;
1156
1157   if(NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1158   {
1159     scrollAmount                          = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1160     mImpl->mEventData->mCheckScrollAmount = false;
1161   }
1162   return scrollAmount;
1163 }
1164
1165 bool Controller::GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight)
1166 {
1167   const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1168   bool           isScrolled;
1169
1170   controlHeight  = mImpl->mModel->mVisualModel->mControlSize.height;
1171   layoutHeight   = layout.height;
1172   scrollPosition = mImpl->mModel->mScrollPosition.y;
1173   isScrolled     = !Equals(mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1);
1174   return isScrolled;
1175 }
1176
1177 void Controller::SetHiddenInputOption(const Property::Map& options)
1178 {
1179   EnsureCreated<HiddenText, Controller*>(mImpl->mHiddenInput, this);
1180   mImpl->mHiddenInput->SetProperties(options);
1181 }
1182
1183 void Controller::GetHiddenInputOption(Property::Map& options)
1184 {
1185   if(mImpl->mHiddenInput)
1186   {
1187     mImpl->mHiddenInput->GetProperties(options);
1188   }
1189 }
1190
1191 void Controller::SetInputFilterOption(const Property::Map& options)
1192 {
1193   EnsureCreated(mImpl->mInputFilter);
1194   mImpl->mInputFilter->SetProperties(options);
1195 }
1196
1197 void Controller::GetInputFilterOption(Property::Map& options)
1198 {
1199   if(mImpl->mInputFilter)
1200   {
1201     mImpl->mInputFilter->GetProperties(options);
1202   }
1203 }
1204
1205 void Controller::SetPlaceholderProperty(const Property::Map& map)
1206 {
1207   PlaceholderHandler::SetPlaceholderProperty(*this, map);
1208 }
1209
1210 void Controller::GetPlaceholderProperty(Property::Map& map)
1211 {
1212   PlaceholderHandler::GetPlaceholderProperty(*this, map);
1213 }
1214
1215 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1216 {
1217   // Make sure the model is up-to-date before layouting
1218   ProcessModifyEvents();
1219
1220   if(mImpl->mUpdateTextDirection)
1221   {
1222     // Operations that can be done only once until the text changes.
1223     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>(CONVERT_TO_UTF32 |
1224                                                                           GET_SCRIPTS |
1225                                                                           VALIDATE_FONTS |
1226                                                                           GET_LINE_BREAKS |
1227                                                                           BIDI_INFO |
1228                                                                           SHAPE_TEXT |
1229                                                                           GET_GLYPH_METRICS);
1230
1231     // Set the update info to relayout the whole text.
1232     mImpl->mTextUpdateInfo.mParagraphCharacterIndex     = 0u;
1233     mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1234
1235     // Make sure the model is up-to-date before layouting
1236     mImpl->UpdateModel(onlyOnceOperations);
1237
1238     Vector3 naturalSize;
1239     DoRelayout(Size(MAX_FLOAT, MAX_FLOAT),
1240                static_cast<OperationsMask>(onlyOnceOperations |
1241                                            LAYOUT | REORDER | UPDATE_DIRECTION),
1242                naturalSize.GetVectorXY());
1243
1244     // Do not do again the only once operations.
1245     mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending & ~onlyOnceOperations);
1246
1247     // Clear the update info. This info will be set the next time the text is updated.
1248     mImpl->mTextUpdateInfo.Clear();
1249
1250     // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1251     mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1252
1253     mImpl->mUpdateTextDirection = false;
1254   }
1255
1256   return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1257 }
1258
1259 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1260 {
1261   return mImpl->mModel->GetVerticalLineAlignment();
1262 }
1263
1264 void Controller::SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment)
1265 {
1266   mImpl->mModel->mVerticalLineAlignment = alignment;
1267 }
1268
1269 Toolkit::DevelText::EllipsisPosition::Type Controller::GetEllipsisPosition() const
1270 {
1271   return mImpl->mModel->GetEllipsisPosition();
1272 }
1273
1274 void Controller::SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition)
1275 {
1276   mImpl->mModel->mEllipsisPosition = ellipsisPosition;
1277   mImpl->mModel->mVisualModel->SetEllipsisPosition(ellipsisPosition);
1278 }
1279
1280 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
1281 {
1282   return Relayouter::Relayout(*this, size, layoutDirection);
1283 }
1284
1285 void Controller::RequestRelayout()
1286 {
1287   mImpl->RequestRelayout();
1288 }
1289
1290 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1291 {
1292   return mImpl->IsInputStyleChangedSignalsQueueEmpty();
1293 }
1294
1295 void Controller::ProcessInputStyleChangedSignals()
1296 {
1297   mImpl->ProcessInputStyleChangedSignals();
1298 }
1299
1300 void Controller::KeyboardFocusGainEvent()
1301 {
1302   EventHandler::KeyboardFocusGainEvent(*this);
1303 }
1304
1305 void Controller::KeyboardFocusLostEvent()
1306 {
1307   EventHandler::KeyboardFocusLostEvent(*this);
1308 }
1309
1310 bool Controller::KeyEvent(const Dali::KeyEvent& keyEvent)
1311 {
1312   return EventHandler::KeyEvent(*this, keyEvent);
1313 }
1314
1315 void Controller::AnchorEvent(float x, float y)
1316 {
1317   EventHandler::AnchorEvent(*this, x, y);
1318 }
1319
1320 void Controller::TapEvent(unsigned int tapCount, float x, float y)
1321 {
1322   EventHandler::TapEvent(*this, tapCount, x, y);
1323 }
1324
1325 void Controller::PanEvent(GestureState state, const Vector2& displacement)
1326 {
1327   EventHandler::PanEvent(*this, state, displacement);
1328 }
1329
1330 void Controller::LongPressEvent(GestureState state, float x, float y)
1331 {
1332   EventHandler::LongPressEvent(*this, state, x, y);
1333 }
1334
1335 void Controller::SelectEvent(float x, float y, SelectionType selectType)
1336 {
1337   EventHandler::SelectEvent(*this, x, y, selectType);
1338 }
1339
1340 void Controller::SelectEvent(const uint32_t start, const uint32_t end, SelectionType selectType)
1341 {
1342   EventHandler::SelectEvent(*this, start, end, selectType);
1343 }
1344
1345 void Controller::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1346 {
1347   if(mImpl->mEventData)
1348   {
1349     mImpl->mEventData->mCheckScrollAmount     = true;
1350     mImpl->mEventData->mIsLeftHandleSelected  = true;
1351     mImpl->mEventData->mIsRightHandleSelected = true;
1352     mImpl->SetTextSelectionRange(start, end);
1353     mImpl->RequestRelayout();
1354     KeyboardFocusGainEvent();
1355   }
1356 }
1357
1358 Uint32Pair Controller::GetTextSelectionRange() const
1359 {
1360   return mImpl->GetTextSelectionRange();
1361 }
1362
1363 CharacterIndex Controller::GetPrimaryCursorPosition() const
1364 {
1365   return mImpl->GetPrimaryCursorPosition();
1366 }
1367
1368 bool Controller::SetPrimaryCursorPosition(CharacterIndex index, bool focused)
1369 {
1370   if(mImpl->mEventData)
1371   {
1372     mImpl->mEventData->mCheckScrollAmount     = true;
1373     mImpl->mEventData->mIsLeftHandleSelected  = true;
1374     mImpl->mEventData->mIsRightHandleSelected = true;
1375     mImpl->mEventData->mCheckScrollAmount     = true;
1376     if(mImpl->SetPrimaryCursorPosition(index, focused) && focused)
1377     {
1378       KeyboardFocusGainEvent();
1379       return true;
1380     }
1381   }
1382   return false;
1383 }
1384
1385 void Controller::SelectWholeText()
1386 {
1387   SelectEvent(0.f, 0.f, SelectionType::ALL);
1388 }
1389
1390 void Controller::SelectNone()
1391 {
1392   SelectEvent(0.f, 0.f, SelectionType::NONE);
1393 }
1394
1395 void Controller::SelectText(const uint32_t start, const uint32_t end)
1396 {
1397   SelectEvent(start, end, SelectionType::RANGE);
1398 }
1399
1400 string Controller::GetSelectedText() const
1401 {
1402   string text;
1403   if(EventData::SELECTING == mImpl->mEventData->mState)
1404   {
1405     mImpl->RetrieveSelection(text, false);
1406   }
1407   return text;
1408 }
1409
1410 string Controller::CopyText()
1411 {
1412   string text;
1413   mImpl->RetrieveSelection(text, false);
1414   mImpl->SendSelectionToClipboard(false); // Text not modified
1415
1416   mImpl->mEventData->mUpdateCursorPosition = true;
1417
1418   mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
1419
1420   return text;
1421 }
1422
1423 string Controller::CutText()
1424 {
1425   string text;
1426   mImpl->RetrieveSelection(text, false);
1427
1428   if(!IsEditable())
1429   {
1430     return EMPTY_STRING;
1431   }
1432
1433   mImpl->SendSelectionToClipboard(true); // Synchronous call to modify text
1434   mImpl->mOperationsPending = ALL_OPERATIONS;
1435
1436   if((0u != mImpl->mModel->mLogicalModel->mText.Count()) ||
1437      !mImpl->IsPlaceholderAvailable())
1438   {
1439     mImpl->QueueModifyEvent(ModifyEvent::TEXT_DELETED);
1440   }
1441   else
1442   {
1443     ShowPlaceholderText();
1444   }
1445
1446   mImpl->mEventData->mUpdateCursorPosition = true;
1447   mImpl->mEventData->mScrollAfterDelete    = true;
1448
1449   mImpl->RequestRelayout();
1450
1451   if(nullptr != mImpl->mEditableControlInterface)
1452   {
1453     mImpl->mEditableControlInterface->TextChanged(true);
1454   }
1455   return text;
1456 }
1457
1458 void Controller::PasteText()
1459 {
1460   mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
1461 }
1462
1463 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1464 {
1465   return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
1466 }
1467
1468 void Controller::PasteClipboardItemEvent()
1469 {
1470   EventHandler::PasteClipboardItemEvent(*this);
1471 }
1472
1473 void Controller::GetTargetSize(Vector2& targetSize)
1474 {
1475   targetSize = mImpl->mModel->mVisualModel->mControlSize;
1476 }
1477
1478 void Controller::AddDecoration(Actor& actor, bool needsClipping)
1479 {
1480   if(mImpl->mEditableControlInterface)
1481   {
1482     mImpl->mEditableControlInterface->AddDecoration(actor, needsClipping);
1483   }
1484 }
1485
1486 bool Controller::IsEditable() const
1487 {
1488   return mImpl->IsEditable();
1489 }
1490
1491 void Controller::SetEditable(bool editable)
1492 {
1493   mImpl->SetEditable(editable);
1494 }
1495
1496 void Controller::ScrollBy(Vector2 scroll)
1497 {
1498   mImpl->ScrollBy(scroll);
1499 }
1500
1501 float Controller::GetHorizontalScrollPosition()
1502 {
1503   return mImpl->GetHorizontalScrollPosition();
1504 }
1505
1506 float Controller::GetVerticalScrollPosition()
1507 {
1508   return mImpl->GetVerticalScrollPosition();
1509 }
1510
1511 void Controller::DecorationEvent(HandleType handleType, HandleState state, float x, float y)
1512 {
1513   EventHandler::DecorationEvent(*this, handleType, state, x, y);
1514 }
1515
1516 void Controller::TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button)
1517 {
1518   EventHandler::TextPopupButtonTouched(*this, button);
1519 }
1520
1521 void Controller::DisplayTimeExpired()
1522 {
1523   mImpl->mEventData->mUpdateCursorPosition = true;
1524   // Apply modifications to the model
1525   mImpl->mOperationsPending = ALL_OPERATIONS;
1526
1527   mImpl->RequestRelayout();
1528 }
1529
1530 void Controller::InsertText(const std::string& text, Controller::InsertType type)
1531 {
1532   TextUpdater::InsertText(*this, text, type);
1533 }
1534
1535 void Controller::PasteText(const std::string& stringToPaste)
1536 {
1537   TextUpdater::PasteText(*this, stringToPaste);
1538 }
1539
1540 bool Controller::RemoveText(int cursorOffset, int numberOfCharacters, UpdateInputStyleType type)
1541 {
1542   return TextUpdater::RemoveText(*this, cursorOffset, numberOfCharacters, type);
1543 }
1544
1545 bool Controller::RemoveSelectedText()
1546 {
1547   return TextUpdater::RemoveSelectedText(*this);
1548 }
1549
1550 void Controller::InsertTextAnchor(int numberOfCharacters, CharacterIndex previousCursorIndex)
1551 {
1552   TextUpdater::InsertTextAnchor(*this, numberOfCharacters, previousCursorIndex);
1553 }
1554
1555 void Controller::RemoveTextAnchor(int cursorOffset, int numberOfCharacters, CharacterIndex previousCursorIndex)
1556 {
1557   TextUpdater::RemoveTextAnchor(*this, cursorOffset, numberOfCharacters, previousCursorIndex);
1558 }
1559
1560 bool Controller::DoRelayout(const Size& size, OperationsMask operationsRequired, Size& layoutSize)
1561 {
1562   return Relayouter::DoRelayout(*this, size, operationsRequired, layoutSize);
1563 }
1564
1565 void Controller::CalculateVerticalOffset(const Size& controlSize)
1566 {
1567   Relayouter::CalculateVerticalOffset(*this, controlSize);
1568 }
1569
1570 void Controller::ProcessModifyEvents()
1571 {
1572   EventHandler::ProcessModifyEvents(*this);
1573 }
1574
1575 void Controller::TextReplacedEvent()
1576 {
1577   EventHandler::TextReplacedEvent(*this);
1578 }
1579
1580 void Controller::TextInsertedEvent()
1581 {
1582   EventHandler::TextInsertedEvent(*this);
1583 }
1584
1585 void Controller::TextDeletedEvent()
1586 {
1587   EventHandler::TextDeletedEvent(*this);
1588 }
1589
1590 bool Controller::DeleteEvent(int keyCode)
1591 {
1592   return EventHandler::DeleteEvent(*this, keyCode);
1593 }
1594
1595 // private : Helpers.
1596
1597 void Controller::ResetText()
1598 {
1599   TextUpdater::ResetText(*this);
1600 }
1601
1602 void Controller::ShowPlaceholderText()
1603 {
1604   PlaceholderHandler::ShowPlaceholderText(*this);
1605 }
1606
1607 void Controller::ResetCursorPosition(CharacterIndex cursorIndex)
1608 {
1609   // Reset the cursor position
1610   if(NULL != mImpl->mEventData)
1611   {
1612     mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
1613
1614     // Update the cursor if it's in editing mode.
1615     if(EventData::IsEditingState(mImpl->mEventData->mState))
1616     {
1617       mImpl->mEventData->mUpdateCursorPosition = true;
1618     }
1619   }
1620 }
1621
1622 CharacterIndex Controller::GetCursorPosition()
1623 {
1624   return mImpl->mEventData ? mImpl->mEventData->mPrimaryCursorPosition : 0;
1625 }
1626
1627 void Controller::SetControlInterface(ControlInterface* controlInterface)
1628 {
1629   mImpl->mControlInterface = controlInterface;
1630 }
1631
1632 void Controller::SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface)
1633 {
1634   mImpl->mAnchorControlInterface = anchorControlInterface;
1635 }
1636
1637 bool Controller::ShouldClearFocusOnEscape() const
1638 {
1639   return mImpl->mShouldClearFocusOnEscape;
1640 }
1641
1642 Actor Controller::CreateBackgroundActor()
1643 {
1644   return mImpl->CreateBackgroundActor();
1645 }
1646
1647 void Controller::GetAnchorActors(std::vector<Toolkit::TextAnchor>& anchorActors)
1648 {
1649   mImpl->GetAnchorActors(anchorActors);
1650 }
1651
1652 int Controller::GetAnchorIndex(size_t characterOffset)
1653 {
1654   return mImpl->GetAnchorIndex(characterOffset);
1655 }
1656
1657 Controller::Controller(ControlInterface*           controlInterface,
1658                        EditableControlInterface*   editableControlInterface,
1659                        SelectableControlInterface* selectableControlInterface,
1660                        AnchorControlInterface*     anchorControlInterface)
1661 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface, anchorControlInterface))
1662 {
1663 }
1664
1665 Controller::~Controller()
1666 {
1667   delete mImpl;
1668 }
1669
1670 } // namespace Dali::Toolkit::Text