opal 0.0.1 → 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.
Files changed (306) hide show
  1. data/.gitignore +10 -1
  2. data/.gitmodules +0 -0
  3. data/Opalfile +371 -0
  4. data/README.md +45 -0
  5. data/Rakefile +237 -34
  6. data/VERSION +1 -1
  7. data/bin/opal +13 -0
  8. data/demos/apps/browser_demo/index.html +11 -0
  9. data/demos/apps/browser_demo/lib/browser_demo.rb +31 -0
  10. data/demos/apps/simple_opal/Opalfile +13 -0
  11. data/demos/apps/simple_opal/index.html +11 -0
  12. data/demos/apps/simple_opal/lib/app_controller.rb +62 -0
  13. data/demos/apps/simple_opal/lib/main_window.rb +146 -0
  14. data/demos/browser/request/index.html +52 -0
  15. data/demos/browser/request/request.rb +48 -0
  16. data/gen/browser/__PROJECT_NAME__/index.html +10 -0
  17. data/gen/browser/__PROJECT_NAME__/lib/__PROJECT_NAME__.rb +1 -0
  18. data/lib/opal.rb +48 -3
  19. data/lib/opal/builders/base.rb +50 -0
  20. data/lib/opal/builders/css.rb +46 -0
  21. data/lib/opal/builders/javascript.rb +44 -0
  22. data/lib/opal/builders/opal.rb +79 -0
  23. data/lib/opal/builders/ruby.rb +50 -0
  24. data/lib/opal/builders/ruby/generate.rb +1851 -0
  25. data/lib/opal/builders/ruby/nodes.rb +210 -0
  26. data/lib/opal/builders/ruby/ruby.rb +916 -0
  27. data/lib/opal/builders/ruby/ruby_parser.rb +6008 -0
  28. data/lib/opal/builders/ruby/ruby_parser.rb.y +1451 -0
  29. data/lib/opal/models/build_item.rb +104 -0
  30. data/lib/opal/models/hash_struct.rb +40 -0
  31. data/lib/opal/models/project.rb +215 -0
  32. data/lib/opal/models/struct_accessors.rb +58 -0
  33. data/lib/opal/models/target.rb +176 -0
  34. data/lib/opal/opal/env/console.rb +66 -0
  35. data/lib/opal/opal/env/fs.rb +98 -0
  36. data/lib/opal/opal/env/object.rb +48 -0
  37. data/lib/opal/opal/environment.rb +139 -0
  38. data/lib/opal/opal/gen.rb +62 -0
  39. data/lib/opal/opal/opal.rb +68 -0
  40. data/lib/opal/opal/repl.rb +38 -0
  41. data/lib/opal/opalfile/dsl.rb +62 -0
  42. data/lib/opal/opalfile/opalfile.rb +133 -0
  43. data/lib/opal/opalfile/task.rb +96 -0
  44. data/lib/opal/opalfile/task_manager.rb +63 -0
  45. data/lib/opal/opalfile/task_scope.rb +52 -0
  46. data/lib/opal/rack/app_server.rb +119 -0
  47. data/opals/aristo/README.md +16 -0
  48. data/opals/browser/Opalfile +11 -0
  49. data/opals/browser/README.md +146 -0
  50. data/opals/browser/SIZZLE_LICESNSE.txt +148 -0
  51. data/opals/browser/lib/browser.rb +118 -0
  52. data/opals/browser/lib/browser/builder.rb +41 -0
  53. data/opals/browser/lib/browser/canvas_context.rb +115 -0
  54. data/opals/browser/lib/browser/dimensions.rb +50 -0
  55. data/opals/browser/lib/browser/document.rb +146 -0
  56. data/opals/browser/lib/browser/element.rb +487 -0
  57. data/opals/browser/lib/browser/element/attributes.rb +88 -0
  58. data/opals/browser/lib/browser/element/css.rb +290 -0
  59. data/opals/browser/lib/browser/element/form.rb +146 -0
  60. data/opals/browser/lib/browser/event/dom_events.rb +81 -0
  61. data/opals/browser/lib/browser/event/event.rb +177 -0
  62. data/opals/browser/lib/browser/event/trigger_events.rb +53 -0
  63. data/opals/browser/lib/browser/geometry.rb +97 -0
  64. data/opals/browser/lib/browser/json.rb +32 -0
  65. data/opals/browser/lib/browser/json_parse.js +321 -0
  66. data/opals/browser/lib/browser/request/request.rb +201 -0
  67. data/opals/browser/lib/browser/sizzle.js +1068 -0
  68. data/opals/browser/lib/browser/string.rb +42 -0
  69. data/opals/browser/lib/browser/touch.rb +37 -0
  70. data/{runtime/yaml.js → opals/browser/lib/browser/vml_context.js} +8 -8
  71. data/opals/browser/lib/browser/window.rb +36 -0
  72. data/opals/browser/spec/browser/browser_detection_spec.rb +7 -0
  73. data/opals/browser/spec/document/aref_spec.rb +110 -0
  74. data/opals/browser/spec/document/ready_spec.rb +16 -0
  75. data/opals/browser/spec/element/body_spec.rb +11 -0
  76. data/opals/browser/spec/element/clear_spec.rb +26 -0
  77. data/opals/browser/spec/element/empty_spec.rb +29 -0
  78. data/opals/browser/spec/element/has_class_spec.rb +40 -0
  79. data/opals/browser/spec/element/hidden_spec.rb +23 -0
  80. data/opals/browser/spec/element/hide_spec.rb +31 -0
  81. data/opals/browser/spec/element/remove_spec.rb +25 -0
  82. data/opals/browser/spec/element/show_spec.rb +31 -0
  83. data/opals/browser/spec/element/style_spec.rb +69 -0
  84. data/opals/browser/spec/element/toggle_spec.rb +31 -0
  85. data/opals/browser/spec/element/visible_spec.rb +23 -0
  86. data/opals/browser/spec/spec_helper.rb +1 -0
  87. data/opals/cherry_kit/Opalfile +6 -0
  88. data/opals/cherry_kit/bin/cherry_kit.rb +11 -0
  89. data/opals/cherry_kit/lib/cherry_kit.rb +29 -0
  90. data/opals/foundation/Opalfile +11 -0
  91. data/opals/foundation/bin/foundation.rb +12 -0
  92. data/opals/foundation/lib/foundation.rb +32 -0
  93. data/opals/foundation/lib/foundation/__table_view_desktop/outline_view.rb +57 -0
  94. data/opals/foundation/lib/foundation/__table_view_desktop/table_column.rb +59 -0
  95. data/opals/foundation/lib/foundation/__table_view_desktop/table_header_view.rb +34 -0
  96. data/opals/foundation/lib/foundation/__table_view_desktop/table_view.rb +304 -0
  97. data/opals/foundation/lib/foundation/controllers/array_controller.rb +54 -0
  98. data/opals/foundation/lib/foundation/controllers/controller.rb +74 -0
  99. data/opals/foundation/lib/foundation/controllers/controller_selection_proxy.rb +67 -0
  100. data/opals/foundation/lib/foundation/controllers/object_controller.rb +145 -0
  101. data/opals/foundation/lib/foundation/controllers/view.rb +40 -0
  102. data/opals/foundation/lib/foundation/core/application.rb +476 -0
  103. data/opals/foundation/lib/foundation/core/attributes.rb +146 -0
  104. data/opals/foundation/lib/foundation/core/bindings.rb +125 -0
  105. data/opals/foundation/lib/foundation/core/builder.rb +101 -0
  106. data/opals/foundation/lib/foundation/core/event.rb +112 -0
  107. data/opals/foundation/lib/foundation/core/index_path.rb +49 -0
  108. data/opals/foundation/lib/foundation/core/index_set.rb +97 -0
  109. data/opals/foundation/lib/foundation/core/notification.rb +113 -0
  110. data/opals/foundation/lib/foundation/core/observable.rb +275 -0
  111. data/opals/foundation/lib/foundation/core/observable_array.rb +30 -0
  112. data/opals/foundation/lib/foundation/core/responder.rb +85 -0
  113. data/opals/foundation/lib/foundation/core/run_loop.rb +89 -0
  114. data/opals/foundation/lib/foundation/core/touch.rb +95 -0
  115. data/opals/foundation/lib/foundation/gestures/gesture_recognizer.rb +35 -0
  116. data/opals/foundation/lib/foundation/rendering/render_context.rb +100 -0
  117. data/opals/foundation/lib/foundation/rendering/renderer.rb +137 -0
  118. data/opals/foundation/lib/foundation/rendering/root_theme.rb +77 -0
  119. data/opals/foundation/lib/foundation/rendering/root_theme/button.rb +62 -0
  120. data/opals/foundation/lib/foundation/rendering/root_theme/control.rb +72 -0
  121. data/opals/foundation/lib/foundation/rendering/root_theme/label.rb +54 -0
  122. data/opals/foundation/lib/foundation/rendering/root_theme/scroller.rb +58 -0
  123. data/opals/foundation/lib/foundation/rendering/root_theme/slider.rb +72 -0
  124. data/opals/foundation/lib/foundation/rendering/root_theme/table_view.rb +97 -0
  125. data/opals/foundation/lib/foundation/rendering/root_theme/text_field.rb +55 -0
  126. data/opals/foundation/lib/foundation/rendering/root_theme/view.rb +81 -0
  127. data/opals/foundation/lib/foundation/rendering/theme.rb +38 -0
  128. data/opals/foundation/lib/foundation/table_view/cell.rb +39 -0
  129. data/opals/foundation/lib/foundation/table_view/table.rb +171 -0
  130. data/opals/foundation/lib/foundation/views/button.rb +63 -0
  131. data/opals/foundation/lib/foundation/views/checkbox.rb +28 -0
  132. data/opals/foundation/lib/foundation/views/clip.rb +47 -0
  133. data/opals/foundation/lib/foundation/views/control.rb +199 -0
  134. data/opals/foundation/lib/foundation/views/label.rb +54 -0
  135. data/opals/foundation/lib/foundation/views/scroll.rb +294 -0
  136. data/opals/foundation/lib/foundation/views/scroll_view_desktop.rb +152 -0
  137. data/opals/foundation/lib/foundation/views/scroller.rb +54 -0
  138. data/opals/foundation/lib/foundation/views/slider.rb +93 -0
  139. data/opals/foundation/lib/foundation/views/text_field.rb +83 -0
  140. data/opals/foundation/lib/foundation/views/view.rb +426 -0
  141. data/opals/foundation/lib/foundation/windows/window.rb +191 -0
  142. data/opals/foundation/resources/button/button.css +23 -0
  143. data/{runtime/init.js → opals/foundation/resources/foundation.css} +27 -33
  144. data/opals/foundation/resources/scroll/scroll.css +22 -0
  145. data/opals/foundation/resources/scroll_view/scroll_view.css +3 -0
  146. data/opals/foundation/resources/scroll_view/scroller.css +3 -0
  147. data/opals/foundation/resources/slider/regular/slider.css +3 -0
  148. data/opals/foundation/resources/slider/slider.css +27 -0
  149. data/opals/foundation/resources/table_view/outline_view.css +3 -0
  150. data/opals/foundation/resources/table_view/table_view.css +15 -0
  151. data/opals/foundation/resources/text_field/text_field.css +71 -0
  152. data/opals/foundation/spec/spec_helper.rb +1 -0
  153. data/opals/foundation/spec/system/attributes/get_attribute_spec.rb +69 -0
  154. data/opals/foundation/spec/system/attributes/get_path_spec.rb +44 -0
  155. data/opals/foundation/spec/system/attributes/set_path_spec.rb +24 -0
  156. data/opals/foundation/spec/system/attributes/set_spec.rb +58 -0
  157. data/opals/foundation/spec/system/bindings/bindings.rb +85 -0
  158. data/opals/foundation/spec/system/key_value_binding/bind_spec.rb +43 -0
  159. data/opals/foundation/spec/system/observable/dependant_keys_spec.rb +74 -0
  160. data/opals/foundation/spec/system/observable/observe_spec.rb +292 -0
  161. data/opals/foundation/spec/system/observable/remove_observer_spec.rb +60 -0
  162. data/opals/opal/Opalfile +14 -0
  163. data/opals/opal/spec/core/array/append_spec.rb +30 -0
  164. data/opals/opal/spec/core/array/assoc_spec.rb +29 -0
  165. data/opals/opal/spec/core/array/at_spec.rb +37 -0
  166. data/opals/opal/spec/core/array/clear_spec.rb +22 -0
  167. data/opals/opal/spec/core/array/collect_bang_spec.rb +27 -0
  168. data/opals/opal/spec/core/array/collect_spec.rb +27 -0
  169. data/opals/opal/spec/core/array/compact_spec.rb +15 -0
  170. data/opals/opal/spec/core/array/concat_spec.rb +15 -0
  171. data/opals/opal/spec/core/array/constructor_spec.rb +14 -0
  172. data/opals/opal/spec/core/array/each_spec.rb +9 -0
  173. data/opals/opal/spec/core/array/element_reference_spec.rb +4 -0
  174. data/opals/opal/spec/core/array/first_spec.rb +35 -0
  175. data/opals/opal/spec/core/array/include_spec.rb +9 -0
  176. data/opals/opal/spec/core/array/map_spec.rb +31 -0
  177. data/opals/opal/spec/core/builtin_constants/builtin_constants_spec.rb +7 -0
  178. data/opals/opal/spec/core/false/and_spec.rb +10 -0
  179. data/opals/opal/spec/core/false/inspect_spec.rb +6 -0
  180. data/opals/opal/spec/core/false/or_spec.rb +10 -0
  181. data/opals/opal/spec/core/false/to_s_spec.rb +6 -0
  182. data/opals/opal/spec/core/false/xor_spec.rb +10 -0
  183. data/opals/opal/spec/core/file/join_spec.rb +19 -0
  184. data/opals/opal/spec/core/kernel/instance_eval_spec.rb +0 -0
  185. data/opals/opal/spec/core/kernel/loop_spec.rb +24 -0
  186. data/opals/opal/spec/core/kernel/raise_spec.rb +0 -0
  187. data/opals/opal/spec/core/module/attr_accessor_spec.rb +28 -0
  188. data/opals/opal/spec/core/number/lt_spec.rb +12 -0
  189. data/opals/opal/spec/core/true/and_spec.rb +10 -0
  190. data/opals/opal/spec/core/true/inspect_spec.rb +6 -0
  191. data/opals/opal/spec/core/true/or_spec.rb +10 -0
  192. data/opals/opal/spec/core/true/to_s_spec.rb +6 -0
  193. data/opals/opal/spec/core/true/xor_spec.rb +10 -0
  194. data/opals/opal/spec/fixtures/super.rb +70 -0
  195. data/opals/opal/spec/language/____temp_remove_this.rb +12 -0
  196. data/opals/opal/spec/language/and_spec.rb +62 -0
  197. data/opals/opal/spec/language/array_spec.rb +52 -0
  198. data/opals/opal/spec/language/block_spec.rb +18 -0
  199. data/opals/opal/spec/language/break_spec.rb +36 -0
  200. data/opals/opal/spec/language/case_spec.rb +103 -0
  201. data/opals/opal/spec/language/def_spec.rb +11 -0
  202. data/opals/opal/spec/language/eigenclass_spec.rb +60 -0
  203. data/opals/opal/spec/language/hash_spec.rb +29 -0
  204. data/opals/opal/spec/language/if_spec.rb +54 -0
  205. data/opals/opal/spec/language/loop_spec.rb +11 -0
  206. data/opals/opal/spec/language/metaclass_spec.rb +21 -0
  207. data/opals/opal/spec/language/method_spec.rb +64 -0
  208. data/opals/opal/spec/language/next_spec.rb +25 -0
  209. data/opals/opal/spec/language/or_spec.rb +34 -0
  210. data/opals/opal/spec/language/redo_spec.rb +24 -0
  211. data/opals/opal/spec/language/rescue_spec.rb +20 -0
  212. data/opals/opal/spec/language/return_spec.rb +47 -0
  213. data/opals/opal/spec/language/string_spec.rb +25 -0
  214. data/opals/opal/spec/language/super_spec.rb +26 -0
  215. data/opals/opal/spec/language/until_spec.rb +157 -0
  216. data/opals/opal/spec/language/while_spec.rb +163 -0
  217. data/opals/opal/spec/spec_helper.rb +5 -0
  218. data/opals/runtime/Opalfile +68 -0
  219. data/opals/runtime/README.md +12 -0
  220. data/opals/runtime/docs/debugging.md +51 -0
  221. data/opals/runtime/lib/array.rb +1516 -0
  222. data/opals/runtime/lib/basic_object.rb +49 -0
  223. data/opals/runtime/lib/class.rb +54 -0
  224. data/opals/runtime/lib/dir.rb +36 -0
  225. data/opals/runtime/lib/error.rb +49 -0
  226. data/opals/runtime/lib/false_class.rb +52 -0
  227. data/opals/runtime/lib/file.rb +79 -0
  228. data/opals/runtime/lib/hash.rb +791 -0
  229. data/opals/runtime/lib/io.rb +39 -0
  230. data/opals/runtime/lib/kernel.rb +288 -0
  231. data/opals/runtime/lib/match_data.rb +36 -0
  232. data/opals/runtime/lib/module.rb +109 -0
  233. data/opals/runtime/lib/nil_class.rb +69 -0
  234. data/opals/runtime/lib/number.rb +398 -0
  235. data/opals/runtime/lib/proc.rb +77 -0
  236. data/opals/runtime/lib/range.rb +63 -0
  237. data/opals/runtime/lib/regexp.rb +111 -0
  238. data/opals/runtime/lib/ruby.rb +30 -0
  239. data/opals/runtime/lib/string.rb +328 -0
  240. data/opals/runtime/lib/symbol.rb +40 -0
  241. data/opals/runtime/lib/top_self.rb +33 -0
  242. data/opals/runtime/lib/true_class.rb +45 -0
  243. data/opals/runtime/runtime/browser.js +287 -0
  244. data/opals/runtime/runtime/debug.js +182 -0
  245. data/opals/runtime/runtime/opal.js +1010 -0
  246. data/opals/runtime/runtime/post_opal.js +1 -0
  247. data/opals/runtime/runtime/pre_opal.js +2 -0
  248. data/opals/runtime/runtime/server_side.js +50 -0
  249. data/opals/spec/LICENSE.txt +26 -0
  250. data/opals/spec/Opalfile +5 -0
  251. data/opals/spec/bin/spec.rb +43 -0
  252. data/opals/spec/lib/spec.rb +33 -0
  253. data/opals/spec/lib/spec/dsl.rb +41 -0
  254. data/opals/spec/lib/spec/example.rb +35 -0
  255. data/opals/spec/lib/spec/example/before_and_after_hooks.rb +81 -0
  256. data/opals/spec/lib/spec/example/errors.rb +42 -0
  257. data/opals/spec/lib/spec/example/example_group.rb +37 -0
  258. data/opals/spec/lib/spec/example/example_group_factory.rb +43 -0
  259. data/opals/spec/lib/spec/example/example_group_hierarchy.rb +45 -0
  260. data/opals/spec/lib/spec/example/example_group_methods.rb +142 -0
  261. data/opals/spec/lib/spec/example/example_group_proxy.rb +41 -0
  262. data/opals/spec/lib/spec/example/example_methods.rb +73 -0
  263. data/opals/spec/lib/spec/example/example_proxy.rb +48 -0
  264. data/opals/spec/lib/spec/expectations.rb +46 -0
  265. data/opals/spec/lib/spec/expectations/errors.rb +35 -0
  266. data/opals/spec/lib/spec/expectations/fail_with.rb +37 -0
  267. data/opals/spec/lib/spec/expectations/handler.rb +48 -0
  268. data/opals/spec/lib/spec/matchers.rb +50 -0
  269. data/opals/spec/lib/spec/matchers/be.rb +26 -0
  270. data/opals/spec/lib/spec/matchers/generated_descriptions.rb +47 -0
  271. data/opals/spec/lib/spec/matchers/operator_matcher.rb +66 -0
  272. data/opals/spec/lib/spec/runner.rb +48 -0
  273. data/opals/spec/lib/spec/runner/example_group_runner.rb +71 -0
  274. data/opals/spec/lib/spec/runner/formatter/html_formatter.rb +100 -0
  275. data/opals/spec/lib/spec/runner/formatter/terminal_formatter.rb +82 -0
  276. data/opals/spec/lib/spec/runner/options.rb +63 -0
  277. data/opals/spec/lib/spec/runner/reporter.rb +123 -0
  278. data/opals/spec/resources/index.html +25 -0
  279. data/opals/spec/resources/spec.css +132 -0
  280. data/spec/cherry_kit/iseq_spec.rb +38 -0
  281. data/spec/spec_helper.rb +16 -0
  282. data/spec/vienna_spec.rb +7 -0
  283. data/yard/index.html +43 -0
  284. data/yard/style.css +765 -0
  285. metadata +312 -49
  286. data/docs/jarv.rdoc +0 -27
  287. data/runtime/array.js +0 -153
  288. data/runtime/class.js +0 -469
  289. data/runtime/compar.js +0 -73
  290. data/runtime/dir.js +0 -115
  291. data/runtime/enum.js +0 -74
  292. data/runtime/file.js +0 -165
  293. data/runtime/gem.js +0 -241
  294. data/runtime/hash.js +0 -181
  295. data/runtime/load.js +0 -251
  296. data/runtime/module.js +0 -98
  297. data/runtime/number.js +0 -148
  298. data/runtime/object.js +0 -522
  299. data/runtime/opal.js +0 -200
  300. data/runtime/parse.js +0 -2218
  301. data/runtime/range.js +0 -56
  302. data/runtime/re.js +0 -91
  303. data/runtime/string.js +0 -199
  304. data/runtime/variable.js +0 -184
  305. data/runtime/vm.js +0 -1150
  306. data/tasks/build.rb +0 -16
