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 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_CLIP );
524 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), TEST_LOCATION );
525 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
526 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ), TEST_LOCATION );
528 // Check that the Alignment properties can be correctly set
529 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
530 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
531 field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
532 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
534 // Check text's color property
535 field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
536 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
538 // Check placeholder text's color property.
539 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
540 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
542 // Check shadow properties.
543 field.SetProperty( TextField::Property::SHADOW_OFFSET, Vector2( 1.f, 1.f ) );
544 DALI_TEST_EQUALS( field.GetProperty<Vector2>( TextField::Property::SHADOW_OFFSET ), Vector2( 1.f, 1.f ), TEST_LOCATION );
545 field.SetProperty( TextField::Property::SHADOW_COLOR, Color::GREEN );
546 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SHADOW_COLOR ), Color::GREEN, TEST_LOCATION );
548 // Check cursor properties
549 field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
550 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
551 field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
552 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
554 field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
555 DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
556 field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
557 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
558 field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
559 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
560 field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
561 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
563 // Check scroll properties.
564 field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
565 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
566 field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
567 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
569 // Check handle images
570 field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
571 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
572 field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
573 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
574 field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
576 // Check handle images
577 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
578 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
579 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
580 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
581 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
582 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
584 // Check the highlight color
585 field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
586 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
588 // Decoration bounding box
589 field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
590 DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
592 // Check input color property.
593 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
594 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
596 // Check the enable markup property.
597 DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
598 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
599 DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
601 // Check input font properties.
602 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
603 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
604 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
605 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION );
606 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
607 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
609 // Reset input font style.
610 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
611 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
612 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" );
613 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
614 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "" );
615 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION );
617 // Check the underline property
618 field.SetProperty( TextField::Property::UNDERLINE, "Underline properties" );
619 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION );
621 // Check the input underline property
622 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
623 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
625 // Check the shadow property
626 field.SetProperty( TextField::Property::SHADOW, "Shadow properties" );
627 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
629 // Check the input shadow property
630 field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
631 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
633 // Check the emboss property
634 field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
635 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
637 // Check the input emboss property
638 field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
639 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
641 // Check the outline property
642 field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
643 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
645 // Check the input outline property
646 field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
647 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
652 // Positive Atlas Text Renderer test
653 int utcDaliTextFieldAtlasRenderP(void)
655 ToolkitTestApplication application;
656 tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
657 StyleManager styleManager = StyleManager::Get();
658 styleManager.ApplyDefaultTheme();
659 TextField field = TextField::New();
660 DALI_TEST_CHECK( field );
662 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
664 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
666 Stage::GetCurrent().Add( field );
670 // Render some text with the shared atlas backend
671 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
672 application.SendNotification();
673 application.Render();
677 tet_result(TET_FAIL);
682 // Positive test for the textChanged signal.
683 int utcDaliTextFieldTextChangedP(void)
685 ToolkitTestApplication application;
686 tet_infoline(" utcDaliTextFieldTextChangedP");
687 TextField field = TextField::New();
688 DALI_TEST_CHECK( field );
690 Stage::GetCurrent().Add( field );
692 // connect to the text changed signal.
693 ConnectionTracker* testTracker = new ConnectionTracker();
694 field.TextChangedSignal().Connect(&TestTextChangedCallback);
695 bool textChangedSignal = false;
696 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
698 gTextChangedCallBackCalled = false;
699 field.SetProperty( TextField::Property::TEXT, "ABC" );
700 DALI_TEST_CHECK( gTextChangedCallBackCalled );
701 DALI_TEST_CHECK( textChangedSignal );
703 application.SendNotification();
705 field.SetKeyInputFocus();
707 gTextChangedCallBackCalled = false;
708 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
709 DALI_TEST_CHECK( gTextChangedCallBackCalled );
714 // Negative test for the textChanged signal.
715 int utcDaliTextFieldTextChangedN(void)
717 ToolkitTestApplication application;
718 tet_infoline(" utcDaliTextFieldTextChangedN");
719 TextField field = TextField::New();
720 DALI_TEST_CHECK( field );
722 Stage::GetCurrent().Add( field );
724 // connect to the text changed signal.
725 ConnectionTracker* testTracker = new ConnectionTracker();
726 field.TextChangedSignal().Connect(&TestTextChangedCallback);
727 bool textChangedSignal = false;
728 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
730 gTextChangedCallBackCalled = false;
731 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
732 DALI_TEST_CHECK( !gTextChangedCallBackCalled );
733 DALI_TEST_CHECK( !textChangedSignal );
738 // Positive test for Max Characters reached signal.
739 int utcDaliTextFieldMaxCharactersReachedP(void)
741 ToolkitTestApplication application;
742 tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
743 TextField field = TextField::New();
744 DALI_TEST_CHECK( field );
746 Stage::GetCurrent().Add( field );
748 const int maxNumberOfCharacters = 1;
749 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
751 field.SetKeyInputFocus();
753 // connect to the text changed signal.
754 ConnectionTracker* testTracker = new ConnectionTracker();
755 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
756 bool maxLengthReachedSignal = false;
757 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
759 gMaxCharactersCallBackCalled = false;
761 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
762 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
764 DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
765 DALI_TEST_CHECK( maxLengthReachedSignal );
770 // Negative test for Max Characters reached signal.
771 int utcDaliTextFieldMaxCharactersReachedN(void)
773 ToolkitTestApplication application;
774 tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
775 TextField field = TextField::New();
776 DALI_TEST_CHECK( field );
778 Stage::GetCurrent().Add( field );
780 const int maxNumberOfCharacters = 3;
781 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
783 field.SetKeyInputFocus();
785 // connect to the text changed signal.
786 ConnectionTracker* testTracker = new ConnectionTracker();
787 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
788 bool maxLengthReachedSignal = false;
789 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
791 gMaxCharactersCallBackCalled = false;
793 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
794 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
796 DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
797 DALI_TEST_CHECK( !maxLengthReachedSignal );
802 int utcDaliTextFieldInputStyleChanged01(void)
804 ToolkitTestApplication application;
805 tet_infoline(" utcDaliTextFieldInputStyleChanged01");
807 // The text-field emits signals when the input style changes. These changes of style are
808 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
809 // can't be emitted during the size negotiation as the callbacks may update the UI.
810 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
811 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
812 application.CreateAdaptor();
816 char* pathNamePtr = get_current_dir_name();
817 const std::string pathName( pathNamePtr );
820 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
821 fontClient.SetDpi( 93u, 93u );
823 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
824 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
826 TextField field = TextField::New();
827 DALI_TEST_CHECK( field );
830 field.SetSize( 300.f, 50.f );
831 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
832 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
834 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
835 field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
837 // connect to the text changed signal.
838 ConnectionTracker* testTracker = new ConnectionTracker();
839 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
840 bool inputStyleChangedSignal = false;
841 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
843 Stage::GetCurrent().Add( field );
846 application.SendNotification();
847 application.Render();
849 // Executes the idle callbacks added by the text control on the change of input style.
850 application.RunIdles();
852 gInputStyleChangedCallbackCalled = false;
853 gInputStyleMask = TextField::InputStyle::NONE;
854 inputStyleChangedSignal = false;
856 // Create a tap event to touch the text field.
857 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
858 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
861 application.SendNotification();
862 application.Render();
864 // Executes the idle callbacks added by the text control on the change of input style.
865 application.RunIdles();
867 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
868 if( gInputStyleChangedCallbackCalled )
870 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
872 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
873 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
875 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
876 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
878 DALI_TEST_CHECK( inputStyleChangedSignal );
880 gInputStyleChangedCallbackCalled = false;
881 gInputStyleMask = TextField::InputStyle::NONE;
882 inputStyleChangedSignal = false;
884 // Create a tap event to touch the text field.
885 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
886 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
889 application.SendNotification();
890 application.Render();
892 // Executes the idle callbacks added by the text control on the change of input style.
893 application.RunIdles();
895 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
896 DALI_TEST_CHECK( !inputStyleChangedSignal );
898 gInputStyleChangedCallbackCalled = false;
899 gInputStyleMask = TextField::InputStyle::NONE;
900 inputStyleChangedSignal = false;
902 // Create a tap event to touch the text field.
903 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
904 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.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 if( gInputStyleChangedCallbackCalled )
916 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
918 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
919 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
921 DALI_TEST_CHECK( inputStyleChangedSignal );
923 gInputStyleChangedCallbackCalled = false;
924 gInputStyleMask = TextField::InputStyle::NONE;
925 inputStyleChangedSignal = false;
927 // Create a tap event to touch the text field.
928 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
929 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
932 application.SendNotification();
933 application.Render();
935 // Executes the idle callbacks added by the text control on the change of input style.
936 application.RunIdles();
938 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
939 if( gInputStyleChangedCallbackCalled )
941 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
943 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
944 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
946 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
947 DALI_TEST_EQUALS( style, "{\"weight\":\"bold\"}", TEST_LOCATION );
949 DALI_TEST_CHECK( inputStyleChangedSignal );
951 gInputStyleChangedCallbackCalled = false;
952 gInputStyleMask = TextField::InputStyle::NONE;
953 inputStyleChangedSignal = false;
955 // Create a tap event to touch the text field.
956 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
957 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
960 application.SendNotification();
961 application.Render();
963 // Executes the idle callbacks added by the text control on the change of input style.
964 application.RunIdles();
966 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
967 DALI_TEST_CHECK( !inputStyleChangedSignal );
969 gInputStyleChangedCallbackCalled = false;
970 gInputStyleMask = TextField::InputStyle::NONE;
971 inputStyleChangedSignal = false;
973 // Create a tap event to touch the text field.
974 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
975 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
978 application.SendNotification();
979 application.Render();
981 // Executes the idle callbacks added by the text control on the change of input style.
982 application.RunIdles();
984 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
985 if( gInputStyleChangedCallbackCalled )
987 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
989 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
990 DALI_TEST_CHECK( style.empty() );
992 DALI_TEST_CHECK( inputStyleChangedSignal );
994 gInputStyleChangedCallbackCalled = false;
995 gInputStyleMask = TextField::InputStyle::NONE;
996 inputStyleChangedSignal = false;
998 // Create a tap event to touch the text field.
999 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1000 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1002 // Render and notify
1003 application.SendNotification();
1004 application.Render();
1006 // Executes the idle callbacks added by the text control on the change of input style.
1007 application.RunIdles();
1009 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1010 DALI_TEST_CHECK( !inputStyleChangedSignal );
1015 int utcDaliTextFieldInputStyleChanged02(void)
1017 ToolkitTestApplication application;
1018 tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1020 // The text-field emits signals when the input style changes. These changes of style are
1021 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1022 // can't be emitted during the size negotiation as the callbacks may update the UI.
1023 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1024 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1025 application.CreateAdaptor();
1029 char* pathNamePtr = get_current_dir_name();
1030 const std::string pathName( pathNamePtr );
1031 free( pathNamePtr );
1033 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1034 fontClient.SetDpi( 93u, 93u );
1036 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1037 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1039 TextField field = TextField::New();
1040 DALI_TEST_CHECK( field );
1043 field.SetSize( 300.f, 50.f );
1044 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1045 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1047 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1048 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>" );
1050 // connect to the text changed signal.
1051 ConnectionTracker* testTracker = new ConnectionTracker();
1052 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1053 bool inputStyleChangedSignal = false;
1054 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1056 Stage::GetCurrent().Add( field );
1058 // Render and notify
1059 application.SendNotification();
1060 application.Render();
1062 // Executes the idle callbacks added by the text control on the change of input style.
1063 application.RunIdles();
1065 gInputStyleChangedCallbackCalled = false;
1066 gInputStyleMask = TextField::InputStyle::NONE;
1067 inputStyleChangedSignal = false;
1069 // Create a tap event to touch the text field.
1070 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1071 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1072 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1073 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1075 // Render and notify
1076 application.SendNotification();
1077 application.Render();
1079 // Executes the idle callbacks added by the text control on the change of input style.
1080 application.RunIdles();
1082 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1083 if( gInputStyleChangedCallbackCalled )
1085 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1086 static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1087 TextField::InputStyle::POINT_SIZE |
1088 TextField::InputStyle::COLOR ),
1091 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1092 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1094 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1095 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1097 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1098 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1100 DALI_TEST_CHECK( inputStyleChangedSignal );
1102 gInputStyleChangedCallbackCalled = false;
1103 gInputStyleMask = TextField::InputStyle::NONE;
1104 inputStyleChangedSignal = false;
1106 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
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>( TextField::InputStyle::COLOR ),
1122 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1123 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1125 DALI_TEST_CHECK( inputStyleChangedSignal );
1127 gInputStyleChangedCallbackCalled = false;
1128 gInputStyleMask = TextField::InputStyle::NONE;
1129 inputStyleChangedSignal = false;
1131 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1133 // Render and notify
1134 application.SendNotification();
1135 application.Render();
1137 // Executes the idle callbacks added by the text control on the change of input style.
1138 application.RunIdles();
1140 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1141 DALI_TEST_CHECK( !inputStyleChangedSignal );
1143 gInputStyleChangedCallbackCalled = false;
1144 gInputStyleMask = TextField::InputStyle::NONE;
1145 inputStyleChangedSignal = false;
1147 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1149 // Render and notify
1150 application.SendNotification();
1151 application.Render();
1153 // Executes the idle callbacks added by the text control on the change of input style.
1154 application.RunIdles();
1156 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1157 if( gInputStyleChangedCallbackCalled )
1159 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1160 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1163 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1164 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1166 DALI_TEST_CHECK( inputStyleChangedSignal );
1168 gInputStyleChangedCallbackCalled = false;
1169 gInputStyleMask = TextField::InputStyle::NONE;
1170 inputStyleChangedSignal = false;
1172 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1174 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"thin\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
1175 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1177 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1178 field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1179 field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1180 field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1182 // Render and notify
1183 application.SendNotification();
1184 application.Render();
1186 // Executes the idle callbacks added by the text control on the change of input style.
1187 application.RunIdles();
1189 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1190 DALI_TEST_CHECK( !inputStyleChangedSignal );
1192 // Create a tap event to touch the text field.
1193 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1194 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1196 // Render and notify
1197 application.SendNotification();
1198 application.Render();
1200 // Executes the idle callbacks added by the text control on the change of input style.
1201 application.RunIdles();
1203 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1204 if( gInputStyleChangedCallbackCalled )
1206 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1207 static_cast<unsigned int>( TextField::InputStyle::COLOR |
1208 TextField::InputStyle::POINT_SIZE |
1209 TextField::InputStyle::FONT_STYLE |
1210 TextField::InputStyle::UNDERLINE |
1211 TextField::InputStyle::SHADOW |
1212 TextField::InputStyle::EMBOSS |
1213 TextField::InputStyle::OUTLINE ),
1216 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1217 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1219 DALI_TEST_CHECK( inputStyleChangedSignal );
1224 int utcDaliTextFieldEvent01(void)
1226 ToolkitTestApplication application;
1227 tet_infoline(" utcDaliTextFieldEvent01");
1229 // Creates a tap event. After creating a tap event the text field should
1230 // have the focus and add text with key events should be possible.
1232 TextField field = TextField::New();
1233 DALI_TEST_CHECK( field );
1235 Stage::GetCurrent().Add( field );
1237 field.SetSize( 300.f, 50.f );
1238 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1239 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1241 // Avoid a crash when core load gl resources.
1242 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1244 // Render and notify
1245 application.SendNotification();
1246 application.Render();
1248 // Add a key event but as the text field has not the focus it should do nothing.
1249 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1251 // Render and notify
1252 application.SendNotification();
1253 application.Render();
1255 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1257 // Create a tap event to touch the text field.
1258 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1259 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1261 // Render and notify
1262 application.SendNotification();
1263 application.Render();
1265 // Now the text field has the focus, so it can handle the key events.
1266 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1267 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1269 // Render and notify
1270 application.SendNotification();
1271 application.Render();
1273 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1275 // Create a second text field and send key events to it.
1276 TextField field2 = TextField::New();
1278 field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1279 field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1280 field2.SetSize( 100.f, 100.f );
1281 field2.SetPosition( 100.f, 100.f );
1283 Stage::GetCurrent().Add( field2 );
1285 // Render and notify
1286 application.SendNotification();
1287 application.Render();
1289 // Create a tap event on the second text field.
1290 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1291 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1293 // Render and notify
1294 application.SendNotification();
1295 application.Render();
1297 // The second text field has the focus. It should handle the key events.
1298 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1299 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1301 // Render and notify
1302 application.SendNotification();
1303 application.Render();
1305 // Check the text has been added to the second text field.
1306 DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1311 int utcDaliTextFieldEvent02(void)
1313 ToolkitTestApplication application;
1314 tet_infoline(" utcDaliTextFieldEvent02");
1316 // Checks if the right number of actors are created.
1318 TextField field = TextField::New();
1319 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1320 DALI_TEST_CHECK( field );
1321 LoadMarkerImages(application, field);
1323 Stage::GetCurrent().Add( field );
1325 field.SetSize( 300.f, 50.f );
1326 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1327 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1329 // Avoid a crash when core load gl resources.
1330 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1332 // Render and notify
1333 application.SendNotification();
1334 application.Render();
1336 // Check there are the expected number of children ( stencil ).
1337 DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
1339 Actor stencil = field.GetChildAt( 0u );
1340 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1342 // Create a tap event to touch the text field.
1343 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1344 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1346 // Render and notify
1347 application.SendNotification();
1348 application.Render();
1350 Actor layer = field.GetChildAt( 1u );
1351 DALI_TEST_CHECK( layer.IsLayer() );
1353 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1354 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1356 // Now the text field has the focus, so it can handle the key events.
1357 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1358 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1360 // Render and notify
1361 application.SendNotification();
1362 application.Render();
1364 // Checks the cursor and the renderer have been created.
1365 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1366 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1368 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1369 DALI_TEST_CHECK( cursor );
1371 // The offscreen root actor has a container with all the actors which contain the text renderers.
1372 Actor container = stencil.GetChildAt( 0u );
1373 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1375 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1376 DALI_TEST_CHECK( renderer );
1379 // Move the cursor and check the position changes.
1380 Vector3 position1 = cursor.GetCurrentPosition();
1382 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1383 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1385 // Render and notify
1386 application.SendNotification();
1387 application.Render();
1389 Vector3 position2 = cursor.GetCurrentPosition();
1391 DALI_TEST_CHECK( position2.x < position1.x );
1393 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1394 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1396 // Render and notify
1397 application.SendNotification();
1398 application.Render();
1400 Vector3 position3 = cursor.GetCurrentPosition();
1402 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1404 // Send some taps and check the cursor positions.
1406 // Try to tap at the beginning.
1407 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1408 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1410 // Render and notify
1411 application.SendNotification();
1412 application.Render();
1414 // Cursor position should be the same than position1.
1415 Vector3 position4 = cursor.GetCurrentPosition();
1417 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1419 // Tap away from the start position.
1420 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1421 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1423 // Render and notify
1424 application.SendNotification();
1425 application.Render();
1427 Vector3 position5 = cursor.GetCurrentPosition();
1429 DALI_TEST_CHECK( position5.x > position4.x );
1431 // Remove all the text.
1432 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1433 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1434 field.SetProperty( TextField::Property::TEXT, "" );
1436 // Render and notify
1437 application.SendNotification();
1438 application.Render();
1440 // Cursor position should be the same than position2.
1441 Vector3 position6 = cursor.GetCurrentPosition();
1443 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1445 // Should not be a renderer.
1446 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1451 int utcDaliTextFieldEvent03(void)
1453 ToolkitTestApplication application;
1454 tet_infoline(" utcDaliTextFieldEvent03");
1456 // Checks if the highlight actor is created.
1458 TextField field = TextField::New();
1459 DALI_TEST_CHECK( field );
1461 Stage::GetCurrent().Add( field );
1463 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1464 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1465 field.SetSize( 30.f, 50.f );
1466 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1467 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1469 // Avoid a crash when core load gl resources.
1470 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1471 LoadMarkerImages(application, field);
1473 // Render and notify
1474 application.SendNotification();
1475 application.Render();
1477 // Tap first to get the focus.
1478 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1479 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1481 // Render and notify
1482 application.SendNotification();
1483 application.Render();
1485 // Double tap to select a word.
1486 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1487 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1489 // Render and notify
1490 application.SendNotification();
1491 application.Render();
1493 // The offscreen root actor should have two actors: the renderer and the highlight actor.
1494 Actor stencil = field.GetChildAt( 0u );
1496 // The offscreen root actor has a container with all the actors which contain the text renderers.
1497 Actor container = stencil.GetChildAt( 0u );
1498 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1500 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1501 DALI_TEST_CHECK( renderer );
1504 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1505 DALI_TEST_CHECK( highlight );
1510 int utcDaliTextFieldEvent04(void)
1512 ToolkitTestApplication application;
1513 tet_infoline(" utcDaliTextFieldEvent04");
1515 // Checks if the highlight actor is created.
1517 TextField field = TextField::New();
1518 DALI_TEST_CHECK( field );
1519 Stage::GetCurrent().Add( field );
1520 LoadMarkerImages(application, field);
1521 // Render and notify
1522 application.SendNotification();
1523 application.Render();
1525 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1526 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1527 field.SetSize( 300.f, 50.f );
1528 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1529 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1531 // Avoid a crash when core load gl resources.
1532 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1533 // Render and notify
1534 application.SendNotification();
1535 application.Render();
1537 // Create a tap event to touch the text field.
1538 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1539 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1540 // Render and notify
1541 application.SendNotification();
1542 application.Render();
1545 // Tap first to get the focus.
1546 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1547 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1549 // Render and notify
1550 application.SendNotification();
1551 application.Render();
1553 // Double tap to select a word.
1554 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1555 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1557 // Render and notify
1558 application.SendNotification();
1559 application.Render();
1562 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1563 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1567 int utcDaliTextFieldEvent05(void)
1569 ToolkitTestApplication application;
1570 tet_infoline(" utcDaliTextFieldEvent05");
1572 // Checks dragging of cursor/grab handle
1574 TextField field = TextField::New();
1575 DALI_TEST_CHECK( field );
1576 Stage::GetCurrent().Add( field );
1577 LoadMarkerImages(application, field);
1578 // Render and notify
1579 application.SendNotification();
1580 application.Render();
1582 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1583 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1584 field.SetSize( 300.f, 50.f );
1585 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1586 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1588 // Avoid a crash when core load gl resources.
1589 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1590 // Render and notify
1591 application.SendNotification();
1592 application.Render();
1594 // Create a tap event to touch the text field.
1595 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1596 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1597 // Render and notify
1598 application.SendNotification();
1599 application.Render();
1602 // Tap first to get the focus.
1603 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1604 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1606 // Render and notify
1607 application.SendNotification();
1608 application.Render();
1610 // Double tap to select a word.
1611 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1612 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1614 // Render and notify
1615 application.SendNotification();
1616 application.Render();
1618 // drag grab handle right
1619 Vector2 pos(0.0f, 40.0f);
1620 SendPan(application, Gesture::Possible, pos);
1621 SendPan(application, Gesture::Started, pos);
1623 Wait(application, 100);
1625 for(int i = 0;i<20;i++)
1627 SendPan(application, Gesture::Continuing, pos);
1632 SendPan(application, Gesture::Finished, pos);
1633 Wait(application, RENDER_FRAME_INTERVAL);
1635 Actor stencil = field.GetChildAt( 1u );
1639 int utcDaliTextFieldEvent06(void)
1641 ToolkitTestApplication application;
1642 tet_infoline(" utcDaliTextFieldEvent06");
1644 // Checks Longpress when in edit mode
1646 TextField field = TextField::New();
1647 DALI_TEST_CHECK( field );
1648 Stage::GetCurrent().Add( field );
1649 LoadMarkerImages(application, field);
1650 // Render and notify
1651 application.SendNotification();
1652 application.Render();
1654 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1655 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1656 field.SetSize( 300.f, 50.f );
1657 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1658 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1660 // Avoid a crash when core load gl resources.
1661 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1662 // Render and notify
1663 application.SendNotification();
1664 application.Render();
1666 // Create a tap event to touch the text field.
1667 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1668 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1669 // Render and notify
1670 application.SendNotification();
1671 application.Render();
1674 // Tap first to get the focus.
1675 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1676 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1678 // Render and notify
1679 application.SendNotification();
1680 application.Render();
1683 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1684 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1686 // Render and notify
1687 application.SendNotification();
1688 application.Render();
1693 int utcDaliTextFieldEvent07(void)
1695 ToolkitTestApplication application;
1696 tet_infoline(" utcDaliTextFieldEvent07");
1698 // Checks Longpress to start edit mode
1700 TextField field = TextField::New();
1701 DALI_TEST_CHECK( field );
1702 Stage::GetCurrent().Add( field );
1703 LoadMarkerImages(application, field);
1704 // Render and notify
1705 application.SendNotification();
1706 application.Render();
1708 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1709 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1710 field.SetSize( 300.f, 50.f );
1711 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1712 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1714 // Avoid a crash when core load gl resources.
1715 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1716 // Render and notify
1717 application.SendNotification();
1718 application.Render();
1721 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1722 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1724 // Render and notify
1725 application.SendNotification();
1726 application.Render();
1731 int utcDaliTextFieldEvent08(void)
1733 ToolkitTestApplication application;
1734 tet_infoline(" utcDaliTextFieldEvent08");
1736 Dali::Clipboard clipboard = Clipboard::Get();
1737 clipboard.SetItem("testTextFieldEvent");
1739 // Checks Longpress when only place holder text
1741 TextField field = TextField::New();
1742 DALI_TEST_CHECK( field );
1743 Stage::GetCurrent().Add( field );
1744 LoadMarkerImages(application, field);
1745 // Render and notify
1746 application.SendNotification();
1747 application.Render();
1749 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
1750 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1751 field.SetSize( 300.f, 50.f );
1752 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1753 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1755 // Avoid a crash when core load gl resources.
1756 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1757 // Render and notify
1758 application.SendNotification();
1759 application.Render();
1762 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1763 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1765 // Render and notify
1766 application.SendNotification();
1767 application.Render();
1769 Wait(application, 500);
1771 Stage stage = Stage::GetCurrent();
1772 Layer layer = stage.GetRootLayer();
1773 Actor actor = layer.FindChildByName("optionPaste");
1777 Vector3 worldPosition = actor.GetCurrentWorldPosition();
1778 Vector2 halfStageSize = stage.GetSize() / 2.0f;
1779 Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
1781 Dali::Integration::TouchEvent event;
1782 event = Dali::Integration::TouchEvent();
1783 event.AddPoint( GetPointDownInside( position ) );
1784 application.ProcessEvent( event );
1786 event = Dali::Integration::TouchEvent();
1787 event.AddPoint( GetPointUpInside( position ) );
1788 application.ProcessEvent( event );
1790 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
1794 int utcDaliTextFieldStyleWhilstSelected(void)
1796 ToolkitTestApplication application;
1797 tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
1799 // Change font and styles whilst text is selected whilst word selected
1801 TextField field = TextField::New();
1802 DALI_TEST_CHECK( field );
1803 Stage::GetCurrent().Add( field );
1804 LoadMarkerImages(application, field);
1805 // Render and notify
1806 application.SendNotification();
1807 application.Render();
1809 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1810 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1811 field.SetSize( 300.f, 50.f );
1812 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1813 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1815 // Avoid a crash when core load gl resources.
1816 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1817 // Render and notify
1818 application.SendNotification();
1819 application.Render();
1821 // Create a tap event to touch the text field.
1822 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1823 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1824 // Render and notify
1825 application.SendNotification();
1826 application.Render();
1829 // Tap first to get the focus.
1830 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1831 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1833 // Render and notify
1834 application.SendNotification();
1835 application.Render();
1837 // Double tap to select a word.
1838 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1839 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1841 // Render and notify
1842 application.SendNotification();
1843 application.Render();
1845 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
1846 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
1848 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
1849 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"slant\":\"italic\"}", TEST_LOCATION );
1851 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"width\":\"expanded\",\"slant\":\"italic\"}" );
1852 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"width\":\"expanded\",\"slant\":\"italic\"}", TEST_LOCATION );
1854 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
1855 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1857 field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
1858 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
1860 field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
1861 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), "{\"weight\":\"bold\",\"slant\":\"italic\"}", TEST_LOCATION );
1863 field.SetProperty( TextField::Property::FONT_STYLE, "{\"width\":\"expanded\"}" );
1864 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), "{\"width\":\"expanded\"}", TEST_LOCATION );