Bug 1292253 - replace some Ci uses in view-helpers and TableWidget; r=gregtatum

MozReview-Commit-ID: JIs4wxNA3Eg
This commit is contained in:
Tom Tromey
2016-08-09 09:43:58 -06:00
parent 7466eebd31
commit 6bb49c290c
4 changed files with 20 additions and 16 deletions

View File

@@ -11,13 +11,16 @@
"clearTimeout": true, "clearTimeout": true,
"console": true, "console": true,
"CSS": true, "CSS": true,
"DocumentFragment": true,
"DOMParser": true, "DOMParser": true,
"dump": true, "dump": true,
"Element": true,
"exports": true, "exports": true,
"isWorker": true, "isWorker": true,
"indexedDB": true, "indexedDB": true,
"loader": true, "loader": true,
"module": true, "module": true,
"Node": true,
"reportError": true, "reportError": true,
"require": true, "require": true,
"setInterval": true, "setInterval": true,

View File

@@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict"; "use strict";
const {Ci} = require("chrome");
const EventEmitter = require("devtools/shared/event-emitter"); const EventEmitter = require("devtools/shared/event-emitter");
loader.lazyRequireGetter(this, "setNamedTimeout", loader.lazyRequireGetter(this, "setNamedTimeout",
"devtools/client/shared/widgets/view-helpers", true); "devtools/client/shared/widgets/view-helpers", true);
@@ -1350,17 +1349,17 @@ Column.prototype = {
// Only sort the array if we are sorting based on this column // Only sort the array if we are sorting based on this column
if (this.sorted == 1) { if (this.sorted == 1) {
items.sort((a, b) => { items.sort((a, b) => {
let val1 = (a[this.id] instanceof Ci.nsIDOMNode) ? let val1 = (a[this.id] instanceof Node) ?
a[this.id].textContent : a[this.id]; a[this.id].textContent : a[this.id];
let val2 = (b[this.id] instanceof Ci.nsIDOMNode) ? let val2 = (b[this.id] instanceof Node) ?
b[this.id].textContent : b[this.id]; b[this.id].textContent : b[this.id];
return val1 > val2; return val1 > val2;
}); });
} else if (this.sorted > 1) { } else if (this.sorted > 1) {
items.sort((a, b) => { items.sort((a, b) => {
let val1 = (a[this.id] instanceof Ci.nsIDOMNode) ? let val1 = (a[this.id] instanceof Node) ?
a[this.id].textContent : a[this.id]; a[this.id].textContent : a[this.id];
let val2 = (b[this.id] instanceof Ci.nsIDOMNode) ? let val2 = (b[this.id] instanceof Node) ?
b[this.id].textContent : b[this.id]; b[this.id].textContent : b[this.id];
return val2 > val1; return val2 > val1;
}); });
@@ -1504,18 +1503,18 @@ Cell.prototype = {
return; return;
} }
if (this.wrapTextInElements && !(value instanceof Ci.nsIDOMNode)) { if (this.wrapTextInElements && !(value instanceof Node)) {
let span = this.label.ownerDocument.createElementNS(HTML_NS, "span"); let span = this.label.ownerDocument.createElementNS(HTML_NS, "span");
span.textContent = value; span.textContent = value;
value = span; value = span;
} }
if (!(value instanceof Ci.nsIDOMNode) && if (!(value instanceof Node) &&
value.length > MAX_VISIBLE_STRING_SIZE) { value.length > MAX_VISIBLE_STRING_SIZE) {
value = value .substr(0, MAX_VISIBLE_STRING_SIZE) + "\u2026"; value = value .substr(0, MAX_VISIBLE_STRING_SIZE) + "\u2026";
} }
if (value instanceof Ci.nsIDOMNode) { if (value instanceof Node) {
this.label.removeAttribute("value"); this.label.removeAttribute("value");
while (this.label.firstChild) { while (this.label.firstChild) {

View File

@@ -5,8 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict"; "use strict";
const { Ci } = require("chrome");
const PANE_APPEARANCE_DELAY = 50; const PANE_APPEARANCE_DELAY = 50;
const PAGE_SIZE_ITEM_COUNT_RATIO = 5; const PAGE_SIZE_ITEM_COUNT_RATIO = 5;
const WIDGET_FOCUSABLE_NODES = new Set(["vbox", "hbox"]); const WIDGET_FOCUSABLE_NODES = new Set(["vbox", "hbox"]);
@@ -128,7 +126,7 @@ const ViewHelpers = exports.ViewHelpers = {
* called preventDefault. * called preventDefault.
*/ */
dispatchEvent: function (target, type, detail) { dispatchEvent: function (target, type, detail) {
if (!(target instanceof Ci.nsIDOMNode)) { if (!(target instanceof Node)) {
// Event cancelled. // Event cancelled.
return true; return true;
} }
@@ -190,9 +188,9 @@ const ViewHelpers = exports.ViewHelpers = {
* True if it's a node, false otherwise. * True if it's a node, false otherwise.
*/ */
isNode: function (object) { isNode: function (object) {
return object instanceof Ci.nsIDOMNode || return object instanceof Node ||
object instanceof Ci.nsIDOMElement || object instanceof Element ||
object instanceof Ci.nsIDOMDocumentFragment; object instanceof DocumentFragment;
}, },
/** /**
@@ -792,12 +790,12 @@ const WidgetMethods = exports.WidgetMethods = {
// If the two items were constructed with prebuilt nodes as // If the two items were constructed with prebuilt nodes as
// DocumentFragments, then those DocumentFragments are now // DocumentFragments, then those DocumentFragments are now
// empty and need to be reassembled. // empty and need to be reassembled.
if (firstPrebuiltTarget instanceof Ci.nsIDOMDocumentFragment) { if (firstPrebuiltTarget instanceof DocumentFragment) {
for (let node of firstTarget.childNodes) { for (let node of firstTarget.childNodes) {
firstPrebuiltTarget.appendChild(node.cloneNode(true)); firstPrebuiltTarget.appendChild(node.cloneNode(true));
} }
} }
if (secondPrebuiltTarget instanceof Ci.nsIDOMDocumentFragment) { if (secondPrebuiltTarget instanceof DocumentFragment) {
for (let node of secondTarget.childNodes) { for (let node of secondTarget.childNodes) {
secondPrebuiltTarget.appendChild(node.cloneNode(true)); secondPrebuiltTarget.appendChild(node.cloneNode(true));
} }

View File

@@ -234,6 +234,10 @@ const globals = exports.globals = {
.createInstance(Ci.nsIXMLHttpRequest); .createInstance(Ci.nsIXMLHttpRequest);
}, },
Node: Ci.nsIDOMNode,
Element: Ci.nsIDOMElement,
DocumentFragment: Ci.nsIDOMDocumentFragment,
// Make sure `define` function exists. This allows defining some modules // Make sure `define` function exists. This allows defining some modules
// in AMD format while retaining CommonJS compatibility through this hook. // in AMD format while retaining CommonJS compatibility through this hook.
// JSON Viewer needs modules in AMD format, as it currently uses RequireJS // JSON Viewer needs modules in AMD format, as it currently uses RequireJS