X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftext-controls%2Ftext-field-impl.cpp;h=b7a6eb4b48660b9b9670af0ff4ce52d32295e46a;hb=HEAD;hp=3cbd0b90617ede57903734d123ba8ed02f347755;hpb=ca37fd65672a1f1628d0d09b8c39cb52f2acf66c;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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 3cbd0b9..8336b14 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-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. @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,7 @@ namespace Internal namespace // unnamed namespace { const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND; +const char* KEY_RETURN_NAME = "Return"; } // unnamed namespace namespace @@ -144,6 +146,9 @@ 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_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "removeFrontInset", BOOLEAN, REMOVE_FRONT_INSET ) +DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextField, "removeBackInset", BOOLEAN, REMOVE_BACK_INSET ) DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION(Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) @@ -207,10 +212,10 @@ Toolkit::TextField::InputStyle::Mask ConvertInputStyle(Text::InputStyle::Mask in } // namespace -Toolkit::TextField TextField::New() +Toolkit::TextField TextField::New(ControlBehaviour additionalBehaviour) { // Create the implementation, temporarily owned by this handle on stack - IntrusivePtr impl = new TextField(); + IntrusivePtr impl = new TextField(additionalBehaviour); // Pass ownership to CustomActor handle Toolkit::TextField handle(*impl); @@ -607,6 +612,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"); @@ -638,7 +668,12 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container) } if(mCursorLayer) { - mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top)); + if(!mStencil) + { + // If there is a stencil, 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. + mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top)); + } ResizeActor(mCursorLayer, contentSize); } @@ -658,7 +693,7 @@ void TextField::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) @@ -695,17 +730,7 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container) // The text-field 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, &TextField::OnIdleSignal); - adaptor.AddIdle(mIdleCallback, false); - } - } + mController->RequestProcessInputStyleChangedSignals(); } } @@ -738,15 +763,12 @@ void TextField::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, &TextField::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. } @@ -764,12 +786,6 @@ void TextField::OnKeyInputFocusLost() mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextField::OnInputMethodContextEvent); } - ClipboardEventNotifier notifier(ClipboardEventNotifier::Get()); - - if(notifier) - { - notifier.ContentSelectedSignal().Disconnect(this, &TextField::OnClipboardTextSelected); - } mController->KeyboardFocusLostEvent(); @@ -785,10 +801,7 @@ bool TextField::OnAccessibilityActivated() void TextField::OnTap(const TapGesture& gesture) { DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get()); - if(mInputMethodContext && IsEditable()) - { - mInputMethodContext.Activate(); - } + // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures Extents padding; padding = Self().GetProperty(Toolkit::Control::Property::PADDING); @@ -796,12 +809,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) @@ -827,12 +849,17 @@ 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(); } return true; } - else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode()) + else if(Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() && KEY_RETURN_NAME == event.GetKeyName()) { // Do nothing when enter is comming. return false; @@ -862,17 +889,29 @@ void TextField::SetEditable(bool editable) void TextField::TextInserted(unsigned int position, unsigned int length, const std::string& content) { - GetAccessibleObject()->EmitTextInserted(position, length, content); + auto accessible = GetAccessibleObject(); + if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) + { + accessible->EmitTextInserted(position, length, content); + } } void TextField::TextDeleted(unsigned int position, unsigned int length, const std::string& content) { - GetAccessibleObject()->EmitTextDeleted(position, length, content); + auto accessible = GetAccessibleObject(); + if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) + { + accessible->EmitTextDeleted(position, length, content); + } } void TextField::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition) { - GetAccessibleObject()->EmitTextCursorMoved(newPosition); + auto accessible = GetAccessibleObject(); + if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) + { + accessible->EmitTextCursorMoved(newPosition); + } if((oldPosition != newPosition) && !mCursorPositionChanged) { @@ -1060,6 +1099,7 @@ void TextField::EnableClipping() 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, @@ -1073,11 +1113,6 @@ void TextField::EnableClipping() } } -void TextField::OnClipboardTextSelected(ClipboardEventNotifier& clipboard) -{ - mController->PasteClipboardItemEvent(); -} - void TextField::KeyboardStatusChanged(bool keyboardShown) { DALI_LOG_INFO(gTextFieldLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown); @@ -1114,18 +1149,8 @@ void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type mController->ChangedLayoutDirection(); } -void TextField::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; -} - -TextField::TextField() -: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), - mIdleCallback(NULL), +TextField::TextField(ControlBehaviour additionalBehaviour) +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)), mAlignmentOffset(0.f), mRenderingBackend(DEFAULT_RENDERING_BACKEND), mExceedPolicy(Dali::Toolkit::TextField::EXCEED_POLICY_CLIP), @@ -1144,11 +1169,6 @@ TextField::TextField() TextField::~TextField() { UnparentAndReset(mStencil); - - if((NULL != mIdleCallback) && Adaptor::IsAvailable()) - { - Adaptor::Get().RemoveIdle(mIdleCallback); - } } Vector TextField::GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const @@ -1161,6 +1181,51 @@ Vector TextField::GetTextPosition(const uint32_t startIndex, const uint return mController->GetTextPosition(startIndex, endIndex); } +Rect TextField::GetLineBoundingRectangle(const uint32_t lineIndex) const +{ + return mController->GetLineBoundingRectangle(lineIndex); +} + +Rect TextField::GetCharacterBoundingRectangle(const uint32_t charIndex) const +{ + return mController->GetCharacterBoundingRectangle(charIndex); +} + +int TextField::GetCharacterIndexAtPosition(float visualX, float visualY) const +{ + return mController->GetCharacterIndexAtPosition(visualX, visualY); +} + +Rect<> TextField::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const +{ + return mController->GetTextBoundingRectangle(startIndex, endIndex); +} + +void TextField::SetSpannedText(const Text::Spanned& spannedText) +{ + mController->SetSpannedText(spannedText); +} + +void TextField::SetRemoveFrontInset(bool remove) +{ + mController->SetRemoveFrontInset(remove); +} + +bool TextField::IsRemoveFrontInset() const +{ + return mController->IsRemoveFrontInset(); +} + +void TextField::SetRemoveBackInset(bool remove) +{ + mController->SetRemoveBackInset(remove); +} + +bool TextField::IsRemoveBackInset() const +{ + return mController->IsRemoveBackInset(); +} + std::string TextField::TextFieldAccessible::GetName() const { if(IsHiddenInput())