| OLD | NEW |
| 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 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 */ | 1542 */ |
| 1543 _editingMediaCommitted: function(media, element, newContent, oldContent, con
text, moveDirection) | 1543 _editingMediaCommitted: function(media, element, newContent, oldContent, con
text, moveDirection) |
| 1544 { | 1544 { |
| 1545 this._parentPane.setEditingStyle(false); | 1545 this._parentPane.setEditingStyle(false); |
| 1546 this._editingMediaFinished(element); | 1546 this._editingMediaFinished(element); |
| 1547 | 1547 |
| 1548 if (newContent) | 1548 if (newContent) |
| 1549 newContent = newContent.trim(); | 1549 newContent = newContent.trim(); |
| 1550 | 1550 |
| 1551 /** | 1551 /** |
| 1552 * @param {!WebInspector.CSSMedia} newMedia | 1552 * @param {?WebInspector.CSSMedia} newMedia |
| 1553 * @this {WebInspector.StylePropertiesSection} | 1553 * @this {WebInspector.StylePropertiesSection} |
| 1554 */ | 1554 */ |
| 1555 function successCallback(newMedia) | 1555 function userCallback(newMedia) |
| 1556 { | 1556 { |
| 1557 this._parentPane._styleSheetMediaEdited(media, newMedia); | 1557 if (newMedia) { |
| 1558 this._parentPane._refreshUpdate(this); | 1558 this._parentPane._styleSheetMediaEdited(media, newMedia); |
| 1559 finishOperation.call(this); | 1559 this._parentPane._refreshUpdate(this); |
| 1560 } | 1560 } |
| 1561 | |
| 1562 /** | |
| 1563 * @this {WebInspector.StylePropertiesSection} | |
| 1564 */ | |
| 1565 function finishOperation() | |
| 1566 { | |
| 1567 delete this._parentPane._userOperation; | 1561 delete this._parentPane._userOperation; |
| 1568 this._editingMediaTextCommittedForTest(); | 1562 this._editingMediaTextCommittedForTest(); |
| 1569 } | 1563 } |
| 1570 | 1564 |
| 1571 // This gets deleted in finishOperation(), which is called both on succe
ss and failure. | 1565 // This gets deleted in finishOperation(), which is called both on succe
ss and failure. |
| 1572 this._parentPane._userOperation = true; | 1566 this._parentPane._userOperation = true; |
| 1573 this._parentPane._cssModel.setMediaText(media, newContent, successCallba
ck.bind(this), finishOperation.bind(this)); | 1567 this._parentPane._cssModel.setMediaText(media, newContent, userCallback.
bind(this)); |
| 1574 }, | 1568 }, |
| 1575 | 1569 |
| 1576 _editingMediaTextCommittedForTest: function() { }, | 1570 _editingMediaTextCommittedForTest: function() { }, |
| 1577 | 1571 |
| 1578 /** | 1572 /** |
| 1579 * @param {!Event} event | 1573 * @param {!Event} event |
| 1580 */ | 1574 */ |
| 1581 _handleSelectorClick: function(event) | 1575 _handleSelectorClick: function(event) |
| 1582 { | 1576 { |
| 1583 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEv
ent} */(event)) && this.navigable && event.target.classList.contains("simple-sel
ector")) { | 1577 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 Loading... |
| 1693 if (newContent) | 1687 if (newContent) |
| 1694 newContent = newContent.trim(); | 1688 newContent = newContent.trim(); |
| 1695 if (newContent === oldContent) { | 1689 if (newContent === oldContent) { |
| 1696 // Revert to a trimmed version of the selector if need be. | 1690 // Revert to a trimmed version of the selector if need be. |
| 1697 this._selectorElement.textContent = newContent; | 1691 this._selectorElement.textContent = newContent; |
| 1698 this._moveEditorFromSelector(moveDirection); | 1692 this._moveEditorFromSelector(moveDirection); |
| 1699 return; | 1693 return; |
| 1700 } | 1694 } |
| 1701 | 1695 |
| 1702 /** | 1696 /** |
| 1703 * @param {!WebInspector.CSSRule} newRule | 1697 * @param {?WebInspector.CSSRule} newRule |
| 1704 * @this {WebInspector.StylePropertiesSection} | 1698 * @this {WebInspector.StylePropertiesSection} |
| 1705 */ | 1699 */ |
| 1706 function successCallback(newRule) | 1700 function finishCallback(newRule) |
| 1707 { | 1701 { |
| 1708 var doesAffectSelectedNode = newRule.matchingSelectors.length > 0; | 1702 if (newRule) { |
| 1709 this.element.classList.toggle("no-affect", !doesAffectSelectedNode); | 1703 var doesAffectSelectedNode = newRule.matchingSelectors.length >
0; |
| 1704 this.element.classList.toggle("no-affect", !doesAffectSelectedNo
de); |
| 1710 | 1705 |
| 1711 var oldSelectorRange = this.rule().selectorRange; | 1706 var oldSelectorRange = this.rule().selectorRange; |
| 1712 this.styleRule.updateRule(newRule); | 1707 this.styleRule.updateRule(newRule); |
| 1713 | 1708 |
| 1714 this._parentPane._refreshUpdate(this); | 1709 this._parentPane._refreshUpdate(this); |
| 1715 this._parentPane._styleSheetRuleEdited(newRule, oldSelectorRange, ne
wRule.selectorRange); | 1710 this._parentPane._styleSheetRuleEdited(newRule, oldSelectorRange
, newRule.selectorRange); |
| 1711 } |
| 1716 | 1712 |
| 1717 finishOperationAndMoveEditor.call(this, moveDirection); | |
| 1718 } | |
| 1719 | |
| 1720 /** | |
| 1721 * @param {string} direction | |
| 1722 * @this {WebInspector.StylePropertiesSection} | |
| 1723 */ | |
| 1724 function finishOperationAndMoveEditor(direction) | |
| 1725 { | |
| 1726 delete this._parentPane._userOperation; | 1713 delete this._parentPane._userOperation; |
| 1727 this._moveEditorFromSelector(direction); | 1714 this._moveEditorFromSelector(moveDirection); |
| 1728 this._editingSelectorCommittedForTest(); | 1715 this._editingSelectorCommittedForTest(); |
| 1729 } | 1716 } |
| 1730 | 1717 |
| 1731 // This gets deleted in finishOperationAndMoveEditor(), which is called
both on success and failure. | 1718 // This gets deleted in finishOperationAndMoveEditor(), which is called
both on success and failure. |
| 1732 this._parentPane._userOperation = true; | 1719 this._parentPane._userOperation = true; |
| 1733 var selectedNode = this._parentPane.node(); | 1720 var selectedNode = this._parentPane.node(); |
| 1734 this._parentPane._cssModel.setRuleSelector(this.rule(), selectedNode ? s
electedNode.id : 0, newContent, successCallback.bind(this), finishOperationAndMo
veEditor.bind(this, moveDirection)); | 1721 this._parentPane._cssModel.setRuleSelector(this.rule(), selectedNode ? s
electedNode.id : 0, newContent, finishCallback.bind(this)); |
| 1735 }, | 1722 }, |
| 1736 | 1723 |
| 1737 _editingSelectorCommittedForTest: function() { }, | 1724 _editingSelectorCommittedForTest: function() { }, |
| 1738 | 1725 |
| 1739 _updateRuleOrigin: function() | 1726 _updateRuleOrigin: function() |
| 1740 { | 1727 { |
| 1741 this._selectorRefElement.removeChildren(); | 1728 this._selectorRefElement.removeChildren(); |
| 1742 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection
.createRuleOriginNode(this._parentPane._cssModel, this._parentPane._linkifier, t
his.rule())); | 1729 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection
.createRuleOriginNode(this._parentPane._cssModel, this._parentPane._linkifier, t
his.rule())); |
| 1743 }, | 1730 }, |
| 1744 | 1731 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 * @param {string} moveDirection | 1858 * @param {string} moveDirection |
| 1872 */ | 1859 */ |
| 1873 editingSelectorCommitted: function(element, newContent, oldContent, context,
moveDirection) | 1860 editingSelectorCommitted: function(element, newContent, oldContent, context,
moveDirection) |
| 1874 { | 1861 { |
| 1875 if (!this.isBlank) { | 1862 if (!this.isBlank) { |
| 1876 WebInspector.StylePropertiesSection.prototype.editingSelectorCommitt
ed.call(this, element, newContent, oldContent, context, moveDirection); | 1863 WebInspector.StylePropertiesSection.prototype.editingSelectorCommitt
ed.call(this, element, newContent, oldContent, context, moveDirection); |
| 1877 return; | 1864 return; |
| 1878 } | 1865 } |
| 1879 | 1866 |
| 1880 /** | 1867 /** |
| 1881 * @param {!WebInspector.CSSRule} newRule | 1868 * @param {?WebInspector.CSSRule} newRule |
| 1882 * @this {WebInspector.StylePropertiesSection} | 1869 * @this {WebInspector.StylePropertiesSection} |
| 1883 */ | 1870 */ |
| 1884 function successCallback(newRule) | 1871 function userCallback(newRule) |
| 1885 { | 1872 { |
| 1873 if (!newRule) { |
| 1874 this.editingSelectorCancelled(); |
| 1875 this._editingSelectorCommittedForTest(); |
| 1876 return; |
| 1877 } |
| 1886 var doesSelectorAffectSelectedNode = newRule.matchingSelectors.lengt
h > 0; | 1878 var doesSelectorAffectSelectedNode = newRule.matchingSelectors.lengt
h > 0; |
| 1887 this._makeNormal(newRule); | 1879 this._makeNormal(newRule); |
| 1888 | 1880 |
| 1889 if (!doesSelectorAffectSelectedNode) | 1881 if (!doesSelectorAffectSelectedNode) |
| 1890 this.element.classList.add("no-affect"); | 1882 this.element.classList.add("no-affect"); |
| 1891 | 1883 |
| 1892 var ruleTextLines = ruleText.split("\n"); | 1884 var ruleTextLines = ruleText.split("\n"); |
| 1893 var startLine = this._ruleLocation.startLine; | 1885 var startLine = this._ruleLocation.startLine; |
| 1894 var startColumn = this._ruleLocation.startColumn; | 1886 var startColumn = this._ruleLocation.startColumn; |
| 1895 var newRange = new WebInspector.TextRange(startLine, startColumn, st
artLine + ruleTextLines.length - 1, startColumn + ruleTextLines[ruleTextLines.le
ngth - 1].length); | 1887 var newRange = new WebInspector.TextRange(startLine, startColumn, st
artLine + ruleTextLines.length - 1, startColumn + ruleTextLines[ruleTextLines.le
ngth - 1].length); |
| 1896 this._parentPane._styleSheetRuleEdited(newRule, this._ruleLocation,
newRange); | 1888 this._parentPane._styleSheetRuleEdited(newRule, this._ruleLocation,
newRange); |
| 1897 | 1889 |
| 1898 this._updateRuleOrigin(); | 1890 this._updateRuleOrigin(); |
| 1899 if (this.element.parentElement) // Might have been detached already. | 1891 if (this.element.parentElement) // Might have been detached already. |
| 1900 this._moveEditorFromSelector(moveDirection); | 1892 this._moveEditorFromSelector(moveDirection); |
| 1901 | 1893 |
| 1902 delete this._parentPane._userOperation; | 1894 delete this._parentPane._userOperation; |
| 1903 this._editingSelectorEnded(); | 1895 this._editingSelectorEnded(); |
| 1904 this._markSelectorMatches(); | 1896 this._markSelectorMatches(); |
| 1905 | 1897 |
| 1906 this._editingSelectorCommittedForTest(); | 1898 this._editingSelectorCommittedForTest(); |
| 1907 } | 1899 } |
| 1908 | 1900 |
| 1909 /** | |
| 1910 * @this {WebInspector.StylePropertiesSection} | |
| 1911 */ | |
| 1912 function failureCallback() | |
| 1913 { | |
| 1914 this.editingSelectorCancelled(); | |
| 1915 this._editingSelectorCommittedForTest(); | |
| 1916 } | |
| 1917 | |
| 1918 if (newContent) | 1901 if (newContent) |
| 1919 newContent = newContent.trim(); | 1902 newContent = newContent.trim(); |
| 1920 this._parentPane._userOperation = true; | 1903 this._parentPane._userOperation = true; |
| 1921 | 1904 |
| 1922 var cssModel = this._parentPane._cssModel; | 1905 var cssModel = this._parentPane._cssModel; |
| 1923 var ruleText = this._rulePrefix() + newContent + " {}"; | 1906 var ruleText = this._rulePrefix() + newContent + " {}"; |
| 1924 cssModel.addRule(this._styleSheetId, this._parentPane.node(), ruleText,
this._ruleLocation, successCallback.bind(this), failureCallback.bind(this)); | 1907 cssModel.addRule(this._styleSheetId, this._parentPane.node(), ruleText,
this._ruleLocation, userCallback.bind(this)); |
| 1925 }, | 1908 }, |
| 1926 | 1909 |
| 1927 editingSelectorCancelled: function() | 1910 editingSelectorCancelled: function() |
| 1928 { | 1911 { |
| 1929 delete this._parentPane._userOperation; | 1912 delete this._parentPane._userOperation; |
| 1930 if (!this.isBlank) { | 1913 if (!this.isBlank) { |
| 1931 WebInspector.StylePropertiesSection.prototype.editingSelectorCancell
ed.call(this); | 1914 WebInspector.StylePropertiesSection.prototype.editingSelectorCancell
ed.call(this); |
| 1932 return; | 1915 return; |
| 1933 } | 1916 } |
| 1934 | 1917 |
| (...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3239 | 3222 |
| 3240 /** | 3223 /** |
| 3241 * @override | 3224 * @override |
| 3242 * @return {?WebInspector.ToolbarItem} | 3225 * @return {?WebInspector.ToolbarItem} |
| 3243 */ | 3226 */ |
| 3244 item: function() | 3227 item: function() |
| 3245 { | 3228 { |
| 3246 return this._button; | 3229 return this._button; |
| 3247 } | 3230 } |
| 3248 } | 3231 } |
| OLD | NEW |