Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-input / text-input-decorator-impl.cpp
index 1e034a3..3e90dd1 100644 (file)
@@ -1,18 +1,19 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include <dali/integration-api/debug.h>
 
@@ -29,38 +30,39 @@ namespace
   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TEXT_INPUT_DECORATOR");
 #endif
 
-  const Vector3 DEFAULT_SELECTION_HANDLE_SIZE( 51.0f, 79.0f, 0.0f );
-  const float TOP_HANDLE_TOP_OFFSET(-1.5f);                                   // Offset between top handle and cutCopyPaste pop-up
-  const float BOTTOM_HANDLE_BOTTOM_OFFSET(1.5f);                              // Offset between bottom handle and cutCopyPaste pop-up
-  const float UI_Z_OFFSET( 0.2f );                                            // Text Selection Handles/Cursor z-offset.
-  const Vector3 UI_OFFSET(0.0f, 0.0f, UI_Z_OFFSET);                           // Text Selection Handles/Cursor offset.
-  const char* DEFAULT_CURSOR( DALI_IMAGE_DIR "cursor.png" );
-  const Vector4 DEFAULT_CURSOR_IMAGE_9_BORDER( 2.0f, 2.0f, 2.0f, 2.0f );
-  const std::size_t CURSOR_BLINK_INTERVAL = 500;                              // Cursor blink interval
-  const float CURSOR_THICKNESS(6.0f);
-  const Degree CURSOR_ANGLE_OFFSET(2.0f);                                     // Offset from the angle
-
-  const unsigned int SCROLL_TICK_INTERVAL = 50u;
-  const float SCROLL_THRESHOLD = 10.f;
-  const float SCROLL_SPEED = 15.f;
-
-  /**
-   * Whether the given position plus the cursor size offset is inside the given boundary.
-   *
-   * @param[in] position The given position.
-   * @param[in] cursorSize The cursor size.
-   * @param[in] controlSize The given boundary.
-   * @param[in] threshold imaginary indent around boundary that will trigger the position to be outside of control.
-   *
-   * @return whether the given position is inside the given boundary.
-   */
-  bool IsPositionWithinControl( const Vector3& position, const Size& cursorSize, const Vector3& controlSize, const Vector2 threshold = Vector2::ZERO )
-  {
-    return ( position.x >= -Math::MACHINE_EPSILON_1000 + threshold.x ) &&
-           ( position.x <= controlSize.width - threshold.x + Math::MACHINE_EPSILON_1000 ) &&
-           ( position.y - cursorSize.height >= -Math::MACHINE_EPSILON_1000 + threshold.y ) &&
-           ( position.y <= controlSize.height + Math::MACHINE_EPSILON_1000 - threshold.y);
-  }
+const Vector3 DEFAULT_SELECTION_HANDLE_SIZE( 51.0f, 79.0f, 0.0f );
+const float TOP_HANDLE_TOP_OFFSET(-1.5f);                                   // Offset between top handle and cutCopyPaste pop-up
+const float BOTTOM_HANDLE_BOTTOM_OFFSET(1.5f);                              // Offset between bottom handle and cutCopyPaste pop-up
+const float UI_Z_OFFSET( 0.2f );                                            // Text Selection Handles/Cursor z-offset.
+const Vector3 UI_OFFSET(0.0f, 0.0f, UI_Z_OFFSET);                           // Text Selection Handles/Cursor offset.
+const char* DEFAULT_CURSOR( DALI_IMAGE_DIR "cursor.png" );
+const Vector4 DEFAULT_CURSOR_IMAGE_9_BORDER( 2.0f, 2.0f, 2.0f, 2.0f );
+const std::size_t CURSOR_BLINK_INTERVAL = 500;                              // Cursor blink interval
+const float CURSOR_THICKNESS(6.0f);
+const Degree CURSOR_ANGLE_OFFSET(2.0f);                                     // Offset from the angle
+
+const unsigned int SCROLL_TICK_INTERVAL = 50u;
+const float SCROLL_THRESHOLD = 10.f;
+const float SCROLL_SPEED = 15.f;
+
+/**
+ * Whether the given position plus the cursor size offset is inside the given boundary.
+ *
+ * @param[in] position The given position.
+ * @param[in] cursorSize The cursor size.
+ * @param[in] controlSize The given boundary.
+ * @param[in] threshold imaginary indent around boundary that will trigger the position to be outside of control.
+ *
+ * @return whether the given position is inside the given boundary.
+ */
+bool IsPositionWithinControl( const Vector3& position, const Size& cursorSize, const Vector3& controlSize, const Vector2 threshold = Vector2::ZERO )
+{
+  return ( position.x >= -Math::MACHINE_EPSILON_1000 + threshold.x ) &&
+         ( position.x <= controlSize.width - threshold.x + Math::MACHINE_EPSILON_1000 ) &&
+         ( position.y - cursorSize.height >= -Math::MACHINE_EPSILON_1000 + threshold.y ) &&
+         ( position.y <= controlSize.height + Math::MACHINE_EPSILON_1000 - threshold.y);
+}
+
 }
 
 namespace Dali
