[Tizen] Revert "Changes after touch consumed behaviour change"
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.cpp
index bf4f766..7f218f2 100644 (file)
@@ -38,6 +38,8 @@
 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/controls/text-controls/autofill-container-impl.h>
 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
 #include <dali-toolkit/internal/text/rendering/text-backend.h>
 #include <dali-toolkit/internal/text/text-effects-style.h>
@@ -135,6 +137,9 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup",
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground",                 VECTOR4,   BACKGROUND                           )
 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText",         STRING,    SELECTED_TEXT                        )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend",               INTEGER,   RENDERING_BACKEND                    )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart",              INTEGER,   SELECTED_TEXT_START                  )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd",                INTEGER,   SELECTED_TEXT_END                    )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableEditing",                  BOOLEAN,   ENABLE_EDITING                       )
 
 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged",        SIGNAL_TEXT_CHANGED )
 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached",   SIGNAL_MAX_LENGTH_REACHED )
@@ -709,6 +714,33 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr
         impl.mController->SetBackgroundColor( backgroundColor );
         break;
       }
+      case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
+      {
+        if( impl.mController )
+        {
+          uint32_t start = static_cast<uint32_t>(value.Get< int >());
+          DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
+          impl.SetTextSelectionRange( &start, nullptr );
+        }
+        break;
+      }
+      case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
+      {
+        if( impl.mController )
+        {
+          uint32_t end = static_cast<uint32_t>(value.Get< int >());
+          DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
+          impl.SetTextSelectionRange( nullptr, &end );
+        }
+        break;
+      }
+      case Toolkit::DevelTextField::Property::ENABLE_EDITING:
+      {
+        const bool editable = value.Get< bool >();
+        DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_EDITING %d\n", impl.mController.Get(), editable );
+        impl.SetEditable( editable );
+        break;
+      }
     } // switch
   } // textfield
 }
@@ -1032,6 +1064,23 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde
         value = impl.mController->GetSelectedText( );
         break;
       }
+      case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
+      {
+        Uint32Pair range = impl.GetTextSelectionRange( );
+        value = static_cast<int>(range.first);
+        break;
+      }
+      case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
+      {
+        Uint32Pair range = impl.GetTextSelectionRange( );
+        value = static_cast<int>(range.second);
+        break;
+      }
+      case Toolkit::DevelTextField::Property::ENABLE_EDITING:
+      {
+        value = impl.IsEditable();
+        break;
+      }
     } //switch
   }
 
@@ -1056,6 +1105,26 @@ void TextField::SelectNone()
   }
 }
 
+void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
+{
+  if( mController && mController->IsShowingRealText() )
+  {
+    mController->SetTextSelectionRange( start, end );
+    SetKeyInputFocus();
+  }
+}
+
+Uint32Pair TextField::GetTextSelectionRange() const
+{
+  Uint32Pair range;
+  if( mController && mController->IsShowingRealText() )
+  {
+    range = mController->GetTextSelectionRange();
+  }
+  return range;
+}
+
+
 InputMethodContext TextField::GetInputMethodContext()
 {
   return mInputMethodContext;
@@ -1108,7 +1177,7 @@ void TextField::OnInitialize()
 {
   Actor self = Self();
 
-  mController = Text::Controller::New( this, this );
+  mController = Text::Controller::New( this, this ,this);
 
   // When using the vector-based rendering, the size of the GLyphs are different
   TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
@@ -1404,7 +1473,7 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
 void TextField::OnKeyInputFocusGained()
 {
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
-  if ( mInputMethodContext )
+  if( mInputMethodContext && IsEditable() )
   {
     mInputMethodContext.ApplyOptions( mInputMethodOptions );
 
@@ -1418,13 +1487,30 @@ void TextField::OnKeyInputFocusGained()
     // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
     mInputMethodContext.SetRestoreAfterFocusLost( true );
   }
-  ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
 
-  if ( notifier )
+  ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
+  if( notifier )
   {
     notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
   }
 
+  Toolkit::Control control = Toolkit::Control::DownCast( Self() );
+  Internal::Control& controlImpl = GetImplementation( control );
+  Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );
+  bool enableAutofill = controlDataImpl.IsAutofillEnabled();
+  if( enableAutofill )
+  {
+    Toolkit::AutofillContainer container = controlDataImpl.GetAutofillContainer();
+    container.SetFocusedControl( control );
+
+    Internal::AutofillContainer& containerImpl = GetImpl( container );
+    Dali::AutofillGroup containerGroup = containerImpl.GetAutofillGroup();
+    if( containerGroup != nullptr )
+    {
+      containerGroup.RequestAuthentication();
+    }
+
+  }
   mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
 
   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
@@ -1459,7 +1545,7 @@ void TextField::OnKeyInputFocusLost()
 void TextField::OnTap( const TapGesture& gesture )
 {
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
-  if ( mInputMethodContext )
+  if ( mInputMethodContext && IsEditable() )
   {
     mInputMethodContext.Activate();
   }
@@ -1479,7 +1565,7 @@ void TextField::OnPan( const PanGesture& gesture )
 
 void TextField::OnLongPress( const LongPressGesture& gesture )
 {
-  if ( mInputMethodContext )
+  if ( mInputMethodContext && IsEditable() )
   {
     mInputMethodContext.Activate();
   }
@@ -1519,6 +1605,20 @@ void TextField::RequestTextRelayout()
   RelayoutRequest();
 }
 
+bool TextField::IsEditable() const
+{
+  return mController->IsEditable();
+}
+
+void TextField::SetEditable( bool editable )
+{
+  mController->SetEditable(editable);
+  if ( mInputMethodContext && !editable )
+  {
+    mInputMethodContext.Deactivate();
+  }
+}
+
 void TextField::TextChanged()
 {
   Dali::Toolkit::TextField handle( GetOwner() );
@@ -1682,7 +1782,7 @@ void TextField::OnSceneConnection( int depth )
 
 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
 {
-  return false;
+  return true;
 }
 
 void TextField::OnIdleSignal()