Handles the behaviour of text components according to USER_INTERACTION_ENABLED.
Fixed the following bug :
If editable is false, all decorators should be disabled.
The prev behaviour is that some decorators are not disabled.
Change-Id: I7aeef2b2c238903723eec83e92b5945b06d0f6df
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
#include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
#include <dali-toolkit/devel-api/text/rendering-backend.h>
#include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
+
+#include <dali/devel-api/actors/actor-devel.h>
#include <dali/devel-api/adaptor-framework/clipboard.h>
#include <dali/devel-api/adaptor-framework/key-devel.h>
#include <dali/devel-api/text-abstraction/font-client.h>
application.SendNotification();
application.Render();
+ textEditor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, true);
+ DALI_TEST_EQUALS(textEditor.GetProperty(DevelActor::Property::USER_INTERACTION_ENABLED).Get<bool>(), true, TEST_LOCATION);
+
textEditor.SetKeyInputFocus();
textEditor.SetProperty(DevelTextEditor::Property::ENABLE_EDITING, false);
application.ProcessEvent(GenerateKey("D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
DALI_TEST_EQUALS(textEditor.GetProperty(TextEditor::Property::TEXT).Get<std::string>(), "D", TEST_LOCATION);
DALI_TEST_EQUALS(textEditor.GetProperty(DevelTextEditor::Property::ENABLE_EDITING).Get<bool>(), true, TEST_LOCATION);
+ // Check the user interaction enabled and for coverage
+ DevelTextEditor::SelectWholeText(textEditor);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ textEditor.SetKeyInputFocus();
+ textEditor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
+ application.ProcessEvent(GenerateKey("D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(textEditor.GetProperty(TextEditor::Property::TEXT).Get<std::string>(), "D", TEST_LOCATION);
+ DALI_TEST_EQUALS(textEditor.GetProperty(DevelActor::Property::USER_INTERACTION_ENABLED).Get<bool>(), false, TEST_LOCATION);
+
END_TEST;
}
#include <dali/integration-api/events/key-event-integ.h>
#include <dali/integration-api/events/touch-event-integ.h>
#include <dali/public-api/rendering/renderer.h>
+#include <dali/devel-api/actors/actor-devel.h>
#include <dali-toolkit-test-suite-utils.h>
#include <dali-toolkit/dali-toolkit.h>
application.SendNotification();
application.Render();
+ textField.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, true);
+ DALI_TEST_EQUALS(textField.GetProperty(DevelActor::Property::USER_INTERACTION_ENABLED).Get<bool>(), true, TEST_LOCATION);
+
textField.SetKeyInputFocus();
textField.SetProperty(DevelTextField::Property::ENABLE_EDITING, false);
application.ProcessEvent(GenerateKey("D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
DALI_TEST_EQUALS(textField.GetProperty(TextField::Property::TEXT).Get<std::string>(), "D", TEST_LOCATION);
DALI_TEST_EQUALS(textField.GetProperty(DevelTextField::Property::ENABLE_EDITING).Get<bool>(), true, TEST_LOCATION);
+ // Check the user interaction enabled and for coverage
+ DevelTextField::SelectWholeText(textField);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ textField.SetKeyInputFocus();
+ textField.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
+ application.ProcessEvent(GenerateKey("D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS(textField.GetProperty(TextField::Property::TEXT).Get<std::string>(), "D", TEST_LOCATION);
+ DALI_TEST_EQUALS(textField.GetProperty(DevelActor::Property::USER_INTERACTION_ENABLED).Get<bool>(), false, TEST_LOCATION);
+
END_TEST;
}
}
}
+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<bool>();
+ 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");
notifier.ContentSelectedSignal().Connect(this, &TextEditor::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.
}
void OnSceneConnection(int depth) override;
/**
+ * @copydoc Control::OnPropertySet()
+ */
+ void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
+
+ /**
* @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
*/
bool OnKeyEvent(const KeyEvent& event) override;
}
}
+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<bool>();
+ 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");
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.
}
void OnSceneConnection(int depth) override;
/**
+ * @copydoc Control::OnPropertySet()
+ */
+ void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
+
+ /**
* @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
*/
bool OnKeyEvent(const KeyEvent& event) override;
void Decorator::SetEditable(bool editable)
{
mImpl->mHidePrimaryCursorAndGrabHandle = !editable;
+ // If editable is false, all decorators should be disabled.
+ if(!editable)
+ {
+ if(IsHighlightActive())
+ {
+ SetHighlightActive(false);
+ }
+ if(IsHandleActive(LEFT_SELECTION_HANDLE))
+ {
+ SetHandleActive(LEFT_SELECTION_HANDLE, false);
+ }
+ if(IsHandleActive(RIGHT_SELECTION_HANDLE))
+ {
+ SetHandleActive(RIGHT_SELECTION_HANDLE, false);
+ }
+ if(IsPopupActive())
+ {
+ SetPopupActive(false);
+ }
+ }
+
mImpl->Relayout(mImpl->mControlSize);
}
/** Handles **/
bool textChanged = false;
bool relayoutNeeded = false;
+ bool isEditable = controller.IsEditable() && controller.IsUserInteractionEnabled();
if((NULL != controller.mImpl->mEventData) &&
(keyEvent.GetState() == KeyEvent::DOWN))
(Dali::DALI_KEY_CURSOR_DOWN == keyCode))
{
// If don't have any text, do nothing.
- if(!controller.mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters)
+ if(!controller.mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters || !isEditable)
{
return false;
}
// Do nothing
return false;
}
- else if(keyEvent.IsCtrlModifier() && !keyEvent.IsShiftModifier())
+ else if(keyEvent.IsCtrlModifier() && !keyEvent.IsShiftModifier() && isEditable)
{
bool consumed = false;
if(keyName == KEY_C_NAME || keyName == KEY_INSERT_NAME || logicalKey == KEY_C_NAME || logicalKey == KEY_INSERT_NAME)
else
{
DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::KeyEvent %p keyString %s\n", &controller, keyString.c_str());
- if(!controller.IsEditable()) return false;
+ if(!isEditable) return false;
std::string refinedKey = keyString;
if(controller.mImpl->mInputFilter != NULL && !refinedKey.empty())
if(mEventData->mDecorator)
{
- mEventData->mDecorator->SetEditable(editable);
+ bool decoratorEditable = editable && mIsUserInteractionEnabled;
+ mEventData->mDecorator->SetEditable(decoratorEditable);
}
}
}
}
}
+void Controller::Impl::SetUserInteractionEnabled(bool enabled)
+{
+ mIsUserInteractionEnabled = enabled;
+
+ if(mEventData && mEventData->mDecorator)
+ {
+ bool editable = mEventData->mEditingEnabled && enabled;
+ mEventData->mDecorator->SetEditable(editable);
+ }
+}
+
void Controller::Impl::ClearFontData()
{
if(mFontDefaults)
const float DEFAULT_TEXTFIT_MAX = 100.f;
const float DEFAULT_TEXTFIT_STEP = 1.f;
const float DEFAULT_FONT_SIZE_SCALE = 1.f;
+const float DEFAULT_DISABLED_COLOR_OPACITY = 0.3f;
//Forward declarations
struct CursorInfo;
mTextFitMaxSize(DEFAULT_TEXTFIT_MAX),
mTextFitStepSize(DEFAULT_TEXTFIT_STEP),
mFontSizeScale(DEFAULT_FONT_SIZE_SCALE),
+ mDisabledColorOpacity(DEFAULT_DISABLED_COLOR_OPACITY),
mFontSizeScaleEnabled(true),
mTextFitEnabled(false),
mTextFitChanged(false),
- mIsLayoutDirectionChanged(false)
+ mIsLayoutDirectionChanged(false),
+ mIsUserInteractionEnabled(true)
{
mModel = Model::New();
void SetDefaultColor(const Vector4& color);
/**
+ * @copydoc Controller::SetUserInteractionEnabled()
+ */
+ void SetUserInteractionEnabled(bool enabled);
+
+ /**
* @brief Helper to clear font-specific data (only).
*/
void ClearFontData();
float mTextFitMaxSize; ///< Maximum Font Size for text fit. Default 100
float mTextFitStepSize; ///< Step Size for font intervalse. Default 1
float mFontSizeScale; ///< Scale value for Font Size. Default 1.0
+ float mDisabledColorOpacity; ///< Color opacity when disabled.
bool mFontSizeScaleEnabled : 1; ///< Whether the font size scale is enabled.
bool mTextFitEnabled : 1; ///< Whether the text's fit is enabled.
bool mTextFitChanged : 1; ///< Whether the text fit property has changed.
bool mIsLayoutDirectionChanged : 1; ///< Whether the layout has changed.
+ bool mIsUserInteractionEnabled : 1; ///< Whether the user interaction is enabled.
private:
friend ControllerImplEventHandler;
return mImpl->mTextColor;
}
+void Controller::SetDisabledColorOpacity(float opacity)
+{
+ mImpl->mDisabledColorOpacity = opacity;
+}
+
+float Controller::GetDisabledColorOpacity() const
+{
+ return mImpl->mDisabledColorOpacity;
+}
+
+void Controller::SetUserInteractionEnabled(bool enabled)
+{
+ mImpl->SetUserInteractionEnabled(enabled);
+}
+
+bool Controller::IsUserInteractionEnabled() const
+{
+ return mImpl->mIsUserInteractionEnabled;
+}
+
void Controller::SetPlaceholderTextColor(const Vector4& textColor)
{
PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
bool IsTextFitChanged() const;
/**
+ * @brief Sets disabled color opacity.
+ *
+ * @param[in] opacity The color opacity value in disabled state.
+ */
+ void SetDisabledColorOpacity(float opacity);
+
+ /**
+ * @brief Retrieves the disabled color opacity.
+ *
+ * @return The disabled color opacity value for disabled state.
+ */
+ float GetDisabledColorOpacity() const;
+
+ /**
* @brief Enable or disable the placeholder text elide.
* @param enabled Whether to enable the placeholder text elide.
*/
const Vector4& GetDefaultColor() const;
/**
+ * @brief Sets the user interaction enabled.
+ *
+ * @param enabled whether to enable the user interaction.
+ */
+ void SetUserInteractionEnabled(bool enabled);
+
+ /**
+ * @brief Whether the user interaction is enabled.
+ *
+ * @return true if the user interaction is enabled, false otherwise.
+ */
+ bool IsUserInteractionEnabled() const;
+
+ /**
* @brief Set the text color
*
* @param textColor The text color