summaryrefslogtreecommitdiffstats
path: root/Source/WebInspectorUI/UserInterface/Views/ReplayDashboardView.js
blob: 598b57d818998ffb668d3d71bd78ee67a916af74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (C) 2015 Apple Inc. All rights reserved.
 * Copyright (C) 2014 University of Washington. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. 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.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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.
 */

WebInspector.ReplayDashboardView = class ReplayDashboardView extends WebInspector.DashboardView
{
    constructor(representedObject)
    {
        super(representedObject, "replay");

        this._navigationBar = new WebInspector.NavigationBar;
        this.element.appendChild(this._navigationBar.element);

        this._captureButtonItem = new WebInspector.ActivateButtonNavigationItem("replay-dashboard-capture", WebInspector.UIString("Start Recording"), WebInspector.UIString("Stop Recording"), "Images/ReplayRecordingButton.svg", 16, 16);
        this._captureButtonItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, this._captureButtonItemClicked, this);
        this._captureButtonItem.hidden = true;
        this._navigationBar.addNavigationItem(this._captureButtonItem);

        this._replayButtonItem = new WebInspector.ToggleButtonNavigationItem("replay-dashboard-replay", WebInspector.UIString("Start Playback"), WebInspector.UIString("Pause Playback"), "Images/ReplayPlayButton.svg", "Images/ReplayPauseButton.svg", 16, 16);
        this._replayButtonItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, this._replayButtonItemClicked, this);
        this._replayButtonItem.hidden = true;
        this._navigationBar.addNavigationItem(this._replayButtonItem);

        // Add events required to track capture and replay state.
        WebInspector.replayManager.addEventListener(WebInspector.ReplayManager.Event.CaptureStarted, this._captureStarted, this);
        WebInspector.replayManager.addEventListener(WebInspector.ReplayManager.Event.CaptureStopped, this._captureStopped, this);
        WebInspector.replayManager.addEventListener(WebInspector.ReplayManager.Event.PlaybackStarted, this._playbackStarted, this);
        WebInspector.replayManager.addEventListener(WebInspector.ReplayManager.Event.PlaybackPaused, this._playbackPaused, this);
        WebInspector.replayManager.addEventListener(WebInspector.ReplayManager.Event.PlaybackFinished, this._playbackFinished, this);

        // Manually initialize style classes by querying current replay state.
        if (WebInspector.replayManager.sessionState === WebInspector.ReplayManager.SessionState.Capturing)
            this._captureStarted();
        else if (WebInspector.replayManager.sessionState === WebInspector.ReplayManager.SessionState.Inactive)
            this._captureStopped();
        // ReplayManager.sessionState must be Replaying.
        else if (WebInspector.replayManager.segmentState === WebInspector.ReplayManager.SegmentState.Dispatching)
            this._playbackStarted();
        // ReplayManager.sessionState must be Unloaded or Loaded, so execution is paused.
        else
            this._playbackPaused();
    }

    // Private

    _captureButtonItemClicked()
    {
        if (WebInspector.replayManager.sessionState !== WebInspector.ReplayManager.SessionState.Capturing)
            WebInspector.replayManager.startCapturing();
        else
            WebInspector.replayManager.stopCapturing();
    }

    _replayButtonItemClicked(event)
    {
        console.assert(WebInspector.replayManager.sessionState !== WebInspector.ReplayManager.SessionState.Capturing, "Tried to start replaying while SessionState is Capturing!");

        if (WebInspector.replayManager.sessionState === WebInspector.ReplayManager.SessionState.Inactive)
            WebInspector.replayManager.replayToCompletion();
        else if (WebInspector.replayManager.segmentState === WebInspector.ReplayManager.SegmentState.Dispatching)
            WebInspector.replayManager.pausePlayback();
        else
            WebInspector.replayManager.replayToCompletion();
    }

    _captureStarted()
    {
        this._captureButtonItem.hidden = false;
        this._captureButtonItem.activated = true;
        this._replayButtonItem.hidden = true;
    }

    _captureStopped()
    {
        this._captureButtonItem.activated = false;
        this._captureButtonItem.hidden = true;
        this._replayButtonItem.hidden = false;
    }

    _playbackStarted()
    {
        this._replayButtonItem.toggled = true;
    }

    _playbackPaused()
    {
        this._replayButtonItem.toggled = false;
    }

    _playbackFinished()
    {
        this._replayButtonItem.toggled = false;
    }
};