fee1690e6295bcf6c59c375b5fd1fdc3598f6a3a
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
1 /*
2  * Copyright (c) 2019 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 <limits>
23 #include <cmath>
24 #include <memory.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
29 #include <dali/devel-api/adaptor-framework/key-devel.h>
30
31 // INTERNAL INCLUDES
32 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
33 #include <dali-toolkit/internal/text/bidirectional-support.h>
34 #include <dali-toolkit/internal/text/character-set-conversion.h>
35 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
36 #include <dali-toolkit/internal/text/markup-processor.h>
37 #include <dali-toolkit/internal/text/multi-language-support.h>
38 #include <dali-toolkit/internal/text/text-controller-impl.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-font-style.h>
41
42 namespace
43 {
44
45 #if defined(DEBUG_ENABLED)
46   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
47 #endif
48
49 const float MAX_FLOAT = std::numeric_limits<float>::max();
50
51 const std::string EMPTY_STRING("");
52
53 const std::string KEY_C_NAME = "c";
54 const std::string KEY_V_NAME = "v";
55 const std::string KEY_X_NAME = "x";
56
57 const char * const PLACEHOLDER_TEXT = "text";
58 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
59 const char * const PLACEHOLDER_COLOR = "color";
60 const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
61 const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
62 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
63 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
64 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
65 const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
66
67 float ConvertToEven( float value )
68 {
69   int intValue(static_cast<int>( value ));
70   return static_cast<float>( intValue + ( intValue & 1 ) );
71 }
72
73 int ConvertPixelToPint( float pixel )
74 {
75   unsigned int horizontalDpi = 0u;
76   unsigned int verticalDpi = 0u;
77   Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
78   fontClient.GetDpi( horizontalDpi, verticalDpi );
79
80   return ( pixel * 72.f ) / static_cast< float >( horizontalDpi );
81 }
82
83
84 } // namespace
85
86 namespace Dali
87 {
88
89 namespace Toolkit
90 {
91
92 namespace Text
93 {
94
95 /**
96  * @brief Adds a new font description run for the selected text.
97  *
98  * The new font parameters are added after the call to this method.
99  *
100  * @param[in] eventData The event data pointer.
101  * @param[in] logicalModel The logical model where to add the new font description run.
102  * @param[out] startOfSelectedText Index to the first selected character.
103  * @param[out] lengthOfSelectedText Number of selected characters.
104  */
105 FontDescriptionRun& UpdateSelectionFontStyleRun( EventData* eventData,
106                                                  LogicalModelPtr logicalModel,
107                                                  CharacterIndex& startOfSelectedText,
108                                                  Length& lengthOfSelectedText )
109 {
110   const bool handlesCrossed = eventData->mLeftSelectionPosition > eventData->mRightSelectionPosition;
111
112   // Get start and end position of selection
113   startOfSelectedText = handlesCrossed ? eventData->mRightSelectionPosition : eventData->mLeftSelectionPosition;
114   lengthOfSelectedText = ( handlesCrossed ? eventData->mLeftSelectionPosition : eventData->mRightSelectionPosition ) - startOfSelectedText;
115
116   // Add the font run.
117   const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
118   logicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
119
120   FontDescriptionRun& fontDescriptionRun = *( logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
121
122   fontDescriptionRun.characterRun.characterIndex = startOfSelectedText;
123   fontDescriptionRun.characterRun.numberOfCharacters = lengthOfSelectedText;
124
125   // Recalculate the selection highlight as the metrics may have changed.
126   eventData->mUpdateLeftSelectionPosition = true;
127   eventData->mUpdateRightSelectionPosition = true;
128   eventData->mUpdateHighlightBox = true;
129
130   return fontDescriptionRun;
131 }
132
133 // public : Constructor.
134
135 ControllerPtr Controller::New()
136 {
137   return ControllerPtr( new Controller() );
138 }
139
140 ControllerPtr Controller::New( ControlInterface* controlInterface )
141 {
142   return ControllerPtr( new Controller( controlInterface ) );
143 }
144
145 ControllerPtr Controller::New( ControlInterface* controlInterface,
146                                EditableControlInterface* editableControlInterface )
147 {
148   return ControllerPtr( new Controller( controlInterface,
149                                         editableControlInterface ) );
150 }
151
152 // public : Configure the text controller.
153
154 void Controller::EnableTextInput( DecoratorPtr decorator, InputMethodContext& inputMethodContext )
155 {
156   if( !decorator )
157   {
158     delete mImpl->mEventData;
159     mImpl->mEventData = NULL;
160
161     // Nothing else to do.
162     return;
163   }
164
165   if( NULL == mImpl->mEventData )
166   {
167     mImpl->mEventData = new EventData( decorator, inputMethodContext );
168   }
169 }
170
171 void Controller::SetGlyphType( TextAbstraction::GlyphType glyphType )
172 {
173   // Metrics for bitmap & vector based glyphs are different
174   mImpl->mMetrics->SetGlyphType( glyphType );
175
176   // Clear the font-specific data
177   ClearFontData();
178
179   mImpl->RequestRelayout();
180 }
181
182 void Controller::SetMarkupProcessorEnabled( bool enable )
183 {
184   if( enable != mImpl->mMarkupProcessorEnabled )
185   {
186     //If Text was already set, call the SetText again for enabling or disabling markup
187     mImpl->mMarkupProcessorEnabled = enable;
188     std::string text;
189     GetText( text );
190     SetText( text );
191   }
192 }
193
194 bool Controller::IsMarkupProcessorEnabled() const
195 {
196   return mImpl->mMarkupProcessorEnabled;
197 }
198
199 void Controller::SetAutoScrollEnabled( bool enable )
200 {
201   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 );
202
203   if( mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX )
204   {
205     if( enable )
206     {
207       DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n" );
208       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
209                                                                LAYOUT                    |
210                                                                ALIGN                     |
211                                                                UPDATE_LAYOUT_SIZE        |
212                                                                UPDATE_DIRECTION          |
213                                                                REORDER );
214
215     }
216     else
217     {
218       DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
219       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
220                                                                LAYOUT                    |
221                                                                ALIGN                     |
222                                                                UPDATE_LAYOUT_SIZE        |
223                                                                REORDER );
224     }
225
226     mImpl->mIsAutoScrollEnabled = enable;
227     mImpl->RequestRelayout();
228   }
229   else
230   {
231     DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" );
232     mImpl->mIsAutoScrollEnabled = false;
233   }
234 }
235
236 bool Controller::IsAutoScrollEnabled() const
237 {
238   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled?"true":"false" );
239
240   return mImpl->mIsAutoScrollEnabled;
241 }
242
243 CharacterDirection Controller::GetAutoScrollDirection() const
244 {
245   return mImpl->mIsTextDirectionRTL;
246 }
247
248 float Controller::GetAutoScrollLineAlignment() const
249 {
250   float offset = 0.f;
251
252   if( mImpl->mModel->mVisualModel &&
253       ( 0u != mImpl->mModel->mVisualModel->mLines.Count() ) )
254   {
255     offset = ( *mImpl->mModel->mVisualModel->mLines.Begin() ).alignmentOffset;
256   }
257
258   return offset;
259 }
260
261 void Controller::SetHorizontalScrollEnabled( bool enable )
262 {
263   if( ( NULL != mImpl->mEventData ) &&
264       mImpl->mEventData->mDecorator )
265   {
266     mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
267   }
268 }
269 bool Controller::IsHorizontalScrollEnabled() const
270 {
271   if( ( NULL != mImpl->mEventData ) &&
272       mImpl->mEventData->mDecorator )
273   {
274     return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
275   }
276
277   return false;
278 }
279
280 void Controller::SetVerticalScrollEnabled( bool enable )
281 {
282   if( ( NULL != mImpl->mEventData ) &&
283       mImpl->mEventData->mDecorator )
284   {
285     if( mImpl->mEventData->mDecorator )
286     {
287       mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
288     }
289   }
290 }
291
292 bool Controller::IsVerticalScrollEnabled() const
293 {
294   if( ( NULL != mImpl->mEventData ) &&
295       mImpl->mEventData->mDecorator )
296   {
297     return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
298   }
299
300   return false;
301 }
302
303 void Controller::SetSmoothHandlePanEnabled( bool enable )
304 {
305   if( ( NULL != mImpl->mEventData ) &&
306       mImpl->mEventData->mDecorator )
307   {
308     mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
309   }
310 }
311
312 bool Controller::IsSmoothHandlePanEnabled() const
313 {
314   if( ( NULL != mImpl->mEventData ) &&
315       mImpl->mEventData->mDecorator )
316   {
317     return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
318   }
319
320   return false;
321 }
322
323 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
324 {
325   mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
326 }
327
328 int Controller::GetMaximumNumberOfCharacters()
329 {
330   return mImpl->mMaximumNumberOfCharacters;
331 }
332
333 void Controller::SetEnableCursorBlink( bool enable )
334 {
335   DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
336
337   if( NULL != mImpl->mEventData )
338   {
339     mImpl->mEventData->mCursorBlinkEnabled = enable;
340
341     if( !enable &&
342         mImpl->mEventData->mDecorator )
343     {
344       mImpl->mEventData->mDecorator->StopCursorBlink();
345     }
346   }
347 }
348
349 bool Controller::GetEnableCursorBlink() const
350 {
351   if( NULL != mImpl->mEventData )
352   {
353     return mImpl->mEventData->mCursorBlinkEnabled;
354   }
355
356   return false;
357 }
358
359 void Controller::SetMultiLineEnabled( bool enable )
360 {
361   const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
362
363   if( layout != mImpl->mLayoutEngine.GetLayout() )
364   {
365     // Set the layout type.
366     mImpl->mLayoutEngine.SetLayout( layout );
367
368     // Set the flags to redo the layout operations
369     const OperationsMask layoutOperations =  static_cast<OperationsMask>( LAYOUT             |
370                                                                           UPDATE_LAYOUT_SIZE |
371                                                                           ALIGN              |
372                                                                           REORDER );
373
374     mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
375     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | layoutOperations );
376
377     // Need to recalculate natural size
378     mImpl->mRecalculateNaturalSize = true;
379
380     mImpl->RequestRelayout();
381   }
382 }
383
384 bool Controller::IsMultiLineEnabled() const
385 {
386   return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
387 }
388
389 void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
390 {
391   if( alignment != mImpl->mModel->mHorizontalAlignment )
392   {
393     // Set the alignment.
394     mImpl->mModel->mHorizontalAlignment = alignment;
395
396     // Set the flag to redo the alignment operation.
397     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
398
399     mImpl->RequestRelayout();
400   }
401 }
402
403 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
404 {
405   return mImpl->mModel->mHorizontalAlignment;
406 }
407
408 void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
409 {
410   if( alignment != mImpl->mModel->mVerticalAlignment )
411   {
412     // Set the alignment.
413     mImpl->mModel->mVerticalAlignment = alignment;
414
415     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | ALIGN );
416
417     mImpl->RequestRelayout();
418   }
419 }
420
421 VerticalAlignment::Type Controller::GetVerticalAlignment() const
422 {
423   return mImpl->mModel->mVerticalAlignment;
424 }
425
426 bool Controller::IsIgnoreSpacesAfterText() const
427 {
428   return mImpl->mModel->mIgnoreSpacesAfterText;
429 }
430
431 void Controller::SetIgnoreSpacesAfterText( bool ignore )
432 {
433   mImpl->mModel->mIgnoreSpacesAfterText = ignore;
434 }
435
436 bool Controller::IsMatchSystemLanguageDirection() const
437 {
438   return mImpl->mModel->mMatchSystemLanguageDirection;
439 }
440
441 void Controller::SetMatchSystemLanguageDirection( bool match )
442 {
443   mImpl->mModel->mMatchSystemLanguageDirection = match;
444 }
445
446 void Controller::SetLayoutDirection( Dali::LayoutDirection::Type layoutDirection )
447 {
448   mImpl->mLayoutDirection = layoutDirection;
449 }
450
451 bool Controller::IsShowingRealText() const
452 {
453   return mImpl->IsShowingRealText();
454 }
455
456
457 void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
458 {
459   if( lineWrapMode != mImpl->mModel->mLineWrapMode )
460   {
461     // Set the text wrap mode.
462     mImpl->mModel->mLineWrapMode = lineWrapMode;
463
464
465     // Update Text layout for applying wrap mode
466     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
467                                                              ALIGN                     |
468                                                              LAYOUT                    |
469                                                              UPDATE_LAYOUT_SIZE        |
470                                                              REORDER                   );
471     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
472     mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
473     mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
474
475     // Request relayout
476     mImpl->RequestRelayout();
477   }
478 }
479
480 Text::LineWrap::Mode Controller::GetLineWrapMode() const
481 {
482   return mImpl->mModel->mLineWrapMode;
483 }
484
485 void Controller::SetTextElideEnabled( bool enabled )
486 {
487   mImpl->mModel->mElideEnabled = enabled;
488 }
489
490 bool Controller::IsTextElideEnabled() const
491 {
492   return mImpl->mModel->mElideEnabled;
493 }
494
495 void Controller::SetTextFitEnabled(bool enabled)
496 {
497   mImpl->mTextFitEnabled = enabled;
498 }
499
500 bool Controller::IsTextFitEnabled() const
501 {
502   return mImpl->mTextFitEnabled;
503 }
504
505 void Controller::SetTextFitMinSize( float minSize, FontSizeType type )
506 {
507   switch( type )
508   {
509     case POINT_SIZE:
510     {
511       mImpl->mTextFitMinSize = minSize;
512       break;
513     }
514     case PIXEL_SIZE:
515     {
516       mImpl->mTextFitMinSize = ConvertPixelToPint( minSize );
517       break;
518     }
519   }
520 }
521
522 float Controller::GetTextFitMinSize() const
523 {
524   return mImpl->mTextFitMinSize;
525 }
526
527 void Controller::SetTextFitMaxSize( float maxSize, FontSizeType type )
528 {
529   switch( type )
530   {
531     case POINT_SIZE:
532     {
533       mImpl->mTextFitMaxSize = maxSize;
534       break;
535     }
536     case PIXEL_SIZE:
537     {
538       mImpl->mTextFitMaxSize = ConvertPixelToPint( maxSize );
539       break;
540     }
541   }
542 }
543
544 float Controller::GetTextFitMaxSize() const
545 {
546   return mImpl->mTextFitMaxSize;
547 }
548
549 void Controller::SetTextFitStepSize( float step, FontSizeType type )
550 {
551   switch( type )
552   {
553     case POINT_SIZE:
554     {
555       mImpl->mTextFitStepSize = step;
556       break;
557     }
558     case PIXEL_SIZE:
559     {
560       mImpl->mTextFitStepSize = ConvertPixelToPint( step );
561       break;
562     }
563   }
564 }
565
566 float Controller::GetTextFitStepSize() const
567 {
568   return mImpl->mTextFitStepSize;
569 }
570
571 void Controller::SetTextFitContentSize(Vector2 size)
572 {
573   mImpl->mTextFitContentSize = size;
574 }
575
576 Vector2 Controller::GetTextFitContentSize() const
577 {
578   return mImpl->mTextFitContentSize;
579 }
580
581 void Controller::SetPlaceholderTextElideEnabled( bool enabled )
582 {
583   mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
584   mImpl->mEventData->mPlaceholderEllipsisFlag = true;
585
586   // Update placeholder if there is no text
587   if( mImpl->IsShowingPlaceholderText() ||
588       ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
589   {
590     ShowPlaceholderText();
591   }
592 }
593
594 bool Controller::IsPlaceholderTextElideEnabled() const
595 {
596   return mImpl->mEventData->mIsPlaceholderElideEnabled;
597 }
598
599 void Controller::SetSelectionEnabled( bool enabled )
600 {
601   mImpl->mEventData->mSelectionEnabled = enabled;
602 }
603
604 bool Controller::IsSelectionEnabled() const
605 {
606   return mImpl->mEventData->mSelectionEnabled;
607 }
608
609 void Controller::SetShiftSelectionEnabled( bool enabled )
610 {
611   mImpl->mEventData->mShiftSelectionFlag = enabled;
612 }
613
614 bool Controller::IsShiftSelectionEnabled() const
615 {
616   return mImpl->mEventData->mShiftSelectionFlag;
617 }
618
619 void Controller::SetGrabHandleEnabled( bool enabled )
620 {
621   mImpl->mEventData->mGrabHandleEnabled = enabled;
622 }
623
624 bool Controller::IsGrabHandleEnabled() const
625 {
626   return mImpl->mEventData->mGrabHandleEnabled;
627 }
628
629 void Controller::SetGrabHandlePopupEnabled(bool enabled)
630 {
631   mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
632 }
633
634 bool Controller::IsGrabHandlePopupEnabled() const
635 {
636   return mImpl->mEventData->mGrabHandlePopupEnabled;
637 }
638
639 // public : Update
640
641 void Controller::SetText( const std::string& text )
642 {
643   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
644
645   // Reset keyboard as text changed
646   mImpl->ResetInputMethodContext();
647
648   // Remove the previously set text and style.
649   ResetText();
650
651   // Remove the style.
652   ClearStyleData();
653
654   CharacterIndex lastCursorIndex = 0u;
655
656   if( NULL != mImpl->mEventData )
657   {
658     // If popup shown then hide it by switching to Editing state
659     if( ( EventData::SELECTING == mImpl->mEventData->mState )          ||
660         ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
661         ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
662         ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
663     {
664       mImpl->ChangeState( EventData::EDITING );
665     }
666   }
667
668   if( !text.empty() )
669   {
670     mImpl->mModel->mVisualModel->SetTextColor( mImpl->mTextColor );
671
672     MarkupProcessData markupProcessData( mImpl->mModel->mLogicalModel->mColorRuns,
673                                          mImpl->mModel->mLogicalModel->mFontDescriptionRuns,
674                                          mImpl->mModel->mLogicalModel->mEmbeddedItems );
675
676     Length textSize = 0u;
677     const uint8_t* utf8 = NULL;
678     if( mImpl->mMarkupProcessorEnabled )
679     {
680       ProcessMarkupString( text, markupProcessData );
681       textSize = markupProcessData.markupProcessedText.size();
682
683       // This is a bit horrible but std::string returns a (signed) char*
684       utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
685     }
686     else
687     {
688       textSize = text.size();
689
690       // This is a bit horrible but std::string returns a (signed) char*
691       utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
692     }
693
694     // Limit the text size. If the text size is too large, crash or deadlock will occur.
695     if( textSize > MAX_TEXT_LENGTH )
696     {
697       DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
698       textSize = MAX_TEXT_LENGTH;
699     }
700
701     //  Convert text into UTF-32
702     Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
703     utf32Characters.Resize( textSize );
704
705     // Transform a text array encoded in utf8 into an array encoded in utf32.
706     // It returns the actual number of characters.
707     Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
708     utf32Characters.Resize( characterCount );
709
710     DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
711     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mModel->mLogicalModel->mText.Count() );
712
713     // The characters to be added.
714     mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
715
716     // To reset the cursor position
717     lastCursorIndex = characterCount;
718
719     // Update the rest of the model during size negotiation
720     mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
721
722     // The natural size needs to be re-calculated.
723     mImpl->mRecalculateNaturalSize = true;
724
725     // The text direction needs to be updated.
726     mImpl->mUpdateTextDirection = true;
727
728     // Apply modifications to the model
729     mImpl->mOperationsPending = ALL_OPERATIONS;
730   }
731   else
732   {
733     ShowPlaceholderText();
734   }
735
736   // Resets the cursor position.
737   ResetCursorPosition( lastCursorIndex );
738
739   // Scrolls the text to make the cursor visible.
740   ResetScrollPosition();
741
742   mImpl->RequestRelayout();
743
744   if( NULL != mImpl->mEventData )
745   {
746     // Cancel previously queued events
747     mImpl->mEventData->mEventQueue.clear();
748   }
749
750   // Do this last since it provides callbacks into application code.
751   if( NULL != mImpl->mEditableControlInterface )
752   {
753     mImpl->mEditableControlInterface->TextChanged();
754   }
755 }
756
757 void Controller::GetText( std::string& text ) const
758 {
759   if( !mImpl->IsShowingPlaceholderText() )
760   {
761     // Retrieves the text string.
762     mImpl->GetText( 0u, text );
763   }
764   else
765   {
766     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this );
767   }
768 }
769
770 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
771 {
772   if( NULL != mImpl->mEventData )
773   {
774     if( PLACEHOLDER_TYPE_INACTIVE == type )
775     {
776       mImpl->mEventData->mPlaceholderTextInactive = text;
777     }
778     else
779     {
780       mImpl->mEventData->mPlaceholderTextActive = text;
781     }
782
783     // Update placeholder if there is no text
784     if( mImpl->IsShowingPlaceholderText() ||
785         ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
786     {
787       ShowPlaceholderText();
788     }
789   }
790 }
791
792 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
793 {
794   if( NULL != mImpl->mEventData )
795   {
796     if( PLACEHOLDER_TYPE_INACTIVE == type )
797     {
798       text = mImpl->mEventData->mPlaceholderTextInactive;
799     }
800     else
801     {
802       text = mImpl->mEventData->mPlaceholderTextActive;
803     }
804   }
805 }
806
807 void Controller::UpdateAfterFontChange( const std::string& newDefaultFont )
808 {
809   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
810
811   if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes
812   {
813     DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
814     mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
815
816     ClearFontData();
817
818     mImpl->RequestRelayout();
819   }
820 }
821
822 // public : Default style & Input style
823
824 void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
825 {
826   if( NULL == mImpl->mFontDefaults )
827   {
828     mImpl->mFontDefaults = new FontDefaults();
829   }
830
831   mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
832   DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
833   mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
834
835   // Clear the font-specific data
836   ClearFontData();
837
838   mImpl->RequestRelayout();
839 }
840
841 const std::string& Controller::GetDefaultFontFamily() const
842 {
843   if( NULL != mImpl->mFontDefaults )
844   {
845     return mImpl->mFontDefaults->mFontDescription.family;
846   }
847
848   return EMPTY_STRING;
849 }
850
851 void Controller::SetPlaceholderFontFamily( const std::string& placeholderTextFontFamily )
852 {
853   if( NULL != mImpl->mEventData )
854   {
855     if( NULL == mImpl->mEventData->mPlaceholderFont )
856     {
857       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
858     }
859
860     mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily;
861     DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str());
862     mImpl->mEventData->mPlaceholderFont->familyDefined = !placeholderTextFontFamily.empty();
863
864     mImpl->RequestRelayout();
865   }
866 }
867
868 const std::string& Controller::GetPlaceholderFontFamily() const
869 {
870   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
871   {
872     return mImpl->mEventData->mPlaceholderFont->mFontDescription.family;
873   }
874
875   return EMPTY_STRING;
876 }
877
878 void Controller::SetDefaultFontWeight( FontWeight weight )
879 {
880   if( NULL == mImpl->mFontDefaults )
881   {
882     mImpl->mFontDefaults = new FontDefaults();
883   }
884
885   mImpl->mFontDefaults->mFontDescription.weight = weight;
886   mImpl->mFontDefaults->weightDefined = true;
887
888   // Clear the font-specific data
889   ClearFontData();
890
891   mImpl->RequestRelayout();
892 }
893
894 bool Controller::IsDefaultFontWeightDefined() const
895 {
896   if( NULL != mImpl->mFontDefaults )
897   {
898     return mImpl->mFontDefaults->weightDefined;
899   }
900
901   return false;
902 }
903
904 FontWeight Controller::GetDefaultFontWeight() const
905 {
906   if( NULL != mImpl->mFontDefaults )
907   {
908     return mImpl->mFontDefaults->mFontDescription.weight;
909   }
910
911   return TextAbstraction::FontWeight::NORMAL;
912 }
913
914 void Controller::SetPlaceholderTextFontWeight( FontWeight weight )
915 {
916   if( NULL != mImpl->mEventData )
917   {
918     if( NULL == mImpl->mEventData->mPlaceholderFont )
919     {
920       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
921     }
922
923     mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight;
924     mImpl->mEventData->mPlaceholderFont->weightDefined = true;
925
926     mImpl->RequestRelayout();
927   }
928 }
929
930 bool Controller::IsPlaceholderTextFontWeightDefined() const
931 {
932   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
933   {
934     return mImpl->mEventData->mPlaceholderFont->weightDefined;
935   }
936   return false;
937 }
938
939 FontWeight Controller::GetPlaceholderTextFontWeight() const
940 {
941   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
942   {
943     return mImpl->mEventData->mPlaceholderFont->mFontDescription.weight;
944   }
945
946   return TextAbstraction::FontWeight::NORMAL;
947 }
948
949 void Controller::SetDefaultFontWidth( FontWidth width )
950 {
951   if( NULL == mImpl->mFontDefaults )
952   {
953     mImpl->mFontDefaults = new FontDefaults();
954   }
955
956   mImpl->mFontDefaults->mFontDescription.width = width;
957   mImpl->mFontDefaults->widthDefined = true;
958
959   // Clear the font-specific data
960   ClearFontData();
961
962   mImpl->RequestRelayout();
963 }
964
965 bool Controller::IsDefaultFontWidthDefined() const
966 {
967   if( NULL != mImpl->mFontDefaults )
968   {
969     return mImpl->mFontDefaults->widthDefined;
970   }
971
972   return false;
973 }
974
975 FontWidth Controller::GetDefaultFontWidth() const
976 {
977   if( NULL != mImpl->mFontDefaults )
978   {
979     return mImpl->mFontDefaults->mFontDescription.width;
980   }
981
982   return TextAbstraction::FontWidth::NORMAL;
983 }
984
985 void Controller::SetPlaceholderTextFontWidth( FontWidth width )
986 {
987   if( NULL != mImpl->mEventData )
988   {
989     if( NULL == mImpl->mEventData->mPlaceholderFont )
990     {
991       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
992     }
993
994     mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width;
995     mImpl->mEventData->mPlaceholderFont->widthDefined = true;
996
997     mImpl->RequestRelayout();
998   }
999 }
1000
1001 bool Controller::IsPlaceholderTextFontWidthDefined() const
1002 {
1003   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1004   {
1005     return mImpl->mEventData->mPlaceholderFont->widthDefined;
1006   }
1007   return false;
1008 }
1009
1010 FontWidth Controller::GetPlaceholderTextFontWidth() const
1011 {
1012   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1013   {
1014     return mImpl->mEventData->mPlaceholderFont->mFontDescription.width;
1015   }
1016
1017   return TextAbstraction::FontWidth::NORMAL;
1018 }
1019
1020 void Controller::SetDefaultFontSlant( FontSlant slant )
1021 {
1022   if( NULL == mImpl->mFontDefaults )
1023   {
1024     mImpl->mFontDefaults = new FontDefaults();
1025   }
1026
1027   mImpl->mFontDefaults->mFontDescription.slant = slant;
1028   mImpl->mFontDefaults->slantDefined = true;
1029
1030   // Clear the font-specific data
1031   ClearFontData();
1032
1033   mImpl->RequestRelayout();
1034 }
1035
1036 bool Controller::IsDefaultFontSlantDefined() const
1037 {
1038   if( NULL != mImpl->mFontDefaults )
1039   {
1040     return mImpl->mFontDefaults->slantDefined;
1041   }
1042   return false;
1043 }
1044
1045 FontSlant Controller::GetDefaultFontSlant() const
1046 {
1047   if( NULL != mImpl->mFontDefaults )
1048   {
1049     return mImpl->mFontDefaults->mFontDescription.slant;
1050   }
1051
1052   return TextAbstraction::FontSlant::NORMAL;
1053 }
1054
1055 void Controller::SetPlaceholderTextFontSlant( FontSlant slant )
1056 {
1057   if( NULL != mImpl->mEventData )
1058   {
1059     if( NULL == mImpl->mEventData->mPlaceholderFont )
1060     {
1061       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1062     }
1063
1064     mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant;
1065     mImpl->mEventData->mPlaceholderFont->slantDefined = true;
1066
1067     mImpl->RequestRelayout();
1068   }
1069 }
1070
1071 bool Controller::IsPlaceholderTextFontSlantDefined() const
1072 {
1073   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1074   {
1075     return mImpl->mEventData->mPlaceholderFont->slantDefined;
1076   }
1077   return false;
1078 }
1079
1080 FontSlant Controller::GetPlaceholderTextFontSlant() const
1081 {
1082   if( ( NULL != mImpl->mEventData ) && ( NULL != mImpl->mEventData->mPlaceholderFont ) )
1083   {
1084     return mImpl->mEventData->mPlaceholderFont->mFontDescription.slant;
1085   }
1086
1087   return TextAbstraction::FontSlant::NORMAL;
1088 }
1089
1090 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
1091 {
1092   if( NULL == mImpl->mFontDefaults )
1093   {
1094     mImpl->mFontDefaults = new FontDefaults();
1095   }
1096
1097   switch( type )
1098   {
1099     case POINT_SIZE:
1100     {
1101       mImpl->mFontDefaults->mDefaultPointSize = fontSize;
1102       mImpl->mFontDefaults->sizeDefined = true;
1103       break;
1104     }
1105     case PIXEL_SIZE:
1106     {
1107       // Point size = Pixel size * 72.f / DPI
1108       unsigned int horizontalDpi = 0u;
1109       unsigned int verticalDpi = 0u;
1110       TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1111       fontClient.GetDpi( horizontalDpi, verticalDpi );
1112
1113       mImpl->mFontDefaults->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1114       mImpl->mFontDefaults->sizeDefined = true;
1115       break;
1116     }
1117   }
1118
1119   // Clear the font-specific data
1120   ClearFontData();
1121
1122   mImpl->RequestRelayout();
1123 }
1124
1125 float Controller::GetDefaultFontSize( FontSizeType type ) const
1126 {
1127   float value = 0.0f;
1128   if( NULL != mImpl->mFontDefaults )
1129   {
1130     switch( type )
1131     {
1132       case POINT_SIZE:
1133       {
1134         value = mImpl->mFontDefaults->mDefaultPointSize;
1135         break;
1136       }
1137       case PIXEL_SIZE:
1138       {
1139         // Pixel size = Point size * DPI / 72.f
1140         unsigned int horizontalDpi = 0u;
1141         unsigned int verticalDpi = 0u;
1142         TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1143         fontClient.GetDpi( horizontalDpi, verticalDpi );
1144
1145         value = mImpl->mFontDefaults->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1146         break;
1147       }
1148     }
1149     return value;
1150   }
1151
1152   return value;
1153 }
1154
1155 void Controller::SetPlaceholderTextFontSize( float fontSize, FontSizeType type )
1156 {
1157   if( NULL != mImpl->mEventData )
1158   {
1159     if( NULL == mImpl->mEventData->mPlaceholderFont )
1160     {
1161       mImpl->mEventData->mPlaceholderFont = new FontDefaults();
1162     }
1163
1164     switch( type )
1165     {
1166       case POINT_SIZE:
1167       {
1168         mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = fontSize;
1169         mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1170         mImpl->mEventData->mIsPlaceholderPixelSize = false; // Font size flag
1171         break;
1172       }
1173       case PIXEL_SIZE:
1174       {
1175         // Point size = Pixel size * 72.f / DPI
1176         unsigned int horizontalDpi = 0u;
1177         unsigned int verticalDpi = 0u;
1178         TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1179         fontClient.GetDpi( horizontalDpi, verticalDpi );
1180
1181         mImpl->mEventData->mPlaceholderFont->mDefaultPointSize = ( fontSize * 72.f ) / static_cast< float >( horizontalDpi );
1182         mImpl->mEventData->mPlaceholderFont->sizeDefined = true;
1183         mImpl->mEventData->mIsPlaceholderPixelSize = true; // Font size flag
1184         break;
1185       }
1186     }
1187
1188     mImpl->RequestRelayout();
1189   }
1190 }
1191
1192 float Controller::GetPlaceholderTextFontSize( FontSizeType type ) const
1193 {
1194   float value = 0.0f;
1195   if( NULL != mImpl->mEventData )
1196   {
1197     switch( type )
1198     {
1199       case POINT_SIZE:
1200       {
1201         if( NULL != mImpl->mEventData->mPlaceholderFont )
1202         {
1203           value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize;
1204         }
1205         else
1206         {
1207           // If the placeholder text font size is not set, then return the default font size.
1208           value = GetDefaultFontSize( POINT_SIZE );
1209         }
1210         break;
1211       }
1212       case PIXEL_SIZE:
1213       {
1214         if( NULL != mImpl->mEventData->mPlaceholderFont )
1215         {
1216           // Pixel size = Point size * DPI / 72.f
1217           unsigned int horizontalDpi = 0u;
1218           unsigned int verticalDpi = 0u;
1219           TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1220           fontClient.GetDpi( horizontalDpi, verticalDpi );
1221
1222           value = mImpl->mEventData->mPlaceholderFont->mDefaultPointSize * static_cast< float >( horizontalDpi ) / 72.f;
1223         }
1224         else
1225         {
1226           // If the placeholder text font size is not set, then return the default font size.
1227           value = GetDefaultFontSize( PIXEL_SIZE );
1228         }
1229         break;
1230       }
1231     }
1232     return value;
1233   }
1234
1235   return value;
1236 }
1237
1238 void Controller::SetDefaultColor( const Vector4& color )
1239 {
1240   mImpl->mTextColor = color;
1241
1242   if( !mImpl->IsShowingPlaceholderText() )
1243   {
1244     mImpl->mModel->mVisualModel->SetTextColor( color );
1245
1246     mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1247
1248     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1249
1250     mImpl->RequestRelayout();
1251   }
1252 }
1253
1254 const Vector4& Controller::GetDefaultColor() const
1255 {
1256   return mImpl->mTextColor;
1257 }
1258
1259 void Controller::SetPlaceholderTextColor( const Vector4& textColor )
1260 {
1261   if( NULL != mImpl->mEventData )
1262   {
1263     mImpl->mEventData->mPlaceholderTextColor = textColor;
1264   }
1265
1266   if( mImpl->IsShowingPlaceholderText() )
1267   {
1268     mImpl->mModel->mVisualModel->SetTextColor( textColor );
1269     mImpl->RequestRelayout();
1270   }
1271 }
1272
1273 const Vector4& Controller::GetPlaceholderTextColor() const
1274 {
1275   if( NULL != mImpl->mEventData )
1276   {
1277     return mImpl->mEventData->mPlaceholderTextColor;
1278   }
1279
1280   return Color::BLACK;
1281 }
1282
1283 void Controller::SetShadowOffset( const Vector2& shadowOffset )
1284 {
1285   mImpl->mModel->mVisualModel->SetShadowOffset( shadowOffset );
1286
1287   mImpl->RequestRelayout();
1288 }
1289
1290 const Vector2& Controller::GetShadowOffset() const
1291 {
1292   return mImpl->mModel->mVisualModel->GetShadowOffset();
1293 }
1294
1295 void Controller::SetShadowColor( const Vector4& shadowColor )
1296 {
1297   mImpl->mModel->mVisualModel->SetShadowColor( shadowColor );
1298
1299   mImpl->RequestRelayout();
1300 }
1301
1302 const Vector4& Controller::GetShadowColor() const
1303 {
1304   return mImpl->mModel->mVisualModel->GetShadowColor();
1305 }
1306
1307 void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
1308 {
1309   if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
1310   {
1311     mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
1312
1313     mImpl->RequestRelayout();
1314   }
1315 }
1316
1317 const float& Controller::GetShadowBlurRadius() const
1318 {
1319   return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1320 }
1321
1322 void Controller::SetUnderlineColor( const Vector4& color )
1323 {
1324   mImpl->mModel->mVisualModel->SetUnderlineColor( color );
1325
1326   mImpl->RequestRelayout();
1327 }
1328
1329 const Vector4& Controller::GetUnderlineColor() const
1330 {
1331   return mImpl->mModel->mVisualModel->GetUnderlineColor();
1332 }
1333
1334 void Controller::SetUnderlineEnabled( bool enabled )
1335 {
1336   mImpl->mModel->mVisualModel->SetUnderlineEnabled( enabled );
1337
1338   mImpl->RequestRelayout();
1339 }
1340
1341 bool Controller::IsUnderlineEnabled() const
1342 {
1343   return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1344 }
1345
1346 void Controller::SetUnderlineHeight( float height )
1347 {
1348   mImpl->mModel->mVisualModel->SetUnderlineHeight( height );
1349
1350   mImpl->RequestRelayout();
1351 }
1352
1353 float Controller::GetUnderlineHeight() const
1354 {
1355   return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1356 }
1357
1358 void Controller::SetOutlineColor( const Vector4& color )
1359 {
1360   mImpl->mModel->mVisualModel->SetOutlineColor( color );
1361
1362   mImpl->RequestRelayout();
1363 }
1364
1365 const Vector4& Controller::GetOutlineColor() const
1366 {
1367   return mImpl->mModel->mVisualModel->GetOutlineColor();
1368 }
1369
1370 void Controller::SetOutlineWidth( uint16_t width )
1371 {
1372   mImpl->mModel->mVisualModel->SetOutlineWidth( width );
1373
1374   mImpl->RequestRelayout();
1375 }
1376
1377 uint16_t Controller::GetOutlineWidth() const
1378 {
1379   return mImpl->mModel->mVisualModel->GetOutlineWidth();
1380 }
1381
1382 void Controller::SetBackgroundColor( const Vector4& color )
1383 {
1384   mImpl->mModel->mVisualModel->SetBackgroundColor( color );
1385
1386   mImpl->RequestRelayout();
1387 }
1388
1389 const Vector4& Controller::GetBackgroundColor() const
1390 {
1391   return mImpl->mModel->mVisualModel->GetBackgroundColor();
1392 }
1393
1394 void Controller::SetBackgroundEnabled( bool enabled )
1395 {
1396   mImpl->mModel->mVisualModel->SetBackgroundEnabled( enabled );
1397
1398   mImpl->RequestRelayout();
1399 }
1400
1401 bool Controller::IsBackgroundEnabled() const
1402 {
1403   return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1404 }
1405
1406 void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
1407 {
1408   if( NULL == mImpl->mEmbossDefaults )
1409   {
1410     mImpl->mEmbossDefaults = new EmbossDefaults();
1411   }
1412
1413   mImpl->mEmbossDefaults->properties = embossProperties;
1414 }
1415
1416 const std::string& Controller::GetDefaultEmbossProperties() const
1417 {
1418   if( NULL != mImpl->mEmbossDefaults )
1419   {
1420     return mImpl->mEmbossDefaults->properties;
1421   }
1422
1423   return EMPTY_STRING;
1424 }
1425
1426 void Controller::SetDefaultOutlineProperties( const std::string& outlineProperties )
1427 {
1428   if( NULL == mImpl->mOutlineDefaults )
1429   {
1430     mImpl->mOutlineDefaults = new OutlineDefaults();
1431   }
1432
1433   mImpl->mOutlineDefaults->properties = outlineProperties;
1434 }
1435
1436 const std::string& Controller::GetDefaultOutlineProperties() const
1437 {
1438   if( NULL != mImpl->mOutlineDefaults )
1439   {
1440     return mImpl->mOutlineDefaults->properties;
1441   }
1442
1443   return EMPTY_STRING;
1444 }
1445
1446 bool Controller::SetDefaultLineSpacing( float lineSpacing )
1447 {
1448   if( std::fabs( lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing() ) > Math::MACHINE_EPSILON_1000 )
1449   {
1450     mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1451     mImpl->mRecalculateNaturalSize = true;
1452     return true;
1453   }
1454   return false;
1455 }
1456
1457 float Controller::GetDefaultLineSpacing() const
1458 {
1459   return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1460 }
1461
1462 void Controller::SetInputColor( const Vector4& color )
1463 {
1464   if( NULL != mImpl->mEventData )
1465   {
1466     mImpl->mEventData->mInputStyle.textColor = color;
1467     mImpl->mEventData->mInputStyle.isDefaultColor = false;
1468
1469     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1470     {
1471       const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1472
1473       // Get start and end position of selection
1474       const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1475       const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
1476
1477       // Add the color run.
1478       const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1479       mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
1480
1481       ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
1482       colorRun.color = color;
1483       colorRun.characterRun.characterIndex = startOfSelectedText;
1484       colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1485
1486       // Request to relayout.
1487       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
1488       mImpl->RequestRelayout();
1489
1490       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1491       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1492       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1493     }
1494   }
1495 }
1496
1497 const Vector4& Controller::GetInputColor() const
1498 {
1499   if( NULL != mImpl->mEventData )
1500   {
1501     return mImpl->mEventData->mInputStyle.textColor;
1502   }
1503
1504   // Return the default text's color if there is no EventData.
1505   return mImpl->mTextColor;
1506
1507 }
1508
1509 void Controller::SetInputFontFamily( const std::string& fontFamily )
1510 {
1511   if( NULL != mImpl->mEventData )
1512   {
1513     mImpl->mEventData->mInputStyle.familyName = fontFamily;
1514     mImpl->mEventData->mInputStyle.isFamilyDefined = true;
1515
1516     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1517     {
1518       CharacterIndex startOfSelectedText = 0u;
1519       Length lengthOfSelectedText = 0u;
1520       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1521                                                                             mImpl->mModel->mLogicalModel,
1522                                                                             startOfSelectedText,
1523                                                                             lengthOfSelectedText );
1524
1525       fontDescriptionRun.familyLength = fontFamily.size();
1526       fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
1527       memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
1528       fontDescriptionRun.familyDefined = true;
1529
1530       // The memory allocated for the font family name is freed when the font description is removed from the logical model.
1531
1532       // Request to relayout.
1533       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1534                                                                VALIDATE_FONTS            |
1535                                                                SHAPE_TEXT                |
1536                                                                GET_GLYPH_METRICS         |
1537                                                                LAYOUT                    |
1538                                                                UPDATE_LAYOUT_SIZE        |
1539                                                                REORDER                   |
1540                                                                ALIGN );
1541       mImpl->mRecalculateNaturalSize = true;
1542       mImpl->RequestRelayout();
1543
1544       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1545       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1546       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1547
1548       // As the font changes, recalculate the handle positions is needed.
1549       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1550       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1551       mImpl->mEventData->mUpdateHighlightBox = true;
1552       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1553     }
1554   }
1555 }
1556
1557 const std::string& Controller::GetInputFontFamily() const
1558 {
1559   if( NULL != mImpl->mEventData )
1560   {
1561     return mImpl->mEventData->mInputStyle.familyName;
1562   }
1563
1564   // Return the default font's family if there is no EventData.
1565   return GetDefaultFontFamily();
1566 }
1567
1568 void Controller::SetInputFontWeight( FontWeight weight )
1569 {
1570   if( NULL != mImpl->mEventData )
1571   {
1572     mImpl->mEventData->mInputStyle.weight = weight;
1573     mImpl->mEventData->mInputStyle.isWeightDefined = true;
1574
1575     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1576     {
1577       CharacterIndex startOfSelectedText = 0u;
1578       Length lengthOfSelectedText = 0u;
1579       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1580                                                                             mImpl->mModel->mLogicalModel,
1581                                                                             startOfSelectedText,
1582                                                                             lengthOfSelectedText );
1583
1584       fontDescriptionRun.weight = weight;
1585       fontDescriptionRun.weightDefined = true;
1586
1587       // Request to relayout.
1588       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1589                                                                VALIDATE_FONTS            |
1590                                                                SHAPE_TEXT                |
1591                                                                GET_GLYPH_METRICS         |
1592                                                                LAYOUT                    |
1593                                                                UPDATE_LAYOUT_SIZE        |
1594                                                                REORDER                   |
1595                                                                ALIGN );
1596       mImpl->mRecalculateNaturalSize = true;
1597       mImpl->RequestRelayout();
1598
1599       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1600       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1601       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1602
1603       // As the font might change, recalculate the handle positions is needed.
1604       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1605       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1606       mImpl->mEventData->mUpdateHighlightBox = true;
1607       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1608     }
1609   }
1610 }
1611
1612 bool Controller::IsInputFontWeightDefined() const
1613 {
1614   bool defined = false;
1615
1616   if( NULL != mImpl->mEventData )
1617   {
1618     defined = mImpl->mEventData->mInputStyle.isWeightDefined;
1619   }
1620
1621   return defined;
1622 }
1623
1624 FontWeight Controller::GetInputFontWeight() const
1625 {
1626   if( NULL != mImpl->mEventData )
1627   {
1628     return mImpl->mEventData->mInputStyle.weight;
1629   }
1630
1631   return GetDefaultFontWeight();
1632 }
1633
1634 void Controller::SetInputFontWidth( FontWidth width )
1635 {
1636   if( NULL != mImpl->mEventData )
1637   {
1638     mImpl->mEventData->mInputStyle.width = width;
1639     mImpl->mEventData->mInputStyle.isWidthDefined = true;
1640
1641     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1642     {
1643       CharacterIndex startOfSelectedText = 0u;
1644       Length lengthOfSelectedText = 0u;
1645       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1646                                                                             mImpl->mModel->mLogicalModel,
1647                                                                             startOfSelectedText,
1648                                                                             lengthOfSelectedText );
1649
1650       fontDescriptionRun.width = width;
1651       fontDescriptionRun.widthDefined = true;
1652
1653       // Request to relayout.
1654       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1655                                                                VALIDATE_FONTS            |
1656                                                                SHAPE_TEXT                |
1657                                                                GET_GLYPH_METRICS         |
1658                                                                LAYOUT                    |
1659                                                                UPDATE_LAYOUT_SIZE        |
1660                                                                REORDER                   |
1661                                                                ALIGN );
1662       mImpl->mRecalculateNaturalSize = true;
1663       mImpl->RequestRelayout();
1664
1665       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1666       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1667       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1668
1669       // As the font might change, recalculate the handle positions is needed.
1670       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1671       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1672       mImpl->mEventData->mUpdateHighlightBox = true;
1673       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1674     }
1675   }
1676 }
1677
1678 bool Controller::IsInputFontWidthDefined() const
1679 {
1680   bool defined = false;
1681
1682   if( NULL != mImpl->mEventData )
1683   {
1684     defined = mImpl->mEventData->mInputStyle.isWidthDefined;
1685   }
1686
1687   return defined;
1688 }
1689
1690 FontWidth Controller::GetInputFontWidth() const
1691 {
1692   if( NULL != mImpl->mEventData )
1693   {
1694     return mImpl->mEventData->mInputStyle.width;
1695   }
1696
1697   return GetDefaultFontWidth();
1698 }
1699
1700 void Controller::SetInputFontSlant( FontSlant slant )
1701 {
1702   if( NULL != mImpl->mEventData )
1703   {
1704     mImpl->mEventData->mInputStyle.slant = slant;
1705     mImpl->mEventData->mInputStyle.isSlantDefined = true;
1706
1707     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1708     {
1709       CharacterIndex startOfSelectedText = 0u;
1710       Length lengthOfSelectedText = 0u;
1711       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1712                                                                             mImpl->mModel->mLogicalModel,
1713                                                                             startOfSelectedText,
1714                                                                             lengthOfSelectedText );
1715
1716       fontDescriptionRun.slant = slant;
1717       fontDescriptionRun.slantDefined = true;
1718
1719       // Request to relayout.
1720       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1721                                                                VALIDATE_FONTS            |
1722                                                                SHAPE_TEXT                |
1723                                                                GET_GLYPH_METRICS         |
1724                                                                LAYOUT                    |
1725                                                                UPDATE_LAYOUT_SIZE        |
1726                                                                REORDER                   |
1727                                                                ALIGN );
1728       mImpl->mRecalculateNaturalSize = true;
1729       mImpl->RequestRelayout();
1730
1731       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1732       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1733       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1734
1735       // As the font might change, recalculate the handle positions is needed.
1736       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1737       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1738       mImpl->mEventData->mUpdateHighlightBox = true;
1739       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1740     }
1741   }
1742 }
1743
1744 bool Controller::IsInputFontSlantDefined() const
1745 {
1746   bool defined = false;
1747
1748   if( NULL != mImpl->mEventData )
1749   {
1750     defined = mImpl->mEventData->mInputStyle.isSlantDefined;
1751   }
1752
1753   return defined;
1754 }
1755
1756 FontSlant Controller::GetInputFontSlant() const
1757 {
1758   if( NULL != mImpl->mEventData )
1759   {
1760     return mImpl->mEventData->mInputStyle.slant;
1761   }
1762
1763   return GetDefaultFontSlant();
1764 }
1765
1766 void Controller::SetInputFontPointSize( float size )
1767 {
1768   if( NULL != mImpl->mEventData )
1769   {
1770     mImpl->mEventData->mInputStyle.size = size;
1771     mImpl->mEventData->mInputStyle.isSizeDefined = true;
1772
1773     if( EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState )
1774     {
1775       CharacterIndex startOfSelectedText = 0u;
1776       Length lengthOfSelectedText = 0u;
1777       FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
1778                                                                             mImpl->mModel->mLogicalModel,
1779                                                                             startOfSelectedText,
1780                                                                             lengthOfSelectedText );
1781
1782       fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
1783       fontDescriptionRun.sizeDefined = true;
1784
1785       // Request to relayout.
1786       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
1787                                                                VALIDATE_FONTS            |
1788                                                                SHAPE_TEXT                |
1789                                                                GET_GLYPH_METRICS         |
1790                                                                LAYOUT                    |
1791                                                                UPDATE_LAYOUT_SIZE        |
1792                                                                REORDER                   |
1793                                                                ALIGN );
1794       mImpl->mRecalculateNaturalSize = true;
1795       mImpl->RequestRelayout();
1796
1797       mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1798       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1799       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1800
1801       // As the font might change, recalculate the handle positions is needed.
1802       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
1803       mImpl->mEventData->mUpdateRightSelectionPosition = true;
1804       mImpl->mEventData->mUpdateHighlightBox = true;
1805       mImpl->mEventData->mScrollAfterUpdatePosition = true;
1806     }
1807   }
1808 }
1809
1810 float Controller::GetInputFontPointSize() const
1811 {
1812   if( NULL != mImpl->mEventData )
1813   {
1814     return mImpl->mEventData->mInputStyle.size;
1815   }
1816
1817   // Return the default font's point size if there is no EventData.
1818   return GetDefaultFontSize( Text::Controller::POINT_SIZE );
1819 }
1820
1821 void Controller::SetInputLineSpacing( float lineSpacing )
1822 {
1823   if( NULL != mImpl->mEventData )
1824   {
1825     mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1826     mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1827   }
1828 }
1829
1830 float Controller::GetInputLineSpacing() const
1831 {
1832   if( NULL != mImpl->mEventData )
1833   {
1834     return mImpl->mEventData->mInputStyle.lineSpacing;
1835   }
1836
1837   return 0.f;
1838 }
1839
1840 void Controller::SetInputShadowProperties( const std::string& shadowProperties )
1841 {
1842   if( NULL != mImpl->mEventData )
1843   {
1844     mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1845   }
1846 }
1847
1848 const std::string& Controller::GetInputShadowProperties() const
1849 {
1850   if( NULL != mImpl->mEventData )
1851   {
1852     return mImpl->mEventData->mInputStyle.shadowProperties;
1853   }
1854
1855   return EMPTY_STRING;
1856 }
1857
1858 void Controller::SetInputUnderlineProperties( const std::string& underlineProperties )
1859 {
1860   if( NULL != mImpl->mEventData )
1861   {
1862     mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1863   }
1864 }
1865
1866 const std::string& Controller::GetInputUnderlineProperties() const
1867 {
1868   if( NULL != mImpl->mEventData )
1869   {
1870     return mImpl->mEventData->mInputStyle.underlineProperties;
1871   }
1872
1873   return EMPTY_STRING;
1874 }
1875
1876 void Controller::SetInputEmbossProperties( const std::string& embossProperties )
1877 {
1878   if( NULL != mImpl->mEventData )
1879   {
1880     mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1881   }
1882 }
1883
1884 const std::string& Controller::GetInputEmbossProperties() const
1885 {
1886   if( NULL != mImpl->mEventData )
1887   {
1888     return mImpl->mEventData->mInputStyle.embossProperties;
1889   }
1890
1891   return GetDefaultEmbossProperties();
1892 }
1893
1894 void Controller::SetInputOutlineProperties( const std::string& outlineProperties )
1895 {
1896   if( NULL != mImpl->mEventData )
1897   {
1898     mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1899   }
1900 }
1901
1902 const std::string& Controller::GetInputOutlineProperties() const
1903 {
1904   if( NULL != mImpl->mEventData )
1905   {
1906     return mImpl->mEventData->mInputStyle.outlineProperties;
1907   }
1908
1909   return GetDefaultOutlineProperties();
1910 }
1911
1912 void Controller::SetInputModePassword( bool passwordInput )
1913 {
1914   if( NULL != mImpl->mEventData )
1915   {
1916     mImpl->mEventData->mPasswordInput = passwordInput;
1917   }
1918 }
1919
1920 bool Controller::IsInputModePassword()
1921 {
1922   if( NULL != mImpl->mEventData )
1923   {
1924     return mImpl->mEventData->mPasswordInput;
1925   }
1926   return false;
1927 }
1928
1929 void Controller::SetNoTextDoubleTapAction( NoTextTap::Action action )
1930 {
1931   if( NULL != mImpl->mEventData )
1932   {
1933     mImpl->mEventData->mDoubleTapAction = action;
1934   }
1935 }
1936
1937 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1938 {
1939   NoTextTap::Action action = NoTextTap::NO_ACTION;
1940
1941   if( NULL != mImpl->mEventData )
1942   {
1943     action = mImpl->mEventData->mDoubleTapAction;
1944   }
1945
1946   return action;
1947 }
1948
1949 void Controller::SetNoTextLongPressAction( NoTextTap::Action action )
1950 {
1951   if( NULL != mImpl->mEventData )
1952   {
1953     mImpl->mEventData->mLongPressAction = action;
1954   }
1955 }
1956
1957 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1958 {
1959   NoTextTap::Action action = NoTextTap::NO_ACTION;
1960
1961   if( NULL != mImpl->mEventData )
1962   {
1963     action = mImpl->mEventData->mLongPressAction;
1964   }
1965
1966   return action;
1967 }
1968
1969 bool Controller::IsUnderlineSetByString()
1970 {
1971   return mImpl->mUnderlineSetByString;
1972 }
1973
1974 void Controller::UnderlineSetByString( bool setByString )
1975 {
1976   mImpl->mUnderlineSetByString = setByString;
1977 }
1978
1979 bool Controller::IsShadowSetByString()
1980 {
1981   return mImpl->mShadowSetByString;
1982 }
1983
1984 void Controller::ShadowSetByString( bool setByString )
1985 {
1986   mImpl->mShadowSetByString = setByString;
1987 }
1988
1989 bool Controller::IsOutlineSetByString()
1990 {
1991   return mImpl->mOutlineSetByString;
1992 }
1993
1994 void Controller::OutlineSetByString( bool setByString )
1995 {
1996   mImpl->mOutlineSetByString = setByString;
1997 }
1998
1999 bool Controller::IsFontStyleSetByString()
2000 {
2001   return mImpl->mFontStyleSetByString;
2002 }
2003
2004 void Controller::FontStyleSetByString( bool setByString )
2005 {
2006   mImpl->mFontStyleSetByString = setByString;
2007 }
2008
2009 // public : Queries & retrieves.
2010
2011 Layout::Engine& Controller::GetLayoutEngine()
2012 {
2013   return mImpl->mLayoutEngine;
2014 }
2015
2016 View& Controller::GetView()
2017 {
2018   return mImpl->mView;
2019 }
2020
2021 Vector3 Controller::GetNaturalSize()
2022 {
2023   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetNaturalSize\n" );
2024   Vector3 naturalSize;
2025
2026   // Make sure the model is up-to-date before layouting
2027   ProcessModifyEvents();
2028
2029   if( mImpl->mRecalculateNaturalSize )
2030   {
2031     // Operations that can be done only once until the text changes.
2032     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32  |
2033                                                                            GET_SCRIPTS       |
2034                                                                            VALIDATE_FONTS    |
2035                                                                            GET_LINE_BREAKS   |
2036                                                                            GET_WORD_BREAKS   |
2037                                                                            BIDI_INFO         |
2038                                                                            SHAPE_TEXT        |
2039                                                                            GET_GLYPH_METRICS );
2040
2041     // Set the update info to relayout the whole text.
2042     mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2043     mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2044
2045     // Make sure the model is up-to-date before layouting
2046     mImpl->UpdateModel( onlyOnceOperations );
2047
2048     // Layout the text for the new width.
2049     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT | REORDER );
2050
2051     // Store the actual control's size to restore later.
2052     const Size actualControlSize = mImpl->mModel->mVisualModel->mControlSize;
2053
2054     DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2055                 static_cast<OperationsMask>( onlyOnceOperations |
2056                                              LAYOUT | REORDER ),
2057                 naturalSize.GetVectorXY() );
2058
2059     // Do not do again the only once operations.
2060     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2061
2062     // Do the size related operations again.
2063     const OperationsMask sizeOperations =  static_cast<OperationsMask>( LAYOUT |
2064                                                                         ALIGN  |
2065                                                                         REORDER );
2066     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2067
2068     // Stores the natural size to avoid recalculate it again
2069     // unless the text/style changes.
2070     mImpl->mModel->mVisualModel->SetNaturalSize( naturalSize.GetVectorXY() );
2071
2072     mImpl->mRecalculateNaturalSize = false;
2073
2074     // Clear the update info. This info will be set the next time the text is updated.
2075     mImpl->mTextUpdateInfo.Clear();
2076     mImpl->mTextUpdateInfo.mClearAll = true;
2077
2078     // Restore the actual control's size.
2079     mImpl->mModel->mVisualModel->mControlSize = actualControlSize;
2080
2081     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize calculated %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2082   }
2083   else
2084   {
2085     naturalSize = mImpl->mModel->mVisualModel->GetNaturalSize();
2086
2087     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetNaturalSize cached %f,%f,%f\n", naturalSize.x, naturalSize.y, naturalSize.z );
2088   }
2089
2090   naturalSize.x = ConvertToEven( naturalSize.x );
2091   naturalSize.y = ConvertToEven( naturalSize.y );
2092
2093   return naturalSize;
2094 }
2095
2096 bool Controller::CheckForTextFit( float pointSize, Size& layoutSize )
2097 {
2098   Size textSize;
2099   mImpl->mFontDefaults->mFitPointSize = pointSize;
2100   mImpl->mFontDefaults->sizeDefined = true;
2101   ClearFontData();
2102
2103   // Operations that can be done only once until the text changes.
2104   const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
2105                                                                               GET_SCRIPTS |
2106                                                                            VALIDATE_FONTS |
2107                                                                           GET_LINE_BREAKS |
2108                                                                           GET_WORD_BREAKS |
2109                                                                                 BIDI_INFO |
2110                                                                                 SHAPE_TEXT|
2111                                                                          GET_GLYPH_METRICS );
2112
2113   mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2114   mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2115
2116   // Make sure the model is up-to-date before layouting
2117   mImpl->UpdateModel( onlyOnceOperations );
2118
2119   DoRelayout( Size( layoutSize.width, MAX_FLOAT ),
2120               static_cast<OperationsMask>( onlyOnceOperations | LAYOUT),
2121               textSize);
2122
2123   // Clear the update info. This info will be set the next time the text is updated.
2124   mImpl->mTextUpdateInfo.Clear();
2125   mImpl->mTextUpdateInfo.mClearAll = true;
2126
2127   if( textSize.width > layoutSize.width || textSize.height > layoutSize.height )
2128   {
2129     return false;
2130   }
2131   return true;
2132 }
2133
2134 void Controller::FitPointSizeforLayout( Size layoutSize )
2135 {
2136   const OperationsMask operations  = mImpl->mOperationsPending;
2137   if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
2138   {
2139     bool actualellipsis = mImpl->mModel->mElideEnabled;
2140     float minPointSize = mImpl->mTextFitMinSize;
2141     float maxPointSize = mImpl->mTextFitMaxSize;
2142     float pointInterval = mImpl->mTextFitStepSize;
2143
2144     mImpl->mModel->mElideEnabled = false;
2145     Vector<float> pointSizeArray;
2146
2147     // check zero value
2148     if( pointInterval < 1.f )
2149     {
2150       mImpl->mTextFitStepSize = pointInterval = 1.0f;
2151     }
2152
2153     pointSizeArray.Reserve( static_cast< unsigned int >( ceil( ( maxPointSize - minPointSize ) / pointInterval ) ) );
2154
2155     for( float i = minPointSize; i < maxPointSize; i += pointInterval )
2156     {
2157       pointSizeArray.PushBack( i );
2158     }
2159
2160     pointSizeArray.PushBack( maxPointSize );
2161
2162     int bestSizeIndex = 0;
2163     int min = bestSizeIndex + 1;
2164     int max = pointSizeArray.Size() - 1;
2165     while( min <= max )
2166     {
2167       int destI = ( min + max ) / 2;
2168
2169       if( CheckForTextFit( pointSizeArray[destI], layoutSize ) )
2170       {
2171         bestSizeIndex = min;
2172         min = destI + 1;
2173       }
2174       else
2175       {
2176         max = destI - 1;
2177         bestSizeIndex = max;
2178       }
2179     }
2180
2181     mImpl->mModel->mElideEnabled = actualellipsis;
2182     mImpl->mFontDefaults->mFitPointSize = pointSizeArray[bestSizeIndex];
2183     mImpl->mFontDefaults->sizeDefined = true;
2184     ClearFontData();
2185   }
2186 }
2187
2188 float Controller::GetHeightForWidth( float width )
2189 {
2190   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::GetHeightForWidth %p width %f\n", this, width );
2191   // Make sure the model is up-to-date before layouting
2192   ProcessModifyEvents();
2193
2194   Size layoutSize;
2195   if( fabsf( width - mImpl->mModel->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 ||
2196                                                          mImpl->mTextUpdateInfo.mFullRelayoutNeeded ||
2197                                                          mImpl->mTextUpdateInfo.mClearAll            )
2198   {
2199     // Operations that can be done only once until the text changes.
2200     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32  |
2201                                                                            GET_SCRIPTS       |
2202                                                                            VALIDATE_FONTS    |
2203                                                                            GET_LINE_BREAKS   |
2204                                                                            GET_WORD_BREAKS   |
2205                                                                            BIDI_INFO         |
2206                                                                            SHAPE_TEXT        |
2207                                                                            GET_GLYPH_METRICS );
2208
2209     // Set the update info to relayout the whole text.
2210     mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2211     mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2212
2213     // Make sure the model is up-to-date before layouting
2214     mImpl->UpdateModel( onlyOnceOperations );
2215
2216
2217     // Layout the text for the new width.
2218     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | LAYOUT );
2219
2220     // Store the actual control's width.
2221     const float actualControlWidth = mImpl->mModel->mVisualModel->mControlSize.width;
2222
2223     DoRelayout( Size( width, MAX_FLOAT ),
2224                 static_cast<OperationsMask>( onlyOnceOperations |
2225                                              LAYOUT ),
2226                 layoutSize );
2227
2228     // Do not do again the only once operations.
2229     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2230
2231     // Do the size related operations again.
2232     const OperationsMask sizeOperations =  static_cast<OperationsMask>( LAYOUT |
2233                                                                         ALIGN  |
2234                                                                         REORDER );
2235
2236     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | sizeOperations );
2237
2238     // Clear the update info. This info will be set the next time the text is updated.
2239     mImpl->mTextUpdateInfo.Clear();
2240     mImpl->mTextUpdateInfo.mClearAll = true;
2241
2242     // Restore the actual control's width.
2243     mImpl->mModel->mVisualModel->mControlSize.width = actualControlWidth;
2244
2245     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height );
2246   }
2247   else
2248   {
2249     layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
2250     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height );
2251   }
2252
2253   return layoutSize.height;
2254 }
2255
2256 int Controller::GetLineCount( float width )
2257 {
2258   GetHeightForWidth( width );
2259   int numberofLines = mImpl->mModel->GetNumberOfLines();
2260   return numberofLines;
2261 }
2262
2263 const ModelInterface* const Controller::GetTextModel() const
2264 {
2265   return mImpl->mModel.Get();
2266 }
2267
2268 float Controller::GetScrollAmountByUserInput()
2269 {
2270   float scrollAmount = 0.0f;
2271
2272   if (NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
2273   {
2274     scrollAmount = mImpl->mModel->mScrollPosition.y -  mImpl->mModel->mScrollPositionLast.y;
2275     mImpl->mEventData->mCheckScrollAmount = false;
2276   }
2277   return scrollAmount;
2278 }
2279
2280 bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight, float& layoutHeight )
2281 {
2282   const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
2283   bool isScrolled;
2284
2285   controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
2286   layoutHeight = layout.height;
2287   scrollPosition = mImpl->mModel->mScrollPosition.y;
2288   isScrolled = !Equals( mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1 );
2289   return isScrolled;
2290 }
2291
2292 void Controller::SetHiddenInputOption(const Property::Map& options )
2293 {
2294   if( NULL == mImpl->mHiddenInput )
2295   {
2296     mImpl->mHiddenInput = new HiddenText( this );
2297   }
2298   mImpl->mHiddenInput->SetProperties(options);
2299 }
2300
2301 void Controller::GetHiddenInputOption(Property::Map& options )
2302 {
2303   if( NULL != mImpl->mHiddenInput )
2304   {
2305     mImpl->mHiddenInput->GetProperties(options);
2306   }
2307 }
2308
2309 void Controller::SetPlaceholderProperty( const Property::Map& map )
2310 {
2311   const Property::Map::SizeType count = map.Count();
2312
2313   for( Property::Map::SizeType position = 0; position < count; ++position )
2314   {
2315     KeyValuePair keyValue = map.GetKeyValue( position );
2316     Property::Key& key = keyValue.first;
2317     Property::Value& value = keyValue.second;
2318
2319     if( key == Toolkit::Text::PlaceHolder::Property::TEXT  || key == PLACEHOLDER_TEXT )
2320     {
2321       std::string text = "";
2322       value.Get( text );
2323       SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
2324     }
2325     else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
2326     {
2327       std::string text = "";
2328       value.Get( text );
2329       SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
2330     }
2331     else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
2332     {
2333       Vector4 textColor;
2334       value.Get( textColor );
2335       if( GetPlaceholderTextColor() != textColor )
2336       {
2337         SetPlaceholderTextColor( textColor );
2338       }
2339     }
2340     else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
2341     {
2342       std::string fontFamily = "";
2343       value.Get( fontFamily );
2344       SetPlaceholderFontFamily( fontFamily );
2345     }
2346     else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
2347     {
2348       SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
2349     }
2350     else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
2351     {
2352       float pointSize;
2353       value.Get( pointSize );
2354       if( !Equals( GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
2355       {
2356         SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
2357       }
2358     }
2359     else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
2360     {
2361       float pixelSize;
2362       value.Get( pixelSize );
2363       if( !Equals( GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
2364       {
2365         SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
2366       }
2367     }
2368     else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
2369     {
2370       bool ellipsis;
2371       value.Get( ellipsis );
2372       SetPlaceholderTextElideEnabled( ellipsis );
2373     }
2374   }
2375 }
2376
2377 void Controller::GetPlaceholderProperty( Property::Map& map )
2378 {
2379   if( NULL != mImpl->mEventData )
2380   {
2381     if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
2382     {
2383       map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
2384     }
2385     if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
2386     {
2387       map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
2388     }
2389
2390     map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
2391     map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
2392
2393     Property::Value fontStyleMapGet;
2394     GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
2395     map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
2396
2397     // Choose font size : POINT_SIZE or PIXEL_SIZE
2398     if( !mImpl->mEventData->mIsPlaceholderPixelSize )
2399     {
2400       map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
2401     }
2402     else
2403     {
2404       map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
2405     }
2406
2407     if( mImpl->mEventData->mPlaceholderEllipsisFlag )
2408     {
2409       map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
2410     }
2411   }
2412 }
2413
2414 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
2415 {
2416   // Make sure the model is up-to-date before layouting
2417   ProcessModifyEvents();
2418
2419   if ( mImpl->mUpdateTextDirection )
2420   {
2421     // Operations that can be done only once until the text changes.
2422     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32  |
2423                                                                            GET_SCRIPTS       |
2424                                                                            VALIDATE_FONTS    |
2425                                                                            GET_LINE_BREAKS   |
2426                                                                            GET_WORD_BREAKS   |
2427                                                                            BIDI_INFO         |
2428                                                                            SHAPE_TEXT        |
2429                                                                            GET_GLYPH_METRICS );
2430
2431     // Set the update info to relayout the whole text.
2432     mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
2433     mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
2434
2435     // Make sure the model is up-to-date before layouting
2436     mImpl->UpdateModel( onlyOnceOperations );
2437
2438     Vector3 naturalSize;
2439     DoRelayout( Size( MAX_FLOAT, MAX_FLOAT ),
2440                 static_cast<OperationsMask>( onlyOnceOperations |
2441                                              LAYOUT | REORDER | UPDATE_DIRECTION ),
2442                 naturalSize.GetVectorXY() );
2443
2444     // Do not do again the only once operations.
2445     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending & ~onlyOnceOperations );
2446
2447     // Clear the update info. This info will be set the next time the text is updated.
2448     mImpl->mTextUpdateInfo.Clear();
2449
2450     mImpl->mUpdateTextDirection = false;
2451   }
2452
2453   return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
2454 }
2455
2456 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
2457 {
2458   return mImpl->mModel->GetVerticalLineAlignment();
2459 }
2460
2461 void Controller::SetVerticalLineAlignment( Toolkit::DevelText::VerticalLineAlignment::Type alignment )
2462 {
2463   mImpl->mModel->mVerticalLineAlignment = alignment;
2464 }
2465
2466 // public : Relayout.
2467
2468 Controller::UpdateTextType Controller::Relayout( const Size& size, Dali::LayoutDirection::Type layoutDirection )
2469 {
2470   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::Relayout %p size %f,%f, autoScroll[%s]\n", this, size.width, size.height, mImpl->mIsAutoScrollEnabled ?"true":"false"  );
2471
2472   UpdateTextType updateTextType = NONE_UPDATED;
2473
2474   if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
2475   {
2476     if( 0u != mImpl->mModel->mVisualModel->mGlyphPositions.Count() )
2477     {
2478       mImpl->mModel->mVisualModel->mGlyphPositions.Clear();
2479       updateTextType = MODEL_UPDATED;
2480     }
2481
2482     // Clear the update info. This info will be set the next time the text is updated.
2483     mImpl->mTextUpdateInfo.Clear();
2484
2485     // Not worth to relayout if width or height is equal to zero.
2486     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout (skipped)\n" );
2487
2488     return updateTextType;
2489   }
2490
2491   // Whether a new size has been set.
2492   const bool newSize = ( size != mImpl->mModel->mVisualModel->mControlSize );
2493
2494   if( newSize )
2495   {
2496     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
2497
2498     if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
2499         ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
2500         ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
2501     {
2502       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2503     }
2504
2505     // Layout operations that need to be done if the size changes.
2506     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2507                                                              LAYOUT                    |
2508                                                              ALIGN                     |
2509                                                              UPDATE_LAYOUT_SIZE        |
2510                                                              REORDER );
2511     // Set the update info to relayout the whole text.
2512     mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2513     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2514
2515     // Store the size used to layout the text.
2516     mImpl->mModel->mVisualModel->mControlSize = size;
2517   }
2518
2519   // Whether there are modify events.
2520   if( 0u != mImpl->mModifyEvents.Count() )
2521   {
2522     // Style operations that need to be done if the text is modified.
2523     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2524                                                              COLOR );
2525   }
2526
2527   // Set the update info to elide the text.
2528   if( mImpl->mModel->mElideEnabled ||
2529       ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
2530   {
2531     // Update Text layout for applying elided
2532     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2533                                                              ALIGN                     |
2534                                                              LAYOUT                    |
2535                                                              UPDATE_LAYOUT_SIZE        |
2536                                                              REORDER );
2537     mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2538     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2539   }
2540
2541   if( mImpl->mModel->mMatchSystemLanguageDirection  && mImpl->mLayoutDirection != layoutDirection )
2542   {
2543     // Clear the update info. This info will be set the next time the text is updated.
2544     mImpl->mTextUpdateInfo.mClearAll = true;
2545     // Apply modifications to the model
2546     // Shape the text again is needed because characters like '()[]{}' have to be mirrored and the glyphs generated again.
2547     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
2548                                                              GET_GLYPH_METRICS         |
2549                                                              SHAPE_TEXT                |
2550                                                              UPDATE_DIRECTION          |
2551                                                              LAYOUT                    |
2552                                                              BIDI_INFO                 |
2553                                                              REORDER );
2554     mImpl->mLayoutDirection = layoutDirection;
2555   }
2556
2557   // Make sure the model is up-to-date before layouting.
2558   ProcessModifyEvents();
2559   bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
2560
2561   // Layout the text.
2562   Size layoutSize;
2563   updated = DoRelayout( size,
2564                         mImpl->mOperationsPending,
2565                         layoutSize ) || updated;
2566
2567
2568   if( updated )
2569   {
2570     updateTextType = MODEL_UPDATED;
2571   }
2572
2573   // Do not re-do any operation until something changes.
2574   mImpl->mOperationsPending = NO_OPERATION;
2575   mImpl->mModel->mScrollPositionLast = mImpl->mModel->mScrollPosition;
2576
2577   // Whether the text control is editable
2578   const bool isEditable = NULL != mImpl->mEventData;
2579
2580   // Keep the current offset as it will be used to update the decorator's positions (if the size changes).
2581   Vector2 offset;
2582   if( newSize && isEditable )
2583   {
2584     offset = mImpl->mModel->mScrollPosition;
2585   }
2586
2587   if( !isEditable || !IsMultiLineEnabled() )
2588   {
2589     // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
2590     CalculateVerticalOffset( size );
2591   }
2592
2593   if( isEditable )
2594   {
2595     if( newSize )
2596     {
2597       // If there is a new size, the scroll position needs to be clamped.
2598       mImpl->ClampHorizontalScroll( layoutSize );
2599
2600       // Update the decorator's positions is needed if there is a new size.
2601       mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - offset );
2602     }
2603
2604     // Move the cursor, grab handle etc.
2605     if( mImpl->ProcessInputEvents() )
2606     {
2607       updateTextType = static_cast<UpdateTextType>( updateTextType | DECORATOR_UPDATED );
2608     }
2609   }
2610
2611   // Clear the update info. This info will be set the next time the text is updated.
2612   mImpl->mTextUpdateInfo.Clear();
2613   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::Relayout\n" );
2614
2615   return updateTextType;
2616 }
2617
2618 void Controller::RequestRelayout()
2619 {
2620   mImpl->RequestRelayout();
2621 }
2622
2623 // public : Input style change signals.
2624
2625 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
2626 {
2627   return ( NULL == mImpl->mEventData ) || ( 0u == mImpl->mEventData->mInputStyleChangedQueue.Count() );
2628 }
2629
2630 void Controller::ProcessInputStyleChangedSignals()
2631 {
2632   if( NULL == mImpl->mEventData )
2633   {
2634     // Nothing to do.
2635     return;
2636   }
2637
2638   for( Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
2639          endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
2640        it != endIt;
2641        ++it )
2642   {
2643     const InputStyle::Mask mask = *it;
2644
2645     if( NULL != mImpl->mEditableControlInterface )
2646     {
2647       // Emit the input style changed signal.
2648       mImpl->mEditableControlInterface->InputStyleChanged( mask );
2649     }
2650   }
2651
2652   mImpl->mEventData->mInputStyleChangedQueue.Clear();
2653 }
2654
2655 // public : Text-input Event Queuing.
2656
2657 void Controller::KeyboardFocusGainEvent()
2658 {
2659   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusGainEvent" );
2660
2661   if( NULL != mImpl->mEventData )
2662   {
2663     if( ( EventData::INACTIVE == mImpl->mEventData->mState ) ||
2664         ( EventData::INTERRUPTED == mImpl->mEventData->mState ) )
2665     {
2666       mImpl->ChangeState( EventData::EDITING );
2667       mImpl->mEventData->mUpdateCursorPosition = true; //If editing started without tap event, cursor update must be triggered.
2668       mImpl->mEventData->mUpdateInputStyle = true;
2669       mImpl->mEventData->mScrollAfterUpdatePosition = true;
2670     }
2671     mImpl->NotifyInputMethodContextMultiLineStatus();
2672     if( mImpl->IsShowingPlaceholderText() )
2673     {
2674       // Show alternative placeholder-text when editing
2675       ShowPlaceholderText();
2676     }
2677
2678     mImpl->RequestRelayout();
2679   }
2680 }
2681
2682 void Controller::KeyboardFocusLostEvent()
2683 {
2684   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyboardFocusLostEvent" );
2685
2686   if( NULL != mImpl->mEventData )
2687   {
2688     if( EventData::INTERRUPTED != mImpl->mEventData->mState )
2689     {
2690       mImpl->ChangeState( EventData::INACTIVE );
2691
2692       if( !mImpl->IsShowingRealText() )
2693       {
2694         // Revert to regular placeholder-text when not editing
2695         ShowPlaceholderText();
2696       }
2697     }
2698   }
2699   mImpl->RequestRelayout();
2700 }
2701
2702 bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
2703 {
2704   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected KeyEvent" );
2705
2706   bool textChanged = false;
2707   bool relayoutNeeded = false;
2708
2709   if( ( NULL != mImpl->mEventData ) &&
2710       ( keyEvent.state == KeyEvent::Down ) )
2711   {
2712     int keyCode = keyEvent.keyCode;
2713     const std::string& keyString = keyEvent.keyPressed;
2714     const std::string keyName = keyEvent.keyPressedName;
2715
2716     const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
2717
2718     // Pre-process to separate modifying events from non-modifying input events.
2719     if( isNullKey )
2720     {
2721       // In some platforms arrive key events with no key code.
2722       // Do nothing.
2723       return false;
2724     }
2725     else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode  || Dali::DALI_KEY_SEARCH == keyCode )
2726     {
2727       // Do nothing
2728       return false;
2729     }
2730     else if( ( Dali::DALI_KEY_CURSOR_LEFT  == keyCode ) ||
2731              ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) ||
2732              ( Dali::DALI_KEY_CURSOR_UP    == keyCode ) ||
2733              ( Dali::DALI_KEY_CURSOR_DOWN  == keyCode ) )
2734     {
2735       // If don't have any text, do nothing.
2736       if( !mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters )
2737       {
2738         return false;
2739       }
2740
2741       uint32_t cursorPosition = mImpl->mEventData->mPrimaryCursorPosition;
2742       uint32_t numberOfCharacters = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2743       uint32_t cursorLine = mImpl->mModel->mVisualModel->GetLineOfCharacter( cursorPosition );
2744       uint32_t numberOfLines = mImpl->mModel->GetNumberOfLines();
2745
2746       // Logic to determine whether this text control will lose focus or not.
2747       if( ( Dali::DALI_KEY_CURSOR_LEFT == keyCode && 0 == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2748           ( Dali::DALI_KEY_CURSOR_RIGHT == keyCode && numberOfCharacters == cursorPosition && !keyEvent.IsShiftModifier() ) ||
2749           ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && cursorLine == numberOfLines -1 ) ||
2750           ( Dali::DALI_KEY_CURSOR_DOWN == keyCode && numberOfCharacters == cursorPosition && cursorLine -1 == numberOfLines -1 ) ||
2751           ( Dali::DALI_KEY_CURSOR_UP == keyCode && cursorLine == 0 ) ||
2752           ( Dali::DALI_KEY_CURSOR_UP == keyCode && numberOfCharacters == cursorPosition && cursorLine == 1 ) )
2753       {
2754         // Release the active highlight.
2755         if( mImpl->mEventData->mState == EventData::SELECTING )
2756         {
2757           mImpl->ChangeState( EventData::EDITING );
2758
2759           // Update selection position.
2760           mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2761           mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
2762           mImpl->mEventData->mUpdateCursorPosition = true;
2763           mImpl->RequestRelayout();
2764         }
2765         return false;
2766       }
2767
2768       mImpl->mEventData->mCheckScrollAmount = true;
2769       Event event( Event::CURSOR_KEY_EVENT );
2770       event.p1.mInt = keyCode;
2771       event.p2.mBool = keyEvent.IsShiftModifier();
2772       mImpl->mEventData->mEventQueue.push_back( event );
2773
2774       // Will request for relayout.
2775       relayoutNeeded = true;
2776     }
2777     else if ( Dali::DevelKey::DALI_KEY_CONTROL_LEFT == keyCode || Dali::DevelKey::DALI_KEY_CONTROL_RIGHT == keyCode )
2778     {
2779       // Left or Right Control key event is received before Ctrl-C/V/X key event is received
2780       // If not handle it here, any selected text will be deleted
2781
2782       // Do nothing
2783       return false;
2784     }
2785     else if ( keyEvent.IsCtrlModifier() )
2786     {
2787       bool consumed = false;
2788       if (keyName == KEY_C_NAME)
2789       {
2790         // Ctrl-C to copy the selected text
2791         TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
2792         consumed = true;
2793       }
2794       else if (keyName == KEY_V_NAME)
2795       {
2796         // Ctrl-V to paste the copied text
2797         TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE );
2798         consumed = true;
2799       }
2800       else if (keyName == KEY_X_NAME)
2801       {
2802         // Ctrl-X to cut the selected text
2803         TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
2804         consumed = true;
2805       }
2806       return consumed;
2807     }
2808     else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
2809              ( Dali::DevelKey::DALI_KEY_DELETE == keyCode ) )
2810     {
2811       textChanged = DeleteEvent( keyCode );
2812
2813       // Will request for relayout.
2814       relayoutNeeded = true;
2815     }
2816     else if( IsKey( keyEvent, Dali::DALI_KEY_POWER ) ||
2817              IsKey( keyEvent, Dali::DALI_KEY_MENU ) ||
2818              IsKey( keyEvent, Dali::DALI_KEY_HOME ) )
2819     {
2820       // Power key/Menu/Home key behaviour does not allow edit mode to resume.
2821       mImpl->ChangeState( EventData::INACTIVE );
2822
2823       // Will request for relayout.
2824       relayoutNeeded = true;
2825
2826       // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2827     }
2828     else if( ( Dali::DALI_KEY_SHIFT_LEFT == keyCode ) || ( Dali::DALI_KEY_SHIFT_RIGHT == keyCode ) )
2829     {
2830       // DALI_KEY_SHIFT_LEFT or DALI_KEY_SHIFT_RIGHT is the key code for Shift. It's sent (by the InputMethodContext?) when the predictive text is enabled
2831       // and a character is typed after the type of a upper case latin character.
2832
2833       // Do nothing.
2834       return false;
2835     }
2836     else if( ( Dali::DALI_KEY_VOLUME_UP == keyCode ) || ( Dali::DALI_KEY_VOLUME_DOWN == keyCode ) )
2837     {
2838       // This branch avoids calling the InsertText() method of the 'else' branch which can delete selected text.
2839       // Do nothing.
2840       return false;
2841     }
2842     else
2843     {
2844       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", this, keyString.c_str() );
2845
2846       if( !keyString.empty() )
2847       {
2848         // InputMethodContext is no longer handling key-events
2849         mImpl->ClearPreEditFlag();
2850
2851         InsertText( keyString, COMMIT );
2852
2853         textChanged = true;
2854
2855         // Will request for relayout.
2856         relayoutNeeded = true;
2857       }
2858
2859     }
2860
2861     if ( ( mImpl->mEventData->mState != EventData::INTERRUPTED ) &&
2862          ( mImpl->mEventData->mState != EventData::INACTIVE ) &&
2863          ( !isNullKey ) &&
2864          ( Dali::DALI_KEY_SHIFT_LEFT != keyCode ) &&
2865          ( Dali::DALI_KEY_SHIFT_RIGHT != keyCode ) &&
2866          ( Dali::DALI_KEY_VOLUME_UP != keyCode ) &&
2867          ( Dali::DALI_KEY_VOLUME_DOWN != keyCode ) )
2868     {
2869       // Should not change the state if the key is the shift send by the InputMethodContext.
2870       // Otherwise, when the state is SELECTING the text controller can't send the right
2871       // surrounding info to the InputMethodContext.
2872       mImpl->ChangeState( EventData::EDITING );
2873
2874       // Will request for relayout.
2875       relayoutNeeded = true;
2876     }
2877
2878     if( relayoutNeeded )
2879     {
2880       mImpl->RequestRelayout();
2881     }
2882   }
2883
2884   if( textChanged &&
2885       ( NULL != mImpl->mEditableControlInterface ) )
2886   {
2887     // Do this last since it provides callbacks into application code
2888     mImpl->mEditableControlInterface->TextChanged();
2889   }
2890
2891   return true;
2892 }
2893
2894 void Controller::TapEvent( unsigned int tapCount, float x, float y )
2895 {
2896   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected TapEvent" );
2897
2898   if( NULL != mImpl->mEventData )
2899   {
2900     DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
2901     EventData::State state( mImpl->mEventData->mState );
2902     bool relayoutNeeded( false );   // to avoid unnecessary relayouts when tapping an empty text-field
2903
2904     if( mImpl->IsClipboardVisible() )
2905     {
2906       if( EventData::INACTIVE == state || EventData::EDITING == state)
2907       {
2908         mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2909       }
2910       relayoutNeeded = true;
2911     }
2912     else if( 1u == tapCount )
2913     {
2914       if( EventData::EDITING_WITH_POPUP == state || EventData::EDITING_WITH_PASTE_POPUP == state )
2915       {
2916         mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );  // If Popup shown hide it here so can be shown again if required.
2917       }
2918
2919       if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != state ) )
2920       {
2921         mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
2922         relayoutNeeded = true;
2923       }
2924       else
2925       {
2926         if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
2927         {
2928           // Hide placeholder text
2929           ResetText();
2930         }
2931
2932         if( EventData::INACTIVE == state )
2933         {
2934           mImpl->ChangeState( EventData::EDITING );
2935         }
2936         else if( !mImpl->IsClipboardEmpty() )
2937         {
2938           mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
2939         }
2940         relayoutNeeded = true;
2941       }
2942     }
2943     else if( 2u == tapCount )
2944     {
2945       if( mImpl->mEventData->mSelectionEnabled &&
2946           mImpl->IsShowingRealText() )
2947       {
2948         relayoutNeeded = true;
2949         mImpl->mEventData->mIsLeftHandleSelected = true;
2950         mImpl->mEventData->mIsRightHandleSelected = true;
2951       }
2952     }
2953
2954     // Handles & cursors must be repositioned after Relayout() i.e. after the Model has been updated
2955     if( relayoutNeeded )
2956     {
2957       Event event( Event::TAP_EVENT );
2958       event.p1.mUint = tapCount;
2959       event.p2.mFloat = x;
2960       event.p3.mFloat = y;
2961       mImpl->mEventData->mEventQueue.push_back( event );
2962
2963       mImpl->RequestRelayout();
2964     }
2965   }
2966
2967   // Reset keyboard as tap event has occurred.
2968   mImpl->ResetInputMethodContext();
2969 }
2970
2971 void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
2972 {
2973   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
2974
2975   if( NULL != mImpl->mEventData )
2976   {
2977     Event event( Event::PAN_EVENT );
2978     event.p1.mInt = state;
2979     event.p2.mFloat = displacement.x;
2980     event.p3.mFloat = displacement.y;
2981     mImpl->mEventData->mEventQueue.push_back( event );
2982
2983     mImpl->RequestRelayout();
2984   }
2985 }
2986
2987 void Controller::LongPressEvent( Gesture::State state, float x, float y  )
2988 {
2989   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
2990
2991   if( ( state == Gesture::Started ) &&
2992       ( NULL != mImpl->mEventData ) )
2993   {
2994     // The 1st long-press on inactive text-field is treated as tap
2995     if( EventData::INACTIVE == mImpl->mEventData->mState )
2996     {
2997       mImpl->ChangeState( EventData::EDITING );
2998
2999       Event event( Event::TAP_EVENT );
3000       event.p1.mUint = 1;
3001       event.p2.mFloat = x;
3002       event.p3.mFloat = y;
3003       mImpl->mEventData->mEventQueue.push_back( event );
3004
3005       mImpl->RequestRelayout();
3006     }
3007     else if( !mImpl->IsShowingRealText() )
3008     {
3009       Event event( Event::LONG_PRESS_EVENT );
3010       event.p1.mInt = state;
3011       event.p2.mFloat = x;
3012       event.p3.mFloat = y;
3013       mImpl->mEventData->mEventQueue.push_back( event );
3014       mImpl->RequestRelayout();
3015     }
3016     else if( !mImpl->IsClipboardVisible() )
3017     {
3018       // Reset the InputMethodContext to commit the pre-edit before selecting the text.
3019       mImpl->ResetInputMethodContext();
3020
3021       Event event( Event::LONG_PRESS_EVENT );
3022       event.p1.mInt = state;
3023       event.p2.mFloat = x;
3024       event.p3.mFloat = y;
3025       mImpl->mEventData->mEventQueue.push_back( event );
3026       mImpl->RequestRelayout();
3027
3028       mImpl->mEventData->mIsLeftHandleSelected = true;
3029       mImpl->mEventData->mIsRightHandleSelected = true;
3030     }
3031   }
3032 }
3033
3034 void Controller::SelectEvent( float x, float y, bool selectAll )
3035 {
3036   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
3037
3038   if( NULL != mImpl->mEventData )
3039   {
3040     if( selectAll )
3041     {
3042       Event event( Event::SELECT_ALL );
3043       mImpl->mEventData->mEventQueue.push_back( event );
3044     }
3045     else
3046     {
3047       Event event( Event::SELECT );
3048       event.p2.mFloat = x;
3049       event.p3.mFloat = y;
3050       mImpl->mEventData->mEventQueue.push_back( event );
3051     }
3052
3053     mImpl->mEventData->mCheckScrollAmount = true;
3054     mImpl->mEventData->mIsLeftHandleSelected = true;
3055     mImpl->mEventData->mIsRightHandleSelected = true;
3056     mImpl->RequestRelayout();
3057   }
3058 }
3059
3060 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
3061 {
3062   // Whether the text needs to be relaid-out.
3063   bool requestRelayout = false;
3064
3065   // Whether to retrieve the text and cursor position to be sent to the InputMethodContext.
3066   bool retrieveText = false;
3067   bool retrieveCursor = false;
3068
3069   switch( inputMethodContextEvent.eventName )
3070   {
3071     case InputMethodContext::COMMIT:
3072     {
3073       InsertText( inputMethodContextEvent.predictiveString, Text::Controller::COMMIT );
3074       requestRelayout = true;
3075       retrieveCursor = true;
3076       break;
3077     }
3078     case InputMethodContext::PRE_EDIT:
3079     {
3080       InsertText( inputMethodContextEvent.predictiveString, Text::Controller::PRE_EDIT );
3081       requestRelayout = true;
3082       retrieveCursor = true;
3083       break;
3084     }
3085     case InputMethodContext::DELETE_SURROUNDING:
3086     {
3087       const bool textDeleted = RemoveText( inputMethodContextEvent.cursorOffset,
3088                                            inputMethodContextEvent.numberOfChars,
3089                                            DONT_UPDATE_INPUT_STYLE );
3090
3091       if( textDeleted )
3092       {
3093         if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3094             !mImpl->IsPlaceholderAvailable() )
3095         {
3096           mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3097         }
3098         else
3099         {
3100           ShowPlaceholderText();
3101         }
3102         mImpl->mEventData->mUpdateCursorPosition = true;
3103         mImpl->mEventData->mScrollAfterDelete = true;
3104
3105         requestRelayout = true;
3106       }
3107       break;
3108     }
3109     case InputMethodContext::GET_SURROUNDING:
3110     {
3111       retrieveText = true;
3112       retrieveCursor = true;
3113       break;
3114     }
3115     case InputMethodContext::PRIVATE_COMMAND:
3116     {
3117       // PRIVATECOMMAND event is just for getting the private command message
3118       retrieveText = true;
3119       retrieveCursor = true;
3120       break;
3121     }
3122     case InputMethodContext::VOID:
3123     {
3124       // do nothing
3125       break;
3126     }
3127   } // end switch
3128
3129   if( requestRelayout )
3130   {
3131     mImpl->mOperationsPending = ALL_OPERATIONS;
3132     mImpl->RequestRelayout();
3133   }
3134
3135   std::string text;
3136   CharacterIndex cursorPosition = 0u;
3137   Length numberOfWhiteSpaces = 0u;
3138
3139   if( retrieveCursor )
3140   {
3141     numberOfWhiteSpaces = mImpl->GetNumberOfWhiteSpaces( 0u );
3142
3143     cursorPosition = mImpl->GetLogicalCursorPosition();
3144
3145     if( cursorPosition < numberOfWhiteSpaces )
3146     {
3147       cursorPosition = 0u;
3148     }
3149     else
3150     {
3151       cursorPosition -= numberOfWhiteSpaces;
3152     }
3153   }
3154
3155   if( retrieveText )
3156   {
3157     if( !mImpl->IsShowingPlaceholderText() )
3158     {
3159       // Retrieves the normal text string.
3160       mImpl->GetText( numberOfWhiteSpaces, text );
3161     }
3162     else
3163     {
3164       // When the current text is Placeholder Text, the surrounding text should be empty string.
3165       // It means DALi should send empty string ("") to IME.
3166       text = "";
3167     }
3168   }
3169
3170   InputMethodContext::CallbackData callbackData( ( retrieveText || retrieveCursor ), cursorPosition, text, false );
3171
3172   if( requestRelayout &&
3173       ( NULL != mImpl->mEditableControlInterface ) )
3174   {
3175     // Do this last since it provides callbacks into application code
3176     mImpl->mEditableControlInterface->TextChanged();
3177   }
3178
3179   return callbackData;
3180 }
3181
3182 void Controller::PasteClipboardItemEvent()
3183 {
3184   // Retrieve the clipboard contents first
3185   ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
3186   std::string stringToPaste( notifier.GetContent() );
3187
3188   // Commit the current pre-edit text; the contents of the clipboard should be appended
3189   mImpl->ResetInputMethodContext();
3190
3191   // Temporary disable hiding clipboard
3192   mImpl->SetClipboardHideEnable( false );
3193
3194   // Paste
3195   PasteText( stringToPaste );
3196
3197   mImpl->SetClipboardHideEnable( true );
3198 }
3199
3200 // protected : Inherit from Text::Decorator::ControllerInterface.
3201
3202 void Controller::GetTargetSize( Vector2& targetSize )
3203 {
3204   targetSize = mImpl->mModel->mVisualModel->mControlSize;
3205 }
3206
3207 void Controller::AddDecoration( Actor& actor, bool needsClipping )
3208 {
3209   if( NULL != mImpl->mEditableControlInterface )
3210   {
3211     mImpl->mEditableControlInterface->AddDecoration( actor, needsClipping );
3212   }
3213 }
3214
3215 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
3216 {
3217   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected DecorationEvent" );
3218
3219   if( NULL != mImpl->mEventData )
3220   {
3221     switch( handleType )
3222     {
3223       case GRAB_HANDLE:
3224       {
3225         Event event( Event::GRAB_HANDLE_EVENT );
3226         event.p1.mUint  = state;
3227         event.p2.mFloat = x;
3228         event.p3.mFloat = y;
3229
3230         mImpl->mEventData->mEventQueue.push_back( event );
3231         break;
3232       }
3233       case LEFT_SELECTION_HANDLE:
3234       {
3235         Event event( Event::LEFT_SELECTION_HANDLE_EVENT );
3236         event.p1.mUint  = state;
3237         event.p2.mFloat = x;
3238         event.p3.mFloat = y;
3239
3240         mImpl->mEventData->mEventQueue.push_back( event );
3241         break;
3242       }
3243       case RIGHT_SELECTION_HANDLE:
3244       {
3245         Event event( Event::RIGHT_SELECTION_HANDLE_EVENT );
3246         event.p1.mUint  = state;
3247         event.p2.mFloat = x;
3248         event.p3.mFloat = y;
3249
3250         mImpl->mEventData->mEventQueue.push_back( event );
3251         break;
3252       }
3253       case LEFT_SELECTION_HANDLE_MARKER:
3254       case RIGHT_SELECTION_HANDLE_MARKER:
3255       {
3256         // Markers do not move the handles.
3257         break;
3258       }
3259       case HANDLE_TYPE_COUNT:
3260       {
3261         DALI_ASSERT_DEBUG( !"Controller::HandleEvent. Unexpected handle type" );
3262       }
3263     }
3264
3265     mImpl->RequestRelayout();
3266   }
3267 }
3268
3269 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
3270
3271 void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button )
3272 {
3273   if( NULL == mImpl->mEventData )
3274   {
3275     return;
3276   }
3277
3278   switch( button )
3279   {
3280     case Toolkit::TextSelectionPopup::CUT:
3281     {
3282       mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
3283       mImpl->mOperationsPending = ALL_OPERATIONS;
3284
3285       if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
3286           !mImpl->IsPlaceholderAvailable() )
3287       {
3288         mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
3289       }
3290       else
3291       {
3292         ShowPlaceholderText();
3293       }
3294
3295       mImpl->mEventData->mUpdateCursorPosition = true;
3296       mImpl->mEventData->mScrollAfterDelete = true;
3297
3298       mImpl->RequestRelayout();
3299
3300       if( NULL != mImpl->mEditableControlInterface )
3301       {
3302         mImpl->mEditableControlInterface->TextChanged();
3303       }
3304       break;
3305     }
3306     case Toolkit::TextSelectionPopup::COPY:
3307     {
3308       mImpl->SendSelectionToClipboard( false ); // Text not modified
3309
3310       mImpl->mEventData->mUpdateCursorPosition = true;
3311
3312       mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
3313       break;
3314     }
3315     case Toolkit::TextSelectionPopup::PASTE:
3316     {
3317       mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
3318       break;
3319     }
3320     case Toolkit::TextSelectionPopup::SELECT:
3321     {
3322       const Vector2& currentCursorPosition = mImpl->mEventData->mDecorator->GetPosition( PRIMARY_CURSOR );
3323
3324       if( mImpl->mEventData->mSelectionEnabled )
3325       {
3326         // Creates a SELECT event.
3327         SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
3328       }
3329       break;
3330     }
3331     case Toolkit::TextSelectionPopup::SELECT_ALL:
3332     {
3333       // Creates a SELECT_ALL event
3334       SelectEvent( 0.f, 0.f, true );
3335       break;
3336     }
3337     case Toolkit::TextSelectionPopup::CLIPBOARD:
3338     {
3339       mImpl->ShowClipboard();
3340       break;
3341     }
3342     case Toolkit::TextSelectionPopup::NONE:
3343     {
3344       // Nothing to do.
3345       break;
3346     }
3347   }
3348 }
3349
3350 void Controller::DisplayTimeExpired()
3351 {
3352   mImpl->mEventData->mUpdateCursorPosition = true;
3353   // Apply modifications to the model
3354   mImpl->mOperationsPending = ALL_OPERATIONS;
3355
3356   mImpl->RequestRelayout();
3357 }
3358
3359 // private : Update.
3360
3361 void Controller::InsertText( const std::string& text, Controller::InsertType type )
3362 {
3363   bool removedPrevious = false;
3364   bool removedSelected = false;
3365   bool maxLengthReached = false;
3366
3367   DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected InsertText" )
3368
3369   if( NULL == mImpl->mEventData )
3370   {
3371     return;
3372   }
3373
3374   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n",
3375                  this, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"),
3376                  mImpl->mEventData->mPrimaryCursorPosition, mImpl->mEventData->mPreEditFlag, mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3377
3378   // TODO: At the moment the underline runs are only for pre-edit.
3379   mImpl->mModel->mVisualModel->mUnderlineRuns.Clear();
3380
3381   // Remove the previous InputMethodContext pre-edit.
3382   if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
3383   {
3384     removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
3385                                   mImpl->mEventData->mPreEditLength,
3386                                   DONT_UPDATE_INPUT_STYLE );
3387
3388     mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
3389     mImpl->mEventData->mPreEditLength = 0u;
3390   }
3391   else
3392   {
3393     // Remove the previous Selection.
3394     removedSelected = RemoveSelectedText();
3395
3396   }
3397
3398   Vector<Character> utf32Characters;
3399   Length characterCount = 0u;
3400
3401   if( !text.empty() )
3402   {
3403     //  Convert text into UTF-32
3404     utf32Characters.Resize( text.size() );
3405
3406     // This is a bit horrible but std::string returns a (signed) char*
3407     const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
3408
3409     // Transform a text array encoded in utf8 into an array encoded in utf32.
3410     // It returns the actual number of characters.
3411     characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
3412     utf32Characters.Resize( characterCount );
3413
3414     DALI_ASSERT_DEBUG( text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length" );
3415     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count() );
3416   }
3417
3418   if( 0u != utf32Characters.Count() ) // Check if Utf8ToUtf32 conversion succeeded
3419   {
3420     // The placeholder text is no longer needed
3421     if( mImpl->IsShowingPlaceholderText() )
3422     {
3423       ResetText();
3424     }
3425
3426     mImpl->ChangeState( EventData::EDITING );
3427
3428     // Handle the InputMethodContext (predicitive text) state changes
3429     if( COMMIT == type )
3430     {
3431       // InputMethodContext is no longer handling key-events
3432       mImpl->ClearPreEditFlag();
3433     }
3434     else // PRE_EDIT
3435     {
3436       if( !mImpl->mEventData->mPreEditFlag )
3437       {
3438         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" );
3439
3440         // Record the start of the pre-edit text
3441         mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition;
3442       }
3443
3444       mImpl->mEventData->mPreEditLength = utf32Characters.Count();
3445       mImpl->mEventData->mPreEditFlag = true;
3446
3447       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", mImpl->mEventData->mPreEditStartPosition, mImpl->mEventData->mPreEditLength );
3448     }
3449
3450     const Length numberOfCharactersInModel = mImpl->mModel->mLogicalModel->mText.Count();
3451
3452     // Restrict new text to fit within Maximum characters setting.
3453     Length maxSizeOfNewText = std::min( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
3454     maxLengthReached = ( characterCount > maxSizeOfNewText );
3455
3456     // The cursor position.
3457     CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3458
3459     // Update the text's style.
3460
3461     // Updates the text style runs by adding characters.
3462     mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
3463
3464     // Get the character index from the cursor index.
3465     const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
3466
3467     // Retrieve the text's style for the given index.
3468     InputStyle style;
3469     mImpl->RetrieveDefaultInputStyle( style );
3470     mImpl->mModel->mLogicalModel->RetrieveStyle( styleIndex, style );
3471
3472     // Whether to add a new text color run.
3473     const bool addColorRun = ( style.textColor != mImpl->mEventData->mInputStyle.textColor ) && !mImpl->mEventData->mInputStyle.isDefaultColor;
3474
3475     // Whether to add a new font run.
3476     const bool addFontNameRun = ( style.familyName != mImpl->mEventData->mInputStyle.familyName ) && mImpl->mEventData->mInputStyle.isFamilyDefined;
3477     const bool addFontWeightRun = ( style.weight != mImpl->mEventData->mInputStyle.weight ) && mImpl->mEventData->mInputStyle.isWeightDefined;
3478     const bool addFontWidthRun = ( style.width != mImpl->mEventData->mInputStyle.width ) && mImpl->mEventData->mInputStyle.isWidthDefined;
3479     const bool addFontSlantRun = ( style.slant != mImpl->mEventData->mInputStyle.slant ) && mImpl->mEventData->mInputStyle.isSlantDefined;
3480     const bool addFontSizeRun = ( style.size != mImpl->mEventData->mInputStyle.size ) && mImpl->mEventData->mInputStyle.isSizeDefined ;
3481
3482     // Add style runs.
3483     if( addColorRun )
3484     {
3485       const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
3486       mImpl->mModel->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
3487
3488       ColorRun& colorRun = *( mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
3489       colorRun.color = mImpl->mEventData->mInputStyle.textColor;
3490       colorRun.characterRun.characterIndex = cursorIndex;
3491       colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3492     }
3493
3494     if( addFontNameRun   ||
3495         addFontWeightRun ||
3496         addFontWidthRun  ||
3497         addFontSlantRun  ||
3498         addFontSizeRun )
3499     {
3500       const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Count();
3501       mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Resize( numberOfRuns + 1u );
3502
3503       FontDescriptionRun& fontDescriptionRun = *( mImpl->mModel->mLogicalModel->mFontDescriptionRuns.Begin() + numberOfRuns );
3504
3505       if( addFontNameRun )
3506       {
3507         fontDescriptionRun.familyLength = mImpl->mEventData->mInputStyle.familyName.size();
3508         fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
3509         memcpy( fontDescriptionRun.familyName, mImpl->mEventData->mInputStyle.familyName.c_str(), fontDescriptionRun.familyLength );
3510         fontDescriptionRun.familyDefined = true;
3511
3512         // The memory allocated for the font family name is freed when the font description is removed from the logical model.
3513       }
3514
3515       if( addFontWeightRun )
3516       {
3517         fontDescriptionRun.weight = mImpl->mEventData->mInputStyle.weight;
3518         fontDescriptionRun.weightDefined = true;
3519       }
3520
3521       if( addFontWidthRun )
3522       {
3523         fontDescriptionRun.width = mImpl->mEventData->mInputStyle.width;
3524         fontDescriptionRun.widthDefined = true;
3525       }
3526
3527       if( addFontSlantRun )
3528       {
3529         fontDescriptionRun.slant = mImpl->mEventData->mInputStyle.slant;
3530         fontDescriptionRun.slantDefined = true;
3531       }
3532
3533       if( addFontSizeRun )
3534       {
3535         fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
3536         fontDescriptionRun.sizeDefined = true;
3537       }
3538
3539       fontDescriptionRun.characterRun.characterIndex = cursorIndex;
3540       fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
3541     }
3542
3543     // Insert at current cursor position.
3544     Vector<Character>& modifyText = mImpl->mModel->mLogicalModel->mText;
3545
3546     if( cursorIndex < numberOfCharactersInModel )
3547     {
3548       modifyText.Insert( modifyText.Begin() + cursorIndex, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3549     }
3550     else
3551     {
3552       modifyText.Insert( modifyText.End(), utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText );
3553     }
3554
3555     // Mark the first paragraph to be updated.
3556     if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3557     {
3558       mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3559       mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3560       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
3561       mImpl->mTextUpdateInfo.mClearAll = true;
3562     }
3563     else
3564     {
3565       mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3566       mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
3567     }
3568
3569     // Update the cursor index.
3570     cursorIndex += maxSizeOfNewText;
3571
3572     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition );
3573   }
3574
3575   if( ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) &&
3576       mImpl->IsPlaceholderAvailable() )
3577   {
3578     // Show place-holder if empty after removing the pre-edit text
3579     ShowPlaceholderText();
3580     mImpl->mEventData->mUpdateCursorPosition = true;
3581     mImpl->ClearPreEditFlag();
3582   }
3583   else if( removedPrevious ||
3584            removedSelected ||
3585            ( 0 != utf32Characters.Count() ) )
3586   {
3587     // Queue an inserted event
3588     mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
3589
3590     mImpl->mEventData->mUpdateCursorPosition = true;
3591     if( removedSelected )
3592     {
3593       mImpl->mEventData->mScrollAfterDelete = true;
3594     }
3595     else
3596     {
3597       mImpl->mEventData->mScrollAfterUpdatePosition = true;
3598     }
3599   }
3600
3601   if( maxLengthReached )
3602   {
3603     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", mImpl->mModel->mLogicalModel->mText.Count() );
3604
3605     mImpl->ResetInputMethodContext();
3606
3607     if( NULL != mImpl->mEditableControlInterface )
3608     {
3609       // Do this last since it provides callbacks into application code
3610       mImpl->mEditableControlInterface->MaxLengthReached();
3611     }
3612   }
3613 }
3614
3615 void Controller::PasteText( const std::string& stringToPaste )
3616 {
3617   InsertText( stringToPaste, Text::Controller::COMMIT );
3618   mImpl->ChangeState( EventData::EDITING );
3619   mImpl->RequestRelayout();
3620
3621   if( NULL != mImpl->mEditableControlInterface )
3622   {
3623     // Do this last since it provides callbacks into application code
3624     mImpl->mEditableControlInterface->TextChanged();
3625   }
3626 }
3627
3628 bool Controller::RemoveText( int cursorOffset,
3629                              int numberOfCharacters,
3630                              UpdateInputStyleType type )
3631 {
3632   bool removed = false;
3633
3634   if( NULL == mImpl->mEventData )
3635   {
3636     return removed;
3637   }
3638
3639   DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n",
3640                  this, mImpl->mModel->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters );
3641
3642   if( !mImpl->IsShowingPlaceholderText() )
3643   {
3644     // Delete at current cursor position
3645     Vector<Character>& currentText = mImpl->mModel->mLogicalModel->mText;
3646     CharacterIndex& oldCursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
3647
3648     CharacterIndex cursorIndex = 0;
3649
3650     // Validate the cursor position & number of characters
3651     if( ( static_cast< int >( mImpl->mEventData->mPrimaryCursorPosition ) + cursorOffset ) >= 0 )
3652     {
3653       cursorIndex = mImpl->mEventData->mPrimaryCursorPosition + cursorOffset;
3654     }
3655
3656     if( ( cursorIndex + numberOfCharacters ) > currentText.Count() )
3657     {
3658       numberOfCharacters = currentText.Count() - cursorIndex;
3659     }
3660
3661     if( mImpl->mEventData->mPreEditFlag || // If the preedit flag is enabled, it means two (or more) of them came together i.e. when two keys have been pressed at the same time.
3662         ( ( cursorIndex + numberOfCharacters ) <= mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) )
3663     {
3664       // Mark the paragraphs to be updated.
3665       if( Layout::Engine::SINGLE_LINE_BOX == mImpl->mLayoutEngine.GetLayout() )
3666       {
3667         mImpl->mTextUpdateInfo.mCharacterIndex = 0;
3668         mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
3669         mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
3670         mImpl->mTextUpdateInfo.mClearAll = true;
3671       }
3672       else
3673       {
3674         mImpl->mTextUpdateInfo.mCharacterIndex = std::min( cursorIndex, mImpl->mTextUpdateInfo.mCharacterIndex );
3675         mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
3676       }
3677
3678       // Update the input style and remove the text's style before removing the text.
3679
3680       if( UPDATE_INPUT_STYLE == type )
3681       {
3682         // Keep a copy of the current input style.
3683         InputStyle currentInputStyle;
3684         currentInputStyle.Copy( mImpl->mEventData->mInputStyle );
3685
3686         // Set first the default input style.
3687         mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
3688
3689         // Update the input style.
3690         mImpl->mModel->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
3691
3692         // Compare if the input style has changed.
3693         const bool hasInputStyleChanged = !currentInputStyle.Equal( mImpl->mEventData->mInputStyle );
3694
3695         if( hasInputStyleChanged )
3696         {
3697           const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask( mImpl->mEventData->mInputStyle );
3698           // Queue the input style changed signal.
3699           mImpl->mEventData->mInputStyleChangedQueue.PushBack( styleChangedMask );
3700         }
3701       }
3702
3703       // Updates the text style runs by removing characters. Runs with no characters are removed.
3704       mImpl->mModel->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
3705
3706       // Remove the characters.
3707       Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
3708       Vector<Character>::Iterator last  = first + numberOfCharacters;
3709
3710       currentText.Erase( first, last );
3711
3712       // Cursor position retreat
3713       oldCursorIndex = cursorIndex;
3714
3715       mImpl->mEventData->mScrollAfterDelete = true;
3716
3717       DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
3718       removed = true;
3719     }
3720   }
3721
3722   return removed;
3723 }
3724
3725 bool Controller::RemoveSelectedText()
3726 {
3727   bool textRemoved( false );
3728
3729   if( EventData::SELECTING == mImpl->mEventData->mState )
3730   {
3731     std::string removedString;
3732     mImpl->RetrieveSelection( removedString, true );
3733
3734     if( !removedString.empty() )
3735     {
3736       textRemoved = true;
3737       mImpl->ChangeState( EventData::EDITING );
3738     }
3739   }
3740
3741   return textRemoved;
3742 }
3743
3744 // private : Relayout.
3745
3746 bool Controller::DoRelayout( const Size& size,
3747                              OperationsMask operationsRequired,
3748                              Size& layoutSize )
3749 {
3750   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout %p size %f,%f\n", this, size.width, size.height );
3751   bool viewUpdated( false );
3752
3753   // Calculate the operations to be done.
3754   const OperationsMask operations = static_cast<OperationsMask>( mImpl->mOperationsPending & operationsRequired );
3755
3756   const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
3757   const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
3758
3759   // Get the current layout size.
3760   layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3761
3762   if( NO_OPERATION != ( LAYOUT & operations ) )
3763   {
3764     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
3765
3766     // Some vectors with data needed to layout and reorder may be void
3767     // after the first time the text has been laid out.
3768     // Fill the vectors again.
3769
3770     // Calculate the number of glyphs to layout.
3771     const Vector<GlyphIndex>& charactersToGlyph = mImpl->mModel->mVisualModel->mCharactersToGlyph;
3772     const Vector<Length>& glyphsPerCharacter = mImpl->mModel->mVisualModel->mGlyphsPerCharacter;
3773     const GlyphIndex* const charactersToGlyphBuffer = charactersToGlyph.Begin();
3774     const Length* const glyphsPerCharacterBuffer = glyphsPerCharacter.Begin();
3775
3776     const CharacterIndex lastIndex = startIndex + ( ( requestedNumberOfCharacters > 0u ) ? requestedNumberOfCharacters - 1u : 0u );
3777     const GlyphIndex startGlyphIndex = mImpl->mTextUpdateInfo.mStartGlyphIndex;
3778
3779     // Make sure the index is not out of bound
3780     if ( charactersToGlyph.Count() != glyphsPerCharacter.Count() ||
3781          requestedNumberOfCharacters > charactersToGlyph.Count() ||
3782          ( lastIndex > charactersToGlyph.Count() && charactersToGlyph.Count() > 0u ) )
3783     {
3784       std::string currentText;
3785       GetText( currentText );
3786
3787       DALI_LOG_ERROR( "Controller::DoRelayout: Attempting to access invalid buffer\n" );
3788       DALI_LOG_ERROR( "Current text is: %s\n", currentText.c_str() );
3789       DALI_LOG_ERROR( "startIndex: %u, lastIndex: %u, requestedNumberOfCharacters: %u, charactersToGlyph.Count = %lu, glyphsPerCharacter.Count = %lu\n", startIndex, lastIndex, requestedNumberOfCharacters, charactersToGlyph.Count(), glyphsPerCharacter.Count());
3790
3791       return false;
3792     }
3793
3794     const Length numberOfGlyphs = ( requestedNumberOfCharacters > 0u ) ? *( charactersToGlyphBuffer + lastIndex ) + *( glyphsPerCharacterBuffer + lastIndex ) - startGlyphIndex : 0u;
3795     const Length totalNumberOfGlyphs = mImpl->mModel->mVisualModel->mGlyphs.Count();
3796
3797     if( 0u == totalNumberOfGlyphs )
3798     {
3799       if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3800       {
3801         mImpl->mModel->mVisualModel->SetLayoutSize( Size::ZERO );
3802       }
3803
3804       // Nothing else to do if there is no glyphs.
3805       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout no glyphs, view updated true\n" );
3806       return true;
3807     }
3808
3809     const Vector<LineBreakInfo>& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo;
3810     const Vector<WordBreakInfo>& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo;
3811     const Vector<CharacterDirection>& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections;
3812     const Vector<GlyphInfo>& glyphs = mImpl->mModel->mVisualModel->mGlyphs;
3813     const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
3814     const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
3815     const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
3816     const float outlineWidth = static_cast<float>( mImpl->mModel->GetOutlineWidth() );
3817
3818     // Set the layout parameters.
3819     Layout::Parameters layoutParameters( size,
3820                                          textBuffer,
3821                                          lineBreakInfo.Begin(),
3822                                          wordBreakInfo.Begin(),
3823                                          ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL,
3824                                          glyphs.Begin(),
3825                                          glyphsToCharactersMap.Begin(),
3826                                          charactersPerGlyph.Begin(),
3827                                          charactersToGlyphBuffer,
3828                                          glyphsPerCharacterBuffer,
3829                                          totalNumberOfGlyphs,
3830                                          mImpl->mModel->mHorizontalAlignment,
3831                                          mImpl->mModel->mLineWrapMode,
3832                                          outlineWidth,
3833                                          mImpl->mModel->mIgnoreSpacesAfterText,
3834                                          mImpl->mModel->mMatchSystemLanguageDirection );
3835
3836     // Resize the vector of positions to have the same size than the vector of glyphs.
3837     Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
3838     glyphPositions.Resize( totalNumberOfGlyphs );
3839
3840     // Whether the last character is a new paragraph character.
3841     mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph =  TextAbstraction::IsNewParagraph( *( textBuffer + ( mImpl->mModel->mLogicalModel->mText.Count() - 1u ) ) );
3842     layoutParameters.isLastNewParagraph = mImpl->mTextUpdateInfo.mIsLastCharacterNewParagraph;
3843
3844     // The initial glyph and the number of glyphs to layout.
3845     layoutParameters.startGlyphIndex = startGlyphIndex;
3846     layoutParameters.numberOfGlyphs = numberOfGlyphs;
3847     layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
3848     layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
3849
3850     // Update the ellipsis
3851     bool elideTextEnabled = mImpl->mModel->mElideEnabled;
3852
3853     if( NULL != mImpl->mEventData )
3854     {
3855       if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
3856       {
3857         elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
3858       }
3859       else if( EventData::INACTIVE != mImpl->mEventData->mState )
3860       {
3861         // Disable ellipsis when editing
3862         elideTextEnabled = false;
3863       }
3864
3865       // Reset the scroll position in inactive state
3866       if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
3867       {
3868         ResetScrollPosition();
3869       }
3870     }
3871
3872     // Update the visual model.
3873     bool isAutoScrollEnabled = mImpl->mIsAutoScrollEnabled;
3874     Size newLayoutSize;
3875     viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
3876                                                    glyphPositions,
3877                                                    mImpl->mModel->mVisualModel->mLines,
3878                                                    newLayoutSize,
3879                                                    elideTextEnabled,
3880                                                    isAutoScrollEnabled );
3881     mImpl->mIsAutoScrollEnabled = isAutoScrollEnabled;
3882
3883     viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
3884
3885     if( viewUpdated )
3886     {
3887       layoutSize = newLayoutSize;
3888
3889       if( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
3890       {
3891         mImpl->mIsTextDirectionRTL = false;
3892       }
3893
3894       // Reorder the lines
3895       if( NO_OPERATION != ( REORDER & operations ) )
3896       {
3897         Vector<BidirectionalParagraphInfoRun>& bidirectionalInfo = mImpl->mModel->mLogicalModel->mBidirectionalParagraphInfo;
3898         Vector<BidirectionalLineInfoRun>& bidirectionalLineInfo = mImpl->mModel->mLogicalModel->mBidirectionalLineInfo;
3899
3900         // Check first if there are paragraphs with bidirectional info.
3901         if( 0u != bidirectionalInfo.Count() )
3902         {
3903           // Get the lines
3904           const Length numberOfLines = mImpl->mModel->mVisualModel->mLines.Count();
3905
3906           // Reorder the lines.
3907           bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters.
3908           ReorderLines( bidirectionalInfo,
3909                         startIndex,
3910                         requestedNumberOfCharacters,
3911                         mImpl->mModel->mVisualModel->mLines,
3912                         bidirectionalLineInfo );
3913
3914           // Set the bidirectional info per line into the layout parameters.
3915           layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin();
3916           layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count();
3917
3918           // Re-layout the text. Reorder those lines with right to left characters.
3919           mImpl->mLayoutEngine.ReLayoutRightToLeftLines( layoutParameters,
3920                                                          startIndex,
3921                                                          requestedNumberOfCharacters,
3922                                                          glyphPositions );
3923
3924           if ( ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) ) && ( numberOfLines > 0 ) )
3925           {
3926             const LineRun* const firstline = mImpl->mModel->mVisualModel->mLines.Begin();
3927             if ( firstline )
3928             {
3929               mImpl->mIsTextDirectionRTL = firstline->direction;
3930             }
3931           }
3932         }
3933       } // REORDER
3934
3935       // Sets the layout size.
3936       if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
3937       {
3938         mImpl->mModel->mVisualModel->SetLayoutSize( layoutSize );
3939       }
3940     } // view updated
3941   }
3942
3943   if( NO_OPERATION != ( ALIGN & operations ) )
3944   {
3945     // The laid-out lines.
3946     Vector<LineRun>& lines = mImpl->mModel->mVisualModel->mLines;
3947
3948     // Need to align with the control's size as the text may contain lines
3949     // starting either with left to right text or right to left.
3950     mImpl->mLayoutEngine.Align( size,
3951                                 startIndex,
3952                                 requestedNumberOfCharacters,
3953                                 mImpl->mModel->mHorizontalAlignment,
3954                                 lines,
3955                                 mImpl->mModel->mAlignmentOffset,
3956                                 mImpl->mLayoutDirection,
3957                                 mImpl->mModel->mMatchSystemLanguageDirection );
3958
3959     viewUpdated = true;
3960   }
3961 #if defined(DEBUG_ENABLED)
3962   std::string currentText;
3963   GetText( currentText );
3964   DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::DoRelayout [%p] mImpl->mIsTextDirectionRTL[%s] [%s]\n", this, (mImpl->mIsTextDirectionRTL)?"true":"false",  currentText.c_str() );
3965 #endif
3966   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--Controller::DoRelayout, view updated %s\n", ( viewUpdated ? "true" : "false" ) );
3967   return viewUpdated;
3968 }
3969
3970 void Controller::CalculateVerticalOffset( const Size& controlSize )
3971 {
3972   Size layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
3973
3974   if( fabsf( layoutSize.height ) < Math::MACHINE_EPSILON_1000 )
3975   {
3976     // Get the line height of the default font.
3977     layoutSize.height = mImpl->GetDefaultFontLineHeight();
3978   }
3979
3980   switch( mImpl->mModel->mVerticalAlignment )
3981   {
3982     case VerticalAlignment::TOP:
3983     {
3984       mImpl->mModel->mScrollPosition.y = 0.f;
3985       break;
3986     }
3987     case VerticalAlignment::CENTER:
3988     {
3989       mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
3990       break;
3991     }
3992     case VerticalAlignment::BOTTOM:
3993     {
3994       mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
3995       break;
3996     }
3997   }
3998 }
3999
4000 // private : Events.
4001
4002 void Controller::ProcessModifyEvents()
4003 {
4004   Vector<ModifyEvent>& events = mImpl->mModifyEvents;
4005
4006   if( 0u == events.Count() )
4007   {
4008     // Nothing to do.
4009     return;
4010   }
4011
4012   for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
4013          endIt = events.End();
4014        it != endIt;
4015        ++it )
4016   {
4017     const ModifyEvent& event = *it;
4018
4019     if( ModifyEvent::TEXT_REPLACED == event.type )
4020     {
4021       // A (single) replace event should come first, otherwise we wasted time processing NOOP events
4022       DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
4023
4024       TextReplacedEvent();
4025     }
4026     else if( ModifyEvent::TEXT_INSERTED == event.type )
4027     {
4028       TextInsertedEvent();
4029     }
4030     else if( ModifyEvent::TEXT_DELETED == event.type )
4031     {
4032       // Placeholder-text cannot be deleted
4033       if( !mImpl->IsShowingPlaceholderText() )
4034       {
4035         TextDeletedEvent();
4036       }
4037     }
4038   }
4039
4040   if( NULL != mImpl->mEventData )
4041   {
4042     // When the text is being modified, delay cursor blinking
4043     mImpl->mEventData->mDecorator->DelayCursorBlink();
4044
4045     // Update selection position after modifying the text
4046     mImpl->mEventData->mLeftSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4047     mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
4048   }
4049
4050   // Discard temporary text
4051   events.Clear();
4052 }
4053
4054 void Controller::TextReplacedEvent()
4055 {
4056   // The natural size needs to be re-calculated.
4057   mImpl->mRecalculateNaturalSize = true;
4058
4059   // The text direction needs to be updated.
4060   mImpl->mUpdateTextDirection = true;
4061
4062   // Apply modifications to the model
4063   mImpl->mOperationsPending = ALL_OPERATIONS;
4064 }
4065
4066 void Controller::TextInsertedEvent()
4067 {
4068   DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextInsertedEvent" );
4069
4070   if( NULL == mImpl->mEventData )
4071   {
4072     return;
4073   }
4074
4075   mImpl->mEventData->mCheckScrollAmount = true;
4076
4077   // The natural size needs to be re-calculated.
4078   mImpl->mRecalculateNaturalSize = true;
4079
4080   // The text direction needs to be updated.
4081   mImpl->mUpdateTextDirection = true;
4082
4083   // Apply modifications to the model; TODO - Optimize this
4084   mImpl->mOperationsPending = ALL_OPERATIONS;
4085 }
4086
4087 void Controller::TextDeletedEvent()
4088 {
4089   DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "Unexpected TextDeletedEvent" );
4090
4091   if( NULL == mImpl->mEventData )
4092   {
4093     return;
4094   }
4095
4096   mImpl->mEventData->mCheckScrollAmount = true;
4097
4098   // The natural size needs to be re-calculated.
4099   mImpl->mRecalculateNaturalSize = true;
4100
4101   // The text direction needs to be updated.
4102   mImpl->mUpdateTextDirection = true;
4103
4104   // Apply modifications to the model; TODO - Optimize this
4105   mImpl->mOperationsPending = ALL_OPERATIONS;
4106 }
4107
4108 bool Controller::DeleteEvent( int keyCode )
4109 {
4110   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p KeyCode : %d \n", this, keyCode );
4111
4112   bool removed = false;
4113
4114   if( NULL == mImpl->mEventData )
4115   {
4116     return removed;
4117   }
4118
4119   // InputMethodContext is no longer handling key-events
4120   mImpl->ClearPreEditFlag();
4121
4122   if( EventData::SELECTING == mImpl->mEventData->mState )
4123   {
4124     removed = RemoveSelectedText();
4125   }
4126   else if( ( mImpl->mEventData->mPrimaryCursorPosition > 0 ) && ( keyCode == Dali::DALI_KEY_BACKSPACE) )
4127   {
4128     // Remove the character before the current cursor position
4129     removed = RemoveText( -1,
4130                           1,
4131                           UPDATE_INPUT_STYLE );
4132   }
4133   else if( keyCode == Dali::DevelKey::DALI_KEY_DELETE )
4134   {
4135     // Remove the character after the current cursor position
4136     removed = RemoveText( 0,
4137                           1,
4138                           UPDATE_INPUT_STYLE );
4139   }
4140
4141   if( removed )
4142   {
4143     if( ( 0u != mImpl->mModel->mLogicalModel->mText.Count() ) ||
4144         !mImpl->IsPlaceholderAvailable() )
4145     {
4146       mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
4147     }
4148     else
4149     {
4150       ShowPlaceholderText();
4151     }
4152     mImpl->mEventData->mUpdateCursorPosition = true;
4153     mImpl->mEventData->mScrollAfterDelete = true;
4154   }
4155
4156   return removed;
4157 }
4158
4159 // private : Helpers.
4160
4161 void Controller::ResetText()
4162 {
4163   // Reset buffers.
4164   mImpl->mModel->mLogicalModel->mText.Clear();
4165
4166   // Reset the embedded images buffer.
4167   mImpl->mModel->mLogicalModel->ClearEmbeddedImages();
4168
4169   // We have cleared everything including the placeholder-text
4170   mImpl->PlaceholderCleared();
4171
4172   mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4173   mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4174   mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
4175
4176   // Clear any previous text.
4177   mImpl->mTextUpdateInfo.mClearAll = true;
4178
4179   // The natural size needs to be re-calculated.
4180   mImpl->mRecalculateNaturalSize = true;
4181
4182   // The text direction needs to be updated.
4183   mImpl->mUpdateTextDirection = true;
4184
4185   // Apply modifications to the model
4186   mImpl->mOperationsPending = ALL_OPERATIONS;
4187 }
4188
4189 void Controller::ShowPlaceholderText()
4190 {
4191   if( mImpl->IsPlaceholderAvailable() )
4192   {
4193     DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
4194
4195     if( NULL == mImpl->mEventData )
4196     {
4197       return;
4198     }
4199
4200     mImpl->mEventData->mIsShowingPlaceholderText = true;
4201
4202     // Disable handles when showing place-holder text
4203     mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
4204     mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
4205     mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
4206
4207     const char* text( NULL );
4208     size_t size( 0 );
4209
4210     // TODO - Switch Placeholder text when changing state
4211     if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
4212         ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
4213     {
4214       text = mImpl->mEventData->mPlaceholderTextActive.c_str();
4215       size = mImpl->mEventData->mPlaceholderTextActive.size();
4216     }
4217     else
4218     {
4219       text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
4220       size = mImpl->mEventData->mPlaceholderTextInactive.size();
4221     }
4222
4223     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4224     mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4225
4226     // Reset model for showing placeholder.
4227     mImpl->mModel->mLogicalModel->mText.Clear();
4228     mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
4229
4230     // Convert text into UTF-32
4231     Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
4232     utf32Characters.Resize( size );
4233
4234     // This is a bit horrible but std::string returns a (signed) char*
4235     const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
4236
4237     // Transform a text array encoded in utf8 into an array encoded in utf32.
4238     // It returns the actual number of characters.
4239     const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
4240     utf32Characters.Resize( characterCount );
4241
4242     // The characters to be added.
4243     mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
4244
4245     // Reset the cursor position
4246     mImpl->mEventData->mPrimaryCursorPosition = 0;
4247
4248     // The natural size needs to be re-calculated.
4249     mImpl->mRecalculateNaturalSize = true;
4250
4251     // The text direction needs to be updated.
4252     mImpl->mUpdateTextDirection = true;
4253
4254     // Apply modifications to the model
4255     mImpl->mOperationsPending = ALL_OPERATIONS;
4256
4257     // Update the rest of the model during size negotiation
4258     mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
4259   }
4260 }
4261
4262 void Controller::ClearFontData()
4263 {
4264   if( mImpl->mFontDefaults )
4265   {
4266     mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
4267   }
4268
4269   // Set flags to update the model.
4270   mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
4271   mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
4272   mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
4273
4274   mImpl->mTextUpdateInfo.mClearAll = true;
4275   mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
4276   mImpl->mRecalculateNaturalSize = true;
4277
4278   mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
4279                                                            VALIDATE_FONTS            |
4280                                                            SHAPE_TEXT                |
4281                                                            BIDI_INFO                 |
4282                                                            GET_GLYPH_METRICS         |
4283                                                            LAYOUT                    |
4284                                                            UPDATE_LAYOUT_SIZE        |
4285                                                            REORDER                   |
4286                                                            ALIGN );
4287 }
4288
4289 void Controller::ClearStyleData()
4290 {
4291   mImpl->mModel->mLogicalModel->mColorRuns.Clear();
4292   mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
4293 }
4294
4295 void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
4296 {
4297   // Reset the cursor position
4298   if( NULL != mImpl->mEventData )
4299   {
4300     mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
4301
4302     // Update the cursor if it's in editing mode.
4303     if( EventData::IsEditingState( mImpl->mEventData->mState )  )
4304     {
4305       mImpl->mEventData->mUpdateCursorPosition = true;
4306     }
4307   }
4308 }
4309
4310 void Controller::ResetScrollPosition()
4311 {
4312   if( NULL != mImpl->mEventData )
4313   {
4314     // Reset the scroll position.
4315     mImpl->mModel->mScrollPosition = Vector2::ZERO;
4316     mImpl->mEventData->mScrollAfterUpdatePosition = true;
4317   }
4318 }
4319
4320 void Controller::SetControlInterface( ControlInterface* controlInterface )
4321 {
4322   mImpl->mControlInterface = controlInterface;
4323 }
4324
4325 bool Controller::ShouldClearFocusOnEscape() const
4326 {
4327   return mImpl->mShouldClearFocusOnEscape;
4328 }
4329
4330 // private : Private contructors & copy operator.
4331
4332 Controller::Controller()
4333 : mImpl( NULL )
4334 {
4335   mImpl = new Controller::Impl( NULL, NULL );
4336 }
4337
4338 Controller::Controller( ControlInterface* controlInterface )
4339 {
4340   mImpl = new Controller::Impl( controlInterface, NULL );
4341 }
4342
4343 Controller::Controller( ControlInterface* controlInterface,
4344                         EditableControlInterface* editableControlInterface )
4345 {
4346   mImpl = new Controller::Impl( controlInterface,
4347                                 editableControlInterface );
4348 }
4349
4350 // The copy constructor and operator are left unimplemented.
4351
4352 // protected : Destructor.
4353
4354 Controller::~Controller()
4355 {
4356   delete mImpl;
4357 }
4358
4359 } // namespace Text
4360
4361 } // namespace Toolkit
4362
4363 } // namespace Dali