7cbc471a946e044c71c67a5ecca18dcb9d53c156
[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 namespace {
13 inline bool isHardwareBackKey(const Evas_Event_Key_Down *event) {
14 #ifdef OS_TIZEN
15   return (strcmp(event->key, "XF86Stop") == 0);
16 #else
17   return (strcmp(event->key, "Escape") == 0);
18 #endif
19 }
20
21 }
22 namespace tizen_webview {
23
24 WebViewEvasEventHandler::WebViewEvasEventHandler(WebView* wv)
25     : webview_ (wv) {
26 }
27
28 bool WebViewEvasEventHandler::HandleEvent_FocusIn() {
29   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
30   if (!wvd)
31     return false;
32   return wvd->RequestHandleEvent_FocusIn(webview_);
33 }
34
35 bool WebViewEvasEventHandler::HandleEvent_FocusOut() {
36   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
37   if (!wvd)
38     return false;
39   return wvd->RequestHandleEvent_FocusOut(webview_);
40 }
41
42 bool WebViewEvasEventHandler::HandleEvent_KeyDown(const Evas_Event_Key_Down* event_info) {
43   bool handled = false;
44
45   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
46   if (wvd) {
47     handled = wvd->RequestHandleEvent_KeyDown(webview_, event_info);
48     if (handled)
49       return handled;
50   }
51
52   if (isHardwareBackKey(event_info)) {
53     if (webview_->GetContextMenuController()) {
54       DVLOG(1) << "Hiding context menu due to back key press";
55       webview_->ResetContextMenuController();
56       webview_->HideSelectionHandlers();
57       handled = true;
58     }
59     if (webview_->GetSelectionController()->IsAnyHandleVisible()) {
60       DVLOG(1) << "Clearing text selection due to back key press";
61       webview_->ClearSelection();
62       handled = true;
63     }
64   }
65   return handled;
66 }
67
68 bool WebViewEvasEventHandler::HandleEvent_KeyUp(const Evas_Event_Key_Up* event_info) {
69
70   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
71   if (!wvd)
72     return false;
73   return wvd->RequestHandleEvent_KeyUp(webview_, event_info);
74 }
75
76 bool WebViewEvasEventHandler::HandleEvent_MouseDown(const Evas_Event_Mouse_Down* event_info) {
77   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
78   if (!wvd)
79     return false;
80   return wvd->RequestHandleEvent_MouseDown(webview_, event_info);
81 }
82
83 bool WebViewEvasEventHandler::HandleEvent_MouseUp(const Evas_Event_Mouse_Up* event_info) {
84   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
85   if (!wvd)
86     return false;
87   return wvd->RequestHandleEvent_MouseUp(webview_, event_info);
88 }
89
90 bool WebViewEvasEventHandler::HandleEvent_MouseMove(const Evas_Event_Mouse_Move* event_info) {
91   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
92   if (!wvd)
93     return false;
94   return wvd->RequestHandleEvent_MouseMove(webview_, event_info);
95 }
96
97 bool WebViewEvasEventHandler::HandleEvent_MouseWheel(const Evas_Event_Mouse_Wheel* event_info) {
98   WebViewDelegate* wvd = WebViewDelegate::GetInstance();
99   if (!wvd)
100     return false;
101   return wvd->RequestHandleEvent_MouseWheel(webview_, event_info);
102 }
103
104 } // namespace tizen_webview