sproutcore 1.11.0.rc3 → 1.11.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 (98) hide show
  1. checksums.yaml +6 -14
  2. data/CHANGELOG +5 -0
  3. data/VERSION.yml +1 -1
  4. data/lib/frameworks/sproutcore/Buildfile +3 -2
  5. data/lib/frameworks/sproutcore/CHANGELOG.md +59 -10
  6. data/lib/frameworks/sproutcore/apps/showcase/resources/main_page.js +1 -0
  7. data/lib/frameworks/sproutcore/apps/showcase/resources/stylesheet.css +9 -4
  8. data/lib/frameworks/sproutcore/frameworks/core_foundation/panes/manipulation.js +1 -1
  9. data/lib/frameworks/sproutcore/frameworks/core_foundation/system/event.js +0 -10
  10. data/lib/frameworks/sproutcore/frameworks/core_foundation/system/locale.js +1 -1
  11. data/lib/frameworks/sproutcore/frameworks/core_foundation/system/root_responder.js +10 -45
  12. data/lib/frameworks/sproutcore/frameworks/core_foundation/system/selection_set.js +3 -3
  13. data/lib/frameworks/sproutcore/frameworks/core_foundation/system/touch.js +76 -0
  14. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/system/{touch.js → touch_test.js} +64 -0
  15. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/pane/append_remove.js +1 -1
  16. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/pane/design_mode_test.js +61 -24
  17. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/createChildViews.js +1 -2
  18. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/destroy.js +0 -3
  19. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/{layoutStyle.js → layout_style_test.js} +4 -4
  20. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/layout_test.js +602 -0
  21. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/viewDidResize.js +0 -23
  22. data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view.js +18 -17
  23. data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/animation.js +5 -5
  24. data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/design_mode.js +64 -24
  25. data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/layout.js +904 -871
  26. data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/layout_style.js +1 -3
  27. data/lib/frameworks/sproutcore/frameworks/core_foundation/views/view/statechart.js +40 -24
  28. data/lib/frameworks/sproutcore/frameworks/datastore/data_sources/fixtures.js +2 -2
  29. data/lib/frameworks/sproutcore/frameworks/datastore/models/record.js +5 -5
  30. data/lib/frameworks/sproutcore/frameworks/datastore/system/nested_store.js +14 -14
  31. data/lib/frameworks/sproutcore/frameworks/datastore/system/query.js +1 -1
  32. data/lib/frameworks/sproutcore/frameworks/datastore/system/record_array.js +2 -2
  33. data/lib/frameworks/sproutcore/frameworks/datastore/system/store.js +36 -33
  34. data/lib/frameworks/sproutcore/frameworks/datastore/tests/models/record/writeAttribute.js +1 -1
  35. data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/nested_store/autonomous_dataSourceCallbacks.js +6 -6
  36. data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/commitChangesFromNestedStore.js +1 -1
  37. data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/commitRecord.js +1 -1
  38. data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/dataSourceCallbacks.js +7 -7
  39. data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/destroyRecord.js +2 -2
  40. data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/recordDidChange.js +2 -2
  41. data/lib/frameworks/sproutcore/frameworks/datastore/tests/system/store/retrieveRecord.js +4 -4
  42. data/lib/frameworks/sproutcore/frameworks/datetime/frameworks/core/system/datetime.js +11 -11
  43. data/lib/frameworks/sproutcore/frameworks/designer/coders/object.js +1 -1
  44. data/lib/frameworks/sproutcore/frameworks/desktop/panes/menu.js +30 -1
  45. data/lib/frameworks/sproutcore/frameworks/desktop/panes/picker.js +12 -1
  46. data/lib/frameworks/sproutcore/frameworks/desktop/views/menu_scroll.js +5 -3
  47. data/lib/frameworks/sproutcore/frameworks/desktop/views/menu_scroller_view.js +0 -36
  48. data/lib/frameworks/sproutcore/frameworks/desktop/views/scroll_view.js +3 -3
  49. data/lib/frameworks/sproutcore/frameworks/desktop/views/segmented.js +1 -1
  50. data/lib/frameworks/sproutcore/frameworks/desktop/views/static_content.js +1 -1
  51. data/lib/frameworks/sproutcore/frameworks/foundation/gestures/pinch_gesture.js +286 -0
  52. data/lib/frameworks/sproutcore/frameworks/foundation/gestures/swipe_gesture.js +449 -0
  53. data/lib/frameworks/sproutcore/frameworks/foundation/gestures/tap_gesture.js +259 -0
  54. data/lib/frameworks/sproutcore/frameworks/foundation/mixins/gesturable.js +218 -30
  55. data/lib/frameworks/sproutcore/frameworks/foundation/system/gesture.js +259 -158
  56. data/lib/frameworks/sproutcore/frameworks/foundation/system/string.js +58 -50
  57. data/lib/frameworks/sproutcore/frameworks/foundation/system/utils/string_measurement.js +1 -1
  58. data/lib/frameworks/sproutcore/frameworks/foundation/tests/gestures/pinch_gesture_test.js +321 -0
  59. data/lib/frameworks/sproutcore/frameworks/foundation/tests/gestures/swipe_gesture_test.js +154 -0
  60. data/lib/frameworks/sproutcore/frameworks/foundation/tests/gestures/tap_gesture_test.js +55 -0
  61. data/lib/frameworks/sproutcore/frameworks/foundation/tests/mixins/gesturable_test.js +233 -0
  62. data/lib/frameworks/sproutcore/frameworks/foundation/tests/mixins/staticLayout.js +2 -2
  63. data/lib/frameworks/sproutcore/frameworks/foundation/tests/system/gesture_test.js +254 -0
  64. data/lib/frameworks/sproutcore/frameworks/foundation/views/container.js +1 -0
  65. data/lib/frameworks/sproutcore/frameworks/foundation/views/text_field.js +1 -1
  66. data/lib/frameworks/sproutcore/frameworks/legacy/object_keys_polyfill.js +51 -0
  67. data/lib/frameworks/sproutcore/frameworks/{core_foundation/system/req_anim_frame.js → legacy/request_animation_frame_polyfill.js} +10 -3
  68. data/lib/frameworks/sproutcore/frameworks/media/views/audio.js +19 -25
  69. data/lib/frameworks/sproutcore/frameworks/media/views/controls.js +7 -7
  70. data/lib/frameworks/sproutcore/frameworks/media/views/mini_controls.js +3 -3
  71. data/lib/frameworks/sproutcore/frameworks/media/views/simple_controls.js +9 -9
  72. data/lib/frameworks/sproutcore/frameworks/runtime/core.js +2 -2
  73. data/lib/frameworks/sproutcore/frameworks/runtime/debug/test_suites/array/insertAt.js +2 -2
  74. data/lib/frameworks/sproutcore/frameworks/runtime/debug/test_suites/array/removeAt.js +1 -1
  75. data/lib/frameworks/sproutcore/frameworks/runtime/ext/array.js +1 -1
  76. data/lib/frameworks/sproutcore/frameworks/runtime/mixins/array.js +2 -2
  77. data/lib/frameworks/sproutcore/frameworks/runtime/mixins/freezable.js +2 -2
  78. data/lib/frameworks/sproutcore/frameworks/runtime/mixins/observable.js +66 -5
  79. data/lib/frameworks/sproutcore/frameworks/runtime/mixins/tree.js +44 -0
  80. data/lib/frameworks/sproutcore/frameworks/runtime/private/observer_queue.js +4 -1
  81. data/lib/frameworks/sproutcore/frameworks/runtime/system/binding.js +0 -25
  82. data/lib/frameworks/sproutcore/frameworks/runtime/system/enumerator.js +1 -1
  83. data/lib/frameworks/sproutcore/frameworks/runtime/system/error.js +67 -15
  84. data/lib/frameworks/sproutcore/frameworks/runtime/system/index_set.js +6 -11
  85. data/lib/frameworks/sproutcore/frameworks/runtime/system/set.js +6 -6
  86. data/lib/frameworks/sproutcore/frameworks/runtime/system/string.js +1 -1
  87. data/lib/frameworks/sproutcore/frameworks/runtime/tests/mixins/observable/{observable.js → observable_test.js} +110 -16
  88. data/lib/frameworks/sproutcore/frameworks/runtime/tests/system/error.js +21 -0
  89. data/lib/frameworks/sproutcore/frameworks/statechart/system/statechart.js +2 -2
  90. data/lib/frameworks/sproutcore/frameworks/template_view/ext/handlebars.js +1 -1
  91. data/lib/frameworks/sproutcore/frameworks/testing/system/plan.js +1 -1
  92. data/lib/sproutcore/render_engines/haml.rb +1 -1
  93. metadata +610 -604
  94. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/layout.js +0 -210
  95. data/lib/frameworks/sproutcore/frameworks/core_foundation/tests/views/view/layoutDidChange.js +0 -275
  96. data/lib/frameworks/sproutcore/frameworks/foundation/gestures/pinch.js +0 -119
  97. data/lib/frameworks/sproutcore/frameworks/foundation/gestures/swipe.js +0 -234
  98. data/lib/frameworks/sproutcore/frameworks/foundation/gestures/tap.js +0 -157
