| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 Bubble implementation. | 6 * @fileoverview Bubble implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 // TODO(xiyuan): Move this into shared. | 9 // TODO(xiyuan): Move this into shared. |
| 10 cr.define('cr.ui', function() { | 10 cr.define('cr.ui', function() { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 * @param {HTMLElement} opt_content Content to show in bubble. | 176 * @param {HTMLElement} opt_content Content to show in bubble. |
| 177 * If not specified, bubble element content is shown. | 177 * If not specified, bubble element content is shown. |
| 178 * @param {number=} opt_offset Offset of the bubble attachment point from | 178 * @param {number=} opt_offset Offset of the bubble attachment point from |
| 179 * left (for vertical attachment) or top (for horizontal attachment) | 179 * left (for vertical attachment) or top (for horizontal attachment) |
| 180 * side of the element. If not specified, the bubble is positioned to | 180 * side of the element. If not specified, the bubble is positioned to |
| 181 * be aligned with the left/top side of the element but not farther than | 181 * be aligned with the left/top side of the element but not farther than |
| 182 * half of its width/height. | 182 * half of its width/height. |
| 183 * @param {number=} opt_padding Optional padding of the bubble. | 183 * @param {number=} opt_padding Optional padding of the bubble. |
| 184 */ | 184 */ |
| 185 showContentForElement: function(el, attachment, opt_content, | 185 showContentForElement: function(el, attachment, opt_content, |
| 186 opt_offset, opt_padding) { | 186 opt_offset, opt_padding, opt_match_width) { |
| 187 /** @const */ var ARROW_OFFSET = 25; | 187 /** @const */ var ARROW_OFFSET = 0; |
| 188 /** @const */ var DEFAULT_PADDING = 18; | 188 /** @const */ var DEFAULT_PADDING = 18; |
| 189 | 189 |
| 190 if (opt_padding == undefined) | 190 if (opt_padding == undefined) |
| 191 opt_padding = DEFAULT_PADDING; | 191 opt_padding = DEFAULT_PADDING; |
| 192 opt_padding += 10; | 192 opt_padding += 10; |
| 193 | 193 |
| 194 var origin = cr.ui.login.DisplayManager.getPosition(el); | 194 var origin = cr.ui.login.DisplayManager.getPosition(el); |
| 195 var offset = opt_offset == undefined ? | 195 var offset = opt_offset == undefined ? |
| 196 [Math.min(ARROW_OFFSET, el.offsetWidth / 2), | 196 [Math.min(ARROW_OFFSET, el.offsetWidth / 2), |
| 197 Math.min(ARROW_OFFSET, el.offsetHeight / 2)] : | 197 Math.min(ARROW_OFFSET, el.offsetHeight / 2)] : |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 case Bubble.Attachment.BOTTOM: | 230 case Bubble.Attachment.BOTTOM: |
| 231 pos.left = origin.left + offset[0] - ARROW_OFFSET; | 231 pos.left = origin.left + offset[0] - ARROW_OFFSET; |
| 232 pos.top = origin.top + el.offsetHeight + opt_padding; | 232 pos.top = origin.top + el.offsetHeight + opt_padding; |
| 233 break; | 233 break; |
| 234 case Bubble.Attachment.LEFT: | 234 case Bubble.Attachment.LEFT: |
| 235 pos.top = origin.top + offset[1] - ARROW_OFFSET; | 235 pos.top = origin.top + offset[1] - ARROW_OFFSET; |
| 236 pos.right = origin.right + el.offsetWidth + opt_padding; | 236 pos.right = origin.right + el.offsetWidth + opt_padding; |
| 237 break; | 237 break; |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 this.style.width = ''; |
| 241 this.removeAttribute('match-width'); |
| 242 if (opt_match_width) { |
| 243 this.setAttribute('match-width', ''); |
| 244 var el_width = window.getComputedStyle(el, null).getPropertyValue('width
'); |
| 245 var padding_left = parseInt(window.getComputedStyle(this, null).getPrope
rtyValue('padding-left')); |
| 246 var padding_right = parseInt(window.getComputedStyle(this, null).getProp
ertyValue('padding-right')); |
| 247 if (el_width) |
| 248 this.style.width = (parseInt(el_width) - padding_left - padding_right)
+ 'px'; |
| 249 } |
| 240 | 250 |
| 241 this.anchor_ = el; | 251 this.anchor_ = el; |
| 242 this.showContentAt_(pos, opt_content); | 252 this.showContentAt_(pos, opt_content); |
| 243 }, | 253 }, |
| 244 | 254 |
| 245 /** | 255 /** |
| 246 * Shows the bubble for given anchor element. | 256 * Shows the bubble for given anchor element. |
| 247 * @param {!HTMLElement} el Anchor element of the bubble. | 257 * @param {!HTMLElement} el Anchor element of the bubble. |
| 248 * @param {string} text Text content to show in bubble. | 258 * @param {string} text Text content to show in bubble. |
| 249 * @param {!Attachment} attachment Bubble attachment (on which side of the | 259 * @param {!Attachment} attachment Bubble attachment (on which side of the |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 handleWindowBlur_: function(e) { | 362 handleWindowBlur_: function(e) { |
| 353 if (!this.hidden) | 363 if (!this.hidden) |
| 354 this.hide(); | 364 this.hide(); |
| 355 } | 365 } |
| 356 }; | 366 }; |
| 357 | 367 |
| 358 return { | 368 return { |
| 359 Bubble: Bubble | 369 Bubble: Bubble |
| 360 }; | 370 }; |
| 361 }); | 371 }); |
| OLD | NEW |