Merge "Bidirectional conversion table for multiline." into devel/master
authorPaul Wisbey <p.wisbey@samsung.com>
Fri, 27 May 2016 15:23:17 +0000 (08:23 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 27 May 2016 15:23:17 +0000 (08:23 -0700)
dali-toolkit/internal/controls/model3d-view/obj-loader.cpp
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/public-api/dali-toolkit-version.cpp
packaging/dali-toolkit.spec

index 857032a..04153d2 100644 (file)
@@ -66,46 +66,46 @@ void ObjLoader::CalculateTangentArray(const Dali::Vector<Vector3>& vertex,
   normal.Clear();
   normal.Resize(vertex.Size());
 
-  Vector3 *tan1 = new Vector3[vertex.Size() * 2];
+  Dali::Vector<Vector3> tangents;
+  tangents.Resize( vertex.Size() );
 
-  memset( tan1, 0, normal.Size() * sizeof(Vector3) * 2 );
-  memset( &normal[0], 0, normal.Size() * sizeof(Vector3) * 2 );
+  // Resize of a vector of Vector3 will initialise with the default constructor, setting to all zeros.
 
   for ( unsigned long a = 0; a < triangle.Size(); a++ )
   {
-    Vector3 Tangent, Bitangent, Normal;
+    Vector3 tangentVector, normalVector;
 
     const Vector3& v0 = vertex[triangle[a].pntIndex[0]];
     const Vector3& v1 = vertex[triangle[a].pntIndex[1]];
     const Vector3& v2 = vertex[triangle[a].pntIndex[2]];
 
-    Vector3 Edge1 = v1 - v0;
-    Vector3 Edge2 = v2 - v0;
+    Vector3 edge1 = v1 - v0;
+    Vector3 edge2 = v2 - v0;
 
-    Normal = Edge1.Cross(Edge2);
+    normalVector = edge1.Cross(edge2);
 
     const Vector2& w0 = texcoord[triangle[a].texIndex[0]];
     const Vector2& w1 = texcoord[triangle[a].texIndex[1]];
     const Vector2& w2 = texcoord[triangle[a].texIndex[2]];
 
-    float DeltaU1 = w1.x - w0.x;
-    float DeltaV1 = w1.y - w0.y;
-    float DeltaU2 = w2.x - w0.x;
-    float DeltaV2 = w2.y - w0.y;
+    float deltaU1 = w1.x - w0.x;
+    float deltaV1 = w1.y - w0.y;
+    float deltaU2 = w2.x - w0.x;
+    float deltaV2 = w2.y - w0.y;
 
-    float f = 1.0f / (DeltaU1 * DeltaV2 - DeltaU2 * DeltaV1);
+    float f = 1.0f / (deltaU1 * deltaV2 - deltaU2 * deltaV1);
 
-    Tangent.x = f * ( DeltaV2 * Edge1.x - DeltaV1 * Edge2.x );
-    Tangent.y = f * ( DeltaV2 * Edge1.y - DeltaV1 * Edge2.y );
-    Tangent.z = f * ( DeltaV2 * Edge1.z - DeltaV1 * Edge2.z );
+    tangentVector.x = f * ( deltaV2 * edge1.x - deltaV1 * edge2.x );
+    tangentVector.y = f * ( deltaV2 * edge1.y - deltaV1 * edge2.y );
+    tangentVector.z = f * ( deltaV2 * edge1.z - deltaV1 * edge2.z );
 
-    tan1[triangle[a].pntIndex[0]] += Tangent;
-    tan1[triangle[a].pntIndex[1]] += Tangent;
-    tan1[triangle[a].pntIndex[2]] += Tangent;
+    tangents[triangle[a].pntIndex[0]] += tangentVector;
+    tangents[triangle[a].pntIndex[1]] += tangentVector;
+    tangents[triangle[a].pntIndex[2]] += tangentVector;
 
-    normal[triangle[a].pntIndex[0]] += Normal;
-    normal[triangle[a].pntIndex[1]] += Normal;
-    normal[triangle[a].pntIndex[2]] += Normal;
+    normal[triangle[a].pntIndex[0]] += normalVector;
+    normal[triangle[a].pntIndex[1]] += normalVector;
+    normal[triangle[a].pntIndex[2]] += normalVector;
   }
 
   for ( unsigned long a = 0; a < triangle.Size(); a++ )
@@ -121,15 +121,13 @@ void ObjLoader::CalculateTangentArray(const Dali::Vector<Vector3>& vertex,
     normal[a].Normalize();
 
     const Vector3& n = normal[a];
-    const Vector3& t = tan1[a];
+    const Vector3& t = tangents[a];
 
     // Gram-Schmidt orthogonalize
     Vector3 calc = t - n * n.Dot(t);
     calc.Normalize();
     tangent[a] = Vector3( calc.x,calc.y,calc.z );
   }
-
-  delete[] tan1;
 }
 
 
index 29b5718..800a721 100644 (file)
@@ -154,16 +154,19 @@ bool Controller::Impl::ProcessInputEvents()
     GetCursorPosition( mEventData->mPrimaryCursorPosition,
                        cursorInfo );
 
-    if( mEventData->mScrollAfterUpdatePosition )
+    // Scroll first the text after delete ...
+    if( mEventData->mScrollAfterDelete )
     {
-      ScrollToMakePositionVisible( cursorInfo.primaryPosition );
-      mEventData->mScrollAfterUpdatePosition = false;
+      ScrollTextToMatchCursor( cursorInfo );
     }
-    else if( mEventData->mScrollAfterDelete )
+
+    // ... then, text can be scrolled to make the cursor visible.
+    if( mEventData->mScrollAfterUpdatePosition )
     {
-      ScrollTextToMatchCursor( cursorInfo );
-      mEventData->mScrollAfterDelete = false;
+      ScrollToMakePositionVisible( cursorInfo.primaryPosition );
     }
+    mEventData->mScrollAfterUpdatePosition = false;
+    mEventData->mScrollAfterDelete = false;
 
     UpdateCursorPosition( cursorInfo );
 
@@ -1302,6 +1305,7 @@ void Controller::Impl::OnSelectEvent( const Event& event )
 
     mEventData->mUpdateLeftSelectionPosition = true;
     mEventData->mUpdateRightSelectionPosition = true;
+    mEventData->mUpdateCursorPosition = false;
 
     mEventData->mScrollAfterUpdatePosition = ( mEventData->mLeftSelectionPosition != mEventData->mRightSelectionPosition );
   }
