Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: Source/devtools/front_end/elements/ElementStatePane.js

Issue 1149373004: Devtools: Extensible toolbar in SSP (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 /**
7 * @constructor
8 * @extends {WebInspector.StylesSidebarPane.BaseToolbarPaneWidget}
9 * @param {!WebInspector.ToolbarItem} toolbarItem
10 */
11 WebInspector.ElementStateView = 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.ElementStateView.prototype = {
59 /**
60 * @override
lushnikov 2015/05/29 10:53:12 param
sergeyv 2015/05/29 12:53:40 Done.
61 */
62 onNodeChanged: function(newNode)
63 {
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
76 __proto__: WebInspector.StylesSidebarPane.BaseToolbarPaneWidget.prototype
77 }
78
79 /**
80 * @constructor
81 * @implements {WebInspector.ToolbarItem.Provider}
82 */
83 WebInspector.ElementStateView.ButtonProvider = function()
84 {
85 this._button = new WebInspector.ToolbarButton(WebInspector.UIString("Toggle Element State"), "element-state-toolbar-item");
86 this._button.addEventListener("click", this._clicked, this);
87 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod eChanged, this);
88 this._nodeChanged();
89 }
90
91 WebInspector.ElementStateView.ButtonProvider.prototype = {
92 _clicked: function()
93 {
94 if (!this._view)
95 this._view = new WebInspector.ElementStateView(this.item());
96
97 var stylesSidebarPane = WebInspector.ElementsPanel.instance().sidebarPan es.styles;
98 stylesSidebarPane.showToolbarPane(!this._view.isShowing() ? this._view : null);
99 },
100
101 _nodeChanged: function()
102 {
103 var node = WebInspector.context.flavor(WebInspector.DOMNode);
104 var enabled = !!node && !node.pseudoType();
105 this._button.setEnabled(!!enabled);
lushnikov 2015/05/29 10:53:12 no need for !!
sergeyv 2015/05/29 12:53:40 Done.
106 if (!enabled && this._view && this._view.isShowing()) {
107 var stylesSidebarPane = WebInspector.ElementsPanel.instance().sideba rPanes.styles;
108 stylesSidebarPane.showToolbarPane(null);
109 }
110 },
111
112 /**
113 * @override
114 * @return {!WebInspector.ToolbarItem}
115 */
116 item: function()
117 {
118 return this._button;
119 }
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698