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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// from webkit2gtk-gir-files
// DO NOT EDIT

use glib::object::Cast;
use glib::object::IsA;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::fmt;

glib::wrapper! {
    /// Result of a Hit Test.
    ///
    /// A Hit Test is an operation to get context information about a given
    /// point in a [`WebView`][crate::WebView]. [`HitTestResult`][crate::HitTestResult] represents the
    /// result of a Hit Test. It provides context information about what is
    /// at the coordinates of the Hit Test, such as if there's a link,
    /// an image or a media.
    ///
    /// You can get the context of the HitTestResult with
    /// [`HitTestResultExt::context()`][crate::prelude::HitTestResultExt::context()] that returns a bitmask of
    /// [`HitTestResultContext`][crate::HitTestResultContext] flags. You can also use
    /// [`HitTestResultExt::context_is_link()`][crate::prelude::HitTestResultExt::context_is_link()], [`HitTestResultExt::context_is_image()`][crate::prelude::HitTestResultExt::context_is_image()] and
    /// [`HitTestResultExt::context_is_media()`][crate::prelude::HitTestResultExt::context_is_media()] to determine whether there's
    /// a link, image or a media element at the coordinates of the Hit Test.
    /// Note that it's possible that several [`HitTestResultContext`][crate::HitTestResultContext] flags
    /// are active at the same time, for example if there's a link containing an image.
    ///
    /// When the mouse is moved over a [`WebView`][crate::WebView] a Hit Test is performed
    /// for the mouse coordinates and `signal::WebView::mouse-target-changed`
    /// signal is emitted with a [`HitTestResult`][crate::HitTestResult].
    ///
    /// # Implements
    ///
    /// [`HitTestResultExt`][trait@crate::prelude::HitTestResultExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "WebKitHitTestResult")]
    pub struct HitTestResult(Object<ffi::WebKitHitTestResult, ffi::WebKitHitTestResultClass>);

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

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

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`HitTestResult`] objects.
    ///
    /// This method returns an instance of [`HitTestResultBuilder`](crate::builders::HitTestResultBuilder) which can be used to create [`HitTestResult`] objects.
    pub fn builder() -> HitTestResultBuilder {
        HitTestResultBuilder::default()
    }
}

#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`HitTestResult`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct HitTestResultBuilder {
    context: Option<u32>,
    image_uri: Option<String>,
    link_label: Option<String>,
    link_title: Option<String>,
    link_uri: Option<String>,
    media_uri: Option<String>,
}

impl HitTestResultBuilder {
    // rustdoc-stripper-ignore-next
    /// Create a new [`HitTestResultBuilder`].
    pub fn new() -> Self {
        Self::default()
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`HitTestResult`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> HitTestResult {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref context) = self.context {
            properties.push(("context", context));
        }
        if let Some(ref image_uri) = self.image_uri {
            properties.push(("image-uri", image_uri));
        }
        if let Some(ref link_label) = self.link_label {
            properties.push(("link-label", link_label));
        }
        if let Some(ref link_title) = self.link_title {
            properties.push(("link-title", link_title));
        }
        if let Some(ref link_uri) = self.link_uri {
            properties.push(("link-uri", link_uri));
        }
        if let Some(ref media_uri) = self.media_uri {
            properties.push(("media-uri", media_uri));
        }
        glib::Object::new::<HitTestResult>(&properties)
    }

    /// Bitmask of [`HitTestResultContext`][crate::HitTestResultContext] flags representing
    /// the context of the [`HitTestResult`][crate::HitTestResult].
    pub fn context(mut self, context: u32) -> Self {
        self.context = Some(context);
        self
    }

    /// The URI of the image if flag [`HitTestResultContext::IMAGE`][crate::HitTestResultContext::IMAGE]
    /// is present in `property::HitTestResult::context`
    pub fn image_uri(mut self, image_uri: &str) -> Self {
        self.image_uri = Some(image_uri.to_string());
        self
    }