@@ -1,210 +0,0 @@
1
- // ==========================================================================
2
- // Project: SproutCore - JavaScript Application Framework
3
- // Copyright: ©2006-2011 Strobe Inc. and contributors.
4
- // ©2008-2011 Apple Inc. All rights reserved.
5
- // License: Licensed under MIT license (see license.js)
6
- // ==========================================================================
7
-
8
- /*global module, test, equals, ok, same */
9
-
10
- var view;
11
-
12
- /** Test isFixedLayout via isFixedSize and isFixedPosition properties. */
13
- module("SC.View.prototype.isFixedLayout", {
14
-
15
- setup: function () {
16
- // Create a basic view.
17
- view = SC.View.create({});
18
- },
19
-
20
- teardown: function () {
21
- // Clean up.
22
- view.destroy();
23
- view = null;
24
- }
25
-
26
- });
27
-
28
- test("Test isFixedHeight, isFixedWidth and isFixedSize for various layouts.", function () {
29
- ok(!view.get('isFixedSize'), "The default layout doesn't correspond to a fixed size.");
30
-
31
- SC.run(function () { view.set('layout', { width: 100 }); });
32
- ok(view.get('isFixedWidth'), "A width alone gives a fixed width.");
33
- ok(!view.get('isFixedHeight'), "A width alone doesn't give a fixed height.");
34
- ok(!view.get('isFixedSize'), "A width alone doesn't correspond to a fixed size.");
35
-
36
- SC.run(function () { view.set('layout', { height: 100 }); });
37
- ok(!view.get('isFixedWidth'), "A height alone doesn't give a fixed width.");
38
- ok(view.get('isFixedHeight'), "A height alone gives a fixed height.");
39
- ok(!view.get('isFixedSize'), "A height alone doesn't correspond to a fixed size.");
40
-
41
- SC.run(function () { view.set('layout', { width: 100, height: 100 }); });
42
- ok(view.get('isFixedWidth'), "A width & height give a fixed width.");
43
- ok(view.get('isFixedHeight'), "A width & height give a fixed height.");
44
- ok(view.get('isFixedSize'), "A width & height corresponds to a fixed size.");
45
- });
46
-
47
- test("Test isFixedPosition for various layouts.", function () {
48
- ok(view.get('isFixedPosition'), "The default layout corresponds to a fixed position.");
49
-
50
- SC.run(function () { view.set('layout', { left: 0 }); });
51
- ok(view.get('isFixedPosition'), "A left: 0 (implied top, bottom, right) corresponds to a fixed position.");
52
-
53
- SC.run(function () { view.set('layout', { top: 0 }); });
54
- ok(view.get('isFixedPosition'), "A top: 0 (implied left, bottom, right) corresponds to a fixed position.");
55
-
56
- SC.run(function () { view.set('layout', { left: 0, top: 0 }); });
57
- ok(view.get('isFixedPosition'), "A left: 0, top: 0 corresponds to a fixed position.");
58
-
59
- SC.run(function () { view.set('layout', { left: 50 }); });
60
- ok(view.get('isFixedPosition'), "A left: 50 corresponds to a fixed position.");
61
-
62
- SC.run(function () { view.set('layout', { top: 50 }); });
63
- ok(view.get('isFixedPosition'), "A top: 50 corresponds to a fixed position.");
64
-
65
- SC.run(function () { view.set('layout', { left: 50, top: 50 }); });
66
- ok(view.get('isFixedPosition'), "A left: 50, top: 50 corresponds to a fixed position.");
67
-
68
- SC.run(function () { view.set('layout', { right: 0 }); });
69
- ok(view.get('isFixedPosition'), "A right: 0 (implied left) corresponds to a fixed position.");
70
-
71
- SC.run(function () { view.set('layout', { bottom: 0 }); });
72
- ok(view.get('isFixedPosition'), "A bottom: 0 (implied top) corresponds to a fixed position.");
73
-
74
- SC.run(function () { view.set('layout', { right: 50 }); });
75
- ok(view.get('isFixedPosition'), "A right: 50 (implied left) corresponds to a fixed position.");
76
-
77
- SC.run(function () { view.set('layout', { bottom: 50 }); });
78
- ok(view.get('isFixedPosition'), "A bottom: 50 (implied top) corresponds to a fixed position.");
79
-
80
- SC.run(function () { view.set('layout', { width: 100 }); });
81
- ok(view.get('isFixedPosition'), "A width: 100 (implied left) corresponds to a fixed position.");
82
-
83
- SC.run(function () { view.set('layout', { height: 100 }); });
84
- ok(view.get('isFixedPosition'), "A height: 100 (implied top) corresponds to a fixed position.");
85
-
86
- SC.run(function () { view.set('layout', { right: 0, width: 100 }); });
87
- ok(!view.get('isFixedPosition'), "A right: 0, width: 100 (overridden left) doesn't correspond to a fixed position.");
88
-
89
- SC.run(function () { view.set('layout', { bottom: 0, height: 100 }); });
90
- ok(!view.get('isFixedPosition'), "A bottom: 0, height: 100 (overridden top) doesn't correspond to a fixed position.");
91
-
92
- SC.run(function () { view.set('layout', { centerX: 0, width: 100 }); });
93
- ok(!view.get('isFixedPosition'), "A centerX: 0, width: 100 (overridden left) doesn't correspond to a fixed position.");
94
-
95
- SC.run(function () { view.set('layout', { centerY: 0, height: 100 }); });
96
- ok(!view.get('isFixedPosition'), "A centerY: 0, height: 100 (overridden top) doesn't correspond to a fixed position.");
97
-
98
- SC.run(function () { view.set('layout', { left: 0.2 }); });
99
- ok(!view.get('isFixedPosition'), "A left: 0.2 (percentage left) doesn't correspond to a fixed position.");
100
-
101
- SC.run(function () { view.set('layout', { top: 0.2 }); });
102
- ok(!view.get('isFixedPosition'), "A top: 0.2 (percentage top) doesn't correspond to a fixed position.");
103
-
104
- SC.run(function () { view.set('layout', { left: SC.LAYOUT_AUTO }); });
105
- ok(!view.get('isFixedPosition'), "A left: SC.LAYOUT_AUTO (auto left) doesn't correspond to a fixed position.");
106
-
107
- SC.run(function () { view.set('layout', { top: SC.LAYOUT_AUTO }); });
108
- ok(!view.get('isFixedPosition'), "A top: SC.LAYOUT_AUTO (auto top) doesn't correspond to a fixed position.");
109
- });
110
-
111
- test("Test explicitLayout for various valid layouts.", function () {
112
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 0 }, "No layout is implied as");
113
-
114
- SC.run(function () { view.set('layout', { left: 5 }); });
115
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 5 }, "{ left: 5 } is implied as");
116
-
117
- SC.run(function () { view.set('layout', { top: 5 }); });
118
- same(view.get('explicitLayout'), { top: 5, right: 0, bottom: 0, left: 0 }, "{ top: 5 } is implied as");
119
-
120
- SC.run(function () { view.set('layout', { bottom: 5 }); });
121
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 5, left: 0 }, "{ bottom: 5 } is implied as");
122
-
123
- SC.run(function () { view.set('layout', { right: 5 }); });
124
- same(view.get('explicitLayout'), { top: 0, right: 5, bottom: 0, left: 0 }, "{ right: 5 } is implied as");
125
-
126
- SC.run(function () { view.set('layout', { bottom: 5, left: 5 }); });
127
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 5, left: 5 }, "{ bottom: 5, left: 5 } is implied as");
128
-
129
- SC.run(function () { view.set('layout', { right: 5, bottom: 5, left: 5 }); });
130
- same(view.get('explicitLayout'), { top: 0, right: 5, bottom: 5, left: 5 }, "{ right: 5, bottom: 5, left: 5 } is implied as");
131
-
132
- SC.run(function () { view.set('layout', { top: 5, right: 5, bottom: 5, left: 5 }); });
133
- same(view.get('explicitLayout'), { top: 5, right: 5, bottom: 5, left: 5 }, "{ top: 5, right: 5, bottom: 5, left: 5 } is implied as");
134
-
135
- SC.run(function () { view.set('layout', { top: 5, right: 5, bottom: 5 }); });
136
- same(view.get('explicitLayout'), { top: 5, right: 5, bottom: 5, left: 0 }, "{ top: 5, right: 5, bottom: 5 } is implied as");
137
-
138
- SC.run(function () { view.set('layout', { top: 5, right: 5 }); });
139
- same(view.get('explicitLayout'), { top: 5, right: 5, bottom: 0, left: 0 }, "{ top: 5, right: 5 } is implied as");
140
-
141
- SC.run(function () { view.set('layout', { width: 100 }); });
142
- same(view.get('explicitLayout'), { top: 0, width: 100, bottom: 0, left: 0 }, "{ width: 100 } is implied as");
143
-
144
- SC.run(function () { view.set('layout', { width: 100, right: 5 }); });
145
- same(view.get('explicitLayout'), { top: 0, width: 100, bottom: 0, right: 5 }, "{ width: 100, right: 5 } is implied as");
146
-
147
- SC.run(function () { view.set('layout', { height: 100 }); });
148
- same(view.get('explicitLayout'), { top: 0, height: 100, right: 0, left: 0 }, "{ height: 100 } is implied as");
149
-
150
- SC.run(function () { view.set('layout', { height: 100, bottom: 5 }); });
151
- same(view.get('explicitLayout'), { right: 0, height: 100, bottom: 5, left: 0 }, "{ height: 100, bottom: 5 } is implied as");
152
-
153
- // MIN/MAX
154
-
155
- SC.run(function () { view.set('layout', { minWidth: 100, maxHeight: 100 }); });
156
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 0, minWidth: 100, maxHeight: 100 }, "{ minWidth: 100, maxHeight: 100 } is implied as");
157
-
158
- SC.run(function () { view.set('layout', { maxWidth: 100, minHeight: 100 }); });
159
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 0, maxWidth: 100, minHeight: 100 }, "{ maxWidth: 100, minHeight: 100 } is implied as");
160
-
161
- // CENTERS
162
-
163
- SC.run(function () { view.set('layout', { centerX: 0, width: 100 }); });
164
- same(view.get('explicitLayout'), { top: 0, centerX: 0, width: 100, bottom: 0 }, "{ centerX: 0, width: 100 } is implied as");
165
-
166
- SC.run(function () { view.set('layout', { centerY: 0, height: 100 }); });
167
- same(view.get('explicitLayout'), { right: 0, centerY: 0, height: 100, left: 0 }, "{ centerY: 0, height: 100 } is implied as");
168
-
169
- // OPACITY
170
-
171
- SC.run(function () { view.set('layout', { opacity: 0.25 }); });
172
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 0, opacity: 0.25 }, "{ opacity: 0.25 } is implied as");
173
-
174
- // TRANSFORMS
175
-
176
- SC.run(function () { view.set('layout', { scale: 0.25 }); });
177
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 0, scale: 0.25 }, "{ scale: 0.25 } is implied as");
178
-
179
- SC.run(function () { view.set('layout', { transformOriginX: 0, transformOriginY: 1 }); });
180
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 0, transformOriginX: 0, transformOriginY: 1 }, "{ transformOriginX: 0, transformOriginY: 1 } is implied as");
181
-
182
- // BORDERS
183
-
184
- SC.run(function () { view.set('layout', { border: 1 }); });
185
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 0, borderTop: 1, borderRight: 1, borderBottom: 1, borderLeft: 1 }, "{ border: 1 } is implied as");
186
-
187
- SC.run(function () { view.set('layout', { border: 1, borderTop: 2 }); });
188
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 0, borderTop: 2, borderRight: 1, borderBottom: 1, borderLeft: 1 }, "{ border: 1, borderTop: 2 } is implied as");
189
-
190
- SC.run(function () { view.set('layout', { borderBottom: 1, borderTop: 2 }); });
191
- same(view.get('explicitLayout'), { top: 0, right: 0, bottom: 0, left: 0, borderTop: 2, borderBottom: 1 }, "{ borderBottom: 1, borderTop: 2 } is implied as");
192
- });
193
-
194
- test("Test explicitLayout for various invalid layouts.", function () {
195
- // Centered without a size dimension.
196
- SC.run(function () { view.set('layout', { centerX: 0 }); });
197
- same(view.get('explicitLayout'), { top: 0, centerX: 0, bottom: 0 }, "{ centerX: 0 } is implied as");
198
-
199
- // Centered without a size dimension.
200
- SC.run(function () { view.set('layout', { centerY: 0 }); });
201
- same(view.get('explicitLayout'), { left: 0, centerY: 0, right: 0 }, "{ centerY: 0 } is implied as");
202
-
203
- // Left, right & width
204
- SC.run(function () { view.set('layout', { left: 5, width: 100, right: 5 }); });
205
- same(view.get('explicitLayout'), { top: 0, left: 5, bottom: 0, width: 100 }, "{ left: 5, width: 100, right: 5 } is implied as");
206
-
207
- // Top, bottom & height
208
- SC.run(function () { view.set('layout', { top: 5, height: 100, bottom: 5 }); });
209
- same(view.get('explicitLayout'), { left: 0, top: 5, right: 0, height: 100 }, "{ top: 5, height: 100, bottom: 5 } is implied as");
210
- });
@@ -1,275 +0,0 @@
1
- // ==========================================================================
2
- // Project: SproutCore - JavaScript Application Framework
3
- // Copyright: ©2006-2011 Apple Inc. and contributors.
4
- // License: Licensed under MIT license (see license.js)
5
- // ==========================================================================
6
-
7
- /*global module, test, equals, ok */
8
-
9
- module("SC.View.prototype.layoutDidChange");
10
-
11
- test("notifies layoutStyle & frame change", function () {
12
-
13
- var view = SC.View.create();
14
- var layoutStyleCallCount = 0, frameCallCount = 0;
15
-
16
- view.addObserver('layoutStyle', function () { layoutStyleCallCount++; });
17
- view.addObserver('frame', function () { frameCallCount++; });
18
-
19
- SC.run(function () {
20
- // Manually indicate a layout change.
21
- view.layoutDidChange();
22
- });
23
-
24
- equals(frameCallCount, 1, 'should trigger observer for frame');
25
- equals(layoutStyleCallCount, 0, 'should not trigger observers for layoutStyle');
26
-
27
- // Attach to the document.
28
- var parent = SC.Pane.create();
29
- parent.append();
30
- parent.appendChild(view);
31
-
32
- equals(frameCallCount, 2, 'should trigger observers for frame when adopted');
33
- equals(layoutStyleCallCount, 0, 'should still not trigger observers for layoutStyle');
34
-
35
- SC.run(function () {
36
- view.adjust('top', 20);
37
- });
38
-
39
- equals(frameCallCount, 3, 'should trigger observers for frame when adjusted');
40
- equals(layoutStyleCallCount, 1, 'should trigger observers for layoutStyle when adjusted');
41
-
42
- // Clean up.
43
- view.destroy();
44
- parent.destroy();
45
- });
46
-
47
- test("invokes layoutDidChangeFor() on layoutView each time it is called", function () {
48
-
49
- var callCount = 0;
50
- var layoutView = SC.View.create({
51
- layoutDidChangeFor: function (changedView) {
52
- equals(this.get('childViewsNeedLayout'), YES, 'should set childViewsNeedLayout to YES before calling layoutDidChangeFor()');
53
-
54
- equals(view, changedView, 'should pass view');
55
- callCount++;
56
-
57
- // Original
58
- var set = this._needLayoutViews;
59
- if (!set) set = this._needLayoutViews = SC.CoreSet.create();
60
- set.add(changedView);
61
- }
62
- });
63
-
64
- var view = SC.View.create({ layoutView: layoutView });
65
-
66
- SC.run(function () {
67
- view.layoutDidChange();
68
- view.layoutDidChange();
69
- view.layoutDidChange();
70
- });
71
-
72
- equals(callCount, 3, 'should call layoutView.layoutDidChangeFor each time');
73
-
74
- // Clean up.
75
- layoutView.destroy();
76
- view.destroy();
77
- });
78
-
79
- test("invokes layoutChildViewsIfNeeded() on layoutView once per runloop", function () {
80
-
81
- var callCount = 0;
82
- var layoutView = SC.View.create({
83
- layoutChildViewsIfNeeded: function () {
84
- callCount++;
85
- }
86
- });
87
-
88
- var view = SC.View.create({ layoutView: layoutView });
89
-
90
- SC.run(function () {
91
- view.layoutDidChange();
92
- view.layoutDidChange();
93
- view.layoutDidChange();
94
- });
95
-
96
- equals(callCount, 1, 'should call layoutView.layoutChildViewsIfNeeded one time');
97
-
98
- // Clean up.
99
- layoutView.destroy();
100
- view.destroy();
101
- });
102
-
103
-
104
- test("should not invoke layoutChildViewsIfNeeded() if layoutDidChangeFor() sets childViewsNeedLayout to NO each time", function () {
105
-
106
- var callCount = 0;
107
- var layoutView = SC.View.create({
108
- layoutDidChangeFor: function () {
109
- this.set('childViewsNeedLayout', NO);
110
- },
111
-
112
- layoutChildViewsIfNeeded: function () {
113
- callCount++;
114
- }
115
- });
116
-
117
- var view = SC.View.create({ layoutView: layoutView });
118
-
119
- SC.run(function () {
120
- view.layoutDidChange();
121
- view.layoutDidChange();
122
- view.layoutDidChange();
123
- });
124
-
125
- equals(callCount, 0, 'should not call layoutView.layoutChildViewsIfNeeded');
126
-
127
- // Clean up.
128
- layoutView.destroy();
129
- view.destroy();
130
- });
131
-
132
- test('returns receiver', function () {
133
- var view = SC.View.create();
134
-
135
- SC.run(function () {
136
- equals(view.layoutDidChange(), view, 'should return receiver');
137
- });
138
-
139
- // Clean up.
140
- view.destroy();
141
- });
142
-
143
- test("is invoked whenever layout property changes", function () {
144
-
145
- var callCount = 0;
146
- var layoutView = SC.View.create({
147
- layoutDidChangeFor: function (changedView) {
148
- callCount++;
149
-
150
- // Original
151
- var set = this._needLayoutViews;
152
- if (!set) set = this._needLayoutViews = SC.CoreSet.create();
153
- set.add(changedView);
154
- }
155
- });
156
-
157
- var view = SC.View.create({ layoutView: layoutView });
158
-
159
- SC.run(function () {
160
- view.set('layout', { top: 0, left: 10 });
161
- });
162
- equals(callCount, 1, 'should call layoutDidChangeFor when setting layout of child view');
163
-
164
- // Clean up.
165
- layoutView.destroy();
166
- view.destroy();
167
- });
168
-
169
- test("is invoked on parentView if no layoutView whenever layout property changes", function () {
170
-
171
- var callCount = 0;
172
- var parentView = SC.View.create({
173
- layoutDidChangeFor: function (changedView) {
174
- callCount++;
175
-
176
- // Original
177
- var set = this._needLayoutViews;
178
- if (!set) set = this._needLayoutViews = SC.CoreSet.create();
179
- set.add(changedView);
180
- }
181
- });
182
-
183
- var view = SC.View.create({});
184
- view.set('parentView', parentView);
185
-
186
- SC.run(function () {
187
- view.set('layout', { top: 0, left: 10 });
188
- });
189
- equals(callCount, 1, 'should call layoutDidChangeFor when setting layout of child view');
190
-
191
- // Clean up.
192
- parentView.destroy();
193
- view.destroy();
194
- });
195
-
196
- test("proxies rotate to rotateZ when 3D transforms are supported", function () {
197
- // Retain CSS support information so we can return to it.
198
- var actualSupport = SC.platform.get('supportsCSS3DTransforms'),
199
- view;
200
-
201
- // YES SUPPORT
202
- SC.platform.set('supportsCSS3DTransforms', YES);
203
- view = SC.View.create();
204
- SC.run(function () {
205
- view.set('layout', { rotate: 45 });
206
- });
207
- equals(view.get('layout').rotate, undefined, "should clear rotate");
208
- equals(view.get('layout').rotateZ, 45, "should set rotateZ");
209
- // Clean up.
210
- view.destroy();
211
-
212
- // NO SUPPORT
213
- SC.platform.set('supportsCSS3DTransforms', NO);
214
- view = SC.View.create();
215
- SC.run(function () {
216
- view.set('layout', { rotate: 45 });
217
- });
218
- equals(view.get('layout').rotate, 45, "should retain rotate");
219
- equals(view.get('layout').rotateZ, undefined, "should not set rotateZ");
220
- // Clean up.
221
- view.destroy();
222
-
223
- // Clean up bigger picture.
224
- SC.platform.set('supportsCSS3DTransforms', actualSupport);
225
- });
226
-
227
- test("rotateZ and rotate together", function () {
228
- var view = SC.View.create({});
229
-
230
- SC.run(function () {
231
- view.set('layout', { rotate: 45, rotateZ: 90 });
232
- });
233
-
234
- equals(view.get('layout').rotate, 45, "if both rotate and rotateZ values are present, both should be retained; rotate is");
235
-
236
- equals(view.get('layout').rotateZ, 90, "if both rotate and rotateZ values are present, both should be retained; rotateZ is");
237
-
238
- // Clean up.
239
- view.destroy();
240
- });
241
-
242
- // The default implementation for viewDidResize calls internal layout-related
243
- // methods on child views. This test confirms that child views that do not
244
- // support layout do not cause this process to explode.
245
- test("Calling viewDidResize on a view notifies its child views", function () {
246
- var regularViewCounter = 0, coreViewCounter = 0;
247
-
248
- var view = SC.View.create({
249
- childViews: ['regular', 'core'],
250
-
251
- regular: SC.View.extend({
252
- viewDidResize: function () {
253
- regularViewCounter++;
254
- // Make sure we call the default implementation to
255
- // ensure potential blow-uppy behavior is invoked
256
- sc_super();
257
- }
258
- }),
259
-
260
- core: SC.CoreView.extend({
261
- viewDidResize: function () {
262
- coreViewCounter++;
263
- sc_super();
264
- }
265
- })
266
- });
267
-
268
- view.viewDidResize();
269
-
270
- equals(regularViewCounter, 1, "regular view's viewDidResize gets called");
271
- equals(coreViewCounter, 1, "core view's viewDidResize gets called");
272
-
273
- // Clean up.
274
- view.destroy();
275
- });