Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
|
lushnikov
2015/05/29 13:38:47
stray line
sergeyv
2015/05/29 13:43:18
Done.
| |
| 5 | |
| 6 /** | |
| 7 * @constructor | |
| 8 * @extends {WebInspector.StylesSidebarPane.BaseToolbarPaneWidget} | |
| 9 * @param {!WebInspector.ToolbarItem} toolbarItem | |
| 10 */ | |
| 11 WebInspector.ElementStatePaneWidget = function(toolbarItem) | |
| 12 { | |
| 13 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.call(this, toolbarItem) ; | |
| 14 this.element.className = "styles-element-state-pane source-code"; | |
| 15 var table = createElement("table"); | |
| 16 | |
| 17 var inputs = []; | |
| 18 this._inputs = inputs; | |
| 19 | |
| 20 /** | |
| 21 * @param {!Event} event | |
| 22 */ | |
| 23 function clickListener(event) | |
| 24 { | |
| 25 var node = WebInspector.context.flavor(WebInspector.DOMNode); | |
| 26 if (!node) | |
| 27 return; | |
| 28 WebInspector.CSSStyleModel.fromNode(node).forcePseudoState(node, event.t arget.state, event.target.checked); | |
| 29 } | |
| 30 | |
| 31 /** | |
| 32 * @param {string} state | |
| 33 * @return {!Element} | |
| 34 */ | |
| 35 function createCheckbox(state) | |
| 36 { | |
| 37 var td = createElement("td"); | |
| 38 var label = createCheckboxLabel(":" + state); | |
| 39 var input = label.checkboxElement; | |
| 40 input.state = state; | |
| 41 input.addEventListener("click", clickListener, false); | |
| 42 inputs.push(input); | |
| 43 td.appendChild(label); | |
| 44 return td; | |
| 45 } | |
| 46 | |
| 47 var tr = table.createChild("tr"); | |
| 48 tr.appendChild(createCheckbox.call(null, "active")); | |
| 49 tr.appendChild(createCheckbox.call(null, "hover")); | |
| 50 | |
| 51 tr = table.createChild("tr"); | |
| 52 tr.appendChild(createCheckbox.call(null, "focus")); | |
| 53 tr.appendChild(createCheckbox.call(null, "visited")); | |
| 54 | |
| 55 this.element.appendChild(table); | |
| 56 } | |
| 57 | |
| 58 WebInspector.ElementStatePaneWidget.prototype = { | |
| 59 /** | |
| 60 * @override | |
| 61 * @param {?WebInspector.DOMNode} newNode | |
| 62 */ | |
| 63 onNodeChanged: function(newNode) { | |
| 64 if (!newNode) | |
| 65 return; | |
| 66 | |
| 67 var nodePseudoState = newNode.getUserProperty(WebInspector.CSSStyleModel .PseudoStatePropertyName); | |
| 68 if (!nodePseudoState) | |
| 69 nodePseudoState = []; | |
| 70 | |
| 71 var inputs = this._inputs; | |
| 72 for (var i = 0; i < inputs.length; ++i) | |
| 73 inputs[i].checked = nodePseudoState.indexOf(inputs[i].state) >= 0; | |
| 74 | |
| 75 var enabled = !!newNode && !newNode.pseudoType(); | |
| 76 if (!enabled && this.isShowing()) | |
| 77 this.detach(); | |
| 78 }, | |
| 79 | |
| 80 __proto__: WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.prototype | |
| 81 } | |
| 82 | |
| 83 /** | |
| 84 * @constructor | |
| 85 * @implements {WebInspector.ToolbarItem.Provider} | |
| 86 */ | |
| 87 WebInspector.ElementStatePaneWidget.ButtonProvider = function() | |
| 88 { | |
| 89 this._button = new WebInspector.ToolbarButton(WebInspector.UIString("Toggle Element State"), "element-state-toolbar-item"); | |
| 90 this._button.addEventListener("click", this._clicked, this); | |
| 91 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod eChanged, this); | |
| 92 this._nodeChanged(); | |
| 93 } | |
| 94 | |
| 95 WebInspector.ElementStatePaneWidget.ButtonProvider.prototype = { | |
| 96 _clicked: function() | |
| 97 { | |
| 98 if (!this._view) | |
| 99 this._view = new WebInspector.ElementStatePaneWidget(this.item()); | |
| 100 | |
| 101 var stylesSidebarPane = WebInspector.ElementsPanel.instance().sidebarPan es.styles; | |
| 102 stylesSidebarPane.showToolbarPane(!this._view.isShowing() ? this._view : null); | |
| 103 }, | |
| 104 | |
| 105 _nodeChanged: function() | |
| 106 { | |
| 107 var node = WebInspector.context.flavor(WebInspector.DOMNode); | |
|
lushnikov
2015/05/29 13:38:47
lets inline
sergeyv
2015/05/29 13:43:18
Done.
| |
| 108 var enabled = !!node && !node.pseudoType(); | |
| 109 this._button.setEnabled(enabled); | |
| 110 }, | |
| 111 | |
| 112 /** | |
| 113 * @override | |
| 114 * @return {!WebInspector.ToolbarItem} | |
| 115 */ | |
| 116 item: function() | |
| 117 { | |
| 118 return this._button; | |
| 119 } | |
| 120 } | |
| OLD | NEW |