From: Paul Wisbey Date: Wed, 3 Aug 2016 16:00:27 +0000 (-0700) Subject: Merge "Geometry Batching" into devel/master X-Git-Tag: dali_1.2.0~4 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=901499a7ec86ca342c4e0fdec62a6e4eeeee5c5f;hp=f29b744f4c9d27aeb355319712313876bb236bca Merge "Geometry Batching" into devel/master --- diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp index 1a3490b..fcf6825 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp @@ -18,6 +18,7 @@ #include "dummy-control.h" #include +#include namespace Dali { @@ -74,6 +75,16 @@ DummyControlImpl::~DummyControlImpl() { } +void DummyControlImpl::RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual ) +{ + Control::RegisterVisual( index, placementActor, visual ); +} + +void DummyControlImpl::UnregisterVisual( Property::Index index ) +{ + Control::UnregisterVisual( index ); +} + DummyControl DummyControlImplOverride::New() { IntrusivePtr< DummyControlImplOverride > impl = new DummyControlImplOverride; diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h index 496786e..897fc17 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dummy-control.h @@ -28,7 +28,7 @@ namespace Toolkit { class DummyControlImpl; - +class ControlRenderer; /** * Control does not have a New method so use this dummy class for the handle. */ @@ -71,6 +71,9 @@ public: inline TapGestureDetector GetTapGestureDetector() const { return Internal::Control::GetTapGestureDetector(); } inline LongPressGestureDetector GetLongPressGestureDetector() const { return Internal::Control::GetLongPressGestureDetector(); } + void RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual); + void UnregisterVisual( Property::Index index ); + // Used to test signal connections void CustomSlot1( Actor actor ); diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp index d42a548..6e9b9f0 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp @@ -70,6 +70,7 @@ void TestGlAbstraction::Initialize() mLastShaderIdUsed = 0; mLastProgramIdUsed = 0; mLastUniformIdUsed = 0; + mLastDepthMask = false; mUniforms.clear(); mProgramUniforms1i.clear(); @@ -79,8 +80,10 @@ void TestGlAbstraction::Initialize() mProgramUniforms4f.clear(); mCullFaceTrace.Reset(); + mDepthFunctionTrace.Reset(); mEnableDisableTrace.Reset(); mShaderTrace.Reset(); + mStencilFunctionTrace.Reset(); mTextureTrace.Reset(); mTexParamaterTrace.Reset(); mDrawTrace.Reset(); diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h index 1f55977..10c3264 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h @@ -1,8 +1,8 @@ -#ifndef __TEST_GL_ABSTRACTION_H__ -#define __TEST_GL_ABSTRACTION_H__ +#ifndef TEST_GL_ABSTRACTION_H +#define TEST_GL_ABSTRACTION_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -468,6 +468,12 @@ public: inline void DepthMask(GLboolean flag) { + mLastDepthMask = flag; + } + + inline bool GetLastDepthMask() const + { + return mLastDepthMask; } inline void DepthRangef(GLclampf zNear, GLclampf zFar) @@ -2059,6 +2065,8 @@ private: GLenum mLastBlendFuncSrcAlpha; GLenum mLastBlendFuncDstAlpha; + GLboolean mLastDepthMask; + // Data for manipulating the IDs returned by GenTextures GLuint mLastAutoTextureIdUsed; std::vector mNextTextureIds; @@ -2258,6 +2266,4 @@ bool BlendEnabled(const Dali::TraceCallStack& callStack); bool BlendDisabled(const Dali::TraceCallStack& callStack); - - -#endif // __TEST_GL_ES_H__ +#endif // TEST_GL_ABSTRACTION_H diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp index 5aff146..ead898d 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp @@ -972,3 +972,38 @@ int UtcDaliButtonSetUnSelectedColorP(void) END_TEST; } +int UtcDaliButtonResetSelectedColorP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonSetSelectedColorP"); + + PushButton pushButton = PushButton::New(); + Stage::GetCurrent().Add( pushButton ); + + application.SendNotification(); + application.Render(); + + const Vector4 FIRST_COLOR = Color::BLUE; + const Vector4 SECOND_COLOR = Color::BLUE; + + pushButton.SetSize( Vector2( 20.0f, 20.0f ) ); + pushButton.SetProperty( Button::Property::SELECTED_COLOR, FIRST_COLOR ); + + application.SendNotification(); + application.Render(); + + Vector4 color = pushButton.GetProperty( Button::Property::SELECTED_COLOR ); + + DALI_TEST_EQUALS( color, FIRST_COLOR, TEST_LOCATION ); + + pushButton.SetProperty( Button::Property::SELECTED_COLOR, SECOND_COLOR ); + + application.SendNotification(); + application.Render(); + + color = pushButton.GetProperty( Button::Property::SELECTED_COLOR ); + + DALI_TEST_EQUALS( color, SECOND_COLOR, TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp index 12ce913..07c6fe4 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ControlImpl.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -944,3 +945,174 @@ int UtcDaliControlImplGetNextKeyboardFocusableActorP(void) END_TEST; } + +int UtcDaliControlImplRegisterThenReRegisterVisual(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; + + Property::Map map; + map[Visual::Property::TYPE] = Visual::COLOR; + map[ColorVisual::Property::MIX_COLOR] = Color::RED; + + visual = visualFactory.CreateVisual( map ); + DALI_TEST_CHECK(visual); + + // Register index with a color visual + dummyImpl.RegisterVisual( index, placementActor, visual ); + + + Property::Map newMap; + newMap[Visual::Property::TYPE] = Visual::COLOR; + newMap[ColorVisual::Property::MIX_COLOR] = Color::BLUE; + + visual = visualFactory.CreateVisual( newMap ); + DALI_TEST_CHECK(visual); + + // ReRegister with altered color visual + dummyImpl.RegisterVisual( index, placementActor, visual ); + + tet_result(TET_PASS); + + END_TEST; +} + +int UtcDaliControlImplRegisterVisaulThenReRegisterToSelf(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; + + Property::Map map; + map[Visual::Property::TYPE] = Visual::COLOR; + map[ColorVisual::Property::MIX_COLOR] = Color::RED; + + visual = visualFactory.CreateVisual( map ); + DALI_TEST_CHECK(visual); + + // Register index with a color visual + dummyImpl.RegisterVisual( index, placementActor, visual ); + + // ReRegister to self + dummyImpl.RegisterVisual( index, dummy, visual ); + + tet_result(TET_PASS); + + END_TEST; +} + +int UtcDaliControlImplRegisterVisualToSelf(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; + + Property::Map map; + map[Visual::Property::TYPE] = Visual::COLOR; + map[ColorVisual::Property::MIX_COLOR] = Color::RED; + + visual = visualFactory.CreateVisual( map ); + DALI_TEST_CHECK(visual); + + // ReRegister to self + dummyImpl.RegisterVisual( index, dummy, visual ); + + tet_result(TET_PASS); + + END_TEST; +} + + +int UtcDaliControlImplRegisterTwoVisuals(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + Property::Index index2 =2; + Actor secondPlacementActor = Actor::New(); + + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; + Toolkit::Visual::Base secondVisual; + + Property::Map map; + map[Visual::Property::TYPE] = Visual::COLOR; + map[ColorVisual::Property::MIX_COLOR] = Color::RED; + + visual = visualFactory.CreateVisual( map ); + DALI_TEST_CHECK(visual); + + // Register index with a color visual + dummyImpl.RegisterVisual( index, placementActor, visual ); + + Property::Map newMap; + newMap[Visual::Property::TYPE] = Visual::COLOR; + newMap[ColorVisual::Property::MIX_COLOR] = Color::BLUE; + + secondVisual = visualFactory.CreateVisual( newMap ); + + // ReRegister with altered color visual + dummyImpl.RegisterVisual( index2, secondPlacementActor, secondVisual ); + + tet_result(TET_PASS); + + END_TEST; +} + +int UtcDaliControlImplRegisterUnregisterVisual(void) +{ + ToolkitTestApplication application; + + DummyControl dummy = DummyControl::New(); + DummyControlImpl& dummyImpl = static_cast(dummy.GetImplementation()); + + Property::Index index =1; + Actor placementActor = Actor::New(); + + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; + + Property::Map map; + map[Visual::Property::TYPE] = Visual::COLOR; + map[ColorVisual::Property::MIX_COLOR] = Color::RED; + + visual = visualFactory.CreateVisual( map ); + DALI_TEST_CHECK(visual); + + // Register index with a color visual + dummyImpl.RegisterVisual( index, placementActor, visual ); + + // Unregister visual + dummyImpl.UnregisterVisual( index ); + + tet_result(TET_PASS); + + END_TEST; +} diff --git a/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp b/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp index b6c4e3b..6562a45 100644 --- a/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp +++ b/dali-toolkit/internal/accessibility-manager/accessibility-manager-impl.cpp @@ -1313,7 +1313,7 @@ bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent& if(!mCurrentGesturedActor) { - DALI_LOG_ERROR("Gesture detected, but no hit actor"); + DALI_LOG_ERROR("Gesture detected, but no hit actor\n"); } } @@ -1362,7 +1362,7 @@ bool AccessibilityManager::HandlePanGesture(const Integration::PanGestureEvent& if(!mCurrentGesturedActor) { - DALI_LOG_ERROR("no more gestured actor"); + DALI_LOG_ERROR("no more gestured actor\n"); } } else diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index 5fc7a89..53ccf41 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -539,6 +539,7 @@ void Button::SetColor( const Vector4& color, Button::PaintState selectedState ) { Actor* contentActor = NULL; // Using a pointer as SetupContent assigns the new Actor to this. bool imageFileExists = false; + Property::Index visualIndex = Toolkit::Button::Property::SELECTED_STATE_IMAGE; if ( selectedState == SelectedState || selectedState == DisabledSelectedState ) { @@ -551,6 +552,7 @@ void Button::SetColor( const Vector4& color, Button::PaintState selectedState ) mUnselectedColor = color; contentActor = &mUnselectedContent; imageFileExists = !GetUnselectedImageFilename().empty(); + visualIndex = Toolkit::Button::Property::UNSELECTED_STATE_IMAGE; } if ( contentActor ) @@ -564,15 +566,17 @@ void Button::SetColor( const Vector4& color, Button::PaintState selectedState ) { // If there is no existing content, create a new actor to use for flat color. Actor placementActor = Actor::New(); - Toolkit::VisualFactory rendererFactory = Toolkit::VisualFactory::Get(); - Toolkit::Visual::Base colorRenderer; + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base visual; Property::Map map; map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR; map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; - colorRenderer = rendererFactory.CreateVisual( map ); - colorRenderer.SetOnStage( placementActor ); + visual = visualFactory.CreateVisual( map ); + + RegisterVisual( visualIndex, placementActor, visual ); + visual.SetOnStage( placementActor ); SetupContent( *contentActor, placementActor ); // contentActor->SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index 281e43d..da49940 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -84,6 +84,7 @@ namespace { const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f ); const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f ); +const Dali::Vector3 ACTIVE_LAYER_ANCHOR_POINT( 0.5f, 0.5f, 0.5f ); const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color. TODO: due some problems, maybe with the blending function in the text clipping, the color is fully opaque. @@ -101,36 +102,9 @@ const float SCROLL_DISTANCE = SCROLL_SPEED * SCROLL_TICK_INTERVAL * TO_SECONDS; const float CURSOR_WIDTH = 1.f; ///< The cursor's width in pixels. -/** - * structure to hold coordinates of each quad, which will make up the mesh. - */ -struct QuadCoordinates -{ - /** - * Default constructor - */ - QuadCoordinates() - { - } - - /** - * Constructor - * @param[in] x1 left co-ordinate - * @param[in] y1 top co-ordinate - * @param[in] x2 right co-ordinate - * @param[in] y2 bottom co-ordinate - */ - QuadCoordinates(float x1, float y1, float x2, float y2) - : min(x1, y1), - max(x2, y2) - { - } +const float POPUP_PADDING = 2.f; ///< Padding space between the highlight box and the text's popup. - Dali::Vector2 min; ///< top-left (minimum) position of quad - Dali::Vector2 max; ///< bottom-right (maximum) position of quad -}; - -typedef std::vector QuadContainer; +typedef Dali::Vector QuadContainer; /** * @brief Takes a bounding rectangle in the local coordinates of an actor and returns the world coordinates Bounding Box. @@ -210,11 +184,13 @@ struct Decorator::Impl : public ConnectionTracker grabDisplacementX( 0.f ), grabDisplacementY( 0.f ), active( false ), - visible( false ), + horizontallyVisible( false ), + verticallyVisible( false ), pressed( false ), verticallyFlippedPreferred( false ), horizontallyFlipped( false ), - verticallyFlipped( false ) + verticallyFlipped( false ), + verticallyFlippedOnTouch( false ) { } @@ -228,12 +204,14 @@ struct Decorator::Impl : public ConnectionTracker float lineHeight; ///< Not the handle height float grabDisplacementX; float grabDisplacementY; - bool active : 1; - bool visible : 1; - bool pressed : 1; + bool active : 1; + bool horizontallyVisible : 1; + bool verticallyVisible : 1; + bool pressed : 1; bool verticallyFlippedPreferred : 1; ///< Whether the handle is preferred to be vertically flipped. bool horizontallyFlipped : 1; ///< Whether the handle has been horizontally flipped. bool verticallyFlipped : 1; ///< Whether the handle has been vertically flipped. + bool verticallyFlippedOnTouch : 1; ///< Whether the handle is vertically flipped on touch. }; struct PopupImpl @@ -261,6 +239,7 @@ struct Decorator::Impl : public ConnectionTracker mCursorBlinkDuration( 0.0f ), mCursorWidth( CURSOR_WIDTH ), mHandleScrolling( HANDLE_TYPE_COUNT ), + mHandleReleased( HANDLE_TYPE_COUNT ), mScrollDirection( SCROLL_NONE ), mScrollThreshold( SCROLL_THRESHOLD ), mScrollSpeed( SCROLL_SPEED ), @@ -280,7 +259,9 @@ struct Decorator::Impl : public ConnectionTracker mIsHandlePreviouslyCrossed( false ), mNotifyEndOfScroll( false ), mHorizontalScrollingEnabled( false ), - mVerticalScrollingEnabled( false ) + mVerticalScrollingEnabled( false ), + mSmoothHandlePanEnabled( false ), + mIsHighlightBoxActive( false ) { mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2; mHighlightShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); @@ -304,10 +285,10 @@ struct Decorator::Impl : public ConnectionTracker if( mPrimaryCursor ) { const CursorImpl& cursor = mCursor[PRIMARY_CURSOR]; - mPrimaryCursorVisible = ( ( cursor.position.x + mCursorWidth <= mControlSize.width ) && - ( cursor.position.x >= 0.f ) && - ( cursor.position.y + cursor.cursorHeight <= mControlSize.height ) && - ( cursor.position.y >= 0.f ) ); + mPrimaryCursorVisible = ( ( mControlSize.width - ( cursor.position.x + mCursorWidth ) > -Math::MACHINE_EPSILON_1000 ) && + ( cursor.position.x > -Math::MACHINE_EPSILON_1000 ) && + ( mControlSize.height - ( cursor.position.y + cursor.cursorHeight ) > -Math::MACHINE_EPSILON_1000 ) && + ( cursor.position.y > -Math::MACHINE_EPSILON_1000 ) ); if( mPrimaryCursorVisible ) { mPrimaryCursor.SetPosition( cursor.position.x, @@ -319,10 +300,10 @@ struct Decorator::Impl : public ConnectionTracker if( mSecondaryCursor ) { const CursorImpl& cursor = mCursor[SECONDARY_CURSOR]; - mSecondaryCursorVisible = ( ( cursor.position.x + mCursorWidth <= mControlSize.width ) && - ( cursor.position.x >= 0.f ) && - ( cursor.position.y + cursor.cursorHeight <= mControlSize.height ) && - ( cursor.position.y >= 0.f ) ); + mSecondaryCursorVisible = ( ( mControlSize.width - ( cursor.position.x + mCursorWidth ) > -Math::MACHINE_EPSILON_1000 ) && + ( cursor.position.x > -Math::MACHINE_EPSILON_1000 ) && + ( mControlSize.height - ( cursor.position.y + cursor.cursorHeight ) > -Math::MACHINE_EPSILON_1000 ) && + ( cursor.position.y > -Math::MACHINE_EPSILON_1000 ) ); if( mSecondaryCursorVisible ) { mSecondaryCursor.SetPosition( cursor.position.x, @@ -335,13 +316,16 @@ struct Decorator::Impl : public ConnectionTracker // Show or hide the grab handle HandleImpl& grabHandle = mHandle[GRAB_HANDLE]; bool newGrabHandlePosition = false; + grabHandle.horizontallyVisible = false; + grabHandle.verticallyVisible = false; if( grabHandle.active ) { - const bool isVisible = ( ( grabHandle.position.x + floor( 0.5f * mCursorWidth ) <= mControlSize.width ) && - ( grabHandle.position.x >= 0.f ) && - ( grabHandle.position.y <= mControlSize.height - grabHandle.lineHeight ) && - ( grabHandle.position.y >= 0.f ) ); + grabHandle.horizontallyVisible = ( ( mControlSize.width - ( grabHandle.position.x + floor( 0.5f * mCursorWidth ) ) > -Math::MACHINE_EPSILON_1000 ) && + ( grabHandle.position.x > -Math::MACHINE_EPSILON_1000 ) ); + grabHandle.verticallyVisible = ( ( ( mControlSize.height - grabHandle.lineHeight ) - grabHandle.position.y > -Math::MACHINE_EPSILON_1000 ) && + ( grabHandle.position.y > -Math::MACHINE_EPSILON_1000 ) ); + const bool isVisible = grabHandle.horizontallyVisible && grabHandle.verticallyVisible; if( isVisible ) { CreateGrabHandle(); @@ -370,22 +354,26 @@ struct Decorator::Impl : public ConnectionTracker HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ]; bool newPrimaryHandlePosition = false; bool newSecondaryHandlePosition = false; + + primary.horizontallyVisible = ( ( mControlSize.width - primary.position.x > -Math::MACHINE_EPSILON_1000 ) && + ( primary.position.x > -Math::MACHINE_EPSILON_1000 ) ); + primary.verticallyVisible = ( ( ( mControlSize.height - primary.lineHeight ) - primary.position.y > -Math::MACHINE_EPSILON_1000 ) && + ( primary.position.y + ( primary.verticallyFlipped ? 0.f : primary.lineHeight ) > -Math::MACHINE_EPSILON_1000 ) ); + secondary.horizontallyVisible = ( ( mControlSize.width - secondary.position.x > -Math::MACHINE_EPSILON_1000 ) && + ( secondary.position.x > -Math::MACHINE_EPSILON_1000 ) ); + secondary.verticallyVisible = ( ( ( mControlSize.height - secondary.lineHeight ) - secondary.position.y > -Math::MACHINE_EPSILON_1000 ) && + ( secondary.position.y + ( secondary.verticallyFlipped ? 0.f : secondary.lineHeight ) > -Math::MACHINE_EPSILON_1000 ) ); + + const bool primaryVisible = primary.horizontallyVisible && primary.verticallyVisible; + const bool secondaryVisible = secondary.horizontallyVisible && secondary.verticallyVisible; + if( primary.active || secondary.active ) { - const bool isPrimaryVisible = ( ( primary.position.x <= mControlSize.width ) && - ( primary.position.x >= 0.f ) && - ( primary.position.y <= mControlSize.height - primary.lineHeight ) && - ( primary.position.y >= 0.f ) ); - const bool isSecondaryVisible = ( ( secondary.position.x <= mControlSize.width ) && - ( secondary.position.x >= 0.f ) && - ( secondary.position.y <= mControlSize.height - secondary.lineHeight ) && - ( secondary.position.y >= 0.f ) ); - - if( isPrimaryVisible || isSecondaryVisible ) + if( primaryVisible || secondaryVisible ) { CreateSelectionHandles(); - if( isPrimaryVisible ) + if( primaryVisible ) { SetSelectionHandlePosition( LEFT_SELECTION_HANDLE ); @@ -397,7 +385,7 @@ struct Decorator::Impl : public ConnectionTracker newPrimaryHandlePosition = true; } - if( isSecondaryVisible ) + if( secondaryVisible ) { SetSelectionHandlePosition( RIGHT_SELECTION_HANDLE ); @@ -412,15 +400,13 @@ struct Decorator::Impl : public ConnectionTracker if( primary.actor ) { - primary.actor.SetVisible( isPrimaryVisible ); + primary.actor.SetVisible( primaryVisible ); } if( secondary.actor ) { - secondary.actor.SetVisible( isSecondaryVisible ); + secondary.actor.SetVisible( secondaryVisible ); } - CreateHighlight(); - UpdateHighlight(); } else { @@ -432,6 +418,15 @@ struct Decorator::Impl : public ConnectionTracker { secondary.actor.Unparent(); } + } + + if( mIsHighlightBoxActive ) + { + CreateHighlight(); + UpdateHighlight(); + } + else + { if( mHighlightActor ) { mHighlightActor.Unparent(); @@ -446,7 +441,8 @@ struct Decorator::Impl : public ConnectionTracker SetupActiveLayerPropertyNotifications(); } - if( mActiveCopyPastePopup ) + if( mActiveCopyPastePopup && + ( primaryVisible || secondaryVisible ) ) { ShowPopup(); mPopupSetNewPosition = true; @@ -473,7 +469,7 @@ struct Decorator::Impl : public ConnectionTracker void ShowPopup() { - if ( !mCopyPastePopup.actor ) + if( !mCopyPastePopup.actor ) { return; } @@ -487,7 +483,124 @@ struct Decorator::Impl : public ConnectionTracker mCopyPastePopup.actor.ShowPopup(); } - void DeterminePositionPopup() + float CalculateVerticalPopUpPosition( float halfHeight, bool preferBelow ) + { + float yPosition = 0.f; + + const HandleImpl& primaryHandle = mHandle[LEFT_SELECTION_HANDLE]; + const HandleImpl& secondaryHandle = mHandle[RIGHT_SELECTION_HANDLE]; + const HandleImpl& grabHandle = mHandle[GRAB_HANDLE]; + + if( primaryHandle.active || secondaryHandle.active ) + { + // The origin of the decorator's coordinate system in world coords. + const Vector3 originWorldCoords = mActiveLayer.GetCurrentWorldPosition() - mActiveLayer.GetCurrentSize() * ACTIVE_LAYER_ANCHOR_POINT; + + if( preferBelow ) + { + // Find out if there is enough space for the popup at the bottom. + const float primaryBelowY = primaryHandle.position.y + primaryHandle.lineHeight + primaryHandle.size.height; + const float secondaryBelowY = secondaryHandle.position.y + secondaryHandle.lineHeight + secondaryHandle.size.height; + + float maxY = std::max( primaryBelowY, secondaryBelowY ); + + yPosition = halfHeight + maxY; + + if( originWorldCoords.y + yPosition + halfHeight > mBoundingBox.w ) + { + // Does not fit below. + + // Try to fit first below the non active handle. Otherwise above the active handle. + if( RIGHT_SELECTION_HANDLE == mHandleReleased ) + { + if( primaryBelowY < secondaryBelowY ) + { + yPosition = halfHeight + primaryBelowY; + } + else + { + yPosition = primaryHandle.position.y - primaryHandle.size.height - halfHeight; + } + } + else if( LEFT_SELECTION_HANDLE == mHandleReleased ) + { + if( secondaryBelowY < primaryBelowY ) + { + yPosition = halfHeight + secondaryBelowY; + } + else + { + yPosition = secondaryHandle.position.y - secondaryHandle.size.height - halfHeight; + } + } + + // Check the handle is whithin the decoration box. + if( originWorldCoords.y + yPosition < mBoundingBox.y ) + { + yPosition = mBoundingBox.y - originWorldCoords.y + halfHeight; + } + + if( originWorldCoords.y + yPosition > mBoundingBox.w ) + { + yPosition = mBoundingBox.w - originWorldCoords.y - halfHeight; + } + } + } // preferBelow + else + { + // Find out if there is enough space for the popup at the top. + const float primaryTopY = primaryHandle.position.y - primaryHandle.size.height; + const float secondaryTopY = secondaryHandle.position.y - secondaryHandle.size.height; + + float minY = std::min( primaryTopY, secondaryTopY ); + + yPosition = -halfHeight + minY; + } // !preferBelow + } // ( primaryHandle.active || secondaryHandle.active ) + else if( grabHandle.active ) + { + if( preferBelow ) + { + yPosition = halfHeight + grabHandle.lineHeight + grabHandle.size.height + grabHandle.position.y; + } + else + { + yPosition = -halfHeight + grabHandle.position.y - POPUP_PADDING; + } + } + + return yPosition; + } + + void ConstrainPopupPosition( const Vector3& popupHalfSize ) + { + // Check if the popup is within the boundaries of the decoration box. + + // Check first the horizontal dimension. If is not within the boundaries, it calculates the offset. + + // The origin of the decorator's coordinate system in world coords. + const Vector3 originWorldCoords = mActiveLayer.GetCurrentWorldPosition() - mActiveLayer.GetCurrentSize() * ACTIVE_LAYER_ANCHOR_POINT; + + // The popup's position in world coords. + Vector3 popupPositionWorldCoords = originWorldCoords + mCopyPastePopup.position; + + if( popupPositionWorldCoords.x - popupHalfSize.width < mBoundingBox.x ) + { + mCopyPastePopup.position.x += mBoundingBox.x - ( popupPositionWorldCoords.x - popupHalfSize.width ); + } + else if( popupPositionWorldCoords.x + popupHalfSize.width > mBoundingBox.z ) + { + mCopyPastePopup.position.x += mBoundingBox.z - ( popupPositionWorldCoords.x + popupHalfSize.width ); + } + + // Check the vertical dimension. If the popup doesn't fit above the handles, it looks for a valid position below. + if( popupPositionWorldCoords.y - popupHalfSize.height < mBoundingBox.y ) + { + mCopyPastePopup.position.y = CalculateVerticalPopUpPosition( popupHalfSize.height, true ); // true -> prefer to set the popup's position below. + } + } + + void SetPopupPosition( Actor actor ) { if( !mActiveCopyPastePopup ) { @@ -495,55 +608,48 @@ struct Decorator::Impl : public ConnectionTracker } // Retrieves the popup's size after relayout. - const Vector3 popupSize = Vector3( mCopyPastePopup.actor.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ), 0.0f ); + const Vector3 popupSize( mCopyPastePopup.actor.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ), 0.0f ); + const Vector3 popupHalfSize = popupSize * 0.5f; if( mPopupSetNewPosition ) { const HandleImpl& primaryHandle = mHandle[LEFT_SELECTION_HANDLE]; const HandleImpl& secondaryHandle = mHandle[RIGHT_SELECTION_HANDLE]; - const CursorImpl& cursor = mCursor[PRIMARY_CURSOR]; + const HandleImpl& grabHandle = mHandle[GRAB_HANDLE]; if( primaryHandle.active || secondaryHandle.active ) { - // Calculates the popup's position if selection handles are active. const float minHandleXPosition = std::min( primaryHandle.position.x, secondaryHandle.position.x ); const float maxHandleXPosition = std::max( primaryHandle.position.x, secondaryHandle.position.x ); - const float maxHandleHeight = std::max( primaryHandle.size.height, secondaryHandle.size.height ); mCopyPastePopup.position.x = minHandleXPosition + ( ( maxHandleXPosition - minHandleXPosition ) * 0.5f ); - mCopyPastePopup.position.y = -0.5f * popupSize.height - maxHandleHeight + std::min( primaryHandle.position.y, secondaryHandle.position.y ); + + const float primaryY = -popupHalfSize.height + primaryHandle.position.y - ( primaryHandle.verticallyFlipped ? primaryHandle.size.height : POPUP_PADDING ); + const float secondaryY = -popupHalfSize.height + secondaryHandle.position.y - ( secondaryHandle.verticallyFlipped ? secondaryHandle.size.height : POPUP_PADDING ); + + mCopyPastePopup.position.y = std::min( primaryY, secondaryY ); } - else + else if( grabHandle.active ) { - // Calculates the popup's position if the grab handle is active. - const HandleImpl& grabHandle = mHandle[GRAB_HANDLE]; - if( grabHandle.verticallyFlipped ) - { - mCopyPastePopup.position = Vector3( cursor.position.x, -0.5f * popupSize.height - grabHandle.size.height + cursor.position.y, 0.0f ); - } - else - { - mCopyPastePopup.position = Vector3( cursor.position.x, -0.5f * popupSize.height + cursor.position.y, 0.0f ); - } + mCopyPastePopup.position.x = grabHandle.position.x; + + mCopyPastePopup.position.y = -popupHalfSize.height + grabHandle.position.y - ( grabHandle.verticallyFlipped ? grabHandle.size.height : POPUP_PADDING ); } - } + } // mPopupSetNewPosition + + // It may change the popup's position to fit within the decoration box. + ConstrainPopupPosition( popupHalfSize ); - // Checks if there is enough space above the text control. If not it places the popup under it. - GetConstrainedPopupPosition( mCopyPastePopup.position, popupSize * AnchorPoint::CENTER, mActiveLayer, mBoundingBox ); + SetUpPopupPositionNotifications( popupHalfSize ); - SetUpPopupPositionNotifications(); + // Prevent pixel mis-alignment by rounding down. + mCopyPastePopup.position.x = floorf( mCopyPastePopup.position.x ); + mCopyPastePopup.position.y = floorf( mCopyPastePopup.position.y ); mCopyPastePopup.actor.SetPosition( mCopyPastePopup.position ); mPopupSetNewPosition = false; } - void PopupRelayoutComplete( Actor actor ) - { - // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box. - - DeterminePositionPopup(); - } - void CreateCursor( Control& cursor, const Vector4& color ) { cursor = Control::New(); @@ -1058,7 +1164,7 @@ struct Decorator::Impl : public ConnectionTracker mHighlightActor.SetPosition( mHighlightPosition.x, mHighlightPosition.y ); - const unsigned int numberOfQuads = mHighlightQuadList.size(); + const unsigned int numberOfQuads = mHighlightQuadList.Count(); if( 0u != numberOfQuads ) { // Set the size of the highlighted text to the actor. @@ -1078,33 +1184,33 @@ struct Decorator::Impl : public ConnectionTracker unsigned int v = 0u; // Traverse all quads. - for( std::vector::iterator it = mHighlightQuadList.begin(), - endIt = mHighlightQuadList.end(); + for( Vector::ConstIterator it = mHighlightQuadList.Begin(), + endIt = mHighlightQuadList.End(); it != endIt; ++it, v += 4u ) { - QuadCoordinates& quad = *it; + const Vector4& quad = *it; Vector2 vertex; // top-left (v+0) - vertex.x = quad.min.x - offsetX; - vertex.y = quad.min.y - offsetY; + vertex.x = quad.x - offsetX; + vertex.y = quad.y - offsetY; vertices.PushBack( vertex ); // top-right (v+1) - vertex.x = quad.max.x - offsetX; - vertex.y = quad.min.y - offsetY; + vertex.x = quad.z - offsetX; + vertex.y = quad.y - offsetY; vertices.PushBack( vertex ); // bottom-left (v+2) - vertex.x = quad.min.x - offsetX; - vertex.y = quad.max.y - offsetY; + vertex.x = quad.x - offsetX; + vertex.y = quad.w - offsetY; vertices.PushBack( vertex ); // bottom-right (v+3) - vertex.x = quad.max.x - offsetX; - vertex.y = quad.max.y - offsetY; + vertex.x = quad.z - offsetX; + vertex.y = quad.w - offsetY; vertices.PushBack( vertex ); // triangle A (3, 1, 0) @@ -1139,7 +1245,7 @@ struct Decorator::Impl : public ConnectionTracker } } - mHighlightQuadList.clear(); + mHighlightQuadList.Clear(); if( mHighlightRenderer ) { @@ -1163,7 +1269,7 @@ struct Decorator::Impl : public ConnectionTracker const float x = handle.globalPosition.x + handle.grabDisplacementX; const float y = handle.globalPosition.y + handle.grabDisplacementY + 0.5f * handle.lineHeight; - const float yVerticallyFlippedCorrected = y - ( handle.verticallyFlipped ? handle.lineHeight : 0.f ); + const float yVerticallyFlippedCorrected = y - ( handle.verticallyFlippedOnTouch ? handle.lineHeight : 0.f ); if( ( Gesture::Started == gesture.state ) || ( Gesture::Continuing == gesture.state ) ) @@ -1294,6 +1400,7 @@ struct Decorator::Impl : public ConnectionTracker if( PointState::DOWN == state ) { primarySelectionHandle.pressed = true; + primarySelectionHandle.verticallyFlippedOnTouch = primarySelectionHandle.verticallyFlipped; } else if( ( PointState::UP == state ) || ( PointState::INTERRUPTED == state ) ) @@ -1301,6 +1408,7 @@ struct Decorator::Impl : public ConnectionTracker primarySelectionHandle.pressed = false; mIsHandlePreviouslyCrossed = mIsHandleCurrentlyCrossed; mIsHandlePanning = false; + mHandleReleased = LEFT_SELECTION_HANDLE; } SetHandleImage( LEFT_SELECTION_HANDLE ); @@ -1323,6 +1431,7 @@ struct Decorator::Impl : public ConnectionTracker if( PointState::DOWN == state ) { secondarySelectionHandle.pressed = true; + secondarySelectionHandle.verticallyFlippedOnTouch = secondarySelectionHandle.verticallyFlipped; } else if( ( PointState::UP == state ) || ( PointState::INTERRUPTED == state ) ) @@ -1330,6 +1439,7 @@ struct Decorator::Impl : public ConnectionTracker secondarySelectionHandle.pressed = false; mIsHandlePreviouslyCrossed = mIsHandleCurrentlyCrossed; mIsHandlePanning = false; + mHandleReleased = RIGHT_SELECTION_HANDLE; } SetHandleImage( RIGHT_SELECTION_HANDLE ); @@ -1377,16 +1487,16 @@ struct Decorator::Impl : public ConnectionTracker // Vertical notifications. // Disconnect any previous connected callback. - if( mVerticalLessThanNotification ) + if( mHandleVerticalLessThanNotification ) { - mVerticalLessThanNotification.NotifySignal().Disconnect( this, &Decorator::Impl::HandleResetPosition ); - mActiveLayer.RemovePropertyNotification( mVerticalLessThanNotification ); + mHandleVerticalLessThanNotification.NotifySignal().Disconnect( this, &Decorator::Impl::HandleResetPosition ); + mActiveLayer.RemovePropertyNotification( mHandleVerticalLessThanNotification ); } - if( mVerticalGreaterThanNotification ) + if( mHandleVerticalGreaterThanNotification ) { - mVerticalGreaterThanNotification.NotifySignal().Disconnect( this, &Decorator::Impl::HandleResetPosition ); - mActiveLayer.RemovePropertyNotification( mVerticalGreaterThanNotification ); + mHandleVerticalGreaterThanNotification.NotifySignal().Disconnect( this, &Decorator::Impl::HandleResetPosition ); + mActiveLayer.RemovePropertyNotification( mHandleVerticalGreaterThanNotification ); } const HandleImpl& grabHandle = mHandle[GRAB_HANDLE]; @@ -1398,36 +1508,36 @@ struct Decorator::Impl : public ConnectionTracker if( grabHandle.verticallyFlipped ) { // The grab handle is vertically flipped. Never is going to exceed the bottom edje of the display. - mVerticalGreaterThanNotification.Reset(); + mHandleVerticalGreaterThanNotification.Reset(); // The vertical distance from the center of the active layer to the top edje of the display. const float topHeight = 0.5f * mControlSize.height - grabHandle.position.y + grabHandle.size.height; - mVerticalLessThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, - LessThanCondition( mBoundingBox.y + topHeight ) ); + mHandleVerticalLessThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, + LessThanCondition( mBoundingBox.y + topHeight ) ); // Notifies the change from false to true and from true to false. - mVerticalLessThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + mHandleVerticalLessThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); // Connects the signals with the callbacks. - mVerticalLessThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); + mHandleVerticalLessThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); } else { // The grab handle is not vertically flipped. Never is going to exceed the top edje of the display. - mVerticalLessThanNotification.Reset(); + mHandleVerticalLessThanNotification.Reset(); // The vertical distance from the center of the active layer to the bottom edje of the display. const float bottomHeight = -0.5f * mControlSize.height + grabHandle.position.y + grabHandle.lineHeight + grabHandle.size.height; - mVerticalGreaterThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, - GreaterThanCondition( mBoundingBox.w - bottomHeight ) ); + mHandleVerticalGreaterThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, + GreaterThanCondition( mBoundingBox.w - bottomHeight ) ); // Notifies the change from false to true and from true to false. - mVerticalGreaterThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + mHandleVerticalGreaterThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); // Connects the signals with the callbacks. - mVerticalGreaterThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); + mHandleVerticalGreaterThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); } } else // The selection handles are active @@ -1435,37 +1545,37 @@ struct Decorator::Impl : public ConnectionTracker if( primaryHandle.verticallyFlipped && secondaryHandle.verticallyFlipped ) { // Both selection handles are vertically flipped. Never are going to exceed the bottom edje of the display. - mVerticalGreaterThanNotification.Reset(); + mHandleVerticalGreaterThanNotification.Reset(); // The vertical distance from the center of the active layer to the top edje of the display. const float topHeight = 0.5f * mControlSize.height + std::max( -primaryHandle.position.y + primaryHandle.size.height, -secondaryHandle.position.y + secondaryHandle.size.height ); - mVerticalLessThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, - LessThanCondition( mBoundingBox.y + topHeight ) ); + mHandleVerticalLessThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, + LessThanCondition( mBoundingBox.y + topHeight ) ); // Notifies the change from false to true and from true to false. - mVerticalLessThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + mHandleVerticalLessThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); // Connects the signals with the callbacks. - mVerticalLessThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); + mHandleVerticalLessThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); } else if( !primaryHandle.verticallyFlipped && !secondaryHandle.verticallyFlipped ) { // Both selection handles aren't vertically flipped. Never are going to exceed the top edje of the display. - mVerticalLessThanNotification.Reset(); + mHandleVerticalLessThanNotification.Reset(); // The vertical distance from the center of the active layer to the bottom edje of the display. const float bottomHeight = -0.5f * mControlSize.height + std::max( primaryHandle.position.y + primaryHandle.lineHeight + primaryHandle.size.height, secondaryHandle.position.y + secondaryHandle.lineHeight + secondaryHandle.size.height ); - mVerticalGreaterThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, - GreaterThanCondition( mBoundingBox.w - bottomHeight ) ); + mHandleVerticalGreaterThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, + GreaterThanCondition( mBoundingBox.w - bottomHeight ) ); // Notifies the change from false to true and from true to false. - mVerticalGreaterThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + mHandleVerticalGreaterThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); // Connects the signals with the callbacks. - mVerticalGreaterThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); + mHandleVerticalGreaterThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); } else { @@ -1476,44 +1586,44 @@ struct Decorator::Impl : public ConnectionTracker -primaryHandle.position.y + primaryHandle.size.height : -secondaryHandle.position.y + secondaryHandle.size.height ); - mVerticalLessThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, - LessThanCondition( mBoundingBox.y + topHeight ) ); + mHandleVerticalLessThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, + LessThanCondition( mBoundingBox.y + topHeight ) ); // Notifies the change from false to true and from true to false. - mVerticalLessThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + mHandleVerticalLessThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); // Connects the signals with the callbacks. - mVerticalLessThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); + mHandleVerticalLessThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); // The vertical distance from the center of the active layer to the bottom edje of the display. const float bottomHeight = -0.5f * mControlSize.height + ( primaryHandle.verticallyFlipped ? secondaryHandle.position.y + secondaryHandle.lineHeight + secondaryHandle.size.height : primaryHandle.position.y + primaryHandle.lineHeight + primaryHandle.size.height ); - mVerticalGreaterThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, - GreaterThanCondition( mBoundingBox.w - bottomHeight ) ); + mHandleVerticalGreaterThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, + GreaterThanCondition( mBoundingBox.w - bottomHeight ) ); // Notifies the change from false to true and from true to false. - mVerticalGreaterThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + mHandleVerticalGreaterThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); // Connects the signals with the callbacks. - mVerticalGreaterThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); + mHandleVerticalGreaterThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); } } // Horizontal notifications. // Disconnect any previous connected callback. - if( mHorizontalLessThanNotification ) + if( mHandleHorizontalLessThanNotification ) { - mHorizontalLessThanNotification.NotifySignal().Disconnect( this, &Decorator::Impl::HandleResetPosition ); - mActiveLayer.RemovePropertyNotification( mHorizontalLessThanNotification ); + mHandleHorizontalLessThanNotification.NotifySignal().Disconnect( this, &Decorator::Impl::HandleResetPosition ); + mActiveLayer.RemovePropertyNotification( mHandleHorizontalLessThanNotification ); } - if( mHorizontalGreaterThanNotification ) + if( mHandleHorizontalGreaterThanNotification ) { - mHorizontalGreaterThanNotification.NotifySignal().Disconnect( this, &Decorator::Impl::HandleResetPosition ); - mActiveLayer.RemovePropertyNotification( mHorizontalGreaterThanNotification ); + mHandleHorizontalGreaterThanNotification.NotifySignal().Disconnect( this, &Decorator::Impl::HandleResetPosition ); + mActiveLayer.RemovePropertyNotification( mHandleHorizontalGreaterThanNotification ); } if( primaryHandle.active || secondaryHandle.active ) @@ -1522,37 +1632,37 @@ struct Decorator::Impl : public ConnectionTracker const float leftWidth = 0.5f * mControlSize.width + std::max( -primaryHandle.position.x + primaryHandle.size.width, -secondaryHandle.position.x + secondaryHandle.size.width ); - mHorizontalLessThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_X, - LessThanCondition( mBoundingBox.x + leftWidth ) ); + mHandleHorizontalLessThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_X, + LessThanCondition( mBoundingBox.x + leftWidth ) ); // Notifies the change from false to true and from true to false. - mHorizontalLessThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + mHandleHorizontalLessThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); // Connects the signals with the callbacks. - mHorizontalLessThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); + mHandleHorizontalLessThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); // The horizontal distance from the center of the active layer to the right edje of the display. const float rightWidth = -0.5f * mControlSize.width + std::max( primaryHandle.position.x + primaryHandle.size.width, secondaryHandle.position.x + secondaryHandle.size.width ); - mHorizontalGreaterThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_X, - GreaterThanCondition( mBoundingBox.z - rightWidth ) ); + mHandleHorizontalGreaterThanNotification = mActiveLayer.AddPropertyNotification( Actor::Property::WORLD_POSITION_X, + GreaterThanCondition( mBoundingBox.z - rightWidth ) ); // Notifies the change from false to true and from true to false. - mHorizontalGreaterThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + mHandleHorizontalGreaterThanNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); // Connects the signals with the callbacks. - mHorizontalGreaterThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); + mHandleHorizontalGreaterThanNotification.NotifySignal().Connect( this, &Decorator::Impl::HandleResetPosition ); } } // Popup - float AlternatePopUpPositionRelativeToCursor() + float AlternatePopUpPositionRelativeToCursor( bool topBottom ) { float alternativePosition = 0.0f; - const float popupHeight = mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ); + const float halfPopupHeight = 0.5f * mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ); const HandleImpl& primaryHandle = mHandle[LEFT_SELECTION_HANDLE]; const HandleImpl& secondaryHandle = mHandle[RIGHT_SELECTION_HANDLE]; @@ -1561,72 +1671,85 @@ struct Decorator::Impl : public ConnectionTracker if( primaryHandle.active || secondaryHandle.active ) { - const float maxHandleHeight = std::max( primaryHandle.size.height, secondaryHandle.size.height ); - alternativePosition = 0.5f * popupHeight + cursor.lineHeight + maxHandleHeight + std::min( primaryHandle.position.y, secondaryHandle.position.y ); + float handleY = 0.f; + float maxHandleHeight = 0.f; + + const bool primaryVisible = primaryHandle.horizontallyVisible && primaryHandle.verticallyVisible; + const bool secondaryVisible = secondaryHandle.horizontallyVisible && secondaryHandle.verticallyVisible; + + if( primaryVisible && secondaryVisible ) + { + handleY = std::max( primaryHandle.position.y, secondaryHandle.position.y ); + maxHandleHeight = std::max( primaryHandle.size.height, secondaryHandle.size.height ); + } + else if( primaryVisible && !secondaryVisible ) + { + handleY = primaryHandle.position.y; + maxHandleHeight = primaryHandle.size.height; + } + else if( !primaryVisible && secondaryVisible ) + { + handleY = secondaryHandle.position.y; + maxHandleHeight = secondaryHandle.size.height; + } + + alternativePosition = handleY + ( topBottom ? halfPopupHeight + maxHandleHeight + cursor.lineHeight : -halfPopupHeight - maxHandleHeight ); } else { - alternativePosition = 0.5f * popupHeight + cursor.lineHeight + grabHandle.size.height + cursor.position.y; + alternativePosition = cursor.position.y + ( topBottom ? halfPopupHeight + grabHandle.size.height + cursor.lineHeight : -halfPopupHeight - grabHandle.size.height ); } return alternativePosition; } - void PopUpLeavesVerticalBoundary( PropertyNotification& source ) + void PopUpLeavesTopBoundary( PropertyNotification& source ) { - float alternativeYPosition = 0.0f; - // todo use AlternatePopUpPositionRelativeToSelectionHandles() if text is highlighted - // if can't be positioned above, then position below row. - alternativeYPosition = AlternatePopUpPositionRelativeToCursor(); + const float popupHeight = mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ); - mCopyPastePopup.actor.SetY( alternativeYPosition ); + // Sets the position of the popup below. + mCopyPastePopup.actor.SetY( floorf( CalculateVerticalPopUpPosition( 0.5f * popupHeight, true ) ) ); } - void SetUpPopupPositionNotifications() + void PopUpLeavesBottomBoundary( PropertyNotification& source ) { - // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left. - - // Exceeding vertical boundary - const float popupHeight = mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ); - PropertyNotification verticalExceedNotification = mCopyPastePopup.actor.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, - OutsideCondition( mBoundingBox.y + popupHeight * 0.5f, - mBoundingBox.w - popupHeight * 0.5f ) ); - - verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary ); + // Sets the position of the popup above. + mCopyPastePopup.actor.SetY( floorf( CalculateVerticalPopUpPosition( 0.5f * popupHeight, false ) ) ); } - void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, const Vector3& popupDistanceFromAnchorPoint, Actor parent, const Vector4& boundingRectangleWorld ) + void SetUpPopupPositionNotifications( const Vector3& popupHalfSize ) { - DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() ) - - // Parent must already by added to Stage for these Get calls to work - const Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize() * parent.GetCurrentAnchorPoint(); - const Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition; // Parent World position plus popup local position gives World Position - - // Calculate distance to move popup (in local space) so fits within the boundary - float xOffSetToKeepWithinBounds = 0.0f; - if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x ) - { - xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x ); - } - else if( popupWorldPosition.x + popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z ) + // Disconnect any previous connected callback. + if( mPopupTopExceedNotification ) { - xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x ); + mPopupTopExceedNotification.NotifySignal().Disconnect( this, &Decorator::Impl::PopUpLeavesTopBoundary ); + mCopyPastePopup.actor.RemovePropertyNotification( mPopupTopExceedNotification ); } - // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind. - if( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y ) + if( mPopupBottomExceedNotification ) { - requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor(); + mPopupBottomExceedNotification.NotifySignal().Disconnect( this, &Decorator::Impl::PopUpLeavesBottomBoundary ); + mCopyPastePopup.actor.RemovePropertyNotification( mPopupBottomExceedNotification ); } - requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds; + // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left. - // Prevent pixel mis-alignment by rounding down. - requiredPopupPosition.x = floor( requiredPopupPosition.x ); - requiredPopupPosition.y = floor( requiredPopupPosition.y ); + // Exceeding vertical boundary + + mPopupTopExceedNotification = mCopyPastePopup.actor.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, + LessThanCondition( mBoundingBox.y + popupHalfSize.height ) ); + + mPopupBottomExceedNotification = mCopyPastePopup.actor.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y, + GreaterThanCondition( mBoundingBox.w - popupHalfSize.height ) ); + + // Notifies the change from false to true and from true to false. + mPopupTopExceedNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + mPopupBottomExceedNotification.SetNotifyMode( PropertyNotification::NotifyOnChanged ); + + mPopupTopExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesTopBoundary ); + mPopupBottomExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesBottomBoundary ); } void SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image ) @@ -1754,11 +1877,13 @@ struct Decorator::Impl : public ConnectionTracker Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink Timer mScrollTimer; ///< Timer used to scroll the text when the grab handle is moved close to the edges. - Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else. - PropertyNotification mVerticalLessThanNotification; ///< Notifies when the 'y' coord of the active layer is less than a given value. - PropertyNotification mVerticalGreaterThanNotification; ///< Notifies when the 'y' coord of the active layer is grater than a given value. - PropertyNotification mHorizontalLessThanNotification; ///< Notifies when the 'x' coord of the active layer is less than a given value. - PropertyNotification mHorizontalGreaterThanNotification; ///< Notifies when the 'x' coord of the active layer is grater than a given value. + Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else. + PropertyNotification mHandleVerticalLessThanNotification; ///< Notifies when the 'y' coord of the active layer is less than a given value. + PropertyNotification mHandleVerticalGreaterThanNotification; ///< Notifies when the 'y' coord of the active layer is grater than a given value. + PropertyNotification mHandleHorizontalLessThanNotification; ///< Notifies when the 'x' coord of the active layer is less than a given value. + PropertyNotification mHandleHorizontalGreaterThanNotification; ///< Notifies when the 'x' coord of the active layer is grater than a given value. + PropertyNotification mPopupTopExceedNotification; ///< Notifies when the popup leaves the bounding box through the top. + PropertyNotification mPopupBottomExceedNotification; ///< Notifies when the popup leaves the bounding box through the bottom. Control mPrimaryCursor; Control mSecondaryCursor; @@ -1778,7 +1903,7 @@ struct Decorator::Impl : public ConnectionTracker PropertyBuffer mQuadVertices; Geometry mQuadGeometry; - QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight + QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight. Vector4 mBoundingBox; ///< The bounding box in world coords. Vector4 mHighlightColor; ///< Color of the highlight @@ -1791,6 +1916,7 @@ struct Decorator::Impl : public ConnectionTracker float mCursorBlinkDuration; float mCursorWidth; ///< The width of the cursors in pixels. HandleType mHandleScrolling; ///< The handle which is scrolling. + HandleType mHandleReleased; ///< The last handle released. ScrollDirection mScrollDirection; ///< The direction of the scroll. float mScrollThreshold; ///< Defines a square area inside the control, close to the edge. A cursor entering this area will trigger scroll events. float mScrollSpeed; ///< The scroll speed in pixels per second. @@ -1813,6 +1939,7 @@ struct Decorator::Impl : public ConnectionTracker bool mHorizontalScrollingEnabled : 1; ///< Whether the horizontal scrolling is enabled. bool mVerticalScrollingEnabled : 1; ///< Whether the vertical scrolling is enabled. bool mSmoothHandlePanEnabled : 1; ///< Whether to pan smoothly the handles. + bool mIsHighlightBoxActive : 1; ///< Whether the highlight box is active. }; DecoratorPtr Decorator::New( ControllerInterface& controller, @@ -2053,9 +2180,9 @@ void Decorator::SetSelectionHandleFlipState( bool indicesSwapped, bool left, boo mImpl->mFlipRightSelectionHandleDirection = right; } -void Decorator::AddHighlight( float x1, float y1, float x2, float y2 ) +void Decorator::AddHighlight( unsigned int index, const Vector4& quad ) { - mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) ); + *( mImpl->mHighlightQuadList.Begin() + index ) = quad; } void Decorator::SetHighLightBox( const Vector2& position, const Size& size ) @@ -2066,10 +2193,15 @@ void Decorator::SetHighLightBox( const Vector2& position, const Size& size ) void Decorator::ClearHighlights() { - mImpl->mHighlightQuadList.clear(); + mImpl->mHighlightQuadList.Clear(); mImpl->mHighlightPosition = Vector2::ZERO; } +void Decorator::ResizeHighlightQuads( unsigned int numberOfQuads ) +{ + mImpl->mHighlightQuadList.Resize( numberOfQuads ); +} + void Decorator::SetHighlightColor( const Vector4& color ) { mImpl->mHighlightColor = color; @@ -2080,6 +2212,16 @@ const Vector4& Decorator::GetHighlightColor() const return mImpl->mHighlightColor; } +void Decorator::SetHighlightActive( bool active ) +{ + mImpl->mIsHighlightBoxActive = active; +} + +bool Decorator::IsHighlightActive() const +{ + return mImpl->mIsHighlightBoxActive; +} + void Decorator::SetTextDepth( int textDepth ) { mImpl->mTextDepth = textDepth; @@ -2092,7 +2234,7 @@ void Decorator::SetPopupActive( bool active ) bool Decorator::IsPopupActive() const { - return mImpl->mActiveCopyPastePopup ; + return mImpl->mActiveCopyPastePopup; } void Decorator::SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask ) @@ -2106,7 +2248,7 @@ void Decorator::SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButt mImpl->mCopyPastePopup.actor.SetName("mCopyPastePopup"); #endif mImpl->mCopyPastePopup.actor.SetAnchorPoint( AnchorPoint::CENTER ); - mImpl->mCopyPastePopup.actor.OnRelayoutSignal().Connect( mImpl, &Decorator::Impl::PopupRelayoutComplete ); // Position popup after size negotiation + mImpl->mCopyPastePopup.actor.OnRelayoutSignal().Connect( mImpl, &Decorator::Impl::SetPopupPosition ); // Position popup after size negotiation } mImpl->mCopyPastePopup.actor.EnableButtons( mImpl->mEnabledPopupButtons ); diff --git a/dali-toolkit/internal/text/decorator/text-decorator.h b/dali-toolkit/internal/text/decorator/text-decorator.h index a868958..6e7c727 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.h +++ b/dali-toolkit/internal/text/decorator/text-decorator.h @@ -437,12 +437,10 @@ public: /** * @brief Adds a quad to the existing selection highlights. Vertices are in decorator's coordinates. * - * @param[in] x1 The top-left x position. - * @param[in] y1 The top-left y position. - * @param[in] x2 The bottom-right x position. - * @param[in] y3 The bottom-right y position. + * @param[in] index Position in the vector where to add the quad. + * @param[in] quad The quad. The 'x' and 'y' coordinates store the min 'x' and min 'y'. The 'z' and 'w' coordinates store the max 'x' and max 'y'. */ - void AddHighlight( float x1, float y1, float x2, float y2 ); + void AddHighlight( unsigned int index, const Vector4& quad ); /** * @brief Sets the min 'x,y' coordinates and the size of the highlighted box. @@ -462,6 +460,13 @@ public: void ClearHighlights(); /** + * @brief Reserves space for the highlight quads. + * + * @param[in] numberOfQuads The expected number of quads. + */ + void ResizeHighlightQuads( unsigned int numberOfQuads ); + + /** * @brief Sets the selection highlight color. * * @param[in] color The color to use. @@ -476,6 +481,20 @@ public: const Vector4& GetHighlightColor() const; /** + * @brief Sets whether the highlight is active. + * + * @param[in] active Whether the highlight is active. + */ + void SetHighlightActive( bool active ); + + /** + * @brief Retrieves whether the highlight is active. + * + * @return @e true if the highlight is active, @e false otherwise. + */ + bool IsHighlightActive() const; + + /** * @brief Sets into the decorator the depth used to render the text. * * @param[in] depth The text's depth. diff --git a/dali-toolkit/internal/text/rendering/text-backend-impl.cpp b/dali-toolkit/internal/text/rendering/text-backend-impl.cpp index 10602c7..5ae10c8 100644 --- a/dali-toolkit/internal/text/rendering/text-backend-impl.cpp +++ b/dali-toolkit/internal/text/rendering/text-backend-impl.cpp @@ -106,7 +106,7 @@ RendererPtr Backend::NewRenderer( unsigned int renderingType ) default: { - DALI_LOG_WARNING( "Unknown renderer type: %d", renderingType ); + DALI_LOG_WARNING( "Unknown renderer type: %d\n", renderingType ); break; } } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 2c45d35..95115da 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -91,6 +91,7 @@ EventData::EventData( DecoratorPtr decorator ) mUpdateGrabHandlePosition( false ), mUpdateLeftSelectionPosition( false ), mUpdateRightSelectionPosition( false ), + mIsLeftHandleSelected( false ), mUpdateHighlightBox( false ), mScrollAfterUpdatePosition( false ), mScrollAfterDelete( false ), @@ -218,16 +219,12 @@ bool Controller::Impl::ProcessInputEvents() GetCursorPosition( mEventData->mRightSelectionPosition, rightHandleInfo ); - if( mEventData->mScrollAfterUpdatePosition && mEventData->mUpdateLeftSelectionPosition ) + if( mEventData->mScrollAfterUpdatePosition && ( mEventData->mIsLeftHandleSelected ? mEventData->mUpdateLeftSelectionPosition : mEventData->mUpdateRightSelectionPosition ) ) { - const Vector2 currentCursorPosition( leftHandleInfo.primaryPosition.x, leftHandleInfo.lineOffset ); - ScrollToMakePositionVisible( currentCursorPosition, leftHandleInfo.lineHeight ); - } + CursorInfo& info = mEventData->mIsLeftHandleSelected ? leftHandleInfo : rightHandleInfo; - if( mEventData->mScrollAfterUpdatePosition && mEventData->mUpdateRightSelectionPosition ) - { - const Vector2 currentCursorPosition( rightHandleInfo.primaryPosition.x, rightHandleInfo.lineOffset ); - ScrollToMakePositionVisible( currentCursorPosition, rightHandleInfo.lineHeight ); + const Vector2 currentCursorPosition( info.primaryPosition.x, info.lineOffset ); + ScrollToMakePositionVisible( currentCursorPosition, info.lineHeight ); } } @@ -1203,17 +1200,31 @@ void Controller::Impl::OnPanEvent( const Event& event ) return; } - int state = event.p1.mInt; + const bool isHorizontalScrollEnabled = mEventData->mDecorator->IsHorizontalScrollEnabled(); + const bool isVerticalScrollEnabled = mEventData->mDecorator->IsVerticalScrollEnabled(); - if( ( Gesture::Started == state ) || - ( Gesture::Continuing == state ) ) + if( !isHorizontalScrollEnabled && !isVerticalScrollEnabled ) { - if( mEventData->mDecorator ) + // Nothing to do if scrolling is not enabled. + return; + } + + const int state = event.p1.mInt; + + switch( state ) + { + case Gesture::Started: + { + // Will remove the cursor, handles or text's popup, ... + ChangeState( EventData::TEXT_PANNING ); + break; + } + case Gesture::Continuing: { const Vector2& layoutSize = mVisualModel->GetLayoutSize(); const Vector2 currentScroll = mScrollPosition; - if( mEventData->mDecorator->IsHorizontalScrollEnabled() ) + if( isHorizontalScrollEnabled ) { const float displacementX = event.p2.mFloat; mScrollPosition.x += displacementX; @@ -1221,7 +1232,7 @@ void Controller::Impl::OnPanEvent( const Event& event ) ClampHorizontalScroll( layoutSize ); } - if( mEventData->mDecorator->IsVerticalScrollEnabled() ) + if( isVerticalScrollEnabled ) { const float displacementY = event.p3.mFloat; mScrollPosition.y += displacementY; @@ -1230,7 +1241,17 @@ void Controller::Impl::OnPanEvent( const Event& event ) } mEventData->mDecorator->UpdatePositions( mScrollPosition - currentScroll ); + break; + } + case Gesture::Finished: + case Gesture::Cancelled: // FALLTHROUGH + { + // Will go back to the previous state to show the cursor, handles, the text's popup, ... + ChangeState( mEventData->mPreviousState ); + break; } + default: + break; } } @@ -1302,6 +1323,9 @@ void Controller::Impl::OnHandleEvent( const Event& event ) // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set. mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled; + + // Will define the order to scroll the text to match the handle position. + mEventData->mIsLeftHandleSelected = true; } else if( Event::RIGHT_SELECTION_HANDLE_EVENT == event.type ) { @@ -1319,6 +1343,9 @@ void Controller::Impl::OnHandleEvent( const Event& event ) // Updates the decorator if the soft handle panning is enabled. It triggers a relayout in the decorator and the new position of the handle is set. mEventData->mDecoratorUpdated = isSmoothHandlePanEnabled; + + // Will define the order to scroll the text to match the handle position. + mEventData->mIsLeftHandleSelected = false; } } // end ( HANDLE_PRESSED == state ) else if( ( HANDLE_RELEASED == state ) || @@ -1361,6 +1388,7 @@ void Controller::Impl::OnHandleEvent( const Event& event ) mEventData->mUpdateHighlightBox = true; mEventData->mUpdateLeftSelectionPosition = true; + mEventData->mUpdateRightSelectionPosition = true; if( handleStopScrolling || isSmoothHandlePanEnabled ) { @@ -1379,6 +1407,7 @@ void Controller::Impl::OnHandleEvent( const Event& event ) mEventData->mUpdateHighlightBox = true; mEventData->mUpdateRightSelectionPosition = true; + mEventData->mUpdateLeftSelectionPosition = true; if( handleStopScrolling || isSmoothHandlePanEnabled ) { @@ -1759,6 +1788,14 @@ void Controller::Impl::RepositionSelectionHandles() const Length numberOfCharactersEnd = *( charactersPerGlyphBuffer + glyphEnd ); bool splitEndGlyph = ( glyphStart != glyphEnd ) && ( numberOfCharactersEnd > 1u ) && HasLigatureMustBreak( mLogicalModel->GetScript( selectionEndMinusOne ) ); + // The number of quads of the selection box. + const unsigned int numberOfQuads = 1u + ( glyphEnd - glyphStart ) + ( ( numberOfLines > 1u ) ? 2u * numberOfLines : 0u ); + mEventData->mDecorator->ResizeHighlightQuads( numberOfQuads ); + + // Count the actual number of quads. + unsigned int actualNumberOfQuads = 0u; + Vector4 quad; + // Traverse the glyphs. for( GlyphIndex index = glyphStart; index <= glyphEnd; ++index ) { @@ -1782,18 +1819,17 @@ void Controller::Impl::RepositionSelectionHandles() // Calculate the number of characters selected. const Length numberOfCharacters = ( glyphStart == glyphEnd ) ? ( selectionEnd - selectionStart ) : ( numberOfCharactersStart - interGlyphIndex ); - const float xPosition = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + glyphAdvance * static_cast( isCurrentRightToLeft ? ( numberOfCharactersStart - interGlyphIndex - numberOfCharacters ) : interGlyphIndex ); - const float xPositionAdvance = xPosition + static_cast( numberOfCharacters ) * glyphAdvance; - const float yPosition = selectionBoxInfo->lineOffset; + quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + glyphAdvance * static_cast( isCurrentRightToLeft ? ( numberOfCharactersStart - interGlyphIndex - numberOfCharacters ) : interGlyphIndex ); + quad.y = selectionBoxInfo->lineOffset; + quad.z = quad.x + static_cast( numberOfCharacters ) * glyphAdvance; + quad.w = selectionBoxInfo->lineOffset + selectionBoxInfo->lineHeight; // Store the min and max 'x' for each line. - selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, xPosition ); - selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, xPositionAdvance ); + selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, quad.x ); + selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, quad.z ); - mEventData->mDecorator->AddHighlight( xPosition, - yPosition, - xPositionAdvance, - yPosition + selectionBoxInfo->lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, quad ); + ++actualNumberOfQuads; splitStartGlyph = false; continue; @@ -1814,35 +1850,35 @@ void Controller::Impl::RepositionSelectionHandles() const Length numberOfCharacters = numberOfCharactersEnd - interGlyphIndex; - const float xPosition = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + ( isCurrentRightToLeft ? ( glyphAdvance * static_cast( numberOfCharacters ) ) : 0.f ); - const float xPositionAdvance = xPosition + static_cast( interGlyphIndex ) * glyphAdvance; - const float yPosition = selectionBoxInfo->lineOffset; + quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x + ( isCurrentRightToLeft ? ( glyphAdvance * static_cast( numberOfCharacters ) ) : 0.f ); + quad.y = selectionBoxInfo->lineOffset; + quad.z = quad.x + static_cast( interGlyphIndex ) * glyphAdvance; + quad.w = quad.y + selectionBoxInfo->lineHeight; // Store the min and max 'x' for each line. - selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, xPosition ); - selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, xPositionAdvance ); + selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, quad.x ); + selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, quad.z ); - mEventData->mDecorator->AddHighlight( xPosition, - yPosition, - xPositionAdvance, - yPosition + selectionBoxInfo->lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; splitEndGlyph = false; continue; } - const float xPosition = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x; - const float xPositionAdvance = xPosition + glyph.advance; - const float yPosition = selectionBoxInfo->lineOffset; + quad.x = lineRun->alignmentOffset + position.x - glyph.xBearing + mScrollPosition.x; + quad.y = selectionBoxInfo->lineOffset; + quad.z = quad.x + glyph.advance; + quad.w = quad.y + selectionBoxInfo->lineHeight; // Store the min and max 'x' for each line. - selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, xPosition ); - selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, xPositionAdvance ); + selectionBoxInfo->minX = std::min( selectionBoxInfo->minX, quad.x ); + selectionBoxInfo->maxX = std::max( selectionBoxInfo->maxX, quad.z ); - mEventData->mDecorator->AddHighlight( xPosition, - yPosition, - xPositionAdvance, - yPosition + selectionBoxInfo->lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Whether to retrieve the next line. if( index == lastGlyphOfLine ) @@ -1886,7 +1922,7 @@ void Controller::Impl::RepositionSelectionHandles() const SelectionBoxInfo& info = *it; // Update the size of the highlighted text. - highLightSize.height += selectionBoxInfo->lineHeight; + highLightSize.height += info.lineHeight; minHighlightX = std::min( minHighlightX, info.minX ); maxHighlightX = std::max( maxHighlightX, info.maxX ); } @@ -1904,11 +1940,15 @@ void Controller::Impl::RepositionSelectionHandles() if( boxifyBegin ) { + quad.x = 0.f; + quad.y = firstSelectionBoxLineInfo.lineOffset; + quad.z = firstSelectionBoxLineInfo.minX; + quad.w = firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight; + // Boxify at the beginning of the line. - mEventData->mDecorator->AddHighlight( 0.f, - firstSelectionBoxLineInfo.lineOffset, - firstSelectionBoxLineInfo.minX, - firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Update the size of the highlighted text. minHighlightX = 0.f; @@ -1916,11 +1956,15 @@ void Controller::Impl::RepositionSelectionHandles() if( boxifyEnd ) { + quad.x = firstSelectionBoxLineInfo.maxX; + quad.y = firstSelectionBoxLineInfo.lineOffset; + quad.z = mVisualModel->mControlSize.width; + quad.w = firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight; + // Boxify at the end of the line. - mEventData->mDecorator->AddHighlight( firstSelectionBoxLineInfo.maxX, - firstSelectionBoxLineInfo.lineOffset, - mVisualModel->mControlSize.width, - firstSelectionBoxLineInfo.lineOffset + firstSelectionBoxLineInfo.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Update the size of the highlighted text. maxHighlightX = mVisualModel->mControlSize.width; @@ -1936,15 +1980,23 @@ void Controller::Impl::RepositionSelectionHandles() { const SelectionBoxInfo& info = *it; - mEventData->mDecorator->AddHighlight( 0.f, - info.lineOffset, - info.minX, - info.lineOffset + info.lineHeight ); + quad.x = 0.f; + quad.y = info.lineOffset; + quad.z = info.minX; + quad.w = info.lineOffset + info.lineHeight; + + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; + + quad.x = info.maxX; + quad.y = info.lineOffset; + quad.z = mVisualModel->mControlSize.width; + quad.w = info.lineOffset + info.lineHeight; - mEventData->mDecorator->AddHighlight( info.maxX, - info.lineOffset, - mVisualModel->mControlSize.width, - info.lineOffset + info.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; } // Update the size of the highlighted text. @@ -1961,11 +2013,15 @@ void Controller::Impl::RepositionSelectionHandles() if( boxifyBegin ) { + quad.x = 0.f; + quad.y = lastSelectionBoxLineInfo.lineOffset; + quad.z = lastSelectionBoxLineInfo.minX; + quad.w = lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight; + // Boxify at the beginning of the line. - mEventData->mDecorator->AddHighlight( 0.f, - lastSelectionBoxLineInfo.lineOffset, - lastSelectionBoxLineInfo.minX, - lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Update the size of the highlighted text. minHighlightX = 0.f; @@ -1973,17 +2029,24 @@ void Controller::Impl::RepositionSelectionHandles() if( boxifyEnd ) { + quad.x = lastSelectionBoxLineInfo.maxX; + quad.y = lastSelectionBoxLineInfo.lineOffset; + quad.z = mVisualModel->mControlSize.width; + quad.w = lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight; + // Boxify at the end of the line. - mEventData->mDecorator->AddHighlight( lastSelectionBoxLineInfo.maxX, - lastSelectionBoxLineInfo.lineOffset, - mVisualModel->mControlSize.width, - lastSelectionBoxLineInfo.lineOffset + lastSelectionBoxLineInfo.lineHeight ); + mEventData->mDecorator->AddHighlight( actualNumberOfQuads, + quad ); + ++actualNumberOfQuads; // Update the size of the highlighted text. maxHighlightX = mVisualModel->mControlSize.width; } } + // Set the actual number of quads. + mEventData->mDecorator->ResizeHighlightQuads( actualNumberOfQuads ); + // Sets the highlight's size and position. In decorator's coords. // The highlight's height has been calculated above (before 'boxifying' the highlight). highLightSize.width = maxHighlightX - minHighlightX; @@ -2152,158 +2215,201 @@ void Controller::Impl::ChangeState( EventData::State newState ) if( mEventData->mState != newState ) { + mEventData->mPreviousState = mEventData->mState; mEventData->mState = newState; - if( EventData::INACTIVE == mEventData->mState ) - { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); - mEventData->mDecorator->StopCursorBlink(); - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetPopupActive( false ); - mEventData->mDecoratorUpdated = true; - HideClipboard(); - } - else if( EventData::INTERRUPTED == mEventData->mState) + switch( mEventData->mState ) { - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetPopupActive( false ); - mEventData->mDecoratorUpdated = true; - HideClipboard(); - } - else if( EventData::SELECTING == mEventData->mState ) - { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); - mEventData->mDecorator->StopCursorBlink(); - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::INACTIVE: { - SetPopupButtons(); - mEventData->mDecorator->SetPopupActive( true ); - } - mEventData->mDecoratorUpdated = true; - } - else if( EventData::EDITING == mEventData->mState ) - { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) - { - mEventData->mDecorator->StartCursorBlink(); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); + mEventData->mDecorator->StopCursorBlink(); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + mEventData->mDecorator->SetPopupActive( false ); + mEventData->mDecoratorUpdated = true; + HideClipboard(); + break; } - // Grab handle is not shown until a tap is received whilst EDITING - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::INTERRUPTED: { + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); mEventData->mDecorator->SetPopupActive( false ); + mEventData->mDecoratorUpdated = true; + HideClipboard(); + break; } - mEventData->mDecoratorUpdated = true; - HideClipboard(); - } - else if( EventData::EDITING_WITH_POPUP == mEventData->mState ) - { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_POPUP \n", newState ); - - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) + case EventData::SELECTING: { - mEventData->mDecorator->StartCursorBlink(); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); + mEventData->mDecorator->StopCursorBlink(); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHighlightActive( true ); + if( mEventData->mGrabHandlePopupEnabled ) + { + SetPopupButtons(); + mEventData->mDecorator->SetPopupActive( true ); + } + mEventData->mDecoratorUpdated = true; + break; } - if( mEventData->mSelectionEnabled ) + case EventData::EDITING: { + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } + // Grab handle is not shown until a tap is received whilst EDITING + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + mEventData->mDecoratorUpdated = true; + HideClipboard(); + break; } - else + case EventData::EDITING_WITH_POPUP: { - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_POPUP \n", newState ); + + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } + if( mEventData->mSelectionEnabled ) + { + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + } + else + { + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + } + if( mEventData->mGrabHandlePopupEnabled ) + { + SetPopupButtons(); + mEventData->mDecorator->SetPopupActive( true ); + } + HideClipboard(); + mEventData->mDecoratorUpdated = true; + break; } - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::EDITING_WITH_GRAB_HANDLE: { - SetPopupButtons(); - mEventData->mDecorator->SetPopupActive( true ); - } - HideClipboard(); - mEventData->mDecoratorUpdated = true; - } - else if( EventData::EDITING_WITH_GRAB_HANDLE == mEventData->mState ) - { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_GRAB_HANDLE \n", newState ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_GRAB_HANDLE \n", newState ); - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) - { - mEventData->mDecorator->StartCursorBlink(); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } + // Grab handle is not shown until a tap is received whilst EDITING + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + mEventData->mDecoratorUpdated = true; + HideClipboard(); + break; } - // Grab handle is not shown until a tap is received whilst EDITING - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::SELECTION_HANDLE_PANNING: { - mEventData->mDecorator->SetPopupActive( false ); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); + mEventData->mDecorator->StopCursorBlink(); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); + mEventData->mDecorator->SetHighlightActive( true ); + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + mEventData->mDecoratorUpdated = true; + break; } - mEventData->mDecoratorUpdated = true; - HideClipboard(); - } - else if( EventData::SELECTION_HANDLE_PANNING == mEventData->mState ) - { - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); - mEventData->mDecorator->StopCursorBlink(); - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true ); - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::GRAB_HANDLE_PANNING: { - mEventData->mDecorator->SetPopupActive( false ); - } - mEventData->mDecoratorUpdated = true; - } - else if( EventData::GRAB_HANDLE_PANNING == mEventData->mState ) - { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GRAB_HANDLE_PANNING \n", newState ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GRAB_HANDLE_PANNING \n", newState ); - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) - { - mEventData->mDecorator->StartCursorBlink(); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + mEventData->mDecoratorUpdated = true; + break; } - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); - if( mEventData->mGrabHandlePopupEnabled ) + case EventData::EDITING_WITH_PASTE_POPUP: { - mEventData->mDecorator->SetPopupActive( false ); - } - mEventData->mDecoratorUpdated = true; - } - else if( EventData::EDITING_WITH_PASTE_POPUP == mEventData->mState ) - { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_PASTE_POPUP \n", newState ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "EDITING_WITH_PASTE_POPUP \n", newState ); - mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); - if( mEventData->mCursorBlinkEnabled ) - { - mEventData->mDecorator->StartCursorBlink(); - } + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_PRIMARY ); + if( mEventData->mCursorBlinkEnabled ) + { + mEventData->mDecorator->StartCursorBlink(); + } - mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); - mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); - mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, true ); + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( false ); - if( mEventData->mGrabHandlePopupEnabled ) + if( mEventData->mGrabHandlePopupEnabled ) + { + SetPopupButtons(); + mEventData->mDecorator->SetPopupActive( true ); + } + HideClipboard(); + mEventData->mDecoratorUpdated = true; + break; + } + case EventData::TEXT_PANNING: { - SetPopupButtons(); - mEventData->mDecorator->SetPopupActive( true ); + mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); + mEventData->mDecorator->StopCursorBlink(); + mEventData->mDecorator->SetHandleActive( GRAB_HANDLE, false ); + if( mEventData->mDecorator->IsHandleActive( LEFT_SELECTION_HANDLE ) || + mEventData->mDecorator->IsHandleActive( RIGHT_SELECTION_HANDLE ) ) + { + mEventData->mDecorator->SetHandleActive( LEFT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); + mEventData->mDecorator->SetHighlightActive( true ); + } + + if( mEventData->mGrabHandlePopupEnabled ) + { + mEventData->mDecorator->SetPopupActive( false ); + } + + mEventData->mDecoratorUpdated = true; + break; } - HideClipboard(); - mEventData->mDecoratorUpdated = true; } } } diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 68659b6..8e9ab39 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -91,7 +91,8 @@ struct EventData EDITING_WITH_GRAB_HANDLE, EDITING_WITH_PASTE_POPUP, GRAB_HANDLE_PANNING, - SELECTION_HANDLE_PANNING + SELECTION_HANDLE_PANNING, + TEXT_PANNING }; EventData( DecoratorPtr decorator ); @@ -117,6 +118,7 @@ struct EventData InputStyle mInputStyle; ///< The style to be set to the new inputed text. + State mPreviousState; ///< Stores the current state before it's updated with the new one. State mState; ///< Selection mode, edit mode etc. CharacterIndex mPrimaryCursorPosition; ///< Index into logical model for primary cursor. @@ -140,6 +142,7 @@ struct EventData bool mUpdateGrabHandlePosition : 1; ///< True if the visual position of the grab handle must be recalculated. bool mUpdateLeftSelectionPosition : 1; ///< True if the visual position of the left selection handle must be recalculated. bool mUpdateRightSelectionPosition : 1; ///< True if the visual position of the right selection handle must be recalculated. + bool mIsLeftHandleSelected : 1; ///< Whether is the left handle the one which is selected. bool mUpdateHighlightBox : 1; ///< True if the text selection high light box must be updated. bool mScrollAfterUpdatePosition : 1; ///< Whether to scroll after the cursor position is updated. bool mScrollAfterDelete : 1; ///< Whether to scroll after delete characters. diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 643c8b8..4c0316f 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -164,7 +164,7 @@ void Controller::SetAutoScrollEnabled( bool enable ) } else { - DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored" ); + DALI_LOG_WARNING( "Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n" ); mImpl->mAutoScrollEnabled = false; } } @@ -572,7 +572,7 @@ float Controller::GetDefaultPointSize() const void Controller::UpdateAfterFontChange( const std::string& newDefaultFont ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange"); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n"); if( !mImpl->mFontDefaults->familyDefined ) // If user defined font then should not update when system font changes { @@ -2172,7 +2172,7 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ { if( !mImpl->mEventData->mPreEditFlag ) { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state" ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Entered PreEdit state\n" ); // Record the start of the pre-edit text mImpl->mEventData->mPreEditStartPosition = mImpl->mEventData->mPrimaryCursorPosition; diff --git a/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp b/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp index 828ecce..6024c98 100644 --- a/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp +++ b/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp @@ -353,7 +353,7 @@ void CubeTransitionEffect::StartTransition( Vector2 panPosition, Vector2 panDisp { if( !mCurrentRenderer ) { - DALI_LOG_ERROR( "Trying to transition a cube transition without an image set" ); + DALI_LOG_ERROR( "Trying to transition a cube transition without an image set\n" ); return; } diff --git a/dali-toolkit/internal/visuals/border/border-visual.cpp b/dali-toolkit/internal/visuals/border/border-visual.cpp index dec584e..a56402f 100644 --- a/dali-toolkit/internal/visuals/border/border-visual.cpp +++ b/dali-toolkit/internal/visuals/border/border-visual.cpp @@ -121,13 +121,13 @@ void BorderVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap Property::Value* color = propertyMap.Find( Toolkit::BorderVisual::Property::COLOR, COLOR_NAME ); if( !( color && color->Get(mBorderColor) ) ) { - DALI_LOG_ERROR( "Fail to provide a border color to the BorderVisual object" ); + DALI_LOG_ERROR( "Fail to provide a border color to the BorderVisual object\n" ); } Property::Value* size = propertyMap.Find( Toolkit::BorderVisual::Property::SIZE, SIZE_NAME ); if( !( size && size->Get(mBorderSize) ) ) { - DALI_LOG_ERROR( "Fail to provide a border size to the BorderVisual object" ); + DALI_LOG_ERROR( "Fail to provide a border size to the BorderVisual object\n" ); } Property::Value* antiAliasing = propertyMap.Find( Toolkit::BorderVisual::Property::ANTI_ALIASING, ANTI_ALIASING ); diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 1c32b40..17cf68a 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -80,7 +80,7 @@ void ColorVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) Property::Value* color = propertyMap.Find( Toolkit::ColorVisual::Property::MIX_COLOR, COLOR_NAME ); if( !( color && color->Get(mMixColor) ) ) { - DALI_LOG_ERROR( "Fail to provide a color to the ColorVisual object" ); + DALI_LOG_ERROR( "Fail to provide a color to the ColorVisual object\n" ); } } diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp index 1a4e604..22f9026 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp @@ -220,7 +220,7 @@ void GradientVisual::DoInitialize( Actor& actor, const Property::Map& propertyMa } else { - DALI_LOG_ERROR( "Fail to provide valid properties to create a GradientVisual object" ); + DALI_LOG_ERROR( "Fail to provide valid properties to create a GradientVisual object\n" ); } } diff --git a/dali-toolkit/internal/visuals/visual-base-data-impl.cpp b/dali-toolkit/internal/visuals/visual-base-data-impl.cpp index 4b9de21..f539dd6 100644 --- a/dali-toolkit/internal/visuals/visual-base-data-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-data-impl.cpp @@ -79,7 +79,7 @@ void Internal::Visual::Base::Impl::CustomShader::SetPropertyMap( const Property: { if( !vertexShaderValue->Get( mVertexShader ) ) { - DALI_LOG_ERROR( "'%s' parameter does not correctly specify a string", CUSTOM_VERTEX_SHADER ); + DALI_LOG_ERROR( "'%s' parameter does not correctly specify a string\n", CUSTOM_VERTEX_SHADER ); } } @@ -88,7 +88,7 @@ void Internal::Visual::Base::Impl::CustomShader::SetPropertyMap( const Property: { if( !fragmentShaderValue->Get( mFragmentShader ) ) { - DALI_LOG_ERROR( "'%s' parameter does not correctly specify a string", CUSTOM_FRAGMENT_SHADER ); + DALI_LOG_ERROR( "'%s' parameter does not correctly specify a string\n", CUSTOM_FRAGMENT_SHADER ); } } @@ -98,7 +98,7 @@ void Internal::Visual::Base::Impl::CustomShader::SetPropertyMap( const Property: int subdivideX; if( !subdivideXValue->Get( subdivideX ) || subdivideX < 1 ) { - DALI_LOG_ERROR( "'%s' parameter does not correctly specify a value greater than 1", CUSTOM_SUBDIVIDE_GRID_X ); + DALI_LOG_ERROR( "'%s' parameter does not correctly specify a value greater than 1\n", CUSTOM_SUBDIVIDE_GRID_X ); } else { @@ -112,7 +112,7 @@ void Internal::Visual::Base::Impl::CustomShader::SetPropertyMap( const Property: int subdivideY; if( !subdivideYValue->Get( subdivideY ) || subdivideY < 1 ) { - DALI_LOG_ERROR( "'%s' parameter does not correctly specify a value greater than 1", CUSTOM_SUBDIVIDE_GRID_Y ); + DALI_LOG_ERROR( "'%s' parameter does not correctly specify a value greater than 1\n", CUSTOM_SUBDIVIDE_GRID_Y ); } else { @@ -125,7 +125,7 @@ void Internal::Visual::Base::Impl::CustomShader::SetPropertyMap( const Property: { if ( ! Scripting::GetBitmaskEnumerationProperty( *hintsValue, SHADER_HINT_TABLE, SHADER_HINT_TABLE_COUNT, mHints ) ) { - DALI_LOG_ERROR( "'%s' parameter does not correctly specify a hint or an array of hint strings", CUSTOM_SHADER_HINTS ); + DALI_LOG_ERROR( "'%s' parameter does not correctly specify a hint or an array of hint strings\n", CUSTOM_SHADER_HINTS ); } } } diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index 2c79c27..f4677a7 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -221,7 +221,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property } else { - DALI_LOG_ERROR( "Renderer type unknown" ); + DALI_LOG_ERROR( "Renderer type unknown\n" ); } return Toolkit::Visual::Base( visualPtr ); diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index d19cb14..6eec362 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -52,6 +52,33 @@ namespace { /** + * Struct used to store Visual within the control, index is a unique key for each visual. + */ +struct RegisteredVisual +{ + Property::Index index; + Toolkit::Visual::Base visual; + Actor placementActor; + + RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, Actor &aPlacementActor) : index(aIndex), visual(aVisual), placementActor(aPlacementActor) {} +}; + +/** + * Finds visual in given array, returning true if found along with the iterator for that visual as a out parameter + */ +bool FindVisual( Property::Index targetIndex, std::vector& visuals, std::vector::iterator& iter ) +{ + for ( iter = visuals.begin(); iter != visuals.end(); iter++ ) + { + if ( (*iter).index == targetIndex ) + { + return true; + } + } + return false; +} + +/** * Creates control through type registry */ BaseHandle Create() @@ -367,6 +394,7 @@ public: // Data Control& mControlImpl; + std::vector mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used. std::string mStyleName; Toolkit::Visual::Base mBackgroundVisual; ///< The visual to render the background Vector4 mBackgroundColor; ///< The color of the background visual @@ -624,6 +652,44 @@ void Control::KeyboardEnter() OnKeyboardEnter(); } +void Control::RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual ) +{ + bool visualReplaced ( false ); + Actor actorToRegister; // Null actor, replaced if placement actor not Self + + if ( placementActor != Self() ) // Prevent increasing ref count if actor self + { + actorToRegister = placementActor; + } + + if ( !mImpl->mVisuals.empty() ) + { + std::vector::iterator iter; + // Check if visual (index) is already registered. Replace if so. + if ( FindVisual( index, mImpl->mVisuals, iter ) ) + { + (*iter).visual = visual; + (*iter).placementActor = actorToRegister; + visualReplaced = true; + } + } + + if ( !visualReplaced ) // New registration entry + { + RegisteredVisual newVisual = RegisteredVisual( index, visual, actorToRegister ); + mImpl->mVisuals.push_back( newVisual ); + } +} + +void Control::UnregisterVisual( Property::Index index ) +{ + std::vector< RegisteredVisual >::iterator iter; + if ( FindVisual( index, mImpl->mVisuals, iter ) ) + { + mImpl->mVisuals.erase( iter ); + } +} + bool Control::OnAccessibilityActivated() { return false; // Accessibility activation is not handled by default diff --git a/dali-toolkit/public-api/controls/control-impl.h b/dali-toolkit/public-api/controls/control-impl.h index 2353cea..e3d0676 100644 --- a/dali-toolkit/public-api/controls/control-impl.h +++ b/dali-toolkit/public-api/controls/control-impl.h @@ -42,6 +42,10 @@ namespace Toolkit class StyleManager; +namespace Visual +{ +class Base; +} namespace Internal { /** @@ -288,6 +292,27 @@ public: protected: // For derived classes to call /** + * @brief Register a visual by Property Index, linking an Actor to controlRenderer when required. + * In the case of the visual being an actor or control deeming controlRenderer not required then controlRenderer should be an empty handle. + * No parenting is done during registration, this should be done by derived class. + * + * @SINCE_1_1.46 + * + * @param[in] index The Property index of the visual, used to reference visual + * @param[in] placementActor The actor used to by the visual. + * @param[in] visual The visual to register + */ + void RegisterVisual( Property::Index index, Actor placementActor, Toolkit::Visual::Base visual ); + + /** + * @brief Erase the entry matching the given index from the list of registered visuals + * @param[in] index The Property index of the visual, used to reference visual + * + * @SINCE_1_1.46 + */ + void UnregisterVisual( Property::Index index ); + + /** * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal * * Should be called last by the control after it acts on the Input Focus change. diff --git a/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.cpp b/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.cpp index 398939e..eadaa49 100644 --- a/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.cpp +++ b/dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.cpp @@ -190,7 +190,7 @@ FixedRuler::FixedRuler(float spacing) { if(fabsf(mSpacing) <= Math::MACHINE_EPSILON_1) { - DALI_LOG_ERROR( "Page spacing too small (%f).", double(spacing) ); + DALI_LOG_ERROR( "Page spacing too small (%f).\n", double(spacing) ); mSpacing = spacing >= 0.0f ? Math::MACHINE_EPSILON_1 : -Math::MACHINE_EPSILON_1; } mType = Fixed; @@ -257,7 +257,7 @@ unsigned int FixedRuler::GetPageFromPosition(float position, bool wrap) const if(pagesPerVolume < 1u) { pagesPerVolume = 1u; - DALI_LOG_ERROR("Ruler domain(%f) is smaller than its spacing(%f).", mDomain.GetSize() * 1.0, mSpacing * 1.0 ); + DALI_LOG_ERROR("Ruler domain(%f) is smaller than its spacing(%f).\n", mDomain.GetSize() * 1.0, mSpacing * 1.0 ); } page %= pagesPerVolume; } diff --git a/plugins/dali-script-v8/src/rendering/texture-set-api.h b/plugins/dali-script-v8/src/rendering/texture-set-api.h index 8b4159d..a834d86 100644 --- a/plugins/dali-script-v8/src/rendering/texture-set-api.h +++ b/plugins/dali-script-v8/src/rendering/texture-set-api.h @@ -57,7 +57,6 @@ namespace TextureSetApi /** * TextureSet API see texture-set.h for a description */ - void SetImage( const v8::FunctionCallbackInfo< v8::Value >& args ); void SetSampler( const v8::FunctionCallbackInfo< v8::Value >& args ); }; // namespace TextureSetApi diff --git a/plugins/dali-script-v8/src/rendering/texture-set-wrapper.cpp b/plugins/dali-script-v8/src/rendering/texture-set-wrapper.cpp index 5296651..5f503ec 100644 --- a/plugins/dali-script-v8/src/rendering/texture-set-wrapper.cpp +++ b/plugins/dali-script-v8/src/rendering/texture-set-wrapper.cpp @@ -45,7 +45,6 @@ const ApiFunction TextureSetFunctionTable[]= * TextureSet API (in order of texture-set.h) **************************************/ - { "SetImage" , TextureSetApi::SetImage }, { "SetSampler" , TextureSetApi::SetSampler }, }; diff --git a/plugins/dali-script-v8/src/utils/v8-utils.cpp b/plugins/dali-script-v8/src/utils/v8-utils.cpp index 193836d..ce656c0 100644 --- a/plugins/dali-script-v8/src/utils/v8-utils.cpp +++ b/plugins/dali-script-v8/src/utils/v8-utils.cpp @@ -87,7 +87,7 @@ void LogError(const v8::FunctionCallbackInfo< v8::Value >& args) output += *utf8_value; output +="\n"; } - DALI_LOG_ERROR_NOFN( "JavaScript: %s",output.c_str() ); + DALI_LOG_ERROR_NOFN( "JavaScript: %s\n",output.c_str() ); } void GetFileContents(const std::string &fileName, std::string& contents)