OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
6 * @typedef {{ | 6 * @typedef {{ |
7 * top: number, | 7 * top: number, |
8 * left: number, | 8 * left: number, |
9 * width: (number|undefined), | 9 * width: (number|undefined), |
10 * height: (number|undefined), | 10 * height: (number|undefined), |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 (function() { | 33 (function() { |
34 /** | 34 /** |
35 * Returns the point to start along the X or Y axis given a start and end | 35 * Returns the point to start along the X or Y axis given a start and end |
36 * point to anchor to, the length of the target and the direction to anchor | 36 * point to anchor to, the length of the target and the direction to anchor |
37 * in. If honoring the anchor would force the menu outside of min/max, this | 37 * in. If honoring the anchor would force the menu outside of min/max, this |
38 * will ignore the anchor position and try to keep the menu within min/max. | 38 * will ignore the anchor position and try to keep the menu within min/max. |
39 * @private | 39 * @private |
40 * @param {number} start | 40 * @param {number} start |
41 * @param {number} end | 41 * @param {number} end |
42 * @param {number} length | 42 * @param {number} menuLength |
43 * @param {AnchorAlignment} anchorAlignment | 43 * @param {AnchorAlignment} anchorAlignment |
44 * @param {number} min | 44 * @param {number} min |
45 * @param {number} max | 45 * @param {number} max |
46 * @return {number} | 46 * @return {number} |
47 */ | 47 */ |
48 function getStartPointWithAnchor( | 48 function getStartPointWithAnchor( |
49 start, end, length, anchorAlignment, min, max) { | 49 start, end, menuLength, anchorAlignment, min, max) { |
50 var startPoint = 0; | 50 var startPoint = 0; |
51 switch (anchorAlignment) { | 51 switch (anchorAlignment) { |
52 case AnchorAlignment.BEFORE_START: | 52 case AnchorAlignment.BEFORE_START: |
53 startPoint = -length; | 53 startPoint = -menuLength; |
54 break; | 54 break; |
55 case AnchorAlignment.AFTER_START: | 55 case AnchorAlignment.AFTER_START: |
56 startPoint = start; | 56 startPoint = start; |
57 break; | 57 break; |
58 case AnchorAlignment.CENTER: | 58 case AnchorAlignment.CENTER: |
59 startPoint = (start + end - length) / 2; | 59 startPoint = (start + end - menuLength) / 2; |
60 break; | 60 break; |
61 case AnchorAlignment.BEFORE_END: | 61 case AnchorAlignment.BEFORE_END: |
62 startPoint = end - length; | 62 startPoint = end - menuLength; |
63 break; | 63 break; |
64 case AnchorAlignment.AFTER_END: | 64 case AnchorAlignment.AFTER_END: |
65 startPoint = end; | 65 startPoint = end; |
66 break; | 66 break; |
67 } | 67 } |
68 | 68 |
69 if (startPoint + length > max) | 69 if (startPoint + menuLength > max) |
70 startPoint = end - length; | 70 startPoint = end - menuLength; |
71 if (startPoint < min) | 71 if (startPoint < min) |
72 startPoint = start; | 72 startPoint = start; |
| 73 |
| 74 startPoint = Math.max(min, Math.min(startPoint, max - menuLength)); |
| 75 |
73 return startPoint; | 76 return startPoint; |
74 } | 77 } |
75 | 78 |
76 /** | 79 /** |
77 * @private | 80 * @private |
78 * @return {!ShowConfig} | 81 * @return {!ShowConfig} |
79 */ | 82 */ |
80 function getDefaultShowConfig() { | 83 function getDefaultShowConfig() { |
81 return { | 84 return { |
82 top: 0, | 85 top: 0, |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 addCloseListeners_: function() { | 366 addCloseListeners_: function() { |
364 this.boundClose_ = this.boundClose_ || function() { | 367 this.boundClose_ = this.boundClose_ || function() { |
365 if (this.open) | 368 if (this.open) |
366 this.close(); | 369 this.close(); |
367 }.bind(this); | 370 }.bind(this); |
368 window.addEventListener('resize', this.boundClose_); | 371 window.addEventListener('resize', this.boundClose_); |
369 window.addEventListener('popstate', this.boundClose_); | 372 window.addEventListener('popstate', this.boundClose_); |
370 }, | 373 }, |
371 }); | 374 }); |
372 })(); | 375 })(); |
OLD | NEW |