// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/controls/control-devel.h>
#include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
-#include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
#include <dali-toolkit/devel-api/text/rendering-backend.h>
#include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
#include <dali-toolkit/internal/controls/text-controls/text-field-property-handler.h>
DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "grabHandleColor", VECTOR4, GRAB_HANDLE_COLOR )
DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputFilter", MAP, INPUT_FILTER )
DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsisPosition", INTEGER, ELLIPSIS_POSITION )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "strikethrough", MAP, STRIKETHROUGH )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "characterSpacing", FLOAT, CHARACTER_SPACING )
DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "cursorPositionChanged", SIGNAL_CURSOR_POSITION_CHANGED)
DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionChanged", SIGNAL_SELECTION_CHANGED )
DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionCleared", SIGNAL_SELECTION_CLEARED )
+DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "selectionStarted", SIGNAL_SELECTION_STARTED )
DALI_TYPE_REGISTRATION_END()
// clang-format on
return fieldInputStyleMask;
}
-bool IsHiddenInput(Toolkit::TextField textField)
-{
- Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
- auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
- if(mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE))
- {
- return true;
- }
- return false;
-}
-
-char GetSubstituteCharacter(Toolkit::TextField textField)
-{
- Property::Map hiddenInputSettings = textField.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
- auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
- if(substChar)
- {
- return static_cast<char>(substChar->Get<int>());
- }
- return STAR;
-}
-
} // namespace
Toolkit::TextField TextField::New()
fieldImpl.SelectionClearedSignal().Connect(tracker, functor);
}
}
+ else if(0 == strcmp(signalName.c_str(), SIGNAL_SELECTION_STARTED))
+ {
+ if(field)
+ {
+ Internal::TextField& fieldImpl(GetImpl(field));
+ fieldImpl.SelectionStartedSignal().Connect(tracker, functor);
+ }
+ }
else
{
// signalName does not match any signal
return mSelectionClearedSignal;
}
+DevelTextField::SelectionStartedSignalType& TextField::SelectionStartedSignal()
+{
+ return mSelectionStartedSignal;
+}
+
void TextField::OnAccessibilityStatusChanged()
{
CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors);
self.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
self.OnSceneSignal().Connect(this, &TextField::OnSceneConnect);
- //Enable highightability
- self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
-
DevelControl::SetInputMethodContext(*this, mInputMethodContext);
if(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy)
EnableClipping();
}
- DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
- return std::unique_ptr<Dali::Accessibility::Accessible>(
- 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, &TextField::OnAccessibilityStatusChanged);
Accessibility::Bridge::DisabledSignal().Connect(this, &TextField::OnAccessibilityStatusChanged);
}
+DevelControl::ControlAccessible* TextField::CreateAccessibleObject()
+{
+ return new TextFieldAccessible(Self());
+}
+
void TextField::OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change)
{
DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
ResizeActor(mActiveLayer, contentSize);
}
+ if(mCursorLayer)
+ {
+ mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
+ ResizeActor(mCursorLayer, contentSize);
+ }
// If there is text changed, callback is called.
if(mTextChanged)
EmitCursorPositionChangedSignal();
}
+ if(mSelectionStarted)
+ {
+ EmitSelectionStartedSignal();
+ }
+
if(mSelectionChanged)
{
EmitSelectionChangedSignal();
void TextField::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);
}
void TextField::OnKeyInputFocusGained()
void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content)
{
- if(Accessibility::IsUp())
- {
- Control::Impl::GetAccessibilityObject(Self())->EmitTextInserted(position, length, content);
- }
+ GetAccessibleObject()->EmitTextInserted(position, length, content);
}
void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
{
- if(Accessibility::IsUp())
- {
- Control::Impl::GetAccessibilityObject(Self())->EmitTextDeleted(position, length, content);
- }
+ GetAccessibleObject()->EmitTextDeleted(position, length, content);
}
void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
{
- if(Accessibility::IsUp())
- {
- Control::Impl::GetAccessibilityObject(Self())->EmitTextCursorMoved(newPosition);
- }
+ GetAccessibleObject()->EmitTextCursorMoved(newPosition);
if((oldPosition != newPosition) && !mCursorPositionChanged)
{
mSelectionCleared = false;
}
+void TextField::EmitSelectionStartedSignal()
+{
+ Dali::Toolkit::TextField handle(GetOwner());
+ mSelectionStartedSignal.Emit(handle);
+ mSelectionStarted = false;
+}
+
void TextField::SelectionChanged(uint32_t oldStart, uint32_t oldEnd, uint32_t newStart, uint32_t newEnd)
{
if(((oldStart != newStart) || (oldEnd != newEnd)) && !mSelectionChanged)
{
mSelectionCleared = true;
}
+ else
+ {
+ if(oldStart == oldEnd)
+ {
+ mSelectionStarted = true;
+ }
+ }
mSelectionChanged = true;
mOldSelectionStart = oldStart;
}
}
-void TextField::AddDecoration(Actor& actor, bool needsClipping)
+void TextField::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
{
if(actor)
{
{
mClippingDecorationActors.push_back(actor);
}
- else
+
+ // If the actor is a layer type, add it.
+ if(type == DecorationType::ACTIVE_LAYER)
+ {
+ AddLayer(mActiveLayer, actor);
+ }
+ else if(type == DecorationType::CURSOR_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(mCursorLayer, actor);
}
}
}
+void TextField::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 TextField::GetControlBackgroundColor(Vector4& color) const
{
Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND);
mSelectionCleared(false),
mOldPosition(0u),
mOldSelectionStart(0u),
- mOldSelectionEnd(0u)
+ mOldSelectionEnd(0u),
+ mSelectionStarted(false)
{
}
return mController->GetTextPosition(startIndex, endIndex);
}
-std::string TextField::AccessibleImpl::GetName() const
+std::string TextField::TextFieldAccessible::GetName() const
{
- auto self = Toolkit::TextField::DownCast(Self());
- if(IsHiddenInput(self))
+ if(IsHiddenInput())
{
return {};
}
- return self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
+ return GetWholeText();
}
-std::string TextField::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const
+const std::vector<Toolkit::TextAnchor>& TextField::TextFieldAccessible::GetTextAnchors() const
{
- if(endOffset <= startOffset)
- {
- return {};
- }
-
auto self = Toolkit::TextField::DownCast(Self());
- auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
- if(startOffset > text.size() || endOffset > text.size())
- {
- return {};
- }
- if(IsHiddenInput(self))
- {
- return std::string(endOffset - startOffset, GetSubstituteCharacter(self));
- }
- return text.substr(startOffset, endOffset - startOffset);
+ return Toolkit::GetImpl(self).mAnchorActors;
}
-size_t TextField::AccessibleImpl::GetCharacterCount() const
+Toolkit::Text::ControllerPtr TextField::TextFieldAccessible::GetTextController() const
{
auto self = Toolkit::TextField::DownCast(Self());
- auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
-
- return text.size();
-}
-size_t TextField::AccessibleImpl::GetCursorOffset() const
-{
- auto self = Toolkit::TextField::DownCast(Self());
- return Dali::Toolkit::GetImpl(self).GetTextController()->GetCursorPosition();
+ return Toolkit::GetImpl(self).GetTextController();
}
-bool TextField::AccessibleImpl::SetCursorOffset(size_t offset)
+std::uint32_t TextField::TextFieldAccessible::GetSubstituteCharacter() const
{
- auto self = Toolkit::TextField::DownCast(Self());
- auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
- if(offset > text.size())
- {
- return false;
- }
+ auto self = Toolkit::TextField::DownCast(Self());
+ auto hiddenInputSettings = self.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
+ auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER);
- auto& selfImpl = Dali::Toolkit::GetImpl(self);
- selfImpl.GetTextController()->ResetCursorPosition(offset);
- selfImpl.RequestTextRelayout();
-
- return true;
-}
-
-Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset(
- size_t offset, Dali::Accessibility::TextBoundary boundary) const
-{
- auto self = Toolkit::TextField::DownCast(Self());
- auto range = Dali::Accessibility::Range{};
-
- if(IsHiddenInput(self))
- {
- // Returning empty object, as there is no possibility to parse the textfield
- // when its content is hidden.
- return range;
- }
-
- auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
- auto textSize = text.size();
-
- 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<char>(textSize, 0);
-
- if(boundary == Dali::Accessibility::TextBoundary::WORD)
- {
- Accessibility::Accessible::FindWordSeparationsUtf8(reinterpret_cast<const utf8_t*>(textString), textSize, "", breaks.data());
- }
- else
- {
- Accessibility::Accessible::FindLineSeparationsUtf8(reinterpret_cast<const utf8_t*>(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 TextField::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::TextField::DownCast(Self());
- auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
- auto indices = controller->GetSelectionIndexes();
-
- auto startOffset = static_cast<size_t>(indices.first);
- auto endOffset = static_cast<size_t>(indices.second);
-
- if(IsHiddenInput(self))
- {
- return {startOffset, endOffset, std::string(endOffset - startOffset, GetSubstituteCharacter(self))};
- }
-
- std::string value{};
- controller->RetrieveSelection(value);
- return {startOffset, endOffset, value};
-}
-
-bool TextField::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::TextField::DownCast(Self());
- Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(0, 0);
- return true;
-}
-
-bool TextField::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::TextField::DownCast(Self());
- Dali::Toolkit::GetImpl(self).GetTextController()->SetSelection(startOffset, endOffset);
- return true;
-}
-
-bool TextField::AccessibleImpl::CopyText(size_t startPosition, size_t endPosition)
-{
- if(endPosition <= startPosition)
- {
- return false;
- }
-
- auto self = Toolkit::TextField::DownCast(Self());
- auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
- Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
-
- return true;
-}
-
-bool TextField::AccessibleImpl::CutText(size_t startPosition, size_t endPosition)
-{
- if(endPosition <= startPosition)
- {
- return false;
- }
-
- auto self = Toolkit::TextField::DownCast(Self());
- auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
- Dali::Toolkit::GetImpl(self).GetTextController()->CopyStringToClipboard(text.substr(startPosition, endPosition - startPosition));
-
- self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
-
- return true;
-}
-
-bool TextField::AccessibleImpl::DeleteText(size_t startPosition, size_t endPosition)
-{
- if(endPosition <= startPosition)
- {
- return false;
- }
-
- auto self = Toolkit::TextField::DownCast(Self());
- auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
-
- self.SetProperty(Toolkit::TextField::Property::TEXT, text.substr(0, startPosition) + text.substr(endPosition));
-
- return true;
-}
-
-Dali::Accessibility::States TextField::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)
+ if(substChar)
{
- states[State::FOCUSED] = true;
+ return static_cast<std::uint32_t>(substChar->Get<int>());
}
- return states;
-}
-
-bool TextField::AccessibleImpl::InsertText(size_t startPosition, std::string text)
-{
- auto self = Toolkit::TextField::DownCast(Self());
- auto insertedText = self.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
-
- insertedText.insert(startPosition, text);
-
- self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(insertedText));
-
- return true;
+ return TextControlAccessible::GetSubstituteCharacter();
}
-bool TextField::AccessibleImpl::SetTextContents(std::string newContents)
+bool TextField::TextFieldAccessible::IsHiddenInput() const
{
- auto self = Toolkit::TextField::DownCast(Self());
- self.SetProperty(Toolkit::TextField::Property::TEXT, std::move(newContents));
- return true;
-}
+ auto self = Toolkit::TextField::DownCast(Self());
+ auto hiddenInputSettings = self.GetProperty<Property::Map>(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS);
+ auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE);
-int32_t TextField::AccessibleImpl::GetLinkCount() const
-{
- auto self = Toolkit::TextField::DownCast(Self());
- return Dali::Toolkit::GetImpl(self).mAnchorActors.size();
+ return (mode && (mode->Get<int>() != Toolkit::HiddenInput::Mode::HIDE_NONE));
}
-Accessibility::Hyperlink* TextField::AccessibleImpl::GetLink(int32_t linkIndex) const
+void TextField::TextFieldAccessible::RequestTextRelayout()
{
- if(linkIndex < 0 || linkIndex >= GetLinkCount())
- {
- return nullptr;
- }
- auto self = Toolkit::TextField::DownCast(Self());
- auto anchorActor = Dali::Toolkit::GetImpl(self).mAnchorActors[linkIndex];
- return dynamic_cast<Accessibility::Hyperlink*>(Dali::Accessibility::Accessible::Get(anchorActor));
-}
+ auto self = Toolkit::TextField::DownCast(Self());
+ auto& selfImpl = Toolkit::GetImpl(self);
-int32_t TextField::AccessibleImpl::GetLinkIndex(int32_t characterOffset) const
-{
- auto self = Toolkit::TextField::DownCast(Self());
- auto controller = Dali::Toolkit::GetImpl(self).GetTextController();
- return controller->GetAnchorIndex(static_cast<size_t>(characterOffset));
+ selfImpl.RequestTextRelayout();
}
} // namespace Internal