Added some keyboard & cursor plumbing 92/36892/5
authorPaul Wisbey <p.wisbey@samsung.com>
Mon, 16 Mar 2015 15:00:22 +0000 (15:00 +0000)
committerPaul Wisbey <p.wisbey@samsung.com>
Mon, 16 Mar 2015 18:15:00 +0000 (18:15 +0000)
Change-Id: Id7db01da8f8476f56873b5f97a5e07e046882fe9

dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
dali-toolkit/internal/controls/text-controls/text-field-impl.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index 5f8d498..fabfc7d 100644 (file)
@@ -26,6 +26,7 @@
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/object/type-registry-helper.h>
 #include <dali/integration-api/debug.h>
+#include <dali/public-api/adaptor-framework/virtual-keyboard.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/text/rendering-backend.h>
@@ -210,7 +211,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr
       {
         if( impl.mController )
         {
-          //impl.mController->SetEnableCursorBlink( value.Get< bool >() ); TODO
+          impl.mController->SetEnableCursorBlink( value.Get< bool >() );
         }
         break;
       }
@@ -324,7 +325,7 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde
       }
       case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
       {
-        //value = impl.mController->GetEnableCursorBlink(); TODO
+        value = impl.mController->GetEnableCursorBlink();
         break;
       }
       case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
@@ -450,8 +451,28 @@ void TextField::OnRelayout( const Vector2& size, ActorSizeContainer& container )
   }
 }
 
+void TextField::OnKeyInputFocusGained()
+{
+  VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
+
+  mController->KeyboardFocusGainEvent();
+}
+
+void TextField::OnKeyInputFocusLost()
+{
+  VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
+
+  mController->KeyboardFocusLostEvent();
+}
+
 void TextField::OnTap( const TapGesture& gesture )
 {
+  // Show the keyboard if it was hidden.
+  if (!VirtualKeyboard::IsVisible())
+  {
+    VirtualKeyboard::Show();
+  }
+
   SetKeyInputFocus();
 
   mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
@@ -500,6 +521,15 @@ void TextField::EnableClipping( bool clipping, const Vector2& size )
   }
 }
 
+void TextField::KeyboardStatusChanged(bool keyboardShown)
+{
+  // Just hide the grab handle when keyboard is hidden.
+  if (!keyboardShown )
+  {
+    mController->KeyboardFocusLostEvent();
+  }
+}
+
 TextField::TextField()
 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
index 5d103c9..4bec09d 100644 (file)
@@ -96,6 +96,16 @@ private: // From Control
   virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container );
 
   /**
+   * @copydoc Control::OnKeyInputFocusGained()
+   */
+  virtual void OnKeyInputFocusGained();
+
+  /**
+   * @copydoc Control::OnKeyInputFocusLost()
+   */
+  virtual void OnKeyInputFocusLost();
+
+  /**
    * Received for single & double taps
    */
   virtual void OnTap( const TapGesture& tap );
@@ -121,6 +131,13 @@ private: // Implementation
   void EnableClipping( bool clipping, const Vector2& size );
 
   /**
+   * @brief Callback when keyboard is shown/hidden.
+   *
+   * @param[in] keyboardShown True if keyboard is shown.
+   */
+  void KeyboardStatusChanged( bool keyboardShown );
+
+  /**
    * Construct a new TextField.
    */
   TextField();
index c302440..79185ba 100644 (file)
@@ -102,7 +102,9 @@ struct Controller::TextInput
   : mLogicalModel( logicalModel ),
     mVisualModel( visualModel ),
     mDecorator( decorator ),
-    mState( INACTIVE )
+    mState( INACTIVE ),
+    mDecoratorUpdated( false ),
+    mCursorBlinkEnabled( true )
   {
   }
 
@@ -155,6 +157,14 @@ struct Controller::TextInput
 
   void OnKeyboardFocus( bool hasFocus )
   {
+    if( !hasFocus )
+    {
+      ChangeState( INACTIVE );
+    }
+    else
+    {
+      ChangeState( EDITING );
+    }
   }
 
   void OnKeyEvent( const Event& event )
