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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from webkit-gir-files
// DO NOT EDIT

use crate::{ffi, Frame};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// Form manager of a #WebKitWebPage in a #WebKitScriptWorld
    ///
    /// ## Signals
    ///
    ///
    /// #### `form-controls-associated`
    ///  Emitted after form elements (or form associated elements) are associated to @frame.
    /// This is useful to implement form auto filling for web pages where form fields are added
    /// dynamically. This signal might be emitted multiple times for the same frame.
    ///
    /// Note that this signal could be also emitted when form controls are moved between forms. In
    /// that case, the @elements array carries the list of those elements which have moved.
    ///
    /// Clients should take a reference to the members of the @elements array if it is desired to
    /// keep them alive after the signal handler returns.
    ///
    ///
    ///
    ///
    /// #### `will-send-submit-event`
    ///  This signal is emitted when the DOM submit event is about to be fired for @form.
    /// JavaScript code may rely on the submit event to detect that the user has clicked
    /// on a submit button, and to possibly cancel the form submission before
    /// #WebKitWebFormManager::will-submit-form signal is emitted.
    /// However, beware that, for historical reasons, the submit event is not emitted at
    /// all if the form submission is triggered by JavaScript. For these reasons,
    /// this signal may not be used to reliably detect whether a form will be submitted.
    /// Instead, use it to detect if a user has clicked on a form's submit button even if
    /// JavaScript later cancels the form submission, or to read the values of the form's
    /// fields even if JavaScript later clears certain fields before submitting. This may
    /// be needed, for example, to implement a robust browser password manager, as some
    /// misguided websites may use such techniques to attempt to thwart password managers.
    ///
    ///
    ///
    ///
    /// #### `will-submit-form`
    ///  This signal is emitted when @form will imminently be submitted. It can no longer
    /// be cancelled. This event always occurs immediately before a form is submitted to
    /// its target, so use this event to reliably detect when a form is submitted. This
    /// signal is emitted after #WebKitWebFormManager::will-send-submit-event if that
    /// signal is emitted.
    ///
    ///
    ///
    /// # Implements
    ///
    /// [`WebFormManagerExt`][trait@crate::prelude::WebFormManagerExt]
    #[doc(alias = "WebKitWebFormManager")]
    pub struct WebFormManager(Object<ffi::WebKitWebFormManager, ffi::WebKitWebFormManagerClass>);

    match fn {
        type_ => || ffi::webkit_web_form_manager_get_type(),
    }
}

impl WebFormManager {
    pub const NONE: Option<&'static WebFormManager> = None;

