2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/adaptor-framework/timer.h>
25 #include <dali/public-api/actors/image-actor.h>
26 #include <dali/public-api/actors/layer.h>
27 #include <dali/devel-api/actors/mesh-actor.h>
28 #include <dali/public-api/animation/constraint.h>
29 #include <dali/public-api/common/constants.h>
30 #include <dali/public-api/common/stage.h>
31 #include <dali/public-api/events/tap-gesture.h>
32 #include <dali/public-api/events/tap-gesture-detector.h>
33 #include <dali/public-api/events/touch-event.h>
34 #include <dali/public-api/events/pan-gesture.h>
35 #include <dali/public-api/events/pan-gesture-detector.h>
36 #include <dali/devel-api/geometry/mesh.h>
37 #include <dali/devel-api/geometry/mesh-data.h>
38 #include <dali/public-api/images/resource-image.h>
39 #include <dali/public-api/math/rect.h>
40 #include <dali/public-api/math/vector2.h>
41 #include <dali/public-api/math/vector4.h>
42 #include <dali/public-api/object/property-notification.h>
43 #include <dali/public-api/signals/connection-tracker.h>
46 #include <dali-toolkit/public-api/controls/control.h>
47 #include <dali-toolkit/public-api/controls/control-impl.h>
48 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
49 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
50 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
51 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
54 #define DECORATOR_DEBUG
64 #ifdef DECORATOR_DEBUG
65 Integration::Log::Filter* gLogFilter( Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_TEXT_DECORATOR") );
76 const char* DEFAULT_GRAB_HANDLE_IMAGE_RELEASED( DALI_IMAGE_DIR "insertpoint-icon.png" );
77 const char* DEFAULT_GRAB_HANDLE_IMAGE_PRESSED( DALI_IMAGE_DIR "insertpoint-icon-pressed.png" );
78 const char* DEFAULT_SELECTION_HANDLE_ONE_RELEASED( DALI_IMAGE_DIR "text-input-selection-handle-left.png" );
79 const char* DEFAULT_SELECTION_HANDLE_ONE_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-left-press.png" );
80 const char* DEFAULT_SELECTION_HANDLE_TWO_RELEASED( DALI_IMAGE_DIR "text-input-selection-handle-right.png" );
81 const char* DEFAULT_SELECTION_HANDLE_TWO_PRESSED( DALI_IMAGE_DIR "text-input-selection-handle-right-press.png" );
83 const int DEFAULT_POPUP_OFFSET( -100.0f ); // Vertical offset of Popup from cursor or handles position.
85 const Dali::Vector3 DEFAULT_GRAB_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f );
86 const Dali::Vector3 DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE( 1.25f, 1.5f, 1.0f );
88 const Dali::Vector4 LIGHT_BLUE( (0xb2 / 255.0f), (0xeb / 255.0f), (0xf2 / 255.0f), 0.5f ); // The text highlight color.
90 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
91 const float TO_MILLISECONDS = 1000.f;
92 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
94 const float DISPLAYED_HIGHLIGHT_Z_OFFSET( -0.05f );
96 const unsigned int SCROLL_TICK_INTERVAL = 50u;
98 const float SCROLL_THRESHOLD = 10.f;
99 const float SCROLL_SPEED = 300.f;
100 const float SCROLL_DISTANCE = SCROLL_SPEED * SCROLL_TICK_INTERVAL * TO_SECONDS;
103 * structure to hold coordinates of each quad, which will make up the mesh.
105 struct QuadCoordinates
108 * Default constructor
116 * @param[in] x1 left co-ordinate
117 * @param[in] y1 top co-ordinate
118 * @param[in] x2 right co-ordinate
119 * @param[in] y2 bottom co-ordinate
121 QuadCoordinates(float x1, float y1, float x2, float y2)
127 Dali::Vector2 min; ///< top-left (minimum) position of quad
128 Dali::Vector2 max; ///< bottom-right (maximum) position of quad
131 typedef std::vector<QuadCoordinates> QuadContainer;
134 * @brief Takes a bounding rectangle in the local coordinates of an actor and returns the world coordinates Bounding Box.
135 * @param[in] boundingRectangle local bounding
136 * @param[out] Vector4 World coordinate bounding Box.
138 void LocalToWorldCoordinatesBoundingBox( const Dali::Rect<int>& boundingRectangle, Dali::Vector4& boundingBox )
140 // Convert to world coordinates and store as a Vector4 to be compatible with Property Notifications.
141 Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
143 const float originX = boundingRectangle.x - 0.5f * stageSize.width;
144 const float originY = boundingRectangle.y - 0.5f * stageSize.height;
146 boundingBox = Dali::Vector4( originX,
148 originX + boundingRectangle.width,
149 originY + boundingRectangle.height );
153 } // end of namespace
164 struct Decorator::Impl : public ConnectionTracker
178 : color( Dali::Color::BLACK ),
180 cursorHeight( 0.0f ),
196 grabDisplacementX( 0.f ),
197 grabDisplacementY( 0.f ),
209 float lineHeight; ///< Not the handle height
210 float grabDisplacementX;
211 float grabDisplacementY;
222 offset( DEFAULT_POPUP_OFFSET )
226 TextSelectionPopup actor;
231 Impl( ControllerInterface& controller,
232 TextSelectionPopupCallbackInterface& callbackInterface )
233 : mController( controller ),
234 mEnabledPopupButtons( TextSelectionPopup::NONE ),
235 mTextSelectionPopupCallbackInterface( callbackInterface ),
236 mBoundingBox( Rect<int>() ),
237 mHighlightColor( LIGHT_BLUE ),
238 mActiveCursor( ACTIVE_CURSOR_NONE ),
239 mCursorBlinkInterval( CURSOR_BLINK_INTERVAL ),
240 mCursorBlinkDuration( 0.0f ),
241 mHandleScrolling( HANDLE_TYPE_COUNT ),
242 mScrollDirection( SCROLL_NONE ),
243 mScrollThreshold( SCROLL_THRESHOLD ),
244 mScrollSpeed( SCROLL_SPEED ),
245 mScrollDistance( SCROLL_DISTANCE ),
246 mActiveCopyPastePopup( false ),
247 mCursorBlinkStatus( true ),
248 mPrimaryCursorVisible( false ),
249 mSecondaryCursorVisible( false ),
250 mSwapSelectionHandles( false )
255 * Relayout of the decorations owned by the decorator.
256 * @param[in] size The Size of the UI control the decorator is adding it's decorations to.
258 void Relayout( const Vector2& size )
260 // TODO - Remove this if nothing is active
263 // Show or hide the cursors
267 const CursorImpl& cursor = mCursor[PRIMARY_CURSOR];
268 mPrimaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
269 if( mPrimaryCursorVisible )
271 Vector2 position = cursor.position;
272 if( GRAB_HANDLE == mHandleScrolling )
274 if( mScrollDirection == SCROLL_RIGHT )
280 position.x = size.width;
284 mPrimaryCursor.SetPosition( position.x,
286 mPrimaryCursor.SetSize( Size( 1.0f, cursor.cursorHeight ) );
288 mPrimaryCursor.SetVisible( mPrimaryCursorVisible );
290 if( mSecondaryCursor )
292 const CursorImpl& cursor = mCursor[SECONDARY_CURSOR];
293 mSecondaryCursorVisible = ( cursor.position.x <= size.width ) && ( cursor.position.x >= 0.f );
294 if( mSecondaryCursorVisible )
296 mSecondaryCursor.SetPosition( cursor.position.x,
298 mSecondaryCursor.SetSize( Size( 1.0f, cursor.cursorHeight ) );
300 mSecondaryCursor.SetVisible( mSecondaryCursorVisible );
303 // Show or hide the grab handle
304 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
305 if( grabHandle.active )
307 Vector2 position = grabHandle.position;
309 if( GRAB_HANDLE == mHandleScrolling )
311 if( mScrollDirection == SCROLL_RIGHT )
317 position.x = size.width;
321 const bool isVisible = ( position.x <= size.width ) && ( position.x >= 0.f );
329 grabHandle.actor.SetPosition( position.x,
330 position.y + grabHandle.lineHeight );
332 grabHandle.actor.SetVisible( isVisible );
334 else if( grabHandle.actor )
336 UnparentAndReset( grabHandle.actor );
339 // Show or hide the selection handles/highlight
340 HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
341 HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
342 if( primary.active || secondary.active )
344 Vector2 primaryPosition = primary.position;
345 Vector2 secondaryPosition = secondary.position;
347 if( LEFT_SELECTION_HANDLE == mHandleScrolling )
349 if( mScrollDirection == SCROLL_RIGHT )
351 primaryPosition.x = 0.f;
355 primaryPosition.x = size.width;
358 else if( RIGHT_SELECTION_HANDLE == mHandleScrolling )
360 if( mScrollDirection == SCROLL_RIGHT )
362 secondaryPosition.x = 0.f;
366 secondaryPosition.x = size.width;
370 const bool isPrimaryVisible = ( primaryPosition.x <= size.width ) && ( primaryPosition.x >= 0.f );
371 const bool isSecondaryVisible = ( secondaryPosition.x <= size.width ) && ( secondaryPosition.x >= 0.f );
373 if( isPrimaryVisible || isSecondaryVisible )
377 CreateSelectionHandles();
379 if( isPrimaryVisible )
381 primary.actor.SetPosition( primaryPosition.x,
382 primaryPosition.y + primary.lineHeight );
385 if( isSecondaryVisible )
387 secondary.actor.SetPosition( secondaryPosition.x,
388 secondaryPosition.y + secondary.lineHeight );
391 primary.actor.SetVisible( isPrimaryVisible );
392 secondary.actor.SetVisible( isSecondaryVisible );
399 UnparentAndReset( primary.actor );
400 UnparentAndReset( secondary.actor );
401 UnparentAndReset( mHighlightMeshActor );
404 if ( mActiveCopyPastePopup )
406 // todo Swap UnparentAndReset for DeterminePositionPopup() if mCopyPastePopup.actor valid Once the issue with the labels disappearing is fixed.
407 UnparentAndReset( mCopyPastePopup.actor );
408 if ( !mCopyPastePopup.actor )
410 mCopyPastePopup.actor = TextSelectionPopup::New( mEnabledPopupButtons, &mTextSelectionPopupCallbackInterface );
411 #ifdef DECORATOR_DEBUG
412 mCopyPastePopup.actor.SetName("mCopyPastePopup");
414 mCopyPastePopup.actor.SetAnchorPoint( AnchorPoint::CENTER );
415 mCopyPastePopup.actor.OnRelayoutSignal().Connect( this, &Decorator::Impl::PopupRelayoutComplete ); // Position popup after size negotiation
416 mActiveLayer.Add ( mCopyPastePopup.actor );
421 if ( mCopyPastePopup.actor )
423 UnparentAndReset( mCopyPastePopup.actor );
428 void UpdatePositions( const Vector2& scrollOffset )
430 mCursor[PRIMARY_CURSOR].position += scrollOffset;
431 mCursor[SECONDARY_CURSOR].position += scrollOffset;
432 mHandle[ GRAB_HANDLE ].position += scrollOffset;
433 mHandle[ LEFT_SELECTION_HANDLE ].position += scrollOffset;
434 mHandle[ RIGHT_SELECTION_HANDLE ].position += scrollOffset;
435 mHighlightPosition += scrollOffset;
438 void DeterminePositionPopup()
440 if ( !mActiveCopyPastePopup )
445 if ( mHandle[LEFT_SELECTION_HANDLE].active || mHandle[RIGHT_SELECTION_HANDLE].active )
447 float minHandleXPosition = std::min ( mHandle[LEFT_SELECTION_HANDLE].position.x, mHandle[RIGHT_SELECTION_HANDLE].position.x );
448 float maxHandleXPosition = std::max ( mHandle[LEFT_SELECTION_HANDLE].position.x, mHandle[RIGHT_SELECTION_HANDLE].position.x );
450 float minHandleYPosition = std::min ( mHandle[LEFT_SELECTION_HANDLE].position.y, mHandle[RIGHT_SELECTION_HANDLE].position.y );
452 mCopyPastePopup.position.x = minHandleXPosition + ( ( maxHandleXPosition - minHandleXPosition ) *0.5f );
453 mCopyPastePopup.position.y = minHandleYPosition + mCopyPastePopup.offset;
457 mCopyPastePopup.position = Vector3( mCursor[PRIMARY_CURSOR].position.x, mCursor[PRIMARY_CURSOR].position.y -100.0f , 0.0f ); //todo 100 to be an offset Property
460 Vector3 popupSize = Vector3( mCopyPastePopup.actor.GetRelayoutSize( Dimension::WIDTH ), mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT ), 0.0f );
462 GetConstrainedPopupPosition( mCopyPastePopup.position, popupSize, AnchorPoint::CENTER, mActiveLayer, mBoundingBox );
464 SetUpPopupPositionNotifications();
466 mCopyPastePopup.actor.SetPosition( mCopyPastePopup.position );
469 void PopupRelayoutComplete( Actor actor )
471 // Size negotiation for CopyPastePopup complete so can get the size and constrain position within bounding box.
472 mCopyPastePopup.actor.OnRelayoutSignal().Disconnect( this, &Decorator::Impl::PopupRelayoutComplete );
474 DeterminePositionPopup();
477 void CreateCursor( ImageActor& cursor, const Vector4& color )
479 cursor = CreateSolidColorActor( color );
480 cursor.SetParentOrigin( ParentOrigin::TOP_LEFT ); // Need to set the default parent origin as CreateSolidColorActor() sets a different one.
481 cursor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
484 // Add or Remove cursor(s) from parent
487 if( mActiveCursor == ACTIVE_CURSOR_NONE )
489 UnparentAndReset( mPrimaryCursor );
490 UnparentAndReset( mSecondaryCursor );
494 /* Create Primary and or Secondary Cursor(s) if active and add to parent */
495 if ( mActiveCursor == ACTIVE_CURSOR_PRIMARY ||
496 mActiveCursor == ACTIVE_CURSOR_BOTH )
498 if ( !mPrimaryCursor )
500 CreateCursor( mPrimaryCursor, mCursor[PRIMARY_CURSOR].color );
501 #ifdef DECORATOR_DEBUG
502 mPrimaryCursor.SetName( "PrimaryCursorActor" );
504 mActiveLayer.Add( mPrimaryCursor );
508 if ( mActiveCursor == ACTIVE_CURSOR_BOTH )
510 if ( !mSecondaryCursor )
512 CreateCursor( mSecondaryCursor, mCursor[SECONDARY_CURSOR].color );
513 #ifdef DECORATOR_DEBUG
514 mSecondaryCursor.SetName( "SecondaryCursorActor" );
516 mActiveLayer.Add( mSecondaryCursor );
521 UnparentAndReset( mSecondaryCursor );
526 bool OnCursorBlinkTimerTick()
529 if ( mPrimaryCursor )
531 mPrimaryCursor.SetVisible( mPrimaryCursorVisible && mCursorBlinkStatus );
533 if ( mSecondaryCursor )
535 mSecondaryCursor.SetVisible( mSecondaryCursorVisible && mCursorBlinkStatus );
538 mCursorBlinkStatus = !mCursorBlinkStatus;
543 void SetupTouchEvents()
547 mTapDetector = TapGestureDetector::New();
548 mTapDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnTap );
551 if ( !mPanGestureDetector )
553 mPanGestureDetector = PanGestureDetector::New();
554 mPanGestureDetector.DetectedSignal().Connect( this, &Decorator::Impl::OnPan );
558 void CreateActiveLayer()
562 mActiveLayer = Layer::New();
563 #ifdef DECORATOR_DEBUG
564 mActiveLayer.SetName ( "ActiveLayerActor" );
567 mActiveLayer.SetParentOrigin( ParentOrigin::CENTER );
568 mActiveLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
569 mActiveLayer.SetPositionInheritanceMode( USE_PARENT_POSITION );
571 // Add the active layer telling the controller it doesn't need clipping.
572 mController.AddDecoration( mActiveLayer, false );
575 mActiveLayer.RaiseToTop();
578 void CreateGrabHandle()
580 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
581 if( !grabHandle.actor )
583 if( !mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] )
585 mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE_RELEASED );
587 if( !mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED] )
589 mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED] = ResourceImage::New( DEFAULT_GRAB_HANDLE_IMAGE_PRESSED );
592 grabHandle.actor = ImageActor::New( mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED] );
593 grabHandle.actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
594 grabHandle.actor.SetDrawMode( DrawMode::OVERLAY );
595 // Area that Grab handle responds to, larger than actual handle so easier to move
596 #ifdef DECORATOR_DEBUG
597 grabHandle.actor.SetName( "GrabHandleActor" );
598 if ( Dali::Internal::gLogFilter->IsEnabledFor( Debug::Verbose ) )
600 grabHandle.grabArea = Toolkit::CreateSolidColorActor( Vector4(0.0f, 0.0f, 0.0f, 0.0f), true, Color::RED, 1 );
601 grabHandle.grabArea.SetName( "GrabArea" );
605 grabHandle.grabArea = Actor::New();
606 grabHandle.grabArea.SetName( "GrabArea" );
609 grabHandle.grabArea = Actor::New();
612 grabHandle.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
613 grabHandle.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
614 grabHandle.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
615 grabHandle.grabArea.SetSizeModeFactor( DEFAULT_GRAB_HANDLE_RELATIVE_SIZE );
616 grabHandle.actor.Add( grabHandle.grabArea );
618 grabHandle.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnGrabHandleTouched );
619 mTapDetector.Attach( grabHandle.grabArea );
620 mPanGestureDetector.Attach( grabHandle.grabArea );
622 mActiveLayer.Add( grabHandle.actor );
626 void CreateSelectionHandles()
628 HandleImpl& primary = mHandle[ LEFT_SELECTION_HANDLE ];
631 if( !mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] )
633 mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_ONE_RELEASED );
635 if( !mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] )
637 mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_ONE_PRESSED );
640 primary.actor = ImageActor::New( mHandleImages[LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
641 #ifdef DECORATOR_DEBUG
642 primary.actor.SetName("SelectionHandleOne");
644 primary.actor.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); // Change to BOTTOM_RIGHT if Look'n'Feel requires handle above text.
645 primary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
646 primary.flipped = false;
648 primary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
649 #ifdef DECORATOR_DEBUG
650 primary.grabArea.SetName("SelectionHandleOneGrabArea");
652 primary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
653 primary.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
654 primary.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
655 primary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
657 mTapDetector.Attach( primary.grabArea );
658 mPanGestureDetector.Attach( primary.grabArea );
659 primary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleOneTouched );
661 primary.actor.Add( primary.grabArea );
662 mActiveLayer.Add( primary.actor );
665 HandleImpl& secondary = mHandle[ RIGHT_SELECTION_HANDLE ];
666 if( !secondary.actor )
668 if( !mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] )
670 mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_TWO_RELEASED );
672 if( !mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] )
674 mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED] = ResourceImage::New( DEFAULT_SELECTION_HANDLE_TWO_PRESSED );
677 secondary.actor = ImageActor::New( mHandleImages[RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED] );
678 #ifdef DECORATOR_DEBUG
679 secondary.actor.SetName("SelectionHandleTwo");
681 secondary.actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // Change to BOTTOM_LEFT if Look'n'Feel requires handle above text.
682 secondary.actor.SetDrawMode( DrawMode::OVERLAY ); // ensure grab handle above text
683 secondary.flipped = false;
685 secondary.grabArea = Actor::New(); // Area that Grab handle responds to, larger than actual handle so easier to move
686 #ifdef DECORATOR_DEBUG
687 secondary.grabArea.SetName("SelectionHandleTwoGrabArea");
689 secondary.grabArea.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
690 secondary.grabArea.SetParentOrigin( ParentOrigin::TOP_CENTER );
691 secondary.grabArea.SetAnchorPoint( AnchorPoint::TOP_CENTER );
692 secondary.grabArea.SetSizeModeFactor( DEFAULT_SELECTION_HANDLE_RELATIVE_SIZE );
694 mTapDetector.Attach( secondary.grabArea );
695 mPanGestureDetector.Attach( secondary.grabArea );
696 secondary.grabArea.TouchedSignal().Connect( this, &Decorator::Impl::OnHandleTwoTouched );
698 secondary.actor.Add( secondary.grabArea );
699 mActiveLayer.Add( secondary.actor );
703 void CreateHighlight()
705 if ( !mHighlightMeshActor )
707 mHighlightMaterial = Material::New( "HighlightMaterial" );
708 mHighlightMaterial.SetDiffuseColor( mHighlightColor );
710 mHighlightMeshData.SetMaterial( mHighlightMaterial );
711 mHighlightMeshData.SetHasNormals( true );
713 mHighlightMesh = Mesh::New( mHighlightMeshData );
715 mHighlightMeshActor = MeshActor::New( mHighlightMesh );
716 #ifdef DECORATOR_DEBUG
717 mHighlightMeshActor.SetName( "HighlightMeshActor" );
719 mHighlightMeshActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
721 // Add the highlight box telling the controller it needs clipping.
722 mController.AddDecoration( mHighlightMeshActor, true );
725 mHighlightMeshActor.SetPosition( mHighlightPosition.x, mHighlightPosition.y, DISPLAYED_HIGHLIGHT_Z_OFFSET );
728 void UpdateHighlight()
730 // Construct a Mesh with a texture to be used as the highlight 'box' for selected text
732 // Example scenarios where mesh is made from 3, 1, 2, 2 ,3 or 3 quads.
734 // [ TOP ] [ TOP ] [TOP ] [ TOP ] [ TOP ] [ TOP ]
735 // [ MIDDLE ] [BOTTOM] [BOTTOM] [ MIDDLE ] [ MIDDLE ]
736 // [ BOTTOM] [ MIDDLE ] [ MIDDLE ]
737 // [BOTTOM] [ MIDDLE ]
740 // Each quad is created as 2 triangles.
741 // Middle is just 1 quad regardless of its size.
755 if ( mHighlightMesh && mHighlightMaterial && !mHighlightQuadList.empty() )
757 MeshData::VertexContainer vertices;
758 Dali::MeshData::FaceIndices faceIndices;
760 std::vector<QuadCoordinates>::iterator iter = mHighlightQuadList.begin();
761 std::vector<QuadCoordinates>::iterator endIter = mHighlightQuadList.end();
763 // vertex position defaults to (0 0 0)
764 MeshData::Vertex vertex;
765 // set normal for all vertices as (0 0 1) pointing outward from TextInput Actor.
768 for(std::size_t v = 0; iter != endIter; ++iter,v+=4 )
770 // Add each quad geometry (a sub-selection) to the mesh data.
780 QuadCoordinates& quad = *iter;
782 vertex.x = quad.min.x;
783 vertex.y = quad.min.y;
784 vertices.push_back( vertex );
787 vertex.x = quad.max.x;
788 vertex.y = quad.min.y;
789 vertices.push_back( vertex );
792 vertex.x = quad.min.x;
793 vertex.y = quad.max.y;
794 vertices.push_back( vertex );
796 // bottom-right (v+3)
797 vertex.x = quad.max.x;
798 vertex.y = quad.max.y;
799 vertices.push_back( vertex );
801 // triangle A (3, 1, 0)
802 faceIndices.push_back( v + 3 );
803 faceIndices.push_back( v + 1 );
804 faceIndices.push_back( v );
806 // triangle B (0, 2, 3)
807 faceIndices.push_back( v );
808 faceIndices.push_back( v + 2 );
809 faceIndices.push_back( v + 3 );
811 mHighlightMeshData.SetFaceIndices( faceIndices );
814 BoneContainer bones(0); // passed empty as bones not required
815 mHighlightMeshData.SetData( vertices, faceIndices, bones, mHighlightMaterial );
816 mHighlightMesh.UpdateMeshData( mHighlightMeshData );
820 void OnTap( Actor actor, const TapGesture& tap )
822 if( actor == mHandle[GRAB_HANDLE].actor )
828 void DoPan( HandleImpl& handle, HandleType type, const PanGesture& gesture )
830 if( Gesture::Started == gesture.state )
832 handle.grabDisplacementX = handle.grabDisplacementY = 0;
835 handle.grabDisplacementX += gesture.displacement.x;
836 handle.grabDisplacementY += gesture.displacement.y;
838 const float x = handle.position.x + handle.grabDisplacementX;
839 const float y = handle.position.y + handle.lineHeight*0.5f + handle.grabDisplacementY;
841 if( Gesture::Started == gesture.state ||
842 Gesture::Continuing == gesture.state )
845 mController.GetTargetSize( targetSize );
847 if( x < mScrollThreshold )
849 mScrollDirection = SCROLL_RIGHT;
850 mHandleScrolling = type;
853 else if( x > targetSize.width - mScrollThreshold )
855 mScrollDirection = SCROLL_LEFT;
856 mHandleScrolling = type;
861 mHandleScrolling = HANDLE_TYPE_COUNT;
863 mController.DecorationEvent( type, HANDLE_PRESSED, x, y );
866 else if( Gesture::Finished == gesture.state ||
867 Gesture::Cancelled == gesture.state )
869 if( mScrollTimer && mScrollTimer.IsRunning() )
871 mHandleScrolling = HANDLE_TYPE_COUNT;
873 mController.DecorationEvent( type, HANDLE_STOP_SCROLLING, x, y );
877 mController.DecorationEvent( type, HANDLE_RELEASED, x, y );
880 if( GRAB_HANDLE == type )
882 handle.actor.SetImage( mHandleImages[type][HANDLE_IMAGE_RELEASED] );
886 HandleType selectionHandleType = type;
888 if( mSwapSelectionHandles != handle.flipped )
890 selectionHandleType = ( LEFT_SELECTION_HANDLE == type ) ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE;
893 handle.actor.SetImage( mHandleImages[selectionHandleType][HANDLE_IMAGE_RELEASED] );
895 handle.pressed = false;
899 void OnPan( Actor actor, const PanGesture& gesture )
901 HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
902 HandleImpl& primarySelectionHandle = mHandle[LEFT_SELECTION_HANDLE];
903 HandleImpl& secondarySelectionHandle = mHandle[RIGHT_SELECTION_HANDLE];
905 if( actor == grabHandle.grabArea )
907 DoPan( grabHandle, GRAB_HANDLE, gesture );
909 else if( actor == primarySelectionHandle.grabArea )
911 DoPan( primarySelectionHandle, LEFT_SELECTION_HANDLE, gesture );
913 else if( actor == secondarySelectionHandle.grabArea )
915 DoPan( secondarySelectionHandle, RIGHT_SELECTION_HANDLE, gesture );
919 bool OnGrabHandleTouched( Actor actor, const TouchEvent& event )
921 // Switch between pressed/release grab-handle images
922 if( event.GetPointCount() > 0 &&
923 mHandle[GRAB_HANDLE].actor )
925 const TouchPoint& point = event.GetPoint(0);
927 if( TouchPoint::Down == point.state )
929 mHandle[GRAB_HANDLE].pressed = true;
930 Image imagePressed = mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_PRESSED];
933 mHandle[GRAB_HANDLE].actor.SetImage( imagePressed );
936 else if( TouchPoint::Up == point.state )
938 mHandle[GRAB_HANDLE].pressed = false;
939 Image imageReleased = mHandleImages[GRAB_HANDLE][HANDLE_IMAGE_RELEASED];
942 mHandle[GRAB_HANDLE].actor.SetImage( imageReleased );
947 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
951 bool OnHandleOneTouched( Actor actor, const TouchEvent& event )
953 // Switch between pressed/release selection handle images
954 if( event.GetPointCount() > 0 &&
955 mHandle[LEFT_SELECTION_HANDLE].actor )
957 const TouchPoint& point = event.GetPoint(0);
959 const bool flip = mSwapSelectionHandles != mHandle[LEFT_SELECTION_HANDLE].flipped;
960 if( TouchPoint::Down == point.state )
962 mHandle[LEFT_SELECTION_HANDLE].pressed = true;
963 Image imagePressed = mHandleImages[flip ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED];
966 mHandle[LEFT_SELECTION_HANDLE].actor.SetImage( imagePressed );
969 else if( TouchPoint::Up == point.state )
971 mHandle[LEFT_SELECTION_HANDLE].pressed = false;
972 Image imageReleased = mHandleImages[flip ? RIGHT_SELECTION_HANDLE : LEFT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED];
975 mHandle[LEFT_SELECTION_HANDLE].actor.SetImage( imageReleased );
980 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
984 bool OnHandleTwoTouched( Actor actor, const TouchEvent& event )
986 // Switch between pressed/release selection handle images
987 if( event.GetPointCount() > 0 &&
988 mHandle[RIGHT_SELECTION_HANDLE].actor )
990 const TouchPoint& point = event.GetPoint(0);
992 const bool flip = mSwapSelectionHandles != mHandle[RIGHT_SELECTION_HANDLE].flipped;
993 if( TouchPoint::Down == point.state )
995 Image imagePressed = mHandleImages[flip ? LEFT_SELECTION_HANDLE : RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_PRESSED];
996 mHandle[RIGHT_SELECTION_HANDLE].pressed = true;
999 mHandle[RIGHT_SELECTION_HANDLE].actor.SetImage( imagePressed );
1002 else if( TouchPoint::Up == point.state )
1004 Image imageReleased = mHandleImages[flip ? LEFT_SELECTION_HANDLE : RIGHT_SELECTION_HANDLE][HANDLE_IMAGE_RELEASED];
1005 mHandle[RIGHT_SELECTION_HANDLE].pressed = false;
1008 mHandle[RIGHT_SELECTION_HANDLE].actor.SetImage( imageReleased );
1013 // Consume to avoid pop-ups accidentally closing, when handle is outside of pop-up area
1019 float AlternatePopUpPositionRelativeToCursor()
1021 float alternativePosition=0.0f;;
1023 if ( mPrimaryCursor ) // Secondary cursor not used for paste
1025 Cursor cursor = PRIMARY_CURSOR;
1026 alternativePosition = mCursor[cursor].position.y;
1029 const float popupHeight = 120.0f; // todo Set as a MaxSize Property in Control or retrieve from CopyPastePopup class.
1031 if( mHandle[GRAB_HANDLE].active )
1033 // If grab handle enabled then position pop-up below the grab handle.
1034 const Vector2 grabHandleSize( 59.0f, 56.0f ); // todo
1035 const float BOTTOM_HANDLE_BOTTOM_OFFSET = 1.5; //todo Should be a property
1036 alternativePosition += grabHandleSize.height + popupHeight + BOTTOM_HANDLE_BOTTOM_OFFSET ;
1040 alternativePosition += popupHeight;
1043 return alternativePosition;
1046 void PopUpLeavesVerticalBoundary( PropertyNotification& source )
1048 float alternativeYPosition=0.0f;
1049 // todo use AlternatePopUpPositionRelativeToSelectionHandles() if text is highlighted
1050 // if can't be positioned above, then position below row.
1051 alternativeYPosition = AlternatePopUpPositionRelativeToCursor();
1053 mCopyPastePopup.actor.SetY( alternativeYPosition );
1057 void SetUpPopupPositionNotifications( )
1059 // Note Property notifications ignore any set anchor point so conditions must allow for this. Default is Top Left.
1061 // Exceeding vertical boundary
1063 Vector4 worldCoordinatesBoundingBox;
1064 LocalToWorldCoordinatesBoundingBox( mBoundingBox, worldCoordinatesBoundingBox );
1066 float popupHeight = mCopyPastePopup.actor.GetRelayoutSize( Dimension::HEIGHT);
1068 PropertyNotification verticalExceedNotification = mCopyPastePopup.actor.AddPropertyNotification( Actor::Property::WORLD_POSITION_Y,
1069 OutsideCondition( worldCoordinatesBoundingBox.y + popupHeight * 0.5f,
1070 worldCoordinatesBoundingBox.w - popupHeight * 0.5f ) );
1072 verticalExceedNotification.NotifySignal().Connect( this, &Decorator::Impl::PopUpLeavesVerticalBoundary );
1075 void GetConstrainedPopupPosition( Vector3& requiredPopupPosition, Vector3& popupSize, Vector3 anchorPoint, Actor& parent, Rect<int>& boundingBox )
1077 DALI_ASSERT_DEBUG ( "Popup parent not on stage" && parent.OnStage() )
1079 // Parent must already by added to Stage for these Get calls to work
1080 Vector3 parentAnchorPoint = parent.GetCurrentAnchorPoint();
1081 Vector3 parentWorldPositionLeftAnchor = parent.GetCurrentWorldPosition() - parent.GetCurrentSize()*parentAnchorPoint;
1082 Vector3 popupWorldPosition = parentWorldPositionLeftAnchor + requiredPopupPosition; // Parent World position plus popup local position gives World Position
1083 Vector3 popupDistanceFromAnchorPoint = popupSize*anchorPoint;
1085 // Bounding rectangle is supplied as screen coordinates, bounding will be done in world coordinates.
1086 Vector4 boundingRectangleWorld;
1087 LocalToWorldCoordinatesBoundingBox( boundingBox, boundingRectangleWorld );
1089 // Calculate distance to move popup (in local space) so fits within the boundary
1090 float xOffSetToKeepWithinBounds = 0.0f;
1091 if( popupWorldPosition.x - popupDistanceFromAnchorPoint.x < boundingRectangleWorld.x )
1093 xOffSetToKeepWithinBounds = boundingRectangleWorld.x - ( popupWorldPosition.x - popupDistanceFromAnchorPoint.x );
1095 else if ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x > boundingRectangleWorld.z )
1097 xOffSetToKeepWithinBounds = boundingRectangleWorld.z - ( popupWorldPosition.x + popupDistanceFromAnchorPoint.x );
1100 // Ensure initial display of Popup is in alternative position if can not fit above. As Property notification will be a frame behind.
1101 if ( popupWorldPosition.y - popupDistanceFromAnchorPoint.y < boundingRectangleWorld.y )
1103 requiredPopupPosition.y = AlternatePopUpPositionRelativeToCursor();
1106 requiredPopupPosition.x = requiredPopupPosition.x + xOffSetToKeepWithinBounds;
1108 // Prevent pixel mis-alignment by rounding down.
1109 requiredPopupPosition.x = static_cast<int>( requiredPopupPosition.x );
1110 requiredPopupPosition.y = static_cast<int>( requiredPopupPosition.y );
1114 void FlipSelectionHandleImages()
1118 CreateSelectionHandles();
1120 HandleImpl& leftHandle = mHandle[LEFT_SELECTION_HANDLE];
1121 HandleImpl& rightHandle = mHandle[RIGHT_SELECTION_HANDLE];
1123 const HandleImageType leftImageType = leftHandle.pressed ? HANDLE_IMAGE_PRESSED : HANDLE_IMAGE_RELEASED;
1124 const HandleImageType rightImageType = rightHandle.pressed ? HANDLE_IMAGE_PRESSED : HANDLE_IMAGE_RELEASED;
1125 const bool leftFlipped = mSwapSelectionHandles != leftHandle.flipped;
1126 const bool rightFlipped = mSwapSelectionHandles != rightHandle.flipped;
1128 leftHandle.actor.SetImage( leftFlipped ? mHandleImages[RIGHT_SELECTION_HANDLE][leftImageType] : mHandleImages[LEFT_SELECTION_HANDLE][leftImageType] );
1130 leftHandle.actor.SetAnchorPoint( leftFlipped ? AnchorPoint::TOP_LEFT : AnchorPoint::TOP_RIGHT );
1132 rightHandle.actor.SetImage( rightFlipped ? mHandleImages[LEFT_SELECTION_HANDLE][rightImageType] : mHandleImages[RIGHT_SELECTION_HANDLE][rightImageType] );
1134 rightHandle.actor.SetAnchorPoint( rightFlipped ? AnchorPoint::TOP_RIGHT : AnchorPoint::TOP_LEFT );
1137 void SetScrollThreshold( float threshold )
1139 mScrollThreshold = threshold;
1142 float GetScrollThreshold() const
1144 return mScrollThreshold;
1147 void SetScrollSpeed( float speed )
1149 mScrollSpeed = speed;
1150 mScrollDistance = speed * SCROLL_TICK_INTERVAL * TO_SECONDS;
1153 float GetScrollSpeed() const
1155 return mScrollSpeed;
1159 * Creates and starts a timer to scroll the text when handles are close to the edges of the text.
1161 * It only starts the timer if it's already created.
1163 void StartScrollTimer()
1167 mScrollTimer = Timer::New( SCROLL_TICK_INTERVAL );
1168 mScrollTimer.TickSignal().Connect( this, &Decorator::Impl::OnScrollTimerTick );
1171 if( !mScrollTimer.IsRunning() )
1173 mScrollTimer.Start();
1178 * Stops the timer used to scroll the text.
1180 void StopScrollTimer()
1184 mScrollTimer.Stop();
1189 * Callback called by the timer used to scroll the text.
1191 * It calculates and sets a new scroll position.
1193 bool OnScrollTimerTick()
1195 if( HANDLE_TYPE_COUNT != mHandleScrolling )
1197 mController.DecorationEvent( mHandleScrolling,
1199 mScrollDirection == SCROLL_RIGHT ? mScrollDistance : -mScrollDistance,
1206 ControllerInterface& mController;
1208 TapGestureDetector mTapDetector;
1209 PanGestureDetector mPanGestureDetector;
1210 Timer mCursorBlinkTimer; ///< Timer to signal cursor to blink
1211 Timer mScrollTimer; ///< Timer used to scroll the text when the grab handle is moved close to the edges.
1213 Layer mActiveLayer; ///< Layer for active handles and alike that ensures they are above all else.
1214 ImageActor mPrimaryCursor;
1215 ImageActor mSecondaryCursor;
1216 MeshActor mHighlightMeshActor; ///< Mesh Actor to display highlight
1218 PopupImpl mCopyPastePopup;
1219 TextSelectionPopup::Buttons mEnabledPopupButtons; /// Bit mask of currently enabled Popup buttons
1220 TextSelectionPopupCallbackInterface& mTextSelectionPopupCallbackInterface;
1222 Image mHandleImages[HANDLE_TYPE_COUNT][HANDLE_IMAGE_TYPE_COUNT];
1224 Mesh mHighlightMesh; ///< Mesh for highlight
1225 MeshData mHighlightMeshData; ///< Mesh Data for highlight
1226 Material mHighlightMaterial; ///< Material used for highlight
1228 CursorImpl mCursor[CURSOR_COUNT];
1229 HandleImpl mHandle[HANDLE_TYPE_COUNT];
1230 QuadContainer mHighlightQuadList; ///< Sub-selections that combine to create the complete selection highlight
1231 Vector2 mHighlightPosition; ///< The position of the highlight actor.
1233 Rect<int> mBoundingBox;
1234 Vector4 mHighlightColor; ///< Color of the highlight
1236 unsigned int mActiveCursor;
1237 unsigned int mCursorBlinkInterval;
1238 float mCursorBlinkDuration;
1239 HandleType mHandleScrolling; ///< The handle which is scrolling.
1240 ScrollDirection mScrollDirection; ///< The direction of the scroll.
1241 float mScrollThreshold; ///< Defines a square area inside the control, close to the edge. A cursor entering this area will trigger scroll events.
1242 float mScrollSpeed; ///< The scroll speed in pixels per second.
1243 float mScrollDistance; ///< Distance the text scrolls during a scroll interval.
1244 unsigned int mScrollInterval; ///< Time in milliseconds of a scroll interval.
1246 bool mActiveCopyPastePopup : 1;
1247 bool mCursorBlinkStatus : 1; ///< Flag to switch between blink on and blink off.
1248 bool mPrimaryCursorVisible : 1; ///< Whether the primary cursor is visible.
1249 bool mSecondaryCursorVisible : 1; ///< Whether the secondary cursor is visible.
1250 bool mSwapSelectionHandles : 1; ///< Whether to swap the selection handle images.
1253 DecoratorPtr Decorator::New( ControllerInterface& controller,
1254 TextSelectionPopupCallbackInterface& callbackInterface )
1256 return DecoratorPtr( new Decorator( controller,
1257 callbackInterface ) );
1260 void Decorator::SetBoundingBox( const Rect<int>& boundingBox )
1262 mImpl->mBoundingBox = boundingBox;
1265 const Rect<int>& Decorator::GetBoundingBox() const
1267 return mImpl->mBoundingBox;
1270 void Decorator::Relayout( const Vector2& size )
1272 mImpl->Relayout( size );
1275 void Decorator::UpdatePositions( const Vector2& scrollOffset )
1277 mImpl->UpdatePositions( scrollOffset );
1282 void Decorator::SetActiveCursor( ActiveCursor activeCursor )
1284 mImpl->mActiveCursor = activeCursor;
1287 unsigned int Decorator::GetActiveCursor() const
1289 return mImpl->mActiveCursor;
1292 void Decorator::SetPosition( Cursor cursor, float x, float y, float cursorHeight, float lineHeight )
1294 mImpl->mCursor[cursor].position.x = x;
1295 mImpl->mCursor[cursor].position.y = y;
1296 mImpl->mCursor[cursor].cursorHeight = cursorHeight;
1297 mImpl->mCursor[cursor].lineHeight = lineHeight;
1300 void Decorator::GetPosition( Cursor cursor, float& x, float& y, float& cursorHeight, float& lineHeight ) const
1302 x = mImpl->mCursor[cursor].position.x;
1303 y = mImpl->mCursor[cursor].position.y;
1304 cursorHeight = mImpl->mCursor[cursor].cursorHeight;
1305 lineHeight = mImpl->mCursor[cursor].lineHeight;
1308 const Vector2& Decorator::GetPosition( Cursor cursor ) const
1310 return mImpl->mCursor[cursor].position;
1313 void Decorator::SetColor( Cursor cursor, const Dali::Vector4& color )
1315 mImpl->mCursor[cursor].color = color;
1318 const Dali::Vector4& Decorator::GetColor( Cursor cursor ) const
1320 return mImpl->mCursor[cursor].color;
1323 void Decorator::StartCursorBlink()
1325 if ( !mImpl->mCursorBlinkTimer )
1327 mImpl->mCursorBlinkTimer = Timer::New( mImpl->mCursorBlinkInterval );
1328 mImpl->mCursorBlinkTimer.TickSignal().Connect( mImpl, &Decorator::Impl::OnCursorBlinkTimerTick );
1331 if ( !mImpl->mCursorBlinkTimer.IsRunning() )
1333 mImpl->mCursorBlinkTimer.Start();
1337 void Decorator::StopCursorBlink()
1339 if ( mImpl->mCursorBlinkTimer )
1341 mImpl->mCursorBlinkTimer.Stop();
1345 void Decorator::SetCursorBlinkInterval( float seconds )
1347 mImpl->mCursorBlinkInterval = static_cast<unsigned int>( seconds * TO_MILLISECONDS ); // Convert to milliseconds
1350 float Decorator::GetCursorBlinkInterval() const
1352 return static_cast<float>( mImpl->mCursorBlinkInterval ) * TO_SECONDS;
1355 void Decorator::SetCursorBlinkDuration( float seconds )
1357 mImpl->mCursorBlinkDuration = seconds;
1360 float Decorator::GetCursorBlinkDuration() const
1362 return mImpl->mCursorBlinkDuration;
1367 void Decorator::SetHandleActive( HandleType handleType, bool active )
1369 mImpl->mHandle[handleType].active = active;
1372 bool Decorator::IsHandleActive( HandleType handleType ) const
1374 return mImpl->mHandle[handleType].active ;
1377 void Decorator::SetHandleImage( HandleType handleType, HandleImageType handleImageType, Dali::Image image )
1379 mImpl->mHandleImages[handleType][handleImageType] = image;
1382 Dali::Image Decorator::GetHandleImage( HandleType handleType, HandleImageType handleImageType ) const
1384 return mImpl->mHandleImages[handleType][handleImageType];
1387 void Decorator::SetPosition( HandleType handleType, float x, float y, float height )
1389 // Adjust grab handle displacement
1390 Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1392 handle.grabDisplacementX -= x - handle.position.x;
1393 handle.grabDisplacementY -= y - handle.position.y;
1395 handle.position.x = x;
1396 handle.position.y = y;
1397 handle.lineHeight = height;
1400 void Decorator::GetPosition( HandleType handleType, float& x, float& y, float& height ) const
1402 Impl::HandleImpl& handle = mImpl->mHandle[handleType];
1404 x = handle.position.x;
1405 y = handle.position.y;
1406 height = handle.lineHeight;
1409 const Vector2& Decorator::GetPosition( HandleType handleType ) const
1411 return mImpl->mHandle[handleType].position;
1414 void Decorator::SwapSelectionHandlesEnabled( bool enable )
1416 mImpl->mSwapSelectionHandles = enable;
1418 mImpl->FlipSelectionHandleImages();
1421 void Decorator::AddHighlight( float x1, float y1, float x2, float y2 )
1423 mImpl->mHighlightQuadList.push_back( QuadCoordinates(x1, y1, x2, y2) );
1426 void Decorator::ClearHighlights()
1428 mImpl->mHighlightQuadList.clear();
1429 mImpl->mHighlightPosition = Vector2::ZERO;
1432 void Decorator::SetHighlightColor( const Vector4& color )
1434 mImpl->mHighlightColor = color;
1437 const Vector4& Decorator::GetHighlightColor() const
1439 return mImpl->mHighlightColor;
1442 void Decorator::SetPopupActive( bool active )
1444 mImpl->mActiveCopyPastePopup = active;
1447 bool Decorator::IsPopupActive() const
1449 return mImpl->mActiveCopyPastePopup ;
1452 void Decorator::SetEnabledPopupButtons( TextSelectionPopup::Buttons& enabledButtonsBitMask )
1454 mImpl->mEnabledPopupButtons = enabledButtonsBitMask;
1457 TextSelectionPopup::Buttons& Decorator::GetEnabledPopupButtons()
1459 return mImpl->mEnabledPopupButtons;
1464 void Decorator::SetScrollThreshold( float threshold )
1466 mImpl->SetScrollThreshold( threshold );
1469 float Decorator::GetScrollThreshold() const
1471 return mImpl->GetScrollThreshold();
1474 void Decorator::SetScrollSpeed( float speed )
1476 mImpl->SetScrollSpeed( speed );
1479 float Decorator::GetScrollSpeed() const
1481 return mImpl->GetScrollSpeed();
1484 Decorator::~Decorator()
1489 Decorator::Decorator( ControllerInterface& controller,
1490 TextSelectionPopupCallbackInterface& callbackInterface )
1493 mImpl = new Decorator::Impl( controller, callbackInterface );
1498 } // namespace Toolkit