| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 UI.GlassPane = class { | 5 UI.GlassPane = class { |
| 6 /** | 6 /** |
| 7 * @param {!Document} document | 7 * @param {!Document} document |
| 8 * @param {boolean} dimmed | 8 * @param {boolean} dimmed |
| 9 * @param {boolean} blockPointerEvents | 9 * @param {boolean} blockPointerEvents |
| 10 * @param {function(!Event)} onClickOutside | 10 * @param {function(!Event)} onClickOutside |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 height = Math.min(height, this._maxSize.height); | 122 height = Math.min(height, this._maxSize.height); |
| 123 } | 123 } |
| 124 | 124 |
| 125 if (this._anchorBox) { | 125 if (this._anchorBox) { |
| 126 var anchorBox = this._anchorBox.relativeToElement(container); | 126 var anchorBox = this._anchorBox.relativeToElement(container); |
| 127 var behavior = this._anchorBehavior; | 127 var behavior = this._anchorBehavior; |
| 128 | 128 |
| 129 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop || behavior === UI.
GlassPane.AnchorBehavior.PreferBottom) { | 129 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop || behavior === UI.
GlassPane.AnchorBehavior.PreferBottom) { |
| 130 var top = anchorBox.y - gutterSize; | 130 var top = anchorBox.y - gutterSize; |
| 131 var bottom = containerHeight - anchorBox.y - anchorBox.height - gutterSi
ze; | 131 var bottom = containerHeight - anchorBox.y - anchorBox.height - gutterSi
ze; |
| 132 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop && top < height &
& bottom >= height) | 132 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop && top < height &
& bottom > top) |
| 133 behavior = UI.GlassPane.AnchorBehavior.PreferBottom; | 133 behavior = UI.GlassPane.AnchorBehavior.PreferBottom; |
| 134 if (behavior === UI.GlassPane.AnchorBehavior.PreferBottom && bottom < he
ight && top >= height) | 134 if (behavior === UI.GlassPane.AnchorBehavior.PreferBottom && bottom < he
ight && top > bottom) |
| 135 behavior = UI.GlassPane.AnchorBehavior.PreferTop; | 135 behavior = UI.GlassPane.AnchorBehavior.PreferTop; |
| 136 | 136 |
| 137 positionX = Math.max(gutterSize, Math.min(anchorBox.x, containerWidth -
width - gutterSize)); | 137 positionX = Math.max(gutterSize, Math.min(anchorBox.x, containerWidth -
width - gutterSize)); |
| 138 width = Math.min(width, containerWidth - positionX - gutterSize); | 138 width = Math.min(width, containerWidth - positionX - gutterSize); |
| 139 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop) { | 139 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop) { |
| 140 positionY = Math.max(gutterSize, anchorBox.y - height); | 140 positionY = Math.max(gutterSize, anchorBox.y - height); |
| 141 height = Math.min(height, anchorBox.y - positionY); | 141 height = Math.min(height, anchorBox.y - positionY); |
| 142 } else { | 142 } else { |
| 143 positionY = anchorBox.y + anchorBox.height; | 143 positionY = anchorBox.y + anchorBox.height; |
| 144 height = Math.min(height, containerHeight - positionY - gutterSize); | 144 height = Math.min(height, containerHeight - positionY - gutterSize); |
| 145 } | 145 } |
| 146 } else { | 146 } else { |
| 147 var left = anchorBox.x - gutterSize; | 147 var left = anchorBox.x - gutterSize; |
| 148 var right = containerWidth - anchorBox.x - anchorBox.width - gutterSize; | 148 var right = containerWidth - anchorBox.x - anchorBox.width - gutterSize; |
| 149 if (behavior === UI.GlassPane.AnchorBehavior.PreferLeft && left < width
&& right >= width) | 149 if (behavior === UI.GlassPane.AnchorBehavior.PreferLeft && left < width
&& right > left) |
| 150 behavior = UI.GlassPane.AnchorBehavior.PreferRight; | 150 behavior = UI.GlassPane.AnchorBehavior.PreferRight; |
| 151 if (behavior === UI.GlassPane.AnchorBehavior.PreferRight && right < widt
h && left >= width) | 151 if (behavior === UI.GlassPane.AnchorBehavior.PreferRight && right < widt
h && left > right) |
| 152 behavior = UI.GlassPane.AnchorBehavior.PreferLeft; | 152 behavior = UI.GlassPane.AnchorBehavior.PreferLeft; |
| 153 | 153 |
| 154 positionY = Math.max(gutterSize, Math.min(anchorBox.y, containerHeight -
height - gutterSize)); | 154 positionY = Math.max(gutterSize, Math.min(anchorBox.y, containerHeight -
height - gutterSize)); |
| 155 height = Math.min(height, containerHeight - positionY - gutterSize); | 155 height = Math.min(height, containerHeight - positionY - gutterSize); |
| 156 if (behavior === UI.GlassPane.AnchorBehavior.PreferLeft) { | 156 if (behavior === UI.GlassPane.AnchorBehavior.PreferLeft) { |
| 157 positionX = Math.max(gutterSize, anchorBox.x - width); | 157 positionX = Math.max(gutterSize, anchorBox.x - width); |
| 158 width = Math.min(width, anchorBox.x - positionX); | 158 width = Math.min(width, anchorBox.x - positionX); |
| 159 } else { | 159 } else { |
| 160 positionX = anchorBox.x + anchorBox.width; | 160 positionX = anchorBox.x + anchorBox.width; |
| 161 width = Math.min(width, containerWidth - positionX - gutterSize); | 161 width = Math.min(width, containerWidth - positionX - gutterSize); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 PreferTop: Symbol('PreferTop'), | 210 PreferTop: Symbol('PreferTop'), |
| 211 PreferBottom: Symbol('PreferBottom'), | 211 PreferBottom: Symbol('PreferBottom'), |
| 212 PreferLeft: Symbol('PreferLeft'), | 212 PreferLeft: Symbol('PreferLeft'), |
| 213 PreferRight: Symbol('PreferRight'), | 213 PreferRight: Symbol('PreferRight'), |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 /** @type {!Map<!Document, !Element>} */ | 216 /** @type {!Map<!Document, !Element>} */ |
| 217 UI.GlassPane._containers = new Map(); | 217 UI.GlassPane._containers = new Map(); |
| 218 /** @type {!Set<!UI.GlassPane>} */ | 218 /** @type {!Set<!UI.GlassPane>} */ |
| 219 UI.GlassPane._panes = new Set(); | 219 UI.GlassPane._panes = new Set(); |
| OLD | NEW |