Outline effect has been fixed to be not front cropped.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index 4cc9d90..7847fb9 100755 (executable)
@@ -27,6 +27,7 @@
 #include <dali/devel-api/text-abstraction/font-client.h>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/public-api/controls/text-controls/placeholder-properties.h>
 #include <dali-toolkit/internal/text/bidirectional-support.h>
 #include <dali-toolkit/internal/text/character-set-conversion.h>
 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
@@ -47,14 +48,14 @@ const float MAX_FLOAT = std::numeric_limits<float>::max();
 
 const std::string EMPTY_STRING("");
 
-const char * const PLACEHOLDER_TEXT = "placeholderText";
-const char * const PLACEHOLDER_TEXT_FOCUSED = "placeholderTextFocused";
-const char * const PLACEHOLDER_COLOR = "placeholderColor";
-const char * const PLACEHOLDER_FONT_FAMILY = "placeholderFontFamily";
-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";
+const char * const PLACEHOLDER_TEXT = "text";
+const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
+const char * const PLACEHOLDER_COLOR = "color";
+const char * const PLACEHOLDER_FONT_FAMILY = "fontFamily";
+const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
+const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
+const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
+const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
 
 float ConvertToEven( float value )
 {
@@ -356,7 +357,7 @@ bool Controller::IsMultiLineEnabled() const
   return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
 }
 
-void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
+void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignment )
 {
   if( alignment != mImpl->mModel->mHorizontalAlignment )
   {
@@ -370,12 +371,12 @@ void Controller::SetHorizontalAlignment( Layout::HorizontalAlignment alignment )
   }
 }
 
-Layout::HorizontalAlignment Controller::GetHorizontalAlignment() const
+Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
 {
   return mImpl->mModel->mHorizontalAlignment;
 }
 
-void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
+void Controller::SetVerticalAlignment( VerticalAlignment::Type alignment )
 {
   if( alignment != mImpl->mModel->mVerticalAlignment )
   {
@@ -388,12 +389,12 @@ void Controller::SetVerticalAlignment( Layout::VerticalAlignment alignment )
   }
 }
 
-Layout::VerticalAlignment Controller::GetVerticalAlignment() const
+VerticalAlignment::Type Controller::GetVerticalAlignment() const
 {
   return mImpl->mModel->mVerticalAlignment;
 }
 
-void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode )
+void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode )
 {
   if( lineWrapMode != mImpl->mModel->mLineWrapMode )
   {
@@ -416,7 +417,7 @@ void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode )
   }
 }
 
-Layout::LineWrap::Mode Controller::GetLineWrapMode() const
+Text::LineWrap::Mode Controller::GetLineWrapMode() const
 {
   return mImpl->mModel->mLineWrapMode;
 }
@@ -1112,6 +1113,21 @@ const Vector4& Controller::GetShadowColor() const
   return mImpl->mModel->mVisualModel->GetShadowColor();
 }
 
+void Controller::SetShadowBlurRadius( const float& shadowBlurRadius )
+{
+  if ( fabsf( GetShadowBlurRadius() - shadowBlurRadius ) > Math::MACHINE_EPSILON_1 )
+  {
+    mImpl->mModel->mVisualModel->SetShadowBlurRadius( shadowBlurRadius );
+
+    mImpl->RequestRelayout();
+  }
+}
+
+const float& Controller::GetShadowBlurRadius() const
+{
+  return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
+}
+
 void Controller::SetUnderlineColor( const Vector4& color )
 {
   mImpl->mModel->mVisualModel->SetUnderlineColor( color );
@@ -1750,6 +1766,16 @@ void Controller::ShadowSetByString( bool setByString )
   mImpl->mShadowSetByString = setByString;
 }
 
+bool Controller::IsOutlineSetByString()
+{
+  return mImpl->mOutlineSetByString;
+}
+
+void Controller::OutlineSetByString( bool setByString )
+{
+  mImpl->mOutlineSetByString = setByString;
+}
+
 bool Controller::IsFontStyleSetByString()
 {
   return mImpl->mFontStyleSetByString;
@@ -1976,19 +2002,19 @@ void Controller::SetPlaceholderProperty( const Property::Map& map )
     Property::Key& key = keyValue.first;
     Property::Value& value = keyValue.second;
 
-    if( key == PLACEHOLDER_TEXT )
+    if( key == Toolkit::Text::PlaceHolder::Property::TEXT  || key == PLACEHOLDER_TEXT )
     {
       std::string text = "";
       value.Get( text );
       SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
     }
-    else if( key == PLACEHOLDER_TEXT_FOCUSED )
+    else if( key == Toolkit::Text::PlaceHolder::Property::TEXT_FOCUSED || key == PLACEHOLDER_TEXT_FOCUSED )
     {
       std::string text = "";
       value.Get( text );
       SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
     }
-    else if( key == PLACEHOLDER_COLOR )
+    else if( key == Toolkit::Text::PlaceHolder::Property::COLOR || key == PLACEHOLDER_COLOR )
     {
       Vector4 textColor;
       value.Get( textColor );
@@ -1997,17 +2023,17 @@ void Controller::SetPlaceholderProperty( const Property::Map& map )
         SetPlaceholderTextColor( textColor );
       }
     }
-    else if( key == PLACEHOLDER_FONT_FAMILY )
+    else if( key == Toolkit::Text::PlaceHolder::Property::FONT_FAMILY || key == PLACEHOLDER_FONT_FAMILY )
     {
       std::string fontFamily = "";
       value.Get( fontFamily );
       SetPlaceholderFontFamily( fontFamily );
     }
