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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/ElementStatePaneWidget.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4
5 /** 4 /**
6 * @constructor 5 * @unrestricted
7 * @extends {WebInspector.Widget}
8 */ 6 */
9 WebInspector.ElementStatePaneWidget = function() 7 WebInspector.ElementStatePaneWidget = class extends WebInspector.Widget {
10 { 8 constructor() {
11 WebInspector.Widget.call(this); 9 super();
12 this.element.className = "styles-element-state-pane"; 10 this.element.className = 'styles-element-state-pane';
13 this.element.createChild("div").createTextChild(WebInspector.UIString("Force element state")); 11 this.element.createChild('div').createTextChild(WebInspector.UIString('Force element state'));
14 var table = createElementWithClass("table", "source-code"); 12 var table = createElementWithClass('table', 'source-code');
15 13
16 var inputs = []; 14 var inputs = [];
17 this._inputs = inputs; 15 this._inputs = inputs;
18 16
19 /** 17 /**
20 * @param {!Event} event 18 * @param {!Event} event
21 */ 19 */
22 function clickListener(event) 20 function clickListener(event) {
23 { 21 var node = WebInspector.context.flavor(WebInspector.DOMNode);
24 var node = WebInspector.context.flavor(WebInspector.DOMNode); 22 if (!node)
25 if (!node) 23 return;
26 return; 24 WebInspector.CSSModel.fromNode(node).forcePseudoState(node, event.target.s tate, event.target.checked);
27 WebInspector.CSSModel.fromNode(node).forcePseudoState(node, event.target .state, event.target.checked);
28 } 25 }
29 26
30 /** 27 /**
31 * @param {string} state 28 * @param {string} state
32 * @return {!Element} 29 * @return {!Element}
33 */ 30 */
34 function createCheckbox(state) 31 function createCheckbox(state) {
35 { 32 var td = createElement('td');
36 var td = createElement("td"); 33 var label = createCheckboxLabel(':' + state);
37 var label = createCheckboxLabel(":" + state); 34 var input = label.checkboxElement;
38 var input = label.checkboxElement; 35 input.state = state;
39 input.state = state; 36 input.addEventListener('click', clickListener, false);
40 input.addEventListener("click", clickListener, false); 37 inputs.push(input);
41 inputs.push(input); 38 td.appendChild(label);
42 td.appendChild(label); 39 return td;
43 return td;
44 } 40 }
45 41
46 var tr = table.createChild("tr"); 42 var tr = table.createChild('tr');
47 tr.appendChild(createCheckbox.call(null, "active")); 43 tr.appendChild(createCheckbox.call(null, 'active'));
48 tr.appendChild(createCheckbox.call(null, "hover")); 44 tr.appendChild(createCheckbox.call(null, 'hover'));
49 45
50 tr = table.createChild("tr"); 46 tr = table.createChild('tr');
51 tr.appendChild(createCheckbox.call(null, "focus")); 47 tr.appendChild(createCheckbox.call(null, 'focus'));
52 tr.appendChild(createCheckbox.call(null, "visited")); 48 tr.appendChild(createCheckbox.call(null, 'visited'));
53 49
54 this.element.appendChild(table); 50 this.element.appendChild(table);
55 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._upd ate, this); 51 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._upd ate, this);
56 }; 52 }
57 53
58 WebInspector.ElementStatePaneWidget.prototype = { 54 /**
59 /** 55 * @param {?WebInspector.Target} target
60 * @param {?WebInspector.Target} target 56 */
61 */ 57 _updateTarget(target) {
62 _updateTarget: function(target) 58 if (this._target === target)
63 { 59 return;
64 if (this._target === target)
65 return;
66 60
67 if (this._target) { 61 if (this._target) {
68 var cssModel = WebInspector.CSSModel.fromTarget(this._target); 62 var cssModel = WebInspector.CSSModel.fromTarget(this._target);
69 cssModel.removeEventListener(WebInspector.CSSModel.Events.PseudoStat eForced, this._update, this); 63 cssModel.removeEventListener(WebInspector.CSSModel.Events.PseudoStateForce d, this._update, this);
70 } 64 }
71 this._target = target; 65 this._target = target;
72 if (target) { 66 if (target) {
73 var cssModel = WebInspector.CSSModel.fromTarget(target); 67 var cssModel = WebInspector.CSSModel.fromTarget(target);
74 cssModel.addEventListener(WebInspector.CSSModel.Events.PseudoStateFo rced, this._update, this); 68 cssModel.addEventListener(WebInspector.CSSModel.Events.PseudoStateForced, this._update, this);
75 } 69 }
76 }, 70 }
77 71
78 /** 72 /**
79 * @override 73 * @override
80 */ 74 */
81 wasShown: function() 75 wasShown() {
82 { 76 this._update();
83 this._update(); 77 }
84 },
85 78
86 _update: function() 79 _update() {
87 { 80 if (!this.isShowing())
88 if (!this.isShowing()) 81 return;
89 return;
90 82
91 var node = WebInspector.context.flavor(WebInspector.DOMNode); 83 var node = WebInspector.context.flavor(WebInspector.DOMNode);
92 if (node) 84 if (node)
93 node = node.enclosingElementOrSelf(); 85 node = node.enclosingElementOrSelf();
94 86
95 this._updateTarget(node ? node.target() : null); 87 this._updateTarget(node ? node.target() : null);
96 if (node) { 88 if (node) {
97 var nodePseudoState = WebInspector.CSSModel.fromNode(node).pseudoSta te(node); 89 var nodePseudoState = WebInspector.CSSModel.fromNode(node).pseudoState(nod e);
98 for (var input of this._inputs) { 90 for (var input of this._inputs) {
99 input.disabled = !!node.pseudoType(); 91 input.disabled = !!node.pseudoType();
100 input.checked = nodePseudoState.indexOf(input.state) >= 0; 92 input.checked = nodePseudoState.indexOf(input.state) >= 0;
101 } 93 }
102 } else { 94 } else {
103 for (var input of this._inputs) { 95 for (var input of this._inputs) {
104 input.disabled = true; 96 input.disabled = true;
105 input.checked = false; 97 input.checked = false;
106 } 98 }
107 } 99 }
108 }, 100 }
109
110 __proto__: WebInspector.Widget.prototype
111 }; 101 };
112 102
113 /** 103 /**
114 * @constructor
115 * @implements {WebInspector.ToolbarItem.Provider} 104 * @implements {WebInspector.ToolbarItem.Provider}
105 * @unrestricted
116 */ 106 */
117 WebInspector.ElementStatePaneWidget.ButtonProvider = function() 107 WebInspector.ElementStatePaneWidget.ButtonProvider = class {
118 { 108 constructor() {
119 this._button = new WebInspector.ToolbarToggle(WebInspector.UIString("Toggle Element State"), "", WebInspector.UIString(":hov")); 109 this._button = new WebInspector.ToolbarToggle(
120 this._button.addEventListener("click", this._clicked, this); 110 WebInspector.UIString('Toggle Element State'), '', WebInspector.UIString (':hov'));
121 this._button.element.classList.add("monospace"); 111 this._button.addEventListener('click', this._clicked, this);
112 this._button.element.classList.add('monospace');
122 this._view = new WebInspector.ElementStatePaneWidget(); 113 this._view = new WebInspector.ElementStatePaneWidget();
114 }
115
116 _clicked() {
117 WebInspector.ElementsPanel.instance().showToolbarPane(!this._view.isShowing( ) ? this._view : null, this._button);
118 }
119
120 /**
121 * @override
122 * @return {!WebInspector.ToolbarItem}
123 */
124 item() {
125 return this._button;
126 }
123 }; 127 };
124
125 WebInspector.ElementStatePaneWidget.ButtonProvider.prototype = {
126 _clicked: function()
127 {
128 WebInspector.ElementsPanel.instance().showToolbarPane(!this._view.isShow ing() ? this._view : null, this._button);
129 },
130
131 /**
132 * @override
133 * @return {!WebInspector.ToolbarItem}
134 */
135 item: function()
136 {
137 return this._button;
138 }
139 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698