Fix when updating the text's layout size. 95/80695/1
authorVictor Cebollada <v.cebollada@samsung.com>
Tue, 19 Jul 2016 12:37:53 +0000 (13:37 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Tue, 19 Jul 2016 13:03:01 +0000 (14:03 +0100)
* If text is selected from the start of a paragraph
  till the end of the text and then deleted, the
  layout engine doesn't layout any text and the new
  layout size was not updated.

  It allows scroll the text with the old layout size
  which is wrong.

Change-Id: Ia6c2ab4af9084c81a3d9e21c073df16f78ec7fc5
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
dali-toolkit/internal/text/layouts/layout-engine.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/internal/text/text-controller.h

index 8d9f8f5..cd51c8d 100644 (file)
@@ -795,6 +795,10 @@ struct LayoutEngine::Impl
         }
       }
 
+      // Calculates the layout size.
+      UpdateLayoutSize( lines,
+                        layoutSize );
+
       // Nothing else do if there are no glyphs to layout.
       return false;
     }
index 6c7f694..2c45d35 100644 (file)
@@ -2503,13 +2503,13 @@ void Controller::Impl::UpdateSelectionHandle( HandleType handleType,
   mEventData->mAllTextSelected = ( startOfSelection == 0 ) && ( endOfSelection == mLogicalModel->mText.Count() );
 }
 
-void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )
+void Controller::Impl::ClampHorizontalScroll( const Vector2& layoutSize )
 {
   // Clamp between -space & 0.
 
-  if( actualSize.width > mVisualModel->mControlSize.width )
+  if( layoutSize.width > mVisualModel->mControlSize.width )
   {
-    const float space = ( actualSize.width - mVisualModel->mControlSize.width );
+    const float space = ( layoutSize.width - mVisualModel->mControlSize.width );
     mScrollPosition.x = ( mScrollPosition.x < -space ) ? -space : mScrollPosition.x;
     mScrollPosition.x = ( mScrollPosition.x > 0.f ) ? 0.f : mScrollPosition.x;
 
@@ -2521,12 +2521,12 @@ void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )
   }
 }
 
