| 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 constructor() { | 6 constructor() { |
| 7 this._widget = new UI.Widget(true); | 7 this._widget = new UI.Widget(true); |
| 8 this._widget.markAsRoot(); | 8 this._widget.markAsRoot(); |
| 9 this.element = this._widget.element; | 9 this.element = this._widget.element; |
| 10 this.contentElement = this._widget.contentElement; | 10 this.contentElement = this._widget.contentElement; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 var width = containerWidth - gutterSize * 2; | 177 var width = containerWidth - gutterSize * 2; |
| 178 var height = containerHeight - gutterSize * 2; | 178 var height = containerHeight - gutterSize * 2; |
| 179 var positionX = gutterSize; | 179 var positionX = gutterSize; |
| 180 var positionY = gutterSize; | 180 var positionY = gutterSize; |
| 181 | 181 |
| 182 if (this._maxSize) { | 182 if (this._maxSize) { |
| 183 width = Math.min(width, this._maxSize.width); | 183 width = Math.min(width, this._maxSize.width); |
| 184 height = Math.min(height, this._maxSize.height); | 184 height = Math.min(height, this._maxSize.height); |
| 185 } | 185 } |
| 186 | 186 |
| 187 var measuredWidth = 0; | |
| 188 var measuredHeight = 0; | |
| 189 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { | 187 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { |
| 190 measuredWidth = this.contentElement.offsetWidth; | 188 var measuredWidth = this.contentElement.offsetWidth; |
| 191 measuredHeight = this.contentElement.offsetHeight; | 189 var measuredHeight = this.contentElement.offsetHeight; |
| 192 width = Math.min(width, measuredWidth); | 190 var widthOverflow = height < measuredHeight ? scrollbarSize : 0; |
| 193 height = Math.min(height, measuredHeight); | 191 var heightOverflow = width < measuredWidth ? scrollbarSize : 0; |
| 192 width = Math.min(width, measuredWidth + widthOverflow); |
| 193 height = Math.min(height, measuredHeight + heightOverflow); |
| 194 } | 194 } |
| 195 | 195 |
| 196 if (this._anchorBox) { | 196 if (this._anchorBox) { |
| 197 var anchorBox = this._anchorBox.relativeToElement(container); | 197 var anchorBox = this._anchorBox.relativeToElement(container); |
| 198 var behavior = this._anchorBehavior; | 198 var behavior = this._anchorBehavior; |
| 199 this._arrowElement.classList.remove('arrow-none', 'arrow-top', 'arrow-bott
om', 'arrow-left', 'arrow-right'); | 199 this._arrowElement.classList.remove('arrow-none', 'arrow-top', 'arrow-bott
om', 'arrow-left', 'arrow-right'); |
| 200 | 200 |
| 201 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop || behavior === UI.
GlassPane.AnchorBehavior.PreferBottom) { | 201 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop || behavior === UI.
GlassPane.AnchorBehavior.PreferBottom) { |
| 202 var top = anchorBox.y - 2 * gutterSize; | 202 var top = anchorBox.y - 2 * gutterSize; |
| 203 var bottom = containerHeight - anchorBox.y - anchorBox.height - 2 * gutt
erSize; | 203 var bottom = containerHeight - anchorBox.y - anchorBox.height - 2 * gutt
erSize; |
| 204 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop && top < height &
& bottom > top) | 204 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop && top < height &
& bottom > top) |
| 205 behavior = UI.GlassPane.AnchorBehavior.PreferBottom; | 205 behavior = UI.GlassPane.AnchorBehavior.PreferBottom; |
| 206 if (behavior === UI.GlassPane.AnchorBehavior.PreferBottom && bottom < he
ight && top > bottom) | 206 if (behavior === UI.GlassPane.AnchorBehavior.PreferBottom && bottom < he
ight && top > bottom) |
| 207 behavior = UI.GlassPane.AnchorBehavior.PreferTop; | 207 behavior = UI.GlassPane.AnchorBehavior.PreferTop; |
| 208 | 208 |
| 209 var arrowY; | 209 var arrowY; |
| 210 var enoughHeight = true; | 210 var enoughHeight = true; |
| 211 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop) { | 211 if (behavior === UI.GlassPane.AnchorBehavior.PreferTop) { |
| 212 positionY = Math.max(gutterSize, anchorBox.y - height - gutterSize); | 212 positionY = Math.max(gutterSize, anchorBox.y - height - gutterSize); |
| 213 var spaceTop = anchorBox.y - positionY - gutterSize; | 213 var spaceTop = anchorBox.y - positionY - gutterSize; |
| 214 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { | 214 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { |
| 215 if (height < measuredHeight) | |
| 216 width += scrollbarSize; | |
| 217 if (height > spaceTop) { | 215 if (height > spaceTop) { |
| 218 this._arrowElement.classList.add('arrow-none'); | 216 this._arrowElement.classList.add('arrow-none'); |
| 219 enoughHeight = false; | 217 enoughHeight = false; |
| 220 } | 218 } |
| 221 } else { | 219 } else { |
| 222 height = Math.min(height, spaceTop); | 220 height = Math.min(height, spaceTop); |
| 223 } | 221 } |
| 224 this._arrowElement.setIconType('mediumicon-arrow-bottom'); | 222 this._arrowElement.setIconType('mediumicon-arrow-bottom'); |
| 225 this._arrowElement.classList.add('arrow-bottom'); | 223 this._arrowElement.classList.add('arrow-bottom'); |
| 226 arrowY = anchorBox.y - gutterSize; | 224 arrowY = anchorBox.y - gutterSize; |
| 227 } else { | 225 } else { |
| 228 positionY = anchorBox.y + anchorBox.height + gutterSize; | 226 positionY = anchorBox.y + anchorBox.height + gutterSize; |
| 229 var spaceBottom = containerHeight - positionY - gutterSize; | 227 var spaceBottom = containerHeight - positionY - gutterSize; |
| 230 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { | 228 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { |
| 231 if (height < measuredHeight) | |
| 232 width += scrollbarSize; | |
| 233 if (height > spaceBottom) { | 229 if (height > spaceBottom) { |
| 234 this._arrowElement.classList.add('arrow-none'); | 230 this._arrowElement.classList.add('arrow-none'); |
| 235 positionY = containerHeight - gutterSize - height; | 231 positionY = containerHeight - gutterSize - height; |
| 236 enoughHeight = false; | 232 enoughHeight = false; |
| 237 } | 233 } |
| 238 } else { | 234 } else { |
| 239 height = Math.min(height, spaceBottom); | 235 height = Math.min(height, spaceBottom); |
| 240 } | 236 } |
| 241 this._arrowElement.setIconType('mediumicon-arrow-top'); | 237 this._arrowElement.setIconType('mediumicon-arrow-top'); |
| 242 this._arrowElement.classList.add('arrow-top'); | 238 this._arrowElement.classList.add('arrow-top'); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 263 behavior = UI.GlassPane.AnchorBehavior.PreferRight; | 259 behavior = UI.GlassPane.AnchorBehavior.PreferRight; |
| 264 if (behavior === UI.GlassPane.AnchorBehavior.PreferRight && right < widt
h && left > right) | 260 if (behavior === UI.GlassPane.AnchorBehavior.PreferRight && right < widt
h && left > right) |
| 265 behavior = UI.GlassPane.AnchorBehavior.PreferLeft; | 261 behavior = UI.GlassPane.AnchorBehavior.PreferLeft; |
| 266 | 262 |
| 267 var arrowX; | 263 var arrowX; |
| 268 var enoughWidth = true; | 264 var enoughWidth = true; |
| 269 if (behavior === UI.GlassPane.AnchorBehavior.PreferLeft) { | 265 if (behavior === UI.GlassPane.AnchorBehavior.PreferLeft) { |
| 270 positionX = Math.max(gutterSize, anchorBox.x - width - gutterSize); | 266 positionX = Math.max(gutterSize, anchorBox.x - width - gutterSize); |
| 271 var spaceLeft = anchorBox.x - positionX - gutterSize; | 267 var spaceLeft = anchorBox.x - positionX - gutterSize; |
| 272 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { | 268 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { |
| 273 if (width < measuredWidth) | |
| 274 height += scrollbarSize; | |
| 275 if (width > spaceLeft) { | 269 if (width > spaceLeft) { |
| 276 this._arrowElement.classList.add('arrow-none'); | 270 this._arrowElement.classList.add('arrow-none'); |
| 277 enoughWidth = false; | 271 enoughWidth = false; |
| 278 } | 272 } |
| 279 } else { | 273 } else { |
| 280 width = Math.min(width, spaceLeft); | 274 width = Math.min(width, spaceLeft); |
| 281 } | 275 } |
| 282 this._arrowElement.setIconType('mediumicon-arrow-right'); | 276 this._arrowElement.setIconType('mediumicon-arrow-right'); |
| 283 this._arrowElement.classList.add('arrow-right'); | 277 this._arrowElement.classList.add('arrow-right'); |
| 284 arrowX = anchorBox.x - gutterSize; | 278 arrowX = anchorBox.x - gutterSize; |
| 285 } else { | 279 } else { |
| 286 positionX = anchorBox.x + anchorBox.width + gutterSize; | 280 positionX = anchorBox.x + anchorBox.width + gutterSize; |
| 287 var spaceRight = containerWidth - positionX - gutterSize; | 281 var spaceRight = containerWidth - positionX - gutterSize; |
| 288 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { | 282 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.MeasureContent) { |
| 289 if (width < measuredWidth) | |
| 290 height += scrollbarSize; | |
| 291 if (width > spaceRight) { | 283 if (width > spaceRight) { |
| 292 this._arrowElement.classList.add('arrow-none'); | 284 this._arrowElement.classList.add('arrow-none'); |
| 293 positionX = containerWidth - gutterSize - width; | 285 positionX = containerWidth - gutterSize - width; |
| 294 enoughWidth = false; | 286 enoughWidth = false; |
| 295 } | 287 } |
| 296 } else { | 288 } else { |
| 297 width = Math.min(width, spaceRight); | 289 width = Math.min(width, spaceRight); |
| 298 } | 290 } |
| 299 this._arrowElement.setIconType('mediumicon-arrow-left'); | 291 this._arrowElement.setIconType('mediumicon-arrow-left'); |
| 300 this._arrowElement.classList.add('arrow-left'); | 292 this._arrowElement.classList.add('arrow-left'); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 UI.GlassPane.MarginBehavior = { | 386 UI.GlassPane.MarginBehavior = { |
| 395 Arrow: Symbol('Arrow'), | 387 Arrow: Symbol('Arrow'), |
| 396 DefaultMargin: Symbol('DefaultMargin'), | 388 DefaultMargin: Symbol('DefaultMargin'), |
| 397 NoMargin: Symbol('NoMargin') | 389 NoMargin: Symbol('NoMargin') |
| 398 }; | 390 }; |
| 399 | 391 |
| 400 /** @type {!Map<!Document, !Element>} */ | 392 /** @type {!Map<!Document, !Element>} */ |
| 401 UI.GlassPane._containers = new Map(); | 393 UI.GlassPane._containers = new Map(); |
| 402 /** @type {!Set<!UI.GlassPane>} */ | 394 /** @type {!Set<!UI.GlassPane>} */ |
| 403 UI.GlassPane._panes = new Set(); | 395 UI.GlassPane._panes = new Set(); |
| OLD | NEW |