(Text Controller) Moved ShowPlaceholder method into PlaceholderHandler 08/248708/2
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 1 Dec 2020 20:33:59 +0000 (20:33 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 1 Dec 2020 21:38:00 +0000 (21:38 +0000)
Change-Id: I3733c34fd78ef6e43d006c8e032fd0869a136f0a

dali-toolkit/internal/text/text-controller-placeholder-handler.cpp
dali-toolkit/internal/text/text-controller-placeholder-handler.h
dali-toolkit/internal/text/text-controller.cpp

index f567cbd..793a3e6 100644 (file)
@@ -23,6 +23,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
+#include <dali-toolkit/internal/text/character-set-conversion.h>
 #include <dali-toolkit/internal/text/text-controller-impl.h>
 #include <dali-toolkit/internal/text/text-font-style.h>
 
 #include <dali-toolkit/internal/text/text-controller-impl.h>
 #include <dali-toolkit/internal/text/text-font-style.h>
 
@@ -454,6 +455,89 @@ void Controller::PlaceholderHandler::GetPlaceholderProperty(Controller& controll
   }
 }
 
   }
 }
 
+void Controller::PlaceholderHandler::ShowPlaceholderText(Controller& controller)
+{
+  Controller::Impl& impl = *controller.mImpl;
+
+  if( impl.IsPlaceholderAvailable() )
+  {
+    EventData*& eventData = impl.mEventData;
+    DALI_ASSERT_DEBUG( eventData && "No placeholder text available" );
+
+    if( NULL == eventData )
+    {
+      return;
+    }
+
+    eventData->mIsShowingPlaceholderText = true;
+
+    // Disable handles when showing place-holder text
+    DecoratorPtr& decorator = eventData->mDecorator;
+    decorator->SetHandleActive( GRAB_HANDLE, false );
+    decorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
+    decorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
+
+    const char* text( NULL );
+    size_t size( 0 );
+
+    // TODO - Switch Placeholder text when changing state
+    std::string& placeholderTextActive = eventData->mPlaceholderTextActive;
+    if( ( EventData::INACTIVE != eventData->mState ) &&
+        ( 0u != placeholderTextActive.c_str() ) )
+    {
+      text = placeholderTextActive.c_str();
+      size = placeholderTextActive.size();
+    }
+    else
+    {
+      std::string& placeholderTextInactive = eventData->mPlaceholderTextInactive;
+      text = placeholderTextInactive.c_str();
+      size = placeholderTextInactive.size();
+    }
+
+    TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
+    textUpdateInfo.mCharacterIndex = 0u;
+    textUpdateInfo.mNumberOfCharactersToRemove = textUpdateInfo.mPreviousNumberOfCharacters;
+
+    // Reset model for showing placeholder.
+    ModelPtr& model = impl.mModel;
+    LogicalModelPtr& logicalModel = model->mLogicalModel;
+    logicalModel->mText.Clear();
+    model->mVisualModel->SetTextColor( eventData->mPlaceholderTextColor );
+
+    // Convert text into UTF-32
+    Vector<Character>& utf32Characters = logicalModel->mText;
+    utf32Characters.Resize( size );
+
+    // This is a bit horrible but std::string returns a (signed) char*
+    const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
+
+    // Transform a text array encoded in utf8 into an array encoded in utf32.
+    // It returns the actual number of characters.
+    const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
+    utf32Characters.Resize( characterCount );
+
+    // The characters to be added.
+    textUpdateInfo.mNumberOfCharactersToAdd = characterCount;
+
+    // Reset the cursor position
+    eventData->mPrimaryCursorPosition = 0;
+
+    // The natural size needs to be re-calculated.
+    impl.mRecalculateNaturalSize = true;
+
+    // The text direction needs to be updated.
+    impl.mUpdateTextDirection = true;
+
+    // Apply modifications to the model
+    impl.mOperationsPending = ALL_OPERATIONS;
+
+    // Update the rest of the model during size negotiation
+    impl.QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
+  }
+}
+
+
 } // namespace Text
 
 } // namespace Toolkit
 } // namespace Text
 
 } // namespace Toolkit
