TizenRefApp-6235 Make message-bubble that contains search-result selected (I part) 16/88116/1
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 13 Sep 2016 11:29:43 +0000 (14:29 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Tue, 13 Sep 2016 11:29:43 +0000 (14:29 +0300)
Change-Id: Ifac1b93f319c27f77464c20a8fadb1d061a68dae
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
res/edje/conv_label_theme.edc
src/Common/Utils/inc/TextDecorator.h
src/Common/Utils/src/TextDecorator.cpp
src/Conversation/ConvList/Controller/inc/BubbleEntityFactory.h
src/Conversation/ConvList/Controller/inc/BubbleTextEntity.h
src/Conversation/ConvList/Controller/inc/ConvListItem.h
src/Conversation/ConvList/Controller/src/BubbleEntityFactory.cpp
src/Conversation/ConvList/Controller/src/ConvListItem.cpp

index 7b8d8ee..4a827cf 100644 (file)
@@ -17,6 +17,7 @@ collections {
             tag:  "highlight" "+ font_weight=Bold";
             tag:  "b" "+ font_weight=Bold";
             tag:  "tab" "\t";
+            tag:  "match" "+ color=#e61c00";
          }
       }
 
index 0d0de7e..18b26f2 100644 (file)
@@ -73,9 +73,10 @@ namespace Msg
              * @brief Search first keyword and highlight it
              * @param[in] str text with keyword
              * @param[in] searchWord word for highlight
+             * @param[out] true if search word found, false otherwise
              * @retval text with highlighted keyword if keyword found, input text otherwise
              */
-            static std::string highlightKeyword(std::string str, const std::string &searchWord);
+            static std::string highlightKeyword(std::string str, const std::string &searchWord, bool *foundRes = nullptr);
     };
 }
 
index e3b486f..874be63 100644 (file)
@@ -132,8 +132,11 @@ std::string TextDecorator::make(const std::string &text,
     return ss.str();
 }
 
