ff28560cbb85cf340a69b51187c1142c841b8829
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / ubrowser / window_ui.cc
1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "window_ui.h"
6
7 #include <assert.h>
8 #include <Elementary.h>
9 #include <EWebKit.h>
10 #include <EWebKit_internal.h>
11 #include <EWebKit_product.h>
12
13 #include "browser.h"
14 #include "logger.h"
15 #include "window.h"
16
17 #include "tizen/system_info.h"
18
19 namespace {
20 static std::string kDefaultNewWindowURL = "http://www.google.com";
21 static double kMinViewScale = 1.0;
22 static double kMaxViewScale = 4.0;
23 static int kNotificationTimeoutSec = 3;
24 }
25
26 WindowUI::WindowUI(Window& window, Browser& browser)
27     : window_(window),
28       browser_(browser),
29       navbar_(nullptr),
30       urlbar_(nullptr),
31       url_entry_(nullptr),
32       stop_reload_button_(nullptr),
33       progress_bar_(nullptr),
34       forward_button_(nullptr),
35       back_button_(nullptr),
36       active_popup_(nullptr),
37       menu_(nullptr),
38 #if BUILDFLAG(IS_TIZEN_TV)
39       should_show_label_(true),
40 #else
41       should_show_label_(browser_.IsDesktop()),
42 #endif
43       is_loading_(false),
44       url_entry_color_() {
45   if (browser_.GetGUILevel() >= Browser::UBROWSER_GUI_LEVEL_URL_ONLY)
46     CreateTopBar();
47   if (browser_.GetGUILevel() >= Browser::UBROWSER_GUI_LEVEL_MINIMAL)
48     CreateBottomBar();
49
50   // TODO: Workaround for http://suprem.sec.samsung.net/jira/browse/TWF-843
51   if (IsTvProfile()) {
52     should_show_label_ = true;
53     Elm_Theme* theme = elm_theme_new();
54     elm_theme_set(theme, "tizen-HD-light");
55     elm_object_theme_set(navbar_, theme);
56     elm_theme_free(theme);
57   }
58 }
59
60 WindowUI::~WindowUI() {
61   if (active_popup_)
62     evas_object_del(active_popup_);
63 }
64
65 void WindowUI::OnURLChanged(const char* url) {
66   log_trace("%s: %s", __PRETTY_FUNCTION__, url);
67   if (url_entry_)
68     elm_object_text_set(url_entry_, url);
69 }
70
71 void WindowUI::OnLoadingStarted() {
72   log_trace("%s", __PRETTY_FUNCTION__);
73   if (progress_bar_)
74     elm_progressbar_pulse(progress_bar_, EINA_TRUE);
75   if (stop_reload_button_) {
76     Evas_Object* icon =
77         elm_object_part_content_get(stop_reload_button_, "icon");
78     elm_icon_standard_set(icon, "close");
79     if (should_show_label_)
80       elm_object_text_set(stop_reload_button_, "Stop");
81   }
82   is_loading_ = true;
83 }
84
85 void WindowUI::OnLoadingFinished() {
86   log_trace("%s", __PRETTY_FUNCTION__);
87   if (progress_bar_)
88     elm_progressbar_pulse(progress_bar_, EINA_FALSE);
89   if (stop_reload_button_) {
90     Evas_Object* icon =
91         elm_object_part_content_get(stop_reload_button_, "icon");
92     elm_icon_standard_set(icon, "refresh");
93     if (should_show_label_)
94       elm_object_text_set(stop_reload_button_, "Reload");
95   }
96   is_loading_ = false;
97 }
98
99 void WindowUI::EnableBackButton(bool enable) {
100   if (back_button_)
101     elm_object_disabled_set(back_button_, !enable);
102 }
103
104 void WindowUI::EnableForwardButton(bool enable) {
105   if (forward_button_)
106     elm_object_disabled_set(forward_button_, !enable);
107 }
108
109 void WindowUI::ShowNotification(const char* text) {
110   log_trace("%s : %s", __PRETTY_FUNCTION__, text);
111   Evas_Object* notification = elm_notify_add(window_.GetEvasObject());
112   elm_notify_timeout_set(notification, kNotificationTimeoutSec);
113   Evas_Object* content = elm_label_add(notification);
114   elm_object_text_set(content, text);
115   elm_object_content_set(notification, content);
116   elm_notify_align_set(notification, 0.5, 0.5);
117   evas_object_show(notification);
118 }
119
120 void WindowUI::CreateTopBar() {
121   urlbar_ = elm_box_add(window_.GetEvasObject());
122   elm_box_horizontal_set(urlbar_, EINA_TRUE);
123   evas_object_size_hint_weight_set(urlbar_, EVAS_HINT_EXPAND, 0.0f);
124   evas_object_size_hint_align_set(urlbar_, EVAS_HINT_FILL, EVAS_HINT_FILL);
125
126   if (browser_.GetGUILevel() >= Browser::UBROWSER_GUI_LEVEL_ALL) {
127     progress_bar_ = elm_progressbar_add(window_.GetEvasObject());
128     elm_object_style_set(progress_bar_, "wheel");
129     elm_progressbar_pulse_set(progress_bar_, EINA_TRUE);
130     elm_progressbar_pulse(progress_bar_, EINA_FALSE);
131     elm_box_pack_end(urlbar_, progress_bar_);
132     evas_object_show(progress_bar_);
133   }
134
135   url_entry_ = elm_entry_add(urlbar_);
136   elm_entry_single_line_set(url_entry_, EINA_TRUE);
137   elm_entry_scrollable_set(url_entry_, EINA_TRUE);
138   elm_entry_input_panel_layout_set(url_entry_, ELM_INPUT_PANEL_LAYOUT_URL);
139   evas_object_size_hint_weight_set(url_entry_, EVAS_HINT_EXPAND, 1.0f);
140   evas_object_size_hint_align_set(url_entry_, EVAS_HINT_FILL, EVAS_HINT_FILL);
141   evas_object_smart_callback_add(url_entry_, "activated", OnURLEntered, this);
142   elm_box_pack_end(urlbar_, url_entry_);
143   evas_object_color_get(url_entry_, &url_entry_color_.r, &url_entry_color_.g,
144                         &url_entry_color_.b, &url_entry_color_.a);
145   evas_object_show(url_entry_);
146
147   if (browser_.GetGUILevel() >= Browser::UBROWSER_GUI_LEVEL_ALL) {
148     Evas_Object* separator = elm_separator_add(urlbar_);
149     elm_separator_horizontal_set(separator, EINA_TRUE);
150     elm_box_pack_end(urlbar_, separator);
151     evas_object_show(separator);
152   }
153 }
154
155 void WindowUI::CreateBottomBar() {
156   navbar_ = elm_box_add(window_.GetEvasObject());
157   elm_box_horizontal_set(navbar_, EINA_TRUE);
158   elm_box_homogeneous_set(navbar_, EINA_TRUE);
159   evas_object_size_hint_weight_set(navbar_, EVAS_HINT_EXPAND, 0.0f);
160   evas_object_size_hint_align_set(navbar_, EVAS_HINT_FILL, EVAS_HINT_FILL);
161
162   if (browser_.GetGUILevel() >= Browser::UBROWSER_GUI_LEVEL_ALL) {
163     AddButton(navbar_, "file", "New Window", &WindowUI::OnCreateWindow);
164     if (browser_.IsDesktop())
165       AddButton(navbar_, "file", "New Incognito Window",
166                 &WindowUI::OnCreateIncognitoWindow);
167   }
168
169   back_button_ = AddButton(navbar_, "arrow_left", "Back", &WindowUI::OnBack);
170   forward_button_ =
171       AddButton(navbar_, "arrow_right", "Forward", &WindowUI::OnForward);
172   stop_reload_button_ =
173       AddButton(navbar_, "refresh", "Reload", &WindowUI::OnStopOrReload);
174   if (browser_.GetGUILevel() >= Browser::UBROWSER_GUI_LEVEL_ALL)
175     AddButton(navbar_, "arrow_up", "More Actions",
176               &WindowUI::OnShowExtraActionsMenu);
177
178   EnableBackButton(false);
179   EnableForwardButton(false);
180 }
181
182 Evas_Object* WindowUI::AddButton(Evas_Object* parent,
183     const char* icon, const char* label, Evas_Smart_Cb cb) {
184   Evas_Object* bt = elm_button_add(parent);
185   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
186   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0.5);
187   if (label && should_show_label_)
188     elm_object_text_set(bt, label);
189   if (icon) {
190     Evas_Object* icon_elm = elm_icon_add(bt);
191     elm_icon_standard_set(icon_elm, icon);
192     elm_object_part_content_set(bt, "icon", icon_elm);
193   }
194   evas_object_smart_callback_add(bt, "clicked", cb, this);
195   elm_box_pack_end(parent, bt);
196   evas_object_show(bt);
197
198   return bt;
199 }
200
201 namespace {
202
203 void _HideCtxPopup(void* data, Evas_Object* obj, void*) {
204   evas_object_hide(obj);
205 }
206
207 } // namespace
208
209 void WindowUI::CloseMenu() {
210   evas_object_hide(menu_);
211   evas_object_del(menu_);
212   menu_ = 0;
213 }
214
215 Evas_Object* WindowUI::CreateExtraActionsMenu(Evas_Object* parent) {
216   if (menu_) {
217     CloseMenu();
218     return 0;
219   }
220   menu_ =  elm_ctxpopup_add(parent);
221
222   if ((IsMobileProfile() || IsWearableProfile())) {
223     int width;
224     evas_object_geometry_get(parent, 0, 0, &width, 0);
225     evas_object_size_hint_min_set(menu_, width, 0);
226   }
227   evas_object_smart_callback_add(menu_, "dismissed", _HideCtxPopup, NULL);
228
229   if (window_.IsFormProfileEnabled()) {
230     elm_ctxpopup_item_append(menu_, "Disable Form Profile", NULL,
231                              &WindowUI::OnFormProfileChange, this);
232   } else {
233     elm_ctxpopup_item_append(menu_, "Enable Form Profile", NULL,
234                              &WindowUI::OnFormProfileChange, this);
235   }
236
237   if (window_.IsRememberFormDataEnabled()) {
238     elm_ctxpopup_item_append(menu_, "Disable Remember Form Data", NULL,
239                              &WindowUI::OnRememberFormDataChange, this);
240   } else {
241     elm_ctxpopup_item_append(menu_, "Enable Remember Form Data", NULL,
242                              &WindowUI::OnRememberFormDataChange, this);
243   }
244
245   if (window_.IsRememberPasswordEnabled()) {
246     elm_ctxpopup_item_append(menu_, "Disable Remember Password", NULL,
247                              &WindowUI::OnRememberPasswordChange, this);
248   } else {
249     elm_ctxpopup_item_append(menu_, "Enable Remember Password", NULL,
250                              &WindowUI::OnRememberPasswordChange, this);
251   }
252
253   elm_ctxpopup_item_append(menu_, "Override User Agent String", NULL,
254                            &WindowUI::OnUAOverride, this);
255
256   if (browser_.IsDesktop()) {
257     elm_ctxpopup_item_append(menu_, "Show Web Inspector", NULL,
258                              &WindowUI::OnInspectorShow, this);
259   } else {
260     elm_ctxpopup_item_append(menu_, "Start Web Inspector server", NULL,
261                              &WindowUI::OnInspectorServerStart, this);
262   }
263
264   elm_ctxpopup_item_append(menu_, "Use Google data proxy", NULL,
265                            &WindowUI::OnUseGoogleDataProxy, this);
266 #if !BUILDFLAG(IS_TIZEN)
267   elm_ctxpopup_item_append(menu_, "Simulate screen rotation", NULL,
268       &WindowUI::OnRotate, this);
269 #endif
270
271   if (window_.AreTouchEventsEnabled()) {
272     elm_ctxpopup_item_append(menu_, "Enable mouse events", NULL,
273                              &WindowUI::OnSelectMouseInput, this);
274   } else {
275     elm_ctxpopup_item_append(menu_, "Enable touch events", NULL,
276                              &WindowUI::OnSelectTouchInput, this);
277   }
278
279   if (!browser_.IsTracingEnabled()) {
280     elm_ctxpopup_item_append(menu_, "Start tracing", NULL,
281                              &WindowUI::OnStartTracing, this);
282   } else {
283     elm_ctxpopup_item_append(menu_, "Stop tracing", NULL,
284                              &WindowUI::OnStopTracing, this);
285   }
286
287   Ewk_Settings* settings = window_.GetEwkSettings();
288   if (!ewk_settings_auto_fitting_get(settings)) {
289     elm_ctxpopup_item_append(menu_, "Enable auto fitting", NULL,
290                              &WindowUI::OnAutoFittingEnabled, this);
291   } else {
292     elm_ctxpopup_item_append(menu_, "Disable auto fitting", NULL,
293                              &WindowUI::OnAutoFittingDisabled, this);
294   }
295
296   if (!ewk_settings_scripts_can_open_windows_get(settings)) {
297     elm_ctxpopup_item_append(menu_, "Enable js window.open", NULL,
298                              &WindowUI::OnScriptWindowOpenEnabled, this);
299   } else {
300     elm_ctxpopup_item_append(menu_, "Disable js window.open", NULL,
301                              &WindowUI::OnScriptWindowOpenDisabled, this);
302   }
303
304   if (!ewk_settings_form_profile_data_enabled_get(settings) ||
305      !ewk_settings_form_candidate_data_enabled_get(settings)) {
306     elm_ctxpopup_item_append(menu_, "Enable autofill", NULL,
307                              &WindowUI::OnAutoFillEnabled, this);
308   } else {
309     elm_ctxpopup_item_append(menu_, "Disable autofill", NULL,
310                              &WindowUI::OnAutoFillDisabled, this);
311   }
312
313   elm_ctxpopup_item_append(menu_, "Change page zoom level", NULL,
314                            &WindowUI::OnShowZoomPopup, this);
315
316   elm_ctxpopup_item_append(menu_, "Take screenshot async", NULL,
317                            &WindowUI::OnTakeScreenshotAsync, this);
318
319   elm_ctxpopup_item_append(menu_, "Take screenshot sync", NULL,
320                            &WindowUI::OnTakeScreenshotSync, this);
321
322   elm_ctxpopup_item_append(menu_, "Quit", NULL, &WindowUI::Exit, this);
323
324   return menu_;
325 }
326
327 void WindowUI::ShowPermissionPopup(const char* title,
328     const char* description, PermissionCallback cb, void* data) {
329   log_trace("%s: (%s, %s)", __PRETTY_FUNCTION__, title, description);
330
331   Evas_Object* popup = elm_popup_add(window_.GetEvasObject());
332   elm_object_part_text_set(popup, "title,text", title);
333   elm_object_part_text_set(popup, NULL, description);
334   elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
335   active_popup_ = popup;
336
337   Evas_Object* btn = elm_button_add(popup);
338   elm_object_text_set(btn, "Yes");
339   PermissionPopupButtonData* buttonData = new PermissionPopupButtonData;
340   buttonData->callbackData=data;
341   buttonData->callback=cb;
342   buttonData->popupData=this;
343
344   evas_object_smart_callback_add(btn, "clicked", PermissionGranted,
345                                  buttonData);
346   elm_object_part_content_set(popup, "button1", btn);
347
348   btn = elm_button_add(popup);
349   elm_object_text_set(btn, "No");
350   evas_object_smart_callback_add(btn, "clicked", PermissionDeclined,
351                                  buttonData);
352   elm_object_part_content_set(popup, "button2", btn);
353
354   evas_object_show(popup);
355 }
356
357 void WindowUI::OnThemeColorChanged(int r, int g, int b, int a) {
358   log_trace("%s: rgba(%d, %d, %d, %d)", __PRETTY_FUNCTION__, r, g, b, a);
359   if (url_entry_) {
360     // FIXME: For darker colors font color is to close to background color in
361     // entry. It is style dependent, so style modification or change would be
362     // needed to solve that issue.
363     if (a != 0)
364       evas_object_color_set(url_entry_, r, g, b, a);
365     else
366       evas_object_color_set(url_entry_, url_entry_color_.r, url_entry_color_.g,
367                             url_entry_color_.b, url_entry_color_.a);
368   }
369 }
370
371 void WindowUI::PermissionGranted(void* data, Evas_Object* button, void*) {
372   log_trace("%s", __PRETTY_FUNCTION__);
373
374   PermissionPopupButtonData* buttonData =(PermissionPopupButtonData*) data;
375   ClosePopup(buttonData->popupData, NULL, NULL);
376   buttonData->callback(true, buttonData->callbackData);
377   delete buttonData;
378 }
379
380 void WindowUI::PermissionDeclined(void* data, Evas_Object* button, void*) {
381   log_trace("%s", __PRETTY_FUNCTION__);
382
383   PermissionPopupButtonData* buttonData =(PermissionPopupButtonData*) data;
384   ClosePopup(buttonData->popupData, NULL, NULL);
385   buttonData->callback(false, buttonData->callbackData);
386   delete buttonData;
387 }
388
389 void WindowUI::ShowInspectorURLPopup(const char* url) {
390   log_trace("%s : %s", __PRETTY_FUNCTION__, url);
391   Evas_Object* popup = elm_popup_add(window_.GetEvasObject());
392   elm_object_part_text_set(popup, "title,text", url);
393   elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
394   active_popup_ = popup;
395
396   Evas_Object* btn = elm_button_add(popup);
397   elm_object_text_set(btn, "Close");
398   evas_object_smart_callback_add(btn, "clicked", ClosePopup, this);
399   elm_object_part_content_set(popup, "button1", btn);
400
401   evas_object_show(popup);
402 }
403
404 void WindowUI::ShowTextEntryPopup(const char* title,
405                                   const char* initial_content,
406                                   Evas_Smart_Cb cb) {
407   log_trace("%s: (%s, %s)", __PRETTY_FUNCTION__, title, initial_content);
408
409   Evas_Object* popup = elm_popup_add(window_.GetEvasObject());
410   elm_object_part_text_set(popup, "title,text", title);
411   elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
412   active_popup_ = popup;
413
414   Evas_Object* entry = elm_entry_add(popup);
415   elm_entry_single_line_set(entry, EINA_TRUE);
416   elm_entry_scrollable_set(entry, EINA_TRUE);
417   elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_URL);
418   evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0f);
419   evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
420   evas_object_smart_callback_add(
421       entry, "activated", cb,
422       new std::pair<Evas_Object*, WindowUI*>(entry, this));
423
424   elm_object_part_content_set(popup, "default", entry);
425   if (initial_content) {
426     elm_object_text_set(entry, initial_content);
427     elm_entry_cursor_end_set(entry);
428   }
429
430   Evas_Object* btn = elm_button_add(popup);
431   elm_object_text_set(btn, "OK");
432   evas_object_smart_callback_add(
433       btn, "clicked", cb, new std::pair<Evas_Object*, WindowUI*>(entry, this));
434   elm_object_part_content_set(popup, "button1", btn);
435
436   btn = elm_button_add(popup);
437   elm_object_text_set(btn, "Cancel");
438   evas_object_smart_callback_add(btn, "clicked", ClosePopup, this);
439   elm_object_part_content_set(popup, "button2", btn);
440
441   evas_object_show(popup);
442 }
443
444 void WindowUI::OnCreateWindow(void* data, Evas_Object*, void*) {
445   log_trace("%s", __PRETTY_FUNCTION__);
446   WindowUI* thiz = static_cast<WindowUI*>(data);
447   if (thiz->browser_.IsDesktop()) {
448     thiz->browser_.CreateWindow().LoadURL(kDefaultNewWindowURL);
449   } else {
450     thiz->browser_.ActivateToolboxWindow();
451   }
452 }
453
454 void WindowUI::OnCreateIncognitoWindow(void* data, Evas_Object*, void*) {
455   log_trace("%s", __PRETTY_FUNCTION__);
456   WindowUI* thiz = static_cast<WindowUI*>(data);
457   thiz->browser_.CreateWindow(true).LoadURL(kDefaultNewWindowURL);
458 }
459
460 void WindowUI::OnBack(void* data, Evas_Object*, void*) {
461   log_trace("%s", __PRETTY_FUNCTION__);
462   static_cast<WindowUI*>(data)->window_.Back();
463 }
464
465 void WindowUI::OnForward(void* data, Evas_Object*, void*) {
466   log_trace("%s", __PRETTY_FUNCTION__);
467   static_cast<WindowUI*>(data)->window_.Forward();
468 }
469
470 void WindowUI::OnStopOrReload(void* data, Evas_Object*, void*) {
471   log_trace("%s", __PRETTY_FUNCTION__);
472   WindowUI* thiz = static_cast<WindowUI*>(data);
473   if (thiz->is_loading_)
474     thiz->window_.Stop();
475   else
476     thiz->window_.Reload();
477 }
478
479 void WindowUI::OnShowExtraActionsMenu(void* data, Evas_Object* obj, void*) {
480   log_trace("%s", __PRETTY_FUNCTION__);
481   WindowUI* thiz = static_cast<WindowUI*>(data);
482   Evas_Object* popup = thiz->CreateExtraActionsMenu(
483       thiz->window_.GetEvasObject());
484
485   if (!popup)
486     return;
487
488   int x, y;
489   evas_object_geometry_get(obj, &x, &y, 0, 0);
490   evas_object_move(popup, x, y);
491   evas_object_show(popup);
492 }
493
494 void WindowUI::OnURLEntered(void* data, Evas_Object*, void*) {
495   log_trace("%s", __PRETTY_FUNCTION__);
496   WindowUI* thiz = static_cast<WindowUI*>(data);
497   thiz->window_.LoadURL(elm_object_text_get(thiz->url_entry_));
498   elm_object_focus_set(thiz->url_entry_, EINA_FALSE);
499 }
500
501 void WindowUI::OnUAOverride(void* data, Evas_Object* obj, void*) {
502   log_trace("%s", __PRETTY_FUNCTION__);
503   WindowUI* thiz = static_cast<WindowUI*>(data);
504   const char* ua = thiz->window_.GetUserAgent();
505   thiz->ShowTextEntryPopup("User Agent Override", ua,
506                            &WindowUI::OnUAOverrideEntered);
507   thiz->CloseMenu();
508 }
509
510 void WindowUI::OnUAOverrideEntered(void* data, Evas_Object*, void*) {
511   std::pair<Evas_Object*, WindowUI*>* p =
512       static_cast<std::pair<Evas_Object*, WindowUI*>*>(data);
513   p->second->window_.SetUserAgent(elm_object_text_get(p->first));
514   evas_object_del(p->second->active_popup_);
515   p->second->active_popup_ = NULL;
516   delete p;
517 }
518
519 void WindowUI::OnInspectorShow(void* data, Evas_Object* obj, void*) {
520   log_trace("%s", __PRETTY_FUNCTION__);
521   WindowUI* thiz = static_cast<WindowUI*>(data);
522   thiz->browser_.ShowInspectorWindow();
523   thiz->CloseMenu();
524 }
525
526 void WindowUI::OnInspectorServerStart(void* data, Evas_Object* obj, void*) {
527     log_trace("%s", __PRETTY_FUNCTION__);
528     WindowUI* thiz = static_cast<WindowUI*>(data);
529     thiz->browser_.StartInspectorServer();
530     thiz->CloseMenu();
531 }
532
533 void WindowUI::OnUseGoogleDataProxy(void* data, Evas_Object* obj, void*) {
534   log_trace("%s", __PRETTY_FUNCTION__);
535   WindowUI* thiz = static_cast<WindowUI*>(data);
536   ewk_context_proxy_set(ewk_context_default_get(), "compress.googlezip.net:80",
537                         "<local>");
538   thiz->window_.SetGoogleDataProxyHeaders();
539   thiz->CloseMenu();
540 }
541
542 void WindowUI::OnRotate(void* data, Evas_Object* obj, void*) {
543   log_trace("%s", __PRETTY_FUNCTION__);
544   WindowUI* thiz = static_cast<WindowUI*>(data);
545   thiz->window_.FakeRotate();
546   thiz->CloseMenu();
547 }
548
549 void WindowUI::OnSelectMouseInput(void* data, Evas_Object* obj, void*) {
550   log_trace("%s", __PRETTY_FUNCTION__);
551   WindowUI* thiz = static_cast<WindowUI*>(data);
552   thiz->window_.EnableTouchEvents(false);
553   thiz->window_.EnableMouseEvents(true);
554   thiz->ShowNotification("Mouse events enabled");
555   thiz->CloseMenu();
556 }
557
558 void WindowUI::OnSelectTouchInput(void* data, Evas_Object* obj, void*) {
559   log_trace("%s", __PRETTY_FUNCTION__);
560   WindowUI* thiz = static_cast<WindowUI*>(data);
561   thiz->window_.EnableTouchEvents(true);
562   thiz->window_.EnableMouseEvents(false);
563   thiz->ShowNotification("Touch events enabled");
564   thiz->CloseMenu();
565 }
566
567 void WindowUI::OnStartTracing(void* data, Evas_Object* obj, void*) {
568   log_trace("%s", __PRETTY_FUNCTION__);
569   WindowUI* thiz = static_cast<WindowUI*>(data);
570   thiz->browser_.StartTracing();
571   thiz->CloseMenu();
572   thiz->ShowNotification("Tracing started");
573 }
574
575 void WindowUI::OnStopTracing(void* data, Evas_Object* obj, void*) {
576   log_trace("%s", __PRETTY_FUNCTION__);
577   WindowUI* thiz = static_cast<WindowUI*>(data);
578   thiz->browser_.StopTracing();
579   thiz->CloseMenu();
580   thiz->ShowNotification("Tracing finished");
581 }
582
583 void WindowUI::OnAutoFittingEnabled(void* data, Evas_Object* obj, void*) {
584   log_trace("%s", __PRETTY_FUNCTION__);
585   WindowUI* thiz = static_cast<WindowUI*>(data);
586   Ewk_Settings* settings = thiz->window_.GetEwkSettings();
587   ewk_settings_auto_fitting_set(settings, true);
588   thiz->CloseMenu();
589   thiz->ShowNotification("Auto fitting enabled");
590 }
591
592 void WindowUI::OnAutoFittingDisabled(void* data, Evas_Object* obj, void*) {
593   log_trace("%s", __PRETTY_FUNCTION__);
594   WindowUI* thiz = static_cast<WindowUI*>(data);
595   Ewk_Settings* settings = thiz->window_.GetEwkSettings();
596   ewk_settings_auto_fitting_set(settings, false);
597   thiz->CloseMenu();
598   thiz->ShowNotification("Auto fitting disabled");
599 }
600
601 void WindowUI::OnAutoFillEnabled(void* data, Evas_Object* obj, void*) {
602   log_trace("%s", __PRETTY_FUNCTION__);
603   WindowUI* thiz = static_cast<WindowUI*>(data);
604   Ewk_Settings* settings = thiz->window_.GetEwkSettings();
605   ewk_settings_form_profile_data_enabled_set(settings, true);
606   ewk_settings_form_candidate_data_enabled_set(settings, true);
607   thiz->CloseMenu();
608   thiz->ShowNotification("Autofill enabled");
609 }
610
611 void WindowUI::OnAutoFillDisabled(void* data, Evas_Object* obj, void*) {
612   log_trace("%s", __PRETTY_FUNCTION__);
613   WindowUI* thiz = static_cast<WindowUI*>(data);
614   Ewk_Settings* settings = thiz->window_.GetEwkSettings();
615   ewk_settings_form_profile_data_enabled_set(settings, false);
616   ewk_settings_form_candidate_data_enabled_set(settings, false);
617   thiz->CloseMenu();
618   thiz->ShowNotification("Autofill disabled");
619 }
620
621 void WindowUI::OnScriptWindowOpenEnabled(void* data, Evas_Object* obj, void*) {
622   log_trace("%s", __PRETTY_FUNCTION__);
623   WindowUI* thiz = static_cast<WindowUI*>(data);
624   Ewk_Settings* settings = thiz->window_.GetEwkSettings();
625   ewk_settings_scripts_can_open_windows_set(settings, true);
626   thiz->CloseMenu();
627   thiz->ShowNotification("JS window.open enabled");
628 }
629
630 void WindowUI::OnScriptWindowOpenDisabled(void* data, Evas_Object* obj, void*) {
631   log_trace("%s", __PRETTY_FUNCTION__);
632   WindowUI* thiz = static_cast<WindowUI*>(data);
633   Ewk_Settings* settings = thiz->window_.GetEwkSettings();
634   ewk_settings_scripts_can_open_windows_set(settings, false);
635   thiz->CloseMenu();
636   thiz->ShowNotification("JS window.open disabled");
637 }
638
639 void WindowUI::ClosePopup(void* data, Evas_Object*, void*) {
640   WindowUI* thiz = static_cast<WindowUI*>(data);
641   evas_object_del(thiz->active_popup_);
642   thiz->active_popup_ = NULL;
643 }
644
645 void WindowUI::ClosePopup() {
646   if (active_popup_) {
647     evas_object_del(active_popup_);
648     active_popup_ = NULL;
649   }
650 }
651
652 void WindowUI::OnShowZoomPopup(void* data, Evas_Object* obj, void*) {
653   log_trace("%s", __PRETTY_FUNCTION__);
654   WindowUI* thiz = static_cast<WindowUI*>(data);
655
656   Evas_Object* popup = elm_popup_add(thiz->window_.GetEvasObject());
657   elm_object_part_text_set(popup, "title,text", "Change page zoom level");
658   elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
659   thiz->active_popup_ = popup;
660   Evas_Object* btn = elm_button_add(popup);
661
662   Evas_Object* slider = elm_slider_add(popup);
663   thiz->window_.GetScaleRange(&kMinViewScale, &kMaxViewScale);
664   elm_slider_min_max_set(slider, kMinViewScale, kMaxViewScale);
665   elm_slider_value_set(slider, thiz->window_.GetScale());
666   elm_slider_indicator_format_set(slider, "%1.2f");
667   elm_slider_indicator_show_set(slider, EINA_TRUE);
668   evas_object_smart_callback_add(slider, "changed", &OnZoomChanged, thiz);
669   elm_object_part_content_set(popup, "default", slider);
670
671   elm_object_text_set(btn, "Close");
672   evas_object_smart_callback_add(btn, "clicked", ClosePopup, thiz);
673   elm_object_part_content_set(popup, "button1", btn);
674
675   evas_object_show(popup);
676   thiz->CloseMenu();
677 }
678
679 void WindowUI::OnTakeScreenshotAsync(void* data, Evas_Object* obj, void*) {
680   log_trace("%s", __PRETTY_FUNCTION__);
681   WindowUI* thiz = static_cast<WindowUI*>(data);
682   thiz->window_.TakeScreenshot(false);
683   thiz->CloseMenu();
684 }
685
686 void WindowUI::OnTakeScreenshotSync(void* data, Evas_Object* obj, void*) {
687   log_trace("%s", __PRETTY_FUNCTION__);
688   WindowUI* thiz = static_cast<WindowUI*>(data);
689   thiz->window_.TakeScreenshot(true);
690   thiz->CloseMenu();
691 }
692
693 void WindowUI::OnZoomChanged(void* data, Evas_Object* obj, void*) {
694   log_trace("%s", __PRETTY_FUNCTION__);
695   WindowUI* thiz = static_cast<WindowUI*>(data);
696   thiz->window_.SetScale(elm_slider_value_get(obj));
697 }
698
699 void WindowUI::OnRememberFormDataChange(void* data, Evas_Object* obj, void*) {
700   log_trace("%s", __PRETTY_FUNCTION__);
701   WindowUI* thiz = static_cast<WindowUI*>(data);
702   Ewk_Settings* settings = thiz->window_.GetEwkSettings();
703   if (thiz->window_.IsRememberFormDataEnabled()) {
704     ewk_settings_form_candidate_data_enabled_set(settings, false);
705     thiz->ShowNotification("Remember Form Data disabled");
706   } else {
707     ewk_settings_form_candidate_data_enabled_set(settings, true);
708     thiz->ShowNotification("Remember Form Data enabled");
709   }
710   thiz->CloseMenu();
711 }
712
713 void WindowUI::OnRememberPasswordChange(void* data, Evas_Object* obj, void*) {
714   log_trace("%s", __PRETTY_FUNCTION__);
715   WindowUI* thiz = static_cast<WindowUI*>(data);
716   Ewk_Settings* settings = thiz->window_.GetEwkSettings();
717   if (thiz->window_.IsRememberPasswordEnabled()) {
718     ewk_settings_autofill_password_form_enabled_set(settings, false);
719     thiz->ShowNotification("Remember Password disabled");
720   } else {
721     ewk_settings_autofill_password_form_enabled_set(settings, true);
722     thiz->ShowNotification("Remember Password enabled");
723   }
724   thiz->CloseMenu();
725 }
726
727 void WindowUI::OnFormProfileChange(void* data, Evas_Object* obj, void*) {
728   log_trace("%s", __PRETTY_FUNCTION__);
729   WindowUI* thiz = static_cast<WindowUI*>(data);
730   Ewk_Settings* settings = thiz->window_.GetEwkSettings();
731   if (thiz->window_.IsFormProfileEnabled()) {
732     ewk_settings_form_profile_data_enabled_set(settings, false);
733     thiz->ShowNotification("Form Profile disabled");
734   } else {
735     ewk_settings_form_profile_data_enabled_set(settings, true);
736     thiz->ShowNotification("Form Profile enabled");
737   }
738   thiz->CloseMenu();
739 }
740
741 void WindowUI::Exit(void* data, Evas_Object*, void*) {
742   WindowUI* thiz = static_cast<WindowUI*>(data);
743   thiz->window_.Exit();
744 }