From f4f5108909297cf3ab4c4b091d35a0194f637428 Mon Sep 17 00:00:00 2001 From: Joogab Yun Date: Tue, 30 Oct 2018 16:02:04 +0900 Subject: [PATCH] support match align for system language direciton on text Field and text Editor also. refer see) commit id : 35bc4b3cfcdfb094a15cd8089ad1c19830287018 support match align for system language direciton if matchSystemLanguageDirection property set true, text align direction follow system language direction. Change-Id: I2716284e2e5deb565c18d33e6866d77fee87062a --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 31 ++++++ .../src/dali-toolkit/utc-Dali-TextField.cpp | 117 +++++++++++++++++++++ .../controls/text-controls/text-editor-devel.h | 9 +- .../controls/text-controls/text-field-devel.h | 10 +- .../controls/text-controls/text-editor-impl.cpp | 17 +++ .../controls/text-controls/text-field-impl.cpp | 17 +++ .../internal/text/text-controller-impl.cpp | 24 ++++- .../1920x1080/dali-toolkit-default-theme.json | 6 +- 8 files changed, 225 insertions(+), 6 deletions(-) mode change 100644 => 100755 dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index dd538d4..49889ff 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -101,6 +101,8 @@ const char* const PROPERTY_NAME_ENABLE_SELECTION = "enableSe const char* const PROPERTY_NAME_PLACEHOLDER = "placeholder"; const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION = "enableShiftSelection"; const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE = "enableGrabHandle"; +const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION = "matchSystemLanguageDirection"; + const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -542,6 +544,7 @@ int UtcDaliTextEditorGetPropertyP(void) DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextEditor::Property::ENABLE_SHIFT_SELECTION ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE ) == DevelTextEditor::Property::ENABLE_GRAB_HANDLE ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ); END_TEST; } @@ -2877,6 +2880,34 @@ int UtcDaliTextEditorEnableGrabHandleProperty(void) END_TEST; } +int UtcDaliTextEditorMatchSystemLanguageDirectionProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextEditorMatchSystemLanguageDirectionProperty"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + editor.SetSize( 300.f, 50.f ); + editor.SetParentOrigin( ParentOrigin::TOP_LEFT ); + editor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + Stage::GetCurrent().Add( editor ); + + application.SendNotification(); + application.Render(); + + // The default value of MATCH_SYSTEM_LANGUAGE_DIRECTION is 'false'. + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), false, TEST_LOCATION ); + + // Check the enable match system language direction property + editor.SetProperty( DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + END_TEST; +} + int UtcDaliTextEditorGetInputMethodContext(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 64a5d55..4a2d453 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -103,6 +103,7 @@ const char* const PROPERTY_NAME_PLACEHOLDER = "placehol const char* const PROPERTY_NAME_ELLIPSIS = "ellipsis"; const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION = "enableShiftSelection"; const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE = "enableGrabHandle"; +const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION = "matchSystemLanguageDirection"; const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -548,6 +549,7 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == TextField::Property::ELLIPSIS ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextField::Property::ENABLE_SHIFT_SELECTION ); DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE ) == DevelTextField::Property::ENABLE_GRAB_HANDLE ); + DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ); END_TEST; } @@ -2823,6 +2825,120 @@ int UtcDaliTextFieldEnableGrabHandleProperty(void) END_TEST; } +int UtcDaliTextFieldMatchSystemLanguageDirectionProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldMatchSystemLanguageDirectionProperty"); + + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + field.SetSize( 300.f, 50.f ); + field.SetParentOrigin( ParentOrigin::TOP_LEFT ); + field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + Stage::GetCurrent().Add( field ); + + application.SendNotification(); + application.Render(); + + // The default value of MATCH_SYSTEM_LANGUAGE_DIRECTION is 'false'. + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), false, TEST_LOCATION ); + + // Check the match system language direction property + field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true ); + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + END_TEST; +} + +int utcDaliTextFieldLayoutDirectionCoverage(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldLayoutDirectionCoverage"); + + // Creates a tap event. After creating a tap event the text field should + // have the focus and add text with key events should be possible. + TextField field = TextField::New(); + DALI_TEST_CHECK( field ); + + Stage::GetCurrent().Add( field ); + + field.SetSize( 300.f, 50.f ); + field.SetParentOrigin( ParentOrigin::TOP_LEFT ); + field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // init direction for coverage + // Set horizontal alignment END + field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END"); + + // Create a tap event to touch the text field. + application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Set MATCH_SYSTEM_LANGUAGE_DIRECTION to true to use the layout direction. + field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true ); + field.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT ); + + // Set horizontal alignment BEGIN + field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "BEGIN"); + + // Create a tap event to touch the text field. + application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Set horizontal alignment CENTER + field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER"); + + // Create a tap event to touch the text field. + application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Set horizontal alignment END + field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END"); + + // Create a tap event to touch the text field. + application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Generate a Esc key event. The text field should lose the focus. + application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION ); + + END_TEST; +} + + int UtcDaliTextFieldGetInputMethodContext(void) { ToolkitTestApplication application; @@ -2833,3 +2949,4 @@ int UtcDaliTextFieldGetInputMethodContext(void) END_TEST; } + diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h index 7bed333..4d600b5 100755 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -110,7 +110,14 @@ namespace Property * @details Name "enableGrabHandle", type Property::BOOLEAN. * @note The default value is true, which means the grab handles are enabled by default. */ - ENABLE_GRAB_HANDLE + ENABLE_GRAB_HANDLE, + + /** + * @brief Modifies the default text alignment to match the direction of the system language. + * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write + * @note The default value is false + */ + MATCH_SYSTEM_LANGUAGE_DIRECTION }; } // namespace Property diff --git a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h index dea5ded..7608577 100755 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h @@ -100,7 +100,15 @@ namespace Property * @details Name "enableGrabHandle", type Property::BOOLEAN. * @note The default value is true, which means the grab handles are enabled by default. */ - ENABLE_GRAB_HANDLE = ELLIPSIS + 2 + ENABLE_GRAB_HANDLE = ELLIPSIS + 2, + + /** + * @brief Modifies the default text alignment to match the direction of the system language. + * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write + * @note The default value is false + */ + MATCH_SYSTEM_LANGUAGE_DIRECTION = ELLIPSIS + 3 + }; } // namespace Property diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index 5196d17..b065e99 100755 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -138,6 +138,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderText", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -745,6 +746,14 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } break; } + case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: + { + if( impl.mController ) + { + impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >()); + } + break; + } } // switch } // texteditor } @@ -1145,6 +1154,14 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } break; } + case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: + { + if( impl.mController ) + { + value = impl.mController->IsMatchSystemLanguageDirection(); + } + break; + } } //switch } diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 5077ced..655c335 100755 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -132,6 +132,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -785,6 +786,14 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: + { + if( impl.mController ) + { + impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >()); + } + break; + } } // switch } // textfield } @@ -1200,6 +1209,14 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde } break; } + case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: + { + if( impl.mController ) + { + value = impl.mController->IsMatchSystemLanguageDirection(); + } + break; + } } //switch } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 97a3da9..acf6291 100755 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -2741,11 +2741,24 @@ void Controller::Impl::GetCursorPosition( CharacterIndex logical, cursorInfo.lineHeight = GetDefaultFontLineHeight(); cursorInfo.primaryCursorHeight = cursorInfo.lineHeight; + bool isRTL = false; + if( mModel->mMatchSystemLanguageDirection ) + { + isRTL = mLayoutDirection == LayoutDirection::RIGHT_TO_LEFT; + } + switch( mModel->mHorizontalAlignment ) { case Text::HorizontalAlignment::BEGIN : { - cursorInfo.primaryPosition.x = 0.f; + if( isRTL ) + { + cursorInfo.primaryPosition.x = mModel->mVisualModel->mControlSize.width - mEventData->mDecorator->GetCursorWidth(); + } + else + { + cursorInfo.primaryPosition.x = 0.f; + } break; } case Text::HorizontalAlignment::CENTER: @@ -2755,7 +2768,14 @@ void Controller::Impl::GetCursorPosition( CharacterIndex logical, } case Text::HorizontalAlignment::END: { - cursorInfo.primaryPosition.x = mModel->mVisualModel->mControlSize.width - mEventData->mDecorator->GetCursorWidth(); + if( isRTL ) + { + cursorInfo.primaryPosition.x = 0.f; + } + else + { + cursorInfo.primaryPosition.x = mModel->mVisualModel->mControlSize.width - mEventData->mDecorator->GetCursorWidth(); + } break; } } diff --git a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json old mode 100644 new mode 100755 index 842a568..4322001 --- a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json @@ -102,7 +102,8 @@ "grabHandleImage" : "{DALI_STYLE_IMAGE_DIR}cursor_handler_drop_center.png", "selectionHandleImageLeft" : {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_left.png" }, "selectionHandleImageRight": {"filename":"{DALI_STYLE_IMAGE_DIR}selection_handle_drop_right.png" }, - "enableSelection":false + "enableSelection":false, + "matchSystemLanguageDirection":true }, "TextFieldFontSize0": @@ -218,7 +219,8 @@ "enableScrollBar":true, "scrollBarShowDuration":0.8, "scrollBarFadeDuration":0.5, - "enableSelection":false + "enableSelection":false, + "matchSystemLanguageDirection":true }, "ProgressBar": { -- 2.7.4