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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 this.close(); | 166 this.close(); |
167 }.bind(this); | 167 }.bind(this); |
168 window.addEventListener('resize', this.boundClose_); | 168 window.addEventListener('resize', this.boundClose_); |
169 window.addEventListener('popstate', this.boundClose_); | 169 window.addEventListener('popstate', this.boundClose_); |
170 | 170 |
171 // Reset position to prevent previous values from affecting layout. | 171 // Reset position to prevent previous values from affecting layout. |
172 this.style.left = ''; | 172 this.style.left = ''; |
173 this.style.right = ''; | 173 this.style.right = ''; |
174 this.style.top = ''; | 174 this.style.top = ''; |
175 | 175 |
| 176 this.anchorElement_.scrollIntoViewIfNeeded(); |
176 this.showModal(); | 177 this.showModal(); |
177 | 178 |
178 var rect = this.anchorElement_.getBoundingClientRect(); | 179 var rect = this.anchorElement_.getBoundingClientRect(); |
179 if (getComputedStyle(this.anchorElement_).direction == 'rtl') { | 180 if (getComputedStyle(this.anchorElement_).direction == 'rtl') { |
180 var right = window.innerWidth - rect.left - this.offsetWidth; | 181 var right = window.innerWidth - rect.left - this.offsetWidth; |
181 this.style.right = right + 'px'; | 182 this.style.right = right + 'px'; |
182 } else { | 183 } else { |
183 var left = rect.right - this.offsetWidth; | 184 var left = rect.right - this.offsetWidth; |
184 this.style.left = left + 'px'; | 185 this.style.left = left + 'px'; |
185 } | 186 } |
186 | 187 |
187 // Attempt to show the menu starting from the top of the rectangle and | 188 // Attempt to show the menu starting from the top of the rectangle and |
188 // extending downwards. If that does not fit within the window, fallback to | 189 // extending downwards. If that does not fit within the window, fallback to |
189 // starting from the bottom and extending upwards. | 190 // starting from the bottom and extending upwards. |
190 var top = rect.top + this.offsetHeight <= window.innerHeight ? rect.top : | 191 var top = rect.top + this.offsetHeight <= window.innerHeight ? rect.top : |
191 rect.bottom - | 192 rect.bottom - |
192 this.offsetHeight - Math.max(rect.bottom - window.innerHeight, 0); | 193 this.offsetHeight - Math.max(rect.bottom - window.innerHeight, 0); |
193 | 194 |
194 this.style.top = top + 'px'; | 195 this.style.top = top + 'px'; |
195 }, | 196 }, |
196 }); | 197 }); |
OLD | NEW |