2
* Copyright (C) 2011 Samsung Electronics
3
* Copyright (C) 2012 Intel Corporation. All rights reserved.
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.
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.
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.
22
#include "InputMethodContextEfl.h"
24
#include "EwkViewImpl.h"
25
#include "WebPageProxy.h"
26
#include <Ecore_Evas.h>
27
#include <Ecore_IMF_Evas.h>
29
using namespace WebCore;
33
InputMethodContextEfl::InputMethodContextEfl(EwkViewImpl* viewImpl, PassOwnPtr<Ecore_IMF_Context> context)
34
: m_viewImpl(viewImpl)
39
ecore_imf_context_event_callback_add(m_context.get(), ECORE_IMF_CALLBACK_PREEDIT_CHANGED, onIMFPreeditSequenceChanged, this);
40
ecore_imf_context_event_callback_add(m_context.get(), ECORE_IMF_CALLBACK_COMMIT, onIMFInputSequenceComplete, this);
43
InputMethodContextEfl::~InputMethodContextEfl()
47
void InputMethodContextEfl::onIMFInputSequenceComplete(void* data, Ecore_IMF_Context*, void* eventInfo)
49
InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
50
if (!eventInfo || !inputMethodContext->m_focused)
53
inputMethodContext->m_viewImpl->page()->confirmComposition(String::fromUTF8(static_cast<char*>(eventInfo)));
56
void InputMethodContextEfl::onIMFPreeditSequenceChanged(void* data, Ecore_IMF_Context* context, void*)
58
InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
60
if (!inputMethodContext->m_viewImpl->page()->focusedFrame() || !inputMethodContext->m_focused)
64
ecore_imf_context_preedit_string_get(context, &buffer, 0);
68
String preeditString = String::fromUTF8(buffer);
70
Vector<CompositionUnderline> underlines;
71
underlines.append(CompositionUnderline(0, preeditString.length(), Color(0, 0, 0), false));
72
inputMethodContext->m_viewImpl->page()->setComposition(preeditString, underlines, 0);
75
PassOwnPtr<Ecore_IMF_Context> InputMethodContextEfl::createIMFContext(Evas* canvas)
77
const char* defaultContextID = ecore_imf_context_default_id_get();
78
if (!defaultContextID)
81
OwnPtr<Ecore_IMF_Context> imfContext = adoptPtr(ecore_imf_context_add(defaultContextID));
85
Ecore_Evas* ecoreEvas = ecore_evas_ecore_evas_get(canvas);
86
ecore_imf_context_client_window_set(imfContext.get(), reinterpret_cast<void*>(ecore_evas_window_get(ecoreEvas)));
87
ecore_imf_context_client_canvas_set(imfContext.get(), canvas);
89
return imfContext.release();
92
void InputMethodContextEfl::handleMouseUpEvent(const Evas_Event_Mouse_Up*)
94
ecore_imf_context_reset(m_context.get());
97
void InputMethodContextEfl::handleKeyDownEvent(const Evas_Event_Key_Down* downEvent, bool* isFiltered)
99
Ecore_IMF_Event inputMethodEvent;
100
ecore_imf_evas_event_key_down_wrap(const_cast<Evas_Event_Key_Down*>(downEvent), &inputMethodEvent.key_down);
102
*isFiltered = ecore_imf_context_filter_event(m_context.get(), ECORE_IMF_EVENT_KEY_DOWN, &inputMethodEvent);
105
void InputMethodContextEfl::updateTextInputState()
110
const EditorState& editor = m_viewImpl->page()->editorState();
112
if (editor.isContentEditable) {
116
ecore_imf_context_reset(m_context.get());
117
ecore_imf_context_focus_in(m_context.get());
123
if (editor.hasComposition)
124
m_viewImpl->page()->cancelComposition();
127
ecore_imf_context_reset(m_context.get());
128
ecore_imf_context_focus_out(m_context.get());