@@ -150,22 +152,19 @@ void Decorator::OnHandlePan(Actor actor, PanGesture gesture)
       // Revert back to non-pressed selection handle images
       if ( actor.GetParent() == mTextInputHandles.GetSelectionHandleOne() )
       {
-        mSelectionHandleOneActualPosition = MoveSelectionHandle( selectionHandleOne, mSelectionHandleOneActualPosition, mSelectionHandleOnePosition, gesture.displacement );
+         mSelectionHandleOneActualPosition = MoveSelectionHandle( selectionHandleOne, mSelectionHandleOneActualPosition, mSelectionHandleOnePosition, gesture.displacement );
         ShowPopupCutCopyPaste();
-        ShowPopUp();
       }
       else if ( actor.GetParent() == mTextInputHandles.GetSelectionHandleTwo() )
       {
         mSelectionHandleTwoActualPosition = MoveSelectionHandle( selectionHandleTwo, mSelectionHandleTwoActualPosition, mSelectionHandleTwoPosition, gesture.displacement );
         ShowPopupCutCopyPaste();
-        ShowPopUp();
       }
       else if ( actor.GetParent() == mTextInputHandles.GetGrabHandle() )
       {
         MoveGrabHandle( gesture.displacement );
         SetCursorVisibility( true );
         ShowPopupCutCopyPaste();
-        ShowPopUp();
       }
     }
     break;
@@ -253,12 +252,6 @@ void Decorator::SetSelectionHandlesVisibility(bool visible )
   mTextInputHandles.SetSelectionHandleTwoVisibility( visible );
 }
 
-bool Decorator::OnHandleReleased()
-{
-  ShowPopUp();
-  return false;
-}
-
 void Decorator::PositionSelectionHandles( std::size_t start, std::size_t end )
 {
   mSelectionHandleOnePosition = start;
@@ -268,8 +261,6 @@ void Decorator::PositionSelectionHandles( std::size_t start, std::size_t end )
 
   mSelectionHandleOneActualPosition = PositionSelectionHandle( mTextInputHandles.GetSelectionHandleOne(), mSelectionHandleOnePosition );
   mSelectionHandleTwoActualPosition = PositionSelectionHandle( mTextInputHandles.GetSelectionHandleTwo(), mSelectionHandleTwoPosition );
-
-  mTextInputHandles.ReleasedSignal().Connect( this, &Decorator::OnHandleReleased );
 }
 
 Vector3 Decorator::MoveSelectionHandle( Actor selectionHandle,
@@ -837,7 +828,7 @@ Vector3 Decorator::PositionOfPopUpRelativeToSelectionHandles()
   // When text is selected, show popup above top handle (and text), or below bottom handle.
 
   // topHandle: referring to the top most point of the handle or the top line of selection.
-  if ( mSelectionHandleTwoActualPosition.y > mSelectionHandleOneActualPosition.y )
+  if ( mSelectionHandleTwoActualPosition.y > mSelectionHandleOneActualPosition.y ) // Handle may switch positions so calculate which is top.
   {
     topHandle = mSelectionHandleOneActualPosition;
     rowSize= mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( mSelectionHandleOnePosition, min, max );