-std::string TextDecorator::highlightKeyword(std::string str, const std::string &searchWord)
+std::string TextDecorator::highlightKeyword(std::string str, const std::string &searchWord, bool *foundRes)
 {
+    if(foundRes)
+        *foundRes = false;
+
     if(str.empty() || searchWord.empty())
         return std::move(str);
 
@@ -141,6 +144,9 @@ std::string TextDecorator::highlightKeyword(std::string str, const std::string &
     if(!found)
         return str;
 
+    if(foundRes)
+        *foundRes = true;
+
     std::string res;
     res.reserve(str.length() + 32); // Reserve string length + highlight tags length
 
index 9a3bd55..0a945f1 100644 (file)
@@ -45,7 +45,7 @@ namespace Msg
 
             BubbleEntity *createEntity(const std::string &filePath, BubbleBgViewItem::BgType bgType, Message::Direction direction);
             BubbleEntity *createEntity(const MsgConvMedia &msgMedia, BubbleBgViewItem::BgType bgType, Message::Direction direction);
-            BubbleTextEntity *createTextEntity(const std::string &text, BubbleBgViewItem::BgType bgType, Message::Direction direction);
+            BubbleTextEntity *createTextEntity(std::string text, BubbleBgViewItem::BgType bgType, Message::Direction direction);
             BubbleDownloadButtonEntity *createDownloadButtonEntity(Message::Direction direction);
 
         private:
index 4f1a540..76882ae 100644 (file)
@@ -27,7 +27,7 @@ namespace Msg
         : public BubbleBgEntity
     {
         public:
-            BubbleTextEntity(BubbleBgViewItem::BgType type, Message::Direction direction, const std::string &text);
+            BubbleTextEntity(BubbleBgViewItem::BgType type, Message::Direction direction, std::string text);
             virtual ~BubbleTextEntity();
 
             virtual BubbleTextViewItem *createView(Evas_Object *parent);
@@ -36,9 +36,9 @@ namespace Msg
             std::string m_Text;
     };
 
-    inline BubbleTextEntity::BubbleTextEntity(BubbleBgViewItem::BgType type, Message::Direction direction, const std::string &text)
+    inline BubbleTextEntity::BubbleTextEntity(BubbleBgViewItem::BgType type, Message::Direction direction, std::string text)
         : BubbleBgEntity(TextItem, type, direction)
-        , m_Text(text)
+        , m_Text(std::move(text))
     {
     }
 
index 65d96da..95e31a4 100644 (file)
@@ -88,8 +88,8 @@ namespace Msg
         private:
             ConvListViewItem::ConvItemType getConvItemType(const MsgConversationItem &item);
             void prepareBubble(const MsgConversationItem &item, const std::string &searchWord);
-            BubbleEntity *createTextEntity(BubbleBgViewItem::BgType bgType, Message::Direction direction, const MsgConvMedia &media, const std::string &searchWord);
-            BubbleEntity *createTextEntity(BubbleBgViewItem::BgType bgType, Message::Direction direction, std::string text, bool markup, const std::string &searchWord);
+            BubbleEntity *createTextEntity(BubbleBgViewItem::BgType bgType, Message::Direction direction, const MsgConvMedia &media, std::string searchWord);
+            BubbleEntity *createTextEntity(BubbleBgViewItem::BgType bgType, Message::Direction direction, std::string text, bool markup, std::string searchWord);
             void addEntity(BubbleEntity *entity);
             void updateEntityBgType(BubbleBgViewItem::BgType bgType);
             BubbleBgViewItem::BgType getBubbleBgType(const MsgConversationItem &item);
index 6d5389f..24b24d0 100644 (file)
@@ -65,9 +65,9 @@ BubbleEntity *BubbleEntityFactory::createEntity(const std::string &filePath, Bub
     return createEntity(filePath, FileUtils::getFileName(filePath), FileUtils::getMimeType(filePath), bgType, direction);
 }
 
-BubbleTextEntity *BubbleEntityFactory::createTextEntity(const std::string &text, BubbleBgViewItem::BgType bgType, Message::Direction direction)
+BubbleTextEntity *BubbleEntityFactory::createTextEntity(std::string text, BubbleBgViewItem::BgType bgType, Message::Direction direction)
 {
-    return text.empty() ? nullptr : new BubbleTextEntity(bgType, direction, text);
+    return text.empty() ? nullptr : new BubbleTextEntity(bgType, direction, std::move(text));
 }
 
 BubbleDownloadButtonEntity *BubbleEntityFactory::createDownloadButtonEntity(Message::Direction direction)
index 17ed1ab..3dc569a 100644 (file)
 
 using namespace Msg;
 
-namespace
-{
-    bool findText(const std::string &text, const std::string &searchWord)
-    {
-        if(text.empty() || searchWord.empty())
-            return false;
-
-        std::string s(markupToUtf8(text));
-        std::transform(s.begin(), s.end(), s.begin(), tolower);
-        std::string sw(markupToUtf8(searchWord));
-        std::transform(sw.begin(), sw.end(), sw.begin(), tolower);
-        size_t size = s.find(sw);
-        return size != std::string::npos;
-    }
-}
-
 ConvListItem::ConvListItem(const MsgConversationItem &item,
                            App &app,
                            BubbleEntityFactory &bubbleEntityFactory,
@@ -164,21 +148,23 @@ BubbleBgViewItem::BgType ConvListItem::getBubbleBgType(const MsgConversationItem
 }
 
 
-BubbleEntity *ConvListItem::createTextEntity(BubbleBgViewItem::BgType bgType, Message::Direction direction, const MsgConvMedia &media, const std::string &searchWord)
+BubbleEntity *ConvListItem::createTextEntity(BubbleBgViewItem::BgType bgType, Message::Direction direction, const MsgConvMedia &media, std::string searchWord)
 {
     std::string text = FileUtils::readTextFile(media.getPath());
-
-    if(findText(text, searchWord))
-        showSearch();
-    return m_BubbleEntityFactory.createTextEntity(utf8ToMarkup(text), bgType, direction);
+    return createTextEntity(bgType, direction, std::move(text), true, std::move(searchWord));
 }
 
-BubbleEntity *ConvListItem::createTextEntity(BubbleBgViewItem::BgType bgType, Message::Direction direction, std::string text, bool markup, const std::string &searchWord)
+BubbleEntity *ConvListItem::createTextEntity(BubbleBgViewItem::BgType bgType, Message::Direction direction, std::string text, bool markup, std::string searchWord)
 {
-    if(findText(text, searchWord))
+    bool found = false;
+    std::string markupText = markup ? utf8ToMarkup(text) : std::move(text);
+    std::string markupSearchWord = markup ? utf8ToMarkup(searchWord) : std::move(searchWord);
+    std::string resText = TextDecorator::highlightKeyword(std::move(markupText), markupSearchWord, &found);
+
+    if(found)
         showSearch();
-    std::string resText = markup ? utf8ToMarkup(text) : std::move(text);
-    return m_BubbleEntityFactory.createTextEntity(resText, bgType, direction);
+
+    return m_BubbleEntityFactory.createTextEntity(std::move(resText), bgType, direction);
 }
 
 BubbleDownloadButtonEntity *ConvListItem::findDownloadButton() const
@@ -219,7 +205,7 @@ void ConvListItem::prepareBubble(const MsgConversationItem &item, const std::str
     Message::Direction direction = item.getDirection();
     if(item.isRestrictedByDpm())
     {
-        addEntity(createTextEntity(BubbleBgViewItem::RestrictedStyle, direction, msg("IDS_MSG_BODY_COULDNT_RECEIVE_THIS_MESSAGE_THE_SECURITY_POLICY_PREVENTS_RECEIVING_MESSAGES"), true, ""));
+        addEntity(createTextEntity(BubbleBgViewItem::RestrictedStyle, direction, msg("IDS_MSG_BODY_COULDNT_RECEIVE_THIS_MESSAGE_THE_SECURITY_POLICY_PREVENTS_RECEIVING_MESSAGES"), false, ""));
     }
     else if(!MsgUtils::isMms(m_Type))
     {
@@ -228,7 +214,7 @@ void ConvListItem::prepareBubble(const MsgConversationItem &item, const std::str
     else if(m_Type == Message::MT_MMS_Noti)
     {
         std::string text = MessageDetailContent::getMmsNotiConvListItemContent(m_App, m_MsgId);
-        addEntity(createTextEntity(bgType, direction, text, false, searchWord));
+        addEntity(createTextEntity(bgType, direction, std::move(text), false, searchWord));
         addEntity(m_BubbleEntityFactory.createDownloadButtonEntity(direction));
         updateDownloadButton();
     }