2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "browser-find-word.h"
20 #include "browser-window.h"
22 #define FIND_WORD_MAX_COUNT 999
24 Browser_Find_Word::Browser_Find_Word(Browser_View *browser_view)
26 : m_find_word_index(0)
27 ,m_find_word_max_count(0)
28 ,m_browser_view(browser_view)
30 BROWSER_LOGD("[%s]", __func__);
33 Browser_Find_Word::~Browser_Find_Word(void)
35 BROWSER_LOGD("[%s]", __func__);
38 void Browser_Find_Word::__did_find_string_cb(Evas_Object* o, const char* string, int match_count, void* user_data)
40 BROWSER_LOGD("match_count = %d", match_count);
42 Browser_Find_Word *find_word = (Browser_Find_Word *)user_data;
43 find_word->m_find_word_max_count = (unsigned int)match_count;
45 if (match_count == 0) {
46 find_word->m_find_word_index = 0;
47 find_word->m_find_word_max_count = 0;
49 find_word->m_browser_view->_update_find_word_index_text("0/0");
53 if (find_word->m_find_word_max_count < 0 || find_word->m_find_word_max_count > FIND_WORD_MAX_COUNT) {
54 BROWSER_LOGD("Matched word counts are over Max. which browser supported. Set as Maximum");
55 find_word->m_find_word_max_count = FIND_WORD_MAX_COUNT;
58 GString *index_string = g_string_new(NULL);
60 BROWSER_LOGE("g_string_new failed");
63 g_string_printf(index_string, "%d/%d", find_word->m_find_word_index, find_word->m_find_word_max_count);
64 find_word->m_browser_view->_update_find_word_index_text(index_string->str);
65 g_string_free(index_string, true);
68 int Browser_Find_Word::find_word(const char *word, Find_Word_Direction direction)
70 BROWSER_LOGD("word to find=[%s]", word);
72 if (direction == BROWSER_FIND_WORD_FORWARD) {
75 ewk_view_string_find(m_browser_view->m_focused_window->m_ewk_view, word,
76 EWK_FIND_OPTIONS_CASE_INSENSITIVE | EWK_FIND_OPTIONS_WRAP_AROUND
77 | EWK_FIND_OPTIONS_SHOW_FIND_INDICATOR | EWK_FIND_OPTIONS_SHOW_HIGHLIGHT, FIND_WORD_MAX_COUNT,
78 __did_find_string_cb, this);
79 } else if (direction == BROWSER_FIND_WORD_BACKWARD) {
81 ewk_view_string_find(m_browser_view->m_focused_window->m_ewk_view, word,
82 EWK_FIND_OPTIONS_CASE_INSENSITIVE | EWK_FIND_OPTIONS_BACKWARDS | EWK_FIND_OPTIONS_WRAP_AROUND
83 | EWK_FIND_OPTIONS_SHOW_FIND_INDICATOR | EWK_FIND_OPTIONS_SHOW_HIGHLIGHT, FIND_WORD_MAX_COUNT,
84 __did_find_string_cb, this);
86 if (m_find_word_index > FIND_WORD_MAX_COUNT)
87 m_find_word_index = FIND_WORD_MAX_COUNT;
89 if (m_find_word_index < 0)
90 m_find_word_index = 0;
92 return m_find_word_index;
95 void Browser_Find_Word::init_index()
97 m_find_word_index = 0;
100 int Browser_Find_Word::get_match_max_value()
102 return m_find_word_max_count;