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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 /** | 92 /** |
93 * @param {!number} width in CSS pixel | 93 * @param {!number} width in CSS pixel |
94 * @param {!number} height in CSS pixel | 94 * @param {!number} height in CSS pixel |
95 */ | 95 */ |
96 function resizeWindow(width, height) { | 96 function resizeWindow(width, height) { |
97 var zoom = global.params.zoomFactor ? global.params.zoomFactor : 1; | 97 var zoom = global.params.zoomFactor ? global.params.zoomFactor : 1; |
98 setWindowRect(adjustWindowRect(width * zoom, height * zoom, width * zoom, he
ight * zoom)); | 98 setWindowRect(adjustWindowRect(width * zoom, height * zoom, width * zoom, he
ight * zoom)); |
99 } | 99 } |
100 | 100 |
101 /** | 101 /** |
102 * @param {!number} width in physical pixel | 102 * @param {!number} width in DIP |
103 * @param {!number} height in physical pixel | 103 * @param {!number} height in DIP |
104 * @param {?number} minWidth in physical pixel | 104 * @param {?number} minWidth in DIP |
105 * @param {?number} minHeight in physical pixel | 105 * @param {?number} minHeight in DIP |
106 * @return {!Rectangle} Adjusted rectangle with physical pixels | 106 * @return {!Rectangle} Adjusted rectangle in DIP |
107 */ | 107 */ |
108 function adjustWindowRect(width, height, minWidth, minHeight) { | 108 function adjustWindowRect(width, height, minWidth, minHeight) { |
109 if (typeof minWidth !== "number") | 109 if (typeof minWidth !== "number") |
110 minWidth = 0; | 110 minWidth = 0; |
111 if (typeof minHeight !== "number") | 111 if (typeof minHeight !== "number") |
112 minHeight = 0; | 112 minHeight = 0; |
113 | 113 |
114 var windowRect = new Rectangle(0, 0, Math.ceil(width), Math.ceil(height)); | 114 var windowRect = new Rectangle(0, 0, Math.ceil(width), Math.ceil(height)); |
115 | 115 |
116 if (!global.params.anchorRectInScreen) | 116 if (!global.params.anchorRectInScreen) |
117 return windowRect; | 117 return windowRect; |
118 | 118 |
119 var anchorRect = new Rectangle(global.params.anchorRectInScreen); | 119 var anchorRect = new Rectangle(global.params.anchorRectInScreen); |
120 var availRect = new Rectangle(window.screen.availLeft, window.screen.availTo
p, window.screen.availWidth, window.screen.availHeight); | 120 var availRect = new Rectangle(window.screen.availLeft, window.screen.availTo
p, window.screen.availWidth, window.screen.availHeight); |
121 | 121 |
122 _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeight); | 122 _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeight); |
123 _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWidth); | 123 _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWidth); |
124 | 124 |
125 return windowRect; | 125 return windowRect; |
126 } | 126 } |
127 | 127 |
128 /** | 128 /** |
129 * Arguments are physical pixels. | 129 * Arguments are DIPs. |
130 */ | 130 */ |
131 function _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeigh
t) { | 131 function _adjustWindowRectVertically(windowRect, availRect, anchorRect, minHeigh
t) { |
132 var availableSpaceAbove = anchorRect.y - availRect.y; | 132 var availableSpaceAbove = anchorRect.y - availRect.y; |
133 availableSpaceAbove = Math.max(0, Math.min(availRect.height, availableSpaceA
bove)); | 133 availableSpaceAbove = Math.max(0, Math.min(availRect.height, availableSpaceA
bove)); |
134 | 134 |
135 var availableSpaceBelow = availRect.maxY - anchorRect.maxY; | 135 var availableSpaceBelow = availRect.maxY - anchorRect.maxY; |
136 availableSpaceBelow = Math.max(0, Math.min(availRect.height, availableSpaceB
elow)); | 136 availableSpaceBelow = Math.max(0, Math.min(availRect.height, availableSpaceB
elow)); |
137 if (windowRect.height > availableSpaceBelow && availableSpaceBelow < availab
leSpaceAbove) { | 137 if (windowRect.height > availableSpaceBelow && availableSpaceBelow < availab
leSpaceAbove) { |
138 windowRect.height = Math.min(windowRect.height, availableSpaceAbove); | 138 windowRect.height = Math.min(windowRect.height, availableSpaceAbove); |
139 windowRect.height = Math.max(windowRect.height, minHeight); | 139 windowRect.height = Math.max(windowRect.height, minHeight); |
140 windowRect.y = anchorRect.y - windowRect.height; | 140 windowRect.y = anchorRect.y - windowRect.height; |
141 } else { | 141 } else { |
142 windowRect.height = Math.min(windowRect.height, availableSpaceBelow); | 142 windowRect.height = Math.min(windowRect.height, availableSpaceBelow); |
143 windowRect.height = Math.max(windowRect.height, minHeight); | 143 windowRect.height = Math.max(windowRect.height, minHeight); |
144 windowRect.y = anchorRect.maxY; | 144 windowRect.y = anchorRect.maxY; |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 /** | 148 /** |
149 * Arguments are physical pixels. | 149 * Arguments are DIPs. |
150 */ | 150 */ |
151 function _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWid
th) { | 151 function _adjustWindowRectHorizontally(windowRect, availRect, anchorRect, minWid
th) { |
152 windowRect.width = Math.min(windowRect.width, availRect.width); | 152 windowRect.width = Math.min(windowRect.width, availRect.width); |
153 windowRect.width = Math.max(windowRect.width, minWidth); | 153 windowRect.width = Math.max(windowRect.width, minWidth); |
154 windowRect.x = anchorRect.x; | 154 windowRect.x = anchorRect.x; |
155 // If we are getting clipped, we want to switch alignment to the right side | 155 // If we are getting clipped, we want to switch alignment to the right side |
156 // of the anchor rect as long as doing so will make the popup not clipped. | 156 // of the anchor rect as long as doing so will make the popup not clipped. |
157 var rightAlignedX = windowRect.x + anchorRect.width - windowRect.width; | 157 var rightAlignedX = windowRect.x + anchorRect.width - windowRect.width; |
158 if (rightAlignedX >= availRect.x && (windowRect.maxX > availRect.maxX || glo
bal.params.isRTL)) | 158 if (rightAlignedX >= availRect.x && (windowRect.maxX > availRect.maxX || glo
bal.params.isRTL)) |
159 windowRect.x = rightAlignedX; | 159 windowRect.x = rightAlignedX; |
160 } | 160 } |
161 | 161 |
162 /** | 162 /** |
163 * @param {!Rectangle} rect Window position and size with physical pixels. | 163 * @param {!Rectangle} rect Window position and size in DIP. |
164 */ | 164 */ |
165 function setWindowRect(rect) { | 165 function setWindowRect(rect) { |
166 if (window.frameElement) { | 166 if (window.frameElement) { |
167 window.frameElement.style.width = rect.width + "px"; | 167 window.frameElement.style.width = rect.width + "px"; |
168 window.frameElement.style.height = rect.height + "px"; | 168 window.frameElement.style.height = rect.height + "px"; |
169 } else { | 169 } else { |
170 window.pagePopupController.setWindowRect(rect.x, rect.y, rect.width, rec
t.height); | 170 window.pagePopupController.setWindowRect(rect.x, rect.y, rect.width, rec
t.height); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 }; | 320 }; |
321 | 321 |
322 Picker.prototype.cleanup = function() {}; | 322 Picker.prototype.cleanup = function() {}; |
323 | 323 |
324 window.addEventListener("keyup", function(event) { | 324 window.addEventListener("keyup", function(event) { |
325 // JAWS dispatches extra Alt events and unless we handle them they move the | 325 // JAWS dispatches extra Alt events and unless we handle them they move the |
326 // focus and close the popup. | 326 // focus and close the popup. |
327 if (event.key === "Alt") | 327 if (event.key === "Alt") |
328 event.preventDefault(); | 328 event.preventDefault(); |
329 }, true); | 329 }, true); |
OLD | NEW |