X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-controls%2Ftext-editor-impl.cpp;h=b44029c454177ceb6532e2156a709c75eb0b09f8;hb=HEAD;hp=7e4b24144578a65e5fc9b67d308dba2ca955d7fc;hpb=d7bf9a0c46a7900e7c066711463babd639154f73;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 7e4b241..43a5884 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -27,17 +27,18 @@ #include #include #include +#include #include #include #include // INTERNAL INCLUDES #include -#include #include #include #include #include +#include #include #include #include @@ -158,6 +159,11 @@ DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "minLineSize", DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "strikethrough", MAP, STRIKETHROUGH ) DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH ) DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "characterSpacing", FLOAT, CHARACTER_SPACING ) +DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "relativeLineSize", FLOAT, RELATIVE_LINE_SIZE ) +DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "verticalAlignment", STRING, VERTICAL_ALIGNMENT ) +DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "selectionPopupStyle", MAP, SELECTION_POPUP_STYLE ) +DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "removeFrontInset", BOOLEAN, REMOVE_FRONT_INSET ) +DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "removeBackInset", BOOLEAN, REMOVE_BACK_INSET ) DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -230,10 +236,10 @@ Toolkit::TextEditor::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask i } // namespace -Toolkit::TextEditor TextEditor::New() +Toolkit::TextEditor TextEditor::New(ControlBehaviour additionalBehaviour) { // Create the implementation, temporarily owned by this handle on stack - IntrusivePtr impl = new TextEditor(); + IntrusivePtr impl = new TextEditor(additionalBehaviour); // Pass ownership to CustomActor handle Toolkit::TextEditor handle(*impl); @@ -361,6 +367,31 @@ Vector TextEditor::GetTextPosition(const uint32_t startIndex, const uin return mController->GetTextPosition(startIndex, endIndex); } +Rect TextEditor::GetLineBoundingRectangle(const uint32_t lineIndex) const +{ + return mController->GetLineBoundingRectangle(lineIndex); +} + +Rect TextEditor::GetCharacterBoundingRectangle(const uint32_t charIndex) const +{ + return mController->GetCharacterBoundingRectangle(charIndex); +} + +int TextEditor::GetCharacterIndexAtPosition(float visualX, float visualY) const +{ + return mController->GetCharacterIndexAtPosition(visualX, visualY); +} + +Rect<> TextEditor::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const +{ + return mController->GetTextBoundingRectangle(startIndex, endIndex); +} + +void TextEditor::SetSpannedText(const Text::Spanned& spannedText) +{ + mController->SetSpannedText(spannedText); +} + string TextEditor::GetSelectedText() const { string selectedText = ""; @@ -582,15 +613,13 @@ 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. mStencil = Control::New(); mStencil.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); mStencil.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mStencil.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIDDEN, true); // Creates a background visual. Even if the color is transparent it updates the stencil. mStencil.SetProperty(Toolkit::Control::Property::BACKGROUND, @@ -602,15 +631,19 @@ void TextEditor::OnInitialize() self.Add(mStencil); - DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) { - return std::unique_ptr( - new AccessibleImpl(actor, Dali::Accessibility::Role::ENTRY)); - }); + // Accessibility + self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::ENTRY); + self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true); Accessibility::Bridge::EnabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged); Accessibility::Bridge::DisabledSignal().Connect(this, &TextEditor::OnAccessibilityStatusChanged); } +DevelControl::ControlAccessible* TextEditor::CreateAccessibleObject() +{ + return new TextEditorAccessible(Self()); +} + void TextEditor::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) { DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnStyleChange\n"); @@ -671,6 +704,31 @@ void TextEditor::ResizeActor(Actor& actor, const Vector2& size) } } +void TextEditor::OnPropertySet(Property::Index index, const Property::Value& propertyValue) +{ + DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::OnPropertySet index[%d]\n", index); + + switch(index) + { + case DevelActor::Property::USER_INTERACTION_ENABLED: + { + const bool enabled = propertyValue.Get(); + mController->SetUserInteractionEnabled(enabled); + if(mStencil) + { + float opacity = enabled ? 1.0f : mController->GetDisabledColorOpacity(); + mStencil.SetProperty(Actor::Property::OPACITY, opacity); + } + break; + } + default: + { + Control::OnPropertySet(index, propertyValue); // up call to control for non-handled properties + break; + } + } +} + void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container) { DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor OnRelayout\n"); @@ -700,6 +758,13 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container) mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top)); ResizeActor(mActiveLayer, contentSize); } + if(mCursorLayer) + { + // The cursor layer is added to the stencil in RenderText. + // Do not calculate the position because the stencil has already been resized excluding the padding size. + // There is no case where the text editor does not have a stencil. + ResizeActor(mCursorLayer, contentSize); + } // If there is text changed, callback is called. if(mTextChanged) @@ -717,7 +782,7 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container) if(mDecorator && (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType))) { - mDecorator->Relayout(contentSize); + mDecorator->Relayout(contentSize, container); } if(!mRenderer) @@ -754,23 +819,13 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container) // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation. if(!mController->IsInputStyleChangedSignalsQueueEmpty()) { - if(Adaptor::IsAvailable()) - { - Adaptor& adaptor = Adaptor::Get(); - - if(NULL == mIdleCallback) - { - // @note: The callback manager takes the ownership of the callback object. - mIdleCallback = MakeCallback(this, &TextEditor::OnIdleSignal); - adaptor.AddIdle(mIdleCallback, false); - } - } + mController->RequestProcessInputStyleChangedSignals(); } } void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType) { - CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType); + CommonTextUtils::RenderText(Self(), mRenderer, mController, mDecorator, mAlignmentOffset, mRenderableActor, mBackgroundActor, mCursorLayer, mStencil, mClippingDecorationActors, mAnchorActors, updateTextType); if(mRenderableActor) { ApplyScrollPosition(); @@ -797,15 +852,12 @@ void TextEditor::OnKeyInputFocusGained() // 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) + if(IsEditable() && mController->IsUserInteractionEnabled()) { - notifier.ContentSelectedSignal().Connect(this, &TextEditor::OnClipboardTextSelected); + mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event } - mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event - EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last. } @@ -824,12 +876,6 @@ void TextEditor::OnKeyInputFocusLost() mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent); } - ClipboardEventNotifier notifier(ClipboardEventNotifier::Get()); - - if(notifier) - { - notifier.ContentSelectedSignal().Disconnect(this, &TextEditor::OnClipboardTextSelected); - } mController->KeyboardFocusLostEvent(); @@ -856,12 +902,21 @@ void TextEditor::OnTap(const TapGesture& gesture) mController->TapEvent(gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top); mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top); + Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get(); + if(keyboardFocusManager) + { + keyboardFocusManager.SetCurrentFocusActor(Self()); + } SetKeyInputFocus(); } void TextEditor::OnPan(const PanGesture& gesture) { mController->PanEvent(gesture.GetState(), gesture.GetDisplacement()); + if(gesture.GetState() == GestureState::STARTED && !mController->IsScrollable(gesture.GetDisplacement())) + { + Dali::DevelActor::SetNeedGesturePropagation(Self(), true); + } } void TextEditor::OnLongPress(const LongPressGesture& gesture) @@ -887,6 +942,11 @@ bool TextEditor::OnKeyEvent(const KeyEvent& event) // Make sure ClearKeyInputFocus when only key is up if(event.GetState() == KeyEvent::UP) { + Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get(); + if(keyboardFocusManager) + { + keyboardFocusManager.ClearFocus(); + } ClearKeyInputFocus(); } @@ -903,25 +963,28 @@ void TextEditor::RequestTextRelayout() void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content) { - if(Accessibility::IsUp()) + auto accessible = GetAccessibleObject(); + if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) { - Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content); + accessible->EmitTextInserted(position, length, content); } } void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content) { - if(Accessibility::IsUp()) + auto accessible = GetAccessibleObject(); + if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) { - Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content); + accessible->EmitTextDeleted(position, length, content); } } void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition) { - if(Accessibility::IsUp()) + auto accessible = GetAccessibleObject(); + if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) { - Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition); + accessible->EmitTextCursorMoved(newPosition); } if((oldPosition != newPosition) && !mCursorPositionChanged) @@ -1032,7 +1095,7 @@ void TextEditor::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t n } } -void TextEditor::AddDecoration(Actor& actor, bool needsClipping) +void TextEditor::AddDecoration(Actor& actor, DecorationType type, bool needsClipping) { if(actor) { @@ -1040,16 +1103,27 @@ void TextEditor::AddDecoration(Actor& actor, bool needsClipping) { mClippingDecorationActors.push_back(actor); } - else + + // If the actor is a layer type, add it. + if(type == DecorationType::ACTIVE_LAYER) { - actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); - actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); - Self().Add(actor); - mActiveLayer = actor; + AddLayer(mActiveLayer, actor); + } + else if(type == DecorationType::CURSOR_LAYER) + { + AddLayer(mCursorLayer, actor); } } } +void TextEditor::AddLayer(Actor& layer, Actor& actor) +{ + actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + Self().Add(actor); + layer = actor; +} + void TextEditor::SetTextSelectionRange(const uint32_t* start, const uint32_t* end) { if(mController && mController->IsShowingRealText()) @@ -1169,7 +1243,7 @@ void TextEditor::UpdateScrollBar() void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation) { // If animation is successfully ended, then emit ScrollStateChangedSignal - if(animation.GetCurrentProgress() == 0.0f) + if(Dali::EqualsZero(animation.GetCurrentProgress())) { mScrollStarted = false; Dali::Toolkit::TextEditor handle(GetOwner()); @@ -1206,11 +1280,6 @@ void TextEditor::GetHandleImagePropertyValue(Property::Value& value, Text::Handl } } -void TextEditor::OnClipboardTextSelected(ClipboardEventNotifier& clipboard) -{ - mController->PasteClipboardItemEvent(); -} - void TextEditor::KeyboardStatusChanged(bool keyboardShown) { DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown); @@ -1242,15 +1311,6 @@ bool TextEditor::OnTouched(Actor actor, const TouchEvent& touch) return false; } -void TextEditor::OnIdleSignal() -{ - // Emits the change of input style signals. - mController->ProcessInputStyleChangedSignals(); - - // Set the pointer to null as the callback manager deletes the callback after execute it. - mIdleCallback = NULL; -} - void TextEditor::ApplyScrollPosition() { const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition(); @@ -1298,10 +1358,29 @@ void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type typ mController->ChangedLayoutDirection(); } -TextEditor::TextEditor() -: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), +void TextEditor::SetRemoveFrontInset(bool remove) +{ + mController->SetRemoveFrontInset(remove); +} + +bool TextEditor::IsRemoveFrontInset() const +{ + return mController->IsRemoveFrontInset(); +} + +void TextEditor::SetRemoveBackInset(bool remove) +{ + mController->SetRemoveBackInset(remove); +} + +bool TextEditor::IsRemoveBackInset() const +{ + return mController->IsRemoveBackInset(); +} + +TextEditor::TextEditor(ControlBehaviour additionalBehaviour) +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)), mAnimationPeriod(0.0f, 0.0f), - mIdleCallback(NULL), mAlignmentOffset(0.f), mScrollAnimationDuration(0.f), mLineSpacing(0.f), @@ -1324,305 +1403,33 @@ TextEditor::TextEditor() TextEditor::~TextEditor() { UnparentAndReset(mStencil); - - if((NULL != mIdleCallback) && Adaptor::IsAvailable()) - { - // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed. - Adaptor::Get().RemoveIdle(mIdleCallback); - } } -std::string TextEditor::AccessibleImpl::GetName() const +std::string TextEditor::TextEditorAccessible::GetName() const { - auto self = Toolkit::TextEditor::DownCast(Self()); - return self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); + return GetWholeText(); } -std::string TextEditor::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const +const std::vector& TextEditor::TextEditorAccessible::GetTextAnchors() 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); + return Toolkit::GetImpl(self).mAnchorActors; } -size_t TextEditor::AccessibleImpl::GetCharacterCount() const +Toolkit::Text::ControllerPtr TextEditor::TextEditorAccessible::GetTextController() const { auto self = Toolkit::TextEditor::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - - return text.size(); -} - -size_t TextEditor::AccessibleImpl::GetCursorOffset() const -{ - auto slf = Toolkit::TextEditor::DownCast(Self()); - return Dali::Toolkit::GetImpl(slf).GetTextController()->GetCursorPosition(); -} - -bool TextEditor::AccessibleImpl::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; + return Toolkit::GetImpl(self).GetTextController(); } -Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(size_t offset, Dali::Accessibility::TextBoundary boundary) const +void TextEditor::TextEditorAccessible::RequestTextRelayout() { - auto self = Toolkit::TextEditor::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); - auto textSize = text.size(); - - auto range = Dali::Accessibility::Range{}; + auto self = Toolkit::TextEditor::DownCast(Self()); + auto& selfImpl = Toolkit::GetImpl(self); - 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::AccessibleImpl::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::AccessibleImpl::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::AccessibleImpl::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; -} - -bool TextEditor::AccessibleImpl::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::AccessibleImpl::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; -} - -bool TextEditor::AccessibleImpl::DeleteText(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(); - - self.SetProperty(Toolkit::TextEditor::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition)); - - return true; -} - -Dali::Accessibility::States TextEditor::AccessibleImpl::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::AccessibleImpl::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::AccessibleImpl::SetTextContents(std::string newContents) -{ - auto self = Toolkit::TextEditor::DownCast(Self()); - self.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(newContents)); - return true; -} - -int32_t TextEditor::AccessibleImpl::GetLinkCount() const -{ - auto self = Toolkit::TextEditor::DownCast(Self()); - return Dali::Toolkit::GetImpl(self).mAnchorActors.size(); -} - -Accessibility::Hyperlink* TextEditor::AccessibleImpl::GetLink(int32_t linkIndex) const -{ - 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)); -} - -int32_t TextEditor::AccessibleImpl::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