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

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

Issue 1149373004: Devtools: Extensible toolbar in SSP (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix naming Created 5 years, 6 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 22 matching lines...) Expand all
33 * @param {function()} requestShowCallback 33 * @param {function()} requestShowCallback
34 */ 34 */
35 WebInspector.StylesSidebarPane = function(requestShowCallback) 35 WebInspector.StylesSidebarPane = function(requestShowCallback)
36 { 36 {
37 WebInspector.ElementsSidebarPane.call(this, WebInspector.UIString("Styles")) ; 37 WebInspector.ElementsSidebarPane.call(this, WebInspector.UIString("Styles")) ;
38 38
39 this.element.addEventListener("contextmenu", this._contextMenuEventFired.bin d(this), true); 39 this.element.addEventListener("contextmenu", this._contextMenuEventFired.bin d(this), true);
40 WebInspector.moduleSetting("colorFormat").addChangeListener(this.update.bind (this)); 40 WebInspector.moduleSetting("colorFormat").addChangeListener(this.update.bind (this));
41 WebInspector.moduleSetting("textEditorIndent").addChangeListener(this.update .bind(this)); 41 WebInspector.moduleSetting("textEditorIndent").addChangeListener(this.update .bind(this));
42 42
43 var toolbar = new WebInspector.Toolbar(this.titleElement); 43 var toolbar = new WebInspector.ExtensibleToolbar("styles-sidebarpane-toolbar ", this.titleElement);
44 toolbar.element.classList.add("styles-pane-toolbar"); 44 toolbar.element.classList.add("styles-pane-toolbar");
45 toolbar.makeNarrow(); 45 toolbar.makeNarrow();
46 46
47 var addNewStyleRuleButton = new WebInspector.ToolbarButton(WebInspector.UISt ring("New Style Rule"), "add-toolbar-item");
48 addNewStyleRuleButton.makeLongClickEnabled();
49 addNewStyleRuleButton.addEventListener("click", this._createNewRuleInViaInsp ectorStyleSheet, this);
50 addNewStyleRuleButton.addEventListener("longClickDown", this._onAddButtonLon gClick, this);
51 toolbar.appendToolbarItem(addNewStyleRuleButton);
52
53 this._elementStateButton = new WebInspector.ToolbarButton(WebInspector.UIStr ing("Toggle Element State"), "element-state-toolbar-item");
54 this._elementStateButton.addEventListener("click", this._toggleElementStateP ane, this);
55 toolbar.appendToolbarItem(this._elementStateButton);
56
57 this._animationsControlButton = new WebInspector.ToolbarButton(WebInspector. UIString("Animations Controls"), "animation-toolbar-item");
58 this._animationsControlButton.addEventListener("click", this._toggleAnimatio nsControlPane, this);
59 toolbar.appendToolbarItem(this._animationsControlButton);
60
61 this._requestShowCallback = requestShowCallback; 47 this._requestShowCallback = requestShowCallback;
62
63 this._createElementStatePane();
64 this.bodyElement.appendChild(this._elementStatePane);
65 this._animationsControlPane = new WebInspector.AnimationControlPane();
66 this.bodyElement.appendChild(this._animationsControlPane.element);
67 this._sectionsContainer = createElement("div"); 48 this._sectionsContainer = createElement("div");
68 this.bodyElement.appendChild(this._sectionsContainer); 49 this.bodyElement.appendChild(this._sectionsContainer);
69 50
70 this._stylesPopoverHelper = new WebInspector.StylesPopoverHelper(); 51 this._stylesPopoverHelper = new WebInspector.StylesPopoverHelper();
71 52
72 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultCSSFormatter()); 53 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultCSSFormatter());
73 54
74 this.element.classList.add("styles-pane"); 55 this.element.classList.add("styles-pane");
75 this.element.addEventListener("mousemove", this._mouseMovedOverElement.bind( this), false); 56 this.element.addEventListener("mousemove", this._mouseMovedOverElement.bind( this), false);
76 this._keyDownBound = this._keyDown.bind(this); 57 this._keyDownBound = this._keyDown.bind(this);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 /** 280 /**
300 * @param {?RegExp} regex 281 * @param {?RegExp} regex
301 */ 282 */
302 _onFilterChanged: function(regex) 283 _onFilterChanged: function(regex)
303 { 284 {
304 this._filterRegex = regex; 285 this._filterRegex = regex;
305 this._updateFilter(); 286 this._updateFilter();
306 }, 287 },
307 288
308 /** 289 /**
309 * @return {?T}
310 * @template T
311 */
312 _forcedPseudoClasses: function()
313 {
314 return this.node() ? (this.node().getUserProperty(WebInspector.CSSStyleM odel.PseudoStatePropertyName) || undefined) : undefined;
315 },
316
317 _updateForcedPseudoStateInputs: function()
318 {
319 var node = this.node();
320 if (!node || !WebInspector.CSSStyleModel.fromNode(node).isEnabled())
321 return;
322
323 var hasPseudoType = !!node.pseudoType();
324 this._elementStateButton.setEnabled(!hasPseudoType);
325 this._elementStatePane.classList.toggle("expanded", !hasPseudoType && th is._elementStateButton.toggled());
326
327 var nodePseudoState = this._forcedPseudoClasses();
328 if (!nodePseudoState)
329 nodePseudoState = [];
330
331 var inputs = this._elementStatePane.inputs;
332 for (var i = 0; i < inputs.length; ++i)
333 inputs[i].checked = nodePseudoState.indexOf(inputs[i].state) >= 0;
334 },
335
336 /**
337 * @override 290 * @override
338 * @param {?WebInspector.DOMNode} node 291 * @param {?WebInspector.DOMNode} node
339 */ 292 */
340 setNode: function(node) 293 setNode: function(node)
341 { 294 {
342 // We should update SSP on main frame navigation only. 295 // We should update SSP on main frame navigation only.
343 var mainFrameNavigated = node && this.node() && node.ownerDocument !== t his.node().ownerDocument; 296 var mainFrameNavigated = node && this.node() && node.ownerDocument !== t his.node().ownerDocument;
344 if (!mainFrameNavigated && node !== this.node()) { 297 if (!mainFrameNavigated && node !== this.node()) {
345 this.element.classList.toggle("no-affect", this._isEditingStyle); 298 this.element.classList.toggle("no-affect", this._isEditingStyle);
346 if (this._isEditingStyle) { 299 if (this._isEditingStyle) {
347 this._pendingNode = node; 300 this._pendingNode = node;
348 return; 301 return;
349 } 302 }
350 } 303 }
351 304
352 this._stylesPopoverHelper.hide(); 305 this._stylesPopoverHelper.hide();
353 node = WebInspector.SharedSidebarModel.elementNode(node); 306 node = WebInspector.SharedSidebarModel.elementNode(node);
354 307
355 this._resetCache(); 308 this._resetCache();
356 this._animationsControlPane.setNode(node);
357 if (this._animationTimeline)
358 this._animationTimeline.setNode(node);
359 WebInspector.ElementsSidebarPane.prototype.setNode.call(this, node); 309 WebInspector.ElementsSidebarPane.prototype.setNode.call(this, node);
360 }, 310 },
361 311
362 /** 312 /**
363 * @param {!WebInspector.StylePropertiesSection=} editedSection 313 * @param {!WebInspector.StylePropertiesSection=} editedSection
364 */ 314 */
365 _refreshUpdate: function(editedSection) 315 _refreshUpdate: function(editedSection)
366 { 316 {
367 var node = this.node(); 317 var node = this.node();
368 if (!node) 318 if (!node)
(...skipping 11 matching lines...) Expand all
380 this._updateFilter(); 330 this._updateFilter();
381 this._nodeStylesUpdatedForTest(node, false); 331 this._nodeStylesUpdatedForTest(node, false);
382 }, 332 },
383 333
384 /** 334 /**
385 * @override 335 * @override
386 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback 336 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback
387 */ 337 */
388 doUpdate: function(finishedCallback) 338 doUpdate: function(finishedCallback)
389 { 339 {
390 this._updateForcedPseudoStateInputs();
391 this._discardElementUnderMouse(); 340 this._discardElementUnderMouse();
392 341
393 this.fetchMatchedCascade() 342 this.fetchMatchedCascade()
394 .then(this._innerRebuildUpdate.bind(this)) 343 .then(this._innerRebuildUpdate.bind(this))
395 .then(finishedCallback) 344 .then(finishedCallback)
396 .catch(/** @type {function()} */(finishedCallback)); 345 .catch(/** @type {function()} */(finishedCallback));
397 }, 346 },
398 347
399 _resetCache: function() 348 _resetCache: function()
400 { 349 {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 { 718 {
770 for (var block of this._sectionBlocks) { 719 for (var block of this._sectionBlocks) {
771 var index = block.sections.indexOf(section); 720 var index = block.sections.indexOf(section);
772 if (index === -1) 721 if (index === -1)
773 continue; 722 continue;
774 block.sections.splice(index, 1); 723 block.sections.splice(index, 1);
775 section.element.remove(); 724 section.element.remove();
776 } 725 }
777 }, 726 },
778 727
779 _toggleElementStatePane: function()
780 {
781 var buttonToggled = !this._elementStateButton.toggled();
782 if (buttonToggled)
783 this.expand();
784 this._elementStateButton.setToggled(buttonToggled);
785 this._elementStatePane.classList.toggle("expanded", buttonToggled);
786 if (!Runtime.experiments.isEnabled("animationInspection"))
787 this._animationsControlButton.setToggled(false);
788 this._animationsControlPane.element.classList.remove("expanded");
789 },
790
791 _createElementStatePane: function()
792 {
793 this._elementStatePane = createElement("div");
794 this._elementStatePane.className = "styles-element-state-pane source-cod e";
795 var table = createElement("table");
796
797 var inputs = [];
798 this._elementStatePane.inputs = inputs;
799
800 /**
801 * @param {!Event} event
802 * @this {WebInspector.StylesSidebarPane}
803 */
804 function clickListener(event)
805 {
806 var node = this.node();
807 if (!node)
808 return;
809 WebInspector.CSSStyleModel.fromNode(node).forcePseudoState(node, eve nt.target.state, event.target.checked);
810 }
811
812 /**
813 * @param {string} state
814 * @return {!Element}
815 * @this {WebInspector.StylesSidebarPane}
816 */
817 function createCheckbox(state)
818 {
819 var td = createElement("td");
820 var label = createCheckboxLabel(":" + state);
821 var input = label.checkboxElement;
822 input.state = state;
823 input.addEventListener("click", clickListener.bind(this), false);
824 inputs.push(input);
825 td.appendChild(label);
826 return td;
827 }
828
829 var tr = table.createChild("tr");
830 tr.appendChild(createCheckbox.call(this, "active"));
831 tr.appendChild(createCheckbox.call(this, "hover"));
832
833 tr = table.createChild("tr");
834 tr.appendChild(createCheckbox.call(this, "focus"));
835 tr.appendChild(createCheckbox.call(this, "visited"));
836
837 this._elementStatePane.appendChild(table);
838 },
839
840 _toggleAnimationsControlPane: function()
841 {
842 var buttonToggled = !this._animationsControlButton.toggled();
843 if (buttonToggled)
844 this.expand();
845 this._animationsControlButton.setToggled(buttonToggled);
846 if (Runtime.experiments.isEnabled("animationInspection")) {
847 if (!this._animationTimeline)
848 this._animationTimeline = new WebInspector.AnimationTimeline();
849 var elementsPanel = WebInspector.ElementsPanel.instance();
850 elementsPanel.setWidgetBelowDOM(buttonToggled ? this._animationTimel ine : null);
851 } else {
852 this._animationsControlPane.element.classList.toggle("expanded", but tonToggled);
853 this._elementStateButton.setToggled(false);
854 this._elementStatePane.classList.remove("expanded");
855 }
856 },
857
858 /** 728 /**
859 * @return {?RegExp} 729 * @return {?RegExp}
860 */ 730 */
861 filterRegex: function() 731 filterRegex: function()
862 { 732 {
863 return this._filterRegex; 733 return this._filterRegex;
864 }, 734 },
865 735
866 _updateFilter: function() 736 _updateFilter: function()
867 { 737 {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 * @param {!Event} event 796 * @param {!Event} event
927 */ 797 */
928 _keyUp: function(event) 798 _keyUp: function(event)
929 { 799 {
930 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho rtcut.Keys.Ctrl.code) || 800 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho rtcut.Keys.Ctrl.code) ||
931 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor tcut.Keys.Meta.code)) { 801 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor tcut.Keys.Meta.code)) {
932 this._discardElementUnderMouse(); 802 this._discardElementUnderMouse();
933 } 803 }
934 }, 804 },
935 805
806 /**
807 * @param {?WebInspector.Widget} widget
808 */
809 showToolbarPane: function(widget)
810 {
811 if (this._currentToolbarPane) {
812 this._currentToolbarPane.detach();
813 this._currentToolbarPane = null;
814 }
815 if (widget) {
816 this._currentToolbarPane = widget;
817 this._currentToolbarPane.show(this.bodyElement, this._sectionsContai ner);
818 }
819 },
820
936 __proto__: WebInspector.ElementsSidebarPane.prototype 821 __proto__: WebInspector.ElementsSidebarPane.prototype
937 } 822 }
938 823
939 /** 824 /**
940 * @param {string} placeholder 825 * @param {string} placeholder
941 * @return {!Element} 826 * @return {!Element}
942 * @param {function(?RegExp)} filterCallback 827 * @param {function(?RegExp)} filterCallback
943 */ 828 */
944 WebInspector.StylesSidebarPane.createPropertyFilterElement = function(placeholde r, filterCallback) 829 WebInspector.StylesSidebarPane.createPropertyFilterElement = function(placeholde r, filterCallback)
945 { 830 {
(...skipping 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after
3241 3126
3242 WebInspector.StylesSidebarPane.MatchedRulesPayload.prototype = { 3127 WebInspector.StylesSidebarPane.MatchedRulesPayload.prototype = {
3243 /** 3128 /**
3244 * @return {boolean} 3129 * @return {boolean}
3245 */ 3130 */
3246 fulfilled: function() 3131 fulfilled: function()
3247 { 3132 {
3248 return !!(this.matchedCSSRules && this.pseudoElements && this.inherited) ; 3133 return !!(this.matchedCSSRules && this.pseudoElements && this.inherited) ;
3249 } 3134 }
3250 } 3135 }
3136
3137 /**
3138 * @constructor
3139 * @extends {WebInspector.Widget}
3140 * @param {!WebInspector.ToolbarItem} toolbarItem
3141 */
3142 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget = function(toolbarItem)
3143 {
3144 WebInspector.Widget.call(this);
3145 this._toolbarItem = toolbarItem;
3146 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod eChanged, this);
3147 }
3148
3149 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.prototype = {
3150 _nodeChanged: function()
3151 {
3152 if (!this.isShowing())
3153 return;
3154
3155 var elementNode = WebInspector.SharedSidebarModel.elementNode(WebInspect or.context.flavor(WebInspector.DOMNode));
3156 this.onNodeChanged(elementNode);
3157 },
3158
3159 /**
3160 * @param {?WebInspector.DOMNode} newNode
3161 * @protected
3162 */
3163 onNodeChanged: function(newNode)
3164 {
3165 },
3166
3167 willHide: function()
lushnikov 2015/05/29 13:38:47 @override?
sergeyv 2015/05/29 13:43:18 Done.
3168 {
3169 this._toolbarItem.setToggled(false);
3170 },
3171
3172 wasShown: function()
lushnikov 2015/05/29 13:38:47 ditto
sergeyv 2015/05/29 13:43:18 Done.
3173 {
3174 this._toolbarItem.setToggled(true);
3175 var elementNode = WebInspector.SharedSidebarModel.elementNode(WebInspect or.context.flavor(WebInspector.DOMNode));
lushnikov 2015/05/29 13:38:47 this._nodeChanged() ?
sergeyv 2015/05/29 13:43:18 Done.
3176 this.onNodeChanged(elementNode);
3177 },
3178
3179 __proto__: WebInspector.Widget.prototype
3180 }
3181
3182 /**
3183 * @constructor
3184 * @implements {WebInspector.ToolbarItem.Provider}
3185 */
3186 WebInspector.StylesSidebarPane.AddNewRuleButtonProvider = function()
3187 {
3188 this._button = new WebInspector.ToolbarButton(WebInspector.UIString("New Sty le Rule"), "add-toolbar-item");
3189 this._button.makeLongClickEnabled();
3190 var stylesSidebarPane = WebInspector.ElementsPanel.instance().sidebarPanes.s tyles;
3191 this._button.addEventListener("click", stylesSidebarPane._createNewRuleInVia InspectorStyleSheet, stylesSidebarPane);
3192 this._button.addEventListener("longClickDown", stylesSidebarPane._onAddButto nLongClick, stylesSidebarPane);
3193 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._onN odeChanged, this);
3194 this._onNodeChanged()
3195 }
3196
3197 WebInspector.StylesSidebarPane.AddNewRuleButtonProvider.prototype = {
3198 _onNodeChanged: function()
3199 {
3200 var node = WebInspector.context.flavor(WebInspector.DOMNode);
3201 this.item().setEnabled(!!node);
3202 },
3203
3204 /**
3205 * @override
3206 * @return {?WebInspector.ToolbarItem}
3207 */
3208 item: function()
3209 {
3210 return this._button;
3211 }
3212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698