Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ffi.rs
- extern crate glib_sys;
- extern crate gtk_sys;
- extern crate gtk;
- extern crate libc;
- #[repr(C)]
- pub struct WebKitWebView(libc::c_void);
- #[link(name="webkit2gtk-4.0")]
- extern "C" {
- pub fn webkit_web_view_new() -> *mut gtk_sys::GtkWidget;
- pub fn webkit_web_view_load_html(webview: *mut gtk_sys::GtkWidget,
- content: *const libc::c_char,
- base_uri: *const libc::c_char);
- pub fn webkit_web_view_get_type() -> glib_sys::GType;
- }
- // webview.rs
- use gtk;
- use glib::translate::*;
- use ffi;
- glib_wrapper! {
- pub struct WebKitWebView(Object<ffi::WebKitWebView>): gtk::Container, gtk::Widget;
- match fn {
- get_type => || ffi::webkit_web_view_get_type(),
- }
- }
- impl WebKitWebView {
- pub fn new() -> WebKitWebView {
- let webview;
- unsafe {
- webview = gtk::Widget::from_glib_none(ffi::webkit_web_view_new());
- }
- webview
- }
- pub fn load_html(&self, html: &str, base_uri: Option<&str>) {
- unsafe {
- ffi::webkit_web_view_load_html(self.to_glib_none().0,
- html.to_glib_none().0,
- base_uri.to_glib_none().0)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment