view subtly/webkit.rb @ 12:3754aca8433a

Added Webkit#back and Webkit#forward
author unexist
date Mon, 14 Dec 2009 00:46:17 +0100
parents c86846c6b2da
children dafbdaa3a699
line wrap: on
line source
##
# @package subtly
#
# @file Webkit bindings
# @author Christoph Kappel <unexist@dorfelite.net>
# @version $Id: subtly/webkit.rb,v 12 1260747977.0-3600 unexist $
#
# This program can be distributed under the terms of the GNU GPL.
##

require "ffi"
require "subtly/gtk"

module Subtly
  class Webkit < Subtly::Gtk::Widget # {{{
    attr_accessor :uri

    extend FFI::Library

    ffi_lib("libwebkit-1.0")

    def initialize
      @widget = Subtly::Webkit.ffi_new
    end

    def uri
      Subtly::Webkit.ffi_get_uri(@widget)
    end

    def uri=(uri)
      Subtly::Webkit.ffi_set_uri(@widget, uri)
    end

    def title
      Subtly::Webkit.ffi_get_title(@widget)
    end

    def back
      Subtly::Webkit.ffi_go_steps(@widget, -1)
    end

    def forward
      Subtly::Webkit.ffi_go_steps(@widget, 1)
    end

    ## ffi_new
    # Create webkit view
    #
    # @return [Pointer] Return the new view
    ##

    attach_function(:ffi_new,
      :webkit_web_view_new, [ ], :pointer
    )

    ## ffi_get_uri
    # Load given uri in view
    #
    # @param  [Pointer, #read]  Webkit view, #GtkWidget
    # @return [String] Uri in webkit view
    ##

    attach_function(:ffi_get_uri,
      :webkit_web_view_get_uri, [ :pointer ], :string
    )

    ## ffi_set_uri
    # Set given uri in view
    #
    # @param  [Pointer, #read]  Webkit view, #GtkWidget
    # @param  [String, #read]   Uri to set
    ##

    attach_function(:ffi_set_uri,
      :webkit_web_view_load_uri, [ :pointer, :string ], :void
    )

    ## ffi_get_title
    # Get title or uri loaded
    #
    # @param  [Pointer, #read]  Webkit view, #GtkWidget
    # @return [String] Title of uri
    ##

    attach_function(:ffi_get_title,
      :webkit_web_view_get_title, [ :pointer ], :string
     )

    ## ffi_go_steps
    # Go back or forward in history
    #
    # @param  [Pointer, #read]  Webkit view, #GtkWidget
    # @param  [Int,     #read]  Steps to go
    ##

    attach_function(:ffi_go_steps,
      :webkit_web_view_go_back_or_forward, [ :pointer, :int ], :void
    )
  end # }}}
end