2 * Copyright (c) 2020 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.
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
25 #include <dali-toolkit/internal/text/text-controller.h>
26 #include <dali-toolkit/internal/text/text-controller-impl.h>
29 using namespace Toolkit;
32 int UtcDaliTextFieldMultipleBackgroundText(void)
34 ToolkitTestApplication application;
35 tet_infoline( "UtcDaliTextFieldMultipleBackgroundText" );
37 // Create a text field
38 TextField textField = TextField::New();
39 textField.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) );
40 textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
41 textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
43 // Add the text field to the stage
44 application.GetScene().Add( textField );
46 application.SendNotification();
49 Toolkit::Internal::TextField& textFieldImpl = GetImpl( textField );
50 ControllerPtr controller = textFieldImpl.GetTextController();
51 Controller::Impl& controllerImpl = Controller::Impl::GetImplementation( *controller.Get() );
53 // Add multiple background colors for the text.
54 ColorRun backgroundColorRun1;
55 backgroundColorRun1.characterRun.characterIndex = 0u;
56 backgroundColorRun1.characterRun.numberOfCharacters = 1u;
57 backgroundColorRun1.color = Color::RED;
58 controllerImpl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun1 );
60 ColorRun backgroundColorRun2;
61 backgroundColorRun2.characterRun.characterIndex = 5u;
62 backgroundColorRun2.characterRun.numberOfCharacters = 8u;
63 backgroundColorRun2.color = Color::CYAN;
64 controllerImpl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun2 );
66 ColorRun backgroundColorRun3;
67 backgroundColorRun3.characterRun.characterIndex = 23u;
68 backgroundColorRun3.characterRun.numberOfCharacters = 6u;
69 backgroundColorRun3.color = Color::GREEN;
70 controllerImpl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun3 );
72 // Check the case where there is only one character in the text
73 controller->SetText( "S" );
75 application.SendNotification();
78 // The offscreen root actor should have one child: the renderable.
79 Actor stencil = textField.GetChildAt( 0u );
80 DALI_TEST_CHECK( stencil.GetChildCount() == 1u );
82 // The renderable actor should have two children: the text and the background.
83 Actor renderableActor = stencil.GetChildAt( 0u );
84 DALI_TEST_CHECK( renderableActor.GetChildCount() == 2u );
86 // Check that the background is created
87 Actor backgroundActor = renderableActor.GetChildAt( 0u );
88 DALI_TEST_CHECK( backgroundActor );
89 DALI_TEST_CHECK( backgroundActor.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "TextBackgroundColorActor" );
91 // Change the text to contain more characters
92 controller->SetText( "Text Multiple Background Test" );
94 application.SendNotification();
97 // Highlight the whole text
98 textFieldImpl.SelectWholeText();
100 application.SendNotification();
101 application.Render();
103 // Now the offscreen root actor should have three children: the renderable, the highlight, and the background.
104 DALI_TEST_CHECK( stencil.GetChildCount() == 3u );
105 // The renderable actor should have one child only: the text
106 DALI_TEST_CHECK( renderableActor.GetChildCount() == 1u );
108 // The background should now be lowered below the highlight
109 backgroundActor = stencil.GetChildAt( 0u );
110 DALI_TEST_CHECK( backgroundActor );
111 DALI_TEST_CHECK( backgroundActor.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "TextBackgroundColorActor" );