@@ -1370,12 +1374,7 @@ void Controller::Impl::RetrieveSelection( std::string& selectedText, bool delete
 
       // Scroll after delete.
       mEventData->mPrimaryCursorPosition = handlesCrossed ? mEventData->mRightSelectionPosition : mEventData->mLeftSelectionPosition;
-      mEventData->mScrollAfterDelete = true;
     }
-    // Udpade the cursor position and the decorator.
-    // Scroll after the position is updated if is not scrolling after delete.
-    mEventData->mUpdateCursorPosition = true;
-    mEventData->mScrollAfterUpdatePosition = !mEventData->mScrollAfterDelete;
     mEventData->mDecoratorUpdated = true;
   }
 }
@@ -2457,8 +2456,10 @@ void Controller::Impl::ClampVerticalScroll( const Vector2& actualSize )
 
 void Controller::Impl::ScrollToMakePositionVisible( const Vector2& position )
 {
+  const float cursorWidth = mEventData->mDecorator ? mEventData->mDecorator->GetCursorWidth() : 0.f;
+
   // position is in actor's coords.
-  const float positionEnd = position.x + ( mEventData->mDecorator ? mEventData->mDecorator->GetCursorWidth() : 0.f );
+  const float positionEnd = position.x + cursorWidth;
 
   // Transform the position to decorator coords.
   const float alignment = IsShowingRealText() ? mAlignmentOffset.x : 0.f;
@@ -2485,6 +2486,9 @@ void Controller::Impl::ScrollTextToMatchCursor( const CursorInfo& cursorInfo )
   mEventData->mScrollPosition.x = currentCursorPosition.x - cursorInfo.primaryPosition.x - mAlignmentOffset.x;
 
   ClampHorizontalScroll( mVisualModel->GetLayoutSize() );
+
+  // Makes the new cursor position visible if needed.
+  ScrollToMakePositionVisible( cursorInfo.primaryPosition );
 }
 
 void Controller::Impl::RequestRelayout()
index 5c1ed0c..3ff675b 100644 (file)
@@ -520,6 +520,12 @@ struct Controller::Impl
 
   void OnSelectAllEvent();
 
+  /**
+   * @brief Retrieves the selected text. It removes the text if the @p deleteAfterRetrieval parameter is @e true.
+   *
+   * @param[out] selectedText The selected text encoded in utf8.
+   * @param[in] deleteAfterRetrieval Whether the text should be deleted after retrieval.
+   */
   void RetrieveSelection( std::string& selectedText, bool deleteAfterRetrieval );
 
   void ShowClipboard();
index 268519b..09a4441 100644 (file)
@@ -614,6 +614,8 @@ bool Controller::RemoveText( int cursorOffset,
       // Cursor position retreat
       oldCursorIndex = cursorIndex;
 
+      mImpl->mEventData->mScrollAfterDelete = true;
+
       DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", this, numberOfCharacters );
       removed = true;
     }
@@ -1434,13 +1436,6 @@ void Controller::TextInsertedEvent()
 
   // Apply modifications to the model; TODO - Optimize this
   mImpl->mOperationsPending = ALL_OPERATIONS;
-
-  // Queue a cursor reposition event; this must wait until after DoRelayout()
-  if( EventData::IsEditingState( mImpl->mEventData->mState ) )
-  {
-    mImpl->mEventData->mUpdateCursorPosition = true;
-    mImpl->mEventData->mScrollAfterUpdatePosition = true;
-  }
 }
 
 void Controller::TextDeletedEvent()
