2 * Copyright (c) 2017 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.
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/devel-api/adaptor-framework/clipboard.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/tap-gesture-event.h>
27 #include <dali/integration-api/events/pan-gesture-event.h>
28 #include <dali-toolkit-test-suite-utils.h>
29 #include <dali-toolkit/dali-toolkit.h>
30 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
33 using namespace Toolkit;
35 void dali_texteditor_startup(void)
37 test_return_value = TET_UNDEF;
40 void dali_texteditor_cleanup(void)
42 test_return_value = TET_PASS;
48 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
49 const char* const PROPERTY_NAME_TEXT = "text";
50 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
51 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
52 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
53 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
54 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
55 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
56 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
57 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
58 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
59 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
60 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
61 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
62 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
63 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
64 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
67 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
68 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
69 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
70 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
71 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
72 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
73 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
74 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
75 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
76 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
77 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
79 const char* const PROPERTY_NAME_LINE_SPACING = "lineSpacing";
80 const char* const PROPERTY_NAME_INPUT_LINE_SPACING = "inputLineSpacing";
81 const char* const PROPERTY_NAME_UNDERLINE = "underline";
82 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
83 const char* const PROPERTY_NAME_SHADOW = "shadow";
84 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
85 const char* const PROPERTY_NAME_EMBOSS = "emboss";
86 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
87 const char* const PROPERTY_NAME_OUTLINE = "outline";
88 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
90 const char* const PROPERTY_NAME_SMOOTH_SCROLL = "smoothScroll";
91 const char* const PROPERTY_NAME_SMOOTH_SCROLL_DURATION = "smoothScrollDuration";
92 const char* const PROPERTY_NAME_ENABLE_SCROLL_BAR = "enableScrollBar";
93 const char* const PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION = "scrollBarShowDuration";
94 const char* const PROPERTY_NAME_SCROLL_BAR_FADE_DURATION = "scrollBarFadeDuration";
96 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
98 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
100 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
101 const float TO_MILLISECONDS = 1000.f;
102 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
103 const float RENDER_FRAME_INTERVAL = 16.66f;
105 const float SCROLL_THRESHOLD = 10.f;
106 const float SCROLL_SPEED = 300.f;
108 const unsigned int DEFAULT_FONT_SIZE = 1152u;
109 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
111 const int KEY_A_CODE = 38;
112 const int KEY_D_CODE = 40;
113 const int KEY_WHITE_SPACE_CODE = 65;
115 const char* HANDLE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insertpoint-icon.png";
117 static bool gTextChangedCallBackCalled;
118 static bool gInputStyleChangedCallbackCalled;
119 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
121 struct CallbackFunctor
123 CallbackFunctor(bool* callbackFlag)
124 : mCallbackFlag( callbackFlag )
130 *mCallbackFlag = true;
135 static void TestTextChangedCallback( TextEditor control )
137 tet_infoline(" TestTextChangedCallback");
139 gTextChangedCallBackCalled = true;
142 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
144 tet_infoline(" TestInputStyleChangedCallback");
146 gInputStyleChangedCallbackCalled = true;
147 gInputStyleMask = mask;
150 // Generate a TapGestureEvent to send to Core.
151 Integration::TapGestureEvent GenerateTap(
152 Gesture::State state,
153 unsigned int numberOfTaps,
154 unsigned int numberOfTouches,
157 Integration::TapGestureEvent tap( state );
159 tap.numberOfTaps = numberOfTaps;
160 tap.numberOfTouches = numberOfTouches;
166 // Generate a PanGestureEvent to send to Core
167 Integration::PanGestureEvent GeneratePan( Gesture::State state,
168 const Vector2& previousPosition,
169 const Vector2& currentPosition,
170 unsigned long timeDelta,
171 unsigned int numberOfTouches = 1u )
173 Integration::PanGestureEvent pan(state);
175 pan.previousPosition = previousPosition;
176 pan.currentPosition = currentPosition;
177 pan.timeDelta = timeDelta;
178 pan.numberOfTouches = numberOfTouches;
183 // Generate a KeyEvent to send to Core.
184 Integration::KeyEvent GenerateKey( const std::string& keyName,
185 const std::string& keyString,
188 unsigned long timeStamp,
189 const Integration::KeyEvent::State& keyState )
191 return Integration::KeyEvent( keyName,
200 * Helper to generate PanGestureEvent
202 * @param[in] application Application instance
203 * @param[in] state The Gesture State
204 * @param[in] pos The current position of touch.
206 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
210 if( (state == Gesture::Started) ||
211 (state == Gesture::Possible) )
217 application.ProcessEvent( GeneratePan( state, last, pos, 16 ) );
224 * Simulate time passed by.
226 * @note this will always process at least 1 frame (1/60 sec)
228 * @param application Test application instance
229 * @param duration Time to pass in milliseconds.
230 * @return The actual time passed in milliseconds
232 static int Wait(ToolkitTestApplication& application, int duration = 0)
236 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
238 application.SendNotification();
239 application.Render(RENDER_FRAME_INTERVAL);
240 time += RENDER_FRAME_INTERVAL;
246 Dali::Integration::Point GetPointDownInside( Vector2& pos )
248 Dali::Integration::Point point;
249 point.SetState( PointState::DOWN );
250 point.SetScreenPosition( pos );
254 Dali::Integration::Point GetPointUpInside( Vector2& pos )
256 Dali::Integration::Point point;
257 point.SetState( PointState::UP );
258 point.SetScreenPosition( pos );
262 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
264 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
266 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
268 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
270 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
271 if( NULL != valueSet )
273 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
275 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
281 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
292 int UtcDaliToolkitTextEditorConstructorP(void)
294 ToolkitTestApplication application;
295 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
296 TextEditor textEditor;
297 DALI_TEST_CHECK( !textEditor );
301 int UtcDaliToolkitTextEditorNewP(void)
303 ToolkitTestApplication application;
304 tet_infoline(" UtcDaliToolkitTextEditorNewP");
305 TextEditor textEditor = TextEditor::New();
306 DALI_TEST_CHECK( textEditor );
310 int UtcDaliToolkitTextEditorDownCastP(void)
312 ToolkitTestApplication application;
313 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
314 TextEditor textEditor1 = TextEditor::New();
315 BaseHandle object( textEditor1 );
317 TextEditor textEditor2 = TextEditor::DownCast( object );
318 DALI_TEST_CHECK( textEditor2 );
320 TextEditor textEditor3 = DownCast< TextEditor >( object );
321 DALI_TEST_CHECK( textEditor3 );
325 int UtcDaliToolkitTextEditorDownCastN(void)
327 ToolkitTestApplication application;
328 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
329 BaseHandle uninitializedObject;
330 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
331 DALI_TEST_CHECK( !textEditor1 );
333 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
334 DALI_TEST_CHECK( !textEditor2 );
338 int UtcDaliToolkitTextEditorCopyConstructorP(void)
340 ToolkitTestApplication application;
341 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
342 TextEditor textEditor = TextEditor::New();
343 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
345 TextEditor copy( textEditor );
346 DALI_TEST_CHECK( copy );
347 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
351 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
353 ToolkitTestApplication application;
354 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
355 TextEditor textEditor = TextEditor::New();
356 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
358 TextEditor copy = textEditor;
359 DALI_TEST_CHECK( copy );
360 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
364 int UtcDaliTextEditorNewP(void)
366 ToolkitTestApplication application;
367 tet_infoline(" UtcDaliToolkitTextEditorNewP");
368 TextEditor textEditor = TextEditor::New();
369 DALI_TEST_CHECK( textEditor );
373 // Positive test case for a method
374 int UtcDaliTextEditorGetPropertyP(void)
376 ToolkitTestApplication application;
377 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
378 TextEditor editor = TextEditor::New();
379 DALI_TEST_CHECK( editor );
381 // Check Property Indices are correct
382 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
383 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
384 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
385 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
386 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
387 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
388 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
389 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
390 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
391 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
392 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
393 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
394 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
395 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
396 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
397 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
398 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
399 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
400 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
401 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
402 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
403 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
404 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
405 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
406 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
407 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
408 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
409 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
410 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
411 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
413 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
414 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
415 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
416 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
417 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
418 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
419 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
420 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
421 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
422 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
423 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
424 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
425 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SCROLL_BAR ) == DevelTextEditor::Property::ENABLE_SCROLL_BAR );
426 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION );
427 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION );
432 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
435 Property::Map imageMap;
436 imageMap[mapKey] =mapValue;
438 editor.SetProperty( property , imageMap );
439 Property::Value propValue = editor.GetProperty( property );
440 Property::Map* resultMap = propValue.GetMap();
442 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
450 // Positive test case for a method
451 int UtcDaliTextEditorSetPropertyP(void)
453 ToolkitTestApplication application;
454 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
455 TextEditor editor = TextEditor::New();
456 DALI_TEST_CHECK( editor );
457 Stage::GetCurrent().Add( editor );
459 // Note - we can't check the defaults since the stylesheets are platform-specific
461 // Check the render backend property.
462 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
463 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
465 // Check text property.
466 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
467 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
469 // Check text's color property
470 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
471 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
473 // Check font properties.
474 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
475 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
477 Property::Map fontStyleMapSet;
478 Property::Map fontStyleMapGet;
479 Property::Value* slantValue = NULL;
481 fontStyleMapSet.Insert( "weight", "bold" );
482 fontStyleMapSet.Insert( "width", "condensed" );
483 fontStyleMapSet.Insert( "slant", "italic" );
485 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
486 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
487 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
488 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
490 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
491 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
494 fontStyleMapSet.Clear();
495 fontStyleMapSet.Insert( "weight", "normal" );
496 fontStyleMapSet.Insert( "slant", "oblique" );
497 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
498 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
499 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
500 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
502 fontStyleMapSet.Clear();
503 fontStyleMapSet.Insert( "slant", "roman" );
504 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
505 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
507 // Replace 'roman' for 'normal'.
508 slantValue = fontStyleMapGet.Find( "slant" );
509 if( NULL != slantValue )
511 if( "normal" == slantValue->Get<std::string>() )
513 fontStyleMapGet["slant"] = "roman";
516 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
517 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
519 fontStyleMapSet.Clear();
521 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
522 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
523 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
524 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
526 // Check that the Alignment properties can be correctly set
527 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
528 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
530 // Check scroll properties.
531 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
532 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
533 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
534 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
536 // Check cursor properties
537 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
538 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
539 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
540 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
542 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
543 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
544 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
545 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
546 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
547 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
548 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
549 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
551 // Check handle images
552 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
553 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
554 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
555 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
556 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
558 // Check handle images
559 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
560 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
561 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
562 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
563 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
564 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
566 // Check the highlight color
567 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
568 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
570 // Decoration bounding box
571 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
572 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
574 // Check the enable markup property.
575 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
576 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
577 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
579 // Check input color property.
580 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
581 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
583 // Check input font properties.
584 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
585 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
587 fontStyleMapSet.Clear();
588 fontStyleMapSet.Insert( "weight", "bold" );
589 fontStyleMapSet.Insert( "width", "condensed" );
590 fontStyleMapSet.Insert( "slant", "italic" );
592 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
593 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
594 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
595 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
597 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
598 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
600 // Reset input font style.
601 fontStyleMapSet.Clear();
602 fontStyleMapSet.Insert( "weight", "normal" );
603 fontStyleMapSet.Insert( "slant", "oblique" );
605 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
606 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
607 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
608 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
610 fontStyleMapSet.Clear();
611 fontStyleMapSet.Insert( "slant", "roman" );
613 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
614 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
616 // Replace 'roman' for 'normal'.
617 slantValue = fontStyleMapGet.Find( "slant" );
618 if( NULL != slantValue )
620 if( "normal" == slantValue->Get<std::string>() )
622 fontStyleMapGet["slant"] = "roman";
625 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
626 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
628 fontStyleMapSet.Clear();
630 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
631 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
632 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
633 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
635 // Check the line spacing property
636 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
637 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
638 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
640 // Check the input line spacing property
641 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
642 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
643 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
645 // Check the underline property
647 Property::Map underlineMapSet;
648 Property::Map underlineMapGet;
650 underlineMapSet.Insert( "enable", "true" );
651 underlineMapSet.Insert( "color", "red" );
652 underlineMapSet.Insert( "height", "1" );
654 editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet );
656 underlineMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::UNDERLINE );
657 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
658 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
660 // Check the input underline property
661 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
662 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
664 // Check the shadow property
665 Property::Map shadowMapSet;
666 Property::Map shadowMapGet;
668 shadowMapSet.Insert( "color", "green" );
669 shadowMapSet.Insert( "offset", "2 2" );
671 editor.SetProperty( TextEditor::Property::SHADOW, shadowMapSet );
673 shadowMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::SHADOW );
674 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
675 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
677 // Check the input shadow property
678 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
679 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
681 // Check the emboss property
682 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
683 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
685 // Check the input emboss property
686 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
687 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
689 // Check the outline property
690 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
691 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
693 // Check the input outline property
694 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
695 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
697 // Check the smooth scroll property
698 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), false, TEST_LOCATION );
699 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
700 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
702 // Check the smooth scroll duration property
703 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
704 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
706 // Check the scroll bar property
707 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), false, TEST_LOCATION );
708 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
709 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
711 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
712 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
713 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
714 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
719 // Positive Atlas Text Renderer test
720 int utcDaliTextEditorAtlasRenderP(void)
722 ToolkitTestApplication application;
723 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
724 StyleManager styleManager = StyleManager::Get();
725 styleManager.ApplyDefaultTheme();
726 TextEditor editor = TextEditor::New();
727 DALI_TEST_CHECK( editor );
729 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
731 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
733 Stage::GetCurrent().Add( editor );
737 // Render some text with the shared atlas backend
738 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
739 application.SendNotification();
740 application.Render();
744 tet_result(TET_FAIL);
749 // Positive test for the textChanged signal.
750 int utcDaliTextEditorTextChangedP(void)
752 ToolkitTestApplication application;
753 tet_infoline(" utcDaliTextEditorTextChangedP");
754 TextEditor editor = TextEditor::New();
755 DALI_TEST_CHECK( editor );
757 Stage::GetCurrent().Add( editor );
759 // connect to the text changed signal.
760 ConnectionTracker* testTracker = new ConnectionTracker();
761 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
762 bool textChangedSignal = false;
763 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
765 gTextChangedCallBackCalled = false;
766 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
767 DALI_TEST_CHECK( gTextChangedCallBackCalled );
768 DALI_TEST_CHECK( textChangedSignal );
770 application.SendNotification();
772 editor.SetKeyInputFocus();
774 gTextChangedCallBackCalled = false;
775 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
776 DALI_TEST_CHECK( gTextChangedCallBackCalled );
781 int utcDaliTextEditorInputStyleChanged01(void)
783 ToolkitTestApplication application;
784 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
786 // The text-editor emits signals when the input style changes. These changes of style are
787 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
788 // can't be emitted during the size negotiation as the callbacks may update the UI.
789 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
790 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
791 application.CreateAdaptor();
795 char* pathNamePtr = get_current_dir_name();
796 const std::string pathName( pathNamePtr );
799 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
800 fontClient.SetDpi( 93u, 93u );
802 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
803 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
805 TextEditor editor = TextEditor::New();
806 DALI_TEST_CHECK( editor );
809 editor.SetSize( 300.f, 50.f );
810 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
811 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
813 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
814 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
816 // connect to the text changed signal.
817 ConnectionTracker* testTracker = new ConnectionTracker();
818 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
819 bool inputStyleChangedSignal = false;
820 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
822 Stage::GetCurrent().Add( editor );
825 application.SendNotification();
826 application.Render();
828 // Executes the idle callbacks added by the text control on the change of input style.
829 application.RunIdles();
831 gInputStyleChangedCallbackCalled = false;
832 gInputStyleMask = TextEditor::InputStyle::NONE;
833 inputStyleChangedSignal = false;
835 // Create a tap event to touch the text editor.
836 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
837 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
840 application.SendNotification();
841 application.Render();
843 // Executes the idle callbacks added by the text control on the change of input style.
844 application.RunIdles();
846 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
847 if( gInputStyleChangedCallbackCalled )
849 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
851 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
852 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
854 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
855 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
857 DALI_TEST_CHECK( inputStyleChangedSignal );
859 gInputStyleChangedCallbackCalled = false;
860 gInputStyleMask = TextEditor::InputStyle::NONE;
861 inputStyleChangedSignal = false;
863 // Create a tap event to touch the text editor.
864 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
865 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
868 application.SendNotification();
869 application.Render();
871 // Executes the idle callbacks added by the text control on the change of input style.
872 application.RunIdles();
874 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
875 DALI_TEST_CHECK( !inputStyleChangedSignal );
877 gInputStyleChangedCallbackCalled = false;
878 gInputStyleMask = TextEditor::InputStyle::NONE;
879 inputStyleChangedSignal = false;
881 // Create a tap event to touch the text editor.
882 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
883 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
886 application.SendNotification();
887 application.Render();
889 // Executes the idle callbacks added by the text control on the change of input style.
890 application.RunIdles();
892 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
893 if( gInputStyleChangedCallbackCalled )
895 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
897 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
898 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
900 DALI_TEST_CHECK( inputStyleChangedSignal );
902 gInputStyleChangedCallbackCalled = false;
903 gInputStyleMask = TextEditor::InputStyle::NONE;
904 inputStyleChangedSignal = false;
906 // Create a tap event to touch the text editor.
907 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
908 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
911 application.SendNotification();
912 application.Render();
914 // Executes the idle callbacks added by the text control on the change of input style.
915 application.RunIdles();
917 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
918 if( gInputStyleChangedCallbackCalled )
920 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
922 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
923 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
925 Property::Map fontStyleMapSet;
926 Property::Map fontStyleMapGet;
928 fontStyleMapSet.Insert( "weight", "bold" );
930 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
931 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
932 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
934 DALI_TEST_CHECK( inputStyleChangedSignal );
936 gInputStyleChangedCallbackCalled = false;
937 gInputStyleMask = TextEditor::InputStyle::NONE;
938 inputStyleChangedSignal = false;
940 // Create a tap event to touch the text editor.
941 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
942 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
945 application.SendNotification();
946 application.Render();
948 // Executes the idle callbacks added by the text control on the change of input style.
949 application.RunIdles();
951 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
952 DALI_TEST_CHECK( !inputStyleChangedSignal );
954 gInputStyleChangedCallbackCalled = false;
955 gInputStyleMask = TextEditor::InputStyle::NONE;
956 inputStyleChangedSignal = false;
958 // Create a tap event to touch the text editor.
959 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
960 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
963 application.SendNotification();
964 application.Render();
966 // Executes the idle callbacks added by the text control on the change of input style.
967 application.RunIdles();
969 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
970 if( gInputStyleChangedCallbackCalled )
972 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
974 Property::Map fontStyleMapSet;
975 Property::Map fontStyleMapGet;
977 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
978 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
979 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
981 DALI_TEST_CHECK( inputStyleChangedSignal );
983 gInputStyleChangedCallbackCalled = false;
984 gInputStyleMask = TextEditor::InputStyle::NONE;
985 inputStyleChangedSignal = false;
987 // Create a tap event to touch the text editor.
988 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
989 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
992 application.SendNotification();
993 application.Render();
995 // Executes the idle callbacks added by the text control on the change of input style.
996 application.RunIdles();
998 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
999 DALI_TEST_CHECK( !inputStyleChangedSignal );
1004 int utcDaliTextEditorInputStyleChanged02(void)
1006 ToolkitTestApplication application;
1007 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
1009 // The text-editor emits signals when the input style changes. These changes of style are
1010 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1011 // can't be emitted during the size negotiation as the callbacks may update the UI.
1012 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
1013 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1014 application.CreateAdaptor();
1018 char* pathNamePtr = get_current_dir_name();
1019 const std::string pathName( pathNamePtr );
1020 free( pathNamePtr );
1022 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1023 fontClient.SetDpi( 93u, 93u );
1025 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1026 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1028 TextEditor editor = TextEditor::New();
1029 DALI_TEST_CHECK( editor );
1032 editor.SetSize( 300.f, 50.f );
1033 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1034 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1036 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
1037 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='blue'> l</color><color value='green'>lo</color> <font weight='bold'>world</font> demo</font>" );
1039 // connect to the text changed signal.
1040 ConnectionTracker* testTracker = new ConnectionTracker();
1041 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1042 bool inputStyleChangedSignal = false;
1043 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1045 Stage::GetCurrent().Add( editor );
1047 // Render and notify
1048 application.SendNotification();
1049 application.Render();
1051 // Executes the idle callbacks added by the text control on the change of input style.
1052 application.RunIdles();
1054 gInputStyleChangedCallbackCalled = false;
1055 gInputStyleMask = TextEditor::InputStyle::NONE;
1056 inputStyleChangedSignal = false;
1058 // Create a tap event to touch the text editor.
1059 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1060 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1061 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1062 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1064 // Render and notify
1065 application.SendNotification();
1066 application.Render();
1068 // Executes the idle callbacks added by the text control on the change of input style.
1069 application.RunIdles();
1071 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1072 if( gInputStyleChangedCallbackCalled )
1074 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1075 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
1076 TextEditor::InputStyle::POINT_SIZE |
1077 TextEditor::InputStyle::COLOR ),
1080 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1081 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1083 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1084 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1086 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
1087 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1089 DALI_TEST_CHECK( inputStyleChangedSignal );
1091 gInputStyleChangedCallbackCalled = false;
1092 gInputStyleMask = TextEditor::InputStyle::NONE;
1093 inputStyleChangedSignal = false;
1095 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1097 // Render and notify
1098 application.SendNotification();
1099 application.Render();
1101 // Executes the idle callbacks added by the text control on the change of input style.
1102 application.RunIdles();
1104 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1105 if( gInputStyleChangedCallbackCalled )
1107 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1108 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1111 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1112 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1114 DALI_TEST_CHECK( inputStyleChangedSignal );
1116 gInputStyleChangedCallbackCalled = false;
1117 gInputStyleMask = TextEditor::InputStyle::NONE;
1118 inputStyleChangedSignal = false;
1120 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1122 // Render and notify
1123 application.SendNotification();
1124 application.Render();
1126 // Executes the idle callbacks added by the text control on the change of input style.
1127 application.RunIdles();
1129 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1130 DALI_TEST_CHECK( !inputStyleChangedSignal );
1132 gInputStyleChangedCallbackCalled = false;
1133 gInputStyleMask = TextEditor::InputStyle::NONE;
1134 inputStyleChangedSignal = false;
1136 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1138 // Render and notify
1139 application.SendNotification();
1140 application.Render();
1142 // Executes the idle callbacks added by the text control on the change of input style.
1143 application.RunIdles();
1145 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1146 if( gInputStyleChangedCallbackCalled )
1148 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1149 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1152 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1153 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1155 DALI_TEST_CHECK( inputStyleChangedSignal );
1157 gInputStyleChangedCallbackCalled = false;
1158 gInputStyleMask = TextEditor::InputStyle::NONE;
1159 inputStyleChangedSignal = false;
1161 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1163 Property::Map fontStyleMapSet;
1164 fontStyleMapSet.Insert( "weight", "thin" );
1165 fontStyleMapSet.Insert( "width", "condensed" );
1166 fontStyleMapSet.Insert( "slant", "italic" );
1168 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1169 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1170 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1172 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1173 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1174 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1175 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1177 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1179 // Render and notify
1180 application.SendNotification();
1181 application.Render();
1183 // Executes the idle callbacks added by the text control on the change of input style.
1184 application.RunIdles();
1186 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1187 DALI_TEST_CHECK( !inputStyleChangedSignal );
1189 // Create a tap event to touch the text editor.
1190 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1191 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1193 // Render and notify
1194 application.SendNotification();
1195 application.Render();
1197 // Executes the idle callbacks added by the text control on the change of input style.
1198 application.RunIdles();
1200 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1201 if( gInputStyleChangedCallbackCalled )
1203 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1204 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1205 TextEditor::InputStyle::POINT_SIZE |
1206 TextEditor::InputStyle::FONT_STYLE |
1207 TextEditor::InputStyle::LINE_SPACING |
1208 TextEditor::InputStyle::UNDERLINE |
1209 TextEditor::InputStyle::SHADOW |
1210 TextEditor::InputStyle::EMBOSS |
1211 TextEditor::InputStyle::OUTLINE ),
1214 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1215 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1217 DALI_TEST_CHECK( inputStyleChangedSignal );
1219 gInputStyleChangedCallbackCalled = false;
1220 gInputStyleMask = TextEditor::InputStyle::NONE;
1221 inputStyleChangedSignal = false;
1223 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1225 fontStyleMapSet.Clear();
1226 fontStyleMapSet.Insert( "weight", "black" );
1227 fontStyleMapSet.Insert( "width", "expanded" );
1228 fontStyleMapSet.Insert( "slant", "oblique" );
1230 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1232 // Create a tap event to touch the text editor.
1233 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1234 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1236 // Render and notify
1237 application.SendNotification();
1238 application.Render();
1240 // Executes the idle callbacks added by the text control on the change of input style.
1241 application.RunIdles();
1243 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1244 if( gInputStyleChangedCallbackCalled )
1246 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1247 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1248 TextEditor::InputStyle::POINT_SIZE |
1249 TextEditor::InputStyle::FONT_STYLE ),
1252 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1253 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1255 DALI_TEST_CHECK( inputStyleChangedSignal );
1260 int utcDaliTextEditorEvent01(void)
1262 ToolkitTestApplication application;
1263 tet_infoline(" utcDaliTextEditorEvent01");
1265 // Creates a tap event. After creating a tap event the text editor should
1266 // have the focus and add text with key events should be possible.
1268 TextEditor editor = TextEditor::New();
1269 DALI_TEST_CHECK( editor );
1271 Stage::GetCurrent().Add( editor );
1273 editor.SetSize( 300.f, 50.f );
1274 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1275 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1277 // Avoid a crash when core load gl resources.
1278 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1280 // Render and notify
1281 application.SendNotification();
1282 application.Render();
1284 // Add a key event but as the text editor has not the focus it should do nothing.
1285 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1287 // Render and notify
1288 application.SendNotification();
1289 application.Render();
1291 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1293 // Create a tap event to touch the text editor.
1294 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1295 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1297 // Render and notify
1298 application.SendNotification();
1299 application.Render();
1301 // Now the text editor has the focus, so it can handle the key events.
1302 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1303 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1305 // Render and notify
1306 application.SendNotification();
1307 application.Render();
1309 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1311 // Create a second text editor and send key events to it.
1312 TextEditor editor2 = TextEditor::New();
1314 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1315 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1316 editor2.SetSize( 100.f, 100.f );
1317 editor2.SetPosition( 100.f, 100.f );
1319 Stage::GetCurrent().Add( editor2 );
1321 // Render and notify
1322 application.SendNotification();
1323 application.Render();
1325 // Create a tap event on the second text editor.
1326 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1327 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1329 // Render and notify
1330 application.SendNotification();
1331 application.Render();
1333 // The second text editor has the focus. It should handle the key events.
1334 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1335 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1337 // Render and notify
1338 application.SendNotification();
1339 application.Render();
1341 // Check the text has been added to the second text editor.
1342 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1347 int utcDaliTextEditorEvent02(void)
1349 ToolkitTestApplication application;
1350 tet_infoline(" utcDaliTextEditorEvent02");
1352 // Checks if the right number of actors are created.
1354 TextEditor editor = TextEditor::New();
1355 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1356 DALI_TEST_CHECK( editor );
1358 Stage::GetCurrent().Add( editor );
1360 editor.SetSize( 300.f, 50.f );
1361 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1362 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1364 // Avoid a crash when core load gl resources.
1365 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1367 // Render and notify
1368 application.SendNotification();
1369 application.Render();
1371 // Check there are the expected number of children (the stencil).
1372 DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1374 Actor stencil = editor.GetChildAt( 0u );
1376 // Create a tap event to touch the text editor.
1377 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1378 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1380 // Render and notify
1381 application.SendNotification();
1382 application.Render();
1384 Actor layer = editor.GetChildAt( 1u );
1385 DALI_TEST_CHECK( layer.IsLayer() );
1387 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1388 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1390 // Now the text editor has the focus, so it can handle the key events.
1391 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1392 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1394 // Render and notify
1395 application.SendNotification();
1396 application.Render();
1398 // Checks the cursor and the renderer have been created.
1399 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1400 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1402 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1403 DALI_TEST_CHECK( cursor );
1405 // The stencil actor has a container with all the actors which contain the text renderers.
1406 Actor container = stencil.GetChildAt( 0u );
1407 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1409 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1410 DALI_TEST_CHECK( renderer );
1413 // Move the cursor and check the position changes.
1414 Vector3 position1 = cursor.GetCurrentPosition();
1416 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1417 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1419 // Render and notify
1420 application.SendNotification();
1421 application.Render();
1423 Vector3 position2 = cursor.GetCurrentPosition();
1425 DALI_TEST_CHECK( position2.x < position1.x );
1427 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1428 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1430 // Render and notify
1431 application.SendNotification();
1432 application.Render();
1434 Vector3 position3 = cursor.GetCurrentPosition();
1436 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1438 // Send some taps and check the cursor positions.
1440 // Try to tap at the beginning.
1441 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1442 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1444 // Render and notify
1445 application.SendNotification();
1446 application.Render();
1448 // Cursor position should be the same than position1.
1449 Vector3 position4 = cursor.GetCurrentPosition();
1451 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1453 // Tap away from the start position.
1454 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1455 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1457 // Render and notify
1458 application.SendNotification();
1459 application.Render();
1461 Vector3 position5 = cursor.GetCurrentPosition();
1463 DALI_TEST_CHECK( position5.x > position4.x );
1465 // Remove all the text.
1466 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1467 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1468 editor.SetProperty( TextEditor::Property::TEXT, "" );
1470 // Render and notify
1471 application.SendNotification();
1472 application.Render();
1474 // Cursor position should be the same than position2.
1475 Vector3 position6 = cursor.GetCurrentPosition();
1477 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1479 // Should not be a renderer.
1480 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1485 int utcDaliTextEditorEvent03(void)
1487 ToolkitTestApplication application;
1488 tet_infoline(" utcDaliTextEditorEvent03");
1490 // Checks if the highlight actor is created.
1492 TextEditor editor = TextEditor::New();
1493 DALI_TEST_CHECK( editor );
1495 Stage::GetCurrent().Add( editor );
1497 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1498 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1499 editor.SetSize( 30.f, 50.f );
1500 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1501 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1503 // Avoid a crash when core load gl resources.
1504 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1506 // Render and notify
1507 application.SendNotification();
1508 application.Render();
1510 // Send some taps and check text controller with clipboard window
1511 Dali::Clipboard clipboard = Clipboard::Get();
1512 clipboard.ShowClipboard();
1513 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1514 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1515 clipboard.HideClipboard();
1517 // Render and notify
1518 application.SendNotification();
1519 application.Render();
1521 // Tap first to get the focus.
1522 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1523 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1525 // Render and notify
1526 application.SendNotification();
1527 application.Render();
1529 // Double tap to select a word.
1530 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1531 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1533 // Render and notify
1534 application.SendNotification();
1535 application.Render();
1537 // The stencil actor should have two actors: the renderer and the highlight actor.
1538 Actor stencil = editor.GetChildAt( 0u );
1540 // The stencil actor has a container with all the actors which contain the text renderers.
1541 Actor container = stencil.GetChildAt( 0u );
1542 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1544 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1545 DALI_TEST_CHECK( renderer );
1548 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1549 DALI_TEST_CHECK( highlight );
1551 // Double tap out of bounds
1552 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 29.f, 25.0f ) ) );
1553 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 29.f, 25.0f ) ) );
1555 // Render and notify
1556 application.SendNotification();
1557 application.Render();
1559 // The stencil actor should have one actors: the renderer actor.
1560 stencil = editor.GetChildAt( 0u );
1562 // The stencil actor has a container with all the actors which contain the text renderers.
1563 container = stencil.GetChildAt( 0u );
1564 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1566 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1567 DALI_TEST_CHECK( renderer );
1573 int utcDaliTextEditorEvent04(void)
1575 ToolkitTestApplication application;
1576 tet_infoline(" utcDaliTextEditorEvent04");
1578 // Checks if the highlight actor is created.
1580 TextEditor editor = TextEditor::New();
1581 DALI_TEST_CHECK( editor );
1583 Stage::GetCurrent().Add( editor );
1585 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1586 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1587 editor.SetSize( 100.f, 50.f );
1588 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1589 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1591 // Avoid a crash when core load gl resources.
1592 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1594 // Render and notify
1595 application.SendNotification();
1596 application.Render();
1598 // Tap on the text editor
1599 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1600 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1602 // Render and notify
1603 application.SendNotification();
1604 application.Render();
1606 // Move at the end of the text.
1607 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1608 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1610 // Render and notify
1611 application.SendNotification();
1612 application.Render();
1614 for( unsigned int index = 0u; index < 10u; ++index )
1616 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1617 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1619 // Render and notify
1620 application.SendNotification();
1621 application.Render();
1625 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
1627 // Render and notify
1628 application.SendNotification();
1629 application.Render();
1631 DALI_TEST_EQUALS( "Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1633 // Add some key events
1634 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1635 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1637 // Render and notify
1638 application.SendNotification();
1639 application.Render();
1641 for( unsigned int index = 0u; index < 10u; ++index )
1643 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1644 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1646 // Render and notify
1647 application.SendNotification();
1648 application.Render();
1652 application.ProcessEvent( GenerateKey( " ", " ", KEY_WHITE_SPACE_CODE, 0, 0, Integration::KeyEvent::Down ) );
1654 // Render and notify
1655 application.SendNotification();
1656 application.Render();
1658 DALI_TEST_EQUALS( " Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1663 int utcDaliTextEditorEvent05(void)
1665 ToolkitTestApplication application;
1666 tet_infoline(" utcDaliTextEditorEvent05");
1668 // Checks if the highlight actor is created.
1670 TextEditor editor = TextEditor::New();
1671 DALI_TEST_CHECK( editor );
1673 Stage::GetCurrent().Add( editor );
1675 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1676 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1677 editor.SetSize( 50.f, 50.f );
1678 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1679 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1680 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1681 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
1682 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
1683 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
1684 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
1686 // Avoid a crash when core load gl resources.
1687 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1689 // Render and notify
1690 application.SendNotification();
1691 application.Render();
1693 // Tap on the text editor
1694 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1695 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1697 // Render and notify
1698 application.SendNotification();
1699 application.Render();
1701 // Move at the end of the text.
1702 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1703 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1705 // Render and notify
1706 application.SendNotification();
1707 application.Render();
1709 for( unsigned int index = 0u; index < 10u; ++index )
1712 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
1714 // Render and notify
1715 application.SendNotification();
1716 application.Render();
1718 // Modify duration after scroll is enabled
1719 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.1f );
1721 // Continuous scroll left to increase coverage
1722 for( unsigned int index = 0u; index < 10u; ++index )
1724 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1726 // Render and notify
1727 application.SendNotification();
1728 application.Render();
1730 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1731 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
1732 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
1733 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1734 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1736 // Press Escape to increase coverage
1737 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up ) );
1738 application.SendNotification();
1739 application.Render();
1741 DALI_TEST_CHECK( !editor.HasKeyInputFocus() );
1746 int utcDaliTextEditorHandles(void)
1748 ToolkitTestApplication application;
1749 tet_infoline(" utcDaliTextEditorHandles");
1751 TextEditor editor = TextEditor::New();
1752 DALI_TEST_CHECK( editor );
1754 Stage::GetCurrent().Add( editor );
1756 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1757 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1758 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, HANDLE_IMAGE_FILE_NAME );
1759 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1761 editor.SetSize( 30.f, 500.f );
1762 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1763 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1765 // Avoid a crash when core load gl resources.
1766 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1768 // Render and notify
1769 application.SendNotification();
1770 application.Render();
1772 // Tap first to get the focus.
1773 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1774 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1776 // Render and notify
1777 application.SendNotification();
1778 application.Render();
1780 // Tap to create the grab handle.
1781 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1782 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1784 // Render and notify
1785 application.SendNotification();
1786 application.Render();
1788 // Get the active layer where the text's decoration is added.
1789 Actor activeLayer = editor.GetChildAt( 1u );
1791 // Get the handle's actor.
1792 Actor handle = activeLayer.GetChildAt( 1u );
1793 handle.SetSize( 100.f, 100.f );
1795 // Render and notify
1796 application.SendNotification();
1797 application.Render();
1799 // Touch the grab handle to set it as pressed.
1800 Vector2 touchPos( 10.0f, 50.0f );
1801 Dali::Integration::TouchEvent event;
1802 event = Dali::Integration::TouchEvent();
1803 event.AddPoint( GetPointDownInside( touchPos ) );
1804 application.ProcessEvent( event );
1806 // Render and notify
1807 application.SendNotification();
1808 application.Render();
1810 // drag grab handle right
1811 SendPan(application, Gesture::Possible, touchPos);
1812 SendPan(application, Gesture::Started, touchPos);
1814 Wait(application, 100);
1816 for(int i = 0;i<20;i++)
1818 SendPan(application, Gesture::Continuing, touchPos);
1823 SendPan(application, Gesture::Finished, touchPos);
1826 // Release the grab handle.
1827 event = Dali::Integration::TouchEvent();
1828 event.AddPoint( GetPointUpInside( touchPos ) );
1829 application.ProcessEvent( event );
1831 // Render and notify
1832 application.SendNotification();
1833 application.Render();