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/integration-api/events/key-event-integ.h>
24 #include <dali/integration-api/events/tap-gesture-event.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/pan-gesture-event.h>
27 #include <dali/integration-api/events/long-press-gesture-event.h>
28 #include <dali-toolkit-test-suite-utils.h>
29 #include <dali-toolkit/dali-toolkit.h>
30 #include "toolkit-clipboard.h"
33 using namespace Toolkit;
35 void dali_textfield_startup(void)
37 test_return_value = TET_UNDEF;
40 void dali_textfield_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_PLACEHOLDER_TEXT = "placeholderText";
51 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED = "placeholderTextFocused";
52 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
53 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
54 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
55 const char* const PROPERTY_NAME_MAX_LENGTH = "maxLength";
56 const char* const PROPERTY_NAME_EXCEED_POLICY = "exceedPolicy";
57 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
58 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT = "verticalAlignment";
59 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
60 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR = "placeholderTextColor";
61 const char* const PROPERTY_NAME_SHADOW_OFFSET = "shadowOffset";
62 const char* const PROPERTY_NAME_SHADOW_COLOR = "shadowColor";
63 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
64 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
65 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
66 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
67 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
68 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
69 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
70 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
71 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
72 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
73 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
74 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
75 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
76 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
77 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
78 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
79 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
80 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
81 const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS = "inputMethodSettings";
82 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
83 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
84 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
85 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
86 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
88 const char* const PROPERTY_NAME_UNDERLINE = "underline";
89 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
90 const char* const PROPERTY_NAME_SHADOW = "shadow";
91 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
92 const char* const PROPERTY_NAME_EMBOSS = "emboss";
93 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
94 const char* const PROPERTY_NAME_OUTLINE = "outline";
95 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
97 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
99 const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
100 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
102 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
103 const float RENDER_FRAME_INTERVAL = 16.66f;
105 const float TO_MILLISECONDS = 1000.f;
106 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
108 const float SCROLL_THRESHOLD = 10.f;
109 const float SCROLL_SPEED = 300.f;
111 const unsigned int DEFAULT_FONT_SIZE = 1152u;
112 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
114 static bool gTextChangedCallBackCalled;
115 static bool gMaxCharactersCallBackCalled;
116 static bool gInputStyleChangedCallbackCalled;
117 static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask;
119 static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
121 Integration::ResourceRequest* request = platform.GetRequest();
122 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
123 Integration::ResourcePointer resource(bitmap);
124 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
128 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
132 static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField)
136 LoadBitmapResource( app.GetPlatform(), width, height );
138 Property::Map propertyMap;
139 propertyMap["filename"] = "image.png";
140 propertyMap["width"] = width;
141 propertyMap["height"] = height;
142 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, propertyMap );
143 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, propertyMap );
144 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, propertyMap );
145 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, propertyMap );
146 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, propertyMap );
147 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, propertyMap );
148 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_IMAGE, propertyMap );
149 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, propertyMap );
152 // Generate a PanGestureEvent to send to Core
153 static Integration::PanGestureEvent GeneratePan(
154 Gesture::State state,
155 const Vector2& previousPosition,
156 const Vector2& currentPosition,
157 unsigned long timeDelta,
158 unsigned int numberOfTouches = 1)
160 Integration::PanGestureEvent pan(state);
162 pan.previousPosition = previousPosition;
163 pan.currentPosition = currentPosition;
164 pan.timeDelta = timeDelta;
165 pan.numberOfTouches = numberOfTouches;
171 * Helper to generate PanGestureEvent
173 * @param[in] application Application instance
174 * @param[in] state The Gesture State
175 * @param[in] pos The current position of touch.
177 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
181 if( (state == Gesture::Started) ||
182 (state == Gesture::Possible) )
188 application.ProcessEvent(GeneratePan(state, last, pos, 16));
195 * Simulate time passed by.
197 * @note this will always process at least 1 frame (1/60 sec)
199 * @param application Test application instance
200 * @param duration Time to pass in milliseconds.
201 * @return The actual time passed in milliseconds
203 static int Wait(ToolkitTestApplication& application, int duration = 0)
207 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
209 application.SendNotification();
210 application.Render(RENDER_FRAME_INTERVAL);
211 time += RENDER_FRAME_INTERVAL;
217 Dali::Integration::Point GetPointDownInside( Vector2& pos )
219 Dali::Integration::Point point;
220 point.SetState( PointState::DOWN );
221 point.SetScreenPosition( pos );
225 Dali::Integration::Point GetPointUpInside( Vector2& pos )
227 Dali::Integration::Point point;
228 point.SetState( PointState::UP );
229 point.SetScreenPosition( pos );
233 struct CallbackFunctor
235 CallbackFunctor(bool* callbackFlag)
236 : mCallbackFlag( callbackFlag )
242 *mCallbackFlag = true;
247 static void TestTextChangedCallback( TextField control )
249 tet_infoline(" TestTextChangedCallback");
251 gTextChangedCallBackCalled = true;
254 static void TestMaxLengthReachedCallback( TextField control )
256 tet_infoline(" TestMaxLengthReachedCallback");
258 gMaxCharactersCallBackCalled = true;
261 static void TestInputStyleChangedCallback( TextField control, TextField::InputStyle::Mask mask )
263 tet_infoline(" TestInputStyleChangedCallback");
265 gInputStyleChangedCallbackCalled = true;
266 gInputStyleMask = mask;
269 // Generate a TapGestureEvent to send to Core.
270 Integration::TapGestureEvent GenerateTap(
271 Gesture::State state,
272 unsigned int numberOfTaps,
273 unsigned int numberOfTouches,
276 Integration::TapGestureEvent tap( state );
278 tap.numberOfTaps = numberOfTaps;
279 tap.numberOfTouches = numberOfTouches;
286 Integration::LongPressGestureEvent GenerateLongPress(
287 Gesture::State state,
288 unsigned int numberOfTouches,
291 Integration::LongPressGestureEvent longPress( state );
293 longPress.numberOfTouches = numberOfTouches;
294 longPress.point = point;
298 // Generate a KeyEvent to send to Core.
299 Integration::KeyEvent GenerateKey( const std::string& keyName,
300 const std::string& keyString,
303 unsigned long timeStamp,
304 const Integration::KeyEvent::State& keyState )
306 return Integration::KeyEvent( keyName,
316 int UtcDaliToolkitTextFieldConstructorP(void)
318 ToolkitTestApplication application;
319 tet_infoline(" UtcDaliToolkitTextFieldConstructorP");
321 DALI_TEST_CHECK( !textField );
325 int UtcDaliToolkitTextFieldNewP(void)
327 ToolkitTestApplication application;
328 tet_infoline(" UtcDaliToolkitTextFieldNewP");
329 TextField textField = TextField::New();
330 DALI_TEST_CHECK( textField );
334 int UtcDaliToolkitTextFieldDownCastP(void)
336 ToolkitTestApplication application;
337 tet_infoline(" UtcDaliToolkitTextFieldDownCastP");
338 TextField textField1 = TextField::New();
339 BaseHandle object( textField1 );
341 TextField textField2 = TextField::DownCast( object );
342 DALI_TEST_CHECK( textField2 );
344 TextField textField3 = DownCast< TextField >( object );
345 DALI_TEST_CHECK( textField3 );
349 int UtcDaliToolkitTextFieldDownCastN(void)
351 ToolkitTestApplication application;
352 tet_infoline(" UtcDaliToolkitTextFieldDownCastN");
353 BaseHandle uninitializedObject;
354 TextField textField1 = TextField::DownCast( uninitializedObject );
355 DALI_TEST_CHECK( !textField1 );
357 TextField textField2 = DownCast< TextField >( uninitializedObject );
358 DALI_TEST_CHECK( !textField2 );
362 int UtcDaliToolkitTextFieldCopyConstructorP(void)
364 ToolkitTestApplication application;
365 tet_infoline(" UtcDaliToolkitTextFieldCopyConstructorP");
366 TextField textField = TextField::New();
367 textField.SetProperty( TextField::Property::TEXT, "Test" );
369 TextField copy( textField );
370 DALI_TEST_CHECK( copy );
371 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textField.GetProperty<std::string>( TextLabel::Property::TEXT ) );
375 int UtcDaliToolkitTextFieldAssignmentOperatorP(void)
377 ToolkitTestApplication application;
378 tet_infoline(" UtcDaliToolkitTextFieldAssignmentOperatorP");
379 TextField textField = TextField::New();
380 textField.SetProperty( TextField::Property::TEXT, "Test" );
382 TextField copy = textField;
383 DALI_TEST_CHECK( copy );
384 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextField::Property::TEXT ) == textField.GetProperty<std::string>( TextField::Property::TEXT ) );
388 int UtcDaliTextFieldNewP(void)
390 ToolkitTestApplication application;
391 tet_infoline(" UtcDaliToolkitTextFieldNewP");
392 TextField textField = TextField::New();
393 DALI_TEST_CHECK( textField );
397 // Positive test case for a method
398 int UtcDaliTextFieldGetPropertyP(void)
400 ToolkitTestApplication application;
401 tet_infoline(" UtcDaliToolkitTextFieldGetPropertyP");
402 TextField field = TextField::New();
403 DALI_TEST_CHECK( field );
405 // Check Property Indices are correct
406 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextField::Property::RENDERING_BACKEND );
407 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextField::Property::TEXT );
408 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == TextField::Property::PLACEHOLDER_TEXT );
409 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED ) == TextField::Property::PLACEHOLDER_TEXT_FOCUSED );
410 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextField::Property::FONT_FAMILY );
411 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextField::Property::FONT_STYLE );
412 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextField::Property::POINT_SIZE );
413 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == TextField::Property::MAX_LENGTH );
414 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EXCEED_POLICY ) == TextField::Property::EXCEED_POLICY );
415 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextField::Property::HORIZONTAL_ALIGNMENT );
416 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextField::Property::VERTICAL_ALIGNMENT );
417 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextField::Property::TEXT_COLOR );
418 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == TextField::Property::PLACEHOLDER_TEXT_COLOR );
419 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_OFFSET ) == TextField::Property::SHADOW_OFFSET );
420 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_COLOR ) == TextField::Property::SHADOW_COLOR );
421 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextField::Property::PRIMARY_CURSOR_COLOR );
422 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextField::Property::SECONDARY_CURSOR_COLOR );
423 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextField::Property::ENABLE_CURSOR_BLINK );
424 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextField::Property::CURSOR_BLINK_INTERVAL );
425 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextField::Property::CURSOR_BLINK_DURATION );
426 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextField::Property::CURSOR_WIDTH );
427 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextField::Property::GRAB_HANDLE_IMAGE );
428 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextField::Property::GRAB_HANDLE_PRESSED_IMAGE );
429 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextField::Property::SCROLL_THRESHOLD );
430 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextField::Property::SCROLL_SPEED );
431 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_IMAGE_LEFT );
432 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT );
433 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
434 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
435 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
436 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
437 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextField::Property::SELECTION_HIGHLIGHT_COLOR );
438 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextField::Property::DECORATION_BOUNDING_BOX );
439 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == TextField::Property::INPUT_METHOD_SETTINGS );
440 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextField::Property::INPUT_COLOR );
441 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextField::Property::ENABLE_MARKUP );
442 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextField::Property::INPUT_FONT_FAMILY );
443 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextField::Property::INPUT_FONT_STYLE );
444 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextField::Property::INPUT_POINT_SIZE );
445 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextField::Property::UNDERLINE );
446 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextField::Property::INPUT_UNDERLINE );
447 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextField::Property::SHADOW );
448 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextField::Property::INPUT_SHADOW );
449 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextField::Property::EMBOSS );
450 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextField::Property::INPUT_EMBOSS );
451 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextField::Property::OUTLINE );
452 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextField::Property::INPUT_OUTLINE );
457 bool SetPropertyMapRetrieved( TextField& field, const Property::Index property, const std::string mapKey, const std::string mapValue )
460 Property::Map imageMap;
461 imageMap[mapKey] =mapValue;
463 field.SetProperty( property , imageMap );
464 Property::Value propValue = field.GetProperty( property );
465 Property::Map* resultMap = propValue.GetMap();
467 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
475 // Positive test case for a method
476 int UtcDaliTextFieldSetPropertyP(void)
478 ToolkitTestApplication application;
479 tet_infoline(" UtcDaliToolkitTextFieldSetPropertyP");
480 TextField field = TextField::New();
481 DALI_TEST_CHECK( field );
482 Stage::GetCurrent().Add( field );
484 // Note - we can't check the defaults since the stylesheets are platform-specific
486 // Check the render backend property.
487 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
488 DALI_TEST_EQUALS( (Text::RenderingType)field.GetProperty<int>( TextField::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
490 // Check text property.
491 field.SetProperty( TextField::Property::TEXT, "Setting Text" );
492 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
494 // Check placeholder text properties.
495 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
496 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION );
498 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Setting Placeholder Text Focused" );
499 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT_FOCUSED ), std::string("Setting Placeholder Text Focused"), TEST_LOCATION );
501 // Check font properties.
502 field.SetProperty( TextField::Property::FONT_FAMILY, "Setting font family" );
503 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
504 field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
505 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION );
506 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
507 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
510 field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
511 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
512 field.SetProperty( TextField::Property::FONT_STYLE, "{\"slant\":\"roman\"}" );
513 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
514 field.SetProperty( TextField::Property::FONT_STYLE, "" );
515 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string(""), TEST_LOCATION );
517 // Check that the MAX_LENGTH property can be correctly set
518 const int maxNumberOfCharacters = 20;
519 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
520 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
522 // Check exceed policy
523 // Set a different exceed policy is not implemented.
525 // Check that the Alignment properties can be correctly set
526 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
527 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
528 field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
529 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
531 // Check text's color property
532 field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
533 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
535 // Check placeholder text's color property.
536 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
537 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
539 // Check shadow properties.
540 field.SetProperty( TextField::Property::SHADOW_OFFSET, Vector2( 1.f, 1.f ) );
541 DALI_TEST_EQUALS( field.GetProperty<Vector2>( TextField::Property::SHADOW_OFFSET ), Vector2( 1.f, 1.f ), TEST_LOCATION );
542 field.SetProperty( TextField::Property::SHADOW_COLOR, Color::GREEN );
543 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SHADOW_COLOR ), Color::GREEN, TEST_LOCATION );
545 // Check cursor properties
546 field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
547 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
548 field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
549 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
551 field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
552 DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
553 field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
554 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
555 field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
556 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
557 field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
558 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
560 // Check scroll properties.
561 field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
562 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
563 field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
564 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
566 // Check handle images
567 field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
568 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
569 field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
570 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
571 field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
573 // Check handle images
574 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
575 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
576 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
577 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
578 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
579 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
581 // Check the highlight color
582 field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
583 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
585 // Decoration bounding box
586 field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
587 DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
589 // Check input color property.
590 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
591 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
593 // Check the enable markup property.
594 DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
595 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
596 DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
598 // Check input font properties.
599 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
600 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
601 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
602 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION );
603 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
604 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
606 // Reset input font style.
607 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
608 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
609 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" );
610 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
611 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "" );
612 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION );
614 // Check the underline property
615 field.SetProperty( TextField::Property::UNDERLINE, "{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}" );
616 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::UNDERLINE ), std::string("{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}"), TEST_LOCATION );
618 // Check the input underline property
619 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
620 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
622 // Check the shadow property
623 field.SetProperty( TextField::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" );
624 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::SHADOW ), std::string("{\"color\":\"green\",\"offset\":\"2 2\"}"), TEST_LOCATION );
626 // Check the input shadow property
627 field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
628 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
630 // Check the emboss property
631 field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
632 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
634 // Check the input emboss property
635 field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
636 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
638 // Check the outline property
639 field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
640 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
642 // Check the input outline property
643 field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
644 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
649 // Positive Atlas Text Renderer test
650 int utcDaliTextFieldAtlasRenderP(void)
652 ToolkitTestApplication application;
653 tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
654 StyleManager styleManager = StyleManager::Get();
655 styleManager.ApplyDefaultTheme();
656 TextField field = TextField::New();
657 DALI_TEST_CHECK( field );
659 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
661 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
663 Stage::GetCurrent().Add( field );
667 // Render some text with the shared atlas backend
668 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
669 application.SendNotification();
670 application.Render();
674 tet_result(TET_FAIL);
679 // Positive test for the textChanged signal.
680 int utcDaliTextFieldTextChangedP(void)
682 ToolkitTestApplication application;
683 tet_infoline(" utcDaliTextFieldTextChangedP");
684 TextField field = TextField::New();
685 DALI_TEST_CHECK( field );
687 Stage::GetCurrent().Add( field );
689 // connect to the text changed signal.
690 ConnectionTracker* testTracker = new ConnectionTracker();
691 field.TextChangedSignal().Connect(&TestTextChangedCallback);
692 bool textChangedSignal = false;
693 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
695 gTextChangedCallBackCalled = false;
696 field.SetProperty( TextField::Property::TEXT, "ABC" );
697 DALI_TEST_CHECK( gTextChangedCallBackCalled );
698 DALI_TEST_CHECK( textChangedSignal );
700 application.SendNotification();
702 field.SetKeyInputFocus();
704 gTextChangedCallBackCalled = false;
705 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
706 DALI_TEST_CHECK( gTextChangedCallBackCalled );
711 // Negative test for the textChanged signal.
712 int utcDaliTextFieldTextChangedN(void)
714 ToolkitTestApplication application;
715 tet_infoline(" utcDaliTextFieldTextChangedN");
716 TextField field = TextField::New();
717 DALI_TEST_CHECK( field );
719 Stage::GetCurrent().Add( field );
721 // connect to the text changed signal.
722 ConnectionTracker* testTracker = new ConnectionTracker();
723 field.TextChangedSignal().Connect(&TestTextChangedCallback);
724 bool textChangedSignal = false;
725 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
727 gTextChangedCallBackCalled = false;
728 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
729 DALI_TEST_CHECK( !gTextChangedCallBackCalled );
730 DALI_TEST_CHECK( !textChangedSignal );
735 // Positive test for Max Characters reached signal.
736 int utcDaliTextFieldMaxCharactersReachedP(void)
738 ToolkitTestApplication application;
739 tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
740 TextField field = TextField::New();
741 DALI_TEST_CHECK( field );
743 Stage::GetCurrent().Add( field );
745 const int maxNumberOfCharacters = 1;
746 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
748 field.SetKeyInputFocus();
750 // connect to the text changed signal.
751 ConnectionTracker* testTracker = new ConnectionTracker();
752 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
753 bool maxLengthReachedSignal = false;
754 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
756 gMaxCharactersCallBackCalled = false;
758 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
759 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
761 DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
762 DALI_TEST_CHECK( maxLengthReachedSignal );
767 // Negative test for Max Characters reached signal.
768 int utcDaliTextFieldMaxCharactersReachedN(void)
770 ToolkitTestApplication application;
771 tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
772 TextField field = TextField::New();
773 DALI_TEST_CHECK( field );
775 Stage::GetCurrent().Add( field );
777 const int maxNumberOfCharacters = 3;
778 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
780 field.SetKeyInputFocus();
782 // connect to the text changed signal.
783 ConnectionTracker* testTracker = new ConnectionTracker();
784 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
785 bool maxLengthReachedSignal = false;
786 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
788 gMaxCharactersCallBackCalled = false;
790 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
791 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
793 DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
794 DALI_TEST_CHECK( !maxLengthReachedSignal );
799 int utcDaliTextFieldInputStyleChanged01(void)
801 ToolkitTestApplication application;
802 tet_infoline(" utcDaliTextFieldInputStyleChanged01");
804 // The text-field emits signals when the input style changes. These changes of style are
805 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
806 // can't be emitted during the size negotiation as the callbacks may update the UI.
807 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
808 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
809 application.CreateAdaptor();
813 char* pathNamePtr = get_current_dir_name();
814 const std::string pathName( pathNamePtr );
817 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
818 fontClient.SetDpi( 93u, 93u );
820 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
821 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
823 TextField field = TextField::New();
824 DALI_TEST_CHECK( field );
827 field.SetSize( 300.f, 50.f );
828 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
829 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
831 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
832 field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
834 // connect to the text changed signal.
835 ConnectionTracker* testTracker = new ConnectionTracker();
836 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
837 bool inputStyleChangedSignal = false;
838 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
840 Stage::GetCurrent().Add( field );
843 application.SendNotification();
844 application.Render();
846 // Executes the idle callbacks added by the text control on the change of input style.
847 application.RunIdles();
849 gInputStyleChangedCallbackCalled = false;
850 gInputStyleMask = TextField::InputStyle::NONE;
851 inputStyleChangedSignal = false;
853 // Create a tap event to touch the text field.
854 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
855 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
858 application.SendNotification();
859 application.Render();
861 // Executes the idle callbacks added by the text control on the change of input style.
862 application.RunIdles();
864 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
865 if( gInputStyleChangedCallbackCalled )
867 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
869 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
870 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
872 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
873 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
875 DALI_TEST_CHECK( inputStyleChangedSignal );
877 gInputStyleChangedCallbackCalled = false;
878 gInputStyleMask = TextField::InputStyle::NONE;
879 inputStyleChangedSignal = false;
881 // Create a tap event to touch the text field.
882 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
883 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
886 application.SendNotification();
887 application.Render();
889 // Executes the idle callbacks added by the text control on the change of input style.
890 application.RunIdles();
892 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
893 DALI_TEST_CHECK( !inputStyleChangedSignal );
895 gInputStyleChangedCallbackCalled = false;
896 gInputStyleMask = TextField::InputStyle::NONE;
897 inputStyleChangedSignal = false;
899 // Create a tap event to touch the text field.
900 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
901 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
904 application.SendNotification();
905 application.Render();
907 // Executes the idle callbacks added by the text control on the change of input style.
908 application.RunIdles();
910 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
911 if( gInputStyleChangedCallbackCalled )
913 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
915 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
916 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
918 DALI_TEST_CHECK( inputStyleChangedSignal );
920 gInputStyleChangedCallbackCalled = false;
921 gInputStyleMask = TextField::InputStyle::NONE;
922 inputStyleChangedSignal = false;
924 // Create a tap event to touch the text field.
925 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
926 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
929 application.SendNotification();
930 application.Render();
932 // Executes the idle callbacks added by the text control on the change of input style.
933 application.RunIdles();
935 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
936 if( gInputStyleChangedCallbackCalled )
938 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
940 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
941 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
943 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
944 DALI_TEST_EQUALS( style, "{\"weight\":\"bold\"}", TEST_LOCATION );
946 DALI_TEST_CHECK( inputStyleChangedSignal );
948 gInputStyleChangedCallbackCalled = false;
949 gInputStyleMask = TextField::InputStyle::NONE;
950 inputStyleChangedSignal = false;
952 // Create a tap event to touch the text field.
953 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
954 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
957 application.SendNotification();
958 application.Render();
960 // Executes the idle callbacks added by the text control on the change of input style.
961 application.RunIdles();
963 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
964 DALI_TEST_CHECK( !inputStyleChangedSignal );
966 gInputStyleChangedCallbackCalled = false;
967 gInputStyleMask = TextField::InputStyle::NONE;
968 inputStyleChangedSignal = false;
970 // Create a tap event to touch the text field.
971 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
972 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
975 application.SendNotification();
976 application.Render();
978 // Executes the idle callbacks added by the text control on the change of input style.
979 application.RunIdles();
981 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
982 if( gInputStyleChangedCallbackCalled )
984 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
986 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
987 DALI_TEST_CHECK( style.empty() );
989 DALI_TEST_CHECK( inputStyleChangedSignal );
991 gInputStyleChangedCallbackCalled = false;
992 gInputStyleMask = TextField::InputStyle::NONE;
993 inputStyleChangedSignal = false;
995 // Create a tap event to touch the text field.
996 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
997 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1000 application.SendNotification();
1001 application.Render();
1003 // Executes the idle callbacks added by the text control on the change of input style.
1004 application.RunIdles();
1006 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1007 DALI_TEST_CHECK( !inputStyleChangedSignal );
1012 int utcDaliTextFieldInputStyleChanged02(void)
1014 ToolkitTestApplication application;
1015 tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1017 // The text-field emits signals when the input style changes. These changes of style are
1018 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1019 // can't be emitted during the size negotiation as the callbacks may update the UI.
1020 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1021 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1022 application.CreateAdaptor();
1026 char* pathNamePtr = get_current_dir_name();
1027 const std::string pathName( pathNamePtr );
1028 free( pathNamePtr );
1030 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1031 fontClient.SetDpi( 93u, 93u );
1033 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1034 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1036 TextField field = TextField::New();
1037 DALI_TEST_CHECK( field );
1040 field.SetSize( 300.f, 50.f );
1041 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1042 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1044 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1045 field.SetProperty( TextField::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>" );
1047 // connect to the text changed signal.
1048 ConnectionTracker* testTracker = new ConnectionTracker();
1049 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1050 bool inputStyleChangedSignal = false;
1051 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1053 Stage::GetCurrent().Add( field );
1055 // Render and notify
1056 application.SendNotification();
1057 application.Render();
1059 // Executes the idle callbacks added by the text control on the change of input style.
1060 application.RunIdles();
1062 gInputStyleChangedCallbackCalled = false;
1063 gInputStyleMask = TextField::InputStyle::NONE;
1064 inputStyleChangedSignal = false;
1066 // Create a tap event to touch the text field.
1067 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1068 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1069 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1070 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1072 // Render and notify
1073 application.SendNotification();
1074 application.Render();
1076 // Executes the idle callbacks added by the text control on the change of input style.
1077 application.RunIdles();
1079 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1080 if( gInputStyleChangedCallbackCalled )
1082 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1083 static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1084 TextField::InputStyle::POINT_SIZE |
1085 TextField::InputStyle::COLOR ),
1088 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1089 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1091 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1092 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1094 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1095 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1097 DALI_TEST_CHECK( inputStyleChangedSignal );
1099 gInputStyleChangedCallbackCalled = false;
1100 gInputStyleMask = TextField::InputStyle::NONE;
1101 inputStyleChangedSignal = false;
1103 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1105 // Render and notify
1106 application.SendNotification();
1107 application.Render();
1109 // Executes the idle callbacks added by the text control on the change of input style.
1110 application.RunIdles();
1112 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1113 if( gInputStyleChangedCallbackCalled )
1115 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1116 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1119 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1120 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1122 DALI_TEST_CHECK( inputStyleChangedSignal );
1124 gInputStyleChangedCallbackCalled = false;
1125 gInputStyleMask = TextField::InputStyle::NONE;
1126 inputStyleChangedSignal = false;
1128 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1130 // Render and notify
1131 application.SendNotification();
1132 application.Render();
1134 // Executes the idle callbacks added by the text control on the change of input style.
1135 application.RunIdles();
1137 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1138 DALI_TEST_CHECK( !inputStyleChangedSignal );
1140 gInputStyleChangedCallbackCalled = false;
1141 gInputStyleMask = TextField::InputStyle::NONE;
1142 inputStyleChangedSignal = false;
1144 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1146 // Render and notify
1147 application.SendNotification();
1148 application.Render();
1150 // Executes the idle callbacks added by the text control on the change of input style.
1151 application.RunIdles();
1153 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1154 if( gInputStyleChangedCallbackCalled )
1156 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1157 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1160 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1161 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1163 DALI_TEST_CHECK( inputStyleChangedSignal );
1165 gInputStyleChangedCallbackCalled = false;
1166 gInputStyleMask = TextField::InputStyle::NONE;
1167 inputStyleChangedSignal = false;
1169 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1171 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"thin\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
1172 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1174 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1175 field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1176 field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1177 field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1179 // Render and notify
1180 application.SendNotification();
1181 application.Render();
1183 // Executes the idle callbacks added by the text control on the change of input style.
1184 application.RunIdles();
1186 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1187 DALI_TEST_CHECK( !inputStyleChangedSignal );
1189 // Create a tap event to touch the text field.
1190 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1191 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1193 // Render and notify
1194 application.SendNotification();
1195 application.Render();
1197 // Executes the idle callbacks added by the text control on the change of input style.
1198 application.RunIdles();
1200 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1201 if( gInputStyleChangedCallbackCalled )
1203 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1204 static_cast<unsigned int>( TextField::InputStyle::COLOR |
1205 TextField::InputStyle::POINT_SIZE |
1206 TextField::InputStyle::FONT_STYLE |
1207 TextField::InputStyle::UNDERLINE |
1208 TextField::InputStyle::SHADOW |
1209 TextField::InputStyle::EMBOSS |
1210 TextField::InputStyle::OUTLINE ),
1213 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1214 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1216 DALI_TEST_CHECK( inputStyleChangedSignal );
1221 int utcDaliTextFieldEvent01(void)
1223 ToolkitTestApplication application;
1224 tet_infoline(" utcDaliTextFieldEvent01");
1226 // Creates a tap event. After creating a tap event the text field should
1227 // have the focus and add text with key events should be possible.
1229 TextField field = TextField::New();
1230 DALI_TEST_CHECK( field );
1232 Stage::GetCurrent().Add( field );
1234 field.SetSize( 300.f, 50.f );
1235 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1236 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1238 // Avoid a crash when core load gl resources.
1239 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1241 // Render and notify
1242 application.SendNotification();
1243 application.Render();
1245 // Add a key event but as the text field has not the focus it should do nothing.
1246 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1248 // Render and notify
1249 application.SendNotification();
1250 application.Render();
1252 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1254 // Create a tap event to touch the text field.
1255 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1256 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1258 // Render and notify
1259 application.SendNotification();
1260 application.Render();
1262 // Now the text field has the focus, so it can handle the key events.
1263 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1264 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1266 // Render and notify
1267 application.SendNotification();
1268 application.Render();
1270 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1272 // Create a second text field and send key events to it.
1273 TextField field2 = TextField::New();
1275 field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1276 field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1277 field2.SetSize( 100.f, 100.f );
1278 field2.SetPosition( 100.f, 100.f );
1280 Stage::GetCurrent().Add( field2 );
1282 // Render and notify
1283 application.SendNotification();
1284 application.Render();
1286 // Create a tap event on the second text field.
1287 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1288 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1290 // Render and notify
1291 application.SendNotification();
1292 application.Render();
1294 // The second text field has the focus. It should handle the key events.
1295 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1296 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1298 // Render and notify
1299 application.SendNotification();
1300 application.Render();
1302 // Check the text has been added to the second text field.
1303 DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1308 int utcDaliTextFieldEvent02(void)
1310 ToolkitTestApplication application;
1311 tet_infoline(" utcDaliTextFieldEvent02");
1313 // Checks if the right number of actors are created.
1315 TextField field = TextField::New();
1316 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1317 DALI_TEST_CHECK( field );
1318 LoadMarkerImages(application, field);
1320 Stage::GetCurrent().Add( field );
1322 field.SetSize( 300.f, 50.f );
1323 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1324 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1326 // Avoid a crash when core load gl resources.
1327 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1329 // Render and notify
1330 application.SendNotification();
1331 application.Render();
1333 // Check there are the expected number of children ( offscreen root actor, and the offscreen image view
1334 DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION );
1336 Actor offscreenRoot = field.GetChildAt( 0u );
1337 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1338 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1340 Actor offscreenImage = field.GetChildAt( 1u );
1341 DALI_TEST_CHECK( offscreenImage );
1343 // Create a tap event to touch the text field.
1344 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1345 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1347 // Render and notify
1348 application.SendNotification();
1349 application.Render();
1351 Actor layer = field.GetChildAt( 2u );
1352 DALI_TEST_CHECK( layer.IsLayer() );
1354 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1355 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1357 // Now the text field has the focus, so it can handle the key events.
1358 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1359 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1361 // Render and notify
1362 application.SendNotification();
1363 application.Render();
1365 // Checks the cursor and the renderer have been created.
1366 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1367 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
1369 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1370 DALI_TEST_CHECK( cursor );
1372 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1373 DALI_TEST_CHECK( camera );
1375 // The offscreen root actor has a container with all the actors which contain the text renderers.
1376 Actor container = offscreenRoot.GetChildAt( 1u );
1377 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1379 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1380 DALI_TEST_CHECK( renderer );
1383 // Move the cursor and check the position changes.
1384 Vector3 position1 = cursor.GetCurrentPosition();
1386 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1387 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1389 // Render and notify
1390 application.SendNotification();
1391 application.Render();
1393 Vector3 position2 = cursor.GetCurrentPosition();
1395 DALI_TEST_CHECK( position2.x < position1.x );
1397 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1398 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1400 // Render and notify
1401 application.SendNotification();
1402 application.Render();
1404 Vector3 position3 = cursor.GetCurrentPosition();
1406 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1408 // Send some taps and check the cursor positions.
1410 // Try to tap at the beginning.
1411 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1412 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1414 // Render and notify
1415 application.SendNotification();
1416 application.Render();
1418 // Cursor position should be the same than position1.
1419 Vector3 position4 = cursor.GetCurrentPosition();
1421 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1423 // Tap away from the start position.
1424 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1425 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1427 // Render and notify
1428 application.SendNotification();
1429 application.Render();
1431 Vector3 position5 = cursor.GetCurrentPosition();
1433 DALI_TEST_CHECK( position5.x > position4.x );
1435 // Remove all the text.
1436 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1437 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1438 field.SetProperty( TextField::Property::TEXT, "" );
1440 // Render and notify
1441 application.SendNotification();
1442 application.Render();
1444 // Cursor position should be the same than position2.
1445 Vector3 position6 = cursor.GetCurrentPosition();
1447 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1449 // Should not be a renderer.
1450 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
1455 int utcDaliTextFieldEvent03(void)
1457 ToolkitTestApplication application;
1458 tet_infoline(" utcDaliTextFieldEvent03");
1460 // Checks if the highlight actor is created.
1462 TextField field = TextField::New();
1463 DALI_TEST_CHECK( field );
1465 Stage::GetCurrent().Add( field );
1467 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1468 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1469 field.SetSize( 30.f, 50.f );
1470 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1471 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1473 // Avoid a crash when core load gl resources.
1474 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1475 LoadMarkerImages(application, field);
1477 // Render and notify
1478 application.SendNotification();
1479 application.Render();
1481 // Tap first to get the focus.
1482 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1483 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1485 // Render and notify
1486 application.SendNotification();
1487 application.Render();
1489 // Double tap to select a word.
1490 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1491 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1493 // Render and notify
1494 application.SendNotification();
1495 application.Render();
1497 // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
1498 Actor offscreenRoot = field.GetChildAt( 1u );
1499 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1501 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1502 DALI_TEST_CHECK( camera );
1504 // The offscreen root actor has a container with all the actors which contain the text renderers.
1505 Actor container = offscreenRoot.GetChildAt( 1u );
1506 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1508 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1509 DALI_TEST_CHECK( renderer );
1512 Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
1513 DALI_TEST_CHECK( highlight );
1518 int utcDaliTextFieldEvent04(void)
1520 ToolkitTestApplication application;
1521 tet_infoline(" utcDaliTextFieldEvent04");
1523 // Checks if the highlight actor is created.
1525 TextField field = TextField::New();
1526 DALI_TEST_CHECK( field );
1527 Stage::GetCurrent().Add( field );
1528 LoadMarkerImages(application, field);
1529 // Render and notify
1530 application.SendNotification();
1531 application.Render();
1533 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1534 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1535 field.SetSize( 300.f, 50.f );
1536 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1537 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1539 // Avoid a crash when core load gl resources.
1540 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1541 // Render and notify
1542 application.SendNotification();
1543 application.Render();
1545 // Create a tap event to touch the text field.
1546 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1547 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1548 // Render and notify
1549 application.SendNotification();
1550 application.Render();
1553 // Tap first to get the focus.
1554 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1555 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1557 // Render and notify
1558 application.SendNotification();
1559 application.Render();
1561 // Double tap to select a word.
1562 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1563 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1565 // Render and notify
1566 application.SendNotification();
1567 application.Render();
1570 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1571 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1575 int utcDaliTextFieldEvent05(void)
1577 ToolkitTestApplication application;
1578 tet_infoline(" utcDaliTextFieldEvent05");
1580 // Checks dragging of cursor/grab handle
1582 TextField field = TextField::New();
1583 DALI_TEST_CHECK( field );
1584 Stage::GetCurrent().Add( field );
1585 LoadMarkerImages(application, field);
1586 // Render and notify
1587 application.SendNotification();
1588 application.Render();
1590 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1591 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1592 field.SetSize( 300.f, 50.f );
1593 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1594 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1596 // Avoid a crash when core load gl resources.
1597 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1598 // Render and notify
1599 application.SendNotification();
1600 application.Render();
1602 // Create a tap event to touch the text field.
1603 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1604 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1605 // Render and notify
1606 application.SendNotification();
1607 application.Render();
1610 // Tap first to get the focus.
1611 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1612 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1614 // Render and notify
1615 application.SendNotification();
1616 application.Render();
1618 // Double tap to select a word.
1619 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1620 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1622 // Render and notify
1623 application.SendNotification();
1624 application.Render();
1626 // drag grab handle right
1627 Vector2 pos(0.0f, 40.0f);
1628 SendPan(application, Gesture::Possible, pos);
1629 SendPan(application, Gesture::Started, pos);
1631 Wait(application, 100);
1633 for(int i = 0;i<20;i++)
1635 SendPan(application, Gesture::Continuing, pos);
1640 SendPan(application, Gesture::Finished, pos);
1641 Wait(application, RENDER_FRAME_INTERVAL);
1643 Actor offscreenRoot = field.GetChildAt( 1u );
1647 int utcDaliTextFieldEvent06(void)
1649 ToolkitTestApplication application;
1650 tet_infoline(" utcDaliTextFieldEvent06");
1652 // Checks Longpress when in edit mode
1654 TextField field = TextField::New();
1655 DALI_TEST_CHECK( field );
1656 Stage::GetCurrent().Add( field );
1657 LoadMarkerImages(application, field);
1658 // Render and notify
1659 application.SendNotification();
1660 application.Render();
1662 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1663 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1664 field.SetSize( 300.f, 50.f );
1665 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1666 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1668 // Avoid a crash when core load gl resources.
1669 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1670 // Render and notify
1671 application.SendNotification();
1672 application.Render();
1674 // Create a tap event to touch the text field.
1675 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1676 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1677 // Render and notify
1678 application.SendNotification();
1679 application.Render();
1682 // Tap first to get the focus.
1683 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1684 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1686 // Render and notify
1687 application.SendNotification();
1688 application.Render();
1691 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1692 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1694 // Render and notify
1695 application.SendNotification();
1696 application.Render();
1701 int utcDaliTextFieldEvent07(void)
1703 ToolkitTestApplication application;
1704 tet_infoline(" utcDaliTextFieldEvent07");
1706 // Checks Longpress to start edit mode
1708 TextField field = TextField::New();
1709 DALI_TEST_CHECK( field );
1710 Stage::GetCurrent().Add( field );
1711 LoadMarkerImages(application, field);
1712 // Render and notify
1713 application.SendNotification();
1714 application.Render();
1716 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1717 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1718 field.SetSize( 300.f, 50.f );
1719 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1720 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1722 // Avoid a crash when core load gl resources.
1723 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1724 // Render and notify
1725 application.SendNotification();
1726 application.Render();
1729 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1730 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1732 // Render and notify
1733 application.SendNotification();
1734 application.Render();
1739 int utcDaliTextFieldEvent08(void)
1741 ToolkitTestApplication application;
1742 tet_infoline(" utcDaliTextFieldEvent08");
1744 Dali::Clipboard clipboard = Clipboard::Get();
1745 clipboard.SetItem("testTextFieldEvent");
1747 // Checks Longpress when only place holder text
1749 TextField field = TextField::New();
1750 DALI_TEST_CHECK( field );
1751 Stage::GetCurrent().Add( field );
1752 LoadMarkerImages(application, field);
1753 // Render and notify
1754 application.SendNotification();
1755 application.Render();
1757 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
1758 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1759 field.SetSize( 300.f, 50.f );
1760 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1761 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1763 // Avoid a crash when core load gl resources.
1764 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1765 // Render and notify
1766 application.SendNotification();
1767 application.Render();
1770 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1771 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1773 // Render and notify
1774 application.SendNotification();
1775 application.Render();
1777 Wait(application, 500);
1779 Stage stage = Stage::GetCurrent();
1780 Layer layer = stage.GetRootLayer();
1781 Actor actor = layer.FindChildByName("optionPaste");
1785 Vector3 worldPosition = actor.GetCurrentWorldPosition();
1786 Vector2 halfStageSize = stage.GetSize() / 2.0f;
1787 Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
1789 Dali::Integration::TouchEvent event;
1790 event = Dali::Integration::TouchEvent();
1791 event.AddPoint( GetPointDownInside( position ) );
1792 application.ProcessEvent( event );
1794 event = Dali::Integration::TouchEvent();
1795 event.AddPoint( GetPointUpInside( position ) );
1796 application.ProcessEvent( event );
1798 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
1802 int utcDaliTextFieldStyleWhilstSelected(void)
1804 ToolkitTestApplication application;
1805 tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
1807 // Change font and styles whilst text is selected whilst word selected
1809 TextField field = TextField::New();
1810 DALI_TEST_CHECK( field );
1811 Stage::GetCurrent().Add( field );
1812 LoadMarkerImages(application, field);
1813 // Render and notify
1814 application.SendNotification();
1815 application.Render();
1817 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1818 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1819 field.SetSize( 300.f, 50.f );
1820 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1821 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1823 // Avoid a crash when core load gl resources.
1824 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1825 // Render and notify
1826 application.SendNotification();
1827 application.Render();
1829 // Create a tap event to touch the text field.
1830 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1831 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1832 // Render and notify
1833 application.SendNotification();
1834 application.Render();
1837 // Tap first to get the focus.
1838 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1839 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1841 // Render and notify
1842 application.SendNotification();
1843 application.Render();
1845 // Double tap to select a word.
1846 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1847 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1849 // Render and notify
1850 application.SendNotification();
1851 application.Render();
1853 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
1854 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
1856 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
1857 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"slant\":\"italic\"}", TEST_LOCATION );
1859 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"width\":\"expanded\",\"slant\":\"italic\"}" );
1860 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"width\":\"expanded\",\"slant\":\"italic\"}", TEST_LOCATION );
1862 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
1863 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1865 field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
1866 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
1868 field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
1869 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), "{\"weight\":\"bold\",\"slant\":\"italic\"}", TEST_LOCATION );
1871 field.SetProperty( TextField::Property::FONT_STYLE, "{\"width\":\"expanded\"}" );
1872 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), "{\"width\":\"expanded\"}", TEST_LOCATION );