mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-03 02:21:05 +08:00
This reverts commit340bd16cd3. Reason for revert: devtools_pre_built no longer makes hardlinks Original change's description: > Revert "Reland "Updates elements to devtools_module"" > > This reverts commit04858cf7dd. > > Reason for revert: This seems to trigger the known issue that > TSC is rewriting source files because of left-over hard-links. > See https://ci.chromium.org/p/devtools-frontend/builders/ci/Stand-alone%20Linux/2582 > > To reproduce locally, check out the commit before this revision, > do a clean build, then check out this revision, and do a build. > This will succeed but rewrite source files (which it shouldn't). > > > Original change's description: > > Reland "Updates elements to devtools_module" > > > > This reverts commit22d876ca02. > > > > Reason for revert: Build issues on bots should be fixed > > > > Original change's description: > > > Revert "Updates elements to devtools_module" > > > > > > This reverts commit81e818fad8. > > > > > > Reason for revert: Anticipating build errors on bots > > > > > > Original change's description: > > > > Updates elements to devtools_module > > > > > > > > Bug: 1101738 > > > > Change-Id: I294d366c95a3b5dc7ac5b757855846a7b31ac60b > > > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2329779 > > > > Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> > > > > Commit-Queue: Paul Lewis <aerotwist@chromium.org> > > > > > > TBR=aerotwist@chromium.org,jacktfranklin@chromium.org > > > > > > Change-Id: I3e36a1520e34be3ce1779ecdf2b4cead6a293971 > > > No-Presubmit: true > > > No-Tree-Checks: true > > > No-Try: true > > > Bug: 1101738 > > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2332815 > > > Reviewed-by: Paul Lewis <aerotwist@chromium.org> > > > Commit-Queue: Paul Lewis <aerotwist@chromium.org> > > > > TBR=aerotwist@chromium.org,jacktfranklin@chromium.org > > > > # Not skipping CQ checks because this is a reland. > > > > Bug: 1101738 > > Change-Id: Ia0d06bb75f2610459f4d0b31ff6b770b1031d982 > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2335060 > > Reviewed-by: Paul Lewis <aerotwist@chromium.org> > > Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> > > Commit-Queue: Paul Lewis <aerotwist@chromium.org> > > TBR=aerotwist@chromium.org,jacktfranklin@chromium.org > > Change-Id: Iabfbe2aad94033078eac41338d64ca069f49332f > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: 1101738 > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2335273 > Reviewed-by: Sigurd Schneider <sigurds@chromium.org> > Commit-Queue: Sigurd Schneider <sigurds@chromium.org> TBR=sigurds@chromium.org,aerotwist@chromium.org,jacktfranklin@chromium.org # Not skipping CQ checks because this is a reland. Bug: 1101738 Change-Id: I42579d6cac06ec45377789253588ba94ee72a226 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2336715 Commit-Queue: Paul Lewis <aerotwist@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
180 lines
6.0 KiB
JavaScript
180 lines
6.0 KiB
JavaScript
/*
|
|
* Copyright (C) 2013 Google Inc. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are
|
|
* met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above
|
|
* copyright notice, this list of conditions and the following disclaimer
|
|
* in the documentation and/or other materials provided with the
|
|
* distribution.
|
|
* * Neither the name of Google Inc. nor the names of its
|
|
* contributors may be used to endorse or promote products derived from
|
|
* this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
// @ts-nocheck
|
|
// TODO(crbug.com/1011811): Enable TypeScript compiler checks
|
|
|
|
import * as Common from '../common/common.js';
|
|
import * as SDK from '../sdk/sdk.js';
|
|
import * as UI from '../ui/ui.js';
|
|
|
|
import {ElementsPanel} from './ElementsPanel.js';
|
|
|
|
/**
|
|
* @implements {SDK.SDKModel.SDKModelObserver<!SDK.OverlayModel.OverlayModel>}
|
|
* @unrestricted
|
|
*/
|
|
export class InspectElementModeController {
|
|
/**
|
|
* @suppressGlobalPropertiesCheck
|
|
*/
|
|
constructor() {
|
|
this._toggleSearchAction = self.UI.actionRegistry.action('elements.toggle-element-search');
|
|
this._mode = Protocol.Overlay.InspectMode.None;
|
|
SDK.SDKModel.TargetManager.instance().addEventListener(
|
|
SDK.SDKModel.Events.SuspendStateChanged, this._suspendStateChanged, this);
|
|
SDK.SDKModel.TargetManager.instance().addModelListener(
|
|
SDK.OverlayModel.OverlayModel, SDK.OverlayModel.Events.ExitedInspectMode,
|
|
() => this._setMode(Protocol.Overlay.InspectMode.None));
|
|
SDK.OverlayModel.OverlayModel.setInspectNodeHandler(this._inspectNode.bind(this));
|
|
SDK.SDKModel.TargetManager.instance().observeModels(SDK.OverlayModel.OverlayModel, this);
|
|
|
|
this._showDetailedInspectTooltipSetting =
|
|
Common.Settings.Settings.instance().moduleSetting('showDetailedInspectTooltip');
|
|
this._showDetailedInspectTooltipSetting.addChangeListener(this._showDetailedInspectTooltipChanged.bind(this));
|
|
|
|
document.addEventListener('keydown', event => {
|
|
if (event.keyCode !== UI.KeyboardShortcut.Keys.Esc.code) {
|
|
return;
|
|
}
|
|
if (!this._isInInspectElementMode()) {
|
|
return;
|
|
}
|
|
this._setMode(Protocol.Overlay.InspectMode.None);
|
|
event.consume(true);
|
|
}, true);
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
* @param {!SDK.OverlayModel.OverlayModel} overlayModel
|
|
*/
|
|
modelAdded(overlayModel) {
|
|
// When DevTools are opening in the inspect element mode, the first target comes in
|
|
// much later than the InspectorFrontendAPI.enterInspectElementMode event.
|
|
if (this._mode === Protocol.Overlay.InspectMode.None) {
|
|
return;
|
|
}
|
|
overlayModel.setInspectMode(this._mode, this._showDetailedInspectTooltipSetting.get());
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
* @param {!SDK.OverlayModel.OverlayModel} overlayModel
|
|
*/
|
|
modelRemoved(overlayModel) {
|
|
}
|
|
|
|
/**
|
|
* @return {boolean}
|
|
*/
|
|
_isInInspectElementMode() {
|
|
return this._mode !== Protocol.Overlay.InspectMode.None;
|
|
}
|
|
|
|
_toggleInspectMode() {
|
|
let mode;
|
|
if (this._isInInspectElementMode()) {
|
|
mode = Protocol.Overlay.InspectMode.None;
|
|
} else {
|
|
mode = Common.Settings.Settings.instance().moduleSetting('showUAShadowDOM').get() ?
|
|
Protocol.Overlay.InspectMode.SearchForUAShadowDOM :
|
|
Protocol.Overlay.InspectMode.SearchForNode;
|
|
}
|
|
this._setMode(mode);
|
|
}
|
|
|
|
_captureScreenshotMode() {
|
|
this._setMode(Protocol.Overlay.InspectMode.CaptureAreaScreenshot);
|
|
}
|
|
|
|
/**
|
|
* @param {!Protocol.Overlay.InspectMode} mode
|
|
*/
|
|
_setMode(mode) {
|
|
if (SDK.SDKModel.TargetManager.instance().allTargetsSuspended()) {
|
|
return;
|
|
}
|
|
this._mode = mode;
|
|
for (const overlayModel of SDK.SDKModel.TargetManager.instance().models(SDK.OverlayModel.OverlayModel)) {
|
|
overlayModel.setInspectMode(mode, this._showDetailedInspectTooltipSetting.get());
|
|
}
|
|
this._toggleSearchAction.setToggled(this._isInInspectElementMode());
|
|
}
|
|
|
|
_suspendStateChanged() {
|
|
if (!SDK.SDKModel.TargetManager.instance().allTargetsSuspended()) {
|
|
return;
|
|
}
|
|
|
|
this._mode = Protocol.Overlay.InspectMode.None;
|
|
this._toggleSearchAction.setToggled(false);
|
|
}
|
|
|
|
/**
|
|
* @param {!SDK.DOMModel.DOMNode} node
|
|
*/
|
|
_inspectNode(node) {
|
|
ElementsPanel.instance().revealAndSelectNode(node, true, true);
|
|
}
|
|
|
|
_showDetailedInspectTooltipChanged() {
|
|
this._setMode(this._mode);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @implements {UI.ActionDelegate.ActionDelegate}
|
|
* @unrestricted
|
|
*/
|
|
export class ToggleSearchActionDelegate {
|
|
/**
|
|
* @override
|
|
* @param {!UI.Context.Context} context
|
|
* @param {string} actionId
|
|
* @return {boolean}
|
|
*/
|
|
handleAction(context, actionId) {
|
|
if (!inspectElementModeController) {
|
|
return false;
|
|
}
|
|
if (actionId === 'elements.toggle-element-search') {
|
|
inspectElementModeController._toggleInspectMode();
|
|
} else if (actionId === 'elements.capture-area-screenshot') {
|
|
inspectElementModeController._captureScreenshotMode();
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/** @type {?InspectElementModeController} */
|
|
export const inspectElementModeController =
|
|
Root.Runtime.queryParam('isSharedWorker') ? null : new InspectElementModeController();
|