    /// The label of the link if flag [`HitTestResultContext::LINK`][crate::HitTestResultContext::LINK]
    /// is present in `property::HitTestResult::context`
    pub fn link_label(mut self, link_label: &str) -> Self {
        self.link_label = Some(link_label.to_string());
        self
    }

    /// The title of the link if flag [`HitTestResultContext::LINK`][crate::HitTestResultContext::LINK]
    /// is present in `property::HitTestResult::context`
    pub fn link_title(mut self, link_title: &str) -> Self {
        self.link_title = Some(link_title.to_string());
        self
    }

    /// The URI of the link if flag [`HitTestResultContext::LINK`][crate::HitTestResultContext::LINK]
    /// is present in `property::HitTestResult::context`
    pub fn link_uri(mut self, link_uri: &str) -> Self {
        self.link_uri = Some(link_uri.to_string());
        self
    }

    /// The URI of the media if flag [`HitTestResultContext::MEDIA`][crate::HitTestResultContext::MEDIA]
    /// is present in `property::HitTestResult::context`
    pub fn media_uri(mut self, media_uri: &str) -> Self {
        self.media_uri = Some(media_uri.to_string());
        self
    }
}

/// Trait containing all [`struct@HitTestResult`] methods.
///
/// # Implementors
///
/// [`HitTestResult`][struct@crate::HitTestResult]
pub trait HitTestResultExt: 'static {
    /// Gets whether [`HitTestResultContext::EDITABLE`][crate::HitTestResultContext::EDITABLE] flag is present in
    /// `property::HitTestResult::context`.
    ///
    /// # Returns
    ///
    /// [`true`] if there's an editable element at the coordinates of the `self`,
    ///  or [`false`] otherwise
    #[doc(alias = "webkit_hit_test_result_context_is_editable")]
    fn context_is_editable(&self) -> bool;

    /// Gets whether [`HitTestResultContext::IMAGE`][crate::HitTestResultContext::IMAGE] flag is present in
    /// `property::HitTestResult::context`.
    ///
    /// # Returns
    ///
    /// [`true`] if there's an image element in the coordinates of the Hit Test,
    ///  or [`false`] otherwise
    #[doc(alias = "webkit_hit_test_result_context_is_image")]
    fn context_is_image(&self) -> bool;

    /// Gets whether [`HitTestResultContext::LINK`][crate::HitTestResultContext::LINK] flag is present in
    /// `property::HitTestResult::context`.
    ///
    /// # Returns
    ///
    /// [`true`] if there's a link element in the coordinates of the Hit Test,
    ///  or [`false`] otherwise
    #[doc(alias = "webkit_hit_test_result_context_is_link")]
    fn context_is_link(&self) -> bool;

    /// Gets whether [`HitTestResultContext::MEDIA`][crate::HitTestResultContext::MEDIA] flag is present in
    /// `property::HitTestResult::context`.
    ///
    /// # Returns
    ///
    /// [`true`] if there's a media element in the coordinates of the Hit Test,
    ///  or [`false`] otherwise
    #[doc(alias = "webkit_hit_test_result_context_is_media")]
    fn context_is_media(&self) -> bool;

    /// Gets whether [`HitTestResultContext::SCROLLBAR`][crate::HitTestResultContext::SCROLLBAR] flag is present in
    /// `property::HitTestResult::context`.
    ///
    /// # Returns
    ///
    /// [`true`] if there's a scrollbar element at the coordinates of the `self`,
    ///  or [`false`] otherwise
    #[doc(alias = "webkit_hit_test_result_context_is_scrollbar")]
    fn context_is_scrollbar(&self) -> bool;

    /// Gets whether [`HitTestResultContext::SELECTION`][crate::HitTestResultContext::SELECTION] flag is present in
    /// `property::HitTestResult::context`.
    ///
    /// # Returns
    ///
    /// [`true`] if there's a selected element at the coordinates of the `self`,
    ///  or [`false`] otherwise
    #[cfg(any(feature = "v2_8", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_8")))]
    #[doc(alias = "webkit_hit_test_result_context_is_selection")]
    fn context_is_selection(&self) -> bool;

    /// Gets the value of the `property::HitTestResult::context` property.
    ///
    /// # Returns
    ///
    /// a bitmask of [`HitTestResultContext`][crate::HitTestResultContext] flags
    #[doc(alias = "webkit_hit_test_result_get_context")]
    #[doc(alias = "get_context")]
    fn context(&self) -> u32;

    /// Gets the value of the `property::HitTestResult::image-uri` property.
    ///
    /// # Returns
    ///
    /// the URI of the image element in the coordinates of the Hit Test,
    ///  or [`None`] if there isn't an image element in `self` context
    #[doc(alias = "webkit_hit_test_result_get_image_uri")]
    #[doc(alias = "get_image_uri")]
    fn image_uri(&self) -> Option<glib::GString>;

    /// Gets the value of the `property::HitTestResult::link-label` property.
    ///
    /// # Returns
    ///
    /// the label of the link element in the coordinates of the Hit Test,
    ///  or [`None`] if there isn't a link element in `self` context or the
    ///  link element doesn't have a label
    #[doc(alias = "webkit_hit_test_result_get_link_label")]
    #[doc(alias = "get_link_label")]
    fn link_label(&self) -> Option<glib::GString>;

    /// Gets the value of the `property::HitTestResult::link-title` property.
    ///
    /// # Returns
    ///
    /// the title of the link element in the coordinates of the Hit Test,
    ///  or [`None`] if there isn't a link element in `self` context or the
    ///  link element doesn't have a title
    #[doc(alias = "webkit_hit_test_result_get_link_title")]
    #[doc(alias = "get_link_title")]
    fn link_title(&self) -> Option<glib::GString>;

    /// Gets the value of the `property::HitTestResult::link-uri` property.
    ///
    /// # Returns
    ///
    /// the URI of the link element in the coordinates of the Hit Test,
    ///  or [`None`] if there isn't a link element in `self` context
    #[doc(alias = "webkit_hit_test_result_get_link_uri")]
    #[doc(alias = "get_link_uri")]
    fn link_uri(&self) -> Option<glib::GString>;

    /// Gets the value of the `property::HitTestResult::media-uri` property.
    ///
    /// # Returns
    ///
    /// the URI of the media element in the coordinates of the Hit Test,
    ///  or [`None`] if there isn't a media element in `self` context
    #[doc(alias = "webkit_hit_test_result_get_media_uri")]
    #[doc(alias = "get_media_uri")]
    fn media_uri(&self) -> Option<glib::GString>;
}

impl<O: IsA<HitTestResult>> HitTestResultExt for O {
    fn context_is_editable(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_hit_test_result_context_is_editable(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn context_is_image(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_hit_test_result_context_is_image(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn context_is_link(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_hit_test_result_context_is_link(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn context_is_media(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_hit_test_result_context_is_media(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn context_is_scrollbar(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_hit_test_result_context_is_scrollbar(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v2_8", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_8")))]
    fn context_is_selection(&self) -> bool {
        unsafe {
            from_glib(ffi::webkit_hit_test_result_context_is_selection(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn context(&self) -> u32 {
        unsafe { ffi::webkit_hit_test_result_get_context(self.as_ref().to_glib_none().0) }
    }

    fn image_uri(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_hit_test_result_get_image_uri(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn link_label(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_hit_test_result_get_link_label(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn link_title(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_hit_test_result_get_link_title(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn link_uri(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_hit_test_result_get_link_uri(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn media_uri(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_hit_test_result_get_media_uri(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl fmt::Display for HitTestResult {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("HitTestResult")
    }
}