IME show properly after disappear the clipboard.
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / efl / InputMethodContextEfl.cpp
1 /*
2    Copyright (C) 2011 Samsung Electronics
3    Copyright (C) 2012 Intel Corporation. All rights reserved.
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18     Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22 #include "InputMethodContextEfl.h"
23
24 #include "EwkViewImpl.h"
25 #include "WebPageProxy.h"
26 #include <Ecore_Evas.h>
27 #include <Ecore_IMF_Evas.h>
28
29 using namespace WebCore;
30
31 namespace WebKit {
32
33 InputMethodContextEfl::InputMethodContextEfl(EwkViewImpl* viewImpl, PassOwnPtr<Ecore_IMF_Context> context)
34     : m_viewImpl(viewImpl)
35     , m_context(context)
36     , m_focused(false)
37 #if ENABLE(TIZEN_ISF_PORT)
38     , m_useInputMethod(false)
39     , m_state(ECORE_IMF_INPUT_PANEL_STATE_HIDE)
40     , m_inputPickerType(-1)
41 #endif
42 {
43     ASSERT(context);
44 #if ENABLE(TIZEN_ISF_PORT)
45     initializeIMFContext(m_context.get(), ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL);
46 #else
47     ecore_imf_context_event_callback_add(m_context.get(), ECORE_IMF_CALLBACK_PREEDIT_CHANGED, onIMFPreeditSequenceChanged, this);
48     ecore_imf_context_event_callback_add(m_context.get(), ECORE_IMF_CALLBACK_COMMIT, onIMFInputSequenceComplete, this);
49 #endif
50 }
51
52 InputMethodContextEfl::~InputMethodContextEfl()
53 {
54 }
55
56 #if ENABLE(TIZEN_ISF_PORT)
57 void InputMethodContextEfl::onIMFInputPanelStateChanged(void* data, Ecore_IMF_Context*, int state)
58 {
59     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
60
61     inputMethodContext->setState(state);
62
63     if (state == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
64 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
65         if (inputMethodContext->m_viewImpl->pageClient->isClipboardWindowOpened())
66             inputMethodContext->m_viewImpl->pageClient->closeClipboardWindow();
67 #endif
68         evas_object_smart_callback_call(inputMethodContext->m_viewImpl->view(), "editorclient,ime,closed", 0);
69     } else if (state == ECORE_IMF_INPUT_PANEL_STATE_SHOW)
70         evas_object_smart_callback_call(inputMethodContext->m_viewImpl->view(), "editorclient,ime,opened", 0);
71 }
72
73 void InputMethodContextEfl::onIMFInputPanelGeometryChanged(void* data, Ecore_IMF_Context*, int value)
74 {
75     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
76
77     Eina_Rectangle rect;
78     ecore_imf_context_input_panel_geometry_get(inputMethodContext->m_context.get(), &rect.x, &rect.y, &rect.w, &rect.h);
79     evas_object_smart_callback_call(inputMethodContext->m_viewImpl->view(), "inputmethod,changed", &rect);
80
81     inputMethodContext->setIMERect(IntRect(rect.x, rect.y, rect.w, rect.h));
82 }
83
84 void InputMethodContextEfl::onIMFCandidatePanelStateChanged(void* data, Ecore_IMF_Context*, int state)
85 {
86     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
87
88     if (state == ECORE_IMF_CANDIDATE_PANEL_SHOW)
89         evas_object_smart_callback_call(inputMethodContext->m_viewImpl->view(), "editorclient,candidate,opened", 0);
90     else
91         evas_object_smart_callback_call(inputMethodContext->m_viewImpl->view(), "editorclient,candidate,closed", 0);
92 }
93
94 void InputMethodContextEfl::onIMFCandidatePanelGeometryChanged(void* data, Ecore_IMF_Context*, int)
95 {
96     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
97
98     Eina_Rectangle rect;
99     ecore_imf_context_candidate_panel_geometry_get(inputMethodContext->m_context.get(), &rect.x, &rect.y, &rect.w, &rect.h);
100     evas_object_smart_callback_call(inputMethodContext->m_viewImpl->view(), "editorclient,candidate,changed", &rect);
101 }
102
103 Eina_Bool InputMethodContextEfl::onIMFRetrieveSurrounding(void* data, Ecore_IMF_Context*, char** text, int* offset)
104 {
105     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
106     if (!inputMethodContext->m_viewImpl->page()->focusedFrame() || !inputMethodContext->m_focused || (!text && !offset))
107         return false;
108
109     String surroundingText;
110     int cursorOffset;
111     inputMethodContext->m_viewImpl->page()->getSurroundingTextAndCursorOffset(surroundingText, cursorOffset);
112
113     if (text) {
114         CString utf8Text(surroundingText.utf8());
115         size_t length = utf8Text.length();
116
117         *text = static_cast<char*>(malloc((length + 1) * sizeof(char)));
118         if (!(*text))
119             return false;
120
121         if (length)
122             strncpy(*text, utf8Text.data(), length);
123         (*text)[length] = 0;
124     }
125
126     if (offset)
127         *offset = cursorOffset;
128
129     return true;
130 }
131
132 void InputMethodContextEfl::onIMFDeleteSurrounding(void* data, Ecore_IMF_Context*, void* eventInfo)
133 {
134     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
135     if (!eventInfo || !inputMethodContext->m_viewImpl->page()->focusedFrame() || !inputMethodContext->m_focused)
136         return;
137
138     Ecore_IMF_Event_Delete_Surrounding* event = static_cast<Ecore_IMF_Event_Delete_Surrounding*>(eventInfo);
139     inputMethodContext->m_viewImpl->page()->deleteSurroundingText(event->offset, event->n_chars);
140 }
141
142 void InputMethodContextEfl::onIMFInputSequenceComplete(void* data, Ecore_IMF_Context*, void* eventInfo)
143 {
144     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
145     if (!eventInfo || !inputMethodContext->m_focused)
146         return;
147
148     inputMethodContext->m_viewImpl->page()->confirmComposition(String::fromUTF8(static_cast<char*>(eventInfo)));
149 }
150
151 #if ENABLE(TIZEN_WEBKIT2_SUPPORT_JAPANESE_IME)
152 unsigned getUTF8CharacterIndex(const char* string, unsigned byteIndex)
153 {
154     unsigned index = 0;
155     const char* end = string + byteIndex;
156
157     while (*string && string < end) {
158         unsigned offset;
159
160         if ((*string & 0x80) == 0x00)
161             offset = 1;
162         else if ((*string & 0xe0) == 0xc0)
163             offset = 2;
164         else if ((*string & 0xf0) == 0xe0)
165             offset = 3;
166         else if ((*string & 0xf8) == 0xf0)
167             offset = 4;
168         else if ((*string & 0xfc) == 0xf8)
169             offset = 5;
170         else if ((*string & 0xfe) == 0xfc)
171             offset = 6;
172         else
173             offset = 1;
174
175         ++index;
176         while (*string && offset--)
177             ++string;
178     }
179
180     return index;
181 }
182 #endif
183
184 void InputMethodContextEfl::onIMFPreeditSequenceChanged(void* data, Ecore_IMF_Context* context, void*)
185 {
186     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
187
188     if (!inputMethodContext->m_viewImpl->page()->focusedFrame() || !inputMethodContext->m_focused)
189         return;
190
191     WebPageProxy* page = inputMethodContext->m_viewImpl->page();
192     if (!page->focusedFrame())
193         return;
194
195     PageClientImpl* pageClient = inputMethodContext->m_viewImpl->pageClient.get();
196     IntRect caretRect;
197     page->getCaretPosition(caretRect);
198     caretRect.scale(pageClient->scaleFactor());
199
200     int viewX, viewY;
201     evas_object_geometry_get(inputMethodContext->m_viewImpl->view(), &viewX, &viewY, 0, 0);
202
203     int x = caretRect.x() - pageClient->scrollPosition().x() + viewX;
204     int y = caretRect.y() - pageClient->scrollPosition().y() + viewY;
205     int w = caretRect.width();
206     int h = caretRect.height();
207     ecore_imf_context_cursor_location_set(context, x, y, w, h);
208
209     char* buffer = 0;
210     Eina_List* preeditAttrs = 0;
211     int cursorPosition = 0;
212
213     ecore_imf_context_preedit_string_with_attributes_get(context, &buffer, &preeditAttrs, &cursorPosition);
214
215     String preeditString = String::fromUTF8(buffer);
216     Vector<CompositionUnderline> underlines;
217
218     if (preeditAttrs) {
219         void* item = 0;
220 #if ENABLE(TIZEN_WEBKIT2_SUPPORT_JAPANESE_IME)
221         Eina_List* listIterator = 0;
222         EINA_LIST_FOREACH(preeditAttrs, listIterator, item) {
223             Ecore_IMF_Preedit_Attr* preeditAttr = static_cast<Ecore_IMF_Preedit_Attr*>(item);
224
225             unsigned startIndex = getUTF8CharacterIndex(buffer, preeditAttr->start_index);
226             unsigned endIndex = getUTF8CharacterIndex(buffer, preeditAttr->end_index);
227             switch (preeditAttr->preedit_type) {
228             case ECORE_IMF_PREEDIT_TYPE_SUB1:
229                 underlines.append(CompositionUnderline(startIndex, endIndex, Color(0, 0, 0), false));
230                 break;
231             case ECORE_IMF_PREEDIT_TYPE_SUB2:
232             case ECORE_IMF_PREEDIT_TYPE_SUB3:
233                 underlines.append(CompositionUnderline(startIndex, endIndex, Color(0, 0, 0), Color(255, 255, 255), false));
234                 break;
235             case ECORE_IMF_PREEDIT_TYPE_SUB4:
236                 underlines.append(CompositionUnderline(startIndex, endIndex, Color(0, 0, 0), Color(46, 168, 255), false));
237                 break;
238             case ECORE_IMF_PREEDIT_TYPE_SUB5:
239                 underlines.append(CompositionUnderline(startIndex, endIndex, Color(0, 0, 0), Color(153, 98, 195), false));
240                 break;
241             case ECORE_IMF_PREEDIT_TYPE_SUB6:
242                 underlines.append(CompositionUnderline(startIndex, endIndex, Color(0, 0, 0), Color(118, 222, 55), false));
243                 break;
244             case ECORE_IMF_PREEDIT_TYPE_SUB7:
245                 underlines.append(CompositionUnderline(startIndex, endIndex, Color(0, 0, 0), Color(153, 153, 153), false));
246                 break;
247             default:
248                 break;
249             }
250         }
251 #endif
252         EINA_LIST_FREE(preeditAttrs, item)
253             free(item);
254     }
255
256     if (underlines.isEmpty())
257         underlines.append(CompositionUnderline(0, preeditString.length(), Color(0, 0, 0), false));
258
259     page->setComposition(preeditString, underlines, cursorPosition);
260
261     if (buffer)
262         free(buffer);
263 }
264 #else
265 void InputMethodContextEfl::onIMFInputSequenceComplete(void* data, Ecore_IMF_Context*, void* eventInfo)
266 {
267     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
268     if (!eventInfo || !inputMethodContext->m_focused)
269         return;
270
271     inputMethodContext->m_viewImpl->page()->confirmComposition(String::fromUTF8(static_cast<char*>(eventInfo)));
272 }
273
274 void InputMethodContextEfl::onIMFPreeditSequenceChanged(void* data, Ecore_IMF_Context* context, void*)
275 {
276     InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
277
278     if (!inputMethodContext->m_viewImpl->page()->focusedFrame() || !inputMethodContext->m_focused)
279         return;
280
281     char* buffer = 0;
282     ecore_imf_context_preedit_string_get(context, &buffer, 0);
283     if (!buffer)
284         return;
285
286     String preeditString = String::fromUTF8(buffer);
287     free(buffer);
288     Vector<CompositionUnderline> underlines;
289     underlines.append(CompositionUnderline(0, preeditString.length(), Color(0, 0, 0), false));
290     inputMethodContext->m_viewImpl->page()->setComposition(preeditString, underlines, 0);
291 }
292 #endif
293
294 PassOwnPtr<Ecore_IMF_Context> InputMethodContextEfl::createIMFContext(Evas* canvas)
295 {
296     const char* defaultContextID = ecore_imf_context_default_id_get();
297     if (!defaultContextID)
298         return nullptr;
299
300     OwnPtr<Ecore_IMF_Context> imfContext = adoptPtr(ecore_imf_context_add(defaultContextID));
301     if (!imfContext)
302         return nullptr;
303
304     Ecore_Evas* ecoreEvas = ecore_evas_ecore_evas_get(canvas);
305     ecore_imf_context_client_window_set(imfContext.get(), reinterpret_cast<void*>(ecore_evas_window_get(ecoreEvas)));
306     ecore_imf_context_client_canvas_set(imfContext.get(), canvas);
307
308     return imfContext.release();
309 }
310
311 void InputMethodContextEfl::handleMouseUpEvent(const Evas_Event_Mouse_Up*)
312 {
313     ecore_imf_context_reset(m_context.get());
314 }
315
316 void InputMethodContextEfl::handleKeyDownEvent(const Evas_Event_Key_Down* downEvent, bool* isFiltered)
317 {
318     Ecore_IMF_Event inputMethodEvent;
319     ecore_imf_evas_event_key_down_wrap(const_cast<Evas_Event_Key_Down*>(downEvent), &inputMethodEvent.key_down);
320
321     *isFiltered = ecore_imf_context_filter_event(m_context.get(), ECORE_IMF_EVENT_KEY_DOWN, &inputMethodEvent);
322 }
323
324 #if ENABLE(TIZEN_ISF_PORT)
325 void InputMethodContextEfl::updateTextInputState()
326 {
327     const EditorState& editor = m_viewImpl->page()->editorState();
328     if (editor.shouldIgnoreCompositionSelectionChange)
329         return;
330
331     if (editor.isContentEditable && m_useInputMethod) {
332 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
333         if (m_viewImpl->pageClient->isClipboardWindowOpened())
334             m_viewImpl->pageClient->closeClipboardWindow();
335 #endif
336         showIMFContext(editor);
337     } else
338         hideIMFContext();
339
340     if (m_context)
341         ecore_imf_context_cursor_position_set(m_context.get(), editor.cursorPosition);
342 }
343 #else
344 void InputMethodContextEfl::updateTextInputState()
345 {
346     if (!m_context)
347         return;
348
349     const EditorState& editor = m_viewImpl->page()->editorState();
350
351     if (editor.isContentEditable) {
352         if (m_focused)
353             return;
354
355         ecore_imf_context_reset(m_context.get());
356         ecore_imf_context_focus_in(m_context.get());
357         m_focused = true;
358     } else {
359         if (!m_focused)
360             return;
361
362         if (editor.hasComposition)
363             m_viewImpl->page()->cancelComposition();
364
365         m_focused = false;
366         ecore_imf_context_reset(m_context.get());
367         ecore_imf_context_focus_out(m_context.get());
368     }
369 }
370 #endif
371
372 #if ENABLE(TIZEN_ISF_PORT)
373 void InputMethodContextEfl::initializeIMFContext(Ecore_IMF_Context* context, Ecore_IMF_Input_Panel_Layout layout)
374 {
375     ecore_imf_context_input_panel_enabled_set(context, false);
376     ecore_imf_context_input_panel_event_callback_add(context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, onIMFInputPanelStateChanged, this);
377     ecore_imf_context_input_panel_event_callback_add(context, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, onIMFInputPanelGeometryChanged, this);
378     ecore_imf_context_input_panel_event_callback_add(context, ECORE_IMF_CANDIDATE_PANEL_STATE_EVENT, onIMFCandidatePanelStateChanged, this);
379     ecore_imf_context_input_panel_event_callback_add(context, ECORE_IMF_CANDIDATE_PANEL_GEOMETRY_EVENT, onIMFCandidatePanelGeometryChanged, this);
380     ecore_imf_context_retrieve_surrounding_callback_set(context, onIMFRetrieveSurrounding, this);
381     ecore_imf_context_event_callback_add(context, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, onIMFDeleteSurrounding, this);
382     ecore_imf_context_event_callback_add(context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, onIMFPreeditSequenceChanged, this);
383     ecore_imf_context_event_callback_add(context, ECORE_IMF_CALLBACK_COMMIT, onIMFInputSequenceComplete, this);
384     ecore_imf_context_input_panel_layout_set(m_context.get(), layout);
385 }
386
387 void InputMethodContextEfl::setUseInputMethod(bool use)
388 {
389     m_useInputMethod = use;
390     updateTextInputState();
391 }
392
393 Ecore_IMF_Input_Panel_Layout InputMethodContextEfl::layoutType(const String& type)
394 {
395     if (type == "number")
396         return ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBER;
397     else if (type == "email")
398         return ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL;
399     else if (type == "url")
400         return ECORE_IMF_INPUT_PANEL_LAYOUT_URL;
401     else if (type == "tel")
402         return ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER;
403     else if (type == "password")
404         return ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD;
405     else
406         return ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL;
407 }
408
409 void InputMethodContextEfl::setIMFContext(Ecore_IMF_Input_Panel_Layout layout, const String& type)
410 {
411     if (m_contextList.contains(layout)) {
412         revertIMFContext();
413         m_context = m_contextList.take(layout);
414     } else if (!m_context || ecore_imf_context_input_panel_layout_get(m_context.get()) != layout) {
415         OwnPtr<Ecore_IMF_Context> context = createIMFContext(evas_object_evas_get(m_viewImpl->view()));
416         if (m_context)
417             revertIMFContext();
418         m_context = context.release();
419         initializeIMFContext(m_context.get(), layout);
420     }
421
422     if (type == "password" || type == "plugin")
423         ecore_imf_context_prediction_allow_set(m_context.get(), false);
424     else
425         ecore_imf_context_prediction_allow_set(m_context.get(), true);
426
427     if (type.isEmpty() || type == "textarea")
428         ecore_imf_context_autocapital_type_set(m_context.get(), ECORE_IMF_AUTOCAPITAL_TYPE_SENTENCE);
429     else
430         ecore_imf_context_autocapital_type_set(m_context.get(), ECORE_IMF_AUTOCAPITAL_TYPE_NONE);
431 }
432
433 bool InputMethodContextEfl::isShow()
434 {
435     return (m_context && m_focused && ecore_imf_context_input_panel_state_get(m_context.get()) != ECORE_IMF_INPUT_PANEL_STATE_HIDE);
436 }
437
438 Ecore_IMF_Autocapital_Type InputMethodContextEfl::autoCapitalType()
439 {
440     return (m_context ? ecore_imf_context_autocapital_type_get(m_context.get()) : ECORE_IMF_AUTOCAPITAL_TYPE_NONE);
441 }
442
443 void InputMethodContextEfl::onFocusIn()
444 {
445     if (m_inputPickerType >= 0) {
446         showInputPicker(m_viewImpl->page()->editorState());
447         return;
448     }
449
450     if (!m_context || !m_focused)
451         return;
452
453     ecore_imf_context_focus_in(m_context.get());
454     ecore_imf_context_input_panel_show(m_context.get());
455 }
456
457 void InputMethodContextEfl::onFocusOut()
458 {
459 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
460     if (m_state != ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
461         if (m_viewImpl->pageClient->isClipboardWindowOpened())
462             m_viewImpl->pageClient->closeClipboardWindow();
463     }
464 #endif
465
466     if (!m_context || !m_focused)
467         return;
468
469     ecore_imf_context_input_panel_hide(m_context.get());
470     ecore_imf_context_focus_out(m_context.get());
471 }
472
473 void InputMethodContextEfl::revertIMFContext()
474 {
475     if (!m_context)
476         return;
477
478     PassOwnPtr<Ecore_IMF_Context> imfContext = m_context.release();
479     int layout = ecore_imf_context_input_panel_layout_get(imfContext.get());
480     m_contextList.add(layout, imfContext);
481 }
482
483 void InputMethodContextEfl::resetIMFContext()
484 {
485     if (!m_context)
486         return;
487
488     ecore_imf_context_reset(m_context.get());
489 }
490
491 void InputMethodContextEfl::showIMFContext(const EditorState& editor)
492 {
493     Ecore_IMF_Input_Panel_Layout layout = layoutType(editor.inputMethodHints);
494
495     if (m_context && m_state != ECORE_IMF_INPUT_PANEL_STATE_HIDE && layout == ecore_imf_context_input_panel_layout_get(m_context.get()))
496         return;
497
498     Ewk_Settings* settings = ewk_view_settings_get(m_viewImpl->view());
499     bool defaultKeypadEnabled = ewk_settings_default_keypad_enabled_get(settings);
500
501 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
502     if (editor.inputMethodHints == "date")
503         m_inputPickerType = EWK_INPUT_TYPE_DATE;
504     else if (editor.inputMethodHints == "datetime")
505         m_inputPickerType = EWK_INPUT_TYPE_DATETIME;
506     else if (editor.inputMethodHints == "datetime-local")
507         m_inputPickerType = EWK_INPUT_TYPE_DATETIMELOCAL;
508     else if (editor.inputMethodHints == "month")
509         m_inputPickerType = EWK_INPUT_TYPE_MONTH;
510     else if (editor.inputMethodHints == "time")
511         m_inputPickerType = EWK_INPUT_TYPE_TIME;
512     else if (editor.inputMethodHints == "week")
513         m_inputPickerType = EWK_INPUT_TYPE_WEEK;
514     else
515         m_inputPickerType = -1;
516
517     if (m_inputPickerType >= 0) {
518         showInputPicker(editor);
519         return;
520     }
521
522 #if ENABLE(TIZEN_DATALIST_ELEMENT)
523     Vector<String> optionList = m_viewImpl->page()->getFocusedInputElementDataList();
524     if (optionList.size() > 0) {
525         if (editor.selectionIsRange || !evas_object_focus_get(m_viewImpl->view()))
526             return;
527
528         if (editor.inputMethodHints == "tel")
529             ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_TELEPHONE, optionList);
530         else if (editor.inputMethodHints == "number")
531             ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_NUMBER, optionList);
532         else if (editor.inputMethodHints == "email")
533             ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_EMAIL, optionList);
534         else if (editor.inputMethodHints == "url")
535             ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_URL, optionList);
536         else
537             ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_TEXT, optionList);
538
539         return;
540     }
541 #endif
542 #endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
543
544     bool hasFocus = evas_object_focus_get(m_viewImpl->view());
545
546     if (!defaultKeypadEnabled) {
547         if (hasFocus) {
548             Eina_Rectangle dummyRectForCustomKeypadCallback;
549             memset(&dummyRectForCustomKeypadCallback, 0, sizeof(Eina_Rectangle));
550             evas_object_smart_callback_call(m_viewImpl->view(), "inputmethod,changed", &dummyRectForCustomKeypadCallback);
551         }
552         return;
553     }
554
555     setIMFContext(layout, editor.inputMethodHints);
556
557     if (!hasFocus) {
558         m_focused = true;
559         return;
560     }
561
562     ecore_imf_context_reset(m_context.get());
563     ecore_imf_context_focus_in(m_context.get());
564     ecore_imf_context_input_panel_show(m_context.get());
565
566     // input field zoom for external keyboard
567     ewk_view_focused_node_adjust(m_viewImpl->view(), EINA_TRUE);
568
569     m_focused = true;
570     m_state = ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW;
571 }
572
573 void InputMethodContextEfl::hideIMFContext()
574 {
575 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
576     if (m_state != ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
577         if (m_viewImpl->pageClient->isClipboardWindowOpened())
578             m_viewImpl->pageClient->closeClipboardWindow();
579     }
580 #endif
581
582     m_inputPickerType = -1;
583
584     if (!m_context || !m_focused)
585         return;
586
587     if (m_viewImpl->page()->editorState().hasComposition)
588         m_viewImpl->page()->cancelComposition();
589
590     m_focused = false;
591
592     if (ecore_imf_context_input_panel_state_get(m_context.get()) != ECORE_IMF_INPUT_PANEL_STATE_HIDE
593         && evas_object_focus_get(m_viewImpl->view())) {
594         ecore_imf_context_reset(m_context.get());
595         ecore_imf_context_input_panel_hide(m_context.get());
596         ecore_imf_context_focus_out(m_context.get());
597     }
598
599     revertIMFContext();
600 }
601
602 void InputMethodContextEfl::destroyIMFContextList()
603 {
604     m_contextList.clear();
605 }
606
607 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
608 void InputMethodContextEfl::showInputPicker(const EditorState& editorState)
609 {
610     if (editorState.selectionIsRange || !evas_object_focus_get(m_viewImpl->view()))
611         return;
612
613     ewkViewInputPickerRequest(m_viewImpl->view(), static_cast<Ewk_Input_Type>(m_inputPickerType), editorState.surroundingText);
614     m_inputPickerType = -1;
615 }
616 #endif
617
618 bool InputMethodContextEfl::isIMEPostion(int x, int y)
619 {
620     if (m_state == ECORE_IMF_INPUT_PANEL_STATE_SHOW)
621         return m_imeRect.contains(x, y);
622
623     return false;
624 }
625
626 #endif
627
628 }