Merge "Add Placeholder Ellipsis in TextField" into devel/master
authorHyunJu Shin <hyunjushin@samsung.com>
Mon, 25 Sep 2017 06:59:26 +0000 (06:59 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Mon, 25 Sep 2017 06:59:26 +0000 (06:59 +0000)
1  2 
automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

@@@ -100,6 -100,7 +100,7 @@@ const char* const PROPERTY_NAME_HIDDEN_
  const char* const PROPERTY_NAME_PIXEL_SIZE                           = "pixelSize";
  const char* const PROPERTY_NAME_ENABLE_SELECTION                     = "enableSelection";
  const char* const PROPERTY_NAME_PLACEHOLDER                          = "placeholder";
+ const char* const PROPERTY_NAME_ELLIPSIS                             = "ellipsis";
  
  const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
  
@@@ -513,6 -514,7 +514,7 @@@ int UtcDaliTextFieldGetPropertyP(void
    DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == DevelTextField::Property::PIXEL_SIZE );
    DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == DevelTextField::Property::ENABLE_SELECTION );
    DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == DevelTextField::Property::PLACEHOLDER );
+   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == DevelTextField::Property::ELLIPSIS );
  
    END_TEST;
  }
@@@ -827,19 -829,8 +829,19 @@@ int UtcDaliTextFieldSetPropertyP(void
    DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
  
    // Check the outline property
 -  field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
 -  DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
 +  Property::Map outlineMapSet;
 +  Property::Map outlineMapGet;
 +
 +  outlineMapSet["color"] = Color::RED;
 +  outlineMapSet["width"] = 2.0f;
 +
 +  field.SetProperty( TextField::Property::OUTLINE, outlineMapSet );
 +
 +  outlineMapSet["color"] = "red";
 +  outlineMapSet["width"] = "2";
 +  outlineMapGet = field.GetProperty<Property::Map>( TextField::Property::OUTLINE );
 +  DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION );
 +  DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION );
  
    // Check the input outline property
    field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
    placeholderPixelSizeMapSet["placeholderColor"] = Color::BLUE;
    placeholderPixelSizeMapSet["placeholderFontFamily"] = "Arial";
    placeholderPixelSizeMapSet["placeholderPixelSize"] = 15.0f;
+   placeholderPixelSizeMapSet["placeholderEllipsis"] = true;
  
    placeholderFontstyleMap.Insert( "weight", "bold" );
    placeholderPixelSizeMapSet["placeholderFontStyle"] = placeholderFontstyleMap;
    placeholderMapSet["placeholderColor"] = Color::RED;
    placeholderMapSet["placeholderFontFamily"] = "Arial";
    placeholderMapSet["placeholderPointSize"] = 12.0f;
+   placeholderMapSet["placeholderEllipsis"] = false;
  
    // Check the placeholder font style property
    placeholderFontstyleMap.Clear();
    DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
    DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
  
+   // Check the ellipsis property
+   DALI_TEST_CHECK( !field.GetProperty<bool>( DevelTextField::Property::ELLIPSIS ) );
+   field.SetProperty( DevelTextField::Property::ELLIPSIS, true );
+   DALI_TEST_CHECK( field.GetProperty<bool>( DevelTextField::Property::ELLIPSIS ) );
    END_TEST;
  }
  
index 482cfc3,4ca2d9a..4cc9d90
mode 100755,100644..100755
@@@ -54,6 -54,7 +54,7 @@@ const char * const PLACEHOLDER_FONT_FAM
  const char * const PLACEHOLDER_FONT_STYLE = "placeholderFontStyle";
  const char * const PLACEHOLDER_POINT_SIZE = "placeholderPointSize";
  const char * const PLACEHOLDER_PIXEL_SIZE = "placeholderPixelSize";
+ const char * const PLACEHOLDER_ELLIPSIS = "placeholderEllipsis";
  
  float ConvertToEven( float value )
  {
@@@ -430,6 -431,24 +431,24 @@@ bool Controller::IsTextElideEnabled() c
    return mImpl->mModel->mElideEnabled;
  }
  
+ void Controller::SetPlaceholderTextElideEnabled( bool enabled )
+ {
+   mImpl->mEventData->mIsPlaceholderElideEnabled = enabled;
+   mImpl->mEventData->mPlaceholderEllipsisFlag = true;
+   // Update placeholder if there is no text
+   if( mImpl->IsShowingPlaceholderText() ||
+       ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
+   {
+     ShowPlaceholderText();
+   }
+ }
+ bool Controller::IsPlaceholderTextElideEnabled() const
+ {
+   return mImpl->mEventData->mIsPlaceholderElideEnabled;
+ }
  void Controller::SetSelectionEnabled( bool enabled )
  {
    mImpl->mEventData->mSelectionEnabled = enabled;
@@@ -1129,30 -1148,6 +1148,30 @@@ float Controller::GetUnderlineHeight() 
    return mImpl->mModel->mVisualModel->GetUnderlineHeight();
  }
  
 +void Controller::SetOutlineColor( const Vector4& color )
 +{
 +  mImpl->mModel->mVisualModel->SetOutlineColor( color );
 +
 +  mImpl->RequestRelayout();
 +}
 +
 +const Vector4& Controller::GetOutlineColor() const
 +{
 +  return mImpl->mModel->mVisualModel->GetOutlineColor();
 +}
 +
 +void Controller::SetOutlineWidth( float width )
 +{
 +  mImpl->mModel->mVisualModel->SetOutlineWidth( width );
 +
 +  mImpl->RequestRelayout();
 +}
 +
 +float Controller::GetOutlineWidth() const
 +{
 +  return mImpl->mModel->mVisualModel->GetOutlineWidth();
 +}
 +
  void Controller::SetDefaultEmbossProperties( const std::string& embossProperties )
  {
    if( NULL == mImpl->mEmbossDefaults )
@@@ -2006,6 -2001,12 +2025,12 @@@ void Controller::SetPlaceholderProperty
          SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
        }
      }
