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

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

Issue 1947283002: DevTools: [LiveSASS] make selectors and medias read-only for sass rules (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 752
753 var openBrace = createElement("span"); 753 var openBrace = createElement("span");
754 openBrace.textContent = " {"; 754 openBrace.textContent = " {";
755 selectorContainer.appendChild(openBrace); 755 selectorContainer.appendChild(openBrace);
756 selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseD own.bind(this), false); 756 selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseD own.bind(this), false);
757 selectorContainer.addEventListener("click", this._handleSelectorContainerCli ck.bind(this), false); 757 selectorContainer.addEventListener("click", this._handleSelectorContainerCli ck.bind(this), false);
758 758
759 var closeBrace = this.element.createChild("div", "sidebar-pane-closing-brace "); 759 var closeBrace = this.element.createChild("div", "sidebar-pane-closing-brace ");
760 closeBrace.textContent = "}"; 760 closeBrace.textContent = "}";
761 761
762 if (this.editable) { 762 this._createHoverMenuToolbar(closeBrace);
763 var items = [];
764 var colorButton = new WebInspector.ToolbarButton(WebInspector.UIString(" Add color"), "foreground-color-toolbar-item");
765 colorButton.addEventListener("click", this._onInsertColorPropertyClick.b ind(this));
766 items.push(colorButton);
767
768 var backgroundButton = new WebInspector.ToolbarButton(WebInspector.UIStr ing("Add background-color"), "background-color-toolbar-item");
769 backgroundButton.addEventListener("click", this._onInsertBackgroundColor PropertyClick.bind(this));
770 items.push(backgroundButton);
771
772 if (rule) {
773 var newRuleButton = new WebInspector.ToolbarButton(WebInspector.UISt ring("Insert Style Rule Below"), "add-toolbar-item");
774 newRuleButton.addEventListener("click", this._onNewRuleClick.bind(th is));
775 items.push(newRuleButton);
776 }
777
778 var menuButton = new WebInspector.ToolbarButton(WebInspector.UIString("M ore tools\u2026"), "menu-toolbar-item");
779 items.push(menuButton);
780
781 if (items.length) {
782 var sectionToolbar = new WebInspector.Toolbar("sidebar-pane-section- toolbar", closeBrace);
783
784 for (var i = 0; i < items.length; ++i)
785 sectionToolbar.appendToolbarItem(items[i]);
786
787 items.pop();
788
789 /**
790 * @param {!Array<!WebInspector.ToolbarButton>} items
791 * @param {boolean} value
792 */
793 function setItemsVisibility(items, value)
794 {
795 for (var i = 0; i < items.length; ++i)
796 items[i].setVisible(value);
797 menuButton.setVisible(!value);
798 }
799 setItemsVisibility(items, false);
800 sectionToolbar.element.addEventListener("mouseenter", setItemsVisibi lity.bind(null, items, true));
801 sectionToolbar.element.addEventListener("mouseleave", setItemsVisibi lity.bind(null, items, false));
802 }
803 }
804 763
805 this._selectorElement.addEventListener("click", this._handleSelectorClick.bi nd(this), false); 764 this._selectorElement.addEventListener("click", this._handleSelectorClick.bi nd(this), false);
806 this.element.addEventListener("mousedown", this._handleEmptySpaceMouseDown.b ind(this), false); 765 this.element.addEventListener("mousedown", this._handleEmptySpaceMouseDown.b ind(this), false);
807 this.element.addEventListener("click", this._handleEmptySpaceClick.bind(this ), false); 766 this.element.addEventListener("click", this._handleEmptySpaceClick.bind(this ), false);
808 767
809 if (rule) { 768 if (rule) {
810 // Prevent editing the user agent and user rules. 769 // Prevent editing the user agent and user rules.
811 if (rule.isUserAgent() || rule.isInjected()) { 770 if (rule.isUserAgent() || rule.isInjected()) {
812 this.editable = false; 771 this.editable = false;
813 } else { 772 } else {
(...skipping 15 matching lines...) Expand all
829 788
830 if (!this.editable) 789 if (!this.editable)
831 this.element.classList.add("read-only"); 790 this.element.classList.add("read-only");
832 791
833 this._markSelectorMatches(); 792 this._markSelectorMatches();
834 this.onpopulate(); 793 this.onpopulate();
835 } 794 }
836 795
837 WebInspector.StylePropertiesSection.prototype = { 796 WebInspector.StylePropertiesSection.prototype = {
838 /** 797 /**
798 * @param {!Element} container
799 */
800 _createHoverMenuToolbar: function(container)
801 {
802 if (!this.editable)
803 return;
804 var items = [];
805 var colorButton = new WebInspector.ToolbarButton(WebInspector.UIString(" Add color"), "foreground-color-toolbar-item");
806 colorButton.addEventListener("click", this._onInsertColorPropertyClick.b ind(this));
807 items.push(colorButton);
808
809 var backgroundButton = new WebInspector.ToolbarButton(WebInspector.UIStr ing("Add background-color"), "background-color-toolbar-item");
810 backgroundButton.addEventListener("click", this._onInsertBackgroundColor PropertyClick.bind(this));
811 items.push(backgroundButton);
812
813 var newRuleButton = null;
814 if (this._style.parentRule) {
815 newRuleButton = new WebInspector.ToolbarButton(WebInspector.UIString ("Insert Style Rule Below"), "add-toolbar-item");
816 newRuleButton.addEventListener("click", this._onNewRuleClick.bind(th is));
817 items.push(newRuleButton);
818 }
819
820 var sectionToolbar = new WebInspector.Toolbar("sidebar-pane-section-tool bar", container);
821 for (var i = 0; i < items.length; ++i)
822 sectionToolbar.appendToolbarItem(items[i]);
823
824 var menuButton = new WebInspector.ToolbarButton(WebInspector.UIString("M ore tools\u2026"), "menu-toolbar-item");
825 sectionToolbar.appendToolbarItem(menuButton);
826 setItemsVisibility.call(this, items, false);
827 sectionToolbar.element.addEventListener("mouseenter", setItemsVisibility .bind(this, items, true));
828 sectionToolbar.element.addEventListener("mouseleave", setItemsVisibility .bind(this, items, false));
829
830 /**
831 * @param {!Array<!WebInspector.ToolbarButton>} items
832 * @param {boolean} value
833 * @this {WebInspector.StylePropertiesSection}
834 */
835 function setItemsVisibility(items, value)
836 {
837 for (var i = 0; i < items.length; ++i)
838 items[i].setVisible(value);
839 menuButton.setVisible(!value);
840 if (this._isSASSStyle())
841 newRuleButton.setVisible(false);
842 }
843 },
844
845 /**
846 * @return {boolean}
847 */
848 _isSASSStyle: function()
849 {
850 var header = this._style.styleSheetId ? this._style.cssModel().styleShee tHeaderForId(this._style.styleSheetId) : null;
851 if (!header)
852 return false;
853 var sourceMap = header.cssModel().sourceMapForHeader(header);
854 return sourceMap ? sourceMap.editable() : false;
855 },
856
857 /**
839 * @return {!WebInspector.CSSStyleDeclaration} 858 * @return {!WebInspector.CSSStyleDeclaration}
840 */ 859 */
841 style: function() 860 style: function()
842 { 861 {
843 return this._style; 862 return this._style;
844 }, 863 },
845 864
846 /** 865 /**
847 * @return {string} 866 * @return {string}
848 */ 867 */
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 event.consume(true); 1314 event.consume(true);
1296 return; 1315 return;
1297 } 1316 }
1298 var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILoc ation(location); 1317 var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILoc ation(location);
1299 if (uiLocation) 1318 if (uiLocation)
1300 WebInspector.Revealer.reveal(uiLocation); 1319 WebInspector.Revealer.reveal(uiLocation);
1301 event.consume(true); 1320 event.consume(true);
1302 return; 1321 return;
1303 } 1322 }
1304 1323
1324 if (!this.editable || this._isSASSStyle())
1325 return;
1326
1305 var config = new WebInspector.InplaceEditor.Config(this._editingMediaCom mitted.bind(this, media), this._editingMediaCancelled.bind(this, element), undef ined, this._editingMediaBlurHandler.bind(this)); 1327 var config = new WebInspector.InplaceEditor.Config(this._editingMediaCom mitted.bind(this, media), this._editingMediaCancelled.bind(this, element), undef ined, this._editingMediaBlurHandler.bind(this));
1306 WebInspector.InplaceEditor.startEditing(element, config); 1328 WebInspector.InplaceEditor.startEditing(element, config);
1307 1329
1308 element.getComponentSelection().setBaseAndExtent(element, 0, element, 1) ; 1330 element.getComponentSelection().setBaseAndExtent(element, 0, element, 1) ;
1309 this._parentPane.setEditingStyle(true); 1331 this._parentPane.setEditingStyle(true);
1310 var parentMediaElement = element.enclosingNodeOrSelfWithClass("media"); 1332 var parentMediaElement = element.enclosingNodeOrSelfWithClass("media");
1311 parentMediaElement.classList.add("editing-media"); 1333 parentMediaElement.classList.add("editing-media");
1312 1334
1313 event.consume(true); 1335 event.consume(true);
1314 }, 1336 },
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 WebInspector.Revealer.reveal(uiLocation); 1424 WebInspector.Revealer.reveal(uiLocation);
1403 event.consume(true); 1425 event.consume(true);
1404 return; 1426 return;
1405 } 1427 }
1406 this._startEditingOnMouseEvent(); 1428 this._startEditingOnMouseEvent();
1407 event.consume(true); 1429 event.consume(true);
1408 }, 1430 },
1409 1431
1410 _startEditingOnMouseEvent: function() 1432 _startEditingOnMouseEvent: function()
1411 { 1433 {
1412 if (!this.editable) 1434 if (!this.editable || this._isSASSStyle())
1413 return; 1435 return;
1414 1436
1415 var rule = this._style.parentRule; 1437 var rule = this._style.parentRule;
1416 if (!rule && !this.propertiesTreeOutline.rootElement().childCount()) { 1438 if (!rule && !this.propertiesTreeOutline.rootElement().childCount()) {
1417 this.addNewBlankProperty().startEditing(); 1439 this.addNewBlankProperty().startEditing();
1418 return; 1440 return;
1419 } 1441 }
1420 1442
1421 if (!rule) 1443 if (!rule)
1422 return; 1444 return;
(...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after
3090 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha nged); 3112 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha nged);
3091 onNodeChanged(); 3113 onNodeChanged();
3092 return button; 3114 return button;
3093 3115
3094 function onNodeChanged() 3116 function onNodeChanged()
3095 { 3117 {
3096 var node = WebInspector.context.flavor(WebInspector.DOMNode); 3118 var node = WebInspector.context.flavor(WebInspector.DOMNode);
3097 button.setEnabled(!!node); 3119 button.setEnabled(!!node);
3098 } 3120 }
3099 } 3121 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698