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-field-impl.cpp;h=15ea36350a96b68680751faac771cf42ee481047;hp=35d06ea4ca2d57bf442a32b61ddc829440508f07;hb=1c6aa75cb7b66fdab6bff180c19066204171ef1e;hpb=cbae9964e389c6a5cafa3a284f281609a0ed2e60 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 35d06ea..15ea363 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -33,10 +33,10 @@ // INTERNAL INCLUDES #include #include -#include #include #include #include +#include #include #include #include @@ -145,6 +145,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "ellipsisPosition 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_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "selectionPopupStyle", MAP, SELECTION_POPUP_STYLE ) DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -206,28 +207,6 @@ Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask in return fieldInputStyleMask; } -bool IsHiddenInput(Toolkit::TextField textField) -{ - Property::Map hiddenInputSettings = textField.GetProperty(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS); - auto mode = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::MODE); - if(mode && (mode->Get() != Toolkit::HiddenInput::Mode::HIDE_NONE)) - { - return true; - } - return false; -} - -char GetSubstituteCharacter(Toolkit::TextField textField) -{ - Property::Map hiddenInputSettings = textField.GetProperty(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS); - auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER); - if(substChar) - { - return static_cast(substChar->Get()); - } - return STAR; -} - } // namespace Toolkit::TextField TextField::New() @@ -550,9 +529,6 @@ void TextField::OnInitialize() 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) @@ -560,15 +536,19 @@ void TextField::OnInitialize() EnableClipping(); } - 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, &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"); @@ -629,6 +609,31 @@ void TextField::ResizeActor(Actor& actor, const Vector2& size) } } +void TextField::OnPropertySet(Property::Index index, const Property::Value& propertyValue) +{ + DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::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 TextField::OnRelayout(const Vector2& size, RelayoutContainer& container) { DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField OnRelayout\n"); @@ -738,7 +743,7 @@ Text::ControllerPtr TextField::GetTextController() 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() @@ -767,7 +772,10 @@ void TextField::OnKeyInputFocusGained() notifier.ContentSelectedSignal().Connect(this, &TextField::OnClipboardTextSelected); } - mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event + if(IsEditable() && mController->IsUserInteractionEnabled()) + { + mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event + } EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last. } @@ -818,12 +826,21 @@ void TextField::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 TextField::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 TextField::OnLongPress(const LongPressGesture& gesture) @@ -849,6 +866,11 @@ bool TextField::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(); } @@ -884,26 +906,17 @@ void TextField::SetEditable(bool editable) 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) { @@ -1192,340 +1205,59 @@ Vector TextField::GetTextPosition(const uint32_t startIndex, const uint return mController->GetTextPosition(startIndex, endIndex); } -std::string TextField::AccessibleImpl::GetName() const -{ - auto self = Toolkit::TextField::DownCast(Self()); - if(IsHiddenInput(self)) - { - return {}; - } - - return self.GetProperty(Toolkit::TextField::Property::TEXT).Get(); -} - -std::string TextField::AccessibleImpl::GetText(size_t startOffset, size_t endOffset) const +std::string TextField::TextFieldAccessible::GetName() const { - if(endOffset <= startOffset) + if(IsHiddenInput()) { return {}; } - auto self = Toolkit::TextField::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get(); - - 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 GetWholeText(); } -size_t TextField::AccessibleImpl::GetCharacterCount() const +const std::vector& TextField::TextFieldAccessible::GetTextAnchors() const { auto self = Toolkit::TextField::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get(); - return text.size(); + return Toolkit::GetImpl(self).mAnchorActors; } -size_t TextField::AccessibleImpl::GetCursorOffset() const +Toolkit::Text::ControllerPtr TextField::TextFieldAccessible::GetTextController() const { auto self = Toolkit::TextField::DownCast(Self()); - return Dali::Toolkit::GetImpl(self).GetTextController()->GetCursorPosition(); -} -bool TextField::AccessibleImpl::SetCursorOffset(size_t offset) -{ - auto self = Toolkit::TextField::DownCast(Self()); - auto text = self.GetProperty(Toolkit::TextField::Property::TEXT).Get(); - if(offset > text.size()) - { - return false; - } - - auto& selfImpl = Dali::Toolkit::GetImpl(self); - selfImpl.GetTextController()->ResetCursorPosition(offset); - selfImpl.RequestTextRelayout(); - - return true; + return Toolkit::GetImpl(self).GetTextController(); } -Dali::Accessibility::Range TextField::AccessibleImpl::GetTextAtOffset( - size_t offset, Dali::Accessibility::TextBoundary boundary) const +std::uint32_t TextField::TextFieldAccessible::GetSubstituteCharacter() 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(); - auto textSize = text.size(); + auto self = Toolkit::TextField::DownCast(Self()); + auto hiddenInputSettings = self.GetProperty(Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS); + auto substChar = hiddenInputSettings.Find(Toolkit::HiddenInput::Property::SUBSTITUTE_CHARACTER); - 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 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(indices.first); - auto endOffset = static_cast(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; -} - -Rect<> TextField::AccessibleImpl::GetRangeExtents(size_t startOffset, size_t endOffset, Accessibility::CoordinateType type) -{ - if (endOffset <= startOffset || endOffset <= 0) - { - return {0, 0, 0, 0}; - } - - auto self = Toolkit::TextField::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 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(); - 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(); - 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(); - - 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(substChar->Get()); } - 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(); - - 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(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() != 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(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(characterOffset)); + selfImpl.RequestTextRelayout(); } } // namespace Internal