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";
95 const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize";
97 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
99 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
101 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
102 const float TO_MILLISECONDS = 1000.f;
103 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
104 const float RENDER_FRAME_INTERVAL = 16.66f;
106 const float SCROLL_THRESHOLD = 10.f;
107 const float SCROLL_SPEED = 300.f;
109 const unsigned int DEFAULT_FONT_SIZE = 1152u;
110 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
112 const int KEY_A_CODE = 38;
113 const int KEY_D_CODE = 40;
114 const int KEY_WHITE_SPACE_CODE = 65;
116 const char* HANDLE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insertpoint-icon.png";
118 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
120 static bool gTextChangedCallBackCalled;
121 static bool gInputStyleChangedCallbackCalled;
122 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
124 struct CallbackFunctor
126 CallbackFunctor(bool* callbackFlag)
127 : mCallbackFlag( callbackFlag )
133 *mCallbackFlag = true;
138 static void TestTextChangedCallback( TextEditor control )
140 tet_infoline(" TestTextChangedCallback");
142 gTextChangedCallBackCalled = true;
145 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
147 tet_infoline(" TestInputStyleChangedCallback");
149 gInputStyleChangedCallbackCalled = true;
150 gInputStyleMask = mask;
153 // Generate a TapGestureEvent to send to Core.
154 Integration::TapGestureEvent GenerateTap(
155 Gesture::State state,
156 unsigned int numberOfTaps,
157 unsigned int numberOfTouches,
160 Integration::TapGestureEvent tap( state );
162 tap.numberOfTaps = numberOfTaps;
163 tap.numberOfTouches = numberOfTouches;
169 // Generate a PanGestureEvent to send to Core
170 Integration::PanGestureEvent GeneratePan( Gesture::State state,
171 const Vector2& previousPosition,
172 const Vector2& currentPosition,
173 unsigned long timeDelta,
174 unsigned int numberOfTouches = 1u )
176 Integration::PanGestureEvent pan(state);
178 pan.previousPosition = previousPosition;
179 pan.currentPosition = currentPosition;
180 pan.timeDelta = timeDelta;
181 pan.numberOfTouches = numberOfTouches;
186 // Generate a KeyEvent to send to Core.
187 Integration::KeyEvent GenerateKey( const std::string& keyName,
188 const std::string& keyString,
191 unsigned long timeStamp,
192 const Integration::KeyEvent::State& keyState,
193 const std::string& deviceName )
195 return Integration::KeyEvent( keyName,
205 * Helper to generate PanGestureEvent
207 * @param[in] application Application instance
208 * @param[in] state The Gesture State
209 * @param[in] pos The current position of touch.
211 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
215 if( (state == Gesture::Started) ||
216 (state == Gesture::Possible) )
222 application.ProcessEvent( GeneratePan( state, last, pos, 16 ) );
229 * Simulate time passed by.
231 * @note this will always process at least 1 frame (1/60 sec)
233 * @param application Test application instance
234 * @param duration Time to pass in milliseconds.
235 * @return The actual time passed in milliseconds
237 static int Wait(ToolkitTestApplication& application, int duration = 0)
241 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
243 application.SendNotification();
244 application.Render(RENDER_FRAME_INTERVAL);
245 time += RENDER_FRAME_INTERVAL;
251 Dali::Integration::Point GetPointDownInside( Vector2& pos )
253 Dali::Integration::Point point;
254 point.SetState( PointState::DOWN );
255 point.SetScreenPosition( pos );
259 Dali::Integration::Point GetPointUpInside( Vector2& pos )
261 Dali::Integration::Point point;
262 point.SetState( PointState::UP );
263 point.SetScreenPosition( pos );
267 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
269 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
271 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
273 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
275 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
276 if( NULL != valueSet )
278 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
280 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
286 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
297 int UtcDaliToolkitTextEditorConstructorP(void)
299 ToolkitTestApplication application;
300 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
301 TextEditor textEditor;
302 DALI_TEST_CHECK( !textEditor );
306 int UtcDaliToolkitTextEditorNewP(void)
308 ToolkitTestApplication application;
309 tet_infoline(" UtcDaliToolkitTextEditorNewP");
310 TextEditor textEditor = TextEditor::New();
311 DALI_TEST_CHECK( textEditor );
315 int UtcDaliToolkitTextEditorDownCastP(void)
317 ToolkitTestApplication application;
318 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
319 TextEditor textEditor1 = TextEditor::New();
320 BaseHandle object( textEditor1 );
322 TextEditor textEditor2 = TextEditor::DownCast( object );
323 DALI_TEST_CHECK( textEditor2 );
325 TextEditor textEditor3 = DownCast< TextEditor >( object );
326 DALI_TEST_CHECK( textEditor3 );
330 int UtcDaliToolkitTextEditorDownCastN(void)
332 ToolkitTestApplication application;
333 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
334 BaseHandle uninitializedObject;
335 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
336 DALI_TEST_CHECK( !textEditor1 );
338 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
339 DALI_TEST_CHECK( !textEditor2 );
343 int UtcDaliToolkitTextEditorCopyConstructorP(void)
345 ToolkitTestApplication application;
346 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
347 TextEditor textEditor = TextEditor::New();
348 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
350 TextEditor copy( textEditor );
351 DALI_TEST_CHECK( copy );
352 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
356 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
358 ToolkitTestApplication application;
359 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
360 TextEditor textEditor = TextEditor::New();
361 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
363 TextEditor copy = textEditor;
364 DALI_TEST_CHECK( copy );
365 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
369 int UtcDaliTextEditorNewP(void)
371 ToolkitTestApplication application;
372 tet_infoline(" UtcDaliToolkitTextEditorNewP");
373 TextEditor textEditor = TextEditor::New();
374 DALI_TEST_CHECK( textEditor );
378 // Positive test case for a method
379 int UtcDaliTextEditorGetPropertyP(void)
381 ToolkitTestApplication application;
382 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
383 TextEditor editor = TextEditor::New();
384 DALI_TEST_CHECK( editor );
386 // Check Property Indices are correct
387 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
388 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
389 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
390 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
391 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
392 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
393 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
394 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
395 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
396 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
397 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
398 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
399 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
400 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
401 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
402 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
403 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
404 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
405 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
406 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
407 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
408 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
409 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
410 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
411 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
412 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
413 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
414 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
415 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
416 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
418 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
419 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
420 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
421 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
422 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
423 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
424 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
425 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
426 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
427 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
428 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
429 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
430 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SCROLL_BAR ) == DevelTextEditor::Property::ENABLE_SCROLL_BAR );
431 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION );
432 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION );
433 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == DevelTextEditor::Property::PIXEL_SIZE );
438 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
441 Property::Map imageMap;
442 imageMap[mapKey] =mapValue;
444 editor.SetProperty( property , imageMap );
445 Property::Value propValue = editor.GetProperty( property );
446 Property::Map* resultMap = propValue.GetMap();
448 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
456 // Positive test case for a method
457 int UtcDaliTextEditorSetPropertyP(void)
459 ToolkitTestApplication application;
460 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
461 TextEditor editor = TextEditor::New();
462 DALI_TEST_CHECK( editor );
463 Stage::GetCurrent().Add( editor );
465 // Note - we can't check the defaults since the stylesheets are platform-specific
467 // Check the render backend property.
468 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
469 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
471 // Check text property.
472 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
473 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
475 // Check text's color property
476 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
477 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
479 // Check font properties.
480 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
481 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
483 Property::Map fontStyleMapSet;
484 Property::Map fontStyleMapGet;
485 Property::Value* slantValue = NULL;
487 fontStyleMapSet.Insert( "weight", "bold" );
488 fontStyleMapSet.Insert( "width", "condensed" );
489 fontStyleMapSet.Insert( "slant", "italic" );
491 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
492 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
493 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
494 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
496 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
497 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
500 fontStyleMapSet.Clear();
501 fontStyleMapSet.Insert( "weight", "normal" );
502 fontStyleMapSet.Insert( "slant", "oblique" );
503 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
504 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
505 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
506 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
508 fontStyleMapSet.Clear();
509 fontStyleMapSet.Insert( "slant", "roman" );
510 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
511 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
513 // Replace 'roman' for 'normal'.
514 slantValue = fontStyleMapGet.Find( "slant" );
515 if( NULL != slantValue )
517 if( "normal" == slantValue->Get<std::string>() )
519 fontStyleMapGet["slant"] = "roman";
522 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
523 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
525 fontStyleMapSet.Clear();
527 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
528 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
529 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
530 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
532 // Check that the Alignment properties can be correctly set
533 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
534 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
536 // Check scroll properties.
537 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
538 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
539 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
540 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
542 // Check cursor properties
543 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
544 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
545 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
546 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
548 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
549 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
550 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
551 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
552 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
553 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
554 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
555 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
557 // Check handle images
558 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
559 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
560 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
561 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
562 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
564 // Check handle images
565 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
566 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
567 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
568 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
569 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
570 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
572 // Check the highlight color
573 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
574 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
576 // Decoration bounding box
577 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
578 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
580 // Check the enable markup property.
581 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
582 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
583 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
585 // Check input color property.
586 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
587 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
589 // Check input font properties.
590 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
591 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
593 fontStyleMapSet.Clear();
594 fontStyleMapSet.Insert( "weight", "bold" );
595 fontStyleMapSet.Insert( "width", "condensed" );
596 fontStyleMapSet.Insert( "slant", "italic" );
598 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
599 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
600 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
601 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
603 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
604 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
606 // Reset input font style.
607 fontStyleMapSet.Clear();
608 fontStyleMapSet.Insert( "weight", "normal" );
609 fontStyleMapSet.Insert( "slant", "oblique" );
611 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
612 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
613 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
614 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
616 fontStyleMapSet.Clear();
617 fontStyleMapSet.Insert( "slant", "roman" );
619 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
620 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
622 // Replace 'roman' for 'normal'.
623 slantValue = fontStyleMapGet.Find( "slant" );
624 if( NULL != slantValue )
626 if( "normal" == slantValue->Get<std::string>() )
628 fontStyleMapGet["slant"] = "roman";
631 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
632 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
634 fontStyleMapSet.Clear();
636 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
637 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
638 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
639 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
641 // Check the line spacing property
642 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
643 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
644 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
646 // Check the input line spacing property
647 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
648 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
649 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
651 // Check the underline property
653 Property::Map underlineMapSet;
654 Property::Map underlineMapGet;
656 underlineMapSet.Insert( "enable", "true" );
657 underlineMapSet.Insert( "color", "red" );
658 underlineMapSet.Insert( "height", "1" );
660 editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet );
662 underlineMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::UNDERLINE );
663 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
664 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
666 // Check the input underline property
667 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
668 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
670 // Check the shadow property
671 Property::Map shadowMapSet;
672 Property::Map shadowMapGet;
674 shadowMapSet.Insert( "color", "green" );
675 shadowMapSet.Insert( "offset", "2 2" );
677 editor.SetProperty( TextEditor::Property::SHADOW, shadowMapSet );
679 shadowMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::SHADOW );
680 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
681 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
683 // Check the input shadow property
684 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
685 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
687 // Check the emboss property
688 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
689 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
691 // Check the input emboss property
692 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
693 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
695 // Check the outline property
696 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
697 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
699 // Check the input outline property
700 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
701 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
703 // Check the smooth scroll property
704 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), false, TEST_LOCATION );
705 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
706 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
708 // Check the smooth scroll duration property
709 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
710 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
712 // Check the scroll bar property
713 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), false, TEST_LOCATION );
714 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
715 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
717 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
718 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
719 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
720 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
722 // Check the pixel size of font
723 editor.SetProperty( DevelTextEditor::Property::PIXEL_SIZE, 20.f );
724 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
729 // Positive Atlas Text Renderer test
730 int utcDaliTextEditorAtlasRenderP(void)
732 ToolkitTestApplication application;
733 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
734 StyleManager styleManager = StyleManager::Get();
735 styleManager.ApplyDefaultTheme();
736 TextEditor editor = TextEditor::New();
737 DALI_TEST_CHECK( editor );
739 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
741 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
743 Stage::GetCurrent().Add( editor );
747 // Render some text with the shared atlas backend
748 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
749 application.SendNotification();
750 application.Render();
754 tet_result(TET_FAIL);
759 // Positive test for the textChanged signal.
760 int utcDaliTextEditorTextChangedP(void)
762 ToolkitTestApplication application;
763 tet_infoline(" utcDaliTextEditorTextChangedP");
764 TextEditor editor = TextEditor::New();
765 DALI_TEST_CHECK( editor );
767 Stage::GetCurrent().Add( editor );
769 // connect to the text changed signal.
770 ConnectionTracker* testTracker = new ConnectionTracker();
771 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
772 bool textChangedSignal = false;
773 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
775 gTextChangedCallBackCalled = false;
776 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
777 DALI_TEST_CHECK( gTextChangedCallBackCalled );
778 DALI_TEST_CHECK( textChangedSignal );
780 application.SendNotification();
782 editor.SetKeyInputFocus();
784 gTextChangedCallBackCalled = false;
785 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
786 DALI_TEST_CHECK( gTextChangedCallBackCalled );
791 int utcDaliTextEditorInputStyleChanged01(void)
793 ToolkitTestApplication application;
794 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
796 // The text-editor emits signals when the input style changes. These changes of style are
797 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
798 // can't be emitted during the size negotiation as the callbacks may update the UI.
799 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
800 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
801 application.CreateAdaptor();
805 char* pathNamePtr = get_current_dir_name();
806 const std::string pathName( pathNamePtr );
809 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
810 fontClient.SetDpi( 93u, 93u );
812 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
813 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
815 TextEditor editor = TextEditor::New();
816 DALI_TEST_CHECK( editor );
819 editor.SetSize( 300.f, 50.f );
820 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
821 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
823 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
824 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
826 // connect to the text changed signal.
827 ConnectionTracker* testTracker = new ConnectionTracker();
828 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
829 bool inputStyleChangedSignal = false;
830 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
832 Stage::GetCurrent().Add( editor );
835 application.SendNotification();
836 application.Render();
838 // Executes the idle callbacks added by the text control on the change of input style.
839 application.RunIdles();
841 gInputStyleChangedCallbackCalled = false;
842 gInputStyleMask = TextEditor::InputStyle::NONE;
843 inputStyleChangedSignal = false;
845 // Create a tap event to touch the text editor.
846 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
847 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
850 application.SendNotification();
851 application.Render();
853 // Executes the idle callbacks added by the text control on the change of input style.
854 application.RunIdles();
856 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
857 if( gInputStyleChangedCallbackCalled )
859 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
861 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
862 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
864 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
865 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
867 DALI_TEST_CHECK( inputStyleChangedSignal );
869 gInputStyleChangedCallbackCalled = false;
870 gInputStyleMask = TextEditor::InputStyle::NONE;
871 inputStyleChangedSignal = false;
873 // Create a tap event to touch the text editor.
874 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
875 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
878 application.SendNotification();
879 application.Render();
881 // Executes the idle callbacks added by the text control on the change of input style.
882 application.RunIdles();
884 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
885 DALI_TEST_CHECK( !inputStyleChangedSignal );
887 gInputStyleChangedCallbackCalled = false;
888 gInputStyleMask = TextEditor::InputStyle::NONE;
889 inputStyleChangedSignal = false;
891 // Create a tap event to touch the text editor.
892 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
893 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
896 application.SendNotification();
897 application.Render();
899 // Executes the idle callbacks added by the text control on the change of input style.
900 application.RunIdles();
902 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
903 if( gInputStyleChangedCallbackCalled )
905 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
907 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
908 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
910 DALI_TEST_CHECK( inputStyleChangedSignal );
912 gInputStyleChangedCallbackCalled = false;
913 gInputStyleMask = TextEditor::InputStyle::NONE;
914 inputStyleChangedSignal = false;
916 // Create a tap event to touch the text editor.
917 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
918 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
921 application.SendNotification();
922 application.Render();
924 // Executes the idle callbacks added by the text control on the change of input style.
925 application.RunIdles();
927 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
928 if( gInputStyleChangedCallbackCalled )
930 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
932 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
933 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
935 Property::Map fontStyleMapSet;
936 Property::Map fontStyleMapGet;
938 fontStyleMapSet.Insert( "weight", "bold" );
940 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
941 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
942 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
944 DALI_TEST_CHECK( inputStyleChangedSignal );
946 gInputStyleChangedCallbackCalled = false;
947 gInputStyleMask = TextEditor::InputStyle::NONE;
948 inputStyleChangedSignal = false;
950 // Create a tap event to touch the text editor.
951 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
952 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
955 application.SendNotification();
956 application.Render();
958 // Executes the idle callbacks added by the text control on the change of input style.
959 application.RunIdles();
961 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
962 DALI_TEST_CHECK( !inputStyleChangedSignal );
964 gInputStyleChangedCallbackCalled = false;
965 gInputStyleMask = TextEditor::InputStyle::NONE;
966 inputStyleChangedSignal = false;
968 // Create a tap event to touch the text editor.
969 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
970 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
973 application.SendNotification();
974 application.Render();
976 // Executes the idle callbacks added by the text control on the change of input style.
977 application.RunIdles();
979 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
980 if( gInputStyleChangedCallbackCalled )
982 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
984 Property::Map fontStyleMapSet;
985 Property::Map fontStyleMapGet;
987 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
988 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
989 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
991 DALI_TEST_CHECK( inputStyleChangedSignal );
993 gInputStyleChangedCallbackCalled = false;
994 gInputStyleMask = TextEditor::InputStyle::NONE;
995 inputStyleChangedSignal = false;
997 // Create a tap event to touch the text editor.
998 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
999 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1001 // Render and notify
1002 application.SendNotification();
1003 application.Render();
1005 // Executes the idle callbacks added by the text control on the change of input style.
1006 application.RunIdles();
1008 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1009 DALI_TEST_CHECK( !inputStyleChangedSignal );
1014 int utcDaliTextEditorInputStyleChanged02(void)
1016 ToolkitTestApplication application;
1017 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
1019 // The text-editor emits signals when the input style changes. These changes of style are
1020 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1021 // can't be emitted during the size negotiation as the callbacks may update the UI.
1022 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
1023 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1024 application.CreateAdaptor();
1028 char* pathNamePtr = get_current_dir_name();
1029 const std::string pathName( pathNamePtr );
1030 free( pathNamePtr );
1032 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1033 fontClient.SetDpi( 93u, 93u );
1035 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1036 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1038 TextEditor editor = TextEditor::New();
1039 DALI_TEST_CHECK( editor );
1042 editor.SetSize( 300.f, 50.f );
1043 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1044 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1046 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
1047 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>" );
1049 // connect to the text changed signal.
1050 ConnectionTracker* testTracker = new ConnectionTracker();
1051 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1052 bool inputStyleChangedSignal = false;
1053 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1055 Stage::GetCurrent().Add( editor );
1057 // Render and notify
1058 application.SendNotification();
1059 application.Render();
1061 // Executes the idle callbacks added by the text control on the change of input style.
1062 application.RunIdles();
1064 gInputStyleChangedCallbackCalled = false;
1065 gInputStyleMask = TextEditor::InputStyle::NONE;
1066 inputStyleChangedSignal = false;
1068 // Create a tap event to touch the text editor.
1069 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1070 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1071 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1072 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1074 // Render and notify
1075 application.SendNotification();
1076 application.Render();
1078 // Executes the idle callbacks added by the text control on the change of input style.
1079 application.RunIdles();
1081 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1082 if( gInputStyleChangedCallbackCalled )
1084 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1085 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
1086 TextEditor::InputStyle::POINT_SIZE |
1087 TextEditor::InputStyle::COLOR ),
1090 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1091 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1093 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1094 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1096 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
1097 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1099 DALI_TEST_CHECK( inputStyleChangedSignal );
1101 gInputStyleChangedCallbackCalled = false;
1102 gInputStyleMask = TextEditor::InputStyle::NONE;
1103 inputStyleChangedSignal = false;
1105 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1107 // Render and notify
1108 application.SendNotification();
1109 application.Render();
1111 // Executes the idle callbacks added by the text control on the change of input style.
1112 application.RunIdles();
1114 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1115 if( gInputStyleChangedCallbackCalled )
1117 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1118 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1121 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1122 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1124 DALI_TEST_CHECK( inputStyleChangedSignal );
1126 gInputStyleChangedCallbackCalled = false;
1127 gInputStyleMask = TextEditor::InputStyle::NONE;
1128 inputStyleChangedSignal = false;
1130 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1132 // Render and notify
1133 application.SendNotification();
1134 application.Render();
1136 // Executes the idle callbacks added by the text control on the change of input style.
1137 application.RunIdles();
1139 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1140 DALI_TEST_CHECK( !inputStyleChangedSignal );
1142 gInputStyleChangedCallbackCalled = false;
1143 gInputStyleMask = TextEditor::InputStyle::NONE;
1144 inputStyleChangedSignal = false;
1146 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1148 // Render and notify
1149 application.SendNotification();
1150 application.Render();
1152 // Executes the idle callbacks added by the text control on the change of input style.
1153 application.RunIdles();
1155 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1156 if( gInputStyleChangedCallbackCalled )
1158 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1159 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1162 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1163 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1165 DALI_TEST_CHECK( inputStyleChangedSignal );
1167 gInputStyleChangedCallbackCalled = false;
1168 gInputStyleMask = TextEditor::InputStyle::NONE;
1169 inputStyleChangedSignal = false;
1171 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1173 Property::Map fontStyleMapSet;
1174 fontStyleMapSet.Insert( "weight", "thin" );
1175 fontStyleMapSet.Insert( "width", "condensed" );
1176 fontStyleMapSet.Insert( "slant", "italic" );
1178 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1179 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1180 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1182 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1183 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1184 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1185 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1187 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1189 // Render and notify
1190 application.SendNotification();
1191 application.Render();
1193 // Executes the idle callbacks added by the text control on the change of input style.
1194 application.RunIdles();
1196 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1197 DALI_TEST_CHECK( !inputStyleChangedSignal );
1199 // Create a tap event to touch the text editor.
1200 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1201 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1203 // Render and notify
1204 application.SendNotification();
1205 application.Render();
1207 // Executes the idle callbacks added by the text control on the change of input style.
1208 application.RunIdles();
1210 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1211 if( gInputStyleChangedCallbackCalled )
1213 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1214 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1215 TextEditor::InputStyle::POINT_SIZE |
1216 TextEditor::InputStyle::FONT_STYLE |
1217 TextEditor::InputStyle::LINE_SPACING |
1218 TextEditor::InputStyle::UNDERLINE |
1219 TextEditor::InputStyle::SHADOW |
1220 TextEditor::InputStyle::EMBOSS |
1221 TextEditor::InputStyle::OUTLINE ),
1224 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1225 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1227 DALI_TEST_CHECK( inputStyleChangedSignal );
1229 gInputStyleChangedCallbackCalled = false;
1230 gInputStyleMask = TextEditor::InputStyle::NONE;
1231 inputStyleChangedSignal = false;
1233 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1235 fontStyleMapSet.Clear();
1236 fontStyleMapSet.Insert( "weight", "black" );
1237 fontStyleMapSet.Insert( "width", "expanded" );
1238 fontStyleMapSet.Insert( "slant", "oblique" );
1240 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1242 // Create a tap event to touch the text editor.
1243 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1244 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1246 // Render and notify
1247 application.SendNotification();
1248 application.Render();
1250 // Executes the idle callbacks added by the text control on the change of input style.
1251 application.RunIdles();
1253 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1254 if( gInputStyleChangedCallbackCalled )
1256 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1257 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1258 TextEditor::InputStyle::POINT_SIZE |
1259 TextEditor::InputStyle::FONT_STYLE ),
1262 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1263 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1265 DALI_TEST_CHECK( inputStyleChangedSignal );
1270 int utcDaliTextEditorEvent01(void)
1272 ToolkitTestApplication application;
1273 tet_infoline(" utcDaliTextEditorEvent01");
1275 // Creates a tap event. After creating a tap event the text editor should
1276 // have the focus and add text with key events should be possible.
1278 TextEditor editor = TextEditor::New();
1279 DALI_TEST_CHECK( editor );
1281 Stage::GetCurrent().Add( editor );
1283 editor.SetSize( 300.f, 50.f );
1284 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1285 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1287 // Avoid a crash when core load gl resources.
1288 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1290 // Render and notify
1291 application.SendNotification();
1292 application.Render();
1294 // Add a key event but as the text editor has not the focus it should do nothing.
1295 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1297 // Render and notify
1298 application.SendNotification();
1299 application.Render();
1301 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1303 // Create a tap event to touch the text editor.
1304 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1305 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1307 // Render and notify
1308 application.SendNotification();
1309 application.Render();
1311 // Now the text editor has the focus, so it can handle the key events.
1312 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1313 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1315 // Render and notify
1316 application.SendNotification();
1317 application.Render();
1319 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1321 // Create a second text editor and send key events to it.
1322 TextEditor editor2 = TextEditor::New();
1324 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1325 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1326 editor2.SetSize( 100.f, 100.f );
1327 editor2.SetPosition( 100.f, 100.f );
1329 Stage::GetCurrent().Add( editor2 );
1331 // Render and notify
1332 application.SendNotification();
1333 application.Render();
1335 // Create a tap event on the second text editor.
1336 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1337 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1339 // Render and notify
1340 application.SendNotification();
1341 application.Render();
1343 // The second text editor has the focus. It should handle the key events.
1344 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1345 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1347 // Render and notify
1348 application.SendNotification();
1349 application.Render();
1351 // Check the text has been added to the second text editor.
1352 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1357 int utcDaliTextEditorEvent02(void)
1359 ToolkitTestApplication application;
1360 tet_infoline(" utcDaliTextEditorEvent02");
1362 // Checks if the right number of actors are created.
1364 TextEditor editor = TextEditor::New();
1365 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1366 DALI_TEST_CHECK( editor );
1368 Stage::GetCurrent().Add( editor );
1370 editor.SetSize( 300.f, 50.f );
1371 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1372 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1374 // Avoid a crash when core load gl resources.
1375 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1377 // Render and notify
1378 application.SendNotification();
1379 application.Render();
1381 // Check there are the expected number of children (the stencil).
1382 DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1384 Actor stencil = editor.GetChildAt( 0u );
1386 // Create a tap event to touch the text editor.
1387 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1388 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1390 // Render and notify
1391 application.SendNotification();
1392 application.Render();
1394 Actor layer = editor.GetChildAt( 1u );
1395 DALI_TEST_CHECK( layer.IsLayer() );
1397 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1398 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1400 // Now the text editor has the focus, so it can handle the key events.
1401 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1402 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1404 // Render and notify
1405 application.SendNotification();
1406 application.Render();
1408 // Checks the cursor and the renderer have been created.
1409 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1410 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1412 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1413 DALI_TEST_CHECK( cursor );
1415 // The stencil actor has a container with all the actors which contain the text renderers.
1416 Actor container = stencil.GetChildAt( 0u );
1417 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1419 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1420 DALI_TEST_CHECK( renderer );
1423 // Move the cursor and check the position changes.
1424 Vector3 position1 = cursor.GetCurrentPosition();
1426 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1427 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1429 // Render and notify
1430 application.SendNotification();
1431 application.Render();
1433 Vector3 position2 = cursor.GetCurrentPosition();
1435 DALI_TEST_CHECK( position2.x < position1.x );
1437 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1438 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1440 // Render and notify
1441 application.SendNotification();
1442 application.Render();
1444 Vector3 position3 = cursor.GetCurrentPosition();
1446 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1448 // Send some taps and check the cursor positions.
1450 // Try to tap at the beginning.
1451 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1452 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1454 // Render and notify
1455 application.SendNotification();
1456 application.Render();
1458 // Cursor position should be the same than position1.
1459 Vector3 position4 = cursor.GetCurrentPosition();
1461 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1463 // Tap away from the start position.
1464 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1465 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1467 // Render and notify
1468 application.SendNotification();
1469 application.Render();
1471 Vector3 position5 = cursor.GetCurrentPosition();
1473 DALI_TEST_CHECK( position5.x > position4.x );
1475 // Remove all the text.
1476 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1477 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1478 editor.SetProperty( TextEditor::Property::TEXT, "" );
1480 // Render and notify
1481 application.SendNotification();
1482 application.Render();
1484 // Cursor position should be the same than position2.
1485 Vector3 position6 = cursor.GetCurrentPosition();
1487 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1489 // Should not be a renderer.
1490 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1495 int utcDaliTextEditorEvent03(void)
1497 ToolkitTestApplication application;
1498 tet_infoline(" utcDaliTextEditorEvent03");
1500 // Checks if the highlight actor is created.
1502 TextEditor editor = TextEditor::New();
1503 DALI_TEST_CHECK( editor );
1505 Stage::GetCurrent().Add( editor );
1507 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1508 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1509 editor.SetSize( 30.f, 50.f );
1510 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1511 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1513 // Avoid a crash when core load gl resources.
1514 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1516 // Render and notify
1517 application.SendNotification();
1518 application.Render();
1520 // Send some taps and check text controller with clipboard window
1521 Dali::Clipboard clipboard = Clipboard::Get();
1522 clipboard.ShowClipboard();
1523 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1524 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1525 clipboard.HideClipboard();
1527 // Render and notify
1528 application.SendNotification();
1529 application.Render();
1531 // Tap first to get the focus.
1532 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1533 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1535 // Render and notify
1536 application.SendNotification();
1537 application.Render();
1539 // Double tap to select a word.
1540 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1541 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1543 // Render and notify
1544 application.SendNotification();
1545 application.Render();
1547 // The stencil actor should have two actors: the renderer and the highlight actor.
1548 Actor stencil = editor.GetChildAt( 0u );
1550 // The stencil actor has a container with all the actors which contain the text renderers.
1551 Actor container = stencil.GetChildAt( 0u );
1552 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1554 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1555 DALI_TEST_CHECK( renderer );
1558 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1559 DALI_TEST_CHECK( highlight );
1561 // Double tap out of bounds
1562 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 29.f, 25.0f ) ) );
1563 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 29.f, 25.0f ) ) );
1565 // Render and notify
1566 application.SendNotification();
1567 application.Render();
1569 // The stencil actor should have one actors: the renderer actor.
1570 stencil = editor.GetChildAt( 0u );
1572 // The stencil actor has a container with all the actors which contain the text renderers.
1573 container = stencil.GetChildAt( 0u );
1574 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1576 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1577 DALI_TEST_CHECK( renderer );
1583 int utcDaliTextEditorEvent04(void)
1585 ToolkitTestApplication application;
1586 tet_infoline(" utcDaliTextEditorEvent04");
1588 // Checks if the highlight actor is created.
1590 TextEditor editor = TextEditor::New();
1591 DALI_TEST_CHECK( editor );
1593 Stage::GetCurrent().Add( editor );
1595 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1596 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1597 editor.SetSize( 100.f, 50.f );
1598 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1599 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1601 // Avoid a crash when core load gl resources.
1602 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1604 // Render and notify
1605 application.SendNotification();
1606 application.Render();
1608 // Tap on the text editor
1609 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1610 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1612 // Render and notify
1613 application.SendNotification();
1614 application.Render();
1616 // Move at the end of the text.
1617 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1618 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1620 // Render and notify
1621 application.SendNotification();
1622 application.Render();
1624 for( unsigned int index = 0u; index < 10u; ++index )
1626 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1627 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1629 // Render and notify
1630 application.SendNotification();
1631 application.Render();
1635 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1637 // Render and notify
1638 application.SendNotification();
1639 application.Render();
1641 DALI_TEST_EQUALS( "Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1643 // Add some key events
1644 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1645 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1647 // Render and notify
1648 application.SendNotification();
1649 application.Render();
1651 for( unsigned int index = 0u; index < 10u; ++index )
1653 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1654 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1656 // Render and notify
1657 application.SendNotification();
1658 application.Render();
1662 application.ProcessEvent( GenerateKey( " ", " ", KEY_WHITE_SPACE_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1664 // Render and notify
1665 application.SendNotification();
1666 application.Render();
1668 DALI_TEST_EQUALS( " Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1673 int utcDaliTextEditorEvent05(void)
1675 ToolkitTestApplication application;
1676 tet_infoline(" utcDaliTextEditorEvent05");
1678 // Checks if the highlight actor is created.
1680 TextEditor editor = TextEditor::New();
1681 DALI_TEST_CHECK( editor );
1683 Stage::GetCurrent().Add( editor );
1685 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1686 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1687 editor.SetSize( 50.f, 50.f );
1688 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1689 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1690 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1691 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
1692 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
1693 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
1694 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
1696 // Avoid a crash when core load gl resources.
1697 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1699 // Render and notify
1700 application.SendNotification();
1701 application.Render();
1703 // Tap on the text editor
1704 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1705 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1707 // Render and notify
1708 application.SendNotification();
1709 application.Render();
1711 // Move at the end of the text.
1712 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1713 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1715 // Render and notify
1716 application.SendNotification();
1717 application.Render();
1719 for( unsigned int index = 0u; index < 10u; ++index )
1722 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1724 // Render and notify
1725 application.SendNotification();
1726 application.Render();
1728 // Modify duration after scroll is enabled
1729 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.1f );
1731 // Continuous scroll left to increase coverage
1732 for( unsigned int index = 0u; index < 10u; ++index )
1734 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1736 // Render and notify
1737 application.SendNotification();
1738 application.Render();
1740 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1741 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
1742 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
1743 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1744 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1746 // Press Escape to increase coverage
1747 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME ) );
1748 application.SendNotification();
1749 application.Render();
1751 DALI_TEST_CHECK( !editor.HasKeyInputFocus() );
1756 int utcDaliTextEditorHandles(void)
1758 ToolkitTestApplication application;
1759 tet_infoline(" utcDaliTextEditorHandles");
1761 TextEditor editor = TextEditor::New();
1762 DALI_TEST_CHECK( editor );
1764 Stage::GetCurrent().Add( editor );
1766 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1767 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1768 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, HANDLE_IMAGE_FILE_NAME );
1769 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1771 editor.SetSize( 30.f, 500.f );
1772 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1773 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1775 // Avoid a crash when core load gl resources.
1776 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1778 // Render and notify
1779 application.SendNotification();
1780 application.Render();
1782 // Tap first to get the focus.
1783 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1784 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1786 // Render and notify
1787 application.SendNotification();
1788 application.Render();
1790 // Tap to create the grab handle.
1791 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1792 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1794 // Render and notify
1795 application.SendNotification();
1796 application.Render();
1798 // Get the active layer where the text's decoration is added.
1799 Actor activeLayer = editor.GetChildAt( 1u );
1801 // Get the handle's actor.
1802 Actor handle = activeLayer.GetChildAt( 1u );
1803 handle.SetSize( 100.f, 100.f );
1805 // Render and notify
1806 application.SendNotification();
1807 application.Render();
1809 // Touch the grab handle to set it as pressed.
1810 Vector2 touchPos( 10.0f, 50.0f );
1811 Dali::Integration::TouchEvent event;
1812 event = Dali::Integration::TouchEvent();
1813 event.AddPoint( GetPointDownInside( touchPos ) );
1814 application.ProcessEvent( event );
1816 // Render and notify
1817 application.SendNotification();
1818 application.Render();
1820 // drag grab handle right
1821 SendPan(application, Gesture::Possible, touchPos);
1822 SendPan(application, Gesture::Started, touchPos);
1824 Wait(application, 100);
1826 for(int i = 0;i<20;i++)
1828 SendPan(application, Gesture::Continuing, touchPos);
1833 SendPan(application, Gesture::Finished, touchPos);
1836 // Release the grab handle.
1837 event = Dali::Integration::TouchEvent();
1838 event.AddPoint( GetPointUpInside( touchPos ) );
1839 application.ProcessEvent( event );
1841 // Render and notify
1842 application.SendNotification();
1843 application.Render();