Merge "Fixing the issue where characters were being drawn at the same location whenev...
authorBowon Ryu <bowon.ryu@samsung.com>
Thu, 8 Apr 2021 07:56:12 +0000 (07:56 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 8 Apr 2021 07:56:12 +0000 (07:56 +0000)
1  2 
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp

@@@ -1,5 -1,5 +1,5 @@@
  /*
 - * Copyright (c) 2020 Samsung Electronics Co., Ltd.
 + * Copyright (c) 2021 Samsung Electronics Co., Ltd.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
@@@ -103,7 -103,6 +103,7 @@@ const char* const PROPERTY_NAME_ENABLE_
  const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION      = "matchSystemLanguageDirection";
  const char* const PROPERTY_NAME_MAX_LENGTH                           = "maxLength";
  const char* const PROPERTY_NAME_FONT_SIZE_SCALE                      = "fontSizeScale";
 +const char* const PROPERTY_NAME_GRAB_HANDLE_COLOR                    = "grabHandleColor";
  
  
  const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
@@@ -130,8 -129,6 +130,8 @@@ const char* HANDLE_RIGHT_SELECTION_FILE
  
  const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
  
 +static bool gAnchorClickedCallBackCalled;
 +static bool gAnchorClickedCallBackNotCalled;
  static bool gTextChangedCallBackCalled;
  static bool gInputStyleChangedCallbackCalled;
  static bool gMaxCharactersCallBackCalled;
@@@ -151,18 -148,6 +151,18 @@@ struct CallbackFuncto
    bool* mCallbackFlag;
  };
  
 +static void TestAnchorClickedCallback(TextEditor control, const char* href, unsigned int hrefLength)
 +{
 +  tet_infoline(" TestAnchorClickedCallback");
 +
 +  gAnchorClickedCallBackNotCalled = false;
 +
 +  if (!strcmp(href, "https://www.tizen.org") && hrefLength == strlen(href))
 +  {
 +    gAnchorClickedCallBackCalled = true;
 +  }
 +}
 +
  static void TestTextChangedCallback( TextEditor control )
  {
    tet_infoline(" TestTextChangedCallback");
@@@ -510,7 -495,6 +510,7 @@@ int UtcDaliTextEditorGetPropertyP(void
    DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE ) == DevelTextEditor::Property::ENABLE_GRAB_HANDLE );
    DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION );
    DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == DevelTextEditor::Property::MAX_LENGTH );
 +  DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_COLOR ) == DevelTextEditor::Property::GRAB_HANDLE_COLOR );
  
  
    END_TEST;
@@@ -926,10 -910,6 +926,10 @@@ int UtcDaliTextEditorSetPropertyP(void
    editor.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
    DALI_TEST_EQUALS( editor.GetProperty<int>( Actor::Property::LAYOUT_DIRECTION ), static_cast<int>( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
  
 +  // Check handle color
 +  editor.SetProperty( DevelTextEditor::Property::GRAB_HANDLE_COLOR, Color::GREEN );
 +  DALI_TEST_EQUALS( editor.GetProperty<Vector4>( DevelTextEditor::Property::GRAB_HANDLE_COLOR ), Color::GREEN, TEST_LOCATION );
 +
    application.SendNotification();
    application.Render();
  
@@@ -966,52 -946,6 +966,52 @@@ int utcDaliTextEditorAtlasRenderP(void
    END_TEST;
  }
  
 +// Positive test for the anchorClicked signal.
 +int utcDaliTextEditorAnchorClickedP(void)
 +{
 +  ToolkitTestApplication application;
 +  tet_infoline(" utcDaliTextEditorAnchorClickedP");
 +  TextEditor editor = TextEditor::New();
 +  DALI_TEST_CHECK(editor);
 +
 +  application.GetScene().Add(editor);
 +
 +  // connect to the anchor clicked signal.
 +  ConnectionTracker* testTracker = new ConnectionTracker();
 +  DevelTextEditor::AnchorClickedSignal(editor).Connect(&TestAnchorClickedCallback);
 +  bool anchorClickedSignal = false;
 +  editor.ConnectSignal(testTracker, "anchorClicked", CallbackFunctor(&anchorClickedSignal));
 +
 +  gAnchorClickedCallBackCalled = false;
 +  editor.SetProperty(TextEditor::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
 +  editor.SetProperty(TextEditor::Property::ENABLE_MARKUP, true);
 +  editor.SetProperty(Actor::Property::SIZE, Vector2(100.f, 50.f));
 +  editor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
 +  editor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
 +
 +  application.SendNotification();
 +  application.Render();
 +  editor.SetKeyInputFocus();
 +
 +  // Create a tap event to touch the text editor.
 +  TestGenerateTap(application, 5.0f, 5.0f);
 +  application.SendNotification();
 +  application.Render();
 +
 +  DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
 +  DALI_TEST_CHECK(anchorClickedSignal);
 +
 +  gAnchorClickedCallBackNotCalled = true;
 +  // Tap the outside of anchor, callback should not be called.
 +  TestGenerateTap(application, 150.f, 100.f);
 +  application.SendNotification();
 +  application.Render();
 +
 +  DALI_TEST_CHECK(gAnchorClickedCallBackNotCalled);
 +
 +  END_TEST;
 +}
 +
  // Positive test for the textChanged signal.
  int utcDaliTextEditorTextChangedP(void)
  {
    DALI_TEST_CHECK( textChangedSignal );
  
    application.SendNotification();
 -
    editor.SetKeyInputFocus();
  
    gTextChangedCallBackCalled = false;
    END_TEST;
  }
  
 +int utcDaliTextEditorTextChangedWithInputMethodContext(void)
 +{
 +  ToolkitTestApplication application;
 +  tet_infoline(" utcDaliTextEditorTextChangedWithInputMethodContext");
 +  TextEditor editor = TextEditor::New();
 +  DALI_TEST_CHECK( editor );
 +
 +
 +  application.GetScene().Add( editor );
 +
 +  // connect to the text changed signal.
 +  ConnectionTracker* testTracker = new ConnectionTracker();
 +  editor.TextChangedSignal().Connect(&TestTextChangedCallback);
 +  bool textChangedSignal = false;
 +  editor.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
 +
 +
 +  // get InputMethodContext
 +  std::string text;
 +  InputMethodContext::EventData imfEvent;
 +  InputMethodContext inputMethodContext = DevelTextEditor::GetInputMethodContext( editor );
 +
 +  editor.SetKeyInputFocus();
 +  editor.SetProperty( DevelTextEditor::Property::ENABLE_EDITING, true );
 +
 +  // input text
 +  gTextChangedCallBackCalled = false;
 +  imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "ㅎ", 0, 1 );
 +  inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
 +  application.SendNotification();
 +  application.Render();
 +  DALI_TEST_CHECK( gTextChangedCallBackCalled );
 +  DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("ㅎ"), TEST_LOCATION );
 +
 +  gTextChangedCallBackCalled = false;
 +  imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "호", 0, 1 );
 +  inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
 +  application.SendNotification();
 +  application.Render();
 +  DALI_TEST_CHECK( gTextChangedCallBackCalled );
 +  DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("호"), TEST_LOCATION );
 +
 +  gTextChangedCallBackCalled = false;
 +  imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "혿", 0, 1 );
 +  inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
 +  application.SendNotification();
 +  application.Render();
 +  DALI_TEST_CHECK( gTextChangedCallBackCalled );
 +  DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("혿"), TEST_LOCATION );
 +
 +  gTextChangedCallBackCalled = false;
 +  imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "", 0, 1 );
 +  inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
 +  DALI_TEST_CHECK( !gTextChangedCallBackCalled );
 +
 +  imfEvent = InputMethodContext::EventData( InputMethodContext::COMMIT, "호", 0, 1 );
 +  inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
 +  DALI_TEST_CHECK( !gTextChangedCallBackCalled );
 +
 +  imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "두", 1, 2 );
 +  inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
 +  DALI_TEST_CHECK( !gTextChangedCallBackCalled );
 +
 +  application.SendNotification();
 +  application.Render();
 +  DALI_TEST_CHECK( gTextChangedCallBackCalled );
 +  DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("호두"), TEST_LOCATION );
 +
 +  END_TEST;
 +}
 +
 +
  int utcDaliTextEditorInputStyleChanged01(void)
  {
    // The text-editor emits signals when the input style changes. These changes of style are
@@@ -3353,3 -3216,36 +3353,36 @@@ int UtcDaliTextEditorPrimaryCursorPosit
  
    END_TEST;
  }
+ int UtcDaliTextEditorLineCountAfterGetNaturalSize(void)
+ {
+   ToolkitTestApplication application;
+   tet_infoline(" UtcDaliTextEditorLineCountAfterGetNaturalSize ");
+   TextEditor textEditor = TextEditor::New();
+   textEditor.SetProperty(TextEditor::Property::TEXT, "A\nB\nC\nD\nE\nF\n");
+   textEditor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
+   textEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+   textEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+   application.GetScene().Add( textEditor );
+   application.SendNotification();
+   application.Render();
+   int lineCount = 0;
+   lineCount =  textEditor.GetProperty<int>( TextEditor::Property::LINE_COUNT );
+   DALI_TEST_EQUALS( lineCount, 7, TEST_LOCATION );
+   textEditor.GetNaturalSize();
+   // Create a tap event to touch the text editor.
+   TestGenerateTap( application, 18.0f, 25.0f );
+   application.SendNotification();
+   application.Render();
+   lineCount =  textEditor.GetProperty<int>( TextEditor::Property::LINE_COUNT );
+   DALI_TEST_EQUALS( lineCount, 7, TEST_LOCATION );
+   END_TEST;
+ }