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
// 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 crate::BackForwardListItem;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// List of visited pages.
    ///
    /// WebKitBackForwardList maintains a list of visited pages used to
    /// navigate to recent pages. Items are inserted in the list in the
    /// order they are visited.
    ///
    /// WebKitBackForwardList also maintains the notion of the current item
    /// (which is always at index 0), the preceding item (which is at index -1),
    /// and the following item (which is at index 1).
    /// Methods [`WebViewExt::go_back()`][crate::prelude::WebViewExt::go_back()] and [`WebViewExt::go_forward()`][crate::prelude::WebViewExt::go_forward()] move
    /// the current item backward or forward by one. Method
    /// [`WebViewExt::go_to_back_forward_list_item()`][crate::prelude::WebViewExt::go_to_back_forward_list_item()] sets the current item to the
    /// specified item. All other methods returning [`BackForwardListItem`][crate::BackForwardListItem]<!-- -->s
    /// do not change the value of the current item, they just return the requested
    /// item or items.
    ///
    /// # Implements
    ///
    /// [`BackForwardListExt`][trait@crate::prelude::BackForwardListExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "WebKitBackForwardList")]
    pub struct BackForwardList(Object<ffi::WebKitBackForwardList, ffi::WebKitBackForwardListClass>);

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

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

/// Trait containing all [`struct@BackForwardList`] methods.
///
/// # Implementors
///
/// [`BackForwardList`][struct@crate::BackForwardList]
pub trait BackForwardListExt: 'static {
    /// Returns the item that precedes the current item.
    ///
    /// # Returns
    ///
    /// the [`BackForwardListItem`][crate::BackForwardListItem]
    ///  preceding the current item or [`None`].
    #[doc(alias = "webkit_back_forward_list_get_back_item")]
    #[doc(alias = "get_back_item")]
    fn back_item(&self) -> Option<BackForwardListItem>;

    /// Obtain the list of items preceding the current one.
    ///
    /// # Returns
    ///
    /// a `GList` of
    ///  items preceding the current item.
    #[doc(alias = "webkit_back_forward_list_get_back_list")]
    #[doc(alias = "get_back_list")]
    fn back_list(&self) -> Vec<BackForwardListItem>;

    /// Obtain a list up to some number of items preceding the current one.
    /// ## `limit`
    /// the number of items to retrieve
    ///
    /// # Returns
    ///
    /// a `GList` of
    ///  items preceding the current item limited by `limit`.
    #[doc(alias = "webkit_back_forward_list_get_back_list_with_limit")]
    #[doc(alias = "get_back_list_with_limit")]
    fn back_list_with_limit(&self, limit: u32) -> Vec<BackForwardListItem>;

    /// Returns the current item in `self`.
    ///
    /// # Returns
    ///
    /// a [`BackForwardListItem`][crate::BackForwardListItem]
    ///  or [`None`] if `self` is empty.
    #[doc(alias = "webkit_back_forward_list_get_current_item")]
    #[doc(alias = "get_current_item")]
    fn current_item(&self) -> Option<BackForwardListItem>;

    /// Returns the item that follows the current item.
    ///
    /// # Returns
    ///
    /// the [`BackForwardListItem`][crate::BackForwardListItem]
    ///  following the current item or [`None`].
    #[doc(alias = "webkit_back_forward_list_get_forward_item")]
    #[doc(alias = "get_forward_item")]
    fn forward_item(&self) -> Option<BackForwardListItem>;

    /// Obtain the list of items following the current one.
    ///
    /// # Returns
    ///
    /// a `GList` of
    ///  items following the current item.
    #[doc(alias = "webkit_back_forward_list_get_forward_list")]
    #[doc(alias = "get_forward_list")]
    fn forward_list(&self) -> Vec<BackForwardListItem>;

    /// Obtain a list up to some number of items following the current one.
    /// ## `limit`
    /// the number of items to retrieve
    ///
    /// # Returns
    ///
    /// a `GList` of
    ///  items following the current item limited by `limit`.
    #[doc(alias = "webkit_back_forward_list_get_forward_list_with_limit")]
    #[doc(alias = "get_forward_list_with_limit")]
    fn forward_list_with_limit(&self, limit: u32) -> Vec<BackForwardListItem>;

    /// Obtain the amount of items in the list.
    ///
    /// # Returns
    ///
    /// the length of `self`.
    #[doc(alias = "webkit_back_forward_list_get_length")]
    #[doc(alias = "get_length")]
    fn length(&self) -> u32;

    /// Returns the item at a given index relative to the current item.
    /// ## `index`
    /// the index of the item
    ///
    /// # Returns
    ///
    /// the [`BackForwardListItem`][crate::BackForwardListItem]
    ///  located at the specified index relative to the current item or [`None`].
    #[doc(alias = "webkit_back_forward_list_get_nth_item")]
    #[doc(alias = "get_nth_item")]
    fn nth_item(&self, index: i32) -> Option<BackForwardListItem>;

    //#[doc(alias = "changed")]
    //fn connect_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<BackForwardList>> BackForwardListExt for O {
    fn back_item(&self) -> Option<BackForwardListItem> {
        unsafe {
            from_glib_none(ffi::webkit_back_forward_list_get_back_item(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn back_list(&self) -> Vec<BackForwardListItem> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::webkit_back_forward_list_get_back_list(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn back_list_with_limit(&self, limit: u32) -> Vec<BackForwardListItem> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(
                ffi::webkit_back_forward_list_get_back_list_with_limit(
                    self.as_ref().to_glib_none().0,
                    limit,
                ),
            )
        }
    }

    fn current_item(&self) -> Option<BackForwardListItem> {
        unsafe {
            from_glib_none(ffi::webkit_back_forward_list_get_current_item(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn forward_item(&self) -> Option<BackForwardListItem> {
        unsafe {
            from_glib_none(ffi::webkit_back_forward_list_get_forward_item(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn forward_list(&self) -> Vec<BackForwardListItem> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(
                ffi::webkit_back_forward_list_get_forward_list(self.as_ref().to_glib_none().0),
            )
        }
    }

    fn forward_list_with_limit(&self, limit: u32) -> Vec<BackForwardListItem> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(
                ffi::webkit_back_forward_list_get_forward_list_with_limit(
                    self.as_ref().to_glib_none().0,
                    limit,
                ),
            )
        }
    }

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

    fn nth_item(&self, index: i32) -> Option<BackForwardListItem> {
        unsafe {
            from_glib_none(ffi::webkit_back_forward_list_get_nth_item(
                self.as_ref().to_glib_none().0,
                index,
            ))
        }
    }

    //fn connect_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
    //    Unimplemented items_removed: *.Pointer
    //}
}

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