Text's selection popup mirroring. 99/109799/10
authorVictor Cebollada <v.cebollada@samsung.com>
Wed, 11 Jan 2017 16:17:08 +0000 (16:17 +0000)
committerVictor Cebollada <v.cebollada@samsung.com>
Thu, 23 Mar 2017 13:27:48 +0000 (13:27 +0000)
* Reverses the order of the text's selection popup toolbar
  when the platform's language is right to left.

* Scrolls to the first reversed button (that's the end
  of the toolbar).

Change-Id: I58c5bbc5402810e0bd94510cc3f12143b572e395
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
14 files changed:
automated-tests/CMakeLists.txt.in
automated-tests/resources/po/ar.po [new file with mode: 0755]
automated-tests/resources/po/en.po [new file with mode: 0755]
automated-tests/src/dali-toolkit/CMakeLists.txt
automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringLTR.cpp [new file with mode: 0644]
automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringRTL.cpp [new file with mode: 0644]
dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.cpp
dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h
dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp
dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp
dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h
dali-toolkit/po/ar.po
dali-toolkit/po/fa.po
dali-toolkit/po/ur.po

index 0a0b958..377ec92 100644 (file)
@@ -11,3 +11,31 @@ INCLUDE_DIRECTORIES(
 )
 
 ADD_SUBDIRECTORY(src)
 )
 
 ADD_SUBDIRECTORY(src)
