From 6f62c2545af5b288bf447c380ccfb562cc7a4370 Mon Sep 17 00:00:00 2001
From: Paul Wisbey
Date: Mon, 16 Mar 2015 15:00:22 +0000
Subject: [PATCH] Added some keyboard & cursor plumbing
Change-Id: Id7db01da8f8476f56873b5f97a5e07e046882fe9
---
.../controls/text-controls/text-field-impl.cpp | 34 ++++++++++++-
.../controls/text-controls/text-field-impl.h | 17 +++++++
dali-toolkit/internal/text/text-controller.cpp | 55 ++++++++++++++++++++--
dali-toolkit/internal/text/text-controller.h | 23 +++++++--
4 files changed, 119 insertions(+), 10 deletions(-)
diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
index 5f8d498..fabfc7d 100644
--- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
+++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
@@ -26,6 +26,7 @@
#include
#include
#include
+#include
// INTERNAL INCLUDES
#include
@@ -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 ),
diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h
index 5d103c9..4bec09d 100644
--- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h
+++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h
@@ -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();
diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp
index c302440..79185ba 100644
--- a/dali-toolkit/internal/text/text-controller.cpp
+++ b/dali-toolkit/internal/text/text-controller.cpp
@@ -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 )
diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h
index 9b38aca..640c2b4 100644
--- a/dali-toolkit/internal/text/text-controller.h
+++ b/dali-toolkit/internal/text/text-controller.h
@@ -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& fonts, Length numberOfCharacters );
+ void GetDefaultFonts( Dali::Vector& 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.
--
2.7.4