Web Inspector: scrolled Snapshot list is reset to top and drawn blank after switching...
[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 scrollableElements()
101     {
102         if (!this._contentViewContainer.currentContentView)
103             return [];
104         return this._contentViewContainer.currentContentView.scrollableElements;
105     }
106
107     get selectionPathComponents()
108     {
109         if (!this._contentViewContainer.currentContentView)
110             return [];
111         return this._contentViewContainer.currentContentView.selectionPathComponents;
112     }
113
114     get supplementalRepresentedObjects()
115     {
116         if (!this._contentViewContainer.currentContentView)
117             return [];
118         return this._contentViewContainer.currentContentView.supplementalRepresentedObjects;
119     }
120
121     get handleCopyEvent()
122     {
123         var currentContentView = this._contentViewContainer.currentContentView;
124         return currentContentView && typeof currentContentView.handleCopyEvent === "function" ? currentContentView.handleCopyEvent.bind(currentContentView) : null;
125     }
126
127     get supportsSave()
128     {
129         var currentContentView = this._contentViewContainer.currentContentView;
130         return currentContentView && currentContentView.supportsSave;
131     }
132
133     get saveData()
134     {
135         var currentContentView = this._contentViewContainer.currentContentView;
136         return currentContentView && currentContentView.saveData || null;
137     }
138
139     get supportsSearch()
140     {
141         // Always return true so we can intercept the search query to resend it when switching content views.
142         return true;
143     }
144
145     get numberOfSearchResults()
146     {
147         var currentContentView = this._contentViewContainer.currentContentView;
148         if (!currentContentView || !currentContentView.supportsSearch)
149             return null;
150         return currentContentView.numberOfSearchResults;
151     }
152
153     get hasPerformedSearch()
154     {
155         var currentContentView = this._contentViewContainer.currentContentView;
156         if (!currentContentView || !currentContentView.supportsSearch)
157             return false;
158         return currentContentView.hasPerformedSearch;
159     }
160
161     set automaticallyRevealFirstSearchResult(reveal)
162     {
163         var currentContentView = this._contentViewContainer.currentContentView;
164         if (!currentContentView || !currentContentView.supportsSearch)
165             return;
166         currentContentView.automaticallyRevealFirstSearchResult = reveal;
167     }
168
169     performSearch(query)
170     {
171         this._searchQuery = query;
172
173         var currentContentView = this._contentViewContainer.currentContentView;
174         if (!currentContentView || !currentContentView.supportsSearch)
175             return;
176         currentContentView.performSearch(query);
177     }
178
179     searchCleared()
180     {
181         this._searchQuery = null;
182
183         var currentContentView = this._contentViewContainer.currentContentView;
184         if (!currentContentView || !currentContentView.supportsSearch)
185             return;
186         currentContentView.searchCleared();
187     }
188
189     searchQueryWithSelection()
190     {
191         var currentContentView = this._contentViewContainer.currentContentView;
192         if (!currentContentView || !currentContentView.supportsSearch)
193             return null;
194         return currentContentView.searchQueryWithSelection();
195     }
196
197     revealPreviousSearchResult(changeFocus)
198     {
199         var currentContentView = this._contentViewContainer.currentContentView;
200         if (!currentContentView || !currentContentView.supportsSearch)
201             return;
202         currentContentView.revealPreviousSearchResult(changeFocus);
203     }
204
205     revealNextSearchResult(changeFocus)
206     {
207         var currentContentView = this._contentViewContainer.currentContentView;
208         if (!currentContentView || !currentContentView.supportsSearch)
209             return;
210         currentContentView.revealNextSearchResult(changeFocus);
211     }
212
213     // Private
214
215     _currentContentViewDidChange(event)
216     {
217         var currentContentView = this._contentViewContainer.currentContentView;
218         if (currentContentView && currentContentView.supportsSearch) {
219             if (this._searchQuery)
220                 currentContentView.performSearch(this._searchQuery);
221             else
222                 currentContentView.searchCleared();
223         }
224
225         this.dispatchEventToListeners(WebInspector.ContentView.Event.SelectionPathComponentsDidChange);
226         this.dispatchEventToListeners(WebInspector.ContentView.Event.NumberOfSearchResultsDidChange);
227         this.dispatchEventToListeners(WebInspector.ContentView.Event.NavigationItemsDidChange);
228     }
229
230     _contentViewSelectionPathComponentDidChange(event)
231     {
232         if (event.target !== this._contentViewContainer.currentContentView)
233             return;
234         this.dispatchEventToListeners(WebInspector.ContentView.Event.SelectionPathComponentsDidChange);
235     }
236
237     _contentViewSupplementalRepresentedObjectsDidChange(event)
238     {
239         if (event.target !== this._contentViewContainer.currentContentView)
240             return;
241         this.dispatchEventToListeners(WebInspector.ContentView.Event.SupplementalRepresentedObjectsDidChange);
242     }
243
244     _contentViewNumberOfSearchResultsDidChange(event)
245     {
246         if (event.target !== this._contentViewContainer.currentContentView)
247             return;
248         this.dispatchEventToListeners(WebInspector.ContentView.Event.NumberOfSearchResultsDidChange);
249     }
250 };