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-editor-impl.cpp;h=7e64b6e3cb412c4d822069f4b8c8efac97988167;hp=75f6d6ff0028cc1c2058b70996ea85a8a08505a1;hb=8e1f9693459d06c4273f4423d16394615f6dfafe;hpb=debf82555db7c20b8cb890d0548227ae42ef92d8 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 75f6d6f..7e64b6e 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -146,6 +147,8 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalScrollPosition DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "verticalScrollPosition", INTEGER, VERTICAL_SCROLL_POSITION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING ) DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "fontSizeScale", FLOAT, FONT_SIZE_SCALE ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "primaryCursorPosition", INTEGER, PRIMARY_CURSOR_POSITION ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -743,6 +746,27 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } break; } + case Toolkit::DevelTextEditor::Property::FONT_SIZE_SCALE: + { + const float scale = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p FONT_SIZE_SCALE %f\n", impl.mController.Get(), scale ); + + if( !Equals( impl.mController->GetFontSizeScale(), scale ) ) + { + impl.mController->SetFontSizeScale( scale ); + } + break; + } + case Toolkit::DevelTextEditor::Property::PRIMARY_CURSOR_POSITION: + { + uint32_t position = static_cast(value.Get< int >()); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p PRIMARY_CURSOR_POSITION %d\n", impl.mController.Get(), position ); + if (impl.mController->SetPrimaryCursorPosition( position )) + { + impl.SetKeyInputFocus(); + } + break; + } } // switch } // texteditor } @@ -1089,6 +1113,16 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind value = impl.GetVerticalScrollPosition(); break; } + case Toolkit::DevelTextEditor::Property::FONT_SIZE_SCALE: + { + value = impl.mController->GetFontSizeScale(); + break; + } + case Toolkit::DevelTextEditor::Property::PRIMARY_CURSOR_POSITION: + { + value = static_cast(impl.mController->GetPrimaryCursorPosition()); + break; + } } //switch } @@ -1158,6 +1192,11 @@ DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal( return mMaxLengthReachedSignal; } +Text::ControllerPtr TextEditor::getController() +{ + return mController; +} + bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { Dali::BaseHandle handle( object ); @@ -1268,6 +1307,9 @@ void TextEditor::OnInitialize() self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT ); self.OnSceneSignal().Connect( this, &TextEditor::OnSceneConnect ); + //Enable highightability + self.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true ); + DevelControl::SetInputMethodContext( *this, mInputMethodContext ); // Creates an extra control to be used as stencil buffer. @@ -1285,6 +1327,11 @@ void TextEditor::OnInitialize() mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); self.Add( mStencil ); + + DevelControl::SetAccessibilityConstructor( self, []( Dali::Actor actor ) { + return std::unique_ptr< Dali::Accessibility::Accessible >( + new AccessibleImpl( actor, Dali::Accessibility::Role::ENTRY ) ); + } ); } void TextEditor::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) @@ -1467,6 +1514,9 @@ void TextEditor::OnKeyInputFocusGained() DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() ); if ( mInputMethodContext && IsEditable() ) { + // All input panel properties, such as layout, return key type, and input hint, should be set before input panel activates (or shows). + mInputMethodContext.NotifyTextInputMultiLine( true ); + mInputMethodContext.StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged ); mInputMethodContext.EventReceivedSignal().Connect( this, &TextEditor::OnInputMethodContextEvent ); @@ -1516,6 +1566,12 @@ void TextEditor::OnKeyInputFocusLost() EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last. } +bool TextEditor::OnAccessibilityActivated() +{ + SetKeyInputFocus(); + return true; +} + void TextEditor::OnTap( const TapGesture& gesture ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() ); @@ -1574,6 +1630,30 @@ void TextEditor::RequestTextRelayout() RelayoutRequest(); } +void TextEditor::TextInserted( unsigned int position, unsigned int length, const std::string &content ) +{ + if( Accessibility::IsUp() ) + { + Control::Impl::GetAccessibilityObject( Self() )->EmitTextInserted( position, length, content ); + } +} + +void TextEditor::TextDeleted( unsigned int position, unsigned int length, const std::string &content ) +{ + if( Accessibility::IsUp() ) + { + Control::Impl::GetAccessibilityObject( Self() )->EmitTextDeleted( position, length, content ); + } +} + +void TextEditor::CaretMoved( unsigned int position ) +{ + if( Accessibility::IsUp() ) + { + Control::Impl::GetAccessibilityObject( Self() )->EmitTextCaretMoved( position ); + } +} + void TextEditor::TextChanged() { Dali::Toolkit::TextEditor handle( GetOwner() ); @@ -1914,6 +1994,220 @@ TextEditor::~TextEditor() } } +std::string TextEditor::AccessibleImpl::GetName() +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + return slf.GetProperty( Toolkit::TextEditor::Property::TEXT ) + .Get< std::string >(); +} + +std::string TextEditor::AccessibleImpl::GetText( size_t startOffset, + size_t endOffset ) +{ + if( endOffset <= startOffset ) + return {}; + + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = + slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >(); + + if( startOffset > txt.size() || endOffset > txt.size() ) + return {}; + + return txt.substr( startOffset, endOffset - startOffset ); +} + +size_t TextEditor::AccessibleImpl::GetCharacterCount() +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = + slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >(); + + return txt.size(); +} + +size_t TextEditor::AccessibleImpl::GetCaretOffset() +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + return Dali::Toolkit::GetImpl( slf ).getController()->GetCursorPosition(); +} + +bool TextEditor::AccessibleImpl::SetCaretOffset(size_t offset) +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >(); + if (offset > txt.size()) + return false; + + auto& slfImpl = Dali::Toolkit::GetImpl( slf ); + slfImpl.getController()->ResetCursorPosition( offset ); + slfImpl.RequestTextRelayout(); + return true; +} + +Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset( + size_t offset, Dali::Accessibility::TextBoundary boundary ) +{ + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >(); + auto txt_size = txt.size(); + + auto range = Dali::Accessibility::Range{}; + + switch(boundary) + { + case Dali::Accessibility::TextBoundary::CHARACTER: + { + if (offset < txt_size) + { + range.content = txt[offset]; + range.startOffset = offset; + range.endOffset = offset + 1; + } + } + break; + case Dali::Accessibility::TextBoundary::WORD: + case Dali::Accessibility::TextBoundary::LINE: + { + auto txt_c_string = txt.c_str(); + auto breaks = std::vector< char >( txt_size, 0 ); + if(boundary == Dali::Accessibility::TextBoundary::WORD) + Accessibility::Accessible::FindWordSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data()); + else + Accessibility::Accessible::FindLineSeparationsUtf8((const utf8_t *) txt_c_string, txt_size, "", breaks.data()); + auto index = 0u; + auto counter = 0u; + while( index < txt_size && counter <= offset ) + { + auto start = index; + if(breaks[index]) + { + while(breaks[index]) + index++; + counter++; + } + else + { + if (boundary == Dali::Accessibility::TextBoundary::WORD) + index++; + if (boundary == Dali::Accessibility::TextBoundary::LINE) + counter++; + } + if ((counter > 0) && ((counter - 1) == offset)) + { + range.content = txt.substr(start, index - start + 1); + range.startOffset = start; + range.endOffset = index + 1; + } + if (boundary == Dali::Accessibility::TextBoundary::LINE) + index++; + } + } + break; + case Dali::Accessibility::TextBoundary::SENTENCE: + { + /* not supported by efl */ + } + break; + case Dali::Accessibility::TextBoundary::PARAGRAPH: + { + /* Paragraph is not supported by libunibreak library */ + } + break; + default: + break; + } + + return range; +} + +Dali::Accessibility::Range +TextEditor::AccessibleImpl::GetSelection( size_t selectionNum ) +{ + // Since DALi supports only one selection indexes higher than 0 are ignored + if( selectionNum > 0 ) + return {}; + + auto slf = Toolkit::TextEditor::DownCast( self ); + auto ctrl = Dali::Toolkit::GetImpl( slf ).getController(); + std::string ret; + ctrl->RetrieveSelection( ret ); + auto r = ctrl->GetSelectionIndexes(); + + return { static_cast(r.first), static_cast(r.second), ret }; +} + +bool TextEditor::AccessibleImpl::RemoveSelection( size_t selectionNum ) +{ + // Since DALi supports only one selection indexes higher than 0 are ignored + if( selectionNum > 0 ) + return false; + + auto slf = Toolkit::TextEditor::DownCast( self ); + Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 ); + return true; +} + +bool TextEditor::AccessibleImpl::SetSelection( size_t selectionNum, + size_t startOffset, + size_t endOffset ) +{ + // Since DALi supports only one selection indexes higher than 0 are ignored + if( selectionNum > 0 ) + return false; + + auto slf = Toolkit::TextEditor::DownCast( self ); + Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset, + endOffset ); + return true; +} + +bool TextEditor::AccessibleImpl::CopyText( size_t startPosition, + size_t endPosition ) +{ + if( endPosition <= startPosition ) + return false; + + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get(); + Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) ); + + return true; +} + +bool TextEditor::AccessibleImpl::CutText( size_t startPosition, + size_t endPosition ) +{ + if( endPosition <= startPosition ) + return false; + + auto slf = Toolkit::TextEditor::DownCast( self ); + auto txt = slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get(); + Dali::Toolkit::GetImpl( slf ).getController()->CopyStringToClipboard( txt.substr(startPosition, endPosition - startPosition) ); + + slf.SetProperty( Toolkit::TextEditor::Property::TEXT, + txt.substr( 0, startPosition ) + txt.substr( endPosition - startPosition, txt.size())); + + return true; +} + +Dali::Accessibility::States TextEditor::AccessibleImpl::CalculateStates() +{ + using namespace Dali::Accessibility; + + auto states = Control::Impl::AccessibleImpl::CalculateStates(); + states[State::EDITABLE] = true; + states[State::FOCUSABLE] = true; + + Toolkit::Control focusControl = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl(); + if (self == focusControl) + { + states[State::FOCUSED] = true; + } + + return states; +} + } // namespace Internal } // namespace Toolkit