+     else if( key == PLACEHOLDER_ELLIPSIS )
+     {
+       bool ellipsis;
+       value.Get( ellipsis );
+       SetPlaceholderTextElideEnabled( ellipsis );
+     }
    }
  }
  
@@@ -2038,6 -2039,11 +2063,11 @@@ void Controller::GetPlaceholderProperty
      {
        map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
      }
+     if( mImpl->mEventData->mPlaceholderEllipsisFlag )
+     {
+       map[ PLACEHOLDER_ELLIPSIS ] = IsPlaceholderTextElideEnabled();
+     }
    }
  }
  
@@@ -2095,6 -2101,20 +2125,20 @@@ Controller::UpdateTextType Controller::
                                                               COLOR );
    }
  
+   // Set the update info to elide the text.
+   if( mImpl->mModel->mElideEnabled ||
+       ( ( NULL != mImpl->mEventData ) && mImpl->mEventData->mIsPlaceholderElideEnabled ) )
+   {
+     // Update Text layout for applying elided
+     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
+                                                              ALIGN                     |
+                                                              LAYOUT                    |
+                                                              UPDATE_LAYOUT_SIZE        |
+                                                              REORDER );
+     mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
+     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
+   }
    // Make sure the model is up-to-date before layouting.
    ProcessModifyEvents();
    bool updated = mImpl->UpdateModel( mImpl->mOperationsPending );
@@@ -3279,13 -3299,35 +3323,35 @@@ bool Controller::DoRelayout( const Size
      layoutParameters.startLineIndex = mImpl->mTextUpdateInfo.mStartLineIndex;
      layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
  
+     // Update the ellipsis
+     bool elideTextEnabled = mImpl->mModel->mElideEnabled;
+     if( NULL != mImpl->mEventData )
+     {
+       if( mImpl->mEventData->mPlaceholderEllipsisFlag && mImpl->IsShowingPlaceholderText() )
+       {
+         elideTextEnabled = mImpl->mEventData->mIsPlaceholderElideEnabled;
+       }
+       else if( EventData::INACTIVE != mImpl->mEventData->mState )
+       {
+         // Disable ellipsis when editing
+         elideTextEnabled = false;
+       }
+       // Reset the scroll position in inactive state
+       if( elideTextEnabled && ( mImpl->mEventData->mState == EventData::INACTIVE ) )
+       {
+         ResetScrollPosition();
+       }
+     }
      // Update the visual model.
      Size newLayoutSize;
      viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
                                                     glyphPositions,
                                                     mImpl->mModel->mVisualModel->mLines,
                                                     newLayoutSize,
-                                                    mImpl->mModel->mElideEnabled );
+                                                    elideTextEnabled );
  
      viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
  
index 3d0eb6c,609fe7a..b02bb68
mode 100755,100644..100755
@@@ -369,6 -369,18 +369,18 @@@ public: // Configure the text controlle
    bool IsTextElideEnabled() const;
  
    /**
+    * @brief Enable or disable the placeholder text elide.
+    * @param enabled Whether to enable the placeholder text elide.
+    */
+   void SetPlaceholderTextElideEnabled( bool enabled );
+   /**
+    * @brief Whether the placeholder text elide property is enabled.
+    * @return True if the placeholder text elide property is enabled, false otherwise.
+    */
+   bool IsPlaceholderTextElideEnabled() const;
+   /**
     * @brief Enable or disable the text selection.
     * @param[in] enabled Whether to enable the text selection.
     */
@@@ -777,34 -789,6 +789,34 @@@ public: // Default style & Input styl
    float GetUnderlineHeight() const;
  
    /**
 +   * @brief Set the outline color.
 +   *
 +   * @param[in] color color of outline.
 +   */
 +  void SetOutlineColor( const Vector4& color );
 +
 +  /**
 +   * @brief Retrieve the outline color.
 +   *
 +   * @return The outline color.
 +   */
 +  const Vector4& GetOutlineColor() const;
 +
 +  /**
 +   * @brief Set the outline width
 +   *
 +   * @param[in] width The width in pixels of the outline, 0 indicates no outline
 +   */
 +  void SetOutlineWidth( float width );
 +
 +  /**
 +   * @brief Retrieves the width of an outline
 +   *
 +   * @return The width of the outline.
 +   */
 +  float GetOutlineWidth() const;
 +
 +  /**
     * @brief Sets the emboss's properties string.
     *
     * @note The string is stored to be recovered.