@@ -0,0 +1,152 @@
1
+ #
2
+ # scroll_view.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ require 'foundation/views/view'
28
+
29
+ module CherryKit
30
+
31
+ class ScrollViewDesktop < View
32
+
33
+ register_builder :scroll_view,
34
+ {}
35
+
36
+ class_names 'ck-scroll-view'
37
+
38
+ attr_accessor :vertical_scroller, :horizontal_scroller
39
+
40
+ def initialize(layout)
41
+ super layout
42
+
43
+ @content_view = ClipView.new
44
+ self << @content_view
45
+
46
+ @header_clip_view = ClipView.new
47
+ self << @header_clip_view
48
+
49
+ self.has_vertical_scroller = true
50
+ self.has_horizontal_scroller = true
51
+ end
52
+
53
+ def document_view
54
+ @content_view.document_view
55
+ end
56
+
57
+ def document_view=(document_view)
58
+ @content_view.document_view = document_view
59
+
60
+ reflect_scrolled_clip_view @content_view
61
+ end
62
+
63
+ def reflect_scrolled_clip_view(clip_view)
64
+ return unless @content_view == clip_view
65
+
66
+ document_view = self.document_view
67
+
68
+ # handle case where we have no document view..
69
+
70
+ @content_view.layout = {
71
+ :left => 0,
72
+ :top => 20,
73
+ :bottom => 16,
74
+ :right => 16
75
+ }
76
+
77
+ @header_clip_view.layout = {
78
+ :left => 0,
79
+ :top => 0,
80
+ :right => 16,
81
+ :height => 20
82
+ }
83
+
84
+ if @vertical_scroller
85
+ @vertical_scroller.layout = {
86
+ :right => 0,
87
+ :top => 20,
88
+ :bottom => 16,
89
+ :width => 16
90
+ }
91
+ end
92
+
93
+ if @horizontal_scroller
94
+ @horizontal_scroller.layout = {
95
+ :left => 0,
96
+ :bottom => 0,
97
+ :right => 16,
98
+ :height => 16
99
+ }
100
+ end
101
+ end
102
+
103
+ def has_vertical_scroller=(flag)
104
+ # puts "making vertical scroller"
105
+ return if @has_vertical_scroller == flag
106
+ # puts "need to set"
107
+ @has_vertical_scroller = flag
108
+
109
+ # if we want a scroller, but have not yet made one... make one
110
+ if flag && !@vertical_scroller
111
+ # self.vertical_scroller = Scroller.build({
112
+ # :layout => {
113
+ # :height => 24,
114
+ # :width => layout[:width]
115
+ # }
116
+ # })
117
+ self.vertical_scroller = Scroller.build(:vertical => true)
118
+ end
119
+
120
+ reflect_scrolled_clip_view @content_view
121
+ end
122
+
123
+ def has_horizontal_scroller=(flag)
124
+ return if @has_horizontal_scroller == flag
125
+
126
+ @has_horizontal_scroller = flag
127
+
128
+ if flag && !@horizontal_scroller
129
+ self.horizontal_scroller = Scroller.new
130
+ end
131
+ end
132
+
133
+ def vertical_scroller=(vertical_scroller)
134
+ # remove old..
135
+
136
+ @vertical_scroller = vertical_scroller
137
+ # vertical_scroller.on_action do
138
+ # _vertical_scroller_did_scroll
139
+ # end
140
+ self << vertical_scroller
141
+ reflect_scrolled_clip_view @clip_view
142
+ end
143
+
144
+ def horizontal_scroller=(horizontal_scroller)
145
+ @horizontal_scroller = horizontal_scroller
146
+
147
+ self << horizontal_scroller
148
+ reflect_scrolled_clip_view @clip_view
149
+ end
150
+
151
+ end
152
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # scroller.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ require 'foundation/views/control'
28
+
29
+ module CherryKit
30
+
31
+ class Scroller < Control
32
+
33
+ class_names 'ck-scroller'
34
+
35
+ attr_writer :vertical
36
+
37
+ def initialize
38
+ super
39
+ @vertical = false
40
+ end
41
+
42
+ def create_renderer(theme)
43
+ theme.scroller self
44
+ end
45
+
46
+ def vertical?
47
+ @vertical
48
+ end
49
+
50
+ def horizontal?
51
+ !@vertical
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,93 @@
1
+ #
2
+ # slider.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ require 'foundation/views/control'
28
+
29
+ module CherryKit
30
+
31
+ class Slider < Control
32
+
33
+ register_builder :slider, {}
34
+
35
+ class_names 'ck-slider'
36
+
37
+ display_attributes :value, :min, :max
38
+
39
+ attr_accessor :value, :min, :max
40
+
41
+ def initialize
42
+ super
43
+ # puts "====================================== setting value to 0"
44
+ @value = 0
45
+ @min = 0
46
+ @max = 100
47
+ # puts @value
48
+ end
49
+
50
+ def create_renderer(theme)
51
+ theme.slider self
52
+ end
53
+
54
+ # slider value for the given location (point)
55
+ #
56
+ def value_for_location(location)
57
+ # 14/7 should be got from the renderer.. each theme/control size may
58
+ # define a different indent
59
+
60
+ # our width is less 2x the track indent
61
+ width = bounds.width - 14
62
+ # our location is the track indent less than what it actually is
63
+ x = location.x - 7
64
+
65
+ (x / width) * 100
66
+ end
67
+
68
+ def start_tracking?(location)
69
+ self.value = value_for_location location
70
+ self.highlighted = true
71
+ end
72
+
73
+ def stop_tracking(location)
74
+ self.value = value_for_location location
75
+ self.highlighted = false
76
+ end
77
+
78
+ def continue_tracking?(location)
79
+ # puts "value should be #{value_for_location(location)}"
80
+ self.value = value_for_location location
81
+ end
82
+
83
+ def value=(value)
84
+ if value < @min
85
+ @value = @min
86
+ elsif @max < value
87
+ @value = @max
88
+ else
89
+ @value = value
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,83 @@
1
+ #
2
+ # text_field.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ require 'foundation/views/control'
28
+
29
+ module CherryKit
30
+
31
+ class TextField < Control
32
+
33
+ register_builder :text_field, {}
34
+
35
+ class_names 'ck-text-field'
36
+
37
+ display_attributes :bezel
38
+
39
+ # Set the bezel style. May be :rounded or :square
40
+ #
41
+ attr_accessor :bezel
42
+
43
+ def initialize(layout)
44
+ super layout
45
+ @value = ""
46
+ @bezel = :square
47
+ end
48
+
49
+ def create_renderer(theme)
50
+ theme.text_field self
51
+ end
52
+
53
+ def key_down(event)
54
+ if event.key == :return
55
+ false
56
+ elsif event.key == :tab
57
+ false
58
+ else
59
+ true
60
+ end
61
+ end
62
+
63
+ def key_up(event)
64
+ puts "key up event!"
65
+ old_value = self.value
66
+
67
+ unless old_value == "some old valye...s.s.s"
68
+
69
+ unless @editing
70
+ @editing = true
71
+ end
72
+
73
+ end
74
+
75
+ true
76
+ end
77
+
78
+ def _string_value=(value)
79
+
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,426 @@
1
+ #
2
+ # view.rb
3
+ # vienna
4
+ #
5
+ # Created by Adam Beynon.
6
+ # Copyright 2010 Adam Beynon.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ require 'foundation/core/responder'
28
+ require 'foundation/core/builder'
29
+
30
+ module CherryKit
31
+
32
+ class View < Responder
33
+
34
+ # Get the layout hash from the receiver (Hash)
35
+ attr_accessor :layout
36
+
37
+ # the view's window
38
+ attr_reader :window
39
+
40
+ # Boolean whether or not the view can receive multi-touch events. Default
41
+ # is false. If false (default), then the view is only sent details of the
42
+ # first touch in the view, all other touches will be ignored within CKApp
43
+ # and not passed to this view.
44
+ #
45
+ # @getter multiple_touch_enabled?
46
+ #
47
+ # @attribute {true|false} multiple_touch_enabled
48
+ #
49
+ attr_writer :multiple_touch_enabled
50
+
51
+ def initialize(frame)
52
+ # initialize
53
+ # default layout
54
+ @layout = {
55
+ :left => 0,
56
+ :top => 0,
57
+ :right => 0,
58
+ :bottom => 0
59
+ }
60
+ # all of our subviews
61
+ @subviews = []
62
+
63
+ # by default only receive single touches
64
+ @multiple_touch_enabled = false
65
+
66
+ # for every display property defined, we add an observer when it changes,
67
+ # so we can tell the view that it needs a redisplay
68
+ self.class.all_display_attributes.each do |property|
69
+ self.observe(property) do |oldvalue, newvalue|
70
+ self.needs_display = true
71
+ end
72
+ end
73
+ end
74
+
75
+ # For duplicating views. This will duplicate all relevant properties.
76
+ # Subclasses should do their own behaviour. Does NOT copy subviews,
77
+ # superview or window
78
+ #
79
+ def dup
80
+ result = self.class.new
81
+ result.layout = layout
82
+
83
+ result
84
+ end
85
+
86
+ # ======================
87
+ # = Display attributes =
88
+ # ======================
89
+
90
+ def self.all_display_attributes
91
+ if CherryKit::View == self
92
+ return @display_attributes ||= []
93
+ else
94
+ @display_attributes ||= []
95
+ return @display_attributes + superclass.all_display_attributes
96
+ end
97
+ end
98
+
99
+ # Add each of the given display properties to the array of properties for
100
+ # this class
101
+ def self.display_attributes(*properties)
102
+ @display_attributes ||= []
103
+ @display_attributes = @display_attributes + properties
104
+ end
105
+
106
+ # Set each of the given class names (strings) to the array of class names
107
+ # which will all be added together with superclass' to build up the full
108
+ # class name. (e.g. CK::Control will be 'ck-view ck-control')
109
+ #
110
+ def self.class_names(*names)
111
+ # puts "setting class names to #{names.inspect} for #{self}"
112
+ @css_class_names = names
113
+ end
114
+
115
+ def self.all_class_names
116
+ # puts "looking for #{self} with #{@css_class_names.inspect}"
117
+ if CherryKit::View == self
118
+ return @css_class_names ||= []
119
+ else
120
+ @css_class_names ||= []
121
+ return ([] + superclass.all_class_names) + @css_class_names
122
+ end
123
+ end
124
+
125
+ display_attributes :visible, :layout
126
+
127
+ class_names 'ck-view'
128
+
129
+ # Return the theme name to use for the view. In all systems, root_theme is
130
+ # used as the default. To use another theme, set the theme_name property for
131
+ # the window when created so that all subviews will inherit that theme.
132
+ #
133
+ # @returns {Symbol} theme name
134
+ #
135
+ def theme_name
136
+ :root_theme
137
+ end
138
+
139
+ # Returns the receivers container view
140
+ #
141
+ # @returns [View] containing view
142
+ #
143
+ def superview
144
+ @superview
145
+ end
146
+
147
+ def render_context
148
+ @render_context
149
+ end
150
+
151
+ # NEVER EVER call this method directly. This will create and / or update
152
+ # the rendering context as needed
153
+ #
154
+ def display
155
+ if @render_context
156
+ update
157
+ else
158
+ render_context = create_render_context
159
+ # first call .render(), then immediately update() it
160
+ render render_context
161
+ update
162
+ # add to super
163
+ @superview.render_context.element << render_context.element
164
+ end
165
+ end
166
+
167
+ # Create the render_context based on the theme and create_renderer()
168
+ def create_render_context
169
+ return @render_context if @render_context
170
+
171
+ render_context = RenderContext.new tag_name
172
+ theme = Theme.find_theme theme_name
173
+ # unless we could find the theme, throw an error - theme must exist
174
+ theme or raise "Cannot find theme named #{theme_name}"
175
+ # get our renderer. unless overridden, this will be theme::View renderer
176
+ @renderer = create_renderer theme
177
+
178
+ @render_context = render_context
179
+ end
180
+
181
+ # Create the renderer just for this view. The default action is to create
182
+ # a simple view renderer. In this case, the most likely behaviour is that
183
+ # .render() and .update() of this view should be overridden for rendering
184
+ # custom views/data etc
185
+ #
186
+ # @param {CherryKit::Theme} theme to create renderer from
187
+ # @returns {CherryKit::Renderer} renderer
188
+ #
189
+ def create_renderer(theme)
190
+ theme.view self
191
+ end
192
+
193
+ # Core method for the initial render of the view. This method is passed the
194
+ # render context that we render to. The default behaviour is to simply call
195
+ # on the @renderer to render itself in the given context. Any view that does
196
+ # not have a themed renderer should use this method instead and MUST call
197
+ # super()
198
+ #
199
+ # @param {CherryKit::RenderContext} render_context to render to
200
+ # @returns nil
201
+ #
202
+ def render(render_context)
203
+ @renderer.render render_context
204
+ end
205
+
206
+ # Core method for updating the view. This is called immediately after render
207
+ # and also everytime the view needs an update (self.needs_display=true).
208
+ # Again the default behaviour is to simply call .update() on the @renderer,
209
+ # but non themed views may simply have their own code here for updating,
210
+ # but as before, MUST call super() to allow the default ViewRenderer do its
211
+ # business
212
+ #
213
+ # @returns nil
214
+ #
215
+ def update
216
+ @renderer.update
217
+ end
218
+
219
+
220
+
221
+ def visible?
222
+ true
223
+ end
224
+
225
+ # Bounds of the view. This often needs to be recalculated based on css
226
+ # layout etc.
227
+ #
228
+ # @returns {Browser::Rect} rect bounds
229
+ def bounds
230
+ Browser::Rect.new 0, 0, `#{render_context.element}.__element__.clientWidth`, `#{render_context.element}.__element__.clientHeight`
231
+ end
232
+
233
+
234
+ # Root element tag_name used for building the responder context. Should be a
235
+ # Symbol. Default is <tt>:div</tt>
236
+ #
237
+ # @returns {Symbol} tag name
238
+ #
239
+ def tag_name
240
+ :div
241
+ end
242
+
243
+ def <<(subview)
244
+ add_subview subview
245
+ end
246
+
247
+ # Add subview
248
+ #
249
+ # @param {CherryKit::View} view to append as subview
250
+ # @returns {self}
251
+ #
252
+ def add_subview(subview)
253
+ # inform subview that it must first remove itself from its superview
254
+ subview.remove_from_superview
255
+ # privately set the window to our current window
256
+ subview._window = @window
257
+ # notify subview that it is soon to move to this view
258
+ subview.will_move_to_superview self
259
+ # set private superview variable on subview
260
+ subview.instance_variable_set :@superview, self
261
+ # do DOM manipulation here
262
+ @subviews << subview
263
+ # reset responder chain for subview
264
+ subview.next_responder = self
265
+ # alert subview that its move is complete
266
+ subview.did_move_to_superview self
267
+ # any callbacks that might be ndded
268
+ did_add_subview subview
269
+ end
270
+
271
+ # Remove the receiver from its current superview
272
+ #
273
+ def remove_from_superview
274
+
275
+ end
276
+
277
+ # Perform additonal actions once the subview has been added to the
278
+ # receiver
279
+ #
280
+ # @param {CherryKit::View} subview that was added
281
+ # @returns {nil}
282
+ #
283
+ def did_add_subview(subview)
284
+ # nothing by default
285
+ end
286
+
287
+ # Called when the receiver is about to move to the given superview
288
+ #
289
+ # @param {CherryKit::View} view to move to
290
+ #
291
+ def will_move_to_superview(superview)
292
+ # nothing by default
293
+ end
294
+
295
+ # Called when the receiver has just moved to the given superview. Default
296
+ # action is to simply call self.needs_display which marks this view as
297
+ # needing display. This should always be called in a custom overridden
298
+ # method, or just use super().
299
+ #
300
+ # @param {CherryKit::View} view that is now the superview
301
+ #
302
+ def did_move_to_superview(superview)
303
+ self.needs_display = true
304
+ end
305
+
306
+ # Marks the receiver as needing displaying (rendering). Windows are in
307
+ # charge of calling renderers etc as needed, so this method simply
308
+ # registers itself with its window as needing display.
309
+ #
310
+ # @param {true|false} needs_displaying
311
+ #
312
+ def needs_display=(needs_displaying)
313
+ # puts "======= needs_display"
314
+ # we should only mark ourself as needing display if we have a window
315
+ if @window
316
+ RunLoop.current_run_loop.add_task self, :display
317
+ end
318
+ end
319
+
320
+ # Sets the window for the view. This method should never be directly called.
321
+ # Instead, use <tt><<</tt> to add the view to another view within the window
322
+ # hierarchy.
323
+ #
324
+ # @private
325
+ #
326
+ # @param {CherryKit::Window} window to set
327
+ #
328
+ def _window=(window)
329
+ # puts "setting window to #{window} for #{self}"
330
+ # if we already belong to the window, just return
331
+ return if @window == window
332
+ # callback
333
+ will_move_to_window window
334
+
335
+ @window = window
336
+
337
+ # mark ourselves as needing redisplay (before our subviews are)
338
+ self.needs_display = true
339
+
340
+ # inform each subview that we are all moving
341
+ @subviews.each do |subview|
342
+ subview._window = window
343
+ end
344
+
345
+ # second callback
346
+ did_move_to_window window
347
+ end
348
+
349
+ # Callback informing the receiver that it is about to join the new window
350
+ #
351
+ # @param {CherryKit::Window} window to join
352
+ #
353
+ def will_move_to_window(window)
354
+ # do nothing by default
355
+ end
356
+
357
+ # Inform the receiver that it has joined the new window
358
+ #
359
+ # @param {CherryKit::Window} window just joint
360
+ #
361
+ def did_move_to_window(window)
362
+ # do nothing by default
363
+ end
364
+
365
+ # ==========
366
+ # = Events =
367
+ # ==========
368
+
369
+ # IF the view should capture all touches (instead of allowing subviews to),
370
+ # then return true. Default is false. ScrollView, for example, returns true
371
+ #
372
+ def capture_touches?
373
+ false
374
+ end
375
+
376
+ # Can the view receive multiple touches: true or false
377
+ def multiple_touch_enabled?
378
+ @multiple_touch_enabled
379
+ end
380
+
381
+ # ===================
382
+ # = Handling events =
383
+ # ===================
384
+
385
+ # Handle mouse down. Default implementation simply calls super(), which
386
+ # passes the event back up to CK::Responders implementation which passes the
387
+ # event onto the next_responder
388
+ #
389
+ # @param {Browser::Event}
390
+ #
391
+ def mouse_down(event)
392
+ super event
393
+ end
394
+
395
+ # ================
396
+ # = Touch Events =
397
+ # ================
398
+ def touches_began(touches, event)
399
+ puts "#{self}#touches_began"
400
+ end
401
+
402
+ def touches_ended(touches, event)
403
+ puts "#{self}#touches_ended"
404
+ end
405
+
406
+ def touches_moved(touches, event)
407
+ puts "#{self}#touches_moved"
408
+ end
409
+ #
410
+ # def touched_cancelled(touches, event)
411
+ #
412
+ # end
413
+
414
+
415
+ # ==================================
416
+ # = Register views to DOM id names =
417
+ # ==================================
418
+ def self.[]=(id, view)
419
+ (@view_ids ||= {})[id] = view
420
+ end
421
+
422
+ def self.[](id)
423
+ @view_ids[id]
424
+ end
425
+ end
426
+ end