OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 11 matching lines...) Expand all Loading... |
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 WebInspector.MetricsSidebarPane = function() | 29 WebInspector.MetricsSidebarPane = function() |
30 { | 30 { |
31 WebInspector.SidebarPane.call(this, WebInspector.UIString("Metrics")); | 31 WebInspector.SidebarPane.call(this, WebInspector.UIString("Metrics")); |
| 32 this._inlineStyleId = null; |
32 } | 33 } |
33 | 34 |
34 WebInspector.MetricsSidebarPane.prototype = { | 35 WebInspector.MetricsSidebarPane.prototype = { |
35 update: function(node) | 36 update: function(node) |
36 { | 37 { |
37 var body = this.bodyElement; | 38 var body = this.bodyElement; |
38 | 39 |
39 body.removeChildren(); | 40 body.removeChildren(); |
40 | 41 |
41 if (node) | 42 if (node) |
42 this.node = node; | 43 this.node = node; |
43 else | 44 else |
44 node = this.node; | 45 node = this.node; |
45 | 46 |
46 if (!node || !node.ownerDocument.defaultView) | 47 if (!node || !node.ownerDocument.defaultView) |
47 return; | 48 return; |
48 | 49 |
49 var style; | 50 if (node.nodeType !== Node.ELEMENT_NODE) |
50 if (node.nodeType === Node.ELEMENT_NODE) | |
51 style = node.ownerDocument.defaultView.getComputedStyle(node); | |
52 if (!style) | |
53 return; | 51 return; |
54 | 52 |
| 53 var self = this; |
| 54 var callback = function(stylePayload) { |
| 55 if (!stylePayload) |
| 56 return; |
| 57 var style = WebInspector.CSSStyleDeclaration.parseStyle(stylePayload
); |
| 58 self._update(node, body, style); |
| 59 }; |
| 60 InspectorController.getComputedStyle(node.id, callback); |
| 61 |
| 62 var inlineStyleCallback = function(stylePayload) { |
| 63 if (!stylePayload) |
| 64 return; |
| 65 self._inlineStyleId = stylePayload.id; |
| 66 }; |
| 67 InspectorController.getInlineStyle(node.id, inlineStyleCallback); |
| 68 }, |
| 69 |
| 70 _update: function(node, body, style) |
| 71 { |
55 var metricsElement = document.createElement("div"); | 72 var metricsElement = document.createElement("div"); |
56 metricsElement.className = "metrics"; | 73 metricsElement.className = "metrics"; |
57 | 74 |
58 function createBoxPartElement(style, name, side, suffix) | 75 function createBoxPartElement(style, name, side, suffix) |
59 { | 76 { |
60 var propertyName = (name !== "position" ? name + "-" : "") + side +
suffix; | 77 var propertyName = (name !== "position" ? name + "-" : "") + side +
suffix; |
61 var value = style.getPropertyValue(propertyName); | 78 var value = style.getPropertyValue(propertyName); |
62 if (value === "" || (name !== "position" && value === "0px")) | 79 if (value === "" || (name !== "position" && value === "0px")) |
63 value = "\u2012"; | 80 value = "\u2012"; |
64 else if (name === "position" && value === "auto") | 81 else if (name === "position" && value === "auto") |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 194 |
178 if (context.box !== "position" && (!userInput || userInput === "\u2012")
) | 195 if (context.box !== "position" && (!userInput || userInput === "\u2012")
) |
179 userInput = "0px"; | 196 userInput = "0px"; |
180 else if (context.box === "position" && (!userInput || userInput === "\u2
012")) | 197 else if (context.box === "position" && (!userInput || userInput === "\u2
012")) |
181 userInput = "auto"; | 198 userInput = "auto"; |
182 | 199 |
183 // Append a "px" unit if the user input was just a number. | 200 // Append a "px" unit if the user input was just a number. |
184 if (/^\d+$/.test(userInput)) | 201 if (/^\d+$/.test(userInput)) |
185 userInput += "px"; | 202 userInput += "px"; |
186 | 203 |
187 this.node.style.setProperty(context.styleProperty, userInput, ""); | 204 var self = this; |
188 | 205 var callback = function(success) { |
189 this.dispatchEventToListeners("metrics edited"); | 206 if (!success) |
190 | 207 return; |
191 this.update(); | 208 self.dispatchEventToListeners("metrics edited"); |
| 209 self.update(); |
| 210 }; |
| 211 InspectorController.setStyleProperty(this._inlineStyleId, context.styleP
roperty, userInput, callback); |
192 } | 212 } |
193 } | 213 } |
194 | 214 |
195 WebInspector.MetricsSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.p
rototype; | 215 WebInspector.MetricsSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.p
rototype; |
OLD | NEW |