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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/SharedSidebarModel.js

Issue 2144923002: DevTools: remove the ComputedStyles -> Styles pane dependency. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @extends {WebInspector.Object}
7 * @constructor
8 */
9 WebInspector.SharedSidebarModel = function()
10 {
11 WebInspector.Object.call(this);
12 this._node = WebInspector.context.flavor(WebInspector.DOMNode);
13 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._onN odeChanged, this);
14 }
15
16 WebInspector.SharedSidebarModel.Events = {
17 ComputedStyleChanged: "ComputedStyleChanged"
18 }
19
20 WebInspector.SharedSidebarModel.prototype = {
21 /**
22 * @return {?WebInspector.DOMNode}
23 */
24 node: function()
25 {
26 return this._node;
27 },
28
29 /**
30 * @return {?WebInspector.CSSModel}
31 */
32 cssModel: function()
33 {
34 return this._cssModel;
35 },
36
37 /**
38 * @param {!WebInspector.Event} event
39 */
40 _onNodeChanged: function(event)
41 {
42 this._node = /** @type {?WebInspector.DOMNode} */(event.data);
43 this._updateTarget(this._node ? this._node.target() : null);
44 this._onComputedStyleChanged();
45 },
46
47 /**
48 * @param {?WebInspector.Target} target
49 */
50 _updateTarget: function(target)
51 {
52 if (this._target === target)
53 return;
54 if (this._targetEvents) {
55 WebInspector.EventTarget.removeEventListeners(this._targetEvents);
56 this._targetEvents = null;
57 }
58 this._target = target;
59 var domModel = null;
60 if (target) {
61 this._cssModel = WebInspector.CSSModel.fromTarget(target);
62 domModel = WebInspector.DOMModel.fromTarget(target);
63 }
64
65 if (domModel && this._cssModel) {
66 this._targetEvents = [
67 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetAdded, this._onComputedStyleChanged, this),
68 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetRemoved, this._onComputedStyleChanged, this),
69 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetChanged, this._onComputedStyleChanged, this),
70 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Med iaQueryResultChanged, this._onComputedStyleChanged, this),
71 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Pse udoStateForced, this._onComputedStyleChanged, this),
72 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Mod elWasEnabled, this._onComputedStyleChanged, this),
73 domModel.addEventListener(WebInspector.DOMModel.Events.DOMMutate d, this._onComputedStyleChanged, this)
74 ];
75 }
76 },
77
78 /**
79 * @return {?WebInspector.DOMNode}
80 */
81 _elementNode: function()
82 {
83 return this.node() ? this.node().enclosingElementOrSelf() : null;
84 },
85
86 /**
87 * @return {!Promise.<?WebInspector.SharedSidebarModel.ComputedStyle>}
88 */
89 fetchComputedStyle: function()
90 {
91 var elementNode = this._elementNode();
92 var cssModel = this.cssModel();
93 if (!elementNode || !cssModel)
94 return Promise.resolve(/** @type {?WebInspector.SharedSidebarModel.C omputedStyle} */(null));
95
96 if (!this._computedStylePromise)
97 this._computedStylePromise = cssModel.computedStylePromise(elementNo de.id).then(verifyOutdated.bind(this, elementNode));
98
99 return this._computedStylePromise;
100
101 /**
102 * @param {!WebInspector.DOMNode} elementNode
103 * @param {?Map.<string, string>} style
104 * @return {?WebInspector.SharedSidebarModel.ComputedStyle}
105 * @this {WebInspector.SharedSidebarModel}
106 */
107 function verifyOutdated(elementNode, style)
108 {
109 return elementNode === this._elementNode() && style ? new WebInspect or.SharedSidebarModel.ComputedStyle(elementNode, style) : /** @type {?WebInspect or.SharedSidebarModel.ComputedStyle} */(null);
110 }
111 },
112
113 _onComputedStyleChanged: function()
114 {
115 delete this._computedStylePromise;
116 this.dispatchEventToListeners(WebInspector.SharedSidebarModel.Events.Com putedStyleChanged);
117 },
118
119 __proto__: WebInspector.Object.prototype
120 }
121
122 /**
123 * @constructor
124 * @param {!WebInspector.DOMNode} node
125 * @param {!Map.<string, string>} computedStyle
126 */
127 WebInspector.SharedSidebarModel.ComputedStyle = function(node, computedStyle)
128 {
129 this.node = node;
130 this.computedStyle = computedStyle;
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698