Bug 1278473 - use Services.focus, not nsIFocusManager, in devtools; r?gregtatum draft
authorTom Tromey <tom@tromey.com>
Mon, 25 Jul 2016 12:24:36 -0600
changeset 392937 f26953095dea77cba60b66006f907594eb5fe736
parent 392936 ccbf505eff5113af886ca4e3738d476bd0a83ca9
child 392938 f191192ce83cfac8833e2f5f8eee1c9ba7b2ef61
push id24147
push userbmo:ttromey@mozilla.com
push dateTue, 26 Jul 2016 14:11:42 +0000
reviewersgregtatum
bugs1278473
milestone50.0a1
Bug 1278473 - use Services.focus, not nsIFocusManager, in devtools; r?gregtatum MozReview-Commit-ID: Ep3G0S62clm
devtools/client/inspector/markup/markup.js
devtools/client/inspector/rules/models/rule.js
devtools/client/inspector/rules/views/rule-editor.js
devtools/client/inspector/rules/views/text-property-editor.js
devtools/client/shared/inplace-editor.js
--- a/devtools/client/inspector/markup/markup.js
+++ b/devtools/client/inspector/markup/markup.js
@@ -3405,19 +3405,19 @@ ElementEditor.prototype = {
         } else if (isModifiedOrder) {
           // The attribute was renamed, reordering the existing attributes.
           // So let's go to the beginning of the attribute list for consistency.
           activeEditor = visibleAttrs[0];
         } else {
           let newAttributeIndex;
           if (isDeletedAttribute) {
             newAttributeIndex = attributeIndex;
-          } else if (direction == Ci.nsIFocusManager.MOVEFOCUS_FORWARD) {
+          } else if (direction == Services.focus.MOVEFOCUS_FORWARD) {
             newAttributeIndex = attributeIndex + 1;
-          } else if (direction == Ci.nsIFocusManager.MOVEFOCUS_BACKWARD) {
+          } else if (direction == Services.focus.MOVEFOCUS_BACKWARD) {
             newAttributeIndex = attributeIndex - 1;
           }
 
           // The number of attributes changed (deleted), or we moved through
           // the array so check we're still within bounds.
           if (newAttributeIndex >= 0 &&
               newAttributeIndex <= visibleAttrs.length - 1) {
             activeEditor = visibleAttrs[newAttributeIndex];
--- a/devtools/client/inspector/rules/models/rule.js
+++ b/devtools/client/inspector/rules/models/rule.js
@@ -1,19 +1,16 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-/* eslint-disable mozilla/reject-some-requires */
-const {Ci} = require("chrome");
-/* eslint-enable mozilla/reject-some-requires */
 const promise = require("promise");
 const CssLogic = require("devtools/shared/inspector/css-logic");
 const {ELEMENT_STYLE} = require("devtools/shared/specs/styles");
 const {TextProperty} =
       require("devtools/client/inspector/rules/models/text-property");
 const {promiseWarn} = require("devtools/client/inspector/shared/utils");
 const {parseDeclarations} = require("devtools/shared/css-parsing-utils");
 const Services = require("Services");
@@ -622,28 +619,28 @@ Rule.prototype = {
    * @param {TextProperty} textProperty
    *        The text property that will be left to focus on a sibling.
    * @param {Number} direction
    *        The move focus direction number.
    */
   editClosestTextProperty: function (textProperty, direction) {
     let index = this.textProps.indexOf(textProperty);
 
-    if (direction === Ci.nsIFocusManager.MOVEFOCUS_FORWARD) {
+    if (direction === Services.focus.MOVEFOCUS_FORWARD) {
       for (++index; index < this.textProps.length; ++index) {
         if (!this.textProps[index].invisible) {
           break;
         }
       }
       if (index === this.textProps.length) {
         textProperty.rule.editor.closeBrace.click();
       } else {
         this.textProps[index].editor.nameSpan.click();
       }
-    } else if (direction === Ci.nsIFocusManager.MOVEFOCUS_BACKWARD) {
+    } else if (direction === Services.focus.MOVEFOCUS_BACKWARD) {
       for (--index; index >= 0; --index) {
         if (!this.textProps[index].invisible) {
           break;
         }
       }
       if (index < 0) {
         textProperty.editor.ruleEditor.selectorText.click();
       } else {
--- a/devtools/client/inspector/rules/views/rule-editor.js
+++ b/devtools/client/inspector/rules/views/rule-editor.js
@@ -1,18 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 /* eslint-disable mozilla/reject-some-requires */
-const {Ci} = require("chrome");
-/* eslint-enable mozilla/reject-some-requires */
-/* eslint-disable mozilla/reject-some-requires */
 const {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
 /* eslint-enable mozilla/reject-some-requires */
 const {l10n} = require("devtools/shared/inspector/css-logic");
 const {ELEMENT_STYLE} = require("devtools/shared/specs/styles");
 const {PREF_ORIG_SOURCES} = require("devtools/client/styleeditor/utils");
 const {Rule} = require("devtools/client/inspector/rules/models/rule");
 const {InplaceEditor, editableField, editableItem} =
       require("devtools/client/shared/inplace-editor");
@@ -579,17 +576,17 @@ RuleEditor.prototype = {
   /**
    * Handle moving the focus change after a tab or return keypress in the
    * selector inplace editor.
    *
    * @param {Number} direction
    *        The move focus direction number.
    */
   _moveSelectorFocus: function (direction) {
-    if (!direction || direction === Ci.nsIFocusManager.MOVEFOCUS_BACKWARD) {
+    if (!direction || direction === Services.focus.MOVEFOCUS_BACKWARD) {
       return;
     }
 
     if (this.rule.textProps.length > 0) {
       this.rule.textProps[0].editor.nameSpan.click();
     } else {
       this.propertyList.click();
     }
--- a/devtools/client/inspector/rules/views/text-property-editor.js
+++ b/devtools/client/inspector/rules/views/text-property-editor.js
@@ -1,32 +1,30 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-/* eslint-disable mozilla/reject-some-requires */
-const {Ci} = require("chrome");
-/* eslint-enable mozilla/reject-some-requires */
 const {l10n} = require("devtools/shared/inspector/css-logic");
 const {getCssProperties} = require("devtools/shared/fronts/css-properties");
 const {InplaceEditor, editableField} =
       require("devtools/client/shared/inplace-editor");
 const {
   createChild,
   appendText,
   advanceValidate,
   blurOnMultipleProperties,
   throttle
 } = require("devtools/client/inspector/shared/utils");
 const {
   parseDeclarations,
   parseSingleValue,
 } = require("devtools/shared/css-parsing-utils");
+const Services = require("Services");
 
 const HTML_NS = "http://www.w3.org/1999/xhtml";
 
 const SHARED_SWATCH_CLASS = "ruleview-swatch";
 const COLOR_SWATCH_CLASS = "ruleview-colorswatch";
 const BEZIER_SWATCH_CLASS = "ruleview-bezierswatch";
 const FILTER_SWATCH_CLASS = "ruleview-filterswatch";
 const ANGLE_SWATCH_CLASS = "ruleview-angleswatch";
@@ -637,17 +635,17 @@ TextPropertyEditor.prototype = {
     if (!value.trim()) {
       this.remove(direction);
       return;
     }
 
     // Remove a property if the property value is empty and the property
     // value is not about to be focused
     if (!this.prop.value &&
-        direction !== Ci.nsIFocusManager.MOVEFOCUS_FORWARD) {
+        direction !== Services.focus.MOVEFOCUS_FORWARD) {
       this.remove(direction);
       return;
     }
 
     // Adding multiple rules inside of name field overwrites the current
     // property with the first, then adds any more onto the property list.
     let properties = parseDeclarations(this.cssProperties.isKnown, value);
 
@@ -736,17 +734,17 @@ TextPropertyEditor.prototype = {
     // If needed, add any new properties after this.prop.
     this.ruleEditor.addProperties(parsedProperties.propertiesToAdd, this.prop);
 
     // If the input value is empty and the focus is moving forward to the next
     // editable field, then remove the whole property.
     // A timeout is used here to accurately check the state, since the inplace
     // editor `done` and `destroy` events fire before the next editor
     // is focused.
-    if (!value.trim() && direction !== Ci.nsIFocusManager.MOVEFOCUS_BACKWARD) {
+    if (!value.trim() && direction !== Services.focus.MOVEFOCUS_BACKWARD) {
       setTimeout(() => {
         if (!this.editing) {
           this.remove(direction);
         }
       }, 0);
     }
   },
 
--- a/devtools/client/shared/inplace-editor.js
+++ b/devtools/client/shared/inplace-editor.js
@@ -20,31 +20,32 @@
  *
  * See editableField() for more options.
  */
 
 "use strict";
 
 const {Ci, Cc} = require("chrome");
 const Services = require("Services");
+const focusManager = Services.focus;
 
 const HTML_NS = "http://www.w3.org/1999/xhtml";
 const CONTENT_TYPES = {
   PLAIN_TEXT: 0,
   CSS_VALUE: 1,
   CSS_MIXED: 2,
   CSS_PROPERTY: 3,
 };
 
 // The limit of 500 autocomplete suggestions should not be reached but is kept
 // for safety.
 const MAX_POPUP_ENTRIES = 500;
 
-const FOCUS_FORWARD = Ci.nsIFocusManager.MOVEFOCUS_FORWARD;
-const FOCUS_BACKWARD = Ci.nsIFocusManager.MOVEFOCUS_BACKWARD;
+const FOCUS_FORWARD = focusManager.MOVEFOCUS_FORWARD;
+const FOCUS_BACKWARD = focusManager.MOVEFOCUS_BACKWARD;
 
 const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
 const EventEmitter = require("devtools/shared/event-emitter");
 const { findMostRelevantCssPropertyIndex } = require("./suggestion-picker");
 
 /**
  * Helper to check if the provided key matches one of the expected keys.
  * Keys will be prefixed with DOM_VK_ and should match a key in nsIDOMKeyEvent.
@@ -78,18 +79,18 @@ function isKeyIn(key, ...keys) {
  *       Will be called when the inplace editor is initialized.
  *    {Function} change:
  *       Will be called when the text input changes.  Will be called
  *       with the current value of the text input.
  *    {Function} done:
  *       Called when input is committed or blurred.  Called with
  *       current value, a boolean telling the caller whether to
  *       commit the change, and the direction of the next element to be
- *       selected. Direction may be one of nsIFocusManager.MOVEFOCUS_FORWARD,
- *       nsIFocusManager.MOVEFOCUS_BACKWARD, or null (no movement).
+ *       selected. Direction may be one of Services.focus.MOVEFOCUS_FORWARD,
+ *       Services.focus.MOVEFOCUS_BACKWARD, or null (no movement).
  *       This function is called before the editor has been torn down.
  *    {Function} destroy:
  *       Called when the editor is destroyed and has been torn down.
  *    {Object} advanceChars:
  *       This can be either a string or a function.
  *       If it is a string, then if any characters in it are typed,
  *       focus will advance to the next element.
  *       Otherwise, if it is a function, then the function will
@@ -1549,19 +1550,15 @@ function copyBoxModelStyles(from, to) {
 
 /**
  * Trigger a focus change similar to pressing tab/shift-tab.
  */
 function moveFocus(win, direction) {
   return focusManager.moveFocus(win, null, direction, 0);
 }
 
-XPCOMUtils.defineLazyGetter(this, "focusManager", function () {
-  return Services.focus;
-});
-
 XPCOMUtils.defineLazyGetter(this, "CSSPropertyList", function () {
   return domUtils.getCSSPropertyNames(domUtils.INCLUDE_ALIASES).sort();
 });
 
 XPCOMUtils.defineLazyGetter(this, "domUtils", function () {
   return Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
 });