Chromium Code Reviews| 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 Polymer({ | 5 Polymer({ |
| 6 is: 'cr-action-menu', | 6 is: 'cr-action-menu', |
| 7 extends: 'dialog', | 7 extends: 'dialog', |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * List of all options in this action menu. | 10 * List of all options in this action menu. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 * @param {!Element} anchorElement | 123 * @param {!Element} anchorElement |
| 124 */ | 124 */ |
| 125 showAt: function(anchorElement) { | 125 showAt: function(anchorElement) { |
| 126 this.anchorElement_ = anchorElement; | 126 this.anchorElement_ = anchorElement; |
| 127 this.onWindowResize_ = this.onWindowResize_ || function() { | 127 this.onWindowResize_ = this.onWindowResize_ || function() { |
| 128 if (this.open) | 128 if (this.open) |
| 129 this.close(); | 129 this.close(); |
| 130 }.bind(this); | 130 }.bind(this); |
| 131 window.addEventListener('resize', this.onWindowResize_); | 131 window.addEventListener('resize', this.onWindowResize_); |
| 132 | 132 |
| 133 // Reset position to prevent previous values from affecting layout. | |
| 134 this.style.left = ''; | |
| 135 this.style.right = ''; | |
| 136 this.style.top = ''; | |
| 137 | |
| 133 this.showModal(); | 138 this.showModal(); |
| 134 | 139 |
| 135 var rect = this.anchorElement_.getBoundingClientRect(); | 140 var rect = this.anchorElement_.getBoundingClientRect(); |
|
dpapad
2017/01/06 16:34:49
I don't fully understand this fix. Per my own debu
dpapad
2017/01/12 18:52:54
Per explanation at https://bugs.chromium.org/p/chr
| |
| 136 if (getComputedStyle(this.anchorElement_).direction == 'rtl') { | 141 if (getComputedStyle(this.anchorElement_).direction == 'rtl') { |
| 137 var right = window.innerWidth - rect.left - this.offsetWidth; | 142 var right = window.innerWidth - rect.left - this.offsetWidth; |
| 138 this.style.right = right + 'px'; | 143 this.style.right = right + 'px'; |
| 139 } else { | 144 } else { |
| 140 var left = rect.right - this.offsetWidth; | 145 var left = rect.right - this.offsetWidth; |
| 141 this.style.left = left + 'px'; | 146 this.style.left = left + 'px'; |
| 142 } | 147 } |
| 143 | 148 |
| 144 // Attempt to show the menu starting from the top of the rectangle and | 149 // Attempt to show the menu starting from the top of the rectangle and |
| 145 // extending downwards. If that does not fit within the window, fallback to | 150 // extending downwards. If that does not fit within the window, fallback to |
| 146 // starting from the bottom and extending upwards. | 151 // starting from the bottom and extending upwards. |
| 147 var top = rect.top + this.offsetHeight <= window.innerHeight ? rect.top : | 152 var top = rect.top + this.offsetHeight <= window.innerHeight ? rect.top : |
| 148 rect.bottom - | 153 rect.bottom - |
| 149 this.offsetHeight - Math.max(rect.bottom - window.innerHeight, 0); | 154 this.offsetHeight - Math.max(rect.bottom - window.innerHeight, 0); |
| 150 | 155 |
| 151 this.style.top = top + 'px'; | 156 this.style.top = top + 'px'; |
| 152 }, | 157 }, |
| 153 }); | 158 }); |
| OLD | NEW |