Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: Source/devtools/front_end/MetricsSidebarPane.js

Issue 221253002: DevTools: move off WebInspector.css/domModel in sidebars. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review comment addressed. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
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 /** 29 /**
30 * @constructor 30 * @constructor
31 * @extends {WebInspector.SidebarPane} 31 * @extends {WebInspector.SidebarPane}
32 */ 32 */
33 WebInspector.MetricsSidebarPane = function() 33 WebInspector.MetricsSidebarPane = function()
34 { 34 {
35 WebInspector.SidebarPane.call(this, WebInspector.UIString("Metrics")); 35 WebInspector.SidebarPane.call(this, WebInspector.UIString("Metrics"));
36
37 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetChanged, this._styleSheetOrMediaQueryResultChanged, this);
38 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Med iaQueryResultChanged, this._styleSheetOrMediaQueryResultChanged, this);
39 WebInspector.domModel.addEventListener(WebInspector.DOMModel.Events.AttrModi fied, this._attributesUpdated, this);
40 WebInspector.domModel.addEventListener(WebInspector.DOMModel.Events.AttrRemo ved, this._attributesUpdated, this);
41 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeMod el.EventTypes.FrameResized, this._frameResized, this);
42 } 36 }
43 37
44 WebInspector.MetricsSidebarPane.prototype = { 38 WebInspector.MetricsSidebarPane.prototype = {
45 /** 39 /**
46 * @param {?WebInspector.DOMNode=} node 40 * @param {?WebInspector.DOMNode=} node
47 */ 41 */
48 update: function(node) 42 update: function(node)
49 { 43 {
50 if (node) 44 if (!node || this._node === node) {
51 this.node = node; 45 this._innerUpdate();
46 return;
47 }
48
49 this._node = node;
50 this._updateTarget(node.target());
52 this._innerUpdate(); 51 this._innerUpdate();
53 }, 52 },
54 53
54 /**
55 * @param {!WebInspector.Target} target
56 */
57 _updateTarget: function(target)
58 {
59 if (this._target === target)
60 return;
61
62 if (this._target) {
63 this._target.cssModel.removeEventListener(WebInspector.CSSStyleModel .Events.StyleSheetChanged, this._styleSheetOrMediaQueryResultChanged, this);
64 this._target.cssModel.removeEventListener(WebInspector.CSSStyleModel .Events.MediaQueryResultChanged, this._styleSheetOrMediaQueryResultChanged, this );
65 this._target.domModel.removeEventListener(WebInspector.DOMModel.Even ts.AttrModified, this._attributesUpdated, this);
66 this._target.domModel.removeEventListener(WebInspector.DOMModel.Even ts.AttrRemoved, this._attributesUpdated, this);
67 this._target.resourceTreeModel.removeEventListener(WebInspector.Reso urceTreeModel.EventTypes.FrameResized, this._frameResized, this);
68 }
69 this._target = target;
70 this._target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events .StyleSheetChanged, this._styleSheetOrMediaQueryResultChanged, this);
71 this._target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events .MediaQueryResultChanged, this._styleSheetOrMediaQueryResultChanged, this);
72 this._target.domModel.addEventListener(WebInspector.DOMModel.Events.Attr Modified, this._attributesUpdated, this);
73 this._target.domModel.addEventListener(WebInspector.DOMModel.Events.Attr Removed, this._attributesUpdated, this);
74 this._target.resourceTreeModel.addEventListener(WebInspector.ResourceTre eModel.EventTypes.FrameResized, this._frameResized, this);
75 },
76
55 _innerUpdate: function() 77 _innerUpdate: function()
56 { 78 {
57 // "style" attribute might have changed. Update metrics unless they are being edited 79 // "style" attribute might have changed. Update metrics unless they are being edited
58 // (if a CSS property is added, a StyleSheetChanged event is dispatched) . 80 // (if a CSS property is added, a StyleSheetChanged event is dispatched) .
59 if (this._isEditingMetrics) 81 if (this._isEditingMetrics)
60 return; 82 return;
61 83
62 // FIXME: avoid updates of a collapsed pane. 84 // FIXME: avoid updates of a collapsed pane.
63 var node = this.node; 85 var node = this._node;
64 86
65 if (!node || node.nodeType() !== Node.ELEMENT_NODE) { 87 if (!node || node.nodeType() !== Node.ELEMENT_NODE) {
66 this.bodyElement.removeChildren(); 88 this.bodyElement.removeChildren();
67 return; 89 return;
68 } 90 }
69 91
70 /** 92 /**
71 * @param {?WebInspector.CSSStyleDeclaration} style 93 * @param {?WebInspector.CSSStyleDeclaration} style
72 * @this {WebInspector.MetricsSidebarPane} 94 * @this {WebInspector.MetricsSidebarPane}
73 */ 95 */
74 function callback(style) 96 function callback(style)
75 { 97 {
76 if (!style || this.node !== node) 98 if (!style || this._node !== node)
77 return; 99 return;
78 this._updateMetrics(style); 100 this._updateMetrics(style);
79 } 101 }
80 WebInspector.cssModel.getComputedStyleAsync(node.id, callback.bind(this) ); 102 this._target.cssModel.getComputedStyleAsync(node.id, callback.bind(this) );
81 103
82 /** 104 /**
83 * @param {?WebInspector.CSSStyleDeclaration} style 105 * @param {?WebInspector.CSSStyleDeclaration} style
84 * @this {WebInspector.MetricsSidebarPane} 106 * @this {WebInspector.MetricsSidebarPane}
85 */ 107 */
86 function inlineStyleCallback(style) 108 function inlineStyleCallback(style)
87 { 109 {
88 if (!style || this.node !== node) 110 if (!style || this._node !== node)
89 return; 111 return;
90 this.inlineStyle = style; 112 this.inlineStyle = style;
91 } 113 }
92 WebInspector.cssModel.getInlineStylesAsync(node.id, inlineStyleCallback. bind(this)); 114 this._target.cssModel.getInlineStylesAsync(node.id, inlineStyleCallback. bind(this));
93 }, 115 },
94 116
95 _styleSheetOrMediaQueryResultChanged: function() 117 _styleSheetOrMediaQueryResultChanged: function()
96 { 118 {
97 this._innerUpdate(); 119 this._innerUpdate();
98 }, 120 },
99 121
100 _frameResized: function() 122 _frameResized: function()
101 { 123 {
102 /** 124 /**
103 * @this {WebInspector.MetricsSidebarPane} 125 * @this {WebInspector.MetricsSidebarPane}
104 */ 126 */
105 function refreshContents() 127 function refreshContents()
106 { 128 {
107 this._innerUpdate(); 129 this._innerUpdate();
108 delete this._activeTimer; 130 delete this._activeTimer;
109 } 131 }
110 132
111 if (this._activeTimer) 133 if (this._activeTimer)
112 clearTimeout(this._activeTimer); 134 clearTimeout(this._activeTimer);
113 135
114 this._activeTimer = setTimeout(refreshContents.bind(this), 100); 136 this._activeTimer = setTimeout(refreshContents.bind(this), 100);
115 }, 137 },
116 138
117 _attributesUpdated: function(event) 139 _attributesUpdated: function(event)
118 { 140 {
119 if (this.node !== event.data.node) 141 if (this._node !== event.data.node)
120 return; 142 return;
121 143
122 this._innerUpdate(); 144 this._innerUpdate();
123 }, 145 },
124 146
125 _getPropertyValueAsPx: function(style, propertyName) 147 _getPropertyValueAsPx: function(style, propertyName)
126 { 148 {
127 return Number(style.getPropertyValue(propertyName).replace(/px$/, "") || 0); 149 return Number(style.getPropertyValue(propertyName).replace(/px$/, "") || 0);
128 }, 150 },
129 151
130 _getBox: function(computedStyle, componentName) 152 _getBox: function(computedStyle, componentName)
131 { 153 {
132 var suffix = componentName === "border" ? "-width" : ""; 154 var suffix = componentName === "border" ? "-width" : "";
133 var left = this._getPropertyValueAsPx(computedStyle, componentName + "-l eft" + suffix); 155 var left = this._getPropertyValueAsPx(computedStyle, componentName + "-l eft" + suffix);
134 var top = this._getPropertyValueAsPx(computedStyle, componentName + "-to p" + suffix); 156 var top = this._getPropertyValueAsPx(computedStyle, componentName + "-to p" + suffix);
135 var right = this._getPropertyValueAsPx(computedStyle, componentName + "- right" + suffix); 157 var right = this._getPropertyValueAsPx(computedStyle, componentName + "- right" + suffix);
136 var bottom = this._getPropertyValueAsPx(computedStyle, componentName + " -bottom" + suffix); 158 var bottom = this._getPropertyValueAsPx(computedStyle, componentName + " -bottom" + suffix);
137 return { left: left, top: top, right: right, bottom: bottom }; 159 return { left: left, top: top, right: right, bottom: bottom };
138 }, 160 },
139 161
140 _highlightDOMNode: function(showHighlight, mode, event) 162 _highlightDOMNode: function(showHighlight, mode, event)
141 { 163 {
142 event.consume(); 164 event.consume();
143 if (showHighlight && this.node) { 165 if (showHighlight && this._node) {
144 if (this._highlightMode === mode) 166 if (this._highlightMode === mode)
145 return; 167 return;
146 this._highlightMode = mode; 168 this._highlightMode = mode;
147 this.node.highlight(mode); 169 this._node.highlight(mode);
148 } else { 170 } else {
149 delete this._highlightMode; 171 delete this._highlightMode;
150 WebInspector.domModel.hideDOMNodeHighlight(); 172 this._target.domModel.hideDOMNodeHighlight();
151 } 173 }
152 174
153 for (var i = 0; this._boxElements && i < this._boxElements.length; ++i) { 175 for (var i = 0; this._boxElements && i < this._boxElements.length; ++i) {
154 var element = this._boxElements[i]; 176 var element = this._boxElements[i];
155 if (!this.node || mode === "all" || element._name === mode) 177 if (!this._node || mode === "all" || element._name === mode)
156 element.style.backgroundColor = element._backgroundColor; 178 element.style.backgroundColor = element._backgroundColor;
157 else 179 else
158 element.style.backgroundColor = ""; 180 element.style.backgroundColor = "";
159 } 181 }
160 }, 182 },
161 183
162 /** 184 /**
163 * @param {!WebInspector.CSSStyleDeclaration} style 185 * @param {!WebInspector.CSSStyleDeclaration} style
164 */ 186 */
165 _updateMetrics: function(style) 187 _updateMetrics: function(style)
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 this.previousPropertyDataCandidate = null; 448 this.previousPropertyDataCandidate = null;
427 var self = this; 449 var self = this;
428 var callback = function(style) { 450 var callback = function(style) {
429 if (!style) 451 if (!style)
430 return; 452 return;
431 self.inlineStyle = style; 453 self.inlineStyle = style;
432 if (!("originalPropertyData" in self)) 454 if (!("originalPropertyData" in self))
433 self.originalPropertyData = self.previousPropertyDataCandidate; 455 self.originalPropertyData = self.previousPropertyDataCandidate;
434 456
435 if (typeof self._highlightMode !== "undefined") 457 if (typeof self._highlightMode !== "undefined")
436 self.node.highlight(self._highlightMode); 458 self._node.highlight(self._highlightMode);
437 459
438 if (commitEditor) { 460 if (commitEditor) {
439 self.dispatchEventToListeners("metrics edited"); 461 self.dispatchEventToListeners("metrics edited");
440 self.update(); 462 self.update();
441 } 463 }
442 }; 464 };
443 465
444 var allProperties = this.inlineStyle.allProperties; 466 var allProperties = this.inlineStyle.allProperties;
445 for (var i = 0; i < allProperties.length; ++i) { 467 for (var i = 0; i < allProperties.length; ++i) {
446 var property = allProperties[i]; 468 var property = allProperties[i];
447 if (property.name !== context.styleProperty || property.inactive) 469 if (property.name !== context.styleProperty || property.inactive)
448 continue; 470 continue;
449 471
450 this.previousPropertyDataCandidate = property; 472 this.previousPropertyDataCandidate = property;
451 property.setValue(userInput, commitEditor, true, callback); 473 property.setValue(userInput, commitEditor, true, callback);
452 return; 474 return;
453 } 475 }
454 476
455 this.inlineStyle.appendProperty(context.styleProperty, userInput, callba ck); 477 this.inlineStyle.appendProperty(context.styleProperty, userInput, callba ck);
456 }, 478 },
457 479
458 editingCommitted: function(element, userInput, previousContent, context) 480 editingCommitted: function(element, userInput, previousContent, context)
459 { 481 {
460 this.editingEnded(element, context); 482 this.editingEnded(element, context);
461 this._applyUserInput(element, userInput, previousContent, context, true) ; 483 this._applyUserInput(element, userInput, previousContent, context, true) ;
462 }, 484 },
463 485
464 __proto__: WebInspector.SidebarPane.prototype 486 __proto__: WebInspector.SidebarPane.prototype
465 } 487 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ElementsPanel.js ('k') | Source/devtools/front_end/PlatformFontsSidebarPane.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698