Merge "DALi Version 1.2.42" into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 2 Jun 2017 14:13:59 +0000 (14:13 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Fri, 2 Jun 2017 14:13:59 +0000 (14:13 +0000)
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h
dali-toolkit/devel-api/controls/text-controls/text-label-devel.h
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index 5cacd19..9fd6789 100644 (file)
@@ -27,6 +27,7 @@
 #include <dali/integration-api/events/pan-gesture-event.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
 
 using namespace Dali;
@@ -93,9 +94,13 @@ const char* const PROPERTY_NAME_ENABLE_SCROLL_BAR                    = "enableSc
 const char* const PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION             = "scrollBarShowDuration";
 const char* const PROPERTY_NAME_SCROLL_BAR_FADE_DURATION             = "scrollBarFadeDuration";
 const char* const PROPERTY_NAME_PIXEL_SIZE                           = "pixelSize";
+const char* const PROPERTY_NAME_LINE_COUNT                           = "lineCount";
+const char* const PROPERTY_NAME_PLACEHOLDER_TEXT                     = "placeholderText";
+const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR               = "placeholderTextColor";
 
 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
 
+const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
 
 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
@@ -433,6 +438,9 @@ int UtcDaliTextEditorGetPropertyP(void)
   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION );
   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION );
   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == DevelTextEditor::Property::PIXEL_SIZE );
+  DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_COUNT) == DevelTextEditor::Property::LINE_COUNT );
+  DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == DevelTextEditor::Property::PLACEHOLDER_TEXT );
+  DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR );
 
   END_TEST;
 }
@@ -725,6 +733,20 @@ int UtcDaliTextEditorSetPropertyP(void)
   editor.SetProperty( DevelTextEditor::Property::PIXEL_SIZE, 20.f );
   DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
 
+  // Check placeholder text properties.
+  editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
+  DALI_TEST_EQUALS( editor.GetProperty<std::string>( DevelTextEditor::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION );
+
+  // Check placeholder text properties when focused.
+  editor.SetProperty( DevelControl::Property::STATE, "FOCUSED" );
+  editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT, "Setting Focused Placeholder Text" );
+  DALI_TEST_EQUALS( editor.GetProperty<int>( DevelControl::Property::STATE ), (int)DevelControl::FOCUSED, TEST_LOCATION );
+  DALI_TEST_EQUALS( editor.GetProperty<std::string>( DevelTextEditor::Property::PLACEHOLDER_TEXT ), std::string("Setting Focused Placeholder Text"), TEST_LOCATION );
+
+  // Check placeholder text's color property.
+  editor.SetProperty( DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
+  DALI_TEST_EQUALS( editor.GetProperty<Vector4>( DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -1935,3 +1957,28 @@ int utcDaliTextEditorFontStylePropertyStringP(void)
 
   END_TEST;
 }
+int utcDaliTextEditorGetPropertyLinecountP(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline(" utcDaliTextEditorGetPropertyLinecount getting line count property");
+
+  int lineCount =0 ;
+
+  TextEditor editor = TextEditor::New();
+  editor.SetProperty( TextEditor::Property::POINT_SIZE, 10) ;
+  editor.SetProperty( TextEditor::Property::TEXT,
+                       "TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST ");
+
+  Stage::GetCurrent().Add( editor );
+
+  editor.SetSize( 100.0f, 100.0f );
+  lineCount =  editor.GetProperty<int>( DevelTextEditor::Property::LINE_COUNT );
+  DALI_TEST_EQUALS( lineCount, 14, TEST_LOCATION );
+
+  editor.SetSize( 50.0f, 100.0f );
+  lineCount =  editor.GetProperty<int>( DevelTextEditor::Property::LINE_COUNT );
+  DALI_TEST_EQUALS( lineCount, 28, TEST_LOCATION );
+
+  END_TEST;
+}
index cff3a39..473adba 100644 (file)
@@ -109,7 +109,26 @@ namespace Property
        * @brief The size of font in pixels.
        * @details name "pixelSize", type float
        */
-      PIXEL_SIZE
+      PIXEL_SIZE,
+
+      /**
+       * @brief The line count of text.
+       * @details name "lineCount", type int
+       * @note this property is read-only.
+       */
+      LINE_COUNT,
+
+      /**
+       * @brief The text to display when the TextEditor is empty and inactive.
+       * @details name "placeholderText", type string
+       */
+      PLACEHOLDER_TEXT,
+
+      /**
+       * @brief The placeholder-text color.
+       * @details name "placeholderTextColor", type vector4
+       */
+      PLACEHOLDER_TEXT_COLOR
   };
 } // namespace Property
 
index 40c6c70..12e9c75 100644 (file)
@@ -83,6 +83,13 @@ namespace Property
        *          values FINISH_LOOP, IMMEDIATE, defualt FINISH_LOOP
        */
       AUTO_SCROLL_STOP_MODE = OUTLINE + 4,