index 273c69b..74ee933 100644 (file)
@@ -58,6 +58,7 @@ struct Controller::PlaceholderHandler
   static const Vector4& GetPlaceholderTextColor(const Controller& controller);
   static void SetPlaceholderProperty(Controller& controller, const Property::Map& map );
   static void GetPlaceholderProperty(Controller& controller, Property::Map& map);
   static const Vector4& GetPlaceholderTextColor(const Controller& controller);
   static void SetPlaceholderProperty(Controller& controller, const Property::Map& map );
   static void GetPlaceholderProperty(Controller& controller, Property::Map& map);
+  static void ShowPlaceholderText(Controller& controller);
 };
 
 } // namespace Text
 };
 
 } // namespace Text
index 8a08051..0fd084c 100644 (file)
@@ -1741,7 +1741,7 @@ bool Controller::GetTextScrollInfo( float& scrollPosition, float& controlHeight,
   return isScrolled;
 }
 
   return isScrolled;
 }
 
-void Controller::SetHiddenInputOption(const Property::Map& options )
+void Controller::SetHiddenInputOption(const Property::Map& options)
 {
   if( NULL == mImpl->mHiddenInput )
   {
 {
   if( NULL == mImpl->mHiddenInput )
   {
@@ -1750,7 +1750,7 @@ void Controller::SetHiddenInputOption(const Property::Map& options )
   mImpl->mHiddenInput->SetProperties(options);
 }
 
   mImpl->mHiddenInput->SetProperties(options);
 }
 
-void Controller::GetHiddenInputOption(Property::Map& options )
+void Controller::GetHiddenInputOption(Property::Map& options)
 {
   if( NULL != mImpl->mHiddenInput )
   {
 {
   if( NULL != mImpl->mHiddenInput )
   {
@@ -2555,75 +2555,7 @@ void Controller::ResetText()
 
 void Controller::ShowPlaceholderText()
 {
 
 void Controller::ShowPlaceholderText()
 {
-  if( mImpl->IsPlaceholderAvailable() )
-  {
-    DALI_ASSERT_DEBUG( mImpl->mEventData && "No placeholder text available" );
-
-    if( NULL == mImpl->mEventData )
-    {
-      return;
-    }
-
-    mImpl->mEventData->mIsShowingPlaceholderText = true;
-
-    // Disable handles when showing place-holder text
-    mImpl->mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false );
-    mImpl->mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false );
-    mImpl->mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false );
-
-    const char* text( NULL );
-    size_t size( 0 );
-
-    // TODO - Switch Placeholder text when changing state
-    if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
-        ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
-    {
-      text = mImpl->mEventData->mPlaceholderTextActive.c_str();
-      size = mImpl->mEventData->mPlaceholderTextActive.size();
-    }
-    else
-    {
-      text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
-      size = mImpl->mEventData->mPlaceholderTextInactive.size();
-    }
-
-    mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
-    mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
-
-    // Reset model for showing placeholder.
-    mImpl->mModel->mLogicalModel->mText.Clear();
-    mImpl->mModel->mVisualModel->SetTextColor( mImpl->mEventData->mPlaceholderTextColor );
-
-    // Convert text into UTF-32
-    Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
-    utf32Characters.Resize( size );
-
-    // This is a bit horrible but std::string returns a (signed) char*
-    const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text );
-
-    // Transform a text array encoded in utf8 into an array encoded in utf32.
-    // It returns the actual number of characters.
-    const Length characterCount = Utf8ToUtf32( utf8, size, utf32Characters.Begin() );
-    utf32Characters.Resize( characterCount );
-
-    // The characters to be added.
-    mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = characterCount;
-
-    // Reset the cursor position
-    mImpl->mEventData->mPrimaryCursorPosition = 0;
-
-    // The natural size needs to be re-calculated.
-    mImpl->mRecalculateNaturalSize = true;
-
-    // The text direction needs to be updated.
-    mImpl->mUpdateTextDirection = true;
-
-    // Apply modifications to the model
-    mImpl->mOperationsPending = ALL_OPERATIONS;
-
-    // Update the rest of the model during size negotiation
-    mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
-  }
+  PlaceholderHandler::ShowPlaceholderText(*this);
 }
 
 void Controller::ClearFontData()
 }
 
 void Controller::ClearFontData()