    /// Set the value of an HTML input element as if it had been edited by
    /// the user, triggering a change event, and set it as filled automatically.
    /// If @element is not an HTML input element this function does nothing.
    /// ## `element`
    /// a #JSCValue
    /// ## `value`
    /// the text to set
    #[doc(alias = "webkit_web_form_manager_input_element_auto_fill")]
    pub fn input_element_auto_fill(element: &javascriptcore::Value, value: &str) {
        assert_initialized_main_thread!();
        unsafe {
            ffi::webkit_web_form_manager_input_element_auto_fill(
                element.to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    /// Get whether @element is an HTML input element that has been filled automatically.
    /// ## `element`
    /// a #JSCValue
    ///
    /// # Returns
    ///
    /// [`true`] if @element is an HTML input element that has been filled automatically,
    ///    or [`false`] otherwise
    #[doc(alias = "webkit_web_form_manager_input_element_is_auto_filled")]
    pub fn input_element_is_auto_filled(element: &javascriptcore::Value) -> bool {
        assert_initialized_main_thread!();
        unsafe {
            from_glib(ffi::webkit_web_form_manager_input_element_is_auto_filled(
                element.to_glib_none().0,
            ))
        }
    }

    /// Get whether @element is an HTML text input element that has been edited by a user action.
    /// ## `element`
    /// a #JSCValue
    ///
    /// # Returns
    ///
    /// [`true`] if @element is an HTML text input element that has been edited by a user action,
    ///    or [`false`] otherwise
    #[doc(alias = "webkit_web_form_manager_input_element_is_user_edited")]
    pub fn input_element_is_user_edited(element: &javascriptcore::Value) -> bool {
        assert_initialized_main_thread!();
        unsafe {
            from_glib(ffi::webkit_web_form_manager_input_element_is_user_edited(
                element.to_glib_none().0,
            ))
        }
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::WebFormManager>> Sealed for T {}
}

/// Trait containing all [`struct@WebFormManager`] methods.
///
/// # Implementors
///
/// [`WebFormManager`][struct@crate::WebFormManager]
pub trait WebFormManagerExt: IsA<WebFormManager> + sealed::Sealed + 'static {
    //#[doc(alias = "form-controls-associated")]
    //fn connect_form_controls_associated<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
    //    Empty ctype elements: *.PtrArray TypeId { ns_id: 16, id: 2 }
    //}

    /// This signal is emitted when the DOM submit event is about to be fired for @form.
    /// JavaScript code may rely on the submit event to detect that the user has clicked
    /// on a submit button, and to possibly cancel the form submission before
    /// #WebKitWebFormManager::will-submit-form signal is emitted.
    /// However, beware that, for historical reasons, the submit event is not emitted at
    /// all if the form submission is triggered by JavaScript. For these reasons,
    /// this signal may not be used to reliably detect whether a form will be submitted.
    /// Instead, use it to detect if a user has clicked on a form's submit button even if
    /// JavaScript later cancels the form submission, or to read the values of the form's
    /// fields even if JavaScript later clears certain fields before submitting. This may
    /// be needed, for example, to implement a robust browser password manager, as some
    /// misguided websites may use such techniques to attempt to thwart password managers.
    /// ## `form`
    /// the #JSCValue to be submitted, which will always correspond to an HTMLFormElement
    /// ## `source_frame`
    /// the #WebKitFrame containing the form to be submitted
    /// ## `target_frame`
    /// the #WebKitFrame containing the form's target,
    ///     which may be the same as @source_frame if no target was specified
    #[doc(alias = "will-send-submit-event")]
    fn connect_will_send_submit_event<
        F: Fn(&Self, &javascriptcore::Value, &Frame, &Frame) + 'static,
    >(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn will_send_submit_event_trampoline<
            P: IsA<WebFormManager>,
            F: Fn(&P, &javascriptcore::Value, &Frame, &Frame) + 'static,
        >(
            this: *mut ffi::WebKitWebFormManager,
            form: *mut javascriptcore::ffi::JSCValue,
            source_frame: *mut ffi::WebKitFrame,
            target_frame: *mut ffi::WebKitFrame,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                WebFormManager::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(form),
                &from_glib_borrow(source_frame),
                &from_glib_borrow(target_frame),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"will-send-submit-event\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    will_send_submit_event_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// This signal is emitted when @form will imminently be submitted. It can no longer
    /// be cancelled. This event always occurs immediately before a form is submitted to
    /// its target, so use this event to reliably detect when a form is submitted. This
    /// signal is emitted after #WebKitWebFormManager::will-send-submit-event if that
    /// signal is emitted.
    /// ## `form`
    /// the #JSCValue to be submitted, which will always correspond to an HTMLFormElement
    /// ## `source_frame`
    /// the #WebKitFrame containing the form to be submitted
    /// ## `target_frame`
    /// the #WebKitFrame containing the form's target,
    ///     which may be the same as @source_frame if no target was specified
    #[doc(alias = "will-submit-form")]
    fn connect_will_submit_form<F: Fn(&Self, &javascriptcore::Value, &Frame, &Frame) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn will_submit_form_trampoline<
            P: IsA<WebFormManager>,
            F: Fn(&P, &javascriptcore::Value, &Frame, &Frame) + 'static,
        >(
            this: *mut ffi::WebKitWebFormManager,
            form: *mut javascriptcore::ffi::JSCValue,
            source_frame: *mut ffi::WebKitFrame,
            target_frame: *mut ffi::WebKitFrame,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                WebFormManager::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(form),
                &from_glib_borrow(source_frame),
                &from_glib_borrow(target_frame),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"will-submit-form\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    will_submit_form_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<WebFormManager>> WebFormManagerExt for O {}