tiny_web_browser 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41ba8e31de38b062a75bd8df10affb28a0ce1a8c
4
+ data.tar.gz: 31b5a31846691cc2c60d5f5b9c273c6ab08e094f
5
+ SHA512:
6
+ metadata.gz: 864be2fed0f632c05b98a8a498fd1a50040297973f780155f96eee75d32d7eba10e7d2f8d856f193384a203f53159210f1a22e89f4ece7d561b47a8e59980855
7
+ data.tar.gz: b1c2b8e3907d6a6e3867e44a2675f2d08be9dd9853f0ff8727d433a4e4a4fd612704125ebb5d3b5538bf893e738a727c04e7f50b4cabad7a451e96b264006d0c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tiny_web_browser.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 trorornmn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # TinyWebBrowser
2
+
3
+ A tiny web browser
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tiny_web_browser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tiny_web_browser
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/trorornmn/tiny_web_browser.
28
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tiny_web_browser"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tiny_web_browser'
4
+
5
+ browser = TinyWebBrowser::Browser.new('https://google.com')
6
+ browser.show_all
7
+ Gtk.main
@@ -0,0 +1,2 @@
1
+ require "tiny_web_browser/version"
2
+ require 'tiny_web_browser/browser'
@@ -0,0 +1,314 @@
1
+ require 'webkit-gtk2'
2
+ require 'uri'
3
+ require 'tiny_web_browser/page'
4
+
5
+ module TinyWebBrowser
6
+ class Browser
7
+
8
+ def initialize(uri)
9
+ @window = Gtk::Window.new
10
+ @window.signal_connect('destroy') do
11
+ Gtk.main_quit
12
+ end
13
+
14
+ @window_box = Gtk::VBox.new
15
+ @notebook = Gtk::Notebook.new
16
+
17
+ @shift_pressed = false
18
+ @ctrl_pressed = false
19
+ @g_pressed_last = false
20
+
21
+ @tabbar = Gtk::VBox.new
22
+ @tabbar_up = Gtk::HBox.new
23
+ @tabbar_down = Gtk::HBox.new
24
+ @go_back_button = Gtk::Button.new('戻る')
25
+ @go_forward_button = Gtk::Button.new('進む')
26
+ @uri_entry = Gtk::Entry.new
27
+ @open_uri_button = Gtk::Button.new('開く')
28
+ @add_tab_buttong = Gtk::Button.new('新規')
29
+ @close_tab_button = Gtk::Button.new('閉じる')
30
+ @search_entry = Gtk::Entry.new
31
+ @last_event = nil
32
+
33
+ @search_entry.signal_connect('changed') do |widget|
34
+ current_webview.search_text(@search_entry.text, false, true, true)
35
+ end
36
+ @search_entry.signal_connect('activate') do |widget|
37
+ @notebook.grab_focus
38
+ end
39
+
40
+ @notebook.signal_connect('key-press-event') do |widget, event|
41
+ puts "notebook #{Gdk::Keyval.to_name(event.keyval)} pressed"
42
+ #puts "notebook #{Gdk::Keyval.to_unicode(event.keyval)} pressed"
43
+ case event.keyval
44
+ when Gdk::Keyval::GDK_KEY_minus
45
+ current_webview.zoom_out
46
+ when Gdk::Keyval::GDK_KEY_plus
47
+ current_webview.zoom_in
48
+ when Gdk::Keyval::GDK_KEY_0
49
+ current_webview.set_zoom_level(1.0)
50
+ when Gdk::Keyval::GDK_KEY_t
51
+ if @last_event != nil
52
+ if @last_event.keyval == Gdk::Keyval::GDK_KEY_g
53
+ next_page
54
+ else
55
+ add_page(uri)
56
+ end
57
+ else
58
+ add_page(uri)
59
+ end
60
+ when Gdk::Keyval::GDK_KEY_T
61
+ if @last_event != nil
62
+ if @last_event.keyval == Gdk::Keyval::GDK_KEY_g
63
+ prev_page
64
+ end
65
+ end
66
+ when Gdk::Keyval::GDK_KEY_g
67
+ if @last_event != nil
68
+ if @last_event.keyval == Gdk::Keyval::GDK_KEY_g
69
+ current_page.dom_element.set_scroll_top(0)
70
+ end
71
+ end
72
+ when Gdk::Keyval::GDK_KEY_G
73
+ current_page.dom_element.set_scroll_top(current_page.dom_element.scroll_height)
74
+ when Gdk::Keyval::GDK_KEY_f
75
+ if @ctrl_pressed
76
+ scroll_top = current_page.dom_element.scroll_top
77
+ current_page.dom_element.set_scroll_top(scroll_top + current_page.dom_element.client_height)
78
+ end
79
+ when Gdk::Keyval::GDK_KEY_b
80
+ if @ctrl_pressed
81
+ scroll_top = current_page.dom_element.scroll_top
82
+ current_page.dom_element.set_scroll_top(scroll_top - current_page.dom_element.client_height)
83
+ end
84
+ when Gdk::Keyval::GDK_KEY_d
85
+ if @ctrl_pressed
86
+ scroll_top = current_page.dom_element.scroll_top
87
+ current_page.dom_element.set_scroll_top(scroll_top + current_page.dom_element.client_height/2)
88
+ else
89
+ close_current_page
90
+ end
91
+ when Gdk::Keyval::GDK_KEY_u
92
+ if @ctrl_pressed
93
+ scroll_top = current_page.dom_element.scroll_top
94
+ current_page.dom_element.set_scroll_top(scroll_top - current_page.dom_element.client_height/2)
95
+ end
96
+ when Gdk::Keyval::GDK_KEY_r
97
+ current_webview.reload
98
+ when Gdk::Keyval::GDK_KEY_i
99
+ @uri_entry.select_region(0, -1)
100
+ @uri_entry.grab_focus
101
+ when Gdk::Keyval::GDK_KEY_h
102
+ scroll_left = current_page.dom_element.scroll_left
103
+ current_page.dom_element.set_scroll_left(scroll_left - 15)
104
+ when Gdk::Keyval::GDK_KEY_l
105
+ scroll_left = current_page.dom_element.scroll_left
106
+ current_page.dom_element.set_scroll_left(scroll_left + 15)
107
+ when Gdk::Keyval::GDK_KEY_j
108
+ scroll_top = current_page.dom_element.scroll_top
109
+ current_page.dom_element.set_scroll_top(scroll_top + 15)
110
+ when Gdk::Keyval::GDK_KEY_k
111
+ scroll_top = current_page.dom_element.scroll_top
112
+ current_page.dom_element.set_scroll_top(scroll_top - 15)
113
+ when Gdk::Keyval::GDK_KEY_slash
114
+ @search_entry.grab_focus
115
+ when Gdk::Keyval::GDK_KEY_n
116
+ if @ctrl_pressed
117
+ next_page
118
+ else
119
+ current_webview.search_text(@search_entry.text, false, true, true)
120
+ end
121
+ when Gdk::Keyval::GDK_KEY_N
122
+ current_webview.search_text(@search_entry.text, false, false, true)
123
+ when Gdk::Keyval::GDK_KEY_H
124
+ current_webview.go_back
125
+ when Gdk::Keyval::GDK_KEY_L
126
+ current_webview.go_forward
127
+ when Gdk::Keyval::GDK_KEY_s
128
+ x, y, width, height, depth = window.window.geometry
129
+ pixbuf = Gdk::Pixbuf.from_drawable(nil,
130
+ window.window,
131
+ 0, 0,
132
+ width, height)
133
+ pixbuf.save("screenshot-#{Time.now.strftime("%Y%m%d%H%M%S")}.png", "png")
134
+ when Gdk::Keyval::GDK_KEY_Shift_L, Gdk::Keyval::GDK_KEY_Shift_R
135
+ @shift_pressed = true
136
+ when Gdk::Keyval::GDK_KEY_Control_L, Gdk::Keyval::GDK_KEY_Control_R
137
+ @ctrl_pressed = true
138
+ when Gdk::Keyval::GDK_KEY_p
139
+ if @ctrl_pressed
140
+ prev_page
141
+ end
142
+ when Gdk::Keyval::GDK_KEY_q
143
+ if @ctrl_pressed
144
+ Gtk.main_quit
145
+ end
146
+ end
147
+
148
+ if Gdk::Keyval.to_unicode(event.keyval) != 0
149
+ @last_event = event
150
+ end
151
+ end
152
+
153
+ @notebook.signal_connect('key-release-event') do |widget, event|
154
+ #puts "notebook #{Gdk::Keyval.to_name(event.keyval)} released"
155
+ case event.keyval
156
+ when Gdk::Keyval::GDK_KEY_Shift_L, Gdk::Keyval::GDK_KEY_Shift_R
157
+ @shift_pressed = false
158
+ when Gdk::Keyval::GDK_KEY_Control_L, Gdk::Keyval::GDK_KEY_Control_R
159
+ @ctrl_pressed = false
160
+ end
161
+ end
162
+
163
+ @notebook.signal_connect('switch_page') do |notebook, page, page_num|
164
+ puts_at_uri_entry(page_num)
165
+ end
166
+
167
+ @go_back_button.signal_connect('clicked') do
168
+ current_webview.go_back
169
+ end
170
+ @go_forward_button.signal_connect('clicked') do
171
+ current_webview.go_forward
172
+ end
173
+ @open_uri_button.signal_connect('clicked') do
174
+ if @uri_entry.text == ''
175
+ current_webview.load_uri(uri)
176
+ else
177
+ current_webview.load_uri(@uri_entry.text)
178
+ end
179
+ end
180
+
181
+
182
+ #@uri_entry.signal_connect('grab-focus') do |widget, event|
183
+ # puts 'grab-focus'
184
+ # @uri_entry.select_region(0, -1)
185
+ # #@notebook.grab_focus
186
+ #end
187
+
188
+ @uri_entry.signal_connect('activate') do |widget, event|
189
+ if (@uri_entry.text =~ /\./) and !(@uri_entry.text =~ /\:\/\//) and (('http://' + @uri_entry.text) =~ URI::regexp)
190
+ open_page('http://' + @uri_entry.text)
191
+ elsif @uri_entry.text =~ URI::regexp
192
+ open_page(@uri_entry.text)
193
+ else
194
+ search_at_google(@uri_entry.text)
195
+ end
196
+ @notebook.grab_focus
197
+ end
198
+ @add_tab_buttong.signal_connect('clicked') do
199
+ add_page(uri)
200
+ end
201
+ @close_tab_button.signal_connect('clicked') do
202
+ close_current_page
203
+ end
204
+ @tabbar_up.pack_start(@go_back_button, false)
205
+ @tabbar_up.pack_start(@go_forward_button, false)
206
+ @tabbar_up.pack_start(@uri_entry)
207
+ @tabbar_up.pack_start(@open_uri_button, false)
208
+ @tabbar_down.pack_start(@add_tab_buttong, false)
209
+ @tabbar_down.pack_start(@close_tab_button, false)
210
+
211
+ @tabbar.pack_start(@tabbar_up)
212
+ @tabbar.pack_start(@tabbar_down)
213
+
214
+ @window_box.pack_start(@tabbar, false)
215
+ @window_box.pack_start(@notebook)
216
+ @window_box.pack_start(@search_entry, false)
217
+
218
+ @window.add(@window_box)
219
+
220
+ @pages = []
221
+ add_page(uri)
222
+ end
223
+
224
+
225
+ def show_all
226
+ @window.show_all
227
+ end
228
+
229
+
230
+ def add_page(uri)
231
+ newpage = BrowserPage.new(uri)
232
+ @pages << newpage
233
+ #@notebook.append_page(@pages[@pages.length - 1].get_page_widget, @pages[@pages.length - 1].get_label_widget)
234
+ @notebook.append_page(@pages[@pages.length - 1].get_widget)
235
+ @notebook.show_all
236
+ @notebook.set_page(@notebook.n_pages - 1)
237
+ puts_at_uri_entry
238
+
239
+ current_webview.signal_connect('title-changed') do |webview, frame, title|
240
+ puts_at_uri_entry
241
+ if title.length >= 10
242
+ @notebook.set_tab_label_text(webview, title[0, 9] + '…')
243
+ else
244
+ @notebook.set_tab_label_text(webview, title)
245
+ end
246
+ end
247
+
248
+ current_webview.signal_connect('create-web-view') do |webview, frame, user_data|
249
+ puts 'create'
250
+ add_page(frame.uri)
251
+ end
252
+ #current_webview.signal_connect('new-window-policy-decision-requested') do |webview, frame, request, navigation_icon, policy_decision, user_data|
253
+ # puts 'new-window'
254
+ # add_page(request.uri)
255
+ #end
256
+ current_webview
257
+ end
258
+
259
+ def close_current_page
260
+ close_page(@notebook.page)
261
+ puts_at_uri_entry
262
+ end
263
+
264
+ def close_page(n)
265
+ if @notebook.n_pages > 1
266
+ @notebook.remove_page(n)
267
+ end
268
+ end
269
+
270
+ def open_page(uri)
271
+ current_webview.load_uri(uri)
272
+ puts_at_uri_entry
273
+ end
274
+
275
+ def prev_page
276
+ if @notebook.page > 0
277
+ @notebook.set_page(@notebook.page - 1)
278
+ else
279
+ @notebook.set_page(@notebook.n_pages - 1)
280
+ end
281
+ end
282
+
283
+ def next_page
284
+ if @notebook.page < @notebook.n_pages - 1
285
+ @notebook.set_page(@notebook.page + 1)
286
+ else
287
+ @notebook.set_page(0)
288
+ end
289
+ end
290
+
291
+ def current_webview
292
+ @notebook.get_nth_page(@notebook.page)
293
+ end
294
+
295
+ def current_page
296
+ @pages[@notebook.page]
297
+ end
298
+
299
+ def search_at_google(query)
300
+ search_uri = 'https://www.google.com/search'
301
+ uri = search_uri + '?q=' + query
302
+ open_page(uri)
303
+ end
304
+
305
+ def puts_at_uri_entry(page_num = -1)
306
+ if page_num < 0
307
+ @uri_entry.set_text(current_webview.uri)
308
+ else
309
+ @uri_entry.set_text(@notebook.get_nth_page(page_num).uri)
310
+ end
311
+ end
312
+
313
+ end
314
+ end
@@ -0,0 +1,22 @@
1
+ require 'webkit-gtk2'
2
+
3
+ module TinyWebBrowser
4
+ class BrowserPage
5
+ def initialize(uri)
6
+ @web_view = WebKitGtk2::WebView.new
7
+ @web_view.load_uri(uri)
8
+ @web_view.show_all
9
+ @web_view
10
+ end
11
+
12
+ def get_widget
13
+ @web_view
14
+ end
15
+
16
+ def dom_element
17
+ dom_document = @web_view.dom_document
18
+ dom_element = dom_document.document_element
19
+ dom_element
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module TinyWebBrowser
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tiny_web_browser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tiny_web_browser"
8
+ spec.version = TinyWebBrowser::VERSION
9
+ spec.authors = ["trorornmn"]
10
+ spec.email = ["trorornmn.develop@gmail.com"]
11
+
12
+ spec.summary = "A tiny web browser"
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/trorornmn/tiny_web_browser"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "webkit-gtk2"
25
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiny_web_browser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - trorornmn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webkit-gtk2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A tiny web browser
56
+ email:
57
+ - trorornmn.develop@gmail.com
58
+ executables:
59
+ - tiny_web_browser
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - exe/tiny_web_browser
71
+ - lib/tiny_web_browser.rb
72
+ - lib/tiny_web_browser/browser.rb
73
+ - lib/tiny_web_browser/page.rb
74
+ - lib/tiny_web_browser/version.rb
75
+ - tiny_web_browser.gemspec
76
+ homepage: https://github.com/trorornmn/tiny_web_browser
77
+ licenses: []
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A tiny web browser
99
+ test_files: []