From: Richard Huang Date: Mon, 15 Jan 2018 16:14:16 +0000 (+0000) Subject: Add a property to enable/disable the grab handles in TextField and TextEditor X-Git-Tag: dali_1.3.9~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=5afa211a27080c036cadec6ab3acc3300de82b12 Add a property to enable/disable the grab handles in TextField and TextEditor Change-Id: I7d9313a0786526565b70f966f52bdd77262b435b --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index c4247af..a55d637 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -100,6 +100,7 @@ const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR = "placehol const char* const PROPERTY_NAME_ENABLE_SELECTION = "enableSelection"; 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 int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -538,6 +539,7 @@ int UtcDaliTextEditorGetPropertyP(void) DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == DevelTextEditor::Property::PLACEHOLDER_TEXT ); 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 ); END_TEST; } @@ -2438,6 +2440,16 @@ int utcDaliTextEditorHandles(void) editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, HANDLE_IMAGE_FILE_NAME ); editor.SetProperty( TextEditor::Property::SMOOTH_SCROLL, true ); + Property::Map imagePropertyMap; + imagePropertyMap["type"] = "BufferImage"; + imagePropertyMap["width"] = 40; + imagePropertyMap["height"] = 40; + + editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, imagePropertyMap ); + editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, imagePropertyMap ); + editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, imagePropertyMap ); + editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, imagePropertyMap ); + editor.SetSize( 30.f, 500.f ); editor.SetParentOrigin( ParentOrigin::TOP_LEFT ); editor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); @@ -2512,10 +2524,61 @@ int utcDaliTextEditorHandles(void) application.SendNotification(); application.Render(); + // Tap first to get the focus. + application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) ); + application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Double tap to select a word and create the selection handles. + application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) ); + application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + touchPos = Vector2( 10.0f, 50.0f ); + + // Touch the left selection handle to set it as pressed. + event = Dali::Integration::TouchEvent(); + event.AddPoint( GetPointDownInside( touchPos ) ); + application.ProcessEvent( event ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // drag the left selection handle right + SendPan(application, Gesture::Possible, touchPos); + SendPan(application, Gesture::Started, touchPos); + touchPos.x += 5.0f; + Wait(application, 100); + + for(int i = 0;i<20;i++) + { + SendPan(application, Gesture::Continuing, touchPos); + touchPos.x += 5.0f; + Wait(application); + } + + SendPan(application, Gesture::Finished, touchPos); + Wait(application); + + // Release the left selection handle. + event = Dali::Integration::TouchEvent(); + event.AddPoint( GetPointUpInside( touchPos ) ); + application.ProcessEvent( event ); + + // Render and notify + application.SendNotification(); + application.Render(); + END_TEST; } - int utcDaliTextEditorUnderPropertyStringP(void) { ToolkitTestApplication application; @@ -2783,3 +2846,31 @@ int UtcDaliTextEditorEnableShiftSelectionProperty(void) END_TEST; } + +int UtcDaliTextEditorEnableGrabHandleProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextEditorEnableGrabHandleProperty"); + + 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 ENABLE_GRAB_HANDLE is 'true'. + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::ENABLE_GRAB_HANDLE ), true, TEST_LOCATION ); + + // Check the enable grab handle property + editor.SetProperty( DevelTextEditor::Property::ENABLE_GRAB_HANDLE, false ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::ENABLE_GRAB_HANDLE ), false, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 3e369f6..ea23f76 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -102,6 +102,7 @@ const char* const PROPERTY_NAME_ENABLE_SELECTION = "enableSe const char* const PROPERTY_NAME_PLACEHOLDER = "placeholder"; 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 int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; @@ -544,6 +545,7 @@ int UtcDaliTextFieldGetPropertyP(void) DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == TextField::Property::PLACEHOLDER ); 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 ); END_TEST; } @@ -1991,7 +1993,6 @@ int utcDaliTextFieldEvent05(void) application.SendNotification(); application.Render(); - // Tap first to get the focus. application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) ); @@ -2791,3 +2792,31 @@ int UtcDaliTextFieldEnableShiftSelectionProperty(void) END_TEST; } + +int UtcDaliTextFieldEnableGrabHandleProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldEnableGrabHandleProperty"); + + 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 ENABLE_GRAB_HANDLE is 'true'. + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE ), true, TEST_LOCATION ); + + // Check the enable grab handle property + field.SetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE, false ); + DALI_TEST_EQUALS( field.GetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE ), false, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + 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 3a8fa6f..34c1b09 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -101,7 +101,14 @@ namespace Property * @brief Enables Text selection using Shift key. * @details Name "enableShiftSelection", type Property::BOOLEAN. */ - ENABLE_SHIFT_SELECTION + ENABLE_SHIFT_SELECTION, + + /** + * @brief Enables the grab handles for text selection. + * @details Name "enableGrabHandle", type Property::BOOLEAN. + * @note The default value is true, which means the grab handles are enabled by default. + */ + ENABLE_GRAB_HANDLE }; } // 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 8e73c99..a5b1df3 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h @@ -91,7 +91,14 @@ namespace Property * @brief Enables Text selection using Shift key. * @details Name "enableShiftSelection", type Property::BOOLEAN. */ - ENABLE_SHIFT_SELECTION = ELLIPSIS + 1 + ENABLE_SHIFT_SELECTION = ELLIPSIS + 1, + + /** + * @brief Enables the grab handles for text selection. + * @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 }; } // 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 77974d5..20fd25c 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -136,6 +136,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineWrapMode", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT ) 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_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -732,6 +733,17 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } break; } + case Toolkit::DevelTextEditor::Property::ENABLE_GRAB_HANDLE: + { + if( impl.mController ) + { + const bool grabHandleEnabled = value.Get(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled ); + + impl.mController->SetGrabHandleEnabled( grabHandleEnabled ); + } + break; + } } // switch } // texteditor } @@ -1124,6 +1136,14 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } break; } + case Toolkit::DevelTextEditor::Property::ENABLE_GRAB_HANDLE: + { + if( impl.mController ) + { + value = impl.mController->IsGrabHandleEnabled(); + } + 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 d79fd7b..137d0c4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -130,6 +130,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, 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_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -772,6 +773,17 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE: + { + if( impl.mController ) + { + const bool grabHandleEnabled = value.Get(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled ); + + impl.mController->SetGrabHandleEnabled( grabHandleEnabled ); + } + break; + } } // switch } // textfield } @@ -1179,6 +1191,14 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde } break; } + case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE: + { + if( impl.mController ) + { + value = impl.mController->IsGrabHandleEnabled(); + } + break; + } } //switch } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 79346b0..3e63578 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -2518,8 +2518,11 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); mEventData->mDecorator->StopCursorBlink(); mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); + if ( mEventData->mGrabHandleEnabled ) + { + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); + } mEventData->mDecorator->SetHighlightActive( true ); if( mEventData->mGrabHandlePopupEnabled ) { @@ -2563,7 +2566,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHighlightActive( false ); } - else + else if ( mEventData->mGrabHandleEnabled ) { mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); } @@ -2585,7 +2588,10 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecorator->StartCursorBlink(); } // Grab handle is not shown until a tap is received whilst EDITING - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + if ( mEventData->mGrabHandleEnabled ) + { + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + } mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHighlightActive( false ); @@ -2601,8 +2607,11 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); mEventData->mDecorator->StopCursorBlink(); mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); + if ( mEventData->mGrabHandleEnabled ) + { + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); + } mEventData->mDecorator->SetHighlightActive( true ); if( mEventData->mGrabHandlePopupEnabled ) { @@ -2620,7 +2629,10 @@ void Controller::Impl::ChangeState( EventData::State newState ) { mEventData->mDecorator->StartCursorBlink(); } - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + if ( mEventData->mGrabHandleEnabled ) + { + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + } mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHighlightActive( false ); @@ -2641,7 +2653,10 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecorator->StartCursorBlink(); } - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + if ( mEventData->mGrabHandleEnabled ) + { + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + } mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHighlightActive( false ); diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 18de434..279f03e 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -476,6 +476,16 @@ bool Controller::IsShiftSelectionEnabled() const return mImpl->mEventData->mShiftSelectionFlag; } +void Controller::SetGrabHandleEnabled( bool enabled ) +{ + mImpl->mEventData->mGrabHandleEnabled = enabled; +} + +bool Controller::IsGrabHandleEnabled() const +{ + return mImpl->mEventData->mGrabHandleEnabled; +} + // public : Update void Controller::SetText( const std::string& text ) diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index defb8b5..415b8f5 100755 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -406,6 +406,20 @@ public: // Configure the text controller. bool IsShiftSelectionEnabled() const; /** + * @brief Enable or disable the grab handles for text selection. + * + * @param[in] enabled Whether to enable the grab handles + */ + void SetGrabHandleEnabled( bool enabled ); + + /** + * @brief Returns whether the grab handles are enabled. + * + * @return True if the grab handles are enabled + */ + bool IsGrabHandleEnabled() const; + + /** * @brief Sets input type to password * * @note The string is displayed hidden character