+
+      /*
+       * @brief The line count of text.
+       * @details name "lineCount", type int
+       * @node this property is read-only.
+       */
+      LINE_COUNT = OUTLINE + 5
   };
 } // namespace Property
 
index 5be99a6..e103702 100644 (file)
@@ -32,6 +32,7 @@
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/text/rendering-backend.h>
 #include <dali-toolkit/public-api/visuals/color-visual-properties.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/devel-api/visuals/visual-properties-devel.h>
@@ -134,6 +135,9 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableScrollBar",
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarShowDuration",          FLOAT,     SCROLL_BAR_SHOW_DURATION             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "scrollBarFadeDuration",          FLOAT,     SCROLL_BAR_FADE_DURATION             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pixelSize",                      FLOAT,     PIXEL_SIZE                           )
+DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "lineCount",            INTEGER,   LINE_COUNT                           )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderText",                STRING,    PLACEHOLDER_TEXT                     )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderTextColor",           VECTOR4,   PLACEHOLDER_TEXT_COLOR               )
 
 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged",        SIGNAL_TEXT_CHANGED )
 DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged",  SIGNAL_INPUT_STYLE_CHANGED )
@@ -660,6 +664,32 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P
         }
         break;
       }
+      case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT:
+      {
+        if( impl.mController )
+        {
+          const std::string& text = value.Get< std::string >();
+          DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor::OnPropertySet %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
+
+          impl.mController->SetPlaceholderText( text );
+        }
+        break;
+      }
+      case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR:
+      {
+        if( impl.mController )
+        {
+          const Vector4& textColor = value.Get< Vector4 >();
+          DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
+
+          if( impl.mController->GetPlaceholderTextColor() != textColor )
+          {
+            impl.mController->SetPlaceholderTextColor( textColor );
+            impl.mRenderer.Reset();
+          }
+        }
+        break;
+      }
     } // switch
   } // texteditor
 }
@@ -994,6 +1024,33 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind
         }
         break;
       }
+      case Toolkit::DevelTextEditor::Property::LINE_COUNT:
+      {
+        if( impl.mController )
+        {
+          float width = textEditor.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
+          value = impl.mController->GetLineCount( width );
+        }
+        break;
+      }
+      case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT:
+      {
+        if( impl.mController )
+        {
+          std::string text;
+          impl.mController->GetPlaceholderText( text );
+          value = text;
+        }
+        break;
+      }
+      case Toolkit::DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR:
+      {
+        if( impl.mController )
+        {
+          value = impl.mController->GetPlaceholderTextColor();
+        }
+        break;
+      }
     } //switch
   }
 
index ff6fc79..5f17f00 100644 (file)
@@ -117,7 +117,8 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline",                   MAP
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize",           FLOAT,   PIXEL_SIZE             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis",            BOOLEAN, ELLIPSIS               )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT,   AUTO_SCROLL_LOOP_DELAY )
-DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode",  STRING,  AUTO_SCROLL_STOP_MODE )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode",  STRING,  AUTO_SCROLL_STOP_MODE  )
+DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT             )
 
 DALI_TYPE_REGISTRATION_END()
 
@@ -736,6 +737,15 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
         }
         break;
       }
+      case Toolkit::DevelTextLabel::Property::LINE_COUNT:
+      {
+        if( impl.mController )
+        {
+          float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
+          value = impl.mController->GetLineCount( width );
+        }
+        break;
+      }
     }
   }
 
index d09e1ed..f119650 100644 (file)
@@ -70,6 +70,7 @@ namespace Text
 EventData::EventData( DecoratorPtr decorator )
 : mDecorator( decorator ),
   mImfManager(),
+  mPlaceholderText(),
   mPlaceholderTextActive(),
   mPlaceholderTextInactive(),
   mPlaceholderTextColor( 0.8f, 0.8f, 0.8f, 0.8f ),
index 3014edb..e9d99f1 100644 (file)
@@ -104,6 +104,7 @@ struct EventData
 
   DecoratorPtr       mDecorator;               ///< Pointer to the decorator.
   ImfManager         mImfManager;              ///< The Input Method Framework Manager.
+  std::string        mPlaceholderText;         ///< The text to display when the TextField is empty.
   std::string        mPlaceholderTextActive;   ///< The text to display when the TextField is empty with key-input focus.
   std::string        mPlaceholderTextInactive; ///< The text to display when the TextField is empty and inactive.
   Vector4            mPlaceholderTextColor;    ///< The in/active placeholder text color.
@@ -383,10 +384,9 @@ struct Controller::Impl
    */
   bool IsPlaceholderAvailable() const
   {
-    return ( mEventData &&
-             ( !mEventData->mPlaceholderTextInactive.empty() ||
-               !mEventData->mPlaceholderTextActive.empty() )
-           );
+    return ( mEventData && ( !mEventData->mPlaceholderText.empty() ||
+                             !mEventData->mPlaceholderTextInactive.empty() ||
+                             !mEventData->mPlaceholderTextActive.empty() ) );
   }
 
   bool IsShowingPlaceholderText() const
