From c45b6c9f3254cde5e817f8cfe6d59703f40d28d7 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Wed, 11 Jan 2017 16:17:08 +0000 Subject: [PATCH 1/1] Text's selection popup mirroring. * 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 --- automated-tests/CMakeLists.txt.in | 28 +++++++ automated-tests/resources/po/ar.po | 3 + automated-tests/resources/po/en.po | 3 + automated-tests/src/dali-toolkit/CMakeLists.txt | 2 + .../utc-Dali-TextSelectionPopupMirroringLTR.cpp | 94 ++++++++++++++++++++++ .../utc-Dali-TextSelectionPopupMirroringRTL.cpp | 94 ++++++++++++++++++++++ .../text-controls/text-selection-toolbar.cpp | 5 ++ .../text-controls/text-selection-toolbar.h | 5 ++ .../text-controls/text-selection-popup-impl.cpp | 22 +++++ .../text-controls/text-selection-toolbar-impl.cpp | 15 +++- .../text-controls/text-selection-toolbar-impl.h | 6 ++ dali-toolkit/po/ar.po | 4 + dali-toolkit/po/fa.po | 4 + dali-toolkit/po/ur.po | 4 + 14 files changed, 288 insertions(+), 1 deletion(-) create mode 100755 automated-tests/resources/po/ar.po create mode 100755 automated-tests/resources/po/en.po create mode 100644 automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringLTR.cpp create mode 100644 automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringRTL.cpp diff --git a/automated-tests/CMakeLists.txt.in b/automated-tests/CMakeLists.txt.in index 0a0b958..377ec92 100644 --- a/automated-tests/CMakeLists.txt.in +++ b/automated-tests/CMakeLists.txt.in @@ -11,3 +11,31 @@ INCLUDE_DIRECTORIES( ) 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 index 0000000..b91b3a7 --- /dev/null +++ b/automated-tests/resources/po/ar.po @@ -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 index 0000000..566fbbd --- /dev/null +++ b/automated-tests/resources/po/en.po @@ -0,0 +1,3 @@ +#: Used to know if the language is using a right to left script +msgid "IDS_LTR" +msgstr "LTR" diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index 97975d1..c7a1b8b 100755 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -32,6 +32,8 @@ SET(TC_SOURCES 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 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 index 0000000..5234210 --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringLTR.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include + +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::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 index 0000000..9d3e750c --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringRTL.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include + +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::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; +} diff --git a/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.cpp b/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.cpp index 46c32c8..84bd8db 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.cpp @@ -76,6 +76,11 @@ void TextSelectionToolbar::RaiseAbove( Layer target ) GetImpl(*this).RaiseAbove( target ); } +void TextSelectionToolbar::ScrollTo( const Vector2& position ) +{ + GetImpl(*this).ScrollTo( position ); +} + TextSelectionToolbar TextSelectionToolbar::DownCast( BaseHandle handle ) { return Control::DownCast(handle); diff --git a/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h b/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h index 26d81a4..6193f77 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h @@ -130,6 +130,11 @@ public: 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. diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp index 6ea83c0..babd0eb 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include #include #include #include @@ -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 std::string IDS_LTR( "IDS_LTR" ); +const std::string RTL_DIRECTION( "RTL" ); + BaseHandle Create() { return Toolkit::TextSelectionPopup::New( NULL ); @@ -802,6 +806,19 @@ std::string TextSelectionPopup::GetPressedImage() const 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; @@ -814,6 +831,11 @@ std::string TextSelectionPopup::GetPressedImage() const AddOption( button, ( numberOfOptionsAdded < numberOfOptionsRequired ) , showIcons, showCaptions ); } } + + if( mirror ) + { + mToolbar.ScrollTo( Vector2( mPopupMaxSize.x, 0.f ) ); + } } void TextSelectionPopup::CreateBackgroundBorder( Property::Map& propertyMap ) diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp index 957e152..612ca8b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp @@ -280,11 +280,16 @@ void TextSelectionToolbar::SetUpScrollBar( bool enable ) void TextSelectionToolbar::OnScrollStarted( const Vector2& position ) { + if( mFirstScrollEnd ) + { + mScrollView.SetOvershootEnabled( true ); + } mTableOfButtons.SetSensitive( false ); } void TextSelectionToolbar::OnScrollCompleted( const Vector2& position ) { + mFirstScrollEnd = true; mTableOfButtons.SetSensitive( true ); } @@ -327,6 +332,13 @@ void TextSelectionToolbar::SetScrollBarPadding( const Vector2& padding ) 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. @@ -369,7 +381,8 @@ TextSelectionToolbar::TextSelectionToolbar() mMaxSize (), mScrollBarPadding( DEFAULT_SCROLL_BAR_PADDING ), mIndexInTable( 0 ), - mDividerIndexes() + mDividerIndexes(), + mFirstScrollEnd( false ) { } diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h index f5908bb..adaf3b6 100644 --- a/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h @@ -97,6 +97,11 @@ public: */ const Vector2& GetScrollBarPadding() const; + /** + * @copydoc Toolkit::TextSelectionToolbar::ScrollTo() + */ + void ScrollTo( const Vector2& position ); + 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. + bool mFirstScrollEnd; ///< Used for RTL mirroring. Avoids the overshoot to be shown the first time the popup is shown. }; } // namespace Internal diff --git a/dali-toolkit/po/ar.po b/dali-toolkit/po/ar.po index a31e003..414fb07 100755 --- a/dali-toolkit/po/ar.po +++ b/dali-toolkit/po/ar.po @@ -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 "اختيار الكل" diff --git a/dali-toolkit/po/fa.po b/dali-toolkit/po/fa.po index 4996205..5e8369b 100644 --- a/dali-toolkit/po/fa.po +++ b/dali-toolkit/po/fa.po @@ -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 "انتخاب همه" diff --git a/dali-toolkit/po/ur.po b/dali-toolkit/po/ur.po index 7872070..b4bf3be 100644 --- a/dali-toolkit/po/ur.po +++ b/dali-toolkit/po/ur.po @@ -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 "تمام منتخب کریں" -- 2.7.4