| 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 | 48 var toolbarPaneContainer = this.bodyElement.createChild("div", "styles-sideb
ar-toolbar-pane-container"); |
| 63 this._createElementStatePane(); | 49 this._toolbarPaneElement = toolbarPaneContainer.createChild("div", "styles-s
idebar-toolbar-pane"); |
| 64 this.bodyElement.appendChild(this._elementStatePane); | 50 this._sectionsContainer = this.bodyElement.createChild("div"); |
| 65 this._animationsControlPane = new WebInspector.AnimationControlPane(); | |
| 66 this.bodyElement.appendChild(this._animationsControlPane.element); | |
| 67 this._sectionsContainer = createElement("div"); | |
| 68 this.bodyElement.appendChild(this._sectionsContainer); | |
| 69 | 51 |
| 70 this._stylesPopoverHelper = new WebInspector.StylesPopoverHelper(); | 52 this._stylesPopoverHelper = new WebInspector.StylesPopoverHelper(); |
| 71 | 53 |
| 72 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa
ultCSSFormatter()); | 54 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa
ultCSSFormatter()); |
| 73 | 55 |
| 74 this.element.classList.add("styles-pane"); | 56 this.element.classList.add("styles-pane"); |
| 75 this.element.addEventListener("mousemove", this._mouseMovedOverElement.bind(
this), false); | 57 this.element.addEventListener("mousemove", this._mouseMovedOverElement.bind(
this), false); |
| 76 this._keyDownBound = this._keyDown.bind(this); | 58 this._keyDownBound = this._keyDown.bind(this); |
| 77 this._keyUpBound = this._keyUp.bind(this); | 59 this._keyUpBound = this._keyUp.bind(this); |
| 78 } | 60 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 /** | 281 /** |
| 300 * @param {?RegExp} regex | 282 * @param {?RegExp} regex |
| 301 */ | 283 */ |
| 302 _onFilterChanged: function(regex) | 284 _onFilterChanged: function(regex) |
| 303 { | 285 { |
| 304 this._filterRegex = regex; | 286 this._filterRegex = regex; |
| 305 this._updateFilter(); | 287 this._updateFilter(); |
| 306 }, | 288 }, |
| 307 | 289 |
| 308 /** | 290 /** |
| 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 | 291 * @override |
| 338 * @param {?WebInspector.DOMNode} node | 292 * @param {?WebInspector.DOMNode} node |
| 339 */ | 293 */ |
| 340 setNode: function(node) | 294 setNode: function(node) |
| 341 { | 295 { |
| 342 // We should update SSP on main frame navigation only. | 296 // We should update SSP on main frame navigation only. |
| 343 var mainFrameNavigated = node && this.node() && node.ownerDocument !== t
his.node().ownerDocument; | 297 var mainFrameNavigated = node && this.node() && node.ownerDocument !== t
his.node().ownerDocument; |
| 344 if (!mainFrameNavigated && node !== this.node()) { | 298 if (!mainFrameNavigated && node !== this.node()) { |
| 345 this.element.classList.toggle("no-affect", this._isEditingStyle); | 299 this.element.classList.toggle("no-affect", this._isEditingStyle); |
| 346 if (this._isEditingStyle) { | 300 if (this._isEditingStyle) { |
| 347 this._pendingNode = node; | 301 this._pendingNode = node; |
| 348 return; | 302 return; |
| 349 } | 303 } |
| 350 } | 304 } |
| 351 | 305 |
| 352 this._stylesPopoverHelper.hide(); | 306 this._stylesPopoverHelper.hide(); |
| 353 node = WebInspector.SharedSidebarModel.elementNode(node); | 307 node = WebInspector.SharedSidebarModel.elementNode(node); |
| 354 | 308 |
| 355 this._resetCache(); | 309 this._resetCache(); |
| 356 this._animationsControlPane.setNode(node); | |
| 357 if (this._animationTimeline) | |
| 358 this._animationTimeline.setNode(node); | |
| 359 WebInspector.ElementsSidebarPane.prototype.setNode.call(this, node); | 310 WebInspector.ElementsSidebarPane.prototype.setNode.call(this, node); |
| 360 }, | 311 }, |
| 361 | 312 |
| 362 /** | 313 /** |
| 363 * @param {!WebInspector.StylePropertiesSection=} editedSection | 314 * @param {!WebInspector.StylePropertiesSection=} editedSection |
| 364 */ | 315 */ |
| 365 _refreshUpdate: function(editedSection) | 316 _refreshUpdate: function(editedSection) |
| 366 { | 317 { |
| 367 var node = this.node(); | 318 var node = this.node(); |
| 368 if (!node) | 319 if (!node) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 380 this._updateFilter(); | 331 this._updateFilter(); |
| 381 this._nodeStylesUpdatedForTest(node, false); | 332 this._nodeStylesUpdatedForTest(node, false); |
| 382 }, | 333 }, |
| 383 | 334 |
| 384 /** | 335 /** |
| 385 * @override | 336 * @override |
| 386 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback | 337 * @param {!WebInspector.Throttler.FinishCallback} finishedCallback |
| 387 */ | 338 */ |
| 388 doUpdate: function(finishedCallback) | 339 doUpdate: function(finishedCallback) |
| 389 { | 340 { |
| 390 this._updateForcedPseudoStateInputs(); | |
| 391 this._discardElementUnderMouse(); | 341 this._discardElementUnderMouse(); |
| 392 | 342 |
| 393 this.fetchMatchedCascade() | 343 this.fetchMatchedCascade() |
| 394 .then(this._innerRebuildUpdate.bind(this)) | 344 .then(this._innerRebuildUpdate.bind(this)) |
| 395 .then(finishedCallback) | 345 .then(finishedCallback) |
| 396 .catch(/** @type {function()} */(finishedCallback)); | 346 .catch(/** @type {function()} */(finishedCallback)); |
| 397 }, | 347 }, |
| 398 | 348 |
| 399 _resetCache: function() | 349 _resetCache: function() |
| 400 { | 350 { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 { | 719 { |
| 770 for (var block of this._sectionBlocks) { | 720 for (var block of this._sectionBlocks) { |
| 771 var index = block.sections.indexOf(section); | 721 var index = block.sections.indexOf(section); |
| 772 if (index === -1) | 722 if (index === -1) |
| 773 continue; | 723 continue; |
| 774 block.sections.splice(index, 1); | 724 block.sections.splice(index, 1); |
| 775 section.element.remove(); | 725 section.element.remove(); |
| 776 } | 726 } |
| 777 }, | 727 }, |
| 778 | 728 |
| 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 /** | 729 /** |
| 859 * @return {?RegExp} | 730 * @return {?RegExp} |
| 860 */ | 731 */ |
| 861 filterRegex: function() | 732 filterRegex: function() |
| 862 { | 733 { |
| 863 return this._filterRegex; | 734 return this._filterRegex; |
| 864 }, | 735 }, |
| 865 | 736 |
| 866 _updateFilter: function() | 737 _updateFilter: function() |
| 867 { | 738 { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 * @param {!Event} event | 797 * @param {!Event} event |
| 927 */ | 798 */ |
| 928 _keyUp: function(event) | 799 _keyUp: function(event) |
| 929 { | 800 { |
| 930 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho
rtcut.Keys.Ctrl.code) || | 801 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho
rtcut.Keys.Ctrl.code) || |
| 931 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor
tcut.Keys.Meta.code)) { | 802 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor
tcut.Keys.Meta.code)) { |
| 932 this._discardElementUnderMouse(); | 803 this._discardElementUnderMouse(); |
| 933 } | 804 } |
| 934 }, | 805 }, |
| 935 | 806 |
| 807 /** |
| 808 * @param {?WebInspector.Widget} widget |
| 809 */ |
| 810 showToolbarPane: function(widget) |
| 811 { |
| 812 if (this._animatedToolbarPane !== undefined) |
| 813 this._pendingWidget = widget; |
| 814 else |
| 815 this._startToolbarPaneAnimation(widget); |
| 816 }, |
| 817 |
| 818 /** |
| 819 * @param {?WebInspector.Widget} widget |
| 820 */ |
| 821 _startToolbarPaneAnimation: function(widget) |
| 822 { |
| 823 if (widget === this._currentToolbarPane) |
| 824 return; |
| 825 |
| 826 this._animatedToolbarPane = widget; |
| 827 |
| 828 if (this._currentToolbarPane) |
| 829 this._toolbarPaneElement.style.animationName = 'styles-element-state
-pane-slideout'; |
| 830 else if (widget) |
| 831 this._toolbarPaneElement.style.animationName = 'styles-element-state
-pane-slidein'; |
| 832 |
| 833 if (widget) |
| 834 widget.show(this._toolbarPaneElement); |
| 835 |
| 836 var listener = onAnimationEnd.bind(this); |
| 837 this._toolbarPaneElement.addEventListener("animationend", listener, fals
e); |
| 838 |
| 839 /** |
| 840 * @this {WebInspector.StylesSidebarPane} |
| 841 */ |
| 842 function onAnimationEnd() |
| 843 { |
| 844 this._toolbarPaneElement.style.removeProperty('animation-name'); |
| 845 this._toolbarPaneElement.removeEventListener("animationend", listene
r, false); |
| 846 |
| 847 if (this._currentToolbarPane) |
| 848 this._currentToolbarPane.detach(); |
| 849 |
| 850 this._currentToolbarPane = this._animatedToolbarPane; |
| 851 delete this._animatedToolbarPane; |
| 852 |
| 853 if (this._pendingWidget !== undefined) { |
| 854 this._startToolbarPaneAnimation(this._pendingWidget); |
| 855 delete this._pendingWidget; |
| 856 } |
| 857 } |
| 858 }, |
| 859 |
| 936 __proto__: WebInspector.ElementsSidebarPane.prototype | 860 __proto__: WebInspector.ElementsSidebarPane.prototype |
| 937 } | 861 } |
| 938 | 862 |
| 939 /** | 863 /** |
| 940 * @param {string} placeholder | 864 * @param {string} placeholder |
| 941 * @return {!Element} | 865 * @return {!Element} |
| 942 * @param {function(?RegExp)} filterCallback | 866 * @param {function(?RegExp)} filterCallback |
| 943 */ | 867 */ |
| 944 WebInspector.StylesSidebarPane.createPropertyFilterElement = function(placeholde
r, filterCallback) | 868 WebInspector.StylesSidebarPane.createPropertyFilterElement = function(placeholde
r, filterCallback) |
| 945 { | 869 { |
| (...skipping 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3241 | 3165 |
| 3242 WebInspector.StylesSidebarPane.MatchedRulesPayload.prototype = { | 3166 WebInspector.StylesSidebarPane.MatchedRulesPayload.prototype = { |
| 3243 /** | 3167 /** |
| 3244 * @return {boolean} | 3168 * @return {boolean} |
| 3245 */ | 3169 */ |
| 3246 fulfilled: function() | 3170 fulfilled: function() |
| 3247 { | 3171 { |
| 3248 return !!(this.matchedCSSRules && this.pseudoElements && this.inherited)
; | 3172 return !!(this.matchedCSSRules && this.pseudoElements && this.inherited)
; |
| 3249 } | 3173 } |
| 3250 } | 3174 } |
| 3175 |
| 3176 /** |
| 3177 * @constructor |
| 3178 * @extends {WebInspector.Widget} |
| 3179 * @param {!WebInspector.ToolbarItem} toolbarItem |
| 3180 */ |
| 3181 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget = function(toolbarItem) |
| 3182 { |
| 3183 WebInspector.Widget.call(this); |
| 3184 this._toolbarItem = toolbarItem; |
| 3185 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod
eChanged, this); |
| 3186 } |
| 3187 |
| 3188 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.prototype = { |
| 3189 /** |
| 3190 * @return {!WebInspector.ToolbarItem} |
| 3191 */ |
| 3192 toolbarItem: function() |
| 3193 { |
| 3194 return this._toolbarItem; |
| 3195 }, |
| 3196 |
| 3197 _nodeChanged: function() |
| 3198 { |
| 3199 if (!this.isShowing()) |
| 3200 return; |
| 3201 |
| 3202 var elementNode = WebInspector.SharedSidebarModel.elementNode(WebInspect
or.context.flavor(WebInspector.DOMNode)); |
| 3203 this.onNodeChanged(elementNode); |
| 3204 }, |
| 3205 |
| 3206 /** |
| 3207 * @param {?WebInspector.DOMNode} newNode |
| 3208 * @protected |
| 3209 */ |
| 3210 onNodeChanged: function(newNode) |
| 3211 { |
| 3212 }, |
| 3213 |
| 3214 /** |
| 3215 * @override |
| 3216 */ |
| 3217 willHide: function() |
| 3218 { |
| 3219 this._toolbarItem.setToggled(false); |
| 3220 }, |
| 3221 |
| 3222 /** |
| 3223 * @override |
| 3224 */ |
| 3225 wasShown: function() |
| 3226 { |
| 3227 this._toolbarItem.setToggled(true); |
| 3228 this._nodeChanged(); |
| 3229 }, |
| 3230 |
| 3231 __proto__: WebInspector.Widget.prototype |
| 3232 } |
| 3233 |
| 3234 /** |
| 3235 * @constructor |
| 3236 * @implements {WebInspector.ToolbarItem.Provider} |
| 3237 */ |
| 3238 WebInspector.StylesSidebarPane.AddNewRuleButtonProvider = function() |
| 3239 { |
| 3240 this._button = new WebInspector.ToolbarButton(WebInspector.UIString("New Sty
le Rule"), "add-toolbar-item"); |
| 3241 this._button.makeLongClickEnabled(); |
| 3242 var stylesSidebarPane = WebInspector.ElementsPanel.instance().sidebarPanes.s
tyles; |
| 3243 this._button.addEventListener("click", stylesSidebarPane._createNewRuleInVia
InspectorStyleSheet, stylesSidebarPane); |
| 3244 this._button.addEventListener("longClickDown", stylesSidebarPane._onAddButto
nLongClick, stylesSidebarPane); |
| 3245 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._onN
odeChanged, this); |
| 3246 this._onNodeChanged() |
| 3247 } |
| 3248 |
| 3249 WebInspector.StylesSidebarPane.AddNewRuleButtonProvider.prototype = { |
| 3250 _onNodeChanged: function() |
| 3251 { |
| 3252 var node = WebInspector.context.flavor(WebInspector.DOMNode); |
| 3253 this.item().setEnabled(!!node); |
| 3254 }, |
| 3255 |
| 3256 /** |
| 3257 * @override |
| 3258 * @return {?WebInspector.ToolbarItem} |
| 3259 */ |
| 3260 item: function() |
| 3261 { |
| 3262 return this._button; |
| 3263 } |
| 3264 } |
| OLD | NEW |