| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 * @private | 127 * @private |
| 128 */ | 128 */ |
| 129 handleSelfClick_: function(e) { | 129 handleSelfClick_: function(e) { |
| 130 // Allow clicking on [x] button. | 130 // Allow clicking on [x] button. |
| 131 if (e.target && e.target.classList.contains('close-button')) | 131 if (e.target && e.target.classList.contains('close-button')) |
| 132 return; | 132 return; |
| 133 e.stopPropagation(); | 133 e.stopPropagation(); |
| 134 }, | 134 }, |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * Sets the attachment of the bubble. |
| 138 * @param {!Attachment} attachment Bubble attachment. |
| 139 */ |
| 140 setAttachment_: function(attachment) { |
| 141 var styleClassList = ['bubble-right', 'bubble-left', |
| 142 'bubble-top', 'bubble-bottom']; |
| 143 for (var i = 0; i < styleClassList.length; ++i) |
| 144 this.classList.toggle(styleClassList[i], i == attachment); |
| 145 }, |
| 146 |
| 147 /** |
| 137 * Shows the bubble for given anchor element. | 148 * Shows the bubble for given anchor element. |
| 138 * @param {!Object} pos Bubble position (left, top, right, bottom in px). | 149 * @param {!Object} pos Bubble position (left, top, right, bottom in px). |
| 139 * @param {HTMLElement} opt_content Content to show in bubble. | 150 * @param {HTMLElement} opt_content Content to show in bubble. |
| 140 * If not specified, bubble element content is shown. | 151 * If not specified, bubble element content is shown. |
| 152 * @param {Attachment=} opt_attachment Bubble attachment (on which side of |
| 153 * the element it should be displayed). |
| 154 * @param {boolean=} opt_oldstyle Optional flag to force old style bubble, |
| 155 * i.e. pre-MD-style. |
| 141 * @private | 156 * @private |
| 142 */ | 157 */ |
| 143 showContentAt_: function(pos, opt_content) { | 158 showContentAt_: function(pos, opt_content, opt_attachment, opt_oldstyle) { |
| 144 this.style.top = this.style.left = this.style.right = this.style.bottom = | 159 this.style.top = this.style.left = this.style.right = this.style.bottom = |
| 145 'auto'; | 160 'auto'; |
| 146 for (var k in pos) { | 161 for (var k in pos) { |
| 147 if (typeof pos[k] == 'number') | 162 if (typeof pos[k] == 'number') |
| 148 this.style[k] = pos[k] + 'px'; | 163 this.style[k] = pos[k] + 'px'; |
| 149 } | 164 } |
| 150 if (opt_content !== undefined) | 165 if (opt_content !== undefined) |
| 151 this.replaceContent(opt_content); | 166 this.replaceContent(opt_content); |
| 152 | 167 |
| 168 if (opt_oldstyle) { |
| 169 this.setAttribute('oldstyle', ''); |
| 170 this.setAttachment_(opt_attachment); |
| 171 } |
| 172 |
| 153 this.hidden = false; | 173 this.hidden = false; |
| 154 this.classList.remove('faded'); | 174 this.classList.remove('faded'); |
| 155 }, | 175 }, |
| 156 | 176 |
| 157 /** | 177 /** |
| 158 * Replaces error message content with the given DOM element. | 178 * Replaces error message content with the given DOM element. |
| 159 * @param {HTMLElement} content Content to show in bubble. | 179 * @param {HTMLElement} content Content to show in bubble. |
| 160 */ | 180 */ |
| 161 replaceContent: function(content) { | 181 replaceContent: function(content) { |
| 162 this.innerHTML = ''; | 182 this.innerHTML = ''; |
| 163 this.appendChild(content); | 183 this.appendChild(content); |
| 164 }, | 184 }, |
| 165 | 185 |
| 166 /** | 186 /** |
| 167 * Shows the bubble for given anchor element. Bubble content is not cleared. | 187 * Shows the bubble for given anchor element. Bubble content is not cleared. |
| 168 * @param {!HTMLElement} el Anchor element of the bubble. | 188 * @param {!HTMLElement} el Anchor element of the bubble. |
| 169 * @param {!Attachment} attachment Bubble attachment (on which side of the | 189 * @param {!Attachment} attachment Bubble attachment (on which side of the |
| 170 * element it should be displayed). | 190 * element it should be displayed). |
| 171 * @param {number=} opt_offset Offset of the bubble. | 191 * @param {number=} opt_offset Offset of the bubble. |
| 172 * @param {number=} opt_padding Optional padding of the bubble. | 192 * @param {number=} opt_padding Optional padding of the bubble. |
| 173 */ | 193 */ |
| 174 showForElement: function(el, attachment, opt_offset, opt_padding) { | 194 showForElement: function(el, attachment, opt_offset, opt_padding) { |
| 195 /* showForElement() is used only to display Accessibility popup in |
| 196 * oobe_screen_network*. It requires old-style bubble, so it is safe |
| 197 * to always set this flag here. |
| 198 */ |
| 175 this.showContentForElement( | 199 this.showContentForElement( |
| 176 el, attachment, undefined, opt_offset, opt_padding); | 200 el, attachment, undefined, opt_offset, opt_padding, undefined, true); |
| 177 }, | 201 }, |
| 178 | 202 |
| 179 /** | 203 /** |
| 180 * Shows the bubble for given anchor element. | 204 * Shows the bubble for given anchor element. |
| 181 * @param {!HTMLElement} el Anchor element of the bubble. | 205 * @param {!HTMLElement} el Anchor element of the bubble. |
| 182 * @param {!Attachment} attachment Bubble attachment (on which side of the | 206 * @param {!Attachment} attachment Bubble attachment (on which side of the |
| 183 * element it should be displayed). | 207 * element it should be displayed). |
| 184 * @param {HTMLElement} opt_content Content to show in bubble. | 208 * @param {HTMLElement} opt_content Content to show in bubble. |
| 185 * If not specified, bubble element content is shown. | 209 * If not specified, bubble element content is shown. |
| 186 * @param {number=} opt_offset Offset of the bubble attachment point from | 210 * @param {number=} opt_offset Offset of the bubble attachment point from |
| 187 * left (for vertical attachment) or top (for horizontal attachment) | 211 * left (for vertical attachment) or top (for horizontal attachment) |
| 188 * side of the element. If not specified, the bubble is positioned to | 212 * side of the element. If not specified, the bubble is positioned to |
| 189 * be aligned with the left/top side of the element but not farther than | 213 * be aligned with the left/top side of the element but not farther than |
| 190 * half of its width/height. | 214 * half of its width/height. |
| 191 * @param {number=} opt_padding Optional padding of the bubble. | 215 * @param {number=} opt_padding Optional padding of the bubble. |
| 192 * @param {boolean=} opt_match_width Optional flag to force the bubble have | 216 * @param {boolean=} opt_match_width Optional flag to force the bubble have |
| 193 * the same width as the element it it attached to. | 217 * the same width as the element it it attached to. |
| 218 * @param {boolean=} opt_oldstyle Optional flag to force old style bubble, |
| 219 * i.e. pre-MD-style. |
| 194 */ | 220 */ |
| 195 showContentForElement: function(el, attachment, opt_content, | 221 showContentForElement: function(el, attachment, opt_content, |
| 196 opt_offset, opt_padding, opt_match_width) { | 222 opt_offset, opt_padding, opt_match_width, |
| 223 opt_oldstyle) { |
| 197 /** @const */ var ARROW_OFFSET = 25; | 224 /** @const */ var ARROW_OFFSET = 25; |
| 198 /** @const */ var DEFAULT_PADDING = 18; | 225 /** @const */ var DEFAULT_PADDING = 18; |
| 199 | 226 |
| 200 if (opt_padding == undefined) | 227 if (opt_padding == undefined) |
| 201 opt_padding = DEFAULT_PADDING; | 228 opt_padding = DEFAULT_PADDING; |
| 202 opt_padding += 10; | 229 |
| 230 if (!opt_oldstyle) |
| 231 opt_padding += 10; |
| 203 | 232 |
| 204 var origin = cr.ui.login.DisplayManager.getPosition(el); | 233 var origin = cr.ui.login.DisplayManager.getPosition(el); |
| 205 var offset = opt_offset == undefined ? | 234 var offset = opt_offset == undefined ? |
| 206 [Math.min(ARROW_OFFSET, el.offsetWidth / 2), | 235 [Math.min(ARROW_OFFSET, el.offsetWidth / 2), |
| 207 Math.min(ARROW_OFFSET, el.offsetHeight / 2)] : | 236 Math.min(ARROW_OFFSET, el.offsetHeight / 2)] : |
| 208 [opt_offset, opt_offset]; | 237 [opt_offset, opt_offset]; |
| 209 | 238 |
| 210 var pos = {}; | 239 var pos = {}; |
| 211 if (isRTL()) { | 240 if (isRTL()) { |
| 212 switch (attachment) { | 241 switch (attachment) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 var paddingLeft = parseInt(window.getComputedStyle(this, null) | 285 var paddingLeft = parseInt(window.getComputedStyle(this, null) |
| 257 .getPropertyValue('padding-left')); | 286 .getPropertyValue('padding-left')); |
| 258 var paddingRight = parseInt(window.getComputedStyle(this, null) | 287 var paddingRight = parseInt(window.getComputedStyle(this, null) |
| 259 .getPropertyValue('padding-right')); | 288 .getPropertyValue('padding-right')); |
| 260 if (elWidth) | 289 if (elWidth) |
| 261 this.style.width = | 290 this.style.width = |
| 262 (parseInt(elWidth) - paddingLeft - paddingRight) + 'px'; | 291 (parseInt(elWidth) - paddingLeft - paddingRight) + 'px'; |
| 263 } | 292 } |
| 264 | 293 |
| 265 this.anchor_ = el; | 294 this.anchor_ = el; |
| 266 this.showContentAt_(pos, opt_content); | 295 this.showContentAt_(pos, opt_content, attachment, opt_oldstyle); |
| 267 }, | 296 }, |
| 268 | 297 |
| 269 /** | 298 /** |
| 270 * Shows the bubble for given anchor element. | 299 * Shows the bubble for given anchor element. |
| 271 * @param {!HTMLElement} el Anchor element of the bubble. | 300 * @param {!HTMLElement} el Anchor element of the bubble. |
| 272 * @param {string} text Text content to show in bubble. | 301 * @param {string} text Text content to show in bubble. |
| 273 * @param {!Attachment} attachment Bubble attachment (on which side of the | 302 * @param {!Attachment} attachment Bubble attachment (on which side of the |
| 274 * element it should be displayed). | 303 * element it should be displayed). |
| 275 * @param {number=} opt_offset Offset of the bubble attachment point from | 304 * @param {number=} opt_offset Offset of the bubble attachment point from |
| 276 * left (for vertical attachment) or top (for horizontal attachment) | 305 * left (for vertical attachment) or top (for horizontal attachment) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 handleWindowBlur_: function(e) { | 405 handleWindowBlur_: function(e) { |
| 377 if (!this.hidden) | 406 if (!this.hidden) |
| 378 this.hide(); | 407 this.hide(); |
| 379 } | 408 } |
| 380 }; | 409 }; |
| 381 | 410 |
| 382 return { | 411 return { |
| 383 Bubble: Bubble | 412 Bubble: Bubble |
| 384 }; | 413 }; |
| 385 }); | 414 }); |
| OLD | NEW |