summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options/controlled_setting.js
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/resources/options/controlled_setting.js')
-rw-r--r--chrome/browser/resources/options/controlled_setting.js62
1 files changed, 59 insertions, 3 deletions
diff --git a/chrome/browser/resources/options/controlled_setting.js b/chrome/browser/resources/options/controlled_setting.js
index eafa7e3..6e2567e 100644
--- a/chrome/browser/resources/options/controlled_setting.js
+++ b/chrome/browser/resources/options/controlled_setting.js
@@ -15,14 +15,13 @@ cr.define('options', function() {
var ControlledSettingIndicator = cr.ui.define('span');
ControlledSettingIndicator.prototype = {
- __proto__: cr.ui.BubbleButton.prototype,
+ __proto__: HTMLSpanElement.prototype,
/**
* Decorates the base element to show the proper icon.
*/
decorate: function() {
- cr.ui.BubbleButton.prototype.decorate.call(this);
- this.classList.add('controlled-setting-indicator');
+ var self = this;
// If there is a pref, track its controlledBy and recommendedValue
// properties in order to be able to bring up the correct bubble.
@@ -31,6 +30,16 @@ cr.define('options', function() {
this.pref, this.handlePrefChange.bind(this));
this.resetHandler = this.clearAssociatedPref_;
}
+
+ this.className = 'controlled-setting-indicator';
+ this.location = cr.ui.ArrowLocation.TOP_END;
+ this.image = document.createElement('div');
+ this.image.tabIndex = 0;
+ this.image.setAttribute('role', 'button');
+ this.image.addEventListener('click', this);
+ this.image.addEventListener('keydown', this);
+ this.image.addEventListener('mousedown', this);
+ this.appendChild(this.image);
},
/**
@@ -44,6 +53,17 @@ cr.define('options', function() {
},
/**
+ * Whether the indicator is currently showing a bubble.
+ * @type {boolean}
+ */
+ get showingBubble() {
+ return this.image.classList.contains('showing-bubble');
+ },
+ set showingBubble(showing) {
+ this.image.classList.toggle('showing-bubble', showing);
+ },
+
+ /**
* Clears the preference associated with this indicator.
* @private
*/
@@ -71,6 +91,42 @@ cr.define('options', function() {
},
/**
+ * Handle mouse and keyboard events, allowing the user to open and close a
+ * bubble with further information.
+ * @param {Event} event Mouse or keyboard event.
+ */
+ handleEvent: function(event) {
+ switch (event.type) {
+ // Toggle the bubble on left click. Let any other clicks propagate.
+ case 'click':
+ if (event.button != 0)
+ return;
+ break;
+ // Toggle the bubble when <Return> or <Space> is pressed. Let any other
+ // key presses propagate.
+ case 'keydown':
+ switch (event.keyCode) {
+ case 13: // Return.
+ case 32: // Space.
+ break;
+ default:
+ return;
+ }
+ break;
+ // Blur focus when a mouse button is pressed, matching the behavior of
+ // other Web UI elements.
+ case 'mousedown':
+ if (document.activeElement)
+ document.activeElement.blur();
+ event.preventDefault();
+ return;
+ }
+ this.toggleBubble_();
+ event.preventDefault();
+ event.stopPropagation();
+ },
+
+ /**
* Open or close a bubble with further information about the pref.
* @private
*/