| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 UI.Popover = class extends UI.Widget { | 34 UI.Popover = class extends UI.Widget { |
| 35 /** | 35 /** |
| 36 * @param {!UI.PopoverHelper=} popoverHelper | 36 * @param {!UI.PopoverHelper=} popoverHelper |
| 37 */ | 37 */ |
| 38 constructor(popoverHelper) { | 38 constructor(popoverHelper) { |
| 39 super(); | 39 super(true); |
| 40 this.markAsRoot(); | 40 this.markAsRoot(); |
| 41 this.element.className = UI.Popover._classNamePrefix; // Override | 41 this.registerRequiredCSS('ui/popover.css'); |
| 42 this._containerElement = createElementWithClass('div', 'fill popover-contain
er'); | 42 this._containerElement = createElementWithClass('div', 'fill popover-contain
er'); |
| 43 | 43 this._popupArrowElement = this.contentElement.createChild('div', 'arrow'); |
| 44 this._popupArrowElement = this.element.createChild('div', 'arrow'); | 44 this._contentDiv = this.contentElement.createChild('div', 'popover-content')
; |
| 45 this._contentDiv = this.element.createChild('div', 'content'); | |
| 46 | |
| 47 this._popoverHelper = popoverHelper; | 45 this._popoverHelper = popoverHelper; |
| 48 this._hideBound = this.hide.bind(this); | 46 this._hideBound = this.hide.bind(this); |
| 49 } | 47 } |
| 50 | 48 |
| 51 /** | 49 /** |
| 52 * @param {!Element} element | 50 * @param {!Element} element |
| 53 * @param {!Element|!AnchorBox} anchor | 51 * @param {!Element|!AnchorBox} anchor |
| 54 * @param {?number=} preferredWidth | 52 * @param {?number=} preferredWidth |
| 55 * @param {?number=} preferredHeight | 53 * @param {?number=} preferredHeight |
| 56 * @param {?UI.Popover.Orientation=} arrowDirection | 54 * @param {?UI.Popover.Orientation=} arrowDirection |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 if (this.isShowing()) | 126 if (this.isShowing()) |
| 129 this.hide(); | 127 this.hide(); |
| 130 this._disposed = true; | 128 this._disposed = true; |
| 131 } | 129 } |
| 132 | 130 |
| 133 /** | 131 /** |
| 134 * @param {boolean} canShrink | 132 * @param {boolean} canShrink |
| 135 */ | 133 */ |
| 136 setCanShrink(canShrink) { | 134 setCanShrink(canShrink) { |
| 137 this._hasFixedHeight = !canShrink; | 135 this._hasFixedHeight = !canShrink; |
| 138 this._contentDiv.classList.toggle('fixed-height', this._hasFixedHeight); | |
| 139 } | 136 } |
| 140 | 137 |
| 141 /** | 138 /** |
| 142 * @param {boolean} noPadding | 139 * @param {boolean} noPadding |
| 143 */ | 140 */ |
| 144 setNoPadding(noPadding) { | 141 setNoPadding(noPadding) { |
| 145 this._hasNoPadding = noPadding; | 142 this._hasNoPadding = noPadding; |
| 146 this._contentDiv.classList.toggle('no-padding', this._hasNoPadding); | 143 this._contentDiv.classList.toggle('no-padding', this._hasNoPadding); |
| 147 } | 144 } |
| 148 | 145 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 newElementPosition.width = totalWidth - borderRadius * 2; | 225 newElementPosition.width = totalWidth - borderRadius * 2; |
| 229 newElementPosition.height += scrollerWidth; | 226 newElementPosition.height += scrollerWidth; |
| 230 horizontalAlignment = 'left'; | 227 horizontalAlignment = 'left'; |
| 231 if (verticalAlignment === UI.Popover.Orientation.Bottom) | 228 if (verticalAlignment === UI.Popover.Orientation.Bottom) |
| 232 newElementPosition.y -= scrollerWidth; | 229 newElementPosition.y -= scrollerWidth; |
| 233 // Position arrow accurately. | 230 // Position arrow accurately. |
| 234 this._popupArrowElement.style.left = | 231 this._popupArrowElement.style.left = |
| 235 Math.max(0, anchorBox.x - newElementPosition.x - borderRadius - arrowR
adius + anchorBox.width / 2) + 'px'; | 232 Math.max(0, anchorBox.x - newElementPosition.x - borderRadius - arrowR
adius + anchorBox.width / 2) + 'px'; |
| 236 } | 233 } |
| 237 | 234 |
| 238 this.element.className = | 235 this._popupArrowElement.className = 'arrow ' + verticalAlignment + '-' + hor
izontalAlignment + '-arrow'; |
| 239 UI.Popover._classNamePrefix + ' ' + verticalAlignment + '-' + horizontal
Alignment + '-arrow'; | |
| 240 this.element.positionAt(newElementPosition.x, newElementPosition.y - borderW
idth, container); | 236 this.element.positionAt(newElementPosition.x, newElementPosition.y - borderW
idth, container); |
| 241 this.element.style.width = newElementPosition.width + borderWidth * 2 + 'px'
; | 237 this.element.style.width = newElementPosition.width + borderWidth * 2 + 'px'
; |
| 242 this.element.style.height = newElementPosition.height + borderWidth * 2 + 'p
x'; | 238 this.element.style.height = newElementPosition.height + borderWidth * 2 + 'p
x'; |
| 243 } | 239 } |
| 244 }; | 240 }; |
| 245 | 241 |
| 246 UI.Popover._classNamePrefix = 'popover'; | 242 UI.Popover._classNamePrefix = 'popover'; |
| 247 | 243 |
| 248 /** | 244 /** |
| 249 * @unrestricted | 245 * @unrestricted |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 this._resetHoverTimer(); | 400 this._resetHoverTimer(); |
| 405 } | 401 } |
| 406 } | 402 } |
| 407 }; | 403 }; |
| 408 | 404 |
| 409 /** @enum {string} */ | 405 /** @enum {string} */ |
| 410 UI.Popover.Orientation = { | 406 UI.Popover.Orientation = { |
| 411 Top: 'top', | 407 Top: 'top', |
| 412 Bottom: 'bottom' | 408 Bottom: 'bottom' |
| 413 }; | 409 }; |
| OLD | NEW |