[Tizen] Add more Preedit styles 23/221123/1
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Mon, 16 Dec 2019 05:20:59 +0000 (14:20 +0900)
committerSeoyeon Kim <seoyeon2.kim@samsung.com>
Fri, 27 Dec 2019 08:06:43 +0000 (17:06 +0900)
- Add more preedit styles for substring : SUB4, SUB5, SUB6, and SUB7.
- The preedit type is NONE, SUB1 ~ SUB7.
   But, DALi changed the name exactly, such as 'UNDERLINE' instead of 'SUB1' and
  'REVERSE' instead of 'SUB2'.
  SUB4 ~ 7 are just to draw the text in underline with various background color.

- The index received from imf is a byte. So it should be converted to character index.

Change-Id: Iea64e1bfc27ff291cee592c839013171df75d31c
Signed-off-by: Seoyeon Kim <seoyeon2.kim@samsung.com>
dali/devel-api/adaptor-framework/input-method-context.cpp
dali/devel-api/adaptor-framework/input-method-context.h
dali/internal/input/common/input-method-context-impl.h
dali/internal/input/generic/input-method-context-impl-generic.cpp
dali/internal/input/generic/input-method-context-impl-generic.h
dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.cpp
dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.h
dali/internal/input/ubuntu-x11/input-method-context-impl-x.cpp
dali/internal/input/ubuntu-x11/input-method-context-impl-x.h
dali/internal/input/windows/input-method-context-impl-win.cpp
dali/internal/input/windows/input-method-context-impl-win.h

index 854134c..bdd03de 100755 (executable)
@@ -221,9 +221,9 @@ void InputMethodContext::SetInputPanelPosition( unsigned int x, unsigned int y )
   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetInputPanelPosition( x, y );
 }
 
-Dali::InputMethodContext::PreeditStyle InputMethodContext::GetPreeditStyle() const
+void InputMethodContext::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs ) const
 {
-  return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetPreeditStyle();
+  Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetPreeditStyle( attrs );
 }
 
 // Signals
index 3eb5553..c0ec0dc 100755 (executable)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/events/key-event.h>
+#include <dali/public-api/common/dali-vector.h>
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/base-handle.h>
@@ -104,10 +105,24 @@ public:
    */
   enum class PreeditStyle
   {
-    NONE,         ///< None style
-    UNDERLINE,    ///< Underline substring style
-    REVERSE,      ///< Reverse substring style
-    HIGHLIGHT     ///< Highlight substring style
+    NONE,             ///< None style
+    UNDERLINE,        ///< Underline substring style
+    REVERSE,          ///< Reverse substring style
+    HIGHLIGHT,        ///< Highlight substring style
+    HIGHLIGHT_SUB4,   ///< SUB4 substring style
+    HIGHLIGHT_SUB5,   ///< SUB5 substring style
+    HIGHLIGHT_SUB6,   ///< SUB6 substring style
+    HIGHLIGHT_SUB7    ///< SUB7 substring style
+  };
+
+  /**
+   * @brief This structure is for the preedit style types and indices.
+   */
+  struct PreeditAttrData
+  {
+    PreeditStyle preeditType; /// The preedit style type
+    unsigned int startIndex;  /// The start index of preedit
+    unsigned int endIndex;    /// The end index of preedit
   };
 
   /**
@@ -476,11 +491,11 @@ public:
   void SetInputPanelPosition( unsigned int x, unsigned int y );
 
   /**
-   * @brief Gets the preedit type.
+   * @brief Gets the preedit attrs data.
    *
-   * @return The preedit style type
+   * @param[out] attrs The preedit attrs data.
    */
-  PreeditStyle GetPreeditStyle() const;
+  void GetPreeditStyle( Vector<PreeditAttrData>& attrs ) const;
 
 public:
 
index 35e1765..f0bc66d 100755 (executable)
@@ -276,7 +276,7 @@ public:
   /**
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
    */
-  virtual Dali::InputMethodContext::PreeditStyle GetPreeditStyle() const { return Dali::InputMethodContext::PreeditStyle(); }
+  virtual void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs ) const {}
 
 public:  // Signals
 
index 04292c4..deeb642 100644 (file)
@@ -298,11 +298,10 @@ void InputMethodContextGeneric::SetInputPanelPosition( unsigned int x, unsigned
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelPosition\n" );
 }
 
-Dali::InputMethodContext::PreeditStyle InputMethodContextGeneric::GetPreeditStyle() const
+void InputMethodContextGeneric::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs) const
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetPreeditStyle\n" );
-
-  return Dali::InputMethodContext::PreeditStyle::NONE;
+  // Do Nothing
 }
 
 } // Adaptor