@@ -278,7 +288,10 @@ struct Controller::TextInput
       else if( EDITING == mState )
       {
         mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY );
-        mDecorator->StartCursorBlink();
+        if( mCursorBlinkEnabled )
+        {
+          mDecorator->StartCursorBlink();
+        }
         mDecorator->SetGrabHandleActive( true );
         mDecorator->SetSelectionActive( false );
         mDecoratorUpdated = true;
@@ -348,7 +361,8 @@ struct Controller::TextInput
 
   State mState;
 
-  bool mDecoratorUpdated;
+  bool mDecoratorUpdated   : 1;
+  bool mCursorBlinkEnabled : 1;
 };
 
 struct Controller::FontDefaults
@@ -575,12 +589,45 @@ void Controller::EnableTextInput( DecoratorPtr decorator )
   }
 }
 
+void Controller::SetEnableCursorBlink( bool enable )
+{
+  DALI_ASSERT_DEBUG( NULL != mImpl->mTextInput && "TextInput disabled" );
+
+  if( mImpl->mTextInput )
+  {
+    mImpl->mTextInput->mCursorBlinkEnabled = enable;
+
+    if( !enable &&
+        mImpl->mTextInput->mDecorator )
+    {
+      mImpl->mTextInput->mDecorator->StopCursorBlink();
+    }
+  }
+}
+
+bool Controller::GetEnableCursorBlink() const
+{
+  if( mImpl->mTextInput )
+  {
+    return mImpl->mTextInput->mCursorBlinkEnabled;
+  }
+
+  return false;
+}
+
 bool Controller::Relayout( const Vector2& size )
 {
   if( ( size.width < Math::MACHINE_EPSILON_1000 ) || ( size.height < Math::MACHINE_EPSILON_1000 ) )
   {
+    bool glyphsRemoved( false );
+    if( 0u != mImpl->mVisualModel->GetNumberOfGlyphPositions() )
+    {
+      mImpl->mVisualModel->SetGlyphPositions( NULL, 0u );
+      glyphsRemoved = true;
+    }
+
     // Not worth to relayout if width or height is equal to zero.
-    return false;
+    return glyphsRemoved;
   }
 
   if( size != mImpl->mControlSize )
index 9b38aca..640c2b4 100644 (file)
@@ -136,7 +136,7 @@ public:
    *
    * @return The default font family.
    */
-   const std::string& GetDefaultFontFamily() const;
+  const std::string& GetDefaultFontFamily() const;
 
   /**
    * @brief Set the default font style.
@@ -150,7 +150,7 @@ public:
    *
    * @return The default font style.
    */
-   const std::string& GetDefaultFontStyle() const;
+  const std::string& GetDefaultFontStyle() const;
 
   /**
    * @brief Set the default point size.
@@ -164,7 +164,7 @@ public:
    *
    * @return The default point size.
    */
-   float GetDefaultPointSize() const;
+  float GetDefaultPointSize() const;
 
   /**
    * @brief Retrieve the default fonts.
@@ -172,7 +172,7 @@ public:
    * @param[out] fonts The default font family, style and point sizes.
    * @param[in] numberOfCharacters The number of characters in the logical model.
    */
-   void GetDefaultFonts( Dali::Vector<FontRun>& fonts, Length numberOfCharacters );
+  void GetDefaultFonts( Dali::Vector<FontRun>& fonts, Length numberOfCharacters );
 
   /**
    * @brief Called to enable text input.
@@ -183,6 +183,21 @@ public:
   void EnableTextInput( DecoratorPtr decorator );
 
   /**
+   * @brief Called to enable/disable cursor blink.
+   *
+   * @note Only editable controls should calls this.
+   * @param[in] enabled Whether the cursor should blink or not.
+   */
+  void SetEnableCursorBlink( bool enable );
+
+  /**
+   * @brief Query whether cursor blink is enabled.
+   *
+   * @return Whether the cursor should blink or not.
+   */
+  bool GetEnableCursorBlink() const;
+
+  /**
    * @brief Triggers a relayout which updates View (if necessary).
    *
    * @note UI Controls are expected to minimize calls to this method e.g. call once after size negotiation.