11// Copyright 2017 The Chromium Authors. All rights reserved.
22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
4-
5- import * as Platform from '../../core/platform/platform.js' ;
6-
74import type { Size } from './Geometry.js' ;
85import glassPaneStyles from './glassPane.css.js' ;
96import { deepElementFromEvent , measuredScrollbarWidth } from './UIUtils.js' ;
@@ -14,7 +11,6 @@ export class GlassPane {
1411
1512 element : typeof Widget . prototype . element ;
1613 contentElement : typeof Widget . prototype . contentElement ;
17- private readonly arrowElement : HTMLSpanElement ;
1814 private readonly onMouseDownBound : ( event : Event ) => void ;
1915 private onClickOutsideCallback : ( ( arg0 : Event ) => void ) | null = null ;
2016 private maxSize : Size | null = null ;
@@ -33,11 +29,6 @@ export class GlassPane {
3329 if ( jslog ) {
3430 this . contentElement . setAttribute ( 'jslog' , jslog ) ;
3531 }
36- this . arrowElement = document . createElement ( 'span' ) ;
37- this . arrowElement . classList . add ( 'arrow' , 'hidden' ) ;
38- if ( this . element . shadowRoot ) {
39- this . element . shadowRoot . appendChild ( this . arrowElement ) ;
40- }
4132
4233 this . registerRequiredCSS ( glassPaneStyles ) ;
4334 this . setPointerEventsBehavior ( PointerEventsBehavior . PIERCE_GLASS_PANE ) ;
@@ -103,7 +94,6 @@ export class GlassPane {
10394
10495 setMarginBehavior ( behavior : MarginBehavior ) : void {
10596 this . marginBehavior = behavior ;
106- this . arrowElement . classList . toggle ( 'hidden' , behavior !== MarginBehavior . ARROW ) ;
10797 }
10898
10999 setIgnoreLeftMargin ( ignore : boolean ) : void {
@@ -151,10 +141,9 @@ export class GlassPane {
151141 return ;
152142 }
153143
154- const showArrow = this . marginBehavior === MarginBehavior . ARROW ;
155- const gutterSize = showArrow ? 8 : ( this . marginBehavior === MarginBehavior . NO_MARGIN ? 0 : 3 ) ;
144+ const gutterSize = this . marginBehavior === MarginBehavior . NO_MARGIN ? 0 : 3 ;
156145 const scrollbarSize = measuredScrollbarWidth ( this . element . ownerDocument ) ;
157- const arrowSize = 10 ;
146+ const offsetSize = 10 ;
158147
159148 const container = ( containers . get ( ( this . element . ownerDocument ) ) ) as HTMLElement ;
160149 if ( this . sizeBehavior === SizeBehavior . MEASURE_CONTENT ) {
@@ -190,7 +179,6 @@ export class GlassPane {
190179 const anchorBox = this . anchorBox . relativeToElement ( container ) ;
191180 let behavior : AnchorBehavior . PREFER_BOTTOM | AnchorBehavior . PREFER_TOP | AnchorBehavior . PREFER_RIGHT |
192181 AnchorBehavior . PREFER_LEFT | AnchorBehavior = this . anchorBehavior ;
193- this . arrowElement . classList . remove ( 'arrow-none' , 'arrow-top' , 'arrow-bottom' , 'arrow-left' , 'arrow-right' ) ;
194182
195183 if ( behavior === AnchorBehavior . PREFER_TOP || behavior === AnchorBehavior . PREFER_BOTTOM ) {
196184 const top = anchorBox . y - 2 * gutterSize ;
@@ -202,35 +190,28 @@ export class GlassPane {
202190 behavior = AnchorBehavior . PREFER_TOP ;
203191 }
204192
205- let arrowY ;
206193 let enoughHeight = true ;
207194 if ( behavior === AnchorBehavior . PREFER_TOP ) {
208195 positionY = Math . max ( gutterSize , anchorBox . y - height - gutterSize ) ;
209196 const spaceTop = anchorBox . y - positionY - gutterSize ;
210197 if ( this . sizeBehavior === SizeBehavior . MEASURE_CONTENT ) {
211198 if ( height > spaceTop ) {
212- this . arrowElement . classList . add ( 'arrow-none' ) ;
213199 enoughHeight = false ;
214200 }
215201 } else {
216202 height = Math . min ( height , spaceTop ) ;
217203 }
218- this . arrowElement . classList . add ( 'arrow-bottom' ) ;
219- arrowY = anchorBox . y - gutterSize ;
220204 } else {
221205 positionY = anchorBox . y + anchorBox . height + gutterSize ;
222206 const spaceBottom = containerHeight - positionY - gutterSize ;
223207 if ( this . sizeBehavior === SizeBehavior . MEASURE_CONTENT ) {
224208 if ( height > spaceBottom ) {
225- this . arrowElement . classList . add ( 'arrow-none' ) ;
226209 positionY = containerHeight - gutterSize - height ;
227210 enoughHeight = false ;
228211 }
229212 } else {
230213 height = Math . min ( height , spaceBottom ) ;
231214 }
232- this . arrowElement . classList . add ( 'arrow-top' ) ;
233- arrowY = anchorBox . y + anchorBox . height + gutterSize ;
234215 }
235216
236217 const naturalPositionX = Math . min ( anchorBox . x , containerWidth - width - gutterSize ) ;
@@ -240,18 +221,11 @@ export class GlassPane {
240221 }
241222
242223 if ( ! enoughHeight ) {
243- positionX = Math . min ( positionX + arrowSize , containerWidth - width - gutterSize ) ;
244- } else if ( showArrow && positionX - arrowSize >= gutterSize ) {
245- positionX -= arrowSize ;
224+ positionX = Math . min ( positionX + offsetSize , containerWidth - width - gutterSize ) ;
225+ } else if ( positionX - offsetSize >= gutterSize ) {
226+ positionX -= offsetSize ;
246227 }
247228 width = Math . min ( width , containerWidth - positionX - gutterSize ) ;
248- if ( 2 * arrowSize >= width ) {
249- this . arrowElement . classList . add ( 'arrow-none' ) ;
250- } else {
251- let arrowX : number = anchorBox . x + Math . min ( 50 , Math . floor ( anchorBox . width / 2 ) ) ;
252- arrowX = Platform . NumberUtilities . clamp ( arrowX , positionX + arrowSize , positionX + width - arrowSize ) ;
253- this . arrowElement . positionAt ( arrowX , arrowY , container ) ;
254- }
255229 } else {
256230 const left = anchorBox . x - 2 * gutterSize ;
257231 const right = containerWidth - anchorBox . x - anchorBox . width - 2 * gutterSize ;
@@ -262,58 +236,43 @@ export class GlassPane {
262236 behavior = AnchorBehavior . PREFER_LEFT ;
263237 }
264238
265- let arrowX ;
266239 let enoughWidth = true ;
267240 if ( behavior === AnchorBehavior . PREFER_LEFT ) {
268241 positionX = Math . max ( gutterSize , anchorBox . x - width - gutterSize ) ;
269242 const spaceLeft = anchorBox . x - positionX - gutterSize ;
270243 if ( this . sizeBehavior === SizeBehavior . MEASURE_CONTENT ) {
271244 if ( width > spaceLeft ) {
272- this . arrowElement . classList . add ( 'arrow-none' ) ;
273245 enoughWidth = false ;
274246 }
275247 } else {
276248 width = Math . min ( width , spaceLeft ) ;
277249 }
278- this . arrowElement . classList . add ( 'arrow-right' ) ;
279- arrowX = anchorBox . x - gutterSize ;
280250 } else {
281251 positionX = anchorBox . x + anchorBox . width + gutterSize ;
282252 const spaceRight = containerWidth - positionX - gutterSize ;
283253 if ( this . sizeBehavior === SizeBehavior . MEASURE_CONTENT ) {
284254 if ( width > spaceRight ) {
285- this . arrowElement . classList . add ( 'arrow-none' ) ;
286255 positionX = containerWidth - gutterSize - width ;
287256 enoughWidth = false ;
288257 }
289258 } else {
290259 width = Math . min ( width , spaceRight ) ;
291260 }
292- this . arrowElement . classList . add ( 'arrow-left' ) ;
293- arrowX = anchorBox . x + anchorBox . width + gutterSize ;
294261 }
295262
296263 positionY = Math . max ( gutterSize , Math . min ( anchorBox . y , containerHeight - height - gutterSize ) ) ;
297264 if ( ! enoughWidth ) {
298- positionY = Math . min ( positionY + arrowSize , containerHeight - height - gutterSize ) ;
299- } else if ( showArrow && positionY - arrowSize >= gutterSize ) {
300- positionY -= arrowSize ;
265+ positionY = Math . min ( positionY + offsetSize , containerHeight - height - gutterSize ) ;
266+ } else if ( positionY - offsetSize >= gutterSize ) {
267+ positionY -= offsetSize ;
301268 }
302269 height = Math . min ( height , containerHeight - positionY - gutterSize ) ;
303- if ( 2 * arrowSize >= height ) {
304- this . arrowElement . classList . add ( 'arrow-none' ) ;
305- } else {
306- let arrowY : number = anchorBox . y + Math . min ( 50 , Math . floor ( anchorBox . height / 2 ) ) ;
307- arrowY = Platform . NumberUtilities . clamp ( arrowY , positionY + arrowSize , positionY + height - arrowSize ) ;
308- this . arrowElement . positionAt ( arrowX , arrowY , container ) ;
309- }
310270 }
311271 } else {
312272 positionX = this . positionX !== null ? this . positionX : ( containerWidth - width ) / 2 ;
313273 positionY = this . positionY !== null ? this . positionY : ( containerHeight - height ) / 2 ;
314274 width = Math . min ( width , containerWidth - positionX - gutterSize ) ;
315275 height = Math . min ( height , containerHeight - positionY - gutterSize ) ;
316- this . arrowElement . classList . add ( 'arrow-none' ) ;
317276 }
318277
319278 this . contentElement . style . width = width + 'px' ;
0 commit comments