WebViewEvasEventHandler does not rely on tizen_webview::WebView anymore
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / tizen_webview / public / tw_webview_evas_event_handler.cc
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Copyright 2014 Samsung Electronics. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #include "tw_webview_evas_event_handler.h"
7
8 #include "tizen_webview/public/tw_webview_delegate.h"
9
10 #include "eweb_view.h"
11
12 using content::SelectionControllerEfl;
13
14 namespace {
15 inline bool isHardwareBackKey(const Evas_Event_Key_Down *event) {
16 #ifdef OS_TIZEN
17   return (strcmp(event->key, "XF86Stop") == 0);
18 #else
19   return (strcmp(event->key, "Escape") == 0);
20 #endif
21 }
22
23 }
24 namespace tizen_webview {
25
26 WebViewEvasEventHandler::WebViewEvasEventHandler(EWebView* wv)
27     : webview_ (wv) {
28 }
29
30 bool WebViewEvasEventHandler::HandleEvent_FocusIn() {
31   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
32   if (!wvd)
33     return false;
34   return wvd->RequestHandleEvent_FocusIn(webview_);
35 }
36
37 bool WebViewEvasEventHandler::HandleEvent_FocusOut() {
38   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
39   if (!wvd)
40     return false;
41   return wvd->RequestHandleEvent_FocusOut(webview_);
42 }
43
44 bool WebViewEvasEventHandler::HandleEvent_KeyDown(const Evas_Event_Key_Down* event_info) {
45   bool handled = false;
46
47   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
48   if (wvd) {
49     handled = wvd->RequestHandleEvent_KeyDown(webview_, event_info);
50     if (handled)
51       return handled;
52   }
53
54   if (isHardwareBackKey(event_info)) {
55     if (webview_->GetContextMenuController()) {
56       DVLOG(1) << "Hiding context menu due to back key press";
57       webview_->ResetContextMenuController();
58       if (SelectionControllerEfl* selection_controller = webview_->GetSelectionController())
59         selection_controller->HideHandles();
60       handled = true;
61     }
62     if (webview_->GetSelectionController()->IsAnyHandleVisible()) {
63       DVLOG(1) << "Clearing text selection due to back key press";
64       webview_->GetSelectionController()->ClearSelection();
65       handled = true;
66     }
67   }
68   return handled;
69 }
70
71 bool WebViewEvasEventHandler::HandleEvent_KeyUp(const Evas_Event_Key_Up* event_info) {
72
73   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
74   if (!wvd)
75     return false;
76   return wvd->RequestHandleEvent_KeyUp(webview_, event_info);
77 }
78
79 bool WebViewEvasEventHandler::HandleEvent_MouseDown(const Evas_Event_Mouse_Down* event_info) {
80   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
81   if (!wvd)
82     return false;
83   return wvd->RequestHandleEvent_MouseDown(webview_, event_info);
84 }
85
86 bool WebViewEvasEventHandler::HandleEvent_MouseUp(const Evas_Event_Mouse_Up* event_info) {
87   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
88   if (!wvd)
89     return false;
90   return wvd->RequestHandleEvent_MouseUp(webview_, event_info);
91 }
92
93 bool WebViewEvasEventHandler::HandleEvent_MouseMove(const Evas_Event_Mouse_Move* event_info) {
94   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
95   if (!wvd)
96     return false;
97   return wvd->RequestHandleEvent_MouseMove(webview_, event_info);
98 }
99
100 bool WebViewEvasEventHandler::HandleEvent_MouseWheel(const Evas_Event_Mouse_Wheel* event_info) {
101   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
102   if (!wvd)
103     return false;
104   return wvd->RequestHandleEvent_MouseWheel(webview_, event_info);
105 }
106
107 } // namespace tizen_webview