1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
Title: HTML5 "autofocus" tag for input element in dillo
Author: rodarima
Created: Thu, 21 Dec 2023 11:43:16 +0000
State: open
We may want to integrate a patch to support autofocus from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1033320 :
> The attached patch adds support for HTML5's autofocus tag to Dillo: this allows to automatically focus certain input fields as soon as the page with the form loads. We're using this to implement a barcode scanner on a raspberry pi 3, so that the browser is immediately ready to scan, without a need to touch into the input field first.
Here is the diff:
```diff
diff -ur dillo-3.0.5.orig/dw/fltkplatform.cc dillo-3.0.5/dw/fltkplatform.cc
--- dillo-3.0.5.orig/dw/fltkplatform.cc 2015-06-10 23:48:53.000000000 +0200
+++ dillo-3.0.5/dw/fltkplatform.cc 2023-03-18 12:41:21.910464773 +0100
@@ -370,6 +370,10 @@
{
}
+void FltkView::focusFltkWidget (Fl_Widget *widget)
+{
+}
+
void FltkView::allocateFltkWidget (Fl_Widget *widget,
core::Allocation *allocation)
{
diff -ur dillo-3.0.5.orig/dw/fltkplatform.hh dillo-3.0.5/dw/fltkplatform.hh
--- dillo-3.0.5.orig/dw/fltkplatform.hh 2015-06-30 16:06:08.000000000 +0200
+++ dillo-3.0.5/dw/fltkplatform.hh 2023-03-18 12:46:12.542094720 +0100
@@ -86,6 +86,7 @@
virtual void allocateFltkWidget (Fl_Widget *widget,
core::Allocation *allocation);
virtual void drawFltkWidget (Fl_Widget *widget, core::Rectangle *area);
+ virtual void focusFltkWidget (Fl_Widget *widget);
};
diff -ur dillo-3.0.5.orig/dw/fltkui.cc dillo-3.0.5/dw/fltkui.cc
--- dillo-3.0.5.orig/dw/fltkui.cc 2015-06-30 16:06:08.000000000 +0200
+++ dillo-3.0.5/dw/fltkui.cc 2023-03-18 12:33:36.914259944 +0100
@@ -460,6 +460,11 @@
this->view = NULL;
}
+void FltkResource::focus ()
+{
+ view->focusFltkWidget (widget);
+}
+
void FltkResource::sizeAllocate (core::Allocation *allocation)
{
this->allocation = *allocation;
@@ -574,6 +579,11 @@
FltkResource::setEnabled (enabled);
}
+template <class I> void FltkSpecificResource<I>::focus ()
+{
+ FltkResource::focus ();
+}
+
// ----------------------------------------------------------------------
class EnterButton : public Fl_Button {
diff -ur dillo-3.0.5.orig/dw/fltkui.hh dillo-3.0.5/dw/fltkui.hh
--- dillo-3.0.5.orig/dw/fltkui.hh 2015-06-30 16:06:09.000000000 +0200
+++ dillo-3.0.5/dw/fltkui.hh 2023-03-18 12:38:41.898264236 +0100
@@ -217,6 +217,8 @@
bool isEnabled ();
void setEnabled (bool enabled);
+
+ void focus ();
};
@@ -232,6 +234,8 @@
bool isEnabled ();
void setEnabled (bool enabled);
+
+ void focus ();
};
diff -ur dillo-3.0.5.orig/dw/fltkviewbase.cc dillo-3.0.5/dw/fltkviewbase.cc
--- dillo-3.0.5.orig/dw/fltkviewbase.cc 2015-06-30 16:06:09.000000000 +0200
+++ dillo-3.0.5/dw/fltkviewbase.cc 2023-03-18 12:18:12.234001790 +0100
@@ -711,6 +711,12 @@
add (widget);
}
+void FltkWidgetView::focusFltkWidget (Fl_Widget *widget)
+{
+ focused_child=widget;
+ widget->take_focus();
+}
+
void FltkWidgetView::removeFltkWidget (Fl_Widget *widget)
{
remove (widget);
diff -ur dillo-3.0.5.orig/dw/fltkviewbase.hh dillo-3.0.5/dw/fltkviewbase.hh
--- dillo-3.0.5.orig/dw/fltkviewbase.hh 2015-06-30 16:06:09.000000000 +0200
+++ dillo-3.0.5/dw/fltkviewbase.hh 2023-03-18 12:39:07.514936690 +0100
@@ -132,6 +132,7 @@
void allocateFltkWidget (Fl_Widget *widget,
core::Allocation *allocation);
void drawFltkWidget (Fl_Widget *widget, core::Rectangle *area);
+ void focusFltkWidget (Fl_Widget *widget);
};
} // namespace fltk
diff -ur dillo-3.0.5.orig/dw/ui.cc dillo-3.0.5/dw/ui.cc
--- dillo-3.0.5.orig/dw/ui.cc 2015-06-30 16:06:09.000000000 +0200
+++ dillo-3.0.5/dw/ui.cc 2023-03-18 12:41:55.403344022 +0100
@@ -223,6 +223,10 @@
{
}
+void Resource::focus ()
+{
+}
+
void Resource::emitEnter ()
{
activateEmitter.emitEnter(this);
diff -ur dillo-3.0.5.orig/dw/ui.hh dillo-3.0.5/dw/ui.hh
--- dillo-3.0.5.orig/dw/ui.hh 2015-06-30 16:06:09.000000000 +0200
+++ dillo-3.0.5/dw/ui.hh 2023-03-18 12:33:20.465828321 +0100
@@ -347,6 +347,8 @@
virtual bool isEnabled () = 0;
virtual void setEnabled (bool enabled) = 0;
+ virtual void focus () = 0;
+
inline void connectActivate (ActivateReceiver *receiver) {
activateEmitter.connectActivate (receiver); }
inline void connectClicked (ClickedReceiver *receiver) {
diff -ur dillo-3.0.5.orig/src/form.cc dillo-3.0.5/src/form.cc
--- dillo-3.0.5.orig/src/form.cc 2015-06-30 16:06:09.000000000 +0200
+++ dillo-3.0.5/src/form.cc 2023-03-18 12:40:04.192424547 +0100
@@ -431,7 +431,7 @@
DilloHtmlInputType inp_type;
Resource *resource = NULL;
Embed *embed = NULL;
- char *value, *name, *type, *init_str, *placeholder = NULL;
+ char *value, *name, *type, *init_str, *placeholder = NULL, *autofocus;
const char *attrbuf, *label;
bool init_val = false;
ResourceFactory *factory;
@@ -451,6 +451,7 @@
value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL);
name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL);
type = a_Html_get_attr_wdef(html, tag, tagsize, "type", "");
+ autofocus = a_Html_get_attr_wdef(html, tag, tagsize, "autofocus", NULL);
init_str = NULL;
inp_type = DILLO_HTML_INPUT_UNKNOWN;
@@ -541,6 +542,9 @@
if (resource)
embed = new Embed (resource);
+ if (resource && autofocus)
+ resource->focus();
+
if (inp_type != DILLO_HTML_INPUT_UNKNOWN) {
Html_add_input(html, inp_type, embed, name,
(init_str) ? init_str : "", init_val);
```
|