@@ -1457,13 +1452,6 @@ void Controller::TextDeletedEvent()
 
   // Apply modifications to the model; TODO - Optimize this
   mImpl->mOperationsPending = ALL_OPERATIONS;
-
-  // Queue a cursor reposition event; this must wait until after DoRelayout()
-  mImpl->mEventData->mUpdateCursorPosition = true;
-  if( 0u != mImpl->mLogicalModel->mText.Count() )
-  {
-    mImpl->mEventData->mScrollAfterDelete = true;
-  }
 }
 
 bool Controller::DoRelayout( const Size& size,
@@ -1930,16 +1918,13 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ
   // TODO: At the moment the underline runs are only for pre-edit.
   mImpl->mVisualModel->mUnderlineRuns.Clear();
 
-  Vector<Character> utf32Characters;
-  Length characterCount( 0u );
+  // Keep the current number of characters.
+  const Length currentNumberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mLogicalModel->mText.Count() : 0u;
 
-  // Remove the previous IMF pre-edit (predicitive text)
-  if( mImpl->mEventData->mPreEditFlag &&
-      ( 0u != mImpl->mEventData->mPreEditLength ) )
+  // Remove the previous IMF pre-edit.
+  if( mImpl->mEventData->mPreEditFlag && ( 0u != mImpl->mEventData->mPreEditLength ) )
   {
-    const CharacterIndex offset = mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition;
-
-    removedPrevious = RemoveText( -static_cast<int>( offset ),
+    removedPrevious = RemoveText( -static_cast<int>( mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition ),
                                   mImpl->mEventData->mPreEditLength,
                                   DONT_UPDATE_INPUT_STYLE );
 
@@ -1948,10 +1933,13 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ
   }
   else
   {
-    // Remove the previous Selection
+    // Remove the previous Selection.
     removedPrevious = RemoveSelectedText();
   }
 
+  Vector<Character> utf32Characters;
+  Length characterCount = 0u;
+
   if( !text.empty() )
   {
     //  Convert text into UTF-32
@@ -2116,6 +2104,8 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ
     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, mImpl->mLogicalModel->mText.Count(), mImpl->mEventData->mPrimaryCursorPosition );
   }
 
+  const Length numberOfCharacters = mImpl->IsShowingRealText() ? mImpl->mLogicalModel->mText.Count() : 0u;
+
   if( ( 0u == mImpl->mLogicalModel->mText.Count() ) &&
       mImpl->IsPlaceholderAvailable() )
   {
@@ -2129,6 +2119,16 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ
   {
     // Queue an inserted event
     mImpl->QueueModifyEvent( ModifyEvent::TEXT_INSERTED );
+
+    mImpl->mEventData->mUpdateCursorPosition = true;
+    if( numberOfCharacters < currentNumberOfCharacters )
+    {
+      mImpl->mEventData->mScrollAfterDelete = true;
+    }
+    else
+    {
+      mImpl->mEventData->mScrollAfterUpdatePosition = true;
+    }
   }
 
   if( maxLengthReached )
@@ -2441,8 +2441,11 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt
       else
       {
         ShowPlaceholderText();
-        mImpl->mEventData->mUpdateCursorPosition = true;
       }
+
+      mImpl->mEventData->mUpdateCursorPosition = true;
+      mImpl->mEventData->mScrollAfterDelete = true;
+
       mImpl->RequestRelayout();
       mImpl->mControlInterface.TextChanged();
       break;
@@ -2530,8 +2533,9 @@ ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, cons
         else
         {
           ShowPlaceholderText();
-          mImpl->mEventData->mUpdateCursorPosition = true;
         }
+        mImpl->mEventData->mUpdateCursorPosition = true;
+        mImpl->mEventData->mScrollAfterDelete = true;
       }
       requestRelayout = true;
       break;
@@ -2618,8 +2622,9 @@ bool Controller::BackspaceKeyEvent()
     else
     {
       ShowPlaceholderText();
-      mImpl->mEventData->mUpdateCursorPosition = true;
     }
+    mImpl->mEventData->mUpdateCursorPosition = true;
+    mImpl->mEventData->mScrollAfterDelete = true;
   }
 
   return removed;
index 5f42b15..1f381d9 100644 (file)
@@ -31,7 +31,7 @@ namespace Toolkit
 
 const unsigned int TOOLKIT_MAJOR_VERSION = 1;
 const unsigned int TOOLKIT_MINOR_VERSION = 1;
-const unsigned int TOOLKIT_MICRO_VERSION = 35;
+const unsigned int TOOLKIT_MICRO_VERSION = 36;
 const char * const TOOLKIT_BUILD_DATE    = __DATE__ " " __TIME__;
 
 #ifdef DEBUG_ENABLED
index 55fc495..1195129 100644 (file)
@@ -1,6 +1,6 @@
 Name:       dali-toolkit
 Summary:    The OpenGLES Canvas Core Library Toolkit
-Version:    1.1.35
+Version:    1.1.36
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0 and BSD-2-Clause and MIT