2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.
17 #include "SearchBox.h"
18 #include "BrowserLogger.h"
20 namespace tizen_browser
25 SearchBox::SearchBox(Evas_Object *parent)
27 std::string edjFilePath = EDJE_DIR;
28 edjFilePath.append("SimpleUI/SearchBox.edj");
29 elm_theme_extension_add(NULL, edjFilePath.c_str());
31 m_entry_layout = elm_layout_add(parent);
32 if(!elm_layout_file_set(m_entry_layout, edjFilePath.c_str(), "search_box"))
33 throw std::runtime_error("Layout file not found: " + edjFilePath);
35 m_webSearchEntry = elm_entry_add(m_entry_layout);
37 elm_object_style_set(m_webSearchEntry, "search_entry");
39 elm_entry_single_line_set(m_webSearchEntry, EINA_TRUE);
40 elm_entry_scrollable_set(m_webSearchEntry, EINA_TRUE);
42 search_caseSensitive = false;
44 elm_object_translatable_part_text_set(m_webSearchEntry, "elm.guide", "Search");
46 evas_object_smart_callback_add(m_webSearchEntry, "changed,user", SearchBox::searchNext, this);
48 //Add Case sensitive checkbox
49 m_caseSensitive = elm_check_add(m_entry_layout);
50 elm_object_part_text_set(m_caseSensitive, "default", "Match case");
51 elm_object_part_text_set(m_caseSensitive, "on", "Match case");
52 elm_object_part_text_set(m_caseSensitive, "off", "Match case");
53 elm_check_state_set(m_caseSensitive, EINA_FALSE);
54 elm_object_part_content_set(m_entry_layout, "search_opts_case", m_caseSensitive);
56 //Add prev and next buttons
57 m_searchPrev = elm_button_add(m_entry_layout);
58 elm_object_style_set(m_searchPrev, "default_button");
59 elm_object_part_text_set(m_searchPrev, "default", "Prev");
60 elm_object_part_content_set(m_entry_layout, "search_opts_prev", m_searchPrev);
62 m_searchNext = elm_button_add(m_entry_layout);
63 elm_object_style_set(m_searchNext, "default_button");
64 elm_object_part_text_set(m_searchNext, "default", "Next");
65 elm_object_part_content_set(m_entry_layout, "search_opts_next", m_searchNext);
67 evas_object_smart_callback_add(m_searchNext, "clicked", SearchBox::searchNext, this);
68 evas_object_smart_callback_add(m_searchPrev, "clicked", SearchBox::searchPrev, this);
69 evas_object_smart_callback_add(m_caseSensitive, "changed", SearchBox::caseSensitiveChanged, this);
71 elm_object_part_content_set(m_entry_layout, "search_entry_swallow", m_webSearchEntry);
76 Evas_Object* SearchBox::getContent()
78 return m_entry_layout;
81 void SearchBox::hide()
83 elm_object_signal_emit(m_entry_layout, "elm,state,hide", "elm");
84 elm_object_signal_emit(m_searchNext, "elm,state,hide", "elm");
85 elm_object_signal_emit(m_searchPrev, "elm,state,hide", "elm");
86 elm_object_signal_emit(m_webSearchEntry, "elm,state,hide", "elm");
87 elm_entry_entry_set(m_webSearchEntry, "");
88 // evas_object_hide(m_caseSensitive);
92 void SearchBox::show()
94 elm_object_signal_emit(m_entry_layout, "elm,state,show", "elm");
95 elm_object_signal_emit(m_searchNext, "elm,state,show", "elm");
96 elm_object_signal_emit(m_searchPrev, "elm,state,show", "elm");
97 elm_object_signal_emit(m_webSearchEntry, "elm,state,show", "elm");
98 // evas_object_show(m_caseSensitive);
102 bool SearchBox::is_visible()
107 void SearchBox::searchNext(void *data, Evas_Object */*obj*/, void */*event_info*/)
109 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
110 SearchBox *self = reinterpret_cast<SearchBox*>(data);
111 std::string entry(elm_entry_markup_to_utf8(elm_entry_entry_get(self->m_webSearchEntry)));
113 if (self->search_caseSensitive)
114 self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT);
116 self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
120 void SearchBox::searchPrev(void *data, Evas_Object */*obj*/, void */*event_info*/)
122 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
123 SearchBox *self = reinterpret_cast<SearchBox*>(data);
124 std::string entry(elm_entry_markup_to_utf8(elm_entry_entry_get(self->m_webSearchEntry)));
126 if (self->search_caseSensitive)
127 self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_BACKWARDS);
129 self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE | EWK_FIND_OPTIONS_BACKWARDS);
133 void SearchBox::caseSensitiveChanged(void *data, Evas_Object */*obj*/, void */*event_info*/)
135 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
136 SearchBox *self = reinterpret_cast<SearchBox*>(data);
137 std::string entry(elm_entry_markup_to_utf8(elm_entry_entry_get(self->m_webSearchEntry)));
138 self->search_caseSensitive = elm_check_state_get(self->m_caseSensitive);
140 if (self->search_caseSensitive)
141 self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT);
143 self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE);