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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/wusyong/gir-files)
// DO NOT EDIT

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

glib::wrapper! {
    #[doc(alias = "WebKitWindowProperties")]
    pub struct WindowProperties(Object<ffi::WebKitWindowProperties, ffi::WebKitWindowPropertiesClass>);

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

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

#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`WindowProperties`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
pub struct WindowPropertiesBuilder {
  fullscreen: Option<bool>,
  geometry: Option<gdk::Rectangle>,
  locationbar_visible: Option<bool>,
  menubar_visible: Option<bool>,
  resizable: Option<bool>,
  scrollbars_visible: Option<bool>,
  statusbar_visible: Option<bool>,
  toolbar_visible: Option<bool>,
}

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

  // rustdoc-stripper-ignore-next
  /// Build the [`WindowProperties`].
  pub fn build(self) -> WindowProperties {
    let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
    if let Some(ref fullscreen) = self.fullscreen {
      properties.push(("fullscreen", fullscreen));
    }
    if let Some(ref geometry) = self.geometry {
      properties.push(("geometry", geometry));
    }
    if let Some(ref locationbar_visible) = self.locationbar_visible {
      properties.push(("locationbar-visible", locationbar_visible));
    }
    if let Some(ref menubar_visible) = self.menubar_visible {
      properties.push(("menubar-visible", menubar_visible));
    }
    if let Some(ref resizable) = self.resizable {
      properties.push(("resizable", resizable));
    }
    if let Some(ref scrollbars_visible) = self.scrollbars_visible {
      properties.push(("scrollbars-visible", scrollbars_visible));
    }
    if let Some(ref statusbar_visible) = self.statusbar_visible {
      properties.push(("statusbar-visible", statusbar_visible));
    }
    if let Some(ref toolbar_visible) = self.toolbar_visible {
      properties.push(("toolbar-visible", toolbar_visible));
    }
    glib::Object::new::<WindowProperties>(&properties)
      .expect("Failed to create an instance of WindowProperties")
  }

  pub fn fullscreen(mut self, fullscreen: bool) -> Self {
    self.fullscreen = Some(fullscreen);
    self
  }

  pub fn geometry(mut self, geometry: &gdk::Rectangle) -> Self {
    self.geometry = Some(geometry.clone());
    self
  }

  pub fn locationbar_visible(mut self, locationbar_visible: bool) -> Self {
    self.locationbar_visible = Some(locationbar_visible);
    self
  }

  pub fn menubar_visible(mut self, menubar_visible: bool) -> Self {
    self.menubar_visible = Some(menubar_visible);
    self
  }

  pub fn resizable(mut self, resizable: bool) -> Self {
    self.resizable = Some(resizable);
    self
  }

  pub fn scrollbars_visible(mut self, scrollbars_visible: bool) -> Self {
    self.scrollbars_visible = Some(scrollbars_visible);
    self
  }

  pub fn statusbar_visible(mut self, statusbar_visible: bool) -> Self {
    self.statusbar_visible = Some(statusbar_visible);
    self
  }

  pub fn toolbar_visible(mut self, toolbar_visible: bool) -> Self {
    self.toolbar_visible = Some(toolbar_visible);
    self
  }
}

pub const NONE_WINDOW_PROPERTIES: Option<&WindowProperties> = None;

pub trait WindowPropertiesExt: 'static {
  #[doc(alias = "webkit_window_properties_get_fullscreen")]
  #[doc(alias = "get_fullscreen")]
  fn is_fullscreen(&self) -> bool;

  #[doc(alias = "webkit_window_properties_get_geometry")]
  #[doc(alias = "get_geometry")]
  fn geometry(&self) -> gdk::Rectangle;

  #[doc(alias = "webkit_window_properties_get_locationbar_visible")]
  #[doc(alias = "get_locationbar_visible")]
  fn is_locationbar_visible(&self) -> bool;

  #[doc(alias = "webkit_window_properties_get_menubar_visible")]
  #[doc(alias = "get_menubar_visible")]
  fn is_menubar_visible(&self) -> bool;

  #[doc(alias = "webkit_window_properties_get_resizable")]
  #[doc(alias = "get_resizable")]
  fn is_resizable(&self) -> bool;

  #[doc(alias = "webkit_window_properties_get_scrollbars_visible")]
  #[doc(alias = "get_scrollbars_visible")]
  fn is_scrollbars_visible(&self) -> bool;

  #[doc(alias = "webkit_window_properties_get_statusbar_visible")]
  #[doc(alias = "get_statusbar_visible")]
  fn is_statusbar_visible(&self) -> bool;

  #[doc(alias = "webkit_window_properties_get_toolbar_visible")]
  #[doc(alias = "get_toolbar_visible")]
  fn is_toolbar_visible(&self) -> bool;
}

impl<O: IsA<WindowProperties>> WindowPropertiesExt for O {
  fn is_fullscreen(&self) -> bool {
    unsafe {
      from_glib(ffi::webkit_window_properties_get_fullscreen(
        self.as_ref().to_glib_none().0,
      ))
    }
  }

  fn geometry(&self) -> gdk::Rectangle {
    unsafe {
      let mut geometry = gdk::Rectangle::uninitialized();
      ffi::webkit_window_properties_get_geometry(
        self.as_ref().to_glib_none().0,
        geometry.to_glib_none_mut().0,
      );
      geometry
    }
  }

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

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

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

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

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

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

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