application.Render();
// Move to second line of the text & Select some text in the right of the current cursor position
- application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+ application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
// remove selection
DALI_TEST_EQUALS(oldSelectionEnd, 23, TEST_LOCATION);
END_TEST;
+}
+
+
+int utcDaliTextEditorInsertCharacterAfterInitWithResizePolicyNaturalSize(void)
+{
+
+ //This is to test a crash when used Resize Policy equals USE_NATURAL_SIZE
+ //DaliException on vector: "Iterator not inside vector"
+
+ ToolkitTestApplication application;
+ tet_infoline(" utcDaliTextEditorInsertCharacterAfterInitWithResizePolicyNaturalSize");
+
+ TextEditor editor = TextEditor::New();
+ DALI_TEST_CHECK( editor );
+
+ application.GetScene().Add( editor );
+
+ // Avoid a crash when core load gl resources.
+ application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+ //Set multilines text
+ editor.SetProperty(Dali::Toolkit::TextEditor::Property::TEXT, "Hello \n World");
+ editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+ //Set ResizePolicy to NaturalSize
+ editor.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ // Create a tap event to touch the text editor.
+ TestGenerateTap( application, 5.0f, 5.0f );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ // Set currsor and add character (in first line)
+ editor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 5);
+ application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+ application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::UP, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ //Check the changed text and cursor position
+ DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::TEXT ).Get<std::string>(), "Hellod \n World", TEST_LOCATION );
+ DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get<int>(), 6, TEST_LOCATION );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ END_TEST;
+}
+
+int utcDaliTextEditorRemoveCharacterAfterInitWithResizePolicyNaturalSize(void)
+{
+
+ //This is to test a crash when used Resize Policy equals USE_NATURAL_SIZE
+ //DaliException on vector: "Iterator not inside vector"
+
+ ToolkitTestApplication application;
+ tet_infoline(" utcDaliTextEditorRemoveCharacterAfterInitWithResizePolicyNaturalSize");
+
+ TextEditor editor = TextEditor::New();
+ DALI_TEST_CHECK( editor );
+
+ application.GetScene().Add( editor );
+
+ // Avoid a crash when core load gl resources.
+ application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+ //Set multilines text
+ editor.SetProperty(Dali::Toolkit::TextEditor::Property::TEXT, "Hello \n World");
+ editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+ //Set ResizePolicy to NaturalSize
+ editor.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
+
+ // Set currsor
+ editor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 5);
+ application.SendNotification();
+ application.Render();
+
+ // Set focus and remove character
+ editor.SetKeyInputFocus();
+ application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ //Check the changed text and cursor position
+ DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::TEXT ).Get<std::string>(), "Hell \n World", TEST_LOCATION );
+ DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get<int>(), 4, TEST_LOCATION );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ END_TEST;
+}
+
+int utcDaliTextEditorCutSelectedTextAfterInitWithResizePolicyNaturalSize(void)
+{
+
+ //This is to test a crash when used Resize Policy equals USE_NATURAL_SIZE
+ //DaliException on vector: "Iterator not inside vector"
+
+ ToolkitTestApplication application;
+ tet_infoline(" utcDaliTextEditorCutSelectedTextAfterInitWithResizePolicyNaturalSize");
+
+ TextEditor editor = TextEditor::New();
+ DALI_TEST_CHECK( editor );
+
+ application.GetScene().Add( editor );
+
+ // Avoid a crash when core load gl resources.
+ application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+ //Set multilines text
+ editor.SetProperty(Dali::Toolkit::TextEditor::Property::TEXT, "Hello \n World");
+ editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+ //Set ResizePolicy to NaturalSize
+ editor.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
+
+ //Select text at initialization (before the first render)
+ DevelTextEditor::SelectText( editor ,3, 5 );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ //Cut text
+ application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_CONTROL_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+ application.ProcessEvent( GenerateKey( "x", "x", "x", KEY_X_CODE, KEY_CONTROL_MODIFIER, 0, Integration::KeyEvent::DOWN, "x", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ //Check the changed text and cursor position
+ DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::TEXT ).Get<std::string>(), "Hel \n World", TEST_LOCATION );
+ DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get<int>(), 3, TEST_LOCATION );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ END_TEST;
+}
+
+
+int utcDaliTextEditorDoubleEnterAfterInitWithResizePolicyNaturalSize(void)
+{
+
+ //This is to test a crash when used Resize Policy equals USE_NATURAL_SIZE
+ //DaliException on vector: "Iterator not inside vector"
+
+ ToolkitTestApplication application;
+ tet_infoline(" utcDaliTextEditorDoubleEnterAfterInitWithResizePolicyNaturalSize");
+
+ TextEditor editor = TextEditor::New();
+ DALI_TEST_CHECK( editor );
+
+ application.GetScene().Add( editor );
+
+ // Avoid a crash when core load gl resources.
+ application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+ //Set multilines text
+ editor.SetProperty(Dali::Toolkit::TextEditor::Property::TEXT, "Hello \n World");
+ editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+ editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+ //Set ResizePolicy to NaturalSize
+ editor.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
+
+ // Set currsor
+ editor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 5);
+ application.SendNotification();
+ application.Render();
+
+ // Set focus and double enter (new line)
+ editor.SetKeyInputFocus();
+ application.ProcessEvent(GenerateKey("Enter", "", "\n", 13, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
+ application.ProcessEvent(GenerateKey("Enter", "", "\n", 13, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ //Check the changed text and cursor position
+ DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::TEXT ).Get<std::string>(), "Hello\n\n \n World", TEST_LOCATION );
+ DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get<int>(), 7, TEST_LOCATION );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ END_TEST;
}
\ No newline at end of file
#include <dali-toolkit/internal/text/text-controller-impl.h>
// EXTERNAL INCLUDES
-#include <cmath>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/actors/layer.h>
-#include <dali/devel-api/adaptor-framework/window-devel.h>
+#include <cmath>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/character-set-conversion.h>
namespace Dali::Toolkit::Text
{
-
namespace
{
-
void SetDefaultInputStyle(InputStyle& inputStyle, const FontDefaults* const fontDefaults, const Vector4& textColor)
{
// Sets the default text's color.
decorator->StopCursorBlink();
decorator->SetHandleActive(GRAB_HANDLE, false);
if(eventData->mDecorator->IsHandleActive(LEFT_SELECTION_HANDLE) ||
- decorator->IsHandleActive(RIGHT_SELECTION_HANDLE))
+ decorator->IsHandleActive(RIGHT_SELECTION_HANDLE))
{
decorator->SetHandleActive(LEFT_SELECTION_HANDLE, false);
decorator->SetHandleActive(RIGHT_SELECTION_HANDLE, false);
if(std::fabs(lineSpacing - mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000)
{
mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
- mRecalculateNaturalSize = true;
RelayoutForNewLineSize();
return true;
if(std::fabs(lineSize - mLayoutEngine.GetDefaultLineSize()) > Math::MACHINE_EPSILON_1000)
{
mLayoutEngine.SetDefaultLineSize(lineSize);
- mRecalculateNaturalSize = true;
RelayoutForNewLineSize();
return true;
mTextUpdateInfo.mNumberOfCharactersToAdd = mModel->mLogicalModel->mText.Count();
mOperationsPending = static_cast<OperationsMask>(mOperationsPending | LAYOUT);
+ mTextUpdateInfo.mFullRelayoutNeeded = true;
+
+ // Need to recalculate natural size
+ mRecalculateNaturalSize = true;
+
//remove selection
- if(mEventData && mEventData->mState == EventData::SELECTING)
+ if((mEventData != nullptr) && (mEventData->mState == EventData::SELECTING))
{
ChangeState(EventData::EDITING);
}
// Emit the input style changed signal for each mask
std::for_each(mEventData->mInputStyleChangedQueue.begin(),
mEventData->mInputStyleChangedQueue.end(),
- [&](const auto mask) { mEditableControlInterface->InputStyleChanged(mask); } );
+ [&](const auto mask) { mEditableControlInterface->InputStyleChanged(mask); });
}
mEventData->mInputStyleChangedQueue.Clear();
{
// Set the alignment.
mModel->mVerticalAlignment = alignment;
- mOperationsPending = static_cast<OperationsMask>(mOperationsPending | ALIGN);
+ mOperationsPending = static_cast<OperationsMask>(mOperationsPending | ALIGN);
RequestRelayout();
}
}
mModel->mLogicalModel->ClearFontDescriptionRuns();
}
-
void Controller::Impl::ResetScrollPosition()
{
if(mEventData)
{
namespace Text
{
-Size Controller::Relayouter::CalculateLayoutSizeOnRequiredControllerSize(Controller& controller, const Size& requestedControllerSize, const OperationsMask& requestedOperationsMask, bool restoreLinesAndGlyphPositions)
+Size Controller::Relayouter::CalculateLayoutSizeOnRequiredControllerSize(Controller& controller, const Size& requestedControllerSize, const OperationsMask& requestedOperationsMask)
{
DALI_LOG_INFO(gLogFilter, Debug::Verbose, "-->CalculateLayoutSizeOnRequiredControllerSize\n");
Size calculatedLayoutSize;
ModelPtr& model = impl.mModel;
VisualModelPtr& visualModel = model->mVisualModel;
- // Store the pending operations mask so that it can be restored later on with no modifications made on it
- // while getting the natural size were reflected on the original mask.
- OperationsMask operationsPendingBackUp = static_cast<OperationsMask>(impl.mOperationsPending);
-
- // This is a hotfix for side effect on Scrolling, LineWrap and Invalid position of cursor in TextEditor after calling CalculateLayoutSizeOnRequiredControllerSize.
- // The number of lines and glyph-positions inside visualModel have been changed by calling DoRelayout with requestedControllerSize.
- // Store the mLines and mGlyphPositions from visualModel so that they can be restored later on with no modifications made on them.
- //TODO: Refactor "DoRelayout" and extract common code of size calculation without modifying attributes of mVisualModel, and then blah, blah, etc.
- Vector<LineRun> linesBackup = visualModel->mLines;
- Vector<Vector2> glyphPositionsBackup = visualModel->mGlyphPositions;
-
// Operations that can be done only once until the text changes.
const OperationsMask onlyOnceOperations = static_cast<OperationsMask>(CONVERT_TO_UTF32 |
GET_SCRIPTS |
textUpdateInfo.mParagraphCharacterIndex = 0u;
textUpdateInfo.mRequestedNumberOfCharacters = model->mLogicalModel->mText.Count();
- // Make sure the model is up-to-date before layouting
- impl.UpdateModel(onlyOnceOperations);
+ // This is to keep Index to the first character to be updated.
+ // Then restore it after calling Clear method.
+ auto updateInfoCharIndexBackup = textUpdateInfo.mCharacterIndex;
// Get a reference to the pending operations member
OperationsMask& operationsPending = impl.mOperationsPending;
// Layout the text for the new width.
- operationsPending = static_cast<OperationsMask>(operationsPending | requestedOperationsMask);
+ // Apply the pending operations, requested operations and the only once operations.
+ // Then remove onlyOnceOperations
+ operationsPending = static_cast<OperationsMask>(operationsPending | requestedOperationsMask | onlyOnceOperations);
+
+ // Make sure the model is up-to-date before layouting
+ impl.UpdateModel(static_cast<OperationsMask>(operationsPending & ~UPDATE_LAYOUT_SIZE));
// Store the actual control's size to restore later.
const Size actualControlSize = visualModel->mControlSize;
DoRelayout(impl,
requestedControllerSize,
- static_cast<OperationsMask>(onlyOnceOperations |
- requestedOperationsMask),
+ static_cast<OperationsMask>(operationsPending & ~UPDATE_LAYOUT_SIZE),
calculatedLayoutSize);
// Clear the update info. This info will be set the next time the text is updated.
textUpdateInfo.Clear();
- textUpdateInfo.mClearAll = true;
+
+ //TODO: Refactor "DoRelayout" and extract common code of size calculation without modifying attributes of mVisualModel,
+ //TODO: then calculate GlyphPositions. Lines, Size, Layout for Natural-Size
+ //TODO: and utilize the values in OperationsPending and TextUpdateInfo without changing the original one.
+ //TODO: Also it will improve performance because there is no need todo FullRelyout on the next need for layouting.
+
+ // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
+ // By this no need to take backup and restore it.
+ textUpdateInfo.mFullRelayoutNeeded = true;
+
+ // Restore mCharacterIndex. Because "Clear" set it to the maximum integer.
+ // The "CalculateTextUpdateIndices" does not work proprely because the mCharacterIndex will be greater than mPreviousNumberOfCharacters.
+ // Which apply an assumption to update only the last paragraph. That could cause many of out of index crashes.
+ textUpdateInfo.mCharacterIndex = updateInfoCharIndexBackup;
+
+ // Do not do again the only once operations.
+ operationsPending = static_cast<OperationsMask>(operationsPending & ~onlyOnceOperations);
+
+ // Do the size related operations again.
+
+ const OperationsMask sizeOperations = static_cast<OperationsMask>(LAYOUT |
+ ALIGN |
+ REORDER);
+
+ operationsPending = static_cast<OperationsMask>(operationsPending | sizeOperations);
// Restore the actual control's size.
visualModel->mControlSize = actualControlSize;
- // Restore the previously backed-up pending operations' mask without the only once operations.
- impl.mOperationsPending = static_cast<OperationsMask>(operationsPendingBackUp & ~onlyOnceOperations);
-
- // Restore the previously backed-up mLines and mGlyphPositions from visualModel.
- if(restoreLinesAndGlyphPositions)
- {
- visualModel->mLines = linesBackup;
- visualModel->mGlyphPositions = glyphPositionsBackup;
- }
return calculatedLayoutSize;
}
OperationsMask requestedOperationsMask = static_cast<OperationsMask>(LAYOUT | REORDER);
Size sizeMaxWidthAndMaxHeight = Size(MAX_FLOAT, MAX_FLOAT);
- naturalSize = CalculateLayoutSizeOnRequiredControllerSize(controller, sizeMaxWidthAndMaxHeight, requestedOperationsMask, true);
+ naturalSize = CalculateLayoutSizeOnRequiredControllerSize(controller, sizeMaxWidthAndMaxHeight, requestedOperationsMask);
// Stores the natural size to avoid recalculate it again
// unless the text/style changes.
OperationsMask requestedOperationsMask = static_cast<OperationsMask>(LAYOUT);
Size sizeRequestedWidthAndMaxHeight = Size(width, MAX_FLOAT);
- // Skip restore, because if GetHeightForWidth called before rendering and layouting then visualModel->mControlSize will be zero which will make LineCount zero.
- // The implementation of Get LineCount property depends on calling GetHeightForWidth then read mLines.Count() from visualModel direct.
- // If the LineCount property is requested before rendering and layouting then the value will be zero, which is incorrect.
- // So we will not restore the previously backed-up mLines and mGlyphPositions from visualModel in such case.
- // Another case to skip restore is when the requested width equals the Control's width which means the caller need to update the old values.
- // For example, when the text is changed.
- bool restoreLinesAndGlyphPositions = (visualModel->mControlSize.width > 0 && visualModel->mControlSize.height > 0) && (visualModel->mControlSize.width != width);
-
- layoutSize = CalculateLayoutSizeOnRequiredControllerSize(controller, sizeRequestedWidthAndMaxHeight, requestedOperationsMask, restoreLinesAndGlyphPositions);
+ layoutSize = CalculateLayoutSizeOnRequiredControllerSize(controller, sizeRequestedWidthAndMaxHeight, requestedOperationsMask);
DALI_LOG_INFO(gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height);
}