mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 20:11:38 +08:00
This reverts commit9fd15ddbd0. Reason for revert: Fixed browser tests loading behavior Original change's description: > Revert "Migrate elements/ to ESM" > > This reverts commit8fefb2ca13. > > Reason for revert: broke browsertest https://ci.chromium.org/p/chromium/builders/try/linux-rel/250464 and blocking roll. > > Original change's description: > > Migrate elements/ to ESM > > > > Bug: 1006759 > > Change-Id: Ie9144a22562eb3ae3341a285f5ad16f3d630896c > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1934212 > > Reviewed-by: Paul Lewis <aerotwist@chromium.org> > > Commit-Queue: Paul Lewis <aerotwist@chromium.org> > > Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> > > TBR=aerotwist@chromium.org,tvanderlippe@chromium.org > > # Not skipping CQ checks because original CL landed > 1 day ago. > > Bug: 1006759 > Change-Id: I16a1fd9851391a6080c5376ca35866402b0bc445 > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1937027 > Reviewed-by: Yang Guo <yangguo@chromium.org> > Commit-Queue: Yang Guo <yangguo@chromium.org> Change-Id: Iba84f5230f20a86b2de75b84115fcb10aeea534e Bug: 1006759 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1937029 Reviewed-by: Mathias Bynens <mathias@chromium.org> Commit-Queue: Mathias Bynens <mathias@chromium.org> Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
151 lines
4.0 KiB
JavaScript
151 lines
4.0 KiB
JavaScript
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
export default class ElementStatePaneWidget extends UI.Widget {
|
|
constructor() {
|
|
super(true);
|
|
this.registerRequiredCSS('elements/elementStatePaneWidget.css');
|
|
this.contentElement.className = 'styles-element-state-pane';
|
|
this.contentElement.createChild('div').createTextChild(Common.UIString('Force element state'));
|
|
const table = createElementWithClass('table', 'source-code');
|
|
|
|
const inputs = [];
|
|
this._inputs = inputs;
|
|
|
|
/**
|
|
* @param {!Event} event
|
|
*/
|
|
function clickListener(event) {
|
|
const node = UI.context.flavor(SDK.DOMNode);
|
|
if (!node) {
|
|
return;
|
|
}
|
|
node.domModel().cssModel().forcePseudoState(node, event.target.state, event.target.checked);
|
|
}
|
|
|
|
/**
|
|
* @param {string} state
|
|
* @return {!Element}
|
|
*/
|
|
function createCheckbox(state) {
|
|
const td = createElement('td');
|
|
const label = UI.CheckboxLabel.create(':' + state);
|
|
const input = label.checkboxElement;
|
|
input.state = state;
|
|
input.addEventListener('click', clickListener, false);
|
|
inputs.push(input);
|
|
td.appendChild(label);
|
|
return td;
|
|
}
|
|
|
|
let tr = table.createChild('tr');
|
|
tr.appendChild(createCheckbox.call(null, 'active'));
|
|
tr.appendChild(createCheckbox.call(null, 'hover'));
|
|
|
|
tr = table.createChild('tr');
|
|
tr.appendChild(createCheckbox.call(null, 'focus'));
|
|
tr.appendChild(createCheckbox.call(null, 'visited'));
|
|
|
|
tr = table.createChild('tr');
|
|
tr.appendChild(createCheckbox.call(null, 'focus-within'));
|
|
try {
|
|
tr.querySelector(':focus-visible'); // Will throw if not supported
|
|
tr.appendChild(createCheckbox.call(null, 'focus-visible'));
|
|
} catch (e) {
|
|
}
|
|
|
|
this.contentElement.appendChild(table);
|
|
UI.context.addFlavorChangeListener(SDK.DOMNode, this._update, this);
|
|
}
|
|
|
|
/**
|
|
* @param {?SDK.CSSModel} cssModel
|
|
*/
|
|
_updateModel(cssModel) {
|
|
if (this._cssModel === cssModel) {
|
|
return;
|
|
}
|
|
if (this._cssModel) {
|
|
this._cssModel.removeEventListener(SDK.CSSModel.Events.PseudoStateForced, this._update, this);
|
|
}
|
|
this._cssModel = cssModel;
|
|
if (this._cssModel) {
|
|
this._cssModel.addEventListener(SDK.CSSModel.Events.PseudoStateForced, this._update, this);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
*/
|
|
wasShown() {
|
|
this._update();
|
|
}
|
|
|
|
_update() {
|
|
if (!this.isShowing()) {
|
|
return;
|
|
}
|
|
|
|
let node = UI.context.flavor(SDK.DOMNode);
|
|
if (node) {
|
|
node = node.enclosingElementOrSelf();
|
|
}
|
|
|
|
this._updateModel(node ? node.domModel().cssModel() : null);
|
|
if (node) {
|
|
const nodePseudoState = node.domModel().cssModel().pseudoState(node);
|
|
for (const input of this._inputs) {
|
|
input.disabled = !!node.pseudoType();
|
|
input.checked = nodePseudoState.indexOf(input.state) >= 0;
|
|
}
|
|
} else {
|
|
for (const input of this._inputs) {
|
|
input.disabled = true;
|
|
input.checked = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @implements {UI.ToolbarItem.Provider}
|
|
* @unrestricted
|
|
*/
|
|
export class ButtonProvider {
|
|
constructor() {
|
|
this._button = new UI.ToolbarToggle(Common.UIString('Toggle Element State'), '');
|
|
this._button.setText(Common.UIString(':hov'));
|
|
this._button.addEventListener(UI.ToolbarButton.Events.Click, this._clicked, this);
|
|
this._button.element.classList.add('monospace');
|
|
this._view = new ElementStatePaneWidget();
|
|
}
|
|
|
|
_clicked() {
|
|
Elements.ElementsPanel.instance().showToolbarPane(!this._view.isShowing() ? this._view : null, this._button);
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
* @return {!UI.ToolbarItem}
|
|
*/
|
|
item() {
|
|
return this._button;
|
|
}
|
|
}
|
|
|
|
/* Legacy exported object */
|
|
self.Elements = self.Elements || {};
|
|
|
|
/* Legacy exported object */
|
|
Elements = Elements || {};
|
|
|
|
/** @constructor */
|
|
Elements.ElementStatePaneWidget = ElementStatePaneWidget;
|
|
|
|
/** @constructor */
|
|
Elements.ElementStatePaneWidget.ButtonProvider = ButtonProvider;
|