X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-controls%2Ftext-field-impl.cpp;h=467748d125144eebaf40efb7c78f239f8ede5a97;hp=d79fd7bb2193bec682d54b643851f427026e219b;hb=593ab514474062b4d3de55682e63627a79b2eb5a;hpb=81d8e007ed1aed6e36e4cf44e456d91cf8024004 diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp old mode 100644 new mode 100755 index d79fd7b..467748d --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -22,18 +22,17 @@ #include #include #include -#include -#include +#include +#include #include #include #include -#include #include // INTERNAL INCLUDES -#include #include #include +#include #include #include #include @@ -44,6 +43,8 @@ #include #include #include +#include +#include using namespace Dali::Toolkit::Text; @@ -63,7 +64,7 @@ namespace // unnamed namespace Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS"); #endif - const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND; + const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND; } // unnamed namespace namespace @@ -77,7 +78,6 @@ BaseHandle Create() // Setup properties, signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create ); -DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED ) @@ -90,8 +90,6 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR ) DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK ) @@ -130,6 +128,12 @@ 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_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND ) +DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -137,6 +141,24 @@ DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT DALI_TYPE_REGISTRATION_END() +const char * const IMAGE_MAP_FILENAME_STRING = "filename"; + +/// Retrieves a filename from a value that is a Property::Map +std::string GetImageFileNameFromPropertyValue( const Property::Value& value ) +{ + std::string filename; + const Property::Map* map = value.GetMap(); + if( map ) + { + const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING ); + if( filenameValue ) + { + filenameValue->Get( filename ); + } + } + return filename; +} + } // namespace Toolkit::TextField TextField::New() @@ -167,13 +189,13 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr switch( index ) { - case Toolkit::TextField::Property::RENDERING_BACKEND: + case Toolkit::DevelTextField::Property::RENDERING_BACKEND: { int backend = value.Get< int >(); DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend ); #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING - if( Text::RENDERING_VECTOR_BASED == backend ) + if( DevelText::RENDERING_VECTOR_BASED == backend ) { backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering } @@ -186,7 +208,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr if( impl.mController ) { // When using the vector-based rendering, the size of the GLyphs are different - TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH; + TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH; impl.mController->SetGlyphType( glyphType ); } } @@ -337,36 +359,6 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } - case Toolkit::TextField::Property::SHADOW_OFFSET: - { - if( impl.mController ) - { - const Vector2& shadowOffset = value.Get< Vector2 >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y ); - - if ( impl.mController->GetShadowOffset() != shadowOffset ) - { - impl.mController->SetShadowOffset( shadowOffset ); - impl.mRenderer.Reset(); - } - } - break; - } - case Toolkit::TextField::Property::SHADOW_COLOR: - { - if( impl.mController ) - { - const Vector4& shadowColor = value.Get< Vector4 >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_COLOR %f,%f,%f,%f\n", impl.mController.Get(), shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a ); - - if ( impl.mController->GetShadowColor() != shadowColor ) - { - impl.mController->SetShadowColor( shadowColor ); - impl.mRenderer.Reset(); - } - } - break; - } case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR: { if( impl.mDecorator ) @@ -439,24 +431,24 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE: { - const ResourceImage image = ResourceImage::New( value.Get< std::string >() ); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() ); + const std::string imageFileName = value.Get< std::string >(); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() ); - if( impl.mDecorator ) + if( impl.mDecorator && imageFileName.size() ) { - impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image ); + impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName ); impl.RequestTextRelayout(); } break; } case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE: { - const ResourceImage image = ResourceImage::New( value.Get< std::string >() ); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() ); + const std::string imageFileName = value.Get< std::string >(); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() ); - if( impl.mDecorator ) + if( impl.mDecorator && imageFileName.size() ) { - impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image ); + impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName ); impl.RequestTextRelayout(); } break; @@ -485,66 +477,66 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT: { - const Image image = Scripting::NewImage( value ); + const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && image ) + if( impl.mDecorator && filename.size() ) { - impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image ); + impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename ); impl.RequestTextRelayout(); } break; } case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT: { - const Image image = Scripting::NewImage( value ); + const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && image ) + if( impl.mDecorator && filename.size() ) { - impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image ); + impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename ); impl.RequestTextRelayout(); } break; } case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT: { - const Image image = Scripting::NewImage( value ); + const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && image ) + if( impl.mDecorator && filename.size() ) { - impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image ); + impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename ); impl.RequestTextRelayout(); } break; } case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT: { - const Image image = Scripting::NewImage( value ); + const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && image ) + if( impl.mDecorator && filename.size() ) { - impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image ); + impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename ); impl.RequestTextRelayout(); } break; } case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT: { - const Image image = Scripting::NewImage( value ); + const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && image ) + if( impl.mDecorator && filename.size() ) { - impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image ); + impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename ); impl.RequestTextRelayout(); } break; } case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT: { - const Image image = Scripting::NewImage( value ); + const std::string filename = GetImageFileNameFromPropertyValue( value ); - if( impl.mDecorator && image ) + if( impl.mDecorator && filename.size() ) { - impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image ); + impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename ); impl.RequestTextRelayout(); } break; @@ -585,7 +577,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl(); if (control == textField) { - impl.mImfManager.ApplyOptions( impl.mInputMethodOptions ); + impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions ); } break; } @@ -772,6 +764,48 @@ 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; + } + case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: + { + if( impl.mController ) + { + impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >()); + } + break; + } + case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP: + { + if( impl.mController ) + { + const bool grabHandlePopupEnabled = value.Get(); + DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled); + + impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled); + break; + } + } + case Toolkit::DevelTextField::Property::BACKGROUND: + { + if( impl.mController ) + { + const Vector4 backgroundColor = value.Get< Vector4 >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p BACKGROUND %f,%f,%f,%f\n", impl.mController.Get(), backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a ); + + impl.mController->SetBackgroundEnabled( true ); + impl.mController->SetBackgroundColor( backgroundColor ); + } + break; + } } // switch } // textfield } @@ -788,7 +822,7 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde switch( index ) { - case Toolkit::TextField::Property::RENDERING_BACKEND: + case Toolkit::DevelTextField::Property::RENDERING_BACKEND: { value = impl.mRenderingBackend; break; @@ -900,22 +934,6 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde } break; } - case Toolkit::TextField::Property::SHADOW_OFFSET: - { - if ( impl.mController ) - { - value = impl.mController->GetShadowOffset(); - } - break; - } - case Toolkit::TextField::Property::SHADOW_COLOR: - { - if ( impl.mController ) - { - value = impl.mController->GetShadowColor(); - } - break; - } case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR: { if( impl.mDecorator ) @@ -965,11 +983,7 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde { if( impl.mDecorator ) { - ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) ); - if( image ) - { - value = image.GetUrl(); - } + value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ); } break; } @@ -977,11 +991,7 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde { if( impl.mDecorator ) { - ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) ); - if( image ) - { - value = image.GetUrl(); - } + value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ); } break; } @@ -1179,12 +1189,75 @@ 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; + } + case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: + { + if( impl.mController ) + { + value = impl.mController->IsMatchSystemLanguageDirection(); + } + break; + } + case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP: + { + if( impl.mController ) + { + value = impl.mController->IsGrabHandlePopupEnabled(); + } + break; + } + case Toolkit::DevelTextField::Property::BACKGROUND: + { + if( impl.mController ) + { + value = impl.mController->GetBackgroundColor(); + } + break; + } + case Toolkit::DevelTextField::Property::SELECTED_TEXT: + { + if( impl.mController ) + { + value = impl.mController->GetSelectedText( ); + } + break; + } } //switch } return value; } +void TextField::SelectWholeText() +{ + if( mController && mController->IsShowingRealText() ) + { + mController->SelectEvent( 0.f, 0.f, SelectionType::ALL ); + SetKeyInputFocus(); + } +} + +void TextField::SelectNone() +{ + if( mController && mController->IsShowingRealText() ) + { + mController->SelectEvent( 0.f, 0.f, SelectionType::NONE ); + SetKeyInputFocus(); + } +} + +InputMethodContext TextField::GetInputMethodContext() +{ + return mInputMethodContext; +} + bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { Dali::BaseHandle handle( object ); @@ -1235,16 +1308,18 @@ void TextField::OnInitialize() mController = Text::Controller::New( this, this ); // When using the vector-based rendering, the size of the GLyphs are different - TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH; + TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH; mController->SetGlyphType( glyphType ); mDecorator = Text::Decorator::New( *mController, *mController ); + mInputMethodContext = InputMethodContext::New( self ); + mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX ); // Enables the text input. - mController->EnableTextInput( mDecorator ); + mController->EnableTextInput( mDecorator, mInputMethodContext ); // Enables the horizontal scrolling after the text input has been enabled. mController->SetHorizontalScrollEnabled( true ); @@ -1258,12 +1333,15 @@ void TextField::OnInitialize() mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT ); mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT ); + // Sets layoutDirection value + Dali::Stage stage = Dali::Stage::GetCurrent(); + Dali::LayoutDirection::Type layoutDirection = static_cast( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + mController->SetLayoutDirection( layoutDirection ); + // Forward input events to controller EnableGestureDetection( static_cast( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) ); GetTapGestureDetector().SetMaximumTapsRequired( 2 ); - mImfManager = ImfManager::Get(); - self.TouchSignal().Connect( this, &TextField::OnTouched ); // Set BoundingBox to stage size if not already set. @@ -1282,7 +1360,9 @@ void TextField::OnInitialize() // Fill-parent area by default self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); - self.OnStageSignal().Connect( this, &TextField::OnStageConnect ); + self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect ); + + DevelControl::SetInputMethodContext( *this, mInputMethodContext ); if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy ) { @@ -1354,7 +1434,15 @@ void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container ) Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) ); // Support Right-To-Left of padding - Dali::LayoutDirection::Type layoutDirection = static_cast( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + Dali::LayoutDirection::Type layoutDirection; + if( mController->IsMatchSystemLanguageDirection() ) + { + layoutDirection = static_cast( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + } + else + { + layoutDirection = static_cast( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + } if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection ) { std::swap( padding.start, padding.end ); @@ -1362,14 +1450,14 @@ void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container ) if( mStencil ) { - mStencil.SetPosition( padding.start, padding.top ); + mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top )); } if( mActiveLayer ) { - mActiveLayer.SetPosition( padding.start, padding.top ); + mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top )); } - const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize ); + const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection ); if( ( Text::Controller::NONE_UPDATED != updateTextType ) || !mRenderer ) @@ -1405,7 +1493,7 @@ void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container ) { // @note: The callback manager takes the ownership of the callback object. mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal ); - adaptor.AddIdle( mIdleCallback ); + adaptor.AddIdle( mIdleCallback, false ); } } } @@ -1430,8 +1518,14 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType ) if( renderableActor != mRenderableActor ) { + UnparentAndReset( mBackgroundActor ); UnparentAndReset( mRenderableActor ); mRenderableActor = renderableActor; + + if ( mRenderableActor ) + { + mBackgroundActor = mController->CreateBackgroundActor(); + } } } @@ -1439,9 +1533,12 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType ) { const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition(); + float renderableActorPositionX, renderableActorPositionY; + if( mStencil ) { - mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y ); + renderableActorPositionX = scrollOffset.x + mAlignmentOffset; + renderableActorPositionY = scrollOffset.y; } else { @@ -1455,13 +1552,17 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType ) std::swap( padding.start, padding.end ); } - mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top ); + renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start; + renderableActorPositionY = scrollOffset.y + padding.top; } + mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY )); // Make sure the actors are parented correctly with/without clipping Actor self = mStencil ? mStencil : Self(); + Actor highlightActor; + for( std::vector::iterator it = mClippingDecorationActors.begin(), endIt = mClippingDecorationActors.end(); it != endIt; @@ -1469,35 +1570,57 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType ) { self.Add( *it ); it->LowerToBottom(); + + if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" ) + { + highlightActor = *it; + } } mClippingDecorationActors.clear(); self.Add( mRenderableActor ); + + if ( mBackgroundActor ) + { + if ( mDecorator && mDecorator->IsHighlightVisible() ) + { + self.Add( mBackgroundActor ); + mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords. + mBackgroundActor.LowerBelow( highlightActor ); + } + else + { + mRenderableActor.Add( mBackgroundActor ); + mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords. + mBackgroundActor.LowerToBottom(); + } + } } } void TextField::OnKeyInputFocusGained() { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() ); + if ( mInputMethodContext ) + { + mInputMethodContext.ApplyOptions( mInputMethodOptions ); - mImfManager.ApplyOptions( mInputMethodOptions ); - - mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged ); - - mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent ); + mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged ); - // Notify that the text editing start. - mImfManager.Activate(); + mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent ); - // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated. - mImfManager.SetRestoreAfterFocusLost( true ); + // Notify that the text editing start. + mInputMethodContext.Activate(); - ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); + // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated. + mInputMethodContext.SetRestoreAfterFocusLost( true ); + } + ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); - if ( notifier ) - { - notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected ); - } + if ( notifier ) + { + notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected ); + } mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event @@ -1507,16 +1630,17 @@ void TextField::OnKeyInputFocusGained() void TextField::OnKeyInputFocusLost() { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() ); + if ( mInputMethodContext ) + { + mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged ); + // The text editing is finished. Therefore the inputMethodContext don't have restore activation. + mInputMethodContext.SetRestoreAfterFocusLost( false ); - mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged ); - // The text editing is finished. Therefore the imf manager don't have restore activation. - mImfManager.SetRestoreAfterFocusLost( false ); - - // Notify that the text editing finish. - mImfManager.Deactivate(); - - mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent ); + // Notify that the text editing finish. + mInputMethodContext.Deactivate(); + mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent ); + } ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); if ( notifier ) @@ -1532,9 +1656,10 @@ void TextField::OnKeyInputFocusLost() void TextField::OnTap( const TapGesture& gesture ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() ); - - mImfManager.Activate(); - + if ( mInputMethodContext ) + { + mInputMethodContext.Activate(); + } // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures Extents padding; padding = Self().GetProperty( Toolkit::Control::Property::PADDING ); @@ -1550,8 +1675,10 @@ void TextField::OnPan( const PanGesture& gesture ) void TextField::OnLongPress( const LongPressGesture& gesture ) { - mImfManager.Activate(); - + if ( mInputMethodContext ) + { + mInputMethodContext.Activate(); + } Extents padding; padding = Self().GetProperty( Toolkit::Control::Property::PADDING ); mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top ); @@ -1561,19 +1688,19 @@ void TextField::OnLongPress( const LongPressGesture& gesture ) bool TextField::OnKeyEvent( const KeyEvent& event ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() ); - if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() ) + if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() ) { // Make sure ClearKeyInputFocus when only key is up - if( event.state == KeyEvent::Up ) + if( event.GetState() == KeyEvent::Up ) { ClearKeyInputFocus(); } return true; } - else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode ) + else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() ) { // Do nothing when enter is comming. return false; @@ -1659,15 +1786,15 @@ void TextField::AddDecoration( Actor& actor, bool needsClipping ) } else { - actor.SetParentOrigin( ParentOrigin::TOP_LEFT ); - actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); Self().Add( actor ); mActiveLayer = actor; } } } -void TextField::OnStageConnect( Dali::Actor actor ) +void TextField::OnSceneConnect( Dali::Actor actor ) { if ( mHasBeenStaged ) { @@ -1679,24 +1806,19 @@ void TextField::OnStageConnect( Dali::Actor actor ) } } -ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent ) +InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName ); - return mController->OnImfEvent( imfManager, imfEvent ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName ); + return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent ); } void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType ) { if( mDecorator ) { - ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) ); - - if ( image ) - { - Property::Map map; - Scripting::CreatePropertyMap( image, map ); - value = map; - } + Property::Map map; + map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType ); + value = map; } } @@ -1706,8 +1828,8 @@ void TextField::EnableClipping() { // Creates an extra control to be used as stencil buffer. mStencil = Control::New(); - mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); // Creates a background visual. Even if the color is transparent it updates the stencil. mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND, @@ -1715,7 +1837,7 @@ void TextField::EnableClipping() Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) ); // Enable the clipping property. - mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); + mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); Self().Add( mStencil ); @@ -1742,20 +1864,20 @@ void TextField::KeyboardStatusChanged(bool keyboardShown) } } -void TextField::OnStageConnection( int depth ) +void TextField::OnSceneConnection( int depth ) { // Sets the depth to the visuals inside the text's decorator. mDecorator->SetTextDepth( depth ); // The depth of the text renderer is set in the RenderText() called from OnRelayout(). - // Call the Control::OnStageConnection() to set the depth of the background. - Control::OnStageConnection( depth ); + // Call the Control::OnSceneConnection() to set the depth of the background. + Control::OnSceneConnection( depth ); } -bool TextField::OnTouched( Actor actor, const TouchData& touch ) +bool TextField::OnTouched( Actor actor, const TouchEvent& touch ) { - return true; + return false; } void TextField::OnIdleSignal()