#include <dali-toolkit/internal/text/bidirectional-support.h>
#include <dali-toolkit/internal/text/character-set-conversion.h>
#include <dali-toolkit/internal/text/layouts/layout-parameters.h>
+#include <dali-toolkit/internal/text/markup-processor.h>
#include <dali-toolkit/internal/text/text-controller-impl.h>
namespace
}
}
+void Controller::SetMarkupProcessorEnabled( bool enable )
+{
+ mImpl->mMarkupProcessorEnabled = enable;
+}
+
+bool Controller::IsMarkupProcessorEnabled() const
+{
+ return mImpl->mMarkupProcessorEnabled;
+}
+
void Controller::SetText( const std::string& text )
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText\n" );
// Reset keyboard as text changed
mImpl->ResetImfManager();
- // Remove the previously set text
+ // Remove the previously set text and style.
ResetText();
+ // Remove the style.
+ ClearStyleData();
+
CharacterIndex lastCursorIndex = 0u;
if( mImpl->mEventData )
{
// If popup shown then hide it by switching to Editing state
if( ( EventData::SELECTING == mImpl->mEventData->mState ) ||
- ( EventData::SELECTION_CHANGED == mImpl->mEventData->mState ) ||
( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
- ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) )
+ ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) ||
+ ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState ) )
{
mImpl->ChangeState( EventData::EDITING );
}
if( !text.empty() )
{
+ MarkupProcessData markupProcessData( mImpl->mLogicalModel->mColorRuns );
+
+ Length textSize = 0u;
+ const uint8_t* utf8 = NULL;
+ if( mImpl->mMarkupProcessorEnabled )
+ {
+ ProcessMarkupString( text, markupProcessData );
+ textSize = markupProcessData.markupProcessedText.size();
+
+ // This is a bit horrible but std::string returns a (signed) char*
+ utf8 = reinterpret_cast<const uint8_t*>( markupProcessData.markupProcessedText.c_str() );
+ }
+ else
+ {
+ textSize = text.size();
+
+ // This is a bit horrible but std::string returns a (signed) char*
+ utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
+ }
+
// Convert text into UTF-32
Vector<Character>& utf32Characters = mImpl->mLogicalModel->mText;
- utf32Characters.Resize( text.size() );
-
- // This is a bit horrible but std::string returns a (signed) char*
- const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
+ utf32Characters.Resize( textSize );
// Transform a text array encoded in utf8 into an array encoded in utf32.
// It returns the actual number of characters.
- Length characterCount = Utf8ToUtf32( utf8, text.size(), utf32Characters.Begin() );
+ Length characterCount = Utf8ToUtf32( utf8, textSize, utf32Characters.Begin() );
utf32Characters.Resize( characterCount );
- DALI_ASSERT_DEBUG( text.size() >= characterCount && "Invalid UTF32 conversion length" );
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, text.size(), mImpl->mLogicalModel->mText.Count() );
+ DALI_ASSERT_DEBUG( textSize >= characterCount && "Invalid UTF32 conversion length" );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, textSize, mImpl->mLogicalModel->mText.Count() );
// To reset the cursor position
lastCursorIndex = characterCount;
return mImpl->mMaximumNumberOfCharacters;
}
-void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily, bool userDefined )
+void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
{
if( !mImpl->mFontDefaults )
{
}
mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
- DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s userDefined: %s\n", defaultFontFamily.c_str(), userDefined ? "true":"false" );
- mImpl->mUserDefinedFontFamily = userDefined;
+ DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
+ mImpl->mUserDefinedFontFamily = true;
// Clear the font-specific data
ClearFontData();
cursorIndex = oldCursorIndex + cursorOffset;
}
- if( (cursorIndex + numberOfChars) > currentText.Count() )
+ if( ( cursorIndex + numberOfChars ) > currentText.Count() )
{
numberOfChars = currentText.Count() - cursorIndex;
}
- if( (cursorIndex + numberOfChars) <= currentText.Count() )
+ if( ( cursorIndex + numberOfChars ) <= currentText.Count() )
{
+ // Update the input style and remove the text's style before removing the text.
+ if( mImpl->mEventData )
+ {
+ // Set first the default input style.
+ mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
+
+ // Update the input style.
+ mImpl->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
+
+ // Remove the text's style before removing the text.
+ mImpl->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfChars );
+ }
+
+ // Remove the characters.
Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
Vector<Character>::Iterator last = first + numberOfChars;
return mImpl->mVisualModel->GetUnderlineHeight();
}
+void Controller::SetInputColor( const Vector4& color )
+{
+ if( mImpl->mEventData )
+ {
+ mImpl->mEventData->mInputStyle.textColor = color;
+
+ if( EventData::SELECTING == mImpl->mEventData->mState )
+ {
+ const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
+
+ // Get start and end position of selection
+ const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
+ const Length lengthOfSelectedText = ( handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition ) - startOfSelectedText;
+
+ // Add the color run.
+ const VectorBase::SizeType numberOfRuns = mImpl->mLogicalModel->mColorRuns.Count();
+ mImpl->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
+
+ ColorRun& colorRun = *( mImpl->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
+ colorRun.color = color;
+ colorRun.characterRun.characterIndex = startOfSelectedText;
+ colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
+
+ // Request to relayout.
+ mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending | COLOR );
+ mImpl->RequestRelayout();
+ }
+ }
+}
+
+const Vector4& Controller::GetInputColor() const
+{
+ if( mImpl->mEventData )
+ {
+ return mImpl->mEventData->mInputStyle.textColor;
+ }
+
+ // Return the default text's color if there is no EventData.
+ return mImpl->mTextColor;
+
+}
+
void Controller::SetEnableCursorBlink( bool enable )
{
DALI_ASSERT_DEBUG( NULL != mImpl->mEventData && "TextInput disabled" );
ProcessModifyEvents();
Size layoutSize;
- if( width != mImpl->mVisualModel->mControlSize.width )
+ if( fabsf( width - mImpl->mVisualModel->mControlSize.width ) > Math::MACHINE_EPSILON_1000 )
{
// Operations that can be done only once until the text changes.
const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
return glyphsRemoved;
}
- if( size != mImpl->mVisualModel->mControlSize )
+ const bool newSize = ( size != mImpl->mVisualModel->mControlSize );
+
+ if( newSize )
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mVisualModel->mControlSize.width, mImpl->mVisualModel->mControlSize.height );
- // Operations that need to be done if the size changes.
+ // Layout operations that need to be done if the size changes.
mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
LAYOUT |
ALIGN |
mImpl->mVisualModel->mControlSize = size;
}
- // Make sure the model is up-to-date before layouting
+ // Whether there are modify events.
+ const bool isModifyEventsEmpty = 0u == mImpl->mModifyEvents.Count();
+
+ // Make sure the model is up-to-date before layouting.
ProcessModifyEvents();
mImpl->UpdateModel( mImpl->mOperationsPending );
+ // Style operations that need to be done if the text is modified.
+ if( !isModifyEventsEmpty )
+ {
+ mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
+ COLOR );
+ }
+
+ // Apply the style runs if text is modified.
+ bool updated = mImpl->UpdateModelStyle( mImpl->mOperationsPending );
+
+ // Layout the text.
Size layoutSize;
- bool updated = DoRelayout( mImpl->mVisualModel->mControlSize,
- mImpl->mOperationsPending,
- layoutSize );
+ updated = DoRelayout( mImpl->mVisualModel->mControlSize,
+ mImpl->mOperationsPending,
+ layoutSize ) || updated;
// Do not re-do any operation until something changes.
mImpl->mOperationsPending = NO_OPERATION;
- // Keep the current offset and alignment as it will be used to update the decorator's positions.
+ // Keep the current offset and alignment as it will be used to update the decorator's positions (if the size changes).
Vector2 offset;
- if( mImpl->mEventData )
+ if( newSize && mImpl->mEventData )
{
offset = mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition;
}
if( mImpl->mEventData )
{
- // If there is a nex size, the scroll position needs to be clamped.
- mImpl->ClampHorizontalScroll( layoutSize );
+ if( newSize )
+ {
+ // If there is a new size, the scroll position needs to be clamped.
+ mImpl->ClampHorizontalScroll( layoutSize );
- // Update the decorator's positions.
- mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition - offset );
+ // Update the decorator's positions is needed if there is a new size.
+ mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mAlignmentOffset + mImpl->mEventData->mScrollPosition - offset );
+ }
// Move the cursor, grab handle etc.
updated = mImpl->ProcessInputEvents() || updated;
void Controller::ProcessModifyEvents()
{
- std::vector<ModifyEvent>& events = mImpl->mModifyEvents;
+ Vector<ModifyEvent>& events = mImpl->mModifyEvents;
- for( unsigned int i=0; i<events.size(); ++i )
+ if( 0u == events.Count() )
{
- if( ModifyEvent::TEXT_REPLACED == events[i].type )
+ // Nothing to do.
+ return;
+ }
+
+ for( Vector<ModifyEvent>::ConstIterator it = events.Begin(),
+ endIt = events.End();
+ it != endIt;
+ ++it )
+ {
+ const ModifyEvent& event = *it;
+
+ if( ModifyEvent::TEXT_REPLACED == event.type )
{
// A (single) replace event should come first, otherwise we wasted time processing NOOP events
- DALI_ASSERT_DEBUG( 0 == i && "Unexpected TEXT_REPLACED event" );
+ DALI_ASSERT_DEBUG( it == events.Begin() && "Unexpected TEXT_REPLACED event" );
TextReplacedEvent();
}
- else if( ModifyEvent::TEXT_INSERTED == events[i].type )
+ else if( ModifyEvent::TEXT_INSERTED == event.type )
{
TextInsertedEvent();
}
- else if( ModifyEvent::TEXT_DELETED == events[i].type )
+ else if( ModifyEvent::TEXT_DELETED == event.type )
{
// Placeholder-text cannot be deleted
if( !mImpl->IsShowingPlaceholderText() )
}
}
- if( mImpl->mEventData &&
- 0 != events.size() )
+ if( mImpl->mEventData )
{
// When the text is being modified, delay cursor blinking
mImpl->mEventData->mDecorator->DelayCursorBlink();
}
// Discard temporary text
- events.clear();
+ events.Clear();
}
void Controller::ResetText()
mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
// Update the cursor if it's in editing mode.
- if( ( EventData::EDITING == mImpl->mEventData->mState ) ||
- ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
- ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) )
+ if ( EventData::IsEditingState( mImpl->mEventData->mState ) )
{
mImpl->mEventData->mUpdateCursorPosition = true;
}
REORDER );
// Queue a cursor reposition event; this must wait until after DoRelayout()
- if( ( EventData::EDITING == mImpl->mEventData->mState ) ||
- ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) ||
- ( EventData::EDITING_WITH_GRAB_HANDLE == mImpl->mEventData->mState ) )
+ if ( EventData::IsEditingState( mImpl->mEventData->mState ) )
{
mImpl->mEventData->mUpdateCursorPosition = true;
mImpl->mEventData->mScrollAfterUpdatePosition = true;
REORDER );
// Queue a cursor reposition event; this must wait until after DoRelayout()
- if( 0u == mImpl->mLogicalModel->mText.Count() )
- {
- mImpl->mEventData->mUpdateCursorPosition = true;
- }
- else
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ if( 0u != mImpl->mLogicalModel->mText.Count() )
{
mImpl->mEventData->mScrollAfterDelete = true;
}
}
case LayoutEngine::HORIZONTAL_ALIGN_CENTER:
{
- const int intOffset = static_cast<int>( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment.
- mImpl->mAlignmentOffset.x = static_cast<float>( intOffset );
+ mImpl->mAlignmentOffset.x = floorf( 0.5f * ( size.width - actualSize.width ) ); // try to avoid pixel alignment.
break;
}
case LayoutEngine::HORIZONTAL_ALIGN_END:
}
case LayoutEngine::VERTICAL_ALIGN_CENTER:
{
- const int intOffset = static_cast<int>( 0.5f * ( size.height - actualSize.height ) ); // try to avoid pixel alignment.
- mImpl->mAlignmentOffset.y = static_cast<float>( intOffset );
+ mImpl->mAlignmentOffset.y = floorf( 0.5f * ( size.height - actualSize.height ) ); // try to avoid pixel alignment.
break;
}
case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
Length maxSizeOfNewText = std::min ( ( mImpl->mMaximumNumberOfCharacters - numberOfCharactersInModel ), characterCount );
maxLengthReached = ( characterCount > maxSizeOfNewText );
- // Insert at current cursor position
+ // The cursor position.
CharacterIndex& cursorIndex = mImpl->mEventData->mPrimaryCursorPosition;
+ // Update the text's style.
+ if( mImpl->mEventData )
+ {
+ // Updates the text style runs.
+ mImpl->mLogicalModel->UpdateTextStyleRuns( cursorIndex, maxSizeOfNewText );
+
+ // Get the character index from the cursor index.
+ const CharacterIndex styleIndex = ( cursorIndex > 0u ) ? cursorIndex - 1u : 0u;
+
+ // Retrieve the text's style for the given index.
+ InputStyle style;
+ mImpl->mLogicalModel->RetrieveStyle( styleIndex, style );
+
+ // Whether to add a new text color run.
+ const bool addColorRun = style.textColor != mImpl->mEventData->mInputStyle.textColor;
+
+ // Add style runs.
+ if( addColorRun )
+ {
+ const VectorBase::SizeType numberOfRuns = mImpl->mLogicalModel->mColorRuns.Count();
+ mImpl->mLogicalModel->mColorRuns.Resize( numberOfRuns + 1u );
+
+ ColorRun& colorRun = *( mImpl->mLogicalModel->mColorRuns.Begin() + numberOfRuns );
+ colorRun.color = mImpl->mEventData->mInputStyle.textColor;
+ colorRun.characterRun.characterIndex = cursorIndex;
+ colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
+ }
+ }
+
+ // Insert at current cursor position.
Vector<Character>& modifyText = mImpl->mLogicalModel->mText;
if( cursorIndex < numberOfCharactersInModel )
{
bool textRemoved( false );
- if ( EventData::SELECTING == mImpl->mEventData->mState ||
- EventData::SELECTION_CHANGED == mImpl->mEventData->mState )
+ if( EventData::SELECTING == mImpl->mEventData->mState )
{
std::string removedString;
mImpl->RetrieveSelection( removedString, true );
if( NULL != mImpl->mEventData )
{
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "TapEvent state:%d \n", mImpl->mEventData->mState );
+
if( 1u == tapCount )
{
// This is to avoid unnecessary relayouts when tapping an empty text-field
bool relayoutNeeded( false );
- if( mImpl->IsShowingRealText() &&
- EventData::EDITING == mImpl->mEventData->mState )
+ if ( EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState || EventData::EDITING_WITH_PASTE_POPUP == mImpl->mEventData->mState )
{
- // Show grab handle on second tap
- mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
- relayoutNeeded = true;
+ mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE); // If Popup shown hide it here so can be shown again if required.
}
- else if( EventData::EDITING != mImpl->mEventData->mState &&
- EventData::EDITING_WITH_GRAB_HANDLE != mImpl->mEventData->mState )
+
+ if( mImpl->IsShowingRealText() && ( EventData::INACTIVE != mImpl->mEventData->mState ) )
{
- if( mImpl->IsShowingPlaceholderText() && ! mImpl->IsFocusedPlaceholderAvailable() )
+ // Already in an active state so show a popup
+ if ( !mImpl->IsClipboardEmpty() )
{
- // Hide placeholder text
- ResetText();
+ // Shows Paste popup but could show full popup with Selection options. ( EDITING_WITH_POPUP )
+ mImpl->ChangeState( EventData::EDITING_WITH_PASTE_POPUP );
+ }
+ else
+ {
+ mImpl->ChangeState( EventData::EDITING_WITH_GRAB_HANDLE );
}
- // Show cursor on first tap
- mImpl->ChangeState( EventData::EDITING );
relayoutNeeded = true;
}
- else if( mImpl->IsShowingRealText() )
+ else
{
- // Move the cursor
+ if( mImpl->IsShowingPlaceholderText() && !mImpl->IsFocusedPlaceholderAvailable() )
+ {
+ // Hide placeholder text
+ ResetText();
+ }
+
+ if ( EventData::INACTIVE == mImpl->mEventData->mState )
+ {
+ mImpl->ChangeState( EventData::EDITING );
+ }
+ else if ( !mImpl->IsClipboardEmpty() )
+ {
+ mImpl->ChangeState( EventData::EDITING_WITH_POPUP );
+ }
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" );
void Controller::SelectEvent( float x, float y, bool selectAll )
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
+
if( mImpl->mEventData )
{
- if ( mImpl->mEventData->mState == EventData::SELECTING )
- {
- mImpl->ChangeState( EventData::SELECTION_CHANGED );
- }
- else
- {
- mImpl->ChangeState( EventData::SELECTING );
- }
+ mImpl->ChangeState( EventData::SELECTING );
if( selectAll )
{
InsertText( stringToPaste, Text::Controller::COMMIT );
mImpl->ChangeState( EventData::EDITING );
mImpl->RequestRelayout();
+
+ // Do this last since it provides callbacks into application code
+ mImpl->mControlInterface.TextChanged();
}
void Controller::PasteClipboardItemEvent()
{
+ // Retrieve the clipboard contents first
ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
std::string stringToPaste( notifier.GetContent() );
+
+ // Commit the current pre-edit text; the contents of the clipboard should be appended
+ mImpl->ResetImfManager();
+
+ // Paste
PasteText( stringToPaste );
}
ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
{
- bool update( false );
+ bool update = false;
bool requestRelayout = false;
std::string text;
bool removed( false );
- if ( EventData::SELECTING == mImpl->mEventData->mState ||
- EventData::SELECTION_CHANGED == mImpl->mEventData->mState )
+ if( EventData::SELECTING == mImpl->mEventData->mState )
{
removed = RemoveSelectedText();
}
{
if( mImpl->mEventData )
{
- ImfManager imfManager = ImfManager::Get();
-
- if( imfManager )
+ if( mImpl->mEventData->mImfManager )
{
// Notifying IMF of a cursor change triggers a surrounding text request so updating it now.
std::string text;
GetText( text );
- imfManager.SetSurroundingText( text );
+ mImpl->mEventData->mImfManager.SetSurroundingText( text );
- imfManager.SetCursorPosition( GetLogicalCursorPosition() );
- imfManager.NotifyCursorPosition();
+ mImpl->mEventData->mImfManager.SetCursorPosition( GetLogicalCursorPosition() );
+ mImpl->mEventData->mImfManager.NotifyCursorPosition();
}
}
}
mImpl->mVisualModel->mGlyphsPerCharacter.Clear();
mImpl->mVisualModel->mGlyphPositions.Clear();
mImpl->mVisualModel->mLines.Clear();
+ mImpl->mVisualModel->mColorRuns.Clear();
mImpl->mVisualModel->ClearCaches();
}
mImpl->mVisualModel->ClearCaches();
}
+void Controller::ClearStyleData()
+{
+ mImpl->mLogicalModel->mColorRuns.Clear();
+}
+
Controller::Controller( ControlInterface& controlInterface )
: mImpl( NULL )
{