index a4cec18..5bfee5b 100644 (file)
@@ -267,7 +267,7 @@ public:
   /**
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
    */
-  Dali::InputMethodContext::PreeditStyle GetPreeditStyle() const override;
+  void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs ) const override;
 
 public:
 
index 1d7be3e..79de283 100755 (executable)
@@ -324,7 +324,6 @@ InputMethodContextEcoreWl::InputMethodContextEcoreWl( Dali::Actor actor )
   mSurroundingText(),
   mRestoreAfterFocusLost( false ),
   mIdleCallbackConnected( false ),
-  mPreeditType( Dali::InputMethodContext::PreeditStyle::NONE ),
   mWindowId( GetWindowIdFromActor( actor ) )
 {
   ecore_imf_init();
@@ -503,6 +502,8 @@ void InputMethodContextEcoreWl::PreEditChanged( void*, ImfContext* imfContext, v
 
   Ecore_IMF_Preedit_Attr* attr;
 
+  mPreeditAttrs.Clear();
+
   // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.
   // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.
   ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );
@@ -512,66 +513,85 @@ void InputMethodContextEcoreWl::PreEditChanged( void*, ImfContext* imfContext, v
     // iterate through the list of attributes getting the type, start and end position.
     for ( l = attrs, (attr =  static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ); l; l = eina_list_next(l), ( attr = static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ))
     {
+      Dali::InputMethodContext::PreeditAttrData data;
+      data.startIndex = 0;
+      data.endIndex = 0;
+
+      size_t visualCharacterIndex = 0;
+      size_t byteIndex = 0;
+
+      // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
+      const char leadByte = preEditString[byteIndex];
+      while( leadByte != '\0' )
+      {
+        // attr->end_index is provided as a byte position not character and we need to know the character position.
+        const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
+        if( byteIndex <= attr->start_index )
+        {
+           data.startIndex = visualCharacterIndex;
+        }
+        if ( byteIndex >= attr->end_index )
+        {
+          data.endIndex = visualCharacterIndex;
+          break;
+          // end loop as found cursor position that matches byte position
+        }
+        else
+        {
+          byteIndex += currentSequenceLength; // jump to next character
+          visualCharacterIndex++;  // increment character count so we know our position for when we get a match
+        }
+      }
+
       switch( attr->preedit_type )
       {
         case ECORE_IMF_PREEDIT_TYPE_NONE:
         {
-          mPreeditType = Dali::InputMethodContext::PreeditStyle::NONE;
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::NONE;
           break;
         }
         case ECORE_IMF_PREEDIT_TYPE_SUB1:
         {
-          mPreeditType = Dali::InputMethodContext::PreeditStyle::UNDERLINE;
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::UNDERLINE;
           break;
         }
         case ECORE_IMF_PREEDIT_TYPE_SUB2:
         {
-          mPreeditType = Dali::InputMethodContext::PreeditStyle::REVERSE;
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::REVERSE;
           break;
         }
         case ECORE_IMF_PREEDIT_TYPE_SUB3:
         {
-          mPreeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT;
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT;
           break;
         }
-        default:
+        case ECORE_IMF_PREEDIT_TYPE_SUB4:
         {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT_SUB4;
           break;
         }
-      }
-
-#ifdef DALI_PROFILE_UBUNTU
-      if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF)
-#else // DALI_PROFILE_UBUNTU
-      if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)
-#endif // DALI_PROFILE_UBUNTU
-      {
-        // check first byte so know how many bytes a character is represented by as keyboard returns cursor position in bytes. Which is different for some languages.
-
-        size_t visualCharacterIndex = 0;
-        size_t byteIndex = 0;
-
-        // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
-        const char leadByte = preEditString[byteIndex];
-        while( leadByte != '\0' )
+        case ECORE_IMF_PREEDIT_TYPE_SUB5:
         {
-          // attr->end_index is provided as a byte position not character and we need to know the character position.
-          const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
-          if ( byteIndex == attr->end_index )
-          {
-            cursorPosition = visualCharacterIndex;
-            break;
-            // end loop as found cursor position that matches byte position
-          }
-          else
-          {
-            byteIndex += currentSequenceLength; // jump to next character
-            visualCharacterIndex++;  // increment character count so we know our position for when we get a match
-          }
-
-          DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT_SUB5;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB6:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT_SUB6;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB7:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT_SUB7;
+          break;
+        }
+        default:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::NONE;
+          break;
         }
       }
