2013-08-01 01:53:31 -07:00
|
|
|
/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-08-30 05:12:02 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
const {Cc, Cu, Ci} = require("chrome");
|
|
|
|
|
|
|
|
let ToolDefinitions = require("main").Tools;
|
2011-08-30 05:12:02 -07:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-11-30 00:07:59 -08:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
loader.lazyGetter(this, "gDevTools", () => Cu.import("resource:///modules/devtools/gDevTools.jsm", {}).gDevTools);
|
|
|
|
loader.lazyGetter(this, "RuleView", () => require("devtools/styleinspector/rule-view"));
|
|
|
|
loader.lazyGetter(this, "ComputedView", () => require("devtools/styleinspector/computed-view"));
|
|
|
|
loader.lazyGetter(this, "_strings", () => Services.strings
|
|
|
|
.createBundle("chrome://browser/locale/devtools/styleinspector.properties"));
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
// This module doesn't currently export any symbols directly, it only
|
|
|
|
// registers inspector tools.
|
2011-10-21 10:40:22 -07:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
function RuleViewTool(aInspector, aWindow, aIFrame)
|
2012-04-19 11:04:46 -07:00
|
|
|
{
|
|
|
|
this.inspector = aInspector;
|
2012-11-30 00:07:59 -08:00
|
|
|
this.doc = aWindow.document;
|
|
|
|
this.outerIFrame = aIFrame;
|
2012-04-19 11:13:42 -07:00
|
|
|
|
2013-08-30 01:06:59 -07:00
|
|
|
this.view = new RuleView.CssRuleView(this.doc);
|
2012-04-19 11:04:46 -07:00
|
|
|
this.doc.documentElement.appendChild(this.view.element);
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this._changeHandler = () => {
|
2012-04-19 11:04:46 -07:00
|
|
|
this.inspector.markDirty();
|
2013-08-08 08:44:57 -07:00
|
|
|
};
|
2012-04-19 11:04:46 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this.view.element.addEventListener("CssRuleViewChanged", this._changeHandler);
|
2012-04-19 11:04:46 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this._refreshHandler = () => {
|
|
|
|
this.inspector.emit("rule-view-refreshed");
|
|
|
|
};
|
|
|
|
|
|
|
|
this.view.element.addEventListener("CssRuleViewRefreshed", this._refreshHandler);
|
|
|
|
|
|
|
|
this._cssLinkHandler = (aEvent) => {
|
2012-04-19 11:04:46 -07:00
|
|
|
let rule = aEvent.detail.rule;
|
2013-08-08 08:44:57 -07:00
|
|
|
let line = rule.line || 0;
|
2012-04-19 11:04:46 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
// The style editor can only display stylesheets coming from content because
|
|
|
|
// chrome stylesheets are not listed in the editor's stylesheet selector.
|
|
|
|
//
|
|
|
|
// If the stylesheet is a content stylesheet we send it to the style
|
|
|
|
// editor else we display it in the view source window.
|
|
|
|
//
|
2013-08-08 08:44:57 -07:00
|
|
|
let href = rule.href;
|
|
|
|
let sheet = rule.parentStyleSheet;
|
|
|
|
if (sheet && href && !sheet.isSystem) {
|
2012-11-30 00:07:59 -08:00
|
|
|
let target = this.inspector.target;
|
2013-04-11 13:59:08 -07:00
|
|
|
if (ToolDefinitions.styleEditor.isTargetSupported(target)) {
|
2012-12-13 05:03:55 -08:00
|
|
|
gDevTools.showToolbox(target, "styleeditor").then(function(toolbox) {
|
2013-08-08 08:44:57 -07:00
|
|
|
toolbox.getCurrentPanel().selectStyleSheet(href, line);
|
2012-11-30 00:07:59 -08:00
|
|
|
});
|
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
return;
|
2012-04-19 11:04:46 -07:00
|
|
|
}
|
2013-08-08 08:44:57 -07:00
|
|
|
|
|
|
|
let contentDoc = this.inspector.selection.document;
|
|
|
|
let viewSourceUtils = this.inspector.viewSourceUtils;
|
|
|
|
viewSourceUtils.viewSource(href, null, contentDoc, line);
|
|
|
|
}
|
2011-11-03 06:37:14 -07:00
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
this.view.element.addEventListener("CssRuleViewCSSLinkClicked",
|
|
|
|
this._cssLinkHandler);
|
2011-11-03 06:37:14 -07:00
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
this._onSelect = this.onSelect.bind(this);
|
2013-01-04 03:54:54 -08:00
|
|
|
this.inspector.selection.on("detached", this._onSelect);
|
2013-08-08 08:44:57 -07:00
|
|
|
this.inspector.selection.on("new-node-front", this._onSelect);
|
2012-11-30 00:07:59 -08:00
|
|
|
this.refresh = this.refresh.bind(this);
|
|
|
|
this.inspector.on("layout-change", this.refresh);
|
2013-08-08 08:44:57 -07:00
|
|
|
|
|
|
|
this.panelSelected = this.panelSelected.bind(this);
|
|
|
|
this.inspector.sidebar.on("ruleview-selected", this.panelSelected);
|
2012-11-30 00:07:59 -08:00
|
|
|
this.inspector.selection.on("pseudoclass", this.refresh);
|
|
|
|
if (this.inspector.highlighter) {
|
|
|
|
this.inspector.highlighter.on("locked", this._onSelect);
|
|
|
|
}
|
2011-10-21 10:40:22 -07:00
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
this.onSelect();
|
|
|
|
}
|
2011-09-01 05:17:05 -07:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
exports.RuleViewTool = RuleViewTool;
|
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
RuleViewTool.prototype = {
|
2012-11-30 00:07:59 -08:00
|
|
|
onSelect: function RVT_onSelect(aEvent) {
|
2013-08-08 08:44:57 -07:00
|
|
|
if (!this.isActive()) {
|
|
|
|
// We'll update when the panel is selected.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.view.setPageStyle(this.inspector.pageStyle);
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
if (!this.inspector.selection.isConnected() ||
|
|
|
|
!this.inspector.selection.isElementNode()) {
|
2012-04-19 11:04:46 -07:00
|
|
|
this.view.highlight(null);
|
|
|
|
return;
|
2011-09-01 05:17:05 -07:00
|
|
|
}
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
if (!aEvent || aEvent == "new-node-front") {
|
2012-11-30 00:07:59 -08:00
|
|
|
if (this.inspector.selection.reason == "highlighter") {
|
|
|
|
this.view.highlight(null);
|
|
|
|
} else {
|
2013-08-08 08:44:57 -07:00
|
|
|
let done = this.inspector.updating("rule-view");
|
|
|
|
this.view.highlight(this.inspector.selection.nodeFront).then(done, done);
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
2011-10-21 10:40:22 -07:00
|
|
|
}
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
if (aEvent == "locked") {
|
2013-08-08 08:44:57 -07:00
|
|
|
let done = this.inspector.updating("rule-view");
|
|
|
|
this.view.highlight(this.inspector.selection.nodeFront).then(done, done);
|
2011-10-21 10:40:22 -07:00
|
|
|
}
|
2012-11-30 00:07:59 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
isActive: function RVT_isActive() {
|
|
|
|
return this.inspector.sidebar.getCurrentTabID() == "ruleview";
|
|
|
|
},
|
2011-10-07 08:38:35 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
refresh: function RVT_refresh() {
|
|
|
|
if (this.isActive()) {
|
2012-04-19 11:04:46 -07:00
|
|
|
this.view.nodeChanged();
|
2011-11-06 19:02:08 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
panelSelected: function() {
|
|
|
|
if (this.inspector.selection.nodeFront === this.view.viewedElement) {
|
|
|
|
this.view.nodeChanged();
|
|
|
|
} else {
|
|
|
|
this.onSelect();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
destroy: function RVT_destroy() {
|
2012-11-30 00:07:59 -08:00
|
|
|
this.inspector.off("layout-change", this.refresh);
|
|
|
|
this.inspector.sidebar.off("ruleview-selected", this.refresh);
|
|
|
|
this.inspector.selection.off("pseudoclass", this.refresh);
|
2013-08-08 08:44:57 -07:00
|
|
|
this.inspector.selection.off("new-node-front", this._onSelect);
|
2012-11-30 00:07:59 -08:00
|
|
|
if (this.inspector.highlighter) {
|
|
|
|
this.inspector.highlighter.off("locked", this._onSelect);
|
|
|
|
}
|
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
this.view.element.removeEventListener("CssRuleViewCSSLinkClicked",
|
2012-11-30 00:07:59 -08:00
|
|
|
this._cssLinkHandler);
|
|
|
|
|
|
|
|
this.view.element.removeEventListener("CssRuleViewChanged",
|
|
|
|
this._changeHandler);
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
this.view.element.removeEventListener("CssRuleViewRefreshed",
|
|
|
|
this._refreshHandler);
|
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
this.doc.documentElement.removeChild(this.view.element);
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
this.view.destroy();
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
delete this.outerIFrame;
|
2012-04-19 11:04:46 -07:00
|
|
|
delete this.view;
|
|
|
|
delete this.doc;
|
|
|
|
delete this.inspector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
function ComputedViewTool(aInspector, aWindow, aIFrame)
|
2012-04-19 11:04:46 -07:00
|
|
|
{
|
|
|
|
this.inspector = aInspector;
|
2012-11-30 00:07:59 -08:00
|
|
|
this.window = aWindow;
|
|
|
|
this.document = aWindow.document;
|
|
|
|
this.outerIFrame = aIFrame;
|
2013-08-08 08:44:57 -07:00
|
|
|
this.view = new ComputedView.CssHtmlTree(this, aInspector.pageStyle);
|
2011-10-21 10:40:22 -07:00
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
this._onSelect = this.onSelect.bind(this);
|
2013-01-04 03:54:54 -08:00
|
|
|
this.inspector.selection.on("detached", this._onSelect);
|
2013-08-08 08:44:57 -07:00
|
|
|
this.inspector.selection.on("new-node-front", this._onSelect);
|
2012-11-30 00:07:59 -08:00
|
|
|
if (this.inspector.highlighter) {
|
|
|
|
this.inspector.highlighter.on("locked", this._onSelect);
|
|
|
|
}
|
|
|
|
this.refresh = this.refresh.bind(this);
|
|
|
|
this.inspector.on("layout-change", this.refresh);
|
|
|
|
this.inspector.selection.on("pseudoclass", this.refresh);
|
2013-08-08 08:44:57 -07:00
|
|
|
this.panelSelected = this.panelSelected.bind(this);
|
|
|
|
this.inspector.sidebar.on("computedview-selected", this.panelSelected);
|
2012-04-19 11:04:46 -07:00
|
|
|
|
|
|
|
this.view.highlight(null);
|
|
|
|
|
|
|
|
this.onSelect();
|
|
|
|
}
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
exports.ComputedViewTool = ComputedViewTool;
|
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
ComputedViewTool.prototype = {
|
|
|
|
onSelect: function CVT_onSelect(aEvent)
|
2011-10-21 10:40:22 -07:00
|
|
|
{
|
2013-08-08 08:44:57 -07:00
|
|
|
if (!this.isActive()) {
|
|
|
|
// We'll try again when we're selected.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.view.setPageStyle(this.inspector.pageStyle);
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
if (!this.inspector.selection.isConnected() ||
|
|
|
|
!this.inspector.selection.isElementNode()) {
|
2013-01-04 03:54:54 -08:00
|
|
|
this.view.highlight(null);
|
2012-11-30 00:07:59 -08:00
|
|
|
return;
|
2011-11-03 06:37:14 -07:00
|
|
|
}
|
2011-08-30 05:12:02 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
if (!aEvent || aEvent == "new-node-front") {
|
2012-11-30 00:07:59 -08:00
|
|
|
if (this.inspector.selection.reason == "highlighter") {
|
|
|
|
// FIXME: We should hide view's content
|
|
|
|
} else {
|
2013-08-08 08:44:57 -07:00
|
|
|
let done = this.inspector.updating("computed-view");
|
|
|
|
this.view.highlight(this.inspector.selection.nodeFront).then(() => {
|
|
|
|
done();
|
|
|
|
});
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
if (aEvent == "locked" && this.inspector.selection.nodeFront != this.view.viewedElement) {
|
|
|
|
let done = this.inspector.updating("computed-view");
|
|
|
|
this.view.highlight(this.inspector.selection.nodeFront).then(() => {
|
|
|
|
done();
|
|
|
|
});
|
2011-08-30 05:12:02 -07:00
|
|
|
}
|
2012-11-30 00:07:59 -08:00
|
|
|
},
|
2012-04-19 11:04:46 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
isActive: function CVT_isActive() {
|
|
|
|
return this.inspector.sidebar.getCurrentTabID() == "computedview";
|
|
|
|
},
|
|
|
|
|
|
|
|
refresh: function CVT_refresh() {
|
|
|
|
if (this.isActive()) {
|
2012-06-02 15:18:33 -07:00
|
|
|
this.view.refreshPanel();
|
|
|
|
}
|
2011-08-30 05:12:02 -07:00
|
|
|
},
|
2011-11-03 06:37:14 -07:00
|
|
|
|
2013-08-08 08:44:57 -07:00
|
|
|
panelSelected: function() {
|
|
|
|
if (this.inspector.selection.nodeFront === this.view.viewedElement) {
|
|
|
|
this.view.refreshPanel();
|
|
|
|
} else {
|
|
|
|
this.onSelect();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
destroy: function CVT_destroy(aContext)
|
2011-11-03 06:37:14 -07:00
|
|
|
{
|
2012-11-30 00:07:59 -08:00
|
|
|
this.inspector.off("layout-change", this.refresh);
|
|
|
|
this.inspector.sidebar.off("computedview-selected", this.refresh);
|
|
|
|
this.inspector.selection.off("pseudoclass", this.refresh);
|
2013-08-08 08:44:57 -07:00
|
|
|
this.inspector.selection.off("new-node-front", this._onSelect);
|
2012-11-30 00:07:59 -08:00
|
|
|
if (this.inspector.highlighter) {
|
|
|
|
this.inspector.highlighter.off("locked", this._onSelect);
|
|
|
|
}
|
|
|
|
|
2012-04-19 11:04:46 -07:00
|
|
|
this.view.destroy();
|
|
|
|
delete this.view;
|
2011-11-03 06:37:14 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
delete this.outerIFrame;
|
2011-11-03 06:37:14 -07:00
|
|
|
delete this.cssLogic;
|
|
|
|
delete this.cssHtmlTree;
|
2012-04-19 11:04:46 -07:00
|
|
|
delete this.window;
|
|
|
|
delete this.document;
|
2012-11-30 00:07:59 -08:00
|
|
|
delete this.inspector;
|
2012-04-19 11:04:46 -07:00
|
|
|
}
|
2013-08-30 01:06:59 -07:00
|
|
|
};
|