~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit2/UIProcess/efl/InputMethodContextEfl.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
{
 
38
    ASSERT(m_context);
 
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);
 
41
}
 
42
 
 
43
InputMethodContextEfl::~InputMethodContextEfl()
 
44
{
 
45
}
 
46
 
 
47
void InputMethodContextEfl::onIMFInputSequenceComplete(void* data, Ecore_IMF_Context*, void* eventInfo)
 
48
{
 
49
    InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
 
50
    if (!eventInfo || !inputMethodContext->m_focused)
 
51
        return;
 
52
 
 
53
    inputMethodContext->m_viewImpl->page()->confirmComposition(String::fromUTF8(static_cast<char*>(eventInfo)));
 
54
}
 
55
 
 
56
void InputMethodContextEfl::onIMFPreeditSequenceChanged(void* data, Ecore_IMF_Context* context, void*)
 
57
{
 
58
    InputMethodContextEfl* inputMethodContext = static_cast<InputMethodContextEfl*>(data);
 
59
 
 
60
    if (!inputMethodContext->m_viewImpl->page()->focusedFrame() || !inputMethodContext->m_focused)
 
61
        return;
 
62
 
 
63
    char* buffer = 0;
 
64
    ecore_imf_context_preedit_string_get(context, &buffer, 0);
 
65
    if (!buffer)
 
66
        return;
 
67
 
 
68
    String preeditString = String::fromUTF8(buffer);
 
69
    free(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);
 
73
}
 
74
 
 
75
PassOwnPtr<Ecore_IMF_Context> InputMethodContextEfl::createIMFContext(Evas* canvas)
 
76
{
 
77
    const char* defaultContextID = ecore_imf_context_default_id_get();
 
78
    if (!defaultContextID)
 
79
        return nullptr;
 
80
 
 
81
    OwnPtr<Ecore_IMF_Context> imfContext = adoptPtr(ecore_imf_context_add(defaultContextID));
 
82
    if (!imfContext)
 
83
        return nullptr;
 
84
 
 
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);
 
88
 
 
89
    return imfContext.release();
 
90
}
 
91
 
 
92
void InputMethodContextEfl::handleMouseUpEvent(const Evas_Event_Mouse_Up*)
 
93
{
 
94
    ecore_imf_context_reset(m_context.get());
 
95
}
 
96
 
 
97
void InputMethodContextEfl::handleKeyDownEvent(const Evas_Event_Key_Down* downEvent, bool* isFiltered)
 
98
{
 
99
    Ecore_IMF_Event inputMethodEvent;
 
100
    ecore_imf_evas_event_key_down_wrap(const_cast<Evas_Event_Key_Down*>(downEvent), &inputMethodEvent.key_down);
 
101
 
 
102
    *isFiltered = ecore_imf_context_filter_event(m_context.get(), ECORE_IMF_EVENT_KEY_DOWN, &inputMethodEvent);
 
103
}
 
104
 
 
105
void InputMethodContextEfl::updateTextInputState()
 
106
{
 
107
    if (!m_context)
 
108
        return;
 
109
 
 
110
    const EditorState& editor = m_viewImpl->page()->editorState();
 
111
 
 
112
    if (editor.isContentEditable) {
 
113
        if (m_focused)
 
114
            return;
 
115
 
 
116
        ecore_imf_context_reset(m_context.get());
 
117
        ecore_imf_context_focus_in(m_context.get());
 
118
        m_focused = true;
 
119
    } else {
 
120
        if (!m_focused)
 
121
            return;
 
122
 
 
123
        if (editor.hasComposition)
 
124
            m_viewImpl->page()->cancelComposition();
 
125
 
 
126
        m_focused = false;
 
127
        ecore_imf_context_reset(m_context.get());
 
128
        ecore_imf_context_focus_out(m_context.get());
 
129
    }
 
130
}
 
131
 
 
132
}