+
+#Internationalization
+SET(PO_DIR ${CMAKE_SOURCE_DIR}/resources/po)
+MESSAGE("po dir: ${PO_DIR}")
+FILE(GLOB PO_FILES RELATIVE "${PO_DIR}" "${PO_DIR}/*.po")
+
+SET(MSGFMT "/usr/bin/msgfmt")
+SET(MO_FILES_DIR /tmp/locale/en/LC_MESSAGES)
+FILE(MAKE_DIRECTORY ${MO_FILES_DIR})
+MESSAGE("mo dir: ${MO_FILES_DIR}")
+
+FOREACH(PO_FILE ${PO_FILES})
+        SET(PO_FILE ${PO_DIR}/${PO_FILE})
+        MESSAGE("PO: ${PO_FILE}")
+        GET_FILENAME_COMPONENT(ABS_PO_FILE ${PO_FILE} ABSOLUTE)
+        MESSAGE("ABS_PO_FILE : ${ABS_PO_FILE}")
+        GET_FILENAME_COMPONENT(lang ${ABS_PO_FILE} NAME_WE)
+        MESSAGE("lang : ${lang}")
+        SET(MO_FILE ${MO_FILES_DIR}/dali-toolkit.mo.${lang})
+        MESSAGE("MO_FILE : ${MO_FILE}")
+        ADD_CUSTOM_COMMAND(OUTPUT ${MO_FILE}
+                           COMMAND ${MSGFMT} -o ${MO_FILE} ${ABS_PO_FILE}
+                           DEPENDS ${ABS_PO_FILE})
+        SET(MO_FILES ${MO_FILES} ${MO_FILE})
+ENDFOREACH(PO_FILE)
+
+MESSAGE(".mo files: ${MO_FILES}")
+ADD_CUSTOM_TARGET(po ALL DEPENDS ${MO_FILES})
diff --git a/automated-tests/resources/po/ar.po b/automated-tests/resources/po/ar.po
new file mode 100755 (executable)
index 0000000..b91b3a7
--- /dev/null
@@ -0,0 +1,3 @@
+#: Used to know if the language is using a right to left script
+msgid "IDS_LTR"
+msgstr "RTL"
diff --git a/automated-tests/resources/po/en.po b/automated-tests/resources/po/en.po
new file mode 100755 (executable)
index 0000000..566fbbd
--- /dev/null
@@ -0,0 +1,3 @@
+#: Used to know if the language is using a right to left script
+msgid "IDS_LTR"
+msgstr "LTR"
index 97975d1..c7a1b8b 100755 (executable)
@@ -32,6 +32,8 @@ SET(TC_SOURCES
    utc-Dali-TextField.cpp
    utc-Dali-TextLabel.cpp
    utc-Dali-TextSelectionPopup.cpp
    utc-Dali-TextField.cpp
    utc-Dali-TextLabel.cpp
    utc-Dali-TextSelectionPopup.cpp
+   utc-Dali-TextSelectionPopupMirroringLTR.cpp
+   utc-Dali-TextSelectionPopupMirroringRTL.cpp
    utc-Dali-ToolBar.cpp
    utc-Dali-Tooltip.cpp
    utc-Dali-TransitionData.cpp
    utc-Dali-ToolBar.cpp
    utc-Dali-Tooltip.cpp
    utc-Dali-TransitionData.cpp
diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringLTR.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringLTR.cpp
new file mode 100644 (file)
index 0000000..5234210
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2017 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 <iostream>
+#include <fstream>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
+
+using namespace Dali;
+using namespace Toolkit;
+
+namespace
+{
+
+const char* DEFAULT_LOCALE_DIR = "/tmp/locale/";
+const std::string DEFAULT_EN_LOCALE_DIR = "/tmp/locale/en/LC_MESSAGES/";
+
+}
+
+void dali_textselectionpopupmirroringltr_startup(void)
+{
+  // Cheat! Copy the .mo file
+  std::ifstream  src( std::string( DEFAULT_EN_LOCALE_DIR + "dali-toolkit.mo.en" ).c_str(), std::ifstream::binary );
+  std::ofstream  dst( std::string( DEFAULT_EN_LOCALE_DIR + "dali-toolkit.mo" ).c_str(), std::ofstream::binary );
+  dst << src.rdbuf();
+
+  test_return_value = TET_UNDEF;
+}
+
+void dali_textselectionpopupmirroringltr_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliToolkitTextSelectionPopupMirroringLTR(void)
+{
+  // Test the popup mirroring.
+  const std::string CUT( "optionCut" );
+  const std::string COPY( "optionCopy" );
+  const std::string PASTE( "optionPaste" );
+
+  ToolkitTestApplication application;
+
+  setlocale( LC_ALL, "en_GB.UTF-8" );
+  textdomain("dali-toolkit");
+  bindtextdomain("dali-toolkit", DEFAULT_LOCALE_DIR );
+
+  TextSelectionPopup textSelectionPopup = TextSelectionPopup::New( NULL );
+
+  // Enable some buttons.
+  TextSelectionPopup::Buttons buttons = static_cast<TextSelectionPopup::Buttons>( TextSelectionPopup::COPY | TextSelectionPopup::CUT | TextSelectionPopup::PASTE );
+  textSelectionPopup.EnableButtons( buttons );
+
+  // Show the popup.
+  textSelectionPopup.ShowPopup();
+
+  Actor cutActor = textSelectionPopup.FindChildByName( CUT );
+  if( !cutActor )
+  {
+    tet_result(TET_FAIL);
+  }
+
+  Actor tableOfButtons = cutActor.GetParent();
+  if( !tableOfButtons )
+  {
+    tet_result(TET_FAIL);
+  }
+
+  // The order should be COPY, CUT, PASTE
+  DALI_TEST_EQUALS( COPY, tableOfButtons.GetChildAt( 0 ).GetName(), TEST_LOCATION );
+  DALI_TEST_EQUALS( CUT, tableOfButtons.GetChildAt( 2 ).GetName(), TEST_LOCATION );
+  DALI_TEST_EQUALS( PASTE, tableOfButtons.GetChildAt( 4 ).GetName(), TEST_LOCATION );
+
+  tet_result(TET_PASS);
+  END_TEST;
+}
diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringRTL.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringRTL.cpp
new file mode 100644 (file)
index 0000000..9d3e750
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2017 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 <iostream>
+#include <fstream>
+#include <stdlib.h>
+#include <locale.h>
+#include <libintl.h>
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
+
+using namespace Dali;
+using namespace Toolkit;
+
+namespace
+{
+
+const char* DEFAULT_LOCALE_DIR = "/tmp/locale/";
+const std::string DEFAULT_EN_LOCALE_DIR = "/tmp/locale/en/LC_MESSAGES/";
+
+}
+
+void dali_textselectionpopupmirroringrtl_startup(void)
+{
+  // Cheat! Copy the .mo file
+  std::ifstream  src( std::string( DEFAULT_EN_LOCALE_DIR + "dali-toolkit.mo.ar" ).c_str(), std::ifstream::binary );
+  std::ofstream  dst( std::string( DEFAULT_EN_LOCALE_DIR + "dali-toolkit.mo" ).c_str(), std::ofstream::binary );
+  dst << src.rdbuf();
+
+  test_return_value = TET_UNDEF;
+}
+
+void dali_textselectionpopupmirroringrtl_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliToolkitTextSelectionPopupMirroringRTL(void)
+{
+  // Test the popup mirroring.
+  const std::string CUT( "optionCut" );
+  const std::string COPY( "optionCopy" );
+  const std::string PASTE( "optionPaste" );
+
+  ToolkitTestApplication application;
+
+  setlocale( LC_ALL, "en_GB.UTF-8" );
+  textdomain("dali-toolkit");
+  bindtextdomain("dali-toolkit", DEFAULT_LOCALE_DIR );
+
+  TextSelectionPopup textSelectionPopup = TextSelectionPopup::New( NULL );
+
+  // Enable some buttons.
+  TextSelectionPopup::Buttons buttons = static_cast<TextSelectionPopup::Buttons>( TextSelectionPopup::COPY | TextSelectionPopup::CUT | TextSelectionPopup::PASTE );
+  textSelectionPopup.EnableButtons( buttons );
+
+  // Show the popup.
+  textSelectionPopup.ShowPopup();
+
+  Actor cutActor = textSelectionPopup.FindChildByName( CUT );
+  if( !cutActor )
+  {
+    tet_result(TET_FAIL);
+  }
+
+  Actor tableOfButtons = cutActor.GetParent();
+  if( !tableOfButtons )
+  {
+    tet_result(TET_FAIL);
+  }
+
+  // The order should be PASTE, CUT, COPY
+  DALI_TEST_EQUALS( PASTE, tableOfButtons.GetChildAt( 0 ).GetName(), TEST_LOCATION );
+  DALI_TEST_EQUALS( CUT, tableOfButtons.GetChildAt( 2 ).GetName(), TEST_LOCATION );
+  DALI_TEST_EQUALS( COPY, tableOfButtons.GetChildAt( 4 ).GetName(), TEST_LOCATION );
+
+  tet_result(TET_PASS);
+  END_TEST;
+}
index 46c32c8..84bd8db 100644 (file)
@@ -76,6 +76,11 @@ void TextSelectionToolbar::RaiseAbove( Layer target )
   GetImpl(*this).RaiseAbove( target );
 }
 
   GetImpl(*this).RaiseAbove( target );
 }
 
