2 * Copyright (c) 2016 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/tap-gesture-event.h>
26 #include <dali-toolkit-test-suite-utils.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
31 using namespace Toolkit;
33 void dali_texteditor_startup(void)
35 test_return_value = TET_UNDEF;
38 void dali_texteditor_cleanup(void)
40 test_return_value = TET_PASS;
46 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
47 const char* const PROPERTY_NAME_TEXT = "text";
48 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
49 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
50 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
51 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
52 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
53 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
54 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
55 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
56 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
57 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
58 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
59 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
60 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
61 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
62 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
67 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
68 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
69 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
70 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
71 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
72 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
73 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
74 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
75 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
77 const char* const PROPERTY_NAME_LINE_SPACING = "lineSpacing";
78 const char* const PROPERTY_NAME_INPUT_LINE_SPACING = "inputLineSpacing";
79 const char* const PROPERTY_NAME_UNDERLINE = "underline";
80 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
81 const char* const PROPERTY_NAME_SHADOW = "shadow";
82 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
83 const char* const PROPERTY_NAME_EMBOSS = "emboss";
84 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
85 const char* const PROPERTY_NAME_OUTLINE = "outline";
86 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
88 const char* const PROPERTY_NAME_SMOOTH_SCROLL = "smoothScroll";
89 const char* const PROPERTY_NAME_SMOOTH_SCROLL_DURATION = "smoothScrollDuration";
90 const char* const PROPERTY_NAME_ENABLE_SCROLL_BAR = "enableScrollBar";
91 const char* const PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION = "scrollBarShowDuration";
92 const char* const PROPERTY_NAME_SCROLL_BAR_FADE_DURATION = "scrollBarFadeDuration";
94 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
96 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
98 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
99 const float TO_MILLISECONDS = 1000.f;
100 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
102 const float SCROLL_THRESHOLD = 10.f;
103 const float SCROLL_SPEED = 300.f;
105 const unsigned int DEFAULT_FONT_SIZE = 1152u;
106 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
108 const int KEY_A_CODE = 38;
109 const int KEY_D_CODE = 40;
110 const int KEY_WHITE_SPACE_CODE = 65;
112 static bool gTextChangedCallBackCalled;
113 static bool gInputStyleChangedCallbackCalled;
114 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
116 struct CallbackFunctor
118 CallbackFunctor(bool* callbackFlag)
119 : mCallbackFlag( callbackFlag )
125 *mCallbackFlag = true;
130 static void TestTextChangedCallback( TextEditor control )
132 tet_infoline(" TestTextChangedCallback");
134 gTextChangedCallBackCalled = true;
137 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
139 tet_infoline(" TestInputStyleChangedCallback");
141 gInputStyleChangedCallbackCalled = true;
142 gInputStyleMask = mask;
145 // Generate a TapGestureEvent to send to Core.
146 Integration::TapGestureEvent GenerateTap(
147 Gesture::State state,
148 unsigned int numberOfTaps,
149 unsigned int numberOfTouches,
152 Integration::TapGestureEvent tap( state );
154 tap.numberOfTaps = numberOfTaps;
155 tap.numberOfTouches = numberOfTouches;
161 // Generate a KeyEvent to send to Core.
162 Integration::KeyEvent GenerateKey( const std::string& keyName,
163 const std::string& keyString,
166 unsigned long timeStamp,
167 const Integration::KeyEvent::State& keyState )
169 return Integration::KeyEvent( keyName,
177 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
179 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
181 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
183 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
185 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
186 if( NULL != valueSet )
188 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
190 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
196 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
207 int UtcDaliToolkitTextEditorConstructorP(void)
209 ToolkitTestApplication application;
210 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
211 TextEditor textEditor;
212 DALI_TEST_CHECK( !textEditor );
216 int UtcDaliToolkitTextEditorNewP(void)
218 ToolkitTestApplication application;
219 tet_infoline(" UtcDaliToolkitTextEditorNewP");
220 TextEditor textEditor = TextEditor::New();
221 DALI_TEST_CHECK( textEditor );
225 int UtcDaliToolkitTextEditorDownCastP(void)
227 ToolkitTestApplication application;
228 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
229 TextEditor textEditor1 = TextEditor::New();
230 BaseHandle object( textEditor1 );
232 TextEditor textEditor2 = TextEditor::DownCast( object );
233 DALI_TEST_CHECK( textEditor2 );
235 TextEditor textEditor3 = DownCast< TextEditor >( object );
236 DALI_TEST_CHECK( textEditor3 );
240 int UtcDaliToolkitTextEditorDownCastN(void)
242 ToolkitTestApplication application;
243 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
244 BaseHandle uninitializedObject;
245 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
246 DALI_TEST_CHECK( !textEditor1 );
248 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
249 DALI_TEST_CHECK( !textEditor2 );
253 int UtcDaliToolkitTextEditorCopyConstructorP(void)
255 ToolkitTestApplication application;
256 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
257 TextEditor textEditor = TextEditor::New();
258 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
260 TextEditor copy( textEditor );
261 DALI_TEST_CHECK( copy );
262 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
266 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
268 ToolkitTestApplication application;
269 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
270 TextEditor textEditor = TextEditor::New();
271 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
273 TextEditor copy = textEditor;
274 DALI_TEST_CHECK( copy );
275 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
279 int UtcDaliTextEditorNewP(void)
281 ToolkitTestApplication application;
282 tet_infoline(" UtcDaliToolkitTextEditorNewP");
283 TextEditor textEditor = TextEditor::New();
284 DALI_TEST_CHECK( textEditor );
288 // Positive test case for a method
289 int UtcDaliTextEditorGetPropertyP(void)
291 ToolkitTestApplication application;
292 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
293 TextEditor editor = TextEditor::New();
294 DALI_TEST_CHECK( editor );
296 // Check Property Indices are correct
297 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
298 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
299 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
300 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
301 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
302 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
303 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
304 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
305 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
306 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
307 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
308 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
309 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
310 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
311 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
312 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
313 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
314 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
315 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
316 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
317 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
318 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
319 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
320 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
321 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
322 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
323 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
324 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
325 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
326 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
328 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
329 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
330 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
331 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
332 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
333 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
334 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
335 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
336 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
337 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
338 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
339 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
340 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SCROLL_BAR ) == DevelTextEditor::Property::ENABLE_SCROLL_BAR );
341 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION );
342 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION );
347 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
350 Property::Map imageMap;
351 imageMap[mapKey] =mapValue;
353 editor.SetProperty( property , imageMap );
354 Property::Value propValue = editor.GetProperty( property );
355 Property::Map* resultMap = propValue.GetMap();
357 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
365 // Positive test case for a method
366 int UtcDaliTextEditorSetPropertyP(void)
368 ToolkitTestApplication application;
369 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
370 TextEditor editor = TextEditor::New();
371 DALI_TEST_CHECK( editor );
372 Stage::GetCurrent().Add( editor );
374 // Note - we can't check the defaults since the stylesheets are platform-specific
376 // Check the render backend property.
377 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
378 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
380 // Check text property.
381 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
382 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
384 // Check text's color property
385 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
386 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
388 // Check font properties.
389 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
390 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
392 Property::Map fontStyleMapSet;
393 Property::Map fontStyleMapGet;
394 Property::Value* slantValue = NULL;
396 fontStyleMapSet.Insert( "weight", "bold" );
397 fontStyleMapSet.Insert( "width", "condensed" );
398 fontStyleMapSet.Insert( "slant", "italic" );
400 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
401 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
402 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
403 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
405 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
406 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
409 fontStyleMapSet.Clear();
410 fontStyleMapSet.Insert( "weight", "normal" );
411 fontStyleMapSet.Insert( "slant", "oblique" );
412 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
413 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
414 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
415 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
417 fontStyleMapSet.Clear();
418 fontStyleMapSet.Insert( "slant", "roman" );
419 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
420 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
422 // Replace 'roman' for 'normal'.
423 slantValue = fontStyleMapGet.Find( "slant" );
424 if( NULL != slantValue )
426 if( "normal" == slantValue->Get<std::string>() )
428 fontStyleMapGet["slant"] = "roman";
431 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
432 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
434 fontStyleMapSet.Clear();
436 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
437 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
438 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
439 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
441 // Check that the Alignment properties can be correctly set
442 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
443 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
445 // Check scroll properties.
446 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
447 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
448 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
449 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
451 // Check cursor properties
452 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
453 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
454 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
455 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
457 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
458 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
459 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
460 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
461 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
462 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
463 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
464 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
466 // Check handle images
467 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
468 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
469 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
470 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
471 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
473 // Check handle images
474 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
475 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
476 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
477 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
478 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
479 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
481 // Check the highlight color
482 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
483 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
485 // Decoration bounding box
486 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
487 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
489 // Check the enable markup property.
490 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
491 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
492 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
494 // Check input color property.
495 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
496 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
498 // Check input font properties.
499 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
500 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
502 fontStyleMapSet.Clear();
503 fontStyleMapSet.Insert( "weight", "bold" );
504 fontStyleMapSet.Insert( "width", "condensed" );
505 fontStyleMapSet.Insert( "slant", "italic" );
507 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
508 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
509 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
510 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
512 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
513 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
515 // Reset input font style.
516 fontStyleMapSet.Clear();
517 fontStyleMapSet.Insert( "weight", "normal" );
518 fontStyleMapSet.Insert( "slant", "oblique" );
520 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
521 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
522 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
523 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
525 fontStyleMapSet.Clear();
526 fontStyleMapSet.Insert( "slant", "roman" );
528 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
529 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
531 // Replace 'roman' for 'normal'.
532 slantValue = fontStyleMapGet.Find( "slant" );
533 if( NULL != slantValue )
535 if( "normal" == slantValue->Get<std::string>() )
537 fontStyleMapGet["slant"] = "roman";
540 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
541 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
543 fontStyleMapSet.Clear();
545 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
546 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
547 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
548 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
550 // Check the line spacing property
551 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
552 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
553 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
555 // Check the input line spacing property
556 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
557 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
558 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
560 // Check the underline property
562 Property::Map underlineMapSet;
563 Property::Map underlineMapGet;
565 underlineMapSet.Insert( "enable", "true" );
566 underlineMapSet.Insert( "color", "red" );
567 underlineMapSet.Insert( "height", "1" );
569 editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet );
571 underlineMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::UNDERLINE );
572 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
573 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
575 // Check the input underline property
576 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
577 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
579 // Check the shadow property
580 Property::Map shadowMapSet;
581 Property::Map shadowMapGet;
583 shadowMapSet.Insert( "color", "green" );
584 shadowMapSet.Insert( "offset", "2 2" );
586 editor.SetProperty( TextEditor::Property::SHADOW, shadowMapSet );
588 shadowMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::SHADOW );
589 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
590 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
592 // Check the input shadow property
593 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
594 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
596 // Check the emboss property
597 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
598 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
600 // Check the input emboss property
601 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
602 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
604 // Check the outline property
605 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
606 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
608 // Check the input outline property
609 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
610 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
612 // Check the smooth scroll property
613 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), false, TEST_LOCATION );
614 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
615 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
617 // Check the smooth scroll duration property
618 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
619 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
621 // Check the scroll bar property
622 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), false, TEST_LOCATION );
623 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
624 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
626 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
627 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
628 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
629 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
634 // Positive Atlas Text Renderer test
635 int utcDaliTextEditorAtlasRenderP(void)
637 ToolkitTestApplication application;
638 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
639 StyleManager styleManager = StyleManager::Get();
640 styleManager.ApplyDefaultTheme();
641 TextEditor editor = TextEditor::New();
642 DALI_TEST_CHECK( editor );
644 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
646 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
648 Stage::GetCurrent().Add( editor );
652 // Render some text with the shared atlas backend
653 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
654 application.SendNotification();
655 application.Render();
659 tet_result(TET_FAIL);
664 // Positive test for the textChanged signal.
665 int utcDaliTextEditorTextChangedP(void)
667 ToolkitTestApplication application;
668 tet_infoline(" utcDaliTextEditorTextChangedP");
669 TextEditor editor = TextEditor::New();
670 DALI_TEST_CHECK( editor );
672 Stage::GetCurrent().Add( editor );
674 // connect to the text changed signal.
675 ConnectionTracker* testTracker = new ConnectionTracker();
676 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
677 bool textChangedSignal = false;
678 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
680 gTextChangedCallBackCalled = false;
681 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
682 DALI_TEST_CHECK( gTextChangedCallBackCalled );
683 DALI_TEST_CHECK( textChangedSignal );
685 application.SendNotification();
687 editor.SetKeyInputFocus();
689 gTextChangedCallBackCalled = false;
690 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
691 DALI_TEST_CHECK( gTextChangedCallBackCalled );
696 int utcDaliTextEditorInputStyleChanged01(void)
698 ToolkitTestApplication application;
699 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
701 // The text-editor emits signals when the input style changes. These changes of style are
702 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
703 // can't be emitted during the size negotiation as the callbacks may update the UI.
704 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
705 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
706 application.CreateAdaptor();
710 char* pathNamePtr = get_current_dir_name();
711 const std::string pathName( pathNamePtr );
714 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
715 fontClient.SetDpi( 93u, 93u );
717 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
718 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
720 TextEditor editor = TextEditor::New();
721 DALI_TEST_CHECK( editor );
724 editor.SetSize( 300.f, 50.f );
725 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
726 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
728 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
729 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
731 // connect to the text changed signal.
732 ConnectionTracker* testTracker = new ConnectionTracker();
733 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
734 bool inputStyleChangedSignal = false;
735 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
737 Stage::GetCurrent().Add( editor );
740 application.SendNotification();
741 application.Render();
743 // Executes the idle callbacks added by the text control on the change of input style.
744 application.RunIdles();
746 gInputStyleChangedCallbackCalled = false;
747 gInputStyleMask = TextEditor::InputStyle::NONE;
748 inputStyleChangedSignal = false;
750 // Create a tap event to touch the text editor.
751 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
752 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
755 application.SendNotification();
756 application.Render();
758 // Executes the idle callbacks added by the text control on the change of input style.
759 application.RunIdles();
761 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
762 if( gInputStyleChangedCallbackCalled )
764 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
766 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
767 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
769 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
770 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
772 DALI_TEST_CHECK( inputStyleChangedSignal );
774 gInputStyleChangedCallbackCalled = false;
775 gInputStyleMask = TextEditor::InputStyle::NONE;
776 inputStyleChangedSignal = false;
778 // Create a tap event to touch the text editor.
779 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
780 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
783 application.SendNotification();
784 application.Render();
786 // Executes the idle callbacks added by the text control on the change of input style.
787 application.RunIdles();
789 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
790 DALI_TEST_CHECK( !inputStyleChangedSignal );
792 gInputStyleChangedCallbackCalled = false;
793 gInputStyleMask = TextEditor::InputStyle::NONE;
794 inputStyleChangedSignal = false;
796 // Create a tap event to touch the text editor.
797 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
798 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
801 application.SendNotification();
802 application.Render();
804 // Executes the idle callbacks added by the text control on the change of input style.
805 application.RunIdles();
807 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
808 if( gInputStyleChangedCallbackCalled )
810 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
812 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
813 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
815 DALI_TEST_CHECK( inputStyleChangedSignal );
817 gInputStyleChangedCallbackCalled = false;
818 gInputStyleMask = TextEditor::InputStyle::NONE;
819 inputStyleChangedSignal = false;
821 // Create a tap event to touch the text editor.
822 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
823 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
826 application.SendNotification();
827 application.Render();
829 // Executes the idle callbacks added by the text control on the change of input style.
830 application.RunIdles();
832 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
833 if( gInputStyleChangedCallbackCalled )
835 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
837 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
838 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
840 Property::Map fontStyleMapSet;
841 Property::Map fontStyleMapGet;
843 fontStyleMapSet.Insert( "weight", "bold" );
845 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
846 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
847 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
849 DALI_TEST_CHECK( inputStyleChangedSignal );
851 gInputStyleChangedCallbackCalled = false;
852 gInputStyleMask = TextEditor::InputStyle::NONE;
853 inputStyleChangedSignal = false;
855 // Create a tap event to touch the text editor.
856 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
857 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
860 application.SendNotification();
861 application.Render();
863 // Executes the idle callbacks added by the text control on the change of input style.
864 application.RunIdles();
866 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
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( 164.f, 25.f ) ) );
875 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.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 if( gInputStyleChangedCallbackCalled )
887 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
889 Property::Map fontStyleMapSet;
890 Property::Map fontStyleMapGet;
892 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
893 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
894 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
896 DALI_TEST_CHECK( inputStyleChangedSignal );
898 gInputStyleChangedCallbackCalled = false;
899 gInputStyleMask = TextEditor::InputStyle::NONE;
900 inputStyleChangedSignal = false;
902 // Create a tap event to touch the text editor.
903 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
904 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
907 application.SendNotification();
908 application.Render();
910 // Executes the idle callbacks added by the text control on the change of input style.
911 application.RunIdles();
913 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
914 DALI_TEST_CHECK( !inputStyleChangedSignal );
919 int utcDaliTextEditorInputStyleChanged02(void)
921 ToolkitTestApplication application;
922 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
924 // The text-editor emits signals when the input style changes. These changes of style are
925 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
926 // can't be emitted during the size negotiation as the callbacks may update the UI.
927 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
928 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
929 application.CreateAdaptor();
933 char* pathNamePtr = get_current_dir_name();
934 const std::string pathName( pathNamePtr );
937 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
938 fontClient.SetDpi( 93u, 93u );
940 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
941 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
943 TextEditor editor = TextEditor::New();
944 DALI_TEST_CHECK( editor );
947 editor.SetSize( 300.f, 50.f );
948 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
949 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
951 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
952 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>" );
954 // connect to the text changed signal.
955 ConnectionTracker* testTracker = new ConnectionTracker();
956 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
957 bool inputStyleChangedSignal = false;
958 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
960 Stage::GetCurrent().Add( editor );
963 application.SendNotification();
964 application.Render();
966 // Executes the idle callbacks added by the text control on the change of input style.
967 application.RunIdles();
969 gInputStyleChangedCallbackCalled = false;
970 gInputStyleMask = TextEditor::InputStyle::NONE;
971 inputStyleChangedSignal = false;
973 // Create a tap event to touch the text editor.
974 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
975 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
976 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
977 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
980 application.SendNotification();
981 application.Render();
983 // Executes the idle callbacks added by the text control on the change of input style.
984 application.RunIdles();
986 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
987 if( gInputStyleChangedCallbackCalled )
989 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
990 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
991 TextEditor::InputStyle::POINT_SIZE |
992 TextEditor::InputStyle::COLOR ),
995 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
996 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
998 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
999 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1001 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
1002 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1004 DALI_TEST_CHECK( inputStyleChangedSignal );
1006 gInputStyleChangedCallbackCalled = false;
1007 gInputStyleMask = TextEditor::InputStyle::NONE;
1008 inputStyleChangedSignal = false;
1010 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1012 // Render and notify
1013 application.SendNotification();
1014 application.Render();
1016 // Executes the idle callbacks added by the text control on the change of input style.
1017 application.RunIdles();
1019 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1020 if( gInputStyleChangedCallbackCalled )
1022 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1023 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1026 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1027 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1029 DALI_TEST_CHECK( inputStyleChangedSignal );
1031 gInputStyleChangedCallbackCalled = false;
1032 gInputStyleMask = TextEditor::InputStyle::NONE;
1033 inputStyleChangedSignal = false;
1035 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1037 // Render and notify
1038 application.SendNotification();
1039 application.Render();
1041 // Executes the idle callbacks added by the text control on the change of input style.
1042 application.RunIdles();
1044 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1045 DALI_TEST_CHECK( !inputStyleChangedSignal );
1047 gInputStyleChangedCallbackCalled = false;
1048 gInputStyleMask = TextEditor::InputStyle::NONE;
1049 inputStyleChangedSignal = false;
1051 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
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 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1061 if( gInputStyleChangedCallbackCalled )
1063 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1064 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1067 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1068 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1070 DALI_TEST_CHECK( inputStyleChangedSignal );
1072 gInputStyleChangedCallbackCalled = false;
1073 gInputStyleMask = TextEditor::InputStyle::NONE;
1074 inputStyleChangedSignal = false;
1076 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1078 Property::Map fontStyleMapSet;
1079 fontStyleMapSet.Insert( "weight", "thin" );
1080 fontStyleMapSet.Insert( "width", "condensed" );
1081 fontStyleMapSet.Insert( "slant", "italic" );
1083 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1084 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1085 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1087 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1088 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1089 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1090 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1092 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1094 // Render and notify
1095 application.SendNotification();
1096 application.Render();
1098 // Executes the idle callbacks added by the text control on the change of input style.
1099 application.RunIdles();
1101 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1102 DALI_TEST_CHECK( !inputStyleChangedSignal );
1104 // Create a tap event to touch the text editor.
1105 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1106 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1108 // Render and notify
1109 application.SendNotification();
1110 application.Render();
1112 // Executes the idle callbacks added by the text control on the change of input style.
1113 application.RunIdles();
1115 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1116 if( gInputStyleChangedCallbackCalled )
1118 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1119 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1120 TextEditor::InputStyle::POINT_SIZE |
1121 TextEditor::InputStyle::FONT_STYLE |
1122 TextEditor::InputStyle::LINE_SPACING |
1123 TextEditor::InputStyle::UNDERLINE |
1124 TextEditor::InputStyle::SHADOW |
1125 TextEditor::InputStyle::EMBOSS |
1126 TextEditor::InputStyle::OUTLINE ),
1129 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1130 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1132 DALI_TEST_CHECK( inputStyleChangedSignal );
1134 gInputStyleChangedCallbackCalled = false;
1135 gInputStyleMask = TextEditor::InputStyle::NONE;
1136 inputStyleChangedSignal = false;
1138 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1140 fontStyleMapSet.Clear();
1141 fontStyleMapSet.Insert( "weight", "black" );
1142 fontStyleMapSet.Insert( "width", "expanded" );
1143 fontStyleMapSet.Insert( "slant", "oblique" );
1145 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1147 // Create a tap event to touch the text editor.
1148 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1149 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1151 // Render and notify
1152 application.SendNotification();
1153 application.Render();
1155 // Executes the idle callbacks added by the text control on the change of input style.
1156 application.RunIdles();
1158 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1159 if( gInputStyleChangedCallbackCalled )
1161 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1162 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1163 TextEditor::InputStyle::POINT_SIZE |
1164 TextEditor::InputStyle::FONT_STYLE ),
1167 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1168 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1170 DALI_TEST_CHECK( inputStyleChangedSignal );
1175 int utcDaliTextEditorEvent01(void)
1177 ToolkitTestApplication application;
1178 tet_infoline(" utcDaliTextEditorEvent01");
1180 // Creates a tap event. After creating a tap event the text editor should
1181 // have the focus and add text with key events should be possible.
1183 TextEditor editor = TextEditor::New();
1184 DALI_TEST_CHECK( editor );
1186 Stage::GetCurrent().Add( editor );
1188 editor.SetSize( 300.f, 50.f );
1189 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1190 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1192 // Avoid a crash when core load gl resources.
1193 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1195 // Render and notify
1196 application.SendNotification();
1197 application.Render();
1199 // Add a key event but as the text editor has not the focus it should do nothing.
1200 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1202 // Render and notify
1203 application.SendNotification();
1204 application.Render();
1206 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1208 // Create a tap event to touch the text editor.
1209 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1210 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1212 // Render and notify
1213 application.SendNotification();
1214 application.Render();
1216 // Now the text editor has the focus, so it can handle the key events.
1217 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1218 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1220 // Render and notify
1221 application.SendNotification();
1222 application.Render();
1224 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1226 // Create a second text editor and send key events to it.
1227 TextEditor editor2 = TextEditor::New();
1229 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1230 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1231 editor2.SetSize( 100.f, 100.f );
1232 editor2.SetPosition( 100.f, 100.f );
1234 Stage::GetCurrent().Add( editor2 );
1236 // Render and notify
1237 application.SendNotification();
1238 application.Render();
1240 // Create a tap event on the second text editor.
1241 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1242 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1244 // Render and notify
1245 application.SendNotification();
1246 application.Render();
1248 // The second text editor has the focus. It should handle the key events.
1249 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1250 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1252 // Render and notify
1253 application.SendNotification();
1254 application.Render();
1256 // Check the text has been added to the second text editor.
1257 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1262 int utcDaliTextEditorEvent02(void)
1264 ToolkitTestApplication application;
1265 tet_infoline(" utcDaliTextEditorEvent02");
1267 // Checks if the right number of actors are created.
1269 TextEditor editor = TextEditor::New();
1270 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1271 DALI_TEST_CHECK( editor );
1273 Stage::GetCurrent().Add( editor );
1275 editor.SetSize( 300.f, 50.f );
1276 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1277 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1279 // Avoid a crash when core load gl resources.
1280 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1282 // Render and notify
1283 application.SendNotification();
1284 application.Render();
1286 // Check there are the expected number of children (the stencil).
1287 DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1289 Actor stencil = editor.GetChildAt( 0u );
1291 // Create a tap event to touch the text editor.
1292 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1293 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1295 // Render and notify
1296 application.SendNotification();
1297 application.Render();
1299 Actor layer = editor.GetChildAt( 1u );
1300 DALI_TEST_CHECK( layer.IsLayer() );
1302 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1303 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1305 // Now the text editor has the focus, so it can handle the key events.
1306 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1307 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1309 // Render and notify
1310 application.SendNotification();
1311 application.Render();
1313 // Checks the cursor and the renderer have been created.
1314 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1315 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1317 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1318 DALI_TEST_CHECK( cursor );
1320 // The stencil actor has a container with all the actors which contain the text renderers.
1321 Actor container = stencil.GetChildAt( 0u );
1322 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1324 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1325 DALI_TEST_CHECK( renderer );
1328 // Move the cursor and check the position changes.
1329 Vector3 position1 = cursor.GetCurrentPosition();
1331 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1332 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1334 // Render and notify
1335 application.SendNotification();
1336 application.Render();
1338 Vector3 position2 = cursor.GetCurrentPosition();
1340 DALI_TEST_CHECK( position2.x < position1.x );
1342 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1343 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1345 // Render and notify
1346 application.SendNotification();
1347 application.Render();
1349 Vector3 position3 = cursor.GetCurrentPosition();
1351 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1353 // Send some taps and check the cursor positions.
1355 // Try to tap at the beginning.
1356 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1357 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1359 // Render and notify
1360 application.SendNotification();
1361 application.Render();
1363 // Cursor position should be the same than position1.
1364 Vector3 position4 = cursor.GetCurrentPosition();
1366 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1368 // Tap away from the start position.
1369 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1370 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1372 // Render and notify
1373 application.SendNotification();
1374 application.Render();
1376 Vector3 position5 = cursor.GetCurrentPosition();
1378 DALI_TEST_CHECK( position5.x > position4.x );
1380 // Remove all the text.
1381 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1382 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1383 editor.SetProperty( TextEditor::Property::TEXT, "" );
1385 // Render and notify
1386 application.SendNotification();
1387 application.Render();
1389 // Cursor position should be the same than position2.
1390 Vector3 position6 = cursor.GetCurrentPosition();
1392 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1394 // Should not be a renderer.
1395 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1400 int utcDaliTextEditorEvent03(void)
1402 ToolkitTestApplication application;
1403 tet_infoline(" utcDaliTextEditorEvent03");
1405 // Checks if the highlight actor is created.
1407 TextEditor editor = TextEditor::New();
1408 DALI_TEST_CHECK( editor );
1410 Stage::GetCurrent().Add( editor );
1412 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1413 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1414 editor.SetSize( 30.f, 50.f );
1415 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1416 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1418 // Avoid a crash when core load gl resources.
1419 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1421 // Render and notify
1422 application.SendNotification();
1423 application.Render();
1425 // Send some taps and check text controller with clipboard window
1426 Dali::Clipboard clipboard = Clipboard::Get();
1427 clipboard.ShowClipboard();
1428 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1429 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1430 clipboard.HideClipboard();
1432 // Render and notify
1433 application.SendNotification();
1434 application.Render();
1436 // Tap first to get the focus.
1437 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1438 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1440 // Render and notify
1441 application.SendNotification();
1442 application.Render();
1444 // Double tap to select a word.
1445 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1446 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1448 // Render and notify
1449 application.SendNotification();
1450 application.Render();
1452 // The stencil actor should have two actors: the renderer and the highlight actor.
1453 Actor stencil = editor.GetChildAt( 0u );
1455 // The stencil actor has a container with all the actors which contain the text renderers.
1456 Actor container = stencil.GetChildAt( 0u );
1457 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1459 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1460 DALI_TEST_CHECK( renderer );
1463 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1464 DALI_TEST_CHECK( highlight );
1469 int utcDaliTextEditorEvent04(void)
1471 ToolkitTestApplication application;
1472 tet_infoline(" utcDaliTextEditorEvent04");
1474 // Checks if the highlight actor is created.
1476 TextEditor editor = TextEditor::New();
1477 DALI_TEST_CHECK( editor );
1479 Stage::GetCurrent().Add( editor );
1481 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1482 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1483 editor.SetSize( 100.f, 50.f );
1484 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1485 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1487 // Avoid a crash when core load gl resources.
1488 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1490 // Render and notify
1491 application.SendNotification();
1492 application.Render();
1494 // Tap on the text editor
1495 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1496 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1498 // Render and notify
1499 application.SendNotification();
1500 application.Render();
1502 // Move at the end of the text.
1503 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1504 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1506 // Render and notify
1507 application.SendNotification();
1508 application.Render();
1510 for( unsigned int index = 0u; index < 10u; ++index )
1512 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1513 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1515 // Render and notify
1516 application.SendNotification();
1517 application.Render();
1521 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
1523 // Render and notify
1524 application.SendNotification();
1525 application.Render();
1527 DALI_TEST_EQUALS( "Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1529 // Add some key events
1530 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1531 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1533 // Render and notify
1534 application.SendNotification();
1535 application.Render();
1537 for( unsigned int index = 0u; index < 10u; ++index )
1539 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1540 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1542 // Render and notify
1543 application.SendNotification();
1544 application.Render();
1548 application.ProcessEvent( GenerateKey( " ", " ", KEY_WHITE_SPACE_CODE, 0, 0, Integration::KeyEvent::Down ) );
1550 // Render and notify
1551 application.SendNotification();
1552 application.Render();
1554 DALI_TEST_EQUALS( " Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1559 int utcDaliTextEditorEvent05(void)
1561 ToolkitTestApplication application;
1562 tet_infoline(" utcDaliTextEditorEvent05");
1564 // Checks if the highlight actor is created.
1566 TextEditor editor = TextEditor::New();
1567 DALI_TEST_CHECK( editor );
1569 Stage::GetCurrent().Add( editor );
1571 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1572 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1573 editor.SetSize( 50.f, 50.f );
1574 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1575 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1576 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1577 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
1578 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
1579 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
1580 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
1582 // Avoid a crash when core load gl resources.
1583 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1585 // Render and notify
1586 application.SendNotification();
1587 application.Render();
1589 // Tap on the text editor
1590 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1591 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1593 // Render and notify
1594 application.SendNotification();
1595 application.Render();
1597 // Move at the end of the text.
1598 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1599 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1601 // Render and notify
1602 application.SendNotification();
1603 application.Render();
1605 for( unsigned int index = 0u; index < 10u; ++index )
1608 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
1610 // Render and notify
1611 application.SendNotification();
1612 application.Render();
1614 // Modify duration after scroll is enabled
1615 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.1f );
1617 // Continuous scroll left to increase coverage
1618 for( unsigned int index = 0u; index < 10u; ++index )
1620 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1622 // Render and notify
1623 application.SendNotification();
1624 application.Render();
1626 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1627 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
1628 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
1629 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1630 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1632 // Press Escape to increase coverage
1633 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up ) );
1634 application.SendNotification();
1635 application.Render();
1637 DALI_TEST_CHECK( !editor.HasKeyInputFocus() );