2 * Copyright (c) 2015 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.
18 #include <Elementary.h>
19 #include <boost/concept_check.hpp>
21 #include <AbstractMainWindow.h>
24 #include "BrowserLogger.h"
25 #include "ServiceManager.h"
30 namespace tizen_browser{
33 EXPORT_SERVICE(ZoomUI, "org.tizen.browser.zoomui")
37 , m_zoom_slider(nullptr)
38 , m_nav_layout(nullptr)
39 , m_current_translation_x(0)
40 , m_current_translation_y(0)
42 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
43 m_edjFilePath = EDJE_DIR;
44 m_edjFilePath.append("ZoomUI/ZoomUI.edj");
45 elm_theme_extension_add(nullptr, m_edjFilePath.c_str());
50 void ZoomUI::init(Evas_Object* parent)
52 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
57 Evas_Object* ZoomUI::getContent()
59 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
62 createLayout(m_parent);
68 evas_object_show(m_layout);
69 evas_object_show(m_zoom_menu);
70 evas_object_show(m_zoom_slider);
71 m_keyDownHandler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _key_down_cb, this);
72 m_keyUpHandler = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _key_up_cb, this);
73 int zoomFactor = *(getZoom());
74 elm_slider_value_set(m_zoom_slider, calculateSliderValue(zoomFactor));
79 evas_object_hide(m_zoom_slider);
80 evas_object_hide(m_nav_layout);
81 evas_object_hide(m_zoom_menu);
82 evas_object_hide(m_layout);
83 ecore_event_handler_del(m_keyDownHandler);
84 ecore_event_handler_del(m_keyUpHandler);
87 void ZoomUI::show(Evas_Object* parent)
89 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
94 elm_object_focus_set(m_zoom_slider, EINA_TRUE);
97 void ZoomUI::showNavigation()
99 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
100 M_ASSERT(m_nav_layout);
101 int zoomFactor = *(getZoom());
102 if (zoomFactor > ZOOM_DEFAULT)
103 evas_object_show(m_nav_layout);
106 bool ZoomUI::isVisible()
108 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
109 if (evas_object_visible_get(m_layout) || (*(getZoom()) != ZOOM_DEFAULT))
115 void ZoomUI::createLayout(Evas_Object *parent)
117 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
119 m_layout = elm_layout_add(parent);
120 elm_layout_file_set(m_layout, m_edjFilePath.c_str(), "zoom-layout");
121 evas_object_size_hint_weight_set(m_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
122 evas_object_size_hint_align_set(m_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
124 createNavigationButtons();
127 void ZoomUI::createZoomSlider()
129 m_zoom_menu = elm_layout_add(m_layout);
130 elm_layout_file_set(m_zoom_menu, m_edjFilePath.c_str(), "zoom-menu");
131 evas_object_size_hint_weight_set(m_zoom_menu, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132 evas_object_size_hint_align_set(m_zoom_menu, EVAS_HINT_FILL, EVAS_HINT_FILL);
134 m_zoom_slider = elm_slider_add(m_zoom_menu);
135 evas_object_size_hint_weight_set(m_zoom_slider, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
136 evas_object_size_hint_align_set(m_zoom_slider, EVAS_HINT_FILL, EVAS_HINT_FILL);
137 evas_object_smart_callback_add(m_zoom_slider, "changed", _zoom_slider_changed, this);
138 elm_object_style_set(m_zoom_slider, "default");
139 elm_slider_horizontal_set(m_zoom_slider, EINA_TRUE);
140 elm_slider_min_max_set(m_zoom_slider, 1, 6);
141 elm_slider_step_set(m_zoom_slider, 0.2);
142 int zoomFactor = *(getZoom());
143 elm_slider_value_set(m_zoom_slider, calculateSliderValue(zoomFactor));
144 elm_slider_indicator_show_set(m_zoom_slider, EINA_FALSE);
146 elm_object_part_content_set(m_zoom_menu, "slider_swallow", m_zoom_slider);
147 evas_object_event_callback_add(m_zoom_slider, EVAS_CALLBACK_KEY_DOWN, _zoom_value_confirmed, this);
150 void ZoomUI::createNavigationButtons()
152 m_nav_layout = elm_layout_add(m_layout);
153 elm_layout_file_set(m_nav_layout, m_edjFilePath.c_str(), "nav-layout");
154 evas_object_size_hint_weight_set(m_nav_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
155 evas_object_size_hint_align_set(m_nav_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
157 m_leftArrow = elm_icon_add(m_nav_layout);
158 setImageFile(m_leftArrow, LEFT, false);
159 evas_object_smart_callback_add(m_leftArrow, "clicked", _left_button_clicked, this);
160 evas_object_event_callback_add(m_leftArrow, EVAS_CALLBACK_MOUSE_IN, _cb_focus_in_left_button, this);
161 evas_object_event_callback_add(m_leftArrow, EVAS_CALLBACK_MOUSE_OUT, _cb_focus_out_left_button, this);
162 elm_object_part_content_set(m_nav_layout, "left_button", m_leftArrow);
164 m_rightArrow = elm_icon_add(m_nav_layout);
165 setImageFile(m_rightArrow, RIGHT, false);
166 evas_object_smart_callback_add(m_rightArrow, "clicked", _right_button_clicked, this);
167 evas_object_event_callback_add(m_rightArrow, EVAS_CALLBACK_MOUSE_IN, _cb_focus_in_right_button, this);
168 evas_object_event_callback_add(m_rightArrow, EVAS_CALLBACK_MOUSE_OUT, _cb_focus_out_right_button, this);
169 elm_object_part_content_set(m_nav_layout, "right_button", m_rightArrow);
171 m_downArrow = elm_icon_add(m_nav_layout);
172 setImageFile(m_downArrow, DOWN, false);
173 evas_object_smart_callback_add(m_downArrow, "clicked", _down_button_clicked, this);
174 evas_object_event_callback_add(m_downArrow, EVAS_CALLBACK_MOUSE_IN, _cb_focus_in_down_button, this);
175 evas_object_event_callback_add(m_downArrow, EVAS_CALLBACK_MOUSE_OUT, _cb_focus_out_down_button, this);
176 elm_object_part_content_set(m_nav_layout, "down_button", m_downArrow);
178 m_upArrow = elm_icon_add(m_nav_layout);
179 setImageFile(m_upArrow, UP, false);
180 evas_object_smart_callback_add(m_upArrow, "clicked", _up_button_clicked, this);
181 evas_object_event_callback_add(m_upArrow, EVAS_CALLBACK_MOUSE_IN, _cb_focus_in_up_button, this);
182 evas_object_event_callback_add(m_upArrow, EVAS_CALLBACK_MOUSE_OUT, _cb_focus_out_up_button, this);
183 elm_object_part_content_set(m_nav_layout, "up_button", m_upArrow);
186 void ZoomUI::clearItems()
188 evas_object_del(m_layout);
189 setZoom(ZOOM_DEFAULT);
192 void ZoomUI::setImageFile(Evas_Object* obj, int direction, bool focused)
194 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
196 case LEFT: elm_image_file_set(obj, m_edjFilePath.c_str(), focused ? "ic_zoom_indicator_left_foc.png" : "ic_zoom_indicator_left_nor.png");
198 case RIGHT: elm_image_file_set(obj, m_edjFilePath.c_str(), focused ? "ic_zoom_indicator_right_foc.png" : "ic_zoom_indicator_right_nor.png");
200 case DOWN: elm_image_file_set(obj, m_edjFilePath.c_str(), focused ? "ic_zoom_indicator_down_foc.png" : "ic_zoom_indicator_down_nor.png");
202 case UP: elm_image_file_set(obj, m_edjFilePath.c_str(), focused ? "ic_zoom_indicator_up_foc.png" : "ic_zoom_indicator_up_nor.png");
204 default: BROWSER_LOGD("[%s:%d] Warning: Unhandled button", __PRETTY_FUNCTION__, __LINE__);
209 void ZoomUI::_zoom_slider_changed(void *data, Evas_Object *obj, void*)
211 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
213 int val = elm_slider_value_get(obj);
214 int zoomLevel = ZOOM_DEFAULT;
215 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
218 case 1: zoomLevel = ZOOM_50;
220 case 2: zoomLevel = ZOOM_75;
222 case 3: zoomLevel = ZOOM_DEFAULT;
224 case 4: zoomLevel = ZOOM_150;
226 case 5: zoomLevel = ZOOM_200;
228 case 6: zoomLevel = ZOOM_300;
230 default:BROWSER_LOGD("[%s:%d] Warning: Unhandled zoom level", __PRETTY_FUNCTION__, __LINE__);
233 zoomUI->setZoom(zoomLevel);
237 void ZoomUI::_zoom_value_confirmed(void* data, Evas*, Evas_Object*, void* event_info)
239 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
240 Evas_Event_Key_Down* ev = static_cast<Evas_Event_Key_Down*>(event_info);
242 if (!data || !ev || !ev->keyname)
245 ZoomUI* self = static_cast<ZoomUI*>(data);
246 if (std::string(ev->keyname) == "Return") {
247 int val = (int)elm_slider_value_get(self->m_zoom_slider);
248 BROWSER_LOGD("[%s:%d] val: %d", __PRETTY_FUNCTION__, __LINE__, val);
250 BROWSER_LOGD("[%s:%d] value is greater than 3", __PRETTY_FUNCTION__, __LINE__);
251 evas_object_show(self->m_nav_layout);
253 BROWSER_LOGD("[%s:%d] value is smaller or equal to 3", __PRETTY_FUNCTION__, __LINE__);
254 evas_object_hide(self->m_nav_layout);
256 evas_object_hide(self->m_zoom_menu);
260 void ZoomUI::escapeZoom()
262 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
264 setZoom(ZoomUI::ZOOM_DEFAULT);
269 Eina_Bool ZoomUI::_key_down_cb(void* data, int, void* event_info)
271 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
272 Ecore_Event_Key* ev = static_cast<Ecore_Event_Key*>(event_info);
274 if (!data || !ev || !ev->keyname)
277 ZoomUI* self = static_cast<ZoomUI*>(data);
278 if (std::string(ev->keyname) == "Left") {
279 _left_button_clicked(data, self->m_leftArrow, event_info);
280 _cb_focus_in_left_button(data, nullptr, self->m_leftArrow, event_info);
281 } else if (std::string(ev->keyname) == "Right") {
282 _right_button_clicked(data, self->m_rightArrow, event_info);
283 _cb_focus_in_right_button(data, nullptr, self->m_rightArrow, event_info);
284 } else if (std::string(ev->keyname) == "Up") {
285 _up_button_clicked(data, self->m_upArrow, event_info);
286 _cb_focus_in_up_button(data, nullptr, self->m_upArrow, event_info);
287 } else if (std::string(ev->keyname) == "Down") {
288 _down_button_clicked(data, self->m_downArrow, event_info);
289 _cb_focus_in_down_button(data, nullptr, self->m_downArrow, event_info);
296 Eina_Bool ZoomUI::_key_up_cb(void* data, int, void* event_info)
298 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
299 Ecore_Event_Key* ev = static_cast<Ecore_Event_Key*>(event_info);
301 if (!data || !ev || !ev->keyname)
304 ZoomUI* self = static_cast<ZoomUI*>(data);
305 if (std::string(ev->keyname) == "Left") {
306 _cb_focus_out_left_button(data, nullptr, self->m_leftArrow, event_info);
307 } else if (std::string(ev->keyname) == "Right") {
308 _cb_focus_out_right_button(data, nullptr, self->m_rightArrow, event_info);
309 } else if (std::string(ev->keyname) == "Up") {
310 _cb_focus_out_up_button(data, nullptr, self->m_upArrow, event_info);
311 } else if (std::string(ev->keyname) == "Down") {
312 _cb_focus_out_down_button(data, nullptr, self->m_downArrow, event_info);
319 void ZoomUI::_left_button_clicked(void * data, Evas_Object * obj, void*)
321 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
323 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
324 zoomUI->scrollView(iDX, 0);
328 void ZoomUI::_right_button_clicked(void * data, Evas_Object * obj, void*)
330 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
332 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
333 zoomUI->scrollView(DX, 0);
337 void ZoomUI::_up_button_clicked(void * data, Evas_Object * obj, void*)
339 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
341 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
342 zoomUI->scrollView(0, iDX);
346 void ZoomUI::_down_button_clicked(void * data, Evas_Object * obj, void*)
348 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
350 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
351 zoomUI->scrollView(0, DX);
355 void ZoomUI::_cb_focus_in_left_button(void * data, Evas *, Evas_Object *obj, void *)
357 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
359 elm_object_focus_set(obj, EINA_TRUE);
360 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
361 zoomUI->setImageFile(obj, LEFT, true);
365 void ZoomUI::_cb_focus_out_left_button(void * data, Evas *, Evas_Object *obj, void *)
367 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
369 elm_object_focus_set(obj, EINA_FALSE);
370 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
371 zoomUI->setImageFile(obj, LEFT, false);
375 void ZoomUI::_cb_focus_in_right_button(void * data, Evas *, Evas_Object *obj, void *)
377 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
379 elm_object_focus_set(obj, EINA_TRUE);
380 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
381 zoomUI->setImageFile(obj, RIGHT, true);
385 void ZoomUI::_cb_focus_out_right_button(void * data, Evas *, Evas_Object *obj, void *)
387 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
389 elm_object_focus_set(obj, EINA_FALSE);
390 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
391 zoomUI->setImageFile(obj, RIGHT, false);
395 void ZoomUI::_cb_focus_in_up_button(void * data, Evas *, Evas_Object *obj, void *)
397 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
399 elm_object_focus_set(obj, EINA_TRUE);
400 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
401 zoomUI->setImageFile(obj, UP, true);
405 void ZoomUI::_cb_focus_out_up_button(void * data, Evas *, Evas_Object *obj, void *)
407 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
409 elm_object_focus_set(obj, EINA_FALSE);
410 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
411 zoomUI->setImageFile(obj, UP, false);
415 void ZoomUI::_cb_focus_in_down_button(void * data, Evas *, Evas_Object *obj, void *)
417 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
419 elm_object_focus_set(obj, EINA_TRUE);
420 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
421 zoomUI->setImageFile(obj, DOWN, true);
425 void ZoomUI::_cb_focus_out_down_button(void * data, Evas *, Evas_Object *obj, void *)
427 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
429 elm_object_focus_set(obj, EINA_FALSE);
430 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
431 zoomUI->setImageFile(obj, DOWN, false);
435 int ZoomUI::calculateSliderValue(int zoom)
437 BROWSER_LOGD("[%s:%d] zoom factor: %d", __PRETTY_FUNCTION__, __LINE__, zoom);
438 int rv = 1; //for zoom < ZOOM_75
439 if (zoom >= ZOOM_300)
441 else if (zoom >= ZOOM_200)
443 else if (zoom >= ZOOM_150)
445 else if (zoom >= ZOOM_100)
447 else if (zoom >= ZOOM_75)