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

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

Issue 1196193016: DevTools: [CSS] promisify CSS domain (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address comments 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 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 337
338 /** 338 /**
339 * @return {!Promise.<?{matched: !WebInspector.SectionCascade, pseudo: !Map. <number, !WebInspector.SectionCascade>}>} 339 * @return {!Promise.<?{matched: !WebInspector.SectionCascade, pseudo: !Map. <number, !WebInspector.SectionCascade>}>}
340 */ 340 */
341 fetchMatchedCascade: function() 341 fetchMatchedCascade: function()
342 { 342 {
343 var node = this.node(); 343 var node = this.node();
344 if (!node) 344 if (!node)
345 return Promise.resolve(/** @type {?{matched: !WebInspector.SectionCa scade, pseudo: !Map.<number, !WebInspector.SectionCascade>}} */(null)); 345 return Promise.resolve(/** @type {?{matched: !WebInspector.SectionCa scade, pseudo: !Map.<number, !WebInspector.SectionCascade>}} */(null));
346 if (!this._matchedCascadePromise) 346 if (!this._matchedCascadePromise)
347 this._matchedCascadePromise = new Promise(this._getMatchedStylesForN ode.bind(this, node)).then(buildMatchedCascades.bind(this, node)); 347 this._matchedCascadePromise = this._getMatchedStylesForNode(node).th en(buildMatchedCascades.bind(this, node));
348 return this._matchedCascadePromise; 348 return this._matchedCascadePromise;
349 349
350 /** 350 /**
351 * @param {!WebInspector.DOMNode} node 351 * @param {!WebInspector.DOMNode} node
352 * @param {!WebInspector.StylesSidebarPane.MatchedRulesPayload} payload 352 * @param {!WebInspector.StylesSidebarPane.MatchedRulesPayload} payload
353 * @return {?{matched: !WebInspector.SectionCascade, pseudo: !Map.<numbe r, !WebInspector.SectionCascade>}} 353 * @return {?{matched: !WebInspector.SectionCascade, pseudo: !Map.<numbe r, !WebInspector.SectionCascade>}}
354 * @this {WebInspector.StylesSidebarPane} 354 * @this {WebInspector.StylesSidebarPane}
355 */ 355 */
356 function buildMatchedCascades(node, payload) 356 function buildMatchedCascades(node, payload)
357 { 357 {
358 if (node !== this.node() || !payload.fulfilled()) 358 if (node !== this.node() || !payload.fulfilled())
359 return null; 359 return null;
360 360
361 return { 361 return {
362 matched: this._buildMatchedRulesSectionCascade(node, payload), 362 matched: this._buildMatchedRulesSectionCascade(node, payload),
363 pseudo: this._buildPseudoCascades(node, payload) 363 pseudo: this._buildPseudoCascades(node, payload)
364 }; 364 };
365 } 365 }
366 }, 366 },
367 367
368 /** 368 /**
369 * @param {!WebInspector.DOMNode} node 369 * @param {!WebInspector.DOMNode} node
370 * @param {function(!WebInspector.StylesSidebarPane.MatchedRulesPayload)} ca llback 370 * @return {!Promise.<!WebInspector.StylesSidebarPane.MatchedRulesPayload>}
371 */ 371 */
372 _getMatchedStylesForNode: function(node, callback) 372 _getMatchedStylesForNode: function(node)
pfeldman 2015/06/25 16:16:11 _matchedStylesForNode
lushnikov 2015/06/25 16:40:30 Done.
373 { 373 {
374 var payload = new WebInspector.StylesSidebarPane.MatchedRulesPayload(); 374 var payload = new WebInspector.StylesSidebarPane.MatchedRulesPayload();
375 var cssModel = this.cssModel(); 375 var cssModel = this.cssModel();
376 if (!cssModel) { 376 if (!cssModel)
377 callback(payload); 377 return Promise.resolve(payload);
378 return; 378
379 } 379 var promises = [
380 cssModel.getInlineStylesAsync(node.id, inlineCallback); 380 cssModel.getInlineStylesPromise(node.id).then(inlineCallback),
381 cssModel.getMatchedStylesAsync(node.id, false, false, matchedCallback); 381 cssModel.getMatchedStylesPromise(node.id, false, false).then(matched Callback)
382 ];
383 return Promise.all(promises).then(returnPayload);
382 384
383 /** 385 /**
384 * @param {?WebInspector.CSSStyleModel.InlineStyleResult} inlineStyleRes ult 386 * @param {?WebInspector.CSSStyleModel.InlineStyleResult} inlineStyleRes ult
385 */ 387 */
386 function inlineCallback(inlineStyleResult) 388 function inlineCallback(inlineStyleResult)
387 { 389 {
388 if (!inlineStyleResult) 390 if (!inlineStyleResult)
389 return; 391 return;
390 payload.inlineStyle = inlineStyleResult.inlineStyle; 392 payload.inlineStyle = inlineStyleResult.inlineStyle;
391 payload.attributesStyle = inlineStyleResult.attributesStyle; 393 payload.attributesStyle = inlineStyleResult.attributesStyle;
392 } 394 }
393 395
394 /** 396 /**
395 * @param {?WebInspector.CSSStyleModel.MatchedStyleResult} matchedResult 397 * @param {?WebInspector.CSSStyleModel.MatchedStyleResult} matchedResult
396 */ 398 */
397 function matchedCallback(matchedResult) 399 function matchedCallback(matchedResult)
398 { 400 {
399 if (matchedResult) { 401 if (matchedResult) {
400 payload.matchedCSSRules = matchedResult.matchedCSSRules; 402 payload.matchedCSSRules = matchedResult.matchedCSSRules;
401 payload.pseudoElements = matchedResult.pseudoElements; 403 payload.pseudoElements = matchedResult.pseudoElements;
402 payload.inherited = matchedResult.inherited; 404 payload.inherited = matchedResult.inherited;
403 } 405 }
404 callback(payload); 406 }
407
408 /**
409 * @return {!WebInspector.StylesSidebarPane.MatchedRulesPayload}
410 */
411 function returnPayload()
412 {
413 return payload;
405 } 414 }
406 }, 415 },
407 416
408 /** 417 /**
409 * @param {boolean} editing 418 * @param {boolean} editing
410 */ 419 */
411 setEditingStyle: function(editing) 420 setEditingStyle: function(editing)
412 { 421 {
413 if (this._isEditingStyle === editing) 422 if (this._isEditingStyle === editing)
414 return; 423 return;
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 */ 1552 */
1544 _editingMediaCommitted: function(media, element, newContent, oldContent, con text, moveDirection) 1553 _editingMediaCommitted: function(media, element, newContent, oldContent, con text, moveDirection)
1545 { 1554 {
1546 this._parentPane.setEditingStyle(false); 1555 this._parentPane.setEditingStyle(false);
1547 this._editingMediaFinished(element); 1556 this._editingMediaFinished(element);
1548 1557
1549 if (newContent) 1558 if (newContent)
1550 newContent = newContent.trim(); 1559 newContent = newContent.trim();
1551 1560
1552 /** 1561 /**
1553 * @param {!WebInspector.CSSMedia} newMedia 1562 * @param {?WebInspector.CSSMedia} newMedia
1554 * @this {WebInspector.StylePropertiesSection} 1563 * @this {WebInspector.StylePropertiesSection}
1555 */ 1564 */
1556 function successCallback(newMedia) 1565 function userCallback(newMedia)
1557 { 1566 {
1558 this._parentPane._styleSheetMediaEdited(media, newMedia); 1567 if (newMedia) {
1559 this._parentPane._refreshUpdate(this); 1568 this._parentPane._styleSheetMediaEdited(media, newMedia);
1560 finishOperation.call(this); 1569 this._parentPane._refreshUpdate(this);
1561 } 1570 }
1562
1563 /**
1564 * @this {WebInspector.StylePropertiesSection}
1565 */
1566 function finishOperation()
1567 {
1568 delete this._parentPane._userOperation; 1571 delete this._parentPane._userOperation;
1569 this._editingMediaTextCommittedForTest(); 1572 this._editingMediaTextCommittedForTest();
1570 } 1573 }
1571 1574
1572 // This gets deleted in finishOperation(), which is called both on succe ss and failure. 1575 // This gets deleted in finishOperation(), which is called both on succe ss and failure.
1573 this._parentPane._userOperation = true; 1576 this._parentPane._userOperation = true;
1574 this._parentPane._cssModel.setMediaText(media, newContent, successCallba ck.bind(this), finishOperation.bind(this)); 1577 this._parentPane._cssModel.setMediaText(media, newContent, userCallback. bind(this));
1575 }, 1578 },
1576 1579
1577 _editingMediaTextCommittedForTest: function() { }, 1580 _editingMediaTextCommittedForTest: function() { },
1578 1581
1579 /** 1582 /**
1580 * @param {!Event} event 1583 * @param {!Event} event
1581 */ 1584 */
1582 _handleSelectorClick: function(event) 1585 _handleSelectorClick: function(event)
1583 { 1586 {
1584 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEv ent} */(event)) && this.navigable && event.target.classList.contains("simple-sel ector")) { 1587 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEv ent} */(event)) && this.navigable && event.target.classList.contains("simple-sel ector")) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 if (newContent) 1697 if (newContent)
1695 newContent = newContent.trim(); 1698 newContent = newContent.trim();
1696 if (newContent === oldContent) { 1699 if (newContent === oldContent) {
1697 // Revert to a trimmed version of the selector if need be. 1700 // Revert to a trimmed version of the selector if need be.
1698 this._selectorElement.textContent = newContent; 1701 this._selectorElement.textContent = newContent;
1699 this._moveEditorFromSelector(moveDirection); 1702 this._moveEditorFromSelector(moveDirection);
1700 return; 1703 return;
1701 } 1704 }
1702 1705
1703 /** 1706 /**
1704 * @param {!WebInspector.CSSRule} newRule 1707 * @param {?WebInspector.CSSRule} newRule
1705 * @this {WebInspector.StylePropertiesSection} 1708 * @this {WebInspector.StylePropertiesSection}
1706 */ 1709 */
1707 function successCallback(newRule) 1710 function finishCallback(newRule)
1708 { 1711 {
1709 var doesAffectSelectedNode = newRule.matchingSelectors.length > 0; 1712 if (newRule) {
1710 this.element.classList.toggle("no-affect", !doesAffectSelectedNode); 1713 var doesAffectSelectedNode = newRule.matchingSelectors.length > 0;
1714 this.element.classList.toggle("no-affect", !doesAffectSelectedNo de);
1711 1715
1712 var oldSelectorRange = this.rule().selectorRange; 1716 var oldSelectorRange = this.rule().selectorRange;
1713 this.styleRule.updateRule(newRule); 1717 this.styleRule.updateRule(newRule);
1714 1718
1715 this._parentPane._refreshUpdate(this); 1719 this._parentPane._refreshUpdate(this);
1716 this._parentPane._styleSheetRuleEdited(newRule, oldSelectorRange, ne wRule.selectorRange); 1720 this._parentPane._styleSheetRuleEdited(newRule, oldSelectorRange , newRule.selectorRange);
1721 }
1717 1722
1718 finishOperationAndMoveEditor.call(this, moveDirection);
1719 }
1720
1721 /**
1722 * @param {string} direction
1723 * @this {WebInspector.StylePropertiesSection}
1724 */
1725 function finishOperationAndMoveEditor(direction)
1726 {
1727 delete this._parentPane._userOperation; 1723 delete this._parentPane._userOperation;
1728 this._moveEditorFromSelector(direction); 1724 this._moveEditorFromSelector(moveDirection);
1729 this._editingSelectorCommittedForTest(); 1725 this._editingSelectorCommittedForTest();
1730 } 1726 }
1731 1727
1732 // This gets deleted in finishOperationAndMoveEditor(), which is called both on success and failure. 1728 // This gets deleted in finishOperationAndMoveEditor(), which is called both on success and failure.
1733 this._parentPane._userOperation = true; 1729 this._parentPane._userOperation = true;
1734 var selectedNode = this._parentPane.node(); 1730 var selectedNode = this._parentPane.node();
1735 this._parentPane._cssModel.setRuleSelector(this.rule(), selectedNode ? s electedNode.id : 0, newContent, successCallback.bind(this), finishOperationAndMo veEditor.bind(this, moveDirection)); 1731 this._parentPane._cssModel.setRuleSelector(this.rule(), selectedNode ? s electedNode.id : 0, newContent, finishCallback.bind(this));
1736 }, 1732 },
1737 1733
1738 _editingSelectorCommittedForTest: function() { }, 1734 _editingSelectorCommittedForTest: function() { },
1739 1735
1740 _updateRuleOrigin: function() 1736 _updateRuleOrigin: function()
1741 { 1737 {
1742 this._selectorRefElement.removeChildren(); 1738 this._selectorRefElement.removeChildren();
1743 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection .createRuleOriginNode(this._parentPane._cssModel, this._parentPane._linkifier, t his.rule())); 1739 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection .createRuleOriginNode(this._parentPane._cssModel, this._parentPane._linkifier, t his.rule()));
1744 }, 1740 },
1745 1741
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1872 * @param {string} moveDirection 1868 * @param {string} moveDirection
1873 */ 1869 */
1874 editingSelectorCommitted: function(element, newContent, oldContent, context, moveDirection) 1870 editingSelectorCommitted: function(element, newContent, oldContent, context, moveDirection)
1875 { 1871 {
1876 if (!this.isBlank) { 1872 if (!this.isBlank) {
1877 WebInspector.StylePropertiesSection.prototype.editingSelectorCommitt ed.call(this, element, newContent, oldContent, context, moveDirection); 1873 WebInspector.StylePropertiesSection.prototype.editingSelectorCommitt ed.call(this, element, newContent, oldContent, context, moveDirection);
1878 return; 1874 return;
1879 } 1875 }
1880 1876
1881 /** 1877 /**
1882 * @param {!WebInspector.CSSRule} newRule 1878 * @param {?WebInspector.CSSRule} newRule
1883 * @this {WebInspector.StylePropertiesSection} 1879 * @this {WebInspector.StylePropertiesSection}
1884 */ 1880 */
1885 function successCallback(newRule) 1881 function userCallback(newRule)
1886 { 1882 {
1883 if (!newRule) {
1884 this.editingSelectorCancelled();
1885 this._editingSelectorCommittedForTest();
1886 return;
1887 }
1887 var doesSelectorAffectSelectedNode = newRule.matchingSelectors.lengt h > 0; 1888 var doesSelectorAffectSelectedNode = newRule.matchingSelectors.lengt h > 0;
1888 this._makeNormal(newRule); 1889 this._makeNormal(newRule);
1889 1890
1890 if (!doesSelectorAffectSelectedNode) 1891 if (!doesSelectorAffectSelectedNode)
1891 this.element.classList.add("no-affect"); 1892 this.element.classList.add("no-affect");
1892 1893
1893 var ruleTextLines = ruleText.split("\n"); 1894 var ruleTextLines = ruleText.split("\n");
1894 var startLine = this._ruleLocation.startLine; 1895 var startLine = this._ruleLocation.startLine;
1895 var startColumn = this._ruleLocation.startColumn; 1896 var startColumn = this._ruleLocation.startColumn;
1896 var newRange = new WebInspector.TextRange(startLine, startColumn, st artLine + ruleTextLines.length - 1, startColumn + ruleTextLines[ruleTextLines.le ngth - 1].length); 1897 var newRange = new WebInspector.TextRange(startLine, startColumn, st artLine + ruleTextLines.length - 1, startColumn + ruleTextLines[ruleTextLines.le ngth - 1].length);
1897 this._parentPane._styleSheetRuleEdited(newRule, this._ruleLocation, newRange); 1898 this._parentPane._styleSheetRuleEdited(newRule, this._ruleLocation, newRange);
1898 1899
1899 this._updateRuleOrigin(); 1900 this._updateRuleOrigin();
1900 if (this.element.parentElement) // Might have been detached already. 1901 if (this.element.parentElement) // Might have been detached already.
1901 this._moveEditorFromSelector(moveDirection); 1902 this._moveEditorFromSelector(moveDirection);
1902 1903
1903 delete this._parentPane._userOperation; 1904 delete this._parentPane._userOperation;
1904 this._editingSelectorEnded(); 1905 this._editingSelectorEnded();
1905 this._markSelectorMatches(); 1906 this._markSelectorMatches();
1906 1907
1907 this._editingSelectorCommittedForTest(); 1908 this._editingSelectorCommittedForTest();
1908 } 1909 }
1909 1910
1910 /**
1911 * @this {WebInspector.StylePropertiesSection}
1912 */
1913 function failureCallback()
1914 {
1915 this.editingSelectorCancelled();
1916 this._editingSelectorCommittedForTest();
1917 }
1918
1919 if (newContent) 1911 if (newContent)
1920 newContent = newContent.trim(); 1912 newContent = newContent.trim();
1921 this._parentPane._userOperation = true; 1913 this._parentPane._userOperation = true;
1922 1914
1923 var cssModel = this._parentPane._cssModel; 1915 var cssModel = this._parentPane._cssModel;
1924 var ruleText = this._rulePrefix() + newContent + " {}"; 1916 var ruleText = this._rulePrefix() + newContent + " {}";
1925 cssModel.addRule(this._styleSheetId, this._parentPane.node(), ruleText, this._ruleLocation, successCallback.bind(this), failureCallback.bind(this)); 1917 cssModel.addRule(this._styleSheetId, this._parentPane.node(), ruleText, this._ruleLocation, userCallback.bind(this));
1926 }, 1918 },
1927 1919
1928 editingSelectorCancelled: function() 1920 editingSelectorCancelled: function()
1929 { 1921 {
1930 delete this._parentPane._userOperation; 1922 delete this._parentPane._userOperation;
1931 if (!this.isBlank) { 1923 if (!this.isBlank) {
1932 WebInspector.StylePropertiesSection.prototype.editingSelectorCancell ed.call(this); 1924 WebInspector.StylePropertiesSection.prototype.editingSelectorCancell ed.call(this);
1933 return; 1925 return;
1934 } 1926 }
1935 1927
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
3240 3232
3241 /** 3233 /**
3242 * @override 3234 * @override
3243 * @return {?WebInspector.ToolbarItem} 3235 * @return {?WebInspector.ToolbarItem}
3244 */ 3236 */
3245 item: function() 3237 item: function()
3246 { 3238 {
3247 return this._button; 3239 return this._button;
3248 } 3240 }
3249 } 3241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698