Merge "Add a TextEditor property to limit input to maximum characters" into devel...
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Fri, 7 Aug 2020 01:25:34 +0000 (01:25 +0000)
committerGerrit Code Review <gerrit@review>
Fri, 7 Aug 2020 01:25:34 +0000 (01:25 +0000)
1  2 
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-editor-impl.h

@@@ -101,6 -101,7 +101,7 @@@ const char* const PROPERTY_NAME_PLACEHO
  const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION               = "enableShiftSelection";
  const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE                   = "enableGrabHandle";
  const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION      = "matchSystemLanguageDirection";
+ const char* const PROPERTY_NAME_MAX_LENGTH                           = "maxLength";
  
  
  const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
@@@ -127,6 -128,7 +128,7 @@@ const std::string DEFAULT_DEVICE_NAME("
  
  static bool gTextChangedCallBackCalled;
  static bool gInputStyleChangedCallbackCalled;
+ static bool gMaxCharactersCallBackCalled;
  static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
  
  struct CallbackFunctor
@@@ -158,6 -160,13 +160,13 @@@ static void TestInputStyleChangedCallba
    gInputStyleMask = mask;
  }
  
+ static void TestMaxLengthReachedCallback( TextEditor control )
+ {
+   tet_infoline(" TestMaxLengthReachedCallback");
+   gMaxCharactersCallBackCalled = true;
+ }
  // Generate a KeyEvent to send to Core.
  Integration::KeyEvent GenerateKey( const std::string& keyName,
                                     const std::string& logicalKey,
@@@ -360,23 -369,6 +369,23 @@@ int UtcDaliToolkitTextEditorCopyConstru
    END_TEST;
  }
  
 +int UtcDaliTextEditorMoveConstructor(void)
 +{
 +  ToolkitTestApplication application;
 +
 +  TextEditor textEditor = TextEditor::New();
 +  textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
 +  DALI_TEST_CHECK( textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) == "Test" );
 +
 +  TextEditor moved = std::move( textEditor );
 +  DALI_TEST_CHECK( moved );
 +  DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
 +  DALI_TEST_CHECK( moved.GetProperty<std::string>( TextEditor::Property::TEXT ) == "Test" );
 +  DALI_TEST_CHECK( !textEditor );
 +
 +  END_TEST;
 +}
 +
  int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
  {
    ToolkitTestApplication application;
    END_TEST;
  }
  
 +int UtcDaliTextEditorMoveAssignment(void)
 +{
 +  ToolkitTestApplication application;
 +
 +  TextEditor textEditor = TextEditor::New();
 +  textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
 +  DALI_TEST_CHECK( textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) == "Test" );
 +
 +  TextEditor moved;
 +  moved = std::move( textEditor );
 +  DALI_TEST_CHECK( moved );
 +  DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
 +  DALI_TEST_CHECK( moved.GetProperty<std::string>( TextEditor::Property::TEXT ) == "Test" );
 +  DALI_TEST_CHECK( !textEditor );
 +
 +  END_TEST;
 +}
 +
  int UtcDaliTextEditorNewP(void)
  {
    ToolkitTestApplication application;
@@@ -481,6 -455,7 +490,7 @@@ int UtcDaliTextEditorGetPropertyP(void
    DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextEditor::Property::ENABLE_SHIFT_SELECTION );
    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 );
  
    END_TEST;
  }
@@@ -2789,3 -2764,36 +2799,36 @@@ int UtcDaliTextEditorGetInputMethodCont
  
    END_TEST;
  }
+ int utcDaliTextEditorMaxCharactersReached(void)
+ {
+   ToolkitTestApplication application;
+   tet_infoline("utcDaliTextEditorMaxCharactersReached");
+   TextEditor editor = TextEditor::New();
+   DALI_TEST_CHECK( editor );
+   application.GetScene().Add( editor );
+   const int maxNumberOfCharacters = 1;
+   editor.SetProperty( DevelTextEditor::Property::MAX_LENGTH, maxNumberOfCharacters );
+   DALI_TEST_EQUALS( editor.GetProperty<int>( DevelTextEditor::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
+   editor.SetKeyInputFocus();
+   // connect to the text changed signal.
+   ConnectionTracker* testTracker = new ConnectionTracker();
+   DevelTextEditor::MaxLengthReachedSignal( editor ).Connect(&TestMaxLengthReachedCallback);
+   bool maxLengthReachedSignal = false;
+   editor.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
+   gMaxCharactersCallBackCalled = false;
+   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+   DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
+   DALI_TEST_CHECK( maxLengthReachedSignal );
+   END_TEST;
+ }
@@@ -35,7 -35,6 +35,6 @@@
  #include <dali-toolkit/devel-api/text/rendering-backend.h>
  #include <dali-toolkit/devel-api/controls/control-devel.h>
  #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
- #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
  #include <dali-toolkit/public-api/visuals/visual-properties.h>
  #include <dali-toolkit/internal/text/text-enumerations-impl.h>
  #include <dali-toolkit/internal/text/rendering/text-backend.h>
@@@ -138,9 -137,11 +137,11 @@@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolk
  DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableGrabHandle",               BOOLEAN,   ENABLE_GRAB_HANDLE                   )
  DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "matchSystemLanguageDirection",   BOOLEAN,   MATCH_SYSTEM_LANGUAGE_DIRECTION      )
  DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend",               INTEGER,   RENDERING_BACKEND                    )
+ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "maxLength",                      INTEGER,   MAX_LENGTH                           )
  
  DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged",        SIGNAL_TEXT_CHANGED )
  DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged",  SIGNAL_INPUT_STYLE_CHANGED )
+ DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "maxLengthReached",   SIGNAL_MAX_LENGTH_REACHED )
  
  DALI_TYPE_REGISTRATION_END()
  
@@@ -771,6 -772,17 +772,17 @@@ void TextEditor::SetProperty( BaseObjec
          }
          break;
        }
+       case Toolkit::DevelTextEditor::Property::MAX_LENGTH:
+       {
+         if( impl.mController )
+         {
+           const int max = value.Get< int >();
+           DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p MAX_LENGTH %d\n", impl.mController.Get(), max );
+           impl.mController->SetMaximumNumberOfCharacters( max );
+         }
+         break;
+       }
      } // switch
    } // texteditor
  }
@@@ -1171,6 -1183,14 +1183,14 @@@ Property::Value TextEditor::GetProperty
          }
          break;
        }
+       case Toolkit::DevelTextEditor::Property::MAX_LENGTH:
+       {
+         if( impl.mController )
+         {
+           value = impl.mController->GetMaximumNumberOfCharacters();
+         }
+         break;
+       }
      } //switch
    }
  
@@@ -1182,6 -1202,11 +1202,11 @@@ InputMethodContext TextEditor::GetInput
    return mInputMethodContext;
  }
  
+ DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal()
+ {
+   return mMaxLengthReachedSignal;
+ }
  bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
  {
    Dali::BaseHandle handle( object );
    {
      editor.InputStyleChangedSignal().Connect( tracker, functor );
    }
+   else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
+   {
+     if( editor )
+     {
+       Internal::TextEditor& editorImpl( GetImpl( editor ) );
+       editorImpl.MaxLengthReachedSignal().Connect( tracker, functor );
+     }
+   }
    else
    {
      // signalName does not match any signal
@@@ -1282,7 -1315,7 +1315,7 @@@ void TextEditor::OnInitialize(
    // Fill-parent area by default
    self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
    self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
 -  self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
 +  self.OnSceneSignal().Connect( this, &TextEditor::OnSceneConnect );
  
    DevelControl::SetInputMethodContext( *this, mInputMethodContext );
  
@@@ -1588,7 -1621,8 +1621,8 @@@ void TextEditor::TextChanged(
  
  void TextEditor::MaxLengthReached()
  {
-   // Nothing to do as TextEditor doesn't emit a max length reached signal.
+   Dali::Toolkit::TextEditor handle( GetOwner() );
+   mMaxLengthReachedSignal.Emit( handle );
  }
  
  void TextEditor::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
@@@ -1759,7 -1793,7 +1793,7 @@@ void TextEditor::OnScrollIndicatorAnima
    }
  }
  
 -void TextEditor::OnStageConnect( Dali::Actor actor )
 +void TextEditor::OnSceneConnect( Dali::Actor actor )
  {
    if ( mHasBeenStaged )
    {
@@@ -1807,20 -1841,20 +1841,20 @@@ void TextEditor::KeyboardStatusChanged(
    }
  }
  
 -void TextEditor::OnStageConnection( int depth )
 +void TextEditor::OnSceneConnection( int depth )
  {
    // Sets the depth to the visuals inside the text's decorator.
    mDecorator->SetTextDepth( depth );
  
    // The depth of the text renderer is set in the RenderText() called from OnRelayout().
  
 -  // Call the Control::OnStageConnection() to set the depth of the background.
 -  Control::OnStageConnection( depth );
 +  // Call the Control::OnSceneConnection() to set the depth of the background.
 +  Control::OnSceneConnection( depth );
  }
  
  bool TextEditor::OnTouched( Actor actor, const TouchData& touch )
  {
 -  return true;
 +  return false;
  }
  
  void TextEditor::OnIdleSignal()
@@@ -27,6 -27,7 +27,7 @@@
  #include <dali-toolkit/public-api/controls/control-impl.h>
  #include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
  #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
+ #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
  #include <dali-toolkit/internal/text/decorator/text-decorator.h>
  #include <dali-toolkit/internal/text/text-control-interface.h>
  #include <dali-toolkit/internal/text/text-editable-control-interface.h>
@@@ -80,6 -81,11 +81,11 @@@ public
    InputMethodContext GetInputMethodContext();
  
    /**
+    * @copydoc Dali::Toollkit::TextEditor::MaxLengthReachedSignal()
+    */
+   DevelTextEditor::MaxLengthReachedSignalType&  MaxLengthReachedSignal();
+   /**
     * Connects a callback function with the object's signals.
     * @param[in] object The object providing the signal.
     * @param[in] tracker Used to disconnect the signal.
@@@ -158,9 -164,9 +164,9 @@@ private: // From Contro
    virtual void OnLongPress( const LongPressGesture& gesture );
  
    /**
 -   * @copydoc Control::OnStageConnection()
 +   * @copydoc Control::OnSceneConnection()
     */
 -  virtual void OnStageConnection( int depth );
 +  virtual void OnSceneConnection( int depth );
  
    /**
     * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
@@@ -279,14 -285,15 +285,15 @@@ private: // Implementatio
     */
    void RenderText( Text::Controller::UpdateTextType updateTextType );
  
 -  // Connection needed to re-render text, when a text editor returns to the stage.
 -  void OnStageConnect( Dali::Actor actor );
 +  // Connection needed to re-render text, when a text editor returns to the scene.
 +  void OnSceneConnect( Dali::Actor actor );
  
  private: // Data
    // Signals
    Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
    Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
    Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
+   Toolkit::DevelTextEditor::MaxLengthReachedSignalType mMaxLengthReachedSignal;
  
    InputMethodContext mInputMethodContext;
    Text::ControllerPtr mController;