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=d9314015954637dedacc4ac57e1ebc48c73c199c;hp=5707e4805598d4835c53f2b113b3cc1df072bb75;hb=549e79b19f4d24588121f55739f9fc53e00fcdaf;hpb=9c1f4310db72879676b5aca2875fbf67b97a4b0a 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 5707e48..d931401 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -33,7 +33,6 @@ // INTERNAL INCLUDES #include -#include #include #include #include @@ -1350,313 +1349,29 @@ TextEditor::~TextEditor() std::string TextEditor::TextEditorAccessible::GetName() const { - auto self = Toolkit::TextEditor::DownCast(Self()); - return self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); -} - -std::string TextEditor::TextEditorAccessible::GetText(size_t startOffset, size_t endOffset) const -{ - if(endOffset <= startOffset) - { - return {}; - } - - auto self = Toolkit::TextEditor::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - - if(startOffset > text.size() || endOffset > text.size()) - { - return {}; - } - - return text.substr(startOffset, endOffset - startOffset); -} - -size_t TextEditor::TextEditorAccessible::GetCharacterCount() const -{ - auto self = Toolkit::TextEditor::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - - return text.size(); -} - -size_t TextEditor::TextEditorAccessible::GetCursorOffset() const -{ - auto slf = Toolkit::TextEditor::DownCast(Self()); - return Dali::Toolkit::GetImpl(slf).GetTextController()->GetCursorPosition(); -} - -bool TextEditor::TextEditorAccessible::SetCursorOffset(size_t offset) -{ - auto slf = Toolkit::TextEditor::DownCast(Self()); - auto txt = slf.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - if(offset > txt.size()) - { - return false; - } - - auto& slfImpl = Dali::Toolkit::GetImpl(slf); - slfImpl.GetTextController()->ResetCursorPosition(offset); - slfImpl.RequestTextRelayout(); - - return true; -} - -Dali::Accessibility::Range TextEditor::TextEditorAccessible::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary) const -{ - auto self = Toolkit::TextEditor::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - auto textSize = text.size(); - - auto range = Dali::Accessibility::Range{}; - - switch(boundary) - { - case Dali::Accessibility::TextBoundary::CHARACTER: - { - if(offset < textSize) - { - range.content = text[offset]; - range.startOffset = offset; - range.endOffset = offset + 1; - } - break; - } - case Dali::Accessibility::TextBoundary::WORD: - case Dali::Accessibility::TextBoundary::LINE: - { - auto textString = text.c_str(); - auto breaks = std::vector(textSize, 0); - - if(boundary == Dali::Accessibility::TextBoundary::WORD) - { - Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast(textString), textSize, "", breaks.data()); - } - else - { - Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast(textString), textSize, "", breaks.data()); - } - - auto index = 0u; - auto counter = 0u; - while(index < textSize && 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 = text.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 default */ - break; - } - case Dali::Accessibility::TextBoundary::PARAGRAPH: - { - /* Paragraph is not supported by libunibreak library */ - break; - } - default: - break; - } - - return range; -} - -Dali::Accessibility::Range TextEditor::TextEditorAccessible::GetRangeOfSelection(size_t selectionIndex) const -{ - // Since DALi supports only one selection indexes higher than 0 are ignored - if(selectionIndex > 0) - { - return {}; - } - - auto self = Toolkit::TextEditor::DownCast(Self()); - auto controller = Dali::Toolkit::GetImpl(self).GetTextController(); - std::string value{}; - controller->RetrieveSelection(value); - auto indices = controller->GetSelectionIndexes(); - - return {static_cast(indices.first), static_cast(indices.second), value}; -} - -bool TextEditor::TextEditorAccessible::RemoveSelection(size_t selectionIndex) -{ - // Since DALi supports only one selection indexes higher than 0 are ignored - if(selectionIndex > 0) - { - return false; - } - - auto self = Toolkit::TextEditor::DownCast(Self()); - Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0); - return true; -} - -bool TextEditor::TextEditorAccessible::SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset) -{ - // Since DALi supports only one selection indexes higher than 0 are ignored - if(selectionIndex > 0) - { - return false; - } - - auto self = Toolkit::TextEditor::DownCast(Self()); - Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset); - return true; -} - -Rect<> TextEditor::TextEditorAccessible::GetRangeExtents(size_t startOffset, size_t endOffset, Accessibility::CoordinateType type) -{ - if (endOffset <= startOffset || endOffset <= 0) - { - return {0, 0, 0, 0}; - } - - auto self = Toolkit::TextEditor::DownCast(Self()); - auto rect = Dali::Toolkit::GetImpl(self).GetTextController()->GetTextBoundingRectangle(startOffset, endOffset - 1); - - auto componentExtents = this->GetExtents(type); - - rect.x += componentExtents.x; - rect.y += componentExtents.y; - - return rect; -} - -bool TextEditor::TextEditorAccessible::CopyText(size_t startPosition, size_t endPosition) -{ - if(endPosition <= startPosition) - { - return false; - } - - auto self = Toolkit::TextEditor::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition)); - - return true; -} - -bool TextEditor::TextEditorAccessible::CutText(size_t startPosition, size_t endPosition) -{ - if(endPosition <= startPosition) - { - return false; - } - - auto self = Toolkit::TextEditor::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition)); - - self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition)); - - return true; + return GetWholeText(); } -bool TextEditor::TextEditorAccessible::DeleteText(size_t startPosition, size_t endPosition) +const std::vector& TextEditor::TextEditorAccessible::GetTextAnchors() const { - if(endPosition <= startPosition) - { - return false; - } - auto self = Toolkit::TextEditor::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - - self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition)); - return true; + return Toolkit::GetImpl(self).mAnchorActors; } -Dali::Accessibility::States TextEditor::TextEditorAccessible::CalculateStates() -{ - using namespace Dali::Accessibility; - - auto states = DevelControl::ControlAccessible::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; -} - -bool TextEditor::TextEditorAccessible::InsertText(size_t startPosition, std::string text) -{ - auto self = Toolkit::TextEditor::DownCast(Self()); - auto insertedText = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - - insertedText.insert(startPosition, text); - - self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(insertedText)); - - return true; -} - -bool TextEditor::TextEditorAccessible::SetTextContents(std::string newContents) +Toolkit::Text::ControllerPtr TextEditor::TextEditorAccessible::GetTextController() const { auto self = Toolkit::TextEditor::DownCast(Self()); - self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(newContents)); - return true; -} -int32_t TextEditor::TextEditorAccessible::GetLinkCount() const -{ - auto self = Toolkit::TextEditor::DownCast(Self()); - return Dali::Toolkit::GetImpl(self).mAnchorActors.size(); + return Toolkit::GetImpl(self).GetTextController(); } -Accessibility::Hyperlink* TextEditor::TextEditorAccessible::GetLink(int32_t linkIndex) const +void TextEditor::TextEditorAccessible::RequestTextRelayout() { - if(linkIndex < 0 || linkIndex >= GetLinkCount()) - { - return nullptr; - } - auto self = Toolkit::TextEditor::DownCast(Self()); - auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex]; - return dynamic_cast(Dali::Accessibility::Accessible::Get(anchorActor)); -} + auto self = Toolkit::TextEditor::DownCast(Self()); + auto& selfImpl = Toolkit::GetImpl(self); -int32_t TextEditor::TextEditorAccessible::GetLinkIndex(int32_t characterOffset) const -{ - auto self = Toolkit::TextEditor::DownCast(Self()); - auto controller = Dali::Toolkit::GetImpl(self).GetTextController(); - return controller->GetAnchorIndex(static_cast(characterOffset)); + selfImpl.RequestTextRelayout(); } } // namespace Internal