+      mPreeditAttrs.PushBack( data );
     }
   }
 
@@ -1125,10 +1145,10 @@ void InputMethodContextEcoreWl::SetInputPanelPosition( unsigned int x, unsigned
   mBackupOperations[Operation::SET_INPUT_PANEL_POSITION] = std::bind( &InputMethodContextEcoreWl::SetInputPanelPosition, this, x, y );
 }
 
-Dali::InputMethodContext::PreeditStyle InputMethodContextEcoreWl::GetPreeditStyle() const
+void InputMethodContextEcoreWl::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs ) const
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextEcoreWl::GetPreeditStyle\n" );
-  return mPreeditType;
+  attrs = mPreeditAttrs;
 }
 
 bool InputMethodContextEcoreWl::ProcessEventKeyDown( const KeyEvent& keyEvent )
index 095e914..00de9a9 100755 (executable)
@@ -265,7 +265,7 @@ public:
   /**
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
    */
-  Dali::InputMethodContext::PreeditStyle GetPreeditStyle() const override;
+  void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs ) const override;
 
 private:
   /**
@@ -345,7 +345,7 @@ private:
 
   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
   InputMethodOptions mOptions;
-  Dali::InputMethodContext::PreeditStyle mPreeditType;
+  Vector< Dali::InputMethodContext::PreeditAttrData > mPreeditAttrs; ///< Stores preedit attr data
 
   int mWindowId;
 };
index 1b516c2..9ae1ad6 100755 (executable)
@@ -149,8 +149,7 @@ InputMethodContextX::InputMethodContextX( Dali::Actor actor )
   mIMFCursorPosition( 0 ),
   mSurroundingText(),
   mRestoreAfterFocusLost( false ),
-  mIdleCallbackConnected( false ),
-  mPreeditType( Dali::InputMethodContext::PreeditStyle::NONE )
+  mIdleCallbackConnected( false )
 {
   ecore_imf_init();
 
@@ -314,6 +313,8 @@ void InputMethodContextX::PreEditChanged( void*, ImfContext* imfContext, void* e
 
   Ecore_IMF_Preedit_Attr* attr;
 
+  mPreeditAttrs.Clear();
+
   // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.
   // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.
   ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );
@@ -323,66 +324,85 @@ void InputMethodContextX::PreEditChanged( void*, ImfContext* imfContext, void* e
     // iterate through the list of attributes getting the type, start and end position.
     for ( l = attrs, (attr =  static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ); l; l = eina_list_next(l), ( attr = static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ))
     {
+      Dali::InputMethodContext::PreeditAttrData data;
+      data.startIndex = 0;
+      data.endIndex = 0;
+
+      size_t visualCharacterIndex = 0;
+      size_t byteIndex = 0;
+
+      // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
+      const char leadByte = preEditString[byteIndex];
+      while( leadByte != '\0' )
+      {
+        // attr->end_index is provided as a byte position not character and we need to know the character position.
+        const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
+        if( byteIndex <= attr->start_index )
+        {
+           data.startIndex = visualCharacterIndex;
+        }
+        if ( byteIndex >= attr->end_index )
+        {
+          data.endIndex = visualCharacterIndex;
+          break;
+          // end loop as found cursor position that matches byte position
+        }
+        else
+        {
+          byteIndex += currentSequenceLength; // jump to next character
+          visualCharacterIndex++;  // increment character count so we know our position for when we get a match
+        }
+      }
+
       switch( attr->preedit_type )
       {
         case ECORE_IMF_PREEDIT_TYPE_NONE:
         {
-          mPreeditType = Dali::InputMethodContext::PreeditStyle::NONE;
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::NONE;
           break;
         }
         case ECORE_IMF_PREEDIT_TYPE_SUB1:
         {
-          mPreeditType = Dali::InputMethodContext::PreeditStyle::UNDERLINE;
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::UNDERLINE;
           break;
         }
         case ECORE_IMF_PREEDIT_TYPE_SUB2:
         {
-          mPreeditType = Dali::InputMethodContext::PreeditStyle::REVERSE;
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::REVERSE;
           break;
         }
         case ECORE_IMF_PREEDIT_TYPE_SUB3:
         {
-          mPreeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT;
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT;
           break;
         }
-        default:
+        case ECORE_IMF_PREEDIT_TYPE_SUB4:
         {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT_SUB4;
           break;
         }
-      }
-
-#ifdef DALI_PROFILE_UBUNTU
-      if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF)
-#else // DALI_PROFILE_UBUNTU
-      if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)
-#endif // DALI_PROFILE_UBUNTU
-      {
-        // check first byte so know how many bytes a character is represented by as keyboard returns cursor position in bytes. Which is different for some languages.
-
-        size_t visualCharacterIndex = 0;
-        size_t byteIndex = 0;
-
-        // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
-        const char leadByte = preEditString[byteIndex];
-        while( leadByte != '\0' )
+        case ECORE_IMF_PREEDIT_TYPE_SUB5:
         {
-          // attr->end_index is provided as a byte position not character and we need to know the character position.
-          const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
-          if ( byteIndex == attr->end_index )
-          {
-            cursorPosition = static_cast<int>( visualCharacterIndex );
-            break;
-            // end loop as found cursor position that matches byte position
-          }
-          else
-          {
-            byteIndex += currentSequenceLength; // jump to next character
-            visualCharacterIndex++;  // increment character count so we know our position for when we get a match
-          }
-
-          DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT_SUB5;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB6:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT_SUB6;
+          break;
+        }
+        case ECORE_IMF_PREEDIT_TYPE_SUB7:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT_SUB7;
+          break;
+        }
+        default:
+        {
+          data.preeditType = Dali::InputMethodContext::PreeditStyle::NONE;
+          break;
         }
       }
+      mPreeditAttrs.PushBack( data );
     }
   }
 
@@ -820,10 +840,10 @@ void InputMethodContextX::SetInputPanelPosition( unsigned int x, unsigned int y
   // ecore_imf_context_input_panel_position_set() is supported from ecore-imf 1.21.0 version.
 }
 
-Dali::InputMethodContext::PreeditStyle InputMethodContextX::GetPreeditStyle() const
+void InputMethodContextX::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs ) const
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetPreeditStyle\n" );
-  return mPreeditType;
+  attrs = mPreeditAttrs;
 }
 
 bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
index f3222d8..24ae757 100755 (executable)
@@ -271,7 +271,7 @@ public:
   /**
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
    */
