| 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 |
| 5 /** |
| 6 * @constructor |
| 7 * @extends {WebInspector.StylesSidebarPane.BaseToolbarPaneWidget} |
| 8 * @param {!WebInspector.ToolbarItem} toolbarItem |
| 9 */ |
| 10 WebInspector.ElementStatePaneWidget = function(toolbarItem) |
| 11 { |
| 12 WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.call(this, toolbarItem)
; |
| 13 this.element.className = "styles-element-state-pane source-code"; |
| 14 var table = createElement("table"); |
| 15 |
| 16 var inputs = []; |
| 17 this._inputs = inputs; |
| 18 |
| 19 /** |
| 20 * @param {!Event} event |
| 21 */ |
| 22 function clickListener(event) |
| 23 { |
| 24 var node = WebInspector.context.flavor(WebInspector.DOMNode); |
| 25 if (!node) |
| 26 return; |
| 27 WebInspector.CSSStyleModel.fromNode(node).forcePseudoState(node, event.t
arget.state, event.target.checked); |
| 28 } |
| 29 |
| 30 /** |
| 31 * @param {string} state |
| 32 * @return {!Element} |
| 33 */ |
| 34 function createCheckbox(state) |
| 35 { |
| 36 var td = createElement("td"); |
| 37 var label = createCheckboxLabel(":" + state); |
| 38 var input = label.checkboxElement; |
| 39 input.state = state; |
| 40 input.addEventListener("click", clickListener, false); |
| 41 inputs.push(input); |
| 42 td.appendChild(label); |
| 43 return td; |
| 44 } |
| 45 |
| 46 var tr = table.createChild("tr"); |
| 47 tr.appendChild(createCheckbox.call(null, "active")); |
| 48 tr.appendChild(createCheckbox.call(null, "hover")); |
| 49 |
| 50 tr = table.createChild("tr"); |
| 51 tr.appendChild(createCheckbox.call(null, "focus")); |
| 52 tr.appendChild(createCheckbox.call(null, "visited")); |
| 53 |
| 54 this.element.appendChild(table); |
| 55 } |
| 56 |
| 57 WebInspector.ElementStatePaneWidget.prototype = { |
| 58 /** |
| 59 * @override |
| 60 * @param {?WebInspector.DOMNode} newNode |
| 61 */ |
| 62 onNodeChanged: function(newNode) |
| 63 { |
| 64 this.toolbarItem().setEnabled(!!newNode); |
| 65 if (!newNode && this.isShowing()) { |
| 66 this.detach(); |
| 67 return; |
| 68 } |
| 69 |
| 70 var nodePseudoState = newNode.getUserProperty(WebInspector.CSSStyleModel
.PseudoStatePropertyName) || []; |
| 71 var inputs = this._inputs; |
| 72 for (var i = 0; i < inputs.length; ++i) { |
| 73 inputs[i].disabled = !!newNode.pseudoType(); |
| 74 inputs[i].checked = nodePseudoState.indexOf(inputs[i].state) >= 0; |
| 75 } |
| 76 }, |
| 77 |
| 78 __proto__: WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.prototype |
| 79 } |
| 80 |
| 81 /** |
| 82 * @constructor |
| 83 * @implements {WebInspector.ToolbarItem.Provider} |
| 84 */ |
| 85 WebInspector.ElementStatePaneWidget.ButtonProvider = function() |
| 86 { |
| 87 this._button = new WebInspector.ToolbarButton(WebInspector.UIString("Toggle
Element State"), "element-state-toolbar-item"); |
| 88 this._button.addEventListener("click", this._clicked, this); |
| 89 this._view = new WebInspector.ElementStatePaneWidget(this.item()); |
| 90 } |
| 91 |
| 92 WebInspector.ElementStatePaneWidget.ButtonProvider.prototype = { |
| 93 _clicked: function() |
| 94 { |
| 95 var stylesSidebarPane = WebInspector.ElementsPanel.instance().sidebarPan
es.styles; |
| 96 stylesSidebarPane.showToolbarPane(!this._view.isShowing() ? this._view :
null); |
| 97 }, |
| 98 |
| 99 /** |
| 100 * @override |
| 101 * @return {!WebInspector.ToolbarItem} |
| 102 */ |
| 103 item: function() |
| 104 { |
| 105 return this._button; |
| 106 } |
| 107 } |
| OLD | NEW |