Merge branch 'tizen' into new_text
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-input / text-input-text-highlight-impl.cpp
index d42abcd..7475678 100644 (file)
@@ -1,33 +1,33 @@
-//
-// 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.
-//
-
-// INTERNAL INCLUDES
+/*
+ * 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.
+ *
+ */
+
+// CLASS HEADER
 #include <dali-toolkit/internal/controls/text-input/text-input-text-highlight-impl.h>
 
-#include <dali/dali.h>
-
-#include <dali/integration-api/debug.h>
-
+// EXTERNAL INCLUDES
 #include <math.h>
 #include <sstream>
 #include <algorithm>
 #include <libintl.h>
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
 
 using namespace Dali;
-using namespace std;
 
 namespace
 {
@@ -100,7 +100,6 @@ void TextHighlight::GetVisualTextSelection(std::vector<bool>& selectedVisualText
 TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t handlePositionStart, std::size_t handlePositionEnd, Toolkit::TextView::TextLayoutInfo& textLayoutInfo )
 {
   // At the moment there is no public API to modify the block alignment option.
-  const bool blockAlignEnabled = true;
 
   TextHighlight::HighlightInfo newHighlightInfo;
   //newHighlightInfo.mQuadList.clear(); // clear last quad information.
@@ -158,7 +157,7 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t
           // TODO: TextView should have a table of visual rows, and each character a reference to the row
           // that it resides on. That way this enumeration is not necessary.
           Vector2 min, max;
-          if(lastIt->mIsNewLineChar)
+          if(lastIt->mIsNewParagraphChar)
           {
             // If the last character is a new line, then to get the row rect, we need to scan from the character before the new line.
             lastIt = std::max( textLayoutInfo.mCharacterLayoutInfoTable.begin(), lastIt - 1 );
@@ -170,7 +169,7 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t
           float rowTop = rowBottom - rowSize.height;
 
           // Still selected, and block-align mode then set rowRight to max, so it can be clamped afterwards
-          if(charSelected && blockAlignEnabled)
+          if(charSelected)
           {
             rowRight = std::numeric_limits<float>::max();
           }
@@ -182,7 +181,7 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t
           if( charSelected )
           {
             // if block-align mode then set rowLeft to min, so it can be clamped afterwards
-            rowLeft = blockAlignEnabled ? 0.0f : charInfo.mPosition.x - textLayoutInfo.mScrollOffset.x;
+            rowLeft = 0.0f;
             rowRight = ( charInfo.mPosition.x - textLayoutInfo.mScrollOffset.x ) + charInfo.mSize.width;
             selectionState = SelectionStarted;
           }
@@ -205,16 +204,19 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t
       {
         // finished selection.
         Vector2 min, max;
-        if(lastIt->mIsNewLineChar)
+        if(lastIt != end && lastIt->mIsNewParagraphChar)
         {
           lastIt = std::max( textLayoutInfo.mCharacterLayoutInfoTable.begin(), lastIt - 1 );
         }
-        const Size rowSize( mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( lastIt - textLayoutInfo.mCharacterLayoutInfoTable.begin(), min, max ) );
-        maxRowLeft = std::min(maxRowLeft, min.x);
-        maxRowRight = std::max(maxRowRight, max.x);
-        float rowBottom = lastIt->mPosition.y - textLayoutInfo.mScrollOffset.y;
-        float rowTop = rowBottom - rowSize.height;
-        newHighlightInfo.AddQuad( rowLeft, rowTop, rowRight, rowBottom );
+        if( lastIt != end )
+        {
+          const Size rowSize( mTextViewCharacterPositioning.GetRowRectFromCharacterPosition( lastIt - textLayoutInfo.mCharacterLayoutInfoTable.begin(), min, max ) );
+          maxRowLeft = std::min(maxRowLeft, min.x);
+          maxRowRight = std::max(maxRowRight, max.x);
+          float rowBottom = lastIt->mPosition.y - textLayoutInfo.mScrollOffset.y;
+          float rowTop = rowBottom - rowSize.height;
+          newHighlightInfo.AddQuad( rowLeft, rowTop, rowRight, rowBottom );
+        }
       }
     }
 
@@ -227,8 +229,6 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t
     newHighlightInfo.Clamp2D( topLeft, bottomRight );
 
     // For block-align align Further Clamp quads to max left and right extents
-    if(blockAlignEnabled)
-    {
       // BlockAlign: Will adjust highlight to block:
       // i.e.
       //   H[ello] (top row right = max of all rows right)
@@ -243,9 +243,8 @@ TextHighlight::HighlightInfo TextHighlight::CalculateHighlightInfo( std::size_t
       // [is some]
       // [text]
       // (common in regular text editors/web browser selection)
-
       newHighlightInfo.Clamp2D( Vector2(maxRowLeft, topLeft.y), Vector2(maxRowRight, bottomRight.y ) );
-    }
+
   }
 
   return newHighlightInfo;