-  Dali::InputMethodContext::PreeditStyle GetPreeditStyle() const override;
+  void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs ) const override;
 
 private:
   /**
@@ -346,7 +346,7 @@ private:
   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
   InputMethodOptions        mOptions;
-  Dali::InputMethodContext::PreeditStyle mPreeditType;
+  Vector< Dali::InputMethodContext::PreeditAttrData > mPreeditAttrs; ///< Stores preedit attr data
 };
 
 } // namespace Adaptor
index 3902cb0..1c2a17c 100755 (executable)
@@ -62,8 +62,7 @@ InputMethodContextWin::InputMethodContextWin( Dali::Actor actor )
   mIMFCursorPosition( 0 ),\r
   mSurroundingText(),\r
   mRestoreAfterFocusLost( false ),\r
-  mIdleCallbackConnected( false ),\r
-  mPreeditType( Dali::InputMethodContext::PreeditStyle::NONE )\r
+  mIdleCallbackConnected( false )\r
 {\r
 \r
   actor.OnStageSignal().Connect( this, &InputMethodContextWin::OnStaged );\r
@@ -365,10 +364,10 @@ void InputMethodContextWin::SetInputPanelPosition( unsigned int x, unsigned int
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelPosition\n" );\r
 }\r
 \r
-Dali::InputMethodContext::PreeditStyle InputMethodContextWin::GetPreeditStyle() const\r
+void InputMethodContextWin::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs ) const\r
 {\r
   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetPreeditStyle\n" );\r
-  return mPreeditType;\r
+  attrs = mPreeditAttrs;\r
 }\r
 \r
 bool InputMethodContextWin::ProcessEventKeyDown( const KeyEvent& keyEvent )\r
index fffc088..8a4dd1f 100755 (executable)
@@ -259,7 +259,7 @@ public:
   /**\r
    * @copydoc Dali::InputMethodContext::GetPreeditStyle()\r
    */\r
-  Dali::InputMethodContext::PreeditStyle GetPreeditStyle() const override;\r
+  void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttrData >& attrs ) const override;\r
 \r
 private:\r
   /**\r
@@ -319,7 +319,7 @@ private:
   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.\r
   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.\r
   InputMethodOptions        mOptions;\r
-  Dali::InputMethodContext::PreeditStyle mPreeditType;\r
+  Vector< Dali::InputMethodContext::PreeditAttrData > mPreeditAttrs;\r
 };\r
 \r
 } // namespace Adaptor\r