2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <Elementary.h>
18 #include <inputmethod.h>
23 #include "common/application_data.h"
24 #include "common/app_control.h"
25 #include "common/app_db.h"
26 #include "common/command_line.h"
27 #include "common/logger.h"
28 #include "common/profiler.h"
29 #include "runtime/common/constants.h"
30 #include "runtime/browser/native_ime_window.h"
31 #include "runtime/browser/preload_manager.h"
32 #include "runtime/browser/runtime.h"
33 #include "runtime/browser/ime_runtime.h"
39 static NativeWindow* CreateNativeWindow() {
41 NativeWindow* window = NULL;
42 auto cached = PreloadManager::GetInstance()->GetCachedNativeWindow();
43 if (cached != nullptr) {
46 window = new NativeImeWindow();
54 ImeRuntime::ImeRuntime(common::ApplicationData* app_data)
60 ImeRuntime::~ImeRuntime() {
65 delete native_window_;
69 static Evas_Object *enter_key_btn = NULL;
71 static void set_return_key_type(Ecore_IMF_Input_Panel_Return_Key_Type type)
74 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE:
75 elm_object_text_set(enter_key_btn, "Done");
77 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO:
78 elm_object_text_set(enter_key_btn, "Go");
80 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN:
81 elm_object_text_set(enter_key_btn, "Join");
83 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN:
84 elm_object_text_set(enter_key_btn, "Login");
86 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT:
87 elm_object_text_set(enter_key_btn, "Next");
89 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH:
90 elm_object_text_set(enter_key_btn, "Search");
92 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND:
93 elm_object_text_set(enter_key_btn, "Send");
95 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SIGNIN:
96 elm_object_text_set(enter_key_btn, "Sign in");
99 elm_object_text_set(enter_key_btn, "Enter");
104 void ImeRuntime::OnAppControl() {
105 std::unique_ptr<common::AppControl>
106 appcontrol(new common::AppControl());
107 appcontrol->set_operation("http://tizen.org/appcontrol/operation/default");
108 common::AppDB* appdb = common::AppDB::GetInstance();
109 appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeBundle,
110 appcontrol->encoded_bundle());
111 if (application_->launched()) {
112 application_->AppControl(std::move(appcontrol));
114 application_->Launch(std::move(appcontrol));
118 void ImeRuntime::OnCreate() {
119 STEP_PROFILE_END("ime_app_main -> OnCreate");
120 STEP_PROFILE_END("Start -> OnCreate");
121 STEP_PROFILE_START("OnCreate -> URL Set");
123 common::CommandLine* cmd = common::CommandLine::ForCurrentProcess();
124 std::string appid = cmd->GetAppIdFromCommandLine(kRuntimeExecName);
126 // Init AppDB for Runtime
127 common::AppDB* appdb = common::AppDB::GetInstance();
128 appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeName, "xwalk-tizen");
129 appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeAppID, appid);
130 if (app_data_->setting_info()->background_support_enabled()) {
131 appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeBackgroundSupport, "true");
133 appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeBackgroundSupport, "false");
135 appdb->Remove(kAppDBRuntimeSection, kAppDBRuntimeBundle);
137 // Init ImeApplication
138 native_window_ = CreateNativeWindow();
139 STEP_PROFILE_START("ImeApplication Create");
140 application_ = new ImeApplication(native_window_, app_data_);
141 STEP_PROFILE_END("ImeApplication Create");
143 setlocale(LC_ALL, "");
144 bindtextdomain(kTextDomainRuntime, kTextLocalePath);
146 LOGGER(DEBUG) << "ime_app_create";
149 Evas_Object *ime_window = native_window_->evas_object();
151 LOGGER(DEBUG) << "Can't get main window: " << get_last_result();
154 elm_win_screen_size_get(ime_window, NULL, NULL, &w, &h);
155 LOGGER(DEBUG) << "w : " << w << ", h : " << h;
160 ime_set_size(w, h*2/5, h, w*3/5);
165 void ImeRuntime::OnTerminate() {
166 LOGGER(DEBUG) << "ime_app_terminate";
169 void ImeRuntime::OnShow(int context_id, ime_context_h context) {
170 Ecore_IMF_Input_Panel_Layout layout;
171 ime_layout_variation_e layout_variation;
173 Ecore_IMF_Autocapital_Type autocapital_type;
174 Ecore_IMF_Input_Panel_Return_Key_Type return_key_type;
175 bool return_key_state, prediction_mode, password_mode;
177 LOGGER(DEBUG) << "ime_app_show";
179 if (ime_context_get_layout(
180 context, &layout) == IME_ERROR_NONE)
181 LOGGER(DEBUG) << "layout: " << layout;
182 if (ime_context_get_layout_variation(
183 context, &layout_variation) == IME_ERROR_NONE)
184 LOGGER(DEBUG) << "layout variation: " << layout_variation;
185 if (ime_context_get_cursor_position(
186 context, &cursor_pos) == IME_ERROR_NONE)
187 LOGGER(DEBUG) << "cursor position: " << cursor_pos;
188 if (ime_context_get_autocapital_type(
189 context, &autocapital_type) == IME_ERROR_NONE)
190 LOGGER(DEBUG) << "autocapital_type: " << autocapital_type;
191 if (ime_context_get_return_key_type(
192 context, &return_key_type) == IME_ERROR_NONE)
193 LOGGER(DEBUG) << "return_key_type: " << return_key_type;
194 if (ime_context_get_return_key_state(
195 context, &return_key_state) == IME_ERROR_NONE)
196 LOGGER(DEBUG) << "return_key_state: " << return_key_state;
197 if (ime_context_get_prediction_mode(
198 context, &prediction_mode) == IME_ERROR_NONE)
199 LOGGER(DEBUG) << "prediction_mode: " << prediction_mode;
200 if (ime_context_get_password_mode(
201 context, &password_mode) == IME_ERROR_NONE)
202 LOGGER(DEBUG) << "password_mode: " << password_mode;
204 set_return_key_type(return_key_type);
207 void ImeRuntime::OnHide(int context_id) {
208 LOGGER(DEBUG) << "ime_app_hide";
211 static void ime_app_focus_in_cb(int ic, void *user_data)
213 LOGGER(DEBUG) << "focus in: " << ic;
216 static void ime_app_focus_out_cb(int ic, void *user_data)
218 LOGGER(DEBUG) << "focus out: " << ic;
221 static void ime_app_cursor_position_updated_cb(
222 int cursor_pos, void *user_data)
224 LOGGER(DEBUG) << "cursor position: " << cursor_pos;
227 static void ime_app_return_key_type_set_cb(
228 Ecore_IMF_Input_Panel_Return_Key_Type type, void *user_data)
230 LOGGER(DEBUG) << "Return key type: " << type;
232 set_return_key_type(type);
235 static void ime_app_return_key_state_set_cb(
236 bool disabled, void *user_data)
238 LOGGER(DEBUG) << "Return key disabled: " << disabled;
241 static void ime_app_layout_set_cb(
242 Ecore_IMF_Input_Panel_Layout layout, void *user_data)
244 LOGGER(DEBUG) << "layout: " << layout;
247 static bool ime_app_process_key_event_cb(
248 ime_key_code_e keycode, ime_key_mask_e keymask,
249 ime_device_info_h dev_info, void *user_data)
251 LOGGER(DEBUG) << "keycode = " << keycode << ", keymask = " << keymask;
253 if ((keymask & IME_KEY_MASK_CONTROL) || (keymask & IME_KEY_MASK_ALT) ||
254 (keymask & IME_KEY_MASK_META) || (keymask & IME_KEY_MASK_WIN) ||
255 (keymask & IME_KEY_MASK_HYPER))
261 static void ime_app_display_language_changed_cb(
262 const char *language, void *user_data)
264 LOGGER(DEBUG) << "language: " << language;
267 int ImeRuntime::Exec(int argc, char* argv[]) {
268 ime_callback_s ops = {NULL, NULL, NULL, NULL};
271 ops.create = [](void* data) -> void {
272 runtime::ImeRuntime* ime_runtime =
273 reinterpret_cast<runtime::ImeRuntime*>(data);
275 LOGGER(ERROR) << "Runtime has not been created.";
278 ime_runtime->OnCreate();
282 ops.terminate = [](void* data) -> void {
283 runtime::ImeRuntime* ime_runtime =
284 reinterpret_cast<runtime::ImeRuntime*>(data);
286 LOGGER(ERROR) << "Runtime has not been created.";
289 ime_runtime->OnTerminate();
293 ops.show = [](int context_id, ime_context_h context, void *data) -> void {
294 runtime::ImeRuntime* ime_runtime =
295 reinterpret_cast<runtime::ImeRuntime*>(data);
297 LOGGER(ERROR) << "Runtime has not been created.";
300 ime_runtime->OnShow(context_id, context);
304 ops.hide = [](int context_id, void *data) -> void {
305 runtime::ImeRuntime* ime_runtime =
306 reinterpret_cast<runtime::ImeRuntime*>(data);
308 LOGGER(ERROR) << "Runtime has not been created.";
311 ime_runtime->OnHide(context_id);
314 STEP_PROFILE_START("ime_app_main -> OnCreate");
316 // Set the necessary callback functions
317 ime_event_set_focus_in_cb(ime_app_focus_in_cb, this);
318 ime_event_set_focus_out_cb(ime_app_focus_out_cb, this);
319 ime_event_set_cursor_position_updated_cb(
320 ime_app_cursor_position_updated_cb, this);
321 ime_event_set_layout_set_cb(
322 ime_app_layout_set_cb, this);
323 ime_event_set_return_key_type_set_cb(
324 ime_app_return_key_type_set_cb, this);
325 ime_event_set_return_key_state_set_cb(
326 ime_app_return_key_state_set_cb, this);
327 ime_event_set_process_key_event_cb(
328 ime_app_process_key_event_cb, this);
329 ime_event_set_display_language_changed_cb(
330 ime_app_display_language_changed_cb, this);
332 return ime_run(&ops, this);
336 // ime_app_main() function is the main entry point of IME application
337 // but in case of Web App. ime_app_main() is not a entry point.
338 // To avoid build fail, add empty function.
343 __attribute__ ((visibility("default")))
344 void ime_app_main(int argc, char **argv) {
345 LOGGER(DEBUG) << "ime_app_main";
352 } // namespace runtime