2 * Copyright (c) 2019 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 )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
145 DALI_TYPE_REGISTRATION_END()
149 Toolkit::TextField TextField::New()
151 // Create the implementation, temporarily owned by this handle on stack
152 IntrusivePtr< TextField > impl = new TextField();
154 // Pass ownership to CustomActor handle
155 Toolkit::TextField handle( *impl );
157 // Second-phase init of the implementation
158 // This can only be done after the CustomActor connection has been made...
164 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
166 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
168 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
173 TextField& impl( GetImpl( textField ) );
177 case Toolkit::TextField::Property::RENDERING_BACKEND:
179 int backend = value.Get< int >();
180 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
182 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
183 if( Text::RENDERING_VECTOR_BASED == backend )
185 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
188 if( impl.mRenderingBackend != backend )
190 impl.mRenderingBackend = backend;
191 impl.mRenderer.Reset();
193 if( impl.mController )
195 // When using the vector-based rendering, the size of the GLyphs are different
196 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
197 impl.mController->SetGlyphType( glyphType );
202 case Toolkit::TextField::Property::TEXT:
204 if( impl.mController )
206 const std::string& text = value.Get< std::string >();
207 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
209 impl.mController->SetText( text );
213 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
215 if( impl.mController )
217 const std::string& text = value.Get< std::string >();
218 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
220 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
224 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
226 if( impl.mController )
228 const std::string& text = value.Get< std::string >();
229 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
231 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
235 case Toolkit::TextField::Property::FONT_FAMILY:
237 if( impl.mController )
239 const std::string& fontFamily = value.Get< std::string >();
240 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
241 impl.mController->SetDefaultFontFamily( fontFamily );
245 case Toolkit::TextField::Property::FONT_STYLE:
247 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
250 case Toolkit::TextField::Property::POINT_SIZE:
252 if( impl.mController )
254 const float pointSize = value.Get< float >();
255 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
257 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
259 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
264 case Toolkit::TextField::Property::MAX_LENGTH:
266 if( impl.mController )
268 const int max = value.Get< int >();
269 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
271 impl.mController->SetMaximumNumberOfCharacters( max );
275 case Toolkit::TextField::Property::EXCEED_POLICY:
277 impl.mExceedPolicy = value.Get<int>();
279 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
281 impl.EnableClipping();
285 UnparentAndReset( impl.mStencil );
287 impl.RequestTextRelayout();
290 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
292 if( impl.mController )
294 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
295 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
297 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
298 impl.mController->SetHorizontalAlignment( alignment );
303 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
305 if( impl.mController )
307 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
308 if( GetVerticalAlignmentEnumeration( value, alignment ) )
310 impl.mController->SetVerticalAlignment( alignment );
311 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
316 case Toolkit::TextField::Property::TEXT_COLOR:
318 if( impl.mController )
320 const Vector4& textColor = value.Get< Vector4 >();
321 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 );
323 if( impl.mController->GetDefaultColor() != textColor )
325 impl.mController->SetDefaultColor( textColor );
326 impl.mController->SetInputColor( textColor );
327 impl.mRenderer.Reset();
332 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
334 if( impl.mController )
336 const Vector4& textColor = value.Get< Vector4 >();
337 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 );
339 if( impl.mController->GetPlaceholderTextColor() != textColor )
341 impl.mController->SetPlaceholderTextColor( textColor );
342 impl.mRenderer.Reset();
347 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
349 if( impl.mDecorator )
351 const Vector4& color = value.Get< Vector4 >();
352 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 );
354 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
355 impl.RequestTextRelayout();
359 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
361 if( impl.mDecorator )
363 const Vector4& color = value.Get< Vector4 >();
364 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 );
366 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
367 impl.RequestTextRelayout();
371 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
373 if( impl.mController )
375 const bool enable = value.Get< bool >();
376 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
378 impl.mController->SetEnableCursorBlink( enable );
379 impl.RequestTextRelayout();
383 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
385 if( impl.mDecorator )
387 const float interval = value.Get< float >();
388 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
390 impl.mDecorator->SetCursorBlinkInterval( interval );
394 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
396 if( impl.mDecorator )
398 const float duration = value.Get< float >();
399 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
401 impl.mDecorator->SetCursorBlinkDuration( duration );
405 case Toolkit::TextField::Property::CURSOR_WIDTH:
407 if( impl.mDecorator )
409 const int width = value.Get< int >();
410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
412 impl.mDecorator->SetCursorWidth( width );
413 impl.mController->GetLayoutEngine().SetCursorWidth( width );
417 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
419 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
420 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
422 if( impl.mDecorator )
424 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
425 impl.RequestTextRelayout();
429 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
431 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
432 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
434 if( impl.mDecorator )
436 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
437 impl.RequestTextRelayout();
441 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
443 const float threshold = value.Get< float >();
444 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
446 if( impl.mDecorator )
448 impl.mDecorator->SetScrollThreshold( threshold );
452 case Toolkit::TextField::Property::SCROLL_SPEED:
454 const float speed = value.Get< float >();
455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
457 if( impl.mDecorator )
459 impl.mDecorator->SetScrollSpeed( speed );
463 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
465 const Image image = Scripting::NewImage( value );
467 if( impl.mDecorator && image )
469 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
470 impl.RequestTextRelayout();
474 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
476 const Image image = Scripting::NewImage( value );
478 if( impl.mDecorator && image )
480 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
481 impl.RequestTextRelayout();
485 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
487 const Image image = Scripting::NewImage( value );
489 if( impl.mDecorator && image )
491 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
492 impl.RequestTextRelayout();
496 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
498 const Image image = Scripting::NewImage( value );
500 if( impl.mDecorator && image )
502 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
503 impl.RequestTextRelayout();
507 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
509 const Image image = Scripting::NewImage( value );
511 if( impl.mDecorator && image )
513 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
514 impl.RequestTextRelayout();
518 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
520 const Image image = Scripting::NewImage( value );
522 if( impl.mDecorator && image )
524 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
525 impl.RequestTextRelayout();
529 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
531 const Vector4 color = value.Get< Vector4 >();
532 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 );
534 if( impl.mDecorator )
536 impl.mDecorator->SetHighlightColor( color );
537 impl.RequestTextRelayout();
541 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
543 if( impl.mDecorator )
545 const Rect<int> box = value.Get< Rect<int> >();
546 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 );
548 impl.mDecorator->SetBoundingBox( box );
549 impl.RequestTextRelayout();
553 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
555 const Property::Map* map = value.GetMap();
558 impl.mInputMethodOptions.ApplyProperty( *map );
560 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
562 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
563 if (control == textField)
565 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
569 case Toolkit::TextField::Property::INPUT_COLOR:
571 if( impl.mController )
573 const Vector4 inputColor = value.Get< Vector4 >();
574 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 );
576 impl.mController->SetInputColor( inputColor );
580 case Toolkit::TextField::Property::ENABLE_MARKUP:
582 if( impl.mController )
584 const bool enableMarkup = value.Get<bool>();
585 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
587 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
591 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
593 if( impl.mController )
595 const std::string& fontFamily = value.Get< std::string >();
596 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
597 impl.mController->SetInputFontFamily( fontFamily );
601 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
603 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
606 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
608 if( impl.mController )
610 const float pointSize = value.Get< float >();
611 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
612 impl.mController->SetInputFontPointSize( pointSize );
616 case Toolkit::TextField::Property::UNDERLINE:
618 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
621 impl.mRenderer.Reset();
625 case Toolkit::TextField::Property::INPUT_UNDERLINE:
627 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
630 impl.mRenderer.Reset();
634 case Toolkit::TextField::Property::SHADOW:
636 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
639 impl.mRenderer.Reset();
643 case Toolkit::TextField::Property::INPUT_SHADOW:
645 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
648 impl.mRenderer.Reset();
652 case Toolkit::TextField::Property::EMBOSS:
654 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
657 impl.mRenderer.Reset();
661 case Toolkit::TextField::Property::INPUT_EMBOSS:
663 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
666 impl.mRenderer.Reset();
670 case Toolkit::TextField::Property::OUTLINE:
672 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
675 impl.mRenderer.Reset();
679 case Toolkit::TextField::Property::INPUT_OUTLINE:
681 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
684 impl.mRenderer.Reset();
688 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
690 const Property::Map* map = value.GetMap();
693 impl.mController->SetHiddenInputOption(*map);
697 case Toolkit::TextField::Property::PIXEL_SIZE:
699 if( impl.mController )
701 const float pixelSize = value.Get< float >();
702 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
704 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
706 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
711 case Toolkit::TextField::Property::ENABLE_SELECTION:
713 if( impl.mController )
715 const bool enableSelection = value.Get< bool >();
716 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
717 impl.mController->SetSelectionEnabled( enableSelection );
721 case Toolkit::TextField::Property::PLACEHOLDER:
723 const Property::Map* map = value.GetMap();
726 impl.mController->SetPlaceholderProperty( *map );
730 case Toolkit::TextField::Property::ELLIPSIS:
732 if( impl.mController )
734 const bool ellipsis = value.Get<bool>();
735 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
737 impl.mController->SetTextElideEnabled( ellipsis );
741 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
743 if( impl.mController )
745 const bool shiftSelection = value.Get<bool>();
746 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
748 impl.mController->SetShiftSelectionEnabled( shiftSelection );
752 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
754 if( impl.mController )
756 const bool grabHandleEnabled = value.Get<bool>();
757 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
759 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
763 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
765 if( impl.mController )
767 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
771 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
773 if( impl.mController )
775 const bool grabHandlePopupEnabled = value.Get<bool>();
776 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
778 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
782 case Toolkit::DevelTextField::Property::BACKGROUND:
784 if( impl.mController )
786 const Vector4 backgroundColor = value.Get< Vector4 >();
787 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 );
789 impl.mController->SetBackgroundEnabled( true );
790 impl.mController->SetBackgroundColor( backgroundColor );
798 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
800 Property::Value value;
802 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
806 TextField& impl( GetImpl( textField ) );
810 case Toolkit::TextField::Property::RENDERING_BACKEND:
812 value = impl.mRenderingBackend;
815 case Toolkit::TextField::Property::TEXT:
817 if( impl.mController )
820 impl.mController->GetText( text );
821 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
826 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
828 if( impl.mController )
831 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
836 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
838 if( impl.mController )
841 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
846 case Toolkit::TextField::Property::FONT_FAMILY:
848 if( impl.mController )
850 value = impl.mController->GetDefaultFontFamily();
854 case Toolkit::TextField::Property::FONT_STYLE:
856 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
859 case Toolkit::TextField::Property::POINT_SIZE:
861 if( impl.mController )
863 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
867 case Toolkit::TextField::Property::MAX_LENGTH:
869 if( impl.mController )
871 value = impl.mController->GetMaximumNumberOfCharacters();
875 case Toolkit::TextField::Property::EXCEED_POLICY:
877 value = impl.mExceedPolicy;
880 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
882 if( impl.mController )
884 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
888 value = std::string( name );
893 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
895 if( impl.mController )
897 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
901 value = std::string( name );
906 case Toolkit::TextField::Property::TEXT_COLOR:
908 if ( impl.mController )
910 value = impl.mController->GetDefaultColor();
914 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
916 if ( impl.mController )
918 value = impl.mController->GetPlaceholderTextColor();
922 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
924 if( impl.mDecorator )
926 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
930 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
932 if( impl.mDecorator )
934 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
938 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
940 value = impl.mController->GetEnableCursorBlink();
943 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
945 if( impl.mDecorator )
947 value = impl.mDecorator->GetCursorBlinkInterval();
951 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
953 if( impl.mDecorator )
955 value = impl.mDecorator->GetCursorBlinkDuration();
959 case Toolkit::TextField::Property::CURSOR_WIDTH:
961 if( impl.mDecorator )
963 value = impl.mDecorator->GetCursorWidth();
967 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
969 if( impl.mDecorator )
971 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
974 value = image.GetUrl();
979 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
981 if( impl.mDecorator )
983 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
986 value = image.GetUrl();
991 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
993 if( impl.mDecorator )
995 value = impl.mDecorator->GetScrollThreshold();
999 case Toolkit::TextField::Property::SCROLL_SPEED:
1001 if( impl.mDecorator )
1003 value = impl.mDecorator->GetScrollSpeed();
1007 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1009 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1012 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1014 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1017 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1019 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1022 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1024 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1027 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1029 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1032 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1034 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1037 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1039 if( impl.mDecorator )
1041 value = impl.mDecorator->GetHighlightColor();
1045 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1047 if( impl.mDecorator )
1049 Rect<int> boundingBox;
1050 impl.mDecorator->GetBoundingBox( boundingBox );
1051 value = boundingBox;
1055 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1058 impl.mInputMethodOptions.RetrieveProperty( map );
1062 case Toolkit::TextField::Property::INPUT_COLOR:
1064 if( impl.mController )
1066 value = impl.mController->GetInputColor();
1070 case Toolkit::TextField::Property::ENABLE_MARKUP:
1072 if( impl.mController )
1074 value = impl.mController->IsMarkupProcessorEnabled();
1078 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1080 if( impl.mController )
1082 value = impl.mController->GetInputFontFamily();
1086 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1088 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1091 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1093 if( impl.mController )
1095 value = impl.mController->GetInputFontPointSize();
1099 case Toolkit::TextField::Property::UNDERLINE:
1101 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1104 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1106 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1109 case Toolkit::TextField::Property::SHADOW:
1111 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1114 case Toolkit::TextField::Property::INPUT_SHADOW:
1116 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1119 case Toolkit::TextField::Property::EMBOSS:
1121 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1124 case Toolkit::TextField::Property::INPUT_EMBOSS:
1126 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1129 case Toolkit::TextField::Property::OUTLINE:
1131 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1134 case Toolkit::TextField::Property::INPUT_OUTLINE:
1136 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1139 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1142 impl.mController->GetHiddenInputOption(map);
1146 case Toolkit::TextField::Property::PIXEL_SIZE:
1148 if( impl.mController )
1150 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1154 case Toolkit::TextField::Property::ENABLE_SELECTION:
1156 if( impl.mController )
1158 value = impl.mController->IsSelectionEnabled();
1162 case Toolkit::TextField::Property::PLACEHOLDER:
1165 impl.mController->GetPlaceholderProperty( map );
1169 case Toolkit::TextField::Property::ELLIPSIS:
1171 if( impl.mController )
1173 value = impl.mController->IsTextElideEnabled();
1177 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1179 if( impl.mController )
1181 value = impl.mController->IsShiftSelectionEnabled();
1185 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1187 if( impl.mController )
1189 value = impl.mController->IsGrabHandleEnabled();
1193 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1195 if( impl.mController )
1197 value = impl.mController->IsMatchSystemLanguageDirection();
1201 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1203 if( impl.mController )
1205 value = impl.mController->IsGrabHandlePopupEnabled();
1209 case Toolkit::DevelTextField::Property::BACKGROUND:
1211 if( impl.mController )
1213 value = impl.mController->GetBackgroundColor();
1223 void TextField::SelectWholeText()
1225 if( mController && mController->IsShowingRealText() )
1227 mController->SelectEvent( 0.f, 0.f, true );
1232 InputMethodContext TextField::GetInputMethodContext()
1234 return mInputMethodContext;
1237 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1239 Dali::BaseHandle handle( object );
1241 bool connected( true );
1242 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1244 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1246 field.TextChangedSignal().Connect( tracker, functor );
1248 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1250 field.MaxLengthReachedSignal().Connect( tracker, functor );
1252 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1254 field.InputStyleChangedSignal().Connect( tracker, functor );
1258 // signalName does not match any signal
1265 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1267 return mTextChangedSignal;
1270 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1272 return mMaxLengthReachedSignal;
1275 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1277 return mInputStyleChangedSignal;
1280 void TextField::OnInitialize()
1282 Actor self = Self();
1284 mController = Text::Controller::New( this, this );
1286 // When using the vector-based rendering, the size of the GLyphs are different
1287 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1288 mController->SetGlyphType( glyphType );
1290 mDecorator = Text::Decorator::New( *mController,
1293 mInputMethodContext = InputMethodContext::New( self );
1295 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1297 // Enables the text input.
1298 mController->EnableTextInput( mDecorator, mInputMethodContext );
1300 // Enables the horizontal scrolling after the text input has been enabled.
1301 mController->SetHorizontalScrollEnabled( true );
1303 // Disables the vertical scrolling.
1304 mController->SetVerticalScrollEnabled( false );
1306 // Disable the smooth handle panning.
1307 mController->SetSmoothHandlePanEnabled( false );
1309 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1310 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1312 // Sets layoutDirection value
1313 Dali::Stage stage = Dali::Stage::GetCurrent();
1314 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1315 mController->SetLayoutDirection( layoutDirection );
1317 // Forward input events to controller
1318 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1319 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1321 self.TouchSignal().Connect( this, &TextField::OnTouched );
1323 // Set BoundingBox to stage size if not already set.
1324 Rect<int> boundingBox;
1325 mDecorator->GetBoundingBox( boundingBox );
1327 if( boundingBox.IsEmpty() )
1329 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1330 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1333 // Flip vertically the 'left' selection handle
1334 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1336 // Fill-parent area by default
1337 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1338 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1339 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1341 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1343 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1349 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1351 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1355 case StyleChange::DEFAULT_FONT_CHANGE:
1357 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1358 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1359 // Property system did not set the font so should update it.
1360 mController->UpdateAfterFontChange( newFont );
1365 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1367 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1371 case StyleChange::THEME_CHANGE:
1373 // Nothing to do, let control base class handle this
1378 // Up call to Control
1379 Control::OnStyleChange( styleManager, change );
1382 Vector3 TextField::GetNaturalSize()
1385 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1387 Vector3 naturalSize = mController->GetNaturalSize();
1388 naturalSize.width += ( padding.start + padding.end );
1389 naturalSize.height += ( padding.top + padding.bottom );
1394 float TextField::GetHeightForWidth( float width )
1397 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1398 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1401 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1403 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1405 Actor self = Self();
1408 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1410 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1412 // Support Right-To-Left of padding
1413 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1414 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1416 std::swap( padding.start, padding.end );
1421 mStencil.SetPosition( padding.start, padding.top );
1425 mActiveLayer.SetPosition( padding.start, padding.top );
1428 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1430 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1433 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1436 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1438 mDecorator->Relayout( size );
1443 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1446 RenderText( updateTextType );
1450 // The text-field emits signals when the input style changes. These changes of style are
1451 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1452 // can't be emitted during the size negotiation as the callbacks may update the UI.
1453 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1454 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1456 if( Adaptor::IsAvailable() )
1458 Adaptor& adaptor = Adaptor::Get();
1460 if( NULL == mIdleCallback )
1462 // @note: The callback manager takes the ownership of the callback object.
1463 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1464 adaptor.AddIdle( mIdleCallback, false );
1470 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1472 Actor renderableActor;
1474 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1478 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1480 renderableActor = mRenderer->Render( mController->GetView(),
1482 Property::INVALID_INDEX, // Animatable property not supported
1484 DepthIndex::CONTENT );
1487 if( renderableActor != mRenderableActor )
1489 UnparentAndReset( mBackgroundActor );
1490 UnparentAndReset( mRenderableActor );
1491 mRenderableActor = renderableActor;
1493 if ( mRenderableActor )
1495 mBackgroundActor = mController->CreateBackgroundActor();
1500 if( mRenderableActor )
1502 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1504 float renderableActorPositionX, renderableActorPositionY;
1508 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1509 renderableActorPositionY = scrollOffset.y;
1514 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1516 // Support Right-To-Left of padding
1517 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1518 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1520 std::swap( padding.start, padding.end );
1523 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1524 renderableActorPositionY = scrollOffset.y + padding.top;
1527 mRenderableActor.SetPosition( renderableActorPositionX, renderableActorPositionY );
1529 // Make sure the actors are parented correctly with/without clipping
1530 Actor self = mStencil ? mStencil : Self();
1532 Actor highlightActor;
1534 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1535 endIt = mClippingDecorationActors.end();
1540 it->LowerToBottom();
1542 if ( it->GetName() == "HighlightActor" )
1544 highlightActor = *it;
1547 mClippingDecorationActors.clear();
1549 self.Add( mRenderableActor );
1551 if ( mBackgroundActor )
1553 if ( mDecorator && mDecorator->IsHighlightVisible() )
1555 self.Add( mBackgroundActor );
1556 mBackgroundActor.SetPosition( renderableActorPositionX, renderableActorPositionY); // In text field's coords.
1557 mBackgroundActor.LowerBelow( highlightActor );
1561 mRenderableActor.Add( mBackgroundActor );
1562 mBackgroundActor.SetPosition( 0.0f, 0.0f ); // In renderable actor's coords.
1563 mBackgroundActor.LowerToBottom();
1569 void TextField::OnKeyInputFocusGained()
1571 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1572 if( mInputMethodContext )
1574 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1576 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1578 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1580 // Notify that the text editing start.
1581 mInputMethodContext.Activate();
1583 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1584 mInputMethodContext.SetRestoreAfterFocusLost( true );
1587 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1590 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1593 Toolkit::Control control = Toolkit::Control::DownCast( Self() );
1594 Internal::Control& controlImpl = GetImplementation( control );
1595 Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
1596 bool enableAutofill = controlDataImpl.IsAutofillEnabled();
1597 if( enableAutofill )
1599 Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
1600 container.SetFocusedControl( control );
1602 Internal::AutofillContainer& containerImpl = GetImpl( container );
1603 Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
1604 if( containerGroup != nullptr )
1606 containerGroup.RequestAuthentication();
1610 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1612 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1615 void TextField::OnKeyInputFocusLost()
1617 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1618 if ( mInputMethodContext )
1620 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1621 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1622 mInputMethodContext.SetRestoreAfterFocusLost( false );
1624 // Notify that the text editing finish.
1625 mInputMethodContext.Deactivate();
1627 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1629 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1633 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1636 mController->KeyboardFocusLostEvent();
1638 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1641 void TextField::OnTap( const TapGesture& gesture )
1643 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1644 if ( mInputMethodContext )
1646 mInputMethodContext.Activate();
1648 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1650 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1651 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1656 void TextField::OnPan( const PanGesture& gesture )
1658 mController->PanEvent( gesture.state, gesture.displacement );
1661 void TextField::OnLongPress( const LongPressGesture& gesture )
1663 if ( mInputMethodContext )
1665 mInputMethodContext.Activate();
1668 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1669 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1674 bool TextField::OnKeyEvent( const KeyEvent& event )
1676 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1678 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1680 // Make sure ClearKeyInputFocus when only key is up
1681 if( event.state == KeyEvent::Up )
1683 ClearKeyInputFocus();
1688 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1690 // Do nothing when enter is comming.
1694 return mController->KeyEvent( event );
1697 void TextField::RequestTextRelayout()
1702 void TextField::TextChanged()
1704 Dali::Toolkit::TextField handle( GetOwner() );
1705 mTextChangedSignal.Emit( handle );
1708 void TextField::MaxLengthReached()
1710 Dali::Toolkit::TextField handle( GetOwner() );
1711 mMaxLengthReachedSignal.Emit( handle );
1714 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1716 Dali::Toolkit::TextField handle( GetOwner() );
1718 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1720 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1722 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1724 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1726 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1728 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1730 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1732 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1734 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1736 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1738 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1740 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1742 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1744 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1746 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1748 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1750 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1752 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1754 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1756 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1758 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1761 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1764 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1770 mClippingDecorationActors.push_back( actor );
1774 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1775 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1776 Self().Add( actor );
1777 mActiveLayer = actor;
1782 void TextField::OnStageConnect( Dali::Actor actor )
1784 if ( mHasBeenStaged )
1786 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1790 mHasBeenStaged = true;
1794 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1796 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1797 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1800 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1804 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1809 Scripting::CreatePropertyMap( image, map );
1815 void TextField::EnableClipping()
1819 // Creates an extra control to be used as stencil buffer.
1820 mStencil = Control::New();
1821 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1822 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1824 // Creates a background visual. Even if the color is transparent it updates the stencil.
1825 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1826 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1827 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1829 // Enable the clipping property.
1830 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1831 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1833 Self().Add( mStencil );
1837 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1839 mController->PasteClipboardItemEvent();
1842 void TextField::KeyboardStatusChanged(bool keyboardShown)
1844 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1846 // Just hide the grab handle when keyboard is hidden.
1847 if (!keyboardShown )
1849 mController->KeyboardFocusLostEvent();
1853 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1857 void TextField::OnStageConnection( int depth )
1859 // Sets the depth to the visuals inside the text's decorator.
1860 mDecorator->SetTextDepth( depth );
1862 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1864 // Call the Control::OnStageConnection() to set the depth of the background.
1865 Control::OnStageConnection( depth );
1868 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1873 void TextField::OnIdleSignal()
1875 // Emits the change of input style signals.
1876 mController->ProcessInputStyleChangedSignals();
1878 // Set the pointer to null as the callback manager deletes the callback after execute it.
1879 mIdleCallback = NULL;
1882 TextField::TextField()
1883 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1884 mIdleCallback( NULL ),
1885 mAlignmentOffset( 0.f ),
1886 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1887 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1888 mHasBeenStaged( false )
1892 TextField::~TextField()
1894 UnparentAndReset( mStencil );
1896 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1898 Adaptor::Get().RemoveIdle( mIdleCallback );
1902 } // namespace Internal
1904 } // namespace Toolkit