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

Unified Diff: chrome/browser/resources/options/controlled_setting.js

Issue 8480037: Controlled settings indicator and bubble for chrome://preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Explain propagation. Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/theme/theme_resources.grd ('k') | chrome/browser/resources/options/options.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/options/controlled_setting.js
diff --git a/chrome/browser/resources/options/controlled_setting.js b/chrome/browser/resources/options/controlled_setting.js
new file mode 100644
index 0000000000000000000000000000000000000000..77ef806625ffd495b80d6b50b6467b8c7f753989
--- /dev/null
+++ b/chrome/browser/resources/options/controlled_setting.js
@@ -0,0 +1,127 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('options', function() {
+
+ var Preferences = options.Preferences;
+
+ /**
+ * A controlled setting indicator that can be placed on a setting as an
+ * indicator that the value is controlled by some external entity such as
+ * policy or an extension.
+ * @constructor
+ * @extends {HTMLSpanElement}
+ */
+ var ControlledSettingIndicator = cr.ui.define('span');
+
+ ControlledSettingIndicator.prototype = {
+ __proto__: HTMLSpanElement.prototype,
+
+ /**
+ * Decorates the base element to show the proper icon.
+ */
+ decorate: function() {
+ var self = this;
+
+ // If there is a pref, track its controlledBy property in order to be able
+ // to bring up the correct bubble.
+ if (this.hasAttribute('pref')) {
+ Preferences.getInstance().addEventListener(
+ this.getAttribute('pref'),
+ function(event) {
+ if (event.value && event.value['controlledBy'])
+ self.setAttribute('controlledBy', event.value['controlledBy']);
+ else
+ self.removeAttribute('controlledBy');
+ });
+ }
+
+ self.addEventListener('click', self.show_);
+ },
+
+ /**
+ * Constructs the bubble DOM tree and shows it.
+ * @private
+ */
+ show_: function() {
+ var self = this;
+ var doc = self.ownerDocument;
+ self.hide_();
+
+ // Work out the bubble text.
+ defaultStrings = {
+ 'policy' : localStrings.getString('controlledSettingPolicy'),
+ 'extension' : localStrings.getString('controlledSettingExtension'),
+ 'recommended' : localStrings.getString('controlledSettingRecommended'),
+ };
+
+ // No controller, no bubble.
+ var controller = self.getAttribute('controlledBy');
+ if (!controller || !controller in defaultStrings)
+ return;
+
+ var text = defaultStrings[controller];
+
+ // Apply text overrides.
+ if (self.hasAttribute('text' + controller))
+ text = self.getAttribute('text' + controller);
+
+ // Create the DOM tree.
+ var bubbleContainer = doc.createElement('div');
+ bubbleContainer.className = 'controlled-setting-bubble';
+
+ var bubbleText = doc.createElement('div');
+ bubbleText.className = 'controlled-setting-bubble-text';
+ bubbleText.textContent = text;
+
+ var pref = self.getAttribute('pref');
+ if (controller == 'recommended' && pref) {
+ var container = doc.createElement('div');
+ var action = doc.createElement('button');
+ action.classList.add('link-button');
+ action.classList.add('controlled-setting-bubble-action');
+ action.textContent =
+ localStrings.getString('controlledSettingApplyRecommendation');
+ action.addEventListener(
+ 'click',
+ function(e) {
+ Preferences.clearPref(pref);
+ self.hide_();
+ // Stop propagation s.t. the click handler on the indicator icon
Patrick Dubroy 2011/11/21 13:53:19 Nit: I don't think this is worth abbreviating. It
+ // doesn't trigger and rebuild the bubble.
+ e.stopPropagation();
+ });
+ container.appendChild(action);
+ bubbleText.appendChild(container);
+ }
+
+ bubbleContainer.appendChild(bubbleText);
+ self.appendChild(bubbleContainer);
+
+ // One-time bubble-closing event handler.
+ doc.addEventListener(
+ 'click',
+ function() {
+ self.hide_();
+ doc.removeEventListener('click', arguments.callee, true);
+ },
+ true);
+ },
+
+ /**
+ * Hides the bubble.
+ * @private
+ */
+ hide_: function() {
+ var bubble = this.querySelector('.controlled-setting-bubble');
+ if (bubble)
+ this.removeChild(bubble);
+ }
+ };
+
+ // Export.
+ return {
+ ControlledSettingIndicator : ControlledSettingIndicator
+ };
+});
« no previous file with comments | « chrome/app/theme/theme_resources.grd ('k') | chrome/browser/resources/options/options.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698