2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/devel-api/adaptor-framework/key-devel.h>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/devel-api/object/property-helper-devel.h>
28 #include <dali/devel-api/actors/actor-devel.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali/integration-api/debug.h>
33 #include <dali-toolkit/public-api/text/rendering-backend.h>
34 #include <dali-toolkit/public-api/text/text-enumerations.h>
35 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
36 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
38 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
39 #include <dali-toolkit/public-api/visuals/visual-properties.h>
40 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-font-style.h>
44 #include <dali-toolkit/internal/text/text-view.h>
45 #include <dali-toolkit/internal/styling/style-manager-impl.h>
46 #include <dali-toolkit/devel-api/controls/control-devel.h>
47 #include <dali/integration-api/adaptor-framework/adaptor.h>
49 using namespace Dali::Toolkit::Text;
60 namespace // unnamed namespace
63 #if defined(DEBUG_ENABLED)
64 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
67 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
68 } // unnamed namespace
75 return Toolkit::TextField::New();
78 // Setup properties, signals and actions using the type-registry.
79 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "reservedProperty01", STRING, RESERVED_PROPERTY_01 )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "reservedProperty02", STRING, RESERVED_PROPERTY_02 )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
138 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
140 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
144 DALI_TYPE_REGISTRATION_END()
148 Toolkit::TextField TextField::New()
150 // Create the implementation, temporarily owned by this handle on stack
151 IntrusivePtr< TextField > impl = new TextField();
153 // Pass ownership to CustomActor handle
154 Toolkit::TextField handle( *impl );
156 // Second-phase init of the implementation
157 // This can only be done after the CustomActor connection has been made...
163 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
165 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
167 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
172 TextField& impl( GetImpl( textField ) );
176 case Toolkit::TextField::Property::RENDERING_BACKEND:
178 int backend = value.Get< int >();
179 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
181 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
182 if( Text::RENDERING_VECTOR_BASED == backend )
184 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
187 if( impl.mRenderingBackend != backend )
189 impl.mRenderingBackend = backend;
190 impl.mRenderer.Reset();
192 if( impl.mController )
194 // When using the vector-based rendering, the size of the GLyphs are different
195 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
196 impl.mController->SetGlyphType( glyphType );
201 case Toolkit::TextField::Property::TEXT:
203 if( impl.mController )
205 const std::string& text = value.Get< std::string >();
206 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
208 impl.mController->SetText( text );
212 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
214 if( impl.mController )
216 const std::string& text = value.Get< std::string >();
217 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
219 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
223 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
225 if( impl.mController )
227 const std::string& text = value.Get< std::string >();
228 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
230 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
234 case Toolkit::TextField::Property::FONT_FAMILY:
236 if( impl.mController )
238 const std::string& fontFamily = value.Get< std::string >();
239 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
240 impl.mController->SetDefaultFontFamily( fontFamily );
244 case Toolkit::TextField::Property::FONT_STYLE:
246 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
249 case Toolkit::TextField::Property::POINT_SIZE:
251 if( impl.mController )
253 const float pointSize = value.Get< float >();
254 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
256 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
258 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
263 case Toolkit::TextField::Property::MAX_LENGTH:
265 if( impl.mController )
267 const int max = value.Get< int >();
268 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
270 impl.mController->SetMaximumNumberOfCharacters( max );
274 case Toolkit::TextField::Property::EXCEED_POLICY:
276 impl.mExceedPolicy = value.Get<int>();
278 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
280 impl.EnableClipping();
284 UnparentAndReset( impl.mStencil );
286 impl.RequestTextRelayout();
289 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
291 if( impl.mController )
293 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
294 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
296 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
297 impl.mController->SetHorizontalAlignment( alignment );
302 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
304 if( impl.mController )
306 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
307 if( GetVerticalAlignmentEnumeration( value, alignment ) )
309 impl.mController->SetVerticalAlignment( alignment );
310 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
315 case Toolkit::TextField::Property::TEXT_COLOR:
317 if( impl.mController )
319 const Vector4& textColor = value.Get< Vector4 >();
320 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 );
322 if( impl.mController->GetDefaultColor() != textColor )
324 impl.mController->SetDefaultColor( textColor );
325 impl.mController->SetInputColor( textColor );
326 impl.mRenderer.Reset();
331 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
333 if( impl.mController )
335 const Vector4& textColor = value.Get< Vector4 >();
336 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 );
338 if( impl.mController->GetPlaceholderTextColor() != textColor )
340 impl.mController->SetPlaceholderTextColor( textColor );
341 impl.mRenderer.Reset();
346 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
348 if( impl.mDecorator )
350 const Vector4& color = value.Get< Vector4 >();
351 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 );
353 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
354 impl.RequestTextRelayout();
358 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
360 if( impl.mDecorator )
362 const Vector4& color = value.Get< Vector4 >();
363 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 );
365 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
366 impl.RequestTextRelayout();
370 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
372 if( impl.mController )
374 const bool enable = value.Get< bool >();
375 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
377 impl.mController->SetEnableCursorBlink( enable );
378 impl.RequestTextRelayout();
382 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
384 if( impl.mDecorator )
386 const float interval = value.Get< float >();
387 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
389 impl.mDecorator->SetCursorBlinkInterval( interval );
393 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
395 if( impl.mDecorator )
397 const float duration = value.Get< float >();
398 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
400 impl.mDecorator->SetCursorBlinkDuration( duration );
404 case Toolkit::TextField::Property::CURSOR_WIDTH:
406 if( impl.mDecorator )
408 const int width = value.Get< int >();
409 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
411 impl.mDecorator->SetCursorWidth( width );
412 impl.mController->GetLayoutEngine().SetCursorWidth( width );
416 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
418 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
419 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
421 if( impl.mDecorator )
423 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
424 impl.RequestTextRelayout();
428 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
430 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
431 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
433 if( impl.mDecorator )
435 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
436 impl.RequestTextRelayout();
440 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
442 const float threshold = value.Get< float >();
443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
445 if( impl.mDecorator )
447 impl.mDecorator->SetScrollThreshold( threshold );
451 case Toolkit::TextField::Property::SCROLL_SPEED:
453 const float speed = value.Get< float >();
454 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
456 if( impl.mDecorator )
458 impl.mDecorator->SetScrollSpeed( speed );
462 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
464 const Image image = Scripting::NewImage( value );
466 if( impl.mDecorator && image )
468 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
469 impl.RequestTextRelayout();
473 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
475 const Image image = Scripting::NewImage( value );
477 if( impl.mDecorator && image )
479 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
480 impl.RequestTextRelayout();
484 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
486 const Image image = Scripting::NewImage( value );
488 if( impl.mDecorator && image )
490 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
491 impl.RequestTextRelayout();
495 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
497 const Image image = Scripting::NewImage( value );
499 if( impl.mDecorator && image )
501 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
502 impl.RequestTextRelayout();
506 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
508 const Image image = Scripting::NewImage( value );
510 if( impl.mDecorator && image )
512 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
513 impl.RequestTextRelayout();
517 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
519 const Image image = Scripting::NewImage( value );
521 if( impl.mDecorator && image )
523 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
524 impl.RequestTextRelayout();
528 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
530 const Vector4 color = value.Get< Vector4 >();
531 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 );
533 if( impl.mDecorator )
535 impl.mDecorator->SetHighlightColor( color );
536 impl.RequestTextRelayout();
540 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
542 if( impl.mDecorator )
544 const Rect<int> box = value.Get< Rect<int> >();
545 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 );
547 impl.mDecorator->SetBoundingBox( box );
548 impl.RequestTextRelayout();
552 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
554 const Property::Map* map = value.GetMap();
557 impl.mInputMethodOptions.ApplyProperty( *map );
559 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
561 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
562 if (control == textField)
564 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
568 case Toolkit::TextField::Property::INPUT_COLOR:
570 if( impl.mController )
572 const Vector4 inputColor = value.Get< Vector4 >();
573 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 );
575 impl.mController->SetInputColor( inputColor );
579 case Toolkit::TextField::Property::ENABLE_MARKUP:
581 if( impl.mController )
583 const bool enableMarkup = value.Get<bool>();
584 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
586 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
590 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
592 if( impl.mController )
594 const std::string& fontFamily = value.Get< std::string >();
595 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
596 impl.mController->SetInputFontFamily( fontFamily );
600 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
602 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
605 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
607 if( impl.mController )
609 const float pointSize = value.Get< float >();
610 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
611 impl.mController->SetInputFontPointSize( pointSize );
615 case Toolkit::TextField::Property::UNDERLINE:
617 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
620 impl.mRenderer.Reset();
624 case Toolkit::TextField::Property::INPUT_UNDERLINE:
626 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
629 impl.mRenderer.Reset();
633 case Toolkit::TextField::Property::SHADOW:
635 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
638 impl.mRenderer.Reset();
642 case Toolkit::TextField::Property::INPUT_SHADOW:
644 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
647 impl.mRenderer.Reset();
651 case Toolkit::TextField::Property::EMBOSS:
653 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
656 impl.mRenderer.Reset();
660 case Toolkit::TextField::Property::INPUT_EMBOSS:
662 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
665 impl.mRenderer.Reset();
669 case Toolkit::TextField::Property::OUTLINE:
671 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
674 impl.mRenderer.Reset();
678 case Toolkit::TextField::Property::INPUT_OUTLINE:
680 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
683 impl.mRenderer.Reset();
687 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
689 const Property::Map* map = value.GetMap();
692 impl.mController->SetHiddenInputOption(*map);
696 case Toolkit::TextField::Property::PIXEL_SIZE:
698 if( impl.mController )
700 const float pixelSize = value.Get< float >();
701 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
703 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
705 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
710 case Toolkit::TextField::Property::ENABLE_SELECTION:
712 if( impl.mController )
714 const bool enableSelection = value.Get< bool >();
715 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
716 impl.mController->SetSelectionEnabled( enableSelection );
720 case Toolkit::TextField::Property::PLACEHOLDER:
722 const Property::Map* map = value.GetMap();
725 impl.mController->SetPlaceholderProperty( *map );
729 case Toolkit::TextField::Property::ELLIPSIS:
731 if( impl.mController )
733 const bool ellipsis = value.Get<bool>();
734 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
736 impl.mController->SetTextElideEnabled( ellipsis );
740 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
742 if( impl.mController )
744 const bool shiftSelection = value.Get<bool>();
745 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
747 impl.mController->SetShiftSelectionEnabled( shiftSelection );
751 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
753 if( impl.mController )
755 const bool grabHandleEnabled = value.Get<bool>();
756 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
758 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
762 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
764 if( impl.mController )
766 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
770 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
772 if( impl.mController )
774 const bool grabHandlePopupEnabled = value.Get<bool>();
775 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
777 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
781 case Toolkit::DevelTextField::Property::BACKGROUND:
783 if( impl.mController )
785 const Vector4 backgroundColor = value.Get< Vector4 >();
786 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 );
788 impl.mController->SetBackgroundEnabled( true );
789 impl.mController->SetBackgroundColor( backgroundColor );
797 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
799 Property::Value value;
801 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
805 TextField& impl( GetImpl( textField ) );
809 case Toolkit::TextField::Property::RENDERING_BACKEND:
811 value = impl.mRenderingBackend;
814 case Toolkit::TextField::Property::TEXT:
816 if( impl.mController )
819 impl.mController->GetText( text );
820 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
825 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
827 if( impl.mController )
830 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
835 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
837 if( impl.mController )
840 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
845 case Toolkit::TextField::Property::FONT_FAMILY:
847 if( impl.mController )
849 value = impl.mController->GetDefaultFontFamily();
853 case Toolkit::TextField::Property::FONT_STYLE:
855 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
858 case Toolkit::TextField::Property::POINT_SIZE:
860 if( impl.mController )
862 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
866 case Toolkit::TextField::Property::MAX_LENGTH:
868 if( impl.mController )
870 value = impl.mController->GetMaximumNumberOfCharacters();
874 case Toolkit::TextField::Property::EXCEED_POLICY:
876 value = impl.mExceedPolicy;
879 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
881 if( impl.mController )
883 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
887 value = std::string( name );
892 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
894 if( impl.mController )
896 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
900 value = std::string( name );
905 case Toolkit::TextField::Property::TEXT_COLOR:
907 if ( impl.mController )
909 value = impl.mController->GetDefaultColor();
913 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
915 if ( impl.mController )
917 value = impl.mController->GetPlaceholderTextColor();
921 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
923 if( impl.mDecorator )
925 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
929 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
931 if( impl.mDecorator )
933 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
937 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
939 value = impl.mController->GetEnableCursorBlink();
942 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
944 if( impl.mDecorator )
946 value = impl.mDecorator->GetCursorBlinkInterval();
950 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
952 if( impl.mDecorator )
954 value = impl.mDecorator->GetCursorBlinkDuration();
958 case Toolkit::TextField::Property::CURSOR_WIDTH:
960 if( impl.mDecorator )
962 value = impl.mDecorator->GetCursorWidth();
966 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
968 if( impl.mDecorator )
970 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
973 value = image.GetUrl();
978 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
980 if( impl.mDecorator )
982 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
985 value = image.GetUrl();
990 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
992 if( impl.mDecorator )
994 value = impl.mDecorator->GetScrollThreshold();
998 case Toolkit::TextField::Property::SCROLL_SPEED:
1000 if( impl.mDecorator )
1002 value = impl.mDecorator->GetScrollSpeed();
1006 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1008 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1011 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1013 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1016 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1018 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1021 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1023 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1026 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1028 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1031 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1033 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1036 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1038 if( impl.mDecorator )
1040 value = impl.mDecorator->GetHighlightColor();
1044 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1046 if( impl.mDecorator )
1048 Rect<int> boundingBox;
1049 impl.mDecorator->GetBoundingBox( boundingBox );
1050 value = boundingBox;
1054 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1057 impl.mInputMethodOptions.RetrieveProperty( map );
1061 case Toolkit::TextField::Property::INPUT_COLOR:
1063 if( impl.mController )
1065 value = impl.mController->GetInputColor();
1069 case Toolkit::TextField::Property::ENABLE_MARKUP:
1071 if( impl.mController )
1073 value = impl.mController->IsMarkupProcessorEnabled();
1077 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1079 if( impl.mController )
1081 value = impl.mController->GetInputFontFamily();
1085 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1087 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1090 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1092 if( impl.mController )
1094 value = impl.mController->GetInputFontPointSize();
1098 case Toolkit::TextField::Property::UNDERLINE:
1100 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1103 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1105 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1108 case Toolkit::TextField::Property::SHADOW:
1110 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1113 case Toolkit::TextField::Property::INPUT_SHADOW:
1115 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1118 case Toolkit::TextField::Property::EMBOSS:
1120 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1123 case Toolkit::TextField::Property::INPUT_EMBOSS:
1125 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1128 case Toolkit::TextField::Property::OUTLINE:
1130 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1133 case Toolkit::TextField::Property::INPUT_OUTLINE:
1135 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1138 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1141 impl.mController->GetHiddenInputOption(map);
1145 case Toolkit::TextField::Property::PIXEL_SIZE:
1147 if( impl.mController )
1149 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1153 case Toolkit::TextField::Property::ENABLE_SELECTION:
1155 if( impl.mController )
1157 value = impl.mController->IsSelectionEnabled();
1161 case Toolkit::TextField::Property::PLACEHOLDER:
1164 impl.mController->GetPlaceholderProperty( map );
1168 case Toolkit::TextField::Property::ELLIPSIS:
1170 if( impl.mController )
1172 value = impl.mController->IsTextElideEnabled();
1176 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1178 if( impl.mController )
1180 value = impl.mController->IsShiftSelectionEnabled();
1184 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1186 if( impl.mController )
1188 value = impl.mController->IsGrabHandleEnabled();
1192 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1194 if( impl.mController )
1196 value = impl.mController->IsMatchSystemLanguageDirection();
1200 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1202 if( impl.mController )
1204 value = impl.mController->IsGrabHandlePopupEnabled();
1208 case Toolkit::DevelTextField::Property::BACKGROUND:
1210 if( impl.mController )
1212 value = impl.mController->GetBackgroundColor();
1216 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1218 if( impl.mController )
1220 value = impl.mController->GetSelectedText( );
1230 void TextField::SelectWholeText()
1232 if( mController && mController->IsShowingRealText() )
1234 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1239 void TextField::SelectNone()
1241 if( mController && mController->IsShowingRealText() )
1243 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1248 InputMethodContext TextField::GetInputMethodContext()
1250 return mInputMethodContext;
1253 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1255 Dali::BaseHandle handle( object );
1257 bool connected( true );
1258 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1260 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1262 field.TextChangedSignal().Connect( tracker, functor );
1264 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1266 field.MaxLengthReachedSignal().Connect( tracker, functor );
1268 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1270 field.InputStyleChangedSignal().Connect( tracker, functor );
1274 // signalName does not match any signal
1281 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1283 return mTextChangedSignal;
1286 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1288 return mMaxLengthReachedSignal;
1291 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1293 return mInputStyleChangedSignal;
1296 void TextField::OnInitialize()
1298 Actor self = Self();
1300 mController = Text::Controller::New( this, this );
1302 // When using the vector-based rendering, the size of the GLyphs are different
1303 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1304 mController->SetGlyphType( glyphType );
1306 mDecorator = Text::Decorator::New( *mController,
1309 mInputMethodContext = InputMethodContext::New( self );
1311 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1313 // Enables the text input.
1314 mController->EnableTextInput( mDecorator, mInputMethodContext );
1316 // Enables the horizontal scrolling after the text input has been enabled.
1317 mController->SetHorizontalScrollEnabled( true );
1319 // Disables the vertical scrolling.
1320 mController->SetVerticalScrollEnabled( false );
1322 // Disable the smooth handle panning.
1323 mController->SetSmoothHandlePanEnabled( false );
1325 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1326 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1328 // Sets layoutDirection value
1329 Dali::Stage stage = Dali::Stage::GetCurrent();
1330 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1331 mController->SetLayoutDirection( layoutDirection );
1333 // Forward input events to controller
1334 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1335 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1337 self.TouchSignal().Connect( this, &TextField::OnTouched );
1339 // Set BoundingBox to stage size if not already set.
1340 Rect<int> boundingBox;
1341 mDecorator->GetBoundingBox( boundingBox );
1343 if( boundingBox.IsEmpty() )
1345 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1346 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1349 // Flip vertically the 'left' selection handle
1350 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1352 // Fill-parent area by default
1353 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1354 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1355 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1357 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1359 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1365 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1367 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1371 case StyleChange::DEFAULT_FONT_CHANGE:
1373 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1374 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1375 // Property system did not set the font so should update it.
1376 mController->UpdateAfterFontChange( newFont );
1381 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1383 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1387 case StyleChange::THEME_CHANGE:
1389 // Nothing to do, let control base class handle this
1394 // Up call to Control
1395 Control::OnStyleChange( styleManager, change );
1398 Vector3 TextField::GetNaturalSize()
1401 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1403 Vector3 naturalSize = mController->GetNaturalSize();
1404 naturalSize.width += ( padding.start + padding.end );
1405 naturalSize.height += ( padding.top + padding.bottom );
1410 float TextField::GetHeightForWidth( float width )
1413 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1414 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1417 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1419 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1421 Actor self = Self();
1424 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1426 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1428 // Support Right-To-Left of padding
1429 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1430 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1432 std::swap( padding.start, padding.end );
1437 mStencil.SetPosition( padding.start, padding.top );
1441 mActiveLayer.SetPosition( padding.start, padding.top );
1444 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1446 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1449 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1452 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1454 mDecorator->Relayout( size );
1459 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1462 RenderText( updateTextType );
1466 // The text-field emits signals when the input style changes. These changes of style are
1467 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1468 // can't be emitted during the size negotiation as the callbacks may update the UI.
1469 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1470 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1472 if( Adaptor::IsAvailable() )
1474 Adaptor& adaptor = Adaptor::Get();
1476 if( NULL == mIdleCallback )
1478 // @note: The callback manager takes the ownership of the callback object.
1479 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1480 adaptor.AddIdle( mIdleCallback, false );
1486 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1488 Actor renderableActor;
1490 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1494 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1496 renderableActor = mRenderer->Render( mController->GetView(),
1498 Property::INVALID_INDEX, // Animatable property not supported
1500 DepthIndex::CONTENT );
1503 if( renderableActor != mRenderableActor )
1505 UnparentAndReset( mBackgroundActor );
1506 UnparentAndReset( mRenderableActor );
1507 mRenderableActor = renderableActor;
1509 if ( mRenderableActor )
1511 mBackgroundActor = mController->CreateBackgroundActor();
1516 if( mRenderableActor )
1518 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1520 float renderableActorPositionX, renderableActorPositionY;
1524 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1525 renderableActorPositionY = scrollOffset.y;
1530 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1532 // Support Right-To-Left of padding
1533 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1534 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1536 std::swap( padding.start, padding.end );
1539 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1540 renderableActorPositionY = scrollOffset.y + padding.top;
1543 mRenderableActor.SetPosition( renderableActorPositionX, renderableActorPositionY );
1545 // Make sure the actors are parented correctly with/without clipping
1546 Actor self = mStencil ? mStencil : Self();
1548 Actor highlightActor;
1550 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1551 endIt = mClippingDecorationActors.end();
1556 it->LowerToBottom();
1558 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1560 highlightActor = *it;
1563 mClippingDecorationActors.clear();
1565 self.Add( mRenderableActor );
1567 if ( mBackgroundActor )
1569 if ( mDecorator && mDecorator->IsHighlightVisible() )
1571 self.Add( mBackgroundActor );
1572 mBackgroundActor.SetPosition( renderableActorPositionX, renderableActorPositionY); // In text field's coords.
1573 mBackgroundActor.LowerBelow( highlightActor );
1577 mRenderableActor.Add( mBackgroundActor );
1578 mBackgroundActor.SetPosition( 0.0f, 0.0f ); // In renderable actor's coords.
1579 mBackgroundActor.LowerToBottom();
1585 void TextField::OnKeyInputFocusGained()
1587 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1588 if ( mInputMethodContext )
1590 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1592 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1594 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1596 // Notify that the text editing start.
1597 mInputMethodContext.Activate();
1599 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1600 mInputMethodContext.SetRestoreAfterFocusLost( true );
1602 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1606 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1609 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1611 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1614 void TextField::OnKeyInputFocusLost()
1616 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1617 if ( mInputMethodContext )
1619 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1620 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1621 mInputMethodContext.SetRestoreAfterFocusLost( false );
1623 // Notify that the text editing finish.
1624 mInputMethodContext.Deactivate();
1626 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1628 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1632 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1635 mController->KeyboardFocusLostEvent();
1637 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1640 void TextField::OnTap( const TapGesture& gesture )
1642 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1643 if ( mInputMethodContext )
1645 mInputMethodContext.Activate();
1647 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1649 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1650 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1655 void TextField::OnPan( const PanGesture& gesture )
1657 mController->PanEvent( gesture.state, gesture.displacement );
1660 void TextField::OnLongPress( const LongPressGesture& gesture )
1662 if ( mInputMethodContext )
1664 mInputMethodContext.Activate();
1667 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1668 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1673 bool TextField::OnKeyEvent( const KeyEvent& event )
1675 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1677 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1679 // Make sure ClearKeyInputFocus when only key is up
1680 if( event.state == KeyEvent::Up )
1682 ClearKeyInputFocus();
1687 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1689 // Do nothing when enter is comming.
1693 return mController->KeyEvent( event );
1696 void TextField::RequestTextRelayout()
1701 void TextField::TextChanged()
1703 Dali::Toolkit::TextField handle( GetOwner() );
1704 mTextChangedSignal.Emit( handle );
1707 void TextField::MaxLengthReached()
1709 Dali::Toolkit::TextField handle( GetOwner() );
1710 mMaxLengthReachedSignal.Emit( handle );
1713 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1715 Dali::Toolkit::TextField handle( GetOwner() );
1717 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1719 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1721 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1723 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1725 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1727 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1729 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1731 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1733 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1735 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1737 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1739 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1741 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1743 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1745 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1747 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1749 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1751 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1753 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1755 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1757 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1760 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1763 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1769 mClippingDecorationActors.push_back( actor );
1773 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1774 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1775 Self().Add( actor );
1776 mActiveLayer = actor;
1781 void TextField::OnStageConnect( Dali::Actor actor )
1783 if ( mHasBeenStaged )
1785 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1789 mHasBeenStaged = true;
1793 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1795 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1796 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1799 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1803 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1808 Scripting::CreatePropertyMap( image, map );
1814 void TextField::EnableClipping()
1818 // Creates an extra control to be used as stencil buffer.
1819 mStencil = Control::New();
1820 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1821 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1823 // Creates a background visual. Even if the color is transparent it updates the stencil.
1824 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1825 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1826 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1828 // Enable the clipping property.
1829 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1830 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1832 Self().Add( mStencil );
1836 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1838 mController->PasteClipboardItemEvent();
1841 void TextField::KeyboardStatusChanged(bool keyboardShown)
1843 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1845 // Just hide the grab handle when keyboard is hidden.
1846 if (!keyboardShown )
1848 mController->KeyboardFocusLostEvent();
1852 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1856 void TextField::OnStageConnection( int depth )
1858 // Sets the depth to the visuals inside the text's decorator.
1859 mDecorator->SetTextDepth( depth );
1861 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1863 // Call the Control::OnStageConnection() to set the depth of the background.
1864 Control::OnStageConnection( depth );
1867 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1872 void TextField::OnIdleSignal()
1874 // Emits the change of input style signals.
1875 mController->ProcessInputStyleChangedSignals();
1877 // Set the pointer to null as the callback manager deletes the callback after execute it.
1878 mIdleCallback = NULL;
1881 TextField::TextField()
1882 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1883 mIdleCallback( NULL ),
1884 mAlignmentOffset( 0.f ),
1885 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1886 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1887 mHasBeenStaged( false )
1891 TextField::~TextField()
1893 UnparentAndReset( mStencil );
1895 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1897 Adaptor::Get().RemoveIdle( mIdleCallback );
1901 } // namespace Internal
1903 } // namespace Toolkit