2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/devel-api/adaptor-framework/key-devel.h>
26 #include <dali/devel-api/adaptor-framework/window-devel.h>
27 #include <dali/devel-api/common/stage.h>
28 #include <dali/devel-api/object/property-helper-devel.h>
29 #include <dali/devel-api/actors/actor-devel.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/text/text-enumerations.h>
35 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
36 #include <dali-toolkit/devel-api/text/rendering-backend.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
42 #include <dali-toolkit/internal/controls/text-controls/autofill-container-impl.h>
43 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
44 #include <dali-toolkit/internal/text/rendering/text-backend.h>
45 #include <dali-toolkit/internal/text/text-effects-style.h>
46 #include <dali-toolkit/internal/text/text-font-style.h>
47 #include <dali-toolkit/internal/text/text-view.h>
48 #include <dali-toolkit/internal/styling/style-manager-impl.h>
49 #include <dali-toolkit/devel-api/controls/control-devel.h>
50 #include <dali/integration-api/adaptor-framework/adaptor.h>
52 using namespace Dali::Toolkit::Text;
63 namespace // unnamed namespace
66 #if defined(DEBUG_ENABLED)
67 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
70 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
71 } // unnamed namespace
78 return Toolkit::TextField::New();
81 // Setup properties, signals and actions using the type-registry.
82 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
138 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
140 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
142 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableEditing", BOOLEAN, ENABLE_EDITING )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
145 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
146 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
148 DALI_TYPE_REGISTRATION_END()
150 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
152 /// Retrieves a filename from a value that is a Property::Map
153 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
155 std::string filename;
156 const Property::Map* map = value.GetMap();
159 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
162 filenameValue->Get( filename );
170 Toolkit::TextField TextField::New()
172 // Create the implementation, temporarily owned by this handle on stack
173 IntrusivePtr< TextField > impl = new TextField();
175 // Pass ownership to CustomActor handle
176 Toolkit::TextField handle( *impl );
178 // Second-phase init of the implementation
179 // This can only be done after the CustomActor connection has been made...
185 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
187 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
189 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
193 TextField& impl( GetImpl( textField ) );
194 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
195 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
199 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
201 int backend = value.Get< int >();
202 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
204 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
205 if( DevelText::RENDERING_VECTOR_BASED == backend )
207 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
210 if( impl.mRenderingBackend != backend )
212 impl.mRenderingBackend = backend;
213 impl.mRenderer.Reset();
215 // When using the vector-based rendering, the size of the GLyphs are different
216 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
217 impl.mController->SetGlyphType( glyphType );
221 case Toolkit::TextField::Property::TEXT:
223 const std::string& text = value.Get< std::string >();
224 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
226 impl.mController->SetText( text );
229 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
231 const std::string& text = value.Get< std::string >();
232 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
234 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
237 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
239 const std::string& text = value.Get< std::string >();
240 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
242 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
245 case Toolkit::TextField::Property::FONT_FAMILY:
247 const std::string& fontFamily = value.Get< std::string >();
248 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
249 impl.mController->SetDefaultFontFamily( fontFamily );
252 case Toolkit::TextField::Property::FONT_STYLE:
254 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
257 case Toolkit::TextField::Property::POINT_SIZE:
259 const float pointSize = value.Get< float >();
260 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
262 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
264 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
268 case Toolkit::TextField::Property::MAX_LENGTH:
270 const int max = value.Get< int >();
271 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
273 impl.mController->SetMaximumNumberOfCharacters( max );
276 case Toolkit::TextField::Property::EXCEED_POLICY:
278 impl.mExceedPolicy = value.Get<int>();
280 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
282 impl.EnableClipping();
286 UnparentAndReset( impl.mStencil );
288 impl.RequestTextRelayout();
291 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
293 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
294 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
296 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
297 impl.mController->SetHorizontalAlignment( alignment );
301 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
303 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
304 if( GetVerticalAlignmentEnumeration( value, alignment ) )
306 impl.mController->SetVerticalAlignment( alignment );
307 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
311 case Toolkit::TextField::Property::TEXT_COLOR:
313 const Vector4& textColor = value.Get< Vector4 >();
314 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
316 if( impl.mController->GetDefaultColor() != textColor )
318 impl.mController->SetDefaultColor( textColor );
319 impl.mController->SetInputColor( textColor );
320 impl.mRenderer.Reset();
324 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
326 const Vector4& textColor = value.Get< Vector4 >();
327 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
329 if( impl.mController->GetPlaceholderTextColor() != textColor )
331 impl.mController->SetPlaceholderTextColor( textColor );
332 impl.mRenderer.Reset();
336 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
338 const Vector4& color = value.Get< Vector4 >();
339 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
341 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
342 impl.RequestTextRelayout();
345 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
347 const Vector4& color = value.Get< Vector4 >();
348 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
350 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
351 impl.RequestTextRelayout();
354 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
356 const bool enable = value.Get< bool >();
357 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
359 impl.mController->SetEnableCursorBlink( enable );
360 impl.RequestTextRelayout();
363 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
365 const float interval = value.Get< float >();
366 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
368 impl.mDecorator->SetCursorBlinkInterval( interval );
371 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
373 const float duration = value.Get< float >();
374 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
376 impl.mDecorator->SetCursorBlinkDuration( duration );
379 case Toolkit::TextField::Property::CURSOR_WIDTH:
381 const int width = value.Get< int >();
382 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
384 impl.mDecorator->SetCursorWidth( width );
385 impl.mController->GetLayoutEngine().SetCursorWidth( width );
388 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
390 const std::string imageFileName = value.Get< std::string >();
391 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
393 if( imageFileName.size() )
395 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
396 impl.RequestTextRelayout();
400 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
402 const std::string imageFileName = value.Get< std::string >();
403 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
405 if( imageFileName.size() )
407 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
408 impl.RequestTextRelayout();
412 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
414 const float threshold = value.Get< float >();
415 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
417 impl.mDecorator->SetScrollThreshold( threshold );
420 case Toolkit::TextField::Property::SCROLL_SPEED:
422 const float speed = value.Get< float >();
423 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
425 impl.mDecorator->SetScrollSpeed( speed );
428 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
430 const std::string filename = GetImageFileNameFromPropertyValue( value );
432 if( filename.size() )
434 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
435 impl.RequestTextRelayout();
439 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
441 const std::string filename = GetImageFileNameFromPropertyValue( value );
443 if( filename.size() )
445 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
446 impl.RequestTextRelayout();
450 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
452 const std::string filename = GetImageFileNameFromPropertyValue( value );
454 if( filename.size() )
456 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
457 impl.RequestTextRelayout();
461 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
463 const std::string filename = GetImageFileNameFromPropertyValue( value );
465 if( filename.size() )
467 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
468 impl.RequestTextRelayout();
472 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
474 const std::string filename = GetImageFileNameFromPropertyValue( value );
476 if( filename.size() )
478 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
479 impl.RequestTextRelayout();
483 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
485 const std::string filename = GetImageFileNameFromPropertyValue( value );
487 if( filename.size() )
489 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
490 impl.RequestTextRelayout();
494 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
496 const Vector4 color = value.Get< Vector4 >();
497 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTION_HIGHLIGHT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
499 impl.mDecorator->SetHighlightColor( color );
500 impl.RequestTextRelayout();
503 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
505 const Rect<int> box = value.Get< Rect<int> >();
506 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p DECORATION_BOUNDING_BOX %d,%d %dx%d\n", impl.mController.Get(), box.x, box.y, box.width, box.height );
508 impl.mDecorator->SetBoundingBox( box );
509 impl.RequestTextRelayout();
512 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
514 const Property::Map* map = value.GetMap();
517 impl.mInputMethodOptions.ApplyProperty( *map );
519 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
521 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
522 if (control == textField)
524 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
528 case Toolkit::TextField::Property::INPUT_COLOR:
530 const Vector4 inputColor = value.Get< Vector4 >();
531 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), inputColor.r, inputColor.g, inputColor.b, inputColor.a );
533 impl.mController->SetInputColor( inputColor );
536 case Toolkit::TextField::Property::ENABLE_MARKUP:
538 const bool enableMarkup = value.Get<bool>();
539 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
541 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
544 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
546 const std::string& fontFamily = value.Get< std::string >();
547 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
548 impl.mController->SetInputFontFamily( fontFamily );
551 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
553 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
556 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
558 const float pointSize = value.Get< float >();
559 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
560 impl.mController->SetInputFontPointSize( pointSize );
563 case Toolkit::TextField::Property::UNDERLINE:
565 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
568 impl.mRenderer.Reset();
572 case Toolkit::TextField::Property::INPUT_UNDERLINE:
574 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
577 impl.mRenderer.Reset();
581 case Toolkit::TextField::Property::SHADOW:
583 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
586 impl.mRenderer.Reset();
590 case Toolkit::TextField::Property::INPUT_SHADOW:
592 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
595 impl.mRenderer.Reset();
599 case Toolkit::TextField::Property::EMBOSS:
601 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
604 impl.mRenderer.Reset();
608 case Toolkit::TextField::Property::INPUT_EMBOSS:
610 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
613 impl.mRenderer.Reset();
617 case Toolkit::TextField::Property::OUTLINE:
619 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
622 impl.mRenderer.Reset();
626 case Toolkit::TextField::Property::INPUT_OUTLINE:
628 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
631 impl.mRenderer.Reset();
635 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
637 const Property::Map* map = value.GetMap();
640 impl.mController->SetHiddenInputOption(*map);
644 case Toolkit::TextField::Property::PIXEL_SIZE:
646 const float pixelSize = value.Get< float >();
647 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
649 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
651 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
655 case Toolkit::TextField::Property::ENABLE_SELECTION:
657 const bool enableSelection = value.Get< bool >();
658 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
659 impl.mController->SetSelectionEnabled( enableSelection );
662 case Toolkit::TextField::Property::PLACEHOLDER:
664 const Property::Map* map = value.GetMap();
667 impl.mController->SetPlaceholderProperty( *map );
671 case Toolkit::TextField::Property::ELLIPSIS:
673 const bool ellipsis = value.Get<bool>();
674 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
676 impl.mController->SetTextElideEnabled( ellipsis );
679 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
681 const bool shiftSelection = value.Get<bool>();
682 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
684 impl.mController->SetShiftSelectionEnabled( shiftSelection );
687 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
689 const bool grabHandleEnabled = value.Get<bool>();
690 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
692 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
695 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
697 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
700 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
702 const bool grabHandlePopupEnabled = value.Get<bool>();
703 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
705 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
708 case Toolkit::DevelTextField::Property::BACKGROUND:
710 const Vector4 backgroundColor = value.Get< Vector4 >();
711 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p BACKGROUND %f,%f,%f,%f\n", impl.mController.Get(), backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a );
713 impl.mController->SetBackgroundEnabled( true );
714 impl.mController->SetBackgroundColor( backgroundColor );
717 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
719 uint32_t start = static_cast<uint32_t>(value.Get< int >());
720 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
721 impl.SetTextSelectionRange( &start, nullptr );
724 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
726 uint32_t end = static_cast<uint32_t>(value.Get< int >());
727 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
728 impl.SetTextSelectionRange( nullptr, &end );
731 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
733 const bool editable = value.Get< bool >();
734 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_EDITING %d\n", impl.mController.Get(), editable );
735 impl.SetEditable( editable );
742 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
744 Property::Value value;
746 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
750 TextField& impl( GetImpl( textField ) );
751 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
752 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
756 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
758 value = impl.mRenderingBackend;
761 case Toolkit::TextField::Property::TEXT:
764 impl.mController->GetText( text );
765 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
769 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
772 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
776 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
779 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
783 case Toolkit::TextField::Property::FONT_FAMILY:
785 value = impl.mController->GetDefaultFontFamily();
788 case Toolkit::TextField::Property::FONT_STYLE:
790 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
793 case Toolkit::TextField::Property::POINT_SIZE:
795 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
798 case Toolkit::TextField::Property::MAX_LENGTH:
800 value = impl.mController->GetMaximumNumberOfCharacters();
803 case Toolkit::TextField::Property::EXCEED_POLICY:
805 value = impl.mExceedPolicy;
808 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
810 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
814 value = std::string( name );
818 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
820 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
824 value = std::string( name );
828 case Toolkit::TextField::Property::TEXT_COLOR:
830 value = impl.mController->GetDefaultColor();
833 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
835 value = impl.mController->GetPlaceholderTextColor();
838 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
840 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
843 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
845 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
848 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
850 value = impl.mController->GetEnableCursorBlink();
853 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
855 value = impl.mDecorator->GetCursorBlinkInterval();
858 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
860 value = impl.mDecorator->GetCursorBlinkDuration();
863 case Toolkit::TextField::Property::CURSOR_WIDTH:
865 value = impl.mDecorator->GetCursorWidth();
868 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
870 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
873 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
875 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
878 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
880 value = impl.mDecorator->GetScrollThreshold();
883 case Toolkit::TextField::Property::SCROLL_SPEED:
885 value = impl.mDecorator->GetScrollSpeed();
888 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
890 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
893 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
895 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
898 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
900 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
903 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
905 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
908 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
910 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
913 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
915 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
918 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
920 value = impl.mDecorator->GetHighlightColor();
923 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
925 Rect<int> boundingBox;
926 impl.mDecorator->GetBoundingBox( boundingBox );
930 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
933 impl.mInputMethodOptions.RetrieveProperty( map );
937 case Toolkit::TextField::Property::INPUT_COLOR:
939 value = impl.mController->GetInputColor();
942 case Toolkit::TextField::Property::ENABLE_MARKUP:
944 value = impl.mController->IsMarkupProcessorEnabled();
947 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
949 value = impl.mController->GetInputFontFamily();
952 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
954 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
957 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
959 value = impl.mController->GetInputFontPointSize();
962 case Toolkit::TextField::Property::UNDERLINE:
964 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
967 case Toolkit::TextField::Property::INPUT_UNDERLINE:
969 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
972 case Toolkit::TextField::Property::SHADOW:
974 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
977 case Toolkit::TextField::Property::INPUT_SHADOW:
979 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
982 case Toolkit::TextField::Property::EMBOSS:
984 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
987 case Toolkit::TextField::Property::INPUT_EMBOSS:
989 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
992 case Toolkit::TextField::Property::OUTLINE:
994 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
997 case Toolkit::TextField::Property::INPUT_OUTLINE:
999 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1002 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1005 impl.mController->GetHiddenInputOption(map);
1009 case Toolkit::TextField::Property::PIXEL_SIZE:
1011 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1014 case Toolkit::TextField::Property::ENABLE_SELECTION:
1016 value = impl.mController->IsSelectionEnabled();
1019 case Toolkit::TextField::Property::PLACEHOLDER:
1022 impl.mController->GetPlaceholderProperty( map );
1026 case Toolkit::TextField::Property::ELLIPSIS:
1028 value = impl.mController->IsTextElideEnabled();
1031 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1033 value = impl.mController->IsShiftSelectionEnabled();
1036 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1038 value = impl.mController->IsGrabHandleEnabled();
1041 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1043 value = impl.mController->IsMatchSystemLanguageDirection();
1046 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1048 value = impl.mController->IsGrabHandlePopupEnabled();
1051 case Toolkit::DevelTextField::Property::BACKGROUND:
1053 value = impl.mController->GetBackgroundColor();
1056 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1058 value = impl.mController->GetSelectedText( );
1061 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1063 Uint32Pair range = impl.GetTextSelectionRange( );
1064 value = static_cast<int>(range.first);
1067 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1069 Uint32Pair range = impl.GetTextSelectionRange( );
1070 value = static_cast<int>(range.second);
1073 case Toolkit::DevelTextField::Property::ENABLE_EDITING:
1075 value = impl.IsEditable();
1084 void TextField::SelectWholeText()
1086 if( mController && mController->IsShowingRealText() )
1088 mController->SelectWholeText();
1093 void TextField::SelectNone()
1095 if( mController && mController->IsShowingRealText() )
1097 mController->SelectNone();
1101 string TextField::GetSelectedText() const
1103 string selectedText = "";
1104 if( mController && mController->IsShowingRealText() )
1106 selectedText = mController->GetSelectedText( );
1108 return selectedText;
1111 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1113 if( mController && mController->IsShowingRealText() )
1115 mController->SetTextSelectionRange( start, end );
1120 Uint32Pair TextField::GetTextSelectionRange() const
1123 if( mController && mController->IsShowingRealText() )
1125 range = mController->GetTextSelectionRange();
1131 InputMethodContext TextField::GetInputMethodContext()
1133 return mInputMethodContext;
1136 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1138 Dali::BaseHandle handle( object );
1140 bool connected( true );
1141 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1143 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1145 field.TextChangedSignal().Connect( tracker, functor );
1147 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1149 field.MaxLengthReachedSignal().Connect( tracker, functor );
1151 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1153 field.InputStyleChangedSignal().Connect( tracker, functor );
1157 // signalName does not match any signal
1164 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1166 return mTextChangedSignal;
1169 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1171 return mMaxLengthReachedSignal;
1174 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1176 return mInputStyleChangedSignal;
1179 void TextField::OnInitialize()
1181 Actor self = Self();
1183 mController = Text::Controller::New( this, this ,this);
1185 // When using the vector-based rendering, the size of the GLyphs are different
1186 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1187 mController->SetGlyphType( glyphType );
1189 mDecorator = Text::Decorator::New( *mController,
1192 mInputMethodContext = InputMethodContext::New( self );
1194 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1196 // Enables the text input.
1197 mController->EnableTextInput( mDecorator, mInputMethodContext );
1199 // Enables the horizontal scrolling after the text input has been enabled.
1200 mController->SetHorizontalScrollEnabled( true );
1202 // Disables the vertical scrolling.
1203 mController->SetVerticalScrollEnabled( false );
1205 // Disable the smooth handle panning.
1206 mController->SetSmoothHandlePanEnabled( false );
1208 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1209 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1211 // Sets layoutDirection value
1212 Dali::Stage stage = Dali::Stage::GetCurrent();
1213 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1214 mController->SetLayoutDirection( layoutDirection );
1216 // Forward input events to controller
1217 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1218 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1220 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1222 // Set BoundingBox to stage size if not already set.
1223 Rect<int> boundingBox;
1224 mDecorator->GetBoundingBox( boundingBox );
1226 if( boundingBox.IsEmpty() )
1228 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1229 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1232 // Flip vertically the 'left' selection handle
1233 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1235 // Fill-parent area by default
1236 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1237 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1238 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1240 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1242 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1248 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1250 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1254 case StyleChange::DEFAULT_FONT_CHANGE:
1256 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1257 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1258 // Property system did not set the font so should update it.
1259 mController->UpdateAfterFontChange( newFont );
1264 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1266 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1270 case StyleChange::THEME_CHANGE:
1272 // Nothing to do, let control base class handle this
1277 // Up call to Control
1278 Control::OnStyleChange( styleManager, change );
1281 Vector3 TextField::GetNaturalSize()
1284 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1286 Vector3 naturalSize = mController->GetNaturalSize();
1287 naturalSize.width += ( padding.start + padding.end );
1288 naturalSize.height += ( padding.top + padding.bottom );
1293 float TextField::GetHeightForWidth( float width )
1296 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1297 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1300 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1302 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1304 Actor self = Self();
1307 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1309 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1311 // Support Right-To-Left of padding
1312 Dali::LayoutDirection::Type layoutDirection;
1313 if( mController->IsMatchSystemLanguageDirection() )
1315 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1319 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1321 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1323 std::swap( padding.start, padding.end );
1328 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1332 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1335 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1337 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1340 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1343 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1345 mDecorator->Relayout( size );
1350 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1353 RenderText( updateTextType );
1357 // The text-field emits signals when the input style changes. These changes of style are
1358 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1359 // can't be emitted during the size negotiation as the callbacks may update the UI.
1360 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1361 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1363 if( Adaptor::IsAvailable() )
1365 Adaptor& adaptor = Adaptor::Get();
1367 if( NULL == mIdleCallback )
1369 // @note: The callback manager takes the ownership of the callback object.
1370 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1371 adaptor.AddIdle( mIdleCallback, false );
1377 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1379 Actor renderableActor;
1381 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1385 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1387 renderableActor = mRenderer->Render( mController->GetView(),
1389 Property::INVALID_INDEX, // Animatable property not supported
1391 DepthIndex::CONTENT );
1394 if( renderableActor != mRenderableActor )
1396 UnparentAndReset( mBackgroundActor );
1397 UnparentAndReset( mRenderableActor );
1398 mRenderableActor = renderableActor;
1400 if ( mRenderableActor )
1402 mBackgroundActor = mController->CreateBackgroundActor();
1407 if( mRenderableActor )
1409 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1411 float renderableActorPositionX, renderableActorPositionY;
1415 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1416 renderableActorPositionY = scrollOffset.y;
1421 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1423 // Support Right-To-Left of padding
1424 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1425 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1427 std::swap( padding.start, padding.end );
1430 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1431 renderableActorPositionY = scrollOffset.y + padding.top;
1434 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1436 // Make sure the actors are parented correctly with/without clipping
1437 Actor self = mStencil ? mStencil : Self();
1439 Actor highlightActor;
1441 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1442 endIt = mClippingDecorationActors.end();
1447 it->LowerToBottom();
1449 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1451 highlightActor = *it;
1454 mClippingDecorationActors.clear();
1456 self.Add( mRenderableActor );
1458 if ( mBackgroundActor )
1460 if ( mDecorator && mDecorator->IsHighlightVisible() )
1462 self.Add( mBackgroundActor );
1463 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1464 mBackgroundActor.LowerBelow( highlightActor );
1468 mRenderableActor.Add( mBackgroundActor );
1469 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1470 mBackgroundActor.LowerToBottom();
1476 void TextField::OnKeyInputFocusGained()
1478 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1479 if( mInputMethodContext && IsEditable() )
1481 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1483 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1485 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1487 // Notify that the text editing start.
1488 mInputMethodContext.Activate();
1490 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1491 mInputMethodContext.SetRestoreAfterFocusLost( true );
1494 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1497 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1500 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1501 Internal::Control& controlImpl = GetImplementation( control );
1502 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1503 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1504 if( enableAutofill )
1506 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1507 container.SetFocusedControl( control );
1509 Internal::AutofillContainer& containerImpl = GetImpl( container );
1510 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1511 if( containerGroup != nullptr )
1513 containerGroup.RequestAuthentication();
1517 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1519 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1522 void TextField::OnKeyInputFocusLost()
1524 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1525 if ( mInputMethodContext )
1527 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1528 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1529 mInputMethodContext.SetRestoreAfterFocusLost( false );
1531 // Notify that the text editing finish.
1532 mInputMethodContext.Deactivate();
1534 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1536 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1540 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1543 mController->KeyboardFocusLostEvent();
1545 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1548 void TextField::OnTap( const TapGesture& gesture )
1550 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1551 if ( mInputMethodContext && IsEditable() )
1553 mInputMethodContext.Activate();
1555 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1557 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1558 const Vector2& localPoint = gesture.GetLocalPoint();
1559 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1564 void TextField::OnPan( const PanGesture& gesture )
1566 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1569 void TextField::OnLongPress( const LongPressGesture& gesture )
1571 if ( mInputMethodContext && IsEditable() )
1573 mInputMethodContext.Activate();
1576 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1577 const Vector2& localPoint = gesture.GetLocalPoint();
1578 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1583 bool TextField::OnKeyEvent( const KeyEvent& event )
1585 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1587 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1589 // Make sure ClearKeyInputFocus when only key is up
1590 if( event.GetState() == KeyEvent::UP )
1592 ClearKeyInputFocus();
1597 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1599 // Do nothing when enter is comming.
1603 return mController->KeyEvent( event );
1606 void TextField::RequestTextRelayout()
1611 bool TextField::IsEditable() const
1613 return mController->IsEditable();
1616 void TextField::SetEditable( bool editable )
1618 mController->SetEditable(editable);
1619 if ( mInputMethodContext && !editable )
1621 mInputMethodContext.Deactivate();
1625 void TextField::TextChanged()
1627 Dali::Toolkit::TextField handle( GetOwner() );
1628 mTextChangedSignal.Emit( handle );
1631 void TextField::MaxLengthReached()
1633 Dali::Toolkit::TextField handle( GetOwner() );
1634 mMaxLengthReachedSignal.Emit( handle );
1637 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1639 Dali::Toolkit::TextField handle( GetOwner() );
1641 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1643 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1645 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1647 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1649 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1651 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1653 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1655 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1657 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1659 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1661 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1663 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1665 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1667 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1669 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1671 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1673 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1675 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1677 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1679 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1681 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1684 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1687 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1693 mClippingDecorationActors.push_back( actor );
1697 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1698 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1699 Self().Add( actor );
1700 mActiveLayer = actor;
1705 void TextField::OnSceneConnect( Dali::Actor actor )
1707 if ( mHasBeenStaged )
1709 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1713 mHasBeenStaged = true;
1717 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1719 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1720 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1723 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1728 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1733 void TextField::EnableClipping()
1737 // Creates an extra control to be used as stencil buffer.
1738 mStencil = Control::New();
1739 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1740 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1742 // Creates a background visual. Even if the color is transparent it updates the stencil.
1743 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1744 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1745 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1747 // Enable the clipping property.
1748 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1749 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1751 Self().Add( mStencil );
1755 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1757 mController->PasteClipboardItemEvent();
1760 void TextField::KeyboardStatusChanged(bool keyboardShown)
1762 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1764 // Just hide the grab handle when keyboard is hidden.
1765 if (!keyboardShown )
1767 mController->KeyboardFocusLostEvent();
1771 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1775 void TextField::OnSceneConnection( int depth )
1777 // Sets the depth to the visuals inside the text's decorator.
1778 mDecorator->SetTextDepth( depth );
1780 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1782 // Call the Control::OnSceneConnection() to set the depth of the background.
1783 Control::OnSceneConnection( depth );
1786 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1791 void TextField::OnIdleSignal()
1793 // Emits the change of input style signals.
1794 mController->ProcessInputStyleChangedSignals();
1796 // Set the pointer to null as the callback manager deletes the callback after execute it.
1797 mIdleCallback = NULL;
1800 TextField::TextField()
1801 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1802 mIdleCallback( NULL ),
1803 mAlignmentOffset( 0.f ),
1804 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1805 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1806 mHasBeenStaged( false )
1810 TextField::~TextField()
1812 UnparentAndReset( mStencil );
1814 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1816 Adaptor::Get().RemoveIdle( mIdleCallback );
1820 } // namespace Internal
1822 } // namespace Toolkit