+void TextSelectionToolbar::ScrollTo( const Vector2& position )
+{
+  GetImpl(*this).ScrollTo( position );
+}
+
 TextSelectionToolbar TextSelectionToolbar::DownCast( BaseHandle handle )
 {
   return Control::DownCast<TextSelectionToolbar, Internal::TextSelectionToolbar>(handle);
 TextSelectionToolbar TextSelectionToolbar::DownCast( BaseHandle handle )
 {
   return Control::DownCast<TextSelectionToolbar, Internal::TextSelectionToolbar>(handle);
index 26d81a4..6193f77 100644 (file)
@@ -130,6 +130,11 @@ public:
   void RaiseAbove( Layer target );
 
   /**
   void RaiseAbove( Layer target );
 
   /**
+   * @copydoc Toolkit::ScrollView::ScrollTo(const Vector2&)
+   */
+  void ScrollTo( const Vector2& position );
+
+  /**
    * @brief Downcast a handle to TextSelectionToolbar.
    *
    * If the BaseHandle points is a TextSelectionToolbar the downcast returns a valid handle.
    * @brief Downcast a handle to TextSelectionToolbar.
    *
    * If the BaseHandle points is a TextSelectionToolbar the downcast returns a valid handle.
index 6ea83c0..babd0eb 100644 (file)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <libintl.h>
 
 // EXTERNAL INCLUDES
 #include <libintl.h>
+#include <string.h>
 #include <cfloat>
 #include <dali/public-api/animation/animation.h>
 #include <dali/devel-api/images/nine-patch-image.h>
 #include <cfloat>
 #include <dali/public-api/animation/animation.h>
 #include <dali/devel-api/images/nine-patch-image.h>
@@ -88,6 +89,9 @@ const char* const OPTION_COPY("optionCopy");
 const char* const OPTION_PASTE("optionPaste");                                    // "Paste" popup option.
 const char* const OPTION_CLIPBOARD("optionClipboard");                            // "Clipboard" popup option.
 
 const char* const OPTION_PASTE("optionPaste");                                    // "Paste" popup option.
 const char* const OPTION_CLIPBOARD("optionClipboard");                            // "Clipboard" popup option.
 
+const std::string IDS_LTR( "IDS_LTR" );
+const std::string RTL_DIRECTION( "RTL" );
+
 BaseHandle Create()
 {
   return Toolkit::TextSelectionPopup::New( NULL );
 BaseHandle Create()
 {
   return Toolkit::TextSelectionPopup::New( NULL );
@@ -802,6 +806,19 @@ std::string TextSelectionPopup::GetPressedImage() const
      self.Add( mToolbar );
    }
 
      self.Add( mToolbar );
    }
 
+   // Whether to mirror the list of buttons (for right to left languages)
+   bool mirror = false;
+   char* idsLtr = GET_LOCALE_TEXT( IDS_LTR.c_str() );
+   if( NULL != idsLtr )
+   {
+     mirror = ( 0 == strcmp( idsLtr, RTL_DIRECTION.c_str() ) );
+
+     if( mirror )
+     {
+       std::reverse( mOrderListOfButtons.begin(), mOrderListOfButtons.end() );
+     }
+   }
+
    // Iterate list of buttons and add active ones to Toolbar
    std::size_t numberOfOptionsRequired =  GetNumberOfEnabledOptions();
    std::size_t numberOfOptionsAdded = 0u;
    // Iterate list of buttons and add active ones to Toolbar
    std::size_t numberOfOptionsRequired =  GetNumberOfEnabledOptions();
    std::size_t numberOfOptionsAdded = 0u;
@@ -814,6 +831,11 @@ std::string TextSelectionPopup::GetPressedImage() const
        AddOption(  button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
      }
    }
        AddOption(  button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions );
      }
    }
+
+   if( mirror )
+   {
+     mToolbar.ScrollTo( Vector2( mPopupMaxSize.x, 0.f ) );
+   }
  }
 
 void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap )
  }
 
 void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap )
index 957e152..612ca8b 100644 (file)
@@ -280,11 +280,16 @@ void TextSelectionToolbar::SetUpScrollBar( bool enable )
 
 void TextSelectionToolbar::OnScrollStarted( const Vector2& position )
 {
 
 void TextSelectionToolbar::OnScrollStarted( const Vector2& position )
 {
+  if( mFirstScrollEnd )
+  {
+    mScrollView.SetOvershootEnabled( true );
+  }
   mTableOfButtons.SetSensitive( false );
 }
 
 void TextSelectionToolbar::OnScrollCompleted( const Vector2& position )
 {
   mTableOfButtons.SetSensitive( false );
 }
 
 void TextSelectionToolbar::OnScrollCompleted( const Vector2& position )
 {
+  mFirstScrollEnd = true;
   mTableOfButtons.SetSensitive( true );
 }
 
   mTableOfButtons.SetSensitive( true );
 }
 
@@ -327,6 +332,13 @@ void TextSelectionToolbar::SetScrollBarPadding( const Vector2& padding )
   RelayoutRequest();
 }
 
   RelayoutRequest();
 }
 
+void TextSelectionToolbar::ScrollTo( const Vector2& position )
+{
+  mFirstScrollEnd = false;
+  mScrollView.SetOvershootEnabled( false );
+  mScrollView.ScrollTo( position, 0.f );
+}
+
 void TextSelectionToolbar::ConfigureScrollview( const Property::Map& properties )
 {
   // Set any properties specified for the label by iterating through all property key-value pairs.
 void TextSelectionToolbar::ConfigureScrollview( const Property::Map& properties )
 {
   // Set any properties specified for the label by iterating through all property key-value pairs.
@@ -369,7 +381,8 @@ TextSelectionToolbar::TextSelectionToolbar()
   mMaxSize (),
   mScrollBarPadding( DEFAULT_SCROLL_BAR_PADDING ),
   mIndexInTable( 0 ),
   mMaxSize (),
   mScrollBarPadding( DEFAULT_SCROLL_BAR_PADDING ),
   mIndexInTable( 0 ),
-  mDividerIndexes()
+  mDividerIndexes(),
+  mFirstScrollEnd( false )
 {
 }
 
 {
 }
 
index f5908bb..adaf3b6 100644 (file)
@@ -97,6 +97,11 @@ public:
    */
   const Vector2& GetScrollBarPadding() const;
 
    */
   const Vector2& GetScrollBarPadding() const;
 
+  /**
+   * @copydoc Toolkit::TextSelectionToolbar::ScrollTo()
+   */
+  void ScrollTo( const Vector2& position );
+
 private: // From Control
 
   /**
 private: // From Control
 
   /**
@@ -184,6 +189,7 @@ private: // Data
   Vector2 mScrollBarPadding;                          ///< The padding used to position the scroll indicator.
   unsigned int mIndexInTable;                         ///< Index in table to add option
   Dali::Vector< unsigned int > mDividerIndexes;       ///< Vector of indexes in the Toolbar that contain dividers.
   Vector2 mScrollBarPadding;                          ///< The padding used to position the scroll indicator.
   unsigned int mIndexInTable;                         ///< Index in table to add option
   Dali::Vector< unsigned int > mDividerIndexes;       ///< Vector of indexes in the Toolbar that contain dividers.
+  bool mFirstScrollEnd;                               ///< Used for RTL mirroring. Avoids the overshoot to be shown the first time the popup is shown.
 };
 
 } // namespace Internal
 };
 
 } // namespace Internal
index a31e003..414fb07 100755 (executable)
@@ -1,3 +1,7 @@
+#: Used to know if the language is using a right to left script
+msgid "IDS_LTR"
+msgstr "RTL"
+
 msgid "IDS_COM_BODY_SELECT_ALL"
 msgstr "اختيار الكل"
 
 msgid "IDS_COM_BODY_SELECT_ALL"
 msgstr "اختيار الكل"
 
index 4996205..5e8369b 100644 (file)
@@ -1,3 +1,7 @@
+#: Used to know if the language is using a right to left script
+msgid "IDS_LTR"
+msgstr "RTL"
+
 msgid "IDS_COM_BODY_SELECT_ALL"
 msgstr "انتخاب همه"
 
 msgid "IDS_COM_BODY_SELECT_ALL"
 msgstr "انتخاب همه"
 
index 7872070..b4bf3be 100644 (file)
@@ -1,3 +1,7 @@
+#: Used to know if the language is using a right to left script
+msgid "IDS_LTR"
+msgstr "RTL"
+
 msgid "IDS_COM_BODY_SELECT_ALL"
 msgstr "تمام منتخب کریں"
 
 msgid "IDS_COM_BODY_SELECT_ALL"
 msgstr "تمام منتخب کریں"