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

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

Issue 1204393002: DevTools: [CSS] promisify CSSStyleModel fetching methods (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @extends {WebInspector.Object} 6 * @extends {WebInspector.Object}
7 * @constructor 7 * @constructor
8 */ 8 */
9 WebInspector.SharedSidebarModel = function() 9 WebInspector.SharedSidebarModel = function()
10 { 10 {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 * @return {!Promise.<?WebInspector.SharedSidebarModel.ComputedStyle>} 100 * @return {!Promise.<?WebInspector.SharedSidebarModel.ComputedStyle>}
101 */ 101 */
102 fetchComputedStyle: function() 102 fetchComputedStyle: function()
103 { 103 {
104 var elementNode = this._elementNode(); 104 var elementNode = this._elementNode();
105 var cssModel = this.cssModel(); 105 var cssModel = this.cssModel();
106 if (!elementNode || !cssModel) 106 if (!elementNode || !cssModel)
107 return Promise.resolve(/** @type {?WebInspector.SharedSidebarModel.C omputedStyle} */(null)); 107 return Promise.resolve(/** @type {?WebInspector.SharedSidebarModel.C omputedStyle} */(null));
108 108
109 if (!this._computedStylePromise) 109 if (!this._computedStylePromise)
110 this._computedStylePromise = new Promise(getComputedStyle.bind(null, elementNode)).then(verifyOutdated.bind(this, elementNode)); 110 this._computedStylePromise = cssModel.computedStylePromise(elementNo de.id).then(verifyOutdated.bind(this, elementNode));
111 111
112 return this._computedStylePromise; 112 return this._computedStylePromise;
113 113
114 /** 114 /**
115 * @param {!WebInspector.DOMNode} elementNode 115 * @param {!WebInspector.DOMNode} elementNode
116 * @param {function(?WebInspector.CSSStyleDeclaration)} resolve
117 */
118 function getComputedStyle(elementNode, resolve)
119 {
120 cssModel.getComputedStyleAsync(elementNode.id, resolve);
121 }
122
123 /**
124 * @param {!WebInspector.DOMNode} elementNode
125 * @param {?WebInspector.CSSStyleDeclaration} style 116 * @param {?WebInspector.CSSStyleDeclaration} style
126 * @return {?WebInspector.SharedSidebarModel.ComputedStyle} 117 * @return {?WebInspector.SharedSidebarModel.ComputedStyle}
127 * @this {WebInspector.SharedSidebarModel} 118 * @this {WebInspector.SharedSidebarModel}
128 */ 119 */
129 function verifyOutdated(elementNode, style) 120 function verifyOutdated(elementNode, style)
130 { 121 {
131 return elementNode === this._elementNode() && style ? new WebInspect or.SharedSidebarModel.ComputedStyle(elementNode, style) : /** @type {?WebInspect or.SharedSidebarModel.ComputedStyle} */(null); 122 return elementNode === this._elementNode() && style ? new WebInspect or.SharedSidebarModel.ComputedStyle(elementNode, style) : /** @type {?WebInspect or.SharedSidebarModel.ComputedStyle} */(null);
132 } 123 }
133 }, 124 },
134 125
135 _onComputedStyleChanged: function() 126 _onComputedStyleChanged: function()
136 { 127 {
137 delete this._computedStylePromise; 128 delete this._computedStylePromise;
138 this.dispatchEventToListeners(WebInspector.SharedSidebarModel.Events.Com putedStyleChanged); 129 this.dispatchEventToListeners(WebInspector.SharedSidebarModel.Events.Com putedStyleChanged);
139 }, 130 },
140 131
141 __proto__: WebInspector.Object.prototype 132 __proto__: WebInspector.Object.prototype
142 } 133 }
143 134
144 /** 135 /**
145 * @constructor 136 * @constructor
146 * @param {!WebInspector.DOMNode} node 137 * @param {!WebInspector.DOMNode} node
147 * @param {!WebInspector.CSSStyleDeclaration} computedStyle 138 * @param {!WebInspector.CSSStyleDeclaration} computedStyle
148 */ 139 */
149 WebInspector.SharedSidebarModel.ComputedStyle = function(node, computedStyle) 140 WebInspector.SharedSidebarModel.ComputedStyle = function(node, computedStyle)
150 { 141 {
151 this.node = node; 142 this.node = node;
152 this.computedStyle = computedStyle; 143 this.computedStyle = computedStyle;
153 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698