1 /*
2 * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
3 * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
4 * Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk>
5 * Copyright 2004 John Tytgat <joty@netsurf-browser.org>
6 * Copyright 2005 Adrian Lees <adrianl@users.sourceforge.net>
7 *
8 * This file is part of NetSurf, http://www.netsurf-browser.org/
9 *
10 * NetSurf is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
13 *
14 * NetSurf is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 /** \file
24 * Textual input handling implementation
25 */
26
27 #include <assert.h>
28 #include <ctype.h>
29 #include <string.h>
30 #include <dom/dom.h>
31
32 #include "utils/log.h"
33 #include "utils/talloc.h"
34 #include "utils/utf8.h"
35 #include "utils/utils.h"
36 #include "netsurf/types.h"
37 #include "netsurf/mouse.h"
38 #include "netsurf/form.h"
39 #include "netsurf/window.h"
40 #include "netsurf/browser_window.h"
41 #include "netsurf/keypress.h"
42 #include "content/content.h"
43
44 #include "desktop/browser_private.h"
45 #include "desktop/textinput.h"
46 #include "desktop/gui_internal.h"
47
48 /* Define to enable textinput debug */
49 #undef TEXTINPUT_DEBUG
50
51
52 /* exported interface documented in desktop/textinput.h */
browser_window_place_caret(struct browser_window * bw,int x,int y,int height,const struct rect * clip)53 void browser_window_place_caret(struct browser_window *bw, int x, int y,
54 int height, const struct rect *clip)
55 {
56 struct browser_window *root_bw;
57 int pos_x = 0;
58 int pos_y = 0;
59 struct rect cr;
60 struct rect *crp = NULL;
61
62 /* Find top level browser window */
63 root_bw = browser_window_get_root(bw);
64 browser_window_get_position(bw, true, &pos_x, &pos_y);
65
66 x = x * bw->scale + pos_x;
67 y = y * bw->scale + pos_y;
68
69 if (clip != NULL) {
70 cr = *clip;
71 cr.x0 += pos_x;
72 cr.y0 += pos_y;
73 cr.x1 += pos_x;
74 cr.y1 += pos_y;
75 crp = &cr;
76 }
77
78 /** \todo intersect with bw viewport */
79
80 guit->window->place_caret(root_bw->window, x, y, height * bw->scale, crp);
81
82 /* Set focus browser window */
83 root_bw->focus = bw;
84 root_bw->can_edit = true;
85 }
86
87 /* exported interface documented in desktop/textinput.h */
browser_window_remove_caret(struct browser_window * bw,bool only_hide)88 void browser_window_remove_caret(struct browser_window *bw, bool only_hide)
89 {
90 struct browser_window *root_bw;
91
92 root_bw = browser_window_get_root(bw);
93 assert(root_bw != NULL);
94
95 if (only_hide) {
96 root_bw->can_edit = true;
97 } else {
98 root_bw->can_edit = false;
99 }
100
101 if (root_bw->window) {
102 guit->window->event(root_bw->window, GW_EVENT_REMOVE_CARET);
103 }
104 }
105
106 /* exported interface documented in netsurf/keypress.h */
browser_window_key_press(struct browser_window * bw,uint32_t key)107 bool browser_window_key_press(struct browser_window *bw, uint32_t key)
108 {
109 struct browser_window *focus = bw->focus;
110
111 assert(bw->window != NULL);
112
113 if (focus == NULL)
114 focus = bw;
115
116 if (focus->current_content == NULL)
117 return false;
118
119 return content_keypress(focus->current_content, key);
120 }
121
122