view subtly/webkit.rb @ 23:8ba26b3c03fd

Added SubtlyBrowserStop
author unexist
date Fri, 22 Jan 2010 13:44:35 +0100
parents dafbdaa3a699
children bb259a0825a1 12b8961eecc0
line wrap: on
line source

##
# @package subtly
#
# @file Webkit bindings
# @author Christoph Kappel <unexist@dorfelite.net>
# @version $Id: subtly/webkit.rb,v 23 1264164275.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")

    ## initialize
    # Create webkit view
    #
    # @return [Oject] New view
    ##

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

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

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

    ## uri=
    # Set given uri
    #
    # @param  [String, #read] uri  Uri to set
    ##
    #
    def uri=(uri)
      Subtly::Webkit.ffi_set_uri(@widget, uri)
    end

    ## title
    # Get title or uri loaded
    #
    # @return [String] Title of uri
    ##

    def title
      Subtly::Webkit.ffi_get_title(@widget)
    end
 
    ## back
    # Step back in browser history
    #
    # @param [Fixnum, #read]  steps  Steps to move back
    ##

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

    ## forward
    # Step forward in history
    #
    # @param [Fixnum, #read]  steps  Steps to move forward
    ##

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

    ## stop
    # Stop page loading
    ##

    def stop
      Subtly::Webkit.ffi_stop(@widget)
    end

    ## reload
    # Reload page from source or cache
    #
    # @param [Bool, #read]  use_cache  Use cache or not
    ##

    def reload(use_cache)
      if(use_cache)
        Subtly::Webkit.ffi_reload_cache(@widget)
      else
        Subtly::Webkit.ffi_reload(@widget)
      end
    end

    private

    ## ffi_new
    # Create webkit view
    #
    # @return [Pointer] New view
    ##

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

    ## ffi_get_uri
    # Load given uri in view
    #
    # @param  [Pointer, #read] web_view  A #WebKitWebView
    #
    # @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]  web_view  A #WebKitWebView
    # @param  [String,  #read] uri        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]  web_view  A #WebKitWebView
    #
    # @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]  web_view  A #WebKitWebView
    # @param  [Int,     #read]  steps     Steps to go
    ##

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

    ## ffi_stop
    # Stop page loading
    #
    # @param  [Pointer, #read]  web_view  A #WebKitWebView
    ##


    attach_function(:ffi_stop,
      :webkit_web_view_stop_loading, [ :pointer ], :void
    )

    ## ffi_reload_cache
    # Reload view from cache
    #
    # @param  [Pointer, #read]  web_view  A #WebKitWebView
    ##

    attach_function(:ffi_reload_cache,
      :webkit_web_view_reload, [ :pointer ], :void
    )

    ## ffi_reload
    # Reload view bypassing cache
    #
    # @param  [Pointer, #read]  web_view  A #WebKitWebView
    ##

    attach_function(:ffi_reload,
      :webkit_web_view_reload_bypass_cache, [ :pointer ], :void
    )    
  end # }}}
end