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/text/text-enumerations-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-font-style.h>
44 #include <dali-toolkit/internal/text/text-view.h>
45 #include <dali-toolkit/internal/styling/style-manager-impl.h>
46 #include <dali-toolkit/devel-api/controls/control-devel.h>
47 #include <dali/integration-api/adaptor-framework/adaptor.h>
49 using namespace Dali::Toolkit::Text;
60 namespace // unnamed namespace
63 #if defined(DEBUG_ENABLED)
64 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
67 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
68 } // unnamed namespace
75 return Toolkit::TextField::New();
78 // Setup properties, signals and actions using the type-registry.
79 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
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, "reservedProperty01", STRING, RESERVED_PROPERTY_01 )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "reservedProperty02", STRING, RESERVED_PROPERTY_02 )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
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()
147 Toolkit::TextField TextField::New()
149 // Create the implementation, temporarily owned by this handle on stack
150 IntrusivePtr< TextField > impl = new TextField();
152 // Pass ownership to CustomActor handle
153 Toolkit::TextField handle( *impl );
155 // Second-phase init of the implementation
156 // This can only be done after the CustomActor connection has been made...
162 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
164 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
166 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
171 TextField& impl( GetImpl( textField ) );
175 case Toolkit::TextField::Property::RENDERING_BACKEND:
177 int backend = value.Get< int >();
178 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
180 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
181 if( Text::RENDERING_VECTOR_BASED == backend )
183 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
186 if( impl.mRenderingBackend != backend )
188 impl.mRenderingBackend = backend;
189 impl.mRenderer.Reset();
191 if( impl.mController )
193 // When using the vector-based rendering, the size of the GLyphs are different
194 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
195 impl.mController->SetGlyphType( glyphType );
200 case Toolkit::TextField::Property::TEXT:
202 if( impl.mController )
204 const std::string& text = value.Get< std::string >();
205 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
207 impl.mController->SetText( text );
211 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
213 if( impl.mController )
215 const std::string& text = value.Get< std::string >();
216 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
218 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
222 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
224 if( impl.mController )
226 const std::string& text = value.Get< std::string >();
227 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
229 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
233 case Toolkit::TextField::Property::FONT_FAMILY:
235 if( impl.mController )
237 const std::string& fontFamily = value.Get< std::string >();
238 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
239 impl.mController->SetDefaultFontFamily( fontFamily );
243 case Toolkit::TextField::Property::FONT_STYLE:
245 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
248 case Toolkit::TextField::Property::POINT_SIZE:
250 if( impl.mController )
252 const float pointSize = value.Get< float >();
253 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
255 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
257 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
262 case Toolkit::TextField::Property::MAX_LENGTH:
264 if( impl.mController )
266 const int max = value.Get< int >();
267 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
269 impl.mController->SetMaximumNumberOfCharacters( max );
273 case Toolkit::TextField::Property::EXCEED_POLICY:
275 impl.mExceedPolicy = value.Get<int>();
277 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
279 impl.EnableClipping();
283 UnparentAndReset( impl.mStencil );
285 impl.RequestTextRelayout();
288 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
290 if( impl.mController )
292 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
293 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
295 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
296 impl.mController->SetHorizontalAlignment( alignment );
301 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
303 if( impl.mController )
305 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
306 if( GetVerticalAlignmentEnumeration( value, alignment ) )
308 impl.mController->SetVerticalAlignment( alignment );
309 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
314 case Toolkit::TextField::Property::TEXT_COLOR:
316 if( impl.mController )
318 const Vector4& textColor = value.Get< Vector4 >();
319 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 );
321 if( impl.mController->GetDefaultColor() != textColor )
323 impl.mController->SetDefaultColor( textColor );
324 impl.mController->SetInputColor( textColor );
325 impl.mRenderer.Reset();
330 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
332 if( impl.mController )
334 const Vector4& textColor = value.Get< Vector4 >();
335 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 );
337 if( impl.mController->GetPlaceholderTextColor() != textColor )
339 impl.mController->SetPlaceholderTextColor( textColor );
340 impl.mRenderer.Reset();
345 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
347 if( impl.mDecorator )
349 const Vector4& color = value.Get< Vector4 >();
350 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 );
352 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
353 impl.RequestTextRelayout();
357 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
359 if( impl.mDecorator )
361 const Vector4& color = value.Get< Vector4 >();
362 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 );
364 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
365 impl.RequestTextRelayout();
369 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
371 if( impl.mController )
373 const bool enable = value.Get< bool >();
374 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
376 impl.mController->SetEnableCursorBlink( enable );
377 impl.RequestTextRelayout();
381 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
383 if( impl.mDecorator )
385 const float interval = value.Get< float >();
386 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
388 impl.mDecorator->SetCursorBlinkInterval( interval );
392 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
394 if( impl.mDecorator )
396 const float duration = value.Get< float >();
397 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
399 impl.mDecorator->SetCursorBlinkDuration( duration );
403 case Toolkit::TextField::Property::CURSOR_WIDTH:
405 if( impl.mDecorator )
407 const int width = value.Get< int >();
408 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
410 impl.mDecorator->SetCursorWidth( width );
411 impl.mController->GetLayoutEngine().SetCursorWidth( width );
415 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
417 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
418 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
420 if( impl.mDecorator )
422 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
423 impl.RequestTextRelayout();
427 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
429 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
430 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
432 if( impl.mDecorator )
434 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
435 impl.RequestTextRelayout();
439 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
441 const float threshold = value.Get< float >();
442 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
444 if( impl.mDecorator )
446 impl.mDecorator->SetScrollThreshold( threshold );
450 case Toolkit::TextField::Property::SCROLL_SPEED:
452 const float speed = value.Get< float >();
453 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
455 if( impl.mDecorator )
457 impl.mDecorator->SetScrollSpeed( speed );
461 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
463 const Image image = Scripting::NewImage( value );
465 if( impl.mDecorator && image )
467 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
468 impl.RequestTextRelayout();
472 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
474 const Image image = Scripting::NewImage( value );
476 if( impl.mDecorator && image )
478 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
479 impl.RequestTextRelayout();
483 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
485 const Image image = Scripting::NewImage( value );
487 if( impl.mDecorator && image )
489 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
490 impl.RequestTextRelayout();
494 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
496 const Image image = Scripting::NewImage( value );
498 if( impl.mDecorator && image )
500 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
501 impl.RequestTextRelayout();
505 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
507 const Image image = Scripting::NewImage( value );
509 if( impl.mDecorator && image )
511 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
512 impl.RequestTextRelayout();
516 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
518 const Image image = Scripting::NewImage( value );
520 if( impl.mDecorator && image )
522 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
523 impl.RequestTextRelayout();
527 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
529 const Vector4 color = value.Get< Vector4 >();
530 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 );
532 if( impl.mDecorator )
534 impl.mDecorator->SetHighlightColor( color );
535 impl.RequestTextRelayout();
539 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
541 if( impl.mDecorator )
543 const Rect<int> box = value.Get< Rect<int> >();
544 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 );
546 impl.mDecorator->SetBoundingBox( box );
547 impl.RequestTextRelayout();
551 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
553 const Property::Map* map = value.GetMap();
556 impl.mInputMethodOptions.ApplyProperty( *map );
558 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
560 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
561 if (control == textField)
563 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
567 case Toolkit::TextField::Property::INPUT_COLOR:
569 if( impl.mController )
571 const Vector4 inputColor = value.Get< Vector4 >();
572 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 );
574 impl.mController->SetInputColor( inputColor );
578 case Toolkit::TextField::Property::ENABLE_MARKUP:
580 if( impl.mController )
582 const bool enableMarkup = value.Get<bool>();
583 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
585 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
589 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
591 if( impl.mController )
593 const std::string& fontFamily = value.Get< std::string >();
594 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
595 impl.mController->SetInputFontFamily( fontFamily );
599 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
601 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
604 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
606 if( impl.mController )
608 const float pointSize = value.Get< float >();
609 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
610 impl.mController->SetInputFontPointSize( pointSize );
614 case Toolkit::TextField::Property::UNDERLINE:
616 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
619 impl.mRenderer.Reset();
623 case Toolkit::TextField::Property::INPUT_UNDERLINE:
625 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
628 impl.mRenderer.Reset();
632 case Toolkit::TextField::Property::SHADOW:
634 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
637 impl.mRenderer.Reset();
641 case Toolkit::TextField::Property::INPUT_SHADOW:
643 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
646 impl.mRenderer.Reset();
650 case Toolkit::TextField::Property::EMBOSS:
652 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
655 impl.mRenderer.Reset();
659 case Toolkit::TextField::Property::INPUT_EMBOSS:
661 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
664 impl.mRenderer.Reset();
668 case Toolkit::TextField::Property::OUTLINE:
670 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
673 impl.mRenderer.Reset();
677 case Toolkit::TextField::Property::INPUT_OUTLINE:
679 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
682 impl.mRenderer.Reset();
686 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
688 const Property::Map* map = value.GetMap();
691 impl.mController->SetHiddenInputOption(*map);
695 case Toolkit::TextField::Property::PIXEL_SIZE:
697 if( impl.mController )
699 const float pixelSize = value.Get< float >();
700 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
702 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
704 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
709 case Toolkit::TextField::Property::ENABLE_SELECTION:
711 if( impl.mController )
713 const bool enableSelection = value.Get< bool >();
714 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
715 impl.mController->SetSelectionEnabled( enableSelection );
719 case Toolkit::TextField::Property::PLACEHOLDER:
721 const Property::Map* map = value.GetMap();
724 impl.mController->SetPlaceholderProperty( *map );
728 case Toolkit::TextField::Property::ELLIPSIS:
730 if( impl.mController )
732 const bool ellipsis = value.Get<bool>();
733 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
735 impl.mController->SetTextElideEnabled( ellipsis );
739 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
741 if( impl.mController )
743 const bool shiftSelection = value.Get<bool>();
744 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
746 impl.mController->SetShiftSelectionEnabled( shiftSelection );
750 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
752 if( impl.mController )
754 const bool grabHandleEnabled = value.Get<bool>();
755 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
757 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
761 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
763 if( impl.mController )
765 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
769 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
771 if( impl.mController )
773 const bool grabHandlePopupEnabled = value.Get<bool>();
774 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
776 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
780 case Toolkit::DevelTextField::Property::BACKGROUND:
782 if( impl.mController )
784 const Vector4 backgroundColor = value.Get< Vector4 >();
785 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 );
787 impl.mController->SetBackgroundEnabled( true );
788 impl.mController->SetBackgroundColor( backgroundColor );
796 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
798 Property::Value value;
800 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
804 TextField& impl( GetImpl( textField ) );
808 case Toolkit::TextField::Property::RENDERING_BACKEND:
810 value = impl.mRenderingBackend;
813 case Toolkit::TextField::Property::TEXT:
815 if( impl.mController )
818 impl.mController->GetText( text );
819 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
824 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
826 if( impl.mController )
829 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
834 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
836 if( impl.mController )
839 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
844 case Toolkit::TextField::Property::FONT_FAMILY:
846 if( impl.mController )
848 value = impl.mController->GetDefaultFontFamily();
852 case Toolkit::TextField::Property::FONT_STYLE:
854 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
857 case Toolkit::TextField::Property::POINT_SIZE:
859 if( impl.mController )
861 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
865 case Toolkit::TextField::Property::MAX_LENGTH:
867 if( impl.mController )
869 value = impl.mController->GetMaximumNumberOfCharacters();
873 case Toolkit::TextField::Property::EXCEED_POLICY:
875 value = impl.mExceedPolicy;
878 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
880 if( impl.mController )
882 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
886 value = std::string( name );
891 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
893 if( impl.mController )
895 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
899 value = std::string( name );
904 case Toolkit::TextField::Property::TEXT_COLOR:
906 if ( impl.mController )
908 value = impl.mController->GetDefaultColor();
912 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
914 if ( impl.mController )
916 value = impl.mController->GetPlaceholderTextColor();
920 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
922 if( impl.mDecorator )
924 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
928 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
930 if( impl.mDecorator )
932 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
936 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
938 value = impl.mController->GetEnableCursorBlink();
941 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
943 if( impl.mDecorator )
945 value = impl.mDecorator->GetCursorBlinkInterval();
949 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
951 if( impl.mDecorator )
953 value = impl.mDecorator->GetCursorBlinkDuration();
957 case Toolkit::TextField::Property::CURSOR_WIDTH:
959 if( impl.mDecorator )
961 value = impl.mDecorator->GetCursorWidth();
965 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
967 if( impl.mDecorator )
969 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
972 value = image.GetUrl();
977 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
979 if( impl.mDecorator )
981 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
984 value = image.GetUrl();
989 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
991 if( impl.mDecorator )
993 value = impl.mDecorator->GetScrollThreshold();
997 case Toolkit::TextField::Property::SCROLL_SPEED:
999 if( impl.mDecorator )
1001 value = impl.mDecorator->GetScrollSpeed();
1005 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1007 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1010 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1012 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1015 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1017 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1020 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1022 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1025 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1027 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1030 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1032 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1035 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1037 if( impl.mDecorator )
1039 value = impl.mDecorator->GetHighlightColor();
1043 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1045 if( impl.mDecorator )
1047 Rect<int> boundingBox;
1048 impl.mDecorator->GetBoundingBox( boundingBox );
1049 value = boundingBox;
1053 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1056 impl.mInputMethodOptions.RetrieveProperty( map );
1060 case Toolkit::TextField::Property::INPUT_COLOR:
1062 if( impl.mController )
1064 value = impl.mController->GetInputColor();
1068 case Toolkit::TextField::Property::ENABLE_MARKUP:
1070 if( impl.mController )
1072 value = impl.mController->IsMarkupProcessorEnabled();
1076 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1078 if( impl.mController )
1080 value = impl.mController->GetInputFontFamily();
1084 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1086 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1089 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1091 if( impl.mController )
1093 value = impl.mController->GetInputFontPointSize();
1097 case Toolkit::TextField::Property::UNDERLINE:
1099 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1102 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1104 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1107 case Toolkit::TextField::Property::SHADOW:
1109 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1112 case Toolkit::TextField::Property::INPUT_SHADOW:
1114 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1117 case Toolkit::TextField::Property::EMBOSS:
1119 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1122 case Toolkit::TextField::Property::INPUT_EMBOSS:
1124 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1127 case Toolkit::TextField::Property::OUTLINE:
1129 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1132 case Toolkit::TextField::Property::INPUT_OUTLINE:
1134 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1137 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1140 impl.mController->GetHiddenInputOption(map);
1144 case Toolkit::TextField::Property::PIXEL_SIZE:
1146 if( impl.mController )
1148 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1152 case Toolkit::TextField::Property::ENABLE_SELECTION:
1154 if( impl.mController )
1156 value = impl.mController->IsSelectionEnabled();
1160 case Toolkit::TextField::Property::PLACEHOLDER:
1163 impl.mController->GetPlaceholderProperty( map );
1167 case Toolkit::TextField::Property::ELLIPSIS:
1169 if( impl.mController )
1171 value = impl.mController->IsTextElideEnabled();
1175 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1177 if( impl.mController )
1179 value = impl.mController->IsShiftSelectionEnabled();
1183 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1185 if( impl.mController )
1187 value = impl.mController->IsGrabHandleEnabled();
1191 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1193 if( impl.mController )
1195 value = impl.mController->IsMatchSystemLanguageDirection();
1199 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1201 if( impl.mController )
1203 value = impl.mController->IsGrabHandlePopupEnabled();
1207 case Toolkit::DevelTextField::Property::BACKGROUND:
1209 if( impl.mController )
1211 value = impl.mController->GetBackgroundColor();
1221 void TextField::SelectWholeText()
1223 if( mController && mController->IsShowingRealText() )
1225 mController->SelectEvent( 0.f, 0.f, true );
1230 InputMethodContext TextField::GetInputMethodContext()
1232 return mInputMethodContext;
1235 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1237 Dali::BaseHandle handle( object );
1239 bool connected( true );
1240 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1242 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1244 field.TextChangedSignal().Connect( tracker, functor );
1246 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1248 field.MaxLengthReachedSignal().Connect( tracker, functor );
1250 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1252 field.InputStyleChangedSignal().Connect( tracker, functor );
1256 // signalName does not match any signal
1263 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1265 return mTextChangedSignal;
1268 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1270 return mMaxLengthReachedSignal;
1273 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1275 return mInputStyleChangedSignal;
1278 void TextField::OnInitialize()
1280 Actor self = Self();
1282 mController = Text::Controller::New( this, this );
1284 // When using the vector-based rendering, the size of the GLyphs are different
1285 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1286 mController->SetGlyphType( glyphType );
1288 mDecorator = Text::Decorator::New( *mController,
1291 mInputMethodContext = InputMethodContext::New( self );
1293 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1295 // Enables the text input.
1296 mController->EnableTextInput( mDecorator, mInputMethodContext );
1298 // Enables the horizontal scrolling after the text input has been enabled.
1299 mController->SetHorizontalScrollEnabled( true );
1301 // Disables the vertical scrolling.
1302 mController->SetVerticalScrollEnabled( false );
1304 // Disable the smooth handle panning.
1305 mController->SetSmoothHandlePanEnabled( false );
1307 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1308 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1310 // Sets layoutDirection value
1311 Dali::Stage stage = Dali::Stage::GetCurrent();
1312 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1313 mController->SetLayoutDirection( layoutDirection );
1315 // Forward input events to controller
1316 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1317 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1319 self.TouchSignal().Connect( this, &TextField::OnTouched );
1321 // Set BoundingBox to stage size if not already set.
1322 Rect<int> boundingBox;
1323 mDecorator->GetBoundingBox( boundingBox );
1325 if( boundingBox.IsEmpty() )
1327 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1328 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1331 // Flip vertically the 'left' selection handle
1332 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1334 // Fill-parent area by default
1335 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1336 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1337 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1339 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1341 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1347 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1349 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1353 case StyleChange::DEFAULT_FONT_CHANGE:
1355 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1356 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1357 // Property system did not set the font so should update it.
1358 mController->UpdateAfterFontChange( newFont );
1363 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1365 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1369 case StyleChange::THEME_CHANGE:
1371 // Nothing to do, let control base class handle this
1376 // Up call to Control
1377 Control::OnStyleChange( styleManager, change );
1380 Vector3 TextField::GetNaturalSize()
1383 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1385 Vector3 naturalSize = mController->GetNaturalSize();
1386 naturalSize.width += ( padding.start + padding.end );
1387 naturalSize.height += ( padding.top + padding.bottom );
1392 float TextField::GetHeightForWidth( float width )
1395 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1396 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1399 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1401 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1403 Actor self = Self();
1406 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1408 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1410 // Support Right-To-Left of padding
1411 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1412 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1414 std::swap( padding.start, padding.end );
1419 mStencil.SetPosition( padding.start, padding.top );
1423 mActiveLayer.SetPosition( padding.start, padding.top );
1426 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1428 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1431 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1434 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1436 mDecorator->Relayout( size );
1441 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1444 RenderText( updateTextType );
1448 // The text-field emits signals when the input style changes. These changes of style are
1449 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1450 // can't be emitted during the size negotiation as the callbacks may update the UI.
1451 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1452 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1454 if( Adaptor::IsAvailable() )
1456 Adaptor& adaptor = Adaptor::Get();
1458 if( NULL == mIdleCallback )
1460 // @note: The callback manager takes the ownership of the callback object.
1461 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1462 adaptor.AddIdle( mIdleCallback, false );
1468 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1470 Actor renderableActor;
1472 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1476 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1478 renderableActor = mRenderer->Render( mController->GetView(),
1480 Property::INVALID_INDEX, // Animatable property not supported
1482 DepthIndex::CONTENT );
1485 if( renderableActor != mRenderableActor )
1487 UnparentAndReset( mBackgroundActor );
1488 UnparentAndReset( mRenderableActor );
1489 mRenderableActor = renderableActor;
1491 if ( mRenderableActor )
1493 mBackgroundActor = mController->CreateBackgroundActor();
1498 if( mRenderableActor )
1500 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1502 float renderableActorPositionX, renderableActorPositionY;
1506 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1507 renderableActorPositionY = scrollOffset.y;
1512 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1514 // Support Right-To-Left of padding
1515 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1516 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1518 std::swap( padding.start, padding.end );
1521 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1522 renderableActorPositionY = scrollOffset.y + padding.top;
1525 mRenderableActor.SetPosition( renderableActorPositionX, renderableActorPositionY );
1527 // Make sure the actors are parented correctly with/without clipping
1528 Actor self = mStencil ? mStencil : Self();
1530 Actor highlightActor;
1532 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1533 endIt = mClippingDecorationActors.end();
1538 it->LowerToBottom();
1540 if ( it->GetName() == "HighlightActor" )
1542 highlightActor = *it;
1545 mClippingDecorationActors.clear();
1547 self.Add( mRenderableActor );
1549 if ( mBackgroundActor )
1551 if ( mDecorator && mDecorator->IsHighlightVisible() )
1553 self.Add( mBackgroundActor );
1554 mBackgroundActor.SetPosition( renderableActorPositionX, renderableActorPositionY); // In text field's coords.
1555 mBackgroundActor.LowerBelow( highlightActor );
1559 mRenderableActor.Add( mBackgroundActor );
1560 mBackgroundActor.SetPosition( 0.0f, 0.0f ); // In renderable actor's coords.
1561 mBackgroundActor.LowerToBottom();
1567 void TextField::OnKeyInputFocusGained()
1569 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1570 if ( mInputMethodContext )
1572 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1574 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1576 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1578 // Notify that the text editing start.
1579 mInputMethodContext.Activate();
1581 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1582 mInputMethodContext.SetRestoreAfterFocusLost( true );
1584 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1588 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1591 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1593 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1596 void TextField::OnKeyInputFocusLost()
1598 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1599 if ( mInputMethodContext )
1601 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1602 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1603 mInputMethodContext.SetRestoreAfterFocusLost( false );
1605 // Notify that the text editing finish.
1606 mInputMethodContext.Deactivate();
1608 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1610 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1614 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1617 mController->KeyboardFocusLostEvent();
1619 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1622 void TextField::OnTap( const TapGesture& gesture )
1624 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1625 if ( mInputMethodContext )
1627 mInputMethodContext.Activate();
1629 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1631 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1632 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1637 void TextField::OnPan( const PanGesture& gesture )
1639 mController->PanEvent( gesture.state, gesture.displacement );
1642 void TextField::OnLongPress( const LongPressGesture& gesture )
1644 if ( mInputMethodContext )
1646 mInputMethodContext.Activate();
1649 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1650 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1655 bool TextField::OnKeyEvent( const KeyEvent& event )
1657 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1659 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1661 // Make sure ClearKeyInputFocus when only key is up
1662 if( event.state == KeyEvent::Up )
1664 ClearKeyInputFocus();
1669 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1671 // Do nothing when enter is comming.
1675 return mController->KeyEvent( event );
1678 void TextField::RequestTextRelayout()
1683 void TextField::TextChanged()
1685 Dali::Toolkit::TextField handle( GetOwner() );
1686 mTextChangedSignal.Emit( handle );
1689 void TextField::MaxLengthReached()
1691 Dali::Toolkit::TextField handle( GetOwner() );
1692 mMaxLengthReachedSignal.Emit( handle );
1695 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1697 Dali::Toolkit::TextField handle( GetOwner() );
1699 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1701 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1703 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1705 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1707 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1709 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1711 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1713 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1715 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1717 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1719 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1721 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1723 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1725 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1727 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1729 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1731 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1733 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1735 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1737 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1739 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1742 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1745 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1751 mClippingDecorationActors.push_back( actor );
1755 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1756 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1757 Self().Add( actor );
1758 mActiveLayer = actor;
1763 void TextField::OnStageConnect( Dali::Actor actor )
1765 if ( mHasBeenStaged )
1767 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1771 mHasBeenStaged = true;
1775 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1777 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1778 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1781 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1785 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1790 Scripting::CreatePropertyMap( image, map );
1796 void TextField::EnableClipping()
1800 // Creates an extra control to be used as stencil buffer.
1801 mStencil = Control::New();
1802 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1803 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1805 // Creates a background visual. Even if the color is transparent it updates the stencil.
1806 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1807 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1808 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1810 // Enable the clipping property.
1811 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1812 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1814 Self().Add( mStencil );
1818 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1820 mController->PasteClipboardItemEvent();
1823 void TextField::KeyboardStatusChanged(bool keyboardShown)
1825 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1827 // Just hide the grab handle when keyboard is hidden.
1828 if (!keyboardShown )
1830 mController->KeyboardFocusLostEvent();
1834 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1838 void TextField::OnStageConnection( int depth )
1840 // Sets the depth to the visuals inside the text's decorator.
1841 mDecorator->SetTextDepth( depth );
1843 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1845 // Call the Control::OnStageConnection() to set the depth of the background.
1846 Control::OnStageConnection( depth );
1849 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1854 void TextField::OnIdleSignal()
1856 // Emits the change of input style signals.
1857 mController->ProcessInputStyleChangedSignals();
1859 // Set the pointer to null as the callback manager deletes the callback after execute it.
1860 mIdleCallback = NULL;
1863 TextField::TextField()
1864 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1865 mIdleCallback( NULL ),
1866 mAlignmentOffset( 0.f ),
1867 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1868 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1869 mHasBeenStaged( false )
1873 TextField::~TextField()
1875 UnparentAndReset( mStencil );
1877 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1879 Adaptor::Get().RemoveIdle( mIdleCallback );
1883 } // namespace Internal
1885 } // namespace Toolkit