@@ -399,7 +399,8 @@ struct Controller::Impl
    */
   bool IsFocusedPlaceholderAvailable() const
   {
-    return ( mEventData && !mEventData->mPlaceholderTextActive.empty() );
+    return ( mEventData && ( !mEventData->mPlaceholderTextActive.empty() ||
+                             !mEventData->mPlaceholderText.empty() ) );
   }
 
   bool IsShowingRealText() const
index a502200..f9445b5 100644 (file)
@@ -512,6 +512,22 @@ void Controller::GetText( std::string& text ) const
   }
 }
 
+void Controller::SetPlaceholderText( const std::string& text )
+{
+  if( NULL != mImpl->mEventData )
+  {
+    mImpl->mEventData->mPlaceholderText = text;
+
+    // Update placeholder if there is no text
+    if( mImpl->IsShowingPlaceholderText() ||
+        ( 0u == mImpl->mModel->mLogicalModel->mText.Count() ) )
+    {
+      ShowPlaceholderText();
+    }
+  }
+}
+
+// This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
 void Controller::SetPlaceholderText( PlaceholderType type, const std::string& text )
 {
   if( NULL != mImpl->mEventData )
@@ -534,6 +550,15 @@ void Controller::SetPlaceholderText( PlaceholderType type, const std::string& te
   }
 }
 
+void Controller::GetPlaceholderText( std::string& text ) const
+{
+  if( NULL != mImpl->mEventData )
+  {
+    text = mImpl->mEventData->mPlaceholderText;
+  }
+}
+
+// This is overloading function for PLACEHOLDER_TEXT_FOCUSED in text-field
 void Controller::GetPlaceholderText( PlaceholderType type, std::string& text ) const
 {
   if( NULL != mImpl->mEventData )
@@ -1599,6 +1624,13 @@ float Controller::GetHeightForWidth( float width )
   return layoutSize.height;
 }
 
+int Controller::GetLineCount( float width )
+{
+  GetHeightForWidth( width );
+  int numberofLines = mImpl->mModel->GetNumberOfLines();
+  return numberofLines;
+}
+
 const ModelInterface* const Controller::GetTextModel() const
 {
   return mImpl->mModel.Get();
@@ -3195,17 +3227,27 @@ void Controller::ShowPlaceholderText()
     const char* text( NULL );
     size_t size( 0 );
 
-    // TODO - Switch placeholder text styles when changing state
-    if( ( EventData::INACTIVE != mImpl->mEventData->mState ) &&
-        ( 0u != mImpl->mEventData->mPlaceholderTextActive.c_str() ) )
+    if( !mImpl->mEventData->mPlaceholderTextActive.empty() || !mImpl->mEventData->mPlaceholderTextInactive.empty() )
     {
-      text = mImpl->mEventData->mPlaceholderTextActive.c_str();
-      size = mImpl->mEventData->mPlaceholderTextActive.size();
+      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();
+      }
     }
     else
     {
-      text = mImpl->mEventData->mPlaceholderTextInactive.c_str();
-      size = mImpl->mEventData->mPlaceholderTextInactive.size();
+      if( 0u != mImpl->mEventData->mPlaceholderText.c_str() )
+      {
+        text = mImpl->mEventData->mPlaceholderText.c_str();
+        size = mImpl->mEventData->mPlaceholderText.size();
+      }
     }
 
     mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
index 7562394..c6b01a4 100644 (file)
@@ -454,6 +454,13 @@ public: // Update.
   /**
    * @brief Replaces any placeholder text previously set.
    *
+   * @param[in] text A string of UTF-8 characters.
+   */
+  void SetPlaceholderText( const std::string& text );
+
+  /**
+   * @brief Replaces any placeholder text previously set.
+   *
    * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
    * @param[in] text A string of UTF-8 characters.
    */
@@ -462,6 +469,13 @@ public: // Update.
   /**
    * @brief Retrieve any placeholder text previously set.
    *
+   * @param[out] A string of UTF-8 characters.
+   */
+  void GetPlaceholderText( std::string& text ) const;
+
+  /**
+   * @brief Retrieve any placeholder text previously set.
+   *
    * @param[in] type Different placeholder-text can be shown when the control is active/inactive.
    * @param[out] A string of UTF-8 characters.
    */
@@ -910,6 +924,13 @@ public: // Queries & retrieves.
   float GetHeightForWidth( float width );
 
   /**
+   * @brief Retrieves the text's number of lines for a given width.
+   * @param[in] width The width of the text's area.
+   * @ return The number of lines.
+   */
+  int GetLineCount( float width );
+
+  /**
    * @brief Retrieves the text's model.
    *
    * @return A pointer to the text's model.