Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 /** | 294 /** |
| 314 * @param {?RegExp} regex | 295 * @param {?RegExp} regex |
| 315 */ | 296 */ |
| 316 _onFilterChanged: function(regex) | 297 _onFilterChanged: function(regex) |
| 317 { | 298 { |
| 318 this._filterRegex = regex; | 299 this._filterRegex = regex; |
| 319 this._updateFilter(); | 300 this._updateFilter(); |
| 320 }, | 301 }, |
| 321 | 302 |
| 322 /** | 303 /** |
| 323 * @return {?T} | |
| 324 * @template T | |
| 325 */ | |
| 326 _forcedPseudoClasses: function() | |
| 327 { | |
| 328 return this.node() ? (this.node().getUserProperty(WebInspector.CSSStyleM odel.PseudoStatePropertyName) || undefined) : undefined; | |
| 329 }, | |
| 330 | |
| 331 _updateForcedPseudoStateInputs: function() | |
| 332 { | |
| 333 var node = this.node(); | |
| 334 if (!node || !WebInspector.CSSStyleModel.fromNode(node).isEnabled()) | |
| 335 return; | |
| 336 | |
| 337 var hasPseudoType = !!node.pseudoType(); | |
| 338 this._elementStateButton.setEnabled(!hasPseudoType); | |
| 339 this._elementStatePane.classList.toggle("expanded", !hasPseudoType && th is._elementStateButton.toggled()); | |
| 340 | |
| 341 var nodePseudoState = this._forcedPseudoClasses(); | |
| 342 if (!nodePseudoState) | |
| 343 nodePseudoState = []; | |
| 344 | |
| 345 var inputs = this._elementStatePane.inputs; | |
| 346 for (var i = 0; i < inputs.length; ++i) | |
| 347 inputs[i].checked = nodePseudoState.indexOf(inputs[i].state) >= 0; | |
| 348 }, | |
| 349 | |
| 350 /** | |
| 351 * @override | 304 * @override |
| 352 * @param {?WebInspector.DOMNode} node | 305 * @param {?WebInspector.DOMNode} node |
| 353 */ | 306 */ |
| 354 setNode: function(node) | 307 setNode: function(node) |
| 355 { | 308 { |
| 356 // We should update SSP on main frame navigation only. | 309 // We should update SSP on main frame navigation only. |
| 357 var mainFrameNavigated = node && this.node() && node.ownerDocument !== t his.node().ownerDocument; | 310 var mainFrameNavigated = node && this.node() && node.ownerDocument !== t his.node().ownerDocument; |
| 358 if (!mainFrameNavigated && node !== this.node()) { | 311 if (!mainFrameNavigated && node !== this.node()) { |
| 359 this.element.classList.toggle("no-affect", this._isEditingStyle); | 312 this.element.classList.toggle("no-affect", this._isEditingStyle); |
| 360 if (this._isEditingStyle) { | 313 if (this._isEditingStyle) { |
| 361 this._pendingNode = node; | 314 this._pendingNode = node; |
| 362 return; | 315 return; |
| 363 } | 316 } |
| 364 } | 317 } |
| 365 | 318 |
| 366 this._stylesPopoverHelper.hide(); | 319 this._stylesPopoverHelper.hide(); |
| 367 node = WebInspector.StylesSidebarPane.normalizeNode(node); | 320 node = WebInspector.StylesSidebarPane.normalizeNode(node); |
| 368 | 321 |
| 369 this._resetCache(); | 322 this._resetCache(); |
| 370 this._animationsControlPane.setNode(node); | |
| 371 if (this._animationTimeline) | |
| 372 this._animationTimeline.setNode(node); | |
| 373 WebInspector.ElementsSidebarPane.prototype.setNode.call(this, node); | 323 WebInspector.ElementsSidebarPane.prototype.setNode.call(this, node); |
| 374 }, | 324 }, |
| 375 | 325 |
| 376 /** | 326 /** |
| 377 * @param {!WebInspector.StylePropertiesSection=} editedSection | 327 * @param {!WebInspector.StylePropertiesSection=} editedSection |
| 378 */ | 328 */ |
| 379 _refreshUpdate: function(editedSection) | 329 _refreshUpdate: function(editedSection) |
| 380 { | 330 { |
| 381 var node = this.node(); | 331 var node = this.node(); |
| 382 if (!node) | 332 if (!node) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 394 this._updateFilter(); | 344 this._updateFilter(); |
| 395 this._nodeStylesUpdatedForTest(node, false); | 345 this._nodeStylesUpdatedForTest(node, false); |
| 396 }, | 346 }, |
| 397 | 347 |
| 398 /** | 348 /** |
| 399 * @override | 349 * @override |
| 400 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback | 350 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback |
| 401 */ | 351 */ |
| 402 doUpdate: function(finishedCallback) | 352 doUpdate: function(finishedCallback) |
| 403 { | 353 { |
| 404 this._updateForcedPseudoStateInputs(); | |
| 405 this._discardElementUnderMouse(); | 354 this._discardElementUnderMouse(); |
| 406 | 355 |
| 407 this.fetchMatchedCascade() | 356 this.fetchMatchedCascade() |
| 408 .then(this._innerRebuildUpdate.bind(this)) | 357 .then(this._innerRebuildUpdate.bind(this)) |
| 409 .then(finishedCallback) | 358 .then(finishedCallback) |
| 410 .catch(/** @type {function()} */(finishedCallback)); | 359 .catch(/** @type {function()} */(finishedCallback)); |
| 411 }, | 360 }, |
| 412 | 361 |
| 413 _resetCache: function() | 362 _resetCache: function() |
| 414 { | 363 { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 { | 732 { |
| 784 for (var block of this._sectionBlocks) { | 733 for (var block of this._sectionBlocks) { |
| 785 var index = block.sections.indexOf(section); | 734 var index = block.sections.indexOf(section); |
| 786 if (index === -1) | 735 if (index === -1) |
| 787 continue; | 736 continue; |
| 788 block.sections.splice(index, 1); | 737 block.sections.splice(index, 1); |
| 789 section.element.remove(); | 738 section.element.remove(); |
| 790 } | 739 } |
| 791 }, | 740 }, |
| 792 | 741 |
| 793 _toggleElementStatePane: function() | |
| 794 { | |
| 795 var buttonToggled = !this._elementStateButton.toggled(); | |
| 796 if (buttonToggled) | |
| 797 this.expand(); | |
| 798 this._elementStateButton.setToggled(buttonToggled); | |
| 799 this._elementStatePane.classList.toggle("expanded", buttonToggled); | |
| 800 if (!Runtime.experiments.isEnabled("animationInspection")) | |
| 801 this._animationsControlButton.setToggled(false); | |
| 802 this._animationsControlPane.element.classList.remove("expanded"); | |
| 803 }, | |
| 804 | |
| 805 _createElementStatePane: function() | |
| 806 { | |
| 807 this._elementStatePane = createElement("div"); | |
| 808 this._elementStatePane.className = "styles-element-state-pane source-cod e"; | |
| 809 var table = createElement("table"); | |
| 810 | |
| 811 var inputs = []; | |
| 812 this._elementStatePane.inputs = inputs; | |
| 813 | |
| 814 /** | |
| 815 * @param {!Event} event | |
| 816 * @this {WebInspector.StylesSidebarPane} | |
| 817 */ | |
| 818 function clickListener(event) | |
| 819 { | |
| 820 var node = this.node(); | |
| 821 if (!node) | |
| 822 return; | |
| 823 WebInspector.CSSStyleModel.fromNode(node).forcePseudoState(node, eve nt.target.state, event.target.checked); | |
| 824 } | |
| 825 | |
| 826 /** | |
| 827 * @param {string} state | |
| 828 * @return {!Element} | |
| 829 * @this {WebInspector.StylesSidebarPane} | |
| 830 */ | |
| 831 function createCheckbox(state) | |
| 832 { | |
| 833 var td = createElement("td"); | |
| 834 var label = createCheckboxLabel(":" + state); | |
| 835 var input = label.checkboxElement; | |
| 836 input.state = state; | |
| 837 input.addEventListener("click", clickListener.bind(this), false); | |
| 838 inputs.push(input); | |
| 839 td.appendChild(label); | |
| 840 return td; | |
| 841 } | |
| 842 | |
| 843 var tr = table.createChild("tr"); | |
| 844 tr.appendChild(createCheckbox.call(this, "active")); | |
| 845 tr.appendChild(createCheckbox.call(this, "hover")); | |
| 846 | |
| 847 tr = table.createChild("tr"); | |
| 848 tr.appendChild(createCheckbox.call(this, "focus")); | |
| 849 tr.appendChild(createCheckbox.call(this, "visited")); | |
| 850 | |
| 851 this._elementStatePane.appendChild(table); | |
| 852 }, | |
| 853 | |
| 854 _toggleAnimationsControlPane: function() | |
| 855 { | |
| 856 var buttonToggled = !this._animationsControlButton.toggled(); | |
| 857 if (buttonToggled) | |
| 858 this.expand(); | |
| 859 this._animationsControlButton.setToggled(buttonToggled); | |
| 860 if (Runtime.experiments.isEnabled("animationInspection")) { | |
| 861 if (!this._animationTimeline) | |
| 862 this._animationTimeline = new WebInspector.AnimationTimeline(); | |
| 863 var elementsPanel = WebInspector.ElementsPanel.instance(); | |
| 864 elementsPanel.setWidgetBelowDOM(buttonToggled ? this._animationTimel ine : null); | |
| 865 } else { | |
| 866 this._animationsControlPane.element.classList.toggle("expanded", but tonToggled); | |
| 867 this._elementStateButton.setToggled(false); | |
| 868 this._elementStatePane.classList.remove("expanded"); | |
| 869 } | |
| 870 }, | |
| 871 | |
| 872 /** | 742 /** |
| 873 * @return {?RegExp} | 743 * @return {?RegExp} |
| 874 */ | 744 */ |
| 875 filterRegex: function() | 745 filterRegex: function() |
| 876 { | 746 { |
| 877 return this._filterRegex; | 747 return this._filterRegex; |
| 878 }, | 748 }, |
| 879 | 749 |
| 880 _updateFilter: function() | 750 _updateFilter: function() |
| 881 { | 751 { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 * @param {!Event} event | 810 * @param {!Event} event |
| 941 */ | 811 */ |
| 942 _keyUp: function(event) | 812 _keyUp: function(event) |
| 943 { | 813 { |
| 944 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho rtcut.Keys.Ctrl.code) || | 814 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho rtcut.Keys.Ctrl.code) || |
| 945 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor tcut.Keys.Meta.code)) { | 815 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor tcut.Keys.Meta.code)) { |
| 946 this._discardElementUnderMouse(); | 816 this._discardElementUnderMouse(); |
| 947 } | 817 } |
| 948 }, | 818 }, |
| 949 | 819 |
| 820 /** | |
| 821 * @param {?WebInspector.Widget} widget | |
| 822 */ | |
| 823 showToolbarPane: function(widget) | |
| 824 { | |
| 825 if (this._currentToolbarPane && this._currentToolbarPane.isShowing()) { | |
| 826 this._currentToolbarPane.detach(); | |
|
lushnikov
2015/05/29 10:53:12
lets detach is hidden
sergeyv
2015/05/29 12:53:41
Done.
| |
| 827 this._currentToolbarPane = null; | |
| 828 } | |
| 829 if (widget) { | |
| 830 this._currentToolbarPane = widget; | |
| 831 this._currentToolbarPane.show(this.bodyElement, this._sectionsContai ner); | |
| 832 } | |
| 833 }, | |
| 834 | |
| 950 __proto__: WebInspector.ElementsSidebarPane.prototype | 835 __proto__: WebInspector.ElementsSidebarPane.prototype |
| 951 } | 836 } |
| 952 | 837 |
| 953 /** | 838 /** |
| 954 * @param {string} placeholder | 839 * @param {string} placeholder |
| 955 * @return {!Element} | 840 * @return {!Element} |
| 956 * @param {function(?RegExp)} filterCallback | 841 * @param {function(?RegExp)} filterCallback |
| 957 */ | 842 */ |
| 958 WebInspector.StylesSidebarPane.createPropertyFilterElement = function(placeholde r, filterCallback) | 843 WebInspector.StylesSidebarPane.createPropertyFilterElement = function(placeholde r, filterCallback) |
| 959 { | 844 { |
| (...skipping 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3255 | 3140 |
| 3256 WebInspector.StylesSidebarPane.MatchedRulesPayload.prototype = { | 3141 WebInspector.StylesSidebarPane.MatchedRulesPayload.prototype = { |
| 3257 /** | 3142 /** |
| 3258 * @return {boolean} | 3143 * @return {boolean} |
| 3259 */ | 3144 */ |
| 3260 fulfilled: function() | 3145 fulfilled: function() |
| 3261 { | 3146 { |
| 3262 return !!(this.matchedCSSRules && this.pseudoElements && this.inherited) ; | 3147 return !!(this.matchedCSSRules && this.pseudoElements && this.inherited) ; |
| 3263 } | 3148 } |
| 3264 } | 3149 } |
| 3150 | |
| 3151 /** | |
| 3152 * @constructor | |
| 3153 * @extends {WebInspector.Widget} | |
| 3154 * @param {!WebInspector.ToolbarItem} toolbarItem | |
| 3155 */ | |
| 3156 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget = function(toolbarItem) | |
| 3157 { | |
| 3158 WebInspector.Widget.call(this); | |
| 3159 this._toolbarItem = toolbarItem; | |
| 3160 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod eChanged, this); | |
| 3161 } | |
| 3162 | |
| 3163 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.prototype = { | |
| 3164 | |
|
lushnikov
2015/05/29 10:53:12
stray line
sergeyv
2015/05/29 12:53:40
Done.
| |
| 3165 _nodeChanged: function() | |
| 3166 { | |
| 3167 if (!this.isShowing()) | |
| 3168 return; | |
| 3169 | |
| 3170 this.onNodeChanged(WebInspector.context.flavor(WebInspector.DOMNode)); | |
| 3171 }, | |
| 3172 | |
| 3173 /** | |
| 3174 * @param {?WebInspector.DOMNode} newNode | |
|
lushnikov
2015/05/29 10:53:12
protected?
sergeyv
2015/05/29 12:53:41
Done.
| |
| 3175 */ | |
| 3176 onNodeChanged: function(newNode) | |
| 3177 { | |
| 3178 }, | |
| 3179 | |
| 3180 willHide: function() | |
| 3181 { | |
| 3182 this.element.classList.remove("expanded"); | |
|
lushnikov
2015/05/29 10:53:12
?
sergeyv
2015/05/29 12:53:40
Done.
| |
| 3183 this._toolbarItem.setToggled(false); | |
| 3184 }, | |
| 3185 | |
| 3186 wasShown: function() | |
| 3187 { | |
| 3188 this._toolbarItem.setToggled(true); | |
| 3189 this.onNodeChanged(WebInspector.context.flavor(WebInspector.DOMNode)); | |
| 3190 }, | |
| 3191 | |
| 3192 __proto__: WebInspector.Widget.prototype | |
| 3193 } | |
| 3194 | |
| 3195 /** | |
| 3196 * @constructor | |
| 3197 * @implements {WebInspector.ToolbarItem.Provider} | |
| 3198 */ | |
| 3199 WebInspector.StylesSidebarPane.AddNewRuleButtonProvider = function() | |
| 3200 { | |
| 3201 this._button = new WebInspector.ToolbarButton(WebInspector.UIString("New Sty le Rule"), "add-toolbar-item"); | |
| 3202 this._button.makeLongClickEnabled(); | |
| 3203 var stylesSidebarPane = WebInspector.ElementsPanel.instance().sidebarPanes.s tyles; | |
| 3204 this._button.addEventListener("click", stylesSidebarPane._createNewRuleInVia InspectorStyleSheet, stylesSidebarPane); | |
| 3205 this._button.addEventListener("longClickDown", stylesSidebarPane._onAddButto nLongClick, stylesSidebarPane); | |
| 3206 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._onN odeChanged, this); | |
| 3207 this._onNodeChanged() | |
| 3208 } | |
| 3209 | |
| 3210 WebInspector.StylesSidebarPane.AddNewRuleButtonProvider.prototype = { | |
| 3211 _onNodeChanged: function() | |
| 3212 { | |
| 3213 var node = WebInspector.context.flavor(WebInspector.DOMNode); | |
| 3214 this.item().setEnabled(!!node); | |
| 3215 }, | |
| 3216 | |
| 3217 /** | |
| 3218 * @override | |
| 3219 * @return {?WebInspector.ToolbarItem} | |
| 3220 */ | |
| 3221 item: function() | |
| 3222 { | |
| 3223 return this._button; | |
| 3224 } | |
| 3225 } | |
| OLD | NEW |