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/devel-api/adaptor-framework/key-devel.h>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/devel-api/object/property-helper-devel.h>
28 #include <dali/devel-api/actors/actor-devel.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali/integration-api/debug.h>
33 #include <dali-toolkit/public-api/text/rendering-backend.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/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
38 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
39 #include <dali-toolkit/public-api/visuals/visual-properties.h>
40 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
41 #include <dali-toolkit/internal/controls/text-controls/autofill-container-impl.h>
42 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
43 #include <dali-toolkit/internal/text/rendering/text-backend.h>
44 #include <dali-toolkit/internal/text/text-effects-style.h>
45 #include <dali-toolkit/internal/text/text-font-style.h>
46 #include <dali-toolkit/internal/text/text-view.h>
47 #include <dali-toolkit/internal/styling/style-manager-impl.h>
48 #include <dali-toolkit/devel-api/controls/control-devel.h>
49 #include <dali/integration-api/adaptor-framework/adaptor.h>
51 using namespace Dali::Toolkit::Text;
62 namespace // unnamed namespace
65 #if defined(DEBUG_ENABLED)
66 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
69 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
70 } // unnamed namespace
77 return Toolkit::TextField::New();
80 // Setup properties, signals and actions using the type-registry.
81 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
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, "reservedProperty01", STRING, RESERVED_PROPERTY_01 )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "reservedProperty02", STRING, RESERVED_PROPERTY_02 )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
140 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
146 DALI_TYPE_REGISTRATION_END()
148 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
150 /// Retrieves a filename from a value that is a Property::Map
151 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
153 std::string filename;
154 const Property::Map* map = value.GetMap();
157 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
160 filenameValue->Get( filename );
168 Toolkit::TextField TextField::New()
170 // Create the implementation, temporarily owned by this handle on stack
171 IntrusivePtr< TextField > impl = new TextField();
173 // Pass ownership to CustomActor handle
174 Toolkit::TextField handle( *impl );
176 // Second-phase init of the implementation
177 // This can only be done after the CustomActor connection has been made...
183 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
185 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
187 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
192 TextField& impl( GetImpl( textField ) );
196 case Toolkit::TextField::Property::RENDERING_BACKEND:
198 int backend = value.Get< int >();
199 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
201 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
202 if( Text::RENDERING_VECTOR_BASED == backend )
204 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
207 if( impl.mRenderingBackend != backend )
209 impl.mRenderingBackend = backend;
210 impl.mRenderer.Reset();
212 if( impl.mController )
214 // When using the vector-based rendering, the size of the GLyphs are different
215 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
216 impl.mController->SetGlyphType( glyphType );
221 case Toolkit::TextField::Property::TEXT:
223 if( impl.mController )
225 const std::string& text = value.Get< std::string >();
226 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
228 impl.mController->SetText( text );
232 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
234 if( impl.mController )
236 const std::string& text = value.Get< std::string >();
237 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
239 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
243 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
245 if( impl.mController )
247 const std::string& text = value.Get< std::string >();
248 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
250 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
254 case Toolkit::TextField::Property::FONT_FAMILY:
256 if( impl.mController )
258 const std::string& fontFamily = value.Get< std::string >();
259 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
260 impl.mController->SetDefaultFontFamily( fontFamily );
264 case Toolkit::TextField::Property::FONT_STYLE:
266 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
269 case Toolkit::TextField::Property::POINT_SIZE:
271 if( impl.mController )
273 const float pointSize = value.Get< float >();
274 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
276 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
278 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
283 case Toolkit::TextField::Property::MAX_LENGTH:
285 if( impl.mController )
287 const int max = value.Get< int >();
288 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
290 impl.mController->SetMaximumNumberOfCharacters( max );
294 case Toolkit::TextField::Property::EXCEED_POLICY:
296 impl.mExceedPolicy = value.Get<int>();
298 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
300 impl.EnableClipping();
304 UnparentAndReset( impl.mStencil );
306 impl.RequestTextRelayout();
309 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
311 if( impl.mController )
313 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
314 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
316 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
317 impl.mController->SetHorizontalAlignment( alignment );
322 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
324 if( impl.mController )
326 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
327 if( GetVerticalAlignmentEnumeration( value, alignment ) )
329 impl.mController->SetVerticalAlignment( alignment );
330 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
335 case Toolkit::TextField::Property::TEXT_COLOR:
337 if( impl.mController )
339 const Vector4& textColor = value.Get< Vector4 >();
340 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 );
342 if( impl.mController->GetDefaultColor() != textColor )
344 impl.mController->SetDefaultColor( textColor );
345 impl.mController->SetInputColor( textColor );
346 impl.mRenderer.Reset();
351 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
353 if( impl.mController )
355 const Vector4& textColor = value.Get< Vector4 >();
356 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 );
358 if( impl.mController->GetPlaceholderTextColor() != textColor )
360 impl.mController->SetPlaceholderTextColor( textColor );
361 impl.mRenderer.Reset();
366 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
368 if( impl.mDecorator )
370 const Vector4& color = value.Get< Vector4 >();
371 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 );
373 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
374 impl.RequestTextRelayout();
378 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
380 if( impl.mDecorator )
382 const Vector4& color = value.Get< Vector4 >();
383 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 );
385 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
386 impl.RequestTextRelayout();
390 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
392 if( impl.mController )
394 const bool enable = value.Get< bool >();
395 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
397 impl.mController->SetEnableCursorBlink( enable );
398 impl.RequestTextRelayout();
402 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
404 if( impl.mDecorator )
406 const float interval = value.Get< float >();
407 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
409 impl.mDecorator->SetCursorBlinkInterval( interval );
413 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
415 if( impl.mDecorator )
417 const float duration = value.Get< float >();
418 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
420 impl.mDecorator->SetCursorBlinkDuration( duration );
424 case Toolkit::TextField::Property::CURSOR_WIDTH:
426 if( impl.mDecorator )
428 const int width = value.Get< int >();
429 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
431 impl.mDecorator->SetCursorWidth( width );
432 impl.mController->GetLayoutEngine().SetCursorWidth( width );
436 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
438 const std::string imageFileName = value.Get< std::string >();
439 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName );
441 if( impl.mDecorator && imageFileName.size() )
443 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
444 impl.RequestTextRelayout();
448 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
450 const std::string imageFileName = value.Get< std::string >();
451 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName );
453 if( impl.mDecorator && imageFileName.size() )
455 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
456 impl.RequestTextRelayout();
460 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
462 const float threshold = value.Get< float >();
463 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
465 if( impl.mDecorator )
467 impl.mDecorator->SetScrollThreshold( threshold );
471 case Toolkit::TextField::Property::SCROLL_SPEED:
473 const float speed = value.Get< float >();
474 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
476 if( impl.mDecorator )
478 impl.mDecorator->SetScrollSpeed( speed );
482 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
484 const std::string filename = GetImageFileNameFromPropertyValue( value );
486 if( impl.mDecorator && filename.size() )
488 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
489 impl.RequestTextRelayout();
493 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
495 const std::string filename = GetImageFileNameFromPropertyValue( value );
497 if( impl.mDecorator && filename.size() )
499 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
500 impl.RequestTextRelayout();
504 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
506 const std::string filename = GetImageFileNameFromPropertyValue( value );
508 if( impl.mDecorator && filename.size() )
510 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
511 impl.RequestTextRelayout();
515 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
517 const std::string filename = GetImageFileNameFromPropertyValue( value );
519 if( impl.mDecorator && filename.size() )
521 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
522 impl.RequestTextRelayout();
526 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
528 const std::string filename = GetImageFileNameFromPropertyValue( value );
530 if( impl.mDecorator && filename.size() )
532 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
533 impl.RequestTextRelayout();
537 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
539 const std::string filename = GetImageFileNameFromPropertyValue( value );
541 if( impl.mDecorator && filename.size() )
543 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
544 impl.RequestTextRelayout();
548 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
550 const Vector4 color = value.Get< Vector4 >();
551 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 );
553 if( impl.mDecorator )
555 impl.mDecorator->SetHighlightColor( color );
556 impl.RequestTextRelayout();
560 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
562 if( impl.mDecorator )
564 const Rect<int> box = value.Get< Rect<int> >();
565 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 );
567 impl.mDecorator->SetBoundingBox( box );
568 impl.RequestTextRelayout();
572 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
574 const Property::Map* map = value.GetMap();
577 impl.mInputMethodOptions.ApplyProperty( *map );
579 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
581 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
582 if (control == textField)
584 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
588 case Toolkit::TextField::Property::INPUT_COLOR:
590 if( impl.mController )
592 const Vector4 inputColor = value.Get< Vector4 >();
593 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 );
595 impl.mController->SetInputColor( inputColor );
599 case Toolkit::TextField::Property::ENABLE_MARKUP:
601 if( impl.mController )
603 const bool enableMarkup = value.Get<bool>();
604 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
606 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
610 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
612 if( impl.mController )
614 const std::string& fontFamily = value.Get< std::string >();
615 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
616 impl.mController->SetInputFontFamily( fontFamily );
620 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
622 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
625 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
627 if( impl.mController )
629 const float pointSize = value.Get< float >();
630 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
631 impl.mController->SetInputFontPointSize( pointSize );
635 case Toolkit::TextField::Property::UNDERLINE:
637 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
640 impl.mRenderer.Reset();
644 case Toolkit::TextField::Property::INPUT_UNDERLINE:
646 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
649 impl.mRenderer.Reset();
653 case Toolkit::TextField::Property::SHADOW:
655 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
658 impl.mRenderer.Reset();
662 case Toolkit::TextField::Property::INPUT_SHADOW:
664 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
667 impl.mRenderer.Reset();
671 case Toolkit::TextField::Property::EMBOSS:
673 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
676 impl.mRenderer.Reset();
680 case Toolkit::TextField::Property::INPUT_EMBOSS:
682 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
685 impl.mRenderer.Reset();
689 case Toolkit::TextField::Property::OUTLINE:
691 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
694 impl.mRenderer.Reset();
698 case Toolkit::TextField::Property::INPUT_OUTLINE:
700 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
703 impl.mRenderer.Reset();
707 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
709 const Property::Map* map = value.GetMap();
712 impl.mController->SetHiddenInputOption(*map);
716 case Toolkit::TextField::Property::PIXEL_SIZE:
718 if( impl.mController )
720 const float pixelSize = value.Get< float >();
721 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
723 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
725 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
730 case Toolkit::TextField::Property::ENABLE_SELECTION:
732 if( impl.mController )
734 const bool enableSelection = value.Get< bool >();
735 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
736 impl.mController->SetSelectionEnabled( enableSelection );
740 case Toolkit::TextField::Property::PLACEHOLDER:
742 const Property::Map* map = value.GetMap();
745 impl.mController->SetPlaceholderProperty( *map );
749 case Toolkit::TextField::Property::ELLIPSIS:
751 if( impl.mController )
753 const bool ellipsis = value.Get<bool>();
754 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
756 impl.mController->SetTextElideEnabled( ellipsis );
760 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
762 if( impl.mController )
764 const bool shiftSelection = value.Get<bool>();
765 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
767 impl.mController->SetShiftSelectionEnabled( shiftSelection );
771 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
773 if( impl.mController )
775 const bool grabHandleEnabled = value.Get<bool>();
776 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
778 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
782 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
784 if( impl.mController )
786 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
790 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
792 if( impl.mController )
794 const bool grabHandlePopupEnabled = value.Get<bool>();
795 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
797 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
801 case Toolkit::DevelTextField::Property::BACKGROUND:
803 if( impl.mController )
805 const Vector4 backgroundColor = value.Get< Vector4 >();
806 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 );
808 impl.mController->SetBackgroundEnabled( true );
809 impl.mController->SetBackgroundColor( backgroundColor );
817 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
819 Property::Value value;
821 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
825 TextField& impl( GetImpl( textField ) );
829 case Toolkit::TextField::Property::RENDERING_BACKEND:
831 value = impl.mRenderingBackend;
834 case Toolkit::TextField::Property::TEXT:
836 if( impl.mController )
839 impl.mController->GetText( text );
840 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
845 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
847 if( impl.mController )
850 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
855 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
857 if( impl.mController )
860 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
865 case Toolkit::TextField::Property::FONT_FAMILY:
867 if( impl.mController )
869 value = impl.mController->GetDefaultFontFamily();
873 case Toolkit::TextField::Property::FONT_STYLE:
875 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
878 case Toolkit::TextField::Property::POINT_SIZE:
880 if( impl.mController )
882 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
886 case Toolkit::TextField::Property::MAX_LENGTH:
888 if( impl.mController )
890 value = impl.mController->GetMaximumNumberOfCharacters();
894 case Toolkit::TextField::Property::EXCEED_POLICY:
896 value = impl.mExceedPolicy;
899 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
901 if( impl.mController )
903 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
907 value = std::string( name );
912 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
914 if( impl.mController )
916 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
920 value = std::string( name );
925 case Toolkit::TextField::Property::TEXT_COLOR:
927 if ( impl.mController )
929 value = impl.mController->GetDefaultColor();
933 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
935 if ( impl.mController )
937 value = impl.mController->GetPlaceholderTextColor();
941 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
943 if( impl.mDecorator )
945 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
949 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
951 if( impl.mDecorator )
953 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
957 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
959 value = impl.mController->GetEnableCursorBlink();
962 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
964 if( impl.mDecorator )
966 value = impl.mDecorator->GetCursorBlinkInterval();
970 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
972 if( impl.mDecorator )
974 value = impl.mDecorator->GetCursorBlinkDuration();
978 case Toolkit::TextField::Property::CURSOR_WIDTH:
980 if( impl.mDecorator )
982 value = impl.mDecorator->GetCursorWidth();
986 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
988 if( impl.mDecorator )
990 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
994 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
996 if( impl.mDecorator )
998 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
1002 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
1004 if( impl.mDecorator )
1006 value = impl.mDecorator->GetScrollThreshold();
1010 case Toolkit::TextField::Property::SCROLL_SPEED:
1012 if( impl.mDecorator )
1014 value = impl.mDecorator->GetScrollSpeed();
1018 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1020 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1023 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1025 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1028 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1030 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1033 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1035 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1038 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1040 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1043 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1045 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1048 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1050 if( impl.mDecorator )
1052 value = impl.mDecorator->GetHighlightColor();
1056 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1058 if( impl.mDecorator )
1060 Rect<int> boundingBox;
1061 impl.mDecorator->GetBoundingBox( boundingBox );
1062 value = boundingBox;
1066 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1069 impl.mInputMethodOptions.RetrieveProperty( map );
1073 case Toolkit::TextField::Property::INPUT_COLOR:
1075 if( impl.mController )
1077 value = impl.mController->GetInputColor();
1081 case Toolkit::TextField::Property::ENABLE_MARKUP:
1083 if( impl.mController )
1085 value = impl.mController->IsMarkupProcessorEnabled();
1089 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1091 if( impl.mController )
1093 value = impl.mController->GetInputFontFamily();
1097 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1099 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1102 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1104 if( impl.mController )
1106 value = impl.mController->GetInputFontPointSize();
1110 case Toolkit::TextField::Property::UNDERLINE:
1112 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1115 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1117 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1120 case Toolkit::TextField::Property::SHADOW:
1122 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1125 case Toolkit::TextField::Property::INPUT_SHADOW:
1127 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1130 case Toolkit::TextField::Property::EMBOSS:
1132 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1135 case Toolkit::TextField::Property::INPUT_EMBOSS:
1137 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1140 case Toolkit::TextField::Property::OUTLINE:
1142 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1145 case Toolkit::TextField::Property::INPUT_OUTLINE:
1147 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1150 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1153 impl.mController->GetHiddenInputOption(map);
1157 case Toolkit::TextField::Property::PIXEL_SIZE:
1159 if( impl.mController )
1161 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1165 case Toolkit::TextField::Property::ENABLE_SELECTION:
1167 if( impl.mController )
1169 value = impl.mController->IsSelectionEnabled();
1173 case Toolkit::TextField::Property::PLACEHOLDER:
1176 impl.mController->GetPlaceholderProperty( map );
1180 case Toolkit::TextField::Property::ELLIPSIS:
1182 if( impl.mController )
1184 value = impl.mController->IsTextElideEnabled();
1188 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1190 if( impl.mController )
1192 value = impl.mController->IsShiftSelectionEnabled();
1196 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1198 if( impl.mController )
1200 value = impl.mController->IsGrabHandleEnabled();
1204 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1206 if( impl.mController )
1208 value = impl.mController->IsMatchSystemLanguageDirection();
1212 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1214 if( impl.mController )
1216 value = impl.mController->IsGrabHandlePopupEnabled();
1220 case Toolkit::DevelTextField::Property::BACKGROUND:
1222 if( impl.mController )
1224 value = impl.mController->GetBackgroundColor();
1228 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1230 if( impl.mController )
1232 value = impl.mController->GetSelectedText( );
1242 void TextField::SelectWholeText()
1244 if( mController && mController->IsShowingRealText() )
1246 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1251 void TextField::SelectNone()
1253 if( mController && mController->IsShowingRealText() )
1255 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1260 InputMethodContext TextField::GetInputMethodContext()
1262 return mInputMethodContext;
1265 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1267 Dali::BaseHandle handle( object );
1269 bool connected( true );
1270 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1272 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1274 field.TextChangedSignal().Connect( tracker, functor );
1276 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1278 field.MaxLengthReachedSignal().Connect( tracker, functor );
1280 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1282 field.InputStyleChangedSignal().Connect( tracker, functor );
1286 // signalName does not match any signal
1293 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1295 return mTextChangedSignal;
1298 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1300 return mMaxLengthReachedSignal;
1303 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1305 return mInputStyleChangedSignal;
1308 void TextField::OnInitialize()
1310 Actor self = Self();
1312 mController = Text::Controller::New( this, this );
1314 // When using the vector-based rendering, the size of the GLyphs are different
1315 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1316 mController->SetGlyphType( glyphType );
1318 mDecorator = Text::Decorator::New( *mController,
1321 mInputMethodContext = InputMethodContext::New( self );
1323 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1325 // Enables the text input.
1326 mController->EnableTextInput( mDecorator, mInputMethodContext );
1328 // Enables the horizontal scrolling after the text input has been enabled.
1329 mController->SetHorizontalScrollEnabled( true );
1331 // Disables the vertical scrolling.
1332 mController->SetVerticalScrollEnabled( false );
1334 // Disable the smooth handle panning.
1335 mController->SetSmoothHandlePanEnabled( false );
1337 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1338 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1340 // Sets layoutDirection value
1341 Dali::Stage stage = Dali::Stage::GetCurrent();
1342 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1343 mController->SetLayoutDirection( layoutDirection );
1345 // Forward input events to controller
1346 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1347 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1349 self.TouchSignal().Connect( this, &TextField::OnTouched );
1351 // Set BoundingBox to stage size if not already set.
1352 Rect<int> boundingBox;
1353 mDecorator->GetBoundingBox( boundingBox );
1355 if( boundingBox.IsEmpty() )
1357 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1358 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1361 // Flip vertically the 'left' selection handle
1362 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1364 // Fill-parent area by default
1365 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1366 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1367 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1369 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1371 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1377 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1379 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1383 case StyleChange::DEFAULT_FONT_CHANGE:
1385 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1386 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1387 // Property system did not set the font so should update it.
1388 mController->UpdateAfterFontChange( newFont );
1393 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1395 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1399 case StyleChange::THEME_CHANGE:
1401 // Nothing to do, let control base class handle this
1406 // Up call to Control
1407 Control::OnStyleChange( styleManager, change );
1410 Vector3 TextField::GetNaturalSize()
1413 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1415 Vector3 naturalSize = mController->GetNaturalSize();
1416 naturalSize.width += ( padding.start + padding.end );
1417 naturalSize.height += ( padding.top + padding.bottom );
1422 float TextField::GetHeightForWidth( float width )
1425 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1426 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1429 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1431 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1433 Actor self = Self();
1436 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1438 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1440 // Support Right-To-Left of padding
1441 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1442 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1444 std::swap( padding.start, padding.end );
1449 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1453 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1456 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1458 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1461 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1464 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1466 mDecorator->Relayout( size );
1471 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1474 RenderText( updateTextType );
1478 // The text-field emits signals when the input style changes. These changes of style are
1479 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1480 // can't be emitted during the size negotiation as the callbacks may update the UI.
1481 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1482 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1484 if( Adaptor::IsAvailable() )
1486 Adaptor& adaptor = Adaptor::Get();
1488 if( NULL == mIdleCallback )
1490 // @note: The callback manager takes the ownership of the callback object.
1491 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1492 adaptor.AddIdle( mIdleCallback, false );
1498 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1500 Actor renderableActor;
1502 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1506 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1508 renderableActor = mRenderer->Render( mController->GetView(),
1510 Property::INVALID_INDEX, // Animatable property not supported
1512 DepthIndex::CONTENT );
1515 if( renderableActor != mRenderableActor )
1517 UnparentAndReset( mBackgroundActor );
1518 UnparentAndReset( mRenderableActor );
1519 mRenderableActor = renderableActor;
1521 if ( mRenderableActor )
1523 mBackgroundActor = mController->CreateBackgroundActor();
1528 if( mRenderableActor )
1530 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1532 float renderableActorPositionX, renderableActorPositionY;
1536 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1537 renderableActorPositionY = scrollOffset.y;
1542 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1544 // Support Right-To-Left of padding
1545 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1546 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1548 std::swap( padding.start, padding.end );
1551 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1552 renderableActorPositionY = scrollOffset.y + padding.top;
1555 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1557 // Make sure the actors are parented correctly with/without clipping
1558 Actor self = mStencil ? mStencil : Self();
1560 Actor highlightActor;
1562 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1563 endIt = mClippingDecorationActors.end();
1568 it->LowerToBottom();
1570 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1572 highlightActor = *it;
1575 mClippingDecorationActors.clear();
1577 self.Add( mRenderableActor );
1579 if ( mBackgroundActor )
1581 if ( mDecorator && mDecorator->IsHighlightVisible() )
1583 self.Add( mBackgroundActor );
1584 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1585 mBackgroundActor.LowerBelow( highlightActor );
1589 mRenderableActor.Add( mBackgroundActor );
1590 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1591 mBackgroundActor.LowerToBottom();
1597 void TextField::OnKeyInputFocusGained()
1599 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1600 if( mInputMethodContext )
1602 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1604 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1606 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1608 // Notify that the text editing start.
1609 mInputMethodContext.Activate();
1611 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1612 mInputMethodContext.SetRestoreAfterFocusLost( true );
1615 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1618 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1621 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1622 Internal::Control& controlImpl = GetImplementation( control );
1623 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1624 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1625 if( enableAutofill )
1627 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1628 container.SetFocusedControl( control );
1630 Internal::AutofillContainer& containerImpl = GetImpl( container );
1631 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1632 if( containerGroup != nullptr )
1634 containerGroup.RequestAuthentication();
1638 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1640 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1643 void TextField::OnKeyInputFocusLost()
1645 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1646 if ( mInputMethodContext )
1648 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1649 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1650 mInputMethodContext.SetRestoreAfterFocusLost( false );
1652 // Notify that the text editing finish.
1653 mInputMethodContext.Deactivate();
1655 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1657 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1661 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1664 mController->KeyboardFocusLostEvent();
1666 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1669 void TextField::OnTap( const TapGesture& gesture )
1671 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1672 if ( mInputMethodContext )
1674 mInputMethodContext.Activate();
1676 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1678 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1679 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1684 void TextField::OnPan( const PanGesture& gesture )
1686 mController->PanEvent( gesture.state, gesture.displacement );
1689 void TextField::OnLongPress( const LongPressGesture& gesture )
1691 if ( mInputMethodContext )
1693 mInputMethodContext.Activate();
1696 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1697 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1702 bool TextField::OnKeyEvent( const KeyEvent& event )
1704 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1706 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1708 // Make sure ClearKeyInputFocus when only key is up
1709 if( event.state == KeyEvent::Up )
1711 ClearKeyInputFocus();
1716 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1718 // Do nothing when enter is comming.
1722 return mController->KeyEvent( event );
1725 void TextField::RequestTextRelayout()
1730 void TextField::TextChanged()
1732 Dali::Toolkit::TextField handle( GetOwner() );
1733 mTextChangedSignal.Emit( handle );
1736 void TextField::MaxLengthReached()
1738 Dali::Toolkit::TextField handle( GetOwner() );
1739 mMaxLengthReachedSignal.Emit( handle );
1742 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1744 Dali::Toolkit::TextField handle( GetOwner() );
1746 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1748 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1750 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1752 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1754 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1756 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1758 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1760 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1762 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1764 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1766 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1768 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1770 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1772 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1774 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1776 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1778 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1780 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1782 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1784 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1786 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1789 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1792 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1798 mClippingDecorationActors.push_back( actor );
1802 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1803 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1804 Self().Add( actor );
1805 mActiveLayer = actor;
1810 void TextField::OnStageConnect( Dali::Actor actor )
1812 if ( mHasBeenStaged )
1814 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1818 mHasBeenStaged = true;
1822 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1824 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1825 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1828 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1833 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1838 void TextField::EnableClipping()
1842 // Creates an extra control to be used as stencil buffer.
1843 mStencil = Control::New();
1844 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1845 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1847 // Creates a background visual. Even if the color is transparent it updates the stencil.
1848 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1849 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1850 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1852 // Enable the clipping property.
1853 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1854 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1856 Self().Add( mStencil );
1860 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1862 mController->PasteClipboardItemEvent();
1865 void TextField::KeyboardStatusChanged(bool keyboardShown)
1867 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1869 // Just hide the grab handle when keyboard is hidden.
1870 if (!keyboardShown )
1872 mController->KeyboardFocusLostEvent();
1876 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1880 void TextField::OnStageConnection( int depth )
1882 // Sets the depth to the visuals inside the text's decorator.
1883 mDecorator->SetTextDepth( depth );
1885 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1887 // Call the Control::OnStageConnection() to set the depth of the background.
1888 Control::OnStageConnection( depth );
1891 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1896 void TextField::OnIdleSignal()
1898 // Emits the change of input style signals.
1899 mController->ProcessInputStyleChangedSignals();
1901 // Set the pointer to null as the callback manager deletes the callback after execute it.
1902 mIdleCallback = NULL;
1905 TextField::TextField()
1906 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1907 mIdleCallback( NULL ),
1908 mAlignmentOffset( 0.f ),
1909 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1910 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1911 mHasBeenStaged( false )
1915 TextField::~TextField()
1917 UnparentAndReset( mStencil );
1919 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1921 Adaptor::Get().RemoveIdle( mIdleCallback );
1925 } // namespace Internal
1927 } // namespace Toolkit