-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/controls/text-input/text-input-decorator-impl.h>
+// EXTERNAL INCLUDES
+#include <dali/public-api/adaptor-framework/clipboard.h>
+#include <dali/public-api/common/stage.h>
+#include <dali/public-api/events/pan-gesture.h>
+#include <dali/public-api/object/property-notification.h>
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/internal/controls/text-input/text-input-decorator-impl.h>
-
#include <dali-toolkit/internal/controls/text-input/text-input-handles-impl.h>
using namespace Dali;
Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TEXT_INPUT_DECORATOR");
#endif
- const Vector3 DEFAULT_SELECTION_HANDLE_SIZE( 51.0f, 79.0f, 0.0f );
- const float TOP_HANDLE_TOP_OFFSET(-1.5f); // Offset between top handle and cutCopyPaste pop-up
- const float BOTTOM_HANDLE_BOTTOM_OFFSET(1.5f); // Offset between bottom handle and cutCopyPaste pop-up
- const float UI_Z_OFFSET( 0.2f ); // Text Selection Handles/Cursor z-offset.
- const Vector3 UI_OFFSET(0.0f, 0.0f, UI_Z_OFFSET); // Text Selection Handles/Cursor offset.
- const char* DEFAULT_CURSOR( DALI_IMAGE_DIR "cursor.png" );
- const Vector4 DEFAULT_CURSOR_IMAGE_9_BORDER( 2.0f, 2.0f, 2.0f, 2.0f );
- const std::size_t CURSOR_BLINK_INTERVAL = 500; // Cursor blink interval
- const float CURSOR_THICKNESS(6.0f);
- const Degree CURSOR_ANGLE_OFFSET(2.0f); // Offset from the angle
-
- const unsigned int SCROLL_TICK_INTERVAL = 50u;
- const float SCROLL_THRESHOLD = 10.f;
- const float SCROLL_SPEED = 15.f;
-
- /**
- * Whether the given position plus the cursor size offset is inside the given boundary.
- *
- * @param[in] position The given position.
- * @param[in] cursorSize The cursor size.
- * @param[in] controlSize The given boundary.
- * @param[in] threshold imaginary indent around boundary that will trigger the position to be outside of control.
- *
- * @return whether the given position is inside the given boundary.
- */
- bool IsPositionWithinControl( const Vector3& position, const Size& cursorSize, const Vector3& controlSize, const Vector2 threshold = Vector2::ZERO )
- {
- return ( position.x >= -Math::MACHINE_EPSILON_1000 + threshold.x ) &&
- ( position.x <= controlSize.width - threshold.x + Math::MACHINE_EPSILON_1000 ) &&
- ( position.y - cursorSize.height >= -Math::MACHINE_EPSILON_1000 + threshold.y ) &&
- ( position.y <= controlSize.height + Math::MACHINE_EPSILON_1000 - threshold.y);
- }
+const Vector3 DEFAULT_SELECTION_HANDLE_SIZE( 51.0f, 79.0f, 0.0f );
+const float TOP_HANDLE_TOP_OFFSET(-1.5f); // Offset between top handle and cutCopyPaste pop-up
+const float BOTTOM_HANDLE_BOTTOM_OFFSET(1.5f); // Offset between bottom handle and cutCopyPaste pop-up
+const float UI_Z_OFFSET( 0.2f ); // Text Selection Handles/Cursor z-offset.
+const Vector3 UI_OFFSET(0.0f, 0.0f, UI_Z_OFFSET); // Text Selection Handles/Cursor offset.
+const char* DEFAULT_CURSOR( DALI_IMAGE_DIR "cursor.png" );
+const Vector4 DEFAULT_CURSOR_IMAGE_9_BORDER( 2.0f, 2.0f, 2.0f, 2.0f );
+const std::size_t CURSOR_BLINK_INTERVAL = 500; // Cursor blink interval
+const float CURSOR_THICKNESS(6.0f);
+const Degree CURSOR_ANGLE_OFFSET(2.0f); // Offset from the angle
+
+const unsigned int SCROLL_TICK_INTERVAL = 50u;
+const float SCROLL_THRESHOLD = 10.f;
+const float SCROLL_SPEED = 15.f;
+
+/**
+ * Whether the given position plus the cursor size offset is inside the given boundary.
+ *
+ * @param[in] position The given position.
+ * @param[in] cursorSize The cursor size.
+ * @param[in] controlSize The given boundary.
+ * @param[in] threshold imaginary indent around boundary that will trigger the position to be outside of control.
+ *
+ * @return whether the given position is inside the given boundary.
+ */
+bool IsPositionWithinControl( const Vector3& position, const Size& cursorSize, const Vector3& controlSize, const Vector2 threshold = Vector2::ZERO )
+{
+ return ( position.x >= -Math::MACHINE_EPSILON_1000 + threshold.x ) &&
+ ( position.x <= controlSize.width - threshold.x + Math::MACHINE_EPSILON_1000 ) &&
+ ( position.y - cursorSize.height >= -Math::MACHINE_EPSILON_1000 + threshold.y ) &&
+ ( position.y <= controlSize.height + Math::MACHINE_EPSILON_1000 - threshold.y);
+}
+
}
namespace Dali
Decorator::Decorator( TextViewCharacterPositioning& textViewManager, TextInputTextStyle& textStyle ):
mTextViewCharacterPositioning( textViewManager ),
mTextStyle( textStyle ),
+ mSelectionHandleOnePosition(0),
+ mSelectionHandleTwoPosition(0),
+ mGrabHandlePosition(0),
mCursorPosition( 0 ),
mTextHighlight( textViewManager ),
mCursorBlinkStatus( true ),
mCursorVisibility( true ),
+ mCursorRTLEnabled( false ),
+ mIsGrabHandleInScrollArea( false ),
+ mIsCursorInScrollArea( false ),
mGrabHandleEnabled( true )
{
}
/**
* Selection Handles
*/
-void Decorator::OnHandlePan(Actor actor, PanGesture gesture)
+void Decorator::OnHandlePan(Actor actor, const PanGesture& gesture)
{
Actor selectionHandleOne = mTextInputHandles.GetSelectionHandleOne();
Actor selectionHandleTwo = mTextInputHandles.GetSelectionHandleTwo();
// Revert back to non-pressed selection handle images
if ( actor.GetParent() == mTextInputHandles.GetSelectionHandleOne() )
{
- mSelectionHandleOneActualPosition = MoveSelectionHandle( selectionHandleOne, mSelectionHandleOneActualPosition, mSelectionHandleOnePosition, gesture.displacement );
+ mSelectionHandleOneActualPosition = MoveSelectionHandle( selectionHandleOne, mSelectionHandleOneActualPosition, mSelectionHandleOnePosition, gesture.displacement );
ShowPopupCutCopyPaste();
- ShowPopUp();
}
else if ( actor.GetParent() == mTextInputHandles.GetSelectionHandleTwo() )
{
mSelectionHandleTwoActualPosition = MoveSelectionHandle( selectionHandleTwo, mSelectionHandleTwoActualPosition, mSelectionHandleTwoPosition, gesture.displacement );
ShowPopupCutCopyPaste();
- ShowPopUp();
}
else if ( actor.GetParent() == mTextInputHandles.GetGrabHandle() )
{
MoveGrabHandle( gesture.displacement );
SetCursorVisibility( true );
ShowPopupCutCopyPaste();
- ShowPopUp();
}
}
break;
selectionHandle.SetPosition( actualPosition += DEFAULT_HANDLE_OFFSET );
- if( mTextViewCharacterPositioning.IsScrollEnabled() )
- {
- const Vector3 controlSize = mTextViewCharacterPositioning.GetTextView().GetCurrentSize();
- const Size cursorSize( GetCursorSizeAt( position ) );
- bool handleVisible = IsPositionWithinControl( actualPosition, Vector2(DEFAULT_HANDLE_OFFSET.width, DEFAULT_HANDLE_OFFSET.height), controlSize );
-
- DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextInputDecorationLayouter::PositionSelectionHandle controlSize[%f,%f] cursorSize[%f,%f] actualPos[%f,%f] visible[%s] \n",
- controlSize.x, controlSize.y, cursorSize.x, cursorSize.y, actualPosition.x, actualPosition.y, ( handleVisible )?"true":"false" );
-
- selectionHandle.SetVisible( handleVisible );
- }
return actualPosition;
}
mTextInputHandles.SetSelectionHandleTwoVisibility( visible );
}
-bool Decorator::OnHandleReleased()
-{
- ShowPopUp();
- return false;
-}
-
void Decorator::PositionSelectionHandles( std::size_t start, std::size_t end )
{
mSelectionHandleOnePosition = start;
mSelectionHandleOneActualPosition = PositionSelectionHandle( mTextInputHandles.GetSelectionHandleOne(), mSelectionHandleOnePosition );
mSelectionHandleTwoActualPosition = PositionSelectionHandle( mTextInputHandles.GetSelectionHandleTwo(), mSelectionHandleTwoPosition );
-
- mTextInputHandles.ReleasedSignal().Connect( this, &Decorator::OnHandleReleased );
}
Vector3 Decorator::MoveSelectionHandle( Actor selectionHandle,
{
Vector3 actualHandlePosition;
actualSelectionHandlePosition.x += displacement.x * selectionHandle.GetCurrentScale().x;
- actualSelectionHandlePosition.y += displacement.y * selectionHandle.GetCurrentScale().y;;
+ actualSelectionHandlePosition.y += displacement.y * selectionHandle.GetCurrentScale().y;
// Selection handles should jump to the nearest character
std::size_t newHandlePosition = 0;
bool handleVisible = true;
- Vector2 min, max;
- if( mTextViewCharacterPositioning.IsScrollEnabled() )
- {
- const Vector3 controlSize = mTextViewCharacterPositioning.GetTextView().GetCurrentSize();
- const Size cursorSize( GetCursorSizeAt( newHandlePosition ) );
-
- handleVisible = IsPositionWithinControl( actualHandlePosition,
- cursorSize,
- controlSize );
-
- if( handleVisible )
- {
- StopScrollTimer();
- mCurrentHandlePosition = actualHandlePosition;
- mScrollDisplacement = Vector2::ZERO;
- }
- else
- {
-
- if( ( actualHandlePosition.x < SCROLL_THRESHOLD ) && ( displacement.x <= 0.f ) )
- {
- mScrollDisplacement.x = -SCROLL_SPEED;
- }
- else if( ( actualHandlePosition.x > controlSize.width - SCROLL_THRESHOLD ) && ( displacement.x >= 0.f ) )
- {
- mScrollDisplacement.x = SCROLL_SPEED;
- }
- if( ( actualHandlePosition.y < SCROLL_THRESHOLD ) && ( displacement.y <= 0.f ) )
- {
- mScrollDisplacement.y = -SCROLL_SPEED;
- }
- else if( ( actualHandlePosition.y > controlSize.height - SCROLL_THRESHOLD ) && ( displacement.y >= 0.f ) )
- {
- mScrollDisplacement.y = SCROLL_SPEED;
- }
- DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextInputDecorationLayouter::MoveSelectionHandle Handle not visible scroll displacement [%f]\n", mScrollDisplacement.x);
-
- StartScrollTimer();
- }
- }
-
if ( handleVisible && // Ensure the handle is visible.
( newHandlePosition != currentSelectionHandlePosition ) && // Ensure the handle has moved.
( newHandlePosition != mSelectionHandleTwoPosition ) && // Ensure new handle position not the same position as an existing handle.
bool handleVisible = true;
- if( mTextViewCharacterPositioning.IsScrollEnabled() )
- {
- const Vector3 controlSize = mTextViewCharacterPositioning.GetTextView().GetCurrentSize();
- const Size cursorSize( GetCursorSizeAt( newHandlePosition ) );
- // Scrolls the text if the handle is not in a visible position
- handleVisible = IsPositionWithinControl( actualHandlePosition,
- cursorSize,
- controlSize );
-
- DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextInputDecorationLayouter::MoveGrabHandle handleVisible[%s]\n", ( handleVisible )?"true":"false");
-
- if( handleVisible )
- {
- StopScrollTimer();
- mCurrentHandlePosition = actualHandlePosition;
- mScrollDisplacement = Vector2::ZERO;
- }
- else
- {
- if( ( actualHandlePosition.x < SCROLL_THRESHOLD ) && ( displacement.x <= 0.f ) )
- {
- mScrollDisplacement.x = -SCROLL_SPEED;
- }
- else if( ( actualHandlePosition.x > controlSize.width - SCROLL_THRESHOLD ) && ( displacement.x >= 0.f ) )
- {
- mScrollDisplacement.x = SCROLL_SPEED;
- }
- if( ( actualHandlePosition.y < SCROLL_THRESHOLD ) && ( displacement.y <= 0.f ) )
- {
- mScrollDisplacement.y = -SCROLL_SPEED;
- }
- else if( ( actualHandlePosition.y > controlSize.height - SCROLL_THRESHOLD ) && ( displacement.y >= 0.f ) )
- {
- mScrollDisplacement.y = SCROLL_SPEED;
- }
- StartScrollTimer();
- }
- }
-
- if( ( newHandlePosition != mGrabHandlePosition ) && // Only redraw cursor and do updates if position changed
+ if( ( newHandlePosition != mGrabHandlePosition ) && // Only redraw cursor and do updates if position changed
( handleVisible ) )// and the new position is visible (if scroll is not enabled, it's always true).
{
mActualGrabHandlePosition = actualHandlePosition;
if ( !mTextViewCharacterPositioning.IsStyledTextEmpty() && ( cursorPosition > 0 ) )
{
DALI_ASSERT_DEBUG( ( 0 <= cursorPosition-1 ) && ( cursorPosition-1 < mTextViewCharacterPositioning.StyledTextSize() ) );
- const TextStyle inputStyle = mTextViewCharacterPositioning.GetStyleAt( cursorPosition-1 );
- mTextStyle.SetInputStyle( inputStyle );
}
}
}
// Get height of cursor and set its size
Size size( CURSOR_THICKNESS, 0.0f );
- if ( !mTextViewCharacterPositioning.IsTextEmpty() )
- {
- Vector2 min, max; // out parameters for GetRowRectFromCharacterPosition
- size.height = mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( mTextViewCharacterPositioning.GetVisualPosition( cursorPosition ), min, max ).height;
- }
- else
- {
- // Measure Font so know how big text will be if no initial text to measure.
- size.height = mTextViewCharacterPositioning.GetLineHeight( nthChar );
- }
+
+ Vector2 min, max; // out parameters for GetRowRectFromCharacterPosition
+ size.height = mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( mTextViewCharacterPositioning.GetVisualPosition( cursorPosition ), min, max ).height;
mCursor.SetSize(size);
{
DALI_ASSERT_DEBUG( ( 0 <= cursorPosition-1 ) && ( cursorPosition-1 < mTextViewCharacterPositioning.StyledTextSize() ) );
const TextStyle styleAtCursor = mTextViewCharacterPositioning.GetStyleAt( cursorPosition-1 );
- mCursor.SetRotation( styleAtCursor.GetItalics() ? Degree( styleAtCursor.GetItalicsAngle() - CURSOR_ANGLE_OFFSET ) : Degree( 0.f ), Vector3::ZAXIS );
+ mCursor.SetRotation( styleAtCursor.IsItalicsEnabled() ? Degree( styleAtCursor.GetItalicsAngle() - CURSOR_ANGLE_OFFSET ) : Degree( 0.f ), Vector3::ZAXIS );
}
DALI_ASSERT_DEBUG( cursorPosition <= mTextViewCharacterPositioning.GetNumberOfCharactersInText() );
SetAltCursorEnabled( altPositionValid );
- if(!altPositionValid)
- {
- mCursor.SetPosition( position + UI_OFFSET );
- }
- else
- {
- size.height *= 0.5f;
- mCursor.SetSize(size);
- mCursor.SetPosition( position + UI_OFFSET - Vector3(0.0f, directionRTL ? 0.0f : size.height, 0.0f) );
- Vector2 min, max; // out parameters for GetRowRectFromCharacterPosition
- Size rowSize = mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( mTextViewCharacterPositioning.GetVisualPosition( cursorPosition ), min, max );
- size.height = rowSize.height * 0.5f;
- mCursorRTL.SetSize(size);
- mCursorRTL.SetPosition( altPosition + UI_OFFSET - Vector3(0.0f, directionRTL ? size.height : 0.0f, 0.0f) );
- }
-
- if( mTextViewCharacterPositioning.IsScrollEnabled() )
- {
- // Whether cursor and grab handle are inside the boundaries of the text-input when text scroll is enabled.
- const Vector3& controlSize = mTextViewCharacterPositioning.GetTextView().GetCurrentSize();
- mIsCursorInScrollArea = mIsGrabHandleInScrollArea = IsPositionWithinControl( position, size, controlSize );
- }
+ mCursor.SetPosition( position + UI_OFFSET );
}
}
{
mHighlightMeshActor = MeshActor::New( mTextHighlight.CreateHighLightMesh() );
mHighlightMeshActor.SetName( "HighlightMeshActor" );
- mHighlightMeshActor.SetInheritShaderEffect( false );
mHighlightMeshActor.SetAffectedByLighting(false);
parent.Add( mHighlightMeshActor );
}
// When text is selected, show popup above top handle (and text), or below bottom handle.
// topHandle: referring to the top most point of the handle or the top line of selection.
- if ( mSelectionHandleTwoActualPosition.y > mSelectionHandleOneActualPosition.y )
+ if ( mSelectionHandleTwoActualPosition.y > mSelectionHandleOneActualPosition.y ) // Handle may switch positions so calculate which is top.
{
topHandle = mSelectionHandleOneActualPosition;
rowSize= mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( mSelectionHandleOnePosition, min, max );
void Decorator::HidePopUp( bool animate, bool signalFinished )
{
- if ( ( mPopUpPanel.GetState() == TextInputPopupNew::StateShowing ) || ( mPopUpPanel.GetState() == TextInputPopupNew::StateShown ) )
- {
- mPopUpPanel.Hide( animate );
- }
}
void Decorator::AddPopupOption(const std::string& name, const std::string& caption, const Image icon, bool finalOption)
scrollPosition += scrollDelta;
mTextViewCharacterPositioning.SetScrollPosition( scrollPosition );
- // If scroll position goes too far TextView will trim it to fit.
- if ( mTextViewCharacterPositioning.IsScrollPositionTrimmed() )
- {
- StopScrollTimer();
- }
-
mActualGrabHandlePosition = mTextViewCharacterPositioning.GetActualPositionFromCharacterPosition( newGrabHandlePosition ).GetVectorXY();
}
}
scrollPosition += scrollDelta;
mTextViewCharacterPositioning.SetScrollPosition( scrollPosition );
- if( mTextViewCharacterPositioning.IsScrollPositionTrimmed() )
- {
- StopScrollTimer();
- }
-
mSelectionHandleOnePosition = newHandleOnePosition;
mSelectionHandleOneActualPosition = mTextViewCharacterPositioning.GetActualPositionFromCharacterPosition( mSelectionHandleOnePosition ).GetVectorXY();
}
scrollPosition += scrollDelta;
mTextViewCharacterPositioning.SetScrollPosition( scrollPosition );
- if( mTextViewCharacterPositioning.IsScrollPositionTrimmed() )
- {
- StopScrollTimer();
- }
-
mSelectionHandleTwoPosition = newHandleTwoPosition;
mCurrentHandlePosition = mTextViewCharacterPositioning.GetActualPositionFromCharacterPosition( mSelectionHandleTwoPosition ).GetVectorXY();