Class: RubyMVC::Toolkit::WxRuby::WebView

Inherits:
Wx::HtmlWindow
  • Object
show all
Includes:
SignalHandler, Common
Defined in:
lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb

Instance Method Summary collapse

Methods included from Common

#title, #title=

Methods included from SignalHandler

#signal_connect, #signal_disconnect, #signal_emit

Constructor Details

#initialize(options = {}, &block) ⇒ WebView

Returns a new instance of WebView.



34
35
36
37
38
39
40
41
42
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 34

def initialize(options = {}, &block)
  super(WxRuby.parent(options))
  set_background_colour(Wx::WHITE)
  if self.respond_to? :evt_html_link_clicked
    evt_html_link_clicked self, :on_link_clicked
    #evt_html_cell_hover self, :on_hover
  end
  @history = BrowserHistory.new
end

Instance Method Details

#append_html(html = "", &block) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 91

def append_html(html = "", &block)
  # FIXME: not sure if I want to keep this API as it
  # seems kinda clunky...
  h = html || ""
  h << block.call if block
  @history.current[:content] << h
  append_to_page(h)
end

#can_go_back?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 48

def can_go_back?
  @history.has_prev?
end

#can_go_forward?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 52

def can_go_forward?
  @history.has_next?
end

#go_backObject



56
57
58
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 56

def go_back
  load_entry @history.prev
end

#go_forwardObject



60
61
62
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 60

def go_forward
  load_entry @history.next
end

#load_html(html, base_uri = nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 77

def load_html(html, base_uri = nil)
  # FIXME: this isn't quite right...
  if base_uri
    if base_uri != @history.current[:uri]
      @history << { :uri => base_uri, :content => html }
    else
      @history.current[:content] = html
    end
  else
    @history << { :uri => base_uri, :content => html }
  end
  load_entry(@history.current)
end

#locationObject



44
45
46
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 44

def location
  @history.current
end

– wxRuby event handlers ++



104
105
106
107
108
109
110
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 104

def on_link_clicked(link)
  if link.is_a? Wx::HtmlLinkEvent
    # fixup for version 2.0.1 API changes
    link = link.link_info
  end
  signal_emit("navigation-requested", self, link.href, link.target)
end

#open(uri) ⇒ Object



64
65
66
67
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 64

def open(uri)
  @history << { :uri => uri }
  load_entry(@history.current)
end

#reloadObject



73
74
75
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 73

def reload
  load_entry(@history.current)
end

#stop_loadingObject



69
70
71
# File 'lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb', line 69

def stop_loading
  # apparently, we can't do this
end