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 sc_require("panes/pane"); 8 SC.Pane.reopen( 9 /** @scope SC.Pane.prototype */ { 10 11 /** 12 Last known window size. 13 14 @type Rect 15 */ 16 currentWindowSize: null, 17 18 /** 19 The parent dimensions are always the last known window size. 20 21 @returns {Rect} current window size 22 */ 23 computeParentDimensions: function (frame) { 24 if (this.get('designer') && SC.suppressMain) { return sc_super(); } 25 26 var wDim = {x: 0, y: 0, width: 1000, height: 1000}, 27 layout = this.get('layout'); 28 29 // There used to be a whole bunch of code right here to calculate 30 // based first on a stored window size, then on root responder, then 31 // from document... but a) it is incorrect because we don't care about 32 // the window size, but instead, the clientWidth/Height of the body, and 33 // b) the performance benefits are not worth complicating the code that much. 34 if (document && document.body) { 35 wDim.width = document.body.clientWidth; 36 wDim.height = document.body.clientHeight; 37 38 // IE7 is the only browser which reports clientHeight _including_ scrollbar. 39 if (SC.browser.name === SC.BROWSER.ie && 40 SC.browser.compare(SC.browser.version, "7") === 0) { 41 42 var scrollbarSize = SC.platform.get('scrollbarSize'); 43 if (document.body.scrollWidth > wDim.width) { 44 wDim.width -= scrollbarSize; 45 } 46 if (document.body.scrollHeight > wDim.height) { 47 wDim.height -= scrollbarSize; 48 } 49 } 50 } 51 52 // If there is a minWidth or minHeight set on the pane, take that 53 // into account when calculating dimensions. 54 55 if (layout.minHeight || layout.minWidth) { 56 if (layout.minHeight) { 57 wDim.height = Math.max(wDim.height, layout.minHeight); 58 } 59 if (layout.minWidth) { 60 wDim.width = Math.max(wDim.width, layout.minWidth); 61 } 62 } 63 return wDim; 64 }, 65 66 /** 67 Invoked by the root responder whenever the window resizes. This should 68 simply begin the process of notifying children that the view size has 69 changed, if needed. 70 71 @param {Rect} oldSize the old window size 72 @param {Rect} newSize the new window size 73 @returns {SC.Pane} receiver 74 */ 75 windowSizeDidChange: function (oldSize, newSize) { 76 this.set('currentWindowSize', newSize); 77 this.setBodyOverflowIfNeeded(); 78 this.parentViewDidResize(newSize); // start notifications. 79 return this; 80 }, 81 82 /** 83 Changes the body overflow according to whether minWidth or minHeight 84 are present in the layout hash. If there are no minimums, nothing 85 is done unless true is passed as the first argument. If so, then 86 overflow:hidden; will be used. 87 88 It's possible to call this manually and pass YES to remove overflow 89 if setting layout to a hash without minWidth and minHeight, but it's 90 probably not a good idea to do so unless you're doing it from the main 91 pane. There's only one body tag, after all, and if this is called from 92 multiple different panes, the panes could fight over whether it gets 93 an overflow if care isn't taken! 94 95 @param {Boolean} [force=false] force a style to be set even if there are no minimums. 96 @returns {void} 97 */ 98 setBodyOverflowIfNeeded: function (force) { 99 //Code to get rid of Lion rubberbanding. 100 var layout = this.get('layout'), 101 size = this.get('currentWindowSize'); 102 103 if (!layout || !size || !size.width || !size.height) return; 104 105 var minW = layout.minWidth, 106 minH = layout.minHeight; 107 108 if (force === true || minW || minH) { 109 if ((minH && size.height < minH) || (minW && size.width < minW)) { 110 SC.bodyOverflowArbitrator.requestVisible(this); 111 } else { 112 SC.bodyOverflowArbitrator.requestHidden(this); 113 } 114 } 115 }, 116 117 /** 118 Stops controlling the body overflow according to the needs of this pane. 119 120 @returns {void} 121 */ 122 unsetBodyOverflowIfNeeded: function () { 123 SC.bodyOverflowArbitrator.withdrawRequest(this); 124 } 125 126 }); 127