Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: ui/login/bubble.js

Issue 2283583003: [ash-md] Updates web-ui tooltips to MD (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/login/bubble.css ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 */ 21 */
22 var Keys = { 22 var Keys = {
23 TAB: 'Tab', 23 TAB: 'Tab',
24 ENTER: 'Enter', 24 ENTER: 'Enter',
25 ESC: 'Escape', 25 ESC: 'Escape',
26 SPACE: ' ' 26 SPACE: ' '
27 }; 27 };
28 28
29 /** 29 /**
30 * Bubble attachment side. 30 * Bubble attachment side.
31 * @enum {string} 31 * @enum {number}
32 */ 32 */
33 Bubble.Attachment = { 33 Bubble.Attachment = {
34 RIGHT: 'bubble-right', 34 RIGHT: 0,
35 LEFT: 'bubble-left', 35 LEFT: 1,
36 TOP: 'bubble-top', 36 TOP: 2,
37 BOTTOM: 'bubble-bottom' 37 BOTTOM: 3
38 }; 38 };
39 39
40 Bubble.prototype = { 40 Bubble.prototype = {
41 __proto__: HTMLDivElement.prototype, 41 __proto__: HTMLDivElement.prototype,
42 42
43 // Anchor element for this bubble. 43 // Anchor element for this bubble.
44 anchor_: undefined, 44 anchor_: undefined,
45 45
46 // If defined, sets focus to this element once bubble is closed. Focus is 46 // If defined, sets focus to this element once bubble is closed. Focus is
47 // set to this element only if there's no any other focused element. 47 // set to this element only if there's no any other focused element.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 for (var k in Bubble.Attachment) {
142 var v = Bubble.Attachment[k];
143 this.classList.toggle(v, v == attachment);
144 }
145 },
146
147 /**
148 * Shows the bubble for given anchor element. 137 * Shows the bubble for given anchor element.
149 * @param {!Object} pos Bubble position (left, top, right, bottom in px). 138 * @param {!Object} pos Bubble position (left, top, right, bottom in px).
150 * @param {!Attachment} attachment Bubble attachment (on which side of the
151 * specified position it should be displayed).
152 * @param {HTMLElement} opt_content Content to show in bubble. 139 * @param {HTMLElement} opt_content Content to show in bubble.
153 * If not specified, bubble element content is shown. 140 * If not specified, bubble element content is shown.
154 * @private 141 * @private
155 */ 142 */
156 showContentAt_: function(pos, attachment, opt_content) { 143 showContentAt_: function(pos, opt_content) {
157 this.style.top = this.style.left = this.style.right = this.style.bottom = 144 this.style.top = this.style.left = this.style.right = this.style.bottom =
158 'auto'; 145 'auto';
159 for (var k in pos) { 146 for (var k in pos) {
160 if (typeof pos[k] == 'number') 147 if (typeof pos[k] == 'number')
161 this.style[k] = pos[k] + 'px'; 148 this.style[k] = pos[k] + 'px';
162 } 149 }
163 if (opt_content !== undefined) { 150 if (opt_content !== undefined) {
164 this.innerHTML = ''; 151 this.innerHTML = '';
165 this.appendChild(opt_content); 152 this.appendChild(opt_content);
166 } 153 }
167 this.setAttachment_(attachment);
168 this.hidden = false; 154 this.hidden = false;
169 this.classList.remove('faded'); 155 this.classList.remove('faded');
170 }, 156 },
171 157
172 /** 158 /**
173 * Shows the bubble for given anchor element. Bubble content is not cleared. 159 * Shows the bubble for given anchor element. Bubble content is not cleared.
174 * @param {!HTMLElement} el Anchor element of the bubble. 160 * @param {!HTMLElement} el Anchor element of the bubble.
175 * @param {!Attachment} attachment Bubble attachment (on which side of the 161 * @param {!Attachment} attachment Bubble attachment (on which side of the
176 * element it should be displayed). 162 * element it should be displayed).
177 * @param {number=} opt_offset Offset of the bubble. 163 * @param {number=} opt_offset Offset of the bubble.
(...skipping 18 matching lines...) Expand all
196 * half of its width/height. 182 * half of its width/height.
197 * @param {number=} opt_padding Optional padding of the bubble. 183 * @param {number=} opt_padding Optional padding of the bubble.
198 */ 184 */
199 showContentForElement: function(el, attachment, opt_content, 185 showContentForElement: function(el, attachment, opt_content,
200 opt_offset, opt_padding) { 186 opt_offset, opt_padding) {
201 /** @const */ var ARROW_OFFSET = 25; 187 /** @const */ var ARROW_OFFSET = 25;
202 /** @const */ var DEFAULT_PADDING = 18; 188 /** @const */ var DEFAULT_PADDING = 18;
203 189
204 if (opt_padding == undefined) 190 if (opt_padding == undefined)
205 opt_padding = DEFAULT_PADDING; 191 opt_padding = DEFAULT_PADDING;
192 opt_padding += 10;
206 193
207 var origin = cr.ui.login.DisplayManager.getPosition(el); 194 var origin = cr.ui.login.DisplayManager.getPosition(el);
208 var offset = opt_offset == undefined ? 195 var offset = opt_offset == undefined ?
209 [Math.min(ARROW_OFFSET, el.offsetWidth / 2), 196 [Math.min(ARROW_OFFSET, el.offsetWidth / 2),
210 Math.min(ARROW_OFFSET, el.offsetHeight / 2)] : 197 Math.min(ARROW_OFFSET, el.offsetHeight / 2)] :
211 [opt_offset, opt_offset]; 198 [opt_offset, opt_offset];
212 199
213 var pos = {}; 200 var pos = {};
214 if (isRTL()) { 201 if (isRTL()) {
215 switch (attachment) { 202 switch (attachment) {
(...skipping 29 matching lines...) Expand all
245 pos.top = origin.top + el.offsetHeight + opt_padding; 232 pos.top = origin.top + el.offsetHeight + opt_padding;
246 break; 233 break;
247 case Bubble.Attachment.LEFT: 234 case Bubble.Attachment.LEFT:
248 pos.top = origin.top + offset[1] - ARROW_OFFSET; 235 pos.top = origin.top + offset[1] - ARROW_OFFSET;
249 pos.right = origin.right + el.offsetWidth + opt_padding; 236 pos.right = origin.right + el.offsetWidth + opt_padding;
250 break; 237 break;
251 } 238 }
252 } 239 }
253 240
254 this.anchor_ = el; 241 this.anchor_ = el;
255 this.showContentAt_(pos, attachment, opt_content); 242 this.showContentAt_(pos, opt_content);
256 }, 243 },
257 244
258 /** 245 /**
259 * Shows the bubble for given anchor element. 246 * Shows the bubble for given anchor element.
260 * @param {!HTMLElement} el Anchor element of the bubble. 247 * @param {!HTMLElement} el Anchor element of the bubble.
261 * @param {string} text Text content to show in bubble. 248 * @param {string} text Text content to show in bubble.
262 * @param {!Attachment} attachment Bubble attachment (on which side of the 249 * @param {!Attachment} attachment Bubble attachment (on which side of the
263 * element it should be displayed). 250 * element it should be displayed).
264 * @param {number=} opt_offset Offset of the bubble attachment point from 251 * @param {number=} opt_offset Offset of the bubble attachment point from
265 * left (for vertical attachment) or top (for horizontal attachment) 252 * left (for vertical attachment) or top (for horizontal attachment)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 handleWindowBlur_: function(e) { 352 handleWindowBlur_: function(e) {
366 if (!this.hidden) 353 if (!this.hidden)
367 this.hide(); 354 this.hide();
368 } 355 }
369 }; 356 };
370 357
371 return { 358 return {
372 Bubble: Bubble 359 Bubble: Bubble
373 }; 360 };
374 }); 361 });
OLDNEW
« no previous file with comments | « ui/login/bubble.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698