2 * Copyright (c) 2018 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/adaptors/adaptor.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/text/rendering-backend.h>
35 #include <dali-toolkit/public-api/text/text-enumerations.h>
36 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47 #include <dali-toolkit/devel-api/controls/control-devel.h>
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 )
137 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
138 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
139 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
141 DALI_TYPE_REGISTRATION_END()
145 Toolkit::TextField TextField::New()
147 // Create the implementation, temporarily owned by this handle on stack
148 IntrusivePtr< TextField > impl = new TextField();
150 // Pass ownership to CustomActor handle
151 Toolkit::TextField handle( *impl );
153 // Second-phase init of the implementation
154 // This can only be done after the CustomActor connection has been made...
160 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
162 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
164 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
169 TextField& impl( GetImpl( textField ) );
173 case Toolkit::TextField::Property::RENDERING_BACKEND:
175 int backend = value.Get< int >();
176 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
178 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
179 if( Text::RENDERING_VECTOR_BASED == backend )
181 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
184 if( impl.mRenderingBackend != backend )
186 impl.mRenderingBackend = backend;
187 impl.mRenderer.Reset();
189 if( impl.mController )
191 // When using the vector-based rendering, the size of the GLyphs are different
192 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
193 impl.mController->SetGlyphType( glyphType );
198 case Toolkit::TextField::Property::TEXT:
200 if( impl.mController )
202 const std::string& text = value.Get< std::string >();
203 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
205 impl.mController->SetText( text );
209 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
211 if( impl.mController )
213 const std::string& text = value.Get< std::string >();
214 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
216 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
220 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
222 if( impl.mController )
224 const std::string& text = value.Get< std::string >();
225 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
227 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
231 case Toolkit::TextField::Property::FONT_FAMILY:
233 if( impl.mController )
235 const std::string& fontFamily = value.Get< std::string >();
236 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
237 impl.mController->SetDefaultFontFamily( fontFamily );
241 case Toolkit::TextField::Property::FONT_STYLE:
243 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
246 case Toolkit::TextField::Property::POINT_SIZE:
248 if( impl.mController )
250 const float pointSize = value.Get< float >();
251 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
253 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
255 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
260 case Toolkit::TextField::Property::MAX_LENGTH:
262 if( impl.mController )
264 const int max = value.Get< int >();
265 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
267 impl.mController->SetMaximumNumberOfCharacters( max );
271 case Toolkit::TextField::Property::EXCEED_POLICY:
273 impl.mExceedPolicy = value.Get<int>();
275 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
277 impl.EnableClipping();
281 UnparentAndReset( impl.mStencil );
283 impl.RequestTextRelayout();
286 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
288 if( impl.mController )
290 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
291 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
293 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
294 impl.mController->SetHorizontalAlignment( alignment );
299 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
301 if( impl.mController )
303 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
304 if( GetVerticalAlignmentEnumeration( value, alignment ) )
306 impl.mController->SetVerticalAlignment( alignment );
307 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
312 case Toolkit::TextField::Property::TEXT_COLOR:
314 if( impl.mController )
316 const Vector4& textColor = value.Get< Vector4 >();
317 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 );
319 if( impl.mController->GetDefaultColor() != textColor )
321 impl.mController->SetDefaultColor( textColor );
322 impl.mController->SetInputColor( textColor );
323 impl.mRenderer.Reset();
328 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
330 if( impl.mController )
332 const Vector4& textColor = value.Get< Vector4 >();
333 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 );
335 if( impl.mController->GetPlaceholderTextColor() != textColor )
337 impl.mController->SetPlaceholderTextColor( textColor );
338 impl.mRenderer.Reset();
343 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
345 if( impl.mDecorator )
347 const Vector4& color = value.Get< Vector4 >();
348 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 );
350 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
351 impl.RequestTextRelayout();
355 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
357 if( impl.mDecorator )
359 const Vector4& color = value.Get< Vector4 >();
360 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 );
362 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
363 impl.RequestTextRelayout();
367 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
369 if( impl.mController )
371 const bool enable = value.Get< bool >();
372 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
374 impl.mController->SetEnableCursorBlink( enable );
375 impl.RequestTextRelayout();
379 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
381 if( impl.mDecorator )
383 const float interval = value.Get< float >();
384 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
386 impl.mDecorator->SetCursorBlinkInterval( interval );
390 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
392 if( impl.mDecorator )
394 const float duration = value.Get< float >();
395 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
397 impl.mDecorator->SetCursorBlinkDuration( duration );
401 case Toolkit::TextField::Property::CURSOR_WIDTH:
403 if( impl.mDecorator )
405 const int width = value.Get< int >();
406 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
408 impl.mDecorator->SetCursorWidth( width );
409 impl.mController->GetLayoutEngine().SetCursorWidth( width );
413 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
415 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
416 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
418 if( impl.mDecorator )
420 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
421 impl.RequestTextRelayout();
425 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
427 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
428 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
430 if( impl.mDecorator )
432 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
433 impl.RequestTextRelayout();
437 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
439 const float threshold = value.Get< float >();
440 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
442 if( impl.mDecorator )
444 impl.mDecorator->SetScrollThreshold( threshold );
448 case Toolkit::TextField::Property::SCROLL_SPEED:
450 const float speed = value.Get< float >();
451 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
453 if( impl.mDecorator )
455 impl.mDecorator->SetScrollSpeed( speed );
459 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
461 const Image image = Scripting::NewImage( value );
463 if( impl.mDecorator && image )
465 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
466 impl.RequestTextRelayout();
470 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
472 const Image image = Scripting::NewImage( value );
474 if( impl.mDecorator && image )
476 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
477 impl.RequestTextRelayout();
481 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
483 const Image image = Scripting::NewImage( value );
485 if( impl.mDecorator && image )
487 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
488 impl.RequestTextRelayout();
492 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
494 const Image image = Scripting::NewImage( value );
496 if( impl.mDecorator && image )
498 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
499 impl.RequestTextRelayout();
503 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
505 const Image image = Scripting::NewImage( value );
507 if( impl.mDecorator && image )
509 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
510 impl.RequestTextRelayout();
514 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
516 const Image image = Scripting::NewImage( value );
518 if( impl.mDecorator && image )
520 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
521 impl.RequestTextRelayout();
525 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
527 const Vector4 color = value.Get< Vector4 >();
528 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 );
530 if( impl.mDecorator )
532 impl.mDecorator->SetHighlightColor( color );
533 impl.RequestTextRelayout();
537 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
539 if( impl.mDecorator )
541 const Rect<int> box = value.Get< Rect<int> >();
542 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 );
544 impl.mDecorator->SetBoundingBox( box );
545 impl.RequestTextRelayout();
549 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
551 const Property::Map* map = value.GetMap();
554 impl.mInputMethodOptions.ApplyProperty( *map );
556 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
558 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
559 if (control == textField)
561 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
565 case Toolkit::TextField::Property::INPUT_COLOR:
567 if( impl.mController )
569 const Vector4 inputColor = value.Get< Vector4 >();
570 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 );
572 impl.mController->SetInputColor( inputColor );
576 case Toolkit::TextField::Property::ENABLE_MARKUP:
578 if( impl.mController )
580 const bool enableMarkup = value.Get<bool>();
581 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
583 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
587 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
589 if( impl.mController )
591 const std::string& fontFamily = value.Get< std::string >();
592 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
593 impl.mController->SetInputFontFamily( fontFamily );
597 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
599 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
602 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
604 if( impl.mController )
606 const float pointSize = value.Get< float >();
607 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
608 impl.mController->SetInputFontPointSize( pointSize );
612 case Toolkit::TextField::Property::UNDERLINE:
614 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
617 impl.mRenderer.Reset();
621 case Toolkit::TextField::Property::INPUT_UNDERLINE:
623 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
626 impl.mRenderer.Reset();
630 case Toolkit::TextField::Property::SHADOW:
632 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
635 impl.mRenderer.Reset();
639 case Toolkit::TextField::Property::INPUT_SHADOW:
641 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
644 impl.mRenderer.Reset();
648 case Toolkit::TextField::Property::EMBOSS:
650 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
653 impl.mRenderer.Reset();
657 case Toolkit::TextField::Property::INPUT_EMBOSS:
659 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
662 impl.mRenderer.Reset();
666 case Toolkit::TextField::Property::OUTLINE:
668 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
671 impl.mRenderer.Reset();
675 case Toolkit::TextField::Property::INPUT_OUTLINE:
677 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
680 impl.mRenderer.Reset();
684 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
686 const Property::Map* map = value.GetMap();
689 impl.mController->SetHiddenInputOption(*map);
693 case Toolkit::TextField::Property::PIXEL_SIZE:
695 if( impl.mController )
697 const float pixelSize = value.Get< float >();
698 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
700 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
702 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
707 case Toolkit::TextField::Property::ENABLE_SELECTION:
709 if( impl.mController )
711 const bool enableSelection = value.Get< bool >();
712 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
713 impl.mController->SetSelectionEnabled( enableSelection );
717 case Toolkit::TextField::Property::PLACEHOLDER:
719 const Property::Map* map = value.GetMap();
722 impl.mController->SetPlaceholderProperty( *map );
726 case Toolkit::TextField::Property::ELLIPSIS:
728 if( impl.mController )
730 const bool ellipsis = value.Get<bool>();
731 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
733 impl.mController->SetTextElideEnabled( ellipsis );
737 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
739 if( impl.mController )
741 const bool shiftSelection = value.Get<bool>();
742 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
744 impl.mController->SetShiftSelectionEnabled( shiftSelection );
748 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
750 if( impl.mController )
752 const bool grabHandleEnabled = value.Get<bool>();
753 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
755 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
759 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
761 if( impl.mController )
763 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
771 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
773 Property::Value value;
775 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
779 TextField& impl( GetImpl( textField ) );
783 case Toolkit::TextField::Property::RENDERING_BACKEND:
785 value = impl.mRenderingBackend;
788 case Toolkit::TextField::Property::TEXT:
790 if( impl.mController )
793 impl.mController->GetText( text );
794 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
799 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
801 if( impl.mController )
804 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
809 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
811 if( impl.mController )
814 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
819 case Toolkit::TextField::Property::FONT_FAMILY:
821 if( impl.mController )
823 value = impl.mController->GetDefaultFontFamily();
827 case Toolkit::TextField::Property::FONT_STYLE:
829 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
832 case Toolkit::TextField::Property::POINT_SIZE:
834 if( impl.mController )
836 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
840 case Toolkit::TextField::Property::MAX_LENGTH:
842 if( impl.mController )
844 value = impl.mController->GetMaximumNumberOfCharacters();
848 case Toolkit::TextField::Property::EXCEED_POLICY:
850 value = impl.mExceedPolicy;
853 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
855 if( impl.mController )
857 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
861 value = std::string( name );
866 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
868 if( impl.mController )
870 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
874 value = std::string( name );
879 case Toolkit::TextField::Property::TEXT_COLOR:
881 if ( impl.mController )
883 value = impl.mController->GetDefaultColor();
887 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
889 if ( impl.mController )
891 value = impl.mController->GetPlaceholderTextColor();
895 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
897 if( impl.mDecorator )
899 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
903 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
905 if( impl.mDecorator )
907 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
911 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
913 value = impl.mController->GetEnableCursorBlink();
916 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
918 if( impl.mDecorator )
920 value = impl.mDecorator->GetCursorBlinkInterval();
924 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
926 if( impl.mDecorator )
928 value = impl.mDecorator->GetCursorBlinkDuration();
932 case Toolkit::TextField::Property::CURSOR_WIDTH:
934 if( impl.mDecorator )
936 value = impl.mDecorator->GetCursorWidth();
940 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
942 if( impl.mDecorator )
944 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
947 value = image.GetUrl();
952 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
954 if( impl.mDecorator )
956 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
959 value = image.GetUrl();
964 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
966 if( impl.mDecorator )
968 value = impl.mDecorator->GetScrollThreshold();
972 case Toolkit::TextField::Property::SCROLL_SPEED:
974 if( impl.mDecorator )
976 value = impl.mDecorator->GetScrollSpeed();
980 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
982 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
985 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
987 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
990 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
992 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
995 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
997 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1000 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1002 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1005 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1007 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1010 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1012 if( impl.mDecorator )
1014 value = impl.mDecorator->GetHighlightColor();
1018 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1020 if( impl.mDecorator )
1022 Rect<int> boundingBox;
1023 impl.mDecorator->GetBoundingBox( boundingBox );
1024 value = boundingBox;
1028 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1031 impl.mInputMethodOptions.RetrieveProperty( map );
1035 case Toolkit::TextField::Property::INPUT_COLOR:
1037 if( impl.mController )
1039 value = impl.mController->GetInputColor();
1043 case Toolkit::TextField::Property::ENABLE_MARKUP:
1045 if( impl.mController )
1047 value = impl.mController->IsMarkupProcessorEnabled();
1051 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1053 if( impl.mController )
1055 value = impl.mController->GetInputFontFamily();
1059 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1061 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1064 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1066 if( impl.mController )
1068 value = impl.mController->GetInputFontPointSize();
1072 case Toolkit::TextField::Property::UNDERLINE:
1074 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1077 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1079 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1082 case Toolkit::TextField::Property::SHADOW:
1084 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1087 case Toolkit::TextField::Property::INPUT_SHADOW:
1089 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1092 case Toolkit::TextField::Property::EMBOSS:
1094 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1097 case Toolkit::TextField::Property::INPUT_EMBOSS:
1099 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1102 case Toolkit::TextField::Property::OUTLINE:
1104 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1107 case Toolkit::TextField::Property::INPUT_OUTLINE:
1109 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1112 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1115 impl.mController->GetHiddenInputOption(map);
1119 case Toolkit::TextField::Property::PIXEL_SIZE:
1121 if( impl.mController )
1123 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1127 case Toolkit::TextField::Property::ENABLE_SELECTION:
1129 if( impl.mController )
1131 value = impl.mController->IsSelectionEnabled();
1135 case Toolkit::TextField::Property::PLACEHOLDER:
1138 impl.mController->GetPlaceholderProperty( map );
1142 case Toolkit::TextField::Property::ELLIPSIS:
1144 if( impl.mController )
1146 value = impl.mController->IsTextElideEnabled();
1150 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1152 if( impl.mController )
1154 value = impl.mController->IsShiftSelectionEnabled();
1158 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1160 if( impl.mController )
1162 value = impl.mController->IsGrabHandleEnabled();
1166 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1168 if( impl.mController )
1170 value = impl.mController->IsMatchSystemLanguageDirection();
1180 InputMethodContext TextField::GetInputMethodContext()
1182 return mInputMethodContext;
1185 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1187 Dali::BaseHandle handle( object );
1189 bool connected( true );
1190 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1192 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1194 field.TextChangedSignal().Connect( tracker, functor );
1196 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1198 field.MaxLengthReachedSignal().Connect( tracker, functor );
1200 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1202 field.InputStyleChangedSignal().Connect( tracker, functor );
1206 // signalName does not match any signal
1213 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1215 return mTextChangedSignal;
1218 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1220 return mMaxLengthReachedSignal;
1223 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1225 return mInputStyleChangedSignal;
1228 void TextField::OnInitialize()
1230 Actor self = Self();
1232 mController = Text::Controller::New( this, this );
1234 // When using the vector-based rendering, the size of the GLyphs are different
1235 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1236 mController->SetGlyphType( glyphType );
1238 mDecorator = Text::Decorator::New( *mController,
1241 mInputMethodContext = InputMethodContext::New();
1243 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1245 // Enables the text input.
1246 mController->EnableTextInput( mDecorator, mInputMethodContext );
1248 // Enables the horizontal scrolling after the text input has been enabled.
1249 mController->SetHorizontalScrollEnabled( true );
1251 // Disables the vertical scrolling.
1252 mController->SetVerticalScrollEnabled( false );
1254 // Disable the smooth handle panning.
1255 mController->SetSmoothHandlePanEnabled( false );
1257 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1258 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1260 // Sets layoutDirection value
1261 Dali::Stage stage = Dali::Stage::GetCurrent();
1262 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1263 mController->SetLayoutDirection( layoutDirection );
1265 // Forward input events to controller
1266 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1267 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1269 self.TouchSignal().Connect( this, &TextField::OnTouched );
1271 // Set BoundingBox to stage size if not already set.
1272 Rect<int> boundingBox;
1273 mDecorator->GetBoundingBox( boundingBox );
1275 if( boundingBox.IsEmpty() )
1277 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1278 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1281 // Flip vertically the 'left' selection handle
1282 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1284 // Fill-parent area by default
1285 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1286 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1287 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1289 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1291 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1297 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1299 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1303 case StyleChange::DEFAULT_FONT_CHANGE:
1305 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1306 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1307 // Property system did not set the font so should update it.
1308 mController->UpdateAfterFontChange( newFont );
1313 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1315 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1319 case StyleChange::THEME_CHANGE:
1321 // Nothing to do, let control base class handle this
1326 // Up call to Control
1327 Control::OnStyleChange( styleManager, change );
1330 Vector3 TextField::GetNaturalSize()
1333 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1335 Vector3 naturalSize = mController->GetNaturalSize();
1336 naturalSize.width += ( padding.start + padding.end );
1337 naturalSize.height += ( padding.top + padding.bottom );
1342 float TextField::GetHeightForWidth( float width )
1345 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1346 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1349 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1351 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1353 Actor self = Self();
1356 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1358 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1360 // Support Right-To-Left of padding
1361 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1362 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1364 std::swap( padding.start, padding.end );
1369 mStencil.SetPosition( padding.start, padding.top );
1373 mActiveLayer.SetPosition( padding.start, padding.top );
1376 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1378 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1381 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1384 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1386 mDecorator->Relayout( size );
1391 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1394 RenderText( updateTextType );
1398 // The text-field emits signals when the input style changes. These changes of style are
1399 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1400 // can't be emitted during the size negotiation as the callbacks may update the UI.
1401 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1402 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1404 if( Adaptor::IsAvailable() )
1406 Adaptor& adaptor = Adaptor::Get();
1408 if( NULL == mIdleCallback )
1410 // @note: The callback manager takes the ownership of the callback object.
1411 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1412 adaptor.AddIdle( mIdleCallback, false );
1418 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1420 Actor renderableActor;
1422 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1426 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1428 renderableActor = mRenderer->Render( mController->GetView(),
1430 Property::INVALID_INDEX, // Animatable property not supported
1432 DepthIndex::CONTENT );
1435 if( renderableActor != mRenderableActor )
1437 UnparentAndReset( mRenderableActor );
1438 mRenderableActor = renderableActor;
1442 if( mRenderableActor )
1444 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1448 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1453 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1455 // Support Right-To-Left of padding
1456 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1457 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1459 std::swap( padding.start, padding.end );
1462 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
1466 // Make sure the actors are parented correctly with/without clipping
1467 Actor self = mStencil ? mStencil : Self();
1469 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1470 endIt = mClippingDecorationActors.end();
1475 it->LowerToBottom();
1477 mClippingDecorationActors.clear();
1479 self.Add( mRenderableActor );
1483 void TextField::OnKeyInputFocusGained()
1485 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1486 if ( mInputMethodContext )
1488 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1490 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1492 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1494 // Notify that the text editing start.
1495 mInputMethodContext.Activate();
1497 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1498 mInputMethodContext.SetRestoreAfterFocusLost( true );
1500 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1504 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1507 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1509 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1512 void TextField::OnKeyInputFocusLost()
1514 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1515 if ( mInputMethodContext )
1517 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1518 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1519 mInputMethodContext.SetRestoreAfterFocusLost( false );
1521 // Notify that the text editing finish.
1522 mInputMethodContext.Deactivate();
1524 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1526 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1530 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1533 mController->KeyboardFocusLostEvent();
1535 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1538 void TextField::OnTap( const TapGesture& gesture )
1540 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1541 if ( mInputMethodContext )
1543 mInputMethodContext.Activate();
1545 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1547 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1548 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1553 void TextField::OnPan( const PanGesture& gesture )
1555 mController->PanEvent( gesture.state, gesture.displacement );
1558 void TextField::OnLongPress( const LongPressGesture& gesture )
1560 if ( mInputMethodContext )
1562 mInputMethodContext.Activate();
1565 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1566 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1571 bool TextField::OnKeyEvent( const KeyEvent& event )
1573 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1575 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1577 // Make sure ClearKeyInputFocus when only key is up
1578 if( event.state == KeyEvent::Up )
1580 ClearKeyInputFocus();
1585 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1587 // Do nothing when enter is comming.
1591 return mController->KeyEvent( event );
1594 void TextField::RequestTextRelayout()
1599 void TextField::TextChanged()
1601 Dali::Toolkit::TextField handle( GetOwner() );
1602 mTextChangedSignal.Emit( handle );
1605 void TextField::MaxLengthReached()
1607 Dali::Toolkit::TextField handle( GetOwner() );
1608 mMaxLengthReachedSignal.Emit( handle );
1611 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1613 Dali::Toolkit::TextField handle( GetOwner() );
1615 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1617 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1619 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1621 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1623 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1625 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1627 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1629 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1631 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1633 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1635 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1637 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1639 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1641 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1643 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1645 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1647 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1649 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1651 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1653 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1655 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1658 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1661 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1667 mClippingDecorationActors.push_back( actor );
1671 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1672 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1673 Self().Add( actor );
1674 mActiveLayer = actor;
1679 void TextField::OnStageConnect( Dali::Actor actor )
1681 if ( mHasBeenStaged )
1683 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1687 mHasBeenStaged = true;
1691 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1693 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1694 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1697 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1701 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1706 Scripting::CreatePropertyMap( image, map );
1712 void TextField::EnableClipping()
1716 // Creates an extra control to be used as stencil buffer.
1717 mStencil = Control::New();
1718 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1719 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1721 // Creates a background visual. Even if the color is transparent it updates the stencil.
1722 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1723 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1724 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1726 // Enable the clipping property.
1727 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1728 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1730 Self().Add( mStencil );
1734 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1736 mController->PasteClipboardItemEvent();
1739 void TextField::KeyboardStatusChanged(bool keyboardShown)
1741 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1743 // Just hide the grab handle when keyboard is hidden.
1744 if (!keyboardShown )
1746 mController->KeyboardFocusLostEvent();
1750 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1754 void TextField::OnStageConnection( int depth )
1756 // Sets the depth to the visuals inside the text's decorator.
1757 mDecorator->SetTextDepth( depth );
1759 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1761 // Call the Control::OnStageConnection() to set the depth of the background.
1762 Control::OnStageConnection( depth );
1765 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1770 void TextField::OnIdleSignal()
1772 // Emits the change of input style signals.
1773 mController->ProcessInputStyleChangedSignals();
1775 // Set the pointer to null as the callback manager deletes the callback after execute it.
1776 mIdleCallback = NULL;
1779 TextField::TextField()
1780 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1781 mIdleCallback( NULL ),
1782 mAlignmentOffset( 0.f ),
1783 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1784 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1785 mHasBeenStaged( false )
1789 TextField::~TextField()
1791 UnparentAndReset( mStencil );
1793 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1795 Adaptor::Get().RemoveIdle( mIdleCallback );
1799 } // namespace Internal
1801 } // namespace Toolkit