drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 26 | WI.AuditTabContentView = class AuditTabContentView extends WI.ContentBrowserTabContentView |
| 27 | { |
| 28 | constructor() |
| 29 | { |
drousso@apple.com | e82f8bd | 2020-03-03 03:22:01 +0000 | [diff] [blame] | 30 | super(AuditTabContentView.tabInfo(), { |
| 31 | navigationSidebarPanelConstructor: WI.AuditNavigationSidebarPanel, |
drousso@apple.com | 33026e3 | 2020-08-29 01:39:46 +0000 | [diff] [blame] | 32 | disableBackForward: true, |
drousso@apple.com | e82f8bd | 2020-03-03 03:22:01 +0000 | [diff] [blame] | 33 | }); |
drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 34 | |
| 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.com | e82f8bd | 2020-03-03 03:22:01 +0000 | [diff] [blame] | 45 | identifier: AuditTabContentView.Type, |
drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 46 | image: "Images/Audit.svg", |
drousso@apple.com | 7cfc783 | 2020-03-27 03:07:25 +0000 | [diff] [blame] | 47 | displayName: WI.UIString("Audit", "Audit Tab Name", "Name of Audit Tab"), |
drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 48 | }; |
| 49 | } |
| 50 | |
| 51 | static isTabAllowed() |
| 52 | { |
drousso@apple.com | 2764480 | 2019-10-17 08:00:46 +0000 | [diff] [blame] | 53 | return WI.sharedApp.isWebDebuggable(); |
drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 54 | } |
| 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.com | 6e92692 | 2020-11-20 22:37:00 +0000 | [diff] [blame] | 76 | attached() |
drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 77 | { |
drousso@apple.com | 6e92692 | 2020-11-20 22:37:00 +0000 | [diff] [blame] | 78 | super.attached(); |
drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 79 | |
| 80 | this._startStopShortcut.disabled = false; |
| 81 | } |
| 82 | |
drousso@apple.com | 6e92692 | 2020-11-20 22:37:00 +0000 | [diff] [blame] | 83 | detached() |
drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 84 | { |
| 85 | this._startStopShortcut.disabled = true; |
| 86 | |
drousso@apple.com | 6e92692 | 2020-11-20 22:37:00 +0000 | [diff] [blame] | 87 | super.detached(); |
drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 88 | } |
| 89 | |
drousso@apple.com | f0f07bb | 2020-08-14 22:00:53 +0000 | [diff] [blame] | 90 | // DropZoneView delegate |
| 91 | |
| 92 | dropZoneShouldAppearForDragEvent(dropZone, event) |
drousso@apple.com | 1fd83a2 | 2019-04-15 18:58:27 +0000 | [diff] [blame] | 93 | { |
drousso@apple.com | f0f07bb | 2020-08-14 22:00:53 +0000 | [diff] [blame] | 94 | 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.com | 1fd83a2 | 2019-04-15 18:58:27 +0000 | [diff] [blame] | 106 | } |
| 107 | |
drousso@apple.com | 4ed15ac | 2018-11-01 01:18:07 +0000 | [diff] [blame] | 108 | // Protected |
| 109 | |
| 110 | initialLayout() |
| 111 | { |
| 112 | super.initialLayout(); |
| 113 | |
drousso@apple.com | f0f07bb | 2020-08-14 22:00:53 +0000 | [diff] [blame] | 114 | let dropZoneView = new WI.DropZoneView(this); |
drousso@apple.com | 33026e3 | 2020-08-29 01:39:46 +0000 | [diff] [blame] | 115 | dropZoneView.text = WI.UIString("Import Audit or Result"); |
drousso@apple.com | f0f07bb | 2020-08-14 22:00:53 +0000 | [diff] [blame] | 116 | dropZoneView.targetElement = this.element; |
| 117 | this.addSubview(dropZoneView); |
| 118 | |
drousso@apple.com | 4ed15ac | 2018-11-01 01:18:07 +0000 | [diff] [blame] | 119 | WI.auditManager.loadStoredTests(); |
| 120 | } |
| 121 | |
drousso@apple.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 122 | // 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.com | fc989ab | 2018-10-31 01:11:36 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | WI.AuditTabContentView.Type = "audit"; |