| OLD | NEW |
| 1 "use strict"; | 1 "use strict"; |
| 2 /* | 2 /* |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 var y = Math.max(rect1.y, rect2.y); | 82 var y = Math.max(rect1.y, rect2.y); |
| 83 var maxY = Math.min(rect1.maxY, rect2.maxY); | 83 var maxY = Math.min(rect1.maxY, rect2.maxY); |
| 84 var width = maxX - x; | 84 var width = maxX - x; |
| 85 var height = maxY - y; | 85 var height = maxY - y; |
| 86 if (width < 0 || height < 0) | 86 if (width < 0 || height < 0) |
| 87 return null; | 87 return null; |
| 88 return new Rectangle(x, y, width, height); | 88 return new Rectangle(x, y, width, height); |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * @param {!number} width | 92 * @param {!number} width in CSS pixel |
| 93 * @param {!number} height | 93 * @param {!number} height in CSS pixel |
| 94 */ | 94 */ |
| 95 function resizeWindow(width, height) { | 95 function resizeWindow(width, height) { |
| 96 setWindowRect(adjustWindowRect(width, height, width, height)); | 96 var zoom = global.params.zoomFactor ? global.params.zoomFactor : 1; |
| 97 setWindowRect(adjustWindowRect(width * zoom, height * zoom, width * zoom, he
ight * zoom)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 /** | 100 /** |
| 100 * @param {!number} width | 101 * @param {!number} width in physical pixel |
| 101 * @param {!number} height | 102 * @param {!number} height in physical pixel |
| 102 * @param {?number} minWidth | 103 * @param {?number} minWidth in physical pixel |
| 103 * @param {?number} minHeight | 104 * @param {?number} minHeight in physical pixel |
| 104 * @return {!Rectangle} | 105 * @return {!Rectangle} Adjusted rectangle with physical pixels |
| 105 */ | 106 */ |
| 106 function adjustWindowRect(width, height, minWidth, minHeight) { | 107 function adjustWindowRect(width, height, minWidth, minHeight) { |
| 107 if (typeof minWidth !== "number") | 108 if (typeof minWidth !== "number") |
| 108 minWidth = 0; | 109 minWidth = 0; |
| 109 if (typeof minHeight !== "number") | 110 if (typeof minHeight !== "number") |
| 110 minHeight = 0; | 111 minHeight = 0; |
| 111 | 112 |
| 112 var windowRect = new Rectangle(0, 0, width, height); | 113 var windowRect = new Rectangle(0, 0, width, height); |
| 113 | 114 |
| 114 if (!global.params.anchorRectInScreen) | 115 if (!global.params.anchorRectInScreen) |
| 115 return windowRect; | 116 return windowRect; |
| 116 | 117 |
| 117 var anchorRect = new Rectangle(global.params.anchorRectInScreen); | 118 var anchorRect = new Rectangle(global.params.anchorRectInScreen); |
| 118 var availRect = new Rectangle(window.screen.availLeft, window.screen.availTo
p, window.screen.availWidth, window.screen.availHeight); | 119 var availRect = new Rectangle(window.screen.availLeft, window.screen.availTo
p, window.screen.availWidth, window.screen.availHeight); |
| 119 | 120 |
| 120 _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeight); | 121 _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeight); |
| 121 _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWidth); | 122 _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWidth); |
| 122 | 123 |
| 123 return windowRect; | 124 return windowRect; |
| 124 } | 125 } |
| 125 | 126 |
| 127 /** |
| 128 * Arguments are physical pixels. |
| 129 */ |
| 126 function _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeigh
t) { | 130 function _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeigh
t) { |
| 127 var availableSpaceAbove = anchorRect.y - availRect.y; | 131 var availableSpaceAbove = anchorRect.y - availRect.y; |
| 128 availableSpaceAbove = Math.max(0, Math.min(availRect.height, availableSpaceA
bove)); | 132 availableSpaceAbove = Math.max(0, Math.min(availRect.height, availableSpaceA
bove)); |
| 129 | 133 |
| 130 var availableSpaceBelow = availRect.maxY - anchorRect.maxY; | 134 var availableSpaceBelow = availRect.maxY - anchorRect.maxY; |
| 131 availableSpaceBelow = Math.max(0, Math.min(availRect.height, availableSpaceB
elow)); | 135 availableSpaceBelow = Math.max(0, Math.min(availRect.height, availableSpaceB
elow)); |
| 132 if (windowRect.height > availableSpaceBelow && availableSpaceBelow < availab
leSpaceAbove) { | 136 if (windowRect.height > availableSpaceBelow && availableSpaceBelow < availab
leSpaceAbove) { |
| 133 windowRect.height = Math.min(windowRect.height, availableSpaceAbove); | 137 windowRect.height = Math.min(windowRect.height, availableSpaceAbove); |
| 134 windowRect.height = Math.max(windowRect.height, minHeight); | 138 windowRect.height = Math.max(windowRect.height, minHeight); |
| 135 windowRect.y = anchorRect.y - windowRect.height; | 139 windowRect.y = anchorRect.y - windowRect.height; |
| 136 } else { | 140 } else { |
| 137 windowRect.height = Math.min(windowRect.height, availableSpaceBelow); | 141 windowRect.height = Math.min(windowRect.height, availableSpaceBelow); |
| 138 windowRect.height = Math.max(windowRect.height, minHeight); | 142 windowRect.height = Math.max(windowRect.height, minHeight); |
| 139 windowRect.y = anchorRect.maxY; | 143 windowRect.y = anchorRect.maxY; |
| 140 } | 144 } |
| 141 } | 145 } |
| 142 | 146 |
| 147 /** |
| 148 * Arguments are physical pixels. |
| 149 */ |
| 143 function _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWid
th) { | 150 function _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWid
th) { |
| 144 windowRect.width = Math.min(windowRect.width, availRect.width); | 151 windowRect.width = Math.min(windowRect.width, availRect.width); |
| 145 windowRect.width = Math.max(windowRect.width, minWidth); | 152 windowRect.width = Math.max(windowRect.width, minWidth); |
| 146 windowRect.x = anchorRect.x; | 153 windowRect.x = anchorRect.x; |
| 147 // If we are getting clipped, we want to switch alignment to the right side | 154 // If we are getting clipped, we want to switch alignment to the right side |
| 148 // of the anchor rect as long as doing so will make the popup not clipped. | 155 // of the anchor rect as long as doing so will make the popup not clipped. |
| 149 var rightAlignedX = windowRect.x + anchorRect.width - windowRect.width; | 156 var rightAlignedX = windowRect.x + anchorRect.width - windowRect.width; |
| 150 if (rightAlignedX >= availRect.x && (windowRect.maxX > availRect.maxX || glo
bal.params.isRTL)) | 157 if (rightAlignedX >= availRect.x && (windowRect.maxX > availRect.maxX || glo
bal.params.isRTL)) |
| 151 windowRect.x = rightAlignedX; | 158 windowRect.x = rightAlignedX; |
| 152 } | 159 } |
| 153 | 160 |
| 154 /** | 161 /** |
| 155 * @param {!Rectangle} rect | 162 * @param {!Rectangle} rect Window position and size with physical pixels. |
| 156 */ | 163 */ |
| 157 function setWindowRect(rect) { | 164 function setWindowRect(rect) { |
| 158 if (window.frameElement) { | 165 if (window.frameElement) { |
| 159 window.frameElement.style.width = rect.width + "px"; | 166 window.frameElement.style.width = rect.width + "px"; |
| 160 window.frameElement.style.height = rect.height + "px"; | 167 window.frameElement.style.height = rect.height + "px"; |
| 161 } else { | 168 } else { |
| 162 window.pagePopupController.setWindowRect(rect.x, rect.y, rect.width, rec
t.height); | 169 window.pagePopupController.setWindowRect(rect.x, rect.y, rect.width, rec
t.height); |
| 163 } | 170 } |
| 164 } | 171 } |
| 165 | 172 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 }; | 316 }; |
| 310 | 317 |
| 311 Picker.prototype.cleanup = function() {}; | 318 Picker.prototype.cleanup = function() {}; |
| 312 | 319 |
| 313 window.addEventListener("keyup", function(event) { | 320 window.addEventListener("keyup", function(event) { |
| 314 // JAWS dispatches extra Alt events and unless we handle them they move the | 321 // JAWS dispatches extra Alt events and unless we handle them they move the |
| 315 // focus and close the popup. | 322 // focus and close the popup. |
| 316 if (event.keyIdentifier === "Alt") | 323 if (event.keyIdentifier === "Alt") |
| 317 event.preventDefault(); | 324 event.preventDefault(); |
| 318 }, true); | 325 }, true); |
| OLD | NEW |