/*
- * 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.
#include <dali/public-api/actors/layer.h>
#include <dali/public-api/adaptor-framework/key.h>
#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/math/math-utils.h>
#include <dali/public-api/object/type-registry-helper.h>
#include <cstring>
#include <limits>
} // namespace
-Toolkit::TextEditor TextEditor::New()
+Toolkit::TextEditor TextEditor::New(ControlBehaviour additionalBehaviour)
{
// Create the implementation, temporarily owned by this handle on stack
- IntrusivePtr<TextEditor> impl = new TextEditor();
+ IntrusivePtr<TextEditor> impl = new TextEditor(additionalBehaviour);
// Pass ownership to CustomActor handle
Toolkit::TextEditor handle(*impl);
return mController->GetTextPosition(startIndex, endIndex);
}
+Rect<float> TextEditor::GetLineBoundingRectangle(const uint32_t lineIndex) const
+{
+ return mController->GetLineBoundingRectangle(lineIndex);
+}
+
+Rect<float> TextEditor::GetCharacterBoundingRectangle(const uint32_t charIndex) const
+{
+ return mController->GetCharacterBoundingRectangle(charIndex);
+}
+
+int TextEditor::GetCharacterIndexAtPosition(float visualX, float visualY) const
+{
+ return mController->GetCharacterIndexAtPosition(visualX, visualY);
+}
+
+Rect<> TextEditor::GetTextBoundingRectangle(uint32_t startIndex, uint32_t endIndex) const
+{
+ return mController->GetTextBoundingRectangle(startIndex, endIndex);
+}
+
+void TextEditor::SetSpannedText(const Text::Spanned& spannedText)
+{
+ mController->SetSpannedText(spannedText);
+}
+
string TextEditor::GetSelectedText() const
{
string selectedText = "";
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,
}
if(mCursorLayer)
{
- mCursorLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top));
+ // 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.
+ // There is no case where the text editor does not have a stencil.
ResizeActor(mCursorLayer, contentSize);
}
if(mDecorator &&
(Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType)))
{
- mDecorator->Relayout(contentSize);
+ mDecorator->Relayout(contentSize, container);
}
if(!mRenderer)
// The text-editor 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, &TextEditor::OnIdleSignal);
- adaptor.AddIdle(mIdleCallback, false);
- }
- }
+ mController->RequestProcessInputStyleChangedSignals();
}
}
// 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)
- {
- notifier.ContentSelectedSignal().Connect(this, &TextEditor::OnClipboardTextSelected);
- }
if(IsEditable() && mController->IsUserInteractionEnabled())
{
mInputMethodContext.EventReceivedSignal().Disconnect(this, &TextEditor::OnInputMethodContextEvent);
}
- ClipboardEventNotifier notifier(ClipboardEventNotifier::Get());
-
- if(notifier)
- {
- notifier.ContentSelectedSignal().Disconnect(this, &TextEditor::OnClipboardTextSelected);
- }
mController->KeyboardFocusLostEvent();
mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
- if (keyboardFocusManager)
+ if(keyboardFocusManager)
{
keyboardFocusManager.SetCurrentFocusActor(Self());
}
if(event.GetState() == KeyEvent::UP)
{
Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
- if (keyboardFocusManager)
+ if(keyboardFocusManager)
{
keyboardFocusManager.ClearFocus();
}
void TextEditor::TextInserted(unsigned int position, unsigned int length, const std::string& content)
{
- GetAccessibleObject()->EmitTextInserted(position, length, content);
+ auto accessible = GetAccessibleObject();
+ if(DALI_LIKELY(accessible))
+ {
+ accessible->EmitTextInserted(position, length, content);
+ }
}
void TextEditor::TextDeleted(unsigned int position, unsigned int length, const std::string& content)
{
- GetAccessibleObject()->EmitTextDeleted(position, length, content);
+ auto accessible = GetAccessibleObject();
+ if(DALI_LIKELY(accessible))
+ {
+ accessible->EmitTextDeleted(position, length, content);
+ }
}
void TextEditor::CursorPositionChanged(unsigned int oldPosition, unsigned int newPosition)
{
- GetAccessibleObject()->EmitTextCursorMoved(newPosition);
+ auto accessible = GetAccessibleObject();
+ if(DALI_LIKELY(accessible))
+ {
+ accessible->EmitTextCursorMoved(newPosition);
+ }
if((oldPosition != newPosition) && !mCursorPositionChanged)
{
void TextEditor::OnScrollIndicatorAnimationFinished(Animation& animation)
{
// If animation is successfully ended, then emit ScrollStateChangedSignal
- if(animation.GetCurrentProgress() == 0.0f)
+ if(Dali::EqualsZero(animation.GetCurrentProgress()))
{
mScrollStarted = false;
Dali::Toolkit::TextEditor handle(GetOwner());
}
}
-void TextEditor::OnClipboardTextSelected(ClipboardEventNotifier& clipboard)
-{
- mController->PasteClipboardItemEvent();
-}
-
void TextEditor::KeyboardStatusChanged(bool keyboardShown)
{
DALI_LOG_INFO(gTextEditorLogFilter, Debug::Verbose, "TextEditor::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown);
return false;
}
-void TextEditor::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;
-}
-
void TextEditor::ApplyScrollPosition()
{
const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
mController->ChangedLayoutDirection();
}
-TextEditor::TextEditor()
-: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
+TextEditor::TextEditor(ControlBehaviour additionalBehaviour)
+: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
mAnimationPeriod(0.0f, 0.0f),
- mIdleCallback(NULL),
mAlignmentOffset(0.f),
mScrollAnimationDuration(0.f),
mLineSpacing(0.f),
TextEditor::~TextEditor()
{
UnparentAndReset(mStencil);
-
- if((NULL != mIdleCallback) && Adaptor::IsAvailable())
- {
- // Removes the callback from the callback manager in case the text-editor is destroyed before the callback is executed.
- Adaptor::Get().RemoveIdle(mIdleCallback);
- }
}
std::string TextEditor::TextEditorAccessible::GetName() const