Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | const {Cc, Cu, Ci} = require("chrome"); |
michael@0 | 8 | const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); |
michael@0 | 9 | |
michael@0 | 10 | let ToolDefinitions = require("main").Tools; |
michael@0 | 11 | |
michael@0 | 12 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | loader.lazyGetter(this, "gDevTools", () => Cu.import("resource:///modules/devtools/gDevTools.jsm", {}).gDevTools); |
michael@0 | 15 | loader.lazyGetter(this, "RuleView", () => require("devtools/styleinspector/rule-view")); |
michael@0 | 16 | loader.lazyGetter(this, "ComputedView", () => require("devtools/styleinspector/computed-view")); |
michael@0 | 17 | loader.lazyGetter(this, "_strings", () => Services.strings |
michael@0 | 18 | .createBundle("chrome://global/locale/devtools/styleinspector.properties")); |
michael@0 | 19 | |
michael@0 | 20 | const { PREF_ORIG_SOURCES } = require("devtools/styleeditor/utils"); |
michael@0 | 21 | |
michael@0 | 22 | // This module doesn't currently export any symbols directly, it only |
michael@0 | 23 | // registers inspector tools. |
michael@0 | 24 | |
michael@0 | 25 | function RuleViewTool(aInspector, aWindow, aIFrame) |
michael@0 | 26 | { |
michael@0 | 27 | this.inspector = aInspector; |
michael@0 | 28 | this.doc = aWindow.document; |
michael@0 | 29 | this.outerIFrame = aIFrame; |
michael@0 | 30 | |
michael@0 | 31 | this.view = new RuleView.CssRuleView(aInspector, this.doc); |
michael@0 | 32 | this.doc.documentElement.appendChild(this.view.element); |
michael@0 | 33 | |
michael@0 | 34 | this._changeHandler = () => { |
michael@0 | 35 | this.inspector.markDirty(); |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | this.view.element.addEventListener("CssRuleViewChanged", this._changeHandler); |
michael@0 | 39 | |
michael@0 | 40 | this._refreshHandler = () => { |
michael@0 | 41 | this.inspector.emit("rule-view-refreshed"); |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | this.view.element.addEventListener("CssRuleViewRefreshed", this._refreshHandler); |
michael@0 | 45 | |
michael@0 | 46 | this._cssLinkHandler = (aEvent) => { |
michael@0 | 47 | let rule = aEvent.detail.rule; |
michael@0 | 48 | let sheet = rule.parentStyleSheet; |
michael@0 | 49 | |
michael@0 | 50 | // Chrome stylesheets are not listed in the style editor, so show |
michael@0 | 51 | // these sheets in the view source window instead. |
michael@0 | 52 | if (!sheet || sheet.isSystem) { |
michael@0 | 53 | let contentDoc = this.inspector.selection.document; |
michael@0 | 54 | let viewSourceUtils = this.inspector.viewSourceUtils; |
michael@0 | 55 | let href = rule.nodeHref || rule.href; |
michael@0 | 56 | viewSourceUtils.viewSource(href, null, contentDoc, rule.line || 0); |
michael@0 | 57 | return; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | let location = promise.resolve(rule.location); |
michael@0 | 61 | if (Services.prefs.getBoolPref(PREF_ORIG_SOURCES)) { |
michael@0 | 62 | location = rule.getOriginalLocation(); |
michael@0 | 63 | } |
michael@0 | 64 | location.then(({ href, line, column }) => { |
michael@0 | 65 | let target = this.inspector.target; |
michael@0 | 66 | if (ToolDefinitions.styleEditor.isTargetSupported(target)) { |
michael@0 | 67 | gDevTools.showToolbox(target, "styleeditor").then(function(toolbox) { |
michael@0 | 68 | toolbox.getCurrentPanel().selectStyleSheet(href, line, column); |
michael@0 | 69 | }); |
michael@0 | 70 | } |
michael@0 | 71 | return; |
michael@0 | 72 | }) |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | this.view.element.addEventListener("CssRuleViewCSSLinkClicked", |
michael@0 | 76 | this._cssLinkHandler); |
michael@0 | 77 | |
michael@0 | 78 | this._onSelect = this.onSelect.bind(this); |
michael@0 | 79 | this.inspector.selection.on("detached", this._onSelect); |
michael@0 | 80 | this.inspector.selection.on("new-node-front", this._onSelect); |
michael@0 | 81 | this.refresh = this.refresh.bind(this); |
michael@0 | 82 | this.inspector.on("layout-change", this.refresh); |
michael@0 | 83 | |
michael@0 | 84 | this.inspector.selection.on("pseudoclass", this.refresh); |
michael@0 | 85 | |
michael@0 | 86 | this.onSelect(); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | exports.RuleViewTool = RuleViewTool; |
michael@0 | 90 | |
michael@0 | 91 | RuleViewTool.prototype = { |
michael@0 | 92 | onSelect: function RVT_onSelect(aEvent) { |
michael@0 | 93 | if (!this.view) { |
michael@0 | 94 | // Skip the event if RuleViewTool has been destroyed. |
michael@0 | 95 | return; |
michael@0 | 96 | } |
michael@0 | 97 | this.view.setPageStyle(this.inspector.pageStyle); |
michael@0 | 98 | |
michael@0 | 99 | if (!this.inspector.selection.isConnected() || |
michael@0 | 100 | !this.inspector.selection.isElementNode()) { |
michael@0 | 101 | this.view.highlight(null); |
michael@0 | 102 | return; |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | if (!aEvent || aEvent == "new-node-front") { |
michael@0 | 106 | let done = this.inspector.updating("rule-view"); |
michael@0 | 107 | this.view.highlight(this.inspector.selection.nodeFront).then(done, done); |
michael@0 | 108 | } |
michael@0 | 109 | }, |
michael@0 | 110 | |
michael@0 | 111 | refresh: function RVT_refresh() { |
michael@0 | 112 | this.view.nodeChanged(); |
michael@0 | 113 | }, |
michael@0 | 114 | |
michael@0 | 115 | destroy: function RVT_destroy() { |
michael@0 | 116 | this.inspector.off("layout-change", this.refresh); |
michael@0 | 117 | this.inspector.selection.off("pseudoclass", this.refresh); |
michael@0 | 118 | this.inspector.selection.off("new-node-front", this._onSelect); |
michael@0 | 119 | |
michael@0 | 120 | this.view.element.removeEventListener("CssRuleViewCSSLinkClicked", |
michael@0 | 121 | this._cssLinkHandler); |
michael@0 | 122 | |
michael@0 | 123 | this.view.element.removeEventListener("CssRuleViewChanged", |
michael@0 | 124 | this._changeHandler); |
michael@0 | 125 | |
michael@0 | 126 | this.view.element.removeEventListener("CssRuleViewRefreshed", |
michael@0 | 127 | this._refreshHandler); |
michael@0 | 128 | |
michael@0 | 129 | this.doc.documentElement.removeChild(this.view.element); |
michael@0 | 130 | |
michael@0 | 131 | this.view.destroy(); |
michael@0 | 132 | |
michael@0 | 133 | delete this.outerIFrame; |
michael@0 | 134 | delete this.view; |
michael@0 | 135 | delete this.doc; |
michael@0 | 136 | delete this.inspector; |
michael@0 | 137 | } |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | function ComputedViewTool(aInspector, aWindow, aIFrame) |
michael@0 | 141 | { |
michael@0 | 142 | this.inspector = aInspector; |
michael@0 | 143 | this.window = aWindow; |
michael@0 | 144 | this.document = aWindow.document; |
michael@0 | 145 | this.outerIFrame = aIFrame; |
michael@0 | 146 | this.view = new ComputedView.CssHtmlTree(this, aInspector.pageStyle); |
michael@0 | 147 | |
michael@0 | 148 | this._onSelect = this.onSelect.bind(this); |
michael@0 | 149 | this.inspector.selection.on("detached", this._onSelect); |
michael@0 | 150 | this.inspector.selection.on("new-node-front", this._onSelect); |
michael@0 | 151 | this.refresh = this.refresh.bind(this); |
michael@0 | 152 | this.inspector.on("layout-change", this.refresh); |
michael@0 | 153 | this.inspector.selection.on("pseudoclass", this.refresh); |
michael@0 | 154 | |
michael@0 | 155 | this.view.highlight(null); |
michael@0 | 156 | |
michael@0 | 157 | this.onSelect(); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | exports.ComputedViewTool = ComputedViewTool; |
michael@0 | 161 | |
michael@0 | 162 | ComputedViewTool.prototype = { |
michael@0 | 163 | onSelect: function CVT_onSelect(aEvent) |
michael@0 | 164 | { |
michael@0 | 165 | if (!this.view) { |
michael@0 | 166 | // Skip the event if ComputedViewTool has been destroyed. |
michael@0 | 167 | return; |
michael@0 | 168 | } |
michael@0 | 169 | this.view.setPageStyle(this.inspector.pageStyle); |
michael@0 | 170 | |
michael@0 | 171 | if (!this.inspector.selection.isConnected() || |
michael@0 | 172 | !this.inspector.selection.isElementNode()) { |
michael@0 | 173 | this.view.highlight(null); |
michael@0 | 174 | return; |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | if (!aEvent || aEvent == "new-node-front") { |
michael@0 | 178 | let done = this.inspector.updating("computed-view"); |
michael@0 | 179 | this.view.highlight(this.inspector.selection.nodeFront).then(() => { |
michael@0 | 180 | done(); |
michael@0 | 181 | }); |
michael@0 | 182 | } |
michael@0 | 183 | }, |
michael@0 | 184 | |
michael@0 | 185 | refresh: function CVT_refresh() { |
michael@0 | 186 | this.view.refreshPanel(); |
michael@0 | 187 | }, |
michael@0 | 188 | |
michael@0 | 189 | destroy: function CVT_destroy(aContext) |
michael@0 | 190 | { |
michael@0 | 191 | this.inspector.off("layout-change", this.refresh); |
michael@0 | 192 | this.inspector.sidebar.off("computedview-selected", this.refresh); |
michael@0 | 193 | this.inspector.selection.off("pseudoclass", this.refresh); |
michael@0 | 194 | this.inspector.selection.off("new-node-front", this._onSelect); |
michael@0 | 195 | |
michael@0 | 196 | this.view.destroy(); |
michael@0 | 197 | delete this.view; |
michael@0 | 198 | |
michael@0 | 199 | delete this.outerIFrame; |
michael@0 | 200 | delete this.cssLogic; |
michael@0 | 201 | delete this.cssHtmlTree; |
michael@0 | 202 | delete this.window; |
michael@0 | 203 | delete this.document; |
michael@0 | 204 | delete this.inspector; |
michael@0 | 205 | } |
michael@0 | 206 | }; |