• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3  * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 #include "config.h"
30 #include "TextInputControllerQt.h"
31 
32 #include <QApplication>
33 #include <QKeyEvent>
34 
TextInputController(QWebPage * parent)35 TextInputController::TextInputController(QWebPage* parent)
36     : QObject(parent)
37 {
38 }
39 
doCommand(const QString & command)40 void TextInputController::doCommand(const QString& command)
41 {
42     Qt::KeyboardModifiers modifiers = Qt::NoModifier;
43     int keycode = 0;
44     if (command == "moveBackwardAndModifySelection:") {
45         modifiers |= Qt::ShiftModifier;
46         keycode = Qt::Key_Left;
47     } else if (command =="moveDown:") {
48         keycode = Qt::Key_Down;
49     } else if (command =="moveDownAndModifySelection:") {
50         modifiers |= Qt::ShiftModifier;
51         keycode = Qt::Key_Down;
52     } else if (command =="moveForward:") {
53         keycode = Qt::Key_Right;
54     } else if (command =="moveForwardAndModifySelection:") {
55         modifiers |= Qt::ShiftModifier;
56         keycode = Qt::Key_Right;
57     } else if (command =="moveLeft:") {
58         keycode = Qt::Key_Left;
59     } else if (command =="moveLeftAndModifySelection:") {
60         modifiers |= Qt::ShiftModifier;
61         keycode = Qt::Key_Left;
62     } else if (command =="moveRight:") {
63         keycode = Qt::Key_Right;
64     } else if (command =="moveRightAndModifySelection:") {
65         modifiers |= Qt::ShiftModifier;
66         keycode = Qt::Key_Right;
67     } else if (command =="moveToBeginningOfDocument:") {
68         modifiers |= Qt::ControlModifier;
69         keycode = Qt::Key_Home;
70     } else if (command =="moveToBeginningOfLine:") {
71         keycode = Qt::Key_Home;
72 //     } else if (command =="moveToBeginningOfParagraph:") {
73     } else if (command =="moveToEndOfDocument:") {
74         modifiers |= Qt::ControlModifier;
75         keycode = Qt::Key_End;
76     } else if (command =="moveToEndOfLine:") {
77         keycode = Qt::Key_End;
78 //     } else if (command =="moveToEndOfParagraph:") {
79     } else if (command =="moveUp:") {
80         keycode = Qt::Key_Up;
81     } else if (command =="moveUpAndModifySelection:") {
82         modifiers |= Qt::ShiftModifier;
83         keycode = Qt::Key_Up;
84     } else if (command =="moveWordBackward:") {
85         modifiers |= Qt::ControlModifier;
86         keycode = Qt::Key_Up;
87     } else if (command =="moveWordBackwardAndModifySelection:") {
88         modifiers |= Qt::ShiftModifier;
89         modifiers |= Qt::ControlModifier;
90         keycode = Qt::Key_Left;
91     } else if (command =="moveWordForward:") {
92         modifiers |= Qt::ControlModifier;
93         keycode = Qt::Key_Right;
94     } else if (command =="moveWordForwardAndModifySelection:") {
95         modifiers |= Qt::ControlModifier;
96         modifiers |= Qt::ShiftModifier;
97         keycode = Qt::Key_Right;
98     } else if (command =="moveWordLeft:") {
99         modifiers |= Qt::ControlModifier;
100         keycode = Qt::Key_Left;
101     } else if (command =="moveWordRight:") {
102         modifiers |= Qt::ControlModifier;
103         keycode = Qt::Key_Left;
104     } else if (command =="moveWordRightAndModifySelection:") {
105         modifiers |= Qt::ShiftModifier;
106         modifiers |= Qt::ControlModifier;
107         keycode = Qt::Key_Right;
108     } else if (command =="moveWordLeftAndModifySelection:") {
109         modifiers |= Qt::ShiftModifier;
110         modifiers |= Qt::ControlModifier;
111         keycode = Qt::Key_Left;
112     } else if (command =="pageDown:") {
113         keycode = Qt::Key_PageDown;
114     } else if (command =="pageUp:") {
115         keycode = Qt::Key_PageUp;
116     } else if (command == "deleteWordBackward:") {
117         modifiers |= Qt::ControlModifier;
118         keycode = Qt::Key_Backspace;
119     } else if (command == "deleteBackward:") {
120         keycode = Qt::Key_Backspace;
121     } else if (command == "deleteForward:") {
122         keycode = Qt::Key_Delete;
123     }
124 
125     QKeyEvent event(QEvent::KeyPress, keycode, modifiers);
126     QApplication::sendEvent(parent(), &event);
127     QKeyEvent event2(QEvent::KeyRelease, keycode, modifiers);
128     QApplication::sendEvent(parent(), &event2);
129 }
130