9f0e81c2dc04e1db3dc742a8991e8c9c889fde53
[platform/core/uifw/libscl-ui-nui.git] / scl / sclkeyfocushandler.h
1 /*
2  * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 #include "scltypes.h"
18 #include "sclres_type.h"
19 #ifndef __SCL_KEY_FOCUS_HANDLER_H__
20 #define __SCL_KEY_FOCUS_HANDLER_H__
21
22 //#define TARGET_EMULATOR
23 //SCL_BEGIN_DECLS
24
25 namespace scl
26 {
27
28 #define NAVI_INFO_MAX_ROWS  20
29 #define NAVI_INFO_MAX_COLS  20
30
31 typedef struct {
32     scl8 candidate;
33     scl8 candidate_otherside;
34 } NEXT_CANDIDATE_INFO;
35
36 /*
37 typedef struct _SclKeyboardRowInfo {
38     sclbyte start_index;
39     sclbyte size;
40     sclchar *sub_layout;
41     sclshort col_coord[NAVI_INFO_MAX_COLS];
42 }SclKeyboardRowInfo;
43
44 typedef struct _SclKeyFocusNavigationInfo {
45     sclbyte total_rows;
46     sclshort row_coord;
47     SclKeyboardRowInfo* rows[NAVI_INFO_MAX_ROWS];
48 }SclKeyFocusNavigationInfo;
49
50 typedef struct _SclPopupRelativeKeyInfo {
51     sclbyte index;
52     sclwindow window;
53 }SclPopupRelativeKeyInfo;
54
55 typedef struct _SclPopupRowInfo {
56     sclbyte start_index;
57     sclbyte size;
58     sclshort col_coord[NAVI_INFO_MAX_COLS];
59     SclPopupRelativeKeyInfo nexts[NAVI_INFO_MAX_COLS][NAVIGATE_MAX];
60 }SclPopupRowInfo;
61
62 typedef struct _SclPopupNavigationInfo {
63     sclbyte total_rows;
64     sclshort row_coord;
65     SclPopupRowInfo* rows[NAVI_INFO_MAX_ROWS];
66 }SclPopupNavigationInfo;
67 */
68
69 /**
70 * @brief The class to store key focus navigation information
71 *
72 * This class implements functions to support key focus navigation on the software keyboard
73 * using remote controller input. It generates navigation information for the currently loaded
74 * keyboard layout and provides the index of next key depending upon the navigation direction.
75 * The key information can be retrieved from the array of key coordinates from Resource Cache.
76 *
77 * Apart from key navigation information, this class also provides functions to grab and ungrab
78 * the remote controller keys.
79 *
80 * The public interface can be divided in three categories :
81 * 1. Focus grab/ungrab API : Invoked while showing and hiding the software keyboard
82 * - Client class: CSCLWindowsImplEfl
83 * 2. Focus navigation info building API : Invoked while computing layout of the current keyboard
84 * - Client class/function: CSCLResourceCache::recompute_layout
85 * 3. Focus navigation API: Invoked while handling remote controller key press events
86 * - Client class: CSCLEventsImplEfl
87 */
88 class CSCLKeyFocusHandler
89 {
90 public:
91     virtual ~CSCLKeyFocusHandler();
92
93     static CSCLKeyFocusHandler* get_instance();
94
95 #ifdef USING_KEY_GRAB
96     /*Focus grab/ungrab API*/
97     bool grab_keyboard(const sclwindow parent);
98     void ungrab_keyboard(const sclwindow parent);
99 #endif
100
101     /*Focus navigation info building API*/
102     void reset_key_navigation_info(sclwindow window);
103     void update_key_navigation_info(sclwindow window, scl8 index, SclLayoutKeyCoordinatePointer p_next_key);
104     void finalize_key_navigation_info(sclwindow window);
105
106     void popup_opened(sclwindow window);
107     void popup_closed(sclwindow window);
108
109     /*Focus navigation API*/
110     void init_key_index();
111     scl8 get_current_focus_key(void);
112     sclwindow get_current_focus_window(void);
113     void process_navigation(SCLHighlightNavigationDirection direction);
114
115     void set_current_focus(sclwindow window, scl8 index);
116
117 private:
118     NEXT_CANDIDATE_INFO get_next_candidate_key(SCLHighlightNavigationDirection direction, SclRectangle cur, sclwindow window);
119
120     sclwindow m_focus_window;
121     scl8 m_focus_key;
122
123 #ifdef USING_KEY_GRAB
124     bool m_keyboard_grabbed;
125 #endif
126     bool sub_layout_match(sclchar *layout1, sclchar *layout2);
127
128     CSCLKeyFocusHandler();
129 #ifdef TARGET_EMULATOR
130     sclwindow m_sniffer;
131     void create_sniffer_window(void);
132     void set_window_accepts_focus(const sclwindow window, sclboolean acceptable);
133 #endif
134 };
135
136 }
137
138 //SCL_END_DECLS
139
140 #endif