Exiting from Screen zoom by pressing "Escape" or "Backspace" key.
[profile/tv/apps/web/browser.git] / services / PlatformInputManager / PlatformInputManager.cpp
1
2 /*
3  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "PlatformInputManager.h"
19
20 #include <Ecore.h>
21 #include <Ecore_Evas.h>
22 #include <Ecore_Input.h>
23 #include <unistd.h>
24
25 #include "BrowserAssert.h"
26 #include "BrowserLogger.h"
27
28 #define E_PROP_DEVICEMGR_INPUTWIN "DeviceMgr Input Window"
29 #define E_PROP_NOT_CURSOR_HIDE "E_NOT_CURSOR_HIDE"
30
31 #define MOUSE_POINTER_MOVE_DELAY 0.015f
32 #define MOUSE_POINTER_STEPS 10
33
34 namespace tizen_browser
35 {
36 namespace services
37 {
38
39 EXPORT_SERVICE(PlatformInputManager, "org.tizen.browser.platforminputmanager")
40
41 PlatformInputManager::PlatformInputManager()
42 {
43
44 }
45
46 void PlatformInputManager::init(Evas_Object* mainWindow)
47 {
48     M_ASSERT(mainWindow);
49     //Suppress compilation warning
50     (void) mainWindow;
51     ecore_event_filter_add(NULL, __filter, NULL, this);
52 }
53
54 Eina_Bool PlatformInputManager::__filter(void *data, void */*loop_data*/, int type, void *event)
55 {
56     PlatformInputManager *self = static_cast<PlatformInputManager*>(data);
57
58     if (type == ECORE_EVENT_KEY_DOWN) {
59         M_ASSERT(event);
60         Ecore_Event_Key *ev = static_cast<Ecore_Event_Key *>(event);
61
62         if(!ev->keyname)
63             return EINA_TRUE;
64
65         BROWSER_LOGD("Pressed key: %s", ev->keyname);
66         const std::string keyName = ev->keyname;
67
68         /**
69          * Because MENU button launches org.tizen.menu
70          * we use blue 'D' button on remote control or F4 on keyboard as substitution of MENU button
71          */
72         if(!keyName.compare("KEY_MENU") || !keyName.compare("KEY_BLUE")) {
73             self->menuPressed();
74             return EINA_FALSE;
75         }
76
77         if(!keyName.compare("KEY_RETURN"))
78             self->returnPressed();
79         else if(!keyName.compare("KEY_LEFT"))
80             self->leftPressed();
81         else if(!keyName.compare("KEY_RIGHT"))
82             self->rightPressed();
83         else if(!keyName.compare("KEY_ENTER"))
84             self->enterPressed();
85             // MERGE_ME dont know if should be commented out
86         else if(!keyName.compare("BackSpace") || !keyName.compare("XF86Back"))
87             self->backPressed();
88         else if(!keyName.compare("Escape"))
89             self->escapePressed();
90     } else if(type == ECORE_EVENT_KEY_UP) {
91         M_ASSERT(event);
92         Ecore_Event_Key *ev = static_cast<Ecore_Event_Key *>(event);
93
94         if(!ev->keyname)
95             return EINA_TRUE;
96
97         BROWSER_LOGD("Released key: %s", ev->keyname);
98     } else if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN) {
99         self->mouseClicked();
100     }
101     return EINA_TRUE;
102 }
103
104 }
105 }