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/devel-api/common/stage.h>
26 #include <dali/devel-api/object/property-helper-devel.h>
27 #include <dali/devel-api/actors/actor-devel.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/debug.h>
32 #include <dali-toolkit/public-api/text/text-enumerations.h>
33 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
34 #include <dali-toolkit/devel-api/text/rendering-backend.h>
35 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
38 #include <dali-toolkit/public-api/visuals/visual-properties.h>
39 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
40 #include <dali-toolkit/internal/controls/text-controls/autofill-container-impl.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47 #include <dali-toolkit/devel-api/controls/control-devel.h>
48 #include <dali/integration-api/adaptor-framework/adaptor.h>
50 using namespace Dali::Toolkit::Text;
61 namespace // unnamed namespace
64 #if defined(DEBUG_ENABLED)
65 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
68 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
69 } // unnamed namespace
76 return Toolkit::TextField::New();
79 // Setup properties, signals and actions using the type-registry.
80 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
136 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
139 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
140 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
143 DALI_TYPE_REGISTRATION_END()
145 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
147 /// Retrieves a filename from a value that is a Property::Map
148 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
150 std::string filename;
151 const Property::Map* map = value.GetMap();
154 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
157 filenameValue->Get( filename );
165 Toolkit::TextField TextField::New()
167 // Create the implementation, temporarily owned by this handle on stack
168 IntrusivePtr< TextField > impl = new TextField();
170 // Pass ownership to CustomActor handle
171 Toolkit::TextField handle( *impl );
173 // Second-phase init of the implementation
174 // This can only be done after the CustomActor connection has been made...
180 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
182 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
184 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
189 TextField& impl( GetImpl( textField ) );
193 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
195 int backend = value.Get< int >();
196 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
198 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
199 if( DevelText::RENDERING_VECTOR_BASED == backend )
201 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
204 if( impl.mRenderingBackend != backend )
206 impl.mRenderingBackend = backend;
207 impl.mRenderer.Reset();
209 if( impl.mController )
211 // When using the vector-based rendering, the size of the GLyphs are different
212 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
213 impl.mController->SetGlyphType( glyphType );
218 case Toolkit::TextField::Property::TEXT:
220 if( impl.mController )
222 const std::string& text = value.Get< std::string >();
223 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
225 impl.mController->SetText( text );
229 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
231 if( impl.mController )
233 const std::string& text = value.Get< std::string >();
234 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
236 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
240 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
242 if( impl.mController )
244 const std::string& text = value.Get< std::string >();
245 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
247 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
251 case Toolkit::TextField::Property::FONT_FAMILY:
253 if( impl.mController )
255 const std::string& fontFamily = value.Get< std::string >();
256 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
257 impl.mController->SetDefaultFontFamily( fontFamily );
261 case Toolkit::TextField::Property::FONT_STYLE:
263 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
266 case Toolkit::TextField::Property::POINT_SIZE:
268 if( impl.mController )
270 const float pointSize = value.Get< float >();
271 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
273 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
275 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
280 case Toolkit::TextField::Property::MAX_LENGTH:
282 if( impl.mController )
284 const int max = value.Get< int >();
285 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
287 impl.mController->SetMaximumNumberOfCharacters( max );
291 case Toolkit::TextField::Property::EXCEED_POLICY:
293 impl.mExceedPolicy = value.Get<int>();
295 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
297 impl.EnableClipping();
301 UnparentAndReset( impl.mStencil );
303 impl.RequestTextRelayout();
306 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
308 if( impl.mController )
310 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
311 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
313 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
314 impl.mController->SetHorizontalAlignment( alignment );
319 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
321 if( impl.mController )
323 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
324 if( GetVerticalAlignmentEnumeration( value, alignment ) )
326 impl.mController->SetVerticalAlignment( alignment );
327 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
332 case Toolkit::TextField::Property::TEXT_COLOR:
334 if( impl.mController )
336 const Vector4& textColor = value.Get< Vector4 >();
337 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 );
339 if( impl.mController->GetDefaultColor() != textColor )
341 impl.mController->SetDefaultColor( textColor );
342 impl.mController->SetInputColor( textColor );
343 impl.mRenderer.Reset();
348 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
350 if( impl.mController )
352 const Vector4& textColor = value.Get< Vector4 >();
353 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 );
355 if( impl.mController->GetPlaceholderTextColor() != textColor )
357 impl.mController->SetPlaceholderTextColor( textColor );
358 impl.mRenderer.Reset();
363 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
365 if( impl.mDecorator )
367 const Vector4& color = value.Get< Vector4 >();
368 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 );
370 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
371 impl.RequestTextRelayout();
375 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
377 if( impl.mDecorator )
379 const Vector4& color = value.Get< Vector4 >();
380 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 );
382 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
383 impl.RequestTextRelayout();
387 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
389 if( impl.mController )
391 const bool enable = value.Get< bool >();
392 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
394 impl.mController->SetEnableCursorBlink( enable );
395 impl.RequestTextRelayout();
399 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
401 if( impl.mDecorator )
403 const float interval = value.Get< float >();
404 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
406 impl.mDecorator->SetCursorBlinkInterval( interval );
410 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
412 if( impl.mDecorator )
414 const float duration = value.Get< float >();
415 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
417 impl.mDecorator->SetCursorBlinkDuration( duration );
421 case Toolkit::TextField::Property::CURSOR_WIDTH:
423 if( impl.mDecorator )
425 const int width = value.Get< int >();
426 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
428 impl.mDecorator->SetCursorWidth( width );
429 impl.mController->GetLayoutEngine().SetCursorWidth( width );
433 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
435 const std::string imageFileName = value.Get< std::string >();
436 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
438 if( impl.mDecorator && imageFileName.size() )
440 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
441 impl.RequestTextRelayout();
445 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
447 const std::string imageFileName = value.Get< std::string >();
448 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
450 if( impl.mDecorator && imageFileName.size() )
452 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
453 impl.RequestTextRelayout();
457 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
459 const float threshold = value.Get< float >();
460 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
462 if( impl.mDecorator )
464 impl.mDecorator->SetScrollThreshold( threshold );
468 case Toolkit::TextField::Property::SCROLL_SPEED:
470 const float speed = value.Get< float >();
471 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
473 if( impl.mDecorator )
475 impl.mDecorator->SetScrollSpeed( speed );
479 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
481 const std::string filename = GetImageFileNameFromPropertyValue( value );
483 if( impl.mDecorator && filename.size() )
485 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
486 impl.RequestTextRelayout();
490 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
492 const std::string filename = GetImageFileNameFromPropertyValue( value );
494 if( impl.mDecorator && filename.size() )
496 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
497 impl.RequestTextRelayout();
501 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
503 const std::string filename = GetImageFileNameFromPropertyValue( value );
505 if( impl.mDecorator && filename.size() )
507 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
508 impl.RequestTextRelayout();
512 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
514 const std::string filename = GetImageFileNameFromPropertyValue( value );
516 if( impl.mDecorator && filename.size() )
518 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
519 impl.RequestTextRelayout();
523 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
525 const std::string filename = GetImageFileNameFromPropertyValue( value );
527 if( impl.mDecorator && filename.size() )
529 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
530 impl.RequestTextRelayout();
534 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
536 const std::string filename = GetImageFileNameFromPropertyValue( value );
538 if( impl.mDecorator && filename.size() )
540 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
541 impl.RequestTextRelayout();
545 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
547 const Vector4 color = value.Get< Vector4 >();
548 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 );
550 if( impl.mDecorator )
552 impl.mDecorator->SetHighlightColor( color );
553 impl.RequestTextRelayout();
557 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
559 if( impl.mDecorator )
561 const Rect<int> box = value.Get< Rect<int> >();
562 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 );
564 impl.mDecorator->SetBoundingBox( box );
565 impl.RequestTextRelayout();
569 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
571 const Property::Map* map = value.GetMap();
574 impl.mInputMethodOptions.ApplyProperty( *map );
576 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
578 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
579 if (control == textField)
581 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
585 case Toolkit::TextField::Property::INPUT_COLOR:
587 if( impl.mController )
589 const Vector4 inputColor = value.Get< Vector4 >();
590 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 );
592 impl.mController->SetInputColor( inputColor );
596 case Toolkit::TextField::Property::ENABLE_MARKUP:
598 if( impl.mController )
600 const bool enableMarkup = value.Get<bool>();
601 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
603 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
607 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
609 if( impl.mController )
611 const std::string& fontFamily = value.Get< std::string >();
612 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
613 impl.mController->SetInputFontFamily( fontFamily );
617 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
619 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
622 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
624 if( impl.mController )
626 const float pointSize = value.Get< float >();
627 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
628 impl.mController->SetInputFontPointSize( pointSize );
632 case Toolkit::TextField::Property::UNDERLINE:
634 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
637 impl.mRenderer.Reset();
641 case Toolkit::TextField::Property::INPUT_UNDERLINE:
643 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
646 impl.mRenderer.Reset();
650 case Toolkit::TextField::Property::SHADOW:
652 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
655 impl.mRenderer.Reset();
659 case Toolkit::TextField::Property::INPUT_SHADOW:
661 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
664 impl.mRenderer.Reset();
668 case Toolkit::TextField::Property::EMBOSS:
670 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
673 impl.mRenderer.Reset();
677 case Toolkit::TextField::Property::INPUT_EMBOSS:
679 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
682 impl.mRenderer.Reset();
686 case Toolkit::TextField::Property::OUTLINE:
688 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
691 impl.mRenderer.Reset();
695 case Toolkit::TextField::Property::INPUT_OUTLINE:
697 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
700 impl.mRenderer.Reset();
704 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
706 const Property::Map* map = value.GetMap();
709 impl.mController->SetHiddenInputOption(*map);
713 case Toolkit::TextField::Property::PIXEL_SIZE:
715 if( impl.mController )
717 const float pixelSize = value.Get< float >();
718 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
720 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
722 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
727 case Toolkit::TextField::Property::ENABLE_SELECTION:
729 if( impl.mController )
731 const bool enableSelection = value.Get< bool >();
732 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
733 impl.mController->SetSelectionEnabled( enableSelection );
737 case Toolkit::TextField::Property::PLACEHOLDER:
739 const Property::Map* map = value.GetMap();
742 impl.mController->SetPlaceholderProperty( *map );
746 case Toolkit::TextField::Property::ELLIPSIS:
748 if( impl.mController )
750 const bool ellipsis = value.Get<bool>();
751 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
753 impl.mController->SetTextElideEnabled( ellipsis );
757 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
759 if( impl.mController )
761 const bool shiftSelection = value.Get<bool>();
762 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
764 impl.mController->SetShiftSelectionEnabled( shiftSelection );
768 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
770 if( impl.mController )
772 const bool grabHandleEnabled = value.Get<bool>();
773 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
775 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
779 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
781 if( impl.mController )
783 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
787 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
789 if( impl.mController )
791 const bool grabHandlePopupEnabled = value.Get<bool>();
792 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
794 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
798 case Toolkit::DevelTextField::Property::BACKGROUND:
800 if( impl.mController )
802 const Vector4 backgroundColor = value.Get< Vector4 >();
803 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 );
805 impl.mController->SetBackgroundEnabled( true );
806 impl.mController->SetBackgroundColor( backgroundColor );
814 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
816 Property::Value value;
818 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
822 TextField& impl( GetImpl( textField ) );
826 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
828 value = impl.mRenderingBackend;
831 case Toolkit::TextField::Property::TEXT:
833 if( impl.mController )
836 impl.mController->GetText( text );
837 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
842 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
844 if( impl.mController )
847 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
852 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
854 if( impl.mController )
857 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
862 case Toolkit::TextField::Property::FONT_FAMILY:
864 if( impl.mController )
866 value = impl.mController->GetDefaultFontFamily();
870 case Toolkit::TextField::Property::FONT_STYLE:
872 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
875 case Toolkit::TextField::Property::POINT_SIZE:
877 if( impl.mController )
879 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
883 case Toolkit::TextField::Property::MAX_LENGTH:
885 if( impl.mController )
887 value = impl.mController->GetMaximumNumberOfCharacters();
891 case Toolkit::TextField::Property::EXCEED_POLICY:
893 value = impl.mExceedPolicy;
896 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
898 if( impl.mController )
900 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
904 value = std::string( name );
909 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
911 if( impl.mController )
913 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
917 value = std::string( name );
922 case Toolkit::TextField::Property::TEXT_COLOR:
924 if ( impl.mController )
926 value = impl.mController->GetDefaultColor();
930 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
932 if ( impl.mController )
934 value = impl.mController->GetPlaceholderTextColor();
938 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
940 if( impl.mDecorator )
942 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
946 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
948 if( impl.mDecorator )
950 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
954 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
956 value = impl.mController->GetEnableCursorBlink();
959 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
961 if( impl.mDecorator )
963 value = impl.mDecorator->GetCursorBlinkInterval();
967 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
969 if( impl.mDecorator )
971 value = impl.mDecorator->GetCursorBlinkDuration();
975 case Toolkit::TextField::Property::CURSOR_WIDTH:
977 if( impl.mDecorator )
979 value = impl.mDecorator->GetCursorWidth();
983 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
985 if( impl.mDecorator )
987 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
991 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
993 if( impl.mDecorator )
995 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
999 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
1001 if( impl.mDecorator )
1003 value = impl.mDecorator->GetScrollThreshold();
1007 case Toolkit::TextField::Property::SCROLL_SPEED:
1009 if( impl.mDecorator )
1011 value = impl.mDecorator->GetScrollSpeed();
1015 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1017 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1020 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1022 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1025 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1027 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1030 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1032 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1035 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1037 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1040 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1042 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1045 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1047 if( impl.mDecorator )
1049 value = impl.mDecorator->GetHighlightColor();
1053 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1055 if( impl.mDecorator )
1057 Rect<int> boundingBox;
1058 impl.mDecorator->GetBoundingBox( boundingBox );
1059 value = boundingBox;
1063 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1066 impl.mInputMethodOptions.RetrieveProperty( map );
1070 case Toolkit::TextField::Property::INPUT_COLOR:
1072 if( impl.mController )
1074 value = impl.mController->GetInputColor();
1078 case Toolkit::TextField::Property::ENABLE_MARKUP:
1080 if( impl.mController )
1082 value = impl.mController->IsMarkupProcessorEnabled();
1086 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1088 if( impl.mController )
1090 value = impl.mController->GetInputFontFamily();
1094 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1096 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1099 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1101 if( impl.mController )
1103 value = impl.mController->GetInputFontPointSize();
1107 case Toolkit::TextField::Property::UNDERLINE:
1109 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1112 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1114 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1117 case Toolkit::TextField::Property::SHADOW:
1119 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1122 case Toolkit::TextField::Property::INPUT_SHADOW:
1124 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1127 case Toolkit::TextField::Property::EMBOSS:
1129 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1132 case Toolkit::TextField::Property::INPUT_EMBOSS:
1134 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1137 case Toolkit::TextField::Property::OUTLINE:
1139 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1142 case Toolkit::TextField::Property::INPUT_OUTLINE:
1144 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1147 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1150 impl.mController->GetHiddenInputOption(map);
1154 case Toolkit::TextField::Property::PIXEL_SIZE:
1156 if( impl.mController )
1158 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1162 case Toolkit::TextField::Property::ENABLE_SELECTION:
1164 if( impl.mController )
1166 value = impl.mController->IsSelectionEnabled();
1170 case Toolkit::TextField::Property::PLACEHOLDER:
1173 impl.mController->GetPlaceholderProperty( map );
1177 case Toolkit::TextField::Property::ELLIPSIS:
1179 if( impl.mController )
1181 value = impl.mController->IsTextElideEnabled();
1185 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1187 if( impl.mController )
1189 value = impl.mController->IsShiftSelectionEnabled();
1193 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1195 if( impl.mController )
1197 value = impl.mController->IsGrabHandleEnabled();
1201 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1203 if( impl.mController )
1205 value = impl.mController->IsMatchSystemLanguageDirection();
1209 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1211 if( impl.mController )
1213 value = impl.mController->IsGrabHandlePopupEnabled();
1217 case Toolkit::DevelTextField::Property::BACKGROUND:
1219 if( impl.mController )
1221 value = impl.mController->GetBackgroundColor();
1225 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1227 if( impl.mController )
1229 value = impl.mController->GetSelectedText( );
1239 void TextField::SelectWholeText()
1241 if( mController && mController->IsShowingRealText() )
1243 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1248 void TextField::SelectNone()
1250 if( mController && mController->IsShowingRealText() )
1252 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1257 InputMethodContext TextField::GetInputMethodContext()
1259 return mInputMethodContext;
1262 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1264 Dali::BaseHandle handle( object );
1266 bool connected( true );
1267 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1269 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1271 field.TextChangedSignal().Connect( tracker, functor );
1273 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1275 field.MaxLengthReachedSignal().Connect( tracker, functor );
1277 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1279 field.InputStyleChangedSignal().Connect( tracker, functor );
1283 // signalName does not match any signal
1290 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1292 return mTextChangedSignal;
1295 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1297 return mMaxLengthReachedSignal;
1300 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1302 return mInputStyleChangedSignal;
1305 void TextField::OnInitialize()
1307 Actor self = Self();
1309 mController = Text::Controller::New( this, this );
1311 // When using the vector-based rendering, the size of the GLyphs are different
1312 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1313 mController->SetGlyphType( glyphType );
1315 mDecorator = Text::Decorator::New( *mController,
1318 mInputMethodContext = InputMethodContext::New( self );
1320 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1322 // Enables the text input.
1323 mController->EnableTextInput( mDecorator, mInputMethodContext );
1325 // Enables the horizontal scrolling after the text input has been enabled.
1326 mController->SetHorizontalScrollEnabled( true );
1328 // Disables the vertical scrolling.
1329 mController->SetVerticalScrollEnabled( false );
1331 // Disable the smooth handle panning.
1332 mController->SetSmoothHandlePanEnabled( false );
1334 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1335 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1337 // Sets layoutDirection value
1338 Dali::Stage stage = Dali::Stage::GetCurrent();
1339 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1340 mController->SetLayoutDirection( layoutDirection );
1342 // Forward input events to controller
1343 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1344 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1346 self.TouchSignal().Connect( this, &TextField::OnTouched );
1348 // Set BoundingBox to stage size if not already set.
1349 Rect<int> boundingBox;
1350 mDecorator->GetBoundingBox( boundingBox );
1352 if( boundingBox.IsEmpty() )
1354 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1355 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1358 // Flip vertically the 'left' selection handle
1359 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1361 // Fill-parent area by default
1362 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1363 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1364 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1366 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1368 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1374 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1376 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1380 case StyleChange::DEFAULT_FONT_CHANGE:
1382 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1383 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1384 // Property system did not set the font so should update it.
1385 mController->UpdateAfterFontChange( newFont );
1390 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1392 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1396 case StyleChange::THEME_CHANGE:
1398 // Nothing to do, let control base class handle this
1403 // Up call to Control
1404 Control::OnStyleChange( styleManager, change );
1407 Vector3 TextField::GetNaturalSize()
1410 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1412 Vector3 naturalSize = mController->GetNaturalSize();
1413 naturalSize.width += ( padding.start + padding.end );
1414 naturalSize.height += ( padding.top + padding.bottom );
1419 float TextField::GetHeightForWidth( float width )
1422 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1423 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1426 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1428 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1430 Actor self = Self();
1433 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1435 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1437 // Support Right-To-Left of padding
1438 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1439 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1441 std::swap( padding.start, padding.end );
1446 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1450 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1453 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1455 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1458 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1461 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1463 mDecorator->Relayout( size );
1468 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1471 RenderText( updateTextType );
1475 // The text-field emits signals when the input style changes. These changes of style are
1476 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1477 // can't be emitted during the size negotiation as the callbacks may update the UI.
1478 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1479 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1481 if( Adaptor::IsAvailable() )
1483 Adaptor& adaptor = Adaptor::Get();
1485 if( NULL == mIdleCallback )
1487 // @note: The callback manager takes the ownership of the callback object.
1488 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1489 adaptor.AddIdle( mIdleCallback, false );
1495 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1497 Actor renderableActor;
1499 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1503 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1505 renderableActor = mRenderer->Render( mController->GetView(),
1507 Property::INVALID_INDEX, // Animatable property not supported
1509 DepthIndex::CONTENT );
1512 if( renderableActor != mRenderableActor )
1514 UnparentAndReset( mBackgroundActor );
1515 UnparentAndReset( mRenderableActor );
1516 mRenderableActor = renderableActor;
1518 if ( mRenderableActor )
1520 mBackgroundActor = mController->CreateBackgroundActor();
1525 if( mRenderableActor )
1527 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1529 float renderableActorPositionX, renderableActorPositionY;
1533 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1534 renderableActorPositionY = scrollOffset.y;
1539 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1541 // Support Right-To-Left of padding
1542 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1543 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1545 std::swap( padding.start, padding.end );
1548 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1549 renderableActorPositionY = scrollOffset.y + padding.top;
1552 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1554 // Make sure the actors are parented correctly with/without clipping
1555 Actor self = mStencil ? mStencil : Self();
1557 Actor highlightActor;
1559 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1560 endIt = mClippingDecorationActors.end();
1565 it->LowerToBottom();
1567 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1569 highlightActor = *it;
1572 mClippingDecorationActors.clear();
1574 self.Add( mRenderableActor );
1576 if ( mBackgroundActor )
1578 if ( mDecorator && mDecorator->IsHighlightVisible() )
1580 self.Add( mBackgroundActor );
1581 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1582 mBackgroundActor.LowerBelow( highlightActor );
1586 mRenderableActor.Add( mBackgroundActor );
1587 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1588 mBackgroundActor.LowerToBottom();
1594 void TextField::OnKeyInputFocusGained()
1596 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1597 if( mInputMethodContext )
1599 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1601 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1603 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1605 // Notify that the text editing start.
1606 mInputMethodContext.Activate();
1608 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1609 mInputMethodContext.SetRestoreAfterFocusLost( true );
1612 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1615 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1618 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1619 Internal::Control& controlImpl = GetImplementation( control );
1620 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1621 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1622 if( enableAutofill )
1624 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1625 container.SetFocusedControl( control );
1627 Internal::AutofillContainer& containerImpl = GetImpl( container );
1628 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1629 if( containerGroup != nullptr )
1631 containerGroup.RequestAuthentication();
1635 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1637 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1640 void TextField::OnKeyInputFocusLost()
1642 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1643 if ( mInputMethodContext )
1645 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1646 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1647 mInputMethodContext.SetRestoreAfterFocusLost( false );
1649 // Notify that the text editing finish.
1650 mInputMethodContext.Deactivate();
1652 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1654 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1658 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1661 mController->KeyboardFocusLostEvent();
1663 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1666 void TextField::OnTap( const TapGesture& gesture )
1668 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1669 if ( mInputMethodContext )
1671 mInputMethodContext.Activate();
1673 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1675 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1676 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1681 void TextField::OnPan( const PanGesture& gesture )
1683 mController->PanEvent( gesture.state, gesture.displacement );
1686 void TextField::OnLongPress( const LongPressGesture& gesture )
1688 if ( mInputMethodContext )
1690 mInputMethodContext.Activate();
1693 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1694 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1699 bool TextField::OnKeyEvent( const KeyEvent& event )
1701 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1703 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1705 // Make sure ClearKeyInputFocus when only key is up
1706 if( event.state == KeyEvent::Up )
1708 ClearKeyInputFocus();
1713 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1715 // Do nothing when enter is comming.
1719 return mController->KeyEvent( event );
1722 void TextField::RequestTextRelayout()
1727 void TextField::TextChanged()
1729 Dali::Toolkit::TextField handle( GetOwner() );
1730 mTextChangedSignal.Emit( handle );
1733 void TextField::MaxLengthReached()
1735 Dali::Toolkit::TextField handle( GetOwner() );
1736 mMaxLengthReachedSignal.Emit( handle );
1739 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1741 Dali::Toolkit::TextField handle( GetOwner() );
1743 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1745 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1747 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1749 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1751 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1753 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1755 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1757 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1759 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1761 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1763 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1765 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1767 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1769 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1771 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1773 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1775 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1777 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1779 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1781 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1783 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1786 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1789 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1795 mClippingDecorationActors.push_back( actor );
1799 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1800 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1801 Self().Add( actor );
1802 mActiveLayer = actor;
1807 void TextField::OnSceneConnect( Dali::Actor actor )
1809 if ( mHasBeenStaged )
1811 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1815 mHasBeenStaged = true;
1819 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1821 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1822 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1825 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1830 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1835 void TextField::EnableClipping()
1839 // Creates an extra control to be used as stencil buffer.
1840 mStencil = Control::New();
1841 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1842 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1844 // Creates a background visual. Even if the color is transparent it updates the stencil.
1845 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1846 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1847 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1849 // Enable the clipping property.
1850 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1851 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1853 Self().Add( mStencil );
1857 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1859 mController->PasteClipboardItemEvent();
1862 void TextField::KeyboardStatusChanged(bool keyboardShown)
1864 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1866 // Just hide the grab handle when keyboard is hidden.
1867 if (!keyboardShown )
1869 mController->KeyboardFocusLostEvent();
1873 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1877 void TextField::OnSceneConnection( int depth )
1879 // Sets the depth to the visuals inside the text's decorator.
1880 mDecorator->SetTextDepth( depth );
1882 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1884 // Call the Control::OnSceneConnection() to set the depth of the background.
1885 Control::OnSceneConnection( depth );
1888 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1893 void TextField::OnIdleSignal()
1895 // Emits the change of input style signals.
1896 mController->ProcessInputStyleChangedSignals();
1898 // Set the pointer to null as the callback manager deletes the callback after execute it.
1899 mIdleCallback = NULL;
1902 TextField::TextField()
1903 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1904 mIdleCallback( NULL ),
1905 mAlignmentOffset( 0.f ),
1906 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1907 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1908 mHasBeenStaged( false )
1912 TextField::~TextField()
1914 UnparentAndReset( mStencil );
1916 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1918 Adaptor::Get().RemoveIdle( mIdleCallback );
1922 } // namespace Internal
1924 } // namespace Toolkit