| OLD | NEW |
| 1 "use strict"; | 1 "use strict"; |
| 2 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 | 5 |
| 6 var global = { | 6 var global = { |
| 7 argumentsReceived: false, | 7 argumentsReceived: false, |
| 8 params: null, | 8 params: null, |
| 9 picker: null | 9 picker: null |
| 10 }; | 10 }; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 // be reopened. | 211 // be reopened. |
| 212 setTimeout(function () { | 212 setTimeout(function () { |
| 213 window.pagePopupController.closePopup(); | 213 window.pagePopupController.closePopup(); |
| 214 }, 0); | 214 }, 0); |
| 215 event.preventDefault(); | 215 event.preventDefault(); |
| 216 } | 216 } |
| 217 }; | 217 }; |
| 218 | 218 |
| 219 ListPicker.prototype._fixWindowSize = function() { | 219 ListPicker.prototype._fixWindowSize = function() { |
| 220 this._selectElement.style.height = ""; | 220 this._selectElement.style.height = ""; |
| 221 var zoom = this._config.zoomFactor; | 221 var scale = this._config.scaleFactor; |
| 222 var maxHeight = this._selectElement.offsetHeight * zoom; | 222 var maxHeight = this._selectElement.offsetHeight; |
| 223 var noScrollHeight = (this._calculateScrollHeight() + ListPicker.ListboxSele
ctBorder * 2) * zoom; | 223 var noScrollHeight = (this._calculateScrollHeight() + ListPicker.ListboxSele
ctBorder * 2); |
| 224 var scrollbarWidth = getScrollbarWidth() * zoom; | 224 var scrollbarWidth = getScrollbarWidth(); |
| 225 var elementOffsetWidth = this._selectElement.offsetWidth * zoom; | 225 var elementOffsetWidth = this._selectElement.offsetWidth; |
| 226 var desiredWindowHeight = noScrollHeight; | 226 var desiredWindowHeight = noScrollHeight; |
| 227 var desiredWindowWidth = elementOffsetWidth; | 227 var desiredWindowWidth = elementOffsetWidth; |
| 228 // If we already have a vertical scrollbar, subtract it out, it will get re-
added below. | 228 // If we already have a vertical scrollbar, subtract it out, it will get re-
added below. |
| 229 if (this._selectElement.scrollHeight > this._selectElement.clientHeight) | 229 if (this._selectElement.scrollHeight > this._selectElement.clientHeight) |
| 230 desiredWindowWidth -= scrollbarWidth; | 230 desiredWindowWidth -= scrollbarWidth; |
| 231 var expectingScrollbar = false; | 231 var expectingScrollbar = false; |
| 232 if (desiredWindowHeight > maxHeight) { | 232 if (desiredWindowHeight > maxHeight) { |
| 233 desiredWindowHeight = maxHeight; | 233 desiredWindowHeight = maxHeight; |
| 234 // Setting overflow to auto does not increase width for the scrollbar | 234 // Setting overflow to auto does not increase width for the scrollbar |
| 235 // so we need to do it manually. | 235 // so we need to do it manually. |
| 236 desiredWindowWidth += scrollbarWidth; | 236 desiredWindowWidth += scrollbarWidth; |
| 237 expectingScrollbar = true; | 237 expectingScrollbar = true; |
| 238 } | 238 } |
| 239 desiredWindowWidth = Math.max(this._config.anchorRectInScreen.width, desired
WindowWidth); | 239 // Screen coordinate for anchorRectInScreen and windowRect is DIP. |
| 240 var windowRect = adjustWindowRect(desiredWindowWidth, desiredWindowHeight, e
lementOffsetWidth, 0); | 240 desiredWindowWidth = Math.max(this._config.anchorRectInScreen.width * scale,
desiredWindowWidth); |
| 241 var windowRect = adjustWindowRect(desiredWindowWidth / scale, desiredWindowH
eight / scale, elementOffsetWidth / scale, 0); |
| 241 // If the available screen space is smaller than maxHeight, we will get an u
nexpected scrollbar. | 242 // If the available screen space is smaller than maxHeight, we will get an u
nexpected scrollbar. |
| 242 if (!expectingScrollbar && windowRect.height < noScrollHeight) { | 243 if (!expectingScrollbar && windowRect.height < noScrollHeight / scale) { |
| 243 desiredWindowWidth = windowRect.width + scrollbarWidth; | 244 desiredWindowWidth = windowRect.width * scale + scrollbarWidth; |
| 244 windowRect = adjustWindowRect(desiredWindowWidth, windowRect.height, win
dowRect.width, windowRect.height); | 245 windowRect = adjustWindowRect(desiredWindowWidth / scale, windowRect.hei
ght, windowRect.width, windowRect.height); |
| 245 } | 246 } |
| 246 this._selectElement.style.width = (windowRect.width / zoom) + "px"; | 247 this._selectElement.style.width = (windowRect.width * scale) + "px"; |
| 247 this._selectElement.style.height = (windowRect.height / zoom) + "px"; | 248 this._selectElement.style.height = (windowRect.height * scale) + "px"; |
| 248 this._element.style.height = (windowRect.height / zoom) + "px"; | 249 this._element.style.height = (windowRect.height * scale) + "px"; |
| 249 setWindowRect(windowRect); | 250 setWindowRect(windowRect); |
| 250 }; | 251 }; |
| 251 | 252 |
| 252 ListPicker.prototype._calculateScrollHeight = function() { | 253 ListPicker.prototype._calculateScrollHeight = function() { |
| 253 // Element.scrollHeight returns an integer value but this calculate the | 254 // Element.scrollHeight returns an integer value but this calculate the |
| 254 // actual fractional value. | 255 // actual fractional value. |
| 256 // TODO(tkent): This can be too large? crbug.com/579863 |
| 255 var top = Infinity; | 257 var top = Infinity; |
| 256 var bottom = -Infinity; | 258 var bottom = -Infinity; |
| 257 for (var i = 0; i < this._selectElement.children.length; i++) { | 259 for (var i = 0; i < this._selectElement.children.length; i++) { |
| 258 var rect = this._selectElement.children[i].getBoundingClientRect(); | 260 var rect = this._selectElement.children[i].getBoundingClientRect(); |
| 259 // Skip hidden elements. | 261 // Skip hidden elements. |
| 260 if (rect.width === 0 && rect.height === 0) | 262 if (rect.width === 0 && rect.height === 0) |
| 261 continue; | 263 continue; |
| 262 top = Math.min(top, rect.top); | 264 top = Math.min(top, rect.top); |
| 263 bottom = Math.max(bottom, rect.bottom); | 265 bottom = Math.max(bottom, rect.bottom); |
| 264 } | 266 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 451 } |
| 450 this._applyItemStyle(element, config.style); | 452 this._applyItemStyle(element, config.style); |
| 451 }; | 453 }; |
| 452 | 454 |
| 453 if (window.dialogArguments) { | 455 if (window.dialogArguments) { |
| 454 initialize(dialogArguments); | 456 initialize(dialogArguments); |
| 455 } else { | 457 } else { |
| 456 window.addEventListener("message", handleMessage, false); | 458 window.addEventListener("message", handleMessage, false); |
| 457 window.setTimeout(handleArgumentsTimeout, 1000); | 459 window.setTimeout(handleArgumentsTimeout, 1000); |
| 458 } | 460 } |
| OLD | NEW |