From: Bartlomiej Grzelewski Date: Thu, 15 Apr 2021 09:27:12 +0000 (+0200) Subject: [AT-SPI] Add SetTextContents, InsertText and DeleteText X-Git-Tag: dali_2.0.29~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a2687fd49865332236bd240452b5c1efe96e5e9b;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [AT-SPI] Add SetTextContents, InsertText and DeleteText Extend at-spi implementation for EditableText widgets. Change-Id: I9669eb4f9fb4c34c3d0a1cd8ed5e751066ce98d7 --- diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls.cpp index f3d97a9..dabd012 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls.cpp @@ -559,6 +559,13 @@ int UtcDaliAccessibilityTextField(void) DALI_TEST_EQUALS( text->SetSelection( 1, 0, 1 ), false, TEST_LOCATION ); DALI_TEST_EQUALS( text->RemoveSelection( 1 ), false, TEST_LOCATION ); + DALI_TEST_EQUALS(editabletext->SetTextContents("adef"), true, TEST_LOCATION); + DALI_TEST_EQUALS(editabletext->InsertText(1, "bc"), true, TEST_LOCATION); + DALI_TEST_EQUALS(text->GetText(0, 6), "abcdef", TEST_LOCATION); + DALI_TEST_EQUALS(editabletext->DeleteText(5, 1), false, TEST_LOCATION); + DALI_TEST_EQUALS(editabletext->DeleteText(1, 5), true, TEST_LOCATION); + DALI_TEST_EQUALS(text->GetText(0, 2), "af", TEST_LOCATION); + Dali::Accessibility::TestEnableSC( false ); END_TEST; @@ -608,6 +615,13 @@ int UtcDaliAccessibilityTextEditor(void) DALI_TEST_EQUALS( text->SetSelection( 1, 0, 1 ), false, TEST_LOCATION ); DALI_TEST_EQUALS( text->RemoveSelection( 1 ), false, TEST_LOCATION ); + DALI_TEST_EQUALS(editabletext->SetTextContents("adef"), true, TEST_LOCATION); + DALI_TEST_EQUALS(editabletext->InsertText(1, "bc"), true, TEST_LOCATION); + DALI_TEST_EQUALS(text->GetText(0, 6), "abcdef", TEST_LOCATION); + DALI_TEST_EQUALS(editabletext->DeleteText(5, 1), false, TEST_LOCATION); + DALI_TEST_EQUALS(editabletext->DeleteText(1, 5), true, TEST_LOCATION); + DALI_TEST_EQUALS(text->GetText(0, 2), "af", TEST_LOCATION); + Dali::Accessibility::TestEnableSC( false ); END_TEST; 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 48e0118..be18ec5 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -2261,7 +2261,22 @@ bool TextEditor::AccessibleImpl::CutText(size_t startPosition, 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())); + txt.substr(0, startPosition) + txt.substr(endPosition)); + + return true; +} + +bool TextEditor::AccessibleImpl::DeleteText(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(); + + slf.SetProperty(Toolkit::TextEditor::Property::TEXT, + txt.substr(0, startPosition) + txt.substr(endPosition)); return true; } @@ -2283,6 +2298,26 @@ Dali::Accessibility::States TextEditor::AccessibleImpl::CalculateStates() return states; } +bool TextEditor::AccessibleImpl::InsertText(size_t startPosition, + std::string text) +{ + auto slf = Toolkit::TextEditor::DownCast(Self()); + auto txt = slf.GetProperty(Toolkit::TextEditor::Property::TEXT).Get(); + + txt.insert(startPosition, text); + + slf.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(txt)); + + return true; +} + +bool TextEditor::AccessibleImpl::SetTextContents(std::string newContents) +{ + auto slf = Toolkit::TextEditor::DownCast(Self()); + slf.SetProperty(Toolkit::TextEditor::Property::TEXT, std::move(newContents)); + return true; +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index d0609b6..eb3bae4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -442,6 +442,9 @@ private: // Data bool CopyText(size_t startPosition, size_t endPosition) override; bool CutText(size_t startPosition, size_t endPosition) override; Accessibility::States CalculateStates() override; + bool InsertText(size_t startPosition, std::string text) override; + bool SetTextContents(std::string newContents) override; + bool DeleteText(size_t startPosition, size_t endPosition) override; }; }; 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 c0d7903..4e5cd9c 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -2128,7 +2128,22 @@ bool TextField::AccessibleImpl::CutText(size_t startPosition, Dali::Toolkit::GetImpl(slf).getController()->CopyStringToClipboard(txt.substr(startPosition, endPosition - startPosition)); slf.SetProperty(Toolkit::TextField::Property::TEXT, - txt.substr(0, startPosition) + txt.substr(endPosition - startPosition, txt.size())); + txt.substr(0, startPosition) + txt.substr(endPosition)); + + return true; +} + +bool TextField::AccessibleImpl::DeleteText(size_t startPosition, + size_t endPosition) +{ + if(endPosition <= startPosition) + return false; + + auto slf = Toolkit::TextField::DownCast(Self()); + auto txt = slf.GetProperty(Toolkit::TextField::Property::TEXT).Get(); + + slf.SetProperty(Toolkit::TextField::Property::TEXT, + txt.substr(0, startPosition) + txt.substr(endPosition)); return true; } @@ -2151,6 +2166,26 @@ Dali::Accessibility::States TextField::AccessibleImpl::CalculateStates() return states; } +bool TextField::AccessibleImpl::InsertText(size_t startPosition, + std::string text) +{ + auto slf = Toolkit::TextField::DownCast(Self()); + auto txt = slf.GetProperty(Toolkit::TextField::Property::TEXT).Get(); + + txt.insert(startPosition, text); + + slf.SetProperty(Toolkit::TextField::Property::TEXT, std::move(txt)); + + return true; +} + +bool TextField::AccessibleImpl::SetTextContents(std::string newContents) +{ + auto slf = Toolkit::TextField::DownCast(Self()); + slf.SetProperty(Toolkit::TextField::Property::TEXT, std::move(newContents)); + return true; +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index 670b81c..c76f05a 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -398,6 +398,9 @@ protected: bool CopyText(size_t startPosition, size_t endPosition) override; bool CutText(size_t startPosition, size_t endPosition) override; Accessibility::States CalculateStates() override; + bool InsertText(size_t startPosition, std::string text) override; + bool SetTextContents(std::string newContents) override; + bool DeleteText(size_t startPosition, size_t endPosition) override; }; };