Bug 1221545 - Allow for the Style Editor to be disabled. r=jdescottes
authorMaxime "Pepe_" Buquet <pep+code@bouah.net>
Tue, 21 Jun 2016 15:13:51 +0200
changeset 302329 55531d6fbd7d
parent 302328 882dd3714959
child 302330 a5e39700fd44
push id30359
push usercbook@mozilla.com
push dateThu, 23 Jun 2016 12:01:22 +0000
treeherdermozilla-central@437fc937572d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1221545
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1221545 - Allow for the Style Editor to be disabled. r=jdescottes
devtools/client/definitions.js
devtools/client/inspector/rules/test/browser_rules_style-editor-link.js
devtools/client/inspector/rules/views/rule-editor.js
--- a/devtools/client/definitions.js
+++ b/devtools/client/definitions.js
@@ -183,16 +183,17 @@ Tools.jsdebugger = {
     return new DebuggerPanel(iframeWindow, toolbox);
   }
 };
 
 Tools.styleEditor = {
   id: "styleeditor",
   key: l10n("open.commandkey", styleEditorStrings),
   ordinal: 4,
+  visibilityswitch: "devtools.styleeditor.enabled",
   accesskey: l10n("open.accesskey", styleEditorStrings),
   modifiers: "shift",
   icon: "chrome://devtools/skin/images/tool-styleeditor.svg",
   invertIconForLightTheme: true,
   url: "chrome://devtools/content/styleeditor/styleeditor.xul",
   label: l10n("ToolboxStyleEditor.label", styleEditorStrings),
   panelLabel: l10n("ToolboxStyleEditor.panelLabel", styleEditorStrings),
   get tooltip() {
--- a/devtools/client/inspector/rules/test/browser_rules_style-editor-link.js
+++ b/devtools/client/inspector/rules/test/browser_rules_style-editor-link.js
@@ -56,16 +56,17 @@ add_task(function* () {
   yield addTab(DOCUMENT_URL);
   let {toolbox, inspector, view, testActor} = yield openRuleView();
   yield selectNode("div", inspector);
 
   yield testInlineStyle(view);
   yield testFirstInlineStyleSheet(view, toolbox, testActor);
   yield testSecondInlineStyleSheet(view, toolbox, testActor);
   yield testExternalStyleSheet(view, toolbox, testActor);
+  yield testDisabledStyleEditor(view, toolbox);
 });
 
 function* testInlineStyle(view) {
   info("Testing inline style");
 
   let onTab = waitForTab();
   info("Clicking on the first link in the rule-view");
   clickLinkByIndex(view, 0);
@@ -142,25 +143,61 @@ function* validateStyleEditorSheet(edito
 
   let expectedHref = yield testActor.eval(
     `content.document.styleSheets[${expectedSheetIndex}].href ||
      content.document.location.href`);
 
   is(href, expectedHref, "loaded stylesheet href matches document stylesheet");
 }
 
+function* testDisabledStyleEditor(view, toolbox) {
+  info("Testing with the style editor disabled");
+
+  info("Switching to the inspector panel in the toolbox");
+  yield toolbox.selectTool("inspector");
+
+  info("Disabling the style editor");
+  Services.prefs.setBoolPref("devtools.styleeditor.enabled", false);
+  gDevTools.emit("tool-unregistered", "styleeditor");
+
+  info("Clicking on a link");
+  testUnselectableRuleViewLink(view, 1);
+  clickLinkByIndex(view, 1);
+
+  is(toolbox.currentToolId, "inspector", "The click should have no effect");
+
+  info("Enabling the style editor");
+  Services.prefs.setBoolPref("devtools.styleeditor.enabled", true);
+  gDevTools.emit("tool-registered", "styleeditor");
+
+  info("Clicking on a link");
+  let onStyleEditorSelected = toolbox.once("styleeditor-selected");
+  clickLinkByIndex(view, 1);
+  yield onStyleEditorSelected;
+  is(toolbox.currentToolId, "styleeditor", "Style Editor should be selected");
+
+  Services.prefs.clearUserPref("devtools.styleeditor.enabled");
+}
+
 function testRuleViewLinkLabel(view) {
   let link = getRuleViewLinkByIndex(view, 2);
   let labelElem = link.querySelector(".ruleview-rule-source-label");
   let value = labelElem.getAttribute("value");
   let tooltipText = labelElem.getAttribute("tooltiptext");
 
   is(value, EXTERNAL_STYLESHEET_FILE_NAME + ":1",
     "rule view stylesheet display value matches filename and line number");
   is(tooltipText, EXTERNAL_STYLESHEET_URL + ":1",
     "rule view stylesheet tooltip text matches the full URI path");
 }
 
+function testUnselectableRuleViewLink(view, index) {
+  let link = getRuleViewLinkByIndex(view, index);
+  let unselectable = link.hasAttribute("unselectable");
+
+  ok(unselectable, "Rule view is unselectable");
+}
+
 function clickLinkByIndex(view, index) {
   let link = getRuleViewLinkByIndex(view, index);
   link.scrollIntoView();
   link.click();
 }
--- a/devtools/client/inspector/rules/views/rule-editor.js
+++ b/devtools/client/inspector/rules/views/rule-editor.js
@@ -55,42 +55,47 @@ const XUL_NS = "http://www.mozilla.org/k
  * @param {Rule} rule
  *        The Rule object we're editing.
  */
 function RuleEditor(ruleView, rule) {
   EventEmitter.decorate(this);
 
   this.ruleView = ruleView;
   this.doc = this.ruleView.styleDocument;
+  this.toolbox = this.ruleView.inspector.toolbox;
   this.rule = rule;
 
   this.isEditable = !rule.isSystem;
   // Flag that blocks updates of the selector and properties when it is
   // being edited
   this.isEditing = false;
 
   this._onNewProperty = this._onNewProperty.bind(this);
   this._newPropertyDestroy = this._newPropertyDestroy.bind(this);
   this._onSelectorDone = this._onSelectorDone.bind(this);
   this._locationChanged = this._locationChanged.bind(this);
+  this.updateSourceLink = this.updateSourceLink.bind(this);
 
   this.rule.domRule.on("location-changed", this._locationChanged);
+  this.toolbox.on("tool-registered", this.updateSourceLink);
+  this.toolbox.on("tool-unregistered", this.updateSourceLink);
 
   this._create();
 }
 
 RuleEditor.prototype = {
   destroy: function () {
     this.rule.domRule.off("location-changed");
+    this.toolbox.off("tool-registered", this.updateSourceLink);
+    this.toolbox.off("tool-unregistered", this.updateSourceLink);
   },
 
   get isSelectorEditable() {
-    let toolbox = this.ruleView.inspector.toolbox;
     let trait = this.isEditable &&
-      toolbox.target.client.traits.selectorEditable &&
+      this.toolbox.target.client.traits.selectorEditable &&
       this.rule.domRule.type !== ELEMENT_STYLE &&
       this.rule.domRule.type !== CSSRule.KEYFRAME_RULE;
 
     // Do not allow editing anonymousselectors until we can
     // detect mutations on  pseudo elements in Bug 1034110.
     return trait && !this.rule.elementStyle.element.isAnonymous;
   },
 
@@ -220,32 +225,38 @@ RuleEditor.prototype = {
     let sourceLabel = this.element.querySelector(".ruleview-rule-source-label");
     let title = this.rule.title;
     let sourceHref = (this.rule.sheet && this.rule.sheet.href) ?
       this.rule.sheet.href : title;
     let sourceLine = this.rule.ruleLine > 0 ? ":" + this.rule.ruleLine : "";
 
     sourceLabel.setAttribute("tooltiptext", sourceHref + sourceLine);
 
+    if (this.toolbox.isToolRegistered("styleeditor")) {
+      this.source.removeAttribute("unselectable");
+    } else {
+      this.source.setAttribute("unselectable", true);
+    }
+
     if (this.rule.isSystem) {
       let uaLabel = _strings.GetStringFromName("rule.userAgentStyles");
       sourceLabel.setAttribute("value", uaLabel + " " + title);
 
       // Special case about:PreferenceStyleSheet, as it is generated on the
       // fly and the URI is not registered with the about: handler.
       // https://bugzilla.mozilla.org/show_bug.cgi?id=935803#c37
       if (sourceHref === "about:PreferenceStyleSheet") {
-        sourceLabel.parentNode.setAttribute("unselectable", "true");
+        this.source.setAttribute("unselectable", "true");
         sourceLabel.setAttribute("value", uaLabel);
         sourceLabel.removeAttribute("tooltiptext");
       }
     } else {
       sourceLabel.setAttribute("value", title);
       if (this.rule.ruleLine === -1 && this.rule.domRule.parentStyleSheet) {
-        sourceLabel.parentNode.setAttribute("unselectable", "true");
+        this.source.setAttribute("unselectable", "true");
       }
     }
 
     let showOrig = Services.prefs.getBoolPref(PREF_ORIG_SOURCES);
     if (showOrig && !this.rule.isSystem &&
         this.rule.domRule.type !== ELEMENT_STYLE) {
       // Only get the original source link if the right pref is set, if the rule
       // isn't a system rule and if it isn't an inline rule.