OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview A collection of utility methods for UberPage and its contained | 6 * @fileoverview A collection of utility methods for UberPage and its contained |
7 * pages. | 7 * pages. |
8 */ | 8 */ |
9 | 9 |
10 cr.define('uber', function() { | 10 cr.define('uber', function() { |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 window.addEventListener('message', handleWindowMessage); | 33 window.addEventListener('message', handleWindowMessage); |
34 } | 34 } |
35 | 35 |
36 /** | 36 /** |
37 * Handles scroll events on the document. This adjusts the position of all | 37 * Handles scroll events on the document. This adjusts the position of all |
38 * headers and updates the parent frame when the page is scrolled. | 38 * headers and updates the parent frame when the page is scrolled. |
39 * @private | 39 * @private |
40 */ | 40 */ |
41 function handleScroll() { | 41 function handleScroll() { |
42 var offset = document.documentElement.scrollLeft * -1; | 42 var scrollLeft = scrollLeftForDocument(document); |
| 43 var offset = scrollLeft * -1; |
43 for (var i = 0; i < headerElements.length; i++) { | 44 for (var i = 0; i < headerElements.length; i++) { |
44 // As a workaround for http://crbug.com/231830, set the transform to | 45 // As a workaround for http://crbug.com/231830, set the transform to |
45 // 'none' rather than 0px. | 46 // 'none' rather than 0px. |
46 headerElements[i].style.webkitTransform = offset ? | 47 headerElements[i].style.webkitTransform = offset ? |
47 'translateX(' + offset + 'px)' : 'none'; | 48 'translateX(' + offset + 'px)' : 'none'; |
48 } | 49 } |
49 | 50 |
50 invokeMethodOnParent('adjustToScroll', document.documentElement.scrollLeft); | 51 invokeMethodOnParent('adjustToScroll', scrollLeft); |
51 }; | 52 }; |
52 | 53 |
53 /** | 54 /** |
54 * Handles 'message' events on window. | 55 * Handles 'message' events on window. |
55 * @param {Event} e The message event. | 56 * @param {Event} e The message event. |
56 */ | 57 */ |
57 function handleWindowMessage(e) { | 58 function handleWindowMessage(e) { |
58 if (e.data.method === 'frameSelected') | 59 if (e.data.method === 'frameSelected') |
59 handleFrameSelected(); | 60 handleFrameSelected(); |
60 else if (e.data.method === 'mouseWheel') | 61 else if (e.data.method === 'mouseWheel') |
61 handleMouseWheel(e.data.params); | 62 handleMouseWheel(e.data.params); |
62 } | 63 } |
63 | 64 |
64 /** | 65 /** |
65 * This is called when a user selects this frame via the navigation bar | 66 * This is called when a user selects this frame via the navigation bar |
66 * frame (and is triggered via postMessage() from the uber page). | 67 * frame (and is triggered via postMessage() from the uber page). |
67 * @private | 68 * @private |
68 */ | 69 */ |
69 function handleFrameSelected() { | 70 function handleFrameSelected() { |
70 document.documentElement.scrollLeft = 0; | 71 setScrollTopForDocument(document, 0); |
71 } | 72 } |
72 | 73 |
73 /** | 74 /** |
74 * Called when a user mouse wheels (or trackpad scrolls) over the nav frame. | 75 * Called when a user mouse wheels (or trackpad scrolls) over the nav frame. |
75 * The wheel event is forwarded here and we scroll the body. | 76 * The wheel event is forwarded here and we scroll the body. |
76 * There's no way to figure out the actual scroll amount for a given delta. | 77 * There's no way to figure out the actual scroll amount for a given delta. |
77 * It differs for every platform and even initWebKitWheelEvent takes a | 78 * It differs for every platform and even initWebKitWheelEvent takes a |
78 * pixel amount instead of a wheel delta. So we just choose something | 79 * pixel amount instead of a wheel delta. So we just choose something |
79 * reasonable and hope no one notices the difference. | 80 * reasonable and hope no one notices the difference. |
80 * @param {Object} params A structure that holds wheel deltas in X and Y. | 81 * @param {Object} params A structure that holds wheel deltas in X and Y. |
(...skipping 29 matching lines...) Expand all Loading... |
110 var data = {method: method, params: opt_params}; | 111 var data = {method: method, params: opt_params}; |
111 targetWindow.postMessage(data, opt_url ? opt_url : '*'); | 112 targetWindow.postMessage(data, opt_url ? opt_url : '*'); |
112 } | 113 } |
113 | 114 |
114 return { | 115 return { |
115 invokeMethodOnParent: invokeMethodOnParent, | 116 invokeMethodOnParent: invokeMethodOnParent, |
116 invokeMethodOnWindow: invokeMethodOnWindow, | 117 invokeMethodOnWindow: invokeMethodOnWindow, |
117 onContentFrameLoaded: onContentFrameLoaded, | 118 onContentFrameLoaded: onContentFrameLoaded, |
118 }; | 119 }; |
119 }); | 120 }); |
OLD | NEW |