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.
7 * @extends {WebInspector.StylesSidebarPane.BaseToolbarPaneWidget}
8 * @param {!WebInspector.ToolbarItem} toolbarItem
10 WebInspector
.ElementStatePaneWidget = function(toolbarItem
)
12 WebInspector
.StylesSidebarPane
.BaseToolbarPaneWidget
.call(this, toolbarItem
);
13 this.element
.className
= "styles-element-state-pane";
14 this.element
.createChild("div").createTextChild(WebInspector
.UIString("Force element state"));
15 var table
= createElementWithClass("table", "source-code");
18 this._inputs
= inputs
;
21 * @param {!Event} event
23 function clickListener(event
)
25 var node
= WebInspector
.context
.flavor(WebInspector
.DOMNode
);
28 WebInspector
.CSSStyleModel
.fromNode(node
).forcePseudoState(node
, event
.target
.state
, event
.target
.checked
);
32 * @param {string} state
35 function createCheckbox(state
)
37 var td
= createElement("td");
38 var label
= createCheckboxLabel(":" + state
);
39 var input
= label
.checkboxElement
;
41 input
.addEventListener("click", clickListener
, false);
43 td
.appendChild(label
);
47 var tr
= table
.createChild("tr");
48 tr
.appendChild(createCheckbox
.call(null, "active"));
49 tr
.appendChild(createCheckbox
.call(null, "hover"));
51 tr
= table
.createChild("tr");
52 tr
.appendChild(createCheckbox
.call(null, "focus"));
53 tr
.appendChild(createCheckbox
.call(null, "visited"));
55 this.element
.appendChild(table
);
58 WebInspector
.ElementStatePaneWidget
.prototype = {
60 * @param {?WebInspector.Target} target
62 _updateTarget: function(target
)
64 if (this._target
=== target
)
68 var cssModel
= WebInspector
.CSSStyleModel
.fromTarget(this._target
);
69 cssModel
.removeEventListener(WebInspector
.CSSStyleModel
.Events
.PseudoStateForced
, this._pseudoStateForced
, this)
71 this._target
= target
;
73 var cssModel
= WebInspector
.CSSStyleModel
.fromTarget(target
);
74 cssModel
.addEventListener(WebInspector
.CSSStyleModel
.Events
.PseudoStateForced
, this._pseudoStateForced
, this)
79 * @param {!WebInspector.Event} event
81 _pseudoStateForced: function(event
)
83 var node
= /** @type{!WebInspector.DOMNode} */(event
.data
.node
);
84 if (node
=== WebInspector
.context
.flavor(WebInspector
.DOMNode
))
85 this._updateInputs(node
);
90 * @param {?WebInspector.DOMNode} newNode
92 onNodeChanged: function(newNode
)
94 this._updateTarget(newNode
? newNode
.target() : null);
96 this._updateInputs(newNode
);
100 * @param {!WebInspector.DOMNode} node
102 _updateInputs: function(node
)
104 var nodePseudoState
= WebInspector
.CSSStyleModel
.fromNode(node
).pseudoState(node
);
105 var inputs
= this._inputs
;
106 for (var i
= 0; i
< inputs
.length
; ++i
) {
107 inputs
[i
].disabled
= !!node
.pseudoType();
108 inputs
[i
].checked
= nodePseudoState
.indexOf(inputs
[i
].state
) >= 0;
112 __proto__
: WebInspector
.StylesSidebarPane
.BaseToolbarPaneWidget
.prototype
117 * @implements {WebInspector.ToolbarItem.Provider}
119 WebInspector
.ElementStatePaneWidget
.ButtonProvider = function()
121 this._button
= new WebInspector
.ToolbarButton(WebInspector
.UIString("Toggle Element State"), "pin-toolbar-item");
122 this._button
.addEventListener("click", this._clicked
, this);
123 this._view
= new WebInspector
.ElementStatePaneWidget(this.item());
124 WebInspector
.context
.addFlavorChangeListener(WebInspector
.DOMNode
, this._nodeChanged
, this);
128 WebInspector
.ElementStatePaneWidget
.ButtonProvider
.prototype = {
131 var stylesSidebarPane
= WebInspector
.ElementsPanel
.instance().sidebarPanes
.styles
;
132 stylesSidebarPane
.showToolbarPane(!this._view
.isShowing() ? this._view
: null);
137 * @return {!WebInspector.ToolbarItem}
144 _nodeChanged: function()
146 var enabled
= !!WebInspector
.context
.flavor(WebInspector
.DOMNode
);
147 this._button
.setEnabled(enabled
);
148 if (!enabled
&& this._button
.toggled())
149 WebInspector
.ElementsPanel
.instance().sidebarPanes
.styles
.showToolbarPane(null);