Web Inspector: Elements: Styles: add icons for various CSS rule types
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / ElementsTabContentView.js
1 /*
2  * Copyright (C) 2015 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.ElementsTabContentView = class ElementsTabContentView extends WI.ContentBrowserTabContentView
27 {
28     constructor(identifier)
29     {
30         let tabBarItem = WI.GeneralTabBarItem.fromTabInfo(WI.ElementsTabContentView.tabInfo());
31
32         let detailsSidebarPanelConstructors = [WI.RulesStyleDetailsSidebarPanel, WI.ComputedStyleDetailsSidebarPanel, WI.ChangesDetailsSidebarPanel, WI.DOMNodeDetailsSidebarPanel];
33         if (window.LayerTreeAgent)
34             detailsSidebarPanelConstructors.push(WI.LayerTreeDetailsSidebarPanel);
35
36         super(identifier || "elements", "elements", tabBarItem, null, detailsSidebarPanelConstructors, true);
37
38         WI.networkManager.addEventListener(WI.NetworkManager.Event.MainFrameDidChange, this._mainFrameDidChange, this);
39         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
40     }
41
42     static tabInfo()
43     {
44         return {
45             image: "Images/Elements.svg",
46             title: WI.UIString("Elements"),
47         };
48     }
49
50     static isTabAllowed()
51     {
52         return !!window.DOMAgent;
53     }
54
55     // Public
56
57     get type()
58     {
59         return WI.ElementsTabContentView.Type;
60     }
61
62     get supportsSplitContentBrowser()
63     {
64         return true;
65     }
66
67     canShowRepresentedObject(representedObject)
68     {
69         return representedObject instanceof WI.DOMTree;
70     }
71
72     showRepresentedObject(representedObject, cookie)
73     {
74         if (!this.contentBrowser.currentContentView)
75             this._showDOMTreeContentView();
76
77         if (!cookie || !cookie.nodeToSelect)
78             return;
79
80         let domTreeContentView = this.contentBrowser.currentContentView;
81         console.assert(domTreeContentView instanceof WI.DOMTreeContentView, "Unexpected DOMTreeContentView representedObject.", domTreeContentView);
82
83         domTreeContentView.selectAndRevealDOMNode(cookie.nodeToSelect);
84
85         // Because nodeToSelect is ephemeral, we don't want to keep
86         // it around in the back-forward history entries.
87         cookie.nodeToSelect = undefined;
88     }
89
90     shown()
91     {
92         super.shown();
93
94         if (!this.contentBrowser.currentContentView)
95             this._showDOMTreeContentView();
96     }
97
98     closed()
99     {
100         super.closed();
101
102         WI.networkManager.removeEventListener(null, null, this);
103         WI.Frame.removeEventListener(null, null, this);
104     }
105
106     // Private
107
108     _showDOMTreeContentView()
109     {
110         this.contentBrowser.contentViewContainer.closeAllContentViews();
111
112         var mainFrame = WI.networkManager.mainFrame;
113         if (mainFrame)
114             this.contentBrowser.showContentViewForRepresentedObject(mainFrame.domTree);
115     }
116
117     _mainFrameDidChange(event)
118     {
119         this._showDOMTreeContentView();
120     }
121
122     _mainResourceDidChange(event)
123     {
124         if (!event.target.isMainFrame())
125             return;
126
127         this._showDOMTreeContentView();
128     }
129 };
130
131 WI.ElementsTabContentView.Type = "elements";