{
#if defined(DEBUG_ENABLED)
- Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
+Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
#endif
- const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
+const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
+const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the text editor in pixels/second.
} // unnamed namespace
namespace
mController->GetLayoutEngine().SetLayout( LayoutEngine::MULTI_LINE_BOX );
+ // Enables the text input.
mController->EnableTextInput( mDecorator );
+ // Enables the vertical scrolling after the text input has been enabled.
+ mController->SetVerticalScrollEnabled( true );
+
+ // Disables the horizontal scrolling.
+ mController->SetHorizontalScrollEnabled( false );
+
mController->SetMaximumNumberOfCharacters( std::numeric_limits<Length>::max() );
+ // Enable the smooth handle panning.
+ mController->SetSmoothHandlePanEnabled( true );
+
// Forward input events to controller
EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
GetTapGestureDetector().SetMaximumTapsRequired( 2 );
mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
}
- // Flip vertically the 'left' selection handle
- mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
+ // Whether to flip the selection handles as soon as they cross.
+ mDecorator->FlipSelectionHandlesOnCrossEnabled( true );
+
+ // Set the default scroll speed.
+ mDecorator->SetScrollSpeed( DEFAULT_SCROLL_SPEED );
// Fill-parent area by default
self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
+ // Enables the text input.
mController->EnableTextInput( mDecorator );
+ // Enables the horizontal scrolling after the text input has been enabled.
+ mController->SetHorizontalScrollEnabled( true );
+
+ // Disables the vertical scrolling.
+ mController->SetVerticalScrollEnabled( false );
+
+ // Disable the smooth handle panning.
+ mController->SetSmoothHandlePanEnabled( false );
+
// Forward input events to controller
EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
GetTapGestureDetector().SetMaximumTapsRequired( 2 );
( isFirstPositionOfLine && !isRightToLeftParagraph ) );
cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + ( addGlyphAdvance ? glyphMetrics.advance : 0.f );
- cursorInfo.secondaryPosition.y = cursorInfo.lineOffset + cursorInfo.lineHeight - cursorInfo.secondaryCursorHeight - line.descender - ( glyphMetrics.fontHeight - glyphMetrics.ascender );
+ cursorInfo.secondaryPosition.y = cursorInfo.lineOffset + cursorInfo.lineHeight - cursorInfo.secondaryCursorHeight;
// Transform the cursor info from line's coords to text's coords.
cursorInfo.secondaryPosition.x += line.alignmentOffset;
const Dali::Vector4 HANDLE_COLOR( 0.0f, (183.0f / 255.0f), (229.0f / 255.0f), 1.0f );
-const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
-const float TO_MILLISECONDS = 1000.f;
-const float TO_SECONDS = 1.f / TO_MILLISECONDS;
+const unsigned int CURSOR_BLINK_INTERVAL = 500u; ///< Cursor blink interval in milliseconds.
+const float TO_MILLISECONDS = 1000.f; ///< Converts from seconds to milliseconds.
+const float TO_SECONDS = 1.f / TO_MILLISECONDS; ///< Converts from milliseconds to seconds.
-const unsigned int SCROLL_TICK_INTERVAL = 50u;
+const unsigned int SCROLL_TICK_INTERVAL = 50u; ///< Scroll interval in milliseconds.
+const float SCROLL_THRESHOLD = 10.f; ///< Threshold in pixels close to the edges of the decorator boundaries from where the scroll timer starts to emit signals.
+const float SCROLL_SPEED = 300.f; ///< The scroll speed in pixels/second.
-const float SCROLL_THRESHOLD = 10.f;
-const float SCROLL_SPEED = 300.f;
-const float SCROLL_DISTANCE = SCROLL_SPEED * SCROLL_TICK_INTERVAL * TO_SECONDS;
+const float SCROLL_DISTANCE = SCROLL_SPEED * SCROLL_TICK_INTERVAL * TO_SECONDS; ///< Distance in pixels scrolled in one second.
-const float CURSOR_WIDTH = 1.f;
+const float CURSOR_WIDTH = 1.f; ///< The cursor's width in pixels.
/**
* structure to hold coordinates of each quad, which will make up the mesh.
{
HandleImpl()
: position(),
+ globalPosition(),
size(),
lineHeight( 0.0f ),
grabDisplacementX( 0.f ),
ImageView markerActor;
Vector2 position;
+ Vector2 globalPosition;
Size size;
float lineHeight; ///< Not the handle height
float grabDisplacementX;
mFlipSelectionHandlesOnCross( false ),
mFlipLeftSelectionHandleDirection( false ),
mFlipRightSelectionHandleDirection( false ),
- mHandlePanning( false ),
- mHandleCurrentCrossed( false ),
- mHandlePreviousCrossed( false ),
- mNotifyEndOfScroll( false )
+ mIsHandlePanning( false ),
+ mIsHandleCurrentlyCrossed( false ),
+ mIsHandlePreviouslyCrossed( false ),
+ mNotifyEndOfScroll( false ),
+ mHorizontalScrollingEnabled( false ),
+ mVerticalScrollingEnabled( false )
{
mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
mHighlightShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
if( mPrimaryCursor )
{
const CursorImpl& cursor = mCursor[PRIMARY_CURSOR];
- mPrimaryCursorVisible = ( cursor.position.x + mCursorWidth <= mControlSize.width ) && ( cursor.position.x >= 0.f );
+ mPrimaryCursorVisible = ( ( cursor.position.x + mCursorWidth <= mControlSize.width ) &&
+ ( cursor.position.x >= 0.f ) &&
+ ( cursor.position.y + cursor.cursorHeight <= mControlSize.height ) &&
+ ( cursor.position.y >= 0.f ) );
if( mPrimaryCursorVisible )
{
mPrimaryCursor.SetPosition( cursor.position.x,
if( mSecondaryCursor )
{
const CursorImpl& cursor = mCursor[SECONDARY_CURSOR];
- mSecondaryCursorVisible = ( cursor.position.x + mCursorWidth <= mControlSize.width ) && ( cursor.position.x >= 0.f );
+ mSecondaryCursorVisible = ( ( cursor.position.x + mCursorWidth <= mControlSize.width ) &&
+ ( cursor.position.x >= 0.f ) &&
+ ( cursor.position.y + cursor.cursorHeight <= mControlSize.height ) &&
+ ( cursor.position.y >= 0.f ) );
if( mSecondaryCursorVisible )
{
mSecondaryCursor.SetPosition( cursor.position.x,
bool newGrabHandlePosition = false;
if( grabHandle.active )
{
- const bool isVisible = ( grabHandle.position.x + floor( 0.5f * mCursorWidth ) <= mControlSize.width ) && ( grabHandle.position.x >= 0.f );
+ const bool isVisible = ( ( grabHandle.position.x + floor( 0.5f * mCursorWidth ) <= mControlSize.width ) &&
+ ( grabHandle.position.x >= 0.f ) &&
+ ( grabHandle.position.y <= mControlSize.height - grabHandle.lineHeight ) &&
+ ( grabHandle.position.y >= 0.f ) );
if( isVisible )
{
bool newSecondaryHandlePosition = false;
if( primary.active || secondary.active )
{
- const bool isPrimaryVisible = ( primary.position.x <= mControlSize.width ) && ( primary.position.x >= 0.f );
- const bool isSecondaryVisible = ( secondary.position.x <= mControlSize.width ) && ( secondary.position.x >= 0.f );
+ const bool isPrimaryVisible = ( ( primary.position.x <= mControlSize.width ) &&
+ ( primary.position.x >= 0.f ) &&
+ ( primary.position.y <= mControlSize.height - primary.lineHeight ) &&
+ ( primary.position.y >= 0.f ) );
+ const bool isSecondaryVisible = ( ( secondary.position.x <= mControlSize.width ) &&
+ ( secondary.position.x >= 0.f ) &&
+ ( secondary.position.y <= mControlSize.height - secondary.lineHeight ) &&
+ ( secondary.position.y >= 0.f ) );
if( isPrimaryVisible || isSecondaryVisible )
{
// The grab handle position in world coords.
// The active layer's world position is the center of the active layer. The origin of the
// coord system of the handles is the top left of the active layer.
- position.x = parentWorldPosition.x - 0.5f * mControlSize.width + handle.position.x;
- position.y = parentWorldPosition.y - 0.5f * mControlSize.height + handle.position.y;
+ position.x = parentWorldPosition.x - 0.5f * mControlSize.width + handle.position.x + ( mSmoothHandlePanEnabled ? handle.grabDisplacementX : 0.f );
+ position.y = parentWorldPosition.y - 0.5f * mControlSize.height + handle.position.y + ( mSmoothHandlePanEnabled ? handle.grabDisplacementY : 0.f );
}
void SetGrabHandlePosition()
if( grabHandle.actor )
{
- grabHandle.actor.SetPosition( grabHandle.position.x + floor( 0.5f * mCursorWidth ),
- yLocalPosition ); // TODO : Fix for multiline.
+ grabHandle.actor.SetPosition( grabHandle.position.x + floor( 0.5f * mCursorWidth ) + ( mSmoothHandlePanEnabled ? grabHandle.grabDisplacementX : 0.f ),
+ yLocalPosition + ( mSmoothHandlePanEnabled ? grabHandle.grabDisplacementY : 0.f ) );
}
}
// Whether to flip the handles if they are crossed.
bool crossFlip = false;
- if( mFlipSelectionHandlesOnCross || !mHandlePanning )
+ if( mFlipSelectionHandlesOnCross || !mIsHandlePanning )
{
- crossFlip = mHandleCurrentCrossed;
+ crossFlip = mIsHandleCurrentlyCrossed;
}
+ // Whether the handle was crossed before start the panning.
+ const bool isHandlePreviouslyCrossed = mFlipSelectionHandlesOnCross ? false : mIsHandlePreviouslyCrossed;
+
// Does not flip if both conditions are true (double flip)
- flipHandle = flipHandle != ( crossFlip || mHandlePreviousCrossed );
+ flipHandle = flipHandle != ( crossFlip || isHandlePreviouslyCrossed );
// Will flip the handles vertically if the user prefers it.
bool verticallyFlippedPreferred = handle.verticallyFlippedPreferred;
- if( crossFlip || mHandlePreviousCrossed )
+ if( crossFlip || isHandlePreviouslyCrossed )
{
if( isPrimaryHandle )
{
if( handle.actor )
{
- handle.actor.SetPosition( handle.position.x,
- yLocalPosition ); // TODO : Fix for multiline.
+ handle.actor.SetPosition( handle.position.x + ( mSmoothHandlePanEnabled ? handle.grabDisplacementX : 0.f ),
+ yLocalPosition + ( mSmoothHandlePanEnabled ? handle.grabDisplacementY : 0.f ) );
}
}
if( Gesture::Started == gesture.state )
{
handle.grabDisplacementX = handle.grabDisplacementY = 0.f;
+
+ handle.globalPosition.x = handle.position.x;
+ handle.globalPosition.y = handle.position.y;
}
handle.grabDisplacementX += gesture.displacement.x;
handle.grabDisplacementY += ( handle.verticallyFlipped ? -gesture.displacement.y : gesture.displacement.y );
- const float x = handle.position.x + handle.grabDisplacementX;
- const float y = handle.position.y + handle.lineHeight*0.5f + handle.grabDisplacementY;
+ const float x = handle.globalPosition.x + handle.grabDisplacementX;
+ const float y = handle.globalPosition.y + handle.grabDisplacementY + 0.5f * handle.lineHeight;
+ const float yVerticallyFlippedCorrected = y - ( handle.verticallyFlipped ? handle.lineHeight : 0.f );
- if( Gesture::Started == gesture.state ||
- Gesture::Continuing == gesture.state )
+ if( ( Gesture::Started == gesture.state ) ||
+ ( Gesture::Continuing == gesture.state ) )
{
Vector2 targetSize;
mController.GetTargetSize( targetSize );
- if( x < mScrollThreshold )
+ if( mHorizontalScrollingEnabled &&
+ ( x < mScrollThreshold ) )
{
mScrollDirection = SCROLL_RIGHT;
mHandleScrolling = type;
StartScrollTimer();
}
- else if( x > targetSize.width - mScrollThreshold )
+ else if( mHorizontalScrollingEnabled &&
+ ( x > targetSize.width - mScrollThreshold ) )
{
mScrollDirection = SCROLL_LEFT;
mHandleScrolling = type;
StartScrollTimer();
}
+ else if( mVerticalScrollingEnabled &&
+ ( yVerticallyFlippedCorrected < mScrollThreshold ) )
+ {
+ mScrollDirection = SCROLL_TOP;
+ mHandleScrolling = type;
+ StartScrollTimer();
+ }
+ else if( mVerticalScrollingEnabled &&
+ ( yVerticallyFlippedCorrected + handle.lineHeight > targetSize.height - mScrollThreshold ) )
+ {
+ mScrollDirection = SCROLL_BOTTOM;
+ mHandleScrolling = type;
+ StartScrollTimer();
+ }
else
{
mHandleScrolling = HANDLE_TYPE_COUNT;
mController.DecorationEvent( type, HANDLE_PRESSED, x, y );
}
- mHandlePanning = true;
+ mIsHandlePanning = true;
}
- else if( Gesture::Finished == gesture.state ||
- Gesture::Cancelled == gesture.state )
+ else if( ( Gesture::Finished == gesture.state ) ||
+ ( Gesture::Cancelled == gesture.state ) )
{
if( mScrollTimer &&
( mScrollTimer.IsRunning() || mNotifyEndOfScroll ) )
}
handle.pressed = false;
- mHandlePanning = false;
+ mIsHandlePanning = false;
}
}
bool OnGrabHandleTouched( Actor actor, const TouchData& touch )
{
+ HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
+
// Switch between pressed/release grab-handle images
if( touch.GetPointCount() > 0 &&
- mHandle[GRAB_HANDLE].actor )
+ grabHandle.actor )
{
const PointState::Type state = touch.GetState( 0 );
if( PointState::DOWN == state )
{
- mHandle[GRAB_HANDLE].pressed = true;
+ grabHandle.pressed = true;
}
else if( ( PointState::UP == state ) ||
( PointState::INTERRUPTED == state ) )
{
- mHandle[GRAB_HANDLE].pressed = false;
+ grabHandle.pressed = false;
}
SetHandleImage( GRAB_HANDLE );
bool OnHandleOneTouched( Actor actor, const TouchData& touch )
{
+ HandleImpl& primarySelectionHandle = mHandle[LEFT_SELECTION_HANDLE];
+
// Switch between pressed/release selection handle images
if( touch.GetPointCount() > 0 &&
- mHandle[LEFT_SELECTION_HANDLE].actor )
+ primarySelectionHandle.actor )
{
const PointState::Type state = touch.GetState( 0 );
if( PointState::DOWN == state )
{
- mHandle[LEFT_SELECTION_HANDLE].pressed = true;
+ primarySelectionHandle.pressed = true;
}
else if( ( PointState::UP == state ) ||
( PointState::INTERRUPTED == state ) )
{
- mHandle[LEFT_SELECTION_HANDLE].pressed = false;
- mHandlePreviousCrossed = mHandleCurrentCrossed;
- mHandlePanning = false;
+ primarySelectionHandle.pressed = false;
+ mIsHandlePreviouslyCrossed = mIsHandleCurrentlyCrossed;
+ mIsHandlePanning = false;
}
SetHandleImage( LEFT_SELECTION_HANDLE );
bool OnHandleTwoTouched( Actor actor, const TouchData& touch )
{
+ HandleImpl& secondarySelectionHandle = mHandle[RIGHT_SELECTION_HANDLE];
+
// Switch between pressed/release selection handle images
if( touch.GetPointCount() > 0 &&
- mHandle[RIGHT_SELECTION_HANDLE].actor )
+ secondarySelectionHandle.actor )
{
const PointState::Type state = touch.GetState( 0 );
if( PointState::DOWN == state )
{
- mHandle[RIGHT_SELECTION_HANDLE].pressed = true;
+ secondarySelectionHandle.pressed = true;
}
else if( ( PointState::UP == state ) ||
( PointState::INTERRUPTED == state ) )
{
- mHandle[RIGHT_SELECTION_HANDLE].pressed = false;
- mHandlePreviousCrossed = mHandleCurrentCrossed;
- mHandlePanning = false;
+ secondarySelectionHandle.pressed = false;
+ mIsHandlePreviouslyCrossed = mIsHandleCurrentlyCrossed;
+ mIsHandlePanning = false;
}
SetHandleImage( RIGHT_SELECTION_HANDLE );
{
if( HANDLE_TYPE_COUNT != mHandleScrolling )
{
+ float x = 0.f;
+ float y = 0.f;
+
+ switch( mScrollDirection )
+ {
+ case SCROLL_RIGHT:
+ {
+ x = mScrollDistance;
+ break;
+ }
+ case SCROLL_LEFT:
+ {
+ x = -mScrollDistance;
+ break;
+ }
+ case SCROLL_TOP:
+ {
+ y = mScrollDistance;
+ break;
+ }
+ case SCROLL_BOTTOM:
+ {
+ y = -mScrollDistance;
+ break;
+ }
+ default:
+ break;
+ }
+
mController.DecorationEvent( mHandleScrolling,
HANDLE_SCROLLING,
- mScrollDirection == SCROLL_RIGHT ? mScrollDistance : -mScrollDistance,
- 0.f );
+ x,
+ y );
}
return true;
bool mFlipSelectionHandlesOnCross : 1; ///< Whether to flip the selection handles as soon as they cross.
bool mFlipLeftSelectionHandleDirection : 1; ///< Whether to flip the left selection handle image because of the character's direction.
bool mFlipRightSelectionHandleDirection : 1; ///< Whether to flip the right selection handle image because of the character's direction.
- bool mHandlePanning : 1; ///< Whether any of the handles is moving.
- bool mHandleCurrentCrossed : 1; ///< Whether the handles are crossed.
- bool mHandlePreviousCrossed : 1; ///< Whether the handles where crossed at the last handle touch up.
+ bool mIsHandlePanning : 1; ///< Whether any of the handles is moving.
+ bool mIsHandleCurrentlyCrossed : 1; ///< Whether the handles are crossed.
+ bool mIsHandlePreviouslyCrossed : 1; ///< Whether the handles where crossed at the last handle touch up.
bool mNotifyEndOfScroll : 1; ///< Whether to notify the end of the scroll.
+ bool mHorizontalScrollingEnabled : 1; ///< Whether the horizontal scrolling is enabled.
+ bool mVerticalScrollingEnabled : 1; ///< Whether the vertical scrolling is enabled.
+ bool mSmoothHandlePanEnabled : 1; ///< Whether to pan smoothly the handles.
};
DecoratorPtr Decorator::New( ControllerInterface& controller,
void Decorator::SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight )
{
- mImpl->mCursor[cursor].position.x = x;
- mImpl->mCursor[cursor].position.y = y;
- mImpl->mCursor[cursor].cursorHeight = cursorHeight;
- mImpl->mCursor[cursor].lineHeight = lineHeight;
+ Impl::CursorImpl& cursorImpl = mImpl->mCursor[cursor];
+
+ cursorImpl.position.x = x;
+ cursorImpl.position.y = y;
+ cursorImpl.cursorHeight = cursorHeight;
+ cursorImpl.lineHeight = lineHeight;
}
void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const
{
- x = mImpl->mCursor[cursor].position.x;
- y = mImpl->mCursor[cursor].position.y;
- cursorHeight = mImpl->mCursor[cursor].cursorHeight;
- lineHeight = mImpl->mCursor[cursor].lineHeight;
+ const Impl::CursorImpl& cursorImpl = mImpl->mCursor[cursor];
+
+ x = cursorImpl.position.x;
+ y = cursorImpl.position.y;
+ cursorHeight = cursorImpl.cursorHeight;
+ lineHeight = cursorImpl.lineHeight;
}
const Vector2& Decorator::GetPosition( Cursor cursor ) const
{
if( ( LEFT_SELECTION_HANDLE == handleType ) || ( RIGHT_SELECTION_HANDLE == handleType ) )
{
- mImpl->mHandlePreviousCrossed = false;
+ mImpl->mIsHandlePreviouslyCrossed = false;
}
// TODO: this is a work-around.
// Adjust handle's displacement
Impl::HandleImpl& handle = mImpl->mHandle[handleType];
- handle.grabDisplacementX -= x - handle.position.x;
- handle.grabDisplacementY -= y - handle.position.y;
-
handle.position.x = x;
handle.position.y = y;
handle.lineHeight = height;
+
+ if( mImpl->mSmoothHandlePanEnabled )
+ {
+ handle.grabDisplacementX = 0.f;
+ handle.grabDisplacementY = 0.f;
+ }
}
void Decorator::GetPosition( HandleType handleType, float& x, float& y, float& height ) const
void Decorator::SetSelectionHandleFlipState( bool indicesSwapped, bool left, bool right )
{
- mImpl->mHandleCurrentCrossed = indicesSwapped;
+ mImpl->mIsHandleCurrentlyCrossed = indicesSwapped;
mImpl->mFlipLeftSelectionHandleDirection = left;
mImpl->mFlipRightSelectionHandleDirection = right;
}
mImpl->NotifyEndOfScroll();
}
+void Decorator::SetHorizontalScrollEnabled( bool enable )
+{
+ mImpl->mHorizontalScrollingEnabled = enable;
+}
+
+bool Decorator::IsHorizontalScrollEnabled() const
+{
+ return mImpl->mHorizontalScrollingEnabled;
+}
+
+void Decorator::SetVerticalScrollEnabled( bool enable )
+{
+ mImpl->mVerticalScrollingEnabled = enable;
+}
+
+bool Decorator::IsVerticalScrollEnabled() const
+{
+ return mImpl->mVerticalScrollingEnabled;
+}
+
+void Decorator::SetSmoothHandlePanEnabled( bool enable )
+{
+ mImpl->mSmoothHandlePanEnabled = enable;
+}
+
+bool Decorator::IsSmoothHandlePanEnabled() const
+{
+ return mImpl->mSmoothHandlePanEnabled;
+}
+
Decorator::~Decorator()
{
delete mImpl;
/**
* @brief Retrieves the blink-interval for a cursor.
*
- * @return The cursor blink-interval.
+ * @return The cursor blink-interval in seconds.
*/
float GetCursorBlinkInterval() const;
/**
* @brief Retrieves the blink-duration for a cursor.
*
- * @return The cursor blink-duration.
+ * @return The cursor blink-duration in seconds.
*/
float GetCursorBlinkDuration() const;
* It defines a square area inside the control, close to the edge.
* When the cursor enters this area, the decorator starts to send scroll events.
*
- * @param[in] threshold The scroll threshold.
+ * @param[in] threshold The scroll threshold in pixels.
*/
void SetScrollThreshold( float threshold );
/**
* @brief Retrieves the scroll threshold.
*
- * @retunr The scroll threshold.
+ * @retunr The scroll threshold in pixels.
*/
float GetScrollThreshold() const;
*
* Is the distance the text is going to be scrolled during a scroll interval.
*
- * @param[in] speed The scroll speed.
+ * @param[in] speed The scroll speed in pixels/second.
*/
void SetScrollSpeed( float speed );
/**
* @brief Retrieves the scroll speed.
*
- * @return The scroll speed.
+ * @return The scroll speed in pixels/second.
*/
float GetScrollSpeed() const;
*/
void NotifyEndOfScroll();
+ /**
+ * @copydoc Text::Controller::SetHorizontalScrollEnabled()
+ */
+ void SetHorizontalScrollEnabled( bool enable );
+
+ /**
+ * @copydoc Text::Controller::IsHorizontalScrollEnabled()
+ */
+ bool IsHorizontalScrollEnabled() const;
+
+ /**
+ * @copydoc Text::Controller::SetVerticalScrollEnabled()
+ */
+ void SetVerticalScrollEnabled( bool enable );
+
+ /**
+ * @copydoc Text::Controller::IsVerticalScrollEnabled()
+ */
+ bool IsVerticalScrollEnabled() const;
+
+ /**
+ * @copydoc Text::Controller::SetSmoothHandlePanEnabled()
+ */
+ void SetSmoothHandlePanEnabled( bool enable );
+
+ /**
+ * @copydoc Text::Controller::IsSmoothHandlePanEnabled()
+ */
+ bool IsSmoothHandlePanEnabled() const;
+
protected:
/**
mRightSelectionPosition( 0u ),
mPreEditStartPosition( 0u ),
mPreEditLength( 0u ),
+ mCursorHookPositionX( 0.f ),
mIsShowingPlaceholderText( false ),
mPreEditFlag( false ),
mDecoratorUpdated( false ),
mGrabHandleEnabled( true ),
mGrabHandlePopupEnabled( true ),
mSelectionEnabled( true ),
- mHorizontalScrollingEnabled( true ),
- mVerticalScrollingEnabled( false ),
mUpdateCursorPosition( false ),
+ mUpdateGrabHandlePosition( false ),
mUpdateLeftSelectionPosition( false ),
mUpdateRightSelectionPosition( false ),
+ mUpdateHighlightBox( false ),
mScrollAfterUpdatePosition( false ),
mScrollAfterDelete( false ),
mAllTextSelected( false ),
}
if( mEventData->mUpdateCursorPosition ||
- mEventData->mUpdateLeftSelectionPosition ||
- mEventData->mUpdateRightSelectionPosition )
+ mEventData->mUpdateHighlightBox )
{
NotifyImfManager();
}
{
// Updates the cursor position and scrolls the text to make it visible.
CursorInfo cursorInfo;
+ // Calculate the cursor position from the new cursor index.
GetCursorPosition( mEventData->mPrimaryCursorPosition,
cursorInfo );
+ if( mEventData->mUpdateCursorHookPosition )
+ {
+ // Update the cursor hook position. Used to move the cursor with the keys 'up' and 'down'.
+ mEventData->mCursorHookPositionX = cursorInfo.primaryPosition.x;
+ mEventData->mUpdateCursorHookPosition = false;
+ }
+
// Scroll first the text after delete ...
if( mEventData->mScrollAfterDelete )
{
// ... then, text can be scrolled to make the cursor visible.
if( mEventData->mScrollAfterUpdatePosition )
{
- ScrollToMakePositionVisible( cursorInfo.primaryPosition );
+ const Vector2 currentCursorPosition( cursorInfo.primaryPosition.x, cursorInfo.lineOffset );
+ ScrollToMakePositionVisible( currentCursorPosition, cursorInfo.lineHeight );
}
mEventData->mScrollAfterUpdatePosition = false;
mEventData->mScrollAfterDelete = false;
mEventData->mDecoratorUpdated = true;
mEventData->mUpdateCursorPosition = false;
+ mEventData->mUpdateGrabHandlePosition = false;
}
else
{
- bool leftScroll = false;
- bool rightScroll = false;
-
CursorInfo leftHandleInfo;
CursorInfo rightHandleInfo;
- if( mEventData->mUpdateLeftSelectionPosition )
+ if( mEventData->mUpdateHighlightBox )
{
GetCursorPosition( mEventData->mLeftSelectionPosition,
leftHandleInfo );
- if( mEventData->mScrollAfterUpdatePosition )
- {
- ScrollToMakePositionVisible( leftHandleInfo.primaryPosition );
- leftScroll = true;
- }
- }
-
- if( mEventData->mUpdateRightSelectionPosition )
- {
GetCursorPosition( mEventData->mRightSelectionPosition,
rightHandleInfo );
- if( mEventData->mScrollAfterUpdatePosition )
+ if( mEventData->mScrollAfterUpdatePosition && mEventData->mUpdateLeftSelectionPosition )
{
- ScrollToMakePositionVisible( rightHandleInfo.primaryPosition );
- rightScroll = true;
+ const Vector2 currentCursorPosition( leftHandleInfo.primaryPosition.x, leftHandleInfo.lineOffset );
+ ScrollToMakePositionVisible( currentCursorPosition, leftHandleInfo.lineHeight );
+ }
+
+ if( mEventData->mScrollAfterUpdatePosition && mEventData->mUpdateRightSelectionPosition )
+ {
+ const Vector2 currentCursorPosition( rightHandleInfo.primaryPosition.x, rightHandleInfo.lineOffset );
+ ScrollToMakePositionVisible( currentCursorPosition, rightHandleInfo.lineHeight );
}
}
SetPopupButtons();
mEventData->mDecoratorUpdated = true;
+ mEventData->mUpdateLeftSelectionPosition = false;
}
if( mEventData->mUpdateRightSelectionPosition )
SetPopupButtons();
mEventData->mDecoratorUpdated = true;
+ mEventData->mUpdateRightSelectionPosition = false;
}
- if( mEventData->mUpdateLeftSelectionPosition || mEventData->mUpdateRightSelectionPosition )
+ if( mEventData->mUpdateHighlightBox )
{
RepositionSelectionHandles();
mEventData->mUpdateLeftSelectionPosition = false;
mEventData->mUpdateRightSelectionPosition = false;
+ mEventData->mUpdateHighlightBox = false;
}
- if( leftScroll || rightScroll )
- {
- mEventData->mScrollAfterUpdatePosition = false;
- }
+ mEventData->mScrollAfterUpdatePosition = false;
}
if( mEventData->mUpdateInputStyle )
}
else if( Dali::DALI_KEY_CURSOR_UP == keyCode )
{
- // TODO
+ // Get first the line index of the current cursor position index.
+ CharacterIndex characterIndex = 0u;
+
+ if( mEventData->mPrimaryCursorPosition > 0u )
+ {
+ characterIndex = mEventData->mPrimaryCursorPosition - 1u;
+ }
+
+ const LineIndex lineIndex = mVisualModel->GetLineOfCharacter( characterIndex );
+
+ if( lineIndex > 0u )
+ {
+ // Retrieve the cursor position info.
+ CursorInfo cursorInfo;
+ GetCursorPosition( mEventData->mPrimaryCursorPosition,
+ cursorInfo );
+
+ // Get the line above.
+ const LineRun& line = *( mVisualModel->mLines.Begin() + ( lineIndex - 1u ) );
+
+ // Get the next hit 'y' point.
+ const float hitPointY = cursorInfo.lineOffset - 0.5f * ( line.ascender - line.descender );
+
+ // Use the cursor hook position 'x' and the next hit 'y' position to calculate the new cursor index.
+ mEventData->mPrimaryCursorPosition = Text::GetClosestCursorIndex( mVisualModel,
+ mLogicalModel,
+ mMetrics,
+ mEventData->mCursorHookPositionX,
+ hitPointY );
+ }
}
else if( Dali::DALI_KEY_CURSOR_DOWN == keyCode )
{
- // TODO
+ // Get first the line index of the current cursor position index.
+ CharacterIndex characterIndex = 0u;
+
+ if( mEventData->mPrimaryCursorPosition > 0u )
+ {
+ characterIndex = mEventData->mPrimaryCursorPosition - 1u;
+ }
+
+ const LineIndex lineIndex = mVisualModel->GetLineOfCharacter( characterIndex );
+
+ if( lineIndex + 1u < mVisualModel->mLines.Count() )
+ {
+ // Retrieve the cursor position info.
+ CursorInfo cursorInfo;
+ GetCursorPosition( mEventData->mPrimaryCursorPosition,
+ cursorInfo );
+
+ // Get the line below.
+ const LineRun& line = *( mVisualModel->mLines.Begin() + lineIndex + 1u );
+
+ // Get the next hit 'y' point.
+ const float hitPointY = cursorInfo.lineOffset + cursorInfo.lineHeight + 0.5f * ( line.ascender - line.descender );
+
+ // Use the cursor hook position 'x' and the next hit 'y' position to calculate the new cursor index.
+ mEventData->mPrimaryCursorPosition = Text::GetClosestCursorIndex( mVisualModel,
+ mLogicalModel,
+ mMetrics,
+ mEventData->mCursorHookPositionX,
+ hitPointY );
+ }
}
mEventData->mUpdateCursorPosition = true;
const float xPosition = event.p2.mFloat - mScrollPosition.x;
const float yPosition = event.p3.mFloat - mScrollPosition.y;
+ // Keep the tap 'x' position. Used to move the cursor.
+ mEventData->mCursorHookPositionX = xPosition;
+
mEventData->mPrimaryCursorPosition = Text::GetClosestCursorIndex( mVisualModel,
mLogicalModel,
mMetrics,
}
mEventData->mUpdateCursorPosition = true;
+ mEventData->mUpdateGrabHandlePosition = true;
mEventData->mScrollAfterUpdatePosition = true;
mEventData->mUpdateInputStyle = true;
if( ( Gesture::Started == state ) ||
( Gesture::Continuing == state ) )
{
- const Vector2& actualSize = mVisualModel->GetLayoutSize();
- const Vector2 currentScroll = mScrollPosition;
-
- if( mEventData->mHorizontalScrollingEnabled )
+ if( mEventData->mDecorator )
{
- const float displacementX = event.p2.mFloat;
- mScrollPosition.x += displacementX;
+ const Vector2& layoutSize = mVisualModel->GetLayoutSize();
+ const Vector2 currentScroll = mScrollPosition;
- ClampHorizontalScroll( actualSize );
- }
+ if( mEventData->mDecorator->IsHorizontalScrollEnabled() )
+ {
+ const float displacementX = event.p2.mFloat;
+ mScrollPosition.x += displacementX;
- if( mEventData->mVerticalScrollingEnabled )
- {
- const float displacementY = event.p3.mFloat;
- mScrollPosition.y += displacementY;
+ ClampHorizontalScroll( layoutSize );
+ }
- ClampVerticalScroll( actualSize );
- }
+ if( mEventData->mDecorator->IsVerticalScrollEnabled() )
+ {
+ const float displacementY = event.p3.mFloat;
+ mScrollPosition.y += displacementY;
+
+ ClampVerticalScroll( layoutSize );
+ }
- if( mEventData->mDecorator )
- {
mEventData->mDecorator->UpdatePositions( mScrollPosition - currentScroll );
}
}
const unsigned int state = event.p1.mUint;
const bool handleStopScrolling = ( HANDLE_STOP_SCROLLING == state );
+ const bool isSmoothHandlePanEnabled = mEventData->mDecorator->IsSmoothHandlePanEnabled();
if( HANDLE_PRESSED == state )
{
const float xPosition = event.p2.mFloat - mScrollPosition.x;
const float yPosition = event.p3.mFloat - mScrollPosition.y;
+ // Need to calculate the handle's new position.
const CharacterIndex handleNewPosition = Text::GetClosestCursorIndex( mVisualModel,
mLogicalModel,
mMetrics,
if( handleNewPosition != mEventData->mPrimaryCursorPosition )
{
- mEventData->mPrimaryCursorPosition = handleNewPosition;
+ // Updates the cursor position if the handle's new position is different than the current one.
mEventData->mUpdateCursorPosition = true;
+ // Does not update the grab handle position if the smooth panning is enabled. (The decorator does it smooth).
+ mEventData->mUpdateGrabHandlePosition = !isSmoothHandlePanEnabled;
+ mEventData->mPrimaryCursorPosition = handleNewPosition;
}
+
+ // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set.
+ mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled;
}
else if( Event::LEFT_SELECTION_HANDLE_EVENT == event.type )
{
if( ( handleNewPosition != mEventData->mLeftSelectionPosition ) &&
( handleNewPosition != mEventData->mRightSelectionPosition ) )
{
+ // Updates the highlight box if the handle's new position is different than the current one.
+ mEventData->mUpdateHighlightBox = true;
+ // Does not update the selection handle position if the smooth panning is enabled. (The decorator does it smooth).
+ mEventData->mUpdateLeftSelectionPosition = !isSmoothHandlePanEnabled;
mEventData->mLeftSelectionPosition = handleNewPosition;
-
- mEventData->mUpdateLeftSelectionPosition = true;
}
+
+ // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set.
+ mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled;
}
else if( Event::RIGHT_SELECTION_HANDLE_EVENT == event.type )
{
if( ( handleNewPosition != mEventData->mRightSelectionPosition ) &&
( handleNewPosition != mEventData->mLeftSelectionPosition ) )
{
+ // Updates the highlight box if the handle's new position is different than the current one.
+ mEventData->mUpdateHighlightBox = true;
+ // Does not update the selection handle position if the smooth panning is enabled. (The decorator does it smooth).
+ mEventData->mUpdateRightSelectionPosition = !isSmoothHandlePanEnabled;
mEventData->mRightSelectionPosition = handleNewPosition;
-
- mEventData->mUpdateRightSelectionPosition = true;
}
+
+ // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set.
+ mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled;
}
} // end ( HANDLE_PRESSED == state )
else if( ( HANDLE_RELEASED == state ) ||
handleStopScrolling )
{
CharacterIndex handlePosition = 0u;
- if( handleStopScrolling )
+ if( handleStopScrolling || isSmoothHandlePanEnabled )
{
// Convert from decorator's coords to text's coords.
const float xPosition = event.p2.mFloat - mScrollPosition.x;
if( Event::GRAB_HANDLE_EVENT == event.type )
{
mEventData->mUpdateCursorPosition = true;
+ mEventData->mUpdateGrabHandlePosition = true;
mEventData->mUpdateInputStyle = true;
if( !IsClipboardEmpty() )
ChangeState( EventData::EDITING_WITH_PASTE_POPUP ); // Moving grabhandle will show Paste Popup
}
- if( handleStopScrolling )
+ if( handleStopScrolling || isSmoothHandlePanEnabled )
{
- mEventData->mScrollAfterUpdatePosition = mEventData->mPrimaryCursorPosition != handlePosition;
+ mEventData->mScrollAfterUpdatePosition = true;
mEventData->mPrimaryCursorPosition = handlePosition;
}
}
{
ChangeState( EventData::SELECTING );
- if( handleStopScrolling )
+ mEventData->mUpdateHighlightBox = true;
+ mEventData->mUpdateLeftSelectionPosition = true;
+
+ if( handleStopScrolling || isSmoothHandlePanEnabled )
{
- mEventData->mUpdateLeftSelectionPosition = ( mEventData->mRightSelectionPosition != handlePosition );
- mEventData->mScrollAfterUpdatePosition = mEventData->mUpdateLeftSelectionPosition;
+ mEventData->mScrollAfterUpdatePosition = true;
- if( mEventData->mUpdateLeftSelectionPosition )
+ if( ( handlePosition != mEventData->mRightSelectionPosition ) &&
+ ( handlePosition != mEventData->mLeftSelectionPosition ) )
{
mEventData->mLeftSelectionPosition = handlePosition;
}
{
ChangeState( EventData::SELECTING );
- if( handleStopScrolling )
+ mEventData->mUpdateHighlightBox = true;
+ mEventData->mUpdateRightSelectionPosition = true;
+
+ if( handleStopScrolling || isSmoothHandlePanEnabled )
{
- mEventData->mUpdateRightSelectionPosition = ( mEventData->mLeftSelectionPosition != handlePosition );
- mEventData->mScrollAfterUpdatePosition = mEventData->mUpdateRightSelectionPosition;
- if( mEventData->mUpdateRightSelectionPosition )
+ mEventData->mScrollAfterUpdatePosition = true;
+ if( ( handlePosition != mEventData->mRightSelectionPosition ) &&
+ ( handlePosition != mEventData->mLeftSelectionPosition ) )
{
mEventData->mRightSelectionPosition = handlePosition;
}
else if( HANDLE_SCROLLING == state )
{
const float xSpeed = event.p2.mFloat;
- const Vector2& actualSize = mVisualModel->GetLayoutSize();
+ const float ySpeed = event.p3.mFloat;
+ const Vector2& layoutSize = mVisualModel->GetLayoutSize();
const Vector2 currentScrollPosition = mScrollPosition;
mScrollPosition.x += xSpeed;
+ mScrollPosition.y += ySpeed;
- ClampHorizontalScroll( actualSize );
+ ClampHorizontalScroll( layoutSize );
+ ClampVerticalScroll( layoutSize );
bool endOfScroll = false;
if( Vector2::ZERO == ( currentScrollPosition - mScrollPosition ) )
// Set the position of the handle.
const bool scrollRightDirection = xSpeed > 0.f;
+ const bool scrollBottomDirection = ySpeed > 0.f;
const bool leftSelectionHandleEvent = Event::LEFT_SELECTION_HANDLE_EVENT == event.type;
const bool rightSelectionHandleEvent = Event::RIGHT_SELECTION_HANDLE_EVENT == event.type;
{
ChangeState( EventData::GRAB_HANDLE_PANNING );
+ // Get the grab handle position in decorator coords.
Vector2 position = mEventData->mDecorator->GetPosition( GRAB_HANDLE );
- // Position the grag handle close to either the left or right edge.
- position.x = scrollRightDirection ? 0.f : mVisualModel->mControlSize.width;
+ if( mEventData->mDecorator->IsHorizontalScrollEnabled() )
+ {
+ // Position the grag handle close to either the left or right edge.
+ position.x = scrollRightDirection ? 0.f : mVisualModel->mControlSize.width;
+ }
+
+ if( mEventData->mDecorator->IsVerticalScrollEnabled() )
+ {
+ position.x = mEventData->mCursorHookPositionX;
+
+ // Position the grag handle close to either the top or bottom edge.
+ position.y = scrollBottomDirection ? 0.f : mVisualModel->mControlSize.height;
+ }
// Get the new handle position.
// The grab handle's position is in decorator's coords. Need to transforms to text's coords.
position.x - mScrollPosition.x,
position.y - mScrollPosition.y );
- mEventData->mUpdateCursorPosition = mEventData->mPrimaryCursorPosition != handlePosition;
- mEventData->mScrollAfterUpdatePosition = mEventData->mUpdateCursorPosition;
- mEventData->mPrimaryCursorPosition = handlePosition;
+ if( mEventData->mPrimaryCursorPosition != handlePosition )
+ {
+ mEventData->mUpdateCursorPosition = true;
+ mEventData->mUpdateGrabHandlePosition = !isSmoothHandlePanEnabled;
+ mEventData->mScrollAfterUpdatePosition = true;
+ mEventData->mPrimaryCursorPosition = handlePosition;
+ }
mEventData->mUpdateInputStyle = mEventData->mUpdateCursorPosition;
+
+ // Updates the decorator if the soft handle panning is enabled.
+ mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled;
}
else if( leftSelectionHandleEvent || rightSelectionHandleEvent )
{
- // TODO: This is recalculating the selection box every time the text is scrolled with the selection handles.
- // Think if something can be done to save power.
-
ChangeState( EventData::SELECTION_HANDLE_PANNING );
+ // Get the selection handle position in decorator coords.
Vector2 position = mEventData->mDecorator->GetPosition( leftSelectionHandleEvent ? Text::LEFT_SELECTION_HANDLE : Text::RIGHT_SELECTION_HANDLE );
- // Position the selection handle close to either the left or right edge.
- position.x = scrollRightDirection ? 0.f : mVisualModel->mControlSize.width;
+ if( mEventData->mDecorator->IsHorizontalScrollEnabled() )
+ {
+ // Position the selection handle close to either the left or right edge.
+ position.x = scrollRightDirection ? 0.f : mVisualModel->mControlSize.width;
+ }
+
+ if( mEventData->mDecorator->IsVerticalScrollEnabled() )
+ {
+ position.x = mEventData->mCursorHookPositionX;
+
+ // Position the grag handle close to either the top or bottom edge.
+ position.y = scrollBottomDirection ? 0.f : mVisualModel->mControlSize.height;
+ }
// Get the new handle position.
// The selection handle's position is in decorator's coords. Need to transform to text's coords.
if( leftSelectionHandleEvent )
{
const bool differentHandles = ( mEventData->mLeftSelectionPosition != handlePosition ) && ( mEventData->mRightSelectionPosition != handlePosition );
- mEventData->mUpdateLeftSelectionPosition = endOfScroll || differentHandles;
- if( differentHandles )
+
+ if( differentHandles || endOfScroll )
{
+ mEventData->mUpdateHighlightBox = true;
+ mEventData->mUpdateLeftSelectionPosition = !isSmoothHandlePanEnabled;
+ mEventData->mUpdateRightSelectionPosition = isSmoothHandlePanEnabled;
mEventData->mLeftSelectionPosition = handlePosition;
}
}
else
{
const bool differentHandles = ( mEventData->mRightSelectionPosition != handlePosition ) && ( mEventData->mLeftSelectionPosition != handlePosition );
- mEventData->mUpdateRightSelectionPosition = endOfScroll || differentHandles;
- if( differentHandles )
+ if( differentHandles || endOfScroll )
{
+ mEventData->mUpdateHighlightBox = true;
+ mEventData->mUpdateRightSelectionPosition = !isSmoothHandlePanEnabled;
+ mEventData->mUpdateLeftSelectionPosition = isSmoothHandlePanEnabled;
mEventData->mRightSelectionPosition = handlePosition;
}
}
{
RepositionSelectionHandles();
- mEventData->mScrollAfterUpdatePosition = true;
+ mEventData->mScrollAfterUpdatePosition = !isSmoothHandlePanEnabled;
}
}
mEventData->mDecoratorUpdated = true;
mEventData->mUpdateLeftSelectionPosition = true;
mEventData->mUpdateRightSelectionPosition = true;
+ mEventData->mUpdateHighlightBox = true;
mEventData->mUpdateCursorPosition = false;
mEventData->mScrollAfterUpdatePosition = ( mEventData->mLeftSelectionPosition != mEventData->mRightSelectionPosition );
mEventData->mScrollAfterUpdatePosition = true;
mEventData->mUpdateLeftSelectionPosition = true;
mEventData->mUpdateRightSelectionPosition = true;
+ mEventData->mUpdateHighlightBox = true;
}
}
const CharacterIndex* const glyphToCharacterBuffer = mVisualModel->mGlyphsToCharacters.Begin();
const CharacterDirection* const modelCharacterDirectionsBuffer = ( 0u != mLogicalModel->mCharacterDirections.Count() ) ? mLogicalModel->mCharacterDirections.Begin() : NULL;
- // TODO: Better algorithm to create the highlight box.
-
const bool isLastCharacter = selectionEnd >= mLogicalModel->mText.Count();
const CharacterDirection startDirection = ( ( NULL == modelCharacterDirectionsBuffer ) ? false : *( modelCharacterDirectionsBuffer + selectionStart ) );
const CharacterDirection endDirection = ( ( NULL == modelCharacterDirectionsBuffer ) ? false : *( modelCharacterDirectionsBuffer + ( selectionEnd - ( isLastCharacter ? 1u : 0u ) ) ) );
// The line's vertical offset of all the lines before the line where the first glyph is laid-out.
selectionBoxInfo->lineOffset = CalculateLineOffset( mVisualModel->mLines,
firstLineIndex );
+ selectionBoxInfo->lineOffset += mScrollPosition.y;
+
lineRun += firstLineIndex;
// The line height is the addition of the line ascender and the line descender.
const float xPosition = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + glyphAdvance * static_cast<float>( isCurrentRightToLeft ? ( numberOfCharactersStart - interGlyphIndex - numberOfCharacters ) : interGlyphIndex );
const float xPositionAdvance = xPosition + static_cast<float>( numberOfCharacters ) * glyphAdvance;
- const float yPosition = selectionBoxInfo->lineOffset + mScrollPosition.y;
+ const float yPosition = selectionBoxInfo->lineOffset;
// Store the min and max 'x' for each line.
selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, xPosition );
const float xPosition = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + ( isCurrentRightToLeft ? ( glyphAdvance * static_cast<float>( numberOfCharacters ) ) : 0.f );
const float xPositionAdvance = xPosition + static_cast<float>( interGlyphIndex ) * glyphAdvance;
- const float yPosition = selectionBoxInfo->lineOffset + mScrollPosition.y;
+ const float yPosition = selectionBoxInfo->lineOffset;
// Store the min and max 'x' for each line.
selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, xPosition );
const float xPosition = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x;
const float xPositionAdvance = xPosition + glyph.advance;
- const float yPosition = selectionBoxInfo->lineOffset + mScrollPosition.y;
+ const float yPosition = selectionBoxInfo->lineOffset;
// Store the min and max 'x' for each line.
selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, xPosition );
++lineIndex;
if( lineIndex < firstLineIndex + numberOfLines )
{
- // Get the selection box info for the next line.
+ // Keep the offset and height of the current selection box.
const float currentLineOffset = selectionBoxInfo->lineOffset;
+ const float currentLineHeight = selectionBoxInfo->lineHeight;
+
+ // Get the selection box info for the next line.
++selectionBoxInfo;
selectionBoxInfo->minX = MAX_FLOAT;
selectionBoxInfo->maxX = MIN_FLOAT;
+ // Update the line's vertical offset.
+ selectionBoxInfo->lineOffset = currentLineOffset + currentLineHeight;
+
// The line height is the addition of the line ascender and the line descender.
// However, the line descender has a negative value, hence the subtraction.
selectionBoxInfo->lineHeight = lineRun->ascender - lineRun->descender;
-
- // Update the line's vertical offset.
- selectionBoxInfo->lineOffset = currentLineOffset + selectionBoxInfo->lineHeight;
}
}
}
}
}
+ if( !mEventData->mDecorator->IsSmoothHandlePanEnabled() )
+ {
+ CursorInfo primaryCursorInfo;
+ GetCursorPosition( mEventData->mLeftSelectionPosition,
+ primaryCursorInfo );
- CursorInfo primaryCursorInfo;
- GetCursorPosition( mEventData->mLeftSelectionPosition,
- primaryCursorInfo );
+ const Vector2 primaryPosition = primaryCursorInfo.primaryPosition + mScrollPosition;
- CursorInfo secondaryCursorInfo;
- GetCursorPosition( mEventData->mRightSelectionPosition,
- secondaryCursorInfo );
+ mEventData->mDecorator->SetPosition( LEFT_SELECTION_HANDLE,
+ primaryPosition.x,
+ primaryCursorInfo.lineOffset + mScrollPosition.y,
+ primaryCursorInfo.lineHeight );
- const Vector2 primaryPosition = primaryCursorInfo.primaryPosition + mScrollPosition;
- const Vector2 secondaryPosition = secondaryCursorInfo.primaryPosition + mScrollPosition;
+ CursorInfo secondaryCursorInfo;
+ GetCursorPosition( mEventData->mRightSelectionPosition,
+ secondaryCursorInfo );
- mEventData->mDecorator->SetPosition( LEFT_SELECTION_HANDLE,
- primaryPosition.x,
- primaryCursorInfo.lineOffset + mScrollPosition.y,
- primaryCursorInfo.lineHeight );
+ const Vector2 secondaryPosition = secondaryCursorInfo.primaryPosition + mScrollPosition;
- mEventData->mDecorator->SetPosition( RIGHT_SELECTION_HANDLE,
- secondaryPosition.x,
- secondaryCursorInfo.lineOffset + mScrollPosition.y,
- secondaryCursorInfo.lineHeight );
+ mEventData->mDecorator->SetPosition( RIGHT_SELECTION_HANDLE,
+ secondaryPosition.x,
+ secondaryCursorInfo.lineOffset + mScrollPosition.y,
+ secondaryCursorInfo.lineHeight );
+ }
// Cursor to be positioned at end of selection so if selection interrupted and edit mode restarted the cursor will be at end of selection
mEventData->mPrimaryCursorPosition = ( indicesSwapped ) ? mEventData->mLeftSelectionPosition : mEventData->mRightSelectionPosition;
cursorIndex += numberOfCharacters;
}
+ // Will update the cursor hook position.
+ mEventData->mUpdateCursorHookPosition = true;
+
return cursorIndex;
}
cursorInfo.lineHeight );
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Primary cursor position: %f,%f\n", cursorPosition.x, cursorPosition.y );
- // Sets the grab handle position.
- mEventData->mDecorator->SetPosition( GRAB_HANDLE,
- cursorPosition.x,
- cursorInfo.lineOffset + mScrollPosition.y,
- cursorInfo.lineHeight );
+ if( mEventData->mUpdateGrabHandlePosition )
+ {
+ // Sets the grab handle position.
+ mEventData->mDecorator->SetPosition( GRAB_HANDLE,
+ cursorPosition.x,
+ cursorInfo.lineOffset + mScrollPosition.y,
+ cursorInfo.lineHeight );
+ }
if( cursorInfo.isSecondaryCursor )
{
}
}
-void Controller::Impl::ScrollToMakePositionVisible( const Vector2& position )
+void Controller::Impl::ScrollToMakePositionVisible( const Vector2& position, float lineHeight )
{
- const float cursorWidth = mEventData->mDecorator ? mEventData->mDecorator->GetCursorWidth() : 0.f;
+ const float cursorWidth = mEventData->mDecorator ? static_cast<float>( mEventData->mDecorator->GetCursorWidth() ) : 0.f;
// position is in actor's coords.
- const float positionEnd = position.x + cursorWidth;
+ const float positionEndX = position.x + cursorWidth;
+ const float positionEndY = position.y + lineHeight;
// Transform the position to decorator coords.
- const float decoratorPositionBegin = position.x + mScrollPosition.x;
- const float decoratorPositionEnd = positionEnd + mScrollPosition.x;
+ const float decoratorPositionBeginX = position.x + mScrollPosition.x;
+ const float decoratorPositionEndX = positionEndX + mScrollPosition.x;
- if( decoratorPositionBegin < 0.f )
+ const float decoratorPositionBeginY = position.y + mScrollPosition.y;
+ const float decoratorPositionEndY = positionEndY + mScrollPosition.y;
+
+ if( decoratorPositionBeginX < 0.f )
{
mScrollPosition.x = -position.x;
}
- else if( decoratorPositionEnd > mVisualModel->mControlSize.width )
+ else if( decoratorPositionEndX > mVisualModel->mControlSize.width )
+ {
+ mScrollPosition.x = mVisualModel->mControlSize.width - positionEndX;
+ }
+
+ if( decoratorPositionBeginY < 0.f )
+ {
+ mScrollPosition.y = -position.y;
+ }
+ else if( decoratorPositionEndY > mVisualModel->mControlSize.height )
{
- mScrollPosition.x = mVisualModel->mControlSize.width - positionEnd;
+ mScrollPosition.y = mVisualModel->mControlSize.height - positionEndY;
}
}
// Calculate the offset to match the cursor position before the character was deleted.
mScrollPosition.x = currentCursorPosition.x - cursorInfo.primaryPosition.x;
+ mScrollPosition.y = currentCursorPosition.y - cursorInfo.lineOffset;
ClampHorizontalScroll( mVisualModel->GetLayoutSize() );
+ ClampVerticalScroll( mVisualModel->GetLayoutSize() );
// Makes the new cursor position visible if needed.
- ScrollToMakePositionVisible( cursorInfo.primaryPosition );
+ ScrollToMakePositionVisible( cursorInfo.primaryPosition, cursorInfo.lineHeight );
}
void Controller::Impl::RequestRelayout()
CharacterIndex mPreEditStartPosition; ///< Used to remove the pre-edit text if necessary.
Length mPreEditLength; ///< Used to remove the pre-edit text if necessary.
+ float mCursorHookPositionX; ///< Used to move the cursor with the keys or when scrolling the text vertically with the handles.
+
bool mIsShowingPlaceholderText : 1; ///< True if the place-holder text is being displayed.
bool mPreEditFlag : 1; ///< True if the model contains text in pre-edit state.
bool mDecoratorUpdated : 1; ///< True if the decorator was updated during event processing.
bool mGrabHandleEnabled : 1; ///< True if grab handle is enabled.
bool mGrabHandlePopupEnabled : 1; ///< True if the grab handle popu-up should be shown.
bool mSelectionEnabled : 1; ///< True if selection handles, highlight etc. are enabled.
- bool mHorizontalScrollingEnabled : 1; ///< True if horizontal scrolling is enabled.
- bool mVerticalScrollingEnabled : 1; ///< True if vertical scrolling is enabled.
+ bool mUpdateCursorHookPosition : 1; ///< True if the cursor hook position must be updated. Used to move the cursor with the keys 'up' and 'down'.
bool mUpdateCursorPosition : 1; ///< True if the visual position of the cursor must be recalculated.
+ bool mUpdateGrabHandlePosition : 1; ///< True if the visual position of the grab handle must be recalculated.
bool mUpdateLeftSelectionPosition : 1; ///< True if the visual position of the left selection handle must be recalculated.
bool mUpdateRightSelectionPosition : 1; ///< True if the visual position of the right selection handle must be recalculated.
+ bool mUpdateHighlightBox : 1; ///< True if the text selection high light box must be updated.
bool mScrollAfterUpdatePosition : 1; ///< Whether to scroll after the cursor position is updated.
bool mScrollAfterDelete : 1; ///< Whether to scroll after delete characters.
bool mAllTextSelected : 1; ///< True if the selection handles are selecting all the text.
* @pre mEventData must not be NULL. (there is a text-input or selection capabilities).
*
* @param[in] position A position in text coords.
+ * @param[in] lineHeight The line height for the given position.
*
* This method is called after inserting text, moving the cursor with the grab handle or the keypad,
* or moving the selection handles.
*/
- void ScrollToMakePositionVisible( const Vector2& position );
+ void ScrollToMakePositionVisible( const Vector2& position, float lineHeight );
/**
* @brief Scrolls the text to make the cursor visible.
// Recalculate the selection highlight as the metrics may have changed.
eventData->mUpdateLeftSelectionPosition = true;
eventData->mUpdateRightSelectionPosition = true;
+ eventData->mUpdateHighlightBox = true;
return fontDescriptionRun;
}
return offset;
}
+void Controller::SetHorizontalScrollEnabled( bool enable )
+{
+ if( ( NULL != mImpl->mEventData ) &&
+ mImpl->mEventData->mDecorator )
+ {
+ mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled( enable );
+ }
+}
+
+bool Controller::IsHorizontalScrollEnabled() const
+{
+ if( ( NULL != mImpl->mEventData ) &&
+ mImpl->mEventData->mDecorator )
+ {
+ return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
+ }
+
+ return false;
+}
+
+void Controller::SetVerticalScrollEnabled( bool enable )
+{
+ if( ( NULL != mImpl->mEventData ) &&
+ mImpl->mEventData->mDecorator )
+ {
+ if( mImpl->mEventData->mDecorator )
+ {
+ mImpl->mEventData->mDecorator->SetVerticalScrollEnabled( enable );
+ }
+ }
+}
+
+bool Controller::IsVerticalScrollEnabled() const
+{
+ if( ( NULL != mImpl->mEventData ) &&
+ mImpl->mEventData->mDecorator )
+ {
+ return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
+ }
+
+ return false;
+}
+
+void Controller::SetSmoothHandlePanEnabled( bool enable )
+{
+ if( ( NULL != mImpl->mEventData ) &&
+ mImpl->mEventData->mDecorator )
+ {
+ mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled( enable );
+ }
+}
+
+bool Controller::IsSmoothHandlePanEnabled() const
+{
+ if( ( NULL != mImpl->mEventData ) &&
+ mImpl->mEventData->mDecorator )
+ {
+ return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
+ }
+
+ return false;
+}
+
void Controller::SetText( const std::string& text )
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
// As the font changes, recalculate the handle positions is needed.
mImpl->mEventData->mUpdateLeftSelectionPosition = true;
mImpl->mEventData->mUpdateRightSelectionPosition = true;
+ mImpl->mEventData->mUpdateHighlightBox = true;
mImpl->mEventData->mScrollAfterUpdatePosition = true;
}
}
// As the font might change, recalculate the handle positions is needed.
mImpl->mEventData->mUpdateLeftSelectionPosition = true;
mImpl->mEventData->mUpdateRightSelectionPosition = true;
+ mImpl->mEventData->mUpdateHighlightBox = true;
mImpl->mEventData->mScrollAfterUpdatePosition = true;
}
}
// As the font might change, recalculate the handle positions is needed.
mImpl->mEventData->mUpdateLeftSelectionPosition = true;
mImpl->mEventData->mUpdateRightSelectionPosition = true;
+ mImpl->mEventData->mUpdateHighlightBox = true;
mImpl->mEventData->mScrollAfterUpdatePosition = true;
}
}
// As the font might change, recalculate the handle positions is needed.
mImpl->mEventData->mUpdateLeftSelectionPosition = true;
mImpl->mEventData->mUpdateRightSelectionPosition = true;
+ mImpl->mEventData->mUpdateHighlightBox = true;
mImpl->mEventData->mScrollAfterUpdatePosition = true;
}
}
// As the font might change, recalculate the handle positions is needed.
mImpl->mEventData->mUpdateLeftSelectionPosition = true;
mImpl->mEventData->mUpdateRightSelectionPosition = true;
+ mImpl->mEventData->mUpdateHighlightBox = true;
mImpl->mEventData->mScrollAfterUpdatePosition = true;
}
}
}
else
{
+ // Show cursor and grabhandle on first tap, this matches the behaviour of tapping when already editing
mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
}
relayoutNeeded = true;
}
void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
- // Show cursor and grabhandle on first tap, this matches the behaviour of tapping when already editing
{
DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
float GetAutoScrollLineAlignment() const;
/**
+ * @brief Enables the horizontal scrolling.
+ *
+ * @param[in] enable Whether to enable the horizontal scrolling.
+ */
+ void SetHorizontalScrollEnabled( bool enable );
+
+ /**
+ * @brief Retrieves whether the horizontal scrolling is enabled.
+ *
+ * @return @e true if the horizontal scrolling is enabled, otherwise it returns @e false.
+ */
+ bool IsHorizontalScrollEnabled() const;
+
+ /**
+ * @brief Enables the vertical scrolling.
+ *
+ * @param[in] enable Whether to enable the vertical scrolling.
+ */
+ void SetVerticalScrollEnabled( bool enable );
+
+ /**
+ * @brief Retrieves whether the verticall scrolling is enabled.
+ *
+ * @return @e true if the vertical scrolling is enabled, otherwise it returns @e false.
+ */
+ bool IsVerticalScrollEnabled() const;
+
+ /**
+ * @brief Enables the smooth handle panning.
+ *
+ * @param[in] enable Whether to enable the smooth handle panning.
+ */
+ void SetSmoothHandlePanEnabled( bool enable );
+
+ /**
+ * @brief Retrieves whether the smooth handle panning is enabled.
+ *
+ * @return @e true if the smooth handle panning is enabled.
+ */
+ bool IsSmoothHandlePanEnabled() const;
+
+ /**
* @brief Replaces any text previously set.
*
* @note This will be converted into UTF-32 when stored in the text model.