-void Controller::Impl::ClampVerticalScroll( const Vector2& actualSize )
+void Controller::Impl::ClampVerticalScroll( const Vector2& layoutSize )
 {
   // Clamp between -space & 0.
-  if( actualSize.height > mVisualModel->mControlSize.height )
+  if( layoutSize.height > mVisualModel->mControlSize.height )
   {
-    const float space = ( actualSize.height - mVisualModel->mControlSize.height );
+    const float space = ( layoutSize.height - mVisualModel->mControlSize.height );
     mScrollPosition.y = ( mScrollPosition.y < -space ) ? -space : mScrollPosition.y;
     mScrollPosition.y = ( mScrollPosition.y > 0.f ) ? 0.f : mScrollPosition.y;
 
index 99693ad..68659b6 100644 (file)
@@ -633,16 +633,16 @@ struct Controller::Impl
   /**
    * @biref Clamps the horizontal scrolling to get the control always filled with text.
    *
-   * @param[in] actualSize The size of the laid out text.
+   * @param[in] layoutSize The size of the laid out text.
    */
-  void ClampHorizontalScroll( const Vector2& actualSize );
+  void ClampHorizontalScroll( const Vector2& layoutSize );
 
   /**
    * @biref Clamps the vertical scrolling to get the control always filled with text.
    *
-   * @param[in] actualSize The size of the laid out text.
+   * @param[in] layoutSize The size of the laid out text.
    */
-  void ClampVerticalScroll( const Vector2& actualSize );
+  void ClampVerticalScroll( const Vector2& layoutSize );
 
   /**
    * @brief Scrolls the text to make a position visible.
index 261575f..643c8b8 100644 (file)
@@ -144,7 +144,7 @@ void Controller::SetAutoScrollEnabled( bool enable )
       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
                                                                LAYOUT                    |
                                                                ALIGN                     |
-                                                               UPDATE_ACTUAL_SIZE        |
+                                                               UPDATE_LAYOUT_SIZE        |
                                                                UPDATE_DIRECTION          |
                                                                REORDER );
 
@@ -155,7 +155,7 @@ void Controller::SetAutoScrollEnabled( bool enable )
       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
                                                                LAYOUT                    |
                                                                ALIGN                     |
-                                                               UPDATE_ACTUAL_SIZE        |
+                                                               UPDATE_LAYOUT_SIZE        |
                                                                REORDER );
     }
 
@@ -925,7 +925,7 @@ void Controller::SetInputFontFamily( const std::string& fontFamily )
                                                                SHAPE_TEXT                |
                                                                GET_GLYPH_METRICS         |
                                                                LAYOUT                    |
-                                                               UPDATE_ACTUAL_SIZE        |
+                                                               UPDATE_LAYOUT_SIZE        |
                                                                REORDER                   |
                                                                ALIGN );
       mImpl->mRecalculateNaturalSize = true;
@@ -999,7 +999,7 @@ void Controller::SetInputFontWeight( FontWeight weight )
                                                                SHAPE_TEXT                |
                                                                GET_GLYPH_METRICS         |
                                                                LAYOUT                    |
-                                                               UPDATE_ACTUAL_SIZE        |
+                                                               UPDATE_LAYOUT_SIZE        |
                                                                REORDER                   |
                                                                ALIGN );
       mImpl->mRecalculateNaturalSize = true;
@@ -1053,7 +1053,7 @@ void Controller::SetInputFontWidth( FontWidth width )
                                                                SHAPE_TEXT                |
                                                                GET_GLYPH_METRICS         |
                                                                LAYOUT                    |
-                                                               UPDATE_ACTUAL_SIZE        |
+                                                               UPDATE_LAYOUT_SIZE        |
                                                                REORDER                   |
                                                                ALIGN );
       mImpl->mRecalculateNaturalSize = true;
@@ -1107,7 +1107,7 @@ void Controller::SetInputFontSlant( FontSlant slant )
                                                                SHAPE_TEXT                |
                                                                GET_GLYPH_METRICS         |
                                                                LAYOUT                    |
-                                                               UPDATE_ACTUAL_SIZE        |
+                                                               UPDATE_LAYOUT_SIZE        |
                                                                REORDER                   |
                                                                ALIGN );
       mImpl->mRecalculateNaturalSize = true;
@@ -1160,7 +1160,7 @@ void Controller::SetInputFontPointSize( float size )
                                                                SHAPE_TEXT                |
                                                                GET_GLYPH_METRICS         |
                                                                LAYOUT                    |
-                                                               UPDATE_ACTUAL_SIZE        |
+                                                               UPDATE_LAYOUT_SIZE        |
                                                                REORDER                   |
                                                                ALIGN );
       mImpl->mRecalculateNaturalSize = true;
@@ -1482,7 +1482,7 @@ Controller::UpdateTextType Controller::Relayout( const Size& size )
     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
                                                              LAYOUT                    |
                                                              ALIGN                     |
-                                                             UPDATE_ACTUAL_SIZE        |
+                                                             UPDATE_LAYOUT_SIZE        |
                                                              REORDER );
     // Set the update info to relayout the whole text.
     mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
@@ -1705,6 +1705,9 @@ bool Controller::DoRelayout( const Size& size,
   const CharacterIndex startIndex = mImpl->mTextUpdateInfo.mParagraphCharacterIndex;
   const Length requestedNumberOfCharacters = mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters;
 
+  // Get the current layout size.
+  layoutSize = mImpl->mVisualModel->GetLayoutSize();
+
   if( NO_OPERATION != ( LAYOUT & operations ) )
   {
     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->Controller::DoRelayout LAYOUT & operations\n");
@@ -1726,7 +1729,7 @@ bool Controller::DoRelayout( const Size& size,
 
     if( 0u == totalNumberOfGlyphs )
     {
-      if( NO_OPERATION != ( UPDATE_ACTUAL_SIZE & operations ) )
+      if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
       {
         mImpl->mVisualModel->SetLayoutSize( Size::ZERO );
       }
@@ -1772,14 +1775,18 @@ bool Controller::DoRelayout( const Size& size,
     layoutParameters.estimatedNumberOfLines = mImpl->mTextUpdateInfo.mEstimatedNumberOfLines;
 
     // Update the visual model.
+    Size newLayoutSize;
     viewUpdated = mImpl->mLayoutEngine.LayoutText( layoutParameters,
                                                    glyphPositions,
                                                    mImpl->mVisualModel->mLines,
-                                                   layoutSize );
+                                                   newLayoutSize );
 
+    viewUpdated = viewUpdated || ( newLayoutSize != layoutSize );
 
     if( viewUpdated )
     {
+      layoutSize = newLayoutSize;
+
       if ( NO_OPERATION != ( UPDATE_DIRECTION & operations ) )
       {
         mImpl->mAutoScrollDirectionRTL = false;
@@ -1826,8 +1833,8 @@ bool Controller::DoRelayout( const Size& size,
         }
       } // REORDER
 
-      // Sets the actual size.
-      if( NO_OPERATION != ( UPDATE_ACTUAL_SIZE & operations ) )
+      // Sets the layout size.
+      if( NO_OPERATION != ( UPDATE_LAYOUT_SIZE & operations ) )
       {
         mImpl->mVisualModel->SetLayoutSize( layoutSize );
       }
@@ -1836,10 +1843,6 @@ bool Controller::DoRelayout( const Size& size,
     // Store the size used to layout the text.
     mImpl->mVisualModel->mControlSize = size;
   }
-  else
-  {
-    layoutSize = mImpl->mVisualModel->GetLayoutSize();
-  }
 
   if( NO_OPERATION != ( ALIGN & operations ) )
   {
@@ -1873,7 +1876,7 @@ void Controller::SetMultiLineEnabled( bool enable )
 
     // Set the flags to redo the layout operations
     const OperationsMask layoutOperations =  static_cast<OperationsMask>( LAYOUT             |
-                                                                          UPDATE_ACTUAL_SIZE |
+                                                                          UPDATE_LAYOUT_SIZE |
                                                                           ALIGN              |
                                                                           REORDER );
 
@@ -2921,7 +2924,7 @@ void Controller::ClearFontData()
                                                            SHAPE_TEXT                |
                                                            GET_GLYPH_METRICS         |
                                                            LAYOUT                    |
-                                                           UPDATE_ACTUAL_SIZE        |
+                                                           UPDATE_LAYOUT_SIZE        |
                                                            REORDER                   |
                                                            ALIGN );
 }
index 304ad2f..ad5c09a 100644 (file)
@@ -82,7 +82,7 @@ public:
     SHAPE_TEXT         = 0x0040,
     GET_GLYPH_METRICS  = 0x0080,
     LAYOUT             = 0x0100,
-    UPDATE_ACTUAL_SIZE = 0x0200,
+    UPDATE_LAYOUT_SIZE = 0x0200,
     REORDER            = 0x0400,
     ALIGN              = 0x0800,
     COLOR              = 0x1000,