34b8bfb5b62e5099c29208f9d3c337cc2d91b0d3
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / ClusterContentView.js
1 /*
2  * Copyright (C) 2013, 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 WebInspector.ClusterContentView = class ClusterContentView extends WebInspector.ContentView
27 {
28     constructor(representedObject)
29     {
30         super(representedObject);
31
32         this.element.classList.add("cluster");
33
34         this._contentViewContainer = new WebInspector.ContentViewContainer;
35         this._contentViewContainer.addEventListener(WebInspector.ContentViewContainer.Event.CurrentContentViewDidChange, this._currentContentViewDidChange, this);
36         this.addSubview(this._contentViewContainer);
37
38         WebInspector.ContentView.addEventListener(WebInspector.ContentView.Event.SelectionPathComponentsDidChange, this._contentViewSelectionPathComponentDidChange, this);
39         WebInspector.ContentView.addEventListener(WebInspector.ContentView.Event.SupplementalRepresentedObjectsDidChange, this._contentViewSupplementalRepresentedObjectsDidChange, this);
40         WebInspector.ContentView.addEventListener(WebInspector.ContentView.Event.NumberOfSearchResultsDidChange, this._contentViewNumberOfSearchResultsDidChange, this);
41     }
42
43     // Public
44
45     get navigationItems()
46     {
47         var currentContentView = this._contentViewContainer.currentContentView;
48         return currentContentView ? currentContentView.navigationItems : [];
49     }
50
51     get contentViewContainer()
52     {
53         return this._contentViewContainer;
54     }
55
56     get supportsSplitContentBrowser()
57     {
58         if (this._contentViewContainer.currentContentView)
59             return this._contentViewContainer.currentContentView.supportsSplitContentBrowser;
60         return true;
61     }
62
63     shown()
64     {
65         this._contentViewContainer.shown();
66     }
67
68     hidden()
69     {
70         this._contentViewContainer.hidden();
71     }
72
73     closed()
74     {
75         this._contentViewContainer.closeAllContentViews();
76
77         WebInspector.ContentView.removeEventListener(null, null, this);
78     }
79
80     canGoBack()
81     {
82         return this._contentViewContainer.canGoBack();
83     }
84
85     canGoForward()
86     {
87         return this._contentViewContainer.canGoForward();
88     }
89
90     goBack()
91     {
92         this._contentViewContainer.goBack();
93     }
94
95     goForward()
96     {
97         this._contentViewContainer.goForward();
98     }
99
100     get selectionPathComponents()
101     {
102         if (!this._contentViewContainer.currentContentView)
103             return [];
104         return this._contentViewContainer.currentContentView.selectionPathComponents;
105     }
106
107     get supplementalRepresentedObjects()
108     {
109         if (!this._contentViewContainer.currentContentView)
110             return [];
111         return this._contentViewContainer.currentContentView.supplementalRepresentedObjects;
112     }
113
114     get handleCopyEvent()
115     {
116         var currentContentView = this._contentViewContainer.currentContentView;
117         return currentContentView && typeof currentContentView.handleCopyEvent === "function" ? currentContentView.handleCopyEvent.bind(currentContentView) : null;
118     }
119
120     get supportsSave()
121     {
122         var currentContentView = this._contentViewContainer.currentContentView;
123         return currentContentView && currentContentView.supportsSave;
124     }
125
126     get saveData()
127     {
128         var currentContentView = this._contentViewContainer.currentContentView;
129         return currentContentView && currentContentView.saveData || null;
130     }
131
132     get supportsSearch()
133     {
134         // Always return true so we can intercept the search query to resend it when switching content views.
135         return true;
136     }
137
138     get numberOfSearchResults()
139     {
140         var currentContentView = this._contentViewContainer.currentContentView;
141         if (!currentContentView || !currentContentView.supportsSearch)
142             return null;
143         return currentContentView.numberOfSearchResults;
144     }
145
146     get hasPerformedSearch()
147     {
148         var currentContentView = this._contentViewContainer.currentContentView;
149         if (!currentContentView || !currentContentView.supportsSearch)
150             return false;
151         return currentContentView.hasPerformedSearch;
152     }
153
154     set automaticallyRevealFirstSearchResult(reveal)
155     {
156         var currentContentView = this._contentViewContainer.currentContentView;
157         if (!currentContentView || !currentContentView.supportsSearch)
158             return;
159         currentContentView.automaticallyRevealFirstSearchResult = reveal;
160     }
161
162     performSearch(query)
163     {
164         this._searchQuery = query;
165
166         var currentContentView = this._contentViewContainer.currentContentView;
167         if (!currentContentView || !currentContentView.supportsSearch)
168             return;
169         currentContentView.performSearch(query);
170     }
171
172     searchCleared()
173     {
174         this._searchQuery = null;
175
176         var currentContentView = this._contentViewContainer.currentContentView;
177         if (!currentContentView || !currentContentView.supportsSearch)
178             return;
179         currentContentView.searchCleared();
180     }
181
182     searchQueryWithSelection()
183     {
184         var currentContentView = this._contentViewContainer.currentContentView;
185         if (!currentContentView || !currentContentView.supportsSearch)
186             return null;
187         return currentContentView.searchQueryWithSelection();
188     }
189
190     revealPreviousSearchResult(changeFocus)
191     {
192         var currentContentView = this._contentViewContainer.currentContentView;
193         if (!currentContentView || !currentContentView.supportsSearch)
194             return;
195         currentContentView.revealPreviousSearchResult(changeFocus);
196     }
197
198     revealNextSearchResult(changeFocus)
199     {
200         var currentContentView = this._contentViewContainer.currentContentView;
201         if (!currentContentView || !currentContentView.supportsSearch)
202             return;
203         currentContentView.revealNextSearchResult(changeFocus);
204     }
205
206     // Private
207
208     _currentContentViewDidChange(event)
209     {
210         var currentContentView = this._contentViewContainer.currentContentView;
211         if (currentContentView && currentContentView.supportsSearch) {
212             if (this._searchQuery)
213                 currentContentView.performSearch(this._searchQuery);
214             else
215                 currentContentView.searchCleared();
216         }
217
218         this.dispatchEventToListeners(WebInspector.ContentView.Event.SelectionPathComponentsDidChange);
219         this.dispatchEventToListeners(WebInspector.ContentView.Event.NumberOfSearchResultsDidChange);
220         this.dispatchEventToListeners(WebInspector.ContentView.Event.NavigationItemsDidChange);
221     }
222
223     _contentViewSelectionPathComponentDidChange(event)
224     {
225         if (event.target !== this._contentViewContainer.currentContentView)
226             return;
227         this.dispatchEventToListeners(WebInspector.ContentView.Event.SelectionPathComponentsDidChange);
228     }
229
230     _contentViewSupplementalRepresentedObjectsDidChange(event)
231     {
232         if (event.target !== this._contentViewContainer.currentContentView)
233             return;
234         this.dispatchEventToListeners(WebInspector.ContentView.Event.SupplementalRepresentedObjectsDidChange);
235     }
236
237     _contentViewNumberOfSearchResultsDidChange(event)
238     {
239         if (event.target !== this._contentViewContainer.currentContentView)
240             return;
241         this.dispatchEventToListeners(WebInspector.ContentView.Event.NumberOfSearchResultsDidChange);
242     }
243 };