blob: 8f8938e44c43e04ea1af3f6a38b2e9504f6c4c59 [file] [log] [blame]
drousso@apple.comfc989ab2018-10-31 01:11:36 +00001/*
2 * Copyright (C) 2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26WI.AuditTabContentView = class AuditTabContentView extends WI.ContentBrowserTabContentView
27{
28 constructor()
29 {
drousso@apple.come82f8bd2020-03-03 03:22:01 +000030 super(AuditTabContentView.tabInfo(), {
31 navigationSidebarPanelConstructor: WI.AuditNavigationSidebarPanel,
drousso@apple.com33026e32020-08-29 01:39:46 +000032 disableBackForward: true,
drousso@apple.come82f8bd2020-03-03 03:22:01 +000033 });
drousso@apple.comfc989ab2018-10-31 01:11:36 +000034
35 this._startStopShortcut = new WI.KeyboardShortcut(null, WI.KeyboardShortcut.Key.Space, this._handleSpace.bind(this));
36 this._startStopShortcut.implicitlyPreventsDefault = false;
37 this._startStopShortcut.disabled = true;
38 }
39
40 // Static
41
42 static tabInfo()
43 {
44 return {
drousso@apple.come82f8bd2020-03-03 03:22:01 +000045 identifier: AuditTabContentView.Type,
drousso@apple.comfc989ab2018-10-31 01:11:36 +000046 image: "Images/Audit.svg",
drousso@apple.com7cfc7832020-03-27 03:07:25 +000047 displayName: WI.UIString("Audit", "Audit Tab Name", "Name of Audit Tab"),
drousso@apple.comfc989ab2018-10-31 01:11:36 +000048 };
49 }
50
51 static isTabAllowed()
52 {
drousso@apple.com27644802019-10-17 08:00:46 +000053 return WI.sharedApp.isWebDebuggable();
drousso@apple.comfc989ab2018-10-31 01:11:36 +000054 }
55
56 // Public
57
58 get type()
59 {
60 return WI.AuditTabContentView.Type;
61 }
62
63 get supportsSplitContentBrowser()
64 {
65 return true;
66 }
67
68 canShowRepresentedObject(representedObject)
69 {
70 return representedObject instanceof WI.AuditTestCase
71 || representedObject instanceof WI.AuditTestGroup
72 || representedObject instanceof WI.AuditTestCaseResult
73 || representedObject instanceof WI.AuditTestGroupResult;
74 }
75
drousso@apple.com6e926922020-11-20 22:37:00 +000076 attached()
drousso@apple.comfc989ab2018-10-31 01:11:36 +000077 {
drousso@apple.com6e926922020-11-20 22:37:00 +000078 super.attached();
drousso@apple.comfc989ab2018-10-31 01:11:36 +000079
80 this._startStopShortcut.disabled = false;
81 }
82
drousso@apple.com6e926922020-11-20 22:37:00 +000083 detached()
drousso@apple.comfc989ab2018-10-31 01:11:36 +000084 {
85 this._startStopShortcut.disabled = true;
86
drousso@apple.com6e926922020-11-20 22:37:00 +000087 super.detached();
drousso@apple.comfc989ab2018-10-31 01:11:36 +000088 }
89
drousso@apple.comf0f07bb2020-08-14 22:00:53 +000090 // DropZoneView delegate
91
92 dropZoneShouldAppearForDragEvent(dropZone, event)
drousso@apple.com1fd83a22019-04-15 18:58:27 +000093 {
drousso@apple.comf0f07bb2020-08-14 22:00:53 +000094 return event.dataTransfer.types.includes("Files");
95 }
96
97 dropZoneHandleDrop(dropZone, event)
98 {
99 let files = event.dataTransfer.files;
100 if (files.length !== 1) {
101 InspectorFrontendHost.beep();
102 return;
103 }
104
105 WI.FileUtilities.readJSON(files, (result) => WI.auditManager.processJSON(result));
drousso@apple.com1fd83a22019-04-15 18:58:27 +0000106 }
107
drousso@apple.com4ed15ac2018-11-01 01:18:07 +0000108 // Protected
109
110 initialLayout()
111 {
112 super.initialLayout();
113
drousso@apple.comf0f07bb2020-08-14 22:00:53 +0000114 let dropZoneView = new WI.DropZoneView(this);
drousso@apple.com33026e32020-08-29 01:39:46 +0000115 dropZoneView.text = WI.UIString("Import Audit or Result");
drousso@apple.comf0f07bb2020-08-14 22:00:53 +0000116 dropZoneView.targetElement = this.element;
117 this.addSubview(dropZoneView);
118
drousso@apple.com4ed15ac2018-11-01 01:18:07 +0000119 WI.auditManager.loadStoredTests();
120 }
121
drousso@apple.comfc989ab2018-10-31 01:11:36 +0000122 // Private
123
124 _handleSpace(event)
125 {
126 if (WI.isEventTargetAnEditableField(event))
127 return;
128
129 if (WI.auditManager.runningState === WI.AuditManager.RunningState.Inactive)
130 WI.auditManager.start(this.contentBrowser.currentRepresentedObjects);
131 else if (WI.auditManager.runningState === WI.AuditManager.RunningState.Active)
132 WI.auditManager.stop();
133 else
134 return;
135
136 event.preventDefault();
137 }
drousso@apple.comfc989ab2018-10-31 01:11:36 +0000138};
139
140WI.AuditTabContentView.Type = "audit";