/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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-toolkit/internal/text/text-font-style.h>
#include <dali-toolkit/internal/text/text-view.h>
#include <dali-toolkit/internal/styling/style-manager-impl.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
using namespace Dali::Toolkit::Text;
if( impl.mController )
{
- // The line spacing isn't supported by the TextEditor. Since it's
- // supported by the TextEditor for now it must be ignored. The
- // property is being shadowed locally so its value isn't affected.
+ // The line spacing isn't supported by the TextEditor. Since it's supported
+ // by the TextLabel for now it must be ignored. The property is being shadowed
+ // locally so its value isn't affected.
const float lineSpacing = value.Get<float>();
impl.mLineSpacing = lineSpacing;
// set it to 0.0 due to missing implementation
return value;
}
-Text::ControllerPtr TextEditor::getController() { return mController; }
+InputMethodContext TextEditor::GetInputMethodContext()
+{
+ return mInputMethodContext;
+}
bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
{
mDecorator = Text::Decorator::New( *mController,
*mController );
+ mInputMethodContext = InputMethodContext::New();
+
mController->GetLayoutEngine().SetLayout( Layout::Engine::MULTI_LINE_BOX );
// Enables the text input.
- mController->EnableTextInput( mDecorator );
+ mController->EnableTextInput( mDecorator, mInputMethodContext );
// Enables the vertical scrolling after the text input has been enabled.
mController->SetVerticalScrollEnabled( true );
EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
GetTapGestureDetector().SetMaximumTapsRequired( 2 );
- mImfManager = ImfManager::Get();
-
self.TouchSignal().Connect( this, &TextEditor::OnTouched );
// Set BoundingBox to stage size if not already set.
self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
self.OnStageSignal().Connect( this, &TextEditor::OnStageConnect );
+ DevelControl::SetInputMethodContext( *this, mInputMethodContext );
+
// Creates an extra control to be used as stencil buffer.
mStencil = Control::New();
mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
// Enable the clipping property.
- mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+ mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
self.Add( mStencil );
mActiveLayer.SetPosition( padding.start, padding.top );
}
- const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
+ const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
!mRenderer )
{
// @note: The callback manager takes the ownership of the callback object.
mIdleCallback = MakeCallback( this, &TextEditor::OnIdleSignal );
- adaptor.AddIdle( mIdleCallback );
+ adaptor.AddIdle( mIdleCallback, false );
}
}
}
void TextEditor::OnKeyInputFocusGained()
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnKeyInputFocusGained %p\n", mController.Get() );
+ if ( mInputMethodContext )
+ {
+ mInputMethodContext.StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
- mImfManager.StatusChangedSignal().Connect( this, &TextEditor::KeyboardStatusChanged );
-
- mImfManager.EventReceivedSignal().Connect( this, &TextEditor::OnImfEvent );
-
- // Notify that the text editing start.
- mImfManager.Activate();
+ mInputMethodContext.EventReceivedSignal().Connect( this, &TextEditor::OnInputMethodContextEvent );
- // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
- mImfManager.SetRestoreAfterFocusLost( true );
+ // Notify that the text editing start.
+ mInputMethodContext.Activate();
- ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
+ // 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 ( notifier )
+ {
+ notifier.ContentSelectedSignal().Connect( this, &TextEditor::OnClipboardTextSelected );
+ }
mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
void TextEditor::OnKeyInputFocusLost()
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor:OnKeyInputFocusLost %p\n", mController.Get() );
+ if ( mInputMethodContext )
+ {
+ mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextEditor::KeyboardStatusChanged );
- mImfManager.StatusChangedSignal().Disconnect( this, &TextEditor::KeyboardStatusChanged );
-
- // The text editing is finished. Therefore the imf manager don't have restore activation.
- mImfManager.SetRestoreAfterFocusLost( false );
-
- // Notify that the text editing finish.
- mImfManager.Deactivate();
+ // The text editing is finished. Therefore the InputMethodContext don't have restore activation.
+ mInputMethodContext.SetRestoreAfterFocusLost( false );
- mImfManager.EventReceivedSignal().Disconnect( this, &TextEditor::OnImfEvent );
+ // Notify that the text editing finish.
+ mInputMethodContext.Deactivate();
+ mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextEditor::OnInputMethodContextEvent );
+ }
ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
if ( notifier )
void TextEditor::OnTap( const TapGesture& gesture )
{
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnTap %p\n", mController.Get() );
-
- mImfManager.Activate();
-
+ if ( mInputMethodContext )
+ {
+ 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<Extents>( Toolkit::Control::Property::PADDING );
void TextEditor::OnLongPress( const LongPressGesture& gesture )
{
- mImfManager.Activate();
-
+ if ( mInputMethodContext )
+ {
+ mInputMethodContext.Activate();
+ }
Extents padding;
padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
}
}
-ImfManager::ImfCallbackData TextEditor::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
+InputMethodContext::CallbackData TextEditor::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
- return mController->OnImfEvent( imfManager, imfEvent );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextEditor::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
+ return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
}
void TextEditor::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
mScrollBarEnabled( false ),
mScrollStarted( false )
{
- SetAccessibilityConstructor( []( Dali::Actor actor ) {
- return std::unique_ptr< Dali::Accessibility::Accessible >(
- new AccessibleImpl( actor, Dali::Accessibility::Role::Text ) );
- } );
}
TextEditor::~TextEditor()
}
}
-std::string TextEditor::AccessibleImpl::GetName()
-{
- auto slf = Toolkit::TextEditor::DownCast( self );
- return slf.GetProperty( Toolkit::TextEditor::Property::TEXT )
- .Get< std::string >();
-}
-
-std::string TextEditor::AccessibleImpl::GetText( size_t startOffset,
- size_t endOffset )
-{
- if( endOffset <= startOffset )
- return {};
-
- auto slf = Toolkit::TextEditor::DownCast( self );
- auto txt =
- slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >();
-
- if( txt.size() > startOffset || txt.size() > endOffset )
- return {};
-
- return txt.substr( startOffset, endOffset - startOffset );
-}
-
-size_t TextEditor::AccessibleImpl::GetCharacterCount()
-{
- auto slf = Toolkit::TextEditor::DownCast( self );
- auto txt =
- slf.GetProperty( Toolkit::TextEditor::Property::TEXT ).Get< std::string >();
-
- return txt.size();
-}
-
-Dali::Accessibility::Range TextEditor::AccessibleImpl::GetTextAtOffset(
- size_t offset, Dali::Accessibility::TextBoundary boundary )
-{
- return {};
-}
-
-Dali::Accessibility::Range
-TextEditor::AccessibleImpl::GetSelection( size_t selectionNum )
-{
- // Since DALi supports only one selection indexes higher than 0 are ignored
- if( selectionNum > 0 )
- return {};
-
- auto slf = Toolkit::TextEditor::DownCast( self );
- std::string ret;
- Dali::Toolkit::GetImpl( slf ).getController()->RetrieveSelection( ret );
-
- return Dali::Accessibility::Range( 0, ret.size(), ret );
-}
-
-bool TextEditor::AccessibleImpl::RemoveSelection( size_t selectionNum )
-{
- // Since DALi supports only one selection indexes higher than 0 are ignored
- if( selectionNum > 0 )
- return false;
-
- auto slf = Toolkit::TextEditor::DownCast( self );
- std::string ret;
- Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( 0, 0 );
- return true;
-}
-
-bool TextEditor::AccessibleImpl::SetSelection( size_t selectionNum,
- size_t startOffset,
- size_t endOffset )
-{
- // Since DALi supports only one selection indexes higher than 0 are ignored
- if( selectionNum > 0 )
- return false;
-
- auto slf = Toolkit::TextEditor::DownCast( self );
- std::string ret;
- Dali::Toolkit::GetImpl( slf ).getController()->SetSelection( startOffset,
- endOffset );
- return true;
-}
-
-bool TextEditor::AccessibleImpl::CopyText( size_t startPosition,
- size_t endPosition )
-{
- return {};
-}
-
-bool TextEditor::AccessibleImpl::CutText( size_t startPosition,
- size_t endPosition )
-{
- return {};
-}
-
} // namespace Internal
} // namespace Toolkit