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

Side by Side Diff: chrome/browser/resources/options/options_bubble.js

Issue 10907148: Implement popup bubbles for the controlled setting indicator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: All comments addressed. Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('options', function() {
6 var BubbleBase = cr.ui.BubbleBase;
7
8 var OptionsBubble = cr.ui.define('div');
9
10 OptionsBubble.prototype = {
11 // Set up the prototype chain.
12 __proto__: BubbleBase.prototype,
13
14 /**
15 * Initialization function for the cr.ui framework.
16 */
17 decorate: function() {
18 BubbleBase.prototype.decorate.call(this);
19 this.classList.add('options-bubble');
20 },
21
22 /**
23 * Show the bubble.
24 */
25 show: function() {
26 if (!this.hidden)
27 return;
28
29 BubbleBase.prototype.show.call(this);
30
31 var doc = this.ownerDocument;
32 this.eventTracker_.add(doc, 'mousewheel', this, true);
33 this.eventTracker_.add(doc, 'scroll', this, true);
34 this.eventTracker_.add(doc, 'elementFocused', this, true);
35 this.eventTracker_.add(window, 'resize', this);
36 },
37
38 /**
39 * Handle events, closing the bubble when the user clicks or moves the focus
40 * outside the bubble and its anchor elements, scrolls the underlying
41 * document or resizes the window.
42 * @param {Event} event The event.
43 */
44 handleEvent: function(event) {
45 BubbleBase.prototype.handleEvent.call(this, event);
46
47 switch (event.type) {
48 // Close the bubble when the user clicks outside it, except if it is a
49 // left-click on the anchor element (allowing the anchor to handle the
50 // event and close the bubble itself).
51 case 'mousedown':
52 if (event.button == 0 && this.anchorNode_.contains(event.target))
53 break;
54 // Close the bubble when the underlying document is scrolled.
55 case 'mousewheel':
56 case 'scroll':
57 if (this.contains(event.target))
58 break;
59 // Close the bubble when the window is resized.
60 case 'resize':
61 this.hide();
62 break;
63 // Close the bubble when the focus moves to an element that is not the
64 // anchor and is not inside the bubble.
65 case 'elementFocused':
66 if (!this.anchorNode_.contains(event.target) &&
67 !this.contains(event.target)) {
68 this.hide();
69 }
70 break;
71 }
72 },
73
74 /**
75 * Attach the bubble to the document's DOM, making it a sibling of the
76 * anchor element so that focusable elements inside the bubble follow the
77 * anchor in the document's tab order.
78 * @private
79 */
80 attachToDOM_: function() {
81 var parent = this.anchorNode_.parentNode;
82 parent.insertBefore(this, this.anchorNode_.nextSibling);
83 },
84 };
85
86 return {
87 OptionsBubble: OptionsBubble
88 };
89 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/options.html ('k') | chrome/browser/resources/options/options_bundle.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698