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 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
119 static bool gTextChangedCallBackCalled;
120 static bool gInputStyleChangedCallbackCalled;
121 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
123 struct CallbackFunctor
125 CallbackFunctor(bool* callbackFlag)
126 : mCallbackFlag( callbackFlag )
132 *mCallbackFlag = true;
137 static void TestTextChangedCallback( TextEditor control )
139 tet_infoline(" TestTextChangedCallback");
141 gTextChangedCallBackCalled = true;
144 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
146 tet_infoline(" TestInputStyleChangedCallback");
148 gInputStyleChangedCallbackCalled = true;
149 gInputStyleMask = mask;
152 // Generate a TapGestureEvent to send to Core.
153 Integration::TapGestureEvent GenerateTap(
154 Gesture::State state,
155 unsigned int numberOfTaps,
156 unsigned int numberOfTouches,
159 Integration::TapGestureEvent tap( state );
161 tap.numberOfTaps = numberOfTaps;
162 tap.numberOfTouches = numberOfTouches;
168 // Generate a PanGestureEvent to send to Core
169 Integration::PanGestureEvent GeneratePan( Gesture::State state,
170 const Vector2& previousPosition,
171 const Vector2& currentPosition,
172 unsigned long timeDelta,
173 unsigned int numberOfTouches = 1u )
175 Integration::PanGestureEvent pan(state);
177 pan.previousPosition = previousPosition;
178 pan.currentPosition = currentPosition;
179 pan.timeDelta = timeDelta;
180 pan.numberOfTouches = numberOfTouches;
185 // Generate a KeyEvent to send to Core.
186 Integration::KeyEvent GenerateKey( const std::string& keyName,
187 const std::string& keyString,
190 unsigned long timeStamp,
191 const Integration::KeyEvent::State& keyState,
192 const std::string& deviceName,
193 const DevelKeyEvent::DeviceClass::Type& deviceClass )
195 return Integration::KeyEvent( keyName,
206 * Helper to generate PanGestureEvent
208 * @param[in] application Application instance
209 * @param[in] state The Gesture State
210 * @param[in] pos The current position of touch.
212 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
216 if( (state == Gesture::Started) ||
217 (state == Gesture::Possible) )
223 application.ProcessEvent( GeneratePan( state, last, pos, 16 ) );
230 * Simulate time passed by.
232 * @note this will always process at least 1 frame (1/60 sec)
234 * @param application Test application instance
235 * @param duration Time to pass in milliseconds.
236 * @return The actual time passed in milliseconds
238 static int Wait(ToolkitTestApplication& application, int duration = 0)
242 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
244 application.SendNotification();
245 application.Render(RENDER_FRAME_INTERVAL);
246 time += RENDER_FRAME_INTERVAL;
252 Dali::Integration::Point GetPointDownInside( Vector2& pos )
254 Dali::Integration::Point point;
255 point.SetState( PointState::DOWN );
256 point.SetScreenPosition( pos );
260 Dali::Integration::Point GetPointUpInside( Vector2& pos )
262 Dali::Integration::Point point;
263 point.SetState( PointState::UP );
264 point.SetScreenPosition( pos );
268 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
270 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
272 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
274 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
276 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
277 if( NULL != valueSet )
279 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
281 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
287 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
298 int UtcDaliToolkitTextEditorConstructorP(void)
300 ToolkitTestApplication application;
301 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
302 TextEditor textEditor;
303 DALI_TEST_CHECK( !textEditor );
307 int UtcDaliToolkitTextEditorNewP(void)
309 ToolkitTestApplication application;
310 tet_infoline(" UtcDaliToolkitTextEditorNewP");
311 TextEditor textEditor = TextEditor::New();
312 DALI_TEST_CHECK( textEditor );
316 int UtcDaliToolkitTextEditorDownCastP(void)
318 ToolkitTestApplication application;
319 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
320 TextEditor textEditor1 = TextEditor::New();
321 BaseHandle object( textEditor1 );
323 TextEditor textEditor2 = TextEditor::DownCast( object );
324 DALI_TEST_CHECK( textEditor2 );
326 TextEditor textEditor3 = DownCast< TextEditor >( object );
327 DALI_TEST_CHECK( textEditor3 );
331 int UtcDaliToolkitTextEditorDownCastN(void)
333 ToolkitTestApplication application;
334 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
335 BaseHandle uninitializedObject;
336 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
337 DALI_TEST_CHECK( !textEditor1 );
339 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
340 DALI_TEST_CHECK( !textEditor2 );
344 int UtcDaliToolkitTextEditorCopyConstructorP(void)
346 ToolkitTestApplication application;
347 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
348 TextEditor textEditor = TextEditor::New();
349 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
351 TextEditor copy( textEditor );
352 DALI_TEST_CHECK( copy );
353 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
357 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
359 ToolkitTestApplication application;
360 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
361 TextEditor textEditor = TextEditor::New();
362 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
364 TextEditor copy = textEditor;
365 DALI_TEST_CHECK( copy );
366 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
370 int UtcDaliTextEditorNewP(void)
372 ToolkitTestApplication application;
373 tet_infoline(" UtcDaliToolkitTextEditorNewP");
374 TextEditor textEditor = TextEditor::New();
375 DALI_TEST_CHECK( textEditor );
379 // Positive test case for a method
380 int UtcDaliTextEditorGetPropertyP(void)
382 ToolkitTestApplication application;
383 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
384 TextEditor editor = TextEditor::New();
385 DALI_TEST_CHECK( editor );
387 // Check Property Indices are correct
388 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
389 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
390 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
391 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
392 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
393 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
394 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
395 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
396 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
397 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
398 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
399 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
400 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
401 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
402 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
403 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
404 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
405 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
406 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
407 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
408 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
409 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
410 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
411 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
412 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
413 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
414 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
415 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
416 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
417 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
419 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
420 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
421 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
422 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
423 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
424 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
425 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
426 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
427 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
428 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
429 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
430 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
431 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SCROLL_BAR ) == DevelTextEditor::Property::ENABLE_SCROLL_BAR );
432 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION );
433 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION );
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 );
725 // Positive Atlas Text Renderer test
726 int utcDaliTextEditorAtlasRenderP(void)
728 ToolkitTestApplication application;
729 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
730 StyleManager styleManager = StyleManager::Get();
731 styleManager.ApplyDefaultTheme();
732 TextEditor editor = TextEditor::New();
733 DALI_TEST_CHECK( editor );
735 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
737 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
739 Stage::GetCurrent().Add( editor );
743 // Render some text with the shared atlas backend
744 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
745 application.SendNotification();
746 application.Render();
750 tet_result(TET_FAIL);
755 // Positive test for the textChanged signal.
756 int utcDaliTextEditorTextChangedP(void)
758 ToolkitTestApplication application;
759 tet_infoline(" utcDaliTextEditorTextChangedP");
760 TextEditor editor = TextEditor::New();
761 DALI_TEST_CHECK( editor );
763 Stage::GetCurrent().Add( editor );
765 // connect to the text changed signal.
766 ConnectionTracker* testTracker = new ConnectionTracker();
767 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
768 bool textChangedSignal = false;
769 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
771 gTextChangedCallBackCalled = false;
772 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
773 DALI_TEST_CHECK( gTextChangedCallBackCalled );
774 DALI_TEST_CHECK( textChangedSignal );
776 application.SendNotification();
778 editor.SetKeyInputFocus();
780 gTextChangedCallBackCalled = false;
781 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
782 DALI_TEST_CHECK( gTextChangedCallBackCalled );
787 int utcDaliTextEditorInputStyleChanged01(void)
789 ToolkitTestApplication application;
790 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
792 // The text-editor emits signals when the input style changes. These changes of style are
793 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
794 // can't be emitted during the size negotiation as the callbacks may update the UI.
795 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
796 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
797 application.CreateAdaptor();
801 char* pathNamePtr = get_current_dir_name();
802 const std::string pathName( pathNamePtr );
805 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
806 fontClient.SetDpi( 93u, 93u );
808 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
809 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
811 TextEditor editor = TextEditor::New();
812 DALI_TEST_CHECK( editor );
815 editor.SetSize( 300.f, 50.f );
816 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
817 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
819 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
820 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
822 // connect to the text changed signal.
823 ConnectionTracker* testTracker = new ConnectionTracker();
824 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
825 bool inputStyleChangedSignal = false;
826 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
828 Stage::GetCurrent().Add( editor );
831 application.SendNotification();
832 application.Render();
834 // Executes the idle callbacks added by the text control on the change of input style.
835 application.RunIdles();
837 gInputStyleChangedCallbackCalled = false;
838 gInputStyleMask = TextEditor::InputStyle::NONE;
839 inputStyleChangedSignal = false;
841 // Create a tap event to touch the text editor.
842 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
843 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
846 application.SendNotification();
847 application.Render();
849 // Executes the idle callbacks added by the text control on the change of input style.
850 application.RunIdles();
852 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
853 if( gInputStyleChangedCallbackCalled )
855 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
857 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
858 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
860 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
861 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
863 DALI_TEST_CHECK( inputStyleChangedSignal );
865 gInputStyleChangedCallbackCalled = false;
866 gInputStyleMask = TextEditor::InputStyle::NONE;
867 inputStyleChangedSignal = false;
869 // Create a tap event to touch the text editor.
870 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
871 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
874 application.SendNotification();
875 application.Render();
877 // Executes the idle callbacks added by the text control on the change of input style.
878 application.RunIdles();
880 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
881 DALI_TEST_CHECK( !inputStyleChangedSignal );
883 gInputStyleChangedCallbackCalled = false;
884 gInputStyleMask = TextEditor::InputStyle::NONE;
885 inputStyleChangedSignal = false;
887 // Create a tap event to touch the text editor.
888 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
889 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
892 application.SendNotification();
893 application.Render();
895 // Executes the idle callbacks added by the text control on the change of input style.
896 application.RunIdles();
898 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
899 if( gInputStyleChangedCallbackCalled )
901 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
903 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
904 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
906 DALI_TEST_CHECK( inputStyleChangedSignal );
908 gInputStyleChangedCallbackCalled = false;
909 gInputStyleMask = TextEditor::InputStyle::NONE;
910 inputStyleChangedSignal = false;
912 // Create a tap event to touch the text editor.
913 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
914 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
917 application.SendNotification();
918 application.Render();
920 // Executes the idle callbacks added by the text control on the change of input style.
921 application.RunIdles();
923 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
924 if( gInputStyleChangedCallbackCalled )
926 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
928 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
929 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
931 Property::Map fontStyleMapSet;
932 Property::Map fontStyleMapGet;
934 fontStyleMapSet.Insert( "weight", "bold" );
936 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
937 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
938 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
940 DALI_TEST_CHECK( inputStyleChangedSignal );
942 gInputStyleChangedCallbackCalled = false;
943 gInputStyleMask = TextEditor::InputStyle::NONE;
944 inputStyleChangedSignal = false;
946 // Create a tap event to touch the text editor.
947 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
948 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
951 application.SendNotification();
952 application.Render();
954 // Executes the idle callbacks added by the text control on the change of input style.
955 application.RunIdles();
957 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
958 DALI_TEST_CHECK( !inputStyleChangedSignal );
960 gInputStyleChangedCallbackCalled = false;
961 gInputStyleMask = TextEditor::InputStyle::NONE;
962 inputStyleChangedSignal = false;
964 // Create a tap event to touch the text editor.
965 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
966 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
969 application.SendNotification();
970 application.Render();
972 // Executes the idle callbacks added by the text control on the change of input style.
973 application.RunIdles();
975 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
976 if( gInputStyleChangedCallbackCalled )
978 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
980 Property::Map fontStyleMapSet;
981 Property::Map fontStyleMapGet;
983 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
984 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
985 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
987 DALI_TEST_CHECK( inputStyleChangedSignal );
989 gInputStyleChangedCallbackCalled = false;
990 gInputStyleMask = TextEditor::InputStyle::NONE;
991 inputStyleChangedSignal = false;
993 // Create a tap event to touch the text editor.
994 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
995 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
998 application.SendNotification();
999 application.Render();
1001 // Executes the idle callbacks added by the text control on the change of input style.
1002 application.RunIdles();
1004 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1005 DALI_TEST_CHECK( !inputStyleChangedSignal );
1010 int utcDaliTextEditorInputStyleChanged02(void)
1012 ToolkitTestApplication application;
1013 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
1015 // The text-editor emits signals when the input style changes. These changes of style are
1016 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1017 // can't be emitted during the size negotiation as the callbacks may update the UI.
1018 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
1019 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1020 application.CreateAdaptor();
1024 char* pathNamePtr = get_current_dir_name();
1025 const std::string pathName( pathNamePtr );
1026 free( pathNamePtr );
1028 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1029 fontClient.SetDpi( 93u, 93u );
1031 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1032 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1034 TextEditor editor = TextEditor::New();
1035 DALI_TEST_CHECK( editor );
1038 editor.SetSize( 300.f, 50.f );
1039 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1040 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1042 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
1043 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>" );
1045 // connect to the text changed signal.
1046 ConnectionTracker* testTracker = new ConnectionTracker();
1047 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1048 bool inputStyleChangedSignal = false;
1049 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1051 Stage::GetCurrent().Add( editor );
1053 // Render and notify
1054 application.SendNotification();
1055 application.Render();
1057 // Executes the idle callbacks added by the text control on the change of input style.
1058 application.RunIdles();
1060 gInputStyleChangedCallbackCalled = false;
1061 gInputStyleMask = TextEditor::InputStyle::NONE;
1062 inputStyleChangedSignal = false;
1064 // Create a tap event to touch the text editor.
1065 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1066 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1067 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1068 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1070 // Render and notify
1071 application.SendNotification();
1072 application.Render();
1074 // Executes the idle callbacks added by the text control on the change of input style.
1075 application.RunIdles();
1077 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1078 if( gInputStyleChangedCallbackCalled )
1080 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1081 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
1082 TextEditor::InputStyle::POINT_SIZE |
1083 TextEditor::InputStyle::COLOR ),
1086 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1087 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1089 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1090 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1092 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
1093 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1095 DALI_TEST_CHECK( inputStyleChangedSignal );
1097 gInputStyleChangedCallbackCalled = false;
1098 gInputStyleMask = TextEditor::InputStyle::NONE;
1099 inputStyleChangedSignal = false;
1101 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1103 // Render and notify
1104 application.SendNotification();
1105 application.Render();
1107 // Executes the idle callbacks added by the text control on the change of input style.
1108 application.RunIdles();
1110 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1111 if( gInputStyleChangedCallbackCalled )
1113 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1114 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1117 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1118 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1120 DALI_TEST_CHECK( inputStyleChangedSignal );
1122 gInputStyleChangedCallbackCalled = false;
1123 gInputStyleMask = TextEditor::InputStyle::NONE;
1124 inputStyleChangedSignal = false;
1126 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1128 // Render and notify
1129 application.SendNotification();
1130 application.Render();
1132 // Executes the idle callbacks added by the text control on the change of input style.
1133 application.RunIdles();
1135 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1136 DALI_TEST_CHECK( !inputStyleChangedSignal );
1138 gInputStyleChangedCallbackCalled = false;
1139 gInputStyleMask = TextEditor::InputStyle::NONE;
1140 inputStyleChangedSignal = false;
1142 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1144 // Render and notify
1145 application.SendNotification();
1146 application.Render();
1148 // Executes the idle callbacks added by the text control on the change of input style.
1149 application.RunIdles();
1151 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1152 if( gInputStyleChangedCallbackCalled )
1154 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1155 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1158 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1159 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1161 DALI_TEST_CHECK( inputStyleChangedSignal );
1163 gInputStyleChangedCallbackCalled = false;
1164 gInputStyleMask = TextEditor::InputStyle::NONE;
1165 inputStyleChangedSignal = false;
1167 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1169 Property::Map fontStyleMapSet;
1170 fontStyleMapSet.Insert( "weight", "thin" );
1171 fontStyleMapSet.Insert( "width", "condensed" );
1172 fontStyleMapSet.Insert( "slant", "italic" );
1174 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1175 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1176 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1178 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1179 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1180 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1181 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1183 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1185 // Render and notify
1186 application.SendNotification();
1187 application.Render();
1189 // Executes the idle callbacks added by the text control on the change of input style.
1190 application.RunIdles();
1192 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1193 DALI_TEST_CHECK( !inputStyleChangedSignal );
1195 // Create a tap event to touch the text editor.
1196 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1197 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1199 // Render and notify
1200 application.SendNotification();
1201 application.Render();
1203 // Executes the idle callbacks added by the text control on the change of input style.
1204 application.RunIdles();
1206 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1207 if( gInputStyleChangedCallbackCalled )
1209 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1210 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1211 TextEditor::InputStyle::POINT_SIZE |
1212 TextEditor::InputStyle::FONT_STYLE |
1213 TextEditor::InputStyle::LINE_SPACING |
1214 TextEditor::InputStyle::UNDERLINE |
1215 TextEditor::InputStyle::SHADOW |
1216 TextEditor::InputStyle::EMBOSS |
1217 TextEditor::InputStyle::OUTLINE ),
1220 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1221 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1223 DALI_TEST_CHECK( inputStyleChangedSignal );
1225 gInputStyleChangedCallbackCalled = false;
1226 gInputStyleMask = TextEditor::InputStyle::NONE;
1227 inputStyleChangedSignal = false;
1229 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1231 fontStyleMapSet.Clear();
1232 fontStyleMapSet.Insert( "weight", "black" );
1233 fontStyleMapSet.Insert( "width", "expanded" );
1234 fontStyleMapSet.Insert( "slant", "oblique" );
1236 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1238 // Create a tap event to touch the text editor.
1239 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1240 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1242 // Render and notify
1243 application.SendNotification();
1244 application.Render();
1246 // Executes the idle callbacks added by the text control on the change of input style.
1247 application.RunIdles();
1249 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1250 if( gInputStyleChangedCallbackCalled )
1252 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1253 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1254 TextEditor::InputStyle::POINT_SIZE |
1255 TextEditor::InputStyle::FONT_STYLE ),
1258 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1259 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1261 DALI_TEST_CHECK( inputStyleChangedSignal );
1266 int utcDaliTextEditorEvent01(void)
1268 ToolkitTestApplication application;
1269 tet_infoline(" utcDaliTextEditorEvent01");
1271 // Creates a tap event. After creating a tap event the text editor should
1272 // have the focus and add text with key events should be possible.
1274 TextEditor editor = TextEditor::New();
1275 DALI_TEST_CHECK( editor );
1277 Stage::GetCurrent().Add( editor );
1279 editor.SetSize( 300.f, 50.f );
1280 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1281 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1283 // Avoid a crash when core load gl resources.
1284 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1286 // Render and notify
1287 application.SendNotification();
1288 application.Render();
1290 // Add a key event but as the text editor has not the focus it should do nothing.
1291 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1293 // Render and notify
1294 application.SendNotification();
1295 application.Render();
1297 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1299 // Create a tap event to touch the text editor.
1300 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1301 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1303 // Render and notify
1304 application.SendNotification();
1305 application.Render();
1307 // Now the text editor has the focus, so it can handle the key events.
1308 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1309 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1311 // Render and notify
1312 application.SendNotification();
1313 application.Render();
1315 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1317 // Create a second text editor and send key events to it.
1318 TextEditor editor2 = TextEditor::New();
1320 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1321 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1322 editor2.SetSize( 100.f, 100.f );
1323 editor2.SetPosition( 100.f, 100.f );
1325 Stage::GetCurrent().Add( editor2 );
1327 // Render and notify
1328 application.SendNotification();
1329 application.Render();
1331 // Create a tap event on the second text editor.
1332 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1333 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1335 // Render and notify
1336 application.SendNotification();
1337 application.Render();
1339 // The second text editor has the focus. It should handle the key events.
1340 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1341 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1343 // Render and notify
1344 application.SendNotification();
1345 application.Render();
1347 // Check the text has been added to the second text editor.
1348 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1353 int utcDaliTextEditorEvent02(void)
1355 ToolkitTestApplication application;
1356 tet_infoline(" utcDaliTextEditorEvent02");
1358 // Checks if the right number of actors are created.
1360 TextEditor editor = TextEditor::New();
1361 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1362 DALI_TEST_CHECK( editor );
1364 Stage::GetCurrent().Add( editor );
1366 editor.SetSize( 300.f, 50.f );
1367 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1368 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1370 // Avoid a crash when core load gl resources.
1371 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1373 // Render and notify
1374 application.SendNotification();
1375 application.Render();
1377 // Check there are the expected number of children (the stencil).
1378 DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1380 Actor stencil = editor.GetChildAt( 0u );
1382 // Create a tap event to touch the text editor.
1383 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1384 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1386 // Render and notify
1387 application.SendNotification();
1388 application.Render();
1390 Actor layer = editor.GetChildAt( 1u );
1391 DALI_TEST_CHECK( layer.IsLayer() );
1393 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1394 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1396 // Now the text editor has the focus, so it can handle the key events.
1397 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1398 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1400 // Render and notify
1401 application.SendNotification();
1402 application.Render();
1404 // Checks the cursor and the renderer have been created.
1405 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1406 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1408 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1409 DALI_TEST_CHECK( cursor );
1411 // The stencil actor has a container with all the actors which contain the text renderers.
1412 Actor container = stencil.GetChildAt( 0u );
1413 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1415 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1416 DALI_TEST_CHECK( renderer );
1419 // Move the cursor and check the position changes.
1420 Vector3 position1 = cursor.GetCurrentPosition();
1422 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1423 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1425 // Render and notify
1426 application.SendNotification();
1427 application.Render();
1429 Vector3 position2 = cursor.GetCurrentPosition();
1431 DALI_TEST_CHECK( position2.x < position1.x );
1433 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1434 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1436 // Render and notify
1437 application.SendNotification();
1438 application.Render();
1440 Vector3 position3 = cursor.GetCurrentPosition();
1442 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1444 // Send some taps and check the cursor positions.
1446 // Try to tap at the beginning.
1447 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1448 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1450 // Render and notify
1451 application.SendNotification();
1452 application.Render();
1454 // Cursor position should be the same than position1.
1455 Vector3 position4 = cursor.GetCurrentPosition();
1457 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1459 // Tap away from the start position.
1460 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1461 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1463 // Render and notify
1464 application.SendNotification();
1465 application.Render();
1467 Vector3 position5 = cursor.GetCurrentPosition();
1469 DALI_TEST_CHECK( position5.x > position4.x );
1471 // Remove all the text.
1472 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1473 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1474 editor.SetProperty( TextEditor::Property::TEXT, "" );
1476 // Render and notify
1477 application.SendNotification();
1478 application.Render();
1480 // Cursor position should be the same than position2.
1481 Vector3 position6 = cursor.GetCurrentPosition();
1483 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1485 // Should not be a renderer.
1486 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1491 int utcDaliTextEditorEvent03(void)
1493 ToolkitTestApplication application;
1494 tet_infoline(" utcDaliTextEditorEvent03");
1496 // Checks if the highlight actor is created.
1498 TextEditor editor = TextEditor::New();
1499 DALI_TEST_CHECK( editor );
1501 Stage::GetCurrent().Add( editor );
1503 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1504 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1505 editor.SetSize( 30.f, 50.f );
1506 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1507 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1509 // Avoid a crash when core load gl resources.
1510 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1512 // Render and notify
1513 application.SendNotification();
1514 application.Render();
1516 // Send some taps and check text controller with clipboard window
1517 Dali::Clipboard clipboard = Clipboard::Get();
1518 clipboard.ShowClipboard();
1519 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1520 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1521 clipboard.HideClipboard();
1523 // Render and notify
1524 application.SendNotification();
1525 application.Render();
1527 // Tap first to get the focus.
1528 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1529 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1531 // Render and notify
1532 application.SendNotification();
1533 application.Render();
1535 // Double tap to select a word.
1536 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1537 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1539 // Render and notify
1540 application.SendNotification();
1541 application.Render();
1543 // The stencil actor should have two actors: the renderer and the highlight actor.
1544 Actor stencil = editor.GetChildAt( 0u );
1546 // The stencil actor has a container with all the actors which contain the text renderers.
1547 Actor container = stencil.GetChildAt( 0u );
1548 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1550 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1551 DALI_TEST_CHECK( renderer );
1554 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1555 DALI_TEST_CHECK( highlight );
1557 // Double tap out of bounds
1558 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 29.f, 25.0f ) ) );
1559 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 29.f, 25.0f ) ) );
1561 // Render and notify
1562 application.SendNotification();
1563 application.Render();
1565 // The stencil actor should have one actors: the renderer actor.
1566 stencil = editor.GetChildAt( 0u );
1568 // The stencil actor has a container with all the actors which contain the text renderers.
1569 container = stencil.GetChildAt( 0u );
1570 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1572 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1573 DALI_TEST_CHECK( renderer );
1579 int utcDaliTextEditorEvent04(void)
1581 ToolkitTestApplication application;
1582 tet_infoline(" utcDaliTextEditorEvent04");
1584 // Checks if the highlight actor is created.
1586 TextEditor editor = TextEditor::New();
1587 DALI_TEST_CHECK( editor );
1589 Stage::GetCurrent().Add( editor );
1591 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1592 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1593 editor.SetSize( 100.f, 50.f );
1594 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1595 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1597 // Avoid a crash when core load gl resources.
1598 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1600 // Render and notify
1601 application.SendNotification();
1602 application.Render();
1604 // Tap on the text editor
1605 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1606 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1608 // Render and notify
1609 application.SendNotification();
1610 application.Render();
1612 // Move at the end of the text.
1613 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1614 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1616 // Render and notify
1617 application.SendNotification();
1618 application.Render();
1620 for( unsigned int index = 0u; index < 10u; ++index )
1622 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1623 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1625 // Render and notify
1626 application.SendNotification();
1627 application.Render();
1631 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1633 // Render and notify
1634 application.SendNotification();
1635 application.Render();
1637 DALI_TEST_EQUALS( "Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1639 // Add some key events
1640 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1641 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1643 // Render and notify
1644 application.SendNotification();
1645 application.Render();
1647 for( unsigned int index = 0u; index < 10u; ++index )
1649 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1650 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1652 // Render and notify
1653 application.SendNotification();
1654 application.Render();
1658 application.ProcessEvent( GenerateKey( " ", " ", KEY_WHITE_SPACE_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1660 // Render and notify
1661 application.SendNotification();
1662 application.Render();
1664 DALI_TEST_EQUALS( " Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1669 int utcDaliTextEditorEvent05(void)
1671 ToolkitTestApplication application;
1672 tet_infoline(" utcDaliTextEditorEvent05");
1674 // Checks if the highlight actor is created.
1676 TextEditor editor = TextEditor::New();
1677 DALI_TEST_CHECK( editor );
1679 Stage::GetCurrent().Add( editor );
1681 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1682 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1683 editor.SetSize( 50.f, 50.f );
1684 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1685 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1686 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1687 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
1688 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
1689 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
1690 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
1692 // Avoid a crash when core load gl resources.
1693 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1695 // Render and notify
1696 application.SendNotification();
1697 application.Render();
1699 // Tap on the text editor
1700 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1701 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1703 // Render and notify
1704 application.SendNotification();
1705 application.Render();
1707 // Move at the end of the text.
1708 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1709 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1711 // Render and notify
1712 application.SendNotification();
1713 application.Render();
1715 for( unsigned int index = 0u; index < 10u; ++index )
1718 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1720 // Render and notify
1721 application.SendNotification();
1722 application.Render();
1724 // Modify duration after scroll is enabled
1725 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.1f );
1727 // Continuous scroll left to increase coverage
1728 for( unsigned int index = 0u; index < 10u; ++index )
1730 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1732 // Render and notify
1733 application.SendNotification();
1734 application.Render();
1736 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1737 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
1738 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
1739 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1740 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1742 // Press Escape to increase coverage
1743 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, DevelKeyEvent::DeviceClass::NONE ) );
1744 application.SendNotification();
1745 application.Render();
1747 DALI_TEST_CHECK( !editor.HasKeyInputFocus() );
1752 int utcDaliTextEditorHandles(void)
1754 ToolkitTestApplication application;
1755 tet_infoline(" utcDaliTextEditorHandles");
1757 TextEditor editor = TextEditor::New();
1758 DALI_TEST_CHECK( editor );
1760 Stage::GetCurrent().Add( editor );
1762 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1763 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1764 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, HANDLE_IMAGE_FILE_NAME );
1765 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1767 editor.SetSize( 30.f, 500.f );
1768 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1769 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1771 // Avoid a crash when core load gl resources.
1772 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1774 // Render and notify
1775 application.SendNotification();
1776 application.Render();
1778 // Tap first to get the focus.
1779 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1780 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1782 // Render and notify
1783 application.SendNotification();
1784 application.Render();
1786 // Tap to create the grab handle.
1787 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1788 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1790 // Render and notify
1791 application.SendNotification();
1792 application.Render();
1794 // Get the active layer where the text's decoration is added.
1795 Actor activeLayer = editor.GetChildAt( 1u );
1797 // Get the handle's actor.
1798 Actor handle = activeLayer.GetChildAt( 1u );
1799 handle.SetSize( 100.f, 100.f );
1801 // Render and notify
1802 application.SendNotification();
1803 application.Render();
1805 // Touch the grab handle to set it as pressed.
1806 Vector2 touchPos( 10.0f, 50.0f );
1807 Dali::Integration::TouchEvent event;
1808 event = Dali::Integration::TouchEvent();
1809 event.AddPoint( GetPointDownInside( touchPos ) );
1810 application.ProcessEvent( event );
1812 // Render and notify
1813 application.SendNotification();
1814 application.Render();
1816 // drag grab handle right
1817 SendPan(application, Gesture::Possible, touchPos);
1818 SendPan(application, Gesture::Started, touchPos);
1820 Wait(application, 100);
1822 for(int i = 0;i<20;i++)
1824 SendPan(application, Gesture::Continuing, touchPos);
1829 SendPan(application, Gesture::Finished, touchPos);
1832 // Release the grab handle.
1833 event = Dali::Integration::TouchEvent();
1834 event.AddPoint( GetPointUpInside( touchPos ) );
1835 application.ProcessEvent( event );
1837 // Render and notify
1838 application.SendNotification();
1839 application.Render();