view subtly/webkit.rb @ 27:bb259a0825a1

Added SubtlyBrowserZoomIn and SubtlyBrowserZoomOut
author unexist
date Fri, 22 Jan 2010 14:57:49 +0100
parents 8ba26b3c03fd
children 304f8997c7d2
line wrap: on
line source
##
# @package subtly
#
# @file Webkit bindings
# @author Christoph Kappel <unexist@dorfelite.net>
# @version $Id: subtly/webkit.rb,v 27 1264168669.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)
      steps *= -1 unless(0 > steps)
      Subtly::Webkit.ffi_go_steps(@widget, steps)
    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

    ## zoom
    # Set zoom level
    #
    # @param [Fixnum, #read] level Level step
    ##

    def zoom=(level)
      if(0 < level)
        Subtly::Webkit.ffi_zoom_in(@widget)
      else
        Subtly::Webkit.ffi_zoom_out(@widget)
      end
    end

    ## zoom
    # Get zoom level
    #
    # @return [Float] Zoom level
    ##

    def zoom
      Subtly::Webkit.ffi_zoom_level(@widget)
    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
    )

    ## ffi_zoom_level
    # Get zoom level
    #
    # @param  [Pointer, #read]  web_view  A #WebKitWebView

    attach_function(:ffi_zoom_level,
      :webkit_web_view_get_zoom_level, [ :pointer ], :float
    )

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

    attach_function(:ffi_zoom_in,
      :webkit_web_view_zoom_in, [ :pointer ], :void
    )

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

    attach_function(:ffi_zoom_out,
      :webkit_web_view_zoom_out, [ :pointer ], :void
    )
  end # }}}
end