NetSurf
textinput.c
Go to the documentation of this file.
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"
41#include "netsurf/keypress.h"
42#include "content/content.h"
43
45#include "desktop/textinput.h"
47
48/* Define to enable textinput debug */
49#undef TEXTINPUT_DEBUG
50
51
52/* exported interface documented in desktop/textinput.h */
53void 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 */
88void 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) {
103 }
104}
105
106/* exported interface documented in netsurf/keypress.h */
107bool 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
120}
121
Browser window private structure.
struct browser_window * browser_window_get_root(struct browser_window *bw)
Get the root level browser window.
Browser window creation and manipulation interface.
void browser_window_get_position(struct browser_window *bw, bool root, int *pos_x, int *pos_y)
Get the position of the current browser window with respect to the root or parent browser window.
Content handling interface.
bool content_keypress(struct hlcache_handle *h, uint32_t key)
Handle keypresses.
Definition: content.c:437
Form handling public interface.
struct netsurf_table * guit
The global interface table.
Definition: gui_factory.c:50
Interface to core interface table.
Core mouse and pointer states.
Interface to platform-specific graphical user interface window operations.
@ GW_EVENT_REMOVE_CARET
Remove the caret, if present.
Definition: window.h:98
Interface to key press operations.
int height
Definition: gui.c:161
Interface to utility string handling.
Browser window data.
struct browser_window * bw
float scale
scale of window contents
struct gui_window * window
Platform specific window data only valid at top level.
struct hlcache_handle * current_content
Content handle of page currently displayed which must have READY or DONE status or NULL for no conten...
struct browser_window * focus
browser window child of root browser window which has input focus
nserror(* event)(struct gui_window *gw, enum gui_window_event event)
Miscellaneous event occurred for a window.
Definition: window.h:254
void(* place_caret)(struct gui_window *g, int x, int y, int height, const struct rect *clip)
Place the caret in a browser window.
Definition: window.h:307
struct gui_window_table * window
Window table.
Definition: gui_table.h:66
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
void browser_window_remove_caret(struct browser_window *bw, bool only_hide)
Removes the caret and callback for key process.
Definition: textinput.c:88
void browser_window_place_caret(struct browser_window *bw, int x, int y, int height, const struct rect *clip)
Position the caret and assign a callback for key presses.
Definition: textinput.c:53
bool browser_window_key_press(struct browser_window *bw, uint32_t key)
Handle key presses in a browser window.
Definition: textinput.c:107
Textual input handling interface.
NetSurf types.
UTF-8 manipulation functions (interface).
Interface to a number of general purpose functionality.
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357