OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 * @fileoverview This file provides utility functions for position popups. | 6 * @fileoverview This file provides utility functions for position popups. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('cr.ui', function() { | 9 cr.define('cr.ui', function() { |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 }; | 50 }; |
51 | 51 |
52 /** | 52 /** |
53 * Helper function for positionPopupAroundElement and positionPopupAroundRect. | 53 * Helper function for positionPopupAroundElement and positionPopupAroundRect. |
54 * @param {!Rect} anchorRect The rect for the anchor. | 54 * @param {!Rect} anchorRect The rect for the anchor. |
55 * @param {!HTMLElement} popupElement The element used for the popup. | 55 * @param {!HTMLElement} popupElement The element used for the popup. |
56 * @param {AnchorType} type The type of anchoring to do. | 56 * @param {AnchorType} type The type of anchoring to do. |
57 */ | 57 */ |
58 function positionPopupAroundRect(anchorRect, popupElement, type) { | 58 function positionPopupAroundRect(anchorRect, popupElement, type) { |
59 var popupRect = popupElement.getBoundingClientRect(); | 59 var popupRect = popupElement.getBoundingClientRect(); |
60 var popupContainer = popupElement.offsetParent; | 60 var popupContainer; |
| 61 var cs = popupElement.ownerDocument.defaultView. |
| 62 getComputedStyle(popupElement); |
| 63 if (cs.position == 'fixed') |
| 64 popupContainer = popupElement.ownerDocument.body; |
| 65 else |
| 66 popupContainer = popupElement.offsetParent; |
61 var availRect = popupContainer.getBoundingClientRect(); | 67 var availRect = popupContainer.getBoundingClientRect(); |
62 var rtl = popupElement.ownerDocument.defaultView. | 68 var rtl = cs.direction == 'rtl'; |
63 getComputedStyle(popupElement).direction == 'rtl'; | |
64 | 69 |
65 // Flip BEFORE, AFTER based on RTL. | 70 // Flip BEFORE, AFTER based on RTL. |
66 if (rtl) { | 71 if (rtl) { |
67 if (type == AnchorType.BEFORE) | 72 if (type == AnchorType.BEFORE) |
68 type = AnchorType.AFTER; | 73 type = AnchorType.AFTER; |
69 else if (type == AnchorType.AFTER) | 74 else if (type == AnchorType.AFTER) |
70 type = AnchorType.BEFORE; | 75 type = AnchorType.BEFORE; |
71 } | 76 } |
72 | 77 |
73 // Flip type based on available size | 78 // Flip type based on available size |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 positionPopupAroundRect(rect, popupElement, AnchorType.BELOW); | 219 positionPopupAroundRect(rect, popupElement, AnchorType.BELOW); |
215 } | 220 } |
216 | 221 |
217 // Export | 222 // Export |
218 return { | 223 return { |
219 AnchorType: AnchorType, | 224 AnchorType: AnchorType, |
220 positionPopupAroundElement: positionPopupAroundElement, | 225 positionPopupAroundElement: positionPopupAroundElement, |
221 positionPopupAtPoint: positionPopupAtPoint | 226 positionPopupAtPoint: positionPopupAtPoint |
222 }; | 227 }; |
223 }); | 228 }); |
OLD | NEW |