2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/devel-api/adaptor-framework/key-devel.h>
25 #include <dali/devel-api/common/stage.h>
26 #include <dali/devel-api/object/property-helper-devel.h>
27 #include <dali/devel-api/actors/actor-devel.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/debug.h>
32 #include <dali-toolkit/public-api/text/text-enumerations.h>
33 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
34 #include <dali-toolkit/devel-api/text/rendering-backend.h>
35 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
38 #include <dali-toolkit/public-api/visuals/visual-properties.h>
39 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
40 #include <dali-toolkit/internal/text/rendering/text-backend.h>
41 #include <dali-toolkit/internal/text/text-effects-style.h>
42 #include <dali-toolkit/internal/text/text-font-style.h>
43 #include <dali-toolkit/internal/text/text-view.h>
44 #include <dali-toolkit/internal/styling/style-manager-impl.h>
45 #include <dali-toolkit/devel-api/controls/control-devel.h>
46 #include <dali/integration-api/adaptor-framework/adaptor.h>
48 using namespace Dali::Toolkit::Text;
59 namespace // unnamed namespace
62 #if defined(DEBUG_ENABLED)
63 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
66 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
67 } // unnamed namespace
74 return Toolkit::TextField::New();
77 // Setup properties, signals and actions using the type-registry.
78 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
80 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
129 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
130 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
134 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
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()
143 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
145 /// Retrieves a filename from a value that is a Property::Map
146 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
148 std::string filename;
149 const Property::Map* map = value.GetMap();
152 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
155 filenameValue->Get( filename );
163 Toolkit::TextField TextField::New()
165 // Create the implementation, temporarily owned by this handle on stack
166 IntrusivePtr< TextField > impl = new TextField();
168 // Pass ownership to CustomActor handle
169 Toolkit::TextField handle( *impl );
171 // Second-phase init of the implementation
172 // This can only be done after the CustomActor connection has been made...
178 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
180 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
182 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
187 TextField& impl( GetImpl( textField ) );
191 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
193 int backend = value.Get< int >();
194 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
196 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
197 if( DevelText::RENDERING_VECTOR_BASED == backend )
199 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
202 if( impl.mRenderingBackend != backend )
204 impl.mRenderingBackend = backend;
205 impl.mRenderer.Reset();
207 if( impl.mController )
209 // When using the vector-based rendering, the size of the GLyphs are different
210 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
211 impl.mController->SetGlyphType( glyphType );
216 case Toolkit::TextField::Property::TEXT:
218 if( impl.mController )
220 const std::string& text = value.Get< std::string >();
221 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
223 impl.mController->SetText( text );
227 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
229 if( impl.mController )
231 const std::string& text = value.Get< std::string >();
232 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
234 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
238 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
240 if( impl.mController )
242 const std::string& text = value.Get< std::string >();
243 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
245 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
249 case Toolkit::TextField::Property::FONT_FAMILY:
251 if( impl.mController )
253 const std::string& fontFamily = value.Get< std::string >();
254 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
255 impl.mController->SetDefaultFontFamily( fontFamily );
259 case Toolkit::TextField::Property::FONT_STYLE:
261 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
264 case Toolkit::TextField::Property::POINT_SIZE:
266 if( impl.mController )
268 const float pointSize = value.Get< float >();
269 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
271 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
273 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
278 case Toolkit::TextField::Property::MAX_LENGTH:
280 if( impl.mController )
282 const int max = value.Get< int >();
283 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
285 impl.mController->SetMaximumNumberOfCharacters( max );
289 case Toolkit::TextField::Property::EXCEED_POLICY:
291 impl.mExceedPolicy = value.Get<int>();
293 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
295 impl.EnableClipping();
299 UnparentAndReset( impl.mStencil );
301 impl.RequestTextRelayout();
304 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
306 if( impl.mController )
308 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
309 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
311 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
312 impl.mController->SetHorizontalAlignment( alignment );
317 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
319 if( impl.mController )
321 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
322 if( GetVerticalAlignmentEnumeration( value, alignment ) )
324 impl.mController->SetVerticalAlignment( alignment );
325 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
330 case Toolkit::TextField::Property::TEXT_COLOR:
332 if( impl.mController )
334 const Vector4& textColor = value.Get< Vector4 >();
335 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 );
337 if( impl.mController->GetDefaultColor() != textColor )
339 impl.mController->SetDefaultColor( textColor );
340 impl.mController->SetInputColor( textColor );
341 impl.mRenderer.Reset();
346 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
348 if( impl.mController )
350 const Vector4& textColor = value.Get< Vector4 >();
351 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 );
353 if( impl.mController->GetPlaceholderTextColor() != textColor )
355 impl.mController->SetPlaceholderTextColor( textColor );
356 impl.mRenderer.Reset();
361 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
363 if( impl.mDecorator )
365 const Vector4& color = value.Get< Vector4 >();
366 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 );
368 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
369 impl.RequestTextRelayout();
373 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
375 if( impl.mDecorator )
377 const Vector4& color = value.Get< Vector4 >();
378 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 );
380 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
381 impl.RequestTextRelayout();
385 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
387 if( impl.mController )
389 const bool enable = value.Get< bool >();
390 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
392 impl.mController->SetEnableCursorBlink( enable );
393 impl.RequestTextRelayout();
397 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
399 if( impl.mDecorator )
401 const float interval = value.Get< float >();
402 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
404 impl.mDecorator->SetCursorBlinkInterval( interval );
408 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
410 if( impl.mDecorator )
412 const float duration = value.Get< float >();
413 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
415 impl.mDecorator->SetCursorBlinkDuration( duration );
419 case Toolkit::TextField::Property::CURSOR_WIDTH:
421 if( impl.mDecorator )
423 const int width = value.Get< int >();
424 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
426 impl.mDecorator->SetCursorWidth( width );
427 impl.mController->GetLayoutEngine().SetCursorWidth( width );
431 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
433 const std::string imageFileName = value.Get< std::string >();
434 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
436 if( impl.mDecorator && imageFileName.size() )
438 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
439 impl.RequestTextRelayout();
443 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
445 const std::string imageFileName = value.Get< std::string >();
446 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
448 if( impl.mDecorator && imageFileName.size() )
450 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
451 impl.RequestTextRelayout();
455 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
457 const float threshold = value.Get< float >();
458 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
460 if( impl.mDecorator )
462 impl.mDecorator->SetScrollThreshold( threshold );
466 case Toolkit::TextField::Property::SCROLL_SPEED:
468 const float speed = value.Get< float >();
469 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
471 if( impl.mDecorator )
473 impl.mDecorator->SetScrollSpeed( speed );
477 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
479 const std::string filename = GetImageFileNameFromPropertyValue( value );
481 if( impl.mDecorator && filename.size() )
483 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
484 impl.RequestTextRelayout();
488 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
490 const std::string filename = GetImageFileNameFromPropertyValue( value );
492 if( impl.mDecorator && filename.size() )
494 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
495 impl.RequestTextRelayout();
499 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
501 const std::string filename = GetImageFileNameFromPropertyValue( value );
503 if( impl.mDecorator && filename.size() )
505 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
506 impl.RequestTextRelayout();
510 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
512 const std::string filename = GetImageFileNameFromPropertyValue( value );
514 if( impl.mDecorator && filename.size() )
516 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
517 impl.RequestTextRelayout();
521 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
523 const std::string filename = GetImageFileNameFromPropertyValue( value );
525 if( impl.mDecorator && filename.size() )
527 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
528 impl.RequestTextRelayout();
532 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
534 const std::string filename = GetImageFileNameFromPropertyValue( value );
536 if( impl.mDecorator && filename.size() )
538 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
539 impl.RequestTextRelayout();
543 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
545 const Vector4 color = value.Get< Vector4 >();
546 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 );
548 if( impl.mDecorator )
550 impl.mDecorator->SetHighlightColor( color );
551 impl.RequestTextRelayout();
555 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
557 if( impl.mDecorator )
559 const Rect<int> box = value.Get< Rect<int> >();
560 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 );
562 impl.mDecorator->SetBoundingBox( box );
563 impl.RequestTextRelayout();
567 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
569 const Property::Map* map = value.GetMap();
572 impl.mInputMethodOptions.ApplyProperty( *map );
574 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
576 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
577 if (control == textField)
579 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
583 case Toolkit::TextField::Property::INPUT_COLOR:
585 if( impl.mController )
587 const Vector4 inputColor = value.Get< Vector4 >();
588 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 );
590 impl.mController->SetInputColor( inputColor );
594 case Toolkit::TextField::Property::ENABLE_MARKUP:
596 if( impl.mController )
598 const bool enableMarkup = value.Get<bool>();
599 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
601 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
605 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
607 if( impl.mController )
609 const std::string& fontFamily = value.Get< std::string >();
610 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
611 impl.mController->SetInputFontFamily( fontFamily );
615 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
617 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
620 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
622 if( impl.mController )
624 const float pointSize = value.Get< float >();
625 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
626 impl.mController->SetInputFontPointSize( pointSize );
630 case Toolkit::TextField::Property::UNDERLINE:
632 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
635 impl.mRenderer.Reset();
639 case Toolkit::TextField::Property::INPUT_UNDERLINE:
641 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
644 impl.mRenderer.Reset();
648 case Toolkit::TextField::Property::SHADOW:
650 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
653 impl.mRenderer.Reset();
657 case Toolkit::TextField::Property::INPUT_SHADOW:
659 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
662 impl.mRenderer.Reset();
666 case Toolkit::TextField::Property::EMBOSS:
668 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
671 impl.mRenderer.Reset();
675 case Toolkit::TextField::Property::INPUT_EMBOSS:
677 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
680 impl.mRenderer.Reset();
684 case Toolkit::TextField::Property::OUTLINE:
686 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
689 impl.mRenderer.Reset();
693 case Toolkit::TextField::Property::INPUT_OUTLINE:
695 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
698 impl.mRenderer.Reset();
702 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
704 const Property::Map* map = value.GetMap();
707 impl.mController->SetHiddenInputOption(*map);
711 case Toolkit::TextField::Property::PIXEL_SIZE:
713 if( impl.mController )
715 const float pixelSize = value.Get< float >();
716 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
718 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
720 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
725 case Toolkit::TextField::Property::ENABLE_SELECTION:
727 if( impl.mController )
729 const bool enableSelection = value.Get< bool >();
730 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
731 impl.mController->SetSelectionEnabled( enableSelection );
735 case Toolkit::TextField::Property::PLACEHOLDER:
737 const Property::Map* map = value.GetMap();
740 impl.mController->SetPlaceholderProperty( *map );
744 case Toolkit::TextField::Property::ELLIPSIS:
746 if( impl.mController )
748 const bool ellipsis = value.Get<bool>();
749 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
751 impl.mController->SetTextElideEnabled( ellipsis );
755 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
757 if( impl.mController )
759 const bool shiftSelection = value.Get<bool>();
760 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
762 impl.mController->SetShiftSelectionEnabled( shiftSelection );
766 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
768 if( impl.mController )
770 const bool grabHandleEnabled = value.Get<bool>();
771 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
773 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
777 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
779 if( impl.mController )
781 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
785 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
787 if( impl.mController )
789 const bool grabHandlePopupEnabled = value.Get<bool>();
790 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
792 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
796 case Toolkit::DevelTextField::Property::BACKGROUND:
798 if( impl.mController )
800 const Vector4 backgroundColor = value.Get< Vector4 >();
801 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 );
803 impl.mController->SetBackgroundEnabled( true );
804 impl.mController->SetBackgroundColor( backgroundColor );
812 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
814 Property::Value value;
816 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
820 TextField& impl( GetImpl( textField ) );
824 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
826 value = impl.mRenderingBackend;
829 case Toolkit::TextField::Property::TEXT:
831 if( impl.mController )
834 impl.mController->GetText( text );
835 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
840 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
842 if( impl.mController )
845 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
850 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
852 if( impl.mController )
855 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
860 case Toolkit::TextField::Property::FONT_FAMILY:
862 if( impl.mController )
864 value = impl.mController->GetDefaultFontFamily();
868 case Toolkit::TextField::Property::FONT_STYLE:
870 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
873 case Toolkit::TextField::Property::POINT_SIZE:
875 if( impl.mController )
877 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
881 case Toolkit::TextField::Property::MAX_LENGTH:
883 if( impl.mController )
885 value = impl.mController->GetMaximumNumberOfCharacters();
889 case Toolkit::TextField::Property::EXCEED_POLICY:
891 value = impl.mExceedPolicy;
894 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
896 if( impl.mController )
898 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
902 value = std::string( name );
907 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
909 if( impl.mController )
911 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
915 value = std::string( name );
920 case Toolkit::TextField::Property::TEXT_COLOR:
922 if ( impl.mController )
924 value = impl.mController->GetDefaultColor();
928 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
930 if ( impl.mController )
932 value = impl.mController->GetPlaceholderTextColor();
936 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
938 if( impl.mDecorator )
940 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
944 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
946 if( impl.mDecorator )
948 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
952 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
954 value = impl.mController->GetEnableCursorBlink();
957 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
959 if( impl.mDecorator )
961 value = impl.mDecorator->GetCursorBlinkInterval();
965 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
967 if( impl.mDecorator )
969 value = impl.mDecorator->GetCursorBlinkDuration();
973 case Toolkit::TextField::Property::CURSOR_WIDTH:
975 if( impl.mDecorator )
977 value = impl.mDecorator->GetCursorWidth();
981 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
983 if( impl.mDecorator )
985 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
989 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
991 if( impl.mDecorator )
993 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
997 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
999 if( impl.mDecorator )
1001 value = impl.mDecorator->GetScrollThreshold();
1005 case Toolkit::TextField::Property::SCROLL_SPEED:
1007 if( impl.mDecorator )
1009 value = impl.mDecorator->GetScrollSpeed();
1013 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1015 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1018 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1020 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1023 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1025 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1028 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1030 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1033 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1035 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1038 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1040 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1043 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1045 if( impl.mDecorator )
1047 value = impl.mDecorator->GetHighlightColor();
1051 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1053 if( impl.mDecorator )
1055 Rect<int> boundingBox;
1056 impl.mDecorator->GetBoundingBox( boundingBox );
1057 value = boundingBox;
1061 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1064 impl.mInputMethodOptions.RetrieveProperty( map );
1068 case Toolkit::TextField::Property::INPUT_COLOR:
1070 if( impl.mController )
1072 value = impl.mController->GetInputColor();
1076 case Toolkit::TextField::Property::ENABLE_MARKUP:
1078 if( impl.mController )
1080 value = impl.mController->IsMarkupProcessorEnabled();
1084 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1086 if( impl.mController )
1088 value = impl.mController->GetInputFontFamily();
1092 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1094 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1097 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1099 if( impl.mController )
1101 value = impl.mController->GetInputFontPointSize();
1105 case Toolkit::TextField::Property::UNDERLINE:
1107 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1110 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1112 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1115 case Toolkit::TextField::Property::SHADOW:
1117 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1120 case Toolkit::TextField::Property::INPUT_SHADOW:
1122 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1125 case Toolkit::TextField::Property::EMBOSS:
1127 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1130 case Toolkit::TextField::Property::INPUT_EMBOSS:
1132 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1135 case Toolkit::TextField::Property::OUTLINE:
1137 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1140 case Toolkit::TextField::Property::INPUT_OUTLINE:
1142 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1145 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1148 impl.mController->GetHiddenInputOption(map);
1152 case Toolkit::TextField::Property::PIXEL_SIZE:
1154 if( impl.mController )
1156 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1160 case Toolkit::TextField::Property::ENABLE_SELECTION:
1162 if( impl.mController )
1164 value = impl.mController->IsSelectionEnabled();
1168 case Toolkit::TextField::Property::PLACEHOLDER:
1171 impl.mController->GetPlaceholderProperty( map );
1175 case Toolkit::TextField::Property::ELLIPSIS:
1177 if( impl.mController )
1179 value = impl.mController->IsTextElideEnabled();
1183 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1185 if( impl.mController )
1187 value = impl.mController->IsShiftSelectionEnabled();
1191 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1193 if( impl.mController )
1195 value = impl.mController->IsGrabHandleEnabled();
1199 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1201 if( impl.mController )
1203 value = impl.mController->IsMatchSystemLanguageDirection();
1207 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1209 if( impl.mController )
1211 value = impl.mController->IsGrabHandlePopupEnabled();
1215 case Toolkit::DevelTextField::Property::BACKGROUND:
1217 if( impl.mController )
1219 value = impl.mController->GetBackgroundColor();
1223 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1225 if( impl.mController )
1227 value = impl.mController->GetSelectedText( );
1237 void TextField::SelectWholeText()
1239 if( mController && mController->IsShowingRealText() )
1241 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1246 void TextField::SelectNone()
1248 if( mController && mController->IsShowingRealText() )
1250 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1255 InputMethodContext TextField::GetInputMethodContext()
1257 return mInputMethodContext;
1260 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1262 Dali::BaseHandle handle( object );
1264 bool connected( true );
1265 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1267 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1269 field.TextChangedSignal().Connect( tracker, functor );
1271 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1273 field.MaxLengthReachedSignal().Connect( tracker, functor );
1275 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1277 field.InputStyleChangedSignal().Connect( tracker, functor );
1281 // signalName does not match any signal
1288 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1290 return mTextChangedSignal;
1293 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1295 return mMaxLengthReachedSignal;
1298 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1300 return mInputStyleChangedSignal;
1303 void TextField::OnInitialize()
1305 Actor self = Self();
1307 mController = Text::Controller::New( this, this );
1309 // When using the vector-based rendering, the size of the GLyphs are different
1310 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1311 mController->SetGlyphType( glyphType );
1313 mDecorator = Text::Decorator::New( *mController,
1316 mInputMethodContext = InputMethodContext::New( self );
1318 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1320 // Enables the text input.
1321 mController->EnableTextInput( mDecorator, mInputMethodContext );
1323 // Enables the horizontal scrolling after the text input has been enabled.
1324 mController->SetHorizontalScrollEnabled( true );
1326 // Disables the vertical scrolling.
1327 mController->SetVerticalScrollEnabled( false );
1329 // Disable the smooth handle panning.
1330 mController->SetSmoothHandlePanEnabled( false );
1332 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1333 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1335 // Sets layoutDirection value
1336 Dali::Stage stage = Dali::Stage::GetCurrent();
1337 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1338 mController->SetLayoutDirection( layoutDirection );
1340 // Forward input events to controller
1341 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1342 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1344 self.TouchSignal().Connect( this, &TextField::OnTouched );
1346 // Set BoundingBox to stage size if not already set.
1347 Rect<int> boundingBox;
1348 mDecorator->GetBoundingBox( boundingBox );
1350 if( boundingBox.IsEmpty() )
1352 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1353 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1356 // Flip vertically the 'left' selection handle
1357 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1359 // Fill-parent area by default
1360 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1361 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1362 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1364 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1366 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1372 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1374 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1378 case StyleChange::DEFAULT_FONT_CHANGE:
1380 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1381 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1382 // Property system did not set the font so should update it.
1383 mController->UpdateAfterFontChange( newFont );
1388 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1390 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1394 case StyleChange::THEME_CHANGE:
1396 // Nothing to do, let control base class handle this
1401 // Up call to Control
1402 Control::OnStyleChange( styleManager, change );
1405 Vector3 TextField::GetNaturalSize()
1408 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1410 Vector3 naturalSize = mController->GetNaturalSize();
1411 naturalSize.width += ( padding.start + padding.end );
1412 naturalSize.height += ( padding.top + padding.bottom );
1417 float TextField::GetHeightForWidth( float width )
1420 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1421 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1424 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1426 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1428 Actor self = Self();
1431 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1433 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1435 // Support Right-To-Left of padding
1436 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1437 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1439 std::swap( padding.start, padding.end );
1444 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1448 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1451 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1453 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1456 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1459 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1461 mDecorator->Relayout( size );
1466 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1469 RenderText( updateTextType );
1473 // The text-field emits signals when the input style changes. These changes of style are
1474 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1475 // can't be emitted during the size negotiation as the callbacks may update the UI.
1476 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1477 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1479 if( Adaptor::IsAvailable() )
1481 Adaptor& adaptor = Adaptor::Get();
1483 if( NULL == mIdleCallback )
1485 // @note: The callback manager takes the ownership of the callback object.
1486 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1487 adaptor.AddIdle( mIdleCallback, false );
1493 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1495 Actor renderableActor;
1497 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1501 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1503 renderableActor = mRenderer->Render( mController->GetView(),
1505 Property::INVALID_INDEX, // Animatable property not supported
1507 DepthIndex::CONTENT );
1510 if( renderableActor != mRenderableActor )
1512 UnparentAndReset( mBackgroundActor );
1513 UnparentAndReset( mRenderableActor );
1514 mRenderableActor = renderableActor;
1516 if ( mRenderableActor )
1518 mBackgroundActor = mController->CreateBackgroundActor();
1523 if( mRenderableActor )
1525 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1527 float renderableActorPositionX, renderableActorPositionY;
1531 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1532 renderableActorPositionY = scrollOffset.y;
1537 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1539 // Support Right-To-Left of padding
1540 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1541 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1543 std::swap( padding.start, padding.end );
1546 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1547 renderableActorPositionY = scrollOffset.y + padding.top;
1550 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1552 // Make sure the actors are parented correctly with/without clipping
1553 Actor self = mStencil ? mStencil : Self();
1555 Actor highlightActor;
1557 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1558 endIt = mClippingDecorationActors.end();
1563 it->LowerToBottom();
1565 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1567 highlightActor = *it;
1570 mClippingDecorationActors.clear();
1572 self.Add( mRenderableActor );
1574 if ( mBackgroundActor )
1576 if ( mDecorator && mDecorator->IsHighlightVisible() )
1578 self.Add( mBackgroundActor );
1579 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1580 mBackgroundActor.LowerBelow( highlightActor );
1584 mRenderableActor.Add( mBackgroundActor );
1585 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1586 mBackgroundActor.LowerToBottom();
1592 void TextField::OnKeyInputFocusGained()
1594 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1595 if ( mInputMethodContext )
1597 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1599 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1601 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1603 // Notify that the text editing start.
1604 mInputMethodContext.Activate();
1606 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1607 mInputMethodContext.SetRestoreAfterFocusLost( true );
1609 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1613 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1616 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1618 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1621 void TextField::OnKeyInputFocusLost()
1623 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1624 if ( mInputMethodContext )
1626 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1627 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1628 mInputMethodContext.SetRestoreAfterFocusLost( false );
1630 // Notify that the text editing finish.
1631 mInputMethodContext.Deactivate();
1633 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1635 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1639 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1642 mController->KeyboardFocusLostEvent();
1644 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1647 void TextField::OnTap( const TapGesture& gesture )
1649 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1650 if ( mInputMethodContext )
1652 mInputMethodContext.Activate();
1654 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1656 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1657 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1662 void TextField::OnPan( const PanGesture& gesture )
1664 mController->PanEvent( gesture.state, gesture.displacement );
1667 void TextField::OnLongPress( const LongPressGesture& gesture )
1669 if ( mInputMethodContext )
1671 mInputMethodContext.Activate();
1674 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1675 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1680 bool TextField::OnKeyEvent( const KeyEvent& event )
1682 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1684 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1686 // Make sure ClearKeyInputFocus when only key is up
1687 if( event.state == KeyEvent::Up )
1689 ClearKeyInputFocus();
1694 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1696 // Do nothing when enter is comming.
1700 return mController->KeyEvent( event );
1703 void TextField::RequestTextRelayout()
1708 void TextField::TextChanged()
1710 Dali::Toolkit::TextField handle( GetOwner() );
1711 mTextChangedSignal.Emit( handle );
1714 void TextField::MaxLengthReached()
1716 Dali::Toolkit::TextField handle( GetOwner() );
1717 mMaxLengthReachedSignal.Emit( handle );
1720 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1722 Dali::Toolkit::TextField handle( GetOwner() );
1724 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1726 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1728 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1730 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1732 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1734 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1736 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1738 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1740 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1742 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1744 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1746 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1748 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1750 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1752 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1754 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1756 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1758 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1760 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1762 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1764 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1767 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1770 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1776 mClippingDecorationActors.push_back( actor );
1780 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1781 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1782 Self().Add( actor );
1783 mActiveLayer = actor;
1788 void TextField::OnSceneConnect( Dali::Actor actor )
1790 if ( mHasBeenStaged )
1792 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1796 mHasBeenStaged = true;
1800 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1802 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1803 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1806 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1811 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1816 void TextField::EnableClipping()
1820 // Creates an extra control to be used as stencil buffer.
1821 mStencil = Control::New();
1822 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1823 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1825 // Creates a background visual. Even if the color is transparent it updates the stencil.
1826 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1827 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1828 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1830 // Enable the clipping property.
1831 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1832 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1834 Self().Add( mStencil );
1838 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1840 mController->PasteClipboardItemEvent();
1843 void TextField::KeyboardStatusChanged(bool keyboardShown)
1845 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1847 // Just hide the grab handle when keyboard is hidden.
1848 if (!keyboardShown )
1850 mController->KeyboardFocusLostEvent();
1854 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1858 void TextField::OnSceneConnection( int depth )
1860 // Sets the depth to the visuals inside the text's decorator.
1861 mDecorator->SetTextDepth( depth );
1863 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1865 // Call the Control::OnSceneConnection() to set the depth of the background.
1866 Control::OnSceneConnection( depth );
1869 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1874 void TextField::OnIdleSignal()
1876 // Emits the change of input style signals.
1877 mController->ProcessInputStyleChangedSignals();
1879 // Set the pointer to null as the callback manager deletes the callback after execute it.
1880 mIdleCallback = NULL;
1883 TextField::TextField()
1884 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1885 mIdleCallback( NULL ),
1886 mAlignmentOffset( 0.f ),
1887 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1888 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1889 mHasBeenStaged( false )
1893 TextField::~TextField()
1895 UnparentAndReset( mStencil );
1897 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1899 Adaptor::Get().RemoveIdle( mIdleCallback );
1903 } // namespace Internal
1905 } // namespace Toolkit