-    else if( key == PLACEHOLDER_FONT_STYLE )
+    else if( key == Toolkit::Text::PlaceHolder::Property::FONT_STYLE || key == PLACEHOLDER_FONT_STYLE )
     {
       SetFontStyleProperty( this, value, Text::FontStyle::PLACEHOLDER );
     }
-    else if( key == PLACEHOLDER_POINT_SIZE )
+    else if( key == Toolkit::Text::PlaceHolder::Property::POINT_SIZE || key == PLACEHOLDER_POINT_SIZE )
     {
       float pointSize;
       value.Get( pointSize );
@@ -2016,7 +2042,7 @@ void Controller::SetPlaceholderProperty( const Property::Map& map )
         SetPlaceholderTextFontSize( pointSize, Text::Controller::POINT_SIZE );
       }
     }
-    else if( key == PLACEHOLDER_PIXEL_SIZE )
+    else if( key == Toolkit::Text::PlaceHolder::Property::PIXEL_SIZE || key == PLACEHOLDER_PIXEL_SIZE )
     {
       float pixelSize;
       value.Get( pixelSize );
@@ -2025,7 +2051,7 @@ void Controller::SetPlaceholderProperty( const Property::Map& map )
         SetPlaceholderTextFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
       }
     }
-    else if( key == PLACEHOLDER_ELLIPSIS )
+    else if( key == Toolkit::Text::PlaceHolder::Property::ELLIPSIS || key == PLACEHOLDER_ELLIPSIS )
     {
       bool ellipsis;
       value.Get( ellipsis );
@@ -2040,33 +2066,33 @@ void Controller::GetPlaceholderProperty( Property::Map& map )
   {
     if( !mImpl->mEventData->mPlaceholderTextActive.empty() )
     {
-      map[ PLACEHOLDER_TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
+      map[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = mImpl->mEventData->mPlaceholderTextActive;
     }
     if( !mImpl->mEventData->mPlaceholderTextInactive.empty() )
     {
-      map[ PLACEHOLDER_TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
+      map[ Text::PlaceHolder::Property::TEXT ] = mImpl->mEventData->mPlaceholderTextInactive;
     }
 
-    map[ PLACEHOLDER_COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
-    map[ PLACEHOLDER_FONT_FAMILY ] = GetPlaceholderFontFamily();
+    map[ Text::PlaceHolder::Property::COLOR ] = mImpl->mEventData->mPlaceholderTextColor;
+    map[ Text::PlaceHolder::Property::FONT_FAMILY ] = GetPlaceholderFontFamily();
 
     Property::Value fontStyleMapGet;
     GetFontStyleProperty( this, fontStyleMapGet, Text::FontStyle::PLACEHOLDER );
-    map[ PLACEHOLDER_FONT_STYLE ] = fontStyleMapGet;
+    map[ Text::PlaceHolder::Property::FONT_STYLE ] = fontStyleMapGet;
 
     // Choose font size : POINT_SIZE or PIXEL_SIZE
     if( !mImpl->mEventData->mIsPlaceholderPixelSize )
     {
-      map[ PLACEHOLDER_POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
+      map[ Text::PlaceHolder::Property::POINT_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::POINT_SIZE );
     }
     else
     {
-      map[ PLACEHOLDER_PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
+      map[ Text::PlaceHolder::Property::PIXEL_SIZE ] = GetPlaceholderTextFontSize( Text::Controller::PIXEL_SIZE );
     }
 
     if( mImpl->mEventData->mPlaceholderEllipsisFlag )
     {
-      map[ PLACEHOLDER_ELLIPSIS ] = IsPlaceholderTextElideEnabled();
+      map[ Text::PlaceHolder::Property::ELLIPSIS ] = IsPlaceholderTextElideEnabled();
     }
   }
 }
@@ -2304,7 +2330,7 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
       // Do nothing.
       return false;
     }
-    else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode )
+    else if( Dali::DALI_KEY_ESCAPE == keyCode || Dali::DALI_KEY_BACK == keyCode  || Dali::DALI_KEY_SEARCH == keyCode )
     {
       // Do nothing
       return false;
@@ -3293,6 +3319,7 @@ bool Controller::DoRelayout( const Size& size,
     const Vector<CharacterIndex>& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters;
     const Vector<Length>& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph;
     const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin();
+    float outlineWidth = mImpl->mModel->GetOutlineWidth();
 
     // Set the layout parameters.
     Layout::Parameters layoutParameters( size,
@@ -3307,7 +3334,8 @@ bool Controller::DoRelayout( const Size& size,
                                          glyphsPerCharacterBuffer,
                                          totalNumberOfGlyphs,
                                          mImpl->mModel->mHorizontalAlignment,
-                                         mImpl->mModel->mLineWrapMode );
+                                         mImpl->mModel->mLineWrapMode,
+                                         outlineWidth );
 
     // Resize the vector of positions to have the same size than the vector of glyphs.
     Vector<Vector2>& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions;
@@ -3450,17 +3478,17 @@ void Controller::CalculateVerticalOffset( const Size& controlSize )
 
   switch( mImpl->mModel->mVerticalAlignment )
   {
-    case Layout::VERTICAL_ALIGN_TOP:
+    case VerticalAlignment::TOP:
     {
       mImpl->mModel->mScrollPosition.y = 0.f;
       break;
     }
-    case Layout::VERTICAL_ALIGN_CENTER:
+    case VerticalAlignment::CENTER:
     {
       mImpl->mModel->mScrollPosition.y = floorf( 0.5f * ( controlSize.height - layoutSize.height ) ); // try to avoid pixel alignment.
       break;
     }
-    case Layout::VERTICAL_ALIGN_BOTTOM:
+    case VerticalAlignment::BOTTOM:
     {
       mImpl->mModel->mScrollPosition.y = controlSize.height - layoutSize.height;
       break;