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 void ZoomUI::createLayout(Evas_Object *parent)
108 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
110 m_layout = elm_layout_add(parent);
111 elm_layout_file_set(m_layout, m_edjFilePath.c_str(), "zoom-layout");
112 evas_object_size_hint_weight_set(m_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
113 evas_object_size_hint_align_set(m_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
115 createNavigationButtons();
118 void ZoomUI::createZoomSlider()
120 m_zoom_menu = elm_layout_add(m_layout);
121 elm_layout_file_set(m_zoom_menu, m_edjFilePath.c_str(), "zoom-menu");
122 evas_object_size_hint_weight_set(m_zoom_menu, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
123 evas_object_size_hint_align_set(m_zoom_menu, EVAS_HINT_FILL, EVAS_HINT_FILL);
125 m_zoom_slider = elm_slider_add(m_zoom_menu);
126 evas_object_size_hint_weight_set(m_zoom_slider, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
127 evas_object_size_hint_align_set(m_zoom_slider, EVAS_HINT_FILL, EVAS_HINT_FILL);
128 evas_object_smart_callback_add(m_zoom_slider, "changed", _zoom_slider_changed, this);
129 elm_object_style_set(m_zoom_slider, "default");
130 elm_slider_horizontal_set(m_zoom_slider, EINA_TRUE);
131 elm_slider_min_max_set(m_zoom_slider, 1, 6);
132 elm_slider_step_set(m_zoom_slider, 0.2);
133 int zoomFactor = *(getZoom());
134 elm_slider_value_set(m_zoom_slider, calculateSliderValue(zoomFactor));
135 elm_slider_indicator_show_set(m_zoom_slider, EINA_FALSE);
137 elm_object_part_content_set(m_zoom_menu, "slider_swallow", m_zoom_slider);
138 evas_object_event_callback_add(m_zoom_slider, EVAS_CALLBACK_KEY_DOWN, _zoom_value_confirmed, this);
141 void ZoomUI::createNavigationButtons()
143 m_nav_layout = elm_layout_add(m_layout);
144 elm_layout_file_set(m_nav_layout, m_edjFilePath.c_str(), "nav-layout");
145 evas_object_size_hint_weight_set(m_nav_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
146 evas_object_size_hint_align_set(m_nav_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
148 m_leftArrow = elm_icon_add(m_nav_layout);
149 setImageFile(m_leftArrow, LEFT, false);
150 evas_object_smart_callback_add(m_leftArrow, "clicked", _left_button_clicked, this);
151 evas_object_event_callback_add(m_leftArrow, EVAS_CALLBACK_MOUSE_IN, _cb_focus_in_left_button, this);
152 evas_object_event_callback_add(m_leftArrow, EVAS_CALLBACK_MOUSE_OUT, _cb_focus_out_left_button, this);
153 elm_object_part_content_set(m_nav_layout, "left_button", m_leftArrow);
155 m_rightArrow = elm_icon_add(m_nav_layout);
156 setImageFile(m_rightArrow, RIGHT, false);
157 evas_object_smart_callback_add(m_rightArrow, "clicked", _right_button_clicked, this);
158 evas_object_event_callback_add(m_rightArrow, EVAS_CALLBACK_MOUSE_IN, _cb_focus_in_right_button, this);
159 evas_object_event_callback_add(m_rightArrow, EVAS_CALLBACK_MOUSE_OUT, _cb_focus_out_right_button, this);
160 elm_object_part_content_set(m_nav_layout, "right_button", m_rightArrow);
162 m_downArrow = elm_icon_add(m_nav_layout);
163 setImageFile(m_downArrow, DOWN, false);
164 evas_object_smart_callback_add(m_downArrow, "clicked", _down_button_clicked, this);
165 evas_object_event_callback_add(m_downArrow, EVAS_CALLBACK_MOUSE_IN, _cb_focus_in_down_button, this);
166 evas_object_event_callback_add(m_downArrow, EVAS_CALLBACK_MOUSE_OUT, _cb_focus_out_down_button, this);
167 elm_object_part_content_set(m_nav_layout, "down_button", m_downArrow);
169 m_upArrow = elm_icon_add(m_nav_layout);
170 setImageFile(m_upArrow, UP, false);
171 evas_object_smart_callback_add(m_upArrow, "clicked", _up_button_clicked, this);
172 evas_object_event_callback_add(m_upArrow, EVAS_CALLBACK_MOUSE_IN, _cb_focus_in_up_button, this);
173 evas_object_event_callback_add(m_upArrow, EVAS_CALLBACK_MOUSE_OUT, _cb_focus_out_up_button, this);
174 elm_object_part_content_set(m_nav_layout, "up_button", m_upArrow);
177 void ZoomUI::clearItems()
179 evas_object_del(m_layout);
180 setZoom(ZOOM_DEFAULT);
183 void ZoomUI::setImageFile(Evas_Object* obj, int direction, bool focused)
185 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
187 case LEFT: elm_image_file_set(obj, m_edjFilePath.c_str(), focused ? "ic_zoom_indicator_left_foc.png" : "ic_zoom_indicator_left_nor.png");
189 case RIGHT: elm_image_file_set(obj, m_edjFilePath.c_str(), focused ? "ic_zoom_indicator_right_foc.png" : "ic_zoom_indicator_right_nor.png");
191 case DOWN: elm_image_file_set(obj, m_edjFilePath.c_str(), focused ? "ic_zoom_indicator_down_foc.png" : "ic_zoom_indicator_down_nor.png");
193 case UP: elm_image_file_set(obj, m_edjFilePath.c_str(), focused ? "ic_zoom_indicator_up_foc.png" : "ic_zoom_indicator_up_nor.png");
195 default: BROWSER_LOGD("[%s:%d] Warning: Unhandled button", __PRETTY_FUNCTION__, __LINE__);
200 void ZoomUI::_zoom_slider_changed(void *data, Evas_Object *obj, void*)
202 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
204 int val = elm_slider_value_get(obj);
205 int zoomLevel = ZOOM_DEFAULT;
206 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
209 case 1: zoomLevel = ZOOM_50;
211 case 2: zoomLevel = ZOOM_75;
213 case 3: zoomLevel = ZOOM_DEFAULT;
215 case 4: zoomLevel = ZOOM_150;
217 case 5: zoomLevel = ZOOM_200;
219 case 6: zoomLevel = ZOOM_300;
221 default:BROWSER_LOGD("[%s:%d] Warning: Unhandled zoom level", __PRETTY_FUNCTION__, __LINE__);
224 zoomUI->setZoom(zoomLevel);
228 void ZoomUI::_zoom_value_confirmed(void* data, Evas*, Evas_Object*, void* event_info)
230 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
231 Evas_Event_Key_Down* ev = static_cast<Evas_Event_Key_Down*>(event_info);
233 if (!data || !ev || !ev->keyname)
236 ZoomUI* self = static_cast<ZoomUI*>(data);
237 if (std::string(ev->keyname) == "Return") {
238 int val = (int)elm_slider_value_get(self->m_zoom_slider);
239 BROWSER_LOGD("[%s:%d] val: %d", __PRETTY_FUNCTION__, __LINE__, val);
241 BROWSER_LOGD("[%s:%d] value is greater than 3", __PRETTY_FUNCTION__, __LINE__);
242 evas_object_show(self->m_nav_layout);
244 BROWSER_LOGD("[%s:%d] value is smaller or equal to 3", __PRETTY_FUNCTION__, __LINE__);
245 evas_object_hide(self->m_nav_layout);
247 evas_object_hide(self->m_zoom_menu);
251 Eina_Bool ZoomUI::_key_down_cb(void* data, int, void* event_info)
253 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
254 Ecore_Event_Key* ev = static_cast<Ecore_Event_Key*>(event_info);
256 if (!data || !ev || !ev->keyname)
259 ZoomUI* self = static_cast<ZoomUI*>(data);
260 if (std::string(ev->keyname) == "Left") {
261 _left_button_clicked(data, self->m_leftArrow, event_info);
262 _cb_focus_in_left_button(data, nullptr, self->m_leftArrow, event_info);
263 } else if (std::string(ev->keyname) == "Right") {
264 _right_button_clicked(data, self->m_rightArrow, event_info);
265 _cb_focus_in_right_button(data, nullptr, self->m_rightArrow, event_info);
266 } else if (std::string(ev->keyname) == "Up") {
267 _up_button_clicked(data, self->m_upArrow, event_info);
268 _cb_focus_in_up_button(data, nullptr, self->m_upArrow, event_info);
269 } else if (std::string(ev->keyname) == "Down") {
270 _down_button_clicked(data, self->m_downArrow, event_info);
271 _cb_focus_in_down_button(data, nullptr, self->m_downArrow, event_info);
278 Eina_Bool ZoomUI::_key_up_cb(void* data, int, void* event_info)
280 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
281 Ecore_Event_Key* ev = static_cast<Ecore_Event_Key*>(event_info);
283 if (!data || !ev || !ev->keyname)
286 ZoomUI* self = static_cast<ZoomUI*>(data);
287 if (std::string(ev->keyname) == "Left") {
288 _cb_focus_out_left_button(data, nullptr, self->m_leftArrow, event_info);
289 } else if (std::string(ev->keyname) == "Right") {
290 _cb_focus_out_right_button(data, nullptr, self->m_rightArrow, event_info);
291 } else if (std::string(ev->keyname) == "Up") {
292 _cb_focus_out_up_button(data, nullptr, self->m_upArrow, event_info);
293 } else if (std::string(ev->keyname) == "Down") {
294 _cb_focus_out_down_button(data, nullptr, self->m_downArrow, event_info);
301 void ZoomUI::_left_button_clicked(void * data, Evas_Object * obj, void*)
303 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
305 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
306 zoomUI->scrollView(iDX, 0);
310 void ZoomUI::_right_button_clicked(void * data, Evas_Object * obj, void*)
312 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
314 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
315 zoomUI->scrollView(DX, 0);
319 void ZoomUI::_up_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(0, iDX);
328 void ZoomUI::_down_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(0, DX);
337 void ZoomUI::_cb_focus_in_left_button(void * data, Evas *, Evas_Object *obj, void *)
339 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
341 elm_object_focus_set(obj, EINA_TRUE);
342 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
343 zoomUI->setImageFile(obj, LEFT, true);
347 void ZoomUI::_cb_focus_out_left_button(void * data, Evas *, Evas_Object *obj, void *)
349 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
351 elm_object_focus_set(obj, EINA_FALSE);
352 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
353 zoomUI->setImageFile(obj, LEFT, false);
357 void ZoomUI::_cb_focus_in_right_button(void * data, Evas *, Evas_Object *obj, void *)
359 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
361 elm_object_focus_set(obj, EINA_TRUE);
362 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
363 zoomUI->setImageFile(obj, RIGHT, true);
367 void ZoomUI::_cb_focus_out_right_button(void * data, Evas *, Evas_Object *obj, void *)
369 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
371 elm_object_focus_set(obj, EINA_FALSE);
372 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
373 zoomUI->setImageFile(obj, RIGHT, false);
377 void ZoomUI::_cb_focus_in_up_button(void * data, Evas *, Evas_Object *obj, void *)
379 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
381 elm_object_focus_set(obj, EINA_TRUE);
382 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
383 zoomUI->setImageFile(obj, UP, true);
387 void ZoomUI::_cb_focus_out_up_button(void * data, Evas *, Evas_Object *obj, void *)
389 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
391 elm_object_focus_set(obj, EINA_FALSE);
392 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
393 zoomUI->setImageFile(obj, UP, false);
397 void ZoomUI::_cb_focus_in_down_button(void * data, Evas *, Evas_Object *obj, void *)
399 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
401 elm_object_focus_set(obj, EINA_TRUE);
402 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
403 zoomUI->setImageFile(obj, DOWN, true);
407 void ZoomUI::_cb_focus_out_down_button(void * data, Evas *, Evas_Object *obj, void *)
409 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
411 elm_object_focus_set(obj, EINA_FALSE);
412 ZoomUI *zoomUI = static_cast<ZoomUI*>(data);
413 zoomUI->setImageFile(obj, DOWN, false);
417 int ZoomUI::calculateSliderValue(int zoom)
419 BROWSER_LOGD("[%s:%d] zoom factor: %d", __PRETTY_FUNCTION__, __LINE__, zoom);
420 int rv = 1; //for zoom < ZOOM_75
421 if (zoom >= ZOOM_300)
423 else if (zoom >= ZOOM_200)
425 else if (zoom >= ZOOM_150)
427 else if (zoom >= ZOOM_100)
429 else if (zoom >= ZOOM_75)