brendanlong

Untitled

Jan 16th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.29 KB | None | 0 0
  1. // ffi.rs
  2. extern crate glib_sys;
  3. extern crate gtk_sys;
  4. extern crate gtk;
  5. extern crate libc;
  6.  
  7. #[repr(C)]
  8. pub struct WebKitWebView(libc::c_void);
  9.  
  10. #[link(name="webkit2gtk-4.0")]
  11. extern "C" {
  12.     pub fn webkit_web_view_new() -> *mut gtk_sys::GtkWidget;
  13.     pub fn webkit_web_view_load_html(webview: *mut gtk_sys::GtkWidget,
  14.                                      content: *const libc::c_char,
  15.                                      base_uri: *const libc::c_char);
  16.     pub fn webkit_web_view_get_type() -> glib_sys::GType;
  17. }
  18.  
  19. // webview.rs
  20. use gtk;
  21. use glib::translate::*;
  22.  
  23. use ffi;
  24.  
  25. glib_wrapper! {
  26.     pub struct WebKitWebView(Object<ffi::WebKitWebView>): gtk::Container, gtk::Widget;
  27.  
  28.     match fn {
  29.         get_type => || ffi::webkit_web_view_get_type(),
  30.     }
  31. }
  32.  
  33. impl WebKitWebView {
  34.     pub fn new() -> WebKitWebView {
  35.         let webview;
  36.         unsafe {
  37.             webview = gtk::Widget::from_glib_none(ffi::webkit_web_view_new());
  38.         }
  39.         webview
  40.     }
  41.  
  42.     pub fn load_html(&self, html: &str, base_uri: Option<&str>) {
  43.         unsafe {
  44.             ffi::webkit_web_view_load_html(self.to_glib_none().0,
  45.                                            html.to_glib_none().0,
  46.                                            